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

#include <G4EmUtility.hh>

Static Public Member Functions

static const G4RegionFindRegion (const G4String &regionName, const G4int verbose=0)
static const G4ElementSampleRandomElement (const G4Material *)
static const G4IsotopeSampleRandomIsotope (const G4Element *)
static std::vector< G4double > * FindCrossSectionMax (G4PhysicsTable *)
static std::vector< G4double > * FindCrossSectionMax (G4VDiscreteProcess *, const G4ParticleDefinition *)
static std::vector< G4TwoPeaksXS * > * FillPeaksStructure (G4PhysicsTable *, G4LossTableBuilder *)
static void InitialiseElementSelectors (G4VEmModel *, const G4ParticleDefinition *, const G4DataVector &cuts, const G4double emin, const G4double emax)
static void FillFluctFlags (std::vector< std::pair< G4String, G4bool > > &reg, std::vector< G4bool > *flags)

Detailed Description

Definition at line 51 of file G4EmUtility.hh.

Member Function Documentation

◆ FillFluctFlags()

void G4EmUtility::FillFluctFlags ( std::vector< std::pair< G4String, G4bool > > & reg,
std::vector< G4bool > * flags )
static

Definition at line 389 of file G4EmUtility.cc.

391{
392 G4RegionStore* regStore = G4RegionStore::GetInstance();
393 G4ProductionCutsTable* theCoupleTable=
395 std::size_t numOfCouples = theCoupleTable->GetTableSize();
396 for (std::size_t i = 0; i < numOfCouples; ++i) {
397 auto couple = theCoupleTable->GetMaterialCutsCouple((G4int)i);
398 auto mat = const_cast<G4Material*>(couple->GetMaterial());
399 for (auto const& r : reg) {
400 const G4String& rname = r.first;
401 G4Region* region = regStore->GetRegion(rname, false);
402 if (nullptr != region) {
403 auto couple1 = region->FindCouple(mat);
404 if (couple1 == couple) {
405 (*flags)[couple->GetIndex()] = r.second;
406 break;
407 }
408 }
409 }
410 }
411}
int G4int
Definition G4Types.hh:85
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
std::size_t GetTableSize() const
static G4ProductionCutsTable * GetProductionCutsTable()
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4MaterialCutsCouple * FindCouple(G4Material *mat)

Referenced by G4EmParameters::DefineFluctuationFlags().

◆ FillPeaksStructure()

std::vector< G4TwoPeaksXS * > * G4EmUtility::FillPeaksStructure ( G4PhysicsTable * p,
G4LossTableBuilder * bld )
static

Definition at line 202 of file G4EmUtility.cc.

