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

Last change on this file since 1036 was 1007, checked in by garnier, 17 years ago

update to geant4.9.2

File size: 8.5 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.3 2008/11/21 12:30:29 vnivanch Exp $
27// GEANT4 tag $Name: geant4-09-02 $
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
63enum PType {unknown=0, eloss, discrete, msc};
64
65//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66
67G4EmConfigurator::G4EmConfigurator()
68{
69 index = 1;
70}
71
72//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73
74G4EmConfigurator::~G4EmConfigurator()
75{}
76
77//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78
79void G4EmConfigurator::AddExtraEmModel(const G4String& particleName,
80 G4VEmModel* em,
81 G4VEmFluctuationModel* fm)
82{
83 particleList.push_back(particleName);
84 modelList.push_back(em);
85 flucModelList.push_back(fm);
86}
87
88//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89
90void G4EmConfigurator::AddModelForRegion(const G4String& particleName,
91 const G4String& processName,
92 const G4String& modelName,
93 const G4String& regionName,
94 G4double emin, G4double emax,
95 const G4String& flucModelName)
96{
97 particles.push_back(particleName);
98 processes.push_back(processName);
99 models.push_back(modelName);
100 regions.push_back(regionName);
101 flucModels.push_back(flucModelName);
102 lowEnergy.push_back(emin);
103 highEnergy.push_back(emax);
104}
105
106//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
107
108void G4EmConfigurator::SetExtraEmModel(const G4String& particleName,
109 const G4String& processName,
110 G4VEmModel* mod,
111 const G4String& regionName,
112 G4double emin,
113 G4double emax,
114 G4VEmFluctuationModel* fm)
115{
116 AddExtraEmModel(particleName, mod, fm);
117 G4String fname = "";
118 if(fm) fname = fm->GetName();
119 AddModelForRegion(particleName, processName, mod->GetName(), regionName,
120 emin, emax, fname);
121}
122
123//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
124
125void G4EmConfigurator::AddModels()
126{
127 size_t n = particles.size();
128 //G4cout << " G4EmConfigurator::AddModels n= " << n << G4endl;
129 if(n > 0) {
130 for(size_t i=0; i<n; i++) {
131 SetModelForRegion(particles[i],processes[i],models[i],regions[i],
132 flucModels[i],lowEnergy[i],highEnergy[i]);
133 }
134 }
135 particles.clear();
136 processes.clear();
137 models.clear();
138 flucModels.clear();
139 regions.clear();
140 lowEnergy.clear();
141 highEnergy.clear();
142}
143
144//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145
146void G4EmConfigurator::SetModelForRegion(const G4String& particleName,
147 const G4String& processName,
148 const G4String& modelName,
149 const G4String& regionName,
150 const G4String& flucModelName,
151 G4double emin, G4double emax)
152{
153 //G4cout << " G4EmConfigurator::SetModelForRegion" << G4endl;
154
155 // new set
156 index--;
157
158 G4ParticleTable::G4PTblDicIterator* theParticleIterator =
159 G4ParticleTable::GetParticleTable()->GetIterator();
160
161 theParticleIterator->reset();
162 while( (*theParticleIterator)() ) {
163 const G4ParticleDefinition* part = theParticleIterator->value();
164
165 //G4cout << particleName << " " << part->GetParticleName() << G4endl;
166
167 if(particleName == part->GetParticleName() ||
168 (particleName == "charged" && part->GetPDGCharge() != 0.0) ) {
169
170
171 // search for process
172 G4ProcessManager* pmanager = part->GetProcessManager();
173 G4ProcessVector* plist = pmanager->GetProcessList();
174 G4int np = pmanager->GetProcessListLength();
175
176 //G4cout << processName << " in list of " << np << G4endl;
177
178 G4VProcess* proc = 0;
179 for(G4int i=0; i<np; i++) {
180 if(processName == (*plist)[i]->GetProcessName()) {
181 proc = (*plist)[i];
182 break;
183 }
184 }
185 if(!proc) {
186 G4cout << "### G4EmConfigurator WARNING: fails to find a process <"
187 << processName << "> for " << particleName << G4endl;
188
189 } else {
190
191 // classify process
192 PType ptype = discrete;
193 G4int ii = proc->GetProcessSubType();
194 if(10 == ii) ptype = msc;
195 else if(2 <= ii && 4 >= ii) ptype = eloss;
196
197 // find out model
198 G4VEmModel* mod = 0;
199 G4VEmFluctuationModel* fluc = 0;
200
201 G4int nm = modelList.size();
202 //G4cout << "Search model " << modelName << " in " << nm << G4endl;
203
204 for(G4int i=0; i<nm; i++) {
205 if(modelName == modelList[i]->GetName() &&
206 (particleList[i] == "" || particleList[i] == particleName) ) {
207 mod = modelList[i];
208 fluc = flucModelList[i];
209 break;
210 }
211 }
212
213 if("dummy" == modelName) mod = new G4DummyModel();
214
215 if(!mod) {
216 G4cout << "### G4EmConfigurator WARNING: fails to find a model <"
217 << modelName << "> for process <"
218 << processName << "> and " << particleName
219 << G4endl;
220 if(flucModelName != "")
221 G4cout << " fluctuation model <"
222 << flucModelName << G4endl;
223 } else {
224
225 // search for region
226 G4Region* reg = 0;
227 G4RegionStore* regStore = G4RegionStore::GetInstance();
228 G4String r = regionName;
229 if(r == "" || r == "world" || r == "World") r = "DefaultRegionForTheWorld";
230 reg = regStore->GetRegion(r, true);
231 if(!reg) {
232 G4cout << "### G4EmConfigurator WARNING: fails to find a region <"
233 << r << "> for model <" << modelName << "> of the process "
234 << processName << " and " << particleName << G4endl;
235 return;
236 }
237
238 // energy limits
239 G4double e1 = std::max(emin,mod->LowEnergyLimit());
240 G4double e2 = std::min(emax,mod->HighEnergyLimit());
241 if(e2 < e1) e2 = e1;
242 mod->SetLowEnergyLimit(e1);
243 mod->SetHighEnergyLimit(e2);
244
245 //G4cout << "e1= " << e1 << " e2= " << e2 << G4endl;
246
247 // added model
248 if(ptype == eloss) {
249 G4VEnergyLossProcess* p = reinterpret_cast<G4VEnergyLossProcess*>(proc);
250 p->AddEmModel(index,mod,fluc,reg);
251 //G4cout << "### Added eloss model order= " << index << " for "
252 // << particleName << " and " << processName << " " << mod << G4endl;
253 } else if(ptype == discrete) {
254 G4VEmProcess* p = reinterpret_cast<G4VEmProcess*>(proc);
255 p->AddEmModel(index,mod,reg);
256 } else if(ptype == msc) {
257 G4VMultipleScattering* p = reinterpret_cast<G4VMultipleScattering*>(proc);
258 p->AddEmModel(index,mod,reg);
259 }
260 }
261 }
262 }
263 }
264}
265
266//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
267
268
269
270
271
272
273
274
Note: See TracBrowser for help on using the repository browser.