Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4MicroElecCrossSectionDataSet Class Reference

#include <G4MicroElecCrossSectionDataSet.hh>

Inheritance diagram for G4MicroElecCrossSectionDataSet:
G4VEMDataSet

Public Member Functions

void AddComponent (G4VEMDataSet *dataSet) override
 
G4double FindValue (G4double e, G4int componentId=0) const override
 
 G4MicroElecCrossSectionDataSet (const G4MicroElecCrossSectionDataSet &copy)=delete
 
 G4MicroElecCrossSectionDataSet (G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
 
const G4VEMDataSet * GetComponent (G4int componentId) const override
 
const G4DataVector & GetData (G4int componentId) const override
 
const G4DataVector & GetEnergies (G4int componentId) const override
 
const G4DataVector & GetLogData (G4int componentId) const override
 
const G4DataVector & GetLogEnergies (G4int componentId) const override
 
G4bool LoadData (const G4String &argFileName) override
 
G4bool LoadNonLogData (const G4String &argFileName) override
 
size_t NumberOfComponents (void) const override
 
G4MicroElecCrossSectionDataSet & operator= (const G4MicroElecCrossSectionDataSet &right)=delete
 
void PrintData (void) const override
 
G4double RandomSelect (G4int) const override
 
G4bool SaveData (const G4String &argFileName) 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
 
 ~G4MicroElecCrossSectionDataSet ()
 

Private Member Functions

void CleanUpComponents ()
 
G4String FullFileName (const G4String &argFileName) const
 
const G4VDataSetAlgorithm * GetAlgorithm () const
 
G4double GetUnitData () const
 
G4double GetUnitEnergies () const
 

Private Attributes

G4VDataSetAlgorithm * algorithm
 
std::vector< G4VEMDataSet * > components
 
G4double unitData
 
G4double unitEnergies
 

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.

◆ ~G4MicroElecCrossSectionDataSet()

G4MicroElecCrossSectionDataSet::~G4MicroElecCrossSectionDataSet ( )

Definition at line 47 of file G4MicroElecCrossSectionDataSet.cc.

References algorithm, and CleanUpComponents().

◆ 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); }
std::vector< G4VEMDataSet * > components

References components.

Referenced by LoadData(), and LoadNonLogData().

◆ CleanUpComponents()

void G4MicroElecCrossSectionDataSet::CleanUpComponents ( void  )
private

Definition at line 535 of file G4MicroElecCrossSectionDataSet.cc.

536{
537 while (!components.empty())
538 {
539 if (components.back()) delete components.back();
540 components.pop_back();
541 }
542}

References components.

Referenced by LoadData(), LoadNonLogData(), and ~G4MicroElecCrossSectionDataSet().

◆ 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

References components.

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

◆ FullFileName()

G4String G4MicroElecCrossSectionDataSet::FullFileName ( const G4String &  argFileName) const
private

Definition at line 431 of file G4MicroElecCrossSectionDataSet.cc.

432{
433 char* path = std::getenv("G4LEDATA");
434 if (!path)
435 {
436 G4Exception("G4MicroElecCrossSectionDataSet::FullFileName","em0006",
437 FatalException,"G4LEDATA environment variable not set.");
438
439 return "";
440 }
441
442 std::ostringstream fullFileName;
443
444 fullFileName << path << "/" << argFileName << ".dat";
445
446 return G4String(fullFileName.str().c_str());
447}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35

References FatalException, and G4Exception().

Referenced by LoadData(), LoadNonLogData(), and SaveData().

◆ GetAlgorithm()

const G4VDataSetAlgorithm * G4MicroElecCrossSectionDataSet::GetAlgorithm ( ) const
inlineprivate

Definition at line 93 of file G4MicroElecCrossSectionDataSet.hh.

93{ return algorithm; }

References algorithm.

Referenced by LoadData(), and LoadNonLogData().

◆ GetComponent()

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

◆ 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

References GetComponent(), and G4VEMDataSet::GetData().

◆ 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

References GetComponent(), and G4VEMDataSet::GetEnergies().

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

