61 if (algorithm == 0)
G4Exception(
"G4DataSet::G4DataSet",
64 "Interpolation == 0");
65 if (randomSet) BuildPdf();
84 if (algorithm == 0)
G4Exception(
"G4DataSet::G4DataSet",
87 "Interpolation == 0");
89 if ((energies == 0) ^ (
data == 0))
93 "different size for energies and data (zero case)");
95 if (energies == 0)
return;
97 if (energies->size() !=
data->size())
101 "different size for energies and data");
103 if (randomSet) BuildPdf();
109 if (energies)
delete energies;
120 if (energies->empty())
return 0;
121 if (energy <= (*energies)[0])
return (*
data)[0];
123 size_t i = energies->size()-1;
124 if (energy >= (*energies)[i])
return (*
data)[i];
139 size_t size = energies->size();
140 for (
size_t i(0); i<size; i++)
142 G4cout <<
"Point: " << ((*energies)[i]/unitEnergies)
143 <<
" - Data value: " << ((*
data)[i]/unitData);
144 if (pdf != 0)
G4cout <<
" - PDF : " << (*pdf)[i];
155 if (energies)
delete energies;
161 if ((energies == 0) ^ (
data==0))
165 "different size for energies and data (zero case)");
167 if (energies == 0)
return;
169 if (energies->size() !=
data->size())
173 "different size for energies and data");
184 G4String fullFileName(FullFileName(fileName));
185 std::ifstream in(fullFileName);
190 std::ostringstream message;
191 message <<
"G4DataSet::LoadData - data file " << fullFileName <<
" not found";
196 message.str().c_str());
203 bool energyColumn(
true);
214 argEnergies->push_back(a*unitEnergies);
217 argData->push_back(a*unitData);
218 energyColumn=(!energyColumn);
224 if (randomSet) BuildPdf();
237 G4String fullFileName(FullFileName(name));
238 std::ofstream out(fullFileName);
243 std::ostringstream message;
244 message <<
"G4DataSet:: SaveData - cannot open " << fullFileName;
249 message.str().c_str());
255 out.setf(std::ofstream::left);
257 if (energies!=0 &&
data!=0)
259 G4DataVector::const_iterator i(energies->begin());
260 G4DataVector::const_iterator endI(energies->end());
261 G4DataVector::const_iterator j(
data->begin());
267 out.setf(std::ofstream::left);
268 out << ((*i)/unitEnergies) <<
' ';
272 out.setf(std::ofstream::left);
273 out << ((*j)/unitData) << std::endl;
282 out.setf(std::ofstream::left);
287 out.setf(std::ofstream::left);
288 out << -1.f << std::endl;
292 out.setf(std::ofstream::left);
297 out.setf(std::ofstream::left);
298 out << -2.f << std::endl;
303 size_t G4DataSet::FindLowerBound(
G4double x)
const
305 size_t lowerBound = 0;
306 size_t upperBound(energies->size() - 1);
308 while (lowerBound <= upperBound)
310 size_t midBin((lowerBound + upperBound) / 2);
312 if (x < (*energies)[midBin]) upperBound = midBin - 1;
313 else lowerBound = midBin + 1;
322 size_t lowerBound = 0;;
323 size_t upperBound(values->size() - 1);
325 while (lowerBound <= upperBound)
327 size_t midBin((lowerBound + upperBound) / 2);
329 if (x < (*values)[midBin]) upperBound = midBin - 1;
330 else lowerBound = midBin + 1;
339 char* path = getenv(
"G4PIIDATA");
344 "G4PIIDATA environment variable not set");
346 std::ostringstream fullFileName;
347 fullFileName << path <<
'/' << name << z <<
".dat";
349 return G4String(fullFileName.str().c_str());
353 void G4DataSet::BuildPdf()
364 for (i=1; i<nData; i++)
368 G4double sum = integrator.
Legendre96(
this, &G4DataSet::IntegrationFunction, xLow, xHigh);
369 totalSum = totalSum + sum;
370 pdf->push_back(totalSum);
375 if (totalSum > 0.) tot = 1. / totalSum;
376 for (i=1; i<nData; i++)
378 (*pdf)[i] = (*pdf)[i] * tot;
391 "PDF has not been created for this data set");
397 size_t bin = FindLowerBound(x,pdf);
404 if (bin == 0) value = linearAlgo.
Calculate(x, bin, *pdf, *energies);
405 else value = algorithm->
Calculate(x, bin, *pdf, *energies);
418 size_t bin = FindLowerBound(x);
426 if (bin == 0) y = linearAlgo.
Calculate(x, bin, *energies, *
data);
G4double Legendre96(T &typeT, F f, G4double a, G4double b)
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
virtual void PrintData(void) const
virtual G4bool LoadData(const G4String &fileName)
const XML_Char const XML_Char * data
virtual G4bool SaveData(const G4String &fileName) const
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
virtual G4double RandomSelect(G4int componentId=0) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual G4double FindValue(G4double x, G4int componentId=0) const
G4double energy(const ThreeVector &p, const G4double m)
G4DataSet(G4int argZ, G4IInterpolator *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
virtual void SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)