104 : interpolation(algorithm), eMin(minE), eMax(maxE), nBins(bins),
105 unit1(unitE), unit2(unitData), zMin(minZ), zMax(maxZ)
113 delete interpolation;
115 std::map<G4int,G4VEMDataSet*,std::less<G4int> >::iterator pos;
117 for (pos = dataMap.begin(); pos != dataMap.end(); ++pos)
127 if (crossSections != 0)
129 size_t n = crossSections->size();
130 for (
size_t i=0; i<n; i++)
132 delete (*crossSections)[i];
134 delete crossSections;
147 delete interpolation;
148 interpolation = algorithm;
152 delete interpolation;
158 nBins = numberOfBins;
167 std::map<G4int,G4VEMDataSet*,std::less<G4int> >::const_iterator pos;
169 for (pos = dataMap.begin(); pos != dataMap.end(); pos++)
176 G4int z = (*pos).first;
178 G4cout <<
"---- Data set for Z = "
182 G4cout <<
"--------------------------------------------------" <<
G4endl;
188 size_t nZ = activeZ.size();
189 for (
size_t i=0; i<nZ; i++)
195 char* path = std::getenv(
"G4LEDATA");
203 std::ostringstream ost;
204 ost << path <<
'/' << fileName << Z <<
".dat";
205 std::ifstream file(ost.str().c_str());
206 std::filebuf* lsdp = file.rdbuf();
208 if (! (lsdp->is_open()) )
210 G4String excep =
"data file: " + ost.str() +
" not found";
235 if (a != -1 && a != -2)
239 orig_reg_energies->push_back(a*unit1);
240 log_reg_energies->push_back(std::log10(a)+std::log10(unit1));
242 else if (k%nColumns == 1)
244 orig_reg_data->push_back(a*unit2);
245 log_reg_data->push_back(std::log10(a)+std::log10(unit2));
257 dataMap[Z] = dataSet;
265 size_t nZ = activeZ.size();
266 for (
size_t i=0; i<nZ; i++)
272 char* path = std::getenv(
"G4LEDATA");
275 G4Exception(
"G4VCrossSectionHandler::LoadNonLogData",
280 std::ostringstream ost;
281 ost << path <<
'/' << fileName << Z <<
".dat";
282 std::ifstream file(ost.str().c_str());
283 std::filebuf* lsdp = file.rdbuf();
285 if (! (lsdp->is_open()) )
287 G4String excep =
"data file: " + ost.str() +
" not found";
288 G4Exception(
"G4VCrossSectionHandler::LoadNonLogData",
308 if (a != -1 && a != -2)
312 orig_reg_energies->push_back(a*unit1);
314 else if (k%nColumns == 1)
316 orig_reg_data->push_back(a*unit2);
328 dataMap[Z] = dataSet;
335 size_t nZ = activeZ.size();
336 for (
size_t i=0; i<nZ; i++)
345 dataMap[Z] = dataSet;
355 std::map<G4int,G4VEMDataSet*,std::less<G4int> >::iterator pos;
357 if(! dataMap.empty())
359 for (pos = dataMap.begin(); pos != dataMap.end(); ++pos)
368 G4int i = (*pos).first;
382 std::map<G4int,G4VEMDataSet*,std::less<G4int> >::const_iterator pos;
383 pos = dataMap.find(Z);
384 if (pos!= dataMap.end())
395 G4cout <<
"WARNING: G4VCrossSectionHandler::FindValue did not find Z = "
402 G4int shellIndex)
const
406 std::map<G4int,G4VEMDataSet*,std::less<G4int> >::const_iterator pos;
407 pos = dataMap.find(Z);
408 if (pos!= dataMap.end())
418 if(shellIndex < nComponents)
423 G4cout <<
"WARNING: G4VCrossSectionHandler::FindValue did not find"
424 <<
" shellIndex= " << shellIndex
434 G4cout <<
"WARNING: G4VCrossSectionHandler::FindValue did not find Z = "
450 for (
G4int i=0 ; i<nElements ; i++)
452 G4int Z = (
G4int) (*elementVector)[i]->GetZ();
454 G4double nAtomsVol = nAtomsPerVolume[i];
455 value += nAtomsVol * elementValue;
468 G4double dBin = std::log10(eMax/eMin) / nBins;
470 for (
G4int i=0; i<nBins+1; i++)
472 energyVector.push_back(std::pow(10., std::log10(eMin)+i*dBin));
478 if (crossSections != 0)
480 std::vector<G4VEMDataSet*>::iterator mat;
481 if (! crossSections->empty())
483 for (mat = crossSections->begin(); mat!= crossSections->end(); ++mat)
489 crossSections->clear();
490 delete crossSections;
497 if (crossSections == 0)
499 G4Exception(
"G4VCrossSectionHandler::BuildMeanFreePathForMaterials",
519 for (
size_t mLocal=0; mLocal<numOfCouples; mLocal++)
525 for (
G4int bin=0; bin<nBins; bin++)
527 G4double energy = energyVector[bin];
528 energies->push_back(energy);
529 log_energies->push_back(std::log10(energy));
531 G4double materialCrossSection = 0.0;
533 for(
G4int j=0; j<nElm; j++) {
537 if (materialCrossSection > 0.)
539 data->push_back(1./materialCrossSection);
540 log_data->push_back(std::log10(1./materialCrossSection));
545 log_data->push_back(std::log10(
DBL_MAX));
580 size_t materialIndex = couple->
GetIndex();
582 G4VEMDataSet* materialSet = (*crossSections)[materialIndex];
583 G4double materialCrossSection0 = 0.0;
586 for (
G4int i=0; i < nElements; i++ )
589 materialCrossSection0 += cr;
590 cross.push_back(materialCrossSection0);
595 for (
G4int k=0 ; k < nElements ; k++ )
597 if (random <= cross[k])
return (
G4int) (*elementVector)[k]->GetZ();
617 G4Element* element = (*elementVector)[0];
624 size_t materialIndex = couple->
GetIndex();
626 G4VEMDataSet* materialSet = (*crossSections)[materialIndex];
627 G4double materialCrossSection0 = 0.0;
630 for (
G4int i=0; i<nElements; i++)
633 materialCrossSection0 += cr;
634 cross.push_back(materialCrossSection0);
639 for (
G4int k=0 ; k < nElements ; k++ )
641 if (random <= cross[k])
return (*elementVector)[k];
644 G4cout <<
"G4VCrossSectionHandler::SelectRandomElement - no element found" <<
G4endl;
664 std::map<G4int,G4VEMDataSet*,std::less<G4int> >::const_iterator pos;
665 pos = dataMap.find(Z);
670 if (pos != dataMap.end())
671 dataSet = (*pos).second;
674 G4Exception(
"G4VCrossSectionHandler::SelectRandomShell",
680 for (
size_t i=0; i<nShells; i++)
683 if (shellDataSet != 0)
687 if (random <= partialSum)
return i;
697 if (materialTable == 0)
698 G4Exception(
"G4VCrossSectionHandler::ActiveElements",
703 for (
G4int mLocal2=0; mLocal2<nMaterials; mLocal2++)
705 const G4Material* material= (*materialTable)[mLocal2];
709 for (
G4int iEl=0; iEl<nElements; iEl++)
711 G4Element* element = (*elementVector)[iEl];
713 if (!(activeZ.
contains(Z)) && Z >= zMin && Z <= zMax)
715 activeZ.push_back(Z);
731 std::map<G4int,G4VEMDataSet*,std::less<G4int> >::const_iterator pos;
732 pos = dataMap.find(Z);
733 if (pos!= dataMap.end())
740 G4cout <<
"WARNING: G4VCrossSectionHandler::NumberOfComponents did not "
std::vector< G4Element * > G4ElementVector
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 size_t GetNumberOfMaterials()
size_t GetNumberOfElements() const
const G4double * GetVecNbOfAtomsPerVolume() const
static G4MaterialTable * GetMaterialTable()
std::size_t GetTableSize() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4VEMDataSet * BuildMeanFreePathForMaterials(const G4DataVector *energyCuts=0)
G4double ValueForMaterial(const G4Material *material, G4double e) const
void LoadShellData(const G4String &dataFile)
virtual std::vector< G4VEMDataSet * > * BuildCrossSectionsForMaterials(const G4DataVector &energyVector, const G4DataVector *energyCuts=0)=0
G4double FindValue(G4int Z, G4double e) const
virtual ~G4VCrossSectionHandler()
G4int NumberOfComponents(G4int Z) const
void LoadData(const G4String &dataFile)
void LoadNonLogData(const G4String &dataFile)
G4int SelectRandomAtom(const G4MaterialCutsCouple *couple, G4double e) const
void Initialise(G4VDataSetAlgorithm *interpolation=0, 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)
G4int SelectRandomShell(G4int Z, G4double e) const
const G4Element * SelectRandomElement(const G4MaterialCutsCouple *material, G4double e) const
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