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

#include <G4MicroElecCrossSectionDataSet_new.hh>

+ Inheritance diagram for G4MicroElecCrossSectionDataSet_new:

Public Member Functions

 G4MicroElecCrossSectionDataSet_new (G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
 
 ~G4MicroElecCrossSectionDataSet_new () override
 
G4double FindValue (G4double e, G4int componentId=0) const override
 
G4double FindShellValue (G4double argEnergy, G4int shell) const
 
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
 
- 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
 

Detailed Description

Definition at line 36 of file G4MicroElecCrossSectionDataSet_new.hh.

Constructor & Destructor Documentation

◆ G4MicroElecCrossSectionDataSet_new()

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

Definition at line 40 of file G4MicroElecCrossSectionDataSet_new.cc.

43 :
44 algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
45{
46 z = 0;
47}

Referenced by G4MicroElecCrossSectionDataSet_new().

◆ ~G4MicroElecCrossSectionDataSet_new()

G4MicroElecCrossSectionDataSet_new::~G4MicroElecCrossSectionDataSet_new ( )
override

Definition at line 51 of file G4MicroElecCrossSectionDataSet_new.cc.

52{
53 CleanUpComponents();
54
55 if (algorithm)
56 delete algorithm;
57}

Member Function Documentation

◆ AddComponent()

void G4MicroElecCrossSectionDataSet_new::AddComponent ( G4VEMDataSet dataSet)
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 49 of file G4MicroElecCrossSectionDataSet_new.hh.

50 { components.push_back(dataSet); }

Referenced by LoadData(), and LoadNonLogData().

◆ FindShellValue()

G4double G4MicroElecCrossSectionDataSet_new::FindShellValue ( G4double  argEnergy,
G4int  shell 
) const

Definition at line 509 of file G4MicroElecCrossSectionDataSet_new.cc.

510{
511 return components.at(shell)->FindValue(argEnergy);
512}

Referenced by G4MicroElecInelasticModel_new::CrossSectionPerVolume().

◆ FindValue()

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

Implements G4VEMDataSet.

Definition at line 490 of file G4MicroElecCrossSectionDataSet_new.cc.

491{
492 // Returns the sum over the shells corresponding to e
493 G4double value = 0.;
494
495 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
496 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
497
498 while (i!=end)
499 {
500 value+=(*i)->FindValue(argEnergy);
501 i++;
502 }
503
504 return value;
505}
double G4double
Definition: G4Types.hh:83

Referenced by G4MicroElecElasticModel_new::CrossSectionPerVolume(), and G4MicroElecInelasticModel_new::CrossSectionPerVolume().

◆ GetComponent()

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

Implements G4VEMDataSet.

Definition at line 47 of file G4MicroElecCrossSectionDataSet_new.hh.

48 { return components[componentId]; }

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

◆ GetData()

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

Implements G4VEMDataSet.

Definition at line 55 of file G4MicroElecCrossSectionDataSet_new.hh.

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

◆ GetEnergies()

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

Implements G4VEMDataSet.

Definition at line 53 of file G4MicroElecCrossSectionDataSet_new.hh.

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

Referenced by SaveData().

◆ GetLogData()

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

Implements G4VEMDataSet.

Definition at line 59 of file G4MicroElecCrossSectionDataSet_new.hh.

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

◆ GetLogEnergies()

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

Implements G4VEMDataSet.

Definition at line 57 of file G4MicroElecCrossSectionDataSet_new.hh.

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

◆ LoadData()

G4bool G4MicroElecCrossSectionDataSet_new::LoadData ( const G4String argFileName)
overridevirtual

Implements G4VEMDataSet.

Definition at line 62 of file G4MicroElecCrossSectionDataSet_new.cc.

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

Referenced by G4MicroElecElasticModel_new::Initialise(), and G4MicroElecInelasticModel_new::Initialise().

◆ LoadNonLogData()

G4bool G4MicroElecCrossSectionDataSet_new::LoadNonLogData ( const G4String argFileName)
overridevirtual

Implements G4VEMDataSet.

Definition at line 244 of file G4MicroElecCrossSectionDataSet_new.cc.

245{
246 CleanUpComponents();
247
248 G4String fullFileName(FullFileName(argFileName));
249 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
250
251 if (!in.is_open())
252 {
253 G4String message("Data file \"");
254 message+=fullFileName;
255 message+="\" not found";
256 G4Exception("G4MicroElecCrossSectionDataSet_new::LoadData","em0003",
257 FatalException,message);
258 return false;
259 }
260
261 std::vector<G4DataVector *> columns;
262
263 std::stringstream *stream(new std::stringstream);
264 char c;
265 G4bool comment(false);
266 G4bool space(true);
267 G4bool first(true);
268
269 try
270 {
271 while (!in.eof())
272 {
273 in.get(c);
274
275 switch (c)
276 {
277 case '\r':
278 case '\n':
279 if (!first)
280 {
281 unsigned long i(0);
282 G4double value;
283
284 while (!stream->eof())
285 {
286 (*stream) >> value;
287
288 while (i>=columns.size())
289 {
290 columns.push_back(new G4DataVector);
291 }
292
293 columns[i]->push_back(value);
294
295 i++;
296 }
297
298 delete stream;
299 stream=new std::stringstream;
300 }
301
302 first=true;
303 comment=false;
304 space=true;
305 break;
306
307 case '#':
308 comment=true;
309 break;
310
311 default:
312 if( c=='\t')
313 c=' ';
314 if( c==' ' && space)
315 break;
316
317 if (comment)
318 break;
319
320 if (c==' ')
321 space=true;
322 else
323 {
324 if (space && (!first))
325 (*stream) << ' ';
326
327 first=false;
328 (*stream) << c;
329 space=false;
330 }
331 }
332 }
333 }
334 catch(const std::ios::failure &e)
335 {
336 // some implementations of STL could throw a "failture" exception
337 // when read wants read characters after end of file
338 }
339
340 delete stream;
341
342 std::vector<G4DataVector *>::size_type maxI(columns.size());
343
344 if (maxI<2)
345 {
346 G4String message("Data file \"");
347 message+=fullFileName;
348 message+="\" should have at least two columns";
349 G4Exception("G4MicroElecCrossSectionDataSet_new::LoadData","em0005",
350 FatalException,message);
351 return false;
352 }
353
354 std::vector<G4DataVector*>::size_type i(1);
355 while (i<maxI)
356 {
357 G4DataVector::size_type maxJ(columns[i]->size());
358
359
360 if (maxJ!=columns[0]->size())
361 {
362 G4String message("Data file \"");
363 message+=fullFileName;
364 message+="\" has lines with a different number of columns.";
365 G4Exception("G4MicroElecCrossSectionDataSet_new::LoadData","em0005",
366 FatalException,message);
367 return false;
368 }
369
370 G4DataVector::size_type j(0);
371
372 G4DataVector *argEnergies=new G4DataVector;
373 G4DataVector *argData=new G4DataVector;
374
375 while(j<maxJ)
376 {
377 argEnergies->push_back(columns[0]->operator[] (j)*GetUnitEnergies());
378 argData->push_back(columns[i]->operator[] (j)*GetUnitData());
379 j++;
380 }
381
382 AddComponent(new G4EMDataSet(i-1, argEnergies, argData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
383
384 i++;
385 }
386
387 i=maxI;
388 while (i>0)
389 {
390 i--;
391 delete columns[i];
392 }
393
394 return true;
395}

◆ NumberOfComponents()

size_t G4MicroElecCrossSectionDataSet_new::NumberOfComponents ( void  ) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 51 of file G4MicroElecCrossSectionDataSet_new.hh.

52 { return components.size(); }

Referenced by PrintData(), and SaveData().

◆ PrintData()

void G4MicroElecCrossSectionDataSet_new::PrintData ( void  ) const
overridevirtual

Implements G4VEMDataSet.

Definition at line 517 of file G4MicroElecCrossSectionDataSet_new.cc.

518{
519 const size_t n(NumberOfComponents());
520
521 G4cout << "The data set has " << n << " components" << G4endl;
522 G4cout << G4endl;
523
524 size_t i(0);
525
526 while (i<n)
527 {
528 G4cout << "--- Component " << i << " ---" << G4endl;
530 i++;
531 }
532}
virtual void PrintData(void) const =0

◆ RandomSelect()

G4double G4MicroElecCrossSectionDataSet_new::RandomSelect ( G4int  ) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 70 of file G4MicroElecCrossSectionDataSet_new.hh.

71 { return -1.; };

◆ SaveData()

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

Implements G4VEMDataSet.

Definition at line 400 of file G4MicroElecCrossSectionDataSet_new.cc.

401{
402 const size_t n(NumberOfComponents());
403
404 if (n==0)
405 {
406 G4Exception("G4MicroElecCrossSectionDataSet_new::SaveData","em0005",
407 FatalException,"Expected at least one component");
408
409 return false;
410 }
411
412 G4String fullFileName(FullFileName(argFileName));
413 std::ofstream out(fullFileName);
414
415 if (!out.is_open())
416 {
417 G4String message("Cannot open \"");
418 message+=fullFileName;
419 message+="\"";
420 G4Exception("G4MicroElecCrossSectionDataSet_new::SaveData","em0005",
421 FatalException,message);
422 return false;
423 }
424
425 G4DataVector::const_iterator iEnergies(GetComponent(0)->GetEnergies(0).begin());
426 G4DataVector::const_iterator iEnergiesEnd(GetComponent(0)->GetEnergies(0).end());
427 G4DataVector::const_iterator * iData(new G4DataVector::const_iterator[n]);
428
429 size_t k(n);
430
431 while (k>0)
432 {
433 k--;
434 iData[k]=GetComponent(k)->GetData(0).begin();
435 }
436
437 while (iEnergies!=iEnergiesEnd)
438 {
439 out.precision(10);
440 out.width(15);
441 out.setf(std::ofstream::left);
442 out << ((*iEnergies)/GetUnitEnergies());
443
444 k=0;
445
446 while (k<n)
447 {
448 out << ' ';
449 out.precision(10);
450 out.width(15);
451 out.setf(std::ofstream::left);
452 out << ((*(iData[k]))/GetUnitData());
453
454 iData[k]++;
455 k++;
456 }
457
458 out << std::endl;
459
460 iEnergies++;
461 }
462
463 delete[] iData;
464
465 return true;
466}
const G4DataVector & GetEnergies(G4int componentId) const override

◆ SetEnergiesData()

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

Implements G4VEMDataSet.

Definition at line 537 of file G4MicroElecCrossSectionDataSet_new.cc.

540{
541 G4VEMDataSet * component(components[argComponentId]);
542
543 if (component)
544 {
545 component->SetEnergiesData(argEnergies, argData, 0);
546 return;
547 }
548
549 std::ostringstream message;
550 message << "Component " << argComponentId << " not found";
551
552 G4Exception("G4MicroElecCrossSectionDataSet_new::SetEnergiesData","em0005",
553 FatalException,message.str().c_str());
554
555}

◆ SetLogEnergiesData()

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

Implements G4VEMDataSet.

Definition at line 559 of file G4MicroElecCrossSectionDataSet_new.cc.

564{
565 G4VEMDataSet * component(components[argComponentId]);
566
567 if (component)
568 {
569 component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
570 return;
571 }
572
573 std::ostringstream message;
574 message << "Component " << argComponentId << " not found";
575
576 G4Exception("G4MicroElecCrossSectionDataSet_new::SetLogEnergiesData","em0005",
577 FatalException,message.str().c_str());
578
579}

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