62 theLorentzTables1(0),theLorentzTables2(0)
85void G4PenelopeBremsstrahlungAngular::ClearTables()
87 if (theLorentzTables1)
89 for (
auto j = theLorentzTables1->begin(); j != theLorentzTables1->end(); j++)
95 delete theLorentzTables1;
96 theLorentzTables1 =
nullptr;
99 if (theLorentzTables2)
101 for (
auto j=theLorentzTables2->begin(); j != theLorentzTables2->end(); j++)
107 delete theLorentzTables2;
108 theLorentzTables2 =
nullptr;
112 delete theEffectiveZSq;
113 theEffectiveZSq =
nullptr;
119void G4PenelopeBremsstrahlungAngular::ReadDataFile()
122 char* path = std::getenv(
"G4LEDATA");
126 "G4PenelopeBremsstrahlungAngular - G4LEDATA environment variable not set!";
127 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
132 G4String pathFile = pathString +
"/penelope/bremsstrahlung/pdbrang.p08";
133 std::ifstream file(pathFile);
137 G4String excep =
"G4PenelopeBremsstrahlungAngular - data file " + pathFile +
" not found!";
138 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
144 for (k=0;k<NumberofKPoints;k++)
145 for (i=0;i<NumberofZPoints;i++)
146 for (j=0;j<NumberofEPoints;j++)
151 file >> iz1 >> ie1 >> ik1 >> zr >> er >> kr >> a1 >> a2;
153 if ((iz1-1 == i) && (ik1-1 == k) && (ie1-1 == j))
161 ed <<
"Corrupted data file " << pathFile <<
"?" <<
G4endl;
162 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
188 G4Exception(
"G4PenelopeBremsstrahlungAngular::PrepareInterpolationTables()",
192 if (!theLorentzTables1)
193 theLorentzTables1 =
new std::map<G4double,G4PhysicsTable*>;
194 if (!theLorentzTables2)
195 theLorentzTables2 =
new std::map<G4double,G4PhysicsTable*>;
197 G4double Zmat = CalculateEffectiveZ(material);
199 const G4int reducedEnergyGrid=21;
203 G4double Q1[NumberofEPoints][NumberofKPoints];
204 G4double Q2[NumberofEPoints][NumberofKPoints];
206 G4double Q1E[NumberofEPoints][reducedEnergyGrid];
207 G4double Q2E[NumberofEPoints][reducedEnergyGrid];
208 G4double pZ[NumberofZPoints] = {2.0,8.0,13.0,47.0,79.0,92.0};
212 for (i=0;i<NumberofEPoints;i++)
214 for (j=0;j<NumberofKPoints;j++)
220 for (k=0;k<NumberofZPoints;k++)
223 QQ2vector->
PutValue(k,pZ[k],QQ2[k][i][j]);
230 Q2[i][j]=QQ2vector->
Value(Zmat);
235 G4double pE[NumberofEPoints] = {1.0e-03*MeV,5.0e-03*MeV,1.0e-02*MeV,5.0e-02*MeV,
236 1.0e-01*MeV,5.0e-01*MeV};
237 G4double pK[NumberofKPoints] = {0.0,0.6,0.8,0.95};
240 for(i=0;i<reducedEnergyGrid;i++)
244 for(i=0;i<NumberofEPoints;i++)
245 betas[i]=std::sqrt(pE[i]*(pE[i]+2*electron_mass_c2))/(pE[i]+electron_mass_c2);
248 for (i=0;i<NumberofEPoints;i++)
250 for (j=0;j<NumberofKPoints;j++)
251 Q1[i][j]=Q1[i][j]/Zmat;
255 for (i=0;i<NumberofEPoints;i++)
260 for (j=0;j<NumberofKPoints;j++)
263 Q2vector->
PutValue(j,pK[j],Q2[i][j]);
266 for (j=0;j<reducedEnergyGrid;j++)
268 Q1E[i][j]=Q1vector->
Value(ppK[j]);
269 Q2E[i][j]=Q2vector->
Value(ppK[j]);
285 for (j=0;j<reducedEnergyGrid;j++)
293 for (j=0;j<reducedEnergyGrid;j++)
297 for (i=0;i<NumberofEPoints;i++)
299 thevec->
PutValue(i,betas[i],Q1E[i][j]);
300 thevec2->
PutValue(i,betas[i],Q2E[i][j]);
306 if (theLorentzTables1 && theLorentzTables2)
308 theLorentzTables1->insert(std::make_pair(Zmat,theTable1));
309 theLorentzTables2->insert(std::make_pair(Zmat,theTable2));
314 ed <<
"Unable to create tables of Lorentz coefficients for " <<
G4endl;
315 ed <<
"<Z>= " << Zmat <<
" in G4PenelopeBremsstrahlungAngular" <<
G4endl;
318 G4Exception(
"G4PenelopeBremsstrahlungAngular::PrepareInterpolationTables()",
334 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
342 if (!theEffectiveZSq)
344 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
350 if (theEffectiveZSq->count(material))
351 Zmat = theEffectiveZSq->find(material)->second;
354 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
355 "em2040",
FatalException,
"Material not found in the effectiveZ table");
359 if (verbosityLevel > 0)
361 G4cout <<
"Effective <Z> for material : " << material->
GetName() <<
367 G4double beta = std::sqrt(ePrimary*(ePrimary+2*electron_mass_c2))/
368 (ePrimary+electron_mass_c2);
374 if (ePrimary > 500*keV)
380 cdt = -1.0*std::pow(-cdt,1./3.);
382 cdt = std::pow(cdt,1./3.);
384 cdt = (cdt+beta)/(1.0+beta*cdt);
386 sinTheta = std::sqrt(1. - cdt*cdt);
389 sinTheta* std::sin(phi),
397 if (!(theLorentzTables1->count(Zmat)) || !(theLorentzTables2->count(Zmat)))
400 ed <<
"Unable to retrieve Lorentz tables for Z= " << Zmat <<
G4endl;
401 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
406 const G4PhysicsTable* theTable1 = theLorentzTables1->find(Zmat)->second;
407 const G4PhysicsTable* theTable2 = theLorentzTables2->find(Zmat)->second;
418 P10 = v1->
Value(beta);
419 P11 = v2->
Value(beta);
420 P1=P10+(RK-(
G4double) ik)*(P11-P10);
427 P2=P20+(RK-(
G4double) ik)*(P21-P20);
430 P1=std::min(
G4Exp(P1)/beta,1.0);
431 G4double betap = std::min(std::max(beta*(1.0+P2/beta),0.0),0.9999);
449 cdt = (cdt+betap)/(1.0+betap*cdt);
452 sinTheta = std::sqrt(1. - cdt*cdt);
455 sinTheta* std::sin(phi),
470 G4cout <<
"WARNING: G4PenelopeBremsstrahlungAngular() does NOT support PolarAngle()" <<
G4endl;
471 G4cout <<
"Please use the alternative interface SampleDirection()" <<
G4endl;
472 G4Exception(
"G4PenelopeBremsstrahlungAngular::PolarAngle()",
479G4double G4PenelopeBremsstrahlungAngular::CalculateEffectiveZ(
const G4Material* material)
481 if (!theEffectiveZSq)
482 theEffectiveZSq =
new std::map<const G4Material*,G4double>;
485 if (theEffectiveZSq->count(material))
486 return theEffectiveZSq->find(material)->second;
489 std::vector<G4double> *StechiometricFactors =
new std::vector<G4double>;
493 for (
G4int i=0;i<nElements;i++)
495 G4double fraction = fractionVector[i];
496 G4double atomicWeigth = (*elementVector)[i]->GetA()/(g/mole);
497 StechiometricFactors->push_back(fraction/atomicWeigth);
500 G4double MaxStechiometricFactor = 0.;
501 for (
G4int i=0;i<nElements;i++)
503 if ((*StechiometricFactors)[i] > MaxStechiometricFactor)
504 MaxStechiometricFactor = (*StechiometricFactors)[i];
507 for (
G4int i=0;i<nElements;i++)
508 (*StechiometricFactors)[i] /= MaxStechiometricFactor;
512 for (
G4int i=0;i<nElements;i++)
514 G4double Z = (*elementVector)[i]->GetZ();
515 sumz2 += (*StechiometricFactors)[i]*Z*Z;
516 sums += (*StechiometricFactors)[i];
518 delete StechiometricFactors;
520 G4double ZBR = std::sqrt(sumz2/sums);
521 theEffectiveZSq->insert(std::make_pair(material,ZBR));
std::vector< G4Element * > G4ElementVector
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=0)
Samples the direction of the outgoing photon (in global coordinates).
G4PenelopeBremsstrahlungAngular()
void PrepareTables(const G4Material *material, G4bool isMaster)
Reserved for Master Model.
G4double PolarAngle(const G4double initial_energy, const G4double final_energy, const G4int Z)
void PutValue(std::size_t index, G4double energy, G4double dValue)
void push_back(G4PhysicsVector *)
G4double Value(G4double theEnergy, std::size_t &lastidx) const
G4ThreeVector fLocalDirection