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

#include <G4RDEMDataSet.hh>

Inheritance diagram for G4RDEMDataSet:
Collaboration diagram for G4RDEMDataSet:

Public Member Functions

 G4RDEMDataSet (G4int argZ, G4RDVDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
 
 G4RDEMDataSet (G4int argZ, G4DataVector *xData, G4DataVector *data, G4RDVDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
 
virtual ~G4RDEMDataSet ()
 
virtual G4double FindValue (G4double x, G4int componentId=0) const
 
virtual void PrintData (void) const
 
virtual const G4RDVEMDataSetGetComponent (G4int) const
 
virtual void AddComponent (G4RDVEMDataSet *)
 
virtual size_t NumberOfComponents (void) const
 
virtual const G4DataVectorGetEnergies (G4int) const
 
virtual const G4DataVectorGetData (G4int) const
 
virtual void SetEnergiesData (G4DataVector *xData, G4DataVector *data, G4int componentId)
 
virtual G4bool LoadData (const G4String &fileName)
 
virtual G4bool SaveData (const G4String &fileName) const
 
virtual G4double RandomSelect (G4int componentId=0) const
 
- Public Member Functions inherited from G4RDVEMDataSet
 G4RDVEMDataSet ()
 
virtual ~G4RDVEMDataSet ()
 

Detailed Description

Definition at line 56 of file G4RDEMDataSet.hh.

Constructor & Destructor Documentation

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

Definition at line 47 of file G4RDEMDataSet.cc.

51  :
52  z(Z),
53  energies(0),
54  data(0),
55  algorithm(algo),
56  unitEnergies(xUnit),
57  unitData(yUnit),
58  pdf(0),
59  randomSet(random)
60 {
61  if (algorithm == 0)
62  G4Exception("G4RDEMDataSet::G4RDEMDataSet()",
63  "InvalidSetup", FatalException, "Interpolation == 0!");
64  if (randomSet) BuildPdf();
65 }
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:

G4RDEMDataSet::G4RDEMDataSet ( G4int  argZ,
G4DataVector xData,
G4DataVector data,
G4RDVDataSetAlgorithm algo,
G4double  xUnit = CLHEP::MeV,
G4double  yUnit = CLHEP::barn,
G4bool  random = false 
)

Definition at line 67 of file G4RDEMDataSet.cc.

73  :
74  z(argZ),
75  energies(dataX),
76  data(dataY),
77  algorithm(algo),
78  unitEnergies(xUnit),
79  unitData(yUnit),
80  pdf(0),
81  randomSet(random)
82 {
83  if (algorithm == 0)
84  G4Exception("G4RDEMDataSet::G4RDEMDataSet()",
85  "InvalidSetup", FatalException, "Interpolation == 0!");
86 
87  if ((energies == 0) ^ (data == 0))
88  G4Exception("G4RDEMDataSet::G4RDEMDataSet()", "InvalidSetup",
89  FatalException, "Different size for energies and data (zero case)!");
90 
91  if (energies == 0) return;
92 
93  if (energies->size() != data->size())
94  G4Exception("G4RDEMDataSet::G4RDEMDataSet()", "InvalidSetup",
95  FatalException, "Different size for energies and data!");
96 
97  if (randomSet) BuildPdf();
98 }
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:

G4RDEMDataSet::~G4RDEMDataSet ( )
virtual

Definition at line 100 of file G4RDEMDataSet.cc.

101 {
102  delete algorithm;
103  if (energies) delete energies;
104  if (data) delete data;
105  if (pdf) delete pdf;
106 }
const XML_Char const XML_Char * data
Definition: expat.h:268

Member Function Documentation

virtual void G4RDEMDataSet::AddComponent ( G4RDVEMDataSet )
inlinevirtual

Implements G4RDVEMDataSet.

Definition at line 81 of file G4RDEMDataSet.hh.

81 {}
G4double G4RDEMDataSet::FindValue ( G4double  x,
G4int  componentId = 0 
) const
virtual

Implements G4RDVEMDataSet.

Definition at line 108 of file G4RDEMDataSet.cc.

109 {
110  if (!energies)
111  G4Exception("G4RDEMDataSet::FindValue()", "InvalidSetup",
112  FatalException, "Energies == 0!");
113  if (energies->empty()) return 0;
114  if (energy <= (*energies)[0]) return (*data)[0];
115 
116  size_t i = energies->size()-1;
117  if (energy >= (*energies)[i]) return (*data)[i];
118 
119  return algorithm->Calculate(energy, FindLowerBound(energy), *energies, *data);
120 }
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
G4double energy(const ThreeVector &p, const G4double m)
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0

Here is the call graph for this function:

virtual const G4RDVEMDataSet* G4RDEMDataSet::GetComponent ( G4int  ) const
inlinevirtual

Implements G4RDVEMDataSet.

Definition at line 79 of file G4RDEMDataSet.hh.

79 { return 0; }
virtual const G4DataVector& G4RDEMDataSet::GetData ( G4int  ) const
inlinevirtual

Implements G4RDVEMDataSet.

Definition at line 86 of file G4RDEMDataSet.hh.

86 { return *data; }
const XML_Char const XML_Char * data
Definition: expat.h:268
virtual const G4DataVector& G4RDEMDataSet::GetEnergies ( G4int  ) const
inlinevirtual

Implements G4RDVEMDataSet.

Definition at line 85 of file G4RDEMDataSet.hh.

85 { return *energies; }
G4bool G4RDEMDataSet::LoadData ( const G4String fileName)
virtual

Implements G4RDVEMDataSet.

Definition at line 164 of file G4RDEMDataSet.cc.

165 {
166  // The file is organized into two columns:
167  // 1st column is the energy
168  // 2nd column is the corresponding value
169  // The file terminates with the pattern: -1 -1
170  // -2 -2
171 
172  G4String fullFileName(FullFileName(fileName));
173  std::ifstream in(fullFileName);
174 
175  if (!in.is_open())
176  {
177  G4String message("Data file \"");
178  message += fullFileName;
179  message += "\" not found";
180  G4Exception("G4RDEMDataSet::LoadData()", "DataNotFound",
181  FatalException, message);
182  }
183 
184  G4DataVector* argEnergies=new G4DataVector;
185  G4DataVector* argData=new G4DataVector;
186 
187  G4double a;
188  bool energyColumn(true);
189 
190  do
191  {
192  in >> a;
193 
194  if (a!=-1 && a!=-2)
195  {
196  if (energyColumn)
197  argEnergies->push_back(a*unitEnergies);
198  else
199  argData->push_back(a*unitData);
200  energyColumn=(!energyColumn);
201  }
202  }
203  while (a != -2);
204 
205  SetEnergiesData(argEnergies, argData, 0);
206  if (randomSet) BuildPdf();
207 
208  return true;
209 }
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
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 SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)

Here is the call graph for this function:

virtual size_t G4RDEMDataSet::NumberOfComponents ( void  ) const
inlinevirtual

Implements G4RDVEMDataSet.

Definition at line 83 of file G4RDEMDataSet.hh.

83 { return 0; }
void G4RDEMDataSet::PrintData ( void  ) const
virtual

Implements G4RDVEMDataSet.

Definition at line 123 of file G4RDEMDataSet.cc.

124 {
125  if (!energies)
126  {
127  G4cout << "Data not available." << G4endl;
128  }
129  else
130  {
131  size_t size = energies->size();
132  for (size_t i(0); i<size; i++)
133  {
134  G4cout << "Point: " << ((*energies)[i]/unitEnergies)
135  << " - Data value: " << ((*data)[i]/unitData);
136  if (pdf != 0) G4cout << " - PDF : " << (*pdf)[i];
137  G4cout << G4endl;
138  }
139  }
140 }
const XML_Char const XML_Char * data
Definition: expat.h:268
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4double G4RDEMDataSet::RandomSelect ( G4int  componentId = 0) const
virtual

Implements G4RDVEMDataSet.

Definition at line 359 of file G4RDEMDataSet.cc.

360 {
361  // Random select a X value according to the cumulative probability distribution
362  // derived from the data
363 
364  if (!pdf) G4Exception("G4RDEMDataSet::RandomSelect()", "InvalidSetup",
365  FatalException, "PDF has not been created for this data set");
366 
367  G4double value = 0.;
369 
370  // Locate the random value in the X vector based on the PDF
371  size_t bin = FindLowerBound(x,pdf);
372 
373  // Interpolate the PDF to calculate the X value:
374  // linear interpolation in the first bin (to avoid problem with 0),
375  // interpolation with associated data set algorithm in other bins
376 
377  G4RDLinInterpolation linearAlgo;
378  if (bin == 0) value = linearAlgo.Calculate(x, bin, *pdf, *energies);
379  else value = algorithm->Calculate(x, bin, *pdf, *energies);
380 
381  // G4cout << x << " random bin "<< bin << " - " << value << G4endl;
382  return value;
383 }
tuple bin
Definition: plottest35.py:22
tuple x
Definition: test.py:50
#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
G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const
double G4double
Definition: G4Types.hh:76
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0

Here is the call graph for this function:

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

Implements G4RDVEMDataSet.

Definition at line 211 of file G4RDEMDataSet.cc.

212 {
213  // The file is organized into two columns:
214  // 1st column is the energy
215  // 2nd column is the corresponding value
216  // The file terminates with the pattern: -1 -1
217  // -2 -2
218 
219  G4String fullFileName(FullFileName(name));
220  std::ofstream out(fullFileName);
221 
222  if (!out.is_open())
223  {
224  G4String message("Cannot open \"");
225  message+=fullFileName;
226  message+="\"";
227  G4Exception("G4RDEMDataSet::SaveData()", "CannotOpenFile",
228  FatalException, message);
229  }
230 
231  out.precision(10);
232  out.width(15);
233  out.setf(std::ofstream::left);
234 
235  if (energies!=0 && data!=0)
236  {
237  G4DataVector::const_iterator i(energies->begin());
238  G4DataVector::const_iterator endI(energies->end());
239  G4DataVector::const_iterator j(data->begin());
240 
241  while (i!=endI)
242  {
243  out.precision(10);
244  out.width(15);
245  out.setf(std::ofstream::left);
246  out << ((*i)/unitEnergies) << ' ';
247 
248  out.precision(10);
249  out.width(15);
250  out.setf(std::ofstream::left);
251  out << ((*j)/unitData) << std::endl;
252 
253  i++;
254  j++;
255  }
256  }
257 
258  out.precision(10);
259  out.width(15);
260  out.setf(std::ofstream::left);
261  out << -1.f << ' ';
262 
263  out.precision(10);
264  out.width(15);
265  out.setf(std::ofstream::left);
266  out << -1.f << std::endl;
267 
268  out.precision(10);
269  out.width(15);
270  out.setf(std::ofstream::left);
271  out << -2.f << ' ';
272 
273  out.precision(10);
274  out.width(15);
275  out.setf(std::ofstream::left);
276  out << -2.f << std::endl;
277 
278  return true;
279 }
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 G4RDEMDataSet::SetEnergiesData ( G4DataVector xData,
G4DataVector data,
G4int  componentId 
)
virtual

Implements G4RDVEMDataSet.

Definition at line 143 of file G4RDEMDataSet.cc.

146 {
147  if (energies) delete energies;
148  energies = dataX;
149 
150  if (data) delete data;
151  data = dataY;
152 
153  if ((energies == 0) ^ (data==0))
154  G4Exception("G4RDEMDataSet::SetEnergiesData()", "InvalidSetup",
155  FatalException, "Different size for energies and data (zero case)!");
156 
157  if (energies == 0) return;
158 
159  if (energies->size() != data->size())
160  G4Exception("G4RDEMDataSet::SetEnergiesData()", "InvalidSetup",
161  FatalException, "Different size for energies and data!");
162 }
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:


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