Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RDShellEMDataSet.cc
Go to the documentation of this file.
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$
28 // GEANT4 tag $Name: $
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 // 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer
37 // (Further clean-up needed)
38 //
39 // -------------------------------------------------------------------
40 
41 #include "G4RDShellEMDataSet.hh"
42 #include "G4RDEMDataSet.hh"
43 #include "G4RDVDataSetAlgorithm.hh"
44 #include <fstream>
45 #include <sstream>
46 
47 
49  G4double eUnit,
50  G4double dataUnit)
51  :
52  z(zeta),
53  algorithm(algo),
54  unitEnergies(eUnit),
55  unitData(dataUnit)
56 {
57  if (algorithm == 0)
58  G4Exception("G4RDShellEMDataSet::G4RDShellEMDataSet()", "InvalidSetup",
59  FatalException, "Interpolation == 0!");
60 }
61 
62 
64 {
66  if (algorithm) delete algorithm;
67 }
68 
69 
71 {
72  // Returns the sum over the shells corresponding to e
73  G4double value = 0.;
74 
75  std::vector<G4RDVEMDataSet *>::const_iterator i(components.begin());
76  std::vector<G4RDVEMDataSet *>::const_iterator end(components.end());
77 
78  while (i != end)
79  {
80  value += (*i)->FindValue(energy);
81  i++;
82  }
83 
84  return value;
85 }
86 
87 
89 {
90  const size_t n = NumberOfComponents();
91 
92  G4cout << "The data set has " << n << " components" << G4endl;
93  G4cout << G4endl;
94 
95  size_t i = 0;
96 
97  while (i < n)
98  {
99  G4cout << "--- Component " << i << " ---" << G4endl;
100  GetComponent(i)->PrintData();
101  i++;
102  }
103 }
104 
105 
107  G4DataVector* data,
108  G4int componentId)
109 {
110  G4RDVEMDataSet* component = components[componentId];
111 
112  if (component)
113  {
114  component->SetEnergiesData(energies, data, 0);
115  return;
116  }
117 
118  std::ostringstream message;
119  message << "Component " << componentId << " not found";
120 
121  G4Exception("G4RDShellEMDataSet::SetEnergiesData()", "DataNotFound",
122  FatalException, message.str().c_str());
123 }
124 
125 
127 {
129 
130  G4String fullFileName = FullFileName(file);
131  std::ifstream in(fullFileName);
132 
133  if (!in.is_open())
134  {
135  G4String message("Data file \"");
136  message += fullFileName;
137  message += "\" not found";
138  G4Exception("G4RDShellEMDataSet::LoadData()", "DataNotFound",
139  FatalException, message);
140  }
141 
142  G4DataVector* energies = 0;
143  G4DataVector* data = 0;
144 
145  G4double a = 0.;
146  G4int shellIndex = 0;
147  bool energyColumn = true;
148 
149  do
150  {
151  in >> a;
152 
153  if (a == -1)
154  {
155  if (energyColumn && energies!=0)
156  {
157  AddComponent(new G4RDEMDataSet(shellIndex, energies, data, algorithm->Clone(), unitEnergies, unitData));
158  energies = 0;
159  data = 0;
160  }
161 
162  energyColumn = (!energyColumn);
163  }
164  else if (a != -2)
165  {
166  if (energies == 0)
167  {
168  energies = new G4DataVector;
169  data = new G4DataVector;
170  }
171 
172  if (energyColumn)
173  energies->push_back(a * unitEnergies);
174  else
175  data->push_back(a * unitData);
176 
177  energyColumn = (!energyColumn);
178  }
179  }
180  while (a != -2);
181 
182  return true;
183 }
184 
185 
187 {
188  G4String fullFileName = FullFileName(file);
189  std::ofstream out(fullFileName);
190 
191  if (!out.is_open())
192  {
193  G4String message("Cannot open \"");
194  message += fullFileName;
195  message += "\"";
196  G4Exception("G4RDEMDataSet::SaveData()", "CannotOpenFile",
197  FatalException, message);
198  }
199 
200  const size_t n = NumberOfComponents();
201  size_t k = 0;
202 
203  while (k < n)
204  {
205  const G4RDVEMDataSet* component = GetComponent(k);
206 
207  if (component)
208  {
209  const G4DataVector& energies = component->GetEnergies(0);
210  const G4DataVector& data = component->GetData(0);
211 
212  G4DataVector::const_iterator i = energies.begin();
213  G4DataVector::const_iterator endI = energies.end();
214  G4DataVector::const_iterator j = data.begin();
215 
216  while (i != endI)
217  {
218  out.precision(10);
219  out.width(15);
220  out.setf(std::ofstream::left);
221  out << ((*i)/unitEnergies) << ' ';
222 
223  out.precision(10);
224  out.width(15);
225  out.setf(std::ofstream::left);
226  out << ((*j)/unitData) << std::endl;
227  i++;
228  j++;
229  }
230  }
231 
232  out.precision(10);
233  out.width(15);
234  out.setf(std::ofstream::left);
235  out << -1.f << ' ';
236 
237  out.precision(10);
238  out.width(15);
239  out.setf(std::ofstream::left);
240  out << -1.f << std::endl;
241 
242  k++;
243  }
244 
245  out.precision(10);
246  out.width(15);
247  out.setf(std::ofstream::left);
248  out << -2.f << ' ';
249 
250  out.precision(10);
251  out.width(15);
252  out.setf(std::ofstream::left);
253  out << -2.f << std::endl;
254 
255  return true;
256 }
257 
258 
260 {
261  while (!components.empty())
262  {
263  if (components.back()) delete components.back();
264  components.pop_back();
265  }
266 }
267 
268 
269 G4String G4RDShellEMDataSet::FullFileName(const G4String& fileName) const
270 {
271  char* path = getenv("G4LEDATA");
272  if (!path)
273  G4Exception("G4RDShellEMDataSet::FullFileName()", "InvalidSetup",
274  FatalException, "G4LEDATA environment variable not set!");
275 
276  std::ostringstream fullFileName;
277 
278  fullFileName << path << '/' << fileName << z << ".dat";
279 
280  return G4String(fullFileName.str().c_str());
281 }
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual G4RDVDataSetAlgorithm * Clone() const =0
virtual const G4DataVector & GetData(G4int componentId) const =0
virtual void PrintData(void) const
G4double z
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
double precision function energy(A, Z)
Definition: dpm25nuc6.f:4106
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
const G4int n
virtual void PrintData(void) const =0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual const G4DataVector & GetEnergies(G4int componentId) const =0
virtual void SetEnergiesData(G4DataVector *energies, G4DataVector *data, G4int componentId)
virtual void AddComponent(G4RDVEMDataSet *dataSet)
virtual G4bool SaveData(const G4String &fileName) const
virtual const G4RDVEMDataSet * GetComponent(G4int componentId) const
virtual G4double FindValue(G4double energy, G4int componentId=0) const
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
virtual size_t NumberOfComponents(void) const
double G4double
Definition: G4Types.hh:76
virtual G4bool LoadData(const G4String &fileName)
G4RDShellEMDataSet(G4int Z, G4RDVDataSetAlgorithm *algo, G4double eUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
const XML_Char const XML_Char * data