Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 500 of file G4DNACrossSectionDataSet.cc.

501 {
502  // Returns the sum over the shells corresponding to e
503  G4double value = 0.;
504 
505  std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
506  std::vector<G4VEMDataSet *>::const_iterator end(components.end());
507 
508  while (i!=end)
509  {
510  value+=(*i)->FindValue(argEnergy);
511  i++;
512  }
513 
514  return value;
515 }
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  c=' ';
170  case ' ':
171  if (space)
172  break;
173  default:
174  if (comment)
175  break;
176 
177  if (c==' ')
178  space=true;
179  else
180  {
181  if (space && (!first))
182  (*stream) << ' ';
183 
184  first=false;
185  (*stream) << c;
186  space=false;
187  }
188  }
189  }
190  }
191  catch(const std::ios::failure &e)
192  {
193  // some implementations of STL could throw a "failture" exception
194  // when read wants read characters after end of file
195  }
196 
197  delete stream;
198 
199  std::vector<G4DataVector *>::size_type maxI(columns.size());
200 
201  if (maxI<2)
202  {
203  G4String message("Data file \"");
204  message+=fullFileName;
205  message+="\" should have at least two columns";
206  G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
207  FatalException,message);
208  return false;
209  }
210 
211  std::vector<G4DataVector*>::size_type i(1);
212  while (i<maxI)
213  {
214  G4DataVector::size_type maxJ(columns[i]->size());
215 
216  if (maxJ!=columns[0]->size())
217  {
218  G4String message("Data file \"");
219  message+=fullFileName;
220  message+="\" has lines with a different number of columns";
221  G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
222  FatalException,message);
223  return false;
224  }
225 
226  G4DataVector::size_type j(0);
227 
228  G4DataVector *argEnergies=new G4DataVector;
229  G4DataVector *argData=new G4DataVector;
230  G4DataVector *argLogEnergies=new G4DataVector;
231  G4DataVector *argLogData=new G4DataVector;
232 
233  while(j<maxJ)
234  {
235  argEnergies->push_back(columns[0]->operator[] (j)*GetUnitEnergies());
236  argData->push_back(columns[i]->operator[] (j)*GetUnitData());
237  argLogEnergies->push_back(log_columns[0]->operator[] (j) + std::log10(GetUnitEnergies()));
238  argLogData->push_back(log_columns[i]->operator[] (j) + std::log10(GetUnitData()));
239  j++;
240  }
241 
242  AddComponent(new G4EMDataSet(i-1, argEnergies, argData, argLogEnergies, argLogData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
243 
244  i++;
245  }
246 
247  i=maxI;
248  while (i>0)
249  {
250  i--;
251  delete columns[i];
252  delete log_columns[i];
253  }
254 
255  return true;
256 }
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
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 259 of file G4DNACrossSectionDataSet.cc.

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

519 {
520  const size_t n(NumberOfComponents());
521 
522  G4cout << "The data set has " << n << " components" << G4endl;
523  G4cout << G4endl;
524 
525  size_t i(0);
526 
527  while (i<n)
528  {
529  G4cout << "--- Component " << i << " ---" << G4endl;
530  GetComponent(i)->PrintData();
531  i++;
532  }
533 }
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
G4GLOB_DLL std::ostream G4cout
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 412 of file G4DNACrossSectionDataSet.cc.

413 {
414  const size_t n(NumberOfComponents());
415 
416  if (n==0)
417  {
418  G4Exception("G4DNACrossSectionDataSet::SaveData","em0005",
419  FatalException,"Expected at least one component");
420 
421  return false;
422  }
423 
424  G4String fullFileName(FullFileName(argFileName));
425  std::ofstream out(fullFileName);
426 
427  if (!out.is_open())
428  {
429  G4String message("Cannot open \"");
430  message+=fullFileName;
431  message+="\"";
432  G4Exception("G4DNACrossSectionDataSet::SaveData","em0005",
433  FatalException,message);
434  return false;
435  }
436 
437  G4DataVector::const_iterator iEnergies(GetComponent(0)->GetEnergies(0).begin());
438  G4DataVector::const_iterator iEnergiesEnd(GetComponent(0)->GetEnergies(0).end());
439  G4DataVector::const_iterator * iData(new G4DataVector::const_iterator[n]);
440 
441  size_t k(n);
442 
443  while (k>0)
444  {
445  k--;
446  iData[k]=GetComponent(k)->GetData(0).begin();
447  }
448 
449  while (iEnergies!=iEnergiesEnd)
450  {
451  out.precision(10);
452  out.width(15);
453  out.setf(std::ofstream::left);
454  out << ((*iEnergies)/GetUnitEnergies());
455 
456  k=0;
457 
458  while (k<n)
459  {
460  out << ' ';
461  out.precision(10);
462  out.width(15);
463  out.setf(std::ofstream::left);
464  out << ((*(iData[k]))/GetUnitData());
465 
466  iData[k]++;
467  k++;
468  }
469 
470  out << std::endl;
471 
472  iEnergies++;
473  }
474 
475  delete[] iData;
476 
477  return true;
478 }
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual const G4DataVector & GetData(G4int componentId) const =0
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 536 of file G4DNACrossSectionDataSet.cc.

539 {
540  G4VEMDataSet * component(components[argComponentId]);
541 
542  if (component)
543  {
544  component->SetEnergiesData(argEnergies, argData, 0);
545  return;
546  }
547 
548  std::ostringstream message;
549  message << "Component " << argComponentId << " not found";
550 
551  G4Exception("G4DNACrossSectionDataSet::SetEnergiesData","em0005",
552  FatalException,message.str().c_str());
553 
554 }
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 557 of file G4DNACrossSectionDataSet.cc.

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