Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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,
81 G4double emax,
83{
84 if(!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(models[i]) {
119 G4Region* reg = FindRegion(regions[i]);
120 if(reg) {
121 --index;
122 SetModelForRegion(models[i],flucModels[i],reg,
123 particles[i],processes[i],
124 lowEnergy[i],highEnergy[i]);
125 }
126 }
127 }
128 }
129 Clear();
130}
131
132//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133
134void G4EmConfigurator::SetModelForRegion(G4VEmModel* mod,
136 G4Region* reg,
137 const G4String& particleName,
138 const G4String& processName,
139 G4double emin, G4double emax)
140{
141 if(!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(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(!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 G4Region* reg = FindRegion(regions[i]);
239 //G4cout << "Region " << reg << G4endl;
240 if(reg) {
241 --index;
242 G4VEmModel* mod = models[i];
243 G4VEmFluctuationModel* fm = flucModels[i];
244 if(mod) {
245 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
246 p->AddEmModel(index,mod,fm,reg);
247 if(1 < verbose) {
248 G4cout << "### Added eloss model order= " << index << " for "
249 << particleName << " and " << processName << G4endl;
250 }
251 }
252 } else if(fm) {
253 p->SetFluctModel(fm);
254 }
255 }
256 }
257 }
258 }
259 }
260}
261
262//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
263
264void
266 G4VEmProcess* p)
267{
268 size_t n = particles.size();
269 if(1 < verbose) {
270 G4cout << " G4EmConfigurator::PrepareModels for EM process n= "
271 << n << G4endl;
272 }
273 if(n > 0) {
274 G4String particleName = aParticle->GetParticleName();
275 G4String processName = p->GetProcessName();
276 //G4cout << particleName << " " << particleName << G4endl;
277 for(size_t i=0; i<n; ++i) {
278 if(processName == processes[i]) {
279 if((particleName == particles[i]) ||
280 (particles[i] == "all") ||
281 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
282 G4Region* reg = FindRegion(regions[i]);
283 //G4cout << "Region " << reg << G4endl;
284 if(reg) {
285 --index;
286 G4VEmModel* mod = models[i];
287 if(mod) {
288 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
289 p->AddEmModel(index,mod,reg);
290 if(1 < verbose) {
291 G4cout << "### Added em model order= " << index << " for "
292 << particleName << " and " << processName << G4endl;
293 }
294 }
295 }
296 }
297 }
298 }
299 }
300 }
301}
302
303//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
304
305void
308{
309 size_t n = particles.size();
310 if(1 < verbose) {
311 G4cout << " G4EmConfigurator::PrepareModels for MSC process n= "
312 << n << G4endl;
313 }
314
315 if(n > 0) {
316 G4String particleName = aParticle->GetParticleName();
317 G4String processName = p->GetProcessName();
318 for(size_t i=0; i<n; ++i) {
319 if(processName == processes[i]) {
320 if((particleName == particles[i]) ||
321 (particles[i] == "all") ||
322 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
323 G4Region* reg = FindRegion(regions[i]);
324 if(reg) {
325 --index;
326 G4VEmModel* mod = models[i];
327 if(mod) {
328 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
329 p->AddEmModel(index,mod,reg);
330 //G4cout << "### Added msc model order= " << index << " for "
331 // << particleName << " and " << processName << G4endl;
332 }
333 }
334 }
335 }
336 }
337 }
338 }
339}
340
341//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
342
344{
345 particles.clear();
346 processes.clear();
347 models.clear();
348 flucModels.clear();
349 regions.clear();
350 lowEnergy.clear();
351 highEnergy.clear();
352}
353
354//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
355
356G4Region* G4EmConfigurator::FindRegion(const G4String& regionName)
357{
358 // search for region
359 G4Region* reg = 0;
361 G4String r = regionName;
362 if(r == "" || r == "world" || r == "World") {
363 r = "DefaultRegionForTheWorld";
364 }
365 reg = regStore->GetRegion(r, true);
366 if(!reg) {
367 G4cout << "### G4EmConfigurator WARNING: fails to find a region <"
368 << r << G4endl;
369 } else if(verbose > 1) {
370 G4cout << "### G4EmConfigurator finds out G4Region <" << r << ">"
371 << G4endl;
372 }
373 return reg;
374}
375
376//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
377
378G4bool G4EmConfigurator::UpdateModelEnergyRange(G4VEmModel* mod,
379 G4double emin, G4double emax)
380{
381 // energy limits
382 G4double e1 = std::max(emin,mod->LowEnergyLimit());
383 G4double e2 = std::min(emax,mod->HighEnergyLimit());
384 if(e2 <= e1) {
385 G4cout << "### G4EmConfigurator WARNING: empty energy interval"
386 << " for <" << mod->GetName()
387 << "> Emin(MeV)= " << e1/CLHEP::MeV
388 << "> Emax(MeV)= " << e2/CLHEP::MeV
389 << G4endl;
390 return false;
391 }
392 mod->SetLowEnergyLimit(e1);
393 mod->SetHighEnergyLimit(e2);
394 if(verbose > 1) {
395 G4cout << "### G4EmConfigurator for " << mod->GetName()
396 << " Emin(MeV)= " << e1/MeV << " Emax(MeV)= " << e2/MeV
397 << G4endl;
398 }
399 return true;
400}
401
402//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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
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)
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
const G4String & GetName() const
void SetHighEnergyLimit(G4double)
Definition: G4VEmModel.hh:757
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:652
G4double HighEnergyLimit() const
Definition: G4VEmModel.hh:645
void SetLowEnergyLimit(G4double)
Definition: G4VEmModel.hh:764
void SetActivationHighEnergyLimit(G4double)
Definition: G4VEmModel.hh:771
const G4String & GetName() const
Definition: G4VEmModel.hh:827
void AddEmModel(G4int, G4VEmModel *, const G4Region *region=nullptr)
void SetFluctModel(G4VEmFluctuationModel *)
void AddEmModel(G4int, G4VEmModel *, G4VEmFluctuationModel *fluc=0, const G4Region *region=nullptr)
void AddEmModel(G4int order, G4VEmModel *, const G4Region *region=nullptr)
G4int GetProcessSubType() const
Definition: G4VProcess.hh:400
const G4String & GetProcessName() const
Definition: G4VProcess.hh:382