203{
204 std::vector<G4TwoPeaksXS*>* ptr = nullptr;
205 if(nullptr == p) { return ptr; }
206
207 const G4int n = (G4int)p->length();
208 ptr = new std::vector<G4TwoPeaksXS*>;
209 ptr->resize(n, nullptr);
210
211 G4double e, ss, xs, ee;
212 G4double e1peak, e1deep, e2peak, e2deep, e3peak;
213 G4bool isDeep = false;
214
215 // first loop on existing vectors
216 for (G4int i=0; i<n; ++i) {
217 const G4PhysicsVector* pv = (*p)[i];
218 ee = xs = 0.0;
219 e1peak = e1deep = e2peak = e2deep = e3peak = DBL_MAX;
220 if(nullptr != pv) {
221 G4int nb = (G4int)pv->GetVectorLength();
222 for (G4int j=0; j<nb; ++j) {
223 e = pv->Energy(j);
224 ss = (*pv)(j);
225 // find out 1st peak
226 if(e1peak == DBL_MAX) {
227 if(ss >= xs) {
228 xs = ss;
229 ee = e;
230 continue;
231 } else {
232 e1peak = ee;
233 }
234 }
235 // find out the deep
236 if(e1deep == DBL_MAX) {
237 if(ss <= xs) {
238 xs = ss;
239 ee = e;
240 continue;
241 } else {
242 e1deep = ee;
243 isDeep = true;
244 }
245 }
246 // find out 2nd peak
247 if(e2peak == DBL_MAX) {
248 if(ss >= xs) {
249 xs = ss;
250 ee = e;
251 continue;
252 } else {
253 e2peak = ee;
254 }
255 }
256 if(e2deep == DBL_MAX) {
257 if(ss <= xs) {
258 xs = ss;
259 ee = e;
260 continue;
261 } else {
262 e2deep = ee;
263 break;
264 }
265 }
266 // find out 3d peak
267 if(e3peak == DBL_MAX) {
268 if(ss >= xs) {
269 xs = ss;
270 ee = e;
271 continue;
272 } else {
273 e3peak = ee;
274 }
275 }
276 }
277 }
278 G4TwoPeaksXS* x = (*ptr)[i];
279 if(nullptr == x) {
280 x = new G4TwoPeaksXS();
281 (*ptr)[i] = x;
282 }
283 x->e1peak = e1peak;
284 x->e1deep = e1deep;
285 x->e2peak = e2peak;
286 x->e2deep = e2deep;
287 x->e3peak = e3peak;
288 }
289 // case of no 1st peak in all vectors
290 if(!isDeep) {
291 for (G4int k=0; k<n; ++k) { delete (*ptr)[k]; }
292 delete ptr;
293 ptr = nullptr;
294 return ptr;
295 }
296 // check base particles
297 if(!bld->GetBaseMaterialFlag()) { return ptr; }
298
299 auto theDensityIdx = bld->GetCoupleIndexes();
300 // second loop using base materials
301 for (G4int i=0; i<n; ++i) {
302 const G4PhysicsVector* pv = (*p)[i];
303 if (nullptr == pv) {
304 G4int j = (*theDensityIdx)[i];
305 if(j == i) { continue; }
306 G4TwoPeaksXS* x = (*ptr)[i];
307 G4TwoPeaksXS* y = (*ptr)[j];
308 if(nullptr == x) {
309 x = new G4TwoPeaksXS();
310 (*ptr)[i] = x;
311 }
312 x->e1peak = y->e1peak;
313 x->e1deep = y->e1deep;
314 x->e2peak = y->e2peak;
315 x->e2deep = y->e2deep;
316 x->e3peak = y->e3peak;
317 }
318 }
319 return ptr;
320}
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
static G4bool GetBaseMaterialFlag()
static const std::vector< G4int > * GetCoupleIndexes()
std::size_t length() const
G4double Energy(const std::size_t index) const
std::size_t GetVectorLength() const
G4double e1peak
G4double e3peak
G4double e2deep
G4double e1deep
G4double e2peak
#define DBL_MAX
Definition templates.hh:62

Referenced by G4VEnergyLossProcess::SetLambdaTable().

◆ FindCrossSectionMax() [1/2]

std::vector< G4double > * G4EmUtility::FindCrossSectionMax ( G4PhysicsTable * p)
static

Definition at line 104 of file G4EmUtility.cc.

105{
106 std::vector<G4double>* ptr = nullptr;
107 if(nullptr == p) { return ptr; }
108
109 const std::size_t n = p->length();
110 ptr = new std::vector<G4double>;
111 ptr->resize(n, DBL_MAX);
112
113 G4bool isPeak = false;
114 G4double e, ss, ee, xs;
115
116 // first loop on existing vectors
117 for (std::size_t i=0; i<n; ++i) {
118 const G4PhysicsVector* pv = (*p)[i];
119 xs = ee = 0.0;
120 if(nullptr != pv) {
121 G4int nb = (G4int)pv->GetVectorLength();
122 for (G4int j=0; j<nb; ++j) {
123 e = pv->Energy(j);
124 ss = (*pv)(j);
125 if(ss >= xs) {
126 xs = ss;
127 ee = e;
128 continue;
129 } else {
130 isPeak = true;
131 (*ptr)[i] = ee;
132 break;
133 }
134 }
135 }
136 }
137
138 // there is no peak for any material
139 if(!isPeak) {
140 delete ptr;
141 ptr = nullptr;
142 }
143 return ptr;
144}

Referenced by G4EmTableUtil::BuildEmProcess(), and G4VEnergyLossProcess::SetLambdaTable().

◆ FindCrossSectionMax() [2/2]

std::vector< G4double > * G4EmUtility::FindCrossSectionMax ( G4VDiscreteProcess * p,
const G4ParticleDefinition * part )
static

