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 //_____________________________________________________________________________
19 TG4G3PhysicsManager::TG4G3PhysicsManager()
26 TG4Globals::Exception(
27 "TG4G3PhysicsManager: attempt to create two instances of singleton.");
32 // initialize fIsCutVector
33 fIsCutVector = new TG4boolVector;
35 //for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->insert(false);
36 for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->push_back(false);
38 // initialize fIsControlVector
39 fIsControlVector = new TG4boolVector;
40 //for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->insert(false);
41 for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->push_back(false);
43 // define fCutNameVector, fControlNameVector
44 FillG3CutNameVector();
45 FillG3ControlNameVector();
48 //_____________________________________________________________________________
49 TG4G3PhysicsManager::TG4G3PhysicsManager(const TG4G3PhysicsManager& right) {
51 TG4Globals::Exception(
52 "Attempt to copy TG4G3PhysicsManager singleton.");
55 //_____________________________________________________________________________
56 TG4G3PhysicsManager::~TG4G3PhysicsManager() {
59 delete fIsControlVector;
64 //_____________________________________________________________________________
66 TG4G3PhysicsManager::operator=(const TG4G3PhysicsManager& right)
68 // check assignement to self
69 if (this == &right) return *this;
71 TG4Globals::Exception(
72 "Attempt to assign TG4G3PhysicsManager singleton.");
79 //_____________________________________________________________________________
80 void TG4G3PhysicsManager::FillG3CutNameVector()
82 // Defines fCutNameVector.
85 fG3CutNameVector.insert("CUTGAM");
86 fG3CutNameVector.insert("CUTELE");
87 fG3CutNameVector.insert("CUTNEU");
88 fG3CutNameVector.insert("CUTHAD");
89 fG3CutNameVector.insert("CUTMUO");
90 fG3CutNameVector.insert("BCUTE");
91 fG3CutNameVector.insert("BCUTM");
92 fG3CutNameVector.insert("DCUTE");
93 fG3CutNameVector.insert("DCUTM");
94 fG3CutNameVector.insert("PPCUTM");
97 //_____________________________________________________________________________
98 void TG4G3PhysicsManager::FillG3ControlNameVector()
100 // Defines fControlNameVector.
103 fG3ControlNameVector.insert("PAIR");
104 fG3ControlNameVector.insert("COMP");
105 fG3ControlNameVector.insert("PHOT");
106 fG3ControlNameVector.insert("PFIS");
107 fG3ControlNameVector.insert("DRAY");
108 fG3ControlNameVector.insert("ANNI");
109 fG3ControlNameVector.insert("BREM");
110 fG3ControlNameVector.insert("HADR");
111 fG3ControlNameVector.insert("MUNU");
112 fG3ControlNameVector.insert("DCAY");
113 fG3ControlNameVector.insert("LOSS");
114 fG3ControlNameVector.insert("MULS");
117 //_____________________________________________________________________________
118 void TG4G3PhysicsManager::SetCut(TG4G3Cut cut, G4double cutValue)
120 // Sets kinetic energy cut (in a G3-like way).
124 // create vector of kinetic energy cut values
125 fCutVector = new TG4G3CutVector();
127 fCutVector->SetG3Cut(cut, cutValue);
128 SwitchIsCutVector(cut);
131 //_____________________________________________________________________________
132 void TG4G3PhysicsManager::SetProcess(TG4G3Control control, G4int controlValue)
134 // Sets control process control (in a G3-like way).
137 if (!fControlVector) {
138 // create vector of control process control values
139 fControlVector = new TG4G3ControlVector;
141 fControlVector->SetG3Control(control, controlValue);
144 //_____________________________________________________________________________
145 void TG4G3PhysicsManager::SwitchIsCutVector(TG4G3Cut cut)
147 // Updates the vector of booleans (fIsCutVector) for the specified cut.
152 (*fIsCutVector)[kGamma] = true;
155 (*fIsCutVector)[kGamma] = true;
158 (*fIsCutVector)[kGamma] = true;
161 (*fIsCutVector)[kElectron] = true;
164 (*fIsCutVector)[kElectron] = true;
167 (*fIsCutVector)[kElectron] = true;
170 (*fIsCutVector)[kNeutralHadron] = true;
173 (*fIsCutVector)[kChargedHadron] = true;
176 (*fIsCutVector)[kMuon] = true;
183 //_____________________________________________________________________________
184 void TG4G3PhysicsManager::SwitchIsControlVector(TG4G3Control control)
186 // Updates the vector of booleans (fIsControlVector) for the specified control.
192 (*fIsControlVector)[kGamma] = true;
196 (*fIsControlVector)[kGamma] = true;
200 (*fIsControlVector)[kGamma] = true;
204 (*fIsControlVector)[kGamma] = true;
207 // all charged particles
208 (*fIsControlVector)[kElectron] = true;
209 (*fIsControlVector)[kEplus] = true;
210 (*fIsControlVector)[kChargedHadron] = true;
211 (*fIsControlVector)[kMuon] = true;
215 (*fIsControlVector)[kEplus] = true;
219 (*fIsControlVector)[kElectron] = true;
220 (*fIsControlVector)[kEplus] = true;
221 (*fIsControlVector)[kMuon] = true;
225 (*fIsControlVector)[kNeutralHadron] = true;
226 (*fIsControlVector)[kChargedHadron] = true;
230 (*fIsControlVector)[kMuon] = true;
234 (*fIsControlVector)[kAny] = true;
237 // all charged particles
238 (*fIsControlVector)[kElectron] = true;
239 (*fIsControlVector)[kEplus] = true;
240 (*fIsControlVector)[kChargedHadron] = true;
241 (*fIsControlVector)[kMuon] = true;
244 // all charged particles
245 (*fIsControlVector)[kElectron] = true;
246 (*fIsControlVector)[kEplus] = true;
247 (*fIsControlVector)[kChargedHadron] = true;
248 (*fIsControlVector)[kMuon] = true;
255 //_____________________________________________________________________________
256 TG4G3Cut TG4G3PhysicsManager::GetG3Cut(G4String cutName)
258 // Retrieves corresponding TG4G3Cut constant from the cutName.
261 if (cutName == fG3CutNameVector[kCUTGAM]) return kCUTGAM;
262 else if (cutName == fG3CutNameVector[kBCUTE]) return kBCUTE;
263 else if (cutName == fG3CutNameVector[kBCUTM]) return kBCUTM;
264 else if (cutName == fG3CutNameVector[kCUTELE]) return kCUTELE;
265 else if (cutName == fG3CutNameVector[kDCUTE]) return kDCUTE;
266 else if (cutName == fG3CutNameVector[kDCUTM]) return kDCUTM;
267 else if (cutName == fG3CutNameVector[kCUTNEU]) return kCUTNEU;
268 else if (cutName == fG3CutNameVector[kCUTHAD]) return kCUTHAD;
269 else if (cutName == fG3CutNameVector[kCUTMUO]) return kCUTMUO;
270 else return kNoG3Cuts;
273 //_____________________________________________________________________________
274 TG4G3Control TG4G3PhysicsManager::GetG3Control(G4String controlName)
276 // Retrieves corresponding TG4G3Control constant from the controlName.
279 if (controlName == fG3ControlNameVector[kPAIR]) return kPAIR;
280 else if (controlName == fG3ControlNameVector[kCOMP]) return kCOMP;
281 else if (controlName == fG3ControlNameVector[kPHOT]) return kPHOT;
282 else if (controlName == fG3ControlNameVector[kPFIS]) return kPFIS;
283 else if (controlName == fG3ControlNameVector[kDRAY]) return kDRAY;
284 else if (controlName == fG3ControlNameVector[kANNI]) return kANNI;
285 else if (controlName == fG3ControlNameVector[kBREM]) return kBREM;
286 else if (controlName == fG3ControlNameVector[kHADR]) return kHADR;
287 else if (controlName == fG3ControlNameVector[kMUNU]) return kMUNU;
288 else if (controlName == fG3ControlNameVector[kDCAY]) return kDCAY;
289 else if (controlName == fG3ControlNameVector[kLOSS]) return kLOSS;
290 else if (controlName == fG3ControlNameVector[kMULS]) return kMULS;
291 else return kNoG3Controls;
296 //_____________________________________________________________________________
297 void TG4G3PhysicsManager::CheckLock()
299 // Gives exception in case the physics manager is locked.
300 // Prevents from modifying physics setup after the physics manager is locked.
304 G4String text = "TG4PhysicsManager: \n";
305 text = text + " It is too late to change physics setup. \n";
306 text = text + " PhysicsManager has been already locked.";
307 TG4Globals::Exception(text);
311 //_____________________________________________________________________________
312 G4VProcess* TG4G3PhysicsManager::FindProcess(G4String processName) const
314 // Finds G4VProcess with specified name.
317 G4ProcessTable* processTable = G4ProcessTable::GetProcessTable();
319 G4ProcessVector* processVector
320 = processTable->FindProcesses(processName);
321 G4VProcess* firstFoundProcess = 0;
322 if (processVector->entries()>0) firstFoundProcess= (*processVector)[0];
324 processVector->clear();
325 delete processVector;
327 return firstFoundProcess;
330 //_____________________________________________________________________________
331 G4bool TG4G3PhysicsManager::CheckCutWithTheVector(G4String name,
332 G4double value, TG4G3Cut& cut)
334 // Retrieves corresponding TG4G3Cut from the name and
335 // in case the value is different from the value in cutVector
336 // sets true the value of the fIsCutVector element
337 // corresponding to this cut and returns true;
338 // returns false otherwise.
341 // convert cut name -> TG4G3Cut
342 cut = GetG3Cut(name);
344 // set switch vector element only if the value
345 // is different from the value in cutVector
346 if (cut !=kNoG3Cuts) {
347 // get tolerance from TG4G3Defaults in GeV
348 G4double tolerance = TG4G3Defaults::CutTolerance()/GeV;
349 if (!(fCutVector) || (abs(value - (*fCutVector)[cut]) > tolerance)) {
350 SwitchIsCutVector(cut);
358 //_____________________________________________________________________________
359 G4bool TG4G3PhysicsManager::CheckControlWithTheVector(G4String name,
360 G4double value, TG4G3Control& control)
362 // Retrieves corresponding TG4G3Control from the name and
363 // in case the value is different from the value in controlVector
364 // sets true the value of the fIsControlVector element
365 // corresponding to this control and returns true;
366 // returns false otherwise.
369 // convert control name -> TG4G3Control
370 control = GetG3Control(name);
372 // set switch vector element only if the value
373 // is different from the value in controlVector
374 if (control !=kNoG3Controls) {
375 if (!(fControlVector) || (abs(value - (*fControlVector)[control]) > 0.01)) {
376 SwitchIsControlVector(control);
384 //_____________________________________________________________________________
385 G4bool TG4G3PhysicsManager::CheckCutWithG3Defaults(G4String name,
386 G4double value, TG4G3Cut& cut)
388 // Retrieves corresponding TG4G3Cut from the name and
389 // in case the value is different from the G3 default value
390 // sets true the value of the SwitchCutVector element
391 // corresponding to this cut and returns true;
392 // returns false otherwise.
395 // convert cut name -> TG4G3Cut
396 cut = GetG3Cut(name);
398 // set switch vector element only if the value
399 // is different from G3 default
400 if (cut !=kNoG3Cuts) {
401 if (!TG4G3Defaults::IsDefaultCut(cut, value)) {
402 SwitchIsCutVector(cut);
410 //_____________________________________________________________________________
411 G4bool TG4G3PhysicsManager::CheckControlWithG3Defaults(G4String name,
412 G4double value, TG4G3Control& control)
414 // Retrieves corresponding TG4G3Control from the name and
415 // in case the value is different from the G3 default value
416 // sets true the value of the SwitchControlVector element
417 // corresponding to this control and returns true;
418 // returns false otherwise.
421 // convert control name -> TG4G3Control
422 control = GetG3Control(name);
424 // set switch vector element only if the value
425 // is different from G3 default
426 if (control !=kNoG3Controls) {
427 if (!TG4G3Defaults::IsDefaultControl(control, value)) {
428 SwitchIsControlVector(control);
436 //_____________________________________________________________________________
437 void TG4G3PhysicsManager::SetG3DefaultCuts()
439 // Sets G3 default values of kinetic energy cuts.
444 // create vector of kinetic energy cut values
445 fCutVector = new TG4G3CutVector();
447 fCutVector->SetG3Defaults();
450 //_____________________________________________________________________________
451 void TG4G3PhysicsManager::SetG3DefaultControls()
453 // Sets G3 default values of control process controls.
457 if (!fControlVector) {
458 // create vector of control process control values
459 fControlVector = new TG4G3ControlVector;
461 fControlVector->SetG3Defaults();
464 //_____________________________________________________________________________
465 G4bool TG4G3PhysicsManager::IsSpecialCuts() const
467 // Returns true if any special cut value is set.
470 for (G4int i=0; i<kNofParticlesWSP; i++)
471 { if ((*fIsCutVector)[i]) return true; }
476 //_____________________________________________________________________________
477 G4bool TG4G3PhysicsManager::IsSpecialControls() const
479 // Returns true if any special control value is set.
482 for (G4int i=0; i<kNofParticlesWSP; i++)
483 { if ((*fIsControlVector)[i]) return true; }
488 //_____________________________________________________________________________
489 TG4G3ParticleWSP TG4G3PhysicsManager::GetG3ParticleWSP(
490 G4ParticleDefinition* particle) const
492 // Returns TG4G3ParticleWSP constant for the specified particle.
493 // (See TG4G3ParticleWSP.h, too.)
496 G4String name = particle->GetParticleName();
497 G4String pType = particle->GetParticleType();
499 if (name == "gamma") {
502 else if (name == "e-") {
505 else if (name == "e+") {
508 else if (( pType == "baryon" || pType == "meson" || pType == "nucleus" )) {
509 if (particle->GetPDGCharge() == 0) {
510 return kNeutralHadron;
513 return kChargedHadron;
515 else if ( name == "mu-" || name == "mu+" ) {
519 return kNofParticlesWSP;
523 //_____________________________________________________________________________
524 void TG4G3PhysicsManager::GetG3ParticleWSPName(G4int particleWSP,
525 G4String& name) const
527 // Fills the passed name with the name/type of particle specified
528 // by TG4G3ParticleWSP constant.
529 // (See TG4G3ParticleWSP.h, too.)
532 switch (particleWSP) {
543 name = "NeutralHadron";
546 name = "ChargedHadron";
554 case kNofParticlesWSP:
558 G4String text = "TG4G3PhysicsManager::GetG3ParticleWSPName:\n";
559 text = text + " Wrong particleWSP.";
560 TG4Globals::Exception(text);