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