source: trunk/source/processes/electromagnetic/lowenergy/src/G4ShellEMDataSet.cc @ 924

Last change on this file since 924 was 819, checked in by garnier, 16 years ago

import all except CVS

File size: 6.9 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4ShellEMDataSet.cc,v 1.15 2007/10/15 08:36:35 pia Exp $
28// GEANT4 tag $Name: geant4-09-01-patch-02 $
29//
30// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31//
32// History:
33// -----------
34// 1 Aug 2001   MGP        Created
35// 09.10.01   V.Ivanchenko Add case z=0
36//
37// -------------------------------------------------------------------
38
39#include "G4ShellEMDataSet.hh"
40#include "G4EMDataSet.hh"
41#include "G4VDataSetAlgorithm.hh"
42#include <fstream>
43#include <sstream>
44
45
46G4ShellEMDataSet::G4ShellEMDataSet(G4int argZ, G4VDataSetAlgorithm* argAlgorithm, 
47                                   G4double argUnitEnergies, 
48                                   G4double argUnitData)
49  :
50  z(argZ),
51  algorithm(argAlgorithm),
52  unitEnergies(argUnitEnergies),
53  unitData(argUnitData)
54{
55  if (algorithm == 0) 
56    G4Exception("G4ShellEMDataSet::G4ShellEMDataSet - interpolation == 0");
57}
58
59
60G4ShellEMDataSet::~G4ShellEMDataSet()
61{
62  CleanUpComponents();
63 
64  if (algorithm)
65    delete algorithm;
66}
67
68
69G4double G4ShellEMDataSet::FindValue(G4double argEnergy, G4int /* argComponentId */) const
70{
71  // Returns the sum over the shells corresponding to e
72  G4double value = 0.;
73
74  std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
75  std::vector<G4VEMDataSet *>::const_iterator end(components.end());
76
77  while (i!=end)
78    {
79      value+=(*i)->FindValue(argEnergy);
80      i++;
81    }
82
83  return value;
84}
85
86
87void G4ShellEMDataSet::PrintData(void) const
88{
89  const size_t n(NumberOfComponents());
90
91  G4cout << "The data set has " << n << " components" << G4endl;
92  G4cout << G4endl;
93 
94  size_t i(0);
95 
96  while (i<n)
97    {
98      G4cout << "--- Component " << i << " ---" << G4endl;
99      GetComponent(i)->PrintData();
100      i++;
101    }
102}
103
104
105void G4ShellEMDataSet :: SetEnergiesData(G4DataVector* argEnergies, 
106                                         G4DataVector* argData, 
107                                         G4int argComponentId)
108{
109  G4VEMDataSet * component(components[argComponentId]);
110 
111  if (component)
112    {
113      component->SetEnergiesData(argEnergies, argData, 0);
114      return;
115    }
116
117  std::ostringstream message;
118  message << "G4ShellEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
119 
120  G4Exception(message.str().c_str());
121}
122
123
124G4bool G4ShellEMDataSet::LoadData(const G4String& argFileName)
125{
126  CleanUpComponents();
127
128  G4String fullFileName(FullFileName(argFileName));
129  std::ifstream in(fullFileName);
130
131  if (!in.is_open())
132    {
133      G4String message("G4ShellEMDataSet::LoadData - data file \"");
134      message+=fullFileName;
135      message+="\" not found";
136      G4Exception(message);
137    }
138
139  G4DataVector* argEnergies(0);
140  G4DataVector* argData(0);
141
142  G4double a;
143  G4int shellIndex(0);
144  bool energyColumn(true);
145
146  do
147    {
148      in >> a;
149 
150      if (a == -1)
151        {
152          if (energyColumn && argEnergies!=0)
153            {
154              AddComponent(new G4EMDataSet(shellIndex, argEnergies, argData, algorithm->Clone(), unitEnergies, unitData));
155              argEnergies=0;
156              argData=0;
157            }
158   
159          energyColumn=(!energyColumn);
160        }
161      else if (a!=-2)
162        {
163          if (argEnergies==0)
164            {
165              argEnergies=new G4DataVector;
166              argData=new G4DataVector;
167            }
168 
169          if (energyColumn)
170            argEnergies->push_back(a*unitEnergies);
171          else
172            argData->push_back(a*unitData);
173
174          energyColumn=(!energyColumn);
175        }
176    }
177  while (a != -2);
178
179  return true;
180}
181
182
183G4bool G4ShellEMDataSet::SaveData(const G4String& argFileName) const
184{
185  G4String fullFileName(FullFileName(argFileName));
186  std::ofstream out(fullFileName);
187
188  if (!out.is_open())
189    {
190      G4String message("G4EMDataSet::SaveData - cannot open \"");
191      message+=fullFileName;
192      message+="\"";
193      G4Exception(message);
194    }
195 
196  const size_t n(NumberOfComponents());
197  size_t k(0);
198 
199  while (k<n)
200    {
201      const G4VEMDataSet * component=GetComponent(k);
202 
203      if (component)
204        {
205          const G4DataVector & energies(component->GetEnergies(0));
206          const G4DataVector & data(component->GetData(0));
207 
208          G4DataVector::const_iterator i(energies.begin());
209          G4DataVector::const_iterator endI(energies.end());
210          G4DataVector::const_iterator j(data.begin());
211 
212          while (i!=endI)
213            {
214              out.precision(10);
215              out.width(15);
216              out.setf(std::ofstream::left);
217              out << ((*i)/unitEnergies) << ' ';
218
219              out.precision(10);
220              out.width(15);
221              out.setf(std::ofstream::left);
222              out << ((*j)/unitData) << std::endl;
223              i++;
224              j++;
225            }
226        }
227 
228      out.precision(10);
229      out.width(15);
230      out.setf(std::ofstream::left);
231      out << -1.f << ' ';
232
233      out.precision(10);
234      out.width(15);
235      out.setf(std::ofstream::left);
236      out << -1.f << std::endl;
237 
238      k++;
239    }
240 
241  out.precision(10);
242  out.width(15);
243  out.setf(std::ofstream::left);
244  out << -2.f << ' ';
245
246  out.precision(10);
247  out.width(15);
248  out.setf(std::ofstream::left);
249  out << -2.f << std::endl;
250
251  return true;
252}
253
254
255
256
257
258void G4ShellEMDataSet::CleanUpComponents(void)
259{
260  while (!components.empty())
261    {
262      if (components.back())
263        delete components.back();
264
265      components.pop_back();
266    }
267}
268
269
270
271
272
273G4String G4ShellEMDataSet::FullFileName(const G4String & argFileName) const
274{
275  char* path = getenv("G4LEDATA");
276  if (!path)
277    G4Exception("G4ShellEMDataSet::FullFileName - G4LEDATA environment variable not set");
278 
279  std::ostringstream fullFileName;
280 
281  fullFileName << path << '/' << argFileName << z << ".dat";
282                     
283  return G4String(fullFileName.str().c_str());
284}
Note: See TracBrowser for help on using the repository browser.