Geant4  10.02
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 91745 2015-08-04 11:51:12Z 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(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  if(mod) {
95  models.push_back(mod);
96  flucModels.push_back(fm);
97  emax = std::min(emax, mod->HighEnergyLimit());
99  } else {
100  models.push_back(new G4DummyModel());
101  flucModels.push_back(0);
102  }
103 
104  particles.push_back(particleName);
105  processes.push_back(processName);
106  regions.push_back(regionName);
107  lowEnergy.push_back(emin);
108  highEnergy.push_back(emax);
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112 
114 {
115  size_t n = models.size();
116  if(0 < verbose) {
117  G4cout << "### G4EmConfigurator::AddModels n= " << n << G4endl;
118  }
119  if(n > 0) {
120  for(size_t i=0; i<n; ++i) {
121  if(models[i]) {
123  if(reg) {
124  --index;
126  particles[i],processes[i],
127  lowEnergy[i],highEnergy[i]);
128  }
129  }
130  }
131  }
132  Clear();
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
139  G4Region* reg,
140  const G4String& particleName,
141  const G4String& processName,
142  G4double emin, G4double emax)
143 {
144  if(1 < verbose) {
145  G4cout << " G4EmConfigurator::SetModelForRegion: " << mod->GetName()
146  << G4endl;
147  G4cout << " For " << particleName
148  << " and " << processName
149  << " in the region <" << reg->GetName()
150  << " Emin(MeV)= " << emin/MeV
151  << " Emax(MeV)= " << emax/MeV;
152  if(fm) { G4cout << " FLmodel " << fm->GetName(); }
153  G4cout << G4endl;
154  }
157 
158  // Loop checking, 03-Aug-2015, Vladimir Ivanchenko
159  theParticleIterator->reset();
160  while( (*theParticleIterator)() ) {
161  const G4ParticleDefinition* part = theParticleIterator->value();
162 
163  //G4cout << particleName << " " << part->GetParticleName() << G4endl;
164 
165  if((part->GetParticleName() == particleName) ||
166  (particleName == "all") ||
167  (particleName == "charged" && part->GetPDGCharge() != 0.0)) {
168 
169  // search for process
170  G4ProcessManager* pmanager = part->GetProcessManager();
171  G4ProcessVector* plist = pmanager->GetProcessList();
172  G4int np = pmanager->GetProcessListLength();
173 
174  //G4cout << processName << " in list of " << np << G4endl;
175 
176  G4VProcess* proc = 0;
177  for(G4int i=0; i<np; ++i) {
178  if(processName == (*plist)[i]->GetProcessName()) {
179  proc = (*plist)[i];
180  break;
181  }
182  }
183  if(!proc) {
184  G4cout << "### G4EmConfigurator WARNING: fails to find a process <"
185  << processName << "> for " << particleName << G4endl;
186  return;
187  }
188 
189  if(mod) {
190  if(!UpdateModelEnergyRange(mod, emin, emax)) { return; }
191  }
192  // classify process
193  G4int ii = proc->GetProcessSubType();
194  if(10 == ii && mod) {
195  G4VMultipleScattering* p = static_cast<G4VMultipleScattering*>(proc);
196  p->AddEmModel(index,mod,reg);
197  if(1 < verbose) {
198  G4cout << "### Added msc model order= " << index << " for "
199  << particleName << " and " << processName << G4endl;
200  }
201  return;
202  } else if(2 <= ii && 4 >= ii) {
203  G4VEnergyLossProcess* p = static_cast<G4VEnergyLossProcess*>(proc);
204  if(!mod && fm) {
205  p->SetFluctModel(fm);
206  } else {
207  p->AddEmModel(index,mod,fm,reg);
208  if(1 < verbose) {
209  G4cout << "### Added eloss model order= " << index << " for "
210  << particleName << " and " << processName << G4endl;
211  }
212  }
213  return;
214  } else if(mod) {
215  G4VEmProcess* p = static_cast<G4VEmProcess*>(proc);
216  p->AddEmModel(index,mod,reg);
217  if(1 < verbose) {
218  G4cout << "### Added em model order= " << index << " for "
219  << particleName << " and " << processName << G4endl;
220  }
221  return;
222  } else {
223  return;
224  }
225  }
226  }
227 }
228 
229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
230 
231 void
234 {
235  size_t n = particles.size();
236  if(1 < verbose) {
237  G4cout << " G4EmConfigurator::PrepareModels for EnergyLoss n= "
238  << n << G4endl;
239  }
240  if(n > 0) {
241  G4String particleName = aParticle->GetParticleName();
242  G4String processName = p->GetProcessName();
243  //G4cout << particleName << " " << processName << G4endl;
244  for(size_t i=0; i<n; ++i) {
245  //G4cout << particles[i] << " " << processes[i] << G4endl;
246  if(processName == processes[i]) {
247  if((particleName == particles[i]) ||
248  (particles[i] == "all") ||
249  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
251  //G4cout << "Region " << reg << G4endl;
252  if(reg) {
253  --index;
254  G4VEmModel* mod = models[i];
256  if(mod) {
257  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
258  p->AddEmModel(index,mod,fm,reg);
259  if(1 < verbose) {
260  G4cout << "### Added eloss model order= " << index << " for "
261  << particleName << " and " << processName << G4endl;
262  }
263  }
264  } else if(fm) {
265  p->SetFluctModel(fm);
266  }
267  }
268  }
269  }
270  }
271  }
272 }
273 
274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275 
276 void
278  G4VEmProcess* p)
279 {
280  size_t n = particles.size();
281  if(1 < verbose) {
282  G4cout << " G4EmConfigurator::PrepareModels for EM process n= "
283  << n << G4endl;
284  }
285  if(n > 0) {
286  G4String particleName = aParticle->GetParticleName();
287  G4String processName = p->GetProcessName();
288  //G4cout << particleName << " " << particleName << G4endl;
289  for(size_t i=0; i<n; ++i) {
290  if(processName == processes[i]) {
291  if((particleName == particles[i]) ||
292  (particles[i] == "all") ||
293  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
295  //G4cout << "Region " << reg << G4endl;
296  if(reg) {
297  --index;
298  G4VEmModel* mod = models[i];
299  if(mod) {
300  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
301  p->AddEmModel(index,mod,reg);
302  if(1 < verbose) {
303  G4cout << "### Added em model order= " << index << " for "
304  << particleName << " and " << processName << G4endl;
305  }
306  }
307  }
308  }
309  }
310  }
311  }
312  }
313 }
314 
315 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
316 
317 void
320 {
321  size_t n = particles.size();
322  if(1 < verbose) {
323  G4cout << " G4EmConfigurator::PrepareModels for MSC process n= "
324  << n << G4endl;
325  }
326 
327  if(n > 0) {
328  G4String particleName = aParticle->GetParticleName();
329  G4String processName = p->GetProcessName();
330  for(size_t i=0; i<n; ++i) {
331  if(processName == processes[i]) {
332  if((particleName == particles[i]) ||
333  (particles[i] == "all") ||
334  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
336  if(reg) {
337  --index;
338  G4VEmModel* mod = models[i];
339  if(mod) {
340  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
341  p->AddEmModel(index,mod,reg);
342  //G4cout << "### Added msc model order= " << index << " for "
343  // << particleName << " and " << processName << G4endl;
344  }
345  }
346  }
347  }
348  }
349  }
350  }
351 }
352 
353 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
354 
356 {
357  particles.clear();
358  processes.clear();
359  models.clear();
360  flucModels.clear();
361  regions.clear();
362  lowEnergy.clear();
363  highEnergy.clear();
364 }
365 
366 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
367 
369 {
370  // search for region
371  G4Region* reg = 0;
373  G4String r = regionName;
374  if(r == "" || r == "world" || r == "World") {
375  r = "DefaultRegionForTheWorld";
376  }
377  reg = regStore->GetRegion(r, true);
378  if(!reg) {
379  G4cout << "### G4EmConfigurator WARNING: fails to find a region <"
380  << r << G4endl;
381  } else if(verbose > 1) {
382  G4cout << "### G4EmConfigurator finds out G4Region <" << r << ">"
383  << G4endl;
384  }
385  return reg;
386 }
387 
388 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
389 
391  G4double emin, G4double emax)
392 {
393  // energy limits
394  G4double e1 = std::max(emin,mod->LowEnergyLimit());
395  G4double e2 = std::min(emax,mod->HighEnergyLimit());
396  if(e2 <= e1) {
397  G4cout << "### G4EmConfigurator WARNING: empty energy interval"
398  << " for <" << mod->GetName()
399  << "> Emin(MeV)= " << e1/CLHEP::MeV
400  << "> Emax(MeV)= " << e2/CLHEP::MeV
401  << G4endl;
402  return false;
403  }
404  mod->SetLowEnergyLimit(e1);
405  mod->SetHighEnergyLimit(e2);
406  if(verbose > 1) {
407  G4cout << "### G4EmConfigurator for " << mod->GetName()
408  << " Emin(MeV)= " << e1/MeV << " Emax(MeV)= " << e2/MeV
409  << G4endl;
410  }
411  return true;
412 }
413 
414 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetModelForRegion(G4VEmModel *model, G4VEmFluctuationModel *fm, G4Region *reg, const G4String &particleName, const G4String &processName, G4double emin, G4double emax)
void SetActivationHighEnergyLimit(G4double)
Definition: G4VEmModel.hh:739
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:641
static const double MeV
Definition: G4SIunits.hh:211
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
const G4String & GetName() const
std::vector< G4double > lowEnergy
std::vector< G4VEmModel * > models
G4double HighEnergyLimit() const
Definition: G4VEmModel.hh:634
static const G4double e2
const G4String & GetName() const
void SetFluctModel(G4VEmFluctuationModel *)
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
G4bool UpdateModelEnergyRange(G4VEmModel *mod, G4double emin, G4double emax)
std::vector< G4String > processes
const G4String & GetParticleName() const
static const G4double reg
G4Region * FindRegion(const G4String &)
void SetHighEnergyLimit(G4double)
Definition: G4VEmModel.hh:725
static G4RegionStore * GetInstance()
G4GLOB_DLL std::ostream G4cout
void reset(G4bool ifSkipIon=true)
bool G4bool
Definition: G4Types.hh:79
G4EmConfigurator(G4int verboseLevel=1)
void AddEmModel(G4int, G4VEmModel *, G4VEmFluctuationModel *fluc=0, const G4Region *region=0)
const G4int n
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
static const G4double e1
static const G4double emax
std::vector< G4String > regions
static G4ParticleTable * GetParticleTable()
void AddEmModel(G4int, G4VEmModel *, const G4Region *region=0)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
void PrepareModels(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
void AddEmModel(G4int order, G4VEmModel *, const G4Region *region=0)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
std::vector< G4VEmFluctuationModel * > flucModels
#define G4endl
Definition: G4ios.hh:61
const G4String & GetName() const
Definition: G4VEmModel.hh:795
double G4double
Definition: G4Types.hh:76
std::vector< G4String > particles
void SetLowEnergyLimit(G4double)
Definition: G4VEmModel.hh:732
G4double GetPDGCharge() const
G4int GetProcessListLength() const
G4int GetProcessSubType() const
Definition: G4VProcess.hh:426
G4PTblDicIterator * GetIterator() const
void SetExtraEmModel(const G4String &particleName, const G4String &processName, G4VEmModel *, const G4String &regionName="", G4double emin=0.0, G4double emax=DBL_MAX, G4VEmFluctuationModel *fm=0)
#define theParticleIterator
G4ProcessVector * GetProcessList() const
std::vector< G4double > highEnergy