58 for (
auto & fRegisteredModel : fRegisteredModels) {
59 fRegisteredModel->SetParticleChange(fpParticleChangeForGamma);
60 fRegisteredModel->Initialise(particle, cuts);
63 BuildMaterialParticleModelTable(particle);
65 BuildMaterialMolPerVolTable();
97 G4double crossSectionTimesNbMolPerVol(0.);
113 const size_t & materialID = material->
GetIndex();
116 auto model = SelectModel(materialID, p, ekin);
121 if (model !=
nullptr) {
122 if (
dynamic_cast<G4VDNAModel*
>(model) ==
nullptr) {
124 crossSectionTimesNbMolPerVol = model->CrossSectionPerVolume(material, p, ekin, emin, emax);
127 crossSectionTimesNbMolPerVol = model->CrossSectionPerVolume(material, p, ekin, emin, emax);
131 crossSectionTimesNbMolPerVol = 0.;
147 for (
const auto& it : componentsMap) {
149 auto component = it.first;
154 G4double nbMoleculeOfComponentInCompositeMat =
155 GetNumMolPerVolUnitForComponentInComposite(component, material);
156 G4cout <<
" ==========>component : " << component->GetName()
157 <<
" nbMoleculeOfComponentInCompositeMat: " << nbMoleculeOfComponentInCompositeMat
161 const std::size_t & componentID = component->GetIndex();
164 auto model = SelectModel(componentID, p, ekin);
170 if (model !=
nullptr) {
171 if (
dynamic_cast<G4VDNAModel*
>(model) ==
nullptr) {
174 model->CrossSectionPerVolume(component, p, ekin, emin, emax)
175 / GetNumMoleculePerVolumeUnitForMaterial(fpG4_WATER);
178 crossSection = model->CrossSectionPerVolume(component, p, ekin, emin, emax)
179 / GetNumMoleculePerVolumeUnitForMaterial(component);
181 crossSectionTimesNbMolPerVol = nbMoleculeOfComponentInCompositeMat * crossSection;
185 crossSectionTimesNbMolPerVol = 0.;
190 fMaterialCS[componentID] = crossSectionTimesNbMolPerVol;
194 fCSsumTot += crossSectionTimesNbMolPerVol;
196 crossSectionTimesNbMolPerVol = fCSsumTot;
201 return crossSectionTimesNbMolPerVol;
217 std::size_t materialID;
245 auto it = fMaterialCS.begin();
246 auto ite = fMaterialCS.end();
248 while (rand > cumulCS) {
253 "The random component selection has failed: we ran into the end of the map without "
254 "having a selected component");
259 cumulCS += it->second;
265 if (rand < cumulCS || cumulCS >=
DBL_MAX) {
267 materialID = it->first;
282 "The random component selection has failed: while loop ended without a selected "
298 fSampledMat = materialID;
303 model->SampleSecondaries(fVect, couple, aDynamicParticle, tmin, tmax);
308 fRegisteredModels.push_back(model);
325 if (componentMap.empty()) {
327 const std::size_t & matID = mat->
GetIndex();
328 InsertModelInTable(matID, p);
334 for (
const auto& itComp : componentMap) {
338 std::ostringstream oss;
339 oss <<
"Material " << mat->
GetName() <<
" is a composite and its component";
340 oss <<
" " << component->
GetName();
341 G4Exception(
"G4DNAModelManager::BuildMaterialParticleModelTable",
"em0007",
346 const std::size_t & compID = component->
GetIndex();
350 InsertModelInTable(compID, p);
359void G4DNAModelInterface::BuildMaterialMolPerVolTable()
367 for (
auto currentMaterial : *materialTable) {
370 const std::size_t & currentMatID = currentMaterial->GetIndex();
374 auto it = fMaterialParticleModelTable.begin();
375 auto ite = fMaterialParticleModelTable.end();
376 for (; it != ite; it++) {
377 const std::size_t & materialID = it->first;
379 if (materialID == currentMatID) {
380 const std::vector<G4double>* numMolPerVolForMat =
382 fMaterialMolPerVol[materialID] = numMolPerVolForMat;
390void G4DNAModelInterface::InsertModelInTable(
const std::size_t& matID,
const G4ParticleDefinition* p)
404 if (fMaterialParticleModelTable.find(matID) == fMaterialParticleModelTable.end()) {
406 if (fMaterialParticleModelTable[matID].find(p) == fMaterialParticleModelTable[matID].end()) {
407 G4int modelNbForMaterial = 0;
408 for (
const auto& it : fRegisteredModels) {
410 if (model !=
nullptr) {
411 if (model->IsParticleExistingInModelForMaterial(p, matID)) {
412 fMaterialParticleModelTable[matID][p] = it;
414 ++modelNbForMaterial;
418 auto index = fpG4_WATER->
GetIndex();
419 fMaterialParticleModelTable[index][p] = it;
420 ++modelNbForMaterial;
423 if (modelNbForMaterial == 0) {
424 std::ostringstream oss;
427 oss <<
" does not have any model registered for the " << fName <<
" interaction.";
436G4VEmModel* G4DNAModelInterface::SelectModel(
const std::size_t& materialID,
444 auto modelData = fMaterialParticleModelTable[materialID][particle];
450 auto DNAModel =
dynamic_cast<G4VDNAModel*
>(modelData);
452 if (DNAModel ==
nullptr) {
454 lowL = modelData->LowEnergyLimit();
455 highL = modelData->HighEnergyLimit();
456 if (ekin >= lowL && ekin < highL) {
468 lowL = DNAModel->GetLowELimit(materialID, particle);
469 highL = DNAModel->GetHighELimit(materialID, particle);
470 if (ekin >= lowL && ekin < highL) {
485G4double G4DNAModelInterface::GetNumMoleculePerVolumeUnitForMaterial(
const G4Material* mat)
493G4DNAModelInterface::GetNumMolPerVolUnitForComponentInComposite(
const G4Material* component,
496 return fMaterialMolPerVol[component->
GetIndex()]->at(composite->
GetIndex());
501 G4long prec = os.precision(5);
502 os <<
"======================================= Materials of " << std::setw(17)
503 << this->
GetName() <<
" ================================================"
505 os << std::setw(15) <<
"Material#" << std::setw(13) <<
"Particle" << std::setw(35) <<
"Model"
506 << std::setw(17) <<
"LowLimit(MeV)" << std::setw(17) <<
"HighLimit(MeV)" << std::setw(13)
507 <<
"Fast" << std::setw(13) <<
"Stationary" << std::setw(13) <<
"Chemistry" <<
G4endl;
508 for (
const auto& it1 : fMaterialParticleModelTable) {
510 for (
const auto& it2 : it1.second) {
511 os << std::setw(13) << it2.first->GetParticleName();
512 os << std::setw(35) << it2.second->GetName();
513 auto DNAModel =
dynamic_cast<G4VDNAModel*
>(it2.second);
514 if (DNAModel ==
nullptr) {
515 os << std::setw(17) << it2.second->LowEnergyLimit();
516 os << std::setw(17) << it2.second->HighEnergyLimit();
519 auto lowL = DNAModel->GetLowELimit(it1.first, it2.first);
520 auto highL = DNAModel->GetHighELimit(it1.first, it2.first);
521 os << std::setw(17) << lowL;
522 os << std::setw(17) << highL;
524 os << std::setw(13) <<
"no";
525 os << std::setw(13) <<
"no";
526 os << std::setw(13) <<
"no" <<
G4endl;
530 os <<
"========================================================================================"
531 "=================================================="
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4Material * > G4MaterialTable
G4GLOB_DLL std::ostream G4cout
void StreamInfo(std::ostream &os) const
void SampleSecondaries(std::vector< G4DynamicParticle * > *fVect, const G4MaterialCutsCouple *couple, const G4DynamicParticle *aDynamicElectron, G4double tmin, G4double tmax) override
SampleSecondaries Used to call the SampleSecondaries method of the registered models....
G4double CrossSectionPerVolume(const G4Material *material, const G4ParticleDefinition *p, G4double ekin, G4double emin, G4double emax) override
CrossSectionPerVolume Method called by the process and used to call the CrossSectionPerVolume method ...
void RegisterModel(G4VEmModel *model)
RegisterModel Method used to associate a model with the interaction.
void Initialise(const G4ParticleDefinition *particle, const G4DataVector &cuts) override
Initialise Initialise method to call all the initialise methods of the registered models.
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
std::size_t GetIndex() const
static G4MaterialTable * GetMaterialTable()
const G4String & GetName() const
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
const G4String & GetParticleName() const
void SetHighEnergyLimit(G4double)
G4ParticleChangeForGamma * GetParticleChangeForGamma()
void SetLowEnergyLimit(G4double)
const G4String & GetName() const