63 theLorentzTables1(0),theLorentzTables2(0)
86 void G4PenelopeBremsstrahlungAngular::ClearTables()
88 if (theLorentzTables1)
90 for (
auto j = theLorentzTables1->begin(); j != theLorentzTables1->end(); j++)
96 delete theLorentzTables1;
97 theLorentzTables1 =
nullptr;
100 if (theLorentzTables2)
102 for (
auto j=theLorentzTables2->begin(); j != theLorentzTables2->end(); j++)
108 delete theLorentzTables2;
109 theLorentzTables2 =
nullptr;
113 delete theEffectiveZSq;
114 theEffectiveZSq =
nullptr;
120 void G4PenelopeBremsstrahlungAngular::ReadDataFile()
123 char* path = getenv(
"G4LEDATA");
127 "G4PenelopeBremsstrahlungAngular - G4LEDATA environment variable not set!";
128 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
133 G4String pathFile = pathString +
"/penelope/bremsstrahlung/pdbrang.p08";
134 std::ifstream file(pathFile);
138 G4String excep =
"G4PenelopeBremsstrahlungAngular - data file " + pathFile +
" not found!";
139 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
145 for (k=0;k<NumberofKPoints;k++)
146 for (i=0;i<NumberofZPoints;i++)
147 for (j=0;j<NumberofEPoints;j++)
152 file >> iz1 >> ie1 >> ik1 >> zr >> er >> kr >> a1 >> a2;
154 if ((iz1-1 == i) && (ik1-1 == k) && (ie1-1 == j))
162 ed <<
"Corrupted data file " << pathFile <<
"?" <<
G4endl;
163 G4Exception(
"G4PenelopeBremsstrahlungAngular::ReadDataFile()",
189 G4Exception(
"G4PenelopeBremsstrahlungAngular::PrepareInterpolationTables()",
193 if (!theLorentzTables1)
194 theLorentzTables1 =
new std::map<G4double,G4PhysicsTable*>;
195 if (!theLorentzTables2)
196 theLorentzTables2 =
new std::map<G4double,G4PhysicsTable*>;
198 G4double Zmat = CalculateEffectiveZ(material);
200 const G4int reducedEnergyGrid=21;
204 G4double Q1[NumberofEPoints][NumberofKPoints];
205 G4double Q2[NumberofEPoints][NumberofKPoints];
207 G4double Q1E[NumberofEPoints][reducedEnergyGrid];
208 G4double Q2E[NumberofEPoints][reducedEnergyGrid];
209 G4double pZ[NumberofZPoints] = {2.0,8.0,13.0,47.0,79.0,92.0};
213 for (i=0;i<NumberofEPoints;i++)
215 for (j=0;j<NumberofKPoints;j++)
221 for (k=0;k<NumberofZPoints;k++)
223 QQ1vector->
PutValue(k,pZ[k],std::log(QQ1[k][i][j]));
224 QQ2vector->
PutValue(k,pZ[k],QQ2[k][i][j]);
231 Q2[i][j]=QQ2vector->
Value(Zmat);
238 G4double pK[NumberofKPoints] = {0.0,0.6,0.8,0.95};
241 for(i=0;i<reducedEnergyGrid;i++)
245 for(i=0;i<NumberofEPoints;i++)
249 for (i=0;i<NumberofEPoints;i++)
251 for (j=0;j<NumberofKPoints;j++)
252 Q1[i][j]=Q1[i][j]/Zmat;
256 for (i=0;i<NumberofEPoints;i++)
261 for (j=0;j<NumberofKPoints;j++)
263 Q1vector->
PutValue(j,pK[j],std::log(Q1[i][j]));
264 Q2vector->
PutValue(j,pK[j],Q2[i][j]);
267 for (j=0;j<reducedEnergyGrid;j++)
269 Q1E[i][j]=Q1vector->
Value(ppK[j]);
270 Q2E[i][j]=Q2vector->
Value(ppK[j]);
286 for (j=0;j<reducedEnergyGrid;j++)
294 for (j=0;j<reducedEnergyGrid;j++)
298 for (i=0;i<NumberofEPoints;i++)
300 thevec->
PutValue(i,betas[i],Q1E[i][j]);
301 thevec2->
PutValue(i,betas[i],Q2E[i][j]);
307 if (theLorentzTables1 && theLorentzTables2)
309 theLorentzTables1->insert(std::make_pair(Zmat,theTable1));
310 theLorentzTables2->insert(std::make_pair(Zmat,theTable2));
315 ed <<
"Unable to create tables of Lorentz coefficients for " <<
G4endl;
316 ed <<
"<Z>= " << Zmat <<
" in G4PenelopeBremsstrahlungAngular" <<
G4endl;
319 G4Exception(
"G4PenelopeBremsstrahlungAngular::PrepareInterpolationTables()",
335 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
343 if (!theEffectiveZSq)
345 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
351 if (theEffectiveZSq->count(material))
352 Zmat = theEffectiveZSq->find(material)->second;
355 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
356 "em2040",
FatalException,
"Material not found in the effectiveZ table");
360 if (verbosityLevel > 0)
362 G4cout <<
"Effective <Z> for material : " << material->
GetName() <<
375 if (ePrimary > 500*
keV)
381 cdt = -1.0*std::pow(-cdt,1./3.);
383 cdt = std::pow(cdt,1./3.);
385 cdt = (cdt+beta)/(1.0+beta*cdt);
387 sinTheta = std::sqrt(1. - cdt*cdt);
390 sinTheta* std::sin(phi),
398 if (!(theLorentzTables1->count(Zmat)) || !(theLorentzTables2->count(Zmat)))
401 ed <<
"Unable to retrieve Lorentz tables for Z= " << Zmat <<
G4endl;
402 G4Exception(
"G4PenelopeBremsstrahlungAngular::SampleDirection()",
407 const G4PhysicsTable* theTable1 = theLorentzTables1->find(Zmat)->second;
408 const G4PhysicsTable* theTable2 = theLorentzTables2->find(Zmat)->second;
419 P10 = v1->
Value(beta);
450 cdt = (cdt+betap)/(1.0+betap*cdt);
453 sinTheta = std::sqrt(1. - cdt*cdt);
456 sinTheta* std::sin(phi),
471 G4cout <<
"WARNING: G4PenelopeBremsstrahlungAngular() does NOT support PolarAngle()" <<
G4endl;
472 G4cout <<
"Please use the alternative interface SampleDirection()" <<
G4endl;
473 G4Exception(
"G4PenelopeBremsstrahlungAngular::PolarAngle()",
480 G4double G4PenelopeBremsstrahlungAngular::CalculateEffectiveZ(
const G4Material* material)
482 if (!theEffectiveZSq)
483 theEffectiveZSq =
new std::map<const G4Material*,G4double>;
486 if (theEffectiveZSq->count(material))
487 return theEffectiveZSq->find(material)->second;
490 std::vector<G4double> *StechiometricFactors =
new std::vector<G4double>;
494 for (
G4int i=0;i<nElements;i++)
496 G4double fraction = fractionVector[i];
497 G4double atomicWeigth = (*elementVector)[i]->GetA()/(
g/
mole);
498 StechiometricFactors->push_back(fraction/atomicWeigth);
501 G4double MaxStechiometricFactor = 0.;
502 for (
G4int i=0;i<nElements;i++)
504 if ((*StechiometricFactors)[i] > MaxStechiometricFactor)
505 MaxStechiometricFactor = (*StechiometricFactors)[i];
508 for (
G4int i=0;i<nElements;i++)
509 (*StechiometricFactors)[i] /= MaxStechiometricFactor;
513 for (
G4int i=0;i<nElements;i++)
515 G4double Z = (*elementVector)[i]->GetZ();
516 sumz2 += (*StechiometricFactors)[i]*Z*
Z;
517 sums += (*StechiometricFactors)[i];
519 delete StechiometricFactors;
521 G4double ZBR = std::sqrt(sumz2/sums);
522 theEffectiveZSq->insert(std::make_pair(material,ZBR));
void set(double x, double y, double z)
static const G4double * P1[nN]
std::vector< G4Element * > G4ElementVector
std::ostringstream G4ExceptionDescription
G4double GetKineticEnergy() const
const G4String & GetName() const
void push_back(G4PhysicsVector *)
static const G4double P20[nE]
void PutValue(size_t index, G4double energy, G4double dataValue)
static const G4double P10[nE]
static const G4double P11[nE]
void PrepareTables(const G4Material *material, G4bool isMaster)
Reserved for Master Model.
static constexpr double g
G4ThreeVector & SampleDirection(const G4DynamicParticle *dp, G4double out_energy, G4int Z, const G4Material *mat=0)
Samples the direction of the outgoing photon (in global coordinates).
const G4ElementVector * GetElementVector() const
static constexpr double twopi
static constexpr double electron_mass_c2
G4GLOB_DLL std::ostream G4cout
const G4ThreeVector & GetMomentumDirection() const
Hep3Vector & rotateUz(const Hep3Vector &)
G4double Value(G4double theEnergy, size_t &lastidx) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
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 const G4double * P2[nN]
G4PenelopeBremsstrahlungAngular()
static constexpr double MeV
size_t GetNumberOfElements() const
G4ThreeVector fLocalDirection
G4double PolarAngle(const G4double initial_energy, const G4double final_energy, const G4int Z)
const G4double * GetFractionVector() const
~G4PenelopeBremsstrahlungAngular()
static constexpr double keV
static constexpr double mole
static const G4double P21[nE]