Geant4 VMC Version 6.7
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TG4G3PhysicsManager.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
15#include "TG4G3PhysicsManager.h"
16#include "TG4G3ControlVector.h"
17#include "TG4G3CutVector.h"
18#include "TG4G3Units.h"
19
20#include <G4ParticleDefinition.hh>
21#include <G4ProcessTable.hh>
22#include <G4UImessenger.hh>
23#include <G4VProcess.hh>
24
26
27//_____________________________________________________________________________
29 : fCutVector(0),
31 fIsCutVector(0),
34 fLock(false)
35{
37
38 if (fgInstance) {
39 TG4Globals::Exception("TG4G3PhysicsManager", "TG4G3PhysicsManager",
40 "Cannot create two instances of singleton.");
41 }
42
43 fgInstance = this;
44
45 // create vector of kinetic energy cut values
47
48 // create vector of control process control values
50
51 // initialize fIsCutVector
53 G4int i;
54 for (i = 0; i < kNofParticlesWSP; i++) fIsCutVector->push_back(false);
55
56 // initialize fIsControlVector
58 for (i = 0; i < kNofParticlesWSP; i++) fIsControlVector->push_back(false);
59}
60
61//_____________________________________________________________________________
63{
65
66 delete fCutVector;
67 delete fControlVector;
68 delete fIsCutVector;
69 delete fIsControlVector;
70
71 fgInstance = 0;
72}
73
74//
75// private methods
76//
77
78//_____________________________________________________________________________
79void TG4G3PhysicsManager::SetCut(TG4G3Cut cut, G4double cutValue)
80{
82
83 // Do nothing if cutValue is not valid
84 if (!TG4G3CutVector::CheckCutValue(cut, cutValue)) return;
85
86 fCutVector->SetCut(cut, cutValue);
88}
89
90//_____________________________________________________________________________
92 TG4G3Control control, TG4G3ControlValue controlValue)
93{
95
96 if (control == kDRAY || control == kG3LOSS) {
99 }
100
101 fControlVector->SetControl(control, controlValue, *fCutVector);
102}
103
104//_____________________________________________________________________________
106{
108
109 switch (cut) {
110 case kCUTGAM:
111 (*fIsCutVector)[kGamma] = true;
112 break;
113 case kBCUTE:
114 (*fIsCutVector)[kGamma] = true;
115 break;
116 case kBCUTM:
117 (*fIsCutVector)[kGamma] = true;
118 break;
119 case kCUTELE:
120 (*fIsCutVector)[kElectron] = true;
121 break;
122 case kDCUTE:
123 (*fIsCutVector)[kElectron] = true;
124 break;
125 case kDCUTM:
126 (*fIsCutVector)[kElectron] = true;
127 break;
128 case kPPCUTM:
129 // (*fIsCutVector)[kElectron] = true;
130 // (*fIsCutVector)[kEplus] = true;
131 // PPCUTM is not applied with special cuts process
132 break;
133 case kCUTNEU:
134 (*fIsCutVector)[kNeutralHadron] = true;
135 break;
136 case kCUTHAD:
137 (*fIsCutVector)[kChargedHadron] = true;
138 break;
139 case kCUTMUO:
140 (*fIsCutVector)[kMuon] = true;
141 break;
142 default:
143 break;
144 }
145}
146
147//_____________________________________________________________________________
149{
152
153 switch (control) {
154 case kPAIR:
155 // gamma
156 (*fIsControlVector)[kGamma] = true;
157 break;
158 case kCOMP:
159 // gamma
160 (*fIsControlVector)[kGamma] = true;
161 break;
162 case kPHOT:
163 // gamma
164 (*fIsControlVector)[kGamma] = true;
165 break;
166 case kPFIS:
167 // gamma
168 (*fIsControlVector)[kGamma] = true;
169 break;
170 case kDRAY:
171 // all charged particles
172 (*fIsControlVector)[kElectron] = true;
173 (*fIsControlVector)[kEplus] = true;
174 (*fIsControlVector)[kChargedHadron] = true;
175 (*fIsControlVector)[kMuon] = true;
176 break;
177 case kANNI:
178 // e+ only
179 (*fIsControlVector)[kEplus] = true;
180 break;
181 case kBREM:
182 // e-/e+, muons
183 (*fIsControlVector)[kElectron] = true;
184 (*fIsControlVector)[kEplus] = true;
185 (*fIsControlVector)[kMuon] = true;
186 break;
187 case kHADR:
188 // hadrons
189 (*fIsControlVector)[kNeutralHadron] = true;
190 (*fIsControlVector)[kChargedHadron] = true;
191 break;
192 case kMUNU:
193 // muons
194 (*fIsControlVector)[kMuon] = true;
195 break;
196 case kDCAY:
197 // any
198 (*fIsControlVector)[kAny] = true;
199 break;
200 case kG3LOSS:
201 // all charged particles
202 (*fIsControlVector)[kElectron] = true;
203 (*fIsControlVector)[kEplus] = true;
204 (*fIsControlVector)[kChargedHadron] = true;
205 (*fIsControlVector)[kMuon] = true;
206 break;
207 case kMULS:
208 // all charged particles
209 (*fIsControlVector)[kElectron] = true;
210 (*fIsControlVector)[kEplus] = true;
211 (*fIsControlVector)[kChargedHadron] = true;
212 (*fIsControlVector)[kMuon] = true;
213 break;
214 default:
215 break;
216 }
217}
218
219//
220// public methods
221//
222
223//_____________________________________________________________________________
225{
228
229 if (fLock) {
230 TG4Globals::Exception("TG4PhysicsManager", "CheckLock",
231 "It is too late to change physics setup." + TG4Globals::Endl() +
232 "PhysicsManager has been already locked.");
233 }
234}
235
236//_____________________________________________________________________________
238 G4String name, G4double value, TG4G3Cut& cut)
239{
245
246 // convert cut name -> TG4G3Cut
247 cut = TG4G3CutVector::GetCut(name);
248
249 // add units
250 if (cut == kTOFMAX)
251 value *= TG4G3Units::Time();
252 else
253 value *= TG4G3Units::Energy();
254
255 // check cut value validity
256 if (!TG4G3CutVector::CheckCutValue(cut, value)) return false;
257
258 // set switch vector element only if the value
259 // is different from the value in cutVector and is valid
260 if (cut != kNoG3Cuts) {
261 // G4cout << "Comparing: "
262 // << value << " "
263 // << (*fCutVector)[cut] << " "
264 // << std::abs(value - (*fCutVector)[cut]) << " > "
265 // << TG4G3CutVector::Tolerance() << G4endl;
266
267 if (std::abs(value - (*fCutVector)[cut]) > TG4G3CutVector::Tolerance()) {
269 return true;
270 }
271 else
272 return false;
273 }
274 return false;
275}
276
277//_____________________________________________________________________________
279 G4double value, TG4G3Control& control, TG4G3ControlValue& controlValue)
280{
286
287 // convert control name -> TG4G3Control
288 control = TG4G3ControlVector::GetControl(name);
289
290 // convert double value -> TG4G3ControlValue
291 controlValue = TG4G3ControlVector::GetControlValue(value, control);
292
293 // set switch vector element only if the value
294 // is different from the value in controlVector
295 if (control != kNoG3Controls) {
296 if (controlValue != (*fControlVector)[control]) {
297 SwitchIsControlVector(control);
298 return true;
299 }
300 else
301 return false;
302 }
303 return false;
304}
305
306//_____________________________________________________________________________
308{
310
311 CheckLock();
312 fCutVector->SetG3Defaults();
313
314 for (G4int i = 0; i < kNofParticlesWSP; i++) (*fIsCutVector)[i] = true;
315}
316
317//_____________________________________________________________________________
319{
321
322 CheckLock();
323 fControlVector->SetG3Defaults();
324
325 for (G4int i = 0; i < kNofParticlesWSP; i++) (*fIsControlVector)[i] = true;
326}
327
328//_____________________________________________________________________________
330{
332
333 for (G4int i = 0; i < kNofParticlesWSP; i++) {
334 if ((*fIsCutVector)[i]) return true;
335 }
336
337 return false;
338}
339
340//_____________________________________________________________________________
342{
346
347 for (G4int i = 0; i < kNofParticlesWSP; i++) {
348 if ((*fIsControlVector)[i]) return true;
349 }
350
351 return false;
352}
353
354//_____________________________________________________________________________
356{
358
359 for (G4int i = 0; i < kNoG3Controls; i++) {
360 if ((*fControlVector)[i] != kUnsetControlValue) return true;
361 }
362
363 return false;
364}
365
366//_____________________________________________________________________________
368 G4ParticleDefinition* particle) const
369{
372
373 G4String name = particle->GetParticleName();
374 G4String pType = particle->GetParticleType();
375
376 if (name == "gamma") {
377 return kGamma;
378 }
379 else if (name == "e-") {
380 return kElectron;
381 }
382 else if (name == "e+") {
383 return kEplus;
384 }
385 else if ((pType == "baryon" || pType == "meson" || pType == "nucleus" ||
386 pType == "Ion")) {
387 if (particle->GetPDGCharge() == 0) {
388 return kNeutralHadron;
389 }
390 else
391 return kChargedHadron;
392 }
393 else if (name == "mu-" || name == "mu+") {
394 return kMuon;
395 }
396 else {
397 return kNofParticlesWSP;
398 }
399}
400
401//_____________________________________________________________________________
402G4String TG4G3PhysicsManager::GetG3ParticleWSPName(G4int particleWSP) const
403{
406
407 switch (particleWSP) {
408 case kGamma:
409 return "Gamma";
410 break;
411 case kElectron:
412 return "Electron";
413 break;
414 case kEplus:
415 return "Eplus";
416 break;
417 case kNeutralHadron:
418 return "NeutralHadron";
419 break;
420 case kChargedHadron:
421 return "ChargedHadron";
422 break;
423 case kMuon:
424 return "Muon";
425 break;
426 case kAny:
427 return "Any";
428 break;
429 case kNofParticlesWSP:
430 return "NoSP";
431 break;
432 default:
434 "TG4G3PhysicsManager", "GetG3ParticleWSPName", "Wrong particleWSP.");
435 return "";
436 }
437}
Definition of the TG4G3ControlVector class.
Definition of the TG4G3CutVector class.
Definition of the TG4G3PhysicsManager class.
Definition of the TG4G3Units class.
Vector of control process values with convenient set/get methods.
static TG4G3Control GetControl(const G4String &controlName)
static TG4G3ControlValue GetControlValue(G4int value, TG4G3Control control)
Vector of kinetic energy cut values with convenient set/get methods.
static TG4G3Cut GetCut(const G4String &cutName)
static G4double Tolerance()
static G4bool CheckCutValue(TG4G3Cut cut, G4double value)
Provides a Geant3 way control to Geant4 physics.
G4bool IsGlobalSpecialControls() const
void SwitchIsCutVector(TG4G3Cut cut)
G4bool CheckControlWithTheVector(G4String name, G4double value, TG4G3Control &control, TG4G3ControlValue &controlValue)
TG4G3ControlVector * fControlVector
TG4G3ControlVector.
void SwitchIsControlVector(TG4G3Control control)
G4String GetG3ParticleWSPName(G4int particleWSP) const
void SetCut(TG4G3Cut cut, G4double cutValue)
TG4boolVector * fIsControlVector
vector of booleans which controls are set
TG4boolVector * fIsCutVector
vector of booleans which cuts are set
G4bool fLock
if true: cut/control vectors cannot be modified
TG4G3ParticleWSP GetG3ParticleWSP(G4ParticleDefinition *particle) const
void SetProcess(TG4G3Control control, TG4G3ControlValue controlValue)
static TG4G3PhysicsManager * fgInstance
this instance
TG4G3Defaults fG3Defaults
G3 default cuts/controls.
TG4G3CutVector * fCutVector
TG4G3CutVector.
G4bool CheckCutWithTheVector(G4String name, G4double value, TG4G3Cut &cut)
static G4double Energy()
Definition TG4G3Units.h:105
static G4double Time()
Definition TG4G3Units.h:93
static void Exception(const TString &className, const TString &methodName, const TString &text)
static TString Endl()
Definition TG4Globals.h:101
TG4G3ControlValue
Enumeration for G3 processes control values.
TG4G3Cut
Enumeration for G3 types of kinetic energy cuts.
Definition TG4G3Cut.h:22
std::vector< G4bool > TG4boolVector
Definition TG4Globals.h:37
TG4G3Control
Enumeration for G3 types of physics processes controls.
@ kUnsetControlValue
value not set
@ kCUTGAM
Definition TG4G3Cut.h:27
@ kDCUTM
Definition TG4G3Cut.h:67
@ kDCUTE
Definition TG4G3Cut.h:62
@ kCUTHAD
Definition TG4G3Cut.h:42
@ kNoG3Cuts
Invalid value.
Definition TG4G3Cut.h:80
@ kBCUTM
Definition TG4G3Cut.h:57
@ kCUTNEU
Definition TG4G3Cut.h:37
@ kCUTMUO
Definition TG4G3Cut.h:47
@ kCUTELE
Definition TG4G3Cut.h:32
@ kPPCUTM
Definition TG4G3Cut.h:72
@ kBCUTE
Definition TG4G3Cut.h:52
@ kTOFMAX
Definition TG4G3Cut.h:77
@ kDCAY
@ kPAIR
@ kPFIS
@ kNoG3Controls
No process control.
@ kHADR
@ kANNI
@ kDRAY
@ kG3LOSS
@ kCOMP
@ kBREM
@ kMUNU
@ kMULS
@ kPHOT
TG4G3ParticleWSP
The particles types which a special process (cuts, controls) is applicable for.
@ kNofParticlesWSP
not a particle with a special control
@ kNeutralHadron
kHADR
@ kGamma
kPAIR, kCOMP, kPHOT, kPHIS
@ kElectron
kDRAY, kBREM, kMULS, kG3LOSS
@ kEplus
kDRAY, kBREM, kMULS, kG3LOSS, kANNI
@ kAny
kDCAY
@ kMuon
kDRAY, kBREM, kMULS, kG3LOSS, kMUNU
@ kChargedHadron
kDRAY, kMULS, kG3LOSS, kHADR,