43 algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
62 G4String fullFileName(FullFileName(argFileName));
63 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
68 message+=fullFileName;
69 message+=
"\" not found";
70 G4Exception(
"G4MicroElecCrossSectionDataSet::LoadData",
"em0003",
75 std::vector<G4DataVector *> columns;
76 std::vector<G4DataVector *> log_columns;
78 std::stringstream *stream(
new std::stringstream);
99 while (!stream->eof())
103 while (i>=columns.size())
109 columns[i]->push_back(value);
123 if (value <=0.) value = 1e-300;
124 log_columns[i]->push_back(std::log10(value));
130 stream=
new std::stringstream;
148 if (comment) {
break; }
149 if (space && (!first)) { (*stream) <<
' '; }
157 catch(
const std::ios::failure &e)
165 std::vector<G4DataVector *>::size_type maxI(columns.size());
170 message+=fullFileName;
171 message+=
"\" should have at least two columns";
172 G4Exception(
"G4MicroElecCrossSectionDataSet::LoadData",
"em0005",
177 std::vector<G4DataVector*>::size_type i(1);
180 G4DataVector::size_type maxJ(columns[i]->size());
182 if (maxJ!=columns[0]->size())
185 message+=fullFileName;
186 message+=
"\" has lines with a different number of columns";
187 G4Exception(
"G4MicroElecCrossSectionDataSet::LoadData",
"em0005",
192 G4DataVector::size_type j(0);
201 argEnergies->push_back(columns[0]->
operator[] (j)*GetUnitEnergies());
202 argData->push_back(columns[i]->
operator[] (j)*GetUnitData());
203 argLogEnergies->push_back(log_columns[0]->
operator[] (j) + std::log10(GetUnitEnergies()));
204 argLogData->push_back(log_columns[i]->
operator[] (j) + std::log10(GetUnitData()));
208 AddComponent(
new G4EMDataSet(i-1, argEnergies, argData, argLogEnergies, argLogData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
218 delete log_columns[i];
229 G4String fullFileName(FullFileName(argFileName));
230 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
235 message+=fullFileName;
236 message+=
"\" not found";
237 G4Exception(
"G4MicroElecCrossSectionDataSet::LoadData",
"em0003",
242 std::vector<G4DataVector *> columns;
244 std::stringstream *stream(
new std::stringstream);
265 while (!stream->eof())
269 while (i>=columns.size())
274 columns[i]->push_back(value);
280 stream=
new std::stringstream;
298 if (comment) {
break; }
299 if (space && (!first)) { (*stream) <<
' '; }
307 catch(
const std::ios::failure &e)
315 std::vector<G4DataVector *>::size_type maxI(columns.size());
320 message+=fullFileName;
321 message+=
"\" should have at least two columns";
322 G4Exception(
"G4MicroElecCrossSectionDataSet::LoadData",
"em0005",
327 std::vector<G4DataVector*>::size_type i(1);
330 G4DataVector::size_type maxJ(columns[i]->size());
332 if (maxJ!=columns[0]->size())
335 message+=fullFileName;
336 message+=
"\" has lines with a different number of columns.";
337 G4Exception(
"G4MicroElecCrossSectionDataSet::LoadData",
"em0005",
342 G4DataVector::size_type j(0);
349 argEnergies->push_back(columns[0]->
operator[] (j)*GetUnitEnergies());
350 argData->push_back(columns[i]->
operator[] (j)*GetUnitData());
354 AddComponent(
new G4EMDataSet(i-1, argEnergies, argData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
376 G4Exception(
"G4MicroElecCrossSectionDataSet::SaveData",
"em0005",
382 G4String fullFileName(FullFileName(argFileName));
383 std::ofstream out(fullFileName);
388 message+=fullFileName;
390 G4Exception(
"G4MicroElecCrossSectionDataSet::SaveData",
"em0005",
397 G4DataVector::const_iterator * iData(
new G4DataVector::const_iterator[n]);
407 while (iEnergies!=iEnergiesEnd)
411 out.setf(std::ofstream::left);
412 out << ((*iEnergies)/GetUnitEnergies());
421 out.setf(std::ofstream::left);
422 out << ((*(iData[k]))/GetUnitData());
439G4String G4MicroElecCrossSectionDataSet::FullFileName(
const G4String& argFileName)
const
441 char* path = std::getenv(
"G4LEDATA");
444 G4Exception(
"G4MicroElecCrossSectionDataSet::FullFileName",
"em0006",
450 std::ostringstream fullFileName;
452 fullFileName << path <<
"/" << argFileName <<
".dat";
454 return G4String(fullFileName.str().c_str());
463 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
464 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
468 value+=(*i)->FindValue(argEnergy);
480 G4cout <<
"The data set has " << n <<
" components" <<
G4endl;
496 G4int argComponentId)
506 std::ostringstream message;
507 message <<
"Component " << argComponentId <<
" not found";
509 G4Exception(
"G4MicroElecCrossSectionDataSet::SetEnergiesData",
"em0005",
519 G4int argComponentId)
529 std::ostringstream message;
530 message <<
"Component " << argComponentId <<
" not found";
532 G4Exception(
"G4MicroElecCrossSectionDataSet::SetLogEnergiesData",
"em0005",
538void G4MicroElecCrossSectionDataSet::CleanUpComponents()
540 while (!components.empty())
542 if (components.back())
delete components.back();
543 components.pop_back();
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
virtual G4bool LoadData(const G4String &argFileName)
virtual ~G4MicroElecCrossSectionDataSet()
virtual const G4DataVector & GetEnergies(G4int componentId) const
virtual G4bool LoadNonLogData(const G4String &argFileName)
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *values, G4int componentId)
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *values, G4DataVector *log_x, G4DataVector *log_values, G4int componentId)
virtual void PrintData(void) const
virtual void AddComponent(G4VEMDataSet *dataSet)
virtual G4bool SaveData(const G4String &argFileName) const
virtual size_t NumberOfComponents(void) const
virtual G4double FindValue(G4double e, G4int componentId=0) const
G4MicroElecCrossSectionDataSet(G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual const G4DataVector & GetData(G4int componentId) const =0
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0
virtual void PrintData(void) const =0