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

#include <G4CrossSectionDataSet.hh>

Inheritance diagram for G4CrossSectionDataSet:
G4VEMDataSet

Public Member Functions

virtual void AddComponent (G4VEMDataSet *dataSet)
 
virtual G4double FindValue (G4double e, G4int componentId=0) const
 
 G4CrossSectionDataSet (G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
 
virtual const G4VEMDataSet * GetComponent (G4int componentId) const
 
virtual const G4DataVector & GetData (G4int componentId) const
 
virtual const G4DataVector & GetEnergies (G4int componentId) const
 
virtual const G4DataVector & GetLogData (G4int componentId) const
 
virtual const G4DataVector & GetLogEnergies (G4int componentId) const
 
virtual G4bool LoadData (const G4String &argFileName)
 
virtual G4bool LoadNonLogData (const G4String &argFileName)
 
virtual size_t NumberOfComponents (void) const
 
virtual void PrintData (void) const
 
virtual G4double RandomSelect (G4int) const
 
virtual G4bool SaveData (const G4String &argFileName) const
 
virtual void SetEnergiesData (G4DataVector *x, G4DataVector *values, G4int componentId)
 
virtual void SetLogEnergiesData (G4DataVector *x, G4DataVector *values, G4DataVector *log_x, G4DataVector *log_values, G4int componentId)
 
virtual ~G4CrossSectionDataSet ()
 

Private Member Functions

void CleanUpComponents (void)
 
G4String FullFileName (const G4String &argFileName) const
 
 G4CrossSectionDataSet ()
 
 G4CrossSectionDataSet (const G4CrossSectionDataSet &copy)=delete
 
const G4VDataSetAlgorithm * GetAlgorithm () const
 
G4double GetUnitData () const
 
G4double GetUnitEnergies () const
 
G4CrossSectionDataSet & operator= (const G4CrossSectionDataSet &right)=delete
 

Private Attributes

G4VDataSetAlgorithm * algorithm
 
std::vector< G4VEMDataSet * > components
 
G4double unitData
 
G4double unitEnergies
 
G4int z = 0
 

Detailed Description

Definition at line 52 of file G4CrossSectionDataSet.hh.

Constructor & Destructor Documentation

◆ G4CrossSectionDataSet() [1/3]

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

Definition at line 65 of file G4CrossSectionDataSet.cc.

67 :
68 algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
69{;}
G4VDataSetAlgorithm * algorithm

◆ ~G4CrossSectionDataSet()

G4CrossSectionDataSet::~G4CrossSectionDataSet ( )
virtual

Definition at line 73 of file G4CrossSectionDataSet.cc.

74{
76
77 if (algorithm)
78 delete algorithm;
79}

References algorithm, and CleanUpComponents().

◆ G4CrossSectionDataSet() [2/3]

G4CrossSectionDataSet::G4CrossSectionDataSet ( )
explicitprivate

◆ G4CrossSectionDataSet() [3/3]

G4CrossSectionDataSet::G4CrossSectionDataSet ( const G4CrossSectionDataSet &  copy)
privatedelete

Member Function Documentation

◆ AddComponent()

virtual void G4CrossSectionDataSet::AddComponent ( G4VEMDataSet *  dataSet)
inlinevirtual

Implements G4VEMDataSet.

Definition at line 69 of file G4CrossSectionDataSet.hh.

70 { components.push_back(dataSet); }
std::vector< G4VEMDataSet * > components

References components.

Referenced by LoadData(), and LoadNonLogData().

◆ CleanUpComponents()

void G4CrossSectionDataSet::CleanUpComponents ( void  )
private

Definition at line 567 of file G4CrossSectionDataSet.cc.

568{
569 while (!components.empty())
570 {
571 if (components.back()) delete components.back();
572 components.pop_back();
573 }
574}

References components.

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

◆ FindValue()

G4double G4CrossSectionDataSet::FindValue ( G4double  e,
G4int  componentId = 0 
) const
virtual

Implements G4VEMDataSet.

Definition at line 485 of file G4CrossSectionDataSet.cc.

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

References components.

Referenced by G4ecpssrBaseKxsModel::CalculateCrossSection().

◆ FullFileName()

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

Definition at line 466 of file G4CrossSectionDataSet.cc.

467{
468 char* path = std::getenv("G4LEDATA");
469 if (!path)
470 {
471 G4Exception("G4CrossSectionDataSet::FullFileName",
472 "em0006",FatalException,"G4LEDATA environment variable not set");
473 return "NULL";
474 }
475
476 std::ostringstream fullFileName;
477
478 fullFileName << path << "/" << argFileName << ".dat";
479
480 return G4String(fullFileName.str().c_str());
481}
@ 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 * G4CrossSectionDataSet::GetAlgorithm ( ) const
inlineprivate

Definition at line 113 of file G4CrossSectionDataSet.hh.

113{ return algorithm; }

References algorithm.

Referenced by LoadData(), and LoadNonLogData().

◆ GetComponent()

virtual const G4VEMDataSet * G4CrossSectionDataSet::GetComponent ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 66 of file G4CrossSectionDataSet.hh.

67 { return components[componentId]; }

References components.

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

◆ GetData()

virtual const G4DataVector & G4CrossSectionDataSet::GetData ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 78 of file G4CrossSectionDataSet.hh.

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

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

◆ GetEnergies()

virtual const G4DataVector & G4CrossSectionDataSet::GetEnergies ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 75 of file G4CrossSectionDataSet.hh.

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

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

Referenced by SaveData().

◆ GetLogData()

virtual const G4DataVector & G4CrossSectionDataSet::GetLogData ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 84 of file G4CrossSectionDataSet.hh.

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

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

◆ GetLogEnergies()

virtual const G4DataVector & G4CrossSectionDataSet::GetLogEnergies ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 81 of file G4CrossSectionDataSet.hh.

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

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

◆ GetUnitData()

G4double G4CrossSectionDataSet::GetUnitData ( ) const
inlineprivate

Definition at line 112 of file G4CrossSectionDataSet.hh.

112{ return unitData; }

References unitData.

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

◆ GetUnitEnergies()

G4double G4CrossSectionDataSet::GetUnitEnergies ( ) const
inlineprivate

Definition at line 111 of file G4CrossSectionDataSet.hh.

111{ return unitEnergies; }

References unitEnergies.

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

◆ LoadData()

G4bool G4CrossSectionDataSet::LoadData ( const G4String &  argFileName)
virtual

Implements G4VEMDataSet.

Definition at line 83 of file G4CrossSectionDataSet.cc.

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

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

Referenced by G4ecpssrBaseKxsModel::G4ecpssrBaseKxsModel().

◆ LoadNonLogData()

G4bool G4CrossSectionDataSet::LoadNonLogData ( const G4String &  argFileName)
virtual

Implements G4VEMDataSet.

Definition at line 251 of file G4CrossSectionDataSet.cc.

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

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

◆ NumberOfComponents()

virtual size_t G4CrossSectionDataSet::NumberOfComponents ( void  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 72 of file G4CrossSectionDataSet.hh.

73 { return components.size(); }

References components.

Referenced by PrintData(), and SaveData().

◆ operator=()

G4CrossSectionDataSet & G4CrossSectionDataSet::operator= ( const G4CrossSectionDataSet &  right)
privatedelete

◆ PrintData()

void G4CrossSectionDataSet::PrintData ( void  ) const
virtual

Implements G4VEMDataSet.

Definition at line 504 of file G4CrossSectionDataSet.cc.

505{
506 const size_t n(NumberOfComponents());
507
508 G4cout << "The data set has " << n << " components" << G4endl;
509 G4cout << G4endl;
510
511 size_t i(0);
512
513 while (i<n)
514 {
515 G4cout << "--- Component " << i << " ---" << G4endl;
517 i++;
518 }
519}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
virtual size_t NumberOfComponents(void) const
virtual void PrintData(void) const =0

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

◆ RandomSelect()

virtual G4double G4CrossSectionDataSet::RandomSelect ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 100 of file G4CrossSectionDataSet.hh.

100{ return -1.; };

◆ SaveData()

G4bool G4CrossSectionDataSet::SaveData ( const G4String &  argFileName) const
virtual

Implements G4VEMDataSet.

Definition at line 397 of file G4CrossSectionDataSet.cc.

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

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

◆ SetEnergiesData()

void G4CrossSectionDataSet::SetEnergiesData ( G4DataVector *  x,
G4DataVector *  values,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 523 of file G4CrossSectionDataSet.cc.

526{
527 G4VEMDataSet * component(components[argComponentId]);
528
529 if (component)
530 {
531 component->SetEnergiesData(argEnergies, argData, 0);
532 return;
533 }
534
535 std::ostringstream message;
536 message << "component " << argComponentId << " not found";
537
538 G4Exception("G4CrossSectionDataSet::SetEnergiesData",
539 "em0005",FatalException,message.str().c_str());
540}

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

◆ SetLogEnergiesData()

void G4CrossSectionDataSet::SetLogEnergiesData ( G4DataVector *  x,
G4DataVector *  values,
G4DataVector *  log_x,
G4DataVector *  log_values,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 544 of file G4CrossSectionDataSet.cc.

549{
550 G4VEMDataSet * component(components[argComponentId]);
551
552 if (component)
553 {
554 component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
555 return;
556 }
557
558 std::ostringstream message;
559 message << "component " << argComponentId << " not found";
560
561 G4Exception("G4CrossSectionDataSet::SetLogEnergiesData",
562 "em0005",FatalException,message.str().c_str());
563}

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

Field Documentation

◆ algorithm

G4VDataSetAlgorithm* G4CrossSectionDataSet::algorithm
private

Definition at line 119 of file G4CrossSectionDataSet.hh.

Referenced by GetAlgorithm(), and ~G4CrossSectionDataSet().

◆ components

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

◆ unitData

G4double G4CrossSectionDataSet::unitData
private

Definition at line 122 of file G4CrossSectionDataSet.hh.

Referenced by GetUnitData().

◆ unitEnergies

G4double G4CrossSectionDataSet::unitEnergies
private

Definition at line 121 of file G4CrossSectionDataSet.hh.

Referenced by GetUnitEnergies().

◆ z

G4int G4CrossSectionDataSet::z = 0
private

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