4 // See the class description in the header file.
6 #include "TG4G3PhysicsManager.h"
7 #include "TG4G3CutVector.h"
8 #include "TG4G3ControlVector.h"
9 #include "TG4G3Defaults.h"
11 #include <G4ParticleDefinition.hh>
12 #include <G4VProcess.hh>
13 #include <G4UImessenger.hh>
14 #include <G4ProcessTable.hh>
16 TG4G3PhysicsManager* TG4G3PhysicsManager::fgInstance = 0;
18 TG4G3PhysicsManager::TG4G3PhysicsManager()
24 TG4Globals::Exception(
25 "TG4G3PhysicsManager: attempt to create two instances of singleton.");
30 // initialize fIsCutVector
31 fIsCutVector = new TG4boolVector;
33 //for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->insert(false);
34 for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->push_back(false);
36 // initialize fIsControlVector
37 fIsControlVector = new TG4boolVector;
38 //for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->insert(false);
39 for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->push_back(false);
41 // define fCutNameVector, fControlNameVector
42 FillG3CutNameVector();
43 FillG3ControlNameVector();
46 TG4G3PhysicsManager::TG4G3PhysicsManager(const TG4G3PhysicsManager& right) {
48 TG4Globals::Exception(
49 "Attempt to copy TG4G3PhysicsManager singleton.");
52 TG4G3PhysicsManager::~TG4G3PhysicsManager() {
55 delete fIsControlVector;
61 TG4G3PhysicsManager::operator=(const TG4G3PhysicsManager& right)
63 // check assignement to self
64 if (this == &right) return *this;
66 TG4Globals::Exception(
67 "Attempt to assign TG4G3PhysicsManager singleton.");
74 void TG4G3PhysicsManager::FillG3CutNameVector()
76 // Defines fCutNameVector.
79 fG3CutNameVector.insert("CUTGAM");
80 fG3CutNameVector.insert("CUTELE");
81 fG3CutNameVector.insert("CUTNEU");
82 fG3CutNameVector.insert("CUTHAD");
83 fG3CutNameVector.insert("CUTMUO");
84 fG3CutNameVector.insert("BCUTE");
85 fG3CutNameVector.insert("BCUTM");
86 fG3CutNameVector.insert("DCUTE");
87 fG3CutNameVector.insert("DCUTM");
88 fG3CutNameVector.insert("PPCUTM");
91 void TG4G3PhysicsManager::FillG3ControlNameVector()
93 // Defines fControlNameVector.
96 fG3ControlNameVector.insert("PAIR");
97 fG3ControlNameVector.insert("COMP");
98 fG3ControlNameVector.insert("PHOT");
99 fG3ControlNameVector.insert("PFIS");
100 fG3ControlNameVector.insert("DRAY");
101 fG3ControlNameVector.insert("ANNI");
102 fG3ControlNameVector.insert("BREM");
103 fG3ControlNameVector.insert("HADR");
104 fG3ControlNameVector.insert("MUNU");
105 fG3ControlNameVector.insert("DCAY");
106 fG3ControlNameVector.insert("LOSS");
107 fG3ControlNameVector.insert("MULS");
110 void TG4G3PhysicsManager::SetCut(TG4G3Cut cut, G4double cutValue)
112 // Sets kinetic energy cut (in a G3-like way).
116 // create vector of kinetic energy cut values
117 fCutVector = new TG4G3CutVector();
119 fCutVector->SetG3Cut(cut, cutValue);
120 SwitchIsCutVector(cut);
123 void TG4G3PhysicsManager::SetProcess(TG4G3Control control, G4int controlValue)
125 // Sets control process control (in a G3-like way).
128 if (!fControlVector) {
129 // create vector of control process control values
130 fControlVector = new TG4G3ControlVector;
132 fControlVector->SetG3Control(control, controlValue);
136 void TG4G3PhysicsManager::SwitchIsCutVector(TG4G3Cut cut)
138 // Updates the vector of booleans (fIsCutVector) for the specified cut.
143 (*fIsCutVector)[kGamma] = true;
146 (*fIsCutVector)[kGamma] = true;
149 (*fIsCutVector)[kGamma] = true;
152 (*fIsCutVector)[kElectron] = true;
155 (*fIsCutVector)[kElectron] = true;
158 (*fIsCutVector)[kElectron] = true;
161 (*fIsCutVector)[kNeutralHadron] = true;
164 (*fIsCutVector)[kChargedHadron] = true;
167 (*fIsCutVector)[kMuon] = true;
174 void TG4G3PhysicsManager::SwitchIsControlVector(TG4G3Control control)
176 // Updates the vector of booleans (fIsControlVector) for the specified control.
182 (*fIsControlVector)[kGamma] = true;
186 (*fIsControlVector)[kGamma] = true;
190 (*fIsControlVector)[kGamma] = true;
194 (*fIsControlVector)[kGamma] = true;
197 // all charged particles
198 (*fIsControlVector)[kElectron] = true;
199 (*fIsControlVector)[kEplus] = true;
200 (*fIsControlVector)[kChargedHadron] = true;
201 (*fIsControlVector)[kMuon] = true;
205 (*fIsControlVector)[kEplus] = true;
209 (*fIsControlVector)[kElectron] = true;
210 (*fIsControlVector)[kEplus] = true;
211 (*fIsControlVector)[kMuon] = true;
215 (*fIsControlVector)[kNeutralHadron] = true;
216 (*fIsControlVector)[kChargedHadron] = true;
220 (*fIsControlVector)[kMuon] = true;
224 (*fIsControlVector)[kAny] = true;
227 // all charged particles
228 (*fIsControlVector)[kElectron] = true;
229 (*fIsControlVector)[kEplus] = true;
230 (*fIsControlVector)[kChargedHadron] = true;
231 (*fIsControlVector)[kMuon] = true;
234 // all charged particles
235 (*fIsControlVector)[kElectron] = true;
236 (*fIsControlVector)[kEplus] = true;
237 (*fIsControlVector)[kChargedHadron] = true;
238 (*fIsControlVector)[kMuon] = true;
245 TG4G3Cut TG4G3PhysicsManager::GetG3Cut(G4String cutName)
247 // Retrieves corresponding TG4G3Cut constant from the cutName.
250 if (cutName == fG3CutNameVector[kCUTGAM]) return kCUTGAM;
251 else if (cutName == fG3CutNameVector[kBCUTE]) return kBCUTE;
252 else if (cutName == fG3CutNameVector[kBCUTM]) return kBCUTM;
253 else if (cutName == fG3CutNameVector[kCUTELE]) return kCUTELE;
254 else if (cutName == fG3CutNameVector[kDCUTE]) return kDCUTE;
255 else if (cutName == fG3CutNameVector[kDCUTM]) return kDCUTM;
256 else if (cutName == fG3CutNameVector[kCUTNEU]) return kCUTNEU;
257 else if (cutName == fG3CutNameVector[kCUTHAD]) return kCUTHAD;
258 else if (cutName == fG3CutNameVector[kCUTMUO]) return kCUTMUO;
259 else return kNoG3Cuts;
262 TG4G3Control TG4G3PhysicsManager::GetG3Control(G4String controlName)
264 // Retrieves corresponding TG4G3Control constant from the controlName.
267 if (controlName == fG3ControlNameVector[kPAIR]) return kPAIR;
268 else if (controlName == fG3ControlNameVector[kCOMP]) return kCOMP;
269 else if (controlName == fG3ControlNameVector[kPHOT]) return kPHOT;
270 else if (controlName == fG3ControlNameVector[kPFIS]) return kPFIS;
271 else if (controlName == fG3ControlNameVector[kDRAY]) return kDRAY;
272 else if (controlName == fG3ControlNameVector[kANNI]) return kANNI;
273 else if (controlName == fG3ControlNameVector[kBREM]) return kBREM;
274 else if (controlName == fG3ControlNameVector[kHADR]) return kHADR;
275 else if (controlName == fG3ControlNameVector[kMUNU]) return kMUNU;
276 else if (controlName == fG3ControlNameVector[kDCAY]) return kDCAY;
277 else if (controlName == fG3ControlNameVector[kLOSS]) return kLOSS;
278 else if (controlName == fG3ControlNameVector[kMULS]) return kMULS;
279 else return kNoG3Controls;
285 void TG4G3PhysicsManager::CheckLock()
287 // Gives exception in case the physics manager is locked.
288 // Prevents from modifying physics setup after the physics manager is locked.
292 G4String text = "TG4PhysicsManager: \n";
293 text = text + " It is too late to change physics setup. \n";
294 text = text + " PhysicsManager has been already locked.";
295 TG4Globals::Exception(text);
300 G4VProcess* TG4G3PhysicsManager::FindProcess(G4String processName) const
302 // Finds G4VProcess with specified name.
305 G4ProcessTable* processTable = G4ProcessTable::GetProcessTable();
307 G4ProcessVector* processVector
308 = processTable->FindProcesses(processName);
309 G4VProcess* firstFoundProcess = 0;
310 if (processVector->entries()>0) firstFoundProcess= (*processVector)[0];
312 processVector->clear();
313 delete processVector;
315 return firstFoundProcess;
319 G4bool TG4G3PhysicsManager::CheckCutWithTheVector(G4String name,
320 G4double value, TG4G3Cut& cut)
322 // Retrieves corresponding TG4G3Cut from the name and
323 // in case the value is different from the value in cutVector
324 // sets true the value of the fIsCutVector element
325 // corresponding to this cut and returns true;
326 // returns false otherwise.
329 // convert cut name -> TG4G3Cut
330 cut = GetG3Cut(name);
332 // set switch vector element only if the value
333 // is different from the value in cutVector
334 if (cut !=kNoG3Cuts) {
335 // get tolerance from TG4G3Defaults in GeV
336 G4double tolerance = TG4G3Defaults::CutTolerance()/GeV;
337 if (!(fCutVector) || (abs(value - (*fCutVector)[cut]) > tolerance)) {
338 SwitchIsCutVector(cut);
346 G4bool TG4G3PhysicsManager::CheckControlWithTheVector(G4String name,
347 G4double value, TG4G3Control& control)
349 // Retrieves corresponding TG4G3Control from the name and
350 // in case the value is different from the value in controlVector
351 // sets true the value of the fIsControlVector element
352 // corresponding to this control and returns true;
353 // returns false otherwise.
356 // convert control name -> TG4G3Control
357 control = GetG3Control(name);
359 // set switch vector element only if the value
360 // is different from the value in controlVector
361 if (control !=kNoG3Controls) {
362 if (!(fControlVector) || (abs(value - (*fControlVector)[control]) > 0.01)) {
363 SwitchIsControlVector(control);
371 G4bool TG4G3PhysicsManager::CheckCutWithG3Defaults(G4String name,
372 G4double value, TG4G3Cut& cut)
374 // Retrieves corresponding TG4G3Cut from the name and
375 // in case the value is different from the G3 default value
376 // sets true the value of the SwitchCutVector element
377 // corresponding to this cut and returns true;
378 // returns false otherwise.
381 // convert cut name -> TG4G3Cut
382 cut = GetG3Cut(name);
384 // set switch vector element only if the value
385 // is different from G3 default
386 if (cut !=kNoG3Cuts) {
387 if (!TG4G3Defaults::IsDefaultCut(cut, value)) {
388 SwitchIsCutVector(cut);
396 G4bool TG4G3PhysicsManager::CheckControlWithG3Defaults(G4String name,
397 G4double value, TG4G3Control& control)
399 // Retrieves corresponding TG4G3Control from the name and
400 // in case the value is different from the G3 default value
401 // sets true the value of the SwitchControlVector element
402 // corresponding to this control and returns true;
403 // returns false otherwise.
406 // convert control name -> TG4G3Control
407 control = GetG3Control(name);
409 // set switch vector element only if the value
410 // is different from G3 default
411 if (control !=kNoG3Controls) {
412 if (!TG4G3Defaults::IsDefaultControl(control, value)) {
413 SwitchIsControlVector(control);
421 void TG4G3PhysicsManager::SetG3DefaultCuts()
423 // Sets G3 default values of kinetic energy cuts.
428 // create vector of kinetic energy cut values
429 fCutVector = new TG4G3CutVector();
431 fCutVector->SetG3Defaults();
434 void TG4G3PhysicsManager::SetG3DefaultControls()
436 // Sets G3 default values of control process controls.
440 if (!fControlVector) {
441 // create vector of control process control values
442 fControlVector = new TG4G3ControlVector;
444 fControlVector->SetG3Defaults();
447 G4bool TG4G3PhysicsManager::IsSpecialCuts() const
449 // Returns true if any special cut value is set.
452 for (G4int i=0; i<kNofParticlesWSP; i++)
453 { if ((*fIsCutVector)[i]) return true; }
458 G4bool TG4G3PhysicsManager::IsSpecialControls() const
460 // Returns true if any special control value is set.
463 for (G4int i=0; i<kNofParticlesWSP; i++)
464 { if ((*fIsControlVector)[i]) return true; }
469 TG4G3ParticleWSP TG4G3PhysicsManager::GetG3ParticleWSP(
470 G4ParticleDefinition* particle) const
472 // Returns TG4G3ParticleWSP constant for the specified particle.
473 // (See TG4G3ParticleWSP.h, too.)
476 G4String name = particle->GetParticleName();
477 G4String pType = particle->GetParticleType();
479 if (name == "gamma") {
482 else if (name == "e-") {
485 else if (name == "e+") {
488 else if (( pType == "baryon" || pType == "meson" || pType == "nucleus" )) {
489 if (particle->GetPDGCharge() == 0) {
490 return kNeutralHadron;
493 return kChargedHadron;
495 else if ( name == "mu-" || name == "mu+" ) {
499 return kNofParticlesWSP;
503 void TG4G3PhysicsManager::GetG3ParticleWSPName(G4int particleWSP,
504 G4String& name) const
506 // Fills the passed name with the name/type of particle specified
507 // by TG4G3ParticleWSP constant.
508 // (See TG4G3ParticleWSP.h, too.)
511 switch (particleWSP) {
522 name = "NeutralHadron";
525 name = "ChargedHadron";
533 case kNofParticlesWSP:
537 G4String text = "TG4G3PhysicsManager::GetG3ParticleWSPName:\n";
538 text = text + " Wrong particleWSP.";
539 TG4Globals::Exception(text);