53 fReducedXSTable(nullptr),fEffectiveZSq(nullptr),fSamplingTable(nullptr),
54 fPBcut(nullptr),fVerbosity(verbosity)
58 {1.0e-12,0.025e0,0.05e0,0.075e0,0.1e0,0.15e0,0.2e0,0.25e0,
59 0.3e0,0.35e0,0.4e0,0.45e0,0.5e0,0.55e0,0.6e0,0.65e0,0.7e0,
60 0.75e0,0.8e0,0.85e0,0.9e0,0.925e0,0.95e0,0.97e0,0.99e0,
61 0.995e0,0.999e0,0.9995e0,0.9999e0,0.99995e0,0.99999e0,1.0e0};
63 for (std::size_t ix=0;ix<fNBinsX;++ix)
64 theXGrid[ix] = tempvector[ix];
66 for (std::size_t i=0;i<fNBinsE;++i)
69 fElementData =
new std::map<G4int,G4DataVector*>;
187 G4Exception(
"G4PenelopeBremsstrahlungFS::BuildScaledXSTable()",
192 G4cout <<
"Entering in G4PenelopeBremsstrahlungFS::BuildScaledXSTable for " <<
194 G4cout <<
"Threshold = " << cut/keV <<
" keV, isMaster= " << isMaster <<
201 new std::map< std::pair<const G4Material*,G4double> ,
G4PhysicsTable*>;
207 if (!fReducedXSTable)
208 fReducedXSTable =
new std::map< std::pair<const G4Material*,G4double> ,
211 fEffectiveZSq =
new std::map<const G4Material*,G4double>;
216 std::vector<G4double> *StechiometricFactors =
new std::vector<G4double>;
220 for (std::size_t i=0;i<nElements;i++)
222 G4double fraction = fractionVector[i];
223 G4double atomicWeigth = (*elementVector)[i]->GetA()/(g/mole);
224 StechiometricFactors->push_back(fraction/atomicWeigth);
227 G4double MaxStechiometricFactor = 0.;
228 for (std::size_t i=0;i<nElements;i++)
230 if ((*StechiometricFactors)[i] > MaxStechiometricFactor)
231 MaxStechiometricFactor = (*StechiometricFactors)[i];
234 for (std::size_t i=0;i<nElements;i++)
235 (*StechiometricFactors)[i] /= MaxStechiometricFactor;
239 for (std::size_t i=0;i<nElements;i++)
241 G4double Z = (*elementVector)[i]->GetZ();
242 sumz2 += (*StechiometricFactors)[i]*Z*Z;
243 sums += (*StechiometricFactors)[i];
247 fEffectiveZSq->insert(std::make_pair(material,ZBR2));
255 for (std::size_t iel=0;iel<nElements;iel++)
257 G4double Z = (*elementVector)[iel]->GetZ();
259 G4double wgt = (*StechiometricFactors)[iel]*Z*Z/ZBR2;
262 if (!fElementData->count(iZ))
265 if (!fElementData->count(iZ))
268 ed <<
"Error in G4PenelopeBremsstrahlungFS::BuildScaledXSTable" <<
G4endl;
269 ed <<
"Unable to retrieve data for element " << iZ <<
G4endl;
270 G4Exception(
"G4PenelopeBremsstrahlungFS::BuildScaledXSTable()",
275 G4DataVector* atomData = fElementData->find(iZ)->second;
277 for (std::size_t ie=0;ie<fNBinsE;++ie)
279 (*tempData)[ie] += wgt*(*atomData)[ie*(fNBinsX+1)+fNBinsX];
280 for (std::size_t ix=0;ix<fNBinsX;++ix)
281 (*tempMatrix)[ie*fNBinsX+ix] += wgt*(*atomData)[ie*(fNBinsX+1)+ix];
289 for (std::size_t ie=0;ie<fNBinsE;++ie)
293 for (std::size_t ix=0;ix<fNBinsX;++ix)
294 tempData2[ix] = (*tempMatrix)[ie*fNBinsX+ix];
297 G4double fact = millibarn*(theEGrid[ie]+electron_mass_c2)*(1./fine_structure_const)/
298 (classic_electr_radius*classic_electr_radius*(theEGrid[ie]+2.0*electron_mass_c2));
299 G4double fnorm = (*tempData)[ie]/(rsum*fact);
300 G4double TST = 100.*std::fabs(fnorm-1.0);
304 ed <<
"G4PenelopeBremsstrahlungFS. Corrupted data files?" <<
G4endl;
305 G4cout <<
"TST= " << TST <<
"; fnorm = " << fnorm <<
G4endl;
308 G4cout << ie <<
" " << theEGrid[ie]/keV <<
" " << (*tempData)[ie]/barn <<
G4endl;
309 G4Exception(
"G4PenelopeBremsstrahlungFS::BuildScaledXSTable()",
312 for (std::size_t ix=0;ix<fNBinsX;++ix)
313 (*tempMatrix)[ie*fNBinsX+ix] *= fnorm;
327 for (std::size_t i=0;i<fNBinsX;++i)
330 for (std::size_t ix=0;ix<fNBinsX;++ix)
334 for (std::size_t ie=0;ie<fNBinsE;++ie)
337 G4double aValue = (*tempMatrix)[ie*fNBinsX+ix];
338 if (aValue < 1e-20*millibarn)
339 aValue = 1e-20*millibarn;
346 G4double val1eV = (*theVec)[1]+derivative*(log1eV-theVec->
Energy(1));
350 std::pair<const G4Material*,G4double> theKey = std::make_pair(material,cut);
351 fReducedXSTable->insert(std::make_pair(theKey,thePhysicsTable));
353 delete StechiometricFactors;
358 if (!(fSamplingTable->count(theKey)))
359 InitializeEnergySampling(material,cut);
444 std::size_t size = fNBinsX;
448 if (momOrder<-1 || size<2 || theXGrid[0]<0)
450 G4Exception(
"G4PenelopeBremsstrahlungFS::GetMomentumIntegral()",
454 for (std::size_t i=1;i<size;++i)
456 if (theXGrid[i]<0 || theXGrid[i]<theXGrid[i-1])
459 ed <<
"Invalid call for bin " << i <<
G4endl;
460 G4Exception(
"G4PenelopeBremsstrahlungFS::GetMomentumIntegral()",
467 if (xup < theXGrid[0])
470 G4double xt = std::min(xup,theXGrid[size-1]);
472 for (std::size_t i=0;i<size-1;++i)
474 G4double x1 = std::max(theXGrid[i],eps);
476 G4double x2 = std::max(theXGrid[i+1],eps);
488 if (std::fabs(dx)>1e-14*std::fabs(dy))
493 ds = a*
G4Log(xtc/x1)+b*(xtc-x1);
494 else if (momOrder == 0)
495 ds = a*(xtc-x1) + 0.5*b*(xtc*xtc-x1*x1);
497 ds = a*(std::pow(xtc,momOrder+1)-std::pow(x1,momOrder+1))/((
G4double) (momOrder + 1))
498 + b*(std::pow(xtc,momOrder+2)-std::pow(x1,momOrder+2))/((
G4double) (momOrder + 2));
501 ds = 0.5*(y1+y2)*(xtc-x1)*std::pow(xtc,momOrder);
606 std::pair<const G4Material*,G4double> theKey = std::make_pair(mat,cut);
607 if (!(fSamplingTable->count(theKey)) || !(fPBcut->count(theKey)))
610 ed <<
"Unable to retrieve the SamplingTable: " <<
611 fSamplingTable->count(theKey) <<
" " <<
612 fPBcut->count(theKey) <<
G4endl;
613 G4Exception(
"G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
616 const G4PhysicsTable* theTableInte = fSamplingTable->find(theKey)->second;
617 const G4PhysicsTable* theTableRed = fReducedXSTable->find(theKey)->second;
620 std::size_t eBin = 0;
621 G4bool firstOrLastBin =
false;
623 if (energy < theEGrid[0])
626 firstOrLastBin =
true;
628 else if (energy > theEGrid[fNBinsE-1])
631 firstOrLastBin =
true;
636 std::size_t j=fNBinsE-1;
639 std::size_t k = (i+j)/2;
640 if (energy > theEGrid[k])
660 fCache.
Put(theTempVec);
664 G4cout <<
"Creating new instance of G4PhysicsFreeVector() on the worker" <<
G4endl;
672 for (std::size_t iloop=0;iloop<fNBinsX;++iloop)
674 G4double val = (*theVec1)[iloop]+(((*theVec2)[iloop]-(*theVec1)[iloop]))*
675 (energy-theEGrid[eBin])/(theEGrid[eBin+1]-theEGrid[eBin]);
676 theTempVec->
PutValues(iloop,theXGrid[iloop],val);
681 for (std::size_t iloop=0;iloop<fNBinsX;++iloop)
682 theTempVec->
PutValues(iloop,theXGrid[iloop],(*theVec1)[iloop]);
686 G4double pbcut = (*(fPBcut->find(theKey)->second))[eBin];
690 pbcut = (*(fPBcut->find(theKey)->second))[eBin] +
691 ((*(fPBcut->find(theKey)->second))[eBin+1]-(*(fPBcut->find(theKey)->second))[eBin])*
692 (energy-theEGrid[eBin])/(theEGrid[eBin+1]-theEGrid[eBin]);
695 G4double pCumulative = (*theTempVec)[fNBinsX-1];
698 G4int nIterations = 0;
705 std::size_t ibin = 0;
706 if (pt < (*theTempVec)[0])
708 else if (pt > (*theTempVec)[fNBinsX-1])
712 G4double delta = pt-(*theTempVec)[fNBinsX-1];
713 if (delta < pt*1e-10)
717 ed <<
"Found that (pt > (*theTempVec)[fNBinsX-1]) with pt = " << pt <<
718 " , (*theTempVec)[fNBinsX-1] = " << (*theTempVec)[fNBinsX-1] <<
" and delta = " <<
719 (pt-(*theTempVec)[fNBinsX-1]) <<
G4endl;
720 ed <<
"Possible symptom of problem with numerical precision" <<
G4endl;
721 G4Exception(
"G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
727 ed <<
"Crash at (pt > (*theTempVec)[fNBinsX-1]) with pt = " << pt <<
728 " , (*theTempVec)[fNBinsX-1]=" << (*theTempVec)[fNBinsX-1] <<
" and fNBinsX = " <<
730 ed <<
"Material: " << mat->
GetName() <<
", energy = " << energy/keV <<
" keV" <<
732 G4Exception(
"G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
739 std::size_t j=fNBinsX-1;
742 std::size_t k = (i+j)/2;
743 if (pt > (*theTempVec)[k])
766 G4double wbcut = (cut < energy) ? cut/energy : 1.0;
768 wbcut = (cut < theEGrid[eBin]) ? cut/theEGrid[eBin] : 1.0;
781 ed <<
"Warning in G4PenelopeBremsstrahlungFS::SampleX()" <<
G4endl;
782 ed <<
"Conflicting end-point values: w1=" << w1 <<
"; w2 = " << w2 <<
G4endl;
783 ed <<
"wbcut = " << wbcut <<
" energy= " << energy/keV <<
" keV" <<
G4endl;
784 ed <<
"cut = " << cut/keV <<
" keV" <<
G4endl;
785 G4Exception(
"G4PenelopeBremsstrahlungFS::SampleGammaEnergy()",
"em2015",
801 if (nIterations > 100)
803 }
while(eGamma < cut);