Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4EMDataSet Class Reference

#include <G4EMDataSet.hh>

Inheritance diagram for G4EMDataSet:
Collaboration diagram for G4EMDataSet:

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.

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 }
const XML_Char const XML_Char * data
Definition: expat.h:268
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:

Here is the caller graph for this function:

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.

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 || !energies || !data) {
103  G4Exception("G4EMDataSet::G4EMDataSet",
104  "em1012",FatalException,"interpolation == 0");
105  } else {
106  if (energies->size() != data->size()) {
107  G4Exception("G4EMDataSet::G4EMDataSet",
108  "em1012",FatalException,"different size for energies and data");
109  } else if (randomSet) {
110  BuildPdf();
111  }
112  }
113 }
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:

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 115 of file G4EMDataSet.cc.

123  :
124  z(argZ),
125  energies(dataX),
126  data(dataY),
127  log_energies(dataLogX),
128  log_data(dataLogY),
129  algorithm(algo),
130  unitEnergies(xUnit),
131  unitData(yUnit),
132  pdf(0),
133  randomSet(random)
134 {
135  if (!algorithm || !energies || !data || !log_energies || !log_data) {
136  G4Exception("G4EMDataSet::G4EMDataSet",
137  "em1012",FatalException,"interpolation == 0");
138  } else {
139  if ((energies->size() != data->size()) ||
140  (energies->size() != log_energies->size()) ||
141  (energies->size() != log_data->size())) {
142  G4Exception("G4EMDataSet::G4EMDataSet",
143  "em1012",FatalException,"different size for energies and data");
144  } else if (randomSet) {
145  BuildPdf();
146  }
147  }
148 }
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:

G4EMDataSet::~G4EMDataSet ( )
virtual

Definition at line 150 of file G4EMDataSet.cc.

151 {
152  delete algorithm;
153  delete energies;
154  delete data;
155  delete pdf;
156  delete log_energies;
157  delete log_data;
158 }
const XML_Char const XML_Char * data
Definition: expat.h:268

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 160 of file G4EMDataSet.cc.

161 {
162  if (energy <= (*energies)[0]) {
163  return (*data)[0];
164  }
165  size_t i = energies->size()-1;
166  if (energy >= (*energies)[i]) { return (*data)[i]; }
167 
168  //Nicolas A. Karakatsanis: Check if the logarithmic data have been loaded to decide
169  // which Interpolation-Calculation method will be applied
170  if (log_energies != 0)
171  {
172  return algorithm->Calculate(energy, FindLowerBound(energy), *energies, *data, *log_energies, *log_data);
173  }
174 
175  return algorithm->Calculate(energy, FindLowerBound(energy), *energies, *data);
176 }
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0
const XML_Char const XML_Char * data
Definition: expat.h:268
G4double energy(const ThreeVector &p, const G4double m)

Here is the call graph for this function:

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
Definition: expat.h:268
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 248 of file G4EMDataSet.cc.

249 {
250  // The file is organized into four columns:
251  // 1st column contains the values of energy
252  // 2nd column contains the corresponding data value
253  // The file terminates with the pattern: -1 -1
254  // -2 -2
255 
256  G4String fullFileName(FullFileName(fileName));
257  std::ifstream in(fullFileName);
258 
259  if (!in.is_open())
260  {
261  G4String message("data file \"");
262  message += fullFileName;
263  message += "\" not found";
264  G4Exception("G4EMDataSet::LoadData",
265  "em1012",FatalException,message);
266  return false;
267  }
268 
269  delete energies;
270  delete data;
271  delete log_energies;
272  delete log_data;
273  energies = new G4DataVector;
274  data = new G4DataVector;
275  log_energies = new G4DataVector;
276  log_data = new G4DataVector;
277 
278  G4double a, b;
279  //G4int k = 0;
280  //G4int nColumns = 2;
281 
282  do
283  {
284  in >> a >> b;
285 
286  if (a != -1 && a != -2)
287  {
288  if (a==0.) { a=1e-300; }
289  if (b==0.) { b=1e-300; }
290  a *= unitEnergies;
291  b *= unitData;
292  energies->push_back(a);
293  log_energies->push_back(std::log10(a));
294  data->push_back(b);
295  log_data->push_back(std::log10(b));
296  }
297  }
298  while (a != -2);
299 
300  if (randomSet) { BuildPdf(); }
301 
302  return true;
303 }
const XML_Char const XML_Char * data
Definition: expat.h:268
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4bool G4EMDataSet::LoadNonLogData ( const G4String fileName)
virtual

