Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ShellEMDataSet.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//
28// Author: Maria Grazia Pia ([email protected])
29//
30// History:
31// -----------
32// 1 Aug 2001 MGP Created
33//
34// 09.10.01 V.Ivanchenko Add case z=0
35//
36// 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer
37// (Further clean-up needed)
38//
39// 15 Jul 2009 Nicolas A. Karakatsanis
40//
41// - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW
42// dataset. It is essentially performing the data loading operations as in the past.
43//
44// - LoadData method was revised in order to calculate the logarithmic values of the data
45// It retrieves the data values from the G4EMLOW data files but, then, calculates the
46// respective log values and loads them to seperate data structures.
47//
48// - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors.
49// The EM data sets, initialized this way, contain both non-log and log values.
50// These initialized data sets can enhance the computing performance of data interpolation
51// operations
52//
53//
54// -------------------------------------------------------------------
55
56#include "G4ShellEMDataSet.hh"
57#include "G4EMDataSet.hh"
59#include <fstream>
60#include <sstream>
61
62
64 G4double eUnit,
65 G4double dataUnit)
66 :
67 z(zeta),
68 algorithm(algo),
69 unitEnergies(eUnit),
70 unitData(dataUnit)
71{
72 if (algorithm == 0) G4Exception("G4ShellEMDataSet::G4ShellEMDataSet()","em0007",FatalErrorInArgument, "Interpolation == 0");
73}
74
75
77{
79 if (algorithm) delete algorithm;
80}
81
82
83G4double G4ShellEMDataSet::FindValue(G4double energy, G4int /* componentId */) const
84{
85 // Returns the sum over the shells corresponding to e
86 G4double value = 0.;
87
88 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
89 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
90
91 while (i != end)
92 {
93 value += (*i)->FindValue(energy);
94 i++;
95 }
96
97 return value;
98}
99
100
102{
103 const size_t n = NumberOfComponents();
104
105 G4cout << "The data set has " << n << " components" << G4endl;
106 G4cout << G4endl;
107
108 size_t i = 0;
109
110 while (i < n)
111 {
112 G4cout << "--- Component " << i << " ---" << G4endl;
114 i++;
115 }
116}
117
118
120 G4DataVector* data,
121 G4int componentId)
122{
123 G4VEMDataSet* component = components[componentId];
124
125 if (component)
126 {
127 component->SetEnergiesData(energies, data, 0);
128 return;
129 }
130
131 G4String msg = "component " + (G4String)componentId + " not found";
132
133 G4Exception("G4ShellEMDataSet::SetEnergiesData()","em0008", FatalErrorInArgument ,msg);
134}
135
136
138 G4DataVector* data,
139 G4DataVector* log_energies,
140 G4DataVector* log_data,
141 G4int componentId)
142{
143 G4VEMDataSet* component = components[componentId];
144
145 if (component)
146 {
147 component->SetLogEnergiesData(energies, data, log_energies, log_data, 0);
148 return;
149 }
150
151 G4String msg = "component " + (G4String)componentId + " not found";
152
153 G4Exception("G4ShellEMDataSet::SetLogEnergiesData()","em0008", FatalErrorInArgument ,msg);
154
155}
156
157
158
160{
162
163 G4String fullFileName = FullFileName(file);
164 std::ifstream in(fullFileName);
165
166 if (!in.is_open())
167 {
168 G4String message("Data file \"");
169 message += fullFileName;
170 message += "\" not found";
171 G4Exception("G4ShellEMDataSet::LoadData()", "em0003",FatalException, message);
172 return 0;
173 }
174
175 G4DataVector* orig_shell_energies = 0;
176 G4DataVector* orig_shell_data = 0;
177 G4DataVector* log_shell_energies = 0;
178 G4DataVector* log_shell_data = 0;
179
180 G4double a = 0.;
181 G4int shellIndex = 0;
182 G4int k = 0;
183 G4int nColumns = 2;
184
185 do
186 {
187 in >> a;
188
189 if (a==0.) a=1e-300;
190
191 // The file is organized into four columns:
192 // 1st column contains the values of energy
193 // 2nd column contains the corresponding data value
194 // The file terminates with the pattern: -1 -1
195 // -2 -2
196 //
197 if (a == -1)
198 {
199 if ((k%nColumns == 0) && (orig_shell_energies != 0) )
200 {
201 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, log_shell_energies, log_shell_data, algorithm->Clone(), unitEnergies, unitData));
202 orig_shell_energies = 0;
203 orig_shell_data = 0;
204 log_shell_energies = 0;
205 log_shell_data = 0;
206 }
207 }
208 else if (a != -2)
209 {
210 if (orig_shell_energies == 0)
211 {
212 orig_shell_energies = new G4DataVector;
213 orig_shell_data = new G4DataVector;
214 log_shell_energies = new G4DataVector;
215 log_shell_data = new G4DataVector;
216 }
217 if (k%nColumns == 0)
218 {
219 orig_shell_energies->push_back(a*unitEnergies);
220 log_shell_energies->push_back(std::log10(a) + std::log10(unitEnergies));
221 }
222 else if (k%nColumns == 1)
223 {
224 orig_shell_data->push_back(a*unitData);
225 log_shell_data->push_back(std::log10(a) + std::log10(unitData));
226 }
227 k++;
228 }
229 else k = 1;
230 }
231 while (a != -2); // End of file
232
233
234 delete orig_shell_energies;
235 delete orig_shell_data;
236 delete log_shell_energies;
237 delete log_shell_data;
238
239 return true;
240}
241
242
244{
246
247 G4String fullFileName = FullFileName(file);
248 std::ifstream in(fullFileName);
249
250 if (!in.is_open())
251 {
252 G4String message("G4ShellEMDataSet::LoadData - data file \"");
253 message += fullFileName;
254 message += "\" not found";
255 G4Exception("G4ShellEMDataSet::LoadNonLogData()", "em0003",FatalException, message);
256 return 0;
257 }
258
259 G4DataVector* orig_shell_energies = 0;
260 G4DataVector* orig_shell_data = 0;
261
262 G4double a = 0.;
263 G4int shellIndex = 0;
264 G4int k = 0;
265 G4int nColumns = 2;
266
267 do
268 {
269 in >> a;
270
271 // The file is organized into four columns:
272 // 1st column contains the values of energy
273 // 2nd column contains the corresponding data value
274 // The file terminates with the pattern: -1 -1
275 // -2 -2
276 //
277 if (a == -1)
278 {
279 if ((k%nColumns == 0) && (orig_shell_energies != 0) )
280 {
281 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, algorithm->Clone(), unitEnergies, unitData));
282 orig_shell_energies = 0;
283 orig_shell_data = 0;
284 }
285 }
286 else if (a != -2)
287 {
288 if (orig_shell_energies == 0)
289 {
290 orig_shell_energies = new G4DataVector;
291 orig_shell_data = new G4DataVector;
292 }
293 if (k%nColumns == 0)
294 {
295 orig_shell_energies->push_back(a*unitEnergies);
296 }
297 else if (k%nColumns == 1)
298 {
299 orig_shell_data->push_back(a*unitData);
300 }
301 k++;
302 }
303 else k = 1;
304 }
305 while (a != -2); // End of file
306
307
308 delete orig_shell_energies;
309 delete orig_shell_data;
310
311 return true;
312}
313
314
315
317{
318 G4String fullFileName = FullFileName(file);
319 std::ofstream out(fullFileName);
320
321 if (!out.is_open())
322 {
323 G4String message("Cannot open \"");
324 message += fullFileName;
325 message += "\"";
326 G4Exception("G4EMDataSet::SaveData()","em0005",FatalException,message);
327 }
328
329 const size_t n = NumberOfComponents();
330 size_t k = 0;
331
332 while (k < n)
333 {
334 const G4VEMDataSet* component = GetComponent(k);
335
336 if (component)
337 {
338 const G4DataVector& energies = component->GetEnergies(0);
339 const G4DataVector& data = component->GetData(0);
340
341 G4DataVector::const_iterator i = energies.begin();
342 G4DataVector::const_iterator endI = energies.end();
343 G4DataVector::const_iterator j = data.begin();
344
345 while (i != endI)
346 {
347 out.precision(10);
348 out.width(15);
349 out.setf(std::ofstream::left);
350 out << ((*i)/unitEnergies) << ' ';
351
352 out.precision(10);
353 out.width(15);
354 out.setf(std::ofstream::left);
355 out << ((*j)/unitData) << std::endl;
356 i++;
357 j++;
358 }
359 }
360
361 out.precision(10);
362 out.width(15);
363 out.setf(std::ofstream::left);
364 out << -1.f << ' ';
365
366 out.precision(10);
367 out.width(15);
368 out.setf(std::ofstream::left);
369 out << -1.f << std::endl;
370
371 k++;
372 }
373
374 out.precision(10);
375 out.width(15);
376 out.setf(std::ofstream::left);
377 out << -2.f << ' ';
378
379 out.precision(10);
380 out.width(15);
381 out.setf(std::ofstream::left);
382 out << -2.f << std::endl;
383
384 return true;
385}
386
387
389{
390 while (!components.empty())
391 {
392 if (components.back()) delete components.back();
393 components.pop_back();
394 }
395}
396
397
398G4String G4ShellEMDataSet::FullFileName(const G4String& fileName) const
399{
400 char* path = std::getenv("G4LEDATA");
401
402 if (!path)
403 {
404 G4Exception("G4ShellEMDataSet::FullFileName()","em0006",JustWarning,"Please set G4LEDATA");
405 return "";
406 }
407
408 std::ostringstream fullFileName;
409
410 fullFileName << path << '/' << fileName << z << ".dat";
411
412 return G4String(fullFileName.str().c_str());
413}
@ JustWarning
@ FatalException
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
virtual G4bool SaveData(const G4String &fileName) const
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
G4ShellEMDataSet(G4int Z, G4VDataSetAlgorithm *algo, G4double eUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
virtual size_t NumberOfComponents(void) const
virtual G4double FindValue(G4double energy, G4int componentId=0) const
void CleanUpComponents(void)
virtual void AddComponent(G4VEMDataSet *dataSet)
virtual G4bool LoadData(const G4String &fileName)
virtual void SetLogEnergiesData(G4DataVector *energies, G4DataVector *data, G4DataVector *log_energies, G4DataVector *log_data, G4int componentId)
virtual void PrintData(void) const
virtual G4bool LoadNonLogData(const G4String &fileName)
virtual ~G4ShellEMDataSet()
virtual void SetEnergiesData(G4DataVector *energies, G4DataVector *data, G4int componentId)
virtual G4VDataSetAlgorithm * Clone() const =0
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual const G4DataVector & GetData(G4int componentId) const =0
virtual const G4DataVector & GetEnergies(G4int componentId) const =0
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0
virtual void PrintData(void) const =0