Definition at line 149 of file G4EmUtility.cc.

151{
152 std::vector<G4double>* ptr = nullptr;
153 if (nullptr == p || nullptr == part) { return ptr; }
154
155 G4EmParameters* theParameters = G4EmParameters::Instance();
156 const G4double tmin = theParameters->MinKinEnergy();
157 const G4double tmax = theParameters->MaxKinEnergy();
158 const G4double ee = G4Log(tmax/tmin);
159 const G4double scale = theParameters->NumberOfBinsPerDecade()/g4log10;
160 G4int nbin = static_cast<G4int>(ee*scale);
161 nbin = std::max(nbin, 4);
162 G4double x = G4Exp(ee/(G4double)nbin);
163
164 const G4ProductionCutsTable* theCoupleTable=
166 std::size_t n = theCoupleTable->GetTableSize();
167 ptr = new std::vector<G4double>;
168 ptr->resize(n, DBL_MAX);
169
170 G4bool isPeak = false;
171
172 // first loop on existing vectors
173 const G4int nn = static_cast<G4int>(n);
174 for (G4int i=0; i<nn; ++i) {
175 G4double sm = 0.0;
176 G4double em = 0.0;
177 G4double e = tmin;
178 for (G4int j=0; j<=nbin; ++j) {
179 G4double sig = p->GetCrossSection(e, theCoupleTable->GetMaterialCutsCouple(i));
180 if (sig >= sm) {
181 em = e;
182 sm = sig;
183 e = (j+1 < nbin) ? e*x : tmax;
184 } else {
185 isPeak = true;
186 (*ptr)[i] = em;
187 break;
188 }
189 }
190 }
191 // there is no peak for any couple
192 if (!isPeak) {
193 delete ptr;
194 ptr = nullptr;
195 }
196 return ptr;
197}
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition G4Exp.hh:132
G4double G4Log(G4double x)
Definition G4Log.hh:169
static G4EmParameters * Instance()
G4double MinKinEnergy() const
G4int NumberOfBinsPerDecade() const
G4double MaxKinEnergy() const
virtual G4double GetCrossSection(const G4double, const G4MaterialCutsCouple *)

◆ FindRegion()

const G4Region * G4EmUtility::FindRegion ( const G4String & regionName,
const G4int verbose = 0 )
static

Definition at line 47 of file G4EmUtility.cc.

48{
49 const G4Region* reg = nullptr;
50 G4RegionStore* regStore = G4RegionStore::GetInstance();
51 G4String r = regionName;
52 if(r == "") { r = "DefaultRegionForTheWorld"; }
53 reg = regStore->GetRegion(r, true);
54 if(nullptr == reg && verbose > 0) {
55 G4cout << "### G4EmUtility WARNING: fails to find a region <"
56 << r << G4endl;
57 } else if(verbose > 1) {
58 G4cout << "### G4EmUtility finds out G4Region <" << r << ">"
59 << G4endl;
60 }
61 return reg;
62}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

Referenced by G4EmConfigurator::AddModels(), G4EmDNAPhysicsActivator::ConstructProcess(), G4EmCalculator::FindRegion(), G4EmConfigurator::PrepareModels(), G4EmConfigurator::PrepareModels(), and G4EmConfigurator::PrepareModels().

◆ InitialiseElementSelectors()

void G4EmUtility::InitialiseElementSelectors ( G4VEmModel * mod,
const G4ParticleDefinition * part,
const G4DataVector & cuts,
const G4double emin,
const G4double emax )
static

Definition at line 324 of file G4EmUtility.cc.

