Separated from TG4PhysicsManager (Initial version)
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 13 Feb 2001 14:20:41 +0000 (14:20 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 13 Feb 2001 14:20:41 +0000 (14:20 +0000)
TGeant4/TG4G3PhysicsManager.cxx [new file with mode: 0644]
TGeant4/TG4G3PhysicsManager.h [new file with mode: 0644]
TGeant4/TG4ParticlesManager.cxx [new file with mode: 0644]
TGeant4/TG4ParticlesManager.h [new file with mode: 0644]

diff --git a/TGeant4/TG4G3PhysicsManager.cxx b/TGeant4/TG4G3PhysicsManager.cxx
new file mode 100644 (file)
index 0000000..93c494b
--- /dev/null
@@ -0,0 +1,543 @@
+// $Id$
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4G3PhysicsManager.h"
+#include "TG4G3CutVector.h"
+#include "TG4G3ControlVector.h"
+#include "TG4G3Defaults.h"
+
+#include <G4ParticleDefinition.hh>
+#include <G4VProcess.hh>
+#include <G4UImessenger.hh>
+#include <G4ProcessTable.hh>
+
+TG4G3PhysicsManager* TG4G3PhysicsManager::fgInstance = 0;
+
+TG4G3PhysicsManager::TG4G3PhysicsManager()
+  : fLock(false),
+    fCutVector(0),
+    fControlVector(0) 
+{ 
+  if (fgInstance) {
+    TG4Globals::Exception(
+      "TG4G3PhysicsManager: attempt to create two instances of singleton.");
+  }
+      
+  fgInstance = this;  
+
+  // initialize fIsCutVector 
+  fIsCutVector = new TG4boolVector;
+  G4int i;
+  //for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->insert(false);  
+  for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->push_back(false);
+
+  // initialize fIsControlVector 
+  fIsControlVector = new TG4boolVector;
+  //for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->insert(false);
+  for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->push_back(false);
+
+  // define fCutNameVector, fControlNameVector
+  FillG3CutNameVector();
+  FillG3ControlNameVector();
+}
+
+TG4G3PhysicsManager::TG4G3PhysicsManager(const TG4G3PhysicsManager& right) {
+// 
+  TG4Globals::Exception(
+    "Attempt to copy TG4G3PhysicsManager singleton.");
+}
+
+TG4G3PhysicsManager::~TG4G3PhysicsManager() {
+//
+  delete fIsCutVector;
+  delete fIsControlVector;
+}
+
+// operators
+
+TG4G3PhysicsManager& 
+TG4G3PhysicsManager::operator=(const TG4G3PhysicsManager& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "Attempt to assign TG4G3PhysicsManager singleton.");
+    
+  return *this;  
+}    
+          
+// private methods
+
+void TG4G3PhysicsManager::FillG3CutNameVector()
+{
+// Defines fCutNameVector.
+// ---
+
+  fG3CutNameVector.insert("CUTGAM");
+  fG3CutNameVector.insert("CUTELE");
+  fG3CutNameVector.insert("CUTNEU");
+  fG3CutNameVector.insert("CUTHAD");
+  fG3CutNameVector.insert("CUTMUO");
+  fG3CutNameVector.insert("BCUTE");
+  fG3CutNameVector.insert("BCUTM"); 
+  fG3CutNameVector.insert("DCUTE");
+  fG3CutNameVector.insert("DCUTM");
+  fG3CutNameVector.insert("PPCUTM");
+}
+
+void TG4G3PhysicsManager::FillG3ControlNameVector() 
+{
+// Defines fControlNameVector.
+// ---
+
+  fG3ControlNameVector.insert("PAIR");
+  fG3ControlNameVector.insert("COMP");
+  fG3ControlNameVector.insert("PHOT");
+  fG3ControlNameVector.insert("PFIS");
+  fG3ControlNameVector.insert("DRAY");
+  fG3ControlNameVector.insert("ANNI");
+  fG3ControlNameVector.insert("BREM");
+  fG3ControlNameVector.insert("HADR");
+  fG3ControlNameVector.insert("MUNU");
+  fG3ControlNameVector.insert("DCAY");
+  fG3ControlNameVector.insert("LOSS");
+  fG3ControlNameVector.insert("MULS");
+}
+
+void TG4G3PhysicsManager::SetCut(TG4G3Cut cut, G4double cutValue)
+{  
+// Sets kinetic energy cut (in a G3-like way).
+// ---
+
+  if (!fCutVector) {
+    // create vector of kinetic energy cut values  
+    fCutVector = new TG4G3CutVector();
+  }  
+  fCutVector->SetG3Cut(cut, cutValue);
+  SwitchIsCutVector(cut);
+}  
+
+void TG4G3PhysicsManager::SetProcess(TG4G3Control control, G4int controlValue)
+{
+// Sets control process control (in a G3-like way).
+// ---
+
+  if (!fControlVector) {
+    // create vector of control process control values
+    fControlVector = new TG4G3ControlVector;
+  }  
+  fControlVector->SetG3Control(control, controlValue);
+} 
+
+
+void TG4G3PhysicsManager::SwitchIsCutVector(TG4G3Cut cut)
+{
+// Updates the vector of booleans (fIsCutVector) for the specified cut.
+// ---
+
+  switch (cut) {
+    case kCUTGAM: 
+           (*fIsCutVector)[kGamma] = true; 
+           break;
+    case kBCUTE:
+           (*fIsCutVector)[kGamma] = true; 
+           break;
+    case kBCUTM:
+           (*fIsCutVector)[kGamma] = true; 
+           break;
+    case kCUTELE:
+           (*fIsCutVector)[kElectron] = true; 
+           break;
+    case kDCUTE:
+           (*fIsCutVector)[kElectron] = true; 
+           break;
+    case kDCUTM:
+           (*fIsCutVector)[kElectron] = true; 
+           break;
+    case kCUTNEU:
+           (*fIsCutVector)[kNeutralHadron] = true; 
+           break;
+    case kCUTHAD:
+           (*fIsCutVector)[kChargedHadron] = true; 
+           break;
+    case kCUTMUO:
+           (*fIsCutVector)[kMuon] = true; 
+           break;
+    default:
+           break;
+  }
+}
+
+void TG4G3PhysicsManager::SwitchIsControlVector(TG4G3Control control)
+{
+// Updates the vector of booleans (fIsControlVector) for the specified control.
+// ---
+
+  switch (control) {
+    case kPAIR: 
+           // gamma
+           (*fIsControlVector)[kGamma] = true; 
+           break;
+    case kCOMP:
+           // gamma
+           (*fIsControlVector)[kGamma] = true; 
+          break;
+    case kPHOT:
+           // gamma
+           (*fIsControlVector)[kGamma] = true; 
+          break;
+    case kPFIS:
+           // gamma
+           (*fIsControlVector)[kGamma] = true; 
+          break;
+    case kDRAY:        
+           // all charged particles
+           (*fIsControlVector)[kElectron] = true; 
+           (*fIsControlVector)[kEplus] = true; 
+           (*fIsControlVector)[kChargedHadron] = true; 
+           (*fIsControlVector)[kMuon] = true; 
+          break;
+    case kANNI:
+          // e+ only
+           (*fIsControlVector)[kEplus] = true; 
+          break;
+    case kBREM:
+          // e-/e+, muons
+           (*fIsControlVector)[kElectron] = true; 
+           (*fIsControlVector)[kEplus] = true; 
+           (*fIsControlVector)[kMuon] = true; 
+          break;
+    case kHADR:
+          // hadrons
+           (*fIsControlVector)[kNeutralHadron] = true; 
+           (*fIsControlVector)[kChargedHadron] = true; 
+          break;
+    case kMUNU:
+           // muons
+           (*fIsControlVector)[kMuon] = true; 
+          break;
+    case kDCAY:
+           // any
+           (*fIsControlVector)[kAny] = true; 
+          break;
+    case kLOSS:
+           // all charged particles
+           (*fIsControlVector)[kElectron] = true; 
+           (*fIsControlVector)[kEplus] = true; 
+           (*fIsControlVector)[kChargedHadron] = true; 
+           (*fIsControlVector)[kMuon] = true; 
+          break;
+    case kMULS:
+           // all charged particles
+           (*fIsControlVector)[kElectron] = true; 
+           (*fIsControlVector)[kEplus] = true; 
+           (*fIsControlVector)[kChargedHadron] = true; 
+           (*fIsControlVector)[kMuon] = true; 
+          break;
+    default:
+          break;
+  }
+}
+
+TG4G3Cut TG4G3PhysicsManager::GetG3Cut(G4String cutName)
+{
+// Retrieves corresponding TG4G3Cut constant from the cutName.
+// ---
+
+  if      (cutName == fG3CutNameVector[kCUTGAM]) return kCUTGAM; 
+  else if (cutName == fG3CutNameVector[kBCUTE])  return kBCUTE; 
+  else if (cutName == fG3CutNameVector[kBCUTM])  return kBCUTM; 
+  else if (cutName == fG3CutNameVector[kCUTELE]) return kCUTELE;
+  else if (cutName == fG3CutNameVector[kDCUTE])  return kDCUTE;
+  else if (cutName == fG3CutNameVector[kDCUTM])  return kDCUTM;
+  else if (cutName == fG3CutNameVector[kCUTNEU]) return kCUTNEU;
+  else if (cutName == fG3CutNameVector[kCUTHAD]) return kCUTHAD;
+  else if (cutName == fG3CutNameVector[kCUTMUO]) return kCUTMUO;
+  else return kNoG3Cuts;
+}
+
+TG4G3Control TG4G3PhysicsManager::GetG3Control(G4String controlName)
+{
+// Retrieves corresponding TG4G3Control constant from the controlName.
+// ---
+
+  if      (controlName == fG3ControlNameVector[kPAIR]) return kPAIR;
+  else if (controlName == fG3ControlNameVector[kCOMP]) return kCOMP;
+  else if (controlName == fG3ControlNameVector[kPHOT]) return kPHOT;
+  else if (controlName == fG3ControlNameVector[kPFIS]) return kPFIS;
+  else if (controlName == fG3ControlNameVector[kDRAY]) return kDRAY;
+  else if (controlName == fG3ControlNameVector[kANNI]) return kANNI;
+  else if (controlName == fG3ControlNameVector[kBREM]) return kBREM;
+  else if (controlName == fG3ControlNameVector[kHADR]) return kHADR;
+  else if (controlName == fG3ControlNameVector[kMUNU]) return kMUNU;
+  else if (controlName == fG3ControlNameVector[kDCAY]) return kDCAY;
+  else if (controlName == fG3ControlNameVector[kLOSS]) return kLOSS;
+  else if (controlName == fG3ControlNameVector[kMULS]) return kMULS;
+  else return kNoG3Controls;
+}
+
+// public methods
+
+
+void TG4G3PhysicsManager::CheckLock()
+{
+// Gives exception in case the physics manager is locked.
+// Prevents from modifying physics setup after the physics manager is locked.
+// ---
+
+  if (fLock) {
+    G4String text = "TG4PhysicsManager: \n";
+    text = text + "    It is too late to change physics setup. \n";
+    text = text + "    PhysicsManager has been already locked.";
+    TG4Globals::Exception(text);
+  }  
+}
+
+
+G4VProcess* TG4G3PhysicsManager::FindProcess(G4String processName) const
+{
+// Finds G4VProcess with specified name.
+// ---
+
+  G4ProcessTable* processTable = G4ProcessTable::GetProcessTable();
+
+  G4ProcessVector* processVector 
+    = processTable->FindProcesses(processName);
+  G4VProcess* firstFoundProcess = 0;
+  if (processVector->entries()>0) firstFoundProcess= (*processVector)[0];
+
+  processVector->clear();
+  delete processVector;
+  
+  return firstFoundProcess;
+}
+
+
+G4bool TG4G3PhysicsManager::CheckCutWithTheVector(G4String name, 
+                                 G4double value, TG4G3Cut& cut)
+{
+// Retrieves corresponding TG4G3Cut from the name and 
+// in case the value is different from the value in cutVector
+// sets true the value of the fIsCutVector element 
+// corresponding to this cut and returns true; 
+// returns false otherwise.
+// ---
+
+  // convert cut name -> TG4G3Cut
+  cut = GetG3Cut(name);
+
+  // set switch vector element only if the value
+  // is different from the value in cutVector
+  if (cut !=kNoG3Cuts) {
+    // get tolerance from TG4G3Defaults in GeV
+    G4double tolerance = TG4G3Defaults::CutTolerance()/GeV;
+    if (!(fCutVector) || (abs(value - (*fCutVector)[cut]) > tolerance)) {
+      SwitchIsCutVector(cut);      
+      return true;
+    }  
+    else return false;  
+  }                     
+  return false;
+}
+
+G4bool TG4G3PhysicsManager::CheckControlWithTheVector(G4String name, 
+                                 G4double value, TG4G3Control& control)
+{
+// Retrieves corresponding TG4G3Control from the name and 
+// in case the value is different from the value in controlVector
+// sets true the value of the fIsControlVector element 
+// corresponding to this control and returns true; 
+// returns false otherwise.
+// ---
+
+  // convert control name -> TG4G3Control
+  control = GetG3Control(name);
+
+  // set switch vector element only if the value
+  // is different from the value in controlVector
+  if (control !=kNoG3Controls) {
+    if (!(fControlVector) || (abs(value - (*fControlVector)[control]) > 0.01)) {
+      SwitchIsControlVector(control);      
+      return true;
+    }  
+    else return false;  
+  }                     
+  return false;
+}
+
+G4bool TG4G3PhysicsManager::CheckCutWithG3Defaults(G4String name, 
+                                 G4double value, TG4G3Cut& cut)
+{
+// Retrieves corresponding TG4G3Cut from the name and 
+// in case the value is different from the G3 default value
+// sets true the value of the SwitchCutVector element 
+// corresponding to this cut and returns true; 
+// returns false otherwise.
+// ---
+
+  // convert cut name -> TG4G3Cut
+  cut = GetG3Cut(name);
+
+  // set switch vector element only if the value
+  // is different from G3 default
+  if (cut !=kNoG3Cuts) {
+    if (!TG4G3Defaults::IsDefaultCut(cut, value)) {
+      SwitchIsCutVector(cut);      
+      return true;
+    }  
+    else return false;  
+  }                     
+  return false;
+}
+
+G4bool TG4G3PhysicsManager::CheckControlWithG3Defaults(G4String name, 
+                                 G4double value, TG4G3Control& control)
+{
+// Retrieves corresponding TG4G3Control from the name and 
+// in case the value is different from the G3 default value
+// sets true the value of the SwitchControlVector element 
+// corresponding to this control and returns true; 
+// returns false otherwise.
+// ---
+
+  // convert control name -> TG4G3Control
+  control = GetG3Control(name);
+
+  // set switch vector element only if the value
+  // is different from G3 default
+  if (control !=kNoG3Controls) {
+    if (!TG4G3Defaults::IsDefaultControl(control, value)) {
+      SwitchIsControlVector(control);      
+      return true;
+    }  
+    else return false;  
+  }                     
+  return false;
+}
+
+void TG4G3PhysicsManager::SetG3DefaultCuts() 
+{
+// Sets G3 default values of kinetic energy cuts.
+// ---
+
+  CheckLock();
+  if (!fCutVector) {
+    // create vector of kinetic energy cut values  
+    fCutVector = new TG4G3CutVector();
+  }  
+  fCutVector->SetG3Defaults();
+}
+
+void TG4G3PhysicsManager::SetG3DefaultControls()
+{
+// Sets G3 default values of control process controls.
+// ---
+
+  CheckLock();
+  if (!fControlVector) {
+    // create vector of control process control values
+    fControlVector = new TG4G3ControlVector;
+  }  
+  fControlVector->SetG3Defaults();
+}  
+
+G4bool TG4G3PhysicsManager::IsSpecialCuts() const
+{
+// Returns true if any special cut value is set.
+// ---
+
+  for (G4int i=0; i<kNofParticlesWSP; i++)
+  {  if ((*fIsCutVector)[i]) return true; }
+
+  return false;
+}
+
+G4bool TG4G3PhysicsManager::IsSpecialControls() const
+{
+// Returns true if any special control value is set.
+// ---
+
+  for (G4int i=0; i<kNofParticlesWSP; i++)
+  {  if ((*fIsControlVector)[i]) return true; }
+
+  return false;
+}
+
+TG4G3ParticleWSP TG4G3PhysicsManager::GetG3ParticleWSP(
+                                      G4ParticleDefinition* particle) const 
+{
+// Returns TG4G3ParticleWSP constant for the specified particle.
+// (See TG4G3ParticleWSP.h, too.)
+// ---
+
+  G4String name = particle->GetParticleName();     
+  G4String pType = particle->GetParticleType();
+    
+  if (name == "gamma") {
+    return kGamma;
+  }  
+  else if (name == "e-") {    
+    return kElectron;
+  }  
+  else if (name == "e+") {   
+    return kEplus;
+  }  
+  else if (( pType == "baryon" || pType == "meson" || pType == "nucleus" )) {
+    if (particle->GetPDGCharge() == 0) { 
+      return kNeutralHadron;
+    }
+    else  
+      return kChargedHadron;
+  }    
+  else if ( name == "mu-" || name == "mu+" ) {
+    return kMuon;
+  }  
+  else {
+    return kNofParticlesWSP;
+  }    
+}  
+
+void TG4G3PhysicsManager::GetG3ParticleWSPName(G4int particleWSP,
+                                               G4String& name) const 
+{
+// Fills the passed name with the name/type of particle specified
+// by TG4G3ParticleWSP constant.
+// (See TG4G3ParticleWSP.h, too.)
+// ---
+
+  switch (particleWSP) {
+    case kGamma:
+      name = "Gamma";
+      break;
+    case kElectron:
+      name = "Electron";
+      break;
+    case kEplus:
+      name = "Eplus";
+      break;
+    case kNeutralHadron:
+      name = "NeutralHadron";
+      break;
+    case kChargedHadron:
+      name = "ChargedHadron";
+      break;
+    case kMuon:
+      name = "Muon";
+      break;
+    case kAny:
+      name = "Any";
+      break;
+    case kNofParticlesWSP:
+      name = "NoSP";
+      break;
+    default:
+      G4String text = "TG4G3PhysicsManager::GetG3ParticleWSPName:\n";
+      text = text + "   Wrong particleWSP."; 
+      TG4Globals::Exception(text);
+      break;      
+  }
+}  
+
diff --git a/TGeant4/TG4G3PhysicsManager.h b/TGeant4/TG4G3PhysicsManager.h
new file mode 100644 (file)
index 0000000..318d28d
--- /dev/null
@@ -0,0 +1,127 @@
+// $Id$
+// Category: physics
+//
+// This class provides a Geant3 way control
+// to Geant4 physics. 
+// The G3 cuts and process controls are
+// stored in fCutVector and fControlVector vectors.
+// These special cuts/controls are activated 
+// by registering their physics constructors
+// (TG4PhysicsConstructorSpecialCuts, G4PhysicsConstructorSpecialControl)
+// to the modular physics list (TG4ModularPhysicsList)
+// by physics manager (TG4PhysicsManager).
+
+#ifndef TG4_G3_PHYSICS_MANAGER_H
+#define TG4_G3_PHYSICS_MANAGER_H
+
+#include "TG4Globals.h"
+#include "TG4NameMap.h"
+#include "TG4IntMap.h"
+#include "TG4G3Cut.h"
+#include "TG4G3Control.h"
+#include "TG4G3ParticleWSP.h"
+
+#include <Rtypes.h>
+#include "AliMCProcess.h"
+
+#include <globals.hh>
+
+class TG4G3CutVector;
+class TG4G3ControlVector;
+
+class G4ParticleDefinition;
+class G4VProcess;
+
+class TG4G3PhysicsManager
+{
+  public:
+    TG4G3PhysicsManager();
+    // --> protected
+    // TG4G3PhysicsManager(const TG4G3PhysicsManager& right);
+    virtual ~TG4G3PhysicsManager();
+        
+    // static access method
+    static TG4G3PhysicsManager* Instance();
+
+    // methods
+    void Lock();     
+    void CheckLock();     
+    G4VProcess*  FindProcess(G4String processName) const;
+    G4bool CheckCutWithTheVector(
+             G4String name, G4double value, TG4G3Cut& cut);   
+    G4bool CheckControlWithTheVector(
+             G4String name, G4double value, TG4G3Control& control); 
+    G4bool CheckCutWithG3Defaults(
+             G4String name, G4double value, TG4G3Cut& cut); 
+    G4bool CheckControlWithG3Defaults(
+             G4String name, G4double value, TG4G3Control& control); 
+
+    // set methods
+    void SetCut(TG4G3Cut cut, G4double cutValue);
+    void SetProcess(TG4G3Control control, G4int controlValue);
+    void SetG3DefaultCuts();                    
+    void SetG3DefaultControls();               
+    
+    // get methods
+    G4bool IsSpecialCuts() const;
+    G4bool IsSpecialControls() const;
+    TG4G3CutVector* GetCutVector() const;    
+    TG4G3ControlVector* GetControlVector() const;   
+    TG4boolVector* GetIsCutVector() const;
+    TG4boolVector* GetIsControlVector() const;
+    TG4G3Cut  GetG3Cut(G4String cutName);
+    TG4G3Control GetG3Control(G4String controlName);
+    TG4G3ParticleWSP GetG3ParticleWSP(G4ParticleDefinition* particle) const;
+    void GetG3ParticleWSPName(G4int particleWSP, G4String& name) const;
+    
+  protected:
+    TG4G3PhysicsManager(const TG4G3PhysicsManager& right);
+
+    // operators
+    TG4G3PhysicsManager& operator=(const TG4G3PhysicsManager& right);
+
+  private:
+    // methods
+    void FillG3CutNameVector();
+    void FillG3ControlNameVector();
+
+    // set methods
+    void SwitchIsCutVector(TG4G3Cut cut);
+    void SwitchIsControlVector(TG4G3Control control);
+
+    // static data members
+    static TG4G3PhysicsManager*  fgInstance; //this instance
+
+    // data members
+    TG4G3CutVector*      fCutVector;    //TG4CutVector  
+    TG4G3ControlVector*  fControlVector;//TG4ControlVector
+    TG4boolVector*    fIsCutVector;  //vector of booleans which cuts are set
+    TG4boolVector*    fIsControlVector; //vector of booleans which controls are set
+    TG4StringVector   fG3CutNameVector; //vector of cut parameters names     
+    TG4StringVector   fG3ControlNameVector; //vector of process control 
+                                        // parameters names   
+    G4bool            fLock;  //if true: cut/control vectors cannot be modified
+};
+
+// inline methods
+
+inline TG4G3PhysicsManager* TG4G3PhysicsManager::Instance() 
+{ return fgInstance; }
+
+inline void TG4G3PhysicsManager::Lock() 
+{ fLock = true; }
+
+inline TG4G3CutVector* TG4G3PhysicsManager::GetCutVector() const
+{ return fCutVector; }
+
+inline TG4G3ControlVector* TG4G3PhysicsManager::GetControlVector() const
+{ return fControlVector; }
+
+inline TG4boolVector* TG4G3PhysicsManager::GetIsCutVector() const
+{ return fIsCutVector; }
+
+inline TG4boolVector* TG4G3PhysicsManager::GetIsControlVector() const
+{ return fIsControlVector; }
+
+#endif //TG4_PHYSICS_MANAGER_H
+
diff --git a/TGeant4/TG4ParticlesManager.cxx b/TGeant4/TG4ParticlesManager.cxx
new file mode 100644 (file)
index 0000000..8041411
--- /dev/null
@@ -0,0 +1,262 @@
+// $Id$
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4ParticlesManager.h"
+#include "TG4G3Units.h"
+
+#include <G4ParticleDefinition.hh>
+#include <G4DynamicParticle.hh>
+#include <G4ParticleTable.hh>
+
+#include <TDatabasePDG.h>
+#include <TParticle.h>
+#include <TClonesArray.h>
+
+TG4ParticlesManager* TG4ParticlesManager::fgInstance = 0;
+
+TG4ParticlesManager::TG4ParticlesManager()
+{ 
+//
+  if (fgInstance) {
+    TG4Globals::Exception(
+      "TG4ParticlesManager: attempt to create two instances of singleton.");
+  }
+      
+  fgInstance = this;  
+}
+
+TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right) {
+// 
+  TG4Globals::Exception(
+    "Attempt to copy TG4ParticlesManager singleton.");
+}
+
+TG4ParticlesManager::~TG4ParticlesManager() {
+//
+}
+
+// operators
+
+TG4ParticlesManager& 
+TG4ParticlesManager::operator=(const TG4ParticlesManager& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "Attempt to assign TG4ParticlesManager singleton.");
+    
+  return *this;  
+}    
+          
+// private methods
+
+G4int TG4ParticlesManager::GetPDGEncoding(G4ParticleDefinition* particle)
+{
+// Returns the PDG code of particle;
+// if standard PDG code is not defined the TDatabasePDG
+// is used.
+// ---
+
+  // get PDG encoding from G4 particle definition
+  G4int pdgEncoding = particle->GetPDGEncoding();
+
+  if (pdgEncoding == 0) {
+    // get PDG encoding from TDatabasePDG
+  
+    // get particle name from the name map
+    G4String g4name = particle->GetParticleName();
+    G4String tname = fParticleNameMap.GetSecond(g4name);
+    if (tname == "Undefined") {
+      G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
+      text = text + "    Particle " + g4name;
+      text = text + " was not found in the name map.";
+      TG4Globals::Exception(text);
+    }  
+  
+    // get particle from TDatabasePDG
+    TDatabasePDG* pdgDB = TDatabasePDG::Instance();
+    TParticlePDG* particle = pdgDB->GetParticle(tname);
+    if (!particle) {
+      G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
+      text = text + "    Particle " + tname;
+      text = text + " was not found in TDatabasePDG.";
+      TG4Globals::Exception(text);
+    }  
+    
+    // get PDG encoding
+    pdgEncoding = particle->PdgCode();
+  }
+    
+  return pdgEncoding;  
+}  
+     
+G4int TG4ParticlesManager::GetPDGEncoding(G4String particleName)
+{
+// Returns the PDG code of particle sepcified by name.
+// ---
+
+  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
+
+  G4ParticleDefinition* particle = 0;  
+  particle = particleTable->FindParticle(particleName);
+  if (!particle) {    
+    G4String text = "TG4ParticlesManager::GetPDGEncoding:\n";
+    text = text + "   G4ParticleTable::FindParticle() " + particleName;
+    text = text + " failed.";
+    TG4Globals::Exception(text);
+  }    
+
+  return GetPDGEncoding(particle);
+}  
+  
+void  TG4ParticlesManager::MapParticles()
+{
+  // map G4 particle names to TDatabasePDG names
+  // (the map is built only for particles that have not
+  //  defined standard PDG encoding)
+  
+  fParticleNameMap.Add("deuteron","Deuteron");
+  fParticleNameMap.Add("triton",  "Triton");
+  fParticleNameMap.Add("alpha",   "Alpha");
+  fParticleNameMap.Add("He3",     "HE3");
+  fParticleNameMap.Add("opticalphoton","Cherenkov");
+  // fParticleNameMap.Add("???","FeedbackPhoton");
+  fParticleNameMap.Add("geantino", "Rootino");
+  
+  // map G4 particle names to TDatabasePDG encodings
+  fParticlePDGMap.Add("deuteron", GetPDGEncoding("deuteron"));
+  fParticlePDGMap.Add("triton", GetPDGEncoding("triton"));
+  fParticlePDGMap.Add("alpha", GetPDGEncoding("alpha"));
+  fParticlePDGMap.Add("He3", GetPDGEncoding("He3") );
+  fParticlePDGMap.Add("opticalphoton", GetPDGEncoding("opticalphoton"));
+  // fParticlePDGMap.Add("???","FeedbackPhoton");
+  fParticleNameMap.Add("geantino", GetPDGEncoding("geantino"));
+
+  // add verbose
+  G4cout << "Particle maps have been filled." << G4endl;
+  //fParticleNameMap.PrintAll();
+  //fParticlePDGMap.PrintAll();
+}    
+
+// public methods
+
+G4int TG4ParticlesManager::GetPDGEncodingFast(G4ParticleDefinition* particle)
+{
+// Returns the PDG code of particle;
+// if standard PDG code is not defined the preregistred
+// fParticlePDGMap is used.
+// ---
+
+  // get PDG encoding from G4 particle definition
+  G4int pdgEncoding = particle->GetPDGEncoding();
+
+  if (pdgEncoding == 0) {
+    // use FParticlePDGMap if standard PDG code is not defined
+    G4String name = particle->GetParticleName();
+    pdgEncoding = fParticlePDGMap.GetSecond(name);
+  }
+    
+  return pdgEncoding;  
+}  
+     
+     
+TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles, 
+                                          G4int index) const
+{
+// Retrives particle with given index from TClonesArray 
+// and checks type.
+// ---
+
+  TObject* particleTObject = particles->UncheckedAt(index);      
+  TParticle* particle
+    = dynamic_cast<TParticle*>(particleTObject);
+
+  // check particle type
+  if (!particle) 
+    TG4Globals::Exception(
+      "TG4ParticlesManager::GetParticle: Unknown particle type");
+  
+  return particle;  
+}     
+
+
+G4ParticleDefinition* TG4ParticlesManager::GetParticleDefinition(
+                               const TParticle* particle) const
+{
+// Returns G4 particle definition for given TParticle
+// TO DO: replace with using particles name map    
+// ---
+
+  // get particle definition from G4ParticleTable
+  G4int pdgEncoding = particle->GetPdgCode();
+  G4ParticleTable* particleTable 
+    = G4ParticleTable::GetParticleTable();                
+  G4ParticleDefinition* particleDefinition = 0;    
+  if (pdgEncoding != 0) 
+    particleDefinition = particleTable->FindParticle(pdgEncoding);
+  else {
+    G4String name = particle->GetName();
+    if (name == "Rootino")     
+      particleDefinition = particleTable->FindParticle("geantino");
+  }    
+  
+  if (particleDefinition==0) {
+    G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
+    G4String text = 
+      "TG4ParticlesManager::GetParticleDefinition:\n";
+    text = text + "   G4ParticleTable::FindParticle() failed.";
+    TG4Globals::Warning(text);
+  }    
+  
+  return particleDefinition;
+}
+
+G4DynamicParticle* TG4ParticlesManager::CreateDynamicParticle(
+                                   const TParticle* particle) const
+{ 
+// Creates G4DynamicParticle.
+// ---
+
+  // get particle properties
+  G4ParticleDefinition* particleDefinition 
+    = GetParticleDefinition(particle);    
+  if (!particleDefinition) return 0;  
+        
+  G4ThreeVector momentum = GetParticleMomentum(particle);
+
+  // create G4DynamicParticle
+  G4DynamicParticle* dynamicParticle 
+    = new G4DynamicParticle(particleDefinition, momentum);
+  
+  return dynamicParticle;
+}
+
+G4ThreeVector TG4ParticlesManager::GetParticlePosition(
+                                   const TParticle* particle) const 
+{
+// Returns particle vertex position.
+// ---
+
+  G4ThreeVector position 
+     = G4ThreeVector(particle->Vx()*TG4G3Units::Length(),
+                     particle->Vy()*TG4G3Units::Length(),
+                    particle->Vz()*TG4G3Units::Length());
+  return position;
+}                   
+                       
+                       
+G4ThreeVector TG4ParticlesManager::GetParticleMomentum(
+                                   const TParticle* particle) const
+{
+// Returns particle momentum.
+// ---
+  G4ThreeVector momentum 
+     = G4ThreeVector(particle->Px()*TG4G3Units::Energy(),
+                     particle->Py()*TG4G3Units::Energy(),
+                    particle->Pz()*TG4G3Units::Energy());
+  return momentum;
+}
+
diff --git a/TGeant4/TG4ParticlesManager.h b/TGeant4/TG4ParticlesManager.h
new file mode 100644 (file)
index 0000000..ed9fe59
--- /dev/null
@@ -0,0 +1,81 @@
+// $Id$
+// Category: physics
+//
+// This class provides mapping between TDatabasePDG
+// and Geant4 particles. 
+
+#ifndef TG4_PARTICLES_MANAGER_H
+#define TG4_PARTICLES_MANAGER_H
+
+#include "TG4Globals.h"
+#include "TG4NameMap.h"
+#include "TG4IntMap.h"
+
+#include <globals.hh>
+#include <G4ThreeVector.hh>
+
+#include <Rtypes.h>
+
+class G4DynamicParticle;
+class G4ParticleDefinition;
+
+class TParticle;
+class TClonesArray;
+
+class TG4ParticlesManager
+{
+  public:
+    TG4ParticlesManager();
+    // --> protected
+    // TG4ParticlesManager(const TG4ParticlesManager& right);
+    virtual ~TG4ParticlesManager();
+
+    // static access method
+    static TG4ParticlesManager* Instance();
+        
+    // methods
+    void MapParticles();
+
+    // get methods
+         // for G4 particle types   
+    G4int GetPDGEncodingFast(G4ParticleDefinition* particle);
+
+         // for Root particle types;
+    TParticle* GetParticle(const TClonesArray* particles, G4int index) const;
+    G4ParticleDefinition* GetParticleDefinition(
+                           const TParticle* particle) const;
+    G4DynamicParticle* CreateDynamicParticle(
+                           const TParticle* particle) const;
+    G4ThreeVector GetParticlePosition(
+                           const TParticle* particle) const;
+    G4ThreeVector GetParticleMomentum(
+                           const TParticle* particle) const;        
+    
+  protected:
+    TG4ParticlesManager(const TG4ParticlesManager& right);
+
+    // operators
+    TG4ParticlesManager& operator=(const TG4ParticlesManager& right);
+
+  private:
+    // methods
+    G4int GetPDGEncoding(G4ParticleDefinition* particle);
+    G4int GetPDGEncoding(G4String particleName);
+
+    // static data members
+    static TG4ParticlesManager*  fgInstance; //this instance
+    
+    // data members
+    TG4NameMap  fParticleNameMap;  //the mapping between G4 particle names
+                                   //and TDatabasePDG names 
+    TG4IntMap   fParticlePDGMap;   //the mapping between G4 particle names
+                                   //and TDatabasePDG codes
+};
+
+// inline methods
+
+inline TG4ParticlesManager* TG4ParticlesManager::Instance() 
+{ return fgInstance; }
+
+#endif //TG4_PARTICLES_MANAGER_H
+