62 fLorentzTables1(nullptr),fLorentzTables2(nullptr)
85void G4PenelopeBremsstrahlungAngular::ClearTables()
89 for (
auto j=fLorentzTables1->begin(); j != fLorentzTables1->end(); ++j)
95 fLorentzTables1->clear();
96 delete fLorentzTables1;
97 fLorentzTables1 =
nullptr;
102 for (
auto j=fLorentzTables2->begin(); j != fLorentzTables2->end(); ++j)
108 fLorentzTables2->clear();
109 delete fLorentzTables2;
110 fLorentzTables2 =
nullptr;
114 delete fEffectiveZSq;
115 fEffectiveZSq =
nullptr;
121void G4PenelopeBremsstrahlungAngular::ReadDataFile()
128 "G4PenelopeBremsstrahlungAngular - G4LEDATA environment variable not set!";
129 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
134 G4String pathFile = pathString +
"/penelope/bremsstrahlung/pdbrang.p08";
135 std::ifstream file(pathFile);
139 G4String excep =
"G4PenelopeBremsstrahlungAngular - data file " + pathFile +
" not found!";
140 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
146 for (k=0;k<fNumberofKPoints;k++)
147 for (i=0;i<fNumberofZPoints;i++)
148 for (j=0;j<fNumberofEPoints;j++)
153 file >> iz1 >> ie1 >> ik1 >> zr >> er >> kr >> a1 >> a2;
155 if ((iz1-1 == i) && (ik1-1 == k) && (ie1-1 == j))
163 ed <<
"Corrupted data file " << pathFile <<
"?" <<
G4endl;
164 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
184 G4Exception(
"G4PenelopeBremsstrahlungAngular::PrepareInterpolationTables()",
188 if (!fLorentzTables1)
189 fLorentzTables1 =
new std::map<G4double,G4PhysicsTable*>;
190 if (!fLorentzTables2)
191 fLorentzTables2 =
new std::map<G4double,G4PhysicsTable*>;
193 G4double Zmat = CalculateEffectiveZ(material);
195 const G4int reducedEnergyGrid=21;
199 G4double Q1[fNumberofEPoints][fNumberofKPoints];
200 G4double Q2[fNumberofEPoints][fNumberofKPoints];
202 G4double Q1E[fNumberofEPoints][reducedEnergyGrid];
203 G4double Q2E[fNumberofEPoints][reducedEnergyGrid];
204 G4double pZ[fNumberofZPoints] = {2.0,8.0,13.0,47.0,79.0,92.0};
208 for (i=0;i<fNumberofEPoints;i++)
210 for (j=0;j<fNumberofKPoints;j++)
218 for (k=0;k<fNumberofZPoints;k++)
221 QQ2vector->
PutValues(k,pZ[k],fQQ2[k][i][j]);
228 Q2[i][j]=QQ2vector->
Value(Zmat);
233 G4double pE[fNumberofEPoints] = {1.0e-03*MeV,5.0e-03*MeV,1.0e-02*MeV,5.0e-02*MeV,
234 1.0e-01*MeV,5.0e-01*MeV};
235 G4double pK[fNumberofKPoints] = {0.0,0.6,0.8,0.95};
238 for(i=0;i<reducedEnergyGrid;i++)
242 for(i=0;i<fNumberofEPoints;i++)
243 betas[i]=std::sqrt(pE[i]*(pE[i]+2*electron_mass_c2))/(pE[i]+electron_mass_c2);
246 for (i=0;i<fNumberofEPoints;i++)
248 for (j=0;j<fNumberofKPoints;j++)
249 Q1[i][j]=Q1[i][j]/Zmat;
253 for (i=0;i<fNumberofEPoints;i++)
258 for (j=0;j<fNumberofKPoints;j++)
264 for (j=0;j<reducedEnergyGrid;j++)
266 Q1E[i][j]=Q1vector->
Value(ppK[j]);
267 Q2E[i][j]=Q2vector->
Value(ppK[j]);
283 for (j=0;j<reducedEnergyGrid;j++)
291 for (j=0;j<reducedEnergyGrid;j++)
295 for (i=0;i<fNumberofEPoints;i++)
298 thevec2->
PutValues(i,betas[i],Q2E[i][j]);
305 if (fLorentzTables1 && fLorentzTables2)
307 fLorentzTables1->insert(std::make_pair(Zmat,theTable1));
308 fLorentzTables2->insert(std::make_pair(Zmat,theTable2));
313 ed <<
"Unable to create tables of Lorentz coefficients for " <<
G4endl;
314 ed <<
"<Z>= " << Zmat <<
" in G4PenelopeBremsstrahlungAngular" <<
G4endl;
317 G4Exception(
"G4PenelopeBremsstrahlungAngular::PrepareInterpolationTables()",
333 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
343 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
349 if (fEffectiveZSq->count(material))
350 Zmat = fEffectiveZSq->find(material)->second;
353 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
354 "em2040",
FatalException,
"Material not found in the effectiveZ table");
358 if (fVerbosityLevel > 0)
360 G4cout <<
"Effective <Z> for material : " << material->
GetName() <<
366 G4double beta = std::sqrt(ePrimary*(ePrimary+2*electron_mass_c2))/
367 (ePrimary+electron_mass_c2);
373 if (ePrimary > 500*keV)
379 cdt = -1.0*std::pow(-cdt,1./3.);
381 cdt = std::pow(cdt,1./3.);
383 cdt = (cdt+beta)/(1.0+beta*cdt);
385 sinTheta = std::sqrt(1. - cdt*cdt);
388 sinTheta* std::sin(phi),
396 if (!(fLorentzTables1->count(Zmat)) || !(fLorentzTables2->count(Zmat)))
399 ed <<
"Unable to retrieve Lorentz tables for Z= " << Zmat <<
G4endl;
400 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
405 const G4PhysicsTable* theTable1 = fLorentzTables1->find(Zmat)->second;
406 const G4PhysicsTable* theTable2 = fLorentzTables2->find(Zmat)->second;
417 P10 = v1->
Value(beta);
418 P11 = v2->
Value(beta);
419 P1=P10+(RK-(
G4double) ik)*(P11-P10);
426 P2=P20+(RK-(
G4double) ik)*(P21-P20);
429 P1=std::min(
G4Exp(P1)/beta,1.0);
430 G4double betap = std::min(std::max(beta*(1.0+P2/beta),0.0),0.9999);
448 cdt = (cdt+betap)/(1.0+betap*cdt);
451 sinTheta = std::sqrt(1. - cdt*cdt);
454 sinTheta* std::sin(phi),
465G4double G4PenelopeBremsstrahlungAngular::CalculateEffectiveZ(
const G4Material* material)
468 fEffectiveZSq =
new std::map<const G4Material*,G4double>;
471 if (fEffectiveZSq->count(material))
472 return fEffectiveZSq->find(material)->second;
475 std::vector<G4double> *StechiometricFactors =
new std::vector<G4double>;
479 for (
G4int i=0;i<nElements;++i)
481 G4double fraction = fractionVector[i];
482 G4double atomicWeigth = (*elementVector)[i]->GetA()/(g/mole);
483 StechiometricFactors->push_back(fraction/atomicWeigth);
486 G4double MaxStechiometricFactor = 0.;
487 for (
G4int i=0;i<nElements;++i)
489 if ((*StechiometricFactors)[i] > MaxStechiometricFactor)
490 MaxStechiometricFactor = (*StechiometricFactors)[i];
493 for (
G4int i=0;i<nElements;++i)
494 (*StechiometricFactors)[i] /= MaxStechiometricFactor;
498 for (
G4int i=0;i<nElements;++i)
500 G4double Z = (*elementVector)[i]->GetZ();
501 sumz2 += (*StechiometricFactors)[i]*
Z*
Z;
502 sums += (*StechiometricFactors)[i];
504 delete StechiometricFactors;
506 G4double ZBR = std::sqrt(sumz2/sums);
507 fEffectiveZSq->insert(std::make_pair(material,ZBR));
std::vector< const G4Element * > G4ElementVector
const char * G4FindDataDir(const char *)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
G4double G4Log(G4double x)
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
Hep3Vector & rotateUz(const Hep3Vector &)
const G4ThreeVector & GetMomentumDirection() const
G4double GetKineticEnergy() const
const G4ElementVector * GetElementVector() const
const G4double * GetFractionVector() const
size_t GetNumberOfElements() const
const G4String & GetName() const
~G4PenelopeBremsstrahlungAngular()
G4ThreeVector & SampleDirection(const G4DynamicParticle *dp, G4double out_energy, G4int Z, const G4Material *mat=nullptr) override
Samples the direction of the outgoing photon (in global coordinates).
G4PenelopeBremsstrahlungAngular()
void PrepareTables(const G4Material *material, G4bool isMaster)
Reserved for Master Model.
void PutValues(const std::size_t index, const G4double energy, const G4double value)
void push_back(G4PhysicsVector *)
G4double Value(const G4double energy, std::size_t &lastidx) const
void FillSecondDerivatives(const G4SplineType=G4SplineType::Base, const G4double dir1=0.0, const G4double dir2=0.0)
G4ThreeVector fLocalDirection