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

#include <G4EMDataSet.hh>

Inheritance diagram for G4EMDataSet:
G4VEMDataSet

Public Member Functions

 G4EMDataSet (G4int argZ, G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
 
 G4EMDataSet (G4int argZ, G4DataVector *xData, G4DataVector *data, G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
 
 G4EMDataSet (G4int argZ, G4DataVector *xData, G4DataVector *data, G4DataVector *xLogData, G4DataVector *Logdata, G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
 
virtual ~G4EMDataSet ()
 
virtual G4double FindValue (G4double x, G4int componentId=0) const
 
virtual void PrintData (void) const
 
virtual const G4VEMDataSetGetComponent (G4int) const
 
virtual void AddComponent (G4VEMDataSet *)
 
virtual size_t NumberOfComponents (void) const
 
virtual const G4DataVectorGetEnergies (G4int) const
 
virtual const G4DataVectorGetData (G4int) const
 
virtual const G4DataVectorGetLogEnergies (G4int) const
 
virtual const G4DataVectorGetLogData (G4int) const
 
virtual void SetEnergiesData (G4DataVector *xData, G4DataVector *data, G4int componentId)
 
virtual void SetLogEnergiesData (G4DataVector *xData, G4DataVector *data, G4DataVector *xLogData, G4DataVector *Logdata, G4int componentId)
 
virtual G4bool LoadData (const G4String &fileName)
 
virtual G4bool LoadNonLogData (const G4String &fileName)
 
virtual G4bool SaveData (const G4String &fileName) const
 
virtual G4double RandomSelect (G4int componentId=0) const
 
- Public Member Functions inherited from G4VEMDataSet
 G4VEMDataSet ()
 
virtual ~G4VEMDataSet ()
 

Detailed Description

Definition at line 58 of file G4EMDataSet.hh.

Constructor & Destructor Documentation

G4EMDataSet::G4EMDataSet ( G4int  argZ,
G4VDataSetAlgorithm algo,
G4double  xUnit = CLHEP::MeV,
G4double  yUnit = CLHEP::barn,
G4bool  random = false 
)

Definition at line 62 of file G4EMDataSet.cc.

References FatalException, G4EMDataSet(), and G4Exception().

Referenced by G4EMDataSet().

66  :
67  z(Z),
68  energies(0),
69  data(0),
70  log_energies(0),
71  log_data(0),
72  algorithm(algo),
73  unitEnergies(xUnit),
74  unitData(yUnit),
75  pdf(0),
76  randomSet(random)
77 {
78  if (algorithm == 0) {
79  G4Exception("G4EMDataSet::G4EMDataSet",
80  "em1012",FatalException,"interpolation == 0");
81  } else if (randomSet) { BuildPdf(); }
82 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const XML_Char const XML_Char * data
G4EMDataSet::G4EMDataSet ( G4int  argZ,
G4DataVector xData,
G4DataVector data,
G4VDataSetAlgorithm algo,
G4double  xUnit = CLHEP::MeV,
G4double  yUnit = CLHEP::barn,
G4bool  random = false 
)

Definition at line 84 of file G4EMDataSet.cc.

References FatalException, G4EMDataSet(), and G4Exception().

90  :
91  z(argZ),
92  energies(dataX),
93  data(dataY),
94  log_energies(0),
95  log_data(0),
96  algorithm(algo),
97  unitEnergies(xUnit),
98  unitData(yUnit),
99  pdf(0),
100  randomSet(random)
101 {
102  if (algorithm == 0) {
103  G4Exception("G4EMDataSet::G4EMDataSet",
104  "em1012",FatalException,"interpolation == 0");
105  } else if ((energies == 0) ^ (data == 0)) {
106  G4Exception("G4EMDataSet::G4EMDataSet",
107  "em1012",FatalException,"different size for energies and data (zero case)");
108  } else if (energies->size() != data->size()) {
109  G4Exception("G4EMDataSet::G4EMDataSet",
110  "em1012",FatalException,"different size for energies and data");
111  } else if (randomSet) {
112  BuildPdf();
113  }
114 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4EMDataSet::G4EMDataSet ( G4int  argZ,
G4DataVector xData,
G4DataVector data,
G4DataVector xLogData,
G4DataVector Logdata,
G4VDataSetAlgorithm algo,
G4double  xUnit = CLHEP::MeV,
G4double  yUnit = CLHEP::barn,
G4bool  random = false 
)

Definition at line 116 of file G4EMDataSet.cc.

References FatalException, G4EMDataSet(), and G4Exception().

124  :
125  z(argZ),
126  energies(dataX),
127  data(dataY),
128  log_energies(dataLogX),
129  log_data(dataLogY),
130  algorithm(algo),
131  unitEnergies(xUnit),
132  unitData(yUnit),
133  pdf(0),
134  randomSet(random)
135 {
136  if (algorithm == 0) {
137  G4Exception("G4EMDataSet::G4EMDataSet",
138  "em1012",FatalException,"interpolation == 0");
139  } else if ((energies == 0) ^ (data == 0)) {
140  G4Exception("G4EMDataSet::G4EMDataSet",
141  "em1012",FatalException,"different size for energies and data (zero case)");
142  } else if (energies->size() != data->size()) {
143  G4Exception("G4EMDataSet::G4EMDataSet",
144  "em1012",FatalException,"different size for energies and data");
145  } else if ((log_energies == 0) ^ (log_data == 0)) {
146  G4Exception("G4EMDataSet::G4EMDataSet",
147  "em1012",FatalException,"different size for log energies and log data (zero case)");
148  } else if (log_energies->size() != log_data->size()) {
149  G4Exception("G4EMDataSet::G4EMDataSet",
150  "em1012",FatalException,"different size for log energies and log data");
151  } else if (randomSet) {
152  BuildPdf();
153  }
154 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4EMDataSet::~G4EMDataSet ( )
virtual

Definition at line 157 of file G4EMDataSet.cc.

158 {
159  delete algorithm;
160  delete energies;
161  delete data;
162  delete pdf;
163  delete log_energies;
164  delete log_data;
165 }
const XML_Char const XML_Char * data

Member Function Documentation

virtual void G4EMDataSet::AddComponent ( G4VEMDataSet )
inlinevirtual

Implements G4VEMDataSet.

Definition at line 93 of file G4EMDataSet.hh.

93 {}
G4double G4EMDataSet::FindValue ( G4double  x,
G4int  componentId = 0 
) const
virtual

Implements G4VEMDataSet.

Definition at line 168 of file G4EMDataSet.cc.

References G4VDataSetAlgorithm::Calculate(), FatalException, and G4Exception().

169 {
170  if (!energies) {
171  G4Exception("G4EMDataSet::FindValue",
172  "em1012",FatalException,"energies == 0");
173  return 0.0;
174  } else if (energies->empty()) {
175  return 0.0;
176  } else if (energy <= (*energies)[0]) {
177  return (*data)[0];
178  }
179  size_t i = energies->size()-1;
180  if (energy >= (*energies)[i]) { return (*data)[i]; }
181 
182  //Nicolas A. Karakatsanis: Check if the logarithmic data have been loaded to decide
183  // which Interpolation-Calculation method will be applied
184  if (log_energies != 0)
185  {
186  return algorithm->Calculate(energy, FindLowerBound(energy), *energies, *data, *log_energies, *log_data);
187  }
188 
189  return algorithm->Calculate(energy, FindLowerBound(energy), *energies, *data);
190 }
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0
double precision function energy(A, Z)
Definition: dpm25nuc6.f:4106
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const XML_Char const XML_Char * data
virtual const G4VEMDataSet* G4EMDataSet::GetComponent ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 91 of file G4EMDataSet.hh.

91 { return 0; }
virtual const G4DataVector& G4EMDataSet::GetData ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 98 of file G4EMDataSet.hh.

98 { return *data; }
const XML_Char const XML_Char * data
virtual const G4DataVector& G4EMDataSet::GetEnergies ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 97 of file G4EMDataSet.hh.

97 { return *energies; }
virtual const G4DataVector& G4EMDataSet::GetLogData ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 100 of file G4EMDataSet.hh.

100 { return *log_data; }
virtual const G4DataVector& G4EMDataSet::GetLogEnergies ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 99 of file G4EMDataSet.hh.

99 { return *log_energies; }
G4bool G4EMDataSet::LoadData ( const G4String fileName)
virtual

Implements G4VEMDataSet.

Definition at line 292 of file G4EMDataSet.cc.

References test::a, test::b, FatalException, and G4Exception().

293 {
294  // The file is organized into four columns:
295  // 1st column contains the values of energy
296  // 2nd column contains the corresponding data value
297  // The file terminates with the pattern: -1 -1
298  // -2 -2
299 
300  G4String fullFileName(FullFileName(fileName));
301  std::ifstream in(fullFileName);
302 
303  if (!in.is_open())
304  {
305  G4String message("data file \"");
306  message += fullFileName;
307  message += "\" not found";
308  G4Exception("G4EMDataSet::LoadData",
309  "em1012",FatalException,message);
310  return false;
311  }
312 
313  delete energies;
314  delete data;
315  delete log_energies;
316  delete log_data;
317  energies = new G4DataVector;
318  data = new G4DataVector;
319  log_energies = new G4DataVector;
320  log_data = new G4DataVector;
321 
322  G4double a, b;
323  //G4int k = 0;
324  //G4int nColumns = 2;
325 
326  do
327  {
328  in >> a >> b;
329 
330  if (a != -1 && a != -2)
331  {
332  if (a==0.) { a=1e-300; }
333  if (b==0.) { b=1e-300; }
334  a *= unitEnergies;
335  b *= unitData;
336  energies->push_back(a);
337  log_energies->push_back(std::log10(a));
338  data->push_back(b);
339  log_data->push_back(std::log10(b));
340  }
341  }
342  while (a != -2);
343 
344  if (randomSet) { BuildPdf(); }
345 
346  return true;
347 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76
const XML_Char const XML_Char * data
G4bool G4EMDataSet::LoadNonLogData ( const G4String fileName)
virtual

Implements G4VEMDataSet.

Definition at line 350 of file G4EMDataSet.cc.

References test::a, FatalException, G4Exception(), and SetEnergiesData().

351 {
352  // The file is organized into four columns:
353  // 1st column contains the values of energy
354  // 2nd column contains the corresponding data value
355  // The file terminates with the pattern: -1 -1
356  // -2 -2
357 
358  G4String fullFileName(FullFileName(fileName));
359  std::ifstream in(fullFileName);
360  if (!in.is_open())
361  {
362  G4String message("data file \"");
363  message += fullFileName;
364  message += "\" not found";
365  G4Exception("G4EMDataSet::LoadNonLogData",
366  "em1012",FatalException,message);
367  }
368 
369  G4DataVector* argEnergies=new G4DataVector;
370  G4DataVector* argData=new G4DataVector;
371 
372  G4double a;
373  G4int k = 0;
374  G4int nColumns = 2;
375 
376  do
377  {
378  in >> a;
379 
380  if (a != -1 && a != -2)
381  {
382  if (k%nColumns == 0)
383  {
384  argEnergies->push_back(a*unitEnergies);
385  }
386  else if (k%nColumns == 1)
387  {
388  argData->push_back(a*unitData);
389  }
390  k++;
391  }
392  }
393  while (a != -2);
394 
395  SetEnergiesData(argEnergies, argData, 0);
396 
397  if (randomSet) BuildPdf();
398 
399  return true;
400 }
virtual void SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)
Definition: G4EMDataSet.cc:213
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76
virtual size_t G4EMDataSet::NumberOfComponents ( void  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 95 of file G4EMDataSet.hh.

95 { return 0; }
void G4EMDataSet::PrintData ( void  ) const
virtual

Implements G4VEMDataSet.

Definition at line 193 of file G4EMDataSet.cc.

References G4cout, and G4endl.

194 {
195  if (!energies)
196  {
197  G4cout << "Data not available." << G4endl;
198  }
199  else
200  {
201  size_t size = energies->size();
202  for (size_t i(0); i<size; i++)
203  {
204  G4cout << "Point: " << ((*energies)[i]/unitEnergies)
205  << " - Data value: " << ((*data)[i]/unitData);
206  if (pdf != 0) G4cout << " - PDF : " << (*pdf)[i];
207  G4cout << G4endl;
208  }
209  }
210 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
const XML_Char const XML_Char * data
G4double G4EMDataSet::RandomSelect ( G4int  componentId = 0) const
virtual

Implements G4VEMDataSet.

Definition at line 555 of file G4EMDataSet.cc.

References plottest35::bin, G4VDataSetAlgorithm::Calculate(), G4LinInterpolation::Calculate(), FatalException, G4Exception(), and G4UniformRand.

556 {
557  G4double value = 0.;
558  // Random select a X value according to the cumulative probability distribution
559  // derived from the data
560 
561  if (!pdf) {
562  G4Exception("G4EMDataSet::RandomSelect",
563  "em1012",FatalException,"PDF has not been created for this data set");
564  return value;
565  }
566 
568 
569  // Locate the random value in the X vector based on the PDF
570  size_t bin = FindLowerBound(x,pdf);
571 
572  // Interpolate the PDF to calculate the X value:
573  // linear interpolation in the first bin (to avoid problem with 0),
574  // interpolation with associated data set algorithm in other bins
575 
576  G4LinInterpolation linearAlgo;
577  if (bin == 0) value = linearAlgo.Calculate(x, bin, *pdf, *energies);
578  else value = algorithm->Calculate(x, bin, *pdf, *energies);
579 
580  // G4cout << x << " random bin "<< bin << " - " << value << G4endl;
581  return value;
582 }
tuple bin
Definition: plottest35.py:22
G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0
#define G4UniformRand()
Definition: Randomize.hh:87
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const XML_Char int const XML_Char * value
double G4double
Definition: G4Types.hh:76
G4bool G4EMDataSet::SaveData ( const G4String fileName) const
virtual

Implements G4VEMDataSet.

Definition at line 404 of file G4EMDataSet.cc.

References FatalException, G4Exception(), and left.

405 {
406  // The file is organized into two columns:
407  // 1st column is the energy
408  // 2nd column is the corresponding value
409  // The file terminates with the pattern: -1 -1
410  // -2 -2
411 
412  G4String fullFileName(FullFileName(name));
413  std::ofstream out(fullFileName);
414 
415  if (!out.is_open())
416  {
417  G4String message("cannot open \"");
418  message+=fullFileName;
419  message+="\"";
420  G4Exception("G4EMDataSet::SaveData",
421  "em1012",FatalException,message);
422  }
423 
424  out.precision(10);
425  out.width(15);
426  out.setf(std::ofstream::left);
427 
428  if (energies!=0 && data!=0)
429  {
430  G4DataVector::const_iterator i(energies->begin());
431  G4DataVector::const_iterator endI(energies->end());
432  G4DataVector::const_iterator j(data->begin());
433 
434  while (i!=endI)
435  {
436  out.precision(10);
437  out.width(15);
438  out.setf(std::ofstream::left);
439  out << ((*i)/unitEnergies) << ' ';
440 
441  out.precision(10);
442  out.width(15);
443  out.setf(std::ofstream::left);
444  out << ((*j)/unitData) << std::endl;
445 
446  i++;
447  j++;
448  }
449  }
450 
451  out.precision(10);
452  out.width(15);
453  out.setf(std::ofstream::left);
454  out << -1.f << ' ';
455 
456  out.precision(10);
457  out.width(15);
458  out.setf(std::ofstream::left);
459  out << -1.f << std::endl;
460 
461  out.precision(10);
462  out.width(15);
463  out.setf(std::ofstream::left);
464  out << -2.f << ' ';
465 
466  out.precision(10);
467  out.width(15);
468  out.setf(std::ofstream::left);
469  out << -2.f << std::endl;
470 
471  return true;
472 }
const XML_Char * name
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const XML_Char const XML_Char * data
void G4EMDataSet::SetEnergiesData ( G4DataVector xData,
G4DataVector data,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 213 of file G4EMDataSet.cc.

References FatalException, and G4Exception().

Referenced by LoadNonLogData().

216 {
217  if (energies) { delete energies; }
218  energies = dataX;
219 
220  if (data) { delete data; }
221  data = dataY;
222 
223  if ((energies == 0) ^ (data==0)) {
224  G4Exception("G4EMDataSet::SetEnergiesData",
225  "em1012",FatalException,"different size for energies and data (zero case)");
226  return;
227  } else if (energies == 0) { return; }
228 
229  //G4cout << "Size of energies: " << energies->size() << G4endl << "Size of data: " << data->size() << G4endl;
230  if (energies->size() != data->size()) {
231  G4Exception("G4EMDataSet::SetEnergiesData",
232  "em1012",FatalException,"different size for energies and data");
233  }
234 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void G4EMDataSet::SetLogEnergiesData ( G4DataVector xData,
G4DataVector data,
G4DataVector xLogData,
G4DataVector Logdata,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 236 of file G4EMDataSet.cc.

References FatalException, and G4Exception().

241 {
242  //Load of the actual energy and data values
243  if (energies) { delete energies; }
244  energies = dataX;
245  if (data) { delete data; }
246  data = dataY;
247  //Load of the logarithmic energy and data values
248  if (log_energies) { delete log_energies; }
249  log_energies = data_logX;
250  if (log_data) { delete log_data; }
251  log_data = data_logY;
252 
253  //Check if data loaded properly from data files
254  if ( !energies ) {
255  if(data || log_energies || log_data ) {
256  G4Exception("G4EMDataSet::SetLogEnergiesData",
257  "em1012",FatalException,"inconsistent data");
258  }
259  return;
260  } else {
261  if ( !data ) {
262  G4Exception("G4EMDataSet::SetLogEnergiesData",
263  "em1012",FatalException,"only energy, no data");
264  return;
265  } else if (energies->size() != data->size()) {
266  G4Exception("G4EMDataSet::SetLogEnergiesData",
267  "em1012",FatalException,"different size for energies and data");
268  return;
269  }
270  //G4cout << "Size of energies: " << energies->size() << G4endl << "Size of data: " << data->size() << G4endl << G4endl;
271 
272  //Check if logarithmic data loaded properly from data files
273  if ( !log_energies ) {
274  if(log_data) {
275  G4Exception("G4EMDataSet::SetLogEnergiesData",
276  "em1012",FatalException,"inconsistence of log_data");
277  }
278  return;
279  } else {
280  if ( !log_data ) {
281  G4Exception("G4EMDataSet::SetLogEnergiesData",
282  "em1012",FatalException,"only log_energies, no data");
283  } else if ((log_energies->size() != log_data->size()) || (log_energies->size() != data->size())) {
284  G4Exception("G4EMDataSet::SetLogEnergiesData",
285  "em1012",FatalException,"different size for log energies and data");
286  }
287  }
288  }
289  //G4cout << "Size of log energies: " << log_energies->size() << G4endl << "Size of log data: " << log_data->size() << G4endl;
290 }
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: