38 :
G4VEmModel(nam), fName(nam), fpParticleChangeForGamma(0), fSampledMat(
"")
48 for(
unsigned int i=0, ie = fRegisteredModels.size(); i<ie; ++i)
50 if(fRegisteredModels.at(i) !=
nullptr)
delete fRegisteredModels.at(i);
69 for(
unsigned int i=0, ie = fRegisteredModels.size(); i<ie; ++i)
71 fRegisteredModels.at(i)->Initialise(particle, cuts, fpParticleChangeForGamma);
77 BuildMaterialParticleModelTable(particle);
79 BuildMaterialMolPerVolTable();
110 G4double crossSectionTimesNbMolPerVol (0);
132 G4double nbOfMoleculePerVolumeUnit = GetNumMoleculePerVolumeUnitForMaterial(material);
136 crossSectionTimesNbMolPerVol = nbOfMoleculePerVolumeUnit * model->
CrossSectionPerVolume(material, materialName, p, ekin, emin, emax);
138 crossSectionTimesNbMolPerVol = 0.;
150 std::map<G4Material*, G4double> componentsMap = material->
GetMatComponents();
153 std::map<G4Material*, G4double>::const_iterator it = componentsMap.begin();
156 unsigned int componentNumber = componentsMap.size();
160 for(
unsigned int i=0; i<componentNumber; ++i)
169 G4double nbMoleculeOfComponentInCompositeMat = GetNumMolPerVolUnitForComponentInComposite(component, material);
180 crossSectionTimesNbMolPerVol =
181 nbMoleculeOfComponentInCompositeMat * model->
CrossSectionPerVolume(component, componentName, p, ekin, emin, emax);
183 crossSectionTimesNbMolPerVol = 0.;
187 fMaterialCS[componentName] = crossSectionTimesNbMolPerVol;
191 fCSsumTot += crossSectionTimesNbMolPerVol;
197 crossSectionTimesNbMolPerVol = fCSsumTot;
203 return crossSectionTimesNbMolPerVol;
249 std::map<const G4String , G4double>::const_iterator it = fMaterialCS.begin();
250 std::map<const G4String , G4double>::const_iterator ite = fMaterialCS.end();
257 G4Exception(
"G4DNAModelManager::SampleSecondaries",
"em0006",
259 "The random component selection has failed: we ran into the end of the map without having a selected component");
264 cumulCS += it->second;
270 if(rand<cumulCS || cumulCS >=
DBL_MAX)
273 materialName = it->
first;
287 G4Exception(
"G4DNAModelManager::SampleSecondaries",
"em0006",
289 "The random component selection has failed: while loop ended without a selected component.");
301 if(materialName.find(
"_MODIFIED")!=G4String::npos)
303 materialName = materialName.substr(0,materialName.size()-9);
306 fSampledMat = materialName;
313 model->
SampleSecondaries(fVect, couple, materialName, aDynamicParticle, fpParticleChangeForGamma, tmin, tmax);
318 fRegisteredModels.push_back(model);
339 G4MaterialTable::iterator it;
351 unsigned int compositeSize = componentMap.size();
354 if(componentMap.empty())
360 InsertModelInTable(matName, pName);
366 std::map<G4Material*, G4double>::const_iterator itComp = componentMap.begin();
370 for(
unsigned int k=0; k<compositeSize; ++k)
391 InsertModelInTable(compName, pName);
402void G4DNAModelInterface::BuildMaterialMolPerVolTable()
410 for(
size_t i=0, ie=materialTable->size(); i<ie; i++)
413 G4Material* currentMaterial = materialTable->at(i);
420 MaterialParticleModelTable::iterator it = fMaterialParticleModelTable.begin();
421 MaterialParticleModelTable::iterator ite = fMaterialParticleModelTable.end();
422 for(; it != ite; it++)
426 if(materialName == currentMatName)
429 fMaterialMolPerVol[materialName] = numMolPerVolForMat;
437void G4DNAModelInterface::InsertModelInTable(
const G4String& matName,
const G4String& pName)
450 if(fMaterialParticleModelTable.find(matName) == fMaterialParticleModelTable.end())
453 if(fMaterialParticleModelTable[matName].find(pName) == fMaterialParticleModelTable[matName].end())
455 G4int modelNbForMaterial (0);
460 for(
unsigned int i=0, ie=fRegisteredModels.size(); i<ie; ++i)
463 if(fRegisteredModels[i]->IsParticleExistingInModelForMaterial(pName, matName))
466 fMaterialParticleModelTable[matName][pName].push_back(fRegisteredModels[i]);
469 ++modelNbForMaterial;
475 if(modelNbForMaterial>1)
481 std::vector<G4VDNAModel*>& models = fMaterialParticleModelTable[matName][pName];
489 std::map<G4double, G4int, std::less<G4double> > sortMap;
495 for(
unsigned int ii=0, em=models.size(); ii<em; ++ii)
497 G4double lowLim = models[ii]->GetLowELimit(matName, pName);
498 G4double highLim = models[ii]->GetHighELimit(matName, pName);
500 if(sortMap.find(lowLim) != sortMap.end() )
505 sortMap[lowLim] = ii;
507 if(sortMap.find(highLim) != sortMap.end() )
509 highLim -= smallDiff;
512 sortMap[highLim] = ii;
519 std::map<G4double, G4int>::iterator it = sortMap.begin();
522 G4double dummyLim = it->first - smallDiff;
527 for(
unsigned int ii=0, eii=models.size(); ii<eii; ++ii)
529 G4double lim1 = it->first - smallDiff;
530 G4int count1 = it->second;
535 G4double lim2 = it->first + smallDiff;
536 G4int count2 = it->second;
545 if( (count1 != count2) || ( std::abs(dummyLim - lim1) > 1.*eV ) )
549 std::ostringstream oss;
550 oss<<
"The material "<<matName<<
" and the particle "<<pName;
551 oss<<
" have several models registered for the "<<fName<<
" interaction and their energy ranges ";
552 oss<<
"do not match. \nEnergy ranges: \n";
554 for(
int iii=0, eiii=models.size(); iii<eiii; ++iii)
556 oss<<models[iii]->GetName()<<
"\n";
557 oss<<
"low: "<<models[iii]->GetLowELimit(matName, pName)/eV<<
" eV \n";
558 oss<<
"high: "<<models[iii]->GetHighELimit(matName, pName)/eV<<
" eV \n";
561 G4Exception(
"G4DNAModelManager::InsertModelInTable",
"em0006",
572 else if(modelNbForMaterial==0)
592 std::vector<G4VDNAModel*>& models = fMaterialParticleModelTable[material][particle];
599 for(
int i=0, ie=models.size(); i<ie; ++i)
602 if( ekin >= models[i]->GetLowELimit(material, particle)
603 && ekin < models[i]->GetHighELimit(material, particle) )
636G4double G4DNAModelInterface::GetNumMoleculePerVolumeUnitForMaterial(
const G4Material* mat)
645 return fMaterialMolPerVol[component->
GetName() ]->at(composite->
GetIndex() );
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4Material * > G4MaterialTable
virtual ~G4DNAModelInterface()
~G4DNAModelManager Destructor
virtual G4double CrossSectionPerVolume(const G4Material *material, const G4ParticleDefinition *p, G4double ekin, G4double emin, G4double emax)
CrossSectionPerVolume Method called by the process and used to call the CrossSectionPerVolume method ...
virtual void Initialise(const G4ParticleDefinition *particle, const G4DataVector &cuts)
Initialise Initialise method to call all the initialise methods of the registered models.
virtual void SampleSecondaries(std::vector< G4DynamicParticle * > *fVect, const G4MaterialCutsCouple *couple, const G4DynamicParticle *aDynamicElectron, G4double tmin, G4double tmax)
SampleSecondaries Used to call the SampleSecondaries method of the registered models....
void RegisterModel(G4VDNAModel *model)
RegisterModel Method used to associate a model with the interaction.
G4DNAModelInterface(const G4String &nam)
G4DNAModelManager Constructor.
const std::vector< G4double > * GetNumMolPerVolTableFor(const G4Material *) const
Retrieve a table of molecular densities (number of molecules per unit volume) in the G4 unit system f...
static G4DNAMolecularMaterial * Instance()
const G4ParticleDefinition * GetParticleDefinition() const
G4double GetKineticEnergy() const
const G4Material * GetMaterial() const
const std::map< G4Material *, G4double > & GetMatComponents() const
static G4MaterialTable * GetMaterialTable()
const G4String & GetName() const
const G4String & GetParticleName() const
std::size_t first(char) const
virtual void SampleSecondaries(std::vector< G4DynamicParticle * > *, const G4MaterialCutsCouple *, const G4String &materialName, const G4DynamicParticle *, G4ParticleChangeForGamma *particleChangeForGamma, G4double tmin=0, G4double tmax=DBL_MAX)=0
SampleSecondaries Each model must implement SampleSecondaries to decide if a particle will be created...
virtual G4double CrossSectionPerVolume(const G4Material *material, const G4String &materialName, const G4ParticleDefinition *p, G4double ekin, G4double emin, G4double emax)=0
CrossSectionPerVolume Every model must implement its own CrossSectionPerVolume method....
void SetHighEnergyLimit(G4double)
G4ParticleChangeForGamma * GetParticleChangeForGamma()
void SetLowEnergyLimit(G4double)
const G4String & GetName() const