Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4SBBremTable Class Reference

#include <G4SBBremTable.hh>

Public Member Functions

 G4SBBremTable ()
 
 ~G4SBBremTable ()
 
void Initialize (const G4double lowe, const G4double highe)
 
void ClearSamplingTables ()
 
double SampleEnergyTransfer (const G4double eekin, const G4double leekin, const G4double gcut, const G4double dielSupConst, const G4int izet, const G4int matCutIndx, const bool iselectron)
 

Detailed Description

Definition at line 63 of file G4SBBremTable.hh.

Constructor & Destructor Documentation

◆ G4SBBremTable()

G4SBBremTable::G4SBBremTable ( )

Definition at line 64 of file G4SBBremTable.cc.

65 : fMaxZet(-1), fNumElEnergy(-1), fNumKappa(-1), fUsedLowEenergy(-1.),
66 fUsedHighEenergy(-1.), fLogMinElEnergy(-1.), fILDeltaElEnergy(-1.)
67{}

◆ ~G4SBBremTable()

G4SBBremTable::~G4SBBremTable ( )

Definition at line 69 of file G4SBBremTable.cc.

70{
72}
void ClearSamplingTables()

Member Function Documentation

◆ ClearSamplingTables()

void G4SBBremTable::ClearSamplingTables ( )

Definition at line 452 of file G4SBBremTable.cc.

452 {
453 for (G4int iz=0; iz<fMaxZet+1; ++iz) {
454 if (fSBSamplingTables[iz]) {
455 for (G4int iee=0; iee<fNumElEnergy; ++iee) {
456 if (fSBSamplingTables[iz]->fTablesPerEnergy[iee]) {
457 fSBSamplingTables[iz]->fTablesPerEnergy[iee]->fSTable.clear();
458 fSBSamplingTables[iz]->fTablesPerEnergy[iee]->fCumCutValues.clear();
459 }
460 }
461 fSBSamplingTables[iz]->fTablesPerEnergy.clear();
462 fSBSamplingTables[iz]->fGammaECuts.clear();
463 fSBSamplingTables[iz]->fLogGammaECuts.clear();
464 fSBSamplingTables[iz]->fMatCutIndxToGamCutIndx.clear();
465 //
466 delete fSBSamplingTables[iz];
467 fSBSamplingTables[iz] = nullptr;
468 }
469 }
470 fSBSamplingTables.clear();
471 fElEnergyVect.clear();
472 fLElEnergyVect.clear();
473 fKappaVect.clear();
474 fLKappaVect.clear();
475 fMaxZet = -1;
476}
int G4int
Definition G4Types.hh:85

Referenced by ~G4SBBremTable().

◆ Initialize()

void G4SBBremTable::Initialize ( const G4double lowe,
const G4double highe )

Definition at line 74 of file G4SBBremTable.cc.

75{
76 fUsedLowEenergy = lowe;
77 fUsedHighEenergy = highe;
78 BuildSamplingTables();
79 InitSamplingTables();
80// Dump();
81}

Referenced by G4SeltzerBergerModel::Initialise().

◆ SampleEnergyTransfer()

double G4SBBremTable::SampleEnergyTransfer ( const G4double eekin,
const G4double leekin,
const G4double gcut,
const G4double dielSupConst,
const G4int izet,
const G4int matCutIndx,
const bool iselectron )

Definition at line 84 of file G4SBBremTable.cc.