Implements G4VEMDataSet.

Definition at line 306 of file G4EMDataSet.cc.

307 {
308  // The file is organized into four columns:
309  // 1st column contains the values of energy
310  // 2nd column contains the corresponding data value
311  // The file terminates with the pattern: -1 -1
312  // -2 -2
313 
314  G4String fullFileName(FullFileName(fileName));
315  std::ifstream in(fullFileName);
316  if (!in.is_open())
317  {
318  G4String message("data file \"");
319  message += fullFileName;
320  message += "\" not found";
321  G4Exception("G4EMDataSet::LoadNonLogData",
322  "em1012",FatalException,message);
323  }
324 
325  G4DataVector* argEnergies=new G4DataVector;
326  G4DataVector* argData=new G4DataVector;
327 
328  G4double a;
329  G4int k = 0;
330  G4int nColumns = 2;
331 
332  do
333  {
334  in >> a;
335 
336  if (a != -1 && a != -2)
337  {
338  if (k%nColumns == 0)
339  {
340  argEnergies->push_back(a*unitEnergies);
341  }
342  else if (k%nColumns == 1)
343  {
344  argData->push_back(a*unitData);
345  }
346  k++;
347  }
348  }
349  while (a != -2);
350 
351  SetEnergiesData(argEnergies, argData, 0);
352 
353  if (randomSet) BuildPdf();
354 
355  return true;
356 }
virtual void SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)
Definition: G4EMDataSet.cc:190
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

Here is the call graph for this function:

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 178 of file G4EMDataSet.cc.

179 {
180  size_t size = energies->size();
181  for (size_t i(0); i<size; i++)
182  {
183  G4cout << "Point: " << ((*energies)[i]/unitEnergies)
184  << " - Data value: " << ((*data)[i]/unitData);
185  if (pdf != 0) G4cout << " - PDF : " << (*pdf)[i];
186  G4cout << G4endl;
187  }
188 }
const XML_Char const XML_Char * data
Definition: expat.h:268
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4double G4EMDataSet::RandomSelect ( G4int  componentId = 0) const
virtual

Implements G4VEMDataSet.

Definition at line 511 of file G4EMDataSet.cc.

512 {
513  G4double value = 0.;
514  // Random select a X value according to the cumulative probability distribution
515  // derived from the data
516 
517  if (!pdf) {
518  G4Exception("G4EMDataSet::RandomSelect",
519  "em1012",FatalException,"PDF has not been created for this data set");
520  return value;
521  }
522 
523  G4double x = G4UniformRand();
524 
525  // Locate the random value in the X vector based on the PDF
526  size_t bin = FindLowerBound(x,pdf);
527 
528  // Interpolate the PDF to calculate the X value:
529  // linear interpolation in the first bin (to avoid problem with 0),
530  // interpolation with associated data set algorithm in other bins
531 
532  G4LinInterpolation linearAlgo;
533  if (bin == 0) value = linearAlgo.Calculate(x, bin, *pdf, *energies);
534  else value = algorithm->Calculate(x, bin, *pdf, *energies);
535 
536  // G4cout << x << " random bin "<< bin << " - " << value << G4endl;
537  return value;
538 }
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:97
const XML_Char int const XML_Char * value
Definition: expat.h:331
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4bool G4EMDataSet::SaveData ( const G4String fileName) const
virtual

Implements G4VEMDataSet.