References GetComponent(), and G4VEMDataSet::GetLogData().

◆ 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

References GetComponent(), and G4VEMDataSet::GetLogEnergies().

◆ GetUnitData()

G4double G4MicroElecCrossSectionDataSet::GetUnitData ( ) const
inlineprivate

Definition at line 92 of file G4MicroElecCrossSectionDataSet.hh.

92{ return unitData; }

References unitData.

Referenced by LoadData(), LoadNonLogData(), and SaveData().

◆ GetUnitEnergies()

G4double G4MicroElecCrossSectionDataSet::GetUnitEnergies ( ) const
inlineprivate

Definition at line 91 of file G4MicroElecCrossSectionDataSet.hh.

91{ return unitEnergies; }

References unitEnergies.

Referenced by LoadData(), LoadNonLogData(), and SaveData().

◆ LoadData()

G4bool G4MicroElecCrossSectionDataSet::LoadData ( const G4String &  argFileName)
overridevirtual

Implements G4VEMDataSet.

Definition at line 56 of file G4MicroElecCrossSectionDataSet.cc.

57{
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::vector<G4DataVector *>::size_type 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::vector<G4DataVector*>::size_type i(1);
170 while (i<maxI)
171 {
172 G4DataVector::size_type 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 G4DataVector::size_type 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(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}
bool G4bool
Definition: G4Types.hh:86
const G4VDataSetAlgorithm * GetAlgorithm() const
G4String FullFileName(const G4String &argFileName) const
void AddComponent(G4VEMDataSet *dataSet) override

References AddComponent(), CleanUpComponents(), FatalException, FullFileName(), G4Exception(), GetAlgorithm(), GetUnitData(), and GetUnitEnergies().

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{
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::vector<G4DataVector *>::size_type 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::vector<G4DataVector*>::size_type i(1);
322 while (i<maxI)
323 {
324 G4DataVector::size_type 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 G4DataVector::size_type 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(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}

References AddComponent(), CleanUpComponents(), FatalException, FullFileName(), G4Exception(), GetAlgorithm(), GetUnitData(), and GetUnitEnergies().

◆ NumberOfComponents()

size_t G4MicroElecCrossSectionDataSet::NumberOfComponents ( void  ) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 55 of file G4MicroElecCrossSectionDataSet.hh.

56 { return components.size(); }

References components.

Referenced by PrintData(), G4MicroElecInelasticModel::RandomSelect(), 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 size_t n(NumberOfComponents());
473
474 G4cout << "The data set has " << n << " components" << G4endl;
475 G4cout << G4endl;
476
477 size_t i(0);
478
479 while (i<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

References G4cout, G4endl, GetComponent(), CLHEP::detail::n, NumberOfComponents(), and G4VEMDataSet::PrintData().

◆ 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 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 size_t k(n);
394
395 while (k>0)
396 {
397 k--;
398 iData[k]=GetComponent(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

References FatalException, FullFileName(), G4Exception(), GetComponent(), G4VEMDataSet::GetData(), GetEnergies(), GetUnitData(), GetUnitEnergies(), CLHEP::detail::n, and NumberOfComponents().

◆ 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}

References components, FatalException, G4Exception(), and G4VEMDataSet::SetEnergiesData().

◆ 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}

References components, FatalException, G4Exception(), and G4VEMDataSet::SetLogEnergiesData().

Field Documentation

◆ algorithm

G4VDataSetAlgorithm* G4MicroElecCrossSectionDataSet::algorithm
private

◆ components

std::vector<G4VEMDataSet*> G4MicroElecCrossSectionDataSet::components
private

◆ unitData

G4double G4MicroElecCrossSectionDataSet::unitData
private

Definition at line 100 of file G4MicroElecCrossSectionDataSet.hh.

Referenced by GetUnitData().

◆ unitEnergies

G4double G4MicroElecCrossSectionDataSet::unitEnergies
private

Definition at line 99 of file G4MicroElecCrossSectionDataSet.hh.

Referenced by GetUnitEnergies().


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