81 }
else if (randomSet) { BuildPdf(); }
102 if (!algorithm || !energies || !
data) {
106 if (energies->size() !=
data->size()) {
109 }
else if (randomSet) {
127 log_energies(dataLogX),
135 if (!algorithm || !energies || !
data || !log_energies || !log_data) {
139 if ((energies->size() !=
data->size()) ||
140 (energies->size() != log_energies->size()) ||
141 (energies->size() != log_data->size())) {
144 }
else if (randomSet) {
162 if (energy <= (*energies)[0]) {
165 size_t i = energies->size()-1;
166 if (energy >= (*energies)[i]) {
return (*
data)[i]; }
170 if (log_energies != 0)
172 return algorithm->
Calculate(energy, FindLowerBound(energy), *energies, *
data, *log_energies, *log_data);
175 return algorithm->
Calculate(energy, FindLowerBound(energy), *energies, *
data);
180 size_t size = energies->size();
181 for (
size_t i(0); i<size; i++)
183 G4cout <<
"Point: " << ((*energies)[i]/unitEnergies)
184 <<
" - Data value: " << ((*
data)[i]/unitData);
185 if (pdf != 0)
G4cout <<
" - PDF : " << (*pdf)[i];
194 if(!dataX || !dataY) {
198 if (dataX->size() != dataY->size()) {
220 if(!dataX || !dataY || !data_logX || !data_logY) {
224 if (dataX->size() != dataY->size() ||
225 dataX->size() != data_logX->size() ||
226 dataX->size() != data_logY->size()) {
238 log_energies = data_logX;
241 log_data = data_logY;
256 G4String fullFileName(FullFileName(fileName));
257 std::ifstream in(fullFileName);
262 message += fullFileName;
263 message +=
"\" not found";
286 if (a != -1 && a != -2)
288 if (a==0.) { a=1e-300; }
289 if (b==0.) { b=1e-300; }
292 energies->push_back(a);
293 log_energies->push_back(std::log10(a));
295 log_data->push_back(std::log10(b));
300 if (randomSet) { BuildPdf(); }
314 G4String fullFileName(FullFileName(fileName));
315 std::ifstream in(fullFileName);
319 message += fullFileName;
320 message +=
"\" not found";
336 if (a != -1 && a != -2)
340 argEnergies->push_back(a*unitEnergies);
342 else if (k%nColumns == 1)
344 argData->push_back(a*unitData);
353 if (randomSet) BuildPdf();
368 G4String fullFileName(FullFileName(name));
369 std::ofstream out(fullFileName);
374 message+=fullFileName;
382 out.setf(std::ofstream::left);
384 if (energies!=0 &&
data!=0)
386 G4DataVector::const_iterator i(energies->begin());
387 G4DataVector::const_iterator endI(energies->end());
388 G4DataVector::const_iterator j(
data->begin());
394 out.setf(std::ofstream::left);
395 out << ((*i)/unitEnergies) <<
' ';
399 out.setf(std::ofstream::left);
400 out << ((*j)/unitData) << std::endl;
409 out.setf(std::ofstream::left);
414 out.setf(std::ofstream::left);
415 out << -1.f << std::endl;
419 out.setf(std::ofstream::left);
424 out.setf(std::ofstream::left);
425 out << -2.f << std::endl;
432 size_t G4EMDataSet::FindLowerBound(
G4double x)
const
434 size_t lowerBound = 0;
435 size_t upperBound(energies->size() - 1);
437 while (lowerBound <= upperBound)
439 size_t midBin((lowerBound + upperBound) / 2);
441 if (x < (*energies)[midBin]) upperBound = midBin - 1;
442 else lowerBound = midBin + 1;
451 size_t lowerBound = 0;;
452 size_t upperBound(values->size() - 1);
454 while (lowerBound <= upperBound)
456 size_t midBin((lowerBound + upperBound) / 2);
458 if (x < (*values)[midBin]) upperBound = midBin - 1;
459 else lowerBound = midBin + 1;
468 char* path = getenv(
"G4LEDATA");
474 std::ostringstream fullFileName;
475 fullFileName << path <<
'/' << name << z <<
".dat";
477 return G4String(fullFileName.str().c_str());
482 void G4EMDataSet::BuildPdf()
493 for (i=1; i<nData; i++)
497 G4double sum = integrator.
Legendre96(
this, &G4EMDataSet::IntegrationFunction, xLow, xHigh);
498 totalSum = totalSum + sum;
499 pdf->push_back(totalSum);
504 if (totalSum > 0.) tot = 1. / totalSum;
505 for (i=1; i<nData; i++)
507 (*pdf)[i] = (*pdf)[i] * tot;
519 "em1012",
FatalException,
"PDF has not been created for this data set");
526 size_t bin = FindLowerBound(x,pdf);
533 if (bin == 0) value = linearAlgo.
Calculate(x, bin, *pdf, *energies);
534 else value = algorithm->
Calculate(x, bin, *pdf, *energies);
547 size_t bin = FindLowerBound(x);
555 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 void SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0
const XML_Char const XML_Char * data
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
virtual G4double FindValue(G4double x, G4int componentId=0) const
virtual G4bool SaveData(const G4String &fileName) const
virtual void PrintData(void) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4EMDataSet(G4int argZ, G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
virtual G4bool LoadData(const G4String &fileName)
G4double energy(const ThreeVector &p, const G4double m)
virtual G4double RandomSelect(G4int componentId=0) const
virtual void SetLogEnergiesData(G4DataVector *xData, G4DataVector *data, G4DataVector *xLogData, G4DataVector *Logdata, G4int componentId)
virtual G4bool LoadNonLogData(const G4String &fileName)