91{
92 static const G4double kAlpha2Pi = CLHEP::twopi*CLHEP::fine_structure_const;
93 const G4double zet = (G4double)iZet;
94 const G4int izet = std::max(std::min(fMaxZet, iZet),1);
95 G4double eGamma = 0.;
96 // this should be checked in the caller
97 // if (eekin<=gcut) return kappa;
98 const G4double lElEnergy = leekin;
99 const SamplingTablePerZ* stZ = fSBSamplingTables[izet];
100 // get the gamma cut of this Z that corresponds to the current mat-cuts
101 const std::size_t gamCutIndx = stZ->fMatCutIndxToGamCutIndx[matCutIndx];
102 // gcut was not found: should never happen (only in verbose mode)
103 if (gamCutIndx >= stZ->fNumGammaCuts || stZ->fGammaECuts[gamCutIndx]!=gcut) {
104 G4String msg = " Gamma cut="+std::to_string(gcut) + " [MeV] was not found ";
105 msg += "in case of Z = " + std::to_string(iZet) + ". ";
106 G4Exception("G4SBBremTable::SampleEnergyTransfer()","em0X",FatalException,
107 msg.c_str());
108 }
109 const G4double lGCut = stZ->fLogGammaECuts[gamCutIndx];
110 // get the random engine
111 CLHEP::HepRandomEngine* rndmEngine = G4Random::getTheEngine();
112 // find lower e- energy bin
113 G4bool isCorner = false; // indicate that the lower edge e- energy < gam-gut
114 G4bool isSimply = false; // simply sampling: isCorner+lower egde is selected
115 G4int elEnergyIndx = stZ->fMaxElEnergyIndx;
116 // only if e- ekin is below the maximum value(use table at maximum otherwise)
117 if (eekin < fElEnergyVect[elEnergyIndx]) {
118 const G4double val = (lElEnergy-fLogMinElEnergy)*fILDeltaElEnergy;
119 elEnergyIndx = (G4int)val;
120 G4double pIndxH = val-elEnergyIndx;
121 // check if we are at limiting case: lower edge e- energy < gam-gut
122 if (fElEnergyVect[elEnergyIndx]<=gcut) {
123 // recompute the probability of taking the higher e- energy bin()
124 pIndxH = (lElEnergy-lGCut)/(fLElEnergyVect[elEnergyIndx+1]-lGCut);
125 isCorner = true;
126 }
127 //
128 if (rndmEngine->flat()<pIndxH) {
129 ++elEnergyIndx; // take the table at the higher e- energy bin
130 } else if (isCorner) { // take the table at the lower e- energy bin
131 // special sampling need to be done if lower edge e- energy < gam-gut:
132 // actually, we "sample" from a table "built" at the gamm-cut i.e. delta
133 isSimply = true;
134 }
135 }
136 // should never happen under normal conditions but add protection
137 if (!stZ->fTablesPerEnergy[elEnergyIndx]) {
138 return 0.;
139 }
140 // Do the photon energy sampling:
141 const STable *st = stZ->fTablesPerEnergy[elEnergyIndx];
142 const std::vector<G4double>& cVect = st->fCumCutValues;
143 const std::vector<STPoint>& pVect = st->fSTable;
144 const G4double minVal = cVect[gamCutIndx];
145
146 // should never happen under normal conditions but add protection
147 if (minVal >= 1.) {
148 return 0.;
149 }
150 // some transfomrmtion variables used in the looop
151 const G4double lCurKappaC = lGCut - leekin;
152 const G4double lUsedKappaC = lGCut - fLElEnergyVect[elEnergyIndx];
153 // dielectric (always) and e+ correction suppressions (if the primary is e+)
154 G4double suppression = 1.;
155 G4double rndm[2];
156 // rejection loop starts here
157 do {
158 rndmEngine->flatArray(2, rndm);
159 G4double kappa = 1.0;
160 if (!isSimply) {
161 const G4double cumRV = rndm[0]*(1.-minVal)+minVal;
162 // find lower index of the values in the Cumulative Function: use linear
163 // instead of binary search because it's faster in our case
164 const G4int cumLIndx = LinSearch(pVect, fNumKappa, cumRV)-1;
165// const G4int cumLIndx = std::lower_bound( pVect.begin(), pVect.end(), cumRV,
166// [](const STPoint& p, const double& cumV) {
167// return p.fCum<cumV; } ) - pVect.begin() -1;
168 const STPoint& stPL = pVect[cumLIndx];
169 const G4double pA = stPL.fParA;
170 const G4double pB = stPL.fParB;
171 const G4double cumL = stPL.fCum;
172 const G4double cumH = pVect[cumLIndx+1].fCum;
173 const G4double lKL = fLKappaVect[cumLIndx];
174 const G4double lKH = fLKappaVect[cumLIndx+1];
175 const G4double dm1 = (cumRV-cumL)/(cumH-cumL);
176 const G4double dm2 = (1.+pA+pB)*dm1;
177 const G4double dm3 = 1.+dm1*(pA+pB*dm1);
178 // kappa sampled at E_i e- energy
179 const G4double lKappa = lKL+dm2/dm3*(lKH-lKL);
180 // transform lKappa to [log(gcut/eekin),0] form [log(gcut/E_i),0]
181 kappa = G4Exp(lKappa*lCurKappaC/lUsedKappaC);
182 } else {
183// const G4double upLimit = std::min(1.*CLHEP::eV,eekin-gcut);
184// kappa = (gcut+rndm[0]*upLimit)/eekin;
185 kappa = 1.-rndm[0]*(1.-gcut/eekin);
186 }
187 // compute the emitted photon energy: k
188 eGamma = kappa*eekin;
189 const G4double invEGamma = 1./eGamma;
190 // compute dielectric suppression: 1/(1+[gk_p/k]^2)
191 suppression = 1./(1.+dielSupConst*invEGamma*invEGamma);
192 // add positron correction if particle is e+
193 if (!isElectron) {
194 const G4double e1 = eekin - gcut;
195 const G4double iBeta1 = (e1 + CLHEP::electron_mass_c2)
196 / std::sqrt(e1*(e1 + 2.*CLHEP::electron_mass_c2));
197 const G4double e2 = eekin - eGamma;
198 const G4double iBeta2 = (e2 + CLHEP::electron_mass_c2)
199 / std::sqrt(e2*(e2 + 2.*CLHEP::electron_mass_c2));
200 const G4double dum = kAlpha2Pi*zet*(iBeta1 - iBeta2);
201 suppression = (dum > -12.) ? suppression*G4Exp(dum) : 0.;
202 }
203 } while (rndm[1] > suppression);
204 // end of rejection loop
205 // return the sampled photon energy value k
206 return eGamma;
207}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition G4Exp.hh:180
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
virtual double flat()=0
virtual void flatArray(const int size, double *vect)=0

Referenced by G4SeltzerBergerModel::SampleSecondaries().


The documentation for this class was generated from the following files: