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

#include <G4DataSet.hh>

Inheritance diagram for G4DataSet:
Collaboration diagram for G4DataSet:

Public Member Functions

 G4DataSet (G4int argZ, G4IInterpolator *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
 
 G4DataSet (G4int argZ, G4DataVector *xData, G4DataVector *data, G4IInterpolator *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
 
virtual ~G4DataSet ()
 
virtual G4double FindValue (G4double x, G4int componentId=0) const
 
virtual void PrintData (void) const
 
virtual const G4IDataSetGetComponent (G4int) const
 
virtual void AddComponent (G4IDataSet *)
 
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 G4IDataSet
 G4IDataSet ()
 
virtual ~G4IDataSet ()
 

Detailed Description

Definition at line 54 of file G4DataSet.hh.

Constructor & Destructor Documentation

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

Definition at line 47 of file G4DataSet.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) G4Exception("G4DataSet::G4DataSet",
62  "pii00000101",
64  "Interpolation == 0");
65  if (randomSet) BuildPdf();
66 }
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:

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

Definition at line 68 of file G4DataSet.cc.

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

G4DataSet::~G4DataSet ( )
virtual

Definition at line 106 of file G4DataSet.cc.

107 {
108  delete algorithm;
109  if (energies) delete energies;
110  if (data) delete data;
111  if (pdf) delete pdf;
112 }
const XML_Char const XML_Char * data
Definition: expat.h:268

Member Function Documentation

virtual void G4DataSet::AddComponent ( G4IDataSet )
inlinevirtual

Implements G4IDataSet.

Definition at line 79 of file G4DataSet.hh.

79 {}
G4double G4DataSet::FindValue ( G4double  x,
G4int  componentId = 0 
) const
virtual

Implements G4IDataSet.

Definition at line 114 of file G4DataSet.cc.

115 {
116  if (!energies) G4Exception("G4DataSet::FindValue",
117  "pii00000120",
119  "energies == 0");
120  if (energies->empty()) return 0;
121  if (energy <= (*energies)[0]) return (*data)[0];
122 
123  size_t i = energies->size()-1;
124  if (energy >= (*energies)[i]) return (*data)[i];
125 
126  G4double interpolated = algorithm->Calculate(energy,FindLowerBound(energy),*energies,*data);
127  return interpolated;
128 }
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
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)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

virtual const G4IDataSet* G4DataSet::GetComponent ( G4int  ) const
inlinevirtual

Implements G4IDataSet.

Definition at line 77 of file G4DataSet.hh.

77 { return 0; }
virtual const G4DataVector& G4DataSet::GetData ( G4int  ) const
inlinevirtual

Implements G4IDataSet.

Definition at line 84 of file G4DataSet.hh.

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

Implements G4IDataSet.

Definition at line 83 of file G4DataSet.hh.

83 { return *energies; }
G4bool G4DataSet::LoadData ( const G4String fileName)
virtual

Implements G4IDataSet.

Definition at line 176 of file G4DataSet.cc.

177 {
178  // The file is organized into two columns:
179  // 1st column is the energy
180  // 2nd column is the corresponding value
181  // The file terminates with the pattern: -1 -1
182  // -2 -2
183 
184  G4String fullFileName(FullFileName(fileName));
185  std::ifstream in(fullFileName);
186 
187  if (!in.is_open())
188  {
189 
190  std::ostringstream message;
191  message << "G4DataSet::LoadData - data file " << fullFileName << " not found";
192 
193  G4Exception("G4CompositeDataSet::LoadData",
194  "pii00000140",
196  message.str().c_str());
197  }
198 
199  G4DataVector* argEnergies=new G4DataVector;
200  G4DataVector* argData=new G4DataVector;
201 
202  G4double a;
203  bool energyColumn(true);
204 
205  do
206  {
207  in >> a;
208 
209  if (a!=-1 && a!=-2)
210  {
211  if (energyColumn)
212  {
213  // std::cout << fullFileName << ", a = " << a <<std::endl;
214  argEnergies->push_back(a*unitEnergies);
215  }
216  else
217  argData->push_back(a*unitData);
218  energyColumn=(!energyColumn);
219  }
220  }
221  while (a != -2);
222 
223  SetEnergiesData(argEnergies, argData, 0);
224  if (randomSet) BuildPdf();
225 
226  return true;
227 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual void SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)
Definition: G4DataSet.cc:151
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

virtual size_t G4DataSet::NumberOfComponents ( void  ) const
inlinevirtual

Implements G4IDataSet.

Definition at line 81 of file G4DataSet.hh.

81 { return 0; }
void G4DataSet::PrintData ( void  ) const
virtual

