Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4DNACrossSectionDataSet Class Reference

#include <G4DNACrossSectionDataSet.hh>

Inheritance diagram for G4DNACrossSectionDataSet:
Collaboration diagram for G4DNACrossSectionDataSet:

Public Member Functions

 G4DNACrossSectionDataSet (G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
 
virtual ~G4DNACrossSectionDataSet ()
 
virtual G4double FindValue (G4double e, G4int componentId=0) const
 
virtual void PrintData (void) const
 
virtual const G4VEMDataSetGetComponent (G4int componentId) const
 
virtual void AddComponent (G4VEMDataSet *dataSet)
 
virtual size_t NumberOfComponents (void) const
 
virtual const G4DataVectorGetEnergies (G4int componentId) const
 
virtual const G4DataVectorGetData (G4int componentId) const
 
virtual const G4DataVectorGetLogEnergies (G4int componentId) const
 
virtual const G4DataVectorGetLogData (G4int componentId) 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 G4bool LoadData (const G4String &argFileName)
 
virtual G4bool LoadNonLogData (const G4String &argFileName)
 
virtual G4bool SaveData (const G4String &argFileName) const
 
virtual G4double RandomSelect (G4int) const
 
- Public Member Functions inherited from G4VEMDataSet
 G4VEMDataSet ()
 
virtual ~G4VEMDataSet ()
 

Detailed Description

Definition at line 55 of file G4DNACrossSectionDataSet.hh.

Constructor & Destructor Documentation

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

Definition at line 65 of file G4DNACrossSectionDataSet.cc.

68  :
69  algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
70 {
71  z = 0;
72 
73 }

Here is the call graph for this function:

Here is the caller graph for this function:

G4DNACrossSectionDataSet::~G4DNACrossSectionDataSet ( )
virtual

Definition at line 76 of file G4DNACrossSectionDataSet.cc.

77 {
78  CleanUpComponents();
79 
80  if (algorithm)
81  delete algorithm;
82 }

Member Function Documentation

virtual void G4DNACrossSectionDataSet::AddComponent ( G4VEMDataSet dataSet)
inlinevirtual

Implements G4VEMDataSet.

Definition at line 72 of file G4DNACrossSectionDataSet.hh.

73  { components.push_back(dataSet); }

Here is the caller graph for this function:

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

Implements G4VEMDataSet.

Definition at line 484 of file G4DNACrossSectionDataSet.cc.

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

Here is the caller graph for this function:

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

Implements G4VEMDataSet.

Definition at line 69 of file G4DNACrossSectionDataSet.hh.

70  { return components[componentId]; }

Here is the caller graph for this function:

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

Implements G4VEMDataSet.

Definition at line 81 of file G4DNACrossSectionDataSet.hh.

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

Here is the call graph for this function:

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

Implements G4VEMDataSet.

Definition at line 78 of file G4DNACrossSectionDataSet.hh.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements G4VEMDataSet.

Definition at line 87 of file G4DNACrossSectionDataSet.hh.

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

Here is the call graph for this function:

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

Implements G4VEMDataSet.

Definition at line 84 of file G4DNACrossSectionDataSet.hh.

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

Here is the call graph for this function:

G4bool G4DNACrossSectionDataSet::LoadData ( const G4String argFileName)
virtual

Implements G4VEMDataSet.

Definition at line 84 of file G4DNACrossSectionDataSet.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4DNACrossSectionDataSet::LoadNonLogData ( const G4String argFileName)
virtual

Implements G4VEMDataSet.

Definition at line 251 of file G4DNACrossSectionDataSet.cc.

252 {
253  CleanUpComponents();
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("G4DNACrossSectionDataSet::LoadData","em0003",
264  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("G4DNACrossSectionDataSet::LoadData","em0005",
349  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("G4DNACrossSectionDataSet::LoadData","em0005",
364  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 }
const XML_Char int const XML_Char * value
Definition: expat.h:331
bool G4bool
Definition: G4Types.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76
tuple c
Definition: test.py:13
virtual void AddComponent(G4VEMDataSet *dataSet)

Here is the call graph for this function:

virtual size_t G4DNACrossSectionDataSet::NumberOfComponents ( void  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 75 of file G4DNACrossSectionDataSet.hh.

76  { return components.size(); }

Here is the caller graph for this function:

void G4DNACrossSectionDataSet::PrintData ( void  ) const
virtual

Implements G4VEMDataSet.

Definition at line 502 of file G4DNACrossSectionDataSet.cc.

503 {
504  const size_t n(NumberOfComponents());
505 
506  G4cout << "The data set has " << n << " components" << G4endl;
507  G4cout << G4endl;
508 
509  size_t i(0);
510 
511  while (i<n)
512  {
513  G4cout << "--- Component " << i << " ---" << G4endl;
514  GetComponent(i)->PrintData();
515  i++;
516  }
517 }
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
G4GLOB_DLL std::ostream G4cout
const G4int n
virtual size_t NumberOfComponents(void) const
virtual void PrintData(void) const =0
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

virtual G4double G4DNACrossSectionDataSet::RandomSelect ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 103 of file G4DNACrossSectionDataSet.hh.

103 { return -1.; };
G4bool G4DNACrossSectionDataSet::SaveData ( const G4String argFileName) const
virtual

Implements G4VEMDataSet.

Definition at line 396 of file G4DNACrossSectionDataSet.cc.

397 {
398  const size_t n(NumberOfComponents());
399 
400  if (n==0)
401  {
402  G4Exception("G4DNACrossSectionDataSet::SaveData","em0005",
403  FatalException,"Expected at least one component");
404 
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("G4DNACrossSectionDataSet::SaveData","em0005",
417  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 G4VEMDataSet * GetComponent(G4int componentId) const
virtual const G4DataVector & GetData(G4int componentId) const =0
const G4int n
virtual size_t NumberOfComponents(void) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual const G4DataVector & GetEnergies(G4int componentId) const

Here is the call graph for this function:

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

Implements G4VEMDataSet.

Definition at line 520 of file G4DNACrossSectionDataSet.cc.

523 {
524  G4VEMDataSet * component(components[argComponentId]);
525 
526  if (component)
527  {
528  component->SetEnergiesData(argEnergies, argData, 0);
529  return;
530  }
531 
532  std::ostringstream message;
533  message << "Component " << argComponentId << " not found";
534 
535  G4Exception("G4DNACrossSectionDataSet::SetEnergiesData","em0005",
536  FatalException,message.str().c_str());
537 
538 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

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

Implements G4VEMDataSet.

Definition at line 541 of file G4DNACrossSectionDataSet.cc.

546 {
547  G4VEMDataSet * component(components[argComponentId]);
548 
549  if (component)
550  {
551  component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
552  return;
553  }
554 
555  std::ostringstream message;
556  message << "Component " << argComponentId << " not found";
557 
558  G4Exception("G4DNACrossSectionDataSet::SetLogEnergiesData","em0005",
559  FatalException,message.str().c_str());
560 
561 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:


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