41 algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
58 G4String fullFileName(FullFileName(argFileName));
59 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
64 message+=fullFileName;
65 message+=
"\" not found";
66 G4Exception(
"G4MuElecCrossSectionDataSet::LoadData",
"em0003",
71 std::vector<G4DataVector *> columns;
72 std::vector<G4DataVector *> log_columns;
74 std::stringstream *stream(
new std::stringstream);
95 while (!stream->eof())
99 while (i>=columns.size())
105 columns[i]->push_back(value);
119 if (value <=0.) value = 1e-300;
120 log_columns[i]->push_back(std::log10(value));
126 stream=
new std::stringstream;
144 if (comment) {
break; }
145 if (space && (!first)) { (*stream) <<
' '; }
153 catch(
const std::ios::failure &e)
161 std::vector<G4DataVector *>::size_type maxI(columns.size());
166 message+=fullFileName;
167 message+=
"\" should have at least two columns";
168 G4Exception(
"G4MuElecCrossSectionDataSet::LoadData",
"em0005",
173 std::vector<G4DataVector*>::size_type i(1);
176 G4DataVector::size_type maxJ(columns[i]->size());
178 if (maxJ!=columns[0]->size())
181 message+=fullFileName;
182 message+=
"\" has lines with a different number of columns";
183 G4Exception(
"G4MuElecCrossSectionDataSet::LoadData",
"em0005",
188 G4DataVector::size_type j(0);
197 argEnergies->push_back(columns[0]->
operator[] (j)*GetUnitEnergies());
198 argData->push_back(columns[i]->
operator[] (j)*GetUnitData());
199 argLogEnergies->push_back(log_columns[0]->
operator[] (j) + std::log10(GetUnitEnergies()));
200 argLogData->push_back(log_columns[i]->
operator[] (j) + std::log10(GetUnitData()));
204 AddComponent(
new G4EMDataSet(i-1, argEnergies, argData, argLogEnergies, argLogData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
214 delete log_columns[i];
225 G4String fullFileName(FullFileName(argFileName));
226 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
231 message+=fullFileName;
232 message+=
"\" not found";
233 G4Exception(
"G4MuElecCrossSectionDataSet::LoadData",
"em0003",
238 std::vector<G4DataVector *> columns;
240 std::stringstream *stream(
new std::stringstream);
261 while (!stream->eof())
265 while (i>=columns.size())
270 columns[i]->push_back(value);
276 stream=
new std::stringstream;
294 if (comment) {
break; }
295 if (space && (!first)) { (*stream) <<
' '; }
303 catch(
const std::ios::failure &e)
311 std::vector<G4DataVector *>::size_type maxI(columns.size());
316 message+=fullFileName;
317 message+=
"\" should have at least two columns";
318 G4Exception(
"G4MuElecCrossSectionDataSet::LoadData",
"em0005",
323 std::vector<G4DataVector*>::size_type i(1);
326 G4DataVector::size_type maxJ(columns[i]->size());
328 if (maxJ!=columns[0]->size())
331 message+=fullFileName;
332 message+=
"\" has lines with a different number of columns.";
333 G4Exception(
"G4MuElecCrossSectionDataSet::LoadData",
"em0005",
338 G4DataVector::size_type j(0);
345 argEnergies->push_back(columns[0]->
operator[] (j)*GetUnitEnergies());
346 argData->push_back(columns[i]->
operator[] (j)*GetUnitData());
350 AddComponent(
new G4EMDataSet(i-1, argEnergies, argData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
372 G4Exception(
"G4MuElecCrossSectionDataSet::SaveData",
"em0005",
378 G4String fullFileName(FullFileName(argFileName));
379 std::ofstream out(fullFileName);
384 message+=fullFileName;
386 G4Exception(
"G4MuElecCrossSectionDataSet::SaveData",
"em0005",
393 G4DataVector::const_iterator * iData(
new G4DataVector::const_iterator[n]);
403 while (iEnergies!=iEnergiesEnd)
408 out << ((*iEnergies)/GetUnitEnergies());
418 out << ((*(iData[k]))/GetUnitData());
435 G4String G4MuElecCrossSectionDataSet::FullFileName(
const G4String& argFileName)
const
437 char* path = getenv(
"G4LEDATA");
440 G4Exception(
"G4MuElecCrossSectionDataSet::FullFileName",
"em0006",
446 std::ostringstream fullFileName;
448 fullFileName << path <<
"/" << argFileName <<
".dat";
450 return G4String(fullFileName.str().c_str());
459 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
460 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
464 value+=(*i)->FindValue(argEnergy);
476 G4cout <<
"The data set has " << n <<
" components" <<
G4endl;
492 G4int argComponentId)
502 std::ostringstream message;
503 message <<
"Component " << argComponentId <<
" not found";
505 G4Exception(
"G4MuElecCrossSectionDataSet::SetEnergiesData",
"em0005",
515 G4int argComponentId)
525 std::ostringstream message;
526 message <<
"Component " << argComponentId <<
" not found";
528 G4Exception(
"G4MuElecCrossSectionDataSet::SetLogEnergiesData",
"em0005",
534 void G4MuElecCrossSectionDataSet::CleanUpComponents()
536 while (!components.empty())
538 if (components.back())
delete components.back();
539 components.pop_back();
virtual ~G4MuElecCrossSectionDataSet()
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual G4double FindValue(G4double e, G4int componentId=0) const
virtual size_t NumberOfComponents(void) const
virtual const G4DataVector & GetData(G4int componentId) const =0
virtual const G4DataVector & GetEnergies(G4int componentId) const
virtual G4bool LoadData(const G4String &argFileName)
virtual void PrintData(void) const
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *values, G4DataVector *log_x, G4DataVector *log_values, G4int componentId)
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual void PrintData(void) const =0
G4MuElecCrossSectionDataSet(G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
virtual G4bool SaveData(const G4String &argFileName) const
virtual G4bool LoadNonLogData(const G4String &argFileName)
virtual void AddComponent(G4VEMDataSet *dataSet)
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *values, G4int componentId)