68 log_energies(nullptr),
77 if (algorithm ==
nullptr) {
80 }
else if (randomSet) { BuildPdf(); }
94 log_energies(nullptr),
103 if (!algorithm || !energies || !data) {
107 if (energies->size() != data->size()) {
110 }
else if (randomSet) {
129 log_energies(dataLogX),
138 if (!algorithm || !energies || !data || !log_energies || !log_data) {
142 if ((energies->size() != data->size()) ||
143 (energies->size() != log_energies->size()) ||
144 (energies->size() != log_data->size())) {
147 }
else if (randomSet) {
169 if (energy <= (*energies)[0]) {
172 std::size_t i = energies->size()-1;
173 if (energy >= (*energies)[i]) {
return (*data)[i]; }
177 if (log_energies !=
nullptr)
179 return algorithm->
Calculate(energy, (
G4int)FindLowerBound(energy), *energies, *data, *log_energies, *log_data);
182 return algorithm->
Calculate(energy, (
G4int)FindLowerBound(energy), *energies, *data);
189 std::size_t size = energies->size();
190 for (std::size_t i(0); i<size; ++i)
192 G4cout <<
"Point: " << ((*energies)[i]/unitEnergies)
193 <<
" - Data value: " << ((*data)[i]/unitData);
194 if (pdf != 0)
G4cout <<
" - PDF : " << (*pdf)[i];
205 if(!dataX || !dataY) {
209 if (dataX->size() != dataY->size()) {
233 if(!dataX || !dataY || !data_logX || !data_logY) {
237 if (dataX->size() != dataY->size() ||
238 dataX->size() != data_logX->size() ||
239 dataX->size() != data_logY->size()) {
251 log_energies = data_logX;
254 log_data = data_logY;
271 G4String fullFileName(FullFileName(fileName));
272 std::ifstream in(fullFileName);
277 message += fullFileName;
278 message +=
"\" not found";
298 if (a != -1 && a != -2)
300 if (a==0.) { a=1e-300; }
301 if (b==0.) { b=1e-300; }
304 energies->push_back(a);
305 log_energies->push_back(std::log10(a));
307 log_data->push_back(std::log10(b));
312 if (randomSet) { BuildPdf(); }
327 G4String fullFileName(FullFileName(fileName));
328 std::ifstream in(fullFileName);
332 message += fullFileName;
333 message +=
"\" not found";
349 if (a != -1 && a != -2)
353 argEnergies->push_back(a*unitEnergies);
355 else if (k%nColumns == 1)
357 argData->push_back(a*unitData);
366 if (randomSet) BuildPdf();
381 G4String fullFileName(FullFileName(name));
382 std::ofstream out(fullFileName);
387 message+=fullFileName;
395 out.setf(std::ofstream::left);
397 if (energies!=0 && data!=0)
399 G4DataVector::const_iterator i(energies->begin());
400 G4DataVector::const_iterator endI(energies->end());
401 G4DataVector::const_iterator j(data->begin());
407 out.setf(std::ofstream::left);
408 out << ((*i)/unitEnergies) <<
' ';
412 out.setf(std::ofstream::left);
413 out << ((*j)/unitData) << std::endl;
422 out.setf(std::ofstream::left);
427 out.setf(std::ofstream::left);
428 out << -1.f << std::endl;
432 out.setf(std::ofstream::left);
437 out.setf(std::ofstream::left);
438 out << -2.f << std::endl;
445std::size_t G4EMDataSet::FindLowerBound(
G4double x)
const
447 std::size_t lowerBound = 0;
448 std::size_t upperBound(energies->size() - 1);
450 while (lowerBound <= upperBound)
452 std::size_t midBin((lowerBound + upperBound) / 2);
454 if (x < (*energies)[midBin]) upperBound = midBin - 1;
455 else lowerBound = midBin + 1;
465 std::size_t lowerBound = 0;;
466 std::size_t upperBound(values->size() - 1);
468 while (lowerBound <= upperBound)
470 std::size_t midBin((lowerBound + upperBound) / 2);
472 if (x < (*values)[midBin]) upperBound = midBin - 1;
473 else lowerBound = midBin + 1;
489 std::ostringstream fullFileName;
490 fullFileName << path <<
'/' <<
name << z <<
".dat";
492 return G4String(fullFileName.str().c_str());
497void G4EMDataSet::BuildPdf()
502 std::size_t nData = data->size();
508 for (i=1; i<nData; ++i)
512 G4double sum = integrator.Legendre96(
this, &G4EMDataSet::IntegrationFunction, xLow, xHigh);
513 totalSum = totalSum + sum;
514 pdf->push_back(totalSum);
519 if (totalSum > 0.) tot = 1. / totalSum;
520 for (i=1; i<nData; ++i)
522 (*pdf)[i] = (*pdf)[i] * tot;
536 "em1012",
FatalException,
"PDF has not been created for this data set");
549 if (bin == 0) value = linearAlgo.
Calculate(x, bin, *pdf, *energies);
550 else value = algorithm->
Calculate(x, bin, *pdf, *energies);
571 if (bin == 0) y = linearAlgo.
Calculate(x, bin, *energies, *data);
572 else y = algorithm->
Calculate(x, bin, *energies, *data);
const char * G4FindDataDir(const char *)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
G4EMDataSet(G4int argZ, G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double yUnit=CLHEP::barn, G4bool random=false)
virtual G4bool LoadNonLogData(const G4String &fileName)
virtual void SetLogEnergiesData(G4DataVector *xData, G4DataVector *data, G4DataVector *xLogData, G4DataVector *Logdata, G4int componentId)
virtual G4bool SaveData(const G4String &fileName) const
virtual G4double RandomSelect(G4int componentId=0) const
virtual G4bool LoadData(const G4String &fileName)
virtual void SetEnergiesData(G4DataVector *xData, G4DataVector *data, G4int componentId)
virtual G4double FindValue(G4double x, G4int componentId=0) const
virtual void PrintData(void) const
G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const override
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0
const char * name(G4int ptype)