Implements G4IDataSet.

Definition at line 131 of file G4DataSet.cc.

132 {
133  if (!energies)
134  {
135  G4cout << "Data not available." << G4endl;
136  }
137  else
138  {
139  size_t size = energies->size();
140  for (size_t i(0); i<size; i++)
141  {
142  G4cout << "Point: " << ((*energies)[i]/unitEnergies)
143  << " - Data value: " << ((*data)[i]/unitData);
144  if (pdf != 0) G4cout << " - PDF : " << (*pdf)[i];
145  G4cout << G4endl;
146  }
147  }
148 }
const XML_Char const XML_Char * data
Definition: expat.h:268
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4double G4DataSet::RandomSelect ( G4int  componentId = 0) const
virtual

Implements G4IDataSet.

Definition at line 383 of file G4DataSet.cc.

384 {
385  // Random select a X value according to the cumulative probability distribution
386  // derived from the data
387 
388  if (!pdf) G4Exception("G4DataSet::RandomSelect",
389  "pii00000170",
391  "PDF has not been created for this data set");
392 
393  G4double value = 0.;
394  G4double x = G4UniformRand();
395 
396  // Locate the random value in the X vector based on the PDF
397  size_t bin = FindLowerBound(x,pdf);
398 
399  // Interpolate the PDF to calculate the X value:
400  // linear interpolation in the first bin (to avoid problem with 0),
401  // interpolation with associated data set algorithm in other bins
402 
403  G4LinInterpolation linearAlgo;
404  if (bin == 0) value = linearAlgo.Calculate(x, bin, *pdf, *energies);
405  else value = algorithm->Calculate(x, bin, *pdf, *energies);
406 
407  // G4cout << x << " random bin "<< bin << " - " << value << G4endl;
408  return value;
409 }
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 G4DataSet::SaveData ( const G4String fileName) const
virtual

Implements G4IDataSet.

Definition at line 229 of file G4DataSet.cc.

230 {
231  // The file is organized into two columns:
232  // 1st column is the energy
233  // 2nd column is the corresponding value
234  // The file terminates with the pattern: -1 -1
235  // -2 -2
236 
237  G4String fullFileName(FullFileName(name));
238  std::ofstream out(fullFileName);
239 
240  if (!out.is_open())
241  {
242 
243  std::ostringstream message;
244  message << "G4DataSet:: SaveData - cannot open " << fullFileName;
245 
246  G4Exception("G4CompositeDataSet::SaveData",
247  "pii00000150",
249  message.str().c_str());
250 
251  }
252 
253  out.precision(10);
254  out.width(15);
255  out.setf(std::ofstream::left);
256 
257  if (energies!=0 && data!=0)
258  {
259  G4DataVector::const_iterator i(energies->begin());
260  G4DataVector::const_iterator endI(energies->end());
261  G4DataVector::const_iterator j(data->begin());
262 
263  while (i!=endI)
264  {
265  out.precision(10);
266  out.width(15);
267  out.setf(std::ofstream::left);
268  out << ((*i)/unitEnergies) << ' ';
269 
270  out.precision(10);
271  out.width(15);
272  out.setf(std::ofstream::left);
273  out << ((*j)/unitData) << std::endl;
274 
275  i++;
276  j++;
277  }
278  }
279 
280  out.precision(10);
281  out.width(15);
282  out.setf(std::ofstream::left);
283  out << -1.f << ' ';
284 
285  out.precision(10);
286  out.width(15);
287  out.setf(std::ofstream::left);
288  out << -1.f << std::endl;
289 
290  out.precision(10);
291  out.width(15);
292  out.setf(std::ofstream::left);
293  out << -2.f << ' ';
294 
295  out.precision(10);
296  out.width(15);
297  out.setf(std::ofstream::left);
298  out << -2.f << std::endl;
299 
300  return true;
301 }
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 G4DataSet::SetEnergiesData ( G4DataVector xData,
G4DataVector data,
G4int  componentId 
)
virtual

Implements G4IDataSet.

Definition at line 151 of file G4DataSet.cc.

154 {
155  if (energies) delete energies;
156  energies = dataX;
157 
158  if (data) delete data;
159  data = dataY;
160 
161  if ((energies == 0) ^ (data==0))
162  G4Exception("G4DataSet::SetEnergiesData",
163  "pii00000130",
165  "different size for energies and data (zero case)");
166 
167  if (energies == 0) return;
168 
169  if (energies->size() != data->size())
170  G4Exception("G4DataSet::SetEnergiesData",
171  "pii00000131",
173  "different size for energies and data");
174 }
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:


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