329{
330 // using spline for element selectors should be investigated in details
331 // because small number of points may provide biased results
332 // large number of points requires significant increase of memory
333 G4bool spline = false;
334
336
337 G4ProductionCutsTable* theCoupleTable=
339 std::size_t numOfCouples = theCoupleTable->GetTableSize();
340
341 // prepare vector
342 auto elmSelectors = mod->GetElementSelectors();
343 if(nullptr == elmSelectors) {
344 elmSelectors = new std::vector<G4EmElementSelector*>;
345 }
346 std::size_t nSelectors = elmSelectors->size();
347 if(numOfCouples > nSelectors) {
348 for(std::size_t i=nSelectors; i<numOfCouples; ++i) {
349 elmSelectors->push_back(nullptr);
350 }
351 nSelectors = numOfCouples;
352 }
353
354 // initialise vector
355 for(std::size_t i=0; i<numOfCouples; ++i) {
356
357 // no need in element selectors for infinite cuts
358 if(cuts[i] == DBL_MAX) { continue; }
359
360 auto couple = theCoupleTable->GetMaterialCutsCouple((G4int)i);
361 auto mat = couple->GetMaterial();
362 mod->SetCurrentCouple(couple);
363
364 // selector already exist then delete
365 delete (*elmSelectors)[i];
366
367 G4double emin = std::max(elow, mod->MinPrimaryEnergy(mat, part, cuts[i]));
368 G4double emax = std::max(ehigh, 10*emin);
369 static const G4double invlog106 = 1.0/(6*G4Log(10.));
370 G4int nbins = G4lrint(nbinsPerDec*G4Log(emax/emin)*invlog106);
371 nbins = std::max(nbins, 3);
372
373 (*elmSelectors)[i] = new G4EmElementSelector(mod,mat,nbins,
374 emin,emax,spline);
375 ((*elmSelectors)[i])->Initialise(part, cuts[i]);
376 /*
377 G4cout << "G4VEmModel::InitialiseElmSelectors i= " << i
378 << " " << part->GetParticleName()
379 << " for " << mod->GetName() << " cut= " << cuts[i]
380 << " " << (*elmSelectors)[i] << G4endl;
381 ((*elmSelectors)[i])->Dump(part);
382 */
383 }
384 mod->SetElementSelectors(elmSelectors);
385}
const G4Material * GetMaterial() const
virtual G4double MinPrimaryEnergy(const G4Material *, const G4ParticleDefinition *, G4double cut=0.0)
void SetElementSelectors(std::vector< G4EmElementSelector * > *)
std::vector< G4EmElementSelector * > * GetElementSelectors()
void SetCurrentCouple(const G4MaterialCutsCouple *)
int G4lrint(double ad)
Definition templates.hh:134

Referenced by G4VEmModel::InitialiseElementSelectors().

◆ SampleRandomElement()

const G4Element * G4EmUtility::SampleRandomElement ( const G4Material * mat)
static

Definition at line 66 of file G4EmUtility.cc.

67{
68 const G4Element* elm = mat->GetElement(0);
69 std::size_t nElements = mat->GetNumberOfElements();
70 if(1 < nElements) {
72 const G4double* y = mat->GetVecNbOfAtomsPerVolume();
73 for(std::size_t i=0; i<nElements; ++i) {
74 elm = mat->GetElement((G4int)i);
75 x -= y[i]*elm->GetZ();
76 if(x <= 0.0) { break; }
77 }
78 }
79 return elm;
80}
#define G4UniformRand()
Definition Randomize.hh:52
G4double GetZ() const
Definition G4Element.hh:119
const G4Element * GetElement(G4int iel) const
G4double GetTotNbOfElectPerVolume() const
const G4double * GetVecNbOfAtomsPerVolume() const
std::size_t GetNumberOfElements() const

Referenced by G4VEmModel::GetCurrentElement().

◆ SampleRandomIsotope()

const G4Isotope * G4EmUtility::SampleRandomIsotope ( const G4Element * elm)
static

Definition at line 84 of file G4EmUtility.cc.

85{
86 const std::size_t ni = elm->GetNumberOfIsotopes();
87 const G4Isotope* iso = elm->GetIsotope(0);
88 if(ni > 1) {
89 const G4double* ab = elm->GetRelativeAbundanceVector();
91 for(std::size_t idx=0; idx<ni; ++idx) {
92 x -= ab[idx];
93 if (x <= 0.0) {
94 iso = elm->GetIsotope((G4int)idx);
95 break;
96 }
97 }
98 }
99 return iso;
100}
G4double * GetRelativeAbundanceVector() const
Definition G4Element.hh:149
std::size_t GetNumberOfIsotopes() const
Definition G4Element.hh:143
const G4Isotope * GetIsotope(G4int iso) const
Definition G4Element.hh:151

Referenced by G4VEmModel::GetCurrentIsotope().


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