Geant4-11
G4EmConfigurator.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// -------------------------------------------------------------------
28//
29// GEANT4 Class
30//
31// File name: G4EmConfigurator
32//
33// Author: Vladimir Ivanchenko
34//
35// Creation date: 14.07.2008
36//
37// Modifications:
38//
39// Class Description:
40//
41// This class provides configuration EM models for
42// particles/processes/regions
43//
44
45// -------------------------------------------------------------------
46//
47
48#include "G4EmConfigurator.hh"
49#include "G4SystemOfUnits.hh"
50#include "G4ParticleTable.hh"
52#include "G4ProcessManager.hh"
53#include "G4VProcess.hh"
54#include "G4ProcessVector.hh"
55#include "G4RegionStore.hh"
56#include "G4Region.hh"
57#include "G4DummyModel.hh"
59#include "G4VEmProcess.hh"
61
62//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63
65{
66 index = -10;
67}
68
69//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70
72{}
73
74//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75
77 const G4String& processName,
78 G4VEmModel* mod,
79 const G4String& regionName,
80 G4double emin,
83{
84 if(nullptr == mod) { return; }
85 if(1 < verbose) {
86 G4cout << " G4EmConfigurator::SetExtraEmModel " << mod->GetName()
87 << " for " << particleName
88 << " and " << processName
89 << " in the region <" << regionName
90 << "> Emin(MeV)= " << emin/MeV
91 << " Emax(MeV)= " << emax/MeV
92 << G4endl;
93 }
94
95 models.push_back(mod);
96 flucModels.push_back(fm);
97 G4double emin0 = std::max(emin, mod->LowEnergyLimit());
98 G4double emax0 = std::min(emax, mod->HighEnergyLimit());
100
101 particles.push_back(particleName);
102 processes.push_back(processName);
103 regions.push_back(regionName);
104 lowEnergy.push_back(emin0);
105 highEnergy.push_back(emax0);
106}
107
108//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109
111{
112 size_t n = models.size();
113 if(0 < verbose) {
114 G4cout << "### G4EmConfigurator::AddModels n= " << n << G4endl;
115 }
116 if(n > 0) {
117 for(size_t i=0; i<n; ++i) {
118 if(nullptr != models[i]) {
119 const G4Region* reg = FindRegion(regions[i]);
120 if(nullptr != reg) {
121 --index;
123 particles[i],processes[i],
124 lowEnergy[i],highEnergy[i]);
125 }
126 }
127 }
128 }
129 Clear();
130}
131
132//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133
136 const G4Region* reg,
137 const G4String& particleName,
138 const G4String& processName,
139 G4double emin, G4double emax)
140{
141 if(nullptr == mod) { return; }
142 if(1 < verbose) {
143 G4cout << " G4EmConfigurator::SetModelForRegion: " << mod->GetName()
144 << G4endl;
145 G4cout << " For " << particleName
146 << " and " << processName
147 << " in the region <" << reg->GetName()
148 << " Emin(MeV)= " << emin/MeV
149 << " Emax(MeV)= " << emax/MeV;
150 if(nullptr != fm) { G4cout << " FLmodel " << fm->GetName(); }
151 G4cout << G4endl;
152 }
153
154 // Loop checking, 03-Aug-2015, Vladimir Ivanchenko
155 auto myParticleIterator = G4ParticleTable::GetParticleTable()->GetIterator();
156 myParticleIterator->reset();
157 while( (*myParticleIterator)() ) {
158 const G4ParticleDefinition* part = myParticleIterator->value();
159
160 if((part->GetParticleName() == particleName) ||
161 (particleName == "all") ||
162 (particleName == "charged" && part->GetPDGCharge() != 0.0)) {
163
164 // search for process
165 G4ProcessManager* pmanager = part->GetProcessManager();
166 G4ProcessVector* plist = pmanager->GetProcessList();
167 G4int np = pmanager->GetProcessListLength();
168
169 if(1 < verbose) {
170 G4cout << "Check process <" << processName << "> for "
171 << particleName << " in list of " << np << " processes"
172 << G4endl;
173 }
174 G4VProcess* proc = nullptr;
175 for(G4int i=0; i<np; ++i) {
176 if(processName == (*plist)[i]->GetProcessName()) {
177 proc = (*plist)[i];
178 break;
179 }
180 }
181 if(nullptr == proc) {
182 G4cout << "### G4EmConfigurator WARNING: fails to find a process <"
183 << processName << "> for " << particleName << G4endl;
184 return;
185 }
186
187 if(!UpdateModelEnergyRange(mod, emin, emax)) { return; }
188 // classify process
189 G4int ii = proc->GetProcessSubType();
190 if(10 == ii) {
191 G4VMultipleScattering* p = static_cast<G4VMultipleScattering*>(proc);
192 p->AddEmModel(index,mod,reg);
193 if(1 < verbose) {
194 G4cout << "### Added msc model order= " << index << " for "
195 << particleName << " and " << processName << G4endl;
196 }
197 } else if(2 <= ii && 4 >= ii) {
198 G4VEnergyLossProcess* p = static_cast<G4VEnergyLossProcess*>(proc);
199 p->AddEmModel(index,mod,fm,reg);
200 if(1 < verbose) {
201 G4cout << "### Added eloss model order= " << index << " for "
202 << particleName << " and " << processName << G4endl;
203 }
204 } else {
205 G4VEmProcess* p = static_cast<G4VEmProcess*>(proc);
206 p->AddEmModel(index,mod,reg);
207 if(1 < verbose) {
208 G4cout << "### Added em model order= " << index << " for "
209 << particleName << " and " << processName << G4endl;
210 }
211 }
212 return;
213 }
214 }
215}
216
217//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218
219void
222{
223 size_t n = particles.size();
224 if(1 < verbose) {
225 G4cout << " G4EmConfigurator::PrepareModels for EnergyLoss n= "
226 << n << G4endl;
227 }
228 if(n > 0) {
229 G4String particleName = aParticle->GetParticleName();
230 G4String processName = p->GetProcessName();
231 //G4cout << particleName << " " << processName << G4endl;
232 for(size_t i=0; i<n; ++i) {
233 //G4cout << particles[i] << " " << processes[i] << G4endl;
234 if(processName == processes[i]) {
235 if((particleName == particles[i]) ||
236 (particles[i] == "all") ||
237 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
238 const G4Region* reg = FindRegion(regions[i]);
239 //G4cout << "Region " << reg << G4endl;
240 if(nullptr != reg) {
241 --index;
242 G4VEmModel* mod = models[i];
244 if(nullptr != mod) {
246 p->AddEmModel(index,mod,fm,reg);
247 if(1 < verbose) {
248 G4cout << "### Added eloss model order= " << index << " for "
249 << particleName << " and " << processName
250 << " for " << reg->GetName() << G4endl;
251 }
252 }
253 } else if(nullptr != fm) {
254 p->SetFluctModel(fm);
255 }
256 }
257 }
258 }
259 }
260 }
261}
262
263//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
264
265void
267 G4VEmProcess* p)
268{
269 size_t n = particles.size();
270 if(1 < verbose) {
271 G4cout << " G4EmConfigurator::PrepareModels for EM process n= "
272 << n << G4endl;
273 }
274 if(n > 0) {
275 G4String particleName = aParticle->GetParticleName();
276 G4String processName = p->GetProcessName();
277 //G4cout << particleName << " " << particleName << G4endl;
278 for(size_t i=0; i<n; ++i) {
279 if(processName == processes[i]) {
280 if((particleName == particles[i]) ||
281 (particles[i] == "all") ||
282 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
283 const G4Region* reg = FindRegion(regions[i]);
284 //G4cout << "Region " << reg << G4endl;
285 if(nullptr != reg) {
286 --index;
287 G4VEmModel* mod = models[i];
288 if(nullptr != mod) {
290 p->AddEmModel(index,mod,reg);
291 if(1 < verbose) {
292 G4cout << "### Added em model order= " << index << " for "
293 << particleName << " and " << processName << G4endl;
294 }
295 }
296 }
297 }
298 }
299 }
300 }
301 }
302}
303
304//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
305
306void
309{
310 size_t n = particles.size();
311 if(1 < verbose) {
312 G4cout << " G4EmConfigurator::PrepareModels for MSC process n= "
313 << n << G4endl;
314 }
315
316 if(n > 0) {
317 G4String particleName = aParticle->GetParticleName();
318 G4String processName = p->GetProcessName();
319 for(size_t i=0; i<n; ++i) {
320 if(processName == processes[i]) {
321 if((particleName == particles[i]) ||
322 (particles[i] == "all") ||
323 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
324 const G4Region* reg = FindRegion(regions[i]);
325 if(nullptr != reg) {
326 --index;
327 G4VEmModel* mod = models[i];
328 if(nullptr != mod) {
330 p->AddEmModel(index,mod,reg);
331 //G4cout << "### Added msc model order= " << index << " for "
332 // << particleName << " and " << processName << G4endl;
333 }
334 }
335 }
336 }
337 }
338 }
339 }
340}
341
342//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
343
345{
346 particles.clear();
347 processes.clear();
348 models.clear();
349 flucModels.clear();
350 regions.clear();
351 lowEnergy.clear();
352 highEnergy.clear();
353}
354
355//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
356
358{
359 // search for region
360 const G4Region* reg = nullptr;
362 G4String r = regionName;
363 if(r == "" || r == "world" || r == "World") {
364 r = "DefaultRegionForTheWorld";
365 }
366 reg = regStore->GetRegion(r, true);
367 if(nullptr == reg) {
368 G4cout << "### G4EmConfigurator WARNING: fails to find a region <"
369 << r << G4endl;
370 } else if(verbose > 1) {
371 G4cout << "### G4EmConfigurator finds out G4Region <" << r << ">"
372 << G4endl;
373 }
374 return reg;
375}
376
377//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
378
380 G4double emin, G4double emax)
381{
382 // energy limits
383 G4double e1 = std::max(emin,mod->LowEnergyLimit());
385 if(e2 <= e1) {
386 G4cout << "### G4EmConfigurator WARNING: empty energy interval"
387 << " for <" << mod->GetName()
388 << "> Emin(MeV)= " << e1/CLHEP::MeV
389 << "> Emax(MeV)= " << e2/CLHEP::MeV
390 << G4endl;
391 return false;
392 }
393 mod->SetLowEnergyLimit(e1);
395 if(verbose > 1) {
396 G4cout << "### G4EmConfigurator for " << mod->GetName()
397 << " Emin(MeV)= " << e1/MeV << " Emax(MeV)= " << e2/MeV
398 << G4endl;
399 }
400 return true;
401}
402
403//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static const G4double e1[44]
static const G4double e2[44]
static const G4double emax
static const G4double reg
static constexpr double MeV
Definition: G4SIunits.hh:200
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
const G4Region * FindRegion(const G4String &)
void SetExtraEmModel(const G4String &particleName, const G4String &processName, G4VEmModel *, const G4String &regionName="", G4double emin=0.0, G4double emax=DBL_MAX, G4VEmFluctuationModel *fm=nullptr)
void PrepareModels(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
G4EmConfigurator(G4int verboseLevel=1)
std::vector< G4String > processes
std::vector< G4double > lowEnergy
std::vector< G4String > particles
G4bool UpdateModelEnergyRange(G4VEmModel *mod, G4double emin, G4double emax)
void SetModelForRegion(G4VEmModel *model, G4VEmFluctuationModel *fm, const G4Region *reg, const G4String &particleName, const G4String &processName, G4double emin, G4double emax)
std::vector< G4VEmModel * > models
std::vector< G4String > regions
std::vector< G4VEmFluctuationModel * > flucModels
std::vector< G4double > highEnergy
G4ProcessManager * GetProcessManager() const
G4double GetPDGCharge() const
const G4String & GetParticleName() const
void reset(G4bool ifSkipIon=true)
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
G4int GetProcessListLength() const
G4ProcessVector * GetProcessList() const
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
const G4String & GetName() const
void SetHighEnergyLimit(G4double)
Definition: G4VEmModel.hh:767
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:662
G4double HighEnergyLimit() const
Definition: G4VEmModel.hh:655
void SetLowEnergyLimit(G4double)
Definition: G4VEmModel.hh:774
void SetActivationHighEnergyLimit(G4double)
Definition: G4VEmModel.hh:781
const G4String & GetName() const
Definition: G4VEmModel.hh:837
void AddEmModel(G4int, G4VEmModel *, const G4Region *region=nullptr)
void AddEmModel(G4int, G4VEmModel *, G4VEmFluctuationModel *fluc=nullptr, const G4Region *region=nullptr)
void SetFluctModel(G4VEmFluctuationModel *)
void AddEmModel(G4int order, G4VEmModel *, const G4Region *region=nullptr)
G4int GetProcessSubType() const
Definition: G4VProcess.hh:400
const G4String & GetProcessName() const
Definition: G4VProcess.hh:382
static constexpr double MeV
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