64 if (randomSet) BuildPdf();
87 if ((energies == 0) ^ (
data == 0))
88 G4Exception(
"G4RDEMDataSet::G4RDEMDataSet()",
"InvalidSetup",
89 FatalException,
"Different size for energies and data (zero case)!");
91 if (energies == 0)
return;
93 if (energies->size() !=
data->size())
94 G4Exception(
"G4RDEMDataSet::G4RDEMDataSet()",
"InvalidSetup",
97 if (randomSet) BuildPdf();
103 if (energies)
delete energies;
111 G4Exception(
"G4RDEMDataSet::FindValue()",
"InvalidSetup",
113 if (energies->empty())
return 0;
114 if (energy <= (*energies)[0])
return (*
data)[0];
116 size_t i = energies->size()-1;
117 if (energy >= (*energies)[i])
return (*
data)[i];
119 return algorithm->
Calculate(energy, FindLowerBound(energy), *energies, *
data);
131 size_t size = energies->size();
132 for (
size_t i(0); i<size; i++)
134 G4cout <<
"Point: " << ((*energies)[i]/unitEnergies)
135 <<
" - Data value: " << ((*
data)[i]/unitData);
136 if (pdf != 0)
G4cout <<
" - PDF : " << (*pdf)[i];
147 if (energies)
delete energies;
153 if ((energies == 0) ^ (
data==0))
154 G4Exception(
"G4RDEMDataSet::SetEnergiesData()",
"InvalidSetup",
155 FatalException,
"Different size for energies and data (zero case)!");
157 if (energies == 0)
return;
159 if (energies->size() !=
data->size())
160 G4Exception(
"G4RDEMDataSet::SetEnergiesData()",
"InvalidSetup",
172 G4String fullFileName(FullFileName(fileName));
173 std::ifstream in(fullFileName);
178 message += fullFileName;
179 message +=
"\" not found";
180 G4Exception(
"G4RDEMDataSet::LoadData()",
"DataNotFound",
188 bool energyColumn(
true);
197 argEnergies->push_back(a*unitEnergies);
199 argData->push_back(a*unitData);
200 energyColumn=(!energyColumn);
206 if (randomSet) BuildPdf();
219 G4String fullFileName(FullFileName(name));
220 std::ofstream out(fullFileName);
225 message+=fullFileName;
227 G4Exception(
"G4RDEMDataSet::SaveData()",
"CannotOpenFile",
235 if (energies!=0 &&
data!=0)
237 G4DataVector::const_iterator i(energies->begin());
238 G4DataVector::const_iterator endI(energies->end());
239 G4DataVector::const_iterator j(
data->begin());
246 out << ((*i)/unitEnergies) <<
' ';
251 out << ((*j)/unitData) << std::endl;
266 out << -1.f << std::endl;
276 out << -2.f << std::endl;
281 size_t G4RDEMDataSet::FindLowerBound(
G4double x)
const
283 size_t lowerBound = 0;
284 size_t upperBound(energies->size() - 1);
286 while (lowerBound <= upperBound)
288 size_t midBin((lowerBound + upperBound) / 2);
290 if (x < (*energies)[midBin]) upperBound = midBin - 1;
291 else lowerBound = midBin + 1;
300 size_t lowerBound = 0;;
301 size_t upperBound(values->size() - 1);
303 while (lowerBound <= upperBound)
305 size_t midBin((lowerBound + upperBound) / 2);
307 if (x < (*values)[midBin]) upperBound = midBin - 1;
308 else lowerBound = midBin + 1;
317 char* path = getenv(
"G4LEDATA");
319 G4Exception(
"G4RDEMDataSet::FullFileName()",
"InvalidSetup",
322 std::ostringstream fullFileName;
323 fullFileName << path <<
'/' << name << z <<
".dat";
325 return G4String(fullFileName.str().c_str());
329 void G4RDEMDataSet::BuildPdf()
340 for (i=1; i<nData; i++)
344 G4double sum = integrator.
Legendre96(
this, &G4RDEMDataSet::IntegrationFunction, xLow, xHigh);
345 totalSum = totalSum + sum;
346 pdf->push_back(totalSum);
351 if (totalSum > 0.) tot = 1. / totalSum;
352 for (i=1; i<nData; i++)
354 (*pdf)[i] = (*pdf)[i] * tot;
364 if (!pdf)
G4Exception(
"G4RDEMDataSet::RandomSelect()",
"InvalidSetup",
371 size_t bin = FindLowerBound(x,pdf);
378 if (bin == 0) value = linearAlgo.
Calculate(x, bin, *pdf, *energies);
379 else value = algorithm->
Calculate(x, bin, *pdf, *energies);
392 size_t bin = FindLowerBound(x);
400 if (bin == 0) y = linearAlgo.
Calculate(x, bin, *energies, *
data);
G4double Legendre96(T &typeT, F f, G4double a, G4double b)
virtual G4double RandomSelect(G4int componentId=0) const
std::vector< ExP01TrackerHit * > a
const XML_Char const XML_Char * data
G4RDEMDataSet(G4int argZ, G4RDVDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
virtual G4bool LoadData(const G4String &fileName)
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
virtual G4double FindValue(G4double x, G4int componentId=0) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4double energy(const ThreeVector &p, const G4double m)
G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const
virtual G4bool SaveData(const G4String &fileName) const
virtual void PrintData(void) const
virtual void SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0