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

Last change on this file since 1315 was 1315, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

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.8 2010/06/04 15:33:56 vnivanch Exp $
27// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
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
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 return;
200 } else if(2 <= ii && 4 >= ii) {
201 G4VEnergyLossProcess* p = static_cast<G4VEnergyLossProcess*>(proc);
202 if(!mod && fm) {
203 p->SetFluctModel(fm);
204 } else {
205 p->AddEmModel(index,mod,fm,reg);
206 if(1 < verbose) {
207 G4cout << "### Added eloss model order= " << index << " for "
208 << particleName << " and " << processName << G4endl;
209 }
210 }
211 return;
212 } else if(mod) {
213 G4VEmProcess* p = static_cast<G4VEmProcess*>(proc);
214 p->AddEmModel(index,mod,reg);
215 if(1 < verbose) {
216 G4cout << "### Added em model order= " << index << " for "
217 << particleName << " and " << processName << G4endl;
218 }
219 return;
220 } else {
221 return;
222 }
223 }
224 }
225}
226
227//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
228
229void
230G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle,
231 G4VEnergyLossProcess* p)
232{
233 size_t n = particles.size();
234 if(1 < verbose) {
235 G4cout << " G4EmConfigurator::PrepareModels for EnergyLoss n= "
236 << n << G4endl;
237 }
238 if(n > 0) {
239 G4String particleName = aParticle->GetParticleName();
240 G4String processName = p->GetProcessName();
241 //G4cout << particleName << " " << processName << G4endl;
242 for(size_t i=0; i<n; ++i) {
243 //G4cout << particles[i] << " " << processes[i] << G4endl;
244 if(processName == processes[i]) {
245 if((particleName == particles[i]) ||
246 (particles[i] == "all") ||
247 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
248 G4Region* reg = FindRegion(regions[i]);
249 //G4cout << "Region " << reg << G4endl;
250 if(reg) {
251 --index;
252 G4VEmModel* mod = models[i];
253 G4VEmFluctuationModel* fm = flucModels[i];
254 if(mod) {
255 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
256 p->AddEmModel(index,mod,fm,reg);
257 if(1 < verbose) {
258 G4cout << "### Added eloss model order= " << index << " for "
259 << particleName << " and " << processName << G4endl;
260 }
261 }
262 } else if(fm) {
263 p->SetFluctModel(fm);
264 }
265 }
266 }
267 }
268 }
269 }
270}
271
272//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
273
274void
275G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle,
276 G4VEmProcess* p)
277{
278 size_t n = particles.size();
279 if(1 < verbose) {
280 G4cout << " G4EmConfigurator::PrepareModels for EM process n= "
281 << n << G4endl;
282 }
283 if(n > 0) {
284 G4String particleName = aParticle->GetParticleName();
285 G4String processName = p->GetProcessName();
286 //G4cout << particleName << " " << particleName << G4endl;
287 for(size_t i=0; i<n; ++i) {
288 if(processName == processes[i]) {
289 if((particleName == particles[i]) ||
290 (particles[i] == "all") ||
291 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
292 G4Region* reg = FindRegion(regions[i]);
293 //G4cout << "Region " << reg << G4endl;
294 if(reg) {
295 --index;
296 G4VEmModel* mod = models[i];
297 if(mod) {
298 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
299 p->AddEmModel(index,mod,reg);
300 if(1 < verbose) {
301 G4cout << "### Added em model order= " << index << " for "
302 << particleName << " and " << processName << G4endl;
303 }
304 }
305 }
306 }
307 }
308 }
309 }
310 }
311}
312
313//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
314
315void
316G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle,
317 G4VMultipleScattering* p)
318{
319 size_t n = particles.size();
320 if(1 < verbose) {
321 G4cout << " G4EmConfigurator::PrepareModels for MSC process n= "
322 << n << G4endl;
323 }
324
325 if(n > 0) {
326 G4String particleName = aParticle->GetParticleName();
327 G4String processName = p->GetProcessName();
328 for(size_t i=0; i<n; ++i) {
329 if(processName == processes[i]) {
330 if((particleName == particles[i]) ||
331 (particles[i] == "all") ||
332 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) {
333 G4Region* reg = FindRegion(regions[i]);
334 if(reg) {
335 --index;
336 G4VEmModel* mod = models[i];
337 if(mod) {
338 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) {
339 p->AddEmModel(index,mod,reg);
340 G4cout << "### Added msc model order= " << index << " for "
341 << particleName << " and " << processName << G4endl;
342 }
343 }
344 }
345 }
346 }
347 }
348 }
349}
350
351//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
352
353void G4EmConfigurator::Clear()
354{
355 particles.clear();
356 processes.clear();
357 models.clear();
358 flucModels.clear();
359 regions.clear();
360 lowEnergy.clear();
361 highEnergy.clear();
362}
363
364//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
365
366G4Region* G4EmConfigurator::FindRegion(const G4String& regionName)
367{
368 // search for region
369 G4Region* reg = 0;
370 G4RegionStore* regStore = G4RegionStore::GetInstance();
371 G4String r = regionName;
372 if(r == "" || r == "world" || r == "World") {
373 r = "DefaultRegionForTheWorld";
374 }
375 reg = regStore->GetRegion(r, true);
376 if(!reg) {
377 G4cout << "### G4EmConfigurator WARNING: fails to find a region <"
378 << r << G4endl;
379 } else if(verbose > 1) {
380 G4cout << "### G4EmConfigurator finds out G4Region <" << r << ">"
381 << G4endl;
382 }
383 return reg;
384}
385
386//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
387
388G4bool G4EmConfigurator::UpdateModelEnergyRange(G4VEmModel* mod,
389 G4double emin, G4double emax)
390{
391 // energy limits
392 G4double e1 = std::max(emin,mod->LowEnergyLimit());
393 G4double e2 = std::min(emax,mod->HighEnergyLimit());
394 if(e2 <= e1) {
395 G4cout << "### G4EmConfigurator WARNING: empty energy interval"
396 << " for <" << mod->GetName()
397 << "> Emin(MeV)= " << e1/CLHEP::MeV
398 << "> Emax(MeV)= " << e2/CLHEP::MeV
399 << G4endl;
400 return false;
401 }
402 mod->SetLowEnergyLimit(e1);
403 mod->SetHighEnergyLimit(e2);
404 if(verbose > 1) {
405 G4cout << "### G4EmConfigurator for " << mod->GetName()
406 << " Emin(MeV)= " << e1/MeV << " Emax(MeV)= " << e2/MeV
407 << G4endl;
408 }
409 return true;
410}
411
412//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.