Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MicroElecCrossSectionDataSet Class Reference

#include <G4MicroElecCrossSectionDataSet.hh>

+ Inheritance diagram for G4MicroElecCrossSectionDataSet:

Public Member Functions

 G4MicroElecCrossSectionDataSet (G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
 
 ~G4MicroElecCrossSectionDataSet ()
 
G4double FindValue (G4double e, G4int componentId=0) const override
 
void PrintData (void) const override
 
const G4VEMDataSetGetComponent (G4int componentId) const override
 
void AddComponent (G4VEMDataSet *dataSet) override
 
size_t NumberOfComponents (void) const override
 
const G4DataVectorGetEnergies (G4int componentId) const override
 
const G4DataVectorGetData (G4int componentId) const override
 
const G4DataVectorGetLogEnergies (G4int componentId) const override
 
const G4DataVectorGetLogData (G4int componentId) const override
 
void SetEnergiesData (G4DataVector *x, G4DataVector *values, G4int componentId) override
 
void SetLogEnergiesData (G4DataVector *x, G4DataVector *values, G4DataVector *log_x, G4DataVector *log_values, G4int componentId) override
 
G4bool LoadData (const G4String &argFileName) override
 
G4bool LoadNonLogData (const G4String &argFileName) override
 
G4bool SaveData (const G4String &argFileName) const override
 
G4double RandomSelect (G4int) const override
 
 G4MicroElecCrossSectionDataSet (const G4MicroElecCrossSectionDataSet &copy)=delete
 
G4MicroElecCrossSectionDataSetoperator= (const G4MicroElecCrossSectionDataSet &right)=delete
 
- Public Member Functions inherited from G4VEMDataSet
 G4VEMDataSet ()
 
virtual ~G4VEMDataSet ()
 
virtual G4double FindValue (G4double x, G4int componentId=0) const =0
 
virtual void PrintData (void) const =0
 
virtual const G4VEMDataSetGetComponent (G4int componentId) const =0
 
virtual void AddComponent (G4VEMDataSet *dataSet)=0
 
virtual size_t NumberOfComponents (void) const =0
 
virtual const G4DataVectorGetEnergies (G4int componentId) const =0
 
virtual const G4DataVectorGetData (G4int componentId) const =0
 
virtual const G4DataVectorGetLogEnergies (G4int componentId) const =0
 
virtual const G4DataVectorGetLogData (G4int componentId) const =0
 
virtual void SetEnergiesData (G4DataVector *x, G4DataVector *data, G4int component=0)=0
 
virtual void SetLogEnergiesData (G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0
 
virtual G4bool LoadData (const G4String &fileName)=0
 
virtual G4bool LoadNonLogData (const G4String &fileName)=0
 
virtual G4bool SaveData (const G4String &fileName) const =0
 
virtual G4double RandomSelect (G4int componentId=0) const =0
 
 G4VEMDataSet (const G4VEMDataSet &copy)=delete
 
G4VEMDataSetoperator= (const G4VEMDataSet &right)=delete
 

Detailed Description

Definition at line 37 of file G4MicroElecCrossSectionDataSet.hh.

Constructor & Destructor Documentation

◆ G4MicroElecCrossSectionDataSet() [1/2]

G4MicroElecCrossSectionDataSet::G4MicroElecCrossSectionDataSet ( G4VDataSetAlgorithm algo,
G4double  xUnit = CLHEP::MeV,
G4double  dataUnit = CLHEP::barn 
)
explicit

Definition at line 39 of file G4MicroElecCrossSectionDataSet.cc.

42 :
43 algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
44{;}

◆ ~G4MicroElecCrossSectionDataSet()

G4MicroElecCrossSectionDataSet::~G4MicroElecCrossSectionDataSet ( )

Definition at line 47 of file G4MicroElecCrossSectionDataSet.cc.

48{
49 CleanUpComponents();
50
51 if (algorithm)
52 delete algorithm;
53}

◆ G4MicroElecCrossSectionDataSet() [2/2]

G4MicroElecCrossSectionDataSet::G4MicroElecCrossSectionDataSet ( const G4MicroElecCrossSectionDataSet copy)
delete

Member Function Documentation

◆ AddComponent()

void G4MicroElecCrossSectionDataSet::AddComponent ( G4VEMDataSet dataSet)
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 52 of file G4MicroElecCrossSectionDataSet.hh.

53 { components.push_back(dataSet); }

Referenced by LoadData(), and LoadNonLogData().

◆ FindValue()

G4double G4MicroElecCrossSectionDataSet::FindValue ( G4double  e,
G4int  componentId = 0 
) const
overridevirtual

Implements G4VEMDataSet.

Definition at line 451 of file G4MicroElecCrossSectionDataSet.cc.

452{
453 // Returns the sum over the shells corresponding to e
454 G4double value = 0.;
455
456 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
457 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
458
459 while (i!=end)
460 {
461 value+=(*i)->FindValue(argEnergy);
462 i++;
463 }
464
465 return value;
466}
double G4double
Definition: G4Types.hh:83

Referenced by G4MicroElecElasticModel::CrossSectionPerVolume(), and G4MicroElecInelasticModel::CrossSectionPerVolume().

◆ GetComponent()

const G4VEMDataSet * G4MicroElecCrossSectionDataSet::GetComponent ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 49 of file G4MicroElecCrossSectionDataSet.hh.

50 { return components[componentId]; }

Referenced by GetData(), GetEnergies(), GetLogData(), GetLogEnergies(), PrintData(), and SaveData().

◆ GetData()

const G4DataVector & G4MicroElecCrossSectionDataSet::GetData ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 61 of file G4MicroElecCrossSectionDataSet.hh.

62 { return GetComponent(componentId)->GetData(0); }
const G4VEMDataSet * GetComponent(G4int componentId) const override
virtual const G4DataVector & GetData(G4int componentId) const =0

◆ GetEnergies()

const G4DataVector & G4MicroElecCrossSectionDataSet::GetEnergies ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 58 of file G4MicroElecCrossSectionDataSet.hh.

59 { return GetComponent(componentId)->GetEnergies(0); }
virtual const G4DataVector & GetEnergies(G4int componentId) const =0

Referenced by SaveData().

◆ GetLogData()

const G4DataVector & G4MicroElecCrossSectionDataSet::GetLogData ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 67 of file G4MicroElecCrossSectionDataSet.hh.

68 { return GetComponent(componentId)->GetLogData(0); }
virtual const G4DataVector & GetLogData(G4int componentId) const =0

◆ GetLogEnergies()

const G4DataVector & G4MicroElecCrossSectionDataSet::GetLogEnergies ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 64 of file G4MicroElecCrossSectionDataSet.hh.

65 { return GetComponent(componentId)->GetLogEnergies(0); }
virtual const G4DataVector & GetLogEnergies(G4int componentId) const =0

◆ LoadData()

G4bool G4MicroElecCrossSectionDataSet::LoadData ( const G4String argFileName)
overridevirtual

Implements G4VEMDataSet.

Definition at line 56 of file G4MicroElecCrossSectionDataSet.cc.

57{
58 CleanUpComponents();
59
60 G4String fullFileName(FullFileName(argFileName));
61 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
62
63 if (!in.is_open())
64 {
65 G4String message("Data file \"");
66 message+=fullFileName;
67 message+="\" not found";
68 G4Exception("G4MicroElecCrossSectionDataSet::LoadData","em0003",
69 FatalException,message);
70 return false;
71 }
72
73 std::vector<G4DataVector *> columns;
74 std::vector<G4DataVector *> log_columns;
75
76 std::stringstream *stream(new std::stringstream);
77 char c;
78 G4bool comment(false);
79 G4bool space(true);
80 G4bool first(true);
81
82 try
83 {
84 while (!in.eof())
85 {
86 in.get(c);
87
88 switch (c)
89 {
90 case '\r':
91 case '\n':
92 if (!first)
93 {
94 unsigned long i(0);
95 G4double value;
96
97 while (!stream->eof())
98 {
99 (*stream) >> value;
100
101 while (i>=columns.size())
102 {
103 columns.push_back(new G4DataVector);
104 log_columns.push_back(new G4DataVector);
105 }
106
107 columns[i]->push_back(value);
108 // N. A. Karakatsanis
109 // A condition is applied to check if negative or zero values are present in the dataset.
110 // If yes, then a near-zero value is applied to allow the computation of the logarithmic value
111 // If a value is zero, this simplification is acceptable
112 // If a value is negative, then it is not acceptable and the data of the particular column of
113 // logarithmic values should not be used by interpolation methods.
114 //
115 // Therefore, G4LogLogInterpolation and G4LinLogLogInterpolation should not be used if negative values are present.
116 // Instead, G4LinInterpolation is safe in every case
117 // SemiLogInterpolation is safe only if the energy columns are non-negative
118 // G4LinLogInterpolation is safe only if the cross section data columns are non-negative
119
120 if (value <=0.) value = 1e-300;
121 log_columns[i]->push_back(std::log10(value));
122
123 ++i;
124 }
125 delete stream;
126 stream=new std::stringstream;
127 }
128 first=true;
129 comment=false;
130 space=true;
131 break;
132
133 case '#':
134 comment=true;
135 break;
136 case '\t':
137 case ' ':
138 space = true;
139 break;
140 default:
141 if (comment) { break; }
142 if (space && (!first)) { (*stream) << ' '; }
143 first=false;
144 (*stream) << c;
145 space=false;
146 }
147 }
148 }
149 catch(const std::ios::failure &e)
150 {
151 // some implementations of STL could throw a "failture" exception
152 // when read wants read characters after end of file
153 }
154
155 delete stream;
156
157 std::size_t maxI(columns.size());
158
159 if (maxI<2)
160 {
161 G4String message("Data file \"");
162 message+=fullFileName;
163 message+="\" should have at least two columns";
164 G4Exception("G4MicroElecCrossSectionDataSet::LoadData","em0005",
165 FatalException,message);
166 return false;
167 }
168
169 std::size_t i(1);
170 while (i<maxI)
171 {
172 std::size_t maxJ(columns[i]->size());
173
174 if (maxJ!=columns[0]->size())
175 {
176 G4String message("Data file \"");
177 message+=fullFileName;
178 message+="\" has lines with a different number of columns";
179 G4Exception("G4MicroElecCrossSectionDataSet::LoadData","em0005",
180 FatalException,message);
181 return false;
182 }
183
184 std::size_t j(0);
185
186 G4DataVector *argEnergies=new G4DataVector;
187 G4DataVector *argData=new G4DataVector;
188 G4DataVector *argLogEnergies=new G4DataVector;
189 G4DataVector *argLogData=new G4DataVector;
190
191 while(j<maxJ)
192 {
193 argEnergies->push_back(columns[0]->operator[] (j)*GetUnitEnergies());
194 argData->push_back(columns[i]->operator[] (j)*GetUnitData());
195 argLogEnergies->push_back(log_columns[0]->operator[] (j) + std::log10(GetUnitEnergies()));
196 argLogData->push_back(log_columns[i]->operator[] (j) + std::log10(GetUnitData()));
197 j++;
198 }
199
200 AddComponent(new G4EMDataSet(G4int(i-1), argEnergies, argData, argLogEnergies, argLogData,
201 GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
202
203 ++i;
204 }
205
206 i=maxI;
207 while (i>0)
208 {
209 --i;
210 delete columns[i];
211 delete log_columns[i];
212 }
213
214 return true;
215}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void AddComponent(G4VEMDataSet *dataSet) override

Referenced by G4MicroElecElasticModel::Initialise(), and G4MicroElecInelasticModel::Initialise().

◆ LoadNonLogData()

G4bool G4MicroElecCrossSectionDataSet::LoadNonLogData ( const G4String argFileName)
overridevirtual

Implements G4VEMDataSet.

Definition at line 219 of file G4MicroElecCrossSectionDataSet.cc.

220{
221 CleanUpComponents();
222
223 G4String fullFileName(FullFileName(argFileName));
224 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
225
226 if (!in.is_open())
227 {
228 G4String message("Data file \"");
229 message+=fullFileName;
230 message+="\" not found";
231 G4Exception("G4MicroElecCrossSectionDataSet::LoadData","em0003",
232 FatalException,message);
233 return false;
234 }
235
236 std::vector<G4DataVector *> columns;
237
238 std::stringstream *stream(new std::stringstream);
239 char c;
240 G4bool comment(false);
241 G4bool space(true);
242 G4bool first(true);
243
244 try
245 {
246 while (!in.eof())
247 {
248 in.get(c);
249
250 switch (c)
251 {
252 case '\r':
253 case '\n':
254 if (!first)
255 {
256 unsigned long i(0);
257 G4double value;
258
259 while (!stream->eof())
260 {
261 (*stream) >> value;
262
263 while (i>=columns.size())
264 {
265 columns.push_back(new G4DataVector);
266 }
267
268 columns[i]->push_back(value);
269
270 i++;
271 }
272
273 delete stream;
274 stream=new std::stringstream;
275 }
276
277 first=true;
278 comment=false;
279 space=true;
280 break;
281
282 case '#':
283 comment=true;
284 break;
285
286 case '\t':
287 case ' ':
288 space = true;
289 break;
290
291 default:
292 if (comment) { break; }
293 if (space && (!first)) { (*stream) << ' '; }
294
295 first=false;
296 (*stream) << c;
297 space=false;
298 }
299 }
300 }
301 catch(const std::ios::failure &e)
302 {
303 // some implementations of STL could throw a "failture" exception
304 // when read wants read characters after end of file
305 }
306
307 delete stream;
308
309 std::size_t maxI(columns.size());
310
311 if (maxI<2)
312 {
313 G4String message("Data file \"");
314 message+=fullFileName;
315 message+="\" should have at least two columns";
316 G4Exception("G4MicroElecCrossSectionDataSet::LoadData","em0005",
317 FatalException,message);
318 return false;
319 }
320
321 std::size_t i(1);
322 while (i<maxI)
323 {
324 std::size_t maxJ(columns[i]->size());
325
326 if (maxJ!=columns[0]->size())
327 {
328 G4String message("Data file \"");
329 message+=fullFileName;
330 message+="\" has lines with a different number of columns.";
331 G4Exception("G4MicroElecCrossSectionDataSet::LoadData","em0005",
332 FatalException,message);
333 return false;
334 }
335
336 std::size_t j(0);
337
338 G4DataVector *argEnergies=new G4DataVector;
339 G4DataVector *argData=new G4DataVector;
340
341 while(j<maxJ)
342 {
343 argEnergies->push_back(columns[0]->operator[] (j)*GetUnitEnergies());
344 argData->push_back(columns[i]->operator[] (j)*GetUnitData());
345 j++;
346 }
347
348 AddComponent(new G4EMDataSet(G4int(i-1), argEnergies, argData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
349
350 i++;
351 }
352
353 i=maxI;
354 while (i>0)
355 {
356 i--;
357 delete columns[i];
358 }
359
360 return true;
361}

◆ NumberOfComponents()

size_t G4MicroElecCrossSectionDataSet::NumberOfComponents ( void  ) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 55 of file G4MicroElecCrossSectionDataSet.hh.

56 { return components.size(); }

Referenced by PrintData(), and SaveData().

◆ operator=()

G4MicroElecCrossSectionDataSet & G4MicroElecCrossSectionDataSet::operator= ( const G4MicroElecCrossSectionDataSet right)
delete

◆ PrintData()

void G4MicroElecCrossSectionDataSet::PrintData ( void  ) const
overridevirtual

Implements G4VEMDataSet.

Definition at line 470 of file G4MicroElecCrossSectionDataSet.cc.

471{
472 const std::size_t n(NumberOfComponents());
473
474 G4cout << "The data set has " << n << " components" << G4endl;
475 G4cout << G4endl;
476
477 G4int i(0);
478
479 while (i<(G4int)n)
480 {
481 G4cout << "--- Component " << i << " ---" << G4endl;
483 i++;
484 }
485}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
size_t NumberOfComponents(void) const override
virtual void PrintData(void) const =0

◆ RandomSelect()

G4double G4MicroElecCrossSectionDataSet::RandomSelect ( G4int  ) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 84 of file G4MicroElecCrossSectionDataSet.hh.

84{ return -1.; };

◆ SaveData()

G4bool G4MicroElecCrossSectionDataSet::SaveData ( const G4String argFileName) const
overridevirtual

Implements G4VEMDataSet.

Definition at line 365 of file G4MicroElecCrossSectionDataSet.cc.

366{
367 const std::size_t n(NumberOfComponents());
368 if (n==0)
369 {
370 G4Exception("G4MicroElecCrossSectionDataSet::SaveData","em0005",
371 FatalException,"Expected at least one component");
372
373 return false;
374 }
375
376 G4String fullFileName(FullFileName(argFileName));
377 std::ofstream out(fullFileName);
378
379 if (!out.is_open())
380 {
381 G4String message("Cannot open \"");
382 message+=fullFileName;
383 message+="\"";
384 G4Exception("G4MicroElecCrossSectionDataSet::SaveData","em0005",
385 FatalException,message);
386 return false;
387 }
388
389 G4DataVector::const_iterator iEnergies(GetComponent(0)->GetEnergies(0).begin());
390 G4DataVector::const_iterator iEnergiesEnd(GetComponent(0)->GetEnergies(0).end());
391 G4DataVector::const_iterator * iData(new G4DataVector::const_iterator[n]);
392
393 std::size_t k(n);
394
395 while (k>0)
396 {
397 k--;
398 iData[k]=GetComponent((G4int)k)->GetData(0).begin();
399 }
400
401 while (iEnergies!=iEnergiesEnd)
402 {
403 out.precision(10);
404 out.width(15);
405 out.setf(std::ofstream::left);
406 out << ((*iEnergies)/GetUnitEnergies());
407
408 k=0;
409
410 while (k<n)
411 {
412 out << ' ';
413 out.precision(10);
414 out.width(15);
415 out.setf(std::ofstream::left);
416 out << ((*(iData[k]))/GetUnitData());
417
418 iData[k]++;
419 k++;
420 }
421 out << std::endl;
422 iEnergies++;
423 }
424 delete[] iData;
425
426 return true;
427}
const G4DataVector & GetEnergies(G4int componentId) const override

◆ SetEnergiesData()

void G4MicroElecCrossSectionDataSet::SetEnergiesData ( G4DataVector x,
G4DataVector values,
G4int  componentId 
)
overridevirtual

Implements G4VEMDataSet.

Definition at line 489 of file G4MicroElecCrossSectionDataSet.cc.

492{
493 G4VEMDataSet * component(components[argComponentId]);
494
495 if (component)
496 {
497 component->SetEnergiesData(argEnergies, argData, 0);
498 return;
499 }
500
501 std::ostringstream message;
502 message << "Component " << argComponentId << " not found";
503
504 G4Exception("G4MicroElecCrossSectionDataSet::SetEnergiesData","em0005",
505 FatalException,message.str().c_str());
506
507}

◆ SetLogEnergiesData()

void G4MicroElecCrossSectionDataSet::SetLogEnergiesData ( G4DataVector x,
G4DataVector values,
G4DataVector log_x,
G4DataVector log_values,
G4int  componentId 
)
overridevirtual

Implements G4VEMDataSet.

Definition at line 511 of file G4MicroElecCrossSectionDataSet.cc.

516{
517 G4VEMDataSet * component(components[argComponentId]);
518
519 if (component)
520 {
521 component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
522 return;
523 }
524
525 std::ostringstream message;
526 message << "Component " << argComponentId << " not found";
527
528 G4Exception("G4MicroElecCrossSectionDataSet::SetLogEnergiesData","em0005",
529 FatalException,message.str().c_str());
530
531}

The documentation for this class was generated from the following files: