Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // $Id: G4EmConfigurator.cc 97432 2016-06-03 07:23:39Z gcosmo $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 Class
31 //
32 // File name: G4EmConfigurator
33 //
34 // Author: Vladimir Ivanchenko
35 //
36 // Creation date: 14.07.2008
37 //
38 // Modifications:
39 //
40 // Class Description:
41 //
42 // This class provides configuration EM models for
43 // particles/processes/regions
44 //
45 
46 // -------------------------------------------------------------------
47 //
48 
49 #include "G4EmConfigurator.hh"
50 #include "G4SystemOfUnits.hh"
51 #include "G4ParticleTable.hh"
52 #include "G4ParticleDefinition.hh"
53 #include "G4ProcessManager.hh"
54 #include "G4VProcess.hh"
55 #include "G4ProcessVector.hh"
56 #include "G4RegionStore.hh"
57 #include "G4Region.hh"
58 #include "G4DummyModel.hh"
59 #include "G4VEnergyLossProcess.hh"
60 #include "G4VEmProcess.hh"
61 #include "G4VMultipleScattering.hh"
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66 {
67  index = -10;
68 }
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
73 {}
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
78  const G4String& processName,
79  G4VEmModel* mod,
80  const G4String& regionName,
81  G4double emin,
82  G4double emax,
84 {
85  if(!mod) { return; }
86  if(1 < verbose) {
87  G4cout << " G4EmConfigurator::SetExtraEmModel " << mod->GetName()
88  << " for " << particleName
89  << " and " << processName
90  << " in the region <" << regionName
91  << "> Emin(MeV)= " << emin/MeV
92  << " Emax(MeV)= " << emax/MeV
93  << G4endl;
94  }
95 
96  models.push_back(mod);
97  flucModels.push_back(fm);
98  emin = std::max(emin, mod->LowEnergyLimit());
99  emax = std::min(emax, mod->HighEnergyLimit());
100  mod->SetActivationHighEnergyLimit(emax);
101 
102  particles.push_back(particleName);
103  processes.push_back(processName);
104  regions.push_back(regionName);
105  lowEnergy.push_back(emin);
106  highEnergy.push_back(emax);
107 }
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110 
112 {
113  size_t n = models.size();
114  if(0 < verbose) {
115  G4cout << "### G4EmConfigurator::AddModels n= " << n << G4endl;
116  }
117  if(n > 0) {
118  for(size_t i=0; i<n; ++i) {
119  if(models[i]) {
120  G4Region* reg = FindRegion(regions[i]);
121  if(reg) {
122  --index;
123  SetModelForRegion(models[i],flucModels[i],reg,
124  particles[i],processes[i],
125  lowEnergy[i],highEnergy[i]);
126  }
127  }
128  }
129  }
130  Clear();
131 }
132 
133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
134 
135 void G4EmConfigurator::SetModelForRegion(G4VEmModel* mod,
137  G4Region* reg,
138  const G4String& particleName,
139  const G4String& processName,
140  G4double emin, G4double emax)
141 {
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  }
155 
156  // Loop checking, 03-Aug-2015, Vladimir Ivanchenko
157  theParticleIterator->reset();
158  while( (*theParticleIterator)() ) {
159  const G4ParticleDefinition* part = theParticleIterator->value();
160 
161  //G4cout << particleName << " " << part->GetParticleName() << G4endl;
162 
163  if((part->GetParticleName() == particleName) ||
164  (particleName == "all") ||
165  (particleName == "charged" && part->GetPDGCharge() != 0.0)) {
166 
167  // search for process
168  G4ProcessManager* pmanager = part->GetProcessManager();
169  G4ProcessVector* plist = pmanager->GetProcessList();
170  G4int np = pmanager->GetProcessListLength();
171 
172  //G4cout << processName << " in list of " << np << G4endl;
173 
174  G4VProcess* proc = 0;
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(mod) {
188  if(!UpdateModelEnergyRange(mod, emin, emax)) { return; }
189  }
190  // classify process
191  G4int ii = proc->GetProcessSubType();
192  if(10 == ii && mod) {
193  G4VMultipleScattering* p = static_cast<G4VMultipleScattering*>(proc);
194  p->AddEmModel(index,mod,reg);
195  if(1 < verbose) {
196  G4cout << "### Added msc model order= " << index << " for "
197  << particleName << " and " << processName << G4endl;
198  }
199  } else if(2 <= ii && 4 >= ii) {
200  G4VEnergyLossProcess* p = static_cast<G4VEnergyLossProcess*>(proc);
201  if(!mod && fm) {
202  p->SetFluctModel(fm);
203  } else {
204  p->AddEmModel(index,mod,fm,reg);
205  if(1 < verbose) {
206  G4cout << "### Added eloss model order= " << index << " for "
207  << particleName << " and " << processName << G4endl;
208  }
209  }
210  } else if(mod) {
211  G4VEmProcess* p = static_cast<G4VEmProcess*>(proc);
212  p->AddEmModel(index,mod,reg);
213  if(1 < verbose) {
214  G4cout << "### Added em model order= " << index << " for "
215  << particleName << " and " << processName << G4endl;
216  }
217  }
218  return;
219  }
220  }
221 }
222 
223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
224 
225 void
228 {
229  size_t n = particles.size();
230  if(1 < verbose) {
231  G4cout << " G4EmConfigurator::PrepareModels for EnergyLoss n= "
232  << n << G4endl;
233  }
234  if(n > 0) {
235  G4String particleName = aParticle->GetParticleName();
236  G4String processName = p->GetProcessName();
237  //G4cout << particleName << " " << processName << G4endl;
238  for(size_t i=0; i<n; ++i) {
239  //G4cout << particles[i] << " " << processes[i] << G4endl;
240  if(processName == processes[i]) {
241  if((particleName == particles[i]) ||
242  (particles[i] == "all") ||
243  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
244  G4Region* reg = FindRegion(regions[i]);
245  //G4cout << "Region " << reg << G4endl;
246  if(reg) {
247  --index;
248  G4VEmModel* mod = models[i];
249  G4VEmFluctuationModel* fm = flucModels[i];
250  if(mod) {
251  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
252  p->AddEmModel(index,mod,fm,reg);
253  if(1 < verbose) {
254  G4cout << "### Added eloss model order= " << index << " for "
255  << particleName << " and " << processName << G4endl;
256  }
257  }
258  } else if(fm) {
259  p->SetFluctModel(fm);
260  }
261  }
262  }
263  }
264  }
265  }
266 }
267 
268 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
269 
270 void
272  G4VEmProcess* p)
273 {
274  size_t n = particles.size();
275  if(1 < verbose) {
276  G4cout << " G4EmConfigurator::PrepareModels for EM process n= "
277  << n << G4endl;
278  }
279  if(n > 0) {
280  G4String particleName = aParticle->GetParticleName();
281  G4String processName = p->GetProcessName();
282  //G4cout << particleName << " " << particleName << G4endl;
283  for(size_t i=0; i<n; ++i) {
284  if(processName == processes[i]) {
285  if((particleName == particles[i]) ||
286  (particles[i] == "all") ||
287  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
288  G4Region* reg = FindRegion(regions[i]);
289  //G4cout << "Region " << reg << G4endl;
290  if(reg) {
291  --index;
292  G4VEmModel* mod = models[i];
293  if(mod) {
294  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
295  p->AddEmModel(index,mod,reg);
296  if(1 < verbose) {
297  G4cout << "### Added em model order= " << index << " for "
298  << particleName << " and " << processName << G4endl;
299  }
300  }
301  }
302  }
303  }
304  }
305  }
306  }
307 }
308 
309 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
310 
311 void
314 {
315  size_t n = particles.size();
316  if(1 < verbose) {
317  G4cout << " G4EmConfigurator::PrepareModels for MSC process n= "
318  << n << G4endl;
319  }
320 
321  if(n > 0) {
322  G4String particleName = aParticle->GetParticleName();
323  G4String processName = p->GetProcessName();
324  for(size_t i=0; i<n; ++i) {
325  if(processName == processes[i]) {
326  if((particleName == particles[i]) ||
327  (particles[i] == "all") ||
328  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
329  G4Region* reg = FindRegion(regions[i]);
330  if(reg) {
331  --index;
332  G4VEmModel* mod = models[i];
333  if(mod) {
334  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
335  p->AddEmModel(index,mod,reg);
336  //G4cout << "### Added msc model order= " << index << " for "
337  // << particleName << " and " << processName << G4endl;
338  }
339  }
340  }
341  }
342  }
343  }
344  }
345 }
346 
347 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
348 
350 {
351  particles.clear();
352  processes.clear();
353  models.clear();
354  flucModels.clear();
355  regions.clear();
356  lowEnergy.clear();
357  highEnergy.clear();
358 }
359 
360 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
361 
362 G4Region* G4EmConfigurator::FindRegion(const G4String& regionName)
363 {
364  // search for region
365  G4Region* reg = 0;
367  G4String r = regionName;
368  if(r == "" || r == "world" || r == "World") {
369  r = "DefaultRegionForTheWorld";
370  }
371  reg = regStore->GetRegion(r, true);
372  if(!reg) {
373  G4cout << "### G4EmConfigurator WARNING: fails to find a region <"
374  << r << G4endl;
375  } else if(verbose > 1) {
376  G4cout << "### G4EmConfigurator finds out G4Region <" << r << ">"
377  << G4endl;
378  }
379  return reg;
380 }
381 
382 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
383 
384 G4bool G4EmConfigurator::UpdateModelEnergyRange(G4VEmModel* mod,
385  G4double emin, G4double emax)
386 {
387  // energy limits
388  G4double e1 = std::max(emin,mod->LowEnergyLimit());
389  G4double e2 = std::min(emax,mod->HighEnergyLimit());
390  if(e2 <= e1) {
391  G4cout << "### G4EmConfigurator WARNING: empty energy interval"
392  << " for <" << mod->GetName()
393  << "> Emin(MeV)= " << e1/CLHEP::MeV
394  << "> Emax(MeV)= " << e2/CLHEP::MeV
395  << G4endl;
396  return false;
397  }
398  mod->SetLowEnergyLimit(e1);
399  mod->SetHighEnergyLimit(e2);
400  if(verbose > 1) {
401  G4cout << "### G4EmConfigurator for " << mod->GetName()
402  << " Emin(MeV)= " << e1/MeV << " Emax(MeV)= " << e2/MeV
403  << G4endl;
404  }
405  return true;
406 }
407 
408 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetActivationHighEnergyLimit(G4double)
Definition: G4VEmModel.hh:746
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:643
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
const G4String & GetName() const
G4double HighEnergyLimit() const
Definition: G4VEmModel.hh:636
const char * p
Definition: xmltok.h:285
void SetExtraEmModel(const G4String &particleName, const G4String &processName, G4VEmModel *, const G4String &regionName="", G4double emin=0.0, G4double emax=DBL_MAX, G4VEmFluctuationModel *fm=nullptr)
const G4String & GetName() const
void SetFluctModel(G4VEmFluctuationModel *)
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
static const G4double reg
void SetHighEnergyLimit(G4double)
Definition: G4VEmModel.hh:732
static G4RegionStore * GetInstance()
void AddEmModel(G4int, G4VEmModel *, G4VEmFluctuationModel *fluc=0, const G4Region *region=nullptr)
G4GLOB_DLL std::ostream G4cout
void reset(G4bool ifSkipIon=true)
bool G4bool
Definition: G4Types.hh:79
G4EmConfigurator(G4int verboseLevel=1)
static constexpr double MeV
#define theParticleIterator
const G4int n
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
static const G4double emax
void AddEmModel(G4int, G4VEmModel *, const G4Region *region=nullptr)
static G4ParticleTable * GetParticleTable()
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4ProcessManager * GetProcessManager() const
void PrepareModels(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
void AddEmModel(G4int order, G4VEmModel *, const G4Region *region=nullptr)
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
const G4String & GetName() const
Definition: G4VEmModel.hh:802
double G4double
Definition: G4Types.hh:76
void SetLowEnergyLimit(G4double)
Definition: G4VEmModel.hh:739
G4double GetPDGCharge() const
G4int GetProcessListLength() const
G4int GetProcessSubType() const
Definition: G4VProcess.hh:426
G4PTblDicIterator * GetIterator() const
G4ProcessVector * GetProcessList() const