Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
G4MuElecCrossSectionDataSet Class Reference

#include <G4MuElecCrossSectionDataSet.hh>

Inheritance diagram for G4MuElecCrossSectionDataSet:
G4VEMDataSet

Public Member Functions

 G4MuElecCrossSectionDataSet (G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
 
virtual ~G4MuElecCrossSectionDataSet ()
 
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 37 of file G4MuElecCrossSectionDataSet.hh.

Constructor & Destructor Documentation

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

Definition at line 39 of file G4MuElecCrossSectionDataSet.cc.

References G4MuElecCrossSectionDataSet().

Referenced by G4MuElecCrossSectionDataSet().

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

Definition at line 50 of file G4MuElecCrossSectionDataSet.cc.

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

Member Function Documentation

virtual void G4MuElecCrossSectionDataSet::AddComponent ( G4VEMDataSet dataSet)
inlinevirtual

Implements G4VEMDataSet.

Definition at line 54 of file G4MuElecCrossSectionDataSet.hh.

Referenced by LoadData(), and LoadNonLogData().

55  { components.push_back(dataSet); }
G4double G4MuElecCrossSectionDataSet::FindValue ( G4double  e,
G4int  componentId = 0 
) const
virtual

Implements G4VEMDataSet.

Definition at line 474 of file G4MuElecCrossSectionDataSet.cc.

Referenced by G4MuElecElasticModel::CrossSectionPerVolume(), and G4MuElecInelasticModel::CrossSectionPerVolume().

475 {
476  // Returns the sum over the shells corresponding to e
477  G4double value = 0.;
478 
479  std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
480  std::vector<G4VEMDataSet *>::const_iterator end(components.end());
481 
482  while (i!=end)
483  {
484  value+=(*i)->FindValue(argEnergy);
485  i++;
486  }
487 
488  return value;
489 }
const XML_Char int const XML_Char * value
double G4double
Definition: G4Types.hh:76
virtual const G4VEMDataSet* G4MuElecCrossSectionDataSet::GetComponent ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 51 of file G4MuElecCrossSectionDataSet.hh.

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

52  { return components[componentId]; }
virtual const G4DataVector& G4MuElecCrossSectionDataSet::GetData ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 63 of file G4MuElecCrossSectionDataSet.hh.

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

64  { return GetComponent(componentId)->GetData(0); }
virtual const G4DataVector & GetData(G4int componentId) const =0
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual const G4DataVector& G4MuElecCrossSectionDataSet::GetEnergies ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 60 of file G4MuElecCrossSectionDataSet.hh.

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

Referenced by SaveData().

61  { return GetComponent(componentId)->GetEnergies(0); }
virtual const G4DataVector & GetEnergies(G4int componentId) const =0
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual const G4DataVector& G4MuElecCrossSectionDataSet::GetLogData ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 69 of file G4MuElecCrossSectionDataSet.hh.

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

70  { return GetComponent(componentId)->GetLogData(0); }
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual const G4DataVector & GetLogData(G4int componentId) const =0
virtual const G4DataVector& G4MuElecCrossSectionDataSet::GetLogEnergies ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 66 of file G4MuElecCrossSectionDataSet.hh.

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

67  { return GetComponent(componentId)->GetLogEnergies(0); }
virtual const G4DataVector & GetLogEnergies(G4int componentId) const =0
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
G4bool G4MuElecCrossSectionDataSet::LoadData ( const G4String argFileName)
virtual

Implements G4VEMDataSet.

Definition at line 58 of file G4MuElecCrossSectionDataSet.cc.

References AddComponent(), test::c, FatalException, and G4Exception().

Referenced by G4MuElecElasticModel::Initialise(), and G4MuElecInelasticModel::Initialise().

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

Implements G4VEMDataSet.

Definition at line 233 of file G4MuElecCrossSectionDataSet.cc.

References AddComponent(), test::c, FatalException, and G4Exception().

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

Implements G4VEMDataSet.

Definition at line 57 of file G4MuElecCrossSectionDataSet.hh.

Referenced by PrintData(), and SaveData().

58  { return components.size(); }
void G4MuElecCrossSectionDataSet::PrintData ( void  ) const
virtual

Implements G4VEMDataSet.

Definition at line 492 of file G4MuElecCrossSectionDataSet.cc.

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

493 {
494  const size_t n(NumberOfComponents());
495 
496  G4cout << "The data set has " << n << " components" << G4endl;
497  G4cout << G4endl;
498 
499  size_t i(0);
500 
501  while (i<n)
502  {
503  G4cout << "--- Component " << i << " ---" << G4endl;
504  GetComponent(i)->PrintData();
505  i++;
506  }
507 }
virtual size_t NumberOfComponents(void) const
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
G4GLOB_DLL std::ostream G4cout
const G4int n
virtual void PrintData(void) const =0
#define G4endl
Definition: G4ios.hh:61
virtual G4double G4MuElecCrossSectionDataSet::RandomSelect ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 85 of file G4MuElecCrossSectionDataSet.hh.

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

Implements G4VEMDataSet.

Definition at line 386 of file G4MuElecCrossSectionDataSet.cc.

References FatalException, G4Exception(), GetComponent(), G4VEMDataSet::GetData(), GetEnergies(), left, n, and NumberOfComponents().

387 {
388  const size_t n(NumberOfComponents());
389 
390  if (n==0)
391  {
392  G4Exception("G4MuElecCrossSectionDataSet::SaveData","em0005",
393  FatalException,"Expected at least one component");
394 
395  return false;
396  }
397 
398  G4String fullFileName(FullFileName(argFileName));
399  std::ofstream out(fullFileName);
400 
401  if (!out.is_open())
402  {
403  G4String message("Cannot open \"");
404  message+=fullFileName;
405  message+="\"";
406  G4Exception("G4MuElecCrossSectionDataSet::SaveData","em0005",
407  FatalException,message);
408  return false;
409  }
410 
411  G4DataVector::const_iterator iEnergies(GetComponent(0)->GetEnergies(0).begin());
412  G4DataVector::const_iterator iEnergiesEnd(GetComponent(0)->GetEnergies(0).end());
413  G4DataVector::const_iterator * iData(new G4DataVector::const_iterator[n]);
414 
415  size_t k(n);
416 
417  while (k>0)
418  {
419  k--;
420  iData[k]=GetComponent(k)->GetData(0).begin();
421  }
422 
423  while (iEnergies!=iEnergiesEnd)
424  {
425  out.precision(10);
426  out.width(15);
427  out.setf(std::ofstream::left);
428  out << ((*iEnergies)/GetUnitEnergies());
429 
430  k=0;
431 
432  while (k<n)
433  {
434  out << ' ';
435  out.precision(10);
436  out.width(15);
437  out.setf(std::ofstream::left);
438  out << ((*(iData[k]))/GetUnitData());
439 
440  iData[k]++;
441  k++;
442  }
443 
444  out << std::endl;
445 
446  iEnergies++;
447  }
448 
449  delete[] iData;
450 
451  return true;
452 }
virtual size_t NumberOfComponents(void) const
virtual const G4DataVector & GetData(G4int componentId) const =0
virtual const G4DataVector & GetEnergies(G4int componentId) const
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
const G4int n
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void G4MuElecCrossSectionDataSet::SetEnergiesData ( G4DataVector x,
G4DataVector values,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 510 of file G4MuElecCrossSectionDataSet.cc.

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

513 {
514  G4VEMDataSet * component(components[argComponentId]);
515 
516  if (component)
517  {
518  component->SetEnergiesData(argEnergies, argData, 0);
519  return;
520  }
521 
522  std::ostringstream message;
523  message << "Component " << argComponentId << " not found";
524 
525  G4Exception("G4MuElecCrossSectionDataSet::SetEnergiesData","em0005",
526  FatalException,message.str().c_str());
527 
528 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void G4MuElecCrossSectionDataSet::SetLogEnergiesData ( G4DataVector x,
G4DataVector values,
G4DataVector log_x,
G4DataVector log_values,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 531 of file G4MuElecCrossSectionDataSet.cc.

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

536 {
537  G4VEMDataSet * component(components[argComponentId]);
538 
539  if (component)
540  {
541  component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
542  return;
543  }
544 
545  std::ostringstream message;
546  message << "Component " << argComponentId << " not found";
547 
548  G4Exception("G4MuElecCrossSectionDataSet::SetLogEnergiesData","em0005",
549  FatalException,message.str().c_str());
550 
551 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

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