Geant4  10.01.p02
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 86129 2014-11-07 11:16:37Z 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  theParticleIterator->reset();
159  while( (*theParticleIterator)() ) {
160  const G4ParticleDefinition* part = theParticleIterator->value();
161 
162  //G4cout << particleName << " " << part->GetParticleName() << G4endl;
163 
164  if((part->GetParticleName() == particleName) ||
165  (particleName == "all") ||
166  (particleName == "charged" && part->GetPDGCharge() != 0.0)) {
167 
168  // search for process
169  G4ProcessManager* pmanager = part->GetProcessManager();
170  G4ProcessVector* plist = pmanager->GetProcessList();
171  G4int np = pmanager->GetProcessListLength();
172 
173  //G4cout << processName << " in list of " << np << G4endl;
174 
175  G4VProcess* proc = 0;
176  for(G4int i=0; i<np; ++i) {
177  if(processName == (*plist)[i]->GetProcessName()) {
178  proc = (*plist)[i];
179  break;
180  }
181  }
182  if(!proc) {
183  G4cout << "### G4EmConfigurator WARNING: fails to find a process <"
184  << processName << "> for " << particleName << G4endl;
185  return;
186  }
187 
188  if(mod) {
189  if(!UpdateModelEnergyRange(mod, emin, emax)) { return; }
190  }
191  // classify process
192  G4int ii = proc->GetProcessSubType();
193  if(10 == ii && mod) {
194  G4VMultipleScattering* p = static_cast<G4VMultipleScattering*>(proc);
195  p->AddEmModel(index,mod,reg);
196  if(1 < verbose) {
197  G4cout << "### Added msc model order= " << index << " for "
198  << particleName << " and " << processName << G4endl;
199  }
200  return;
201  } else if(2 <= ii && 4 >= ii) {
202  G4VEnergyLossProcess* p = static_cast<G4VEnergyLossProcess*>(proc);
203  if(!mod && fm) {
204  p->SetFluctModel(fm);
205  } else {
206  p->AddEmModel(index,mod,fm,reg);
207  if(1 < verbose) {
208  G4cout << "### Added eloss model order= " << index << " for "
209  << particleName << " and " << processName << G4endl;
210  }
211  }
212  return;
213  } else if(mod) {
214  G4VEmProcess* p = static_cast<G4VEmProcess*>(proc);
215  p->AddEmModel(index,mod,reg);
216  if(1 < verbose) {
217  G4cout << "### Added em model order= " << index << " for "
218  << particleName << " and " << processName << G4endl;
219  }
220  return;
221  } else {
222  return;
223  }
224  }
225  }
226 }
227 
228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
229 
230 void
233 {
234  size_t n = particles.size();
235  if(1 < verbose) {
236  G4cout << " G4EmConfigurator::PrepareModels for EnergyLoss n= "
237  << n << G4endl;
238  }
239  if(n > 0) {
240  G4String particleName = aParticle->GetParticleName();
241  G4String processName = p->GetProcessName();
242  //G4cout << particleName << " " << processName << G4endl;
243  for(size_t i=0; i<n; ++i) {
244  //G4cout << particles[i] << " " << processes[i] << G4endl;
245  if(processName == processes[i]) {
246  if((particleName == particles[i]) ||
247  (particles[i] == "all") ||
248  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
250  //G4cout << "Region " << reg << G4endl;
251  if(reg) {
252  --index;
253  G4VEmModel* mod = models[i];
255  if(mod) {
256  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
257  p->AddEmModel(index,mod,fm,reg);
258  if(1 < verbose) {
259  G4cout << "### Added eloss model order= " << index << " for "
260  << particleName << " and " << processName << G4endl;
261  }
262  }
263  } else if(fm) {
264  p->SetFluctModel(fm);
265  }
266  }
267  }
268  }
269  }
270  }
271 }
272 
273 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
274 
275 void
277  G4VEmProcess* p)
278 {
279  size_t n = particles.size();
280  if(1 < verbose) {
281  G4cout << " G4EmConfigurator::PrepareModels for EM process n= "
282  << n << G4endl;
283  }
284  if(n > 0) {
285  G4String particleName = aParticle->GetParticleName();
286  G4String processName = p->GetProcessName();
287  //G4cout << particleName << " " << particleName << G4endl;
288  for(size_t i=0; i<n; ++i) {
289  if(processName == processes[i]) {
290  if((particleName == particles[i]) ||
291  (particles[i] == "all") ||
292  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
294  //G4cout << "Region " << reg << G4endl;
295  if(reg) {
296  --index;
297  G4VEmModel* mod = models[i];
298  if(mod) {
299  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
300  p->AddEmModel(index,mod,reg);
301  if(1 < verbose) {
302  G4cout << "### Added em model order= " << index << " for "
303  << particleName << " and " << processName << G4endl;
304  }
305  }
306  }
307  }
308  }
309  }
310  }
311  }
312 }
313 
314 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
315 
316 void
319 {
320  size_t n = particles.size();
321  if(1 < verbose) {
322  G4cout << " G4EmConfigurator::PrepareModels for MSC process n= "
323  << n << G4endl;
324  }
325 
326  if(n > 0) {
327  G4String particleName = aParticle->GetParticleName();
328  G4String processName = p->GetProcessName();
329  for(size_t i=0; i<n; ++i) {
330  if(processName == processes[i]) {
331  if((particleName == particles[i]) ||
332  (particles[i] == "all") ||
333  (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
335  if(reg) {
336  --index;
337  G4VEmModel* mod = models[i];
338  if(mod) {
339  if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
340  p->AddEmModel(index,mod,reg);
341  G4cout << "### Added msc model order= " << index << " for "
342  << particleName << " and " << processName << G4endl;
343  }
344  }
345  }
346  }
347  }
348  }
349  }
350 }
351 
352 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
353 
355 {
356  particles.clear();
357  processes.clear();
358  models.clear();
359  flucModels.clear();
360  regions.clear();
361  lowEnergy.clear();
362  highEnergy.clear();
363 }
364 
365 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
366 
368 {
369  // search for region
370  G4Region* reg = 0;
372  G4String r = regionName;
373  if(r == "" || r == "world" || r == "World") {
374  r = "DefaultRegionForTheWorld";
375  }
376  reg = regStore->GetRegion(r, true);
377  if(!reg) {
378  G4cout << "### G4EmConfigurator WARNING: fails to find a region <"
379  << r << G4endl;
380  } else if(verbose > 1) {
381  G4cout << "### G4EmConfigurator finds out G4Region <" << r << ">"
382  << G4endl;
383  }
384  return reg;
385 }
386 
387 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
388 
390  G4double emin, G4double emax)
391 {
392  // energy limits
393  G4double e1 = std::max(emin,mod->LowEnergyLimit());
394  G4double e2 = std::min(emax,mod->HighEnergyLimit());
395  if(e2 <= e1) {
396  G4cout << "### G4EmConfigurator WARNING: empty energy interval"
397  << " for <" << mod->GetName()
398  << "> Emin(MeV)= " << e1/CLHEP::MeV
399  << "> Emax(MeV)= " << e2/CLHEP::MeV
400  << G4endl;
401  return false;
402  }
403  mod->SetLowEnergyLimit(e1);
404  mod->SetHighEnergyLimit(e2);
405  if(verbose > 1) {
406  G4cout << "### G4EmConfigurator for " << mod->GetName()
407  << " Emin(MeV)= " << e1/MeV << " Emax(MeV)= " << e2/MeV
408  << G4endl;
409  }
410  return true;
411 }
412 
413 //....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:721
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:623
static const double MeV
Definition: G4SIunits.hh:193
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:616
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:707
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
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:777
double G4double
Definition: G4Types.hh:76
std::vector< G4String > particles
void SetLowEnergyLimit(G4double)
Definition: G4VEmModel.hh:714
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