106 : interpolation(algorithm), eMin(minE), eMax(maxE),
107 unit1(unitE), unit2(unitData), zMin(minZ), zMax(maxZ),
110 crossSections =
nullptr;
118 delete interpolation;
119 interpolation =
nullptr;
121 for (
auto & pos : dataMap)
127 if (crossSections !=
nullptr)
129 std::size_t n = crossSections->size();
130 for (std::size_t i=0; i<n; i++)
132 delete (*crossSections)[i];
134 delete crossSections;
135 crossSections =
nullptr;
147 if (algorithm !=
nullptr)
149 delete interpolation;
150 interpolation = algorithm;
154 delete interpolation;
160 nBins = numberOfBins;
171 for (
auto & pos : dataMap)
175 G4cout <<
"---- Data set for Z = "
179 G4cout <<
"--------------------------------------------------" <<
G4endl;
187 std::size_t nZ = activeZ.size();
188 for (std::size_t i=0; i<nZ; ++i)
201 std::ostringstream ost;
202 ost << path <<
'/' << fileName << Z <<
".dat";
203 std::ifstream file(ost.str().c_str());
204 std::filebuf* lsdp = file.rdbuf();
206 if (! (lsdp->is_open()) )
208 G4String excep =
"data file: " + ost.str() +
" not found";
233 if (a != -1 && a != -2)
237 orig_reg_energies->push_back(a*unit1);
238 log_reg_energies->push_back(std::log10(a)+std::log10(unit1));
240 else if (k%nColumns == 1)
242 orig_reg_data->push_back(a*unit2);
243 log_reg_data->push_back(std::log10(a)+std::log10(unit2));
253 log_reg_energies,log_reg_data,algo);
254 dataMap[Z] = dataSet;
262 std::size_t nZ = activeZ.size();
263 for (std::size_t i=0; i<nZ; ++i)
271 G4Exception(
"G4VCrossSectionHandler::LoadNonLogData",
276 std::ostringstream ost;
277 ost << path <<
'/' << fileName << Z <<
".dat";
278 std::ifstream file(ost.str().c_str());
279 std::filebuf* lsdp = file.rdbuf();
281 if (! (lsdp->is_open()) )
283 G4String excep =
"data file: " + ost.str() +
" not found";
284 G4Exception(
"G4VCrossSectionHandler::LoadNonLogData",
304 if (a != -1 && a != -2)
308 orig_reg_energies->push_back(a*unit1);
310 else if (k%nColumns == 1)
312 orig_reg_data->push_back(a*unit2);
323 dataMap[Z] = dataSet;
331 std::size_t nZ = activeZ.size();
332 for (std::size_t i=0; i<nZ; ++i)
339 dataMap[Z] = dataSet;
348 if(! dataMap.empty())
350 for (
auto & pos : dataMap)
356 dataMap[i] =
nullptr;
370 auto pos = dataMap.find(Z);
371 if (pos!= dataMap.end())
378 G4cout <<
"WARNING: G4VCrossSectionHandler::FindValue did not find Z = "
387 G4int shellIndex)
const
390 auto pos = dataMap.find(Z);
391 if (pos!= dataMap.cend())
397 if(shellIndex < nComponents)
401 G4cout <<
"WARNING: G4VCrossSectionHandler::FindValue did not find"
402 <<
" shellIndex= " << shellIndex
412 G4cout <<
"WARNING: G4VCrossSectionHandler::FindValue did not find Z = "
428 for (std::size_t i=0 ; i<nElements ; ++i)
430 G4int Z = (
G4int) (*elementVector)[i]->GetZ();
432 G4double nAtomsVol = nAtomsPerVolume[i];
433 value += nAtomsVol * elementValue;
446 G4double dBin = std::log10(eMax/eMin) / nBins;
448 for (
G4int i=0; i<nBins+1; i++)
450 energyVector.push_back(std::pow(10., std::log10(eMin)+i*dBin));
456 if (crossSections !=
nullptr)
458 if (! crossSections->empty())
460 for (
auto mat=crossSections->begin(); mat != crossSections->end(); ++mat)
466 crossSections->clear();
467 delete crossSections;
468 crossSections =
nullptr;
474 if (crossSections ==
nullptr)
476 G4Exception(
"G4VCrossSectionHandler::BuildMeanFreePathForMaterials",
493 for (
G4int mLocal=0; mLocal<numOfCouples; ++mLocal)
499 for (
G4int bin=0; bin<nBins; bin++)
501 G4double energy = energyVector[bin];
502 energies->push_back(energy);
503 log_energies->push_back(std::log10(energy));
505 G4double materialCrossSection = 0.0;
507 for(
G4int j=0; j<nElm; ++j) {
511 if (materialCrossSection > 0.)
513 data->push_back(1./materialCrossSection);
514 log_data->push_back(std::log10(1./materialCrossSection));
519 log_data->push_back(std::log10(
DBL_MAX));
548 std::size_t materialIndex = couple->
GetIndex();
550 G4VEMDataSet* materialSet = (*crossSections)[materialIndex];
551 G4double materialCrossSection0 = 0.0;
554 for (
G4int i=0; i < nElements; i++ )
557 materialCrossSection0 += cr;
558 cross.push_back(materialCrossSection0);
562 for (
G4int k=0 ; k < nElements ; k++ )
564 if (random <= cross[k])
return (
G4int) (*elementVector)[k]->GetZ();
585 return (*elementVector)[0];
591 std::size_t materialIndex = couple->
GetIndex();
593 G4VEMDataSet* materialSet = (*crossSections)[materialIndex];
594 G4double materialCrossSection0 = 0.0;
597 for (
G4int i=0; i<nElements; ++i)
600 materialCrossSection0 += cr;
601 cross.push_back(materialCrossSection0);
606 for (
G4int k=0 ; k < nElements ; ++k )
608 if (random <= cross[k])
return (*elementVector)[k];
611 G4cout <<
"G4VCrossSectionHandler::SelectRandomElement - no element found" <<
G4endl;
631 auto pos = dataMap.find(Z);
632 if (pos != dataMap.end())
633 dataSet = (*pos).second;
636 G4Exception(
"G4VCrossSectionHandler::SelectRandomShell",
642 for (
G4int i=0; i<nShells; ++i)
645 if (shellDataSet !=
nullptr)
649 if (random <= partialSum)
return i;
661 if (materialTable ==
nullptr)
662 G4Exception(
"G4VCrossSectionHandler::ActiveElements",
667 for (std::size_t mLocal2=0; mLocal2<nMaterials; ++mLocal2)
669 const G4Material* material= (*materialTable)[mLocal2];
673 for (std::size_t iEl=0; iEl<nElements; ++iEl)
675 G4double Z = (*elementVector)[iEl]->GetZ();
676 if (!(activeZ.
contains(Z)) && Z >= zMin && Z <= zMax)
678 activeZ.push_back(Z);
698 auto pos = dataMap.find(Z);
699 if (pos!= dataMap.end())
706 G4cout <<
"WARNING: G4VCrossSectionHandler::NumberOfComponents did not "
std::vector< const G4Element * > G4ElementVector
const char * G4FindDataDir(const char *)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4Material * > G4MaterialTable
G4GLOB_DLL std::ostream G4cout
G4bool contains(const G4double &) const
const G4Material * GetMaterial() const
const G4ElementVector * GetElementVector() const
static std::size_t GetNumberOfMaterials()
const G4double * GetVecNbOfAtomsPerVolume() const
static G4MaterialTable * GetMaterialTable()
std::size_t GetNumberOfElements() const
std::size_t GetTableSize() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4double ValueForMaterial(const G4Material *material, G4double e) const
void LoadShellData(const G4String &dataFile)
G4VEMDataSet * BuildMeanFreePathForMaterials(const G4DataVector *energyCuts=nullptr)
G4double FindValue(G4int Z, G4double e) const
virtual ~G4VCrossSectionHandler()
G4int NumberOfComponents(G4int Z) const
virtual std::vector< G4VEMDataSet * > * BuildCrossSectionsForMaterials(const G4DataVector &energyVector, const G4DataVector *energyCuts=nullptr)=0
void LoadData(const G4String &dataFile)
void LoadNonLogData(const G4String &dataFile)
G4int SelectRandomAtom(const G4MaterialCutsCouple *couple, G4double e) const
G4int SelectRandomShell(G4int Z, G4double e) const
const G4Element * SelectRandomElement(const G4MaterialCutsCouple *material, G4double e) const
void Initialise(G4VDataSetAlgorithm *interpolation=nullptr, G4double minE=250 *CLHEP::eV, G4double maxE=100 *CLHEP::GeV, G4int numberOfBins=200, G4double unitE=CLHEP::MeV, G4double unitData=CLHEP::barn, G4int minZ=1, G4int maxZ=99)
virtual G4VDataSetAlgorithm * CreateInterpolation()
virtual G4VDataSetAlgorithm * Clone() const =0
virtual const G4VEMDataSet * GetComponent(G4int componentId) const =0
virtual G4double FindValue(G4double x, G4int componentId=0) const =0
virtual void AddComponent(G4VEMDataSet *dataSet)=0
virtual size_t NumberOfComponents(void) const =0
virtual G4bool LoadData(const G4String &fileName)=0
virtual void PrintData(void) const =0