60 if (algorithm == 0)
G4Exception(
"G4DataSet::G4DataSet",
63 "Interpolation == 0");
64 if (randomSet) BuildPdf();
83 if (algorithm == 0)
G4Exception(
"G4DataSet::G4DataSet",
86 "Interpolation == 0");
88 if ((energies == 0) ^ (data == 0))
92 "different size for energies and data (zero case)");
94 if (energies == 0)
return;
96 if (energies->size() != data->size())
100 "different size for energies and data");
102 if (randomSet) BuildPdf();
108 if (energies)
delete energies;
109 if (data)
delete data;
119 if (energies->empty())
return 0;
120 if (energy <= (*energies)[0])
return (*data)[0];
122 size_t i = energies->size()-1;
123 if (energy >= (*energies)[i])
return (*data)[i];
125 G4double interpolated = algorithm->
Calculate(energy,FindLowerBound(energy),*energies,*data);
138 size_t size = energies->size();
139 for (
size_t i(0); i<size; i++)
141 G4cout <<
"Point: " << ((*energies)[i]/unitEnergies)
142 <<
" - Data value: " << ((*data)[i]/unitData);
143 if (pdf != 0)
G4cout <<
" - PDF : " << (*pdf)[i];
154 if (energies)
delete energies;
157 if (data)
delete data;
160 if ((energies == 0) ^ (data==0))
164 "different size for energies and data (zero case)");
166 if (energies == 0)
return;
168 if (energies->size() != data->size())
172 "different size for energies and data");
183 G4String fullFileName(FullFileName(fileName));
184 std::ifstream in(fullFileName);
189 std::ostringstream message;
190 message <<
"G4DataSet::LoadData - data file " << fullFileName <<
" not found";
195 message.str().c_str());
202 bool energyColumn(
true);
213 argEnergies->push_back(a*unitEnergies);
216 argData->push_back(a*unitData);
217 energyColumn=(!energyColumn);
223 if (randomSet) BuildPdf();
236 G4String fullFileName(FullFileName(name));
237 std::ofstream out(fullFileName);
242 std::ostringstream message;
243 message <<
"G4DataSet:: SaveData - cannot open " << fullFileName;
248 message.str().c_str());
254 out.setf(std::ofstream::left);
256 if (energies!=0 && data!=0)
258 G4DataVector::const_iterator i(energies->begin());
259 G4DataVector::const_iterator endI(energies->end());
260 G4DataVector::const_iterator j(data->begin());
266 out.setf(std::ofstream::left);
267 out << ((*i)/unitEnergies) <<
' ';
271 out.setf(std::ofstream::left);
272 out << ((*j)/unitData) << std::endl;
281 out.setf(std::ofstream::left);
286 out.setf(std::ofstream::left);
287 out << -1.f << std::endl;
291 out.setf(std::ofstream::left);
296 out.setf(std::ofstream::left);
297 out << -2.f << std::endl;
302size_t G4DataSet::FindLowerBound(
G4double x)
const
304 size_t lowerBound = 0;
305 size_t upperBound(energies->size() - 1);
307 while (lowerBound <= upperBound)
309 size_t midBin((lowerBound + upperBound) / 2);
311 if (x < (*energies)[midBin]) upperBound = midBin - 1;
312 else lowerBound = midBin + 1;
321 size_t lowerBound = 0;;
322 size_t upperBound(values->size() - 1);
324 while (lowerBound <= upperBound)
326 size_t midBin((lowerBound + upperBound) / 2);
328 if (x < (*values)[midBin]) upperBound = midBin - 1;
329 else lowerBound = midBin + 1;
338 char* path = std::getenv(
"G4PIIDATA");
343 "G4PIIDATA environment variable not set");
345 std::ostringstream fullFileName;
346 fullFileName << path <<
'/' <<
name << z <<
".dat";
348 return G4String(fullFileName.str().c_str());
352void G4DataSet::BuildPdf()
357 G4int nData = data->size();
363 for (i=1; i<nData; i++)
367 G4double sum = integrator.Legendre96(
this, &G4DataSet::IntegrationFunction, xLow, xHigh);
368 totalSum = totalSum + sum;
369 pdf->push_back(totalSum);
374 if (totalSum > 0.) tot = 1. / totalSum;
375 for (i=1; i<nData; i++)
377 (*pdf)[i] = (*pdf)[i] * tot;
390 "PDF has not been created for this data set");
396 size_t bin = FindLowerBound(x,pdf);
403 if (bin == 0) value = linearAlgo.
Calculate(x, bin, *pdf, *energies);
404 else value = algorithm->
Calculate(x, bin, *pdf, *energies);
417 size_t bin = FindLowerBound(x);
425 if (bin == 0) y = linearAlgo.
Calculate(x, bin, *energies, *data);
426 else y = algorithm->
Calculate(x, bin, *energies, *data);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
virtual void PrintData(void) const
virtual void SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)
G4DataSet(G4int argZ, G4IInterpolator *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
virtual G4double RandomSelect(G4int componentId=0) const
virtual G4bool SaveData(const G4String &fileName) const
virtual G4double FindValue(G4double x, G4int componentId=0) const
virtual G4bool LoadData(const G4String &fileName)
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0
G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const
const char * name(G4int ptype)