source: trunk/source/processes/electromagnetic/utils/src/G4EmConfigurator.cc @ 1343

Last change on this file since 1343 was 1340, checked in by garnier, 14 years ago

update ti head

File size: 12.4 KB
Line 
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,v 1.9 2010/07/29 11:13:28 vnivanch Exp $
27// GEANT4 tag $Name: emutils-V09-03-23 $
28//
29// -------------------------------------------------------------------
30//
31// GEANT4 Class
32//
33// File name:     G4EmConfigurator
34//
35// Author:        Vladimir Ivanchenko
36//
37// Creation date: 14.07.2008
38//
39// Modifications:
40//
41// Class Description:
42//
43// This class provides configuration EM models for
44// particles/processes/regions
45//
46
47// -------------------------------------------------------------------
48//
49
50#include "G4EmConfigurator.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
65G4EmConfigurator::G4EmConfigurator(G4int val):verbose(val)
66{
67  index = -10;
68}
69
70//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
72G4EmConfigurator::~G4EmConfigurator()
73{}
74
75//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76
77void G4EmConfigurator::SetExtraEmModel(const G4String& particleName,
78                                       const G4String& processName,
79                                       G4VEmModel* mod,
80                                       const G4String& regionName,
81                                       G4double emin,
82                                       G4double emax,
83                                       G4VEmFluctuationModel* fm)
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 || fm) {
95    models.push_back(mod);
96    flucModels.push_back(fm);
97  } else {
98    models.push_back(new G4DummyModel());
99    flucModels.push_back(0);
100  }
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
111void G4EmConfigurator::AddModels()
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
135void G4EmConfigurator::SetModelForRegion(G4VEmModel* mod,
136                                         G4VEmFluctuationModel* fm,
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  }
153  G4ParticleTable::G4PTblDicIterator* theParticleIterator = 
154    G4ParticleTable::GetParticleTable()->GetIterator(); 
155
156  theParticleIterator->reset();
157  while( (*theParticleIterator)() ) {
158    const G4ParticleDefinition* part = theParticleIterator->value();
159
160    //G4cout << particleName << " " << part->GetParticleName() << G4endl;
161
162    if((part->GetParticleName() == particleName) ||
163       (particleName == "all") ||
164       (particleName == "charged" && part->GetPDGCharge() != 0.0)) {
165
166      // search for process
167      G4ProcessManager* pmanager = part->GetProcessManager();
168      G4ProcessVector* plist = pmanager->GetProcessList();
169      G4int np = pmanager->GetProcessListLength();
170 
171      //G4cout << processName << " in list of " << np << G4endl;
172
173      G4VProcess* proc = 0;
174      for(G4int i=0; i<np; ++i) {
175        if(processName == (*plist)[i]->GetProcessName()) {
176          proc = (*plist)[i];
177          break;
178        }
179      }
180      if(!proc) {
181        G4cout << "### G4EmConfigurator WARNING: fails to find a process <"
182               << processName << "> for " << particleName << G4endl;
183        return; 
184      } 
185
186      if(mod) {
187        if(!UpdateModelEnergyRange(mod, emin, emax)) { return; }
188      }
189      // classify process
190      G4int ii = proc->GetProcessSubType();
191      if(10 == ii && mod) {
192        G4VMultipleScattering* p = static_cast<G4VMultipleScattering*>(proc);
193        p->AddEmModel(index,mod,reg);
194        if(1 < verbose) {
195          G4cout << "### Added msc model order= " << index << " for " 
196                 << particleName << " and " << processName << G4endl;
197        }
198        return;
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        return;
211      } else if(mod) {
212        G4VEmProcess* p = static_cast<G4VEmProcess*>(proc);
213        p->AddEmModel(index,mod,reg);
214        if(1 < verbose) {
215          G4cout << "### Added em model order= " << index << " for " 
216                 << particleName << " and " << processName << G4endl;
217        }
218        return;
219      } else {
220        return;
221      }
222    }
223  }
224}
225
226//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
227
228void 
229G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle,
230                                G4VEnergyLossProcess* p)
231{
232  size_t n = particles.size();
233  if(1 < verbose) {
234    G4cout << " G4EmConfigurator::PrepareModels for EnergyLoss n= " 
235           << n << G4endl;
236  }
237  if(n > 0) {
238    G4String particleName = aParticle->GetParticleName(); 
239    G4String processName  = p->GetProcessName(); 
240    //G4cout <<  particleName << "  " <<  processName << G4endl;
241    for(size_t i=0; i<n; ++i) {
242      //G4cout <<  particles[i] << "  " <<  processes[i] << G4endl;
243      if(processName == processes[i]) {
244        if((particleName == particles[i]) ||
245           (particles[i] == "all") ||
246           (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
247          G4Region* reg = FindRegion(regions[i]);
248          //G4cout << "Region " << reg << G4endl;
249          if(reg) {
250            --index;
251            G4VEmModel* mod = models[i];
252            G4VEmFluctuationModel* fm = flucModels[i];
253            if(mod) {
254              if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
255                p->AddEmModel(index,mod,fm,reg);
256                if(1 < verbose) {
257                  G4cout << "### Added eloss model order= " << index << " for " 
258                         << particleName << " and " << processName << G4endl;
259                }
260              }
261            } else if(fm) {
262              p->SetFluctModel(fm);
263            }
264          }
265        }
266      }
267    }
268  }
269}
270
271//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
272
273void 
274G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle,
275                                G4VEmProcess* p)
276{
277  size_t n = particles.size();
278  if(1 < verbose) {
279    G4cout << " G4EmConfigurator::PrepareModels for EM process n= " 
280           << n << G4endl;
281  }
282  if(n > 0) {
283    G4String particleName = aParticle->GetParticleName(); 
284    G4String processName  = p->GetProcessName(); 
285    //G4cout <<  particleName << "  " <<  particleName << G4endl;
286    for(size_t i=0; i<n; ++i) {
287      if(processName == processes[i]) {
288        if((particleName == particles[i]) ||
289           (particles[i] == "all") ||
290           (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
291          G4Region* reg = FindRegion(regions[i]);
292          //G4cout << "Region " << reg << G4endl;
293          if(reg) {
294            --index;
295            G4VEmModel* mod = models[i];
296            if(mod) {
297              if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) { 
298                p->AddEmModel(index,mod,reg);
299                if(1 < verbose) {
300                  G4cout << "### Added em model order= " << index << " for " 
301                         << particleName << " and " << processName << G4endl;
302                }
303              }
304            }
305          }
306        }
307      }
308    }
309  }
310}
311
312//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
313
314void 
315G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle,
316                                G4VMultipleScattering* p)
317{
318  size_t n = particles.size();
319  if(1 < verbose) {
320    G4cout << " G4EmConfigurator::PrepareModels for MSC process n= " 
321           << n << G4endl;
322  }
323
324  if(n > 0) {
325    G4String particleName = aParticle->GetParticleName(); 
326    G4String processName  = p->GetProcessName(); 
327    for(size_t i=0; i<n; ++i) {
328      if(processName == processes[i]) {
329        if((particleName == particles[i]) ||
330           (particles[i] == "all") ||
331           (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
332          G4Region* reg = FindRegion(regions[i]);
333          if(reg) {
334            --index;
335            G4VEmModel* mod = models[i];
336            if(mod) {
337              if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) { 
338                p->AddEmModel(index,mod,reg);
339                G4cout << "### Added msc model order= " << index << " for " 
340                       << particleName << " and " << processName << G4endl;
341              }
342            }
343          }
344        }
345      }
346    }
347  }
348}
349
350//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
351
352void G4EmConfigurator::Clear()
353{
354  particles.clear();
355  processes.clear();
356  models.clear();
357  flucModels.clear();
358  regions.clear();
359  lowEnergy.clear();
360  highEnergy.clear();
361}
362
363//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
364
365G4Region* G4EmConfigurator::FindRegion(const G4String& regionName)
366{
367  // search for region
368  G4Region* reg = 0;
369  G4RegionStore* regStore = G4RegionStore::GetInstance();
370  G4String r = regionName;
371  if(r == "" || r == "world" || r == "World") { 
372    r = "DefaultRegionForTheWorld";
373  }
374  reg = regStore->GetRegion(r, true); 
375  if(!reg) {
376    G4cout << "### G4EmConfigurator WARNING: fails to find a region <"
377           << r << G4endl;
378  } else if(verbose > 1) {
379    G4cout << "### G4EmConfigurator finds out G4Region <" << r << ">" 
380           << G4endl;
381  } 
382  return reg; 
383}
384
385//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
386
387G4bool G4EmConfigurator::UpdateModelEnergyRange(G4VEmModel* mod, 
388                                                G4double emin, G4double emax)
389{
390  // energy limits
391  G4double e1 = std::max(emin,mod->LowEnergyLimit());
392  G4double e2 = std::min(emax,mod->HighEnergyLimit());
393  if(e2 <= e1) {
394    G4cout << "### G4EmConfigurator WARNING: empty energy interval"
395           << " for <" << mod->GetName() 
396           << ">  Emin(MeV)= " << e1/CLHEP::MeV
397           << ">  Emax(MeV)= " << e2/CLHEP::MeV
398           << G4endl;
399    return false;       
400  }
401  mod->SetLowEnergyLimit(e1);
402  mod->SetHighEnergyLimit(e2);
403  if(verbose > 1) {
404    G4cout << "### G4EmConfigurator for " << mod->GetName() 
405           << " Emin(MeV)= " << e1/MeV << " Emax(MeV)= " << e2/MeV
406           << G4endl;
407  } 
408  return true;
409}
410
411//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.