81 }
else if (randomSet) { BuildPdf(); }
102 if (algorithm == 0) {
105 }
else if ((energies == 0) ^ (data == 0)) {
107 "em1012",
FatalException,
"different size for energies and data (zero case)");
108 }
else if (energies->size() != data->size()) {
111 }
else if (randomSet) {
128 log_energies(dataLogX),
136 if (algorithm == 0) {
139 }
else if ((energies == 0) ^ (data == 0)) {
141 "em1012",
FatalException,
"different size for energies and data (zero case)");
142 }
else if (energies->size() != data->size()) {
145 }
else if ((log_energies == 0) ^ (log_data == 0)) {
147 "em1012",
FatalException,
"different size for log energies and log data (zero case)");
148 }
else if (log_energies->size() != log_data->size()) {
150 "em1012",
FatalException,
"different size for log energies and log data");
151 }
else if (randomSet) {
174 }
else if (energies->empty()) {
176 }
else if (energy <= (*energies)[0]) {
179 size_t i = energies->size()-1;
180 if (energy >= (*energies)[i]) {
return (*data)[i]; }
184 if (log_energies != 0)
186 return algorithm->
Calculate(energy, FindLowerBound(energy), *energies, *data, *log_energies, *log_data);
189 return algorithm->
Calculate(energy, FindLowerBound(energy), *energies, *data);
201 size_t size = energies->size();
202 for (
size_t i(0); i<size; i++)
204 G4cout <<
"Point: " << ((*energies)[i]/unitEnergies)
205 <<
" - Data value: " << ((*data)[i]/unitData);
206 if (pdf != 0)
G4cout <<
" - PDF : " << (*pdf)[i];
217 if (energies) {
delete energies; }
220 if (data) {
delete data; }
223 if ((energies == 0) ^ (data==0)) {
225 "em1012",
FatalException,
"different size for energies and data (zero case)");
227 }
else if (energies == 0) {
return; }
230 if (energies->size() != data->size()) {
243 if (energies) {
delete energies; }
245 if (data) {
delete data; }
248 if (log_energies) {
delete log_energies; }
249 log_energies = data_logX;
250 if (log_data) {
delete log_data; }
251 log_data = data_logY;
255 if(data || log_energies || log_data ) {
265 }
else if (energies->size() != data->size()) {
273 if ( !log_energies ) {
283 }
else if ((log_energies->size() != log_data->size()) || (log_energies->size() != data->size())) {
285 "em1012",
FatalException,
"different size for log energies and data");
300 G4String fullFileName(FullFileName(fileName));
301 std::ifstream in(fullFileName);
306 message += fullFileName;
307 message +=
"\" not found";
330 if (a != -1 && a != -2)
332 if (a==0.) { a=1e-300; }
333 if (b==0.) { b=1e-300; }
336 energies->push_back(a);
337 log_energies->push_back(std::log10(a));
339 log_data->push_back(std::log10(b));
344 if (randomSet) { BuildPdf(); }
358 G4String fullFileName(FullFileName(fileName));
359 std::ifstream in(fullFileName);
363 message += fullFileName;
364 message +=
"\" not found";
380 if (a != -1 && a != -2)
384 argEnergies->push_back(a*unitEnergies);
386 else if (k%nColumns == 1)
388 argData->push_back(a*unitData);
397 if (randomSet) BuildPdf();
412 G4String fullFileName(FullFileName(name));
413 std::ofstream out(fullFileName);
418 message+=fullFileName;
426 out.setf(std::ofstream::left);
428 if (energies!=0 && data!=0)
430 G4DataVector::const_iterator i(energies->begin());
431 G4DataVector::const_iterator endI(energies->end());
432 G4DataVector::const_iterator j(data->begin());
438 out.setf(std::ofstream::left);
439 out << ((*i)/unitEnergies) <<
' ';
443 out.setf(std::ofstream::left);
444 out << ((*j)/unitData) << std::endl;
453 out.setf(std::ofstream::left);
458 out.setf(std::ofstream::left);
459 out << -1.f << std::endl;
463 out.setf(std::ofstream::left);
468 out.setf(std::ofstream::left);
469 out << -2.f << std::endl;
476size_t G4EMDataSet::FindLowerBound(
G4double x)
const
478 size_t lowerBound = 0;
479 size_t upperBound(energies->size() - 1);
481 while (lowerBound <= upperBound)
483 size_t midBin((lowerBound + upperBound) / 2);
485 if (x < (*energies)[midBin]) upperBound = midBin - 1;
486 else lowerBound = midBin + 1;
495 size_t lowerBound = 0;;
496 size_t upperBound(values->size() - 1);
498 while (lowerBound <= upperBound)
500 size_t midBin((lowerBound + upperBound) / 2);
502 if (x < (*values)[midBin]) upperBound = midBin - 1;
503 else lowerBound = midBin + 1;
512 char* path = getenv(
"G4LEDATA");
518 std::ostringstream fullFileName;
519 fullFileName << path <<
'/' << name << z <<
".dat";
521 return G4String(fullFileName.str().c_str());
526void G4EMDataSet::BuildPdf()
531 G4int nData = data->size();
537 for (i=1; i<nData; i++)
541 G4double sum = integrator.Legendre96(
this, &G4EMDataSet::IntegrationFunction, xLow, xHigh);
542 totalSum = totalSum + sum;
543 pdf->push_back(totalSum);
548 if (totalSum > 0.) tot = 1. / totalSum;
549 for (i=1; i<nData; i++)
551 (*pdf)[i] = (*pdf)[i] * tot;
563 "em1012",
FatalException,
"PDF has not been created for this data set");
570 size_t bin = FindLowerBound(x,pdf);
577 if (bin == 0) value = linearAlgo.
Calculate(x, bin, *pdf, *energies);
578 else value = algorithm->
Calculate(x, bin, *pdf, *energies);
591 size_t bin = FindLowerBound(x);
599 if (bin == 0) y = linearAlgo.
Calculate(x, bin, *energies, *data);
600 else y = algorithm->
Calculate(x, bin, *energies, *data);
G4DLLIMPORT 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
virtual G4double Calculate(G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const =0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)