Definition at line 360 of file G4EMDataSet.cc.

361 {
362  // The file is organized into two columns:
363  // 1st column is the energy
364  // 2nd column is the corresponding value
365  // The file terminates with the pattern: -1 -1
366  // -2 -2
367 
368  G4String fullFileName(FullFileName(name));
369  std::ofstream out(fullFileName);
370 
371  if (!out.is_open())
372  {
373  G4String message("cannot open \"");
374  message+=fullFileName;
375  message+="\"";
376  G4Exception("G4EMDataSet::SaveData",
377  "em1012",FatalException,message);
378  }
379 
380  out.precision(10);
381  out.width(15);
382  out.setf(std::ofstream::left);
383 
384  if (energies!=0 && data!=0)
385  {
386  G4DataVector::const_iterator i(energies->begin());
387  G4DataVector::const_iterator endI(energies->end());
388  G4DataVector::const_iterator j(data->begin());
389 
390  while (i!=endI)
391  {
392  out.precision(10);
393  out.width(15);
394  out.setf(std::ofstream::left);
395  out << ((*i)/unitEnergies) << ' ';
396 
397  out.precision(10);
398  out.width(15);
399  out.setf(std::ofstream::left);
400  out << ((*j)/unitData) << std::endl;
401 
402  i++;
403  j++;
404  }
405  }
406 
407  out.precision(10);
408  out.width(15);
409  out.setf(std::ofstream::left);
410  out << -1.f << ' ';
411 
412  out.precision(10);
413  out.width(15);
414  out.setf(std::ofstream::left);
415  out << -1.f << std::endl;
416 
417  out.precision(10);
418  out.width(15);
419  out.setf(std::ofstream::left);
420  out << -2.f << ' ';
421 
422  out.precision(10);
423  out.width(15);
424  out.setf(std::ofstream::left);
425  out << -2.f << std::endl;
426 
427  return true;
428 }
const XML_Char * name
Definition: expat.h:151
const XML_Char const XML_Char * data
Definition: expat.h:268
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 G4EMDataSet::SetEnergiesData ( G4DataVector xData,
G4DataVector data,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 190 of file G4EMDataSet.cc.

193 {
194  if(!dataX || !dataY) {
195  G4Exception("G4EMDataSet::SetEnergiesData",
196  "em1012",FatalException,"new interpolation == 0");
197  } else {
198  if (dataX->size() != dataY->size()) {
199  G4Exception("G4EMDataSet::SetEnergiesData",
200  "em1012",FatalException,"different size for energies and data");
201  } else {
202 
203  delete energies;
204  energies = dataX;
205 
206  delete data;
207  data = dataY;
208  //G4cout << "Size of energies: " << energies->size() << G4endl
209  //<< "Size of data: " << data->size() << G4endl;
210  }
211  }
212 }
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:

Here is the caller graph for this function:

void G4EMDataSet::SetLogEnergiesData ( G4DataVector xData,
G4DataVector data,
G4DataVector xLogData,
G4DataVector Logdata,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 214 of file G4EMDataSet.cc.

219 {
220  if(!dataX || !dataY || !data_logX || !data_logY) {
221  G4Exception("G4EMDataSet::SetEnergiesData",
222  "em1012",FatalException,"new interpolation == 0");
223  } else {
224  if (dataX->size() != dataY->size() ||
225  dataX->size() != data_logX->size() ||
226  dataX->size() != data_logY->size()) {
227  G4Exception("G4EMDataSet::SetEnergiesData",
228  "em1012",FatalException,"different size for energies and data");
229  } else {
230 
231  delete energies;
232  energies = dataX;
233 
234  delete data;
235  data = dataY;
236 
237  delete log_energies;
238  log_energies = data_logX;
239 
240  delete log_data;
241  log_data = data_logY;
242  //G4cout << "Size of energies: " << energies->size() << G4endl
243  //<< "Size of data: " << data->size() << G4endl;
244  }
245  }
246 }
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: