85 G4RegionModels::G4RegionModels(
G4int nMod, std::vector<G4int>& indx,
88 nModelsForRegion = nMod;
89 theListOfModelIndexes =
new G4int [nModelsForRegion];
90 lowKineticEnergy =
new G4double [nModelsForRegion+1];
91 for (
G4int i=0; i<nModelsForRegion; ++i) {
92 theListOfModelIndexes[i] = indx[i];
93 lowKineticEnergy[i] = lowE[i];
95 lowKineticEnergy[nModelsForRegion] = lowE[nModelsForRegion];
101 G4RegionModels::~G4RegionModels()
103 delete [] theListOfModelIndexes;
104 delete [] lowKineticEnergy;
129 maxSubCutInRange = 0.7*
mm;
131 flucModels.reserve(4);
133 orderOfModels.reserve(4);
135 severalModels =
true;
137 currRegionModel =
nullptr;
140 theCutsNew =
nullptr;
141 theSubCuts =
nullptr;
158 if(1 < verboseLevel) {
161 size_t n = setOfRegionModels.size();
163 for(
size_t i=0; i<
n; ++i) {
164 delete setOfRegionModels[i];
165 setOfRegionModels[i] =
nullptr;
176 G4cout <<
"G4EmModelManager::AddEmModel WARNING: no model defined."
181 flucModels.push_back(fm);
182 regions.push_back(r);
183 orderOfModels.push_back(num);
195 for(
G4int i=0; i<nEmModels; ++i) {
196 if(nam == models[i]->GetName()) {
197 models[i]->SetLowEnergyLimit(emin);
198 models[i]->SetHighEnergyLimit(emax);
203 G4cout <<
"G4EmModelManager::UpdateEmModel WARNING: no model <"
204 << nam <<
"> is found out"
213 if(i < nEmModels) { model = models[i]; }
214 else if(verboseLevel > 0 && ver) {
215 G4cout <<
"G4EmModelManager::GetModel WARNING: "
216 <<
"index " << i <<
" is wrong Nmodels= "
238 return rm->NumberOfModels();
251 if(1 < verboseLevel) {
252 G4cout <<
"G4EmModelManager::Initialise() for "
253 << partname <<
" Nmodels= " << nEmModels <<
G4endl;
260 G4Exception(
"G4EmModelManager::Initialise",
"em0002",
269 regionStore->
GetRegion(
"DefaultRegionForTheWorld",
false);
273 std::vector<const G4Region*> setr;
274 setr.push_back(world);
277 for (
G4int ii=0; ii<nEmModels; ++ii) {
279 if ( r == 0 || r == world) {
285 for (
G4int j=1; j<nRegions; ++j) {
286 if ( r == setr[j] ) { newRegion =
false; }
298 ed <<
"No models defined for the World volume for "
300 G4Exception(
"G4EmModelManager::Initialise",
"em0002",
310 if(nRegions > 1 && nEmModels > 1) {
311 idxOfRegionModels.resize(numOfCouples,0);
312 setOfRegionModels.resize((
size_t)nRegions,0);
314 idxOfRegionModels.resize(1,0);
315 setOfRegionModels.resize(1,0);
318 std::vector<G4int> modelAtRegion(nEmModels);
319 std::vector<G4int> modelOrd(nEmModels);
323 if(1 < verboseLevel) {
324 G4cout <<
" Nregions= " << nRegions
325 <<
" Nmodels= " << nEmModels <<
G4endl;
329 for (
G4int reg=0; reg<nRegions; ++
reg) {
333 for (
G4int ii=0; ii<nEmModels; ++ii) {
336 if ( region == regions[ii] ) {
340 G4int ord = orderOfModels[ii];
345 if(1 < verboseLevel) {
347 <<
" <" << model->
GetName() <<
"> for region <";
350 <<
" tmin(MeV)= " << tmin/
MeV
351 <<
"; tmax(MeV)= " << tmax/
MeV
352 <<
"; order= " << ord
367 if( tmax - tmin <= limitdelta) { push =
false; }
369 else if (tmax == eLow[0]) {
374 }
else if(tmin < eHigh[n-1]) {
376 for(
G4int k=0; k<
n; ++k) {
380 if(ord >= modelOrd[k]) {
381 if(tmin < eHigh[k] && tmin >= eLow[k]) { tmin = eHigh[k]; }
382 if(tmax <= eHigh[k] && tmax > eLow[k]) { tmax = eLow[k]; }
383 if(tmax > eHigh[k] && tmin < eLow[k]) {
384 if(tmax - eHigh[k] > eLow[k] - tmin) { tmin = eHigh[k]; }
385 else { tmax = eLow[k]; }
387 if( tmax - tmin <= limitdelta) {
402 if (tmax <= eLow[0]) {
407 }
else if(tmin < eHigh[n-1]) {
409 if(tmin > eLow[n-1] && tmax >= eHigh[n-1]) {
412 }
else if(tmin <= eLow[0] && tmax < eHigh[0]) {
419 for(
G4int k=n-1; k>=0; --k) {
420 if(tmin <= eLow[k] && tmax >= eHigh[k]) {
422 isUsed[modelAtRegion[k]] = 0;
426 for(
G4int kk=k; kk<n-1; ++kk) {
427 modelAtRegion[kk] = modelAtRegion[kk+1];
428 modelOrd[kk] = modelOrd[kk+1];
429 eLow[kk] = eLow[kk+1];
430 eHigh[kk] = eHigh[kk+1];
437 if(tmin <= eLow[k] && tmax > eLow[k]) {
442 }
else if(tmin < eHigh[k] && tmax >= eHigh[k]) {
449 }
else if(tmin > eLow[k] && tmax < eHigh[k]) {
450 if(eHigh[k] - tmax > tmin - eLow[k]) {
472 for(
G4int k=n-1; k>=idx; --k) {
473 modelAtRegion[k+1] = modelAtRegion[k];
474 modelOrd[k+1] = modelOrd[k];
476 eHigh[k+1] = eHigh[k];
482 if (push || insert) {
484 modelAtRegion[idx] = ii;
491 for(
G4int k=n-1; k>=0; --k) {
492 if(eHigh[k] - eLow[k] <= limitdelta) {
493 isUsed[modelAtRegion[k]] = 0;
495 for(
G4int kk=k; kk<n-1; ++kk) {
496 modelAtRegion[kk] = modelAtRegion[kk+1];
497 modelOrd[kk] = modelOrd[kk+1];
498 eLow[kk] = eLow[kk+1];
499 eHigh[kk] = eHigh[kk+1];
508 eLow[
n] = eHigh[n-1];
510 if(1 < verboseLevel) {
511 G4cout <<
"### New G4RegionModels set with " << n <<
" models for region <";
513 G4cout <<
"> Elow(MeV)= ";
518 setOfRegionModels[
reg] = rm;
520 if(1 == nEmModels) {
break; }
523 currRegionModel = setOfRegionModels[0];
524 currModel = models[0];
528 if(secondaryParticle) {
539 if(theCutsNew) { *theCutsNew = *theCuts; }
541 if(minSubRange < 1.0) {
543 theSubCuts->resize(numOfCouples,
DBL_MAX);
548 for(
size_t i=0; i<numOfCouples; ++i) {
556 if(nRegions > 1 && nEmModels > 1) {
559 do {--
reg;}
while (reg>0 && pcuts != (setr[reg]->GetProductionCuts()));
560 idxOfRegionModels[i] =
reg;
562 if(1 < verboseLevel) {
563 G4cout <<
"G4EmModelManager::Initialise() for "
565 <<
" indexOfCouple= " << i
566 <<
" indexOfRegion= " << reg
571 if(secondaryParticle) {
574 if( cut <
DBL_MAX && minSubRange < 1.0) {
581 if(tcutmax < subcut) { subcut = tcutmax; }
582 (*theSubCuts)[i] = subcut;
588 if(nRegions > 1 && nEmModels > 1) {
589 inn = idxOfRegionModels[i];
593 currRegionModel = setOfRegionModels[inn];
594 nnm = currRegionModel->NumberOfModels();
598 for(
G4int jj=0; jj<nnm; ++jj) {
601 currModel = models[currRegionModel->ModelIndex(jj)];
604 if(!theCutsNew) { theCutsNew =
new G4DataVector(*theCuts); }
605 (*theCutsNew)[i] = cutlim;
617 if(theCutsNew) { theCuts = theCutsNew; }
621 severalModels =
true;
622 for(
G4int jj=0; jj<nEmModels; ++jj) {
623 if(1 == isUsed[jj]) {
625 currModel = models[jj];
627 if(flucModels[jj]) { flucModels[jj]->InitialiseMe(particle); }
630 if(1 == nn) { severalModels =
false; }
632 if(1 < verboseLevel) {
633 G4cout <<
"G4EmModelManager for " << partname
634 <<
" is initialised; nRegions= " << nRegions
635 <<
" severalModels: " << severalModels
655 if(theSubCuts) { emin = (*theSubCuts)[i]; }
658 if(1 < verboseLevel) {
659 G4cout <<
"G4EmModelManager::FillDEDXVector() for "
661 <<
" cut(MeV)= " << cut
662 <<
" emin(MeV)= " << emin
669 if(nRegions > 1 && nEmModels > 1) { reg = idxOfRegionModels[i]; }
671 G4int nmod = regModels->NumberOfModels();
680 for(
size_t j=0; j<totBinsLoss; ++j) {
689 do {--k;}
while (k>0 && e <= regModels->LowEdgeEnergy(k));
691 if(k > 0 && k != k0) {
693 G4double elow = regModels->LowEdgeEnergy(k);
694 G4double dedx1 = ComputeDEDX(models[regModels->ModelIndex(k-1)],
695 couple,elow,cut,emin);
696 G4double dedx2 = ComputeDEDX(models[regModels->ModelIndex(k)],
697 couple,elow,cut,emin);
699 if(dedx2 > 0.0) { del = (dedx1/dedx2 - 1.0)*elow; }
705 ComputeDEDX(models[regModels->ModelIndex(k)],couple,e,cut,emin);
706 dedx *= (1.0 + del/e);
708 if(2 < verboseLevel) {
709 G4cout <<
"Material= " << couple->GetMaterial()->GetName()
710 <<
" E(MeV)= " << e/
MeV
711 <<
" dEdx(MeV/mm)= " << dedx*
mm/
MeV
712 <<
" del= " << del*
mm/
MeV<<
" k= " << k
713 <<
" modelIdx= " << regModels->ModelIndex(k)
716 if(dedx < 0.0) { dedx = 0.0; }
733 if(theSubCuts) { cut = (*theSubCuts)[i]; }
737 if(nRegions > 1 && nEmModels > 1) { reg = idxOfRegionModels[i]; }
739 G4int nmod = regModels->NumberOfModels();
740 if(1 < verboseLevel) {
741 G4cout <<
"G4EmModelManager::FillLambdaVector() for "
744 <<
" Emin(MeV)= " << aVector->
Energy(0)
749 <<
" theSubCuts " << theSubCuts
758 G4VEmModel* mod = models[regModels->ModelIndex(0)];
759 for(
size_t j=0; j<totBinsLambda; ++j) {
767 do {--k;}
while (k>0 && e <= regModels->LowEdgeEnergy(k));
768 if(k > 0 && k != k0) {
770 G4double elow = regModels->LowEdgeEnergy(k);
771 G4VEmModel* mod1 = models[regModels->ModelIndex(k-1)];
773 mod = models[regModels->ModelIndex(k)];
776 if(xs2 > 0.0) { del = (xs1/xs2 - 1.0)*elow; }
782 cross *= (1.0 + del/e);
785 if(j==0 && startFromNull) { cross = 0.0; }
787 if(2 < verboseLevel) {
788 G4cout <<
"FillLambdaVector: " << j <<
". e(MeV)= " << e/
MeV
789 <<
" cross(1/mm)= " << cross*
mm
790 <<
" del= " << del*
mm <<
" k= " << k
791 <<
" modelIdx= " << regModels->ModelIndex(k)
794 if(cross < 0.0) { cross = 0.0; }
803 if(verb == 0) {
return; }
804 for(
G4int i=0; i<nRegions; ++i) {
807 G4int n = r->NumberOfModels();
809 G4cout <<
" ===== EM models for the G4Region " << reg->
GetName()
811 for(
G4int j=0; j<
n; ++j) {
825 size_t kk = table->size();
826 for(
size_t k=0; k<kk; ++k) {
830 G4cout <<
" Table with " << nn <<
" bins Emin= "
847 if(1 == nEmModels) {
break; }
850 G4cout <<
" ===== Limit on energy threshold has been applied "
G4int NumberOfRegionModels(size_t index_couple) const
G4double LowEnergyActivationLimit() const
G4double HighEnergyActivationLimit() const
G4double LowEnergyLimit() const
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
const G4String & GetName() const
const std::vector< G4double > * GetEnergyCutsVector(size_t pcIdx) const
G4double GetMaxEnergy() const
static constexpr double mm
std::ostringstream G4ExceptionDescription
G4VEmModel * GetModel(G4int idx, G4bool ver=false)
G4double HighEnergyLimit() const
G4double GetProductionCut(G4int index) const
virtual void DefineForRegion(const G4Region *)
void UpdateEmModel(const G4String &model_name, G4double emin, G4double emax)
const G4String & GetName() const
G4VEmAngularDistribution * GetAngularDistribution()
void AddEmModel(G4int, G4VEmModel *, G4VEmFluctuationModel *, const G4Region *)
G4PhysicsTable * GetCrossSectionTable()
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
size_t GetVectorLength() const
virtual G4double MinEnergyCut(const G4ParticleDefinition *, const G4MaterialCutsCouple *)
void FillLambdaVector(G4PhysicsVector *, const G4MaterialCutsCouple *, G4bool startFromNull=true, G4EmTableType t=fRestricted)
const G4String & GetParticleName() const
static const G4double reg
virtual void Initialise(const G4ParticleDefinition *, const G4DataVector &)=0
static G4RegionStore * GetInstance()
G4VEmModel * GetRegionModel(G4int idx, size_t index_couple)
G4GLOB_DLL std::ostream G4cout
void FillDEDXVector(G4PhysicsVector *, const G4MaterialCutsCouple *, G4EmTableType t=fRestricted)
size_t GetTableSize() const
G4double CrossSection(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy=0.0, G4double maxEnergy=DBL_MAX)
void PutValue(size_t index, G4double theValue)
static constexpr double eV
G4double Energy(size_t index) const
void DumpModelList(G4int verb)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
const G4DataVector * Initialise(const G4ParticleDefinition *part, const G4ParticleDefinition *secPart, G4double minSubRange, G4int verb)
static const G4double emax
static G4ProductionCutsTable * GetProductionCutsTable()
G4bool DeexcitationFlag() const
static G4Positron * Positron()
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
static G4Electron * Electron()
static constexpr double MeV
const G4String & GetName() const
G4double ConvertRangeToEnergy(const G4ParticleDefinition *particle, const G4Material *material, G4double range)
G4ProductionCuts * GetProductionCuts() const
const XML_Char XML_Content * model
const G4String & GetName() const
const G4Material * GetMaterial() const