4 // Author: I. Hrivnacova
6 // Class TG4G3PhysicsManager
7 // -------------------------
8 // See the class description in the header file.
10 #include "TG4G3PhysicsManager.h"
11 #include "TG4G3CutVector.h"
12 #include "TG4G3ControlVector.h"
13 #include "TG4G3Defaults.h"
14 #include "TG4G3Units.h"
16 #include <G4ParticleDefinition.hh>
17 #include <G4VProcess.hh>
18 #include <G4UImessenger.hh>
19 #include <G4ProcessTable.hh>
21 TG4G3PhysicsManager* TG4G3PhysicsManager::fgInstance = 0;
23 //_____________________________________________________________________________
24 TG4G3PhysicsManager::TG4G3PhysicsManager()
33 TG4Globals::Exception(
34 "TG4G3PhysicsManager: attempt to create two instances of singleton.");
39 // create vector of kinetic energy cut values
40 fCutVector = new TG4G3CutVector();
42 // create vector of control process control values
43 fControlVector = new TG4G3ControlVector();
45 // initialize fIsCutVector
46 fIsCutVector = new TG4boolVector();
48 for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->push_back(false);
50 // initialize fIsControlVector
51 fIsControlVector = new TG4boolVector;
52 for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->push_back(false);
55 //_____________________________________________________________________________
56 TG4G3PhysicsManager::TG4G3PhysicsManager(const TG4G3PhysicsManager& right) {
58 TG4Globals::Exception(
59 "Attempt to copy TG4G3PhysicsManager singleton.");
62 //_____________________________________________________________________________
63 TG4G3PhysicsManager::~TG4G3PhysicsManager() {
65 // delete fIsCutVector;
66 delete fIsControlVector;
71 //_____________________________________________________________________________
73 TG4G3PhysicsManager::operator=(const TG4G3PhysicsManager& right)
75 // check assignement to self
76 if (this == &right) return *this;
78 TG4Globals::Exception(
79 "Attempt to assign TG4G3PhysicsManager singleton.");
86 //_____________________________________________________________________________
87 void TG4G3PhysicsManager::SetCut(TG4G3Cut cut, G4double cutValue)
89 // Sets kinetic energy cut (in a G3-like way).
92 fCutVector->SetCut(cut, cutValue);
93 SwitchIsCutVector(cut);
96 //_____________________________________________________________________________
97 void TG4G3PhysicsManager::SetProcess(TG4G3Control control,
98 TG4G3ControlValue controlValue)
100 // Sets control process control (in a G3-like way).
103 if (control == kDRAY || control == kLOSS) {
104 SwitchIsCutVector(kDCUTE);
105 SwitchIsCutVector(kDCUTM);
108 fControlVector->SetControl(control, controlValue, *fCutVector);
112 //_____________________________________________________________________________
113 void TG4G3PhysicsManager::SwitchIsCutVector(TG4G3Cut cut)
115 // Updates the vector of booleans (fIsCutVector) for the specified cut.
120 (*fIsCutVector)[kGamma] = true;
123 (*fIsCutVector)[kGamma] = true;
126 (*fIsCutVector)[kGamma] = true;
129 (*fIsCutVector)[kElectron] = true;
130 (*fIsCutVector)[kEplus] = true;
133 (*fIsCutVector)[kElectron] = true;
136 (*fIsCutVector)[kElectron] = true;
139 (*fIsCutVector)[kNeutralHadron] = true;
142 (*fIsCutVector)[kChargedHadron] = true;
145 (*fIsCutVector)[kMuon] = true;
152 //_____________________________________________________________________________
153 void TG4G3PhysicsManager::SwitchIsControlVector(TG4G3Control control)
155 // Updates the vector of booleans (fIsControlVector) for the specified control.
161 (*fIsControlVector)[kGamma] = true;
165 (*fIsControlVector)[kGamma] = true;
169 (*fIsControlVector)[kGamma] = true;
173 (*fIsControlVector)[kGamma] = true;
176 // all charged particles
177 (*fIsControlVector)[kElectron] = true;
178 (*fIsControlVector)[kEplus] = true;
179 (*fIsControlVector)[kChargedHadron] = true;
180 (*fIsControlVector)[kMuon] = true;
184 (*fIsControlVector)[kEplus] = true;
188 (*fIsControlVector)[kElectron] = true;
189 (*fIsControlVector)[kEplus] = true;
190 (*fIsControlVector)[kMuon] = true;
194 (*fIsControlVector)[kNeutralHadron] = true;
195 (*fIsControlVector)[kChargedHadron] = true;
199 (*fIsControlVector)[kMuon] = true;
203 (*fIsControlVector)[kAny] = true;
206 // all charged particles
207 (*fIsControlVector)[kElectron] = true;
208 (*fIsControlVector)[kEplus] = true;
209 (*fIsControlVector)[kChargedHadron] = true;
210 (*fIsControlVector)[kMuon] = true;
213 // all charged particles
214 (*fIsControlVector)[kElectron] = true;
215 (*fIsControlVector)[kEplus] = true;
216 (*fIsControlVector)[kChargedHadron] = true;
217 (*fIsControlVector)[kMuon] = true;
226 //_____________________________________________________________________________
227 void TG4G3PhysicsManager::CheckLock()
229 // Gives exception in case the physics manager is locked.
230 // Prevents from modifying physics setup after the physics manager is locked.
234 G4String text = "TG4PhysicsManager: \n";
235 text = text + " It is too late to change physics setup. \n";
236 text = text + " PhysicsManager has been already locked.";
237 TG4Globals::Exception(text);
241 //_____________________________________________________________________________
242 G4VProcess* TG4G3PhysicsManager::FindProcess(G4String processName) const
244 // Finds G4VProcess with specified name.
247 G4ProcessTable* processTable = G4ProcessTable::GetProcessTable();
249 G4ProcessVector* processVector
250 = processTable->FindProcesses(processName);
251 G4VProcess* firstFoundProcess = 0;
252 if (processVector->entries()>0) firstFoundProcess= (*processVector)[0];
254 processVector->clear();
255 delete processVector;
257 return firstFoundProcess;
260 //_____________________________________________________________________________
261 G4bool TG4G3PhysicsManager::CheckCutWithTheVector(G4String name,
262 G4double value, TG4G3Cut& cut)
264 // Retrieves corresponding TG4G3Cut from the name and
265 // in case the value is different from the value in cutVector
266 // sets true the value of the fIsCutVector element
267 // corresponding to this cut and returns true;
268 // returns false otherwise.
271 // convert cut name -> TG4G3Cut
272 cut = TG4G3CutVector::GetCut(name);
274 // set switch vector element only if the value
275 // is different from the value in cutVector
276 if (cut !=kNoG3Cuts) {
277 // get tolerance from TG4G3CutVector in G3 units
278 G4double tolerance = TG4G3CutVector::Tolerance()/ TG4G3Units::Energy();
279 if (abs(value - (*fCutVector)[cut]) > tolerance) {
280 SwitchIsCutVector(cut);
288 //_____________________________________________________________________________
289 G4bool TG4G3PhysicsManager::CheckControlWithTheVector(G4String name,
290 G4double value, TG4G3Control& control,
291 TG4G3ControlValue& controlValue)
293 // Retrieves corresponding TG4G3Control from the name and
294 // in case the value is different from the value in controlVector
295 // sets true the value of the fIsControlVector element
296 // corresponding to this control and returns true;
297 // returns false otherwise.
300 // convert control name -> TG4G3Control
301 control = TG4G3ControlVector::GetControl(name);
303 // convert double value -> TG4G3ControlValue
304 controlValue = TG4G3ControlVector::GetControlValue(value, control);
306 // set switch vector element only if the value
307 // is different from the value in controlVector
308 if (control !=kNoG3Controls) {
309 if (controlValue != (*fControlVector)[control]) {
310 SwitchIsControlVector(control);
318 //_____________________________________________________________________________
319 G4bool TG4G3PhysicsManager::CheckCutWithG3Defaults(G4String name,
320 G4double value, TG4G3Cut& cut)
322 // Retrieves corresponding TG4G3Cut from the name and
323 // in case the value is different from the G3 default value
324 // sets true the value of the SwitchCutVector element
325 // corresponding to this cut and returns true;
326 // returns false otherwise.
329 // convert cut name -> TG4G3Cut
330 cut = TG4G3CutVector::GetCut(name);
332 // set switch vector element only if the value
333 // is different from G3 default
334 if (cut !=kNoG3Cuts) {
335 if (!fG3Defaults.IsDefaultCut(cut, value)) {
336 SwitchIsCutVector(cut);
344 //_____________________________________________________________________________
345 G4bool TG4G3PhysicsManager::CheckControlWithG3Defaults(G4String name,
346 G4double value, TG4G3Control& control,
347 TG4G3ControlValue& controlValue)
349 // Retrieves corresponding TG4G3Control from the name and
350 // in case the value is different from the G3 default value
351 // sets true the value of the SwitchControlVector element
352 // corresponding to this control and returns true;
353 // returns false otherwise.
356 // convert control name -> TG4G3Control
357 control = TG4G3ControlVector::GetControl(name);
359 // convert double value -> TG4G3ControlValue
360 controlValue = TG4G3ControlVector::GetControlValue(value, control);
362 // set switch vector element only if the value
363 // is different from G3 default
364 if (control !=kNoG3Controls) {
365 if (!fG3Defaults.IsDefaultControl(control, controlValue)) {
366 SwitchIsControlVector(control);
374 //_____________________________________________________________________________
375 void TG4G3PhysicsManager::SetG3DefaultCuts()
377 // Sets G3 default values of kinetic energy cuts.
381 fCutVector->SetG3Defaults();
384 //_____________________________________________________________________________
385 void TG4G3PhysicsManager::SetG3DefaultControls()
387 // Sets G3 default values of control process controls.
391 fControlVector->SetG3Defaults();
394 //_____________________________________________________________________________
395 G4bool TG4G3PhysicsManager::IsSpecialCuts() const
397 // Returns true if any special cut value is set.
401 for (G4int i=0; i<kNofParticlesWSP; i++)
402 { if ((*fIsCutVector)[i]) return true; }
407 //_____________________________________________________________________________
408 G4bool TG4G3PhysicsManager::IsSpecialControls() const
410 // Returns true if any special control value is set.
413 for (G4int i=0; i<kNofParticlesWSP; i++)
414 { if ((*fIsControlVector)[i]) return true; }
419 //_____________________________________________________________________________
420 TG4G3ParticleWSP TG4G3PhysicsManager::GetG3ParticleWSP(
421 G4ParticleDefinition* particle) const
423 // Returns TG4G3ParticleWSP constant for the specified particle.
424 // (See TG4G3ParticleWSP.h, too.)
427 G4String name = particle->GetParticleName();
428 G4String pType = particle->GetParticleType();
430 if (name == "gamma") {
433 else if (name == "e-") {
436 else if (name == "e+") {
439 else if (( pType == "baryon" || pType == "meson" || pType == "nucleus" )) {
440 if (particle->GetPDGCharge() == 0) {
441 return kNeutralHadron;
444 return kChargedHadron;
446 else if ( name == "mu-" || name == "mu+" ) {
450 return kNofParticlesWSP;
454 //_____________________________________________________________________________
455 G4String TG4G3PhysicsManager::GetG3ParticleWSPName(G4int particleWSP) const
457 // Returns the name of the particle specified by TG4G3ParticleWSP constant.
458 // (See TG4G3ParticleWSP.h, too.)
461 switch (particleWSP) {
472 return "NeutralHadron";
475 return "ChargedHadron";
483 case kNofParticlesWSP:
487 G4String text = "TG4G3PhysicsManager::GetG3ParticleWSPName:\n";
488 text = text + " Wrong particleWSP.";
489 TG4Globals::Exception(text);