]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
This commit was generated by cvs2svn to compensate for changes in r1461,
authorfca <fca@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 21 Jun 2000 17:15:02 +0000 (17:15 +0000)
committerfca <fca@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 21 Jun 2000 17:15:02 +0000 (17:15 +0000)
which included commits to RCS files with non-trunk default branches.

58 files changed:
TGeant4/Makefile [new file with mode: 0644]
TGeant4/TG3Attribute.h [new file with mode: 0644]
TGeant4/TG3Cut.h [new file with mode: 0644]
TGeant4/TG3Flag.h [new file with mode: 0644]
TGeant4/TG3ParticleWSP.h [new file with mode: 0644]
TGeant4/TG3Process.h [new file with mode: 0644]
TGeant4/TG3Units.cxx [new file with mode: 0644]
TGeant4/TG3Units.h [new file with mode: 0644]
TGeant4/TG4CutVector.cxx [new file with mode: 0644]
TGeant4/TG4CutVector.h [new file with mode: 0644]
TGeant4/TG4ElementTable.cxx [new file with mode: 0644]
TGeant4/TG4ElementTable.h [new file with mode: 0644]
TGeant4/TG4FlagVector.cxx [new file with mode: 0644]
TGeant4/TG4FlagVector.h [new file with mode: 0644]
TGeant4/TG4G3Defaults.cxx [new file with mode: 0644]
TGeant4/TG4G3Defaults.h [new file with mode: 0644]
TGeant4/TG4GeometryManager.cxx [new file with mode: 0644]
TGeant4/TG4GeometryManager.h [new file with mode: 0644]
TGeant4/TG4GeometryOutputManager.cxx [new file with mode: 0644]
TGeant4/TG4GeometryOutputManager.h [new file with mode: 0644]
TGeant4/TG4Globals.cxx [new file with mode: 0644]
TGeant4/TG4Globals.h [new file with mode: 0644]
TGeant4/TG4IntMap.cxx [new file with mode: 0644]
TGeant4/TG4IntMap.h [new file with mode: 0644]
TGeant4/TG4Limits.cxx [new file with mode: 0644]
TGeant4/TG4Limits.h [new file with mode: 0644]
TGeant4/TG4Messenger.cxx [new file with mode: 0644]
TGeant4/TG4Messenger.h [new file with mode: 0644]
TGeant4/TG4NameMap.cxx [new file with mode: 0644]
TGeant4/TG4NameMap.h [new file with mode: 0644]
TGeant4/TG4PhysicsList.cxx [new file with mode: 0644]
TGeant4/TG4PhysicsList.h [new file with mode: 0644]
TGeant4/TG4PhysicsListMessenger.cxx [new file with mode: 0644]
TGeant4/TG4PhysicsListMessenger.h [new file with mode: 0644]
TGeant4/TG4PhysicsManager.cxx [new file with mode: 0644]
TGeant4/TG4PhysicsManager.h [new file with mode: 0644]
TGeant4/TG4RunManager.cxx [new file with mode: 0644]
TGeant4/TG4RunManager.h [new file with mode: 0644]
TGeant4/TG4RunMessenger.cxx [new file with mode: 0644]
TGeant4/TG4RunMessenger.h [new file with mode: 0644]
TGeant4/TG4SpecialCuts.cxx [new file with mode: 0644]
TGeant4/TG4SpecialCuts.h [new file with mode: 0644]
TGeant4/TG4SpecialFlags.cxx [new file with mode: 0644]
TGeant4/TG4SpecialFlags.h [new file with mode: 0644]
TGeant4/TG4StepManager.cxx [new file with mode: 0644]
TGeant4/TG4StepManager.h [new file with mode: 0644]
TGeant4/TG4UICmdWithAComplexString.cxx [new file with mode: 0644]
TGeant4/TG4UICmdWithAComplexString.h [new file with mode: 0644]
TGeant4/TG4VRunConfiguration.cxx [new file with mode: 0644]
TGeant4/TG4VRunConfiguration.h [new file with mode: 0644]
TGeant4/TG4VSensitiveDetector.cxx [new file with mode: 0644]
TGeant4/TG4VSensitiveDetector.h [new file with mode: 0644]
TGeant4/TG4VisManager.cxx [new file with mode: 0644]
TGeant4/TG4VisManager.h [new file with mode: 0644]
TGeant4/TGeant4.cxx [new file with mode: 0644]
TGeant4/TGeant4.h [new file with mode: 0644]
TGeant4/TGeant4.icc [new file with mode: 0644]
TGeant4/TGeant4LinkDef.h [new file with mode: 0644]

diff --git a/TGeant4/Makefile b/TGeant4/Makefile
new file mode 100644 (file)
index 0000000..696d7d5
--- /dev/null
@@ -0,0 +1,77 @@
+# $Id$
+
+############################### TGeant4 Makefile ###############################
+
+# Include Geant4 specific definitions
+
+include $(G4INSTALL)/config/architecture.gmk
+
+# Include machine specific definitions
+
+include $(ALICE_ROOT)/conf/GeneralDef
+include $(ALICE_ROOT)/conf/MachineDef.$(ALICE_TARGET)
+
+# Include Alice Geant4 specific definitions
+
+include $(ALICE_ROOT)/conf/Geant4.gmk
+
+PACKAGE = TGeant4
+
+# C++ sources
+
+SRCS           = $(wildcard *.cxx)
+
+# C++ Headers
+
+HDRS          =  $(wildcard *.icc) $(wildcard *.h)
+
+# Library Root dictionary
+# only for selected classes
+
+DICT          = TGeant4Cint.cxx
+DICTH         = TGeant4.h TG4VRunConfiguration.h TGeant4LinkDef.h
+DICTO         = $(patsubst %.cxx,tgt_$(ALICE_TARGET)/%.o,$(DICT))
+
+# C++ Objects
+
+OBJS          = $(patsubst %.cxx,tgt_$(ALICE_TARGET)/%.o,$(SRCS)) $(DICTO)
+
+# C++ compilation flags
+
+CXXFLAGS      = $(CXXOPTS) -I$(ROOTSYS)/include -I. -I$(ALICE_ROOT)/include/
+##### TARGETS #####
+# Target
+
+SLIBRARY       = $(LIBDIR)/libTGeant4.$(SL)
+ALIBRARY       = $(LIBDIR)/lib/libTGeant4.a
+
+default:       $(SLIBRARY)
+
+$(LIBDIR)/libTGeant4.$(SL):            $(OBJS)
+
+$(DICT):                               $(DICTH)
+
+depend:                                        $(SRCS)
+
+#HEADERS =     $(filter-out %LinkDef.h,$(HDRS))
+
+TOCLEAN        =       $(OBJS) *Cint.cxx *Cint.h
+
+CHECKS  =       $(patsubst %.cxx,check/%.viol,$(SRCS))
+
+############################### General Macros ################################
+
+include $(ALICE_ROOT)/conf/GeneralMacros
+
+
+# Geant4 specific compiler flags
+
+CXXFLAGS += $(CPPFLAGS)
+
+
+############################ Dependencies #####################################
+
+-include tgt_$(ALICE_TARGET)/Make-depend 
diff --git a/TGeant4/TG3Attribute.h b/TGeant4/TG3Attribute.h
new file mode 100644 (file)
index 0000000..d663167
--- /dev/null
@@ -0,0 +1,36 @@
+// $Id$
+// Category: visualization
+
+#ifndef TG3_ATTRIBUTE_H
+#define TG3_ATTRIBUTE_H
+
+enum TG3Attribute
+{
+  kWORK,       // Set the volume active/inactive for tracking (not used!)
+  kSEEN,       // Set visibility : 0-invisible , 1-visible,
+               //                 -1-volume and daughters invisible,
+               //                 -2-volume visible but daughters invisible.
+  kLSTY,       // Set line style : 1-unbroken(default)
+               //                  2-dashed
+               //                  3-dotted
+               //      negative values do the same for daughters.
+  kLWID,       // Set line width : 
+  kCOLO,       // Set colour :    1-7 -G3 base colours(default=1)
+               //      1-black    n=7+m, m=1,9, grey with increasing luminosity,
+               //      2-red      n=17+m, m=1,25,
+               //      3-green    n=67+m, m=1,25,
+               //      4-blue     n=118+m, m=1,25,
+               //      5-yellow   n=42+m, m=1,25,
+               //      6-violet   n=142+m, m=1,25,
+               //      7-turquoise     n=92+m, m=1,25,
+               //      negative values do the same for daughters.
+  kFILL,       // Set fill style: 0- forces drawing style to wireframe(default)
+               //                 1- forces solid drawing style.
+               //      negative values do the same for daughters.
+  kSET,                // Set number associated to volume name (not used!)
+  kDET,                // Set detector number associated to volume name (not used!)
+  kDTYP,       // Set detector type (not used!)
+  kUNKNOWN
+};
+
+#endif //TG3_ATTRIBUTE_H
diff --git a/TGeant4/TG3Cut.h b/TGeant4/TG3Cut.h
new file mode 100644 (file)
index 0000000..a9219bf
--- /dev/null
@@ -0,0 +1,46 @@
+// $Id$
+// Category: physics
+
+#ifndef TG3_CUT_H
+#define TG3_CUT_H
+
+enum TG3Cut
+{
+  kCUTGAM, // gammas 
+               // G4 particles: "gamma"         
+               // G3 default value: 0.001 GeV
+  kCUTELE, // electrons        
+               // G4 particles: "e-"         
+               // ?? positrons
+               // G3 default value: 0.001 GeV
+  kCUTNEU, // neutral hadrons  
+               // G4 particles: of type "baryon", "meson", "nucleus"   
+              //               with zero charge     
+               // G3 default value: 0.01 GeV
+  kCUTHAD, // charged hadrons  
+               // G4 particles: of type "baryon", "meson", "nucleus"        
+              //               with non-zero charge     
+               // G3 default value: 0.01 GeV
+  kCUTMUO, // muons            
+               // G4 particles: "mu+", "mu-"         
+               // G3 default value: 0.01 GeV
+  kBCUTE,  // electron bremsstrahlung         
+               // G4 particles: "gamma"         
+               // G3 default value: CUTGAM
+  kBCUTM,  // muon and hadron bremsstrahlung  
+               // G4 particles: "gamma"         
+               // G3 default value: CUTGAM
+  kDCUTE,  // delta-rays by electrons 
+               // G4 particles: "e-"         
+               // G3 default value: 10**4
+  kDCUTM,  // delta-rays by muons        
+               // G4 particles: "e-"         
+               // G3 default value: 10**4
+  // the following cut is not yet implemented
+  kPPCUTM, // direct pair production by muons 
+               // G4 particles: ??         
+               // G3 default value: 0.01 GeV
+  kNoG3Cuts    
+};
+
+#endif //TG3_CUT_H
diff --git a/TGeant4/TG3Flag.h b/TGeant4/TG3Flag.h
new file mode 100644 (file)
index 0000000..c44dbf7
--- /dev/null
@@ -0,0 +1,101 @@
+// $Id$
+// Category: physics
+
+#ifndef TG3_FLAG_H
+#define TG3_FLAG_H
+
+enum TG3Flag
+{
+  kPAIR, // pair production       
+             // G3 default value: 1
+             // G4 processes: G4GammaConversion
+             //               (?? G4MuPairProduction/G4IMuPairProduction)
+  kCOMP, // Compton scattering    
+             // G3 default value: 1
+             // G4 processes: G4ComptonScattering 
+  kPHOT, // photo electric effect 
+             // G3 default value: 1
+             // G4 processes: G4PhotoElectricEffect
+  kPFIS, // photofission          
+             // G3 default value: 0
+             // G4 process: ??
+  kDRAY, // delta-ray              
+             // G3 default value: 2
+            // CHECK:
+             // G4 processes: G4eIonisation/G4IeIonization,
+            //               G4eIonisationPlus (??)
+             //               G4MuIonisation/G4IMuIonization, 
+            //               G4hIonisation/G4IhIonisation
+            // !! G4 treats delta rays in different way
+  kANNI, // annihilation          
+             // G3 default value: 1
+             // G4 processes: G4eplusAnnihilation/G4IeplusAnnihilation
+            // only for e+ 
+  kBREM, // bremsstrahlung        
+             // G3 default value: 1
+             // G4 processes: G4eBremsstrahlung/G4IeBremsstrahlung,
+            //               G4eBremsstrahlungPlus (??),  
+            //               G4MuBremsstrahlung/G4IMuBremsstrahlung
+            // only for e-/e+; mu+/mu- 
+  kHADR, // hadronic process      
+             // G3 default value: 1
+             // ??
+  kMUNU, // muon nuclear interaction 
+             // G3 default value: 0
+            // G4 processes: G4MuNuclearInteraction
+  kDCAY, // decay                 
+             // G3 default value: 1
+            // G4 process: G4Decay
+  kLOSS, // energy loss           
+             // G3 default value: 2
+             // G4 processes: G4eIonisation/G4IeIonization,
+            //               G4eIonisationPlus (??)
+             //               G4MuIonisation/G4IMuIonization, 
+            //               G4hIonisation/G4IhIonisation
+  kMULS, // multiple scattering   
+             // G3 default value: 1
+            // G4 process: G4MultipleScattering/G4IMultipleScattering
+            // all charged particles
+/* to be added  
+  kCKOV  // Cerenkov photon generation
+           // G3 default value: 0
+          // G4 process: G4Cerenkov
+          //             + light photon absorption processes (??which)
+          // all charged particles  
+  kRAYL, // Rayleigh scattering
+           // G3 default value: 0           
+          // G4 process: ?? G4OpRayleigh (check)
+  kLABS, // light photon absorption
+         // it is turned on when Cerenkov process is turned on
+        // --> may be removed from the enum
+           // G3 default value: 0           
+          // G4 process: ?? G4PhotoAbsorption, G4OpAbsorption (check)
+  kSYNC, // synchrotron radiation in magnetic field       
+           // G3 default value: 0           
+          // G4 process: ?? G4SynchrotronRadiation (check)
+*/
+  kNoG3Flags
+};
+
+enum TG3FlagValue {
+// in G3 the control flag values meaning can be different for
+// different processes, but for most of them is:
+//   0  process is not activated
+//   1  process is activated WITH generation of secondaries
+//   2  process is activated WITHOUT generation of secondaries
+// if process does not generate seconadaries => 1 same as 2
+//
+// Exceptions:
+//   MULS:  also 3
+//   LOSS:  also 3, 4 
+//   RAYL:  only 0,1
+//   HADR:  may be > 2
+//
+  kUnset      = -1, 
+  kInActivate = 0, 
+  kActivate   = 1,
+  kActivate2  = 2   
+}; 
+
+#endif //TG3_FLAG_H
+
diff --git a/TGeant4/TG3ParticleWSP.h b/TGeant4/TG3ParticleWSP.h
new file mode 100644 (file)
index 0000000..65f832b
--- /dev/null
@@ -0,0 +1,21 @@
+// $Id$
+// Category: physics
+
+#ifndef TG3_PARTICLE_WSP_H
+#define TG3_PARTICLE_WSP_H
+
+enum TG3ParticleWSP
+// particle with special process
+{
+  kGamma,           // kPAIR, kCOMP, kPHOT, kPHIS
+  kElectron,        // kDRAY, kBREM, kMULS, kLOSS
+  kEplus,           // kDRAY, kBREM, kMULS, kLOSS, kANNI
+  kNeutralHadron,   // kHADR 
+  kChargedHadron,   // kDRAY, kMULS, kLOSS, kHADR,
+  kMuon,            // kDRAY, kBREM, kMULS, kLOSS, kMUNU
+  kAny,             // kDCAY
+  kNofParticlesWSP
+};
+   
+#endif //TG3_PARTICLE_WSP_H
+
diff --git a/TGeant4/TG3Process.h b/TGeant4/TG3Process.h
new file mode 100644 (file)
index 0000000..ad1fb66
--- /dev/null
@@ -0,0 +1,60 @@
+// $Id$
+// Category: physics
+
+#ifndef TG3_PROCESS_H
+#define TG3_PROCESS_H
+
+//  NAMEC    List  of possible  mechanisms  for  step size  limitation  *
+//           filled in GINIT :                                          *
+//     DATA MEC/'NEXT','MULS','LOSS','FIEL','DCAY','PAIR','COMP','PHOT' *
+//    +        ,'BREM','DRAY','ANNI','HADR','ECOH','EVAP','FISS','ABSO' *
+//    +        ,'ANNH','CAPT','EINC','INHE','MUNU','TOFM','PFIS','SCUT' *
+//    +        ,'RAYL','PARA','PRED','LOOP','NULL','STOP'/              *
+//
+
+enum TG3Process
+{
+         // process description           //LMEC value
+                                          //in /GCTRAK/ common   
+  kNEXT,
+  kMULS, // multiple scattering   
+  kLOSS, // energy loss    
+  kFIEL,     
+  kDCAY, // decay                 
+  kPAIR, // pair production       
+  kCOMP, // Compton scattering    
+  kPHOT, // photo electric effect 
+  kBREM, // bremsstrahlung        
+  kDRAY, // delta-ray              
+  kANNI, // positron annihilation          
+  kHADR, // hadronic process      
+
+  kECOH,
+  kEVAP,
+  kFISS,
+  kABSO,
+  kANNH,
+  kCAPT,
+  kEINC,
+  kINHE,
+  kMUNU, // muon nuclear interaction 
+  kTOFM
+  kPFIS, // photofission          
+  kSCUT,
+  kRAYL, // Rayleigh scattering;          
+  kPARA,
+  kPRED,
+  kLOOP,
+  kNULL,
+  kSTOP,
+  
+  kLABS, // light photon absorption;      code: 101
+  kLREF, // photon boundary effects;      code: 102
+  kCKOV  // Cerenkov photon generation;   code: 105    
+  kREFL, // photon reflection;            code: 106
+  kREFR, // photon refraction;            code: 107
+
+  kNoG3Process
+};
+
+#endif //TG3_PROCESS_H
diff --git a/TGeant4/TG3Units.cxx b/TGeant4/TG3Units.cxx
new file mode 100644 (file)
index 0000000..f40200b
--- /dev/null
@@ -0,0 +1,26 @@
+// $Id$
+// Category: global
+//
+// See the class description in the header file.
+
+#include "TG3Units.h"
+
+// static const data members
+
+const G4double TG3Units::fgLength  = cm;
+const G4double TG3Units::fgTime    = s;
+const G4double TG3Units::fgCharge  = eplus;
+const G4double TG3Units::fgEnergy  = GeV;
+const G4double TG3Units::fgMass    = GeV;
+const G4double TG3Units::fgMassDensity  = g/cm3;
+const G4double TG3Units::fgAtomicWeight = g/mole;
+const G4double TG3Units::fgField   = tesla;
+
+TG3Units::TG3Units() {
+//
+}
+  
+TG3Units::~TG3Units() {
+//
+}
+
diff --git a/TGeant4/TG3Units.h b/TGeant4/TG3Units.h
new file mode 100644 (file)
index 0000000..1d15e65
--- /dev/null
@@ -0,0 +1,56 @@
+// $Id$
+// Category: global
+//
+// Class defines the G3 default units of physical quantities; 
+// all physical quantities returned by MC are expressed in these units.
+
+#ifndef TG3_UNITS_H
+#define TG3_UNITS_H
+
+#include <globals.hh>
+
+class TG3Units
+{
+  public:
+    // --> protected
+    // TG3Units();  
+    virtual ~TG3Units();
+
+    // static get methods
+    static G4double Length(); 
+    static G4double Time(); 
+    static G4double Charge(); 
+    static G4double Energy(); 
+    static G4double Mass(); 
+    static G4double MassDensity(); 
+    static G4double AtomicWeight();     
+    static G4double Field(); 
+      
+  protected:
+    TG3Units();      
+        // only static data members and methods
+
+  private:
+    // static data members  
+    static const G4double fgLength;       //G3 length unit 
+    static const G4double fgTime;         //G3 time unit 
+    static const G4double fgCharge;       //G3 charge unit  
+    static const G4double fgEnergy;       //G3 energy unit  
+    static const G4double fgMass;         //G3 mass unit
+    static const G4double fgMassDensity;  //G3 mass density unit 
+    static const G4double fgAtomicWeight; //G3 atomic weight unit  
+    static const G4double fgField;        //G3 magnetic field unit 
+};     
+
+// inline methods
+
+inline G4double TG3Units::Length() { return fgLength; }
+inline G4double TG3Units::Time()   { return fgTime; }
+inline G4double TG3Units::Charge() { return fgCharge; }
+inline G4double TG3Units::Energy() { return fgEnergy; }
+inline G4double TG3Units::Mass()   { return fgMass; }
+inline G4double TG3Units::MassDensity()  { return fgMassDensity; }
+inline G4double TG3Units::AtomicWeight() { return fgAtomicWeight; }
+inline G4double TG3Units::Field()  { return fgField; }
+
+#endif //TG3_UNITS_H
diff --git a/TGeant4/TG4CutVector.cxx b/TGeant4/TG4CutVector.cxx
new file mode 100644 (file)
index 0000000..13653ff
--- /dev/null
@@ -0,0 +1,205 @@
+// $Id$
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4CutVector.h"
+#include "TG4G3Defaults.h"
+
+#include <G4Track.hh>
+#include <G4ParticleDefinition.hh>
+#include <G4VProcess.hh>
+
+TG4CutVector::TG4CutVector()
+{
+  // initialize fCutVector 
+  fCutVector = new TG4doubleVector;
+  for (G4int i=0; i<kNoG3Cuts; i++) fCutVector->insert(0.); 
+}
+
+TG4CutVector::TG4CutVector(const TG4CutVector& right)
+{
+  // copy fCutVector 
+  fCutVector = new TG4doubleVector;
+  for (G4int i=0; i<kNoG3Cuts; i++) {
+    fCutVector->insert((*right.fCutVector)[i]);
+  }   
+}
+
+TG4CutVector::~TG4CutVector() {
+//
+  delete fCutVector;
+}
+
+// operators
+
+TG4CutVector& TG4CutVector::operator=(const TG4CutVector& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // initialize fCutVector 
+  fCutVector->clear();
+  for (G4int i=0; i<kNoG3Cuts; i++) {
+    fCutVector->insert((*right.fCutVector)[i]);
+  }
+  
+  return *this;   
+}  
+
+G4double TG4CutVector::operator[](G4int index) const 
+{
+//
+  if (index < kNoG3Cuts)
+    return (*fCutVector)[index];
+  else {
+    TG4Globals::Exception(
+      "TG4CutVector::operator[]: index out of the vector scope");
+    return 0.;  
+  }    
+}  
+
+// public methods
+
+void TG4CutVector::SetG3Cut(TG3Cut g3Cut, G4double cutValue)
+{
+// Sets the cutValue for the specified cut.
+// ---
+
+  if (g3Cut<kNoG3Cuts) {
+    (*fCutVector)[g3Cut] = cutValue;
+  }  
+  else {
+    TG4Globals::Exception(
+      "TG4CutVector::SetG3Cut: Inconsistent cut.");
+  }
+}
+
+void TG4CutVector::SetG3Defaults()
+{
+// Sets G3 default values for all cuts.
+// ---
+
+  for (G4int i=0; i<kNoG3Cuts; i++) {
+   (*fCutVector)[i] = TG4G3Defaults::CutValue(i);
+  } 
+}
+
+G4double TG4CutVector::GetMinEkine(const G4Track& track) const
+{
+// Returns the cut value for the particle associated with
+// specified track.
+// ---
+
+  G4ParticleDefinition* particle = track.GetDefinition(); 
+  G4String particleName = particle->GetParticleName();
+
+  if  (particleName == "gamma") {
+    return GetMinEkineForGamma(track);
+  }    
+  else if (particleName == "e-") {    
+    return GetMinEkineForElectron(track);
+  }  
+  else if ((particle->GetParticleType() == "baryon") ||
+           (particle->GetParticleType() == "meson") ||
+           (particle->GetParticleType() == "nucleus")) { 
+    if (particle->GetPDGCharge() == 0) 
+      return GetMinEkineForHadron(track);
+    else 
+      return GetMinEkineForNeutralHadron(track);
+  }    
+  else if ((particleName == "mu-") || (particleName == "mu+")) {
+    return GetMinEkineForMuon(track);
+  }  
+  else {
+    G4String text = "TG4CutVector::GetMinEkine: \n";
+    text = text + "    The kinetic energy cut for " + particleName;
+    text = text + " is not defined.";   
+    TG4Globals::Warning(text);
+    return 0.;
+  }    
+}
+
+G4double TG4CutVector::GetMinEkineForGamma(const G4Track& track) const
+{
+// Returns the cut value for gamma.
+// (Cut is not applied for "opticalphoton" 
+//  as it is treated in G4 as a particle different 
+//  from "gamma" in G4.)
+// ---
+
+  G4cout << "TG4CutVector::GetMinEkineForGamma start" << endl;
+  const G4VProcess* kpCreatorProcess = track.GetCreatorProcess();
+  G4String processName = "";
+  if (kpCreatorProcess) processName = kpCreatorProcess->GetProcessName();
+
+  if ((processName == "eBrem") || (processName == "IeBrem")) {
+    return (*fCutVector)[kBCUTE];
+  }     
+  else if ((processName == "MuBrems") || (processName == "IMuBrems") || 
+           (processName == "//hBrems")|| (processName == "//IhBrems")) {
+           // hadron Brehmstrahlung is not defined in G4
+    return (*fCutVector)[kBCUTM];
+  }
+  else {
+    return (*fCutVector)[kCUTGAM];
+  }
+}
+
+G4double TG4CutVector::GetMinEkineForElectron(const G4Track& track) const
+{
+// Returns the cut value for e-.
+// Should these cuts be applied to e+ too ??
+// ---
+
+  const G4VProcess* kpCreatorProcess = track.GetCreatorProcess();
+  G4String processName = "";
+  if (kpCreatorProcess) processName = kpCreatorProcess->GetProcessName();
+
+  if ((processName == "eIoni") || (processName == "IeIoni")) {
+     // !! Geant4 treats delta rays + continuous energy loss
+     // within one process
+    return (*fCutVector)[kDCUTE];
+  }
+  else if ((processName == "MuIoni") || (processName == "IMuIoni")) {
+     // !! Geant4 treats delta rays + continuous energy loss
+     // within one process
+    return (*fCutVector)[kDCUTM];
+  }
+  else {   
+    return (*fCutVector)[kCUTELE];
+  }
+}
+
+G4double TG4CutVector::GetMinEkineForHadron(const G4Track& track) const
+{
+// Returns the cut value for charged hadron.
+// ---
+
+  return (*fCutVector)[kCUTHAD];
+}
+
+G4double TG4CutVector::GetMinEkineForNeutralHadron(const G4Track& track) const
+{
+// Returns the cut value for neutral hadron.
+// ---
+
+  return (*fCutVector)[kCUTNEU];
+}
+
+G4double TG4CutVector::GetMinEkineForMuon(const G4Track& track) const
+{
+// Returns the cut value for neutral muon.
+// ---
+
+  return (*fCutVector)[kCUTMUO];
+}
+
+G4double TG4CutVector::GetMinEkineForOther(const G4Track& track) const
+{
+// Returns 0.
+// ---
+
+  return 0.;
+}
+
diff --git a/TGeant4/TG4CutVector.h b/TGeant4/TG4CutVector.h
new file mode 100644 (file)
index 0000000..7971b42
--- /dev/null
@@ -0,0 +1,47 @@
+// $Id$
+// Category: physics
+//
+// Vector of kinetic energy cut values with
+// convenient set/get methods
+
+#ifndef TG4_CUT_VECTOR_H
+#define TG4_CUT_VECTOR_H
+
+#include "TG4Globals.h"
+#include "TG3Cut.h"
+
+class G4Track;
+
+class TG4CutVector
+{
+  public:
+    TG4CutVector();
+    TG4CutVector(const TG4CutVector& right);
+    virtual ~TG4CutVector();
+    
+    // operators
+    TG4CutVector& operator=(const TG4CutVector& right);
+    G4double operator[](G4int index) const;
+        
+    // set methods
+    void SetG3Cut(TG3Cut g3Cut, G4double cutValue);
+    void SetG3Defaults();
+    
+    // get methods
+    G4double GetMinEkine(const G4Track& track) const;
+    G4double GetMinEkineForGamma(const G4Track& track) const;
+    G4double GetMinEkineForElectron(const G4Track& track) const;
+    G4double GetMinEkineForHadron(const G4Track& track) const;
+    G4double GetMinEkineForNeutralHadron(const G4Track& track) const;
+    G4double GetMinEkineForMuon(const G4Track& track) const;
+    G4double GetMinEkineForOther(const G4Track& track) const;
+
+  private:
+    // data members
+    TG4doubleVector*  fCutVector; //vector of kinetic energy cut values 
+};
+
+#endif //TG4_CUT_VECTOR_H
+
+
+
diff --git a/TGeant4/TG4ElementTable.cxx b/TGeant4/TG4ElementTable.cxx
new file mode 100644 (file)
index 0000000..2e019e5
--- /dev/null
@@ -0,0 +1,148 @@
+// $Id$
+// Category: geometry
+//
+// See the class description in the header file.
+
+#include "TG4ElementTable.h"
+#include "TG4Globals.h"
+
+#include <G4Element.hh>
+
+// static data members
+
+TG4ElementTable* TG4ElementTable::fgInstance = 0;
+
+// lifecycle
+
+TG4ElementTable::TG4ElementTable() {
+// 
+  Construct();
+}
+
+TG4ElementTable::TG4ElementTable(const TG4ElementTable& right) { 
+//
+  TG4Globals::Exception(
+    "Attempt to copy TG4ElementTable singleton.");
+}
+
+TG4ElementTable::~TG4ElementTable(){
+//
+}
+
+// operators
+
+TG4ElementTable& TG4ElementTable::operator=(const TG4ElementTable& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "Attempt to assign TG4ElementTable singleton.");
+    
+  return *this;  
+}    
+          
+// static methods
+  
+TG4ElementTable* TG4ElementTable::Instance() 
+{
+// singleton access method
+// ---
+
+  if (fgInstance == 0 ) {
+    fgInstance = new TG4ElementTable();
+  }
+  
+  return fgInstance;
+}
+
+// private methods
+
+void TG4ElementTable::Construct() 
+{ 
+// construct element table
+// ---
+
+  // new G4Element(name, symbol, z, a);
+  // check names
+  new G4Element("Hydrogen",  "H",   1.,  1.00797*g/mole);
+  new G4Element("Helium",    "He",  2.,  4.00260*g/mole);
+  new G4Element("Lithium",   "Li",  3.,  6.941*g/mole);
+  new G4Element("Berylium",  "Be",  4.,  9.01218*g/mole);
+  new G4Element("Bohr",      "B",   5.,  10.811*g/mole);
+  new G4Element("Carbon",    "C",   6.,  12.01115*g/mole);
+  new G4Element("Nitrogen",  "N",   7.,  14.0067*g/mole);
+  //in periodic table
+  //new G4Element("Oxygen",    "O",   8.,  15.9994*g/mole);
+  new G4Element("Oxygen",    "O",   8.,  16.00*g/mole);
+  new G4Element("Fluorine",  "F",   9.,  18.99840*g/mole);
+  new G4Element("Neon",      "Ne", 10.,  20.179*g/mole);
+  new G4Element("Sodium",    "Na", 11.,  22.98977*g/mole);
+  new G4Element("Magnesium", "Mg", 12.,  24.305 *g/mole);
+  new G4Element("Aluminium", "Al", 13.,  26.98154*g/mole);
+  new G4Element("Silicon",   "Si", 14.,  28.086*g/mole);
+  new G4Element("Phosphorus","P",  15.,  30.97376*g/mole);
+  new G4Element("Sulfur",    "S",  16.,  32.064*g/mole);
+  new G4Element("Chlorine",  "Cl", 17.,  35.453*g/mole);
+  new G4Element("Argon",     "Ar", 18,   39.948*g/mole);
+  new G4Element("Pottassium","K",  19.,  39.098*g/mole);
+  new G4Element("Calcium",   "Ca", 20.,  40.08*g/mole);
+  new G4Element("Scandium",  "Sc", 21.,  44.9559*g/mole);
+  new G4Element("Titanium",  "Ti", 22.,  47.90*g/mole);
+  new G4Element("Vanadium",  "V",  23.,  50.9414*g/mole);
+  new G4Element("Chromium",  "Cr", 24.,  51.996*g/mole);
+  new G4Element("Manganese", "Mn", 25.,  54.9380*g/mole);
+  new G4Element("Iron",      "Fe", 26.,  55.847*g/mole);
+  new G4Element("Cobalt",    "Co", 27.,  58.9332*g/mole);
+  new G4Element("Nickel",    "Ni", 28.,  58.70*g/mole);
+  new G4Element("Copper",    "Cu", 29.,  63.546*g/mole);
+  new G4Element("Zinc",      "Zn", 30.,  65.38*g/mole);
+  new G4Element("Gallium",   "Ga", 31.,  69.72*g/mole);
+  new G4Element("Germanium", "Ge", 32.,  72.59*g/mole);
+  new G4Element("Arsenic",   "As", 33.,  74.9216*g/mole);
+  new G4Element("Selenium",  "Se", 34.,  78.96*g/mole);
+  new G4Element("Bromine",   "Br", 35.,  79.904*g/mole);
+  new G4Element("Krypton",   "Kr", 36.,  83.80*g/mole);
+  new G4Element("Rubidium",  "Rb", 37.,  85.4678*g/mole);
+  new G4Element("Strontium", "Sr", 38.,  87.62*g/mole);
+  new G4Element("Yttrium",   "Y",  39.,  88.9059*g/mole);
+  new G4Element("Zirconium", "Zr", 40.,  91.22*g/mole);
+  new G4Element("Niobium",   "Nb", 41.,  92.9064*g/mole);
+  new G4Element("Molybdenum","Mo", 42.,  95.94*g/mole);
+  new G4Element("Technetium","Tc", 43.,  97.*g/mole);
+  new G4Element("Ruthenium", "Ru", 44.,  101.07*g/mole);
+  new G4Element("Rhodium",   "Rh", 45.,  102.9055*g/mole);
+  new G4Element("Palladium", "Pd", 46.,  106.4*g/mole);
+  new G4Element("Silver",    "Ag", 47.,  107.868*g/mole);
+/*  
+  new G4Element("Cadmium",   "", ,  *g/mole);
+  new G4Element("Indium",   "", ,  *g/mole);
+  new G4Element("Tin",   "", ,  *g/mole);
+  new G4Element("Antimony",   "", ,  *g/mole);
+  new G4Element("Tellurium",   "", ,  *g/mole);
+  new G4Element("Iodine",   "", ,  *g/mole);
+  new G4Element("Xenon",   "", ,  *g/mole);
+  new G4Element("Cesium",   "", ,  *g/mole);
+  new G4Element("Ba??",   "", ,  *g/mole);
+  new G4Element("Lanthanum",   "", ,  *g/mole);
+  new G4Element("Hafnium",   "", ,  *g/mole);
+  new G4Element("Tantalum",   "", ,  *g/mole);
+  new G4Element("Tungsten",   "", ,  *g/mole);
+  new G4Element("Rhenium",   "", ,  *g/mole);
+  new G4Element("Osmium",   "", ,  *g/mole);
+  new G4Element("Iridium",   "", ,  *g/mole);
+  new G4Element("Platinum",   "", ,  *g/mole);
+  new G4Element("Gold",   "", ,  *g/mole);
+  new G4Element("Mercury",   "", ,  *g/mole);
+  new G4Element("Thallium",   "", ,  *g/mole);
+  new G4Element("Lead",      "Pb", 82., 207.19*g/mole);
+  new G4Element("Bismuth",   "", ,  *g/mole);
+  new G4Element("Polonium",   "", ,  *g/mole);
+  new G4Element("Astatine",   "", ,  *g/mole);
+  new G4Element("Radon",   "", ,  *g/mole);
+  new G4Element("Franicum",   "", ,  *g/mole);
+  new G4Element("Radium",   "", ,  *g/mole);
+  new G4Element("Actinium",   "", ,  *g/mole);
+*/
+}
+
diff --git a/TGeant4/TG4ElementTable.h b/TGeant4/TG4ElementTable.h
new file mode 100644 (file)
index 0000000..b367ceb
--- /dev/null
@@ -0,0 +1,36 @@
+// $Id$
+// Category: geometry
+//
+// Singleton class that builds the default element table
+// Currently defined elements: up to Z=47
+// to be continued
+
+#ifndef TG4_ELEMENT_TABLE_H
+#define TG4_ELEMENT_TABLE_H
+
+class TG4ElementTable 
+{
+  public:
+    // --> protected
+    // TG4ElementTable();
+    // TG4ElementTable(const TG4ElementTable& right);
+    virtual ~TG4ElementTable();
+    
+    // static methods
+    static TG4ElementTable* Instance();
+
+  protected:
+    TG4ElementTable();    
+    TG4ElementTable(const TG4ElementTable& right); 
+    
+    // operators
+    TG4ElementTable& operator=(const TG4ElementTable& right);
+          
+  private:
+    void Construct();
+
+    // data members
+    static TG4ElementTable*  fgInstance; //this instance
+};   
+
+#endif //G4_ELEMENT_TABLE_H
diff --git a/TGeant4/TG4FlagVector.cxx b/TGeant4/TG4FlagVector.cxx
new file mode 100644 (file)
index 0000000..6254e2f
--- /dev/null
@@ -0,0 +1,138 @@
+// $Id$
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4FlagVector.h"
+#include "TG4CutVector.h"
+#include "TG4G3Defaults.h"
+#include "TG4Globals.h"
+
+#include <G4ParticleDefinition.hh>
+#include <G4VProcess.hh>
+
+#include <math.h>
+
+TG4FlagVector::TG4FlagVector()
+{
+  // initialize fFlagVector 
+  fFlagVector = new TG3FlagVector;
+  for (G4int i=0; i<kNoG3Flags; i++) fFlagVector->insert(kUnset); 
+}
+
+TG4FlagVector::TG4FlagVector(const TG4FlagVector& right)
+{
+  // copy fFlagVector 
+  fFlagVector = new TG3FlagVector;
+  for (G4int i=0; i<kNoG3Flags; i++) {
+    fFlagVector->insert((*right.fFlagVector)[i]);
+  }   
+}
+
+TG4FlagVector::~TG4FlagVector() {
+//
+  delete fFlagVector;
+}
+
+// operators
+
+TG4FlagVector& TG4FlagVector::operator=(const TG4FlagVector& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // initialize fFlagVector 
+  fFlagVector->clear();
+  for (G4int i=0; i<kNoG3Flags; i++) {
+    fFlagVector->insert((*right.fFlagVector)[i]);
+  }
+  
+  return *this;   
+}  
+
+G4double TG4FlagVector::operator[](G4int index) const
+{
+//
+  if (index < kNoG3Flags)
+    return (*fFlagVector)[index];
+  else {
+    TG4Globals::Exception(
+      "TG4FlagVector::operator[]: index out of the vector scope");
+    return 0.;  
+  }    
+}  
+
+// public methods
+
+void TG4FlagVector::SetG3Flag(TG3Flag g3Flag, G4double flagValue)
+{
+// Sets the flagValue for the specified flag.
+// ---
+
+  if (g3Flag<kNoG3Flags) {
+    // conversion G4double -> G3FlagValue
+    if (abs(flagValue - kUnset) < 0.01) {
+        (*fFlagVector)[g3Flag] = kUnset ;
+     }  
+     else if (abs(flagValue - kInActivate) < 0.01) {
+        (*fFlagVector)[g3Flag] = kInActivate; 
+     }
+     else if (abs(flagValue - kActivate) < 0.01) {
+        (*fFlagVector)[g3Flag] = kActivate; 
+     } 
+     else if (abs(flagValue - kActivate2) < 0.01) {
+        (*fFlagVector)[g3Flag] = kActivate2; 
+     }           
+     else {
+      G4String text = "TG4FlagVector::SetG3Flag:\n ";
+      text = text + "Inconsistent/Not-yet-implemented flag has been ignored.";
+      TG4Globals::Warning(text);
+     } 
+  }
+}
+
+void TG4FlagVector::SetG3Defaults()
+{
+// Sets G3 default values for all flags.
+// ---
+
+  for (G4int i=0; i<kNoG3Flags; i++) {
+   (*fFlagVector)[i] = TG4G3Defaults::FlagValue(i);
+  } 
+}
+
+G4int TG4FlagVector::GetFlag(G4VProcess* process) const 
+{
+// Returns the flag value for the particle associated with
+// the specified process.
+// ---
+
+  G4String name = process->GetProcessName();
+  if       (name == "conv")    return (*fFlagVector)(kPAIR);
+  else if  (name == "compt")   return (*fFlagVector)(kCOMP);
+  else if  (name == "phot")    return (*fFlagVector)(kPHOT);
+  // else if (name == "??")  return (*fFlagVector)(kPFIS);
+  else if ((name == "eIoni") || 
+           (name == "IeIoni") || 
+          (name == "eIoni+") ||
+           (name == "MuIoni") || 
+          (name == "IMuIonisation") ||
+          (name == "hIoni") || 
+          (name == "IhIoni"))    
+                               return (*fFlagVector)(kDRAY); 
+  else if  (name == "annihil") return (*fFlagVector)(kANNI);
+  else if ((name == "eBrem") || 
+           (name == "eBrem+") || 
+          (name == "IeBrems") || 
+           (name == "MuBrems") || 
+          (name == "IMuBremsstrahlung"))   
+                              return (*fFlagVector)(kBREM);
+  // else if (name == "??")  return (*fFlagVector)(kHADR);
+  else if (name == "MuNucl")  return (*fFlagVector)(kMUNU);
+  else if (name == "Decay")   return (*fFlagVector)(kDCAY);
+  // else if (name == "??")  return (*fFlagVector)(kLOSS);
+     // !!! not yet implemented 
+  else if ((name == "msc") || 
+           (name == "Imsc"))  return (*fFlagVector)(kMULS);
+  else return kUnset;
+}
diff --git a/TGeant4/TG4FlagVector.h b/TGeant4/TG4FlagVector.h
new file mode 100644 (file)
index 0000000..c30f748
--- /dev/null
@@ -0,0 +1,41 @@
+// $Id$
+// Category: physics
+//
+// Vector of control process flag values
+// with convenient set/get methods
+
+#ifndef TG4_FLAG_VECTOR_H
+#define TG4_FLAG_VECTOR_H
+
+#include "TG4Globals.h"
+#include "TG3Flag.h"
+
+class G4VProcess;
+
+class TG4FlagVector
+{
+  public:
+    TG4FlagVector();
+    TG4FlagVector(const TG4FlagVector& right);
+    virtual ~TG4FlagVector();
+    
+    // operators
+    TG4FlagVector& operator=(const TG4FlagVector& right);
+    G4double operator[](G4int index) const;
+
+    // set methods
+    void SetG3Flag(TG3Flag g3Flag, G4double flagValue);
+    void SetG3Defaults();
+    
+    // get methods
+    G4int GetFlag(G4VProcess* process) const; 
+
+  private:
+    // data members
+    TG3FlagVector*  fFlagVector; //vector of control process flag values
+};
+
+#endif //TG4_FLAG_VECTOR_H
+
+
+
diff --git a/TGeant4/TG4G3Defaults.cxx b/TGeant4/TG4G3Defaults.cxx
new file mode 100644 (file)
index 0000000..6eb43eb
--- /dev/null
@@ -0,0 +1,138 @@
+// $Id$
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4G3Defaults.h"
+#include "TG4Globals.h"
+
+#include <math.h>
+
+// static const data members
+
+// precision tolerance
+const G4double TG4G3Defaults::fgCutTolerance = 1. * keV;
+
+// kinetic energy cuts
+const G4double TG4G3Defaults::fgCUTGAM = 0.001 * GeV;
+const G4double TG4G3Defaults::fgCUTELE = 0.001 * GeV;
+const G4double TG4G3Defaults::fgCUTNEU = 0.01 * GeV;
+const G4double TG4G3Defaults::fgCUTHAD = 0.01 * GeV;
+const G4double TG4G3Defaults::fgCUTMUO = 0.01 * GeV;
+const G4double TG4G3Defaults::fgBCUTE  = fgCUTGAM;
+const G4double TG4G3Defaults::fgBCUTM  = fgCUTGAM;
+const G4double TG4G3Defaults::fgDCUTE  = 10. * TeV;
+const G4double TG4G3Defaults::fgDCUTM  = 10. * TeV;
+const G4double TG4G3Defaults::fgPPCUTM = 0.01 * GeV;
+
+// physics processes
+const TG3FlagValue TG4G3Defaults::fgPAIR = kActivate;   // 1
+const TG3FlagValue TG4G3Defaults::fgCOMP = kActivate;   // 1
+const TG3FlagValue TG4G3Defaults::fgPHOT = kActivate;   // 1
+const TG3FlagValue TG4G3Defaults::fgPFIS = kInActivate; // 0
+const TG3FlagValue TG4G3Defaults::fgDRAY = kActivate2;  // 2
+const TG3FlagValue TG4G3Defaults::fgANNI = kActivate;   // 1
+const TG3FlagValue TG4G3Defaults::fgBREM = kActivate;   // 1
+const TG3FlagValue TG4G3Defaults::fgHADR = kActivate;   // 1
+const TG3FlagValue TG4G3Defaults::fgMUNU = kInActivate; // 0
+const TG3FlagValue TG4G3Defaults::fgDCAY = kActivate;   // 1
+const TG3FlagValue TG4G3Defaults::fgLOSS = kActivate2;  // 2
+const TG3FlagValue TG4G3Defaults::fgMULS = kActivate;   // 1
+
+TG4G3Defaults::TG4G3Defaults() {
+//
+}
+  
+TG4G3Defaults::~TG4G3Defaults() {
+//
+}
+
+G4double TG4G3Defaults::CutValue(G4int g3Cut)
+{
+// Returns the G3 default value for the specified cut.
+// ---
+
+  switch (g3Cut) {
+    case kCUTGAM:  
+      return fgCUTGAM; break;
+    case kCUTELE:  
+      return fgCUTELE; break;
+    case kCUTNEU:  
+      return fgCUTNEU; break;
+    case kCUTHAD:  
+      return fgCUTHAD; break;
+    case kCUTMUO:  
+      return fgCUTMUO; break;
+    case kBCUTE:   
+      return fgBCUTE;  break;
+    case kBCUTM:   
+      return fgBCUTM;  break; 
+    case kDCUTE:   
+      return fgDCUTE;  break;
+    case kDCUTM:   
+      return fgDCUTM;  break;
+    case kPPCUTM:  
+      return fgPPCUTM; break;
+    default:
+      TG4Globals::Warning("TG4G3Defaults::CutValue: Inconsistent cut.");
+      return 0.;      
+  }
+}          
+
+TG3FlagValue TG4G3Defaults::FlagValue(G4int g3Flag)
+{
+// Returns the G3 default value for the specified flag.
+// ---
+
+  switch (g3Flag) {
+    case kPAIR:
+      return fgPAIR; break;
+    case kCOMP:
+      return fgCOMP; break;
+    case kPHOT:
+      return fgPHOT; break;
+    case kPFIS:
+      return fgPFIS; break;
+    case kDRAY:
+      return fgDRAY; break;
+    case kANNI:
+      return fgANNI; break;
+    case kBREM:
+      return fgBREM; break;
+    case kHADR:
+      return fgHADR; break;
+    case kMUNU:
+      return fgMUNU; break;
+    case kDCAY:
+      return fgDCAY; break;
+    case kLOSS:
+      return fgLOSS; break;
+    case kMULS:
+      return fgMULS; break;
+    default:
+      TG4Globals::Warning("TG4G3Defaults::FlagValue: Inconsistent flag.");
+      return kUnset;      
+  }
+}          
+
+G4bool TG4G3Defaults::IsDefaultCut(TG3Cut g3Cut, G4double value)
+{
+// Tests if the parameter value is equal to the G3 default value.
+// ---
+
+  if (abs(value*GeV - CutValue(g3Cut)) > fgCutTolerance) 
+    return false;
+  else  
+    return true;
+}
+
+G4bool TG4G3Defaults::IsDefaultFlag(TG3Flag g3Flag, G4double value)
+{
+// Tests if the parameter value is equal to the G3 default value.
+// ---
+
+  if (value == FlagValue(g3Flag)) 
+    return true;
+  else  
+    return false;
+}
diff --git a/TGeant4/TG4G3Defaults.h b/TGeant4/TG4G3Defaults.h
new file mode 100644 (file)
index 0000000..2b8ecbe
--- /dev/null
@@ -0,0 +1,71 @@
+// $Id$
+// Category: physics
+//
+// Class stores the default G3 values of the kinetic energy cuts
+// for particles and the control process flags parameters
+
+#ifndef TG4_G3DEFAULTS_H
+#define TG4_G3DEFAULTS_H
+
+#include "TG3Cut.h"
+#include "TG3Flag.h"
+
+#include <globals.hh>
+
+class TG4G3Defaults
+{
+  public:
+    // --> protected
+    // TG4G3Defaults();
+    virtual ~TG4G3Defaults();
+
+    // static methods
+    static G4bool IsDefaultCut(TG3Cut g3Cut, G4double value); 
+    static G4bool IsDefaultFlag(TG3Flag g3Flag, G4double value); 
+
+    // static get methods
+       // precision tolerance
+    static G4double CutTolerance();
+    static G4double CutValue(G4int g3Cut);   
+    static TG3FlagValue FlagValue(G4int g3Flag); 
+      
+  protected:
+    TG4G3Defaults();      
+      // only static data members and methods
+
+  private:
+    // static data members  
+      // precision tolerance
+    static const G4double fgCutTolerance; //tolerance for checking
+                                          //cut values with default
+       // kinetic energy cuts
+    static const G4double fgCUTGAM;   //CUTGAM default value 
+    static const G4double fgCUTELE;   //CUTELE default value
+    static const G4double fgCUTNEU;   //CUTNEU default value
+    static const G4double fgCUTHAD;   //CUTHAD default value
+    static const G4double fgCUTMUO;   //CUTMUO default value
+    static const G4double fgBCUTE;    //BCUTE default value
+    static const G4double fgBCUTM;    //BCUTM default value
+    static const G4double fgDCUTE;    //DCUTE default value
+    static const G4double fgDCUTM;    //DCUTM default value
+    static const G4double fgPPCUTM;   //PPCUTM default value
+       // physics processes flags
+    static const TG3FlagValue fgPAIR; //PAIR default value   
+    static const TG3FlagValue fgCOMP; //COMP default value   
+    static const TG3FlagValue fgPHOT; //PHOT default value   
+    static const TG3FlagValue fgPFIS; //PFIS default value   
+    static const TG3FlagValue fgDRAY; //DRAY default value  
+    static const TG3FlagValue fgANNI; //ANNI default value   
+    static const TG3FlagValue fgBREM; //BREM default value  
+    static const TG3FlagValue fgHADR; //HADR default value   
+    static const TG3FlagValue fgMUNU; //MUNU default value   
+    static const TG3FlagValue fgDCAY; //DCAY default value  
+    static const TG3FlagValue fgLOSS; //LOSS default value  
+    static const TG3FlagValue fgMULS; //MULS default value  
+};     
+
+// inline methods
+
+inline G4double TG4G3Defaults::CutTolerance() { return fgCutTolerance; }
+
+#endif //ALI_G3DEFAULTS_H
diff --git a/TGeant4/TG4GeometryManager.cxx b/TGeant4/TG4GeometryManager.cxx
new file mode 100644 (file)
index 0000000..f22b8ae
--- /dev/null
@@ -0,0 +1,1230 @@
+// $Id$
+// Category: geometry
+//
+// C++ interface to Geant3 basic routines 
+// for building Geant4 geometry
+//
+// by V. Berejnoi, 25.2.1999
+// materials, tracking media support 
+// added by I.Hrivnacova, 27.5.1999
+
+#include "TG4GeometryManager.h"
+#include "TG4GeometryOutputManager.h"
+#include "TG4PhysicsManager.h"
+#include "TG4VSensitiveDetector.h"
+#include "TG4Limits.h"
+#include "TG4Globals.h"
+#include "TG3Units.h"
+
+#include <G3toG4.hh> 
+#include <G3toG4BuildTree.hh>
+#include <G3VolTable.hh>
+#include <G3RotTable.hh>
+#include <G3EleTable.hh>
+#include <G3MatTable.hh>
+#include <G3MedTable.hh>
+#include <G3SensVolVector.hh>
+
+#include <G4SDManager.hh>
+#include <G4VSensitiveDetector.hh>
+#include <G4LogicalVolumeStore.hh>
+#include <G4PVPlacement.hh>
+#include <G4Material.hh>
+#include <G4MaterialPropertiesTable.hh>
+#include <G4Element.hh> 
+
+#include <math.h>
+#include <ctype.h>
+
+// extern global method from g3tog4
+void G3CLRead(G4String &, char *);
+
+TG4GeometryManager* TG4GeometryManager::fgInstance = 0;
+
+TG4GeometryManager::TG4GeometryManager() 
+  : fMediumCounter(0),
+    fMaterialCounter(0),
+    fMatrixCounter(0),
+    fUseG3TMLimits(false),
+    fWriteGeometry(true)
+{
+//
+  if (fgInstance) {
+    TG4Globals::Exception(
+      "TG4GeometryManager: attempt to create two instances of singleton.");
+  }
+
+  fOutputManager = new TG4GeometryOutputManager();
+
+  fgInstance = this;
+      
+  // instantiate the default element table
+  //TG4ElementTable::Instance();
+}
+
+TG4GeometryManager::TG4GeometryManager(const TG4GeometryManager& right) {
+// 
+  TG4Globals::Exception(
+    "Attempt to copy TG4GeometryManager singleton.");
+}
+
+
+TG4GeometryManager::~TG4GeometryManager() {
+//
+  delete fOutputManager;
+}
+
+//==================================================================== =========
+//
+// operators
+//
+//==================================================================== =========
+
+TG4GeometryManager& 
+TG4GeometryManager::operator=(const TG4GeometryManager& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "Attempt to assign TG4GeometryManager singleton.");
+    
+  return *this;  
+}    
+          
+
+//=============================================================================
+//
+// private methods
+//
+//=============================================================================
+
+
+G4double* TG4GeometryManager::CreateG4doubleArray(Float_t* array, 
+               G4int size) const
+{
+// Converts Float_t* array to G4double*,
+// !! The new array has to be deleted by user.
+// ---
+
+  G4double* doubleArray;
+  if (size>0) {
+    doubleArray = new G4double[size]; 
+    for (G4int i=0; i<size; i++) doubleArray[i] = array[i];
+  }
+  else {
+    doubleArray = 0; 
+  }  
+  return doubleArray;
+}
+
+
+G4String TG4GeometryManager::CutName(const char* name) const
+{
+// Removes spaces after the name if present.
+// ---
+
+  G4String cutName = name;
+  G4int i = cutName.length();
+  while (cutName(--i) == ' ') cutName = cutName(0,i);
+
+  return cutName;
+}  
+
+
+void TG4GeometryManager::GstparCut(G4int itmed, TG3Cut par, G4double parval)
+{
+// Sets special tracking medium parameter. 
+// It is applied to all logical volumes that use the specified 
+// tracking medium.
+// ---
+
+  // get medium from table
+  G3MedTableEntry* medium = G3Med.get(itmed);
+  if (!medium) {
+    G4String text = "TG4GeometryManager::GstparCut: \n";
+    text = text + "    Medium not found."; 
+    G4Exception(text);
+  }  
+
+  // get/create user limits
+  G4UserLimits* limits = medium->GetLimits();
+  TG4Limits* tg4Limits;
+  if (limits) {
+    tg4Limits = dynamic_cast<TG4Limits*> (limits);
+    if (!tg4Limits)
+      G4Exception("TG4GeometryManager::GstparCut: Wrong limits type.");
+  }    
+  else {     
+    tg4Limits = new TG4Limits();
+    medium->SetLimits(tg4Limits);
+    // add verbose 
+    G4cout << "TG4GeometryManager::GstparCut: new TG4Limits() for medium " 
+           << itmed << " has been created." << endl;  
+  }       
+  // set parameter
+  tg4Limits->SetG3Cut(par, parval*GeV);
+}
+
+
+void TG4GeometryManager::GstparFlag(G4int itmed, TG3Flag par, G4double parval)
+{
+// Sets special tracking medium parameter. 
+// It is applied to all logical volumes that use the specified 
+// tracking medium.
+// ---
+
+  // get medium from table
+  G3MedTableEntry* medium = G3Med.get(itmed);
+  if (!medium) {
+    G4String text = "TG4GeometryManager::GstparFlag: \n";
+    text = text + "    Medium not found."; 
+    G4Exception(text);
+  }  
+
+  // get/create user limits
+  G4UserLimits* limits = medium->GetLimits();
+  TG4Limits* tg4Limits;
+  if (limits) {
+    tg4Limits = dynamic_cast<TG4Limits*> (limits);
+    if (!tg4Limits)
+      G4Exception("TG4GeometryManager::GstparFlag: Wrong limits type.");
+  }    
+  else {     
+    tg4Limits = new TG4Limits();
+    medium->SetLimits(tg4Limits);
+    // add verbose 
+    G4cout << "TG4GeometryManager::GstparFlag: new TG4Limits() for medium " 
+           << itmed << " has been created." << endl;  
+  }
+  // set parameter
+  tg4Limits->SetG3Flag(par, parval);
+}
+
+void TG4GeometryManager::FillMediumIdVector()
+{
+// The second index for materials (having its origin in
+// G4 tracking media concept) is stored in a vector of G4int
+// parallel to G4MaterialTable.
+// ---
+
+  // initialize vector 
+  G4int nofMaterials = G4Material::GetNumberOfMaterials();
+  G4int i;
+  for (i=0; i<nofMaterials; i++) 
+    fMediumIdVector.push_back(0);
+  
+  // fill vector
+  for (i=0; i<fMediumCounter; i++) {
+    // material index (index in G4Material table)
+    G3MedTableEntry* mte = G3Med.get(i+1);
+    G4int materialIndex = mte->GetMaterial()->GetIndex();
+
+    // medium index (ID of G3MedTableEntry)
+    G4int mediumIndex = mte->GetID();
+    
+    // store medium index in the vector
+    fMediumIdVector[materialIndex] = mediumIndex;
+  }  
+
+  // add verbose
+  G4cout << "Total nof materials: " << nofMaterials << endl;
+  G4cout << "Total nof tracking medias: " << fMediumCounter << endl;  
+}    
+
+
+//=============================================================================
+//
+// public methods - AliMC implementation
+//
+//=============================================================================
+
+void TG4GeometryManager::Material(Int_t& kmat, const char* name, Float_t a, 
+          Float_t z, Float_t dens, Float_t radl, Float_t absl, Float_t* buf, 
+          Int_t nwbuf)
+{
+// Creates G4Material.
+// !! Parameters radl, absl, buf, nwbuf are ignored in G4gsmate
+// Comment: 
+// absl - this parameter is ignored by GEANT3, too
+// ---
+
+    kmat = ++fMaterialCounter;
+    G4double* bufin = CreateG4doubleArray(buf, nwbuf); 
+
+    // write token to the output file
+    if (fWriteGeometry) 
+      fOutputManager->WriteGsmate(kmat, name, a, z, dens, radl, nwbuf, bufin); 
+
+    G4gsmate(kmat, name, a, z, dens, radl, nwbuf, bufin); 
+
+    delete [] bufin;
+
+    if (nwbuf > 0) {  
+      G4String matName = name;
+      G4String text 
+        = "TG4GeometryManager: user defined parameters for material ";
+      text = text + matName;
+      text = text + " are ignored by Geant4."; 
+      TG4Globals::Warning(text);
+    }
+}
+  
+void TG4GeometryManager::Mixture(Int_t& kmat, const char *name, Float_t *a, 
+          Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat)
+{ 
+// Creates G4Material composed of more elements.
+// !! Parameters radl, absl, buf, nwbuf are ignored in G4gsmate
+// Comment: 
+// absl - this parameter is ignored by GEANT3, too
+// ---
+
+   Int_t npar = abs(nlmat);
+   G4double *ain = CreateG4doubleArray(a, npar); 
+   G4double *zin = CreateG4doubleArray(z, npar); 
+   G4double *wmatin = CreateG4doubleArray(wmat, npar); 
+
+   kmat = ++fMaterialCounter;
+
+   // write token to the output file
+   if (fWriteGeometry) 
+     fOutputManager->WriteGsmixt(kmat, name, ain, zin, dens, nlmat, wmatin);
+
+   G4gsmixt(kmat, name, ain, zin, dens, nlmat, wmatin);
+   
+   // !!! in Geant3:
+   // After a call with ratios by number (negative number of elements), 
+   // the ratio array is changed to the ratio by weight, so all successive 
+   // calls with the same array must specify the number of elements as 
+   // positive
+   
+   // wmatin may be modified
+   for (G4int i=0; i<npar; i++) wmat[i] = wmatin[i]; 
+
+   delete [] ain;
+   delete [] zin;
+   delete [] wmatin;
+} 
+
+void TG4GeometryManager::Medium(Int_t& kmed, const char *name, Int_t nmat, 
+          Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd, 
+          Float_t stemax, Float_t deemax, Float_t epsil, 
+          Float_t stmin, Float_t* ubuf, Int_t nbuf)
+{ 
+// Creates a temporary "medium" that is used for 
+// assigning corresponding parameters to G4 objects:
+// NTMED is stored as a second material index;
+// ISVOL is used for builing TG3SensVolVector;
+// STEMAX is passed in TG4Limits (if fUseG3TMLimits is set true);
+// !! The other parameters (IFIELD, FIELDM, TMAXFD, DEEMAX, EPSIL, STMIN)
+// are ignored by Geant4.
+// ---
+
+//  Geant3 desription:
+//  ==================
+//  NTMED  Tracking medium number
+//  NAME   Tracking medium name
+//  NMAT   Material number
+//  ISVOL  Sensitive volume flag
+//  IFIELD Magnetic field
+//  FIELDM Max. field value (Kilogauss)
+//  TMAXFD Max. angle due to field (deg/step)
+//  STEMAX Max. step allowed
+//  DEEMAX Max. fraction of energy lost in a step
+//  EPSIL  Tracking precision (cm)
+//  STMIN  Min. step due to continuos processes (cm)
+//
+//  IFIELD = 0 if no magnetic field; IFIELD = -1 if user decision in GUSWIM;
+//  IFIELD = 1 if tracking performed with GRKUTA; IFIELD = 2 if tracking
+//  performed with GHELIX; IFIELD = 3 if tracking performed with GHELX3.  
+// ---
+
+  kmed = ++fMediumCounter;
+
+  // write token to the output file
+  if (fWriteGeometry) 
+    fOutputManager->WriteGstmed(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, 
+        stemax, deemax, epsil, stmin, 0, 0);
+
+  G4gstmed(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, 
+       epsil, stmin, 0, fUseG3TMLimits);
+     // !! instead of the nbuf argument the bool fIsG3Default is passed
+
+  if (nbuf > 0) {  
+    G4String medName = name;
+    G4String text
+      = "TG4GeometryManager: user defined parameters for medium ";
+    text = text + medName;
+    text = text + " are ignored by Geant4.";  
+    TG4Globals::Warning(text);
+  }
+} 
+
+
+void TG4GeometryManager::Matrix(Int_t& krot, Float_t thetaX, Float_t phiX, 
+           Float_t thetaY, Float_t phiY, Float_t thetaZ, Float_t phiZ)
+{
+// Creates G4RotationMatrix.
+// ---
+
+  krot = ++fMatrixCounter;
+
+  // write token to the output file
+  if (fWriteGeometry) 
+    fOutputManager->WriteGsrotm(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
+
+  G4gsrotm(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
+}
+  
+
+G4Material* TG4GeometryManager::MixMaterials(G4String name, G4double density, 
+        TG4StringVector* matNames, TG4doubleVector* matWeights)
+{
+// Creates a mixture of selected materials
+// ---
+
+  // number of materials to be mixed  
+  G4int nofMaterials = matNames->entries();
+  if (nofMaterials != matWeights->entries()) {
+    G4String text = "TG4GeometryManager::MixMaterials: ";
+    text = text +  "different number of material names and weigths.";
+    TG4Globals::Exception(text);
+  }    
+  // add verbose
+  // G4cout << "Nof of materials to be mixed: " << nofMaterials << endl;
+
+  // fill vector of materials
+  TG4MaterialVector matVector;  
+  G4int im;
+  for (im=0; im< nofMaterials; im++) {
+    // material
+    G4Material* material = G4Material::GetMaterial((*matNames)[im]);
+    matVector.insert(material);
+  } 
+
+  // create the mixed material
+  G4Material* mixture = new G4Material(name, density, nofMaterials);
+  for (im=0; im< nofMaterials; im++) {
+    G4Material* material = matVector[im];
+    G4double fraction = (*matWeights)[im];
+    mixture->AddMaterial(material, fraction);
+  }
+
+  return mixture;
+}  
+
+void TG4GeometryManager::Ggclos() 
+{ 
+// Sets the top VTE in temporary G3 volume table.
+// Close geometry output file (if fWriteGeometry is set true).
+//
+//  Geant3 desription:
+//  ==================
+// close out the geometry
+// ---
+
+  if (fWriteGeometry) fOutputManager->WriteGgclos();
+
+  G4ggclos();    
+} 
+
+void TG4GeometryManager::Gfmate(Int_t imat, char *name, Float_t &a, 
+          Float_t &z, Float_t &dens, Float_t &radl, Float_t &absl,
+          Float_t* ubuf, Int_t& nbuf) 
+{ 
+//  Geant3 desription:
+//  ==================
+// Return parameters for material IMAT 
+// ---
+
+  G4Material* material = G3Mat.get(imat);
+  
+  if (material) {
+    // to do: change this correctly 
+    // !! unsafe conversion
+    const char* chName = material->GetName();
+    name = (char*)chName;
+    a = GetEffA(material);
+    z = GetEffZ(material);
+    
+    dens = material->GetDensity();
+    dens /= TG3Units::MassDensity();
+
+    radl = material->GetRadlen();
+    radl /= TG3Units::Length();
+
+    // the following parameters are not defined in Geant4
+    absl = 0.; 
+    ubuf = 0;
+    nbuf = 0;
+  }
+  else {
+    TG4Globals::Exception(
+     "TG4GeometryManager::Gfmate: material has not been found.");
+  }
+} 
+
+void  TG4GeometryManager::Gstpar(Int_t itmed, const char *param, 
+           Float_t parval) 
+{ 
+// Passes the tracking medium parameter to TG4Limits.
+// The tracking medium parameter is set only in case
+// its value is different from the "global" physics setup.
+// (If: CheckCut/FlagWithG3Defaults is used checking
+//  is performed with respect to G3 default values.)
+// When any cut/flag parameter is set in limits
+// the physics manager is locked and the physics setup
+// cannot be changed.
+// Applying this TG4Limits to particles and physical
+// processes is still in development.
+//
+//  Geant3 desription:
+//  ==================
+//  To change the value of cut  or mechanism "CHPAR"
+//  to a new value PARVAL  for tracking medium ITMED
+//  The  data   structure  JTMED   contains  the   standard  tracking
+//  parameters (CUTS and flags to control the physics processes)  which
+//  are used  by default  for all  tracking media.   It is  possible to
+//  redefine individually  with GSTPAR  any of  these parameters  for a
+//  given tracking medium. 
+//  ITMED     tracking medium number 
+//  CHPAR     is a character string (variable name) 
+//  PARVAL    must be given as a floating point.
+// ---
+
+  // write token to the output file
+  if (fWriteGeometry) 
+    fOutputManager->WriteGstpar(itmed, param, parval); 
+
+  // get physics setup
+  TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
+  //TG4CutVector* cutVector = physicsManager->GetCutVector();
+  //TG4FlagVector* flagVector = physicsManager->GetFlagVector();
+
+  G4String name = CutName(param); 
+  TG3Cut g3Cut;
+  if (physicsManager->CheckCutWithCutVector(name, parval, g3Cut)) {
+      GstparCut(itmed, g3Cut, parval);
+      physicsManager->Lock();
+  }  
+  else {
+    TG3Flag g3Flag;
+    if (physicsManager->CheckFlagWithFlagVector(name, parval, g3Flag)) {
+      GstparFlag(itmed, g3Flag, parval);
+      physicsManager->Lock();
+    } 
+    else if (g3Cut==kNoG3Cuts && g3Flag==kNoG3Flags) { 
+      G4String text = "TG4GeometryManager::Gstpar:";
+      text = text + name;
+      text = text + " parameter is not yet implemented.";
+      TG4Globals::Warning(text);
+    }  
+  } 
+} 
+void  TG4GeometryManager::Gsckov(Int_t itmed, Int_t npckov, Float_t* ppckov,
+                        Float_t* absco, Float_t* effic, Float_t* rindex)
+{
+//
+//  Geant3 desription:
+//  ==================
+//
+//    Stores the tables for UV photon tracking in medium ITMED 
+//    Please note that it is the user's responsability to 
+//    provide all the coefficients:
+//
+//
+//       ITMED       Tracking medium number
+//       NPCKOV      Number of bins of each table
+//       PPCKOV      Value of photon momentum (in GeV)
+//       ABSCO       Absorbtion coefficients 
+//                   dielectric: absorbtion length in cm
+//                   metals    : absorbtion fraction (0<=x<=1)
+//       EFFIC       Detection efficiency for UV photons 
+//       RINDEX      Refraction index (if=0 metal)
+// ---
+
+  G4double* ppckovDbl = CreateG4doubleArray(ppckov, npckov); 
+  G4double* abscoDbl  = CreateG4doubleArray(absco, npckov); 
+  G4double* efficDbl  = CreateG4doubleArray(effic, npckov); 
+  G4double* rindexDbl = CreateG4doubleArray(rindex, npckov); 
+  
+  // add units
+  G4int i;
+  for (i=0; i<npckov; i++) {
+    ppckovDbl[i] = ppckovDbl[i]*TG3Units::Energy();
+    abscoDbl[i]  = abscoDbl[i]*TG3Units::Length();
+  }  
+
+  // create material properties table
+  G4MaterialPropertiesTable* table = new G4MaterialPropertiesTable(); 
+  table->AddProperty("ABSLENGTH", ppckovDbl, abscoDbl, npckov);
+                    // used in G4OpAbsorption process
+  table->AddProperty("EFFICIENCY", ppckovDbl, efficDbl, npckov);
+                    // used in G4OpBoundary process
+  table->AddProperty("RINDEX", ppckovDbl, rindexDbl, npckov);
+                    // used in G4Cerenkov, G4OpRayleigh, G4OpBoundary
+
+  // get material of medium from table
+  G3MedTableEntry* medium = G3Med.get(itmed);
+  if (!medium) {
+    G4String text = "TG4GeometryManager::Gsckov: \n";
+    text = text + "    Medium not found."; 
+    G4Exception(text);
+  }  
+  G4Material* material = medium->GetMaterial();
+  
+  // set material properties table 
+  material->SetMaterialPropertiesTable(table);
+
+  G4cout << "The tables for UV photon tracking set for "
+         << material->GetName() << endl;
+  for (i=0; i<npckov; i++)
+    G4cout << ppckovDbl[i] << " " << rindexDbl[i] << endl;
+        
+  delete ppckovDbl;
+  delete abscoDbl;
+  delete efficDbl;
+  delete rindexDbl;     
+}                       
+
+void  TG4GeometryManager::Gsdvn(const char *name, const char *mother, 
+           Int_t ndiv, Int_t iaxis) 
+{ 
+//  Geant3 desription:
+//  ==================
+//  NAME   Volume name
+//  MOTHER Mother volume name
+//  NDIV   Number of divisions
+//  IAXIS  Axis value
+//
+//  X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
+//  It divides a previously defined volume.
+//  ---
+
+    // write token to the output file
+    if (fWriteGeometry) 
+      fOutputManager->WriteGsdvn(name, mother, ndiv, iaxis);
+
+    G4gsdvn(CutName(name), CutName(mother), ndiv, iaxis);
+
+    // register name in name map
+    fNameMap.AddName(CutName(name));
+} 
+void  TG4GeometryManager::Gsdvn2(const char *name, const char *mother, 
+           Int_t ndiv, Int_t iaxis, Float_t c0i, Int_t numed) 
+{ 
+//  Geant3 desription:
+//  ==================
+//  DIVIDES MOTHER INTO NDIV DIVISIONS CALLED NAME
+//  ALONG AXIS IAXIS STARTING AT COORDINATE VALUE C0.
+//  THE NEW VOLUME CREATED WILL BE MEDIUM NUMBER NUMED.
+// ---
+
+    // write token to the output file
+    if (fWriteGeometry) 
+      fOutputManager->WriteGsdvn2(name, mother, ndiv, iaxis, c0i, numed);
+
+    G4gsdvn2(CutName(name),CutName(mother), ndiv, iaxis, c0i, numed);
+
+    // register name in name map
+    fNameMap.AddName(CutName(name));
+} 
+void  TG4GeometryManager::Gsdvt(const char *name, const char *mother, 
+           Float_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
+{ 
+//  Geant3 desription:
+//  ==================
+//       Divides MOTHER into divisions called NAME along
+//       axis IAXIS in steps of STEP. If not exactly divisible 
+//       will make as many as possible and will centre them 
+//       with respect to the mother. Divisions will have medium 
+//       number NUMED. If NUMED is 0, NUMED of MOTHER is taken.
+//       NDVMX is the expected maximum number of divisions
+//          (If 0, no protection tests are performed) 
+// ---
+
+    // write token to the output file
+    if (fWriteGeometry) 
+      fOutputManager->WriteGsdvt(name, mother, step, iaxis, numed, ndvmx);
+
+    G4gsdvt(CutName(name), CutName(mother), step, iaxis, numed, ndvmx);
+
+    // register name in name map
+    fNameMap.AddName(CutName(name));
+} 
+void  TG4GeometryManager::Gsdvt2(const char *name, const char *mother, 
+           Float_t step, Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx)
+{ 
+//  Geant3 desription:
+//  ==================
+// Create a new volume by dividing an existing one
+//                                                                    
+//           Divides MOTHER into divisions called NAME along          
+//            axis IAXIS starting at coordinate value C0 with step    
+//            size STEP.                                              
+//           The new volume created will have medium number NUMED.    
+//           If NUMED is 0, NUMED of mother is taken.                 
+//           NDVMX is the expected maximum number of divisions        
+//             (If 0, no protection tests are performed)              
+// ---
+
+    // write token to the output file
+    if (fWriteGeometry) 
+      fOutputManager->WriteGsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
+
+    G4gsdvt2(CutName(name), CutName(mother), step, iaxis, c0, numed, ndvmx);
+
+    // register name in name map
+    fNameMap.AddName(CutName(name));
+} 
+void  TG4GeometryManager::Gsord(const char *name, Int_t iax) 
+{ 
+// No corresponding action in G4.
+//
+//  Geant3 desription:
+//  ==================
+//    Flags volume CHNAME whose contents will have to be ordered 
+//    along axis IAX, by setting the search flag to -IAX
+//           IAX = 1    X axis 
+//           IAX = 2    Y axis 
+//           IAX = 3    Z axis 
+//           IAX = 4    Rxy (static ordering only  -> GTMEDI)
+//           IAX = 14   Rxy (also dynamic ordering -> GTNEXT)
+//           IAX = 5    Rxyz (static ordering only -> GTMEDI)
+//           IAX = 15   Rxyz (also dynamic ordering -> GTNEXT)
+//           IAX = 6    PHI   (PHI=0 => X axis)
+//           IAX = 7    THETA (THETA=0 => Z axis)
+// ---
+
+  TG4Globals::Warning("TG4GeometryManager::Gsord: dummy method.");
+} 
+void  TG4GeometryManager::Gspos(const char *vname, Int_t num, 
+          const char *vmoth, Float_t x, Float_t y, Float_t z, Int_t irot, 
+          const char *vonly) 
+{ 
+//  Geant3 desription:
+//  ==================
+// Position a volume into an existing one
+//
+//  NAME   Volume name
+//  NUMBER Copy number of the volume
+//  MOTHER Mother volume name
+//  X      X coord. of the volume in mother ref. sys.
+//  Y      Y coord. of the volume in mother ref. sys.
+//  Z      Z coord. of the volume in mother ref. sys.
+//  IROT   Rotation matrix number w.r.t. mother ref. sys.
+//  ONLY   ONLY/MANY flag
+//
+//  It positions a previously defined volume in the mother.
+// ---  
+
+   // write token to the output file
+   if (fWriteGeometry) 
+     fOutputManager->WriteGspos(vname, num, vmoth, x, y, z, irot, vonly);
+
+   G4gspos(CutName(vname), num, CutName(vmoth), x, y, z, irot, vonly);
+
+   // register name in name map
+   fNameMap.AddName(CutName(vname));
+} 
+void  TG4GeometryManager::Gsposp(const char *name, Int_t nr, 
+           const char *mother, Float_t x, Float_t y, Float_t z, Int_t irot, 
+           const char *konly, Float_t *upar, Int_t np ) 
+{ 
+//  Geant3 desription:
+//  ==================
+//      Place a copy of generic volume NAME with user number
+//      NR inside MOTHER, with its parameters UPAR(1..NP)
+// ---
+
+   G4double* parin = CreateG4doubleArray(upar, np); 
+
+   // write token to the output file
+   if (fWriteGeometry) 
+     fOutputManager->WriteGsposp(name, nr, mother, x, y, z, irot, konly, parin, np);
+
+   G4gsposp(CutName(name), nr, CutName(mother), x, y, z, irot, konly, 
+             parin, np);
+
+   delete [] parin;
+
+   // register name in name map
+   fNameMap.AddName(CutName(name));
+} 
+Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape, 
+          Int_t nmed, Float_t *upar, Int_t npar) 
+{ 
+//  Geant3 desription:
+//  ==================
+//  NAME   Volume name
+//  SHAPE  Volume type
+//  NUMED  Tracking medium number
+//  NPAR   Number of shape parameters
+//  UPAR   Vector containing shape parameters
+//
+//  It creates a new volume in the JVOLUM data structure.
+// ---  
+
+  G4double* parin = CreateG4doubleArray(upar, npar); 
+
+  // write token to the output file
+  if (fWriteGeometry) 
+    fOutputManager->WriteGsvolu(name, shape, nmed, parin, npar);    
+
+  G4gsvolu(CutName(name), CutName(shape), nmed, parin, npar);
+
+  delete [] parin;
+  
+  // register name in name map
+  fNameMap.AddName(CutName(name));
+
+  return 0;
+} 
+
+
+void TG4GeometryManager::WriteEuclid(const char* filnam, const char* topvol,
+         Int_t number, Int_t nlevel)
+{
+//  Geant3 desription:
+//  ==================
+//
+//     ******************************************************************
+//     *                                                                *
+//     *  Write out the geometry of the detector in EUCLID file format  *
+//     *                                                                *
+//     *       filnam : will be with the extension .euc                 *
+//     *       topvol : volume name of the starting node                *
+//     *       number : copy number of topvol (relevant for gsposp)     *
+//     *       nlevel : number of  levels in the tree structure         *
+//     *                to be written out, starting from topvol         *
+//     *                                                                *
+//     *       Author : M. Maire                                        *
+//     *                                                                *
+//     ******************************************************************
+//
+//     File filnam.tme is written out with the definitions of tracking
+//     medias and materials.
+//     As to restore original numbers for materials and medias, program
+//     searches in the file euc_medi.dat and comparing main parameters of
+//     the mat. defined inside geant and the one in file recognizes them
+//     and is able to take number from file. If for any material or medium,
+//     this procedure fails, ordering starts from 1.
+//     Arrays IOTMED and IOMATE are used for this procedure
+// ---
+
+  TG4Globals::Warning(
+    "TG4GeometryManager::WriteEuclid(..) is not yet implemented.");
+}
+
+Int_t TG4GeometryManager::VolId(const Text_t* volName) const
+{ 
+// Returns the sensitive detector identifier.
+// !! Gives exception in case logical volume is not associated with 
+// a sensitive detector.
+// ---
+
+  G4String g4VolName = CutName(volName);
+  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+  
+  for (G4int i=0; i<pLVStore->entries(); i++) {
+    G4LogicalVolume* lv = pLVStore->at(i);
+    G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
+  
+    if ((sd) && (sd->GetName()==g4VolName)) {
+      TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
+      if (tsd)
+        return tsd->GetID();
+      else {
+        TG4Globals::Exception(
+          "TG4GeometryManager::VolId: Unknown sensitive detector type");
+        return 0;
+      }        
+    }   
+  }
+
+  G4String text = "TG4GeometryManager::VolId: Sensitive detector ";
+  text = text + g4VolName;
+  text = text + " is not defined.\n"; 
+  text = text + "    Set /alDet/setAllSensitive true in PreInit.";
+  TG4Globals::Exception(text);
+  return 0;
+}
+
+
+const char* TG4GeometryManager::VolName(Int_t id) const
+{
+// Returns the name of the sensitive detector with the given identifier.
+// !! Gives exception in case logical volume is not associated with 
+// a sensitive detector.
+// ---
+
+  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+  
+  for (G4int i=0; i<pLVStore->entries(); i++) {
+    G4LogicalVolume* lv = pLVStore->at(i);
+    G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
+    
+    if (sd) {
+      G4int sdID;
+      TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
+      if (tsd)
+        sdID = tsd->GetID();
+      else {
+        TG4Globals::Exception(
+          "TG4GeometryManager::VolId: Unknown sensitive detector type");
+        return 0;
+      }   
+      if (sdID == id) return sd->GetName();
+    }  
+  }
+
+  G4String text = "TG4GeometryManager::VolName:\n";
+  text = text + "    Sensitive detector with given id is not defined. \n";
+  text = text + "    Set /alDet/setAllSensitive true in PreInit.";
+  TG4Globals::Exception(text);
+  return "";                    
+}
+
+
+Int_t TG4GeometryManager::NofVolumes() const
+{
+// Returns the total number of sensitive detectors.
+// ---
+
+  return NofSensitiveDetectors();
+}
+
+void TG4GeometryManager::ReadG3Geometry(G4String filePath)
+{
+// Processes g3calls.dat file and fills G3 tables.
+// ---
+
+  // add verbose
+  G4cout << "Reading the call list file " << filePath << "..." << endl;
+  G3CLRead(filePath, NULL);
+  G4cout << "Call list file read completed. Build geometry" << endl;
+}
+
+//=============================================================================
+//
+// public methods - Geant4 only
+//
+//=============================================================================
+
+G4VPhysicalVolume* TG4GeometryManager::CreateG4Geometry()
+{
+// Creates G4 geometry objects according to the G3VolTable 
+// and returns the top physical volume in case it was created
+// (return zero otherwise).
+// ---
+
+  // set the first entry in the G3Vol table
+  Ggclos();
+  G3VolTableEntry* first = G3Vol.GetFirstVTE();
+  
+  // close g3calls.dat
+  if (fWriteGeometry) fOutputManager->CloseFile();  
+
+  // create G4 geometry
+  G3toG4BuildTree(first,0);  
+
+  // print G3 volume table statistics
+  G3Vol.VTEStat();
+
+  // print G4 geometry statistics
+  G4cout << "G4 Stat: instantiated " 
+         << NofG4LogicalVolumes()  << " logical volumes \n"
+        << "                      " 
+        << NofG4PhysicalVolumes() << " physical volumes" << endl;
+
+  // position the first entry 
+  // (in Geant3 the top volume cannot be positioned)
+  // 
+  G4VPhysicalVolume* top = 0;
+  if (first->GetLV()->GetNoDaughters() == 0) {
+    top = new G4PVPlacement(0, G4ThreeVector(), first->GetName(), 
+                            first->GetLV(), 0, false, 0);
+  }
+  return top;                
+}
+
+void TG4GeometryManager::UseG3TrackingMediaLimits()
+{
+// Sets fUseG3TMLimits option.
+// !! This method has to be called only before starting
+// creating geometry.
+// ---
+
+  if (fMediumCounter == 0) {
+    fUseG3TMLimits = true;
+  }
+  else {
+    G4String text = "TG4GeometryManager::UseG3TMLimits: \n";
+    text = text + "    It is too late to set G3 defaults. \n";
+    text = text + "    Some media has been already processed.";
+    TG4Globals::Exception(text);
+  }
+}
+
+void TG4GeometryManager::ClearG3Tables()
+{ 
+// Clears G3 volumes, materials, rotations(?) tables
+// and sensitive volumes vector.
+// The top volume is kept in the vol table.
+// ---
+
+  // clear volume table 
+  // but keep the top volume in the table 
+  G3VolTableEntry* top = G3Vol.GetFirstVTE();
+  G4String name = top->GetName();
+  G4String shape = top->GetShape(); 
+  G3VolTableEntry* keep 
+    = new G3VolTableEntry(name, shape, top->GetRpar(), top->GetNpar(), 
+                           top->GetNmed(), top->GetSolid(), false);
+  keep->SetLV(top->GetLV());
+  G3Vol.Clear();  
+  G3Vol.PutVTE(keep);
+  
+  // clear other tables
+  G3Mat.Clear();
+  //G3Rot.Clear();
+  G3SensVol.clear(); 
+}
+
+void TG4GeometryManager::ClearG3TablesFinal()
+{
+// Clears G3 medias and volumes tables
+// (the top volume is removed from the vol table)
+// ---
+
+  // fill medium id vector
+  FillMediumIdVector();
+
+  G3Med.Clear();
+  G3Vol.Clear();  
+
+  // reset medium counter
+  //fMaterialCounter = 0;
+  fMediumCounter = 0;  
+}
+
+void TG4GeometryManager::OpenOutFile(G4String filePath)
+{ 
+// Opens output file.
+// ---
+
+  fOutputManager->OpenFile(filePath);
+}
+
+void TG4GeometryManager::PrintNameMap()
+{
+// Prints the map of volumes names to second names.
+// ---
+
+  fNameMap.PrintAll();
+}
+
+void TG4GeometryManager::SetWriteGeometry(G4bool writeGeometry)
+{ 
+// Controls geometry output.
+// ---
+
+  fWriteGeometry = writeGeometry; 
+}
+
+void TG4GeometryManager::SetMapSecond(const G4String& name)
+{
+// Sets the second name for the map of volumes names.
+// ---
+
+  fNameMap.SetSecond(name);
+}
+
+
+Int_t TG4GeometryManager::NofG3Volumes() const
+{
+// Returns the total number of logical volumes corresponding
+// to G3 volumes. (
+// The logical volume that were created by Gsposp method 
+// with a generic name (name_copyNo) are NOT included.
+// ---
+
+  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+
+  G4int counter = 0;  
+  for (G4int i=0; i<pLVStore->entries(); i++) {
+    G4LogicalVolume* lv = (*pLVStore)[i];
+    if (IsG3Volume(lv->GetName())) counter++;
+  }
+  
+  return counter;  
+}
+
+
+Int_t TG4GeometryManager::NofG4LogicalVolumes() const
+{
+// Returns the total number of logical volumes in the geometry.
+// ---
+
+  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+  return pLVStore->entries();
+}
+
+
+Int_t TG4GeometryManager::NofG4PhysicalVolumes() const
+{
+// Returns the total number of physical volumes in the geometry.
+// ---
+
+  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+
+  G4int counter = 0;
+  for (G4int i=0; i<pLVStore->entries(); i++) {
+    counter += ((*pLVStore)[i])->GetNoDaughters();
+  }
+  
+  return counter;  
+}
+
+
+Int_t TG4GeometryManager::NofSensitiveDetectors() const
+{
+// Returns the total number of sensitive detectors.
+// ---
+
+  return TG4VSensitiveDetector::GetTotalNofSensitiveDetectors();
+}
+
+G4bool TG4GeometryManager::IsG3Volume(G4String lvName) const
+{
+// Returns true if the logical volume of given volumeName
+// was not created by Gsposp method with a generic name 
+// (name_copyNo).
+// ---
+
+  if (lvName.contains(gSeparator))
+    return false;  
+  else
+    return true;   
+}
+
+void TG4GeometryManager::G4ToG3VolumeName(G4String& name) const
+{
+// Cuts _copyNo extension added to logical volume name in case 
+// the logical volume was created by Gsposp method.
+// ---
+
+  if (name.contains(gSeparator)) 
+  name = name(0,name.first(gSeparator));
+}
+
+const G4String& TG4GeometryManager::GetMapSecond(const G4String& name)
+{ 
+// Returns the second string associated with the name in
+// the name map.
+// ---
+
+  return fNameMap.GetSecond(name); 
+}
+
+G4int TG4GeometryManager::GetMediumId(G4Material* material) const
+{
+// Returns the second index for materials (having its origin in
+// G4 tracking media concept)
+// ---
+
+  return fMediumIdVector[material->GetIndex()];
+}  
+
+
+G4double TG4GeometryManager::GetEffA(G4Material* material) const
+{
+// Returns A or effective A=sum(pi*Ai) (if compound/mixture)
+// of given material.
+// ---
+
+  G4double a = 0.;
+  G4int nofElements = material->GetNumberOfElements();
+  if (nofElements > 1) {
+    G4String text = "Effective A for material mixture (";
+    text = text + material->GetName();
+    text = text + ") is used.";
+    //TG4Globals::Warning(text);
+
+    for (G4int i=0; i<nofElements; i++) {
+      G4double aOfElement = material->GetElement(i)->GetA();
+      G4double massFraction = material->GetFractionVector()[i];      
+      a += aOfElement*massFraction /(TG3Units::AtomicWeight());
+    }
+  }
+  else { 
+    a = material->GetA();
+    a /= TG3Units::AtomicWeight();
+  }
+  return a;
+}
+
+
+G4double TG4GeometryManager::GetEffZ(G4Material* material) const
+{
+// Returns Z or effective Z=sum(pi*Zi) (if compound/mixture)
+// of given material.
+// ---
+
+  G4double z = 0.;
+  G4int nofElements = material->GetNumberOfElements();
+  if (nofElements > 1) {
+    G4String text = "Effective Z for material mixture (";
+    text = text + material->GetName();
+    text = text + ") is used.";
+    //TG4Globals::Warning(text);
+
+    for (G4int i=0; i<nofElements; i++) {
+      G4double zOfElement = material->GetElement(i)->GetZ();
+      G4double massFraction = material->GetFractionVector()[i];
+      z += zOfElement*massFraction;
+    }
+  }
+  else { 
+    z = material->GetZ(); 
+  }  
+  return z;
+}
diff --git a/TGeant4/TG4GeometryManager.h b/TGeant4/TG4GeometryManager.h
new file mode 100644 (file)
index 0000000..3d44811
--- /dev/null
@@ -0,0 +1,179 @@
+// $Id$
+// Category: geometry
+//
+// Geant4 implementation of the MonteCarlo interface methods                    
+// for building Geant4 geometry and access to it
+
+#ifndef TG4_GEOMETRY_MANAGER_H
+#define TG4_GEOMETRY_MANAGER_H
+
+#include "TG4NameMap.h"
+#include "TG4Globals.h"
+#include "TG3Cut.h"
+#include "TG3Flag.h"
+
+#include <globals.hh>
+#include <G3SensVolVector.hh>
+
+#include <Rtypes.h>
+
+#include "g4std/fstream"
+#include "g4std/vector"
+
+class TG4CutVector;
+class TG4FlagVector;
+class TG4GeometryOutputManager;
+
+class G4Material;
+class G4VPhysicalVolume;
+
+class TG4GeometryManager
+{
+  public:
+    TG4GeometryManager();
+    // --> protected
+    // TG4GeometryManager(const TG4GeometryManager& right);
+    virtual ~TG4GeometryManager();
+
+    // static access method
+    static TG4GeometryManager* Instance();
+
+    //
+    // methods (from the base class)
+    
+    // detector composition
+    void  Material(Int_t& kmat, const char* name, Float_t a, 
+                     Float_t z, Float_t dens, Float_t radl, Float_t absl,
+                     Float_t* buf, Int_t nwbuf);
+    void  Mixture(Int_t& kmat, const char *name, Float_t *a, 
+                     Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat);
+    void  Medium(Int_t& kmed, const char *name, Int_t nmat, 
+                     Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd, 
+                     Float_t stemax, Float_t deemax, Float_t epsil, 
+                    Float_t stmin, Float_t* ubuf, Int_t nbuf);
+    void  Matrix(Int_t& krot, Float_t thetaX, Float_t phiX, 
+                     Float_t thetaY, Float_t phiY, Float_t thetaZ, 
+                    Float_t phiZ);
+
+    // NEW - for G4 only
+    G4Material* MixMaterials(G4String name, G4double density,
+                     TG4StringVector* matNames, TG4doubleVector* matWeights);
+
+    // functions from GBASE 
+    void  Ggclos(); 
+
+    // functions from GCONS 
+    void  Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,  
+                        Float_t &dens, Float_t &radl, Float_t &absl,
+                        Float_t* ubuf, Int_t& nbuf); 
+    void  Gstpar(Int_t itmed, const char *param, Float_t parval); 
+    void  Gsckov(Int_t itmed, Int_t npckov, Float_t *ppckov,
+                        Float_t *absco, Float_t *effic, Float_t *rindex); 
+
+    // functions from GGEOM 
+    Int_t Gsvolu(const char *name, const char *shape, Int_t nmed,  
+                         Float_t *upar, Int_t np); 
+    void  Gsdvn(const char *name, const char *mother, Int_t ndiv, 
+                        Int_t iaxis);
+    void  Gsdvn2(const char *name, const char *mother, Int_t ndiv, 
+                         Int_t iaxis, Float_t c0i, Int_t numed); 
+    void  Gsdvt(const char *name, const char *mother, Float_t step,
+                         Int_t iaxis, Int_t numed, Int_t ndvmx); 
+    void  Gsdvt2(const char *name, const char *mother, Float_t step, 
+                         Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx); 
+
+    void  Gsord(const char *name, Int_t iax); 
+    void  Gspos(const char *name, Int_t nr, const char *mother,  
+                        Float_t x, Float_t y, Float_t z, Int_t irot, 
+                        const char *konly); 
+    void  Gsposp(const char *name, Int_t nr, const char *mother,  
+                         Float_t x, Float_t y, Float_t z, Int_t irot,
+                         const char *konly, Float_t *upar, Int_t np); 
+        
+    // Euclid                 
+    void WriteEuclid(const char*, const char*, Int_t, Int_t); //new
+                              
+    // get methods
+    Int_t VolId(const Text_t* volName) const;                
+    const char* VolName(Int_t id) const; //new
+    Int_t NofVolumes() const; 
+    
+    // end of methods
+    // 
+
+    //
+    // methods for Geant4 only 
+    G4VPhysicalVolume* CreateG4Geometry();
+    void ReadG3Geometry(G4String filePath);
+    void UseG3TrackingMediaLimits();
+    void ClearG3Tables();       
+    void ClearG3TablesFinal();
+    void OpenOutFile(G4String filePath);
+    void PrintNameMap();
+    
+    // set methods
+    void SetWriteGeometry(G4bool writeGeometry);
+    void SetMapSecond(const G4String& name);
+
+    // get methods
+          // volumes
+    Int_t NofG3Volumes() const; 
+    Int_t NofG4LogicalVolumes() const; 
+    Int_t NofG4PhysicalVolumes() const; 
+    Int_t NofSensitiveDetectors() const; 
+    G4bool IsG3Volume(G4String lvName) const;
+    void G4ToG3VolumeName(G4String& name) const;
+    const G4String& GetMapSecond(const G4String& name);
+
+          // sensitive volumes
+    G3SensVolVector GetG3SensVolVector() const;
+
+          // materials
+    G4int GetMediumId(G4Material* material) const;    
+    G4double GetEffA(G4Material* material) const;
+    G4double GetEffZ(G4Material* material) const;
+
+    // end of methods for Geant4 only 
+    //
+    
+  protected:
+    TG4GeometryManager(const TG4GeometryManager& right);
+
+    // operators
+    TG4GeometryManager& operator=(const TG4GeometryManager& right);
+
+  private:
+    // methods
+    G4double* CreateG4doubleArray(Float_t* array, G4int size) const;
+    G4String  CutName(const char* name) const;
+    void GstparCut(G4int itmed, TG3Cut par, G4double parval);
+    void GstparFlag(G4int itmed, TG3Flag par, G4double parval);
+    void FillMediumIdVector();
+        
+    // static data members
+    static TG4GeometryManager*  fgInstance;     //this instance
+
+    // data members
+    TG4GeometryOutputManager*   fOutputManager; //output manager 
+    TG4NameMap       fNameMap;         //map of volumes names to modules names
+    vector<G4int>    fMediumIdVector;  //vector of second indexes for materials
+    G4int            fMediumCounter;   //global medium counter
+    G4int            fMaterialCounter; //global material counter
+    G4int            fMatrixCounter;   //global matrix counter
+    G4bool           fUseG3TMLimits;   //if true: G3 limits are passed to G4 
+                                       //(in development)
+    G4bool           fWriteGeometry;   //if true: geometry parameters are written
+                                       //in a file (ASCII)  
+};
+
+// inline methods
+inline TG4GeometryManager* TG4GeometryManager::Instance()
+{ return fgInstance; }
+
+inline G3SensVolVector TG4GeometryManager::GetG3SensVolVector() const
+{ return G3SensVol; }
+
+#endif //TG4_GEOMETRY_MANAGER_H
+
diff --git a/TGeant4/TG4GeometryOutputManager.cxx b/TGeant4/TG4GeometryOutputManager.cxx
new file mode 100644 (file)
index 0000000..dd3a348
--- /dev/null
@@ -0,0 +1,430 @@
+// $Id$
+// Category: geometry
+//
+// See the class description in the header file.
+
+#include "TG4GeometryOutputManager.h"
+#include <iostream.h>
+#include <iomanip.h>
+
+TG4GeometryOutputManager::TG4GeometryOutputManager() {
+//
+}
+
+TG4GeometryOutputManager::~TG4GeometryOutputManager() {
+//
+}
+
+// public methods
+
+void TG4GeometryOutputManager::OpenFile(G4String filePath)
+{ 
+// Opens output files.
+// ---
+
+  G4cout << "TG4GeometryOutputManager::OpenFile: " << filePath << endl;
+  
+  fOutFile.open(filePath, ios::out, filebuf::openprot); 
+  
+  if (!fOutFile) {
+    G4String text = "Cannot open ";
+    text = text + filePath;
+    TG4Globals::Warning(text);  
+  }
+  
+  // use FORTRAN compatibility output
+  fOutFile << setiosflags(ios::showpoint | ios::uppercase);
+}
+
+
+void TG4GeometryOutputManager::CloseFile()
+{ 
+// Closess output files.
+// ---
+
+  fOutFile.close(); 
+}
+
+
+void TG4GeometryOutputManager::WriteGsvolu( 
+              G4String vname, G4String shape, G4int nmed, G4double* Rpar,
+              G4int npar)
+{
+// from fortran (g3routines.F)
+// write(fmt,'(A,I2,A)')'(a4,1x,a6,1x,a4,1x,a4,2i5,',max(npar,1),
+//>      '(1x,e16.8))'
+// write(lunlist,fmt) context, rname, name, shape, nmed, npar,
+//+      (par(k),k=1,npar)
+// ---
+
+  G4String context("----");
+  G4String rname("GSVOLU");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << vname    << space
+         << shape
+         << setw(5) << nmed  
+         << setw(5) << npar;
+  for (G4int i=0; i<npar; i++)       
+    fOutFile << space << setw(16) << setprecision(8) << Rpar[i];
+  fOutFile << G4endl;   
+}
+
+
+void TG4GeometryOutputManager::WriteGspos(
+             G4String vname, G4int num, G4String vmoth, G4double x,
+             G4double y, G4double z, G4int irot, G4String vonly)
+{           
+// from fortran (g3routines.F)
+// write(lunlist,
+//+      '(a4,1x,a6,1x,a4,i5,1x,a4,3(1x,e16.8),i5,1x,a4)')
+//+      context, rname, name, num, moth, x, y, z, irot, only
+// ---
+
+  G4String context("----");
+  G4String rname("GSPOS");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << vname   << space
+         << setw(5) << num << space 
+         << vmoth   << space
+          << setw(16) << setprecision(8) << x << space
+          << setw(16) << setprecision(8) << y << space
+          << setw(16) << setprecision(8) << z
+         << setw(5) << irot << space
+         << vonly 
+         << G4endl;
+}           
+  
+
+void TG4GeometryOutputManager::WriteGsposp(
+              G4String vname, G4int num, G4String vmoth, G4double x,
+              G4double y, G4double z, G4int irot, G4String vonly,
+              G4double pars[], G4int npar)
+{
+// from fortran (g3routines.F)
+// write(fmt,'(A,A,I2,A)')
+//+      '(a4,1x,a6,1x,a4,i5,1x,a4,3(1x,e16.8),',       
+//+      'i5,1x,a4,i5,',max(npar,1),'(1x,e16.8))'
+// write(lunlist,fmt)
+//+      context, rname, name, num, moth, x, y, z, irot, only,
+//+      npar,
+//+      (par(k),k=1,npar)
+// ---
+
+  G4String context("----");
+  G4String rname("GSPOSP");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << vname   << space
+         << setw(5) << num << space 
+         << vmoth   << space
+          << setw(16) << setprecision(8) << x << space
+          << setw(16) << setprecision(8) << y << space
+          << setw(16) << setprecision(8) << z
+         << setw(5) << irot << space
+         << vonly 
+         << setw(5) << npar;
+  for (G4int i=0; i<npar; i++)       
+    fOutFile << space << setw(16) << setprecision(8) << pars[i];
+  fOutFile << G4endl;
+}            
+
+
+void TG4GeometryOutputManager::WriteGsrotm(
+              G4int irot, G4double theta1, G4double phi1,
+              G4double theta2, G4double phi2, G4double theta3, G4double phi3)
+{
+// from fortran (g3routines.F)
+// write(lunlist,
+//+      '(a4,1x,a6,i5,6f11.5)')
+//+      context, rname, irot, theta1, phi1, theta2, phi2,
+//+      theta3, phi3
+// ---
+  
+  G4String context("----");
+  G4String rname("GSROTM");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << setw(5) << irot
+          << setw(11) << setprecision(5) << theta1
+          << setw(11) << setprecision(5) << phi1
+          << setw(11) << setprecision(5) << theta2
+          << setw(11) << setprecision(5) << phi2
+          << setw(11) << setprecision(5) << theta3
+          << setw(11) << setprecision(5) << phi3
+         << G4endl;
+}        
+
+
+void TG4GeometryOutputManager::WriteGsdvn(
+              G4String vname, G4String vmoth, G4int ndiv, G4int iaxis)
+{
+// from fortran (g3routines.F)
+// write(lunlist,
+//+      '(a4,1x,a6,1x,a4,1x,a4,i5,i3)')
+//+      context, rname, name, moth, ndiv, iaxis
+// ---
+
+  G4String context("----");
+  G4String rname("GSDVN");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << vname    << space
+         << vmoth   << space
+         << setw(5) << ndiv  
+         << setw(5) << iaxis
+          << G4endl;
+}           
+
+
+void TG4GeometryOutputManager::WriteGsdvn2(
+               G4String vname, G4String vmoth, G4int ndiv, G4int iaxis,
+               G4double c0, G4int numed)
+{
+// from fortran (g3routines.F)
+// write(lunlist,
+//+      '(a4,1x,a6,1x,a4,1x,a4,i5,i3,(1x,e16.8),i5)')
+//+      context, rname, name, moth, ndiv, iaxis, c0, numed
+// ---
+
+  G4String context("----");
+  G4String rname("GSDVN2");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << vname    << space
+         << vmoth   << space
+         << setw(5) << ndiv  
+         << setw(5) << iaxis << " "
+          << setw(16) << setprecision(8) << c0
+         << setw(5) << numed
+         << G4endl;
+}           
+
+
+void TG4GeometryOutputManager::WriteGsdvt(
+             G4String vname, G4String vmoth, G4double step, G4int iaxis,
+             G4int numed, G4int ndvmx) 
+{
+// from fortran (g3routines.F)
+// write(lunlist,
+// +    '(a4,1x,a6,1x,a4,1x,a4,(1x,e16.8),3i5)')
+// +    context, rname, name, moth, step, iaxis, numed, ndvmx
+// ---
+
+  G4String context("----");
+  G4String rname("GSDVT");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << vname    << space
+         << vmoth   << space
+          << setw(16) << setprecision(8) << step
+         << setw(5) << iaxis
+         << setw(5) << numed
+         << setw(5) << ndvmx
+         << G4endl;
+}           
+
+
+void TG4GeometryOutputManager::WriteGsdvt2(
+               G4String vname, G4String vmoth, G4double step, G4int iaxis,
+               G4double c0, G4int numed, G4int ndvmx)
+{             
+// from fortran (g3routines.F)
+// write(lunlist,
+//+      '(a4,1x,a6,1x,a4,1x,a4,(1x,e16.8),i3,(1x,e16.8),2i5)')
+//+      context, rname, name, moth, step, iaxis, c0, numed, ndvmx
+// ---
+
+  G4String context("----");
+  G4String rname("GSDVT2");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << vname    << space
+         << vmoth   << space
+          << setw(16) << setprecision(8) << step
+         << setw(3) << iaxis << space
+          << setw(16) << setprecision(8) << c0
+         << setw(5) << numed
+         << setw(5) << ndvmx
+         << endl;
+}           
+
+
+void TG4GeometryOutputManager::WriteGsdvx(
+             G4String name, G4String moth, G4int ndiv, G4int iaxis,
+             G4double step, G4double c0, G4int numed, G4int ndvmx)
+{
+// from fortran (g3routines.F)
+// write(lunlist,
+// +     '(a4,1x,a6,1x,a4,1x,a4,i5,i3,2(1x,e16.8),2i5)')
+// +     context, rname, name, moth, ndiv, iaxis,step, c0,
+// +     numed, ndvmx
+// ---
+
+  G4String context("----");
+  G4String rname("GSDVX");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << name    << space
+         << moth    << space
+         << setw(5) << ndiv
+         << setw(3) << iaxis << space
+          << setw(16) << setprecision(8) << step << space
+          << setw(16) << setprecision(8) << c0
+         << setw(5) << numed
+         << setw(5) << ndvmx
+         << endl;
+}           
+
+
+void TG4GeometryOutputManager::WriteGsmate(
+              G4int imate, G4String name, G4double ain, G4double zin,
+              G4double densin, G4double radl, G4int nwbf, G4double* ubuf)
+{
+// from fortran (g3routines.F)
+// write(fmt,'(A,I3,A)')
+//+      '(a4,1x,a6,i5,1x,''"'',a,''"'',4(1x,e16.8),i3,',
+//+      max(nwbf,1),'(1x,e16.8))'
+// write(lunlist,fmt)
+//+      context, rname, imate, name, a, z, dens, radl,
+//+      nwbf, (ubf(k), k=1,nwbf)
+// ---
+
+  G4String context("----");
+  G4String rname("GSMATE");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << setw(5) << imate << space 
+         << '"' << name << '"' << space
+          << setw(16) << setprecision(8) << ain << space
+          << setw(16) << setprecision(8) << zin << space
+          << setw(16) << setprecision(8) << densin << space
+          << setw(16) << setprecision(8) << radl
+         << setw(3) << nwbf;
+  for (G4int i=0; i<nwbf; i++)       
+    fOutFile << space << setw(16) << setprecision(8) << ubuf[i];
+  fOutFile << endl;
+}            
+
+
+void TG4GeometryOutputManager::WriteGsmixt(
+              G4int imate, G4String name, G4double* a, G4double* z,
+              G4double dens, G4int nlmat, G4double* wmat)
+{
+// from fortran (g3routines.F)
+// write(fmt,'(A,I3,A,I3,A,I3,A)')
+//+      '(a4,1x,a6,i5,1x,''"'',a,''"'',1x,e16.8,1x,i3,',
+//+      max(nlmata,1),
+//+      '(1x,e16.8),',max(nlmata,1),'(1x,e16.8),',
+//+      max(nlmata,1),'(1x,e16.8))'
+// write(lunlist,fmt)
+//+      context, rname, imate, name, dens,
+//+      nlmat, 
+//+      (a(k), k=1,abs(nlmat)),
+//+      (z(k), k=1,abs(nlmat)),
+//+      (wmat(k), k=1,abs(nlmat))
+// ---
+
+  G4String context("----");
+  G4String rname("GSMIXT");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << setw(5) << imate << space 
+         << '"' << name << '"' << space
+          << setw(16) << setprecision(8) << dens << space
+         << setw(3) << nlmat;
+  G4int i;       
+  for (i=0; i<abs(nlmat); i++)       
+    fOutFile << space << setw(16) << setprecision(8) << a[i];
+  for (i=0; i<abs(nlmat); i++)       
+    fOutFile << space << setw(16) << setprecision(8) << z[i];
+  for (i=0; i<abs(nlmat); i++)       
+    fOutFile << space << setw(16) << setprecision(8) << wmat[i];
+  fOutFile << endl;
+}            
+
+
+void TG4GeometryOutputManager::WriteGstmed(
+              G4int itmed, G4String name, G4int nmat, G4int isvol,
+              G4int ifield, G4double fieldm, G4double tmaxfd,
+              G4double stemax, G4double deemax, G4double epsil,
+              G4double stmin, G4double* ubuf, G4int nwbuf)
+{
+// from fortran (g3routines.F)
+// write(fmt,'(A,I3,A)') 
+//>      '(a4,1x,a6,i5,1x,''"'',a,''"'',3i3,6(1x,e16.8),i3,',
+//>      max(nwbuf,1),'(1x,e16.8))'
+// write(lunlist,fmt)
+//+      context, rname, itmed, name, nmat, isvol, ifield, fieldm,
+//+      tmaxfd, stemax, deemax, epsil, stmin,
+//+      nwbuf, (ubuf(k),k=1,nwbuf)
+// ---
+
+  G4String context("----");
+  G4String rname("GSTMED");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << setw(5) << itmed << space
+         << '"' << name << '"' 
+         << setw(3) << nmat
+         << setw(3) << isvol
+         << setw(3) << ifield << space
+          << setw(16) << setprecision(8) << fieldm << space
+          << setw(16) << setprecision(8) << tmaxfd << space
+          << setw(16) << setprecision(8) << stemax << space
+          << setw(16) << setprecision(8) << deemax << space
+          << setw(16) << setprecision(8) << epsil << space
+          << setw(16) << setprecision(8) << stmin << space
+         << setw(3) << nwbuf;
+  for (G4int i=0; i<nwbuf; i++)              
+    fOutFile << space << setw(16) << setprecision(8) << ubuf[i];
+  fOutFile << endl;
+}        
+
+
+void TG4GeometryOutputManager::WriteGstpar(
+               G4int itmed, G4String param, G4double parval)
+{             
+// from fortran (g3routines.F)
+// write(lunlist,
+//+     '(a4,1x,a6,i5,1x,a4,(1x,e16.8))')
+//+     context, rname, itmed, chpar, parval
+// ---
+
+  G4String context("----");
+  G4String rname("GSTPAR");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   << space
+         << setw(5) << itmed << space 
+         << param   << space
+          << setw(16) << setprecision(8) << parval
+          << endl;
+}            
+
+
+void TG4GeometryOutputManager::WriteGgclos()
+{
+// Writes GGCLOS token
+// ---
+
+  G4String context("----");
+  G4String rname("GGCLOS");
+  G4String space(" "); 
+  fOutFile << context << space 
+          << rname   
+         << endl;
+}        
diff --git a/TGeant4/TG4GeometryOutputManager.h b/TGeant4/TG4GeometryOutputManager.h
new file mode 100644 (file)
index 0000000..1a98150
--- /dev/null
@@ -0,0 +1,78 @@
+// $Id$
+// Category: geometry
+//
+// This class provides methods for writing
+// tokens (ASCII form of Geant3 routines calls)
+// into the specified output file
+
+#ifndef TG4_GEOMETRY_OUTPUT_MANAGER_H
+#define TG4_GEOMETRY_OUTPUT_MANAGER_H
+
+#include "TG4Globals.h"
+
+#include <globals.hh>
+
+//#include <fstream.h>
+#include "g4std/fstream"
+
+class TG4GeometryOutputManager
+{
+  public:
+    TG4GeometryOutputManager();
+    virtual ~TG4GeometryOutputManager();
+
+    // methods
+    void OpenFile(G4String filePath);
+    void CloseFile();
+
+    void WriteGsvolu(G4String name, G4String shape, G4int nmed, G4double* par,
+              G4int npar);
+
+    void WriteGspos(G4String name, G4int num, G4String moth, G4double x,
+              G4double y, G4double z, G4int irot, G4String only);
+
+    void WriteGsposp(G4String name, G4int num, G4String moth, G4double x,
+              G4double y, G4double z, G4int irot, G4String only,
+              G4double* Rpar, G4int npar);
+
+    void WriteGsrotm(G4int irot, G4double theta1, G4double phi1,
+              G4double theta2, G4double phi2, G4double theta3, G4double phi3);
+
+    //void WriteGsatt(G4String name, G4String attr, G4int ival);
+
+    void WriteGsdvn(G4String vname, G4String vmoth, G4int ndiv, G4int iaxis);
+
+    void WriteGsdvt(G4String name, G4String moth, G4double Step, G4int iaxis,
+              G4int numed, G4int ndvmx);
+
+    void WriteGsdvx(G4String name, G4String moth, G4int ndiv, G4int iaxis,
+              G4double Step, G4double c0, G4int numed, G4int ndvmx);
+
+    void WriteGsdvn2(G4String name, G4String moth, G4int ndiv, G4int iaxis,
+              G4double c0, G4int numed);
+
+    void WriteGsdvt2(G4String name, G4String moth, G4double Step, G4int iaxis,
+              G4double c0, G4int numed, G4int ndvmx);
+
+    void WriteGsmate(G4int imate, G4String name, G4double a, G4double z,
+              G4double dens, G4double radl, G4int nwbf, G4double* ubuf);
+
+    void WriteGsmixt(G4int imate, G4String name, G4double* a, G4double* z,
+              G4double dens, G4int nlmat, G4double* wmat);
+
+    void WriteGstmed(G4int itmed, G4String name, G4int nmat, G4int isvol,
+              G4int ifield, G4double fieldm, G4double tmaxfd,
+              G4double stemax, G4double deemax, G4double epsil,
+              G4double stmin, G4double* par, G4int npar);
+
+    void WriteGstpar(G4int itmed, G4String par, G4double parval);
+
+    void WriteGgclos();
+
+  private:
+    // data members
+    G4std::ofstream  fOutFile; //output file
+};
+
+#endif //TG4_GEOMETRY_OUTPUT_MANAGER_H
+
diff --git a/TGeant4/TG4Globals.cxx b/TGeant4/TG4Globals.cxx
new file mode 100644 (file)
index 0000000..c7ce33f
--- /dev/null
@@ -0,0 +1,40 @@
+// $Id$
+// Category: global
+//
+// See the class description in the header file.
+
+#include "TG4Globals.h"
+
+#include <stdlib.h>
+
+TG4Globals::TG4Globals() {
+//
+}
+  
+TG4Globals::~TG4Globals() {
+//
+}
+  
+// static methods
+
+void TG4Globals::Exception(const char* string)
+{
+// Prints error message end exits the program.
+// ---
+
+  if (string)
+  {  cerr << endl << "    " << string << endl; }
+  cerr << "*** TG4Exception: Aborting execution ***" << endl;   
+  exit(1);
+}
+
+void TG4Globals::Warning(const char* string)
+{
+// Prints warning message.
+// ---
+
+  cerr << "++++  TG4Warning:  ++++" << endl;   
+  if (string)
+  {  cerr  << "    " << string << endl; }
+  cerr << "+++++++++++++++++++++++" << endl;   
+}
diff --git a/TGeant4/TG4Globals.h b/TGeant4/TG4Globals.h
new file mode 100644 (file)
index 0000000..16e9c49
--- /dev/null
@@ -0,0 +1,50 @@
+// $Id$
+// Category: global
+//
+// Class for generally used basic types and functions.
+// It is protected from instantiating (only static data members
+// and static methods are defined).
+
+#ifndef TG4_GLOBALS_H
+#define TG4_GLOBALS_H
+
+#include "TG3Flag.h"
+
+#include <globals.hh>
+
+#include <g4rw/tvordvec.h>
+#include <g4rw/tpordvec.h>
+
+#include <vector.h>
+
+class G4Material;
+class G4Element;
+
+//typedef G4RWTValOrderedVector<G4bool>   TG4boolVector;
+typedef vector<G4bool>   TG4boolVector;
+typedef G4RWTValOrderedVector<G4double> TG4doubleVector;
+typedef G4RWTValOrderedVector<G4String> TG4StringVector;
+typedef G4RWTValOrderedVector<TG3FlagValue> TG3FlagVector;
+typedef G4RWTPtrOrderedVector<G4Material>   TG4MaterialVector;
+typedef G4RWTPtrOrderedVector<G4Element>    TG4ElementVector;  
+
+class TG4Globals
+{
+  public:
+    // --> protected 
+    // TG4Globals();
+    virtual ~TG4Globals();
+
+    // static methods
+    static void Exception(const char* string=0);
+      // Global error function prints string to cerr, and aborts
+      // program - according to G4Exception.cc
+    static void Warning(const char* string=0);
+      // Global warning function prints string to cerr
+
+  protected:
+    TG4Globals();  
+      // only typedefs's and static methods
+};  
+
+#endif //ALGLOBALS_H
diff --git a/TGeant4/TG4IntMap.cxx b/TGeant4/TG4IntMap.cxx
new file mode 100644 (file)
index 0000000..b0987d3
--- /dev/null
@@ -0,0 +1,111 @@
+// $Id$
+// Category: global
+//
+// See the class description in the header file.
+
+#include "TG4IntMap.h"
+#include "TG4Globals.h"
+
+#include "g4std/iomanip"
+#include "globals.hh"
+
+typedef G4std::map<G4String, G4int, G4std::less<G4String> >
+  :: iterator IntMapIterator;
+
+TG4IntMap::TG4IntMap(){
+//
+}
+
+TG4IntMap::TG4IntMap(const TG4IntMap& right) {
+//
+  TG4Globals::Exception("TG4IntMap is protected from copying.");
+}  
+
+TG4IntMap::~TG4IntMap() {
+//
+}
+
+// operators
+
+TG4IntMap& TG4IntMap::operator=(const TG4IntMap& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception("TG4IntMap is protected from assigning.");
+    
+  return *this;  
+}    
+          
+// private methods
+
+G4bool TG4IntMap::IsDefined(const G4String& first)
+{
+// Returns true if the first is already in the map.
+// ---
+
+  IntMapIterator i = fMap.find(first);
+  if (i == fMap.end()) 
+    return false;
+  else                 
+    return true;
+}
+
+// public methods
+
+G4bool TG4IntMap::Add(const G4String& first, G4int second)
+{  
+// Adds pair (name, int number) to the map.
+// ---
+
+  if (!IsDefined(first)) {
+    // insert into map 
+    // only in case it is not yet here
+    fMap[first] = second;
+    return true;
+  }
+  return false;
+}
+
+G4int TG4IntMap::GetSecond(const G4String& name)
+{
+// Gets second name associated with given name.
+// ---
+
+  IntMapIterator i = fMap.find(name);
+  if (i == fMap.end()) {
+    G4String text = "G4IntMap::GetSecond: ";
+    text = text + name + " is not defined.";
+    TG4Globals::Warning(text);
+    return 0;
+  }  
+  else {                
+    return (*i).second;
+  }  
+}
+
+void TG4IntMap::PrintAll()
+{
+// Dumps all map.
+// ---
+
+  if (fMap.size()) {
+    G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
+    G4int counter = 0;
+    for (IntMapIterator i=fMap.begin(); i != fMap.end(); i++) {
+      const G4String& first  = (*i).first;
+      G4int second = (*i).second;
+      G4cout << "Map element " << G4std::setw(3) << counter++ << "   " 
+             << first << "   " << second << G4endl;
+    }
+  }
+}
+
+
+void TG4IntMap::Clear() 
+{
+// Clears the map.
+// ---
+
+  if (fMap.size()>0) fMap.clear();
+}  
diff --git a/TGeant4/TG4IntMap.h b/TGeant4/TG4IntMap.h
new file mode 100644 (file)
index 0000000..ed024bc
--- /dev/null
@@ -0,0 +1,40 @@
+// $Id$
+// Category: global
+//
+// The map container for integer numbers associated with names.
+
+#ifndef TG4_INT_MAP_H
+#define TG4_INT_MAP_H
+
+#include "g4std/map"
+#include "globals.hh"
+
+class TG4IntMap
+{
+  public:
+    TG4IntMap();
+    // --> protected
+    // TG4IntMap(const TG4IntMap& right);
+    virtual ~TG4IntMap();
+
+    // methods
+    G4bool Add(const G4String& first, G4int second);  
+    G4int GetSecond(const G4String& name);
+    void PrintAll();
+    void Clear();
+
+  protected:
+    TG4IntMap(const TG4IntMap& right);
+
+    // operators
+    TG4IntMap& operator=(const TG4IntMap& right);
+  
+  private:
+    G4bool IsDefined(const G4String& first);
+  
+    // data members
+    G4std::map<G4String, G4int, G4std::less<G4String> > fMap;
+                                  //map container
+};
+
+#endif //TG4_NAME_MAP_H
diff --git a/TGeant4/TG4Limits.cxx b/TGeant4/TG4Limits.cxx
new file mode 100644 (file)
index 0000000..17dd454
--- /dev/null
@@ -0,0 +1,178 @@
+// $Id$
+// Category: global
+//
+// See the class description in the header file.
+
+#include "TG4Limits.h"
+#include "TG4CutVector.h"
+#include "TG4FlagVector.h"
+
+TG4Limits::TG4Limits()
+  : G4UserLimits(),              
+    // default values of G4UserLimits data members are set: 
+    // fMaxStep (DBL_MAX), fMaxTrack(DBL_MAX),fMaxTime(DBL_MAX),
+    // fMinEkine(0.), fMinRange(0.)
+    fIsCut(false),
+    fIsFlag(false) 
+{
+//
+  fCutVector = new TG4CutVector();
+  fFlagVector = new TG4FlagVector();
+}
+
+TG4Limits::TG4Limits(const TG4Limits& right)
+  : G4UserLimits(right) 
+{
+//    
+  fCutVector = new TG4CutVector(*right.fCutVector);
+  fFlagVector = new TG4FlagVector(*right.fFlagVector);
+}  
+
+TG4Limits::~TG4Limits() {
+//
+  delete fCutVector;
+  delete fFlagVector;
+}
+
+// operators
+
+TG4Limits& TG4Limits::operator=(const TG4Limits& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // base class assignement
+  G4UserLimits::operator=(right);
+
+  *fCutVector  = *right.fCutVector;
+  *fFlagVector = *right.fFlagVector;
+
+  return *this;  
+}    
+          
+// private methods
+
+G4double TG4Limits::GetUserMinEkine(const G4Track& track)
+{
+// Returns the kinetic energy cut for the particle
+// associated with the specified track.
+// ---
+
+  if (fIsCut)
+    return fCutVector->GetMinEkine(track);
+  else 
+    return fMinEkine;
+}
+
+// public methods
+
+void TG4Limits::SetG3Cut(TG3Cut g3Cut, G4double cutValue)
+{
+// Sets the cut value for the specified cut.
+// ---
+
+  fCutVector->SetG3Cut(g3Cut, cutValue);
+  fIsCut = true;
+}
+
+void TG4Limits::SetG3Flag(TG3Flag g3Flag, G4double flagValue)
+{
+// Sets the process control value for the specified flag.
+// ---
+
+  fFlagVector->SetG3Flag(g3Flag, flagValue);
+  if (flagValue - kUnset > 0.01) fIsFlag = true;
+}
+
+void TG4Limits::SetG3DefaultCuts()
+{
+// Sets the G3 default cut values for all cuts.
+// ---
+
+  fCutVector->SetG3Defaults();
+  fIsCut = true;  
+}
+
+void TG4Limits::SetG3DefaultFlags()
+{
+// Sets the G3 default process control values for all flags.
+// ---
+
+  fFlagVector->SetG3Defaults();
+  fIsFlag = true;
+}
+
+G4double TG4Limits::GetMinEkineForGamma(const G4Track& track) const
+{
+// Returns the cut value for gamma.
+// ---
+
+  if (fIsCut)
+    return fCutVector->GetMinEkine(track);
+  else 
+    return fMinEkine;
+}
+
+G4double TG4Limits::GetMinEkineForElectron(const G4Track& track) const
+{
+// Returns the cut value for e-.
+// ---
+
+  if (fIsCut)
+    return fCutVector->GetMinEkineForElectron(track);
+  else 
+    return fMinEkine;
+}
+
+G4double TG4Limits::GetMinEkineForHadron(const G4Track& track) const
+{
+// Returns the cut value for charged hadron.
+// ---
+
+  if (fIsCut)
+    return fCutVector->GetMinEkineForHadron(track);
+  else 
+    return fMinEkine;
+}
+
+G4double TG4Limits::GetMinEkineForNeutralHadron(const G4Track& track) const
+{
+// Returns the cut value for neutral hadron.
+// ---
+
+  if (fIsCut)
+    return fCutVector->GetMinEkineForNeutralHadron(track);
+  else 
+    return fMinEkine;
+}
+
+G4double TG4Limits::GetMinEkineForMuon(const G4Track& track) const
+{
+// Returns the cut value for neutral muon.
+// ---
+
+  if (fIsCut)
+    return fCutVector->GetMinEkineForMuon(track);
+  else 
+    return fMinEkine;
+}
+
+G4double TG4Limits::GetMinEkineForOther(const G4Track& track) const
+{
+ // Returns 0.
+// ---
+
+ return fMinEkine;
+}
+
+G4int TG4Limits::GetFlag(G4VProcess* process) const 
+{
+// Returns the flag value for the particle associated with
+// the specified process.
+// ---
+
+  if (fIsFlag)
+    return fFlagVector->GetFlag(process);
+  else 
+    return kUnset;
+}
diff --git a/TGeant4/TG4Limits.h b/TGeant4/TG4Limits.h
new file mode 100644 (file)
index 0000000..6afffae
--- /dev/null
@@ -0,0 +1,66 @@
+// $Id$
+// Category: global
+//
+// G4UserLimits derived class extended with
+// vectors of kinetic energy cuts and control process flags
+// data members
+
+#ifndef TG4_LIMITS_H
+#define TG4_LIMITS_H
+
+#include "TG4Globals.h"
+#include "TG3Cut.h"
+#include "TG3Flag.h"
+
+#include <G4UserLimits.hh>
+
+class TG4CutVector;
+class TG4FlagVector;
+
+class G4VProcess;
+
+class TG4Limits: public G4UserLimits
+{
+  public:
+    TG4Limits();
+    TG4Limits(const TG4Limits& right);
+    virtual ~TG4Limits();
+    
+    // operators
+    TG4Limits& operator=(const TG4Limits& right);
+
+    // set methods
+    void SetG3Cut(TG3Cut g3Cut, G4double cutValue);
+    void SetG3Flag(TG3Flag g3Flag, G4double flagValue);
+    void SetG3DefaultCuts();
+    void SetG3DefaultFlags();
+    
+    // get methods
+    G4bool IsCut() const;
+    G4bool IsFlag() const;
+    virtual G4double GetUserMinEkine(const G4Track& track);
+    G4double GetMinEkineForGamma(const G4Track& track) const;
+    G4double GetMinEkineForElectron(const G4Track& track) const;
+    G4double GetMinEkineForHadron(const G4Track& track) const;
+    G4double GetMinEkineForNeutralHadron(const G4Track& track) const;
+    G4double GetMinEkineForMuon(const G4Track& track) const;
+    G4double GetMinEkineForOther(const G4Track& track) const;
+    G4int GetFlag(G4VProcess* process) const; 
+
+  private:
+    // data members
+    G4bool            fIsCut;      //true if any cut value is set
+    G4bool            fIsFlag;     //true if any flag value is set
+    TG4CutVector*     fCutVector;  //TG4CutVector
+    TG4FlagVector*    fFlagVector; //TG4FlagVector
+};
+
+// inline methods
+
+inline G4bool TG4Limits::IsCut() const  { return fIsCut; }
+inline G4bool TG4Limits::IsFlag() const { return fIsFlag; }
+
+#endif //TG4_USER_LIMITS_H
+
+
+
diff --git a/TGeant4/TG4Messenger.cxx b/TGeant4/TG4Messenger.cxx
new file mode 100644 (file)
index 0000000..79cd321
--- /dev/null
@@ -0,0 +1,62 @@
+// $Id$
+// Category: run
+//
+// See the class description in the header file.
+
+#include "TG4Messenger.h"
+#include "TG4GeometryManager.h"
+#include "TG4StepManager.h"
+#include "TG4PhysicsManager.h"
+
+#include <G4UIcmdWithoutParameter.hh>
+
+TG4Messenger::TG4Messenger(TG4GeometryManager* geometryManager, 
+       TG4PhysicsManager* physicsManager, TG4StepManager* stepManager)
+  : fGeometryManager(geometryManager),
+    fPhysicsManager(physicsManager),
+    fStepManager(stepManager)
+{ 
+//
+  fProcessActivationCmd
+     = new G4UIcmdWithoutParameter("/g4mc/setProcessActivation", this);
+  fProcessActivationCmd->SetGuidance("Activate/inactivate physics processes.");
+  fProcessActivationCmd->AvailableForStates(Idle);
+}
+
+TG4Messenger::TG4Messenger(){
+//
+} 
+
+TG4Messenger::TG4Messenger(const TG4Messenger& right) {
+// 
+  TG4Globals::Exception("TG4Messenger is protected from copying.");
+}
+
+TG4Messenger::~TG4Messenger() {
+//
+  delete fProcessActivationCmd;
+}
+
+// operators
+
+TG4Messenger& TG4Messenger::operator=(const TG4Messenger& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception("TG4Messenger is protected from assigning.");
+    
+  return *this;  
+}    
+          
+// public methods
+
+void TG4Messenger::SetNewValue(G4UIcommand* command, G4String newValue)
+{ 
+// Applies command to the associated object.
+// ---
+
+  if (command == fProcessActivationCmd) {
+    fPhysicsManager->SetProcessActivation();
+  }  
+}
diff --git a/TGeant4/TG4Messenger.h b/TGeant4/TG4Messenger.h
new file mode 100644 (file)
index 0000000..8f5b0ec
--- /dev/null
@@ -0,0 +1,48 @@
+// $Id$
+// Category: run
+//
+// Messenger class that defines commands for 
+// geometry, physics and step managers
+
+#ifndef TG4_MESSENGER_H
+#define TG4_MESSENGER_H 
+
+#include <G4UImessenger.hh>
+#include <globals.hh>
+
+class TG4GeometryManager;
+class TG4PhysicsManager;
+class TG4StepManager;
+
+class G4UIcmdWithoutParameter;
+
+class TG4Messenger: public G4UImessenger
+{
+  public:
+    TG4Messenger(TG4GeometryManager* geometryManager, 
+       TG4PhysicsManager* physicsManager, TG4StepManager* stepManager);
+    // --> protected   
+    // TG4Messenger();
+    // TG4Messenger(const TG4Messenger& right);
+    virtual ~TG4Messenger();
+   
+    // methods 
+    virtual void SetNewValue(G4UIcommand* command, G4String string);
+    
+  protected:
+    TG4Messenger();  
+    TG4Messenger(const TG4Messenger& right);
+
+    // operators
+    TG4Messenger& operator=(const TG4Messenger& right);
+
+  private:
+    // data members
+    TG4GeometryManager*       fGeometryManager; //geometry manager
+    TG4PhysicsManager*        fPhysicsManager;  //physics manager
+    TG4StepManager*           fStepManager;     //step manager
+    G4UIcmdWithoutParameter*  fProcessActivationCmd; //command 
+                                                //setProcessActivation    
+};
+
+#endif //TG4_MESSENGER_H
diff --git a/TGeant4/TG4NameMap.cxx b/TGeant4/TG4NameMap.cxx
new file mode 100644 (file)
index 0000000..d6130ec
--- /dev/null
@@ -0,0 +1,119 @@
+// $Id$
+// Category: global
+//
+// See the class description in the header file.
+
+#include "TG4NameMap.h"
+#include "TG4Globals.h"
+
+#include "g4std/iomanip"
+#include "globals.hh"
+
+G4String TG4NameMap::fgUndefined = "Undefined";
+
+typedef G4std::map<G4String, G4String, G4std::less<G4String> >
+  :: iterator MapIterator;
+
+TG4NameMap::TG4NameMap() 
+  : fSecond(fgUndefined) {
+//
+}
+
+TG4NameMap::TG4NameMap(const TG4NameMap& right) {
+//
+  TG4Globals::Exception("TG4NameMap is protected from copying.");
+}  
+
+TG4NameMap::~TG4NameMap() {
+//
+}
+
+// operators
+
+TG4NameMap& TG4NameMap::operator=(const TG4NameMap& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception("TG4NameMap is protected from assigning.");
+    
+  return *this;  
+}    
+          
+// public methods
+
+G4bool TG4NameMap::Add(const G4String& first, const G4String& second)
+{  
+// Adds names pair to the map.
+// fSecond is not used in this add method.
+// ---
+
+  if (GetSecond(first) == fgUndefined) {
+    // insert into map 
+    // only in case it is not yet here
+    fMap[first] = second;
+    return true;
+  }
+  return false;
+}
+
+
+G4bool TG4NameMap::AddName(const G4String& name)
+{  
+// Adds name to the map.
+// ---
+
+  if (GetSecond(name) == fgUndefined) {
+    // insert into map 
+    // only in case it is not yet here
+    fMap[name] = fSecond;
+    return true;
+  }
+  return false;
+}
+
+
+const G4String& TG4NameMap::GetSecond(const G4String& name)
+{
+// Gets second name associated with given name.
+// ---
+
+  MapIterator i = fMap.find(name);
+  if (i == fMap.end()) 
+    return fgUndefined;
+  else                 
+    return (*i).second;
+}
+
+
+void TG4NameMap::PrintAll()
+{
+// Dumps all map.
+// ---
+
+  if (fMap.size()) {
+    G4cout << "Dump of TG4NameMap - " << fMap.size() << " entries:" << G4endl;
+    G4int counter = 0;
+    for (MapIterator i=fMap.begin(); i != fMap.end(); i++) {
+      const G4String& first  = (*i).first;
+      const G4String& second = (*i).second;
+      G4cout << "Map element " << G4std::setw(3) << counter++ << "   " 
+             << first << "   " << second << G4endl;
+    }
+  }
+}
+
+
+void TG4NameMap::Clear() 
+{
+// Clears the map.
+// ---
+
+  if (fMap.size()>0){
+    for (MapIterator i=fMap.begin(); i != fMap.end(); i++) {
+      delete (*i).second;
+    }
+    fMap.clear();
+  }
+  fSecond = "Undefined";
+}  
diff --git a/TGeant4/TG4NameMap.h b/TGeant4/TG4NameMap.h
new file mode 100644 (file)
index 0000000..eed5fc1
--- /dev/null
@@ -0,0 +1,53 @@
+// $Id$
+// Category: global
+//
+// The map container for associated names. 
+// The names can be added into map either in pairs (Add() method)
+// or standalone - then they are paired with the fSecond data member 
+// (AddName() method)
+
+#ifndef TG4_NAME_MAP_H
+#define TG4_NAME_MAP_H
+
+#include "g4std/map"
+#include "globals.hh"
+
+class TG4NameMap
+{
+  public:
+    TG4NameMap();
+    // --> protected
+    // TG4NameMap(const TG4NameMap& right);
+    virtual ~TG4NameMap();
+
+    // methods
+    G4bool Add(const G4String& first, const G4String& second);  
+    G4bool AddName(const G4String& name);  
+    const G4String& GetSecond(const G4String& name);
+    void PrintAll();
+    void Clear();
+
+    // set methods
+    void SetSecond(const G4String& name);
+
+  protected:
+    TG4NameMap(const TG4NameMap& right);
+
+    // operators
+    TG4NameMap& operator=(const TG4NameMap& right);
+  
+  private:
+    // static data members
+    static G4String fgUndefined;  //the value of undefined second
+
+    // data members
+    G4std::map<G4String, G4String, G4std::less<G4String> > fMap;
+                                  //map container
+    G4String  fSecond;            //the current second
+};
+
+// inline methods
+inline void TG4NameMap::SetSecond(const G4String& secondName)
+{ fSecond = secondName; }
+
+#endif //TG4_NAME_MAP_H
diff --git a/TGeant4/TG4PhysicsList.cxx b/TGeant4/TG4PhysicsList.cxx
new file mode 100644 (file)
index 0000000..b9e3088
--- /dev/null
@@ -0,0 +1,1110 @@
+// $Id$
+// Category: physics
+//
+// According to:
+// ExN04PhysicsList.cc,v 1.7 1999/12/15 14:49:26 gunter
+// GEANT4 tag Name: geant4-01-01
+
+#include "TG4PhysicsList.h"
+#include "TG4PhysicsListMessenger.h"
+#include "TG4PhysicsManager.h"
+#include "TG4CutVector.h"
+#include "TG4FlagVector.h"
+#include "TG4SpecialCuts.h"
+#include "TG4SpecialFlags.h"
+
+#include <G4ParticleDefinition.hh>
+#include <G4ParticleWithCuts.hh>
+#include <G4ProcessManager.hh>
+#include <G4ProcessVector.hh>
+#include <G4ParticleTypes.hh>
+#include <G4ParticleTable.hh>
+#include <G4BosonConstructor.hh>
+#include <G4LeptonConstructor.hh>
+#include <G4MesonConstructor.hh>
+#include <G4BaryonConstructor.hh>
+#include <G4IonConstructor.hh>
+#include <G4ShortLivedConstructor.hh>
+#include <G4Material.hh>
+#include <G4MaterialTable.hh>
+#include <G4ProcessTable.hh>
+//#include <G4ios.hh>
+
+#include <g4std/iomanip>
+
+
+TG4PhysicsList::TG4PhysicsList()
+  : G4VUserPhysicsList(),
+    fSetOptical(false),
+    fSetHadron(false),
+    fSetSpecialCuts(false),
+    fSetSpecialFlags(false)
+{
+  // default cut value  (1.0mm) 
+  defaultCutValue = 1.0*mm;
+
+  // messenger
+  fMessenger = new TG4PhysicsListMessenger(this);
+
+  SetVerboseLevel(1);
+}
+
+TG4PhysicsList::TG4PhysicsList(const TG4PhysicsList& right)
+  : G4VUserPhysicsList(right)
+{
+  // messenger
+  fMessenger = new TG4PhysicsListMessenger(this);
+  
+  fSetOptical = right.fSetOptical;
+  fSetHadron = right.fSetHadron;
+  fSetSpecialCuts = right.fSetSpecialCuts;
+  fSetSpecialFlags = right.fSetSpecialFlags;
+}
+
+TG4PhysicsList::~TG4PhysicsList() {
+//
+}
+
+// operators
+
+TG4PhysicsList& TG4PhysicsList::operator=(const TG4PhysicsList& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // base class assignement
+  G4VUserPhysicsList::operator=(right);
+
+  fSetOptical = right.fSetOptical;
+  fSetHadron = right.fSetHadron;
+  fSetSpecialCuts = right.fSetSpecialCuts;
+  fSetSpecialFlags = right.fSetSpecialFlags;
+  
+  return *this;
+}  
+
+// public methods
+
+void TG4PhysicsList::ConstructParticle()
+{
+// In this method, static member functions should be called
+// for all particles which you want to use.
+// This ensures that objects of these particle types will be
+// created in the program. 
+// ---
+
+  // lock physics manager
+  TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
+  physicsManager->Lock();  
+  physicsManager->SetPhysicsList(this);
+  // create all particles
+  ConstructAllBosons();
+  ConstructAllLeptons();
+  ConstructAllMesons();
+  ConstructAllBaryons();
+  ConstructAllIons();
+  ConstructAllShortLiveds();
+}
+
+void TG4PhysicsList::ConstructProcess()
+{
+// Constructs all processes.
+// ---
+
+  AddTransportation();
+
+  ConstructEM();
+  if (fSetHadron)  ConstructHad();
+  if (fSetOptical) ConstructOp();
+  if (fSetSpecialCuts)  ConstructSpecialCuts();
+  if (fSetSpecialFlags) ConstructSpecialFlags();  
+  ConstructGeneral();
+  if (verboseLevel>1) PrintAllProcesses();
+  // InActivateEM();
+}
+
+void TG4PhysicsList::SetProcessActivation()
+{
+// (In)Activates built processes according
+// to the setup in TG4PhysicsManager::fFlagVector.
+// ---
+
+  G4cout << "TG4PhysicsList::SetProcessActivation() start" << endl;
+  
+  TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
+  TG4FlagVector* flagVector = physicsManager->GetFlagVector();
+
+  // uncomment following lines to print
+  // the flagVector values
+  //for (G4int i=0; i<kNoG3Flags; i++)
+  //{ cout << i << " flag: " << (*flagVector)[i] << endl; }
+
+  if (flagVector) {
+    theParticleIterator->reset();
+    while ((*theParticleIterator)())
+    {
+      G4ParticleDefinition* particle = theParticleIterator->value();
+      G4ProcessManager* processManager = particle->GetProcessManager(); 
+      G4ProcessVector* processVector = processManager->GetProcessList();
+    
+      // set processes flags
+      for (G4int i=0; i<processManager->GetProcessListLength(); i++) {
+        G4int flag = flagVector->GetFlag((*processVector)[i]);
+        if ((flag == kInActivate) && 
+            (processManager->GetProcessActivation(i))) {
+          if (verboseLevel>1) {
+             G4cout << "Set process inactivation for " 
+                    << (*processVector)[i]->GetProcessName() << endl;
+          }
+          processManager->SetProcessActivation(i,false);
+        }  
+        else if (((flag == kActivate) || (flag == kActivate2)) &&
+                 (!processManager->GetProcessActivation(i))) {
+          if (verboseLevel>1) {
+             G4cout << "Set process activation for " 
+                    << (*processVector)[i]->GetProcessName() << endl;
+          }
+          processManager->SetProcessActivation(i,true);
+        } 
+      }
+    }
+  }
+  else {
+    G4String text = "TG4PhysicsList::SetProcessActivation: \n";
+    text = text + "    Vector of processes flags is not set.";
+    TG4Globals::Warning(text);
+  }    
+  G4cout << "TG4PhysicsList::SetProcessActivation() end" << endl;
+}
+
+void TG4PhysicsList::PrintAllProcesses() const
+{
+// Prints all processes.
+// ---
+
+  G4cout << "TG4PhysicsList processes: " << endl;
+  G4cout << "========================= " << endl;
+  G4ProcessTable* processTable = G4ProcessTable::GetProcessTable();
+  TG4StringVector* processNameList = processTable->GetNameList();
+
+  for (G4int i=0; i <processNameList->entries(); i++){
+    G4cout << "   " << (*processNameList)[i] << endl;
+  }  
+}
+
+// protected methods
+
+#include <G4ComptonScattering.hh>
+#include <G4GammaConversion.hh>
+#include <G4PhotoElectricEffect.hh>
+
+#include <G4MultipleScattering.hh>
+
+#include <G4eIonisation.hh>
+#include <G4eBremsstrahlung.hh>
+#include <G4eplusAnnihilation.hh>
+
+#include <G4MuIonisation.hh>
+#include <G4MuBremsstrahlung.hh>
+#include <G4MuPairProduction.hh>
+
+#include <G4hIonisation.hh>
+#include <G4ionIonisation.hh>
+
+void TG4PhysicsList::ConstructEM()
+{
+// Constructs electromagnetic processes.
+// ---
+
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() ){
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* pmanager = particle->GetProcessManager();
+    G4String particleName = particle->GetParticleName();
+     
+    if (particleName == "gamma") {
+    // gamma
+      // Construct processes for gamma
+      pmanager->AddDiscreteProcess(new G4GammaConversion());
+      pmanager->AddDiscreteProcess(new G4ComptonScattering());      
+      pmanager->AddDiscreteProcess(new G4PhotoElectricEffect());
+
+    } else if (particleName == "e-") {
+    //electron
+      // Construct processes for electron
+      G4VProcess* theeminusMultipleScattering = new G4MultipleScattering();
+      G4VProcess* theeminusIonisation = new G4eIonisation();
+      G4VProcess* theeminusBremsstrahlung = new G4eBremsstrahlung();
+      // add processes
+      pmanager->AddProcess(theeminusMultipleScattering);
+      pmanager->AddProcess(theeminusIonisation);
+      pmanager->AddProcess(theeminusBremsstrahlung);      
+      // set ordering for AlongStepDoIt
+      pmanager->SetProcessOrdering(theeminusMultipleScattering, idxAlongStep,  1);
+      pmanager->SetProcessOrdering(theeminusIonisation, idxAlongStep,  2);
+      // set ordering for PostStepDoIt
+      pmanager->SetProcessOrdering(theeminusMultipleScattering, idxPostStep, 1);
+      pmanager->SetProcessOrdering(theeminusIonisation, idxPostStep, 2);
+      pmanager->SetProcessOrdering(theeminusBremsstrahlung, idxPostStep, 3);
+
+    } else if (particleName == "e+") {
+    //positron
+      // Construct processes for positron
+      G4VProcess* theeplusMultipleScattering = new G4MultipleScattering();
+      G4VProcess* theeplusIonisation = new G4eIonisation();
+      G4VProcess* theeplusBremsstrahlung = new G4eBremsstrahlung();
+      G4VProcess* theeplusAnnihilation = new G4eplusAnnihilation();
+      // add processes
+      pmanager->AddProcess(theeplusMultipleScattering);
+      pmanager->AddProcess(theeplusIonisation);
+      pmanager->AddProcess(theeplusBremsstrahlung);
+      pmanager->AddProcess(theeplusAnnihilation);
+      // set ordering for AtRestDoIt
+      pmanager->SetProcessOrderingToFirst(theeplusAnnihilation, idxAtRest);
+      // set ordering for AlongStepDoIt
+      pmanager->SetProcessOrdering(theeplusMultipleScattering, idxAlongStep,  1);
+      pmanager->SetProcessOrdering(theeplusIonisation, idxAlongStep,  2);
+      // set ordering for PostStepDoIt
+      pmanager->SetProcessOrdering(theeplusMultipleScattering, idxPostStep, 1);
+      pmanager->SetProcessOrdering(theeplusIonisation, idxPostStep, 2);
+      pmanager->SetProcessOrdering(theeplusBremsstrahlung, idxPostStep, 3);
+      pmanager->SetProcessOrdering(theeplusAnnihilation, idxPostStep, 4);
+  
+    } else if( particleName == "mu+" || 
+               particleName == "mu-"    ) {
+    //muon  
+     // Construct processes for muon+
+     G4VProcess* aMultipleScattering = new G4MultipleScattering();
+     G4VProcess* aBremsstrahlung = new G4MuBremsstrahlung();
+     G4VProcess* aPairProduction = new G4MuPairProduction();
+     G4VProcess* anIonisation = new G4MuIonisation();
+      // add processes
+     pmanager->AddProcess(anIonisation);
+     pmanager->AddProcess(aMultipleScattering);
+     pmanager->AddProcess(aBremsstrahlung);
+     pmanager->AddProcess(aPairProduction);
+     // set ordering for AlongStepDoIt
+     pmanager->SetProcessOrdering(aMultipleScattering, idxAlongStep,  1);
+     pmanager->SetProcessOrdering(anIonisation, idxAlongStep,  2);
+     // set ordering for PostStepDoIt
+     pmanager->SetProcessOrdering(aMultipleScattering, idxPostStep, 1);
+     pmanager->SetProcessOrdering(anIonisation, idxPostStep, 2);
+     pmanager->SetProcessOrdering(aBremsstrahlung, idxPostStep, 3);
+     pmanager->SetProcessOrdering(aPairProduction, idxPostStep, 4);
+     
+    } else if( particleName == "GenericIon" ) {
+     G4VProcess* aionIonization = new G4ionIonisation;
+     G4VProcess* aMultipleScattering = new G4MultipleScattering();
+     pmanager->AddProcess(aionIonization);
+     pmanager->AddProcess(aMultipleScattering);
+     // set ordering for AlongStepDoIt
+     pmanager->SetProcessOrdering(aMultipleScattering, idxAlongStep,  1);
+     pmanager->SetProcessOrdering(aionIonization, idxAlongStep,  2);
+     // set ordering for PostStepDoIt
+     pmanager->SetProcessOrdering(aMultipleScattering, idxPostStep, 1);
+     pmanager->SetProcessOrdering(aionIonization, idxPostStep, 2);
+
+   } else if ((!particle->IsShortLived()) &&
+             (particle->GetPDGCharge() != 0.0) && 
+             (particle->GetParticleName() != "chargedgeantino")) {
+     // all others charged particles except geantino
+     G4VProcess* aMultipleScattering = new G4MultipleScattering();
+     G4VProcess* anIonisation = new G4hIonisation();
+     // add processes
+     pmanager->AddProcess(anIonisation);
+     pmanager->AddProcess(aMultipleScattering);
+     // set ordering for AlongStepDoIt
+     pmanager->SetProcessOrdering(aMultipleScattering, idxAlongStep,  1);
+     pmanager->SetProcessOrdering(anIonisation, idxAlongStep,  2);
+     // set ordering for PostStepDoIt
+     pmanager->SetProcessOrdering(aMultipleScattering, idxPostStep, 1);
+     pmanager->SetProcessOrdering(anIonisation, idxPostStep, 2);
+    }
+  }
+}
+
+
+// Hadron Processes
+
+#include <G4HadronElasticProcess.hh>
+
+#include <G4PionPlusInelasticProcess.hh>
+#include <G4PionMinusInelasticProcess.hh>
+#include <G4KaonPlusInelasticProcess.hh>
+#include <G4KaonZeroSInelasticProcess.hh>
+#include <G4KaonZeroLInelasticProcess.hh>
+#include <G4KaonMinusInelasticProcess.hh>
+#include <G4ProtonInelasticProcess.hh>
+#include <G4AntiProtonInelasticProcess.hh>
+#include <G4NeutronInelasticProcess.hh>
+#include <G4AntiNeutronInelasticProcess.hh>
+#include <G4LambdaInelasticProcess.hh>
+#include <G4AntiLambdaInelasticProcess.hh>
+#include <G4SigmaPlusInelasticProcess.hh>
+#include <G4SigmaMinusInelasticProcess.hh>
+#include <G4AntiSigmaPlusInelasticProcess.hh>
+#include <G4AntiSigmaMinusInelasticProcess.hh>
+#include <G4XiZeroInelasticProcess.hh>
+#include <G4XiMinusInelasticProcess.hh>
+#include <G4AntiXiZeroInelasticProcess.hh>
+#include <G4AntiXiMinusInelasticProcess.hh>
+#include <G4DeuteronInelasticProcess.hh>
+#include <G4TritonInelasticProcess.hh>
+#include <G4AlphaInelasticProcess.hh>
+#include <G4OmegaMinusInelasticProcess.hh>
+#include <G4AntiOmegaMinusInelasticProcess.hh>
+
+// Low-energy Models
+
+#include <G4LElastic.hh>
+
+#include <G4LEPionPlusInelastic.hh>
+#include <G4LEPionMinusInelastic.hh>
+#include <G4LEKaonPlusInelastic.hh>
+#include <G4LEKaonZeroSInelastic.hh>
+#include <G4LEKaonZeroLInelastic.hh>
+#include <G4LEKaonMinusInelastic.hh>
+#include <G4LEProtonInelastic.hh>
+#include <G4LEAntiProtonInelastic.hh>
+#include <G4LENeutronInelastic.hh>
+#include <G4LEAntiNeutronInelastic.hh>
+#include <G4LELambdaInelastic.hh>
+#include <G4LEAntiLambdaInelastic.hh>
+#include <G4LESigmaPlusInelastic.hh>
+#include <G4LESigmaMinusInelastic.hh>
+#include <G4LEAntiSigmaPlusInelastic.hh>
+#include <G4LEAntiSigmaMinusInelastic.hh>
+#include <G4LEXiZeroInelastic.hh>
+#include <G4LEXiMinusInelastic.hh>
+#include <G4LEAntiXiZeroInelastic.hh>
+#include <G4LEAntiXiMinusInelastic.hh>
+#include <G4LEDeuteronInelastic.hh>
+#include <G4LETritonInelastic.hh>
+#include <G4LEAlphaInelastic.hh>
+#include <G4LEOmegaMinusInelastic.hh>
+#include <G4LEAntiOmegaMinusInelastic.hh>
+
+// High-energy Models
+
+#include <G4HEPionPlusInelastic.hh>
+#include <G4HEPionMinusInelastic.hh>
+#include <G4HEKaonPlusInelastic.hh>
+#include <G4HEKaonZeroInelastic.hh>
+#include <G4HEKaonZeroInelastic.hh>
+#include <G4HEKaonMinusInelastic.hh>
+#include <G4HEProtonInelastic.hh>
+#include <G4HEAntiProtonInelastic.hh>
+#include <G4HENeutronInelastic.hh>
+#include <G4HEAntiNeutronInelastic.hh>
+#include <G4HELambdaInelastic.hh>
+#include <G4HEAntiLambdaInelastic.hh>
+#include <G4HESigmaPlusInelastic.hh>
+#include <G4HESigmaMinusInelastic.hh>
+#include <G4HEAntiSigmaPlusInelastic.hh>
+#include <G4HEAntiSigmaMinusInelastic.hh>
+#include <G4HEXiZeroInelastic.hh>
+#include <G4HEXiMinusInelastic.hh>
+#include <G4HEAntiXiZeroInelastic.hh>
+#include <G4HEAntiXiMinusInelastic.hh>
+#include <G4HEOmegaMinusInelastic.hh>
+#include <G4HEAntiOmegaMinusInelastic.hh>
+
+// Stopping processes
+
+#ifdef TRIUMF_STOP_PIMINUS
+#include <G4PionMinusAbsorptionAtRest.hh>
+#else
+#include <G4PiMinusAbsorptionAtRest.hh>
+#endif
+#ifdef TRIUMF_STOP_KMINUS
+#include <G4KaonMinusAbsorption.hh>
+#else
+#include <G4KaonMinusAbsorptionAtRest.hh>
+#endif
+
+void TG4PhysicsList::ConstructHad()
+{
+//
+// ConstructHad()
+//
+// Makes discrete physics processes for the hadrons, at present limited
+// to those particles with GHEISHA interactions (INTRC > 0).
+// The processes are: Elastic scattering and Inelastic scattering.
+//
+// F.W.Jones  09-JUL-1998
+// ---
+
+   G4cout << "### TG4PhysicsList::ConstructHad()" << endl;
+
+   G4HadronElasticProcess* theElasticProcess = 
+                                    new G4HadronElasticProcess;
+   G4LElastic* theElasticModel = new G4LElastic;
+   theElasticProcess->RegisterMe(theElasticModel);
+
+   theParticleIterator->reset();
+   while ((*theParticleIterator)()) {
+      G4ParticleDefinition* particle = theParticleIterator->value();
+      G4ProcessManager* pmanager = particle->GetProcessManager();
+      G4String particleName = particle->GetParticleName();
+     
+      if (particleName == "pi+") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4PionPlusInelasticProcess* theInelasticProcess = 
+                                new G4PionPlusInelasticProcess("inelastic");
+         G4LEPionPlusInelastic* theLEInelasticModel = 
+                                new G4LEPionPlusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEPionPlusInelastic* theHEInelasticModel = 
+                                new G4HEPionPlusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "pi-") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4PionMinusInelasticProcess* theInelasticProcess = 
+                                new G4PionMinusInelasticProcess("inelastic");
+         G4LEPionMinusInelastic* theLEInelasticModel = 
+                                new G4LEPionMinusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEPionMinusInelastic* theHEInelasticModel = 
+                                new G4HEPionMinusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+#ifdef TRIUMF_STOP_PIMINUS
+         pmanager->AddRestProcess(new G4PionMinusAbsorptionAtRest, ordDefault);
+#else
+         G4String prcNam;
+         pmanager->AddRestProcess(
+           new G4PiMinusAbsorptionAtRest(
+                prcNam="PiMinusAbsorptionAtRest"), ordDefault);
+#endif
+      }
+      else if (particleName == "kaon+") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4KaonPlusInelasticProcess* theInelasticProcess = 
+                                  new G4KaonPlusInelasticProcess("inelastic");
+         G4LEKaonPlusInelastic* theLEInelasticModel = 
+                                  new G4LEKaonPlusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEKaonPlusInelastic* theHEInelasticModel = 
+                                  new G4HEKaonPlusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "kaon0S") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4KaonZeroSInelasticProcess* theInelasticProcess = 
+                             new G4KaonZeroSInelasticProcess("inelastic");
+         G4LEKaonZeroSInelastic* theLEInelasticModel = 
+                             new G4LEKaonZeroSInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEKaonZeroInelastic* theHEInelasticModel = 
+                             new G4HEKaonZeroInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "kaon0L") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4KaonZeroLInelasticProcess* theInelasticProcess = 
+                             new G4KaonZeroLInelasticProcess("inelastic");
+         G4LEKaonZeroLInelastic* theLEInelasticModel = 
+                             new G4LEKaonZeroLInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEKaonZeroInelastic* theHEInelasticModel = 
+                             new G4HEKaonZeroInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "kaon-") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4KaonMinusInelasticProcess* theInelasticProcess = 
+                                 new G4KaonMinusInelasticProcess("inelastic");
+         G4LEKaonMinusInelastic* theLEInelasticModel = 
+                                 new G4LEKaonMinusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEKaonMinusInelastic* theHEInelasticModel = 
+                                 new G4HEKaonMinusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+#ifdef TRIUMF_STOP_KMINUS
+         pmanager->AddRestProcess(new G4KaonMinusAbsorption, ordDefault);
+#else
+         pmanager->AddRestProcess(new G4KaonMinusAbsorptionAtRest, ordDefault);
+#endif
+      }
+      else if (particleName == "proton") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4ProtonInelasticProcess* theInelasticProcess = 
+                                    new G4ProtonInelasticProcess("inelastic");
+         G4LEProtonInelastic* theLEInelasticModel = new G4LEProtonInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEProtonInelastic* theHEInelasticModel = new G4HEProtonInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "anti_proton") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AntiProtonInelasticProcess* theInelasticProcess = 
+                                new G4AntiProtonInelasticProcess("inelastic");
+         G4LEAntiProtonInelastic* theLEInelasticModel = 
+                                new G4LEAntiProtonInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEAntiProtonInelastic* theHEInelasticModel = 
+                                new G4HEAntiProtonInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "neutron") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4NeutronInelasticProcess* theInelasticProcess = 
+                                    new G4NeutronInelasticProcess("inelastic");
+         G4LENeutronInelastic* theLEInelasticModel = 
+                                    new G4LENeutronInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HENeutronInelastic* theHEInelasticModel = 
+                                    new G4HENeutronInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }  
+      else if (particleName == "anti_neutron") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AntiNeutronInelasticProcess* theInelasticProcess = 
+                               new G4AntiNeutronInelasticProcess("inelastic");
+         G4LEAntiNeutronInelastic* theLEInelasticModel = 
+                               new G4LEAntiNeutronInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEAntiNeutronInelastic* theHEInelasticModel = 
+                               new G4HEAntiNeutronInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "lambda") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4LambdaInelasticProcess* theInelasticProcess = 
+                                    new G4LambdaInelasticProcess("inelastic");
+         G4LELambdaInelastic* theLEInelasticModel = new G4LELambdaInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HELambdaInelastic* theHEInelasticModel = new G4HELambdaInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "anti_lambda") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AntiLambdaInelasticProcess* theInelasticProcess = 
+                                new G4AntiLambdaInelasticProcess("inelastic");
+         G4LEAntiLambdaInelastic* theLEInelasticModel = 
+                                new G4LEAntiLambdaInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEAntiLambdaInelastic* theHEInelasticModel = 
+                                new G4HEAntiLambdaInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "sigma+") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4SigmaPlusInelasticProcess* theInelasticProcess = 
+                                 new G4SigmaPlusInelasticProcess("inelastic");
+         G4LESigmaPlusInelastic* theLEInelasticModel = 
+                                 new G4LESigmaPlusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HESigmaPlusInelastic* theHEInelasticModel = 
+                                 new G4HESigmaPlusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "sigma-") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4SigmaMinusInelasticProcess* theInelasticProcess = 
+                                 new G4SigmaMinusInelasticProcess("inelastic");
+         G4LESigmaMinusInelastic* theLEInelasticModel = 
+                                 new G4LESigmaMinusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HESigmaMinusInelastic* theHEInelasticModel = 
+                                 new G4HESigmaMinusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "anti_sigma+") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AntiSigmaPlusInelasticProcess* theInelasticProcess = 
+                             new G4AntiSigmaPlusInelasticProcess("inelastic");
+         G4LEAntiSigmaPlusInelastic* theLEInelasticModel = 
+                                 new G4LEAntiSigmaPlusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEAntiSigmaPlusInelastic* theHEInelasticModel = 
+                                 new G4HEAntiSigmaPlusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "anti_sigma-") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AntiSigmaMinusInelasticProcess* theInelasticProcess = 
+                            new G4AntiSigmaMinusInelasticProcess("inelastic");
+         G4LEAntiSigmaMinusInelastic* theLEInelasticModel = 
+                                 new G4LEAntiSigmaMinusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEAntiSigmaMinusInelastic* theHEInelasticModel = 
+                                 new G4HEAntiSigmaMinusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "xi0") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4XiZeroInelasticProcess* theInelasticProcess = 
+                            new G4XiZeroInelasticProcess("inelastic");
+         G4LEXiZeroInelastic* theLEInelasticModel = 
+                                 new G4LEXiZeroInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEXiZeroInelastic* theHEInelasticModel = 
+                                 new G4HEXiZeroInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "xi-") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4XiMinusInelasticProcess* theInelasticProcess = 
+                            new G4XiMinusInelasticProcess("inelastic");
+         G4LEXiMinusInelastic* theLEInelasticModel = 
+                                 new G4LEXiMinusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEXiMinusInelastic* theHEInelasticModel = 
+                                 new G4HEXiMinusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "anti_xi0") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AntiXiZeroInelasticProcess* theInelasticProcess = 
+                            new G4AntiXiZeroInelasticProcess("inelastic");
+         G4LEAntiXiZeroInelastic* theLEInelasticModel = 
+                                 new G4LEAntiXiZeroInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEAntiXiZeroInelastic* theHEInelasticModel = 
+                                 new G4HEAntiXiZeroInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "anti_xi-") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AntiXiMinusInelasticProcess* theInelasticProcess = 
+                            new G4AntiXiMinusInelasticProcess("inelastic");
+         G4LEAntiXiMinusInelastic* theLEInelasticModel = 
+                                 new G4LEAntiXiMinusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEAntiXiMinusInelastic* theHEInelasticModel = 
+                                 new G4HEAntiXiMinusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "deuteron") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4DeuteronInelasticProcess* theInelasticProcess = 
+                            new G4DeuteronInelasticProcess("inelastic");
+         G4LEDeuteronInelastic* theLEInelasticModel = 
+                                 new G4LEDeuteronInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "triton") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4TritonInelasticProcess* theInelasticProcess = 
+                            new G4TritonInelasticProcess("inelastic");
+         G4LETritonInelastic* theLEInelasticModel = 
+                                 new G4LETritonInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "alpha") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AlphaInelasticProcess* theInelasticProcess = 
+                            new G4AlphaInelasticProcess("inelastic");
+         G4LEAlphaInelastic* theLEInelasticModel = 
+                                 new G4LEAlphaInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "omega-") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4OmegaMinusInelasticProcess* theInelasticProcess = 
+                            new G4OmegaMinusInelasticProcess("inelastic");
+         G4LEOmegaMinusInelastic* theLEInelasticModel = 
+                                 new G4LEOmegaMinusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEOmegaMinusInelastic* theHEInelasticModel = 
+                                 new G4HEOmegaMinusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+      else if (particleName == "anti_omega-") {
+         pmanager->AddDiscreteProcess(theElasticProcess);
+         G4AntiOmegaMinusInelasticProcess* theInelasticProcess = 
+                            new G4AntiOmegaMinusInelasticProcess("inelastic");
+         G4LEAntiOmegaMinusInelastic* theLEInelasticModel = 
+                                 new G4LEAntiOmegaMinusInelastic;
+         theInelasticProcess->RegisterMe(theLEInelasticModel);
+         G4HEAntiOmegaMinusInelastic* theHEInelasticModel = 
+                                 new G4HEAntiOmegaMinusInelastic;
+         theInelasticProcess->RegisterMe(theHEInelasticModel);
+         pmanager->AddDiscreteProcess(theInelasticProcess);
+      }
+   }
+
+   G4cout << "### TG4PhysicsList::ConstructHad() finished." << endl;
+
+}
+
+
+#include <G4Cerenkov.hh>
+#include <G4OpAbsorption.hh>
+#include <G4OpRayleigh.hh>
+#include <G4OpBoundaryProcess.hh>
+
+void TG4PhysicsList::ConstructOp()
+{
+// Constructs optical processes.
+// According to ExN06PhysicsList.cc.
+// (geant4 1.1)
+// ---
+
+  G4Cerenkov*     theCerenkovProcess = new G4Cerenkov("Cerenkov");
+  G4OpAbsorption* theAbsorptionProcess = new G4OpAbsorption();
+  G4OpRayleigh*   theRayleighScatteringProcess = new G4OpRayleigh();
+  G4OpBoundaryProcess* theBoundaryProcess = new G4OpBoundaryProcess();
+
+  theCerenkovProcess->DumpPhysicsTable();
+  //theAbsorptionProcess->DumpPhysicsTable();
+  //theRayleighScatteringProcess->DumpPhysicsTable();
+
+  // add verbose 
+  //theCerenkovProcess->SetVerboseLevel(1);
+  //theAbsorptionProcess->SetVerboseLevel(1);
+  //theRayleighScatteringProcess->SetVerboseLevel(1);
+  //theBoundaryProcess->SetVerboseLevel(1);
+
+  G4int maxNumPhotons = 300;
+
+  theCerenkovProcess->SetTrackSecondariesFirst(true);
+  theCerenkovProcess->SetMaxNumPhotonsPerStep(maxNumPhotons);
+
+  //G4OpticalSurfaceModel themodel = unified;   
+  // model from GEANT3
+  G4OpticalSurfaceModel themodel = glisur;
+  theBoundaryProcess->SetModel(themodel);
+
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() ){
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* processManager = particle->GetProcessManager();
+    G4String particleName = particle->GetParticleName();
+    if (theCerenkovProcess->IsApplicable(*particle)) {
+      processManager->AddContinuousProcess(theCerenkovProcess);
+    }
+    if (particleName == "opticalphoton") {
+      G4cout << " AddDiscreteProcess to OpticalPhoton " << G4endl;
+      processManager->AddDiscreteProcess(theAbsorptionProcess);
+      processManager->AddDiscreteProcess(theRayleighScatteringProcess);
+      processManager->AddDiscreteProcess(theBoundaryProcess);
+    }
+  }
+}
+
+#include <G4Decay.hh>
+
+void TG4PhysicsList::ConstructGeneral()
+{
+// Constructs general processes.
+// ---
+
+  // Add Decay Process
+  G4Decay* theDecayProcess = new G4Decay();
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() ){
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* pmanager = particle->GetProcessManager();
+    if (theDecayProcess->IsApplicable(*particle)) { 
+      pmanager ->AddProcess(theDecayProcess);
+      // set ordering for PostStepDoIt and AtRestDoIt
+      pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep);
+      pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest);
+    }
+  }
+}
+
+void TG4PhysicsList::ConstructSpecialCuts()
+{
+// Adds TG4SpecialCuts "process" that activates
+// the kinetic energy cuts defined in 
+// the vector of cuts (PhysicsManager::fCutVector) or in TG4Limits.
+// ---
+
+  TG4PhysicsManager* physicsManager 
+    = TG4PhysicsManager::Instance();
+
+  if (physicsManager->IsSpecialCuts())
+  {
+    TG4CutVector* cutVector
+      = physicsManager->GetCutVector(); 
+    TG4boolVector* isCutVector 
+      = physicsManager->GetIsCutVector(); 
+
+    theParticleIterator->reset();
+    while ((*theParticleIterator)())
+    {
+      G4ParticleDefinition* particle = theParticleIterator->value();
+      TG3ParticleWSP particleWSP 
+        = physicsManager->GetG3ParticleWSP(particle);
+      G4String name;
+      physicsManager->GetG3ParticleWSPName(particleWSP, name);
+      
+      // uncomment this to see all particles "WSP"
+      //G4cout << "Iterating particle: " 
+      //       << particle->GetParticleName() << " " << particleWSP << " "
+      //       << name << endl;
+
+      // special process is created in case
+      // cutVector (vector of kinetic energy cuts) is set
+      // or the special cut is set by TG4Limits
+      if ((particleWSP !=kNofParticlesWSP) && 
+          ((*isCutVector)[particleWSP])) {
+        // check if process already exists
+       G4String processName = "specialCutFor" + name;
+       G4VProcess* process = FindProcess(processName);
+       if (!process) {
+          process = new TG4SpecialCuts(particleWSP, cutVector, processName);
+       }  
+        //particle->GetProcessManager()->AddProcess(process, 0, -1, 1);
+        particle->GetProcessManager()->AddDiscreteProcess(process);
+      }
+    }
+
+    if (verboseLevel>0) {
+      G4cout << "TG4PhysicsList::ConstructSpecialCuts: " << endl;
+      if (cutVector)
+        G4cout << "   Global kinetic energy cuts are set." << endl;
+      G4cout << "   Special cuts process is defined for: " << endl 
+             << "   ";
+      for (G4int i=0; i<kAny; i++) {
+        G4String name;
+        physicsManager->GetG3ParticleWSPName(i, name);
+        if ((*isCutVector)[i]) G4cout << name << " ";
+      }  
+      G4cout << endl;
+    }  
+  }
+}
+
+void TG4PhysicsList::ConstructSpecialFlags()
+{
+// Adds TG4SpecialFlags "process" that activates
+// the control process flags defined in TG4Limits.
+// ---
+
+  TG4PhysicsManager* physicsManager 
+    = TG4PhysicsManager::Instance();
+
+  if (physicsManager->IsSpecialFlags())
+  {
+    G4cout << "IsSpecialFlags started" << endl;
+    TG4boolVector* isFlagVector 
+      = physicsManager->GetIsFlagVector(); 
+
+    theParticleIterator->reset();
+    while ((*theParticleIterator)())
+    {
+      G4ParticleDefinition* particle = theParticleIterator->value();
+      TG3ParticleWSP particleWSP 
+        = physicsManager->GetG3ParticleWSP(particle);
+      //G4String name;
+      //GetG3ParticleWSPName(particleWSP, name);
+
+      // special process is set in case
+      // the special flag is set by TG4Limits    
+      if ((particleWSP !=kNofParticlesWSP) && 
+          ((*isFlagVector)[particleWSP])) {
+        // check if process already exists
+       G4String processName = "specialFlag";
+       G4VProcess* process = FindProcess(processName);
+       if (!process) {
+          process = new TG4SpecialFlags(processName);
+       }  
+        //particle->GetProcessManager()->AddProcess(process, 0, -1, 1);
+        particle->GetProcessManager()->AddDiscreteProcess(process);
+      }
+    }
+
+    if (verboseLevel>0) {
+      G4cout << "TG4PhysicsList::ConstructSpecialFlagss: " << endl;
+      G4cout << "   Special flags process is defined for: " << endl
+             << "   ";
+      for (G4int i=0; i<kNofParticlesWSP; i++) {
+        G4String name;
+        physicsManager->GetG3ParticleWSPName(i, name);
+        if ((*isFlagVector)[i]) G4cout << name << " ";
+      }  
+      G4cout << endl;
+    }  
+  }
+}
+
+void TG4PhysicsList::SetCuts()
+{
+// "G4VUserPhysicsList::SetCutsWithDefault" method sets 
+// the default cut value for all particle types 
+// ---
+
+  SetCutsWithDefault();   
+}
+
+void TG4PhysicsList::ConstructAllBosons()
+{
+// Construct all bosons
+// ---
+
+  G4BosonConstructor pConstructor;
+  pConstructor.ConstructParticle();
+}
+
+void TG4PhysicsList::ConstructAllLeptons()
+{
+// Construct all leptons
+// ---
+
+  G4LeptonConstructor pConstructor;
+  pConstructor.ConstructParticle();
+}
+
+void TG4PhysicsList::ConstructAllMesons()
+{
+// Construct all mesons
+// ---
+
+  G4MesonConstructor pConstructor;
+  pConstructor.ConstructParticle();
+}
+
+void TG4PhysicsList::ConstructAllBaryons()
+{
+// Construct all barions
+// ---
+
+  G4BaryonConstructor pConstructor;
+  pConstructor.ConstructParticle();
+}
+
+void TG4PhysicsList::ConstructAllIons()
+{
+// Construct light ions
+// ---
+
+  G4IonConstructor pConstructor;
+  pConstructor.ConstructParticle();  
+}
+
+void TG4PhysicsList::ConstructAllShortLiveds()
+{
+// Construct  resonaces and quarks
+// ---
+
+  G4ShortLivedConstructor pConstructor;
+  pConstructor.ConstructParticle();  
+}
+
+// private methods
+
+G4VProcess* TG4PhysicsList::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;
+}
+
+void TG4PhysicsList::InActivateProcess(G4String processName, 
+                        G4ParticleDefinition* particle)              
+{
+// Activates the process specified by name for the specified 
+// particle.
+// Only for tests - to be removed.
+// ---
+
+  G4ProcessManager* processManager = particle->GetProcessManager();
+  G4ProcessVector* processVector = processManager->GetProcessList();
+  for (G4int i=0; i<processVector->entries(); i++) {
+    if ((*processVector)[i]->GetProcessName() == processName) {
+      processManager->SetProcessActivation((*processVector)[i], false);
+      return;
+    }
+  }
+  G4String text = "TG4PhysicsList::InActivateProcess: ";
+  text = text + processName + " is not set for ";
+  text = text + particle->GetParticleName();
+  TG4Globals::Exception(text);
+}
+
+void TG4PhysicsList::InActivateEM()
+{
+// Inactivates specified electromagnetic processes.
+// Only for tests - to be removed.
+// !! This method must be called after all Construct methods.
+// Uncomment the selected line(s) to inactivate desired processes.
+// ---
+
+ theParticleIterator->reset();
+  while ((*theParticleIterator)())
+  {
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4String name = particle->GetParticleName();     
+    
+    if (name == "gamma") {
+      // gamma
+      //InActivateProcess("phot",  particle);      
+      //InActivateProcess("compt", particle);      
+      //InActivateProcess("conv", particle);      
+    } 
+    else if (name == "e-") {
+      //electron
+      InActivateProcess("msc",  particle);      
+      G4cout << "msc inactivated." << endl;
+      //InActivateProcess("eIoni",  particle);      
+      //G4cout << "eIoni inactivated." << endl;
+      InActivateProcess("eBrem",  particle);      
+      G4cout << "eBrem inactivated." << endl;
+    } 
+    else if (name == "e+") {
+      //positron
+      //InActivateProcess("msc",  particle);      
+      //InActivateProcess("eIoni",  particle);      
+      //InActivateProcess("eBrem",  particle);      
+      //InActivateProcess("annihil",  particle);      
+    } 
+    else if (name == "mu+" || name == "mu-") {
+      //muon  
+      //InActivateProcess("msc",  particle);      
+      //InActivateProcess("MuIoni",  particle);      
+      //InActivateProcess("MuBrem",  particle);      
+      //InActivateProcess("MuPairProd",  particle);      
+    } 
+    else if ((!particle->IsShortLived()) &&
+            (particle->GetPDGCharge() != 0.0) && 
+            (particle->GetParticleName() != "chargedgeantino")) 
+    {
+      // all others charged particles except geantino
+      //InActivateProcess("msc",  particle);      
+      //InActivateProcess("hIoni",  particle);      
+    }
+  }
+}
+
diff --git a/TGeant4/TG4PhysicsList.h b/TGeant4/TG4PhysicsList.h
new file mode 100644 (file)
index 0000000..e2272a3
--- /dev/null
@@ -0,0 +1,98 @@
+// $Id$
+// Category: physics
+//
+// Physics list (mandatory) class.
+// According to:
+// ExN04PhysicsList.hh, GEANT4 tag Name: geant4-01-01
+
+#ifndef TG4_PHYSICS_LIST_H
+#define TG4_PHYSICS_LIST_H
+
+#include <G4VUserPhysicsList.hh>
+#include <globals.hh>
+
+class TG4PhysicsListMessenger;
+
+class G4VProcess;
+
+class TG4PhysicsList: public G4VUserPhysicsList
+{
+  public:
+    TG4PhysicsList();
+    TG4PhysicsList(const TG4PhysicsList& right);
+    virtual ~TG4PhysicsList();
+  
+    // operators
+    TG4PhysicsList& operator=(const TG4PhysicsList& right);
+    
+    // methods
+    void PrintAllProcesses() const;
+    void SetProcessActivation();
+    
+    // set methods
+    void SetOptical(G4bool optical);
+    void SetHadron(G4bool hadron);
+    void SetSpecialCuts(G4bool specialCuts);
+    void SetSpecialFlags(G4bool specialFlags);
+
+  protected:
+    // methods
+          // construct particle and physics
+    virtual void ConstructParticle();
+    virtual void ConstructProcess();
+  
+         // construct physics processes and register them
+    void ConstructGeneral();
+    void ConstructEM();
+    void ConstructHad();
+    void ConstructOp();
+    void ConstructNewSpecialCuts();
+    void ConstructSpecialCuts();
+    void ConstructSpecialFlags();
+
+         // construct all particles in each category
+    void ConstructAllBosons();
+    void ConstructAllLeptons();
+    void ConstructAllMesons();
+    void ConstructAllBaryons();
+    void ConstructAllIons();
+    void ConstructAllShortLiveds();
+
+    // set methods
+    virtual void SetCuts();
+   
+  private:
+    // methods
+    G4VProcess* FindProcess(G4String processName) const;
+
+        // only for tests - to be removed  
+    void InActivateEM();
+    void InActivateProcess(G4String processName, 
+           G4ParticleDefinition* particle);  
+          
+    // data members
+    G4bool  fSetOptical;     //optical processes control
+    G4bool  fSetHadron;      //hadron processes control
+    G4bool  fSetSpecialCuts; //special cuts process control (under development)                  
+    G4bool  fSetSpecialFlags;//special flags process control (under development)
+
+    TG4PhysicsListMessenger*  fMessenger;   //messenger
+};
+
+// inline methods
+
+inline void TG4PhysicsList::SetOptical(G4bool optical)
+{ fSetOptical = optical; }
+
+inline void TG4PhysicsList::SetHadron(G4bool hadron)
+{ fSetHadron = hadron; }
+
+inline void TG4PhysicsList::SetSpecialCuts(G4bool specialCuts)
+{ fSetSpecialCuts = specialCuts; }
+
+inline void TG4PhysicsList::SetSpecialFlags(G4bool specialFlags)
+{ fSetSpecialFlags = specialFlags; }
+
+#endif //TG4_PHYSICS_LIST_H
+
diff --git a/TGeant4/TG4PhysicsListMessenger.cxx b/TGeant4/TG4PhysicsListMessenger.cxx
new file mode 100644 (file)
index 0000000..186adfd
--- /dev/null
@@ -0,0 +1,98 @@
+// $Id$
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4PhysicsListMessenger.h"
+#include "TG4PhysicsList.h"
+#include "TG4Globals.h"
+
+#include <G4UIcmdWithABool.hh>
+
+TG4PhysicsListMessenger::TG4PhysicsListMessenger(TG4PhysicsList* physicsList)
+  : fPhysicsList(physicsList)
+{ 
+//
+  fSetOpticalCmd
+     = new G4UIcmdWithABool("/g4mc/setOptical", this);
+  fSetOpticalCmd->SetGuidance("Set Cerenkov and optical processes.");
+  fSetOpticalCmd->SetParameterName("OpticalControl", false);
+  fSetOpticalCmd->AvailableForStates(PreInit);
+
+  fSetHadronCmd
+     = new G4UIcmdWithABool("/g4mc/setHadron", this);
+  fSetHadronCmd->SetGuidance("Set hadron processes.");
+  fSetHadronCmd->SetParameterName("HadronControl", false);
+  fSetHadronCmd->AvailableForStates(PreInit);
+
+  fSetSpecialCutsCmd
+     = new G4UIcmdWithABool("/g4mc/setSpecialCuts", this);
+  fSetSpecialCutsCmd->SetGuidance("Set special cuts process.");
+  fSetSpecialCutsCmd
+    ->SetGuidance("!! Support for this option is under development.");
+  fSetSpecialCutsCmd->SetParameterName("SpecialCutsControl", false);
+  fSetSpecialCutsCmd->AvailableForStates(PreInit);
+
+  fSetSpecialFlagsCmd
+     = new G4UIcmdWithABool("/g4mc/setSpecialFlags", this);
+  fSetSpecialFlagsCmd->SetGuidance("Set special flags process.");
+  fSetSpecialFlagsCmd
+    ->SetGuidance("!! Support for this option is under development.");
+  fSetSpecialFlagsCmd->SetParameterName("SpecialFlagsControl", false);
+  fSetSpecialFlagsCmd->AvailableForStates(PreInit);
+}
+
+TG4PhysicsListMessenger::TG4PhysicsListMessenger(
+                            const TG4PhysicsListMessenger& right) {
+//                          
+  TG4Globals::Exception(
+    "TG4PhysicsListMessenger is protected from copying.");
+}
+
+TG4PhysicsListMessenger::~TG4PhysicsListMessenger() {
+//
+  delete fSetOpticalCmd;
+  delete fSetHadronCmd;
+  delete fSetSpecialCutsCmd;
+  delete fSetSpecialFlagsCmd;
+}
+
+// operators
+
+TG4PhysicsListMessenger& 
+TG4PhysicsListMessenger::operator=(const TG4PhysicsListMessenger& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "TG4PhysicsListMessenger is protected from assigning.");
+    
+  return *this;  
+}    
+          
+// public methods
+
+void TG4PhysicsListMessenger::SetNewValue(G4UIcommand* command, 
+                                          G4String newValues)
+{ 
+// Applies command to the associated object.
+// ---
+
+  if (command == fSetOpticalCmd) {
+    fPhysicsList
+      ->SetOptical(fSetOpticalCmd->GetNewBoolValue(newValues)); 
+  }    
+  else if (command == fSetHadronCmd) {
+    fPhysicsList
+      ->SetHadron(fSetHadronCmd->GetNewBoolValue(newValues)); 
+  }    
+  else if (command == fSetSpecialCutsCmd) {
+    fPhysicsList
+      ->SetSpecialCuts(fSetSpecialCutsCmd->GetNewBoolValue(newValues)); 
+  }    
+  else if (command == fSetSpecialFlagsCmd) {
+    fPhysicsList
+      ->SetSpecialFlags(fSetSpecialFlagsCmd->GetNewBoolValue(newValues)); 
+  }    
+}
diff --git a/TGeant4/TG4PhysicsListMessenger.h b/TGeant4/TG4PhysicsListMessenger.h
new file mode 100644 (file)
index 0000000..a07f307
--- /dev/null
@@ -0,0 +1,43 @@
+// $Id$
+// Category: physics
+//
+// Messenger class that defines commands for TG4PhysicsList
+
+#ifndef TG4_PHYSICS_LIST_MESSENGER_H
+#define TG4_PHYSICS_LIST_MESSENGER_H 
+
+#include <G4UImessenger.hh>
+#include <globals.hh>
+
+class TG4PhysicsList;
+
+class G4UIcmdWithABool;
+
+class TG4PhysicsListMessenger: public G4UImessenger
+{
+  public:
+    TG4PhysicsListMessenger(TG4PhysicsList* physicsList); 
+    // --> protected                       
+    // TG4PhysicsListMessenger(const TG4PhysicsListMessenger& right);
+    virtual ~TG4PhysicsListMessenger();
+   
+    // methods 
+    virtual void SetNewValue(G4UIcommand* command, G4String string);
+    
+  protected:
+    TG4PhysicsListMessenger(const TG4PhysicsListMessenger& right);
+
+    // operators
+    TG4PhysicsListMessenger& operator=(
+                            const TG4PhysicsListMessenger& right);
+
+  private:
+    // data members
+    TG4PhysicsList*    fPhysicsList;        //associated class 
+    G4UIcmdWithABool*  fSetOpticalCmd;      //setCerenkov command   
+    G4UIcmdWithABool*  fSetHadronCmd;       //setHadron command   
+    G4UIcmdWithABool*  fSetSpecialCutsCmd;  //setSpecialCuts command   
+    G4UIcmdWithABool*  fSetSpecialFlagsCmd; //setSpecialFlags command   
+};
+
+#endif //TG4_PHYSICS_LIST_MESSENGER_H
diff --git a/TGeant4/TG4PhysicsManager.cxx b/TGeant4/TG4PhysicsManager.cxx
new file mode 100644 (file)
index 0000000..c0d319d
--- /dev/null
@@ -0,0 +1,751 @@
+// $Id$
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4PhysicsManager.h"
+#include "TG4PhysicsList.h"
+#include "TG4CutVector.h"
+#include "TG4FlagVector.h"
+#include "TG4G3Defaults.h"
+
+#include <G4ParticleDefinition.hh>
+#include <Randomize.hh>
+
+#include <TDatabasePDG.h>
+
+TG4PhysicsManager* TG4PhysicsManager::fgInstance = 0;
+
+TG4PhysicsManager::TG4PhysicsManager()
+  : fLock(false),
+    fPhysicsList(0),
+    fCutVector(0),
+    fFlagVector(0) 
+{ 
+//
+  if (fgInstance) {
+    TG4Globals::Exception(
+      "TG4PhysicsManager: 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 fIsFlagVector 
+  fIsFlagVector = new TG4boolVector;
+  //for (i=0; i<kNofParticlesWSP; i++) fIsFlagVector->insert(false);
+  for (i=0; i<kNofParticlesWSP; i++) fIsFlagVector->push_back(false);
+
+  // define 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");
+
+  // define fFlagNameVector
+  fG3FlagNameVector.insert("PAIR");
+  fG3FlagNameVector.insert("COMP");
+  fG3FlagNameVector.insert("PHOT");
+  fG3FlagNameVector.insert("PFIS");
+  fG3FlagNameVector.insert("DRAY");
+  fG3FlagNameVector.insert("ANNI");
+  fG3FlagNameVector.insert("BREM");
+  fG3FlagNameVector.insert("HADR");
+  fG3FlagNameVector.insert("MUNU");
+  fG3FlagNameVector.insert("DCAY");
+  fG3FlagNameVector.insert("LOSS");
+  fG3FlagNameVector.insert("MULS");
+}
+
+TG4PhysicsManager::TG4PhysicsManager(const TG4PhysicsManager& right) {
+// 
+  TG4Globals::Exception(
+    "Attempt to copy TG4PhysicsManager singleton.");
+}
+
+TG4PhysicsManager::~TG4PhysicsManager() {
+//
+  delete fIsCutVector;
+  delete fIsFlagVector;
+}
+
+// operators
+
+TG4PhysicsManager& 
+TG4PhysicsManager::operator=(const TG4PhysicsManager& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "Attempt to assign TG4PhysicsManager singleton.");
+    
+  return *this;  
+}    
+          
+// private methods
+
+void TG4PhysicsManager::LockException() const
+{
+// Gives exception in case of attempt to modified physics
+// setup after physics manager was locked.
+// ---
+
+  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);
+}
+
+G4int TG4PhysicsManager::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 = "TG4PhysicsManager::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 = "TG4PhysicsManager::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 TG4PhysicsManager::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 = "TG4PhysicsManager::GetPDGEncoding:\n";
+    text = text + "   G4ParticleTable::FindParticle() " + particleName;
+    text = text + " failed.";
+    TG4Globals::Exception(text);
+  }    
+
+  return GetPDGEncoding(particle);
+}  
+  
+void TG4PhysicsManager::SetCut(TG3Cut cut, G4double cutValue)
+{  
+// Sets kinetic energy cut (in a G3-like way).
+// ---
+
+  if (!fCutVector) {
+    // create vector of kinetic energy cut values  
+    fCutVector = new TG4CutVector();
+  }  
+  fCutVector->SetG3Cut(cut, cutValue);
+  SwitchIsCutVector(cut);
+}  
+
+void TG4PhysicsManager::SetProcess(TG3Flag flag, G4int flagValue)
+{
+// Sets control process flag (in a G3-like way).
+// ---
+
+  if (!fFlagVector) {
+    // create vector of control process flag values
+    fFlagVector = new TG4FlagVector;
+  }  
+  fFlagVector->SetG3Flag(flag, flagValue);
+} 
+
+
+Float_t TG4PhysicsManager::Xsec(char* ch, Float_t p1, Int_t i1, Int_t i2)
+{
+// Not yet implemented -> gives exception.
+// ---
+
+  TG4Globals::Exception(
+    "TG4PhysicsManager::Xsec: not yet implemented.");
+
+  return 0.;
+}    
+  
+Int_t TG4PhysicsManager::IdFromPDG(Int_t pdgID) const
+{
+// G4 does not use the integer particle identifiers
+// Id <-> PDG is identity.
+// ---
+
+  return pdgID;
+}  
+
+Int_t TG4PhysicsManager::PDGFromId(Int_t mcID) const
+{
+// G4 does not use integer particle identifiers
+// Id <-> PDG is identity.
+// ---
+
+  return mcID;
+}  
+
+void  TG4PhysicsManager::DefineParticles()
+{
+  // ======
+  // Taken from TGeant3
+  //
+  // Use ENDF-6 mapping for ions = 10000*z+10*a+iso
+  // and add 1 000 000
+  // and numbers above 5 000 000 for special applications
+  //
+
+  const Int_t kion=10000000;
+  const Int_t kspe=50000000;
+
+  const Double_t kGeV=0.9314943228;
+  const Double_t kHslash = 1.0545726663e-27;
+  const Double_t kErgGeV = 1/1.6021773349e-3;
+  const Double_t kHshGeV = kHslash*kErgGeV;
+  const Double_t kYearsToSec = 3600*24*365.25;
+
+  TDatabasePDG *pdgDB = TDatabasePDG::Instance();
+
+  pdgDB->AddParticle("Deuteron","Deuteron",2*kGeV+8.071e-3,kTRUE,
+                    0,1,"Ion",kion+10020);
+                    
+  pdgDB->AddParticle("Triton","Triton",3*kGeV+14.931e-3,kFALSE,
+                    kHshGeV/(12.33*kYearsToSec),1,"Ion",kion+10030);
+
+  pdgDB->AddParticle("Alpha","Alpha",4*kGeV+2.424e-3,kTRUE,
+                    kHshGeV/(12.33*kYearsToSec),2,"Ion",kion+20040);
+
+  pdgDB->AddParticle("HE3","HE3",3*kGeV+14.931e-3,kFALSE,
+                    0,2,"Ion",kion+20030);
+
+  pdgDB->AddParticle("Cherenkov","Cherenkov",0,kFALSE,
+                    0,0,"Special",kspe+50);
+
+  pdgDB->AddParticle("FeedbackPhoton","FeedbackPhoton",0,kFALSE,
+                    0,0,"Special",kspe+51);
+
+
+  // To do: define the PDG database extension
+  // in a common part.
+  //
+  // AliMC::ExtendPDGDatabase(); 
+  //
+  // end of "common" implementation
+  // ======
+
+  // 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." << endl;
+  //fParticleNameMap.PrintAll();
+  //fParticlePDGMap.PrintAll();
+}    
+
+void TG4PhysicsManager::SwitchIsCutVector(TG3Cut 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 TG4PhysicsManager::SwitchIsFlagVector(TG3Flag flag)
+{
+// Updates the vector of booleans (fIsFlagVector) for the specified flag.
+// ---
+
+  switch (flag) {
+    case kPAIR: 
+           // gamma
+           (*fIsFlagVector)[kGamma] = true; 
+           break;
+    case kCOMP:
+           // gamma
+           (*fIsFlagVector)[kGamma] = true; 
+          break;
+    case kPHOT:
+           // gamma
+           (*fIsFlagVector)[kGamma] = true; 
+          break;
+    case kPFIS:
+           // gamma
+           (*fIsFlagVector)[kGamma] = true; 
+          break;
+    case kDRAY:        
+           // all charged particles
+           (*fIsFlagVector)[kElectron] = true; 
+           (*fIsFlagVector)[kEplus] = true; 
+           (*fIsFlagVector)[kChargedHadron] = true; 
+           (*fIsFlagVector)[kMuon] = true; 
+          break;
+    case kANNI:
+          // e+ only
+           (*fIsFlagVector)[kEplus] = true; 
+          break;
+    case kBREM:
+          // e-/e+, muons
+           (*fIsFlagVector)[kElectron] = true; 
+           (*fIsFlagVector)[kEplus] = true; 
+           (*fIsFlagVector)[kMuon] = true; 
+          break;
+    case kHADR:
+          // hadrons
+           (*fIsFlagVector)[kNeutralHadron] = true; 
+           (*fIsFlagVector)[kChargedHadron] = true; 
+          break;
+    case kMUNU:
+           // muons
+           (*fIsFlagVector)[kMuon] = true; 
+          break;
+    case kDCAY:
+           // any
+           (*fIsFlagVector)[kAny] = true; 
+          break;
+    case kLOSS:
+           // all charged particles
+           (*fIsFlagVector)[kElectron] = true; 
+           (*fIsFlagVector)[kEplus] = true; 
+           (*fIsFlagVector)[kChargedHadron] = true; 
+           (*fIsFlagVector)[kMuon] = true; 
+          break;
+    case kMULS:
+           // all charged particles
+           (*fIsFlagVector)[kElectron] = true; 
+           (*fIsFlagVector)[kEplus] = true; 
+           (*fIsFlagVector)[kChargedHadron] = true; 
+           (*fIsFlagVector)[kMuon] = true; 
+          break;
+    default:
+          break;
+  }
+}
+
+TG3Cut TG4PhysicsManager::GetG3Cut(G4String cutName)
+{
+// Retrieves corresponding TG3Cut 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;
+}
+
+TG3Flag TG4PhysicsManager::GetG3Flag(G4String flagName)
+{
+// Retrieves corresponding TG3Flag constant from the flagName.
+// ---
+
+  if      (flagName == fG3FlagNameVector[kPAIR]) return kPAIR;
+  else if (flagName == fG3FlagNameVector[kCOMP]) return kCOMP;
+  else if (flagName == fG3FlagNameVector[kPHOT]) return kPHOT;
+  else if (flagName == fG3FlagNameVector[kPFIS]) return kPFIS;
+  else if (flagName == fG3FlagNameVector[kDRAY]) return kDRAY;
+  else if (flagName == fG3FlagNameVector[kANNI]) return kANNI;
+  else if (flagName == fG3FlagNameVector[kBREM]) return kBREM;
+  else if (flagName == fG3FlagNameVector[kHADR]) return kHADR;
+  else if (flagName == fG3FlagNameVector[kMUNU]) return kMUNU;
+  else if (flagName == fG3FlagNameVector[kDCAY]) return kDCAY;
+  else if (flagName == fG3FlagNameVector[kLOSS]) return kLOSS;
+  else if (flagName == fG3FlagNameVector[kMULS]) return kMULS;
+  else return kNoG3Flags;
+}
+
+// public methods
+
+void TG4PhysicsManager::BuildPhysics()
+{
+// Empty function - not needed in G4.
+// (Physics is built within /run/initialize.)
+
+  TG4Globals::Warning(
+    "TG4PhysicsManager::BuildPhysics: is empty function in G4 MC.");
+}    
+
+void TG4PhysicsManager::SetCut(const char* cutName, Float_t cutValue)
+{
+// Sets the specified cut.
+// ---
+
+  if (fLock) LockException();
+  TG3Cut g3Cut = GetG3Cut(cutName);
+  if (g3Cut != kNoG3Cuts)
+    SetCut(g3Cut, cutValue);
+  else {   
+    G4String text = "TG4PhysicsManager::SetCut:\n";
+    text = text + "    Parameter " + cutName;
+    text = text + " is not implemented.";
+    TG4Globals::Warning(text);
+  }  
+}  
+  
+void TG4PhysicsManager::SetProcess(const char* flagName, Int_t flagValue)
+{
+// Sets the specified process control.
+// ---
+
+  if (fLock) LockException();
+  TG3Flag g3Flag = GetG3Flag(flagName);
+  if (g3Flag != kNoG3Flags)
+    SetProcess(g3Flag, flagValue);
+  else {   
+    G4String text = "TG4PhysicsManager::SetProcess:\n";
+    text = text + "    Parameter " + flagName;
+    text = text + " is not implemented.";
+    TG4Globals::Warning(text);
+  }  
+}  
+
+void TG4PhysicsManager::SetProcessActivation()
+{
+// (In)Activates built processes according
+// to the setup in fFlagVector.
+// ---
+
+  if (fPhysicsList) {
+    // temporarily excluded
+    // fPhysicsList->SetProcessActivation();
+  }  
+  else {
+    G4String text = "TG4PhysicsManager::SetProcessActivation:\n";
+    text = text +   "   There is no physics list set.";
+    TG4Globals::Exception(text);
+  }
+}       
+
+G4int TG4PhysicsManager::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;  
+}  
+     
+G4bool TG4PhysicsManager::CheckCutWithCutVector(G4String name, 
+                             G4double value, TG3Cut& cut)
+{
+// Retrieves corresponding TG3Cut 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 -> TG3Cut
+  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 TG4PhysicsManager::CheckFlagWithFlagVector(G4String name, 
+                              G4double value, TG3Flag& flag)
+{
+// Retrieves corresponding TG3Flag from the name and 
+// in case the value is different from the value in flagVector
+// sets true the value of the fIsFlagVector element 
+// corresponding to this flag and returns true; 
+// returns false otherwise.
+// ---
+
+  // convert flag name -> TG3Flag
+  flag = GetG3Flag(name);
+
+  // set switch vector element only if the value
+  // is different from the value in flagVector
+  if (flag !=kNoG3Flags) {
+    if (!(fFlagVector) || (abs(value - (*fFlagVector)[flag]) > 0.01)) {
+      SwitchIsFlagVector(flag);      
+      return true;
+    }  
+    else return false;  
+  }                     
+  return false;
+}
+
+G4bool TG4PhysicsManager::CheckCutWithG3Defaults(G4String name, 
+                              G4double value, TG3Cut& cut)
+{
+// Retrieves corresponding TG3Cut 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 -> TG3Cut
+  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 TG4PhysicsManager::CheckFlagWithG3Defaults(G4String name, 
+                              G4double value, TG3Flag& flag)
+{
+// Retrieves corresponding TG3Flag from the name and 
+// in case the value is different from the G3 default value
+// sets true the value of the SwitchFlagVector element 
+// corresponding to this flag and returns true; 
+// returns false otherwise.
+// ---
+
+  // convert flag name -> TG3Flag
+  flag = GetG3Flag(name);
+
+  // set switch vector element only if the value
+  // is different from G3 default
+  if (flag !=kNoG3Flags) {
+    if (!TG4G3Defaults::IsDefaultFlag(flag, value)) {
+      SwitchIsFlagVector(flag);      
+      return true;
+    }  
+    else return false;  
+  }                     
+  return false;
+}
+
+void TG4PhysicsManager::SetG3DefaultCuts() 
+{
+// Sets G3 default values of kinetic energy cuts.
+// ---
+
+  if (fLock) LockException();
+  if (!fCutVector) {
+    // create vector of kinetic energy cut values  
+    fCutVector = new TG4CutVector();
+  }  
+  fCutVector->SetG3Defaults();
+}
+
+void TG4PhysicsManager::SetG3DefaultProcesses()
+{
+// Sets G3 default values of control process flags.
+// ---
+
+  if (fLock) LockException();
+  if (!fFlagVector) {
+    // create vector of control process flag values
+    fFlagVector = new TG4FlagVector;
+  }  
+  fFlagVector->SetG3Defaults();
+}  
+
+G4bool TG4PhysicsManager::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 TG4PhysicsManager::IsSpecialFlags() const
+{
+// Returns true if any special flag value is set.
+// ---
+
+  for (G4int i=0; i<kNofParticlesWSP; i++)
+  {  if ((*fIsFlagVector)[i]) return true; }
+
+  return false;
+}
+
+TG3ParticleWSP TG4PhysicsManager::GetG3ParticleWSP(
+                                  G4ParticleDefinition* particle) const 
+{
+// Returns TG3ParticleWSP constant for the specified particle.
+// (See TG3ParticleWSP.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 TG4PhysicsManager::GetG3ParticleWSPName(G4int particleWSP,
+                                             G4String& name) const 
+{
+// Fills the passed name with the name/type of particle specified
+// by TG3ParticleWSP constant.
+// (See TG3ParticleWSP.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 = "TG4PhysicsList::GetG3ParticleWSPName:\n";
+      text = text + "   Wrong particleWSP."; 
+      TG4Globals::Exception(text);
+      break;      
+  }
+}  
+
diff --git a/TGeant4/TG4PhysicsManager.h b/TGeant4/TG4PhysicsManager.h
new file mode 100644 (file)
index 0000000..b04c6f5
--- /dev/null
@@ -0,0 +1,151 @@
+// $Id$
+// Category: physics
+//
+// Geant4 implementation of the MonteCarlo interface methods                    
+// for building Geant4 physics and access to it
+
+#ifndef TG4_PHYSICS_MANAGER_H
+#define TG4_PHYSICS_MANAGER_H
+
+#include "TG4Globals.h"
+#include "TG4NameMap.h"
+#include "TG4IntMap.h"
+#include "TG3Cut.h"
+#include "TG3Flag.h"
+#include "TG3ParticleWSP.h"
+
+#include <globals.hh>
+
+#include <Rtypes.h>
+
+class TG4CutVector;
+class TG4FlagVector;
+class TG4PhysicsList;
+
+class G4ParticleDefinition;
+
+class TG4PhysicsManager
+{
+  public:
+    TG4PhysicsManager();
+    // --> protected
+    // TG4PhysicsManager(const TG4PhysicsManager& right);
+    virtual ~TG4PhysicsManager();
+
+    // static access method
+    static TG4PhysicsManager* Instance();
+        
+    // methods
+    void BuildPhysics();
+
+    // set methods
+    void SetCut(const char* cutName, Float_t cutValue);
+    void SetProcess(const char* flagName, Int_t flagValue);
+    Float_t Xsec(char* reac, Float_t energy, Int_t part, Int_t mate);
+        // particle table usage         
+    Int_t IdFromPDG(Int_t pdgID) const;
+    Int_t PDGFromId(Int_t mcID) const;
+    void  DefineParticles();      
+    
+    //
+    // methods for Geant4 only 
+    //
+
+    void Lock();     
+    void SetProcessActivation();  
+    G4int GetPDGEncodingFast(G4ParticleDefinition* particle);
+    G4bool CheckCutWithCutVector(
+             G4String name, G4double value, TG3Cut& cut);   
+    G4bool CheckFlagWithFlagVector(
+             G4String name, G4double value, TG3Flag& flag); 
+    G4bool CheckCutWithG3Defaults(
+             G4String name, G4double value, TG3Cut& cut); 
+    G4bool CheckFlagWithG3Defaults(
+             G4String name, G4double value, TG3Flag& flag); 
+
+    // set methods
+    void SetPhysicsList(TG4PhysicsList* physicsList);
+    void SetG3DefaultCuts();                    
+    void SetG3DefaultProcesses();               
+    
+    // get methods
+    G4bool IsLock() const;   
+    G4bool IsSpecialCuts() const;
+    G4bool IsSpecialFlags() const;
+    TG4CutVector*  GetCutVector() const;    
+    TG4FlagVector* GetFlagVector() const;   
+    TG4boolVector* GetIsCutVector() const;
+    TG4boolVector* GetIsFlagVector() const;
+    TG3ParticleWSP GetG3ParticleWSP(G4ParticleDefinition* particle) const;
+    void GetG3ParticleWSPName(G4int particleWSP, G4String& name) const;
+    
+  protected:
+    TG4PhysicsManager(const TG4PhysicsManager& right);
+
+    // operators
+    TG4PhysicsManager& operator=(const TG4PhysicsManager& right);
+
+  private:
+    // methods
+    void LockException() const;
+    G4int GetPDGEncoding(G4ParticleDefinition* particle);
+    G4int GetPDGEncoding(G4String particleName);
+
+    // set methods
+    void SetCut(TG3Cut cut, G4double cutValue);
+    void SetProcess(TG3Flag flag, G4int flagValue);
+    void SwitchIsCutVector(TG3Cut cut);
+    void SwitchIsFlagVector(TG3Flag flag);
+
+    // get methods
+    TG3Cut  GetG3Cut(G4String cutName);
+    TG3Flag GetG3Flag(G4String flagName);
+
+    // static data members
+    static TG4PhysicsManager*  fgInstance; //this instance
+    
+    // data members
+    G4bool           fLock;         //if true: cut/flag vectors cannot be modified
+    TG4PhysicsList*  fPhysicsList;  //physics list
+    TG4CutVector*    fCutVector;    //TG4CutVector  
+    TG4FlagVector*   fFlagVector;   //TG4FlagVector
+    TG4boolVector*   fIsCutVector;  //vector of booleans which cuts are set
+    TG4boolVector*   fIsFlagVector; //vector of booleans which flags are set
+    TG4StringVector  fG3CutNameVector;  //vector of cut parameters names     
+    TG4StringVector  fG3FlagNameVector; //vector of process control parameters
+                                        //names   
+    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 TG4PhysicsManager* TG4PhysicsManager::Instance() 
+{ return fgInstance; }
+
+inline void TG4PhysicsManager::Lock() 
+{ fLock = true; }
+
+inline void TG4PhysicsManager::SetPhysicsList(TG4PhysicsList* physicsList)
+{ fPhysicsList = physicsList; }
+
+inline G4bool TG4PhysicsManager::IsLock() const
+{ return fLock; }
+
+inline TG4CutVector* TG4PhysicsManager::GetCutVector() const
+{ return fCutVector; }
+
+inline TG4FlagVector* TG4PhysicsManager::GetFlagVector() const
+{ return fFlagVector; }
+
+inline TG4boolVector* TG4PhysicsManager::GetIsCutVector() const
+{ return fIsCutVector; }
+
+inline TG4boolVector* TG4PhysicsManager::GetIsFlagVector() const
+{ return fIsFlagVector; }
+
+#endif //TG4_PHYSICS_MANAGER_H
+
diff --git a/TGeant4/TG4RunManager.cxx b/TGeant4/TG4RunManager.cxx
new file mode 100644 (file)
index 0000000..ff8fd70
--- /dev/null
@@ -0,0 +1,340 @@
+// $Id$
+// Category: run
+//
+// See the class description in the header file.
+
+#include "TG4RunManager.h"
+#include "TG4RunMessenger.h"
+#include "TG4VRunConfiguration.h"
+#include "TGeant4.h"
+#include "TG4Globals.h"
+#include "TG4GeometryManager.h"
+#include "TG4PhysicsManager.h"
+//#include "TG4StepManager.h"
+
+#include <G4RunManager.hh>
+#include <G4StateManager.hh>
+#include <G4UIsession.hh>
+#include <G4UImanager.hh>
+#include <G4UIterminal.hh>
+#include <G4UIXm.hh>
+#ifdef G4UI_USE_WO
+#include <G4UIWo.hh>
+#endif
+#ifdef G4UI_USE_GAG
+#include <G4UIGAG.hh>
+#endif
+#include <globals.hh>
+
+#include <TRint.h>
+#include <TROOT.h> 
+#include <TCint.h> 
+
+TG4RunManager* TG4RunManager::fgInstance = 0;
+
+TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration, 
+                             int argc, char** argv)              
+  : fRunConfiguration(runConfiguration),
+    fGeantUISession(0),
+    fRootUISession(0),
+    fRootUIOwner(false),
+    fARGC(argc),
+    fARGV(argv)
+  
+{
+// 
+  if (fgInstance) {
+    TG4Globals::Exception(
+      "TG4RunManager: attempt to create two instances of singleton.");
+  };
+      
+  if (!fRunConfiguration) {
+    TG4Globals::Exception(
+      "TG4RunManager: attempt to create instance without runConfiguration.");
+  };
+      
+  fgInstance = this;
+  
+  // create and configure geant4 run manager
+  fRunManager =  new G4RunManager();
+  fRunConfiguration->ConfigureRunManager(fRunManager);
+  // add verbose level
+  //G4cout << "G4RunManager has been created." << endl;
+
+  // create geant4 UI
+  CreateGeantUI();
+      // must be created before TG4VisManager::Initialize()
+      // (that is invoked in TGeant4 constructor)
+
+  // create root UI
+  CreateRootUI();
+
+  // messenger
+  fMessenger = new TG4RunMessenger(this);
+}
+
+TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
+  : fRunConfiguration(runConfiguration),
+    fGeantUISession(0),
+    fRootUISession(0),
+    fRootUIOwner(false),
+    fARGC(0),
+    fARGV(0)
+  
+{
+//
+  if (fgInstance) {
+    TG4Globals::Exception(
+      "TG4RunManager: attempt to create two instances of singleton.");
+  };
+      
+  if (!fRunConfiguration) {
+    TG4Globals::Exception(
+      "TG4RunManager: attempt to create instance without runConfiguration.");
+  };
+      
+  fgInstance = this;
+  
+  // set primary UI
+  fRootUISession = gROOT->GetApplication();
+  if (fRootUISession) {
+    fARGC = fRootUISession->Argc();
+    fARGV = fRootUISession->Argv();
+  }
+
+  // create and configure geant4 run manager
+  fRunManager =  new G4RunManager();
+  fRunConfiguration->ConfigureRunManager(fRunManager);
+  // add verbose level
+  //G4cout << "G4RunManager has been created." << endl;
+
+  // create geant4 UI
+  CreateGeantUI();
+      // must be created before TG4VisManager::Initialize()
+      // (that is invoked in TGeant4 constructor)
+
+  // create root UI
+  CreateRootUI();
+
+  // messenger
+  fMessenger = new TG4RunMessenger(this);
+}
+
+TG4RunManager::TG4RunManager() {
+//
+}
+
+TG4RunManager::TG4RunManager(const TG4RunManager& right) {
+// 
+  TG4Globals::Exception(
+    "Attempt to copy TG4RunManager singleton.");
+}
+
+TG4RunManager::~TG4RunManager() {
+//  
+  delete fRunConfiguration;
+  delete fRunManager;
+  delete fGeantUISession;
+  if (fRootUIOwner) delete fRootUISession;
+  delete fMessenger;
+}
+
+// operators
+
+TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "Attempt to assign TG4RunManager singleton.");
+    
+  return *this;  
+}    
+
+// private methods
+
+void TG4RunManager::CreateGeantUI()
+{
+// Creates interactive Geant4.
+// ---
+
+  if (!fGeantUISession)
+  {
+    // create geant4 UI
+    G4UImanager* pUI = G4UImanager::GetUIpointer();  
+    if (fARGC == 1) {
+#ifdef G4UI_USE_GAG
+      fGeantUISession = new G4UIGAG();
+#else      
+      fGeantUISession = new G4UIterminal(); 
+#endif      
+    }  
+    else if (strcmp (fARGV[1], "dumb") == 0) {
+      fGeantUISession = new G4UIterminal(); 
+    }
+#ifdef G4UI_USE_WO
+    else if (strcmp (fARGV[1], "Wo") == 0) {
+      fGeantUISession = new G4UIWo(fARGC, fARGV); 
+    }
+#endif
+#ifdef G4UI_USE_XM
+    else if (strcmp (fARGV[1], "Xm") == 0) {
+      fGeantUISession = new G4UIXm(fARGC, fARGV); 
+    }
+#endif
+#ifdef G4UI_USE_XAW
+    else if (strcmp (fARGV[1], "Xaw") == 0) {
+      fGeantUISession = new G4UIXaw(fARGC, fARGV); 
+    }
+#endif 
+#ifdef G4UI_USE_GAG
+    else if (strcmp (fARGV[1], "GAG") == 0) {
+      fGeantUISession = new G4UIGAG (); 
+    }
+#endif 
+    if (fGeantUISession) {   
+      pUI->SetSession(fGeantUISession); 
+    }
+  }
+}
+
+void TG4RunManager::CreateRootUI()
+{
+// Creates interactive Root.
+// ---
+
+  if (!fRootUISession) 
+  {
+    // create session if it does not exist  
+    fRootUISession = new TRint("aliroot", 0, 0, 0, 0);
+
+    // set ownership of Root UI
+    fRootUIOwner = true;
+  }
+}
+
+// public methods
+
+void TG4RunManager::Initialize()
+{
+// Initializes G4.
+// ---
+
+  // initialize Geant4 
+  fRunManager->Initialize();
+  
+  // activate/inactivate physics processes
+  // (this operation is not allowed in "Init" phase)
+  TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
+  physicsManager->SetProcessActivation();
+}
+
+void TG4RunManager::ProcessEvent()
+{
+// Not yet implemented.
+// ---
+
+  TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
+}
+    
+void TG4RunManager::ProcessRun(G4int nofEvents)
+{
+// Processes Geant4 run.
+// ---
+
+  fRunManager->BeamOn(nofEvents); 
+}
+    
+void TG4RunManager::StartGeantUI()
+{ 
+// Starts interactive/batch Geant4.
+// ---
+
+  if (!fGeantUISession) CreateGeantUI();
+  if (fGeantUISession) {  
+    // interactive session
+    G4cout << "Welcome back in Geant4" << endl;
+    fGeantUISession->SessionStart();
+    G4cout << "Welcome back in Root" << endl;  
+  }
+  else {
+    // execute Geant4 macro if file is specified as an argument 
+    G4String fileName = fARGV[1];
+    ProcessGeantMacro(fileName);
+  }
+}
+
+void TG4RunManager::StartRootUI()
+{
+// Starts interactive Root.
+// ---
+
+  if (!fRootUISession) CreateRootUI();
+  if (fRootUISession) { 
+    G4cout << "Welcome back in Root" << endl;
+    fRootUISession->Run(kTRUE);
+    G4cout << "Welcome back in Geant4" << endl;  
+  }
+}
+void TG4RunManager::ProcessGeantMacro(G4String macroName)
+{
+// Processes Geant4 macro.
+// ---
+
+  G4String command = "/control/execute " + macroName;
+  ProcessGeantCommand(command);
+}
+void TG4RunManager::ProcessRootMacro(G4String macroName)
+{
+// Processes Root macro.
+// ---
+
+  // load macro file
+  G4String macroFile = macroName;
+  macroFile.append(".C");
+  gROOT->LoadMacro(macroFile);
+
+  // execute macro function
+  G4String macroFunction = macroName;
+  macroFunction.append("()");
+  gInterpreter->ProcessLine(macroFunction);
+}
+void TG4RunManager::ProcessGeantCommand(G4String command)
+{
+// Processes Geant4 command.
+// ---
+
+  G4UImanager* pUI = G4UImanager::GetUIpointer();  
+  pUI->ApplyCommand(command);
+}
+
+void TG4RunManager::ProcessRootCommand(G4String command)
+{
+// Processes Root command.
+// ---
+
+  gInterpreter->ProcessLine(command);
+}
+
+void TG4RunManager::UseG3Defaults() 
+{
+// Controls G3 defaults usage.
+// ---
+
+  TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
+  TG4PhysicsManager::Instance()->SetG3DefaultCuts();
+  TG4PhysicsManager::Instance()->SetG3DefaultProcesses();
+}
+
+Int_t TG4RunManager::CurrentEvent() const
+{
+// Returns the number of the current event.
+// ---
+
+  G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();
+  return eventID;
+}
diff --git a/TGeant4/TG4RunManager.h b/TGeant4/TG4RunManager.h
new file mode 100644 (file)
index 0000000..9f11b93
--- /dev/null
@@ -0,0 +1,91 @@
+// $Id$
+// Category: run
+//
+// Geant4 implementation of the MonteCarlo interface methods                    
+// for access to Geant4 at run level
+
+#ifndef TG4_RUN_MANAGER_H
+#define TG4_RUN_MANAGER_H
+
+#include <globals.hh>
+
+#include <Rtypes.h>
+
+class AliMC;
+
+class TG4VRunConfiguration;
+class TG4RunMessenger;
+
+class G4RunManager;
+class G4UIsession;
+
+class TApplication;
+
+class TG4RunManager
+{
+  public:
+    TG4RunManager(TG4VRunConfiguration* configuration, int argc, char** argv);
+    TG4RunManager(TG4VRunConfiguration* configuration);
+    // --> protected
+    // TG4RunManager();
+    // TG4RunManager(const TG4RunManager& right);
+    virtual ~TG4RunManager();
+
+    // static access method
+    static TG4RunManager* Instance();
+
+    // methods
+    void Initialize();
+    void ProcessEvent();
+    void ProcessRun(G4int nofEvents);
+
+    // get methods
+    Int_t CurrentEvent() const;
+
+    //
+    // methods for Geant4 only 
+    //
+    void StartGeantUI();
+    void StartRootUI();
+    void ProcessGeantMacro(G4String macroName);
+    void ProcessRootMacro(G4String macroName);
+    void ProcessGeantCommand(G4String command);
+    void ProcessRootCommand(G4String command);
+    void UseG3Defaults();      
+
+
+  protected:
+    TG4RunManager();
+    TG4RunManager(const TG4RunManager& right);
+
+    // operators
+    TG4RunManager& operator=(const TG4RunManager& right);
+   
+    // data members    
+    G4RunManager*     fRunManager; //G4RunManager
+    TG4RunMessenger*  fMessenger;  //messenger
+
+  private:
+    // methods
+    void CreateGeantUI();
+    void CreateRootUI();
+    Text_t* G4StringToTextT(G4String string) const;
+    
+    // static data members
+    static TG4RunManager*  fgInstance; //this instance
+    
+    // data members    
+    TG4VRunConfiguration*  fRunConfiguration; //TG4VRunConfiguration
+    G4UIsession*           fGeantUISession;   //G4 UI 
+    TApplication*          fRootUISession;    //Root UI 
+    G4bool                 fRootUIOwner;      //ownership of Root UI
+    G4int                  fARGC;             //argc 
+    char**                 fARGV;             //argv
+};
+
+// inline methods
+inline TG4RunManager* TG4RunManager::Instance() 
+{ return fgInstance; }
+
+#endif //TG4_RUN_MANAGER_H
+
diff --git a/TGeant4/TG4RunMessenger.cxx b/TGeant4/TG4RunMessenger.cxx
new file mode 100644 (file)
index 0000000..5566cc0
--- /dev/null
@@ -0,0 +1,92 @@
+// $Id$
+// Category: run
+//
+// See the class description in the header file.
+
+#include "TG4RunMessenger.h"
+#include "TG4RunManager.h"
+#include "TG4Globals.h"
+#include "TG4UICmdWithAComplexString.h"
+
+#include <G4UIdirectory.hh>
+#include <G4UIcmdWithoutParameter.hh>
+#include <G4UIcmdWithAString.hh>
+
+TG4RunMessenger::TG4RunMessenger(TG4RunManager* runManager)
+  : fRunManager(runManager)
+{ 
+//
+  fDirectory = new G4UIdirectory("/g4mc/");
+  fDirectory->SetGuidance("TGeant4 control commands.");
+
+  fRootCmd = new G4UIcmdWithoutParameter("/g4mc/root", this);
+  fRootCmd->SetGuidance("Switch to Root interactive shell.");
+  fRootCmd->AvailableForStates(PreInit, Init, Idle, GeomClosed, EventProc);
+
+  fRootMacroCmd = new G4UIcmdWithAString("/g4mc/rootMacro", this);
+  fRootMacroCmd->SetGuidance("Process Root macro with given name (from file name.C)");
+  fRootMacroCmd->SetParameterName("macroName", true);
+  fRootMacroCmd->AvailableForStates(PreInit, Init, Idle, GeomClosed, EventProc);
+
+  fRootCommandCmd = new TG4UICmdWithAComplexString("/g4mc/rootCmd", this);
+  fRootCommandCmd->SetGuidance("Process Root command");
+  fRootCommandCmd->SetParameterName("command", false);
+  fRootCommandCmd->SetDefaultValue(" ");
+  fRootCommandCmd->AvailableForStates(PreInit, Init, Idle, GeomClosed, EventProc);
+
+  fG3DefaultsCmd = new G4UIcmdWithoutParameter("/g4mc/g3Defaults", this);
+  fG3DefaultsCmd->SetGuidance("Set G3 default parameters (cut values,");
+  fG3DefaultsCmd->SetGuidance("tracking media max step values, ...)");
+  fG3DefaultsCmd->AvailableForStates(PreInit);
+}
+
+TG4RunMessenger::TG4RunMessenger(){
+//
+} 
+
+TG4RunMessenger::TG4RunMessenger(const TG4RunMessenger& right) {
+// 
+  TG4Globals::Exception("TG4RunMessenger is protected from copying.");
+}
+
+TG4RunMessenger::~TG4RunMessenger() {
+//
+  delete fDirectory;
+  delete fRootCmd;
+  delete fRootMacroCmd;
+  delete fRootCommandCmd;
+  delete fG3DefaultsCmd;
+}
+
+// operators
+
+TG4RunMessenger& TG4RunMessenger::operator=(const TG4RunMessenger& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception("TG4RunMessenger is protected from assigning.");
+    
+  return *this;  
+}    
+          
+// public methods
+
+void TG4RunMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
+{ 
+// Applies command to the associated object.
+// ---
+
+  if (command == fRootCmd) {
+    fRunManager->StartRootUI(); 
+  }
+  else if (command == fRootMacroCmd) {  
+    fRunManager->ProcessRootMacro(newValue); 
+  }
+  else if (command == fRootCommandCmd) {
+    fRunManager->ProcessRootCommand(newValue); 
+  }
+  else if (command == fG3DefaultsCmd) {
+    fRunManager->UseG3Defaults(); 
+  }
+}
diff --git a/TGeant4/TG4RunMessenger.h b/TGeant4/TG4RunMessenger.h
new file mode 100644 (file)
index 0000000..a279950
--- /dev/null
@@ -0,0 +1,49 @@
+// $Id$
+// Category: run
+//
+// Messenger class that defines commands for TG4RunManager
+
+#ifndef TG4_RUN_MESSENGER_H
+#define TG4_RUN_MESSENGER_H 
+
+#include <G4UImessenger.hh>
+#include <globals.hh>
+
+class TG4RunManager;
+class TG4UICmdWithAComplexString;
+
+class G4UIdirectory;
+class G4UIcmdWithoutParameter;
+class G4UIcmdWithAString;
+
+class TG4RunMessenger: public G4UImessenger
+{
+  public:
+    TG4RunMessenger(TG4RunManager* runManager);
+    // protected
+    // TG4RunMessenger();
+    // TG4RunMessenger(const TG4RunMessenger& right);
+    virtual ~TG4RunMessenger();
+   
+    // methods 
+    virtual void SetNewValue(G4UIcommand* command, G4String string);
+    
+  protected:
+    TG4RunMessenger();  
+    TG4RunMessenger(const TG4RunMessenger& right);
+
+    // operators
+    TG4RunMessenger& operator=(const TG4RunMessenger& right);
+
+  private:
+    // data members
+    TG4RunManager*  fRunManager; //associated class   
+    G4UIdirectory*  fDirectory;  //command directory
+
+    G4UIcmdWithoutParameter*    fRootCmd;        //command: root
+    G4UIcmdWithAString*         fRootMacroCmd;   //command: rootMacro 
+    TG4UICmdWithAComplexString* fRootCommandCmd; //command: rootCmd 
+    G4UIcmdWithoutParameter*    fG3DefaultsCmd;  //command: g3Defaults   
+};
+
+#endif //TG4_RUN_MESSENGER_H
diff --git a/TGeant4/TG4SpecialCuts.cxx b/TGeant4/TG4SpecialCuts.cxx
new file mode 100644 (file)
index 0000000..9f3a5a9
--- /dev/null
@@ -0,0 +1,173 @@
+// $Id$
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4SpecialCuts.h"
+#include "TG4CutVector.h"
+#include "TG4Limits.h"
+
+#include <G4UserLimits.hh>
+
+#include <G4EnergyLossTables.hh>
+
+TG4SpecialCuts::TG4SpecialCuts(TG3ParticleWSP particle, TG4CutVector* cutVector,
+                               const G4String& processName)
+  : G4UserSpecialCuts(processName),
+    fCutVector(cutVector)
+{
+//
+  switch (particle) {
+    case kGamma:
+      fPtrMinEkineInCutVector = &TG4CutVector::GetMinEkineForGamma;
+      fPtrMinEkineInLimits = &TG4Limits::GetMinEkineForGamma;
+      break;
+    case kElectron: case kEplus:  
+      fPtrMinEkineInCutVector = &TG4CutVector::GetMinEkineForElectron;
+      fPtrMinEkineInLimits = &TG4Limits::GetMinEkineForElectron;
+      break;
+    case kChargedHadron:  
+      fPtrMinEkineInCutVector = &TG4CutVector::GetMinEkineForHadron;
+      fPtrMinEkineInLimits = &TG4Limits::GetMinEkineForHadron;
+      break;
+    case kNeutralHadron:  
+      fPtrMinEkineInCutVector = &TG4CutVector::GetMinEkineForNeutralHadron;
+      fPtrMinEkineInLimits = &TG4Limits::GetMinEkineForNeutralHadron;
+      break;
+    case kMuon:  
+      fPtrMinEkineInCutVector = &TG4CutVector::GetMinEkineForMuon;
+      fPtrMinEkineInLimits = &TG4Limits::GetMinEkineForMuon;
+      break;
+    case kAny:
+      fPtrMinEkineInCutVector = &TG4CutVector::GetMinEkineForOther;
+      fPtrMinEkineInLimits = &TG4Limits::GetMinEkineForOther;
+      break;
+    case kNofParticlesWSP:
+      TG4Globals::Exception("TG4SpecialCuts: Wrong particle specification.");
+      break;  
+  }
+}
+
+TG4SpecialCuts::TG4SpecialCuts() {
+//
+}
+
+TG4SpecialCuts::TG4SpecialCuts(const TG4SpecialCuts& right) {
+// 
+  TG4Globals::Exception(
+    "TG4SpecialCuts is protected from copying.");
+}
+
+TG4SpecialCuts::~TG4SpecialCuts() {
+//
+}
+
+// operators
+
+TG4SpecialCuts& TG4SpecialCuts::operator=(const TG4SpecialCuts& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "TG4SpecialCuts is protected from assigning.");
+    
+  return *this;  
+}    
+          
+// public methods
+
+G4double TG4SpecialCuts::PostStepGetPhysicalInteractionLength(
+                           const G4Track& track, G4double previousStepSize,
+                          G4ForceCondition* condition)
+{
+// Returns the Step-size (actual length) which is allowed 
+// by this process.
+// ---
+
+  // set condition
+  *condition = NotForced;
+
+  G4double proposedStep = DBL_MAX;
+  G4UserLimits* limits 
+    = track.GetVolume()->GetLogicalVolume()->GetUserLimits();
+  if (limits) { 
+    // max track length
+    proposedStep 
+      = (limits->GetUserMaxTrackLength(track) - track.GetTrackLength());
+    if (proposedStep < 0.) return 0.;
+
+    // max time limit
+    G4double beta 
+      = (track.GetDynamicParticle()->GetTotalMomentum()) /
+        (track.GetTotalEnergy());
+    G4double time
+      = (limits->GetUserMaxTime(track) - track.GetGlobalTime());
+    G4double temp = beta*c_light*time;
+    if (temp < 0.) return 0.;
+    if (proposedStep > temp) proposedStep = temp;
+
+    // min remaining range
+    G4ParticleDefinition* particle = track.GetDefinition();
+    G4double kinEnergy = track.GetKineticEnergy();
+    G4Material* material = track.GetMaterial();
+    G4double rangeNow 
+      = G4EnergyLossTables::GetRange(particle, kinEnergy, material);
+    temp = (rangeNow - limits->GetUserMinRange(track));
+    if (temp < 0.) return 0.;
+    if (proposedStep > temp) proposedStep = temp;
+
+    // min kinetic energy (from limits)
+    // the kin energy cut can be applied only in case
+    // G4EnergyLossTables are defined for the particle
+    if (G4EnergyLossTables::GetDEDXTable(particle)) {
+      TG4Limits* tg4Limits = dynamic_cast<TG4Limits*>(limits);
+      if (!tg4Limits) {
+        G4String text = "TG4SpecialCuts::PostStepGetPhysicalInteractionLength:\n";
+        text = text + "    Unknown limits type.";
+        TG4Globals::Exception(text);
+      }  
+      G4double minEkine 
+        = (tg4Limits->*fPtrMinEkineInLimits)(track);
+      G4double minR 
+        = G4EnergyLossTables::GetRange(particle, minEkine, material);
+      temp = rangeNow - minR;
+      if (temp < 0.) return 0.;
+      if (proposedStep > temp) proposedStep = temp;  
+    }  
+
+  }
+  else if (fCutVector) {
+    // min kinetic energy (from cut vector)
+    // the kin energy cut can be applied only in case
+    // G4EnergyLossTables are defined for the particle
+    G4ParticleDefinition* particle = track.GetDefinition();
+    if (G4EnergyLossTables::GetDEDXTable(particle)) {
+      G4double kinEnergy = track.GetKineticEnergy();
+      G4Material* material = track.GetMaterial();
+      G4double rangeNow 
+        = G4EnergyLossTables::GetRange(particle, kinEnergy, material);
+      G4double minEkine 
+        = (fCutVector->*fPtrMinEkineInCutVector)(track);
+      G4double minR 
+        = G4EnergyLossTables::GetRange(particle, minEkine, material);
+      G4double temp = rangeNow - minR;
+      if (temp < 0.) return 0.;
+      if (proposedStep > temp) proposedStep = temp;  
+    }  
+  }   
+  return proposedStep;
+}
+
+G4VParticleChange* TG4SpecialCuts::PostStepDoIt(const G4Track& track, 
+                                                const G4Step&)
+{
+// Kills the current particle, if requested by G4UserLimits.
+// ---
+  aParticleChange.Initialize(track);
+  aParticleChange.SetEnergyChange(0.) ;
+  aParticleChange.SetLocalEnergyDeposit(track.GetKineticEnergy()) ;
+  aParticleChange.SetStatusChange(fStopAndKill);
+  return &aParticleChange;
+}
diff --git a/TGeant4/TG4SpecialCuts.h b/TGeant4/TG4SpecialCuts.h
new file mode 100644 (file)
index 0000000..10ea8e9
--- /dev/null
@@ -0,0 +1,56 @@
+// $Id$
+// Category: physics
+//
+// Special process that activates kinetic energy cuts
+
+#ifndef TG4_SPECIAL_CUTS_H
+#define TG4_SPECIAL_CUTS_H
+
+#include <G4UserSpecialCuts.hh>
+#include "TG3ParticleWSP.h"
+
+class TG4CutVector;
+class TG4Limits;
+
+typedef G4double(TG4CutVector::*PtrMinEkineInCutVector)(const G4Track&) const;
+typedef G4double(TG4Limits::*PtrMinEkineInLimits)(const G4Track&) const;
+
+class TG4SpecialCuts: public G4UserSpecialCuts
+// to do: change to inheritance from G4VProcess
+{
+  public:
+    TG4SpecialCuts(TG3ParticleWSP particle, TG4CutVector* cutVector, 
+                   const G4String& processName ="specialCut");
+    // --> protected
+    // TG4SpecialCuts();                  
+    // TG4SpecialCuts(const TG4SpecialCuts& right);
+    virtual ~TG4SpecialCuts();
+
+    // methods
+    virtual G4double PostStepGetPhysicalInteractionLength(
+                       const G4Track& track, G4double previousStepSize,
+                       G4ForceCondition* condition);
+    virtual G4VParticleChange* PostStepDoIt(const G4Track& , const G4Step&);
+                           
+  protected:
+    TG4SpecialCuts();             
+    TG4SpecialCuts(const TG4SpecialCuts& right);
+    
+    // operators
+    TG4SpecialCuts& operator = (const TG4SpecialCuts& right);
+    
+  private:
+    // data members
+    TG4CutVector*           fCutVector;              //TG4CutVector 
+    PtrMinEkineInCutVector  fPtrMinEkineInCutVector; //pointer to 
+                                //TG4CutVector::GetMinEKineForXX() method for 
+                               //the particle XX that this process is applied to 
+    PtrMinEkineInLimits     fPtrMinEkineInLimits;    //pointer to 
+                                //TG4Limits::GetMinEKineForXX() method for 
+                               //the particle XX that this process is applied to 
+};
+
+#endif //TG4_SPECIAL_CUTS_H
+
+
+
diff --git a/TGeant4/TG4SpecialFlags.cxx b/TGeant4/TG4SpecialFlags.cxx
new file mode 100644 (file)
index 0000000..b00ecfe
--- /dev/null
@@ -0,0 +1,163 @@
+// $Id$ //
+// Category: physics
+//
+// See the class description in the header file.
+
+#include "TG4SpecialFlags.h"
+#include "TG4Limits.h"
+
+#include <G4StepStatus.hh>
+#include <G4ProcessManager.hh>
+#include <G4ProcessVector.hh>
+
+TG4SpecialFlags::TG4SpecialFlags(const G4String& aName)
+  : G4VProcess(aName),
+    fSwitchFlags(kUnswitch)
+{
+   // verboseLevel = 1;
+   if (verboseLevel>0) {
+     G4cout << GetProcessName() << " is created "<< endl;
+   }
+}
+
+TG4SpecialFlags::TG4SpecialFlags(const TG4SpecialFlags& right) {
+// 
+  TG4Globals::Exception(
+    "TG4SpecialFlags is protected from copying.");
+}
+
+TG4SpecialFlags::~TG4SpecialFlags() {
+//
+}
+
+// operators
+
+TG4SpecialFlags& TG4SpecialFlags::operator=(const TG4SpecialFlags& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "TG4SpecialFlags is protected from assigning.");
+    
+  return *this;  
+} 
+
+// public methods   
+          
+G4double TG4SpecialFlags::PostStepGetPhysicalInteractionLength(
+                           const G4Track& track, G4double previousStepSize,
+                          G4ForceCondition* condition)
+{
+// Returns the Step-size (actual length) which is allowed 
+// by this process.
+// ---
+
+  *condition = NotForced;
+
+  G4double proposedStep = DBL_MAX;
+  G4double minStep = (1.0e-9)*m;
+    // must be greater than DBL_MIN - so that particle can get out of
+    // the boundary 
+    // proposedStep = 0.; causes navigator to fall into panic 
+  
+  G4StepStatus status     
+    = track.GetStep()->GetPreStepPoint()->GetStepStatus();
+  TG4Limits* limits 
+    = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits();
+
+  if (fSwitchFlags != kUnswitch) {
+    if (status == fGeomBoundary) {
+      if  ((limits) && (limits->IsFlag())) {
+        // particle is exiting a logical volume with special flags
+        // and entering another logical volume with special flags 
+       proposedStep = minStep;
+        fSwitchFlags = kReswitch;
+        if (verboseLevel>0) G4cout << "kReswitch" << endl;
+      }
+      else {
+        // particle is exiting a logical volume with special flags
+        // and entering a logical volume without special flags 
+       proposedStep = minStep;
+        fSwitchFlags = kUnswitch;
+        if (verboseLevel>0) G4cout << "kUnswitch" << endl;
+      }
+    }
+  }
+  else if ((limits) && (limits->IsFlag())) {
+       // particle is entering a logical volume with special flags
+       // that have not yet been set
+       proposedStep = minStep;
+       fSwitchFlags = kSwitch;
+       if (verboseLevel>0) G4cout << "kSwitch" << endl;
+  }  
+  return proposedStep;
+}
+
+G4VParticleChange* TG4SpecialFlags::PostStepDoIt(
+                      const G4Track& track, const G4Step& step)
+{
+// Changes processes activation of the current track
+// according to the current user limits.
+// ---
+
+  TG4Limits* limits 
+    = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits();
+
+  G4ProcessManager* processManager
+    = track.GetDefinition()->GetProcessManager();
+  G4ProcessVector* processVector = processManager->GetProcessList();
+  // processManager->DumpInfo();
+
+  if ((fSwitchFlags==kUnswitch) || (fSwitchFlags==kReswitch)) {
+    // set processes activation back
+    for (G4int i=0; i<fSwitchedProcesses.entries(); i++) {
+      if (verboseLevel>0) {
+        G4cout << "Reset process activation back in" 
+              << track.GetVolume()->GetName() 
+               << endl;
+      }
+      processManager
+        ->SetProcessActivation(fSwitchedProcesses[i],fSwitchedFlags[i]);
+    }
+    fSwitchedProcesses.clear();
+    fSwitchedFlags.clear();
+  }
+
+  if ((fSwitchFlags==kSwitch) ||  (fSwitchFlags==kReswitch)) {
+    // set TG4Limits processes flags
+    for (G4int i=0; i<processManager->GetProcessListLength(); i++) {
+      G4int flag = limits->GetFlag((*processVector)[i]);
+      if (flag != kUnset) {
+        // store the current processes flags;
+        fSwitchedProcesses.insert((*processVector)[i]);
+        //fSwitchedFlags.insert(processManager->GetProcessActivation(i));
+        fSwitchedFlags.push_back(processManager->GetProcessActivation(i));
+        if (flag == kInActivate) {
+          if (verboseLevel>0) {
+            G4cout << "Set process inactivation for " 
+                   << (*processVector)[i]->GetProcessName() << " in " 
+                  << track.GetVolume()->GetName() 
+                  << endl;
+          }
+          processManager->SetProcessActivation(i,false);
+        }  
+        else {
+         // ((flag == kActivate) || (flag == kActivate2)) 
+          if (verboseLevel>0) {
+            G4cout << "Set process activation for " 
+                   << (*processVector)[i]->GetProcessName() << " in " 
+                  << track.GetVolume()->GetName() 
+                  << endl;
+          }
+          processManager->SetProcessActivation(i,true);
+        }
+      }         
+    }
+  }  
+  // processManager->DumpInfo();       
+  aParticleChange.Initialize(track);
+  aParticleChange.SetStatusChange(fAlive);
+  return &aParticleChange;
+}
+
diff --git a/TGeant4/TG4SpecialFlags.h b/TGeant4/TG4SpecialFlags.h
new file mode 100644 (file)
index 0000000..d8780cb
--- /dev/null
@@ -0,0 +1,69 @@
+// $Id$
+// Category: physics
+//
+// Special process that applies process control flags 
+
+#ifndef TG4_SPECIAL_FLAGS_H
+#define TG4_SPECIAL_FLAGS_H
+
+#include "TG4Globals.h"
+
+#include <G4VProcess.hh>
+#include <G4ProcessVector.hh>
+#include <globals.hh>
+
+class TG4SpecialFlags : public G4VProcess 
+{
+  enum Switch { kSwitch, kReswitch, kUnswitch };
+
+  public:     
+    TG4SpecialFlags(const G4String& processName ="specialFlag" );
+    // --> protected
+    // TG4SpecialFlags(const TG4SpecialFlags& right);
+    virtual ~TG4SpecialFlags();
+
+    // methods
+
+    virtual G4double PostStepGetPhysicalInteractionLength(
+                         const G4Track& track, G4double previousStepSize, 
+                        G4ForceCondition* condition);
+
+    virtual G4VParticleChange* PostStepDoIt(const G4Track& track, 
+                                   const G4Step& step);
+
+    virtual G4double AlongStepGetPhysicalInteractionLength(
+                         const G4Track& track, G4double previousStepSize ,
+                        G4double currentMinimumStep, G4double& proposedSafety,
+                         G4GPILSelection* selection)
+                        { return -1.0; }
+
+    virtual G4VParticleChange* AlongStepDoIt(const G4Track& ,
+                                  const G4Step& step)
+                        { return 0; }
+
+    virtual G4double AtRestGetPhysicalInteractionLength(
+                         const G4Track& track, G4ForceCondition* condition)
+                         { return -1.0; }
+
+    virtual G4VParticleChange* AtRestDoIt(const G4Track& track,
+                                  const G4Step& step)
+                         { return 0; }
+
+  protected:
+    TG4SpecialFlags(const TG4SpecialFlags& right);
+    
+    //operators
+    TG4SpecialFlags& operator = (const TG4SpecialFlags& right);
+    
+  private:  
+    // data members
+    Switch           fSwitchFlags;       //directive passed from PostStepGetPIL
+                                         //to PostStepDoIt
+    G4ProcessVector  fSwitchedProcesses; //vector of the processes activation of
+                                         //which is changed by this process
+    TG4boolVector    fSwitchedFlags;     //vector for storing the current values of 
+                                         //the processes activation   
+};
+
+#endif //TG4_SPECIAL_FLAGS_H
+
diff --git a/TGeant4/TG4StepManager.cxx b/TGeant4/TG4StepManager.cxx
new file mode 100644 (file)
index 0000000..cff250d
--- /dev/null
@@ -0,0 +1,1043 @@
+// $Id$
+// Category: event
+//
+// See the class description in the header file.
+
+#include "TG4StepManager.h"
+#include "TG4GeometryManager.h"
+#include "TG4PhysicsManager.h"
+#include "TG4VSensitiveDetector.h"
+#include "TG4Globals.h"
+#include "TG3Units.h"
+
+#include <G4Step.hh>
+#include <G4SteppingManager.hh>
+#include <G4UserLimits.hh>
+#include <G4ParticleTable.hh>
+#include <G4UImanager.hh>
+#include <G4AffineTransform.hh>
+//#include <G4TransportationManager.hh>
+//#include <G4Navigator.hh>
+
+#include <Randomize.hh>
+
+#include <TLorentzVector.h>
+
+TG4StepManager* TG4StepManager::fgInstance = 0;
+
+TG4StepManager::TG4StepManager() 
+  : fStep(0),
+    fSteppingManager(0)
+{
+// 
+  if (fgInstance) {
+    TG4Globals::Exception(
+      "TG4StepManager: attempt to create two instances of singleton.");
+  }
+      
+  fgInstance = this;  
+}
+
+TG4StepManager::TG4StepManager(const TG4StepManager& right) {
+// 
+  TG4Globals::Exception(
+    "Attempt to copy TG4StepManager singleton.");
+}
+
+TG4StepManager::~TG4StepManager() {
+//
+}
+
+// operators
+
+TG4StepManager& TG4StepManager::operator=(const TG4StepManager& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "Attempt to assign TG4StepManager singleton.");
+    
+  return *this;  
+}    
+          
+// private methods
+
+void TG4StepManager::SetTLorentzVector(G4ThreeVector xyz, G4double t, 
+                                       TLorentzVector& lv) const                                      
+{
+// Fills TLorentzVector with G4ThreeVector and G4double.
+// ---
+
+   lv[0] = xyz.x();                                   
+   lv[1] = xyz.y();                                   
+   lv[2] = xyz.z();                                   
+   lv[3] = t;
+}                                     
+
+// public methods
+
+void TG4StepManager::StopTrack()
+{
+// Stops the current track and skips to the next.
+// ?? do we want to invoke rest processes?
+// ?? do we want to stop secondaries too?
+//   possible "stop" track status from G4:
+//   fStopButAlive,      // Invoke active rest physics processes and
+//                       // and kill the current track afterward
+//   fStopAndKill,       // Kill the current track
+//   fKillTrackAndSecondaries,
+//                       // Kill the current track and also associated
+//                       // secondaries.
+// ---
+
+  if (fStep) {
+    // check
+    fStep->GetTrack()->SetTrackStatus(fStopAndKill);
+    // fStep->GetTrack()->SetTrackStatus(fStopButAlive);
+    // fStep->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries);
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }
+}
+
+void TG4StepManager::StopEvent()
+{
+// Aborts the current event processing.
+// ---
+
+  if (fStep) {
+    fStep->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries);
+      //StopTrack();   // cannot be used as it keeps secondaries
+    G4UImanager::GetUIpointer()->ApplyCommand("/event/abort");
+    G4UImanager::GetUIpointer()->ApplyCommand("/alStacking/clearStack");
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }
+}
+
+void TG4StepManager::Rndm(Float_t* array, const Int_t size) const
+{   
+// Random numbers array of the specified size.
+// ---
+
+  G4double* const doubleArray = new G4double[size];
+  RandFlat::shootArray(size,doubleArray);
+  for (G4int i=0; i<size; i++) { 
+    array[i] = doubleArray[i]; 
+  } 
+  delete [] doubleArray;
+}
+void TG4StepManager::SetMaxStep(Float_t step)
+{
+// Maximum step allowed in the current logical volume.
+// The maximum value is kept for following tracks - is it ok ??
+// ---
+
+  if (fStep) {
+    // check this
+    G4LogicalVolume* curLogVolume
+      = fStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
+    G4UserLimits* userLimits 
+      = curLogVolume->GetUserLimits();
+    if (userLimits == 0)
+    { 
+      userLimits = new G4UserLimits(step); 
+      curLogVolume->SetUserLimits(userLimits);
+    }
+    else
+    { userLimits->SetMaxAllowedStep(step); }  
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }
+}
+
+void TG4StepManager::SetMaxNStep(Int_t maxNofSteps)
+{
+// Not yet implemented.
+// ---
+
+  TG4Globals::Warning(
+    "TG4StepManager::SetMaxNStep(..) is not yet implemented.");
+}
+
+void TG4StepManager::SetUserDecay(Int_t)
+{
+// Not yet implemented.
+// ---
+
+  TG4Globals::Exception(
+    "TG4StepManager::SetUserDecay(..) is not yet implemented.");
+}
+
+Int_t TG4StepManager::CurrentVolID(Int_t& copyNo) const
+{
+// Returns the current sensitive detector ID
+// and the copy number of the current physical volume.
+// ---
+
+  if (fStep) {
+    // check this
+    G4VPhysicalVolume* physVolume 
+      = fStep->GetPreStepPoint()->GetPhysicalVolume();
+    copyNo = physVolume->GetCopyNo();
+
+    // sensitive detector ID
+    G4VSensitiveDetector* sd
+        = physVolume->GetLogicalVolume()->GetSensitiveDetector();
+    if (sd) {
+      TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
+      if (tsd)
+        return tsd->GetID();
+      else {
+        TG4Globals::Exception(
+          "TG4StepManager::CurrentVol: Unknown sensitive detector type");
+        return 0;
+      }        
+    }  
+    else {
+      G4String text = "TG4StepManager::CurrentVol: \n";
+      text = text + "    Volume " + physVolume->GetName();
+      text = text + " has not a sensitive detector.";
+      TG4Globals::Exception(text);
+      return 0;
+    }          
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+Int_t TG4StepManager::CurrentVolOffID(Int_t off, Int_t&  copyNo) const
+{ 
+// Returns the off-th mother's of the current volume
+// the sensitive detector ID and the copy number.
+// ---
+
+  if (off == 0) return CurrentVolID(copyNo);
+
+  if (fStep) {
+    // check this !!
+    // mother of physical volume may not be set ?!!
+    G4VPhysicalVolume* physVolume 
+      = fStep->GetPreStepPoint()->GetPhysicalVolume();
+
+    G4VPhysicalVolume* mother = 0;
+    Int_t level = off;
+    while (level > 0) { 
+      mother = physVolume->GetMother();
+      level--;
+    }
+    
+    if (mother) {
+      copyNo = mother->GetCopyNo();
+
+      // sensitive detector ID
+      G4VSensitiveDetector* sd
+        = mother->GetLogicalVolume()->GetSensitiveDetector();
+      if (sd) {
+        TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
+        if (tsd)
+          return tsd->GetID();
+        else {
+          TG4Globals::Exception(
+            "TG4StepManager::CurrentVolOff: Unknown sensitive detector type");
+          return 0;
+        }      
+      }  
+      else {
+        G4String text = "TG4StepManager::CurrentVolOff: \n";
+        text = text + "    Volume " + mother->GetName();
+        text = text + " has not a sensitive detector.";
+        TG4Globals::Exception(text);
+        return 0;
+      } 
+    }
+    else {             
+      G4String text = "TG4StepManager::CurrentVolOff: Volume ";
+      text = text + physVolume->GetName();
+      text = text + " has not defined mother in required level.";
+      TG4Globals::Exception(text);
+      return 0;
+    }  
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+const char* TG4StepManager::CurrentVolName() const
+{
+// Returns the current physical volume name.
+// ---
+
+  if (fStep) {
+    G4VPhysicalVolume* physVolume 
+      = fStep->GetPreStepPoint()->GetPhysicalVolume();
+    return physVolume->GetName();
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+const char* TG4StepManager::CurrentVolOffName(Int_t off) const
+{ 
+// Returns the off-th mother's physical volume name.
+// ---
+
+  if (fStep) {
+    G4VPhysicalVolume* physVolume 
+      = fStep->GetPreStepPoint()->GetPhysicalVolume();
+
+    G4VPhysicalVolume* mother = 0;
+    Int_t level = off;
+    while (level > 0) { 
+      mother = physVolume->GetMother();
+      level--;
+    }
+    
+    if (mother) {
+      return mother->GetName();
+    }
+    else {
+      TG4Globals::Exception("TG4StepManager::CurrentVolOff: wrong usage.");
+      return 0;
+    }
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+Int_t TG4StepManager::CurrentMaterial(Float_t &a, Float_t &z, Float_t &dens, 
+                          Float_t &radl, Float_t &absl) const
+{
+// Returns the parameters of the current material during transport
+// the return value is the number of elements in the mixture.
+// ---
+
+  if (fStep) {
+    // check this
+    G4LogicalVolume* curLogVolume 
+      = fStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
+    G4Material* material
+      = curLogVolume->GetMaterial();
+
+    // this if may be redundant - check
+    if (material)
+    {
+      G4int nofElements = material->GetNumberOfElements();
+      TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
+      a = pGeometryManager->GetEffA(material);
+      z = pGeometryManager->GetEffZ(material);
+      
+      // density 
+      dens = material->GetDensity();
+      dens /= TG3Units::MassDensity();      
+      
+      // radiation length
+      radl = material->GetRadlen();
+      radl /= TG3Units::Length();
+      
+      absl = 0.;  // this parameter is not defined in Geant4
+      return nofElements;
+    }
+    else {
+      TG4Globals::Exception(
+       "TG4StepManager::CurrentMaterial(..): material is not defined.");
+      return 0;
+    }
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+void TG4StepManager::Gmtod(Float_t* xm, Float_t* xd, Int_t iflag) 
+{ 
+// Transforms a position from the world reference frame
+// to the current volume reference frame.
+//
+//  Geant3 desription:
+//  ==================
+//       Computes coordinates XD (in DRS) 
+//       from known coordinates XM in MRS 
+//       The local reference system can be initialized by
+//         - the tracking routines and GMTOD used in GUSTEP
+//         - a call to GMEDIA(XM,NUMED)
+//         - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER) 
+//             (inverse routine is GDTOM) 
+//
+//        If IFLAG=1  convert coordinates 
+//           IFLAG=2  convert direction cosinus
+//
+// ---
+
+  if (fStep) {
+    G4ThreeVector theGlobalPoint(xm[0],xm[1],xm[2]); 
+
+    //const G4NavigationHistory* history
+    //   =  fStep->GetPreStepPoint()->GetTouchable()->GetHistory();
+    G4AffineTransform affineTransform
+      = fStep->GetPreStepPoint()->GetTouchable()->GetHistory()
+        ->GetTopTransform();
+
+    G4ThreeVector theLocalPoint;
+    if(iflag == 1) 
+         theLocalPoint = affineTransform.TransformPoint(theGlobalPoint);
+    else if ( iflag == 2)
+         theLocalPoint = affineTransform.TransformAxis(theGlobalPoint);
+    else 
+      TG4Globals::Exception(
+        "TG4StepManager::Gmtod(..,iflag): iflag is not in 1..2");
+
+    xd[0] = theLocalPoint.x();
+    xd[1] = theLocalPoint.y();
+    xd[2] = theLocalPoint.z();
+     
+ /* 
+   // does not work ???
+   G4ThreeVector direction(0,0,0);
+   G4bool RelativeSearch = true;
+   G4Navigator* theNavigator =
+     G4TransportationManager::GetTransportationManager()->
+     GetNavigatorForTracking();
+
+   G4VPhysicalVolume* pPhysVol;
+   pPhysVol
+     = LocateGlobalPointAndSetup(theGlobalPoint, &direction, RelativeSearch);  
+   //LocateGlobalPointWithinVolume(theGlobalPoint);
+
+   G4AffineTransform at
+     = theNavigator->GetGlobalToLocalTransform();
+ */  
+  } 
+  else { 
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }  
+} 
+void TG4StepManager::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag) 
+{ 
+// Transforms a position from the current volume reference frame
+// to the world reference frame.
+//
+//  Geant3 desription:
+//  ==================
+//  Computes coordinates XM (Master Reference System
+//  knowing the coordinates XD (Detector Ref System)
+//  The local reference system can be initialized by
+//    - the tracking routines and GDTOM used in GUSTEP
+//    - a call to GSCMED(NLEVEL,NAMES,NUMBER)
+//        (inverse routine is GMTOD)
+// 
+//   If IFLAG=1  convert coordinates
+//      IFLAG=2  convert direction cosinus
+//
+// ---
+
+  if (fStep) {
+    // check this
+    
+   G4ThreeVector theLocalPoint(xd[0],xd[1],xd[2]); 
+
+   G4AffineTransform affineTransform
+      = fStep->GetPreStepPoint()->GetTouchable()->GetHistory()
+        ->GetTopTransform().Inverse();
+  
+   G4ThreeVector theGlobalPoint;
+   if(iflag == 1)
+         theGlobalPoint = affineTransform.TransformPoint(theLocalPoint);
+   else if( iflag == 2)
+         theGlobalPoint = affineTransform.TransformAxis(theLocalPoint);
+   else 
+      TG4Globals::Warning(
+        "TG4StepManager::Gdtom(...,iflag): iflag is not in 1..2");
+
+   xm[0] = theGlobalPoint.x();
+   xm[1] = theGlobalPoint.y();
+   xm[2] = theGlobalPoint.z();
+  }   
+  else { 
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }  
+} 
+Float_t TG4StepManager::MaxStep() const
+{   
+// Returns maximum step allowed in the current logical volume
+// by User Limits.
+// ---
+
+  if (fStep) {
+    // check this
+    G4LogicalVolume* curLogVolume
+      = fStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
+    G4UserLimits* userLimits 
+      = curLogVolume->GetUserLimits();
+    G4double maxStep;
+    if (userLimits == 0)
+    { 
+      G4String text = "User Limits are not defined for log volume ";
+      text = text + curLogVolume->GetName();
+      TG4Globals::Warning(text);
+      return DBL_MAX;
+    }
+    else
+    { 
+      const G4Track& trackRef = *(fStep->GetTrack());
+      maxStep = userLimits->GetMaxAllowedStep(trackRef); 
+      maxStep /= TG3Units::Length(); 
+      return maxStep;
+    }  
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return DBL_MAX;
+  }
+}
+
+Int_t TG4StepManager::GetMaxNStep() const
+{   
+// Not yet implemented.
+// ---
+
+  TG4Globals::Warning(
+    "Method GetMaxNStep is not yet implemented in TG4StepManager.");
+  return 0; 
+}
+
+void TG4StepManager::TrackPosition(TLorentzVector& position) const
+{ 
+// Current particle position (in the world reference frame)
+// and the local time since the current track is created
+// (position of the PostStepPoint).
+// ---
+
+  if (fStep) {
+    // position
+    G4ThreeVector positionVector
+       = fStep->GetPostStepPoint()->GetPosition();
+    positionVector *= 1./(TG3Units::Length());   
+     
+    // local time   
+    G4double time
+      = fStep->GetTrack()->GetLocalTime();
+    time /= TG3Units::Time();
+      
+    SetTLorentzVector(positionVector, time, position);
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }
+}
+
+Int_t TG4StepManager::GetMedium() const
+{   
+// Returns the second index of the current material (corresponding to
+// G3 tracking medium index).
+// --- 
+
+  if (fStep) {
+    // current material
+    G4Material* curMaterial
+      = fStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetMaterial();
+
+    // medium index  
+    TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
+    return pGeometryManager->GetMediumId(curMaterial);
+  }  
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+void TG4StepManager::TrackMomentum(TLorentzVector& momentum) const
+{  
+// Current particle "momentum" (px, py, pz, Etot).
+// ---
+
+  if (fStep) {
+    G4ThreeVector momentumVector
+      = fStep->GetTrack()->GetMomentum(); 
+
+    G4double energy
+      = fStep->GetTrack()->GetDynamicParticle()->GetTotalEnergy();
+    energy /= TG3Units::Energy();  
+
+    SetTLorentzVector(momentumVector, energy, momentum);
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }
+}
+
+void TG4StepManager::TrackVertexPosition(TLorentzVector& position) const
+{ 
+// The vertex particle position (in the world reference frame)
+// and the local time since the current track is created.
+// ---
+
+  if (fStep) {
+    // position
+    G4ThreeVector positionVector
+       = fStep->GetTrack()->GetVertexPosition();
+    positionVector *= 1./(TG3Units::Length());   
+     
+    // local time 
+    // to be checked  
+    G4double time
+      = fStep->GetTrack()->GetLocalTime();
+    time /= TG3Units::Time();
+      
+    SetTLorentzVector(positionVector, time, position);
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }
+}
+
+void TG4StepManager::TrackVertexMomentum(TLorentzVector& momentum) const
+{  
+// The vertex particle "momentum" (px, py, pz, Ekin)
+// to do: change Ekin -> Etot 
+// ---
+
+  if (fStep) {
+    G4ThreeVector momentumVector
+      = fStep->GetTrack()->GetVertexMomentumDirection(); 
+
+    G4double energy
+      = fStep->GetTrack()->GetVertexKineticEnergy();
+    energy /= TG3Units::Energy();  
+
+    SetTLorentzVector(momentumVector, energy, momentum);
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+  }
+}
+
+Float_t TG4StepManager::TrackStep() const
+{   
+// Returns the current step length.
+// ---
+
+  if (fStep) {
+    // check
+    G4double length = fStep->GetStepLength();
+    length /= TG3Units::Length();
+    return length;
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0.;
+  }
+}
+
+Float_t TG4StepManager::TrackLength() const
+{
+// Returns the length of the current track from its origin.
+// ---
+
+  if (fStep) {
+    G4double length
+      = fStep->GetTrack()->GetTrackLength();
+    length /= TG3Units::Length();
+    return length;
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+Float_t TG4StepManager::TrackTime() const
+{
+// Returns the local time since the current track is created.
+// Comment:
+// in Geant4: there is also defined proper time as
+// the proper time of the dynamical particle of the current track.
+// ---
+
+  if (fStep) {
+    G4double time
+      = fStep->GetTrack()->GetLocalTime();
+    time /= TG3Units::Time();
+    return time;
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+Float_t TG4StepManager::Edep() const
+{   
+// Returns total energy deposit in this step.
+// ---
+
+  if (fStep) {
+    // G4double deltaEnergy = fStep->GetDeltaEnergy();
+    G4double deltaEnergy = fStep->GetTotalEnergyDeposit();
+    deltaEnergy /= TG3Units::Energy();
+    return deltaEnergy;
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0.;
+  }
+}
+
+Int_t TG4StepManager::TrackPid() const
+{   
+// Returns the current particle PDG encoding.
+// ---
+
+  if (fStep) {
+    G4ParticleDefinition* particle
+      = fStep->GetTrack()->GetDynamicParticle()->GetDefinition();
+      
+    // ask TG4PhysicsManager to get PDG encoding 
+    // (in order to get PDG from extended TDatabasePDG
+    // in case the standard PDG code is not defined)
+    TG4PhysicsManager* pPhysicsManager = TG4PhysicsManager::Instance();
+    G4int pdgEncoding = pPhysicsManager->GetPDGEncodingFast(particle);
+
+    return pdgEncoding;
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+Float_t TG4StepManager::TrackCharge() const
+{   
+// Returns the current particle charge.
+// ---
+
+  if (fStep) {
+    G4double charge
+      = fStep->GetTrack()->GetDynamicParticle()->GetDefinition()
+        ->GetPDGCharge();
+    charge /= TG3Units::Charge();      
+    return charge;
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+Float_t TG4StepManager::TrackMass() const
+{   
+// Returns current particle rest mass.
+// ---
+
+  if (fStep) {
+    G4double mass
+      = fStep->GetTrack()->GetDynamicParticle()->GetDefinition()
+        ->GetPDGMass();
+    mass /= TG3Units::Mass();  
+    return mass;
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0;
+  }
+}
+
+Float_t TG4StepManager::Etot() const
+{   
+// Returns total energy of the current particle.
+// ---
+
+  if (fStep) {
+    G4double energy
+      = fStep->GetTrack()->GetDynamicParticle()->GetTotalEnergy();
+    energy /= TG3Units::Energy();  
+    return energy;
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return 0.;
+  }
+}
+
+Bool_t TG4StepManager::IsTrackInside() const
+{   
+// Returns true if particle does not cross geometrical boundary
+// at both pre-step and post-step points.
+// ---
+
+  if ( !(IsTrackEntering()) && !(IsTrackExiting()) )
+  { return true; }
+  else
+  { return false; }
+}
+
+Bool_t TG4StepManager::IsTrackEntering() const
+{   
+// Returns true if particle cross a geometrical boundary
+// at pre-step point.
+// ---
+
+  if (fStep) {
+    G4StepStatus status
+       = fStep->GetPreStepPoint()->GetStepStatus();
+    if (status == fGeomBoundary)
+    { return true; }
+    else
+    { return false; }
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return false;
+  }
+}
+
+Bool_t TG4StepManager::IsTrackExiting() const
+{   
+// Returns true if particle cross a geometrical boundary
+// at post-step point.
+// ---
+
+  if (fStep) {
+    // check
+    G4StepStatus status
+       = fStep->GetPostStepPoint()->GetStepStatus();
+    if (status == fGeomBoundary)
+    { return true; }
+    else
+    { return false; }
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return false;
+  }
+}
+
+Bool_t TG4StepManager::IsTrackOut() const
+{   
+// Returns true if particle cross the Hall frame 
+// at post-step point.
+// ---
+
+  if (fStep) {
+    // check
+    G4String volName
+       = fStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
+    if (volName == "pHallFrame")
+    { return true; }
+    else
+    { return false; }
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return false;
+  }
+}
+
+Bool_t TG4StepManager::IsTrackStop() const
+{   
+// Returns true if particle has stopped 
+// or has been killed, suspended or postponed to next event.
+//
+// Possible track status from G4:
+//   fAlive,             // Continue the tracking
+//   fStopButAlive,      // Invoke active rest physics processes and
+//                            // and kill the current track afterward
+//   fStopAndKill,       // Kill the current track
+//   fKillTrackAndSecondaries,
+//                       // Kill the current track and also associated
+//                       // secondaries.
+//   fSuspend,           // Suspend the current track
+//   fPostponeToNextEvent
+//                       // Postpones the tracking of thecurrent track 
+//                       // to the next event.
+// ---
+
+  if (fStep) {
+    // check
+    G4TrackStatus status
+       = fStep->GetTrack()->GetTrackStatus();
+    if ((status == fStopAndKill) ||  
+        (status == fKillTrackAndSecondaries) ||
+        (status == fSuspend) ||
+        (status == fPostponeToNextEvent))
+    { return true; }
+    else
+    { return false; }
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return false;
+  }
+}
+
+Bool_t TG4StepManager::IsTrackDisappeared() const
+{ 
+// Returns true if particle has disappeared 
+// (due to any physical process)
+// or has been killed, suspended or postponed to next event.
+// ---
+
+  if (fStep) {
+    // check
+    G4TrackStatus status
+       = fStep->GetTrack()->GetTrackStatus();
+    if ((status == fStopButAlive) ||  
+        (status == fKillTrackAndSecondaries) ||
+        (status == fSuspend) ||
+        (status == fPostponeToNextEvent))
+    { return true; }
+    else
+    { return false; }
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return false;
+  }
+}
+
+Bool_t TG4StepManager::IsTrackAlive() const
+{   
+// Returns true if particle continues tracking.
+// ---
+
+  if (fStep) {
+    G4TrackStatus status
+       = fStep->GetTrack()->GetTrackStatus();
+    if (status == fAlive)
+    { return true; }
+    else
+    { return false; }
+  } 
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return false;
+  }
+}
+
+Bool_t TG4StepManager::IsNewTrack() const
+{
+// Returns true when track performs the first step.
+// ---
+
+  if (fStep->GetTrack()->GetCurrentStepNumber() == 1)
+    return true;
+  else  
+    return false;
+}
+
+Int_t TG4StepManager::NSecondaries() const
+{
+// Returns the number of secondary particles generated 
+// in the current step.
+// ---
+
+  if (fSteppingManager) 
+  {
+    G4int nofSecondaries = 0;
+    nofSecondaries += fSteppingManager->GetfN2ndariesAtRestDoIt();
+    nofSecondaries += fSteppingManager->GetfN2ndariesAlongStepDoIt();
+    nofSecondaries += fSteppingManager->GetfN2ndariesPostStepDoIt();
+
+    return nofSecondaries;
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: SteppingManager is not defined.");
+    return 0;
+  }
+}
+
+void TG4StepManager::GetSecondary(Int_t index, Int_t& particleId, 
+                          TLorentzVector& position, TLorentzVector& momentum)
+{
+// Fills the parameters (particle encoding, position, momentum)
+// of the generated secondary particle which is specified by index.
+// !! Check if indexing of secondaries is same !!
+// ---
+
+  if (fSteppingManager) 
+  {
+    G4int nofSecondaries = NSecondaries();
+    G4TrackVector* secondaryTracks = fSteppingManager->GetSecondary();
+
+    if (secondaryTracks)
+    {
+      if (index < nofSecondaries)
+      {
+        // the index of the first secondary of this step
+        G4int startIndex 
+          = secondaryTracks->entries() - nofSecondaries;
+               // (the secondaryTracks vector contains secondaries 
+               // produced by the track at previous steps, too)
+        G4Track* track 
+          = (*secondaryTracks)[startIndex + index]; 
+   
+        // particle encoding
+        particleId 
+          = track->GetDynamicParticle()->GetDefinition()->GetPDGEncoding();
+        // position & time
+        G4ThreeVector positionVector = track->GetPosition();
+       positionVector *= 1./(TG3Units::Length());
+        G4double time = track->GetLocalTime();
+       time /= TG3Units::Time();
+        SetTLorentzVector(positionVector, time, position);
+
+        // momentum & energy
+        G4ThreeVector momentumVector = track->GetMomentum();   
+        G4double energy = track->GetDynamicParticle()->GetTotalEnergy();
+       energy /= TG3Units::Energy();
+        SetTLorentzVector(momentumVector, energy, momentum);
+      }
+      else {
+        TG4Globals::Exception(
+          "TG4StepManager::GetSecondary(): wrong secondary track index.");
+      }
+    }
+    else {
+      TG4Globals::Exception(
+        "TG4StepManager::GetSecondary(): secondary tracks vector is empty");
+    }
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: SteppingManager is not defined.");
+  }
+}
+
+const char* TG4StepManager::ProdProcess() const
+{
+// Returns the name of the process that defined current step
+// (and may produce the secondary particles).
+// ---
+
+  if (fStep) 
+  {
+    const G4VProcess* curProcess 
+      = fStep->GetPostStepPoint()->GetProcessDefinedStep(); 
+
+    G4String g4Name = curProcess->GetProcessName(); 
+    return g4Name;
+  }
+  else {   
+    TG4Globals::Exception("TG4StepManager: Step is not defined.");
+    return "";
+  }
+}
diff --git a/TGeant4/TG4StepManager.h b/TGeant4/TG4StepManager.h
new file mode 100644 (file)
index 0000000..9bf68bf
--- /dev/null
@@ -0,0 +1,127 @@
+// $Id$
+// Category: event
+//
+// Geant4 implementation of the MonteCarlo interface methods                    
+// for access to Geant4 at step level
+//
+// The public methods that do not implement AliMC methods
+// are commented as G4 specific
+
+#ifndef TG4_STEP_MANAGER_H
+#define TG4_STEP_MANAGER_H
+
+#include <G4ThreeVector.hh>
+#include <globals.hh>
+
+#include <Rtypes.h>
+
+class G4Step;
+class G4SteppingManager;
+
+class TLorentzVector;
+
+class TG4StepManager
+{
+  public:
+    TG4StepManager();
+    // --> protected
+    // TG4StepManager(const TG4StepManager& right);
+    virtual ~TG4StepManager();
+
+    // static access method
+    static TG4StepManager* Instance();
+        
+    // methods
+    void StopTrack(); //new
+    void StopEvent(); //new
+    void Rndm(Float_t* array, const Int_t size) const;
+    
+    // set methods
+    void SetStep(G4Step* step);                          // G4 specific
+    void SetSteppingManager(G4SteppingManager* manager); // G4 specific
+    void SetMaxStep(Float_t step);
+    void SetMaxNStep(Int_t maxNofSteps);  //??
+    void SetUserDecay(Int_t);  //NEW
+    
+    // get methods
+    G4Step* GetStep() const;                              // G4 specific
+    
+        // tracking volume(s) 
+    Int_t CurrentVolID(Int_t& copyNo) const;
+    Int_t CurrentVolOffID(Int_t off, Int_t& copyNo) const;
+    const char* CurrentVolName() const;
+    const char* CurrentVolOffName(Int_t off) const;
+    Int_t CurrentMaterial(Float_t &a, Float_t &z, Float_t &dens, 
+                    Float_t &radl, Float_t &absl) const;
+    void Gmtod(Float_t* xm, Float_t* xd, Int_t iflag);  //new
+    void Gdtom(Float_t* xd, Float_t* xm, Int_t iflag); //new
+    Float_t MaxStep() const;
+    Int_t GetMaxNStep() const;  //??                       
+    Int_t GetMedium() const;  //??
+
+        // tracking particle 
+        // dynamic properties
+    void TrackPosition(TLorentzVector& position) const;
+    void TrackMomentum(TLorentzVector& momentum) const;
+    void TrackVertexPosition(TLorentzVector& position) const;
+    void TrackVertexMomentum(TLorentzVector& momentum) const;
+    Float_t TrackStep() const;  
+    Float_t TrackLength() const;   
+    Float_t TrackTime() const;  
+    Float_t Edep() const;
+        // static properties
+    Int_t TrackPid() const;
+    Float_t TrackCharge() const;
+    Float_t TrackMass() const;
+    Float_t Etot() const;
+
+        // track status
+    Bool_t IsTrackInside() const;
+    Bool_t IsTrackEntering() const;
+    Bool_t IsTrackExiting() const;
+    Bool_t IsTrackOut() const;
+    Bool_t IsTrackDisappeared() const;
+    Bool_t IsTrackStop() const;
+    Bool_t IsTrackAlive() const;
+    Bool_t IsNewTrack() const;
+
+        // secondaries
+    Int_t NSecondaries() const;
+    void GetSecondary(Int_t isec, Int_t& particleId,
+                      TLorentzVector& position, TLorentzVector& momentum);      
+    const char* ProdProcess() const; 
+
+  protected:
+    TG4StepManager(const TG4StepManager& right);
+
+    // operators
+    TG4StepManager& operator=(const TG4StepManager& right);
+
+  private:
+    // methods
+    void SetTLorentzVector(G4ThreeVector, G4double, TLorentzVector&) const;
+    
+    // static data members
+    static TG4StepManager*  fgInstance;   //this instance
+    
+    // data members
+    G4Step*             fStep;            //current step
+    G4SteppingManager*  fSteppingManager; //G4SteppingManager
+};
+
+// inline methods
+
+inline TG4StepManager* TG4StepManager::Instance() 
+{ return fgInstance; }
+
+inline void TG4StepManager::SetStep(G4Step* step)
+{ fStep = step; }
+
+inline void TG4StepManager::SetSteppingManager(G4SteppingManager* manager)
+{ fSteppingManager = manager; }
+
+inline G4Step* TG4StepManager::GetStep() const
+{ return fStep; }
+
+#endif //TG4_STEP_MANAGER_H
+
diff --git a/TGeant4/TG4UICmdWithAComplexString.cxx b/TGeant4/TG4UICmdWithAComplexString.cxx
new file mode 100644 (file)
index 0000000..f0e56e7
--- /dev/null
@@ -0,0 +1,83 @@
+// $ Id:$
+
+#include "TG4UICmdWithAComplexString.h"
+
+#include <g4std/strstream>
+
+TG4UICmdWithAComplexString::TG4UICmdWithAComplexString(
+                                 G4String commandPath, G4UImessenger* messenger)
+  : G4UIcommand(commandPath, messenger)
+{
+// The command string with full path directory
+// and the pointer to the messenger must be given.
+// ---
+
+  G4UIparameter* first  = new G4UIparameter('s');
+  SetParameter(first);
+  G4UIparameter* second = new G4UIparameter('s');
+  SetParameter(second);
+  G4UIparameter* third  = new G4UIparameter('s');
+  SetParameter(third);
+}
+
+TG4UICmdWithAComplexString::~TG4UICmdWithAComplexString() {
+//
+}
+                              
+// public methods
+
+void TG4UICmdWithAComplexString::SetParameterName(G4String name, 
+                                                  G4bool omittable)
+{
+// Set the parameter names for the parameters. 
+// The "omittable" is set only for the first parameter, 
+// for the second and third it is always true.
+// The "currentAsDefault" flag is valid only if "omittable" is true.
+// If this flag is true, the current values are used as the default values
+// when user ommits the parameters. If this flag is false, the values
+// given by the next SetDefaultValue() method are used. 
+// ---
+
+  G4UIparameter* first = GetParameter(0);
+  first->SetParameterName(name);
+  first->SetOmittable(omittable);
+  first->SetCurrentAsDefault(false);
+  
+  G4UIparameter* second = GetParameter(1);
+  G4String secondName = name + "_cont1";
+  second->SetParameterName(secondName);
+  second->SetOmittable(true);
+  second->SetCurrentAsDefault(false);
+
+  G4UIparameter* third = GetParameter(2);
+  G4String thirdName = name + "_cont2";
+  third->SetParameterName(thirdName);
+  third->SetOmittable(true);
+  third->SetCurrentAsDefault(false);
+}
+
+void TG4UICmdWithAComplexString::SetDefaultValue(G4String defaultValue)
+{
+// Sets the default values of the parameters.
+// These default values are used when user of this command ommits 
+// some of the parameter values, and "ommitable" is true and 
+// "currentAsDefault" is false.
+
+  G4UIparameter* first = GetParameter(0);
+  first->SetDefaultValue(defaultValue);
+
+  G4UIparameter* second = GetParameter(1);
+  second->SetDefaultValue(" ");
+
+  G4UIparameter* third = GetParameter(2);
+  third->SetDefaultValue(" ");
+}
+
+G4String TG4UICmdWithAComplexString::GetNewStringValue(G4String paramString)
+{
+// Returns the parameter string 
+// ---
+
+  return paramString;
+}
+
diff --git a/TGeant4/TG4UICmdWithAComplexString.h b/TGeant4/TG4UICmdWithAComplexString.h
new file mode 100644 (file)
index 0000000..36ed4b4
--- /dev/null
@@ -0,0 +1,27 @@
+// $ Id:$
+// Category: global
+
+// Concrete class of G4UIcommand. 
+// The command defined by this class takes up to three string values.
+// General information of G4UIcommand is given in G4UIcommand.hh.
+
+#ifndef TG4_UI_CMD_WITH_STRING_H
+#define TG4_UI_CMD_WITH_STRING_H
+
+#include <G4UIcommand.hh>
+
+class TG4UICmdWithAComplexString : public G4UIcommand
+{
+  public:
+    TG4UICmdWithAComplexString(G4String commandPath, G4UImessenger* messenger);
+    virtual ~TG4UICmdWithAComplexString();                            
+
+    // set methods
+    void SetParameterName(G4String name, G4bool omittable);
+    void SetDefaultValue(G4String defVal);
+
+    // get methods
+    G4String GetNewStringValue(G4String paramString);
+};
+
+#endif //TG4_UI_CMD_WITH_STRING_H
diff --git a/TGeant4/TG4VRunConfiguration.cxx b/TGeant4/TG4VRunConfiguration.cxx
new file mode 100644 (file)
index 0000000..3a2822a
--- /dev/null
@@ -0,0 +1,76 @@
+// $Id$
+// Category: run
+//
+// See the class description in the header file.
+
+#include "TG4VRunConfiguration.h"
+#include "TG4Globals.h"
+
+#include <G4VUserDetectorConstruction.hh>
+#include <G4VUserPhysicsList.hh>
+#include <G4VUserPrimaryGeneratorAction.hh>
+#include <G4UserRunAction.hh>
+#include <G4UserEventAction.hh>
+#include <G4UserTrackingAction.hh>
+#include <G4UserSteppingAction.hh>
+#include <G4UserStackingAction.hh>
+#include <G4RunManager.hh>
+
+TG4VRunConfiguration::TG4VRunConfiguration()
+  : fDetectorConstruction(0),
+    fPhysicsList(0),
+    fPrimaryGenerator(0),
+    fRunAction(0),
+    fEventAction(0),
+    fTrackingAction(0),
+    fSteppingAction(0),
+    fStackingAction(0)
+{
+//
+}
+
+TG4VRunConfiguration::TG4VRunConfiguration(const TG4VRunConfiguration& right)
+{
+//
+  TG4Globals::Exception("TG4VRunConfiguration is protected from copying.");
+}
+
+TG4VRunConfiguration::~TG4VRunConfiguration(){
+//
+}
+
+// operators
+
+TG4VRunConfiguration& TG4VRunConfiguration::operator=(
+                                const TG4VRunConfiguration& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+  
+  TG4Globals::Exception("TG4VRunConfiguration is protected from assigning.");
+
+  return *this;  
+}    
+          
+// protected methods
+
+void TG4VRunConfiguration::ConfigureRunManager(G4RunManager* runManager)
+{
+// Sets the user action classes to G4RunManager.
+// --- 
+
+  //if (!fDetectorConstruction || !fPhysicsList || !fPrimaryGenerator)
+  //TG4Globals::Exception("Mandatory user classes are missing.");    
+  
+  // set mandatory classes
+  runManager->SetUserInitialization(fDetectorConstruction);
+  runManager->SetUserInitialization(fPhysicsList);
+  runManager->SetUserAction(fPrimaryGenerator);      
+
+  // user other action classes 
+  if (fRunAction)      runManager->SetUserAction(fRunAction);  
+  if (fEventAction)    runManager->SetUserAction(fEventAction);   
+  if (fTrackingAction) runManager->SetUserAction(fTrackingAction);   
+  if (fSteppingAction) runManager->SetUserAction(fSteppingAction);
+  if (fStackingAction) runManager->SetUserAction(fStackingAction);
+}
diff --git a/TGeant4/TG4VRunConfiguration.h b/TGeant4/TG4VRunConfiguration.h
new file mode 100644 (file)
index 0000000..c7259bf
--- /dev/null
@@ -0,0 +1,54 @@
+// $Id$
+// Category: run
+//
+// Abstract class that takes care of creating  all user defined classes 
+// that will be initialized and managed by Geant4 kernel (G4RunManager).
+// It has one pure virtual method CreateUserConfiguration()
+// that has to be be implemented by derived class.
+
+#ifndef TG4V_RUN_CONFIGURATION_H
+#define TG4V_RUN_CONFIGURATION_H
+
+class G4VUserDetectorConstruction;
+class G4VUserPhysicsList;
+class G4VUserPrimaryGeneratorAction;
+class G4UserRunAction;
+class G4UserEventAction;
+class G4UserTrackingAction;
+class G4UserSteppingAction;
+class G4UserStackingAction;
+class G4RunManager;
+
+class TG4VRunConfiguration
+{
+  public:
+    TG4VRunConfiguration();
+    // --> protected
+    // TG4VRunConfiguration(const TG4VRunConfiguration& right);
+    virtual ~TG4VRunConfiguration();
+
+    // methods
+    void ConfigureRunManager(G4RunManager* runManager);
+
+  protected:
+    TG4VRunConfiguration(const TG4VRunConfiguration& right);
+
+    // operators
+    TG4VRunConfiguration& operator=(const TG4VRunConfiguration& right);
+
+    // methods
+    virtual void CreateUserConfiguration() = 0;
+
+    // data members
+    G4VUserDetectorConstruction*    fDetectorConstruction; //det construction
+    G4VUserPhysicsList*             fPhysicsList;          //physics list
+    G4VUserPrimaryGeneratorAction*  fPrimaryGenerator;     //primary generator
+    G4UserRunAction*                fRunAction;            //run action
+    G4UserEventAction*              fEventAction;          //event action
+    G4UserTrackingAction*           fTrackingAction;       //tracking action
+    G4UserSteppingAction*           fSteppingAction;       //stepping action
+    G4UserStackingAction*           fStackingAction;       //stacking action
+};
+
+#endif //TG4V_RUN_CONFIGURATION_H
+
diff --git a/TGeant4/TG4VSensitiveDetector.cxx b/TGeant4/TG4VSensitiveDetector.cxx
new file mode 100644 (file)
index 0000000..962ac35
--- /dev/null
@@ -0,0 +1,61 @@
+// $Id$ //
+// Category: geometry
+//
+// See the class description in the header file.
+
+#include "TG4VSensitiveDetector.h"
+
+#include "TG4StepManager.h"
+
+G4int TG4VSensitiveDetector::fgSDCounter = 0;
+
+TG4VSensitiveDetector::TG4VSensitiveDetector(G4String sdName)
+  : G4VSensitiveDetector(sdName)
+{
+//
+  fID = fgSDCounter++;
+}
+
+TG4VSensitiveDetector::TG4VSensitiveDetector(G4String sdName, G4int id)
+  : G4VSensitiveDetector(sdName),
+    fID(id)
+{
+//
+  fgSDCounter++;
+}
+
+TG4VSensitiveDetector::TG4VSensitiveDetector(
+                                    const TG4VSensitiveDetector& right)
+  : G4VSensitiveDetector(right)
+{                                  
+//
+  fID = right.fID;
+
+  fgSDCounter++;;
+}
+
+TG4VSensitiveDetector::TG4VSensitiveDetector()
+  : G4VSensitiveDetector("") 
+{
+//
+}
+
+TG4VSensitiveDetector::~TG4VSensitiveDetector() {
+//
+}
+
+// operators
+
+TG4VSensitiveDetector& TG4VSensitiveDetector::operator=(
+                                    const TG4VSensitiveDetector &right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  // base class assignement
+  TG4VSensitiveDetector::operator=(right);
+  
+  fID = right.fID;
+  
+  return *this;
+}
diff --git a/TGeant4/TG4VSensitiveDetector.h b/TGeant4/TG4VSensitiveDetector.h
new file mode 100644 (file)
index 0000000..380049f
--- /dev/null
@@ -0,0 +1,52 @@
+// $Id$
+// Category: geometry
+//
+// This class adds integer identifier data member to G4VSensitiveDetector
+
+#ifndef TG4V_SENSITIVE_DETECTOR_H
+#define TG4V_SENSITIVE_DETECTOR_H
+
+#include <G4VSensitiveDetector.hh>
+#include <globals.hh>
+
+class TG4VSensitiveDetector : public G4VSensitiveDetector
+{
+  public:
+    TG4VSensitiveDetector(G4String sdName);
+    TG4VSensitiveDetector(G4String sdName, G4int id);
+    TG4VSensitiveDetector(const TG4VSensitiveDetector& right);
+    // --> protected
+    // TG4VSensitiveDetector();
+    virtual ~TG4VSensitiveDetector();
+
+    // operators
+    TG4VSensitiveDetector& operator=(const TG4VSensitiveDetector &right);
+
+    // static get method
+    static G4int GetTotalNofSensitiveDetectors();
+
+    // get methods
+    G4int GetID() const;
+    
+  protected:
+    TG4VSensitiveDetector(); 
+
+    // data members
+    G4int  fID;                //sensitive detector ID
+    
+  private:          
+    // data members
+    static G4int  fgSDCounter; //sensitive detector counter
+};
+
+// inline methods
+
+inline G4int TG4VSensitiveDetector::GetTotalNofSensitiveDetectors()
+{ return fgSDCounter; }
+
+inline G4int TG4VSensitiveDetector::GetID() const
+{ return fID; }
+
+#endif //TG4V_SENSITIVE_DETECTOR_H
+
+
diff --git a/TGeant4/TG4VisManager.cxx b/TGeant4/TG4VisManager.cxx
new file mode 100644 (file)
index 0000000..5dee7a4
--- /dev/null
@@ -0,0 +1,850 @@
+// $Id$
+// Category: visualization
+//
+// According to visualization/management/include/MyVisManager.*
+// John Allison 24th January 1998.
+// I. Hrivnacova 12.5.98
+//
+// Renamed to TG4VisManager
+// I. Hrivnacova, 3.9.99
+//
+// Added AliMC implementation
+// A. Gheata, 22.2.00
+//
+// Added OpenGL*Win32, RayTracer (as replacement of RayX) drivers 
+// based on G4 suggestions.
+// I. Gonzalez, 4.4.2000
+//
+// Example Visualization Manager description:
+//   Implements virtual function RegisterGraphicsSystems.  
+//   Exploits C-pre-processor variables G4VIS_USE_DAWN, etc.,
+//   which are set by the G4 makefiles if
+//   environment variables of the same name are set.
+//
+// So all you have to do is set environment variables and compile and
+//   instantiate this in your main().
+//
+// Alternatively, you can implement an empty function here and just
+//   register the systems you want in your main(), e.g.:
+//   G4VisManager* myVisManager = new MyVisManager;
+//   myVisManager -> RegisterGraphicsSystem (new MyGraphicsSystem);
+
+
+#include "TG4Globals.h"
+
+#include <G4LogicalVolumeStore.hh>
+#include <G4PhysicalVolumeStore.hh>
+#include <G4PhysicalVolumeModel.hh>
+#include <G4LogicalVolumeModel.hh>
+#include <G4TransportationManager.hh>
+#include <G4Material.hh>
+
+#ifdef G4VIS_USE
+#include "TG4VisManager.h"
+
+#include <G4VVisManager.hh>
+
+// Supported drivers...
+
+#ifdef G4VIS_USE_DAWN
+#include <G4FukuiRenderer.hh>
+#endif
+
+#ifdef G4VIS_USE_DAWNFILE
+#include <G4DAWNFILE.hh>
+#endif
+
+#ifdef G4VIS_USE_OPACS
+#include <G4Wo.hh>
+#include <G4Xo.hh>
+#endif
+
+#ifdef G4VIS_USE_OPENGLX
+#include <G4OpenGLImmediateX.hh>
+#include <G4OpenGLStoredX.hh>
+#endif
+
+#ifdef G4VIS_USE_OPENGLXM
+#include <G4OpenGLImmediateXm.hh>
+#include <G4OpenGLStoredXm.hh>
+#endif
+
+#ifdef G4VIS_USE_OPENGLWIN32
+#include "G4OpenGLImmediateWin32.hh"
+#include "G4OpenGLStoredWin32.hh"
+#endif
+
+#ifdef G4VIS_USE_OIX
+#include <G4OpenInventorX.hh>
+#endif
+
+#ifdef G4VIS_USE_OIWIN32
+#include <G4OpenInventorWin32.hh>
+#endif
+
+#ifdef G4VIS_USE_RAYTRACER
+#include "G4RayTracer.hh"
+#endif
+
+#ifdef G4VIS_USE_VRML
+#include <G4VRML1.hh>
+#include <G4VRML2.hh>
+#endif
+
+#ifdef G4VIS_USE_VRMLFILE
+#include <G4VRML1File.hh>
+#include <G4VRML2File.hh>
+#endif
+
+TG4VisManager::TG4VisManager(G4int verboseLevel) {
+//  
+  fVerbose = verboseLevel; 
+  fColourFlag = true;
+}
+
+TG4VisManager::TG4VisManager(const TG4VisManager& right) {
+// 
+  TG4Globals::Exception(
+    "Attempt to copy TG4VisManager singleton.");
+}
+
+TG4VisManager::~TG4VisManager() {
+//
+}  
+
+// operators
+
+TG4VisManager& TG4VisManager::operator=(const TG4VisManager& right) 
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception(
+    "Attempt to assign TG4VisManager singleton.");
+    
+  return *this;  
+}    
+          
+// private methods
+
+void TG4VisManager::RegisterGraphicsSystems() 
+{
+// Registers the graphics systems.
+// ---
+
+  // all created graphics system instances are
+  // deleted in G4VisManager::~G4VisManager()
+#ifdef G4VIS_USE_DAWN
+  RegisterGraphicsSystem(new G4FukuiRenderer);
+#endif
+
+#ifdef G4VIS_USE_DAWNFILE
+  RegisterGraphicsSystem(new G4DAWNFILE);
+#endif
+
+#ifdef G4VIS_USE_OPACS
+  RegisterGraphicsSystem(new G4Wo);
+  RegisterGraphicsSystem(new G4Xo);
+#endif
+
+#ifdef G4VIS_USE_OPENGLX
+  RegisterGraphicsSystem(new G4OpenGLImmediateX);
+  RegisterGraphicsSystem(new G4OpenGLStoredX);
+#endif
+
+#ifdef G4VIS_USE_OPENGLXM
+  RegisterGraphicsSystem(new G4OpenGLImmediateXm);
+  RegisterGraphicsSystem(new G4OpenGLStoredXm);
+#endif
+
+#ifdef G4VIS_USE_OPENGLWIN32
+  RegisterGraphicsSystem (new G4OpenGLImmediateWin32);
+  RegisterGraphicsSystem (new G4OpenGLStoredWin32);
+#endif
+
+#ifdef G4VIS_USE_OIX
+  RegisterGraphicsSystem(new G4OpenInventorX);
+#endif
+
+#ifdef G4VIS_USE_OIWIN32
+  RegisterGraphicsSystem(new G4OpenInventorWin32);
+#endif
+
+#ifdef G4VIS_USE_RAYTRACER
+  RegisterGraphicsSystem (new G4RayTracer);
+#endif
+
+#ifdef G4VIS_USE_VRML
+  RegisterGraphicsSystem(new G4VRML1);
+  RegisterGraphicsSystem(new G4VRML2);
+#endif
+
+#ifdef G4VIS_USE_VRMLFILE
+  RegisterGraphicsSystem(new G4VRML1File);
+  RegisterGraphicsSystem(new G4VRML2File);
+#endif
+
+  if (fVerbose > 0) {
+    cout <<
+      "\nYou have successfully chosen to use the following graphics systems."
+        << endl;
+    PrintAvailableGraphicsSystems();
+  }
+}
+
+//---------------------------------------------------------------
+// private methods
+//---------------------------------------------------------------
+
+
+G4RWTPtrOrderedVector<G4LogicalVolume> TG4VisManager::GetLVList(G4String name)
+{
+// Get function returning the list of logical volumes
+// associated to NAME; G4 built clones of a G3 volume (identified 
+// with NAME_NUMBER will be added to the list)  
+//  NAME can be the name of a logical or physical volume
+// ---
+
+ G4RWTPtrOrderedVector <G4LogicalVolume> lvList;
+ G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+ G4LogicalVolume* pLV = 0; 
+ if (pLVStore)
+ {
+   for (G4int i=0; i<pLVStore->entries(); i++)
+   {
+     pLV = pLVStore->at(i);  
+     if (CaseInsensitiveEqual(name,pLV->GetName())) 
+     {
+       if (!lvList.contains(pLV)) lvList.append(pLV);
+     }
+   }
+ }  
+ if (!lvList.isEmpty()) return lvList;
+ G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
+ G4VPhysicalVolume* pPV = 0;
+ if (pPVStore) 
+ {
+   for (G4int i=0; i<pPVStore->entries(); i++)
+   {
+     pPV = pPVStore->at(i); 
+     if (CaseInsensitiveEqual(name,pPV->GetName())) 
+     {
+       pLV = pPV->GetLogicalVolume();
+       if (!lvList.contains(pLV)) lvList.append(pLV);
+     }     
+   }
+ }  
+ return lvList;
+}
+
+
+G4RWTPtrOrderedVector<G4VPhysicalVolume> TG4VisManager::GetPVList(G4String name)
+{
+// Get function returning the physical volume pointer for NAME
+// ---
+
+  G4RWTPtrOrderedVector <G4VPhysicalVolume> pvList;
+  G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
+  if (!pPVStore)
+  {
+    TG4Globals::Warning("TG4VisManager::Gdraw : No volume store !");
+    return pvList;
+  }
+  G4VPhysicalVolume* pPV = 0;
+  for (G4int i=0; i<pPVStore->entries(); i++)
+  {
+    pPV = pPVStore->at(i);
+    if (CaseInsensitiveEqual(name,pPV->GetName()))
+    {
+      if (!pvList.contains(pPV)) pvList.append(pPV);
+    }  
+  }
+  return pvList;
+}
+
+
+G4bool TG4VisManager::CaseInsensitiveEqual(const G4String string1,
+                                          const G4String string2)
+{
+// Case insensitive comparison of 2 strings
+// ---
+
+  G4int i;
+  if (string1 == string2) return true;
+//  if (string1.length() != string2.length()) return false;
+  for (i=0; i<string1.length(); i++)
+  {
+    G4int diff = abs((G4int)string1(i)-(G4int)string2(i));
+    if (diff && (diff!=32)) return false;
+  }
+  if (string2.length() > string1.length())
+  {
+    if (string2(i) == '_') return true;
+    return false;
+  }    
+  return true;
+}
+
+void TG4VisManager::SetAtt4Daughters(G4LogicalVolume* const lv, 
+                                    const TG3Attribute att, const G4int val)
+{
+// Iterator for setting a visual attribute for all daughters
+// ---
+
+  SetG4Attribute(lv,att,val);  
+  
+  G4String lvName = lv->GetName();
+  G4int nOfDaughters = lv->GetNoDaughters();
+  if (nOfDaughters>0)
+  {
+    G4String previousName = "";
+    for (G4int i=0; i<nOfDaughters; i++) 
+    { 
+      G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume(); 
+      G4String currentName = lvd->GetName();
+      if (currentName != lvName && currentName != previousName)
+      {
+        SetAtt4Daughters(lvd, att, val);
+        previousName = currentName;
+      } 
+    }
+  }   
+}
+
+
+G4bool TG4VisManager::IsSharedVisAttributes(const G4LogicalVolume* pLV)
+{
+// Function seeking if the volume's visible attributes are shared with
+//  other volumes
+// ---
+
+  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+  G4LogicalVolume* pLVCurrent = 0;
+  const G4VisAttributes* pVisAtt = pLV->GetVisAttributes();
+  if (!pVisAtt) return false;
+  for (G4int i=0; i<pLVStore->entries(); i++)
+  {
+    pLVCurrent = pLVStore->at(i);
+    if (pLVCurrent != pLV)
+    {
+      if (pLVCurrent->GetVisAttributes() == pVisAtt) 
+      {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+
+void TG4VisManager::SetG4Attribute(G4LogicalVolume* const lv,
+                                  const TG3Attribute att, const G4int val)
+{
+// Set the G4 attribute fo volume LV accordingly to the G3 description
+//  of (att- val)    
+// --
+
+ if (!lv) return;
+ // Dupplicating old vis. attributes    
+ const G4VisAttributes* visAttributes = lv->GetVisAttributes();
+ G4VisAttributes* newVisAttributes;
+ if (!visAttributes)
+   newVisAttributes    = new G4VisAttributes(false);
+ else
+   newVisAttributes    = new G4VisAttributes(visAttributes);
+
+ const G4int absVal = abs(val);        // the functionality is given by the abs value
+
+ // Default visible attributes
+ G4double red(0),green(0),blue(0); // default is black
+ G4bool isVisible(false);
+ G4bool isDaughtersInvisible(false);
+ G4VisAttributes::LineStyle lineStyle = G4VisAttributes::unbroken;
+ G4double lineWidth = 1.0;
+ G4bool isForceDrawingStyle(false);
+ G4VisAttributes::ForcedDrawingStyle drawingStyle = G4VisAttributes::wireframe;
+ // a 'hardcopy' of old vis attributes is needed because the copy constructor
+ // resets to defaults some of the data members of G4VisAttributes class
+ if (visAttributes)
+ {
+   isVisible         = visAttributes->IsVisible();
+   isDaughtersInvisible = visAttributes->IsDaughtersInvisible();
+   red   = visAttributes->GetColour().GetRed();
+   green = visAttributes->GetColour().GetGreen(); 
+   blue         = visAttributes->GetColour().GetBlue();        // old RGB components
+   lineStyle = visAttributes->GetLineStyle();
+   lineWidth = visAttributes->GetLineWidth();
+   isForceDrawingStyle = visAttributes->IsForceDrawingStyle();
+   if (isForceDrawingStyle) 
+       drawingStyle = visAttributes->GetForcedDrawingStyle();
+   
+ }
+ G4double luminosityBin(0.04),  // bin for luminosity 
+          luminosity(0);       // colour luminosity
+
+ // Delete old vis. attributes if they are not shared
+ if (visAttributes && !IsSharedVisAttributes(lv)) delete visAttributes;
+
+ // Set the required attribute
+ switch (att)
+ {
+  case kSEEN:
+   switch (val)
+   {
+    case  0:
+     isVisible = false; 
+     break;
+    case  1:
+     isVisible = true;  
+     break;
+    case -1:
+     isVisible = false; 
+     break;
+    case -2:
+     isVisible = false; 
+     break;
+    default:
+     isVisible = false; 
+   }       
+   break;
+  case kLSTY:
+   switch (absVal)
+   {
+    case 1:
+     lineStyle = G4VisAttributes::unbroken; break;
+    case 2:
+     lineStyle = G4VisAttributes::dashed; break;
+    case 3:
+     lineStyle = G4VisAttributes::dotted; break;
+    default:
+     if (fVerbose > 0)
+      G4cout << "TG4VisManager::Gsatt() Usage of LSTY :" << endl
+            << "ATT = 1,2,3 means line unbroken, dashed or dotted" << endl
+            << "any other value resets to the default : unbroken" << endl;
+     lineStyle = G4VisAttributes::unbroken;
+   }       
+   break;
+  case kLWID:
+   lineWidth = absVal;
+   if (lineWidth > 7) lineWidth = 7;
+   if (fVerbose > 0) 
+       G4cout << "TG4VisManager::Gsatt() Usage for LWID :" << endl
+              << "  The VAL you supply means the width of lines in pixels "
+             << "for the screen and in 0.1*mm for paper." << endl
+             << "  Negative values means the same, but for all daughters"
+             << endl;
+   break;
+  case kCOLO:
+   if (absVal < 8)     // G3 base colours
+   {
+    switch (absVal)
+    {
+     case 1:
+       red=0; green=0; blue=0;         //black
+       break;                  
+     case 2:
+       red=1; green=0; blue=0;         //red
+       break;                  
+     case 3:
+       red=0; green=1; blue=0;         //green
+       break;                  
+     case 4:
+       red=0; green=0; blue=1;         //blue
+       break;                  
+     case 5:
+       red=1; green=1; blue=0;         //yellow
+       break;                  
+     case 6:
+       red=1; green=0; blue=1;         //violet
+       break;                  
+     case 7:
+       red=0; green=1; blue=1;         //lightblue (almost !)
+    }
+    luminosity = 0.;
+   }
+   if (absVal>=8 && absVal<=16)
+   {
+     red=0; green=0; blue=0;
+     luminosity = (absVal-7)*luminosityBin;
+   }
+   if (absVal>=17 && absVal<=41)
+   {
+     red=1; green=0; blue=0;
+     luminosity = (absVal-16)*luminosityBin;
+   }
+   if (absVal>=67 && absVal<=91)
+   {
+     red=0; green=1; blue=0;
+     luminosity = (absVal-66)*luminosityBin;
+   }
+   if (absVal>=117 && absVal<=141)
+   {
+     red=0; green=0; blue=1;
+     luminosity = (absVal-116)*luminosityBin;
+   }
+   if (absVal>=42 && absVal<=66)
+   {
+     red=1; green=1; blue=0;
+     luminosity = (absVal-41)*luminosityBin;
+   }
+   if (absVal>=142 && absVal<=166)
+   {
+     red=1; green=0; blue=1;
+     luminosity = (absVal-141)*luminosityBin;
+   }
+   if (absVal>=92 && absVal<=116)
+   {
+     red=0; green=1; blue=1;
+     luminosity = (absVal-91)*luminosityBin;
+   }
+   if (red < luminosityBin)    red += luminosity;
+   if (green < luminosityBin) green += luminosity;
+   if (blue < luminosityBin)   blue += luminosity;
+   break;
+  case kFILL:
+   isForceDrawingStyle = true;
+   switch (absVal)
+   {
+    case 0:
+     drawingStyle = G4VisAttributes::wireframe;
+     break;
+    case 1:
+     drawingStyle = G4VisAttributes::solid;
+     break;
+    default:
+     if (fVerbose > 0)
+         G4cout << "TG4VisManager::Gsatt() FILL usage :" << endl
+               << "  The FILL values you can supply are only :" << endl
+               << "+/- 1 : forces wireframe drawing (default)" << endl
+               << "+/- 2 : forces solid drawing" << endl
+               << "other values sets the drawing style to solid"
+               << endl;                
+     drawingStyle = G4VisAttributes::solid;
+   }      
+ }
+ // Register vis. attributes
+ newVisAttributes->SetVisibility(isVisible);
+ newVisAttributes->SetDaughtersInvisible(isDaughtersInvisible);
+ newVisAttributes->SetColour(red,green,blue);
+ newVisAttributes->SetLineStyle(lineStyle);
+ newVisAttributes->SetLineWidth(lineWidth);
+ if (drawingStyle == G4VisAttributes::wireframe) 
+       newVisAttributes->SetForceWireframe(isForceDrawingStyle);
+ if (drawingStyle == G4VisAttributes::solid) 
+       newVisAttributes->SetForceSolid(isForceDrawingStyle);
+ lv->SetVisAttributes(newVisAttributes);
+} 
+  
+//-----------------------------------------------------------------
+// functions for drawing
+//-----------------------------------------------------------------
+
+void TG4VisManager::DrawOneSpec(const char* name)
+{
+// Function called when one double-clicks on a volume name
+// in a TPaveLabel drawn by Gdtree
+// ---
+
+ G4cout << "TG4VisManager::DrawOneSpec() Not yet implemented";
+}
+
+
+void TG4VisManager::SetColors()
+{
+// Function for setting default volume colours
+// ---
+
+  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+  const G4LogicalVolume* pLV = 0; 
+  if (!pLVStore)
+  {
+    TG4Globals::Warning("TG4VisManager::SetColors : Ignored, geometry not built.");
+    return;
+  }
+  // parse the LV tree and set colours according to material density
+  for (G4int i=0; i<pLVStore->entries(); i++)
+  {
+    pLV = pLVStore->at(i);
+//    G4cout << "VOLUME : " << pLV->GetName() << endl;
+    const G4Material* pMaterial = pLV->GetMaterial();
+    const G4State state = pMaterial->GetState();
+    G4double density = (pMaterial->GetDensity())*cm3/g;
+    G4String nState = "Undefined";
+    G4int colour = 1;                  //black by default
+    G4double luminosity = 0.;
+    if (state == kStateUndefined) 
+    {
+      nState = "Undefined";
+    }
+    if (state == kStateSolid) 
+    {
+      nState = "Solid";
+      if (density < 2)
+      {
+        colour = 17;   //red
+       luminosity = 25 - 25*density/2;
+      }
+      else if (density < 3)
+      {
+        colour = 117;  //blue
+       luminosity = 25 - 25*(density-2);
+      }
+      else if (density < 10)
+      {
+        colour = 67;   //green
+       luminosity = 25 - 25*(density-5)/5;
+      }
+      else if (density < 15)
+      {
+        colour = 92;   //cyan
+       luminosity = 25 - 25*(density-10)/5;
+      }
+      else if (density < 20)
+      {
+        colour = 8;    //black
+       luminosity = 9 - 9*(density-15)/5;
+      }
+    }
+    if (state == kStateLiquid) 
+    {
+      nState = "Liquid";
+      colour = 142;    //violet
+      luminosity = 25 - 25*density/2;
+    }
+    if (state == kStateGas) 
+    {
+      nState = "Gas";
+      if (density < 0.001)  {colour = 42;}     //yellow
+      else if (density < 0.002) {colour = 27;} //light red
+      else if (density < 0.003) {colour = 77;} //light green
+      else {colour = 102;}                     //light cyan
+      luminosity = 0;
+    }
+    if (luminosity < 0) luminosity=0;
+    colour += (G4int)luminosity;
+    //  Setting the corresponding colour
+    Gsatt(pLV->GetName(),"COLO",colour);
+  }
+} 
+  
+
+void TG4VisManager::Gsatt(const char* name, const char* att, Int_t val)
+{
+// Geant3 description :
+//  
+//    NAME   Volume name
+//    IOPT   Name of the attribute to be set
+//    IVAL   Value to which the attribute is to be set
+//  
+//    name= "*" stands for all the volumes.
+//    iopt can be chosen among the following :
+//    kWORK, kSEEN, kLSTY, kLWID, kCOLO, kFILL, kSET, kDET, kDTYP
+// ---
+
+ G4int ival = val;
+ G4LogicalVolume* lv = 0; 
+ G4RWTPtrOrderedVector<G4LogicalVolume> lvList;
+ G4String sname(name),
+          satt(att);           
+
+ // seek for known attributes
+ TG3Attribute attribute = kUNKNOWN;
+ if (CaseInsensitiveEqual(att,"WORK"))
+ {
+   G4String message = "TG4VisManager::Gsatt: G3Attribute ";
+   message += satt + " not used in G4";
+   TG4Globals::Warning(message);
+   return;
+ }
+ if (CaseInsensitiveEqual(att,"SEEN")) attribute = kSEEN;  
+ if (CaseInsensitiveEqual(att,"LSTY")) attribute = kLSTY;  
+ if (CaseInsensitiveEqual(att,"LWID")) attribute = kLWID;
+ if (CaseInsensitiveEqual(att,"COLO")) attribute = kCOLO;  
+ if (CaseInsensitiveEqual(att,"FILL")) attribute = kFILL;  
+ if (CaseInsensitiveEqual(att,"SET"))
+ {
+   G4String message = "TG4VisManager::Gsatt: G3Attribute ";
+   message += satt + " not used in G4";
+   TG4Globals::Warning(message);
+   return;
+ }
+ if (CaseInsensitiveEqual(att,"DET"))
+ {
+   G4String message = "TG4VisManager::Gsatt: G3Attribute ";
+   message += satt + " not used in G4";
+   TG4Globals::Warning(message);
+   return;
+ }
+ if (CaseInsensitiveEqual(att,"DTYP"))
+ {
+   G4String message = "TG4VisManager::Gsatt: G3Attribute ";
+   message += satt + " not used in G4";
+   TG4Globals::Warning(message);
+   return;
+ }
+ if (attribute == kUNKNOWN)
+ {
+   G4String message = "TG4VisManager::Gsatt: G3Attribute ";
+   message += satt + " unknown";
+   TG4Globals::Warning(message);
+   return;
+ }
+ G4bool         doForDaughters(false),         // tree iterator flag 
+         doForAll(false),              // activated if NAME is "*" 
+        topVisible(false);             // activated for kSEEN/-2
+ if (sname == "*")     doForAll = true;
+ if (val < 0 && sname!="*") doForDaughters = true;
+ if (attribute==kSEEN && val==-2) topVisible = true;
+ // parse all the tree
+ if (doForAll)
+ {
+     G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
+     for (G4int i=0; i<pLVStore->entries(); i++)
+     {
+         lv = pLVStore->at(i);
+        SetG4Attribute(lv,attribute,ival);
+     }
+     return;
+ }
+
+ // get the logical volume pointer corresponding to NAME
+ lvList = GetLVList(name);
+ if (lvList.isEmpty())
+ {
+     G4String message = "TG4VisManager::Gsatt(): Ignored\n";
+     message += "    Logical volume " + sname + " has not been found.\n";
+     TG4Globals::Warning(message); 
+     return;
+ }
+// set attribute for all descendents
+ if (doForDaughters)
+ {
+   for (G4int i=0; i<lvList.entries(); i++)
+   {
+     lv = lvList[i];
+     SetAtt4Daughters(lv,attribute,ival);
+   }     
+ }
+ else
+ {
+   for (G4int i=0; i<lvList.entries(); i++)
+   {
+     lv = lvList[i];
+     SetG4Attribute(lv,attribute,ival);
+   }     
+ }
+ if (topVisible) 
+ {
+   for (G4int i=0; i<lvList.entries(); i++)
+   {
+     lv = lvList[i];
+     SetG4Attribute(lv,attribute,1); 
+   }
+ }       
+} 
+
+
+void TG4VisManager::Gdraw(const char *name,Float_t theta, Float_t phi, Float_t psi,
+                   Float_t u0,Float_t v0,Float_t ul,Float_t vl)
+{ 
+// Draw the physical volume NAME and all descendents;
+// Mandatory : the graphics system, scene and view must be
+//     initialized, e.g. "/vis~/create_view/new_graphics_system OGLSX";
+//     Any call of Gdraw() will use the current graphics system and
+//     the current window.
+// The result will be a centered view drawing of the designated volume,
+//     lights moving with camera, viewpoint direction given by theta/phi
+//     and rotation on the screen given by psi;
+// The u0, v0, ul, vl factors are ignored since the object will be 
+//     automatically centered and will be confortable in the window
+//     at any viewing angle.
+//
+// check if G4 graphics is ready for drawing
+// ---
+
+  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
+  if (!pVVisManager) { 
+    TG4Globals::Warning(
+       "TG4VisManager::Gdraw: Ignored - No graphics driver is built. ");
+    return;
+  }     
+  if (NeedSetColours())
+  {
+    SetColors();
+    SetColourFlag(false);
+  }
+  
+  const G4double rad = M_PI/180.;
+  G4RWTPtrOrderedVector<G4VPhysicalVolume> pvList;
+  G4String sname(name);
+  G4bool  successful           = false;
+
+  pvList = GetPVList(name);
+  if (pvList.isEmpty())
+  {
+    G4String message = "TG4VisManager::Gdraw() :\n";
+    message += "Volume " + sname + " not found. Bailing out";
+    TG4Globals::Warning(message); 
+    return;
+  }
+
+  G4VPhysicalVolume *pPV = 0;
+
+  // clear the current scene if not empty
+  if (!fpScene->IsEmpty()) fpScene->Clear();
+
+  // create and add object's model list to the runtime-duration model 
+  // list and draw it
+  // (it is deleted in the VisManager destructor within 
+  // all the RWTPtrOrderedVectors of the scene)
+  for (G4int i=0; i<pvList.entries(); i++)
+  { 
+    pPV = pvList[i];
+    G4LogicalVolume* pLV = pPV->GetLogicalVolume();
+    G4VSolid* pSolid = pLV->GetSolid();
+
+    successful = fpScene->AddRunDurationModel(new G4PhysicalVolumeModel(pPV));
+    if (!successful) 
+    {
+      G4String message = "TG4VisManager::Gdraw() Could not add ";
+      message += pPV->GetName() + " to the drawing list. Probably ";
+      message += "it is already in the list.";
+      TG4Globals::Warning(message);
+    }  
+  }
+  // get the standard target point of the scene
+  const G4Point3D targetPoint = fpScene->GetStandardTargetPoint();
+
+  // set the viewpoint and the rotation on the screen
+  G4Vector3D viewpointDirection(sin(theta*rad)*cos(phi*rad), 
+                                sin(theta*rad)*sin(phi*rad), cos(theta*rad)); 
+  G4Vector3D upVector(sin(psi*rad), cos(psi*rad),0);                          
+
+  // set and register view parameters to the viewer
+  
+  fVP.SetLightsMoveWithCamera(true);
+  fVP.SetViewGeom();
+  fVP.UnsetViewHits();
+  fVP.UnsetViewDigis();
+  fVP.SetNoOfSides(48);
+  fVP.SetCurrentTargetPoint(targetPoint);
+  fVP.SetViewpointDirection(viewpointDirection);
+  fVP.SetUpVector(upVector);
+  fVP.SetDensityCulling(true);
+  fpViewer->SetViewParameters(fVP);
+
+  if (IsValidView())
+  {
+    fpSceneHandler->SetScene(fpScene);
+    fpSceneHandler->SetCurrentViewer(fpViewer);
+    fpViewer->DrawView();
+    fpViewer->ShowView();
+  }
+  else TG4Globals::Warning(
+         "TG4VisManager::Gdraw: Ignored - Failed to register volume"); 
+}
+#endif //G4VIS_USE
diff --git a/TGeant4/TG4VisManager.h b/TGeant4/TG4VisManager.h
new file mode 100644 (file)
index 0000000..6986426
--- /dev/null
@@ -0,0 +1,97 @@
+// $Id$
+// Category: visualization
+//
+// G4VisManager derived class that takes care of registering
+// graphics syystem and provides 
+// Geant4 implementation of the MonteCarlo interface methods                    
+// for visualization.
+
+#ifndef TG4_VIS_MANAGER_H
+#define TG4_VIS_MANAGER_H
+#ifdef G4VIS_USE
+
+#include "TG3Attribute.h"
+
+#include <G4VisManager.hh>
+#include <g4rw/tpordvec.h>
+
+#include <Rtypes.h>
+
+class TG4VisManager: public G4VisManager 
+{
+  public:
+    TG4VisManager(G4int verboseLevel = 0);  
+      // Controls initial verbose level of VisManager and VisMessenger.
+      // Can be changed by /vis/set/verbose.
+    // --> protected  
+    // TG4VisManager(const TG4VisManager& right);
+    virtual ~TG4VisManager();  
+    
+    //----------------------  
+    // functions for drawing
+    //----------------------
+    void DrawOneSpec(const char* name); // not implemented
+    
+    // see TG4VisManager.cxx for detailed description of Gsatt(), Gdraw()
+    void Gsatt(const char* name, const char* att, Int_t val);
+    void Gdraw(const char* name, Float_t theta , Float_t phi, 
+               Float_t psi, Float_t u0, Float_t v0, Float_t ul, 
+              Float_t vl);
+    void SetColors();
+
+  protected:
+    TG4VisManager(const TG4VisManager& right);
+
+    // operators
+    TG4VisManager& operator=(const TG4VisManager& right);
+
+  private:
+    // methods
+    //--------
+    void RegisterGraphicsSystems();
+    G4bool NeedSetColours();
+    void SetColourFlag(G4bool value);
+    
+    // methods used by Gsatt(), Gdraw()
+    //---------------------------------
+    
+    // Get the logical volume list corresponding to NAME
+    //         Either a logical or physical volume name can be supplied
+    // Clones of G3VOLUME_NUMBER will be atached to the list   
+    G4RWTPtrOrderedVector<G4LogicalVolume> GetLVList(G4String name);
+
+    // Get the physical volume list corresponding to NAME
+    G4RWTPtrOrderedVector<G4VPhysicalVolume> GetPVList(G4String name);
+    
+    // Case insensitive string comparison
+    G4bool CaseInsensitiveEqual(const G4String string1,
+                               const G4String string2);
+    
+    // Return true if the vis. attributes pointer corresponding to the 
+    // selected volume is shared by others. In this case, duplication
+    //  of those is mandatory
+    G4bool IsSharedVisAttributes(const G4LogicalVolume* pLV);
+    
+    // Set an attribute to a specific volume
+    void SetG4Attribute(G4LogicalVolume* const lv, const TG3Attribute att,
+                       const G4int val);
+    // Set an attribute to the tree coresponding to a volume                   
+    void SetAtt4Daughters(G4LogicalVolume* const lv, const TG3Attribute att,
+                       const G4int val);                           
+
+    //data members
+    //------------
+    G4bool fColourFlag; //colour flag
+};
+
+// inline methods
+
+inline G4bool TG4VisManager::NeedSetColours()
+{ return fColourFlag; }
+
+inline void TG4VisManager::SetColourFlag(G4bool value)
+{ fColourFlag = value; }
+
+
+#endif //G4VIS_USE
+#endif //TG4_VIS_MANAGER_H
diff --git a/TGeant4/TGeant4.cxx b/TGeant4/TGeant4.cxx
new file mode 100644 (file)
index 0000000..a18d5ec
--- /dev/null
@@ -0,0 +1,446 @@
+// $Id$
+// Category: run
+//
+// See the class description in the header file.
+
+#include "TGeant4.h"
+#include "TG4Messenger.h"
+#include "TG4GeometryManager.h" 
+#include "TG4PhysicsManager.h" 
+#include "TG4StepManager.h" 
+#include "TG4VisManager.h"
+#include "TG4RunManager.h"
+#include "TG4Globals.h"
+
+TGeant4::TGeant4(const char* name, const char* title,
+                 TG4VRunConfiguration* configuration, int argc, char** argv)
+  : AliMC(name, title),
+    fVisManager(0)
+{
+  // create run manager
+  fRunManager = new TG4RunManager(configuration, argc, argv);
+  // add verbose level
+  //G4cout << "TG4RunManager has been created." << endl;
+
+  // create geometry manager
+  fGeometryManager = new TG4GeometryManager();
+  // add verbose level
+  //G4cout << "TG4GeometryManager has been created." << endl;
+  
+  // create physics manager  
+  fPhysicsManager = new TG4PhysicsManager();
+  // add verbose level
+  //G4cout << "TG4GeometryManager has been created." << endl;
+  
+  // create step manager 
+  fStepManager = new TG4StepManager();
+  // add verbose level
+  //G4cout << "TG4StepManager has been created." << endl;
+  
+#ifdef G4VIS_USE
+  // create visualization manager
+  fVisManager = new TG4VisManager();
+  fVisManager->Initialize();
+#endif
+
+  // create messenger
+  fMessenger = 
+    new TG4Messenger(fGeometryManager, fPhysicsManager, fStepManager);
+}
+    
+TGeant4::TGeant4(const char* name, const char* title,
+                 TG4VRunConfiguration* configuration)
+  : AliMC(name, title),
+    fVisManager(0)
+{
+  // create run manager
+  fRunManager = new TG4RunManager(configuration);
+  // add verbose level
+  //G4cout << "TG4RunManager has been created." << endl;
+
+  // create geometry manager
+  fGeometryManager = new TG4GeometryManager();
+  // add verbose level
+  //G4cout << "TG4GeometryManager has been created." << endl;
+  
+  // create physics manager  
+  fPhysicsManager = new TG4PhysicsManager();
+  // add verbose level
+  //G4cout << "TG4GeometryManager has been created." << endl;
+  
+  // create step manager 
+  fStepManager = new TG4StepManager();
+  // add verbose level
+  //G4cout << "TG4StepManager has been created." << endl;
+  
+#ifdef G4VIS_USE
+  // create visualization manager
+  fVisManager = new TG4VisManager();
+  fVisManager->Initialize();
+#endif
+
+  // create messenger
+  fMessenger = 
+    new TG4Messenger(fGeometryManager, fPhysicsManager, fStepManager);
+}
+    
+TGeant4::TGeant4() {
+//
+}
+
+TGeant4::TGeant4(const TGeant4& right) {
+// 
+  TG4Globals::Exception("TGeant4 is protected from copying.");
+}
+
+TGeant4::~TGeant4() {
+//
+  delete fRunManager;
+  delete fGeometryManager;
+  delete fPhysicsManager;
+  delete fStepManager;
+  // fVisManager is deleted with G4RunManager destructor
+  delete fMessenger;
+}
+
+// operators
+
+TGeant4& TGeant4::operator=(const TGeant4& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  TG4Globals::Exception("TGeant4 is protected from assigning.");
+    
+  return *this;  
+}    
+          
+
+// methods for building/management of geometry
+// ------------------------------------------------
+
+void TGeant4::FinishGeometry() {
+//
+  fGeometryManager->Ggclos();
+} 
+
+void TGeant4::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,  
+                        Float_t &dens, Float_t &radl, Float_t &absl,
+                        Float_t* ubuf, Int_t& nbuf) {
+//
+  fGeometryManager
+    ->Gfmate(imat, name, a, z, dens, radl, absl, ubuf, nbuf);
+} 
+
+void TGeant4::Material(Int_t& kmat, const char* name, Float_t a, 
+                     Float_t z, Float_t dens, Float_t radl, Float_t absl,
+                     Float_t* buf, Int_t nwbuf) {
+//
+  fGeometryManager
+    ->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf); 
+} 
+
+void TGeant4::Mixture(Int_t& kmat, const char *name, Float_t *a, 
+                     Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat) {
+//
+   fGeometryManager
+     ->Mixture(kmat, name, a, z, dens, nlmat, wmat); 
+} 
+
+void TGeant4::Medium(Int_t& kmed, const char *name, Int_t nmat, 
+                     Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd, 
+                     Float_t stemax, Float_t deemax, Float_t epsil, 
+                    Float_t stmin, Float_t* ubuf, Int_t nbuf) { 
+//
+  fGeometryManager
+    ->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, 
+        epsil, stmin, ubuf, nbuf);
+} 
+
+void TGeant4::Matrix(Int_t& krot, Float_t thetaX, Float_t phiX, 
+                     Float_t thetaY, Float_t phiY, Float_t thetaZ, 
+                    Float_t phiZ) {
+//                  
+  fGeometryManager
+    ->Matrix(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ); 
+} 
+
+void TGeant4::Gstpar(Int_t itmed, const char *param, Float_t parval) {
+//
+  fGeometryManager->Gstpar(itmed, param, parval); 
+}    
+
+void TGeant4::Gsckov(Int_t itmed, Int_t npckov, Float_t *ppckov,
+                    Float_t *absco, Float_t *effic, Float_t *rindex) {
+//
+
+  fGeometryManager->Gsckov(itmed, npckov, ppckov, absco, effic, rindex);
+}                                    
+
+Int_t TGeant4::Gsvolu(const char *name, const char *shape, Int_t nmed,  
+                         Float_t *upar, Int_t np)  {
+//
+  return fGeometryManager->Gsvolu(name, shape, nmed, upar, np); 
+}
+void TGeant4::Gsdvn(const char *name, const char *mother, Int_t ndiv, 
+                        Int_t iaxis) {
+//
+  fGeometryManager->Gsdvn(name, mother, ndiv, iaxis); 
+} 
+
+void TGeant4::Gsdvn2(const char *name, const char *mother, Int_t ndiv, 
+                         Int_t iaxis, Float_t c0i, Int_t numed) {
+//
+  fGeometryManager->Gsdvn2(name, mother, ndiv, iaxis, c0i, numed); 
+} 
+
+void TGeant4::Gsdvt(const char *name, const char *mother, Float_t step, 
+                        Int_t iaxis, Int_t numed, Int_t ndvmx) {
+//                     
+  fGeometryManager->Gsdvt(name, mother, step, iaxis, numed, ndvmx); 
+} 
+
+void TGeant4::Gsdvt2(const char *name, const char *mother, Float_t step, 
+                         Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx) { 
+//
+  fGeometryManager->Gsdvt2(name, mother, step, iaxis, c0, numed, ndvmx); 
+} 
+
+void TGeant4::Gsord(const char *name, Int_t iax) {
+//
+  fGeometryManager->Gsord(name, iax); 
+} 
+
+void TGeant4::Gspos(const char *name, Int_t nr, const char *mother,  
+                        Float_t x, Float_t y, Float_t z, Int_t irot, 
+                        const char *konly) {
+//
+  fGeometryManager->Gspos(name, nr, mother, x, y, z, irot, konly); 
+} 
+
+void TGeant4::Gsposp(const char *name, Int_t nr, const char *mother,  
+                         Float_t x, Float_t y, Float_t z, Int_t irot,
+                         const char *konly, Float_t *upar, Int_t np)  {
+//
+  fGeometryManager->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np); 
+} 
+
+void TGeant4::WriteEuclid(const char* fileName, const char* topVol, 
+                          Int_t number, Int_t nlevel) {
+//
+  fGeometryManager->WriteEuclid(fileName, topVol, number, nlevel); 
+} 
+                              
+Int_t TGeant4::VolId(const Text_t* volName) const {
+//
+  return fGeometryManager->VolId(volName); 
+} 
+
+const char* TGeant4::VolName(Int_t id) const {
+//
+  return fGeometryManager->VolName(id); 
+}
+Int_t TGeant4::NofVolumes() const {
+//
+  return fGeometryManager->NofVolumes(); 
+} 
+
+// methods for physics management
+// ------------------------------------------------
+void TGeant4::BuildPhysics() {
+//
+  fPhysicsManager->BuildPhysics();
+}  
+
+void TGeant4::SetCut(const char* cutName, Float_t cutValue) { 
+//
+  fPhysicsManager->SetCut(cutName, cutValue);
+}  
+
+void TGeant4::SetProcess(const char* flagName, Int_t flagValue) {
+//
+  fPhysicsManager->SetProcess(flagName, flagValue);
+}  
+Float_t TGeant4::Xsec(char* reac, Float_t energy, Int_t part, Int_t mate) {
+//
+  return fPhysicsManager->Xsec(reac, energy, part, mate);
+}  
+
+Int_t TGeant4::IdFromPDG(Int_t pdgID) const { 
+//
+  return fPhysicsManager->IdFromPDG(pdgID);
+}  
+
+Int_t TGeant4::PDGFromId(Int_t mcID) const {
+//
+  return fPhysicsManager->PDGFromId(mcID);
+}  
+
+void TGeant4::DefineParticles() { 
+//
+  fPhysicsManager->DefineParticles();
+}  
+
+// methods for step management
+// ------------------------------------------------
+// inlined (in TGeant4.icc)
+
+void TGeant4::Rndm(Float_t* array, const Int_t size) const { 
+// 
+  fStepManager->Rndm(array, size); 
+} 
+
+// methods for visualization
+// ------------------------------------------------
+
+#ifdef G4VIS_USE
+void TGeant4::DrawOneSpec(const char* name) {
+//
+  fVisManager->DrawOneSpec(name); 
+} 
+
+void TGeant4::Gsatt(const char* name, const char* att, Int_t val) {
+//
+  fVisManager->Gsatt(name, att, val); 
+} 
+
+void TGeant4::Gdraw(const char* name, Float_t theta, Float_t phi,
+                       Float_t psi, Float_t u0, Float_t v0,
+                       Float_t ul, Float_t vl) {
+//
+  fVisManager->Gdraw(name, theta, phi, psi, u0, v0, ul, vl); 
+} 
+
+#else
+void TGeant4::DrawOneSpec(const char* name) {
+//
+  TG4Globals:: Warning("TGeant4::DrawOneSpec(): no visualization available."); 
+} 
+
+void TGeant4::Gsatt(const char* name, const char* att, Int_t val) {
+//
+  TG4Globals:: Warning("TGeant4::Gsatt(): no visualization available."); 
+} 
+
+void TGeant4::Gdraw(const char* p1, Float_t theta, Float_t phi,
+                       Float_t psi, Float_t u0, Float_t v0,
+                       Float_t ul, Float_t vl) {
+//
+  TG4Globals:: Warning("TGeant4::Gdraw(): no visualization available."); 
+} 
+
+#endif //G4VIS_USE
+
+// methods for run control
+// ------------------------------------------------
+
+void TGeant4::Init() { 
+//
+  fRunManager->Initialize();
+}  
+  
+void TGeant4::ProcessEvent() { 
+//
+  fRunManager->ProcessEvent();
+}  
+
+void TGeant4::ProcessRun(Int_t nofEvents) {
+//
+  fRunManager->ProcessRun(nofEvents);
+}  
+
+void TGeant4::StartGeantUI() {
+//
+  fRunManager->StartGeantUI();
+}  
+
+void TGeant4::StartRootUI() {
+//
+  fRunManager->StartGeantUI();
+}  
+
+void TGeant4::ProcessGeantMacro(const char* macroName) {
+//
+  fRunManager->ProcessGeantMacro(macroName);
+}  
+  
+void TGeant4::ProcessGeantCommand(const char* command) {
+//
+  fRunManager->ProcessGeantCommand(command);
+}  
+  
+Int_t TGeant4::CurrentEvent() const {
+//
+  return fRunManager->CurrentEvent(); 
+} 
+
+// Geant3 specific methods
+// !!! need to be transformed to common interface
+// ------------------------------------------------
+    
+void TGeant4::Gdopt(const char* name, const char* value) {
+//
+  TG4Globals:: Warning("TGeant4::Gdopt(..) is not implemented."); 
+}
+
+void TGeant4::SetClipBox(const char *name, Float_t xmin, Float_t xmax,
+                    Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax) { 
+//
+  TG4Globals:: Warning("TGeant4::SetClipBox(..) is not implemented."); 
+}
+
+void TGeant4::DefaultRange() { 
+//
+  TG4Globals:: Warning("TGeant4::DefaultRange() is not implemented."); 
+}
+
+void TGeant4::Gdhead(Int_t isel, const char* name, Float_t chrsiz) { 
+//
+  TG4Globals:: Warning("TGeant4::Gdhead(..) is not implemented."); 
+}
+
+void TGeant4::Gdman(Float_t u, Float_t v, const char* type) { 
+//
+  TG4Globals:: Warning("TGeant4::Gdman(..) is not implemented."); 
+}
+
+void TGeant4::SetColors() { 
+//
+  TG4Globals:: Warning("TGeant4::SetColours() is not implemented."); 
+}
+
+void TGeant4::Gtreve() { 
+//
+  TG4Globals:: Warning("TGeant4::Gtreve() is not implemented."); 
+}
+
+void TGeant4::Gtreve_root() { 
+//
+  TG4Globals:: Warning("TGeant4::Gtreve_root() is not implemented."); 
+}
+
+void TGeant4::Gckmat(Int_t itmed, char* natmed) { 
+//
+  TG4Globals:: Warning("TGeant4::Gckmat(..) is not implemented."); 
+}
+
+void TGeant4::InitLego() { 
+//
+  TG4Globals:: Warning("TGeant4::InitLego() is not implemented."); 
+}
+
+void TGeant4::Gfpart(Int_t ipart, char *name, Int_t& itrtyp,  
+                    Float_t& amass, Float_t& charge, Float_t& tlife) { 
+//
+  TG4Globals:: Warning("TGeant4::Gfpart(..) is not implemented."); 
+}
+
+void TGeant4::Gspart(Int_t ipart, const char *name, Int_t itrtyp,  
+                    Float_t amass, Float_t charge, Float_t tlife) {  
+//
+  TG4Globals:: Warning("TGeant4::Gspart(..) is not implemented."); 
+}
diff --git a/TGeant4/TGeant4.h b/TGeant4/TGeant4.h
new file mode 100644 (file)
index 0000000..f47f0f2
--- /dev/null
@@ -0,0 +1,244 @@
+// $Id$
+// Category: run
+//
+// Geant4 implementation of the MonteCarlo interface                      
+
+#ifndef TGEANT4_H
+#define TGEANT4_H
+
+#include "AliMC.h"
+
+class TG4VRunConfiguration;
+class TG4GeometryManager;
+class TG4PhysicsManager;
+class TG4StepManager;
+class TG4VisManager;
+class TG4RunManager;
+class TG4Messenger;
+
+class TGeant4: public AliMC
+{
+  public:
+    TGeant4(const char* name, const char* title,
+            TG4VRunConfiguration* configuration, int argc, char** argv);
+    TGeant4(const char* name, const char* title,
+            TG4VRunConfiguration* configuration);
+    // --> protected
+    // TGeant4();
+    // TGeant4(const TGeant4& right);
+    virtual ~TGeant4();
+
+    //
+    // methods for building/management of geometry
+    // ------------------------------------------------
+    //
+
+    // functions from GBASE 
+    virtual void  FinishGeometry(); 
+                  //Ggclos(); 
+
+    // functions from GCONS 
+    virtual void  Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,  
+                        Float_t &dens, Float_t &radl, Float_t &absl,
+                        Float_t* ubuf, Int_t& nbuf); 
+
+    // detector composition
+    virtual void  Material(Int_t& kmat, const char* name, Float_t a, 
+                     Float_t z, Float_t dens, Float_t radl, Float_t absl,
+                     Float_t* buf, Int_t nwbuf);
+    virtual void  Mixture(Int_t& kmat, const char *name, Float_t *a, 
+                     Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat);
+    virtual void  Medium(Int_t& kmed, const char *name, Int_t nmat, 
+                     Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd, 
+                     Float_t stemax, Float_t deemax, Float_t epsil, 
+                    Float_t stmin, Float_t* ubuf, Int_t nbuf);
+    virtual void  Matrix(Int_t& krot, Float_t thetaX, Float_t phiX, 
+                     Float_t thetaY, Float_t phiY, Float_t thetaZ, 
+                    Float_t phiZ);
+    virtual void  Gstpar(Int_t itmed, const char *param, Float_t parval); 
+    virtual void  Gsckov(Int_t itmed, Int_t npckov, Float_t *ppckov,
+                        Float_t *absco, Float_t *effic, Float_t *rindex); 
+
+    // functions from GGEOM 
+    virtual Int_t Gsvolu(const char *name, const char *shape, Int_t nmed,  
+                         Float_t *upar, Int_t np); 
+    virtual void  Gsdvn(const char *name, const char *mother, Int_t ndiv, 
+                        Int_t iaxis); 
+    virtual void  Gsdvn2(const char *name, const char *mother, Int_t ndiv, 
+                         Int_t iaxis, Float_t c0i, Int_t numed); 
+    virtual void  Gsdvt(const char *name, const char *mother, Float_t step, 
+                        Int_t iaxis, Int_t numed, Int_t ndvmx); 
+    virtual void  Gsdvt2(const char *name, const char *mother, Float_t step, 
+                         Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx); 
+    virtual void  Gsord(const char *name, Int_t iax); 
+    virtual void  Gspos(const char *name, Int_t nr, const char *mother,  
+                        Float_t x, Float_t y, Float_t z, Int_t irot, 
+                        const char *konly); 
+    virtual void  Gsposp(const char *name, Int_t nr, const char *mother,  
+                         Float_t x, Float_t y, Float_t z, Int_t irot,
+                         const char *konly, Float_t *upar, Int_t np); 
+    
+    // Euclid                 
+    virtual void WriteEuclid(const char* fileName, const char* topVol, 
+                             Int_t number, Int_t nlevel);
+                              
+    // get methods
+    virtual Int_t VolId(const Text_t* volName) const;
+    virtual const char* VolName(Int_t id) const;
+    virtual Int_t NofVolumes() const;
+
+    //
+    // methods for physics management
+    // ------------------------------------------------
+    //
+    virtual void BuildPhysics();
+
+    // set methods
+    virtual void SetCut(const char* cutName, Float_t cutValue);
+    virtual void SetProcess(const char* flagName, Int_t flagValue);
+    virtual Float_t Xsec(char* reac, Float_t energy, Int_t part, Int_t mate);
+        // particle table usage         
+    virtual Int_t IdFromPDG(Int_t pdgID) const;
+    virtual Int_t PDGFromId(Int_t mcID) const;
+    virtual void  DefineParticles();       
+
+    //
+    // methods for step management
+    // ------------------------------------------------
+    //
+
+    // action methods
+    virtual void StopTrack();
+    virtual void StopEvent();   
+
+    // set methods
+    virtual void SetMaxStep(Float_t);
+    virtual void SetMaxNStep(Int_t);
+    virtual void SetUserDecay(Int_t);  //NEW
+
+    // get methods
+         // tracking volume(s) 
+    virtual Int_t CurrentVolID(Int_t& copyNo) const;
+    virtual Int_t CurrentVolOffID(Int_t off, Int_t& copyNo) const;
+    virtual const char* CurrentVolName() const;
+    virtual const char* CurrentVolOffName(Int_t off) const;
+    virtual Int_t CurrentMaterial(Float_t &a, Float_t &z, 
+                    Float_t &dens, Float_t &radl, Float_t &absl) const;  
+    virtual void  Gmtod(Float_t* xm, Float_t* xd, Int_t iflag);
+    virtual void  Gdtom(Float_t* xd, Float_t* xm, Int_t iflag);
+    virtual Float_t MaxStep() const;
+    virtual Int_t GetMaxNStep() const;
+    virtual Int_t GetMedium() const;
+
+        // tracking particle 
+        // dynamic properties
+    virtual void    TrackPosition(TLorentzVector& position) const;
+    virtual void    TrackMomentum(TLorentzVector& momentum) const;
+    virtual void    TrackVertexPosition(TLorentzVector& position) const;
+    virtual void    TrackVertexMomentum(TLorentzVector& momentum) const;
+    virtual Float_t TrackStep() const;
+    virtual Float_t TrackLength() const; 
+    virtual Float_t TrackTime() const;
+    virtual Float_t Edep() const;
+        // static properties
+    virtual Int_t   TrackPid() const;
+    virtual Float_t TrackCharge() const;
+    virtual Float_t TrackMass() const;
+    virtual Float_t Etot() const;
+
+        // track status
+    virtual Bool_t  IsTrackInside() const;
+    virtual Bool_t  IsTrackEntering() const;
+    virtual Bool_t  IsTrackExiting() const;
+    virtual Bool_t  IsTrackOut() const;
+    virtual Bool_t  IsTrackDisappeared() const;
+    virtual Bool_t  IsTrackStop() const;
+    virtual Bool_t  IsTrackAlive() const;
+    virtual Bool_t  IsNewTrack() const;
+
+        // secondaries
+    virtual Int_t NSecondaries() const;
+    virtual void  GetSecondary(Int_t isec, Int_t& particleId, 
+                    TLorentzVector& position, TLorentzVector& momentum);
+    virtual const char* ProdProcess() const; 
+
+       // random number generator          
+    virtual void Rndm(Float_t* array, const Int_t size) const;    
+  
+    //
+    // methods for visualization
+    // ------------------------------------------------
+    //
+    // functions for drawing
+    virtual void  DrawOneSpec(const char* name);
+    virtual void  Gsatt(const char* name, const char* att, Int_t val);
+    virtual void  Gdraw(const char* name, Float_t theta, Float_t phi,
+                       Float_t psi, Float_t u0, Float_t v0,
+                       Float_t ul, Float_t vl);
+
+    //
+    // NEW
+    // Geant3 specific methods
+    // !!! need to be transformed to common interface
+    //
+    virtual void Gdopt(const char* name , const char* value);
+    virtual void SetClipBox(const char *name, Float_t xmin, Float_t xmax,
+                      Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax);
+    virtual void DefaultRange();
+    virtual void Gdhead(Int_t isel, const char* name, Float_t chrsiz);   
+    virtual void Gdman(Float_t u, Float_t v, const char* type);
+    virtual void SetColors();
+    virtual void Gtreve();
+    virtual void Gtreve_root();
+    virtual void Gckmat(Int_t itmed, char* natmed);
+    virtual void InitLego();
+    virtual void Gfpart(Int_t ipart, char *name, Int_t& itrtyp,  
+                      Float_t& amass, Float_t& charge, Float_t& tlife);
+    virtual void Gspart(Int_t ipart, const char *name, Int_t itrtyp,  
+                      Float_t amass, Float_t charge, Float_t tlife); 
+
+    //
+    // methods for run control
+    // ------------------------------------------------
+    //
+
+    virtual void Init();
+    virtual void ProcessEvent();
+    virtual void ProcessRun(Int_t nofEvents);
+
+        // UI control methods
+    void StartGeantUI();       
+    void StartRootUI();        
+    void ProcessGeantMacro(const char* macroName);
+    void ProcessGeantCommand(const char* commandPath);
+
+        // get methods
+    virtual Int_t CurrentEvent() const; 
+
+  protected:
+    TGeant4();
+    TGeant4(const TGeant4& right);
+
+    // operators
+    TGeant4& operator=(const TGeant4& right);
+
+  private:
+    // data members
+    TG4GeometryManager*  fGeometryManager; //geometry manager
+    TG4PhysicsManager*   fPhysicsManager;  //physics manager
+    TG4StepManager*      fStepManager;     //step manager
+    TG4VisManager*       fVisManager;      //visualization manager
+    TG4RunManager*       fRunManager;      //run manager
+    TG4Messenger*        fMessenger;       //messenger
+};
+
+#ifndef __CINT__
+
+// inline methods
+#include "TGeant4.icc"
+
+#endif
+#endif // TGEANT4_H
+
diff --git a/TGeant4/TGeant4.icc b/TGeant4/TGeant4.icc
new file mode 100644 (file)
index 0000000..630a304
--- /dev/null
@@ -0,0 +1,199 @@
+// $Id$
+// Category: run
+
+#include "TG4StepManager.h" 
+
+// methods for step management
+// ------------------------------------------------
+
+inline void TGeant4::StopTrack()
+{ 
+  fStepManager->StopTrack(); 
+} 
+
+inline void TGeant4::StopEvent()   
+{ 
+  fStepManager->StopEvent(); 
+} 
+
+inline void TGeant4::SetMaxStep(Float_t step)
+{ 
+  fStepManager->SetMaxStep(step); 
+} 
+
+inline void TGeant4::SetMaxNStep(Int_t number)
+{ 
+  fStepManager->SetMaxNStep(number); 
+} 
+
+inline void TGeant4::SetUserDecay(Int_t number)
+{ 
+  fStepManager->SetUserDecay(number); 
+} 
+
+inline Int_t TGeant4::CurrentVolID(Int_t& copyNo) const
+{ 
+  return fStepManager->CurrentVolID(copyNo); 
+} 
+
+inline Int_t TGeant4::CurrentVolOffID(Int_t off, Int_t& copyNo) const
+{ 
+  return fStepManager->CurrentVolOffID(off, copyNo); 
+} 
+
+inline const char* TGeant4::CurrentVolName() const
+{ 
+  return fStepManager->CurrentVolName(); 
+} 
+
+inline const char* TGeant4::CurrentVolOffName(Int_t off) const
+{ 
+  return fStepManager->CurrentVolOffName(off); 
+} 
+
+inline Int_t TGeant4::CurrentMaterial(Float_t &a, Float_t &z, 
+                    Float_t &dens, Float_t &radl, Float_t &absl) const  
+{ 
+  return fStepManager->CurrentMaterial(a, z, dens, radl, absl); 
+} 
+
+inline void TGeant4::Gmtod(Float_t* xm, Float_t* xd, Int_t iflag)
+{ 
+  fStepManager->Gmtod(xm, xd, iflag); 
+} 
+
+inline void TGeant4::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag)
+{ 
+  fStepManager->Gdtom(xd, xm, iflag); 
+} 
+    
+inline Float_t TGeant4::MaxStep() const
+{ 
+  return fStepManager->MaxStep(); 
+} 
+
+inline Int_t TGeant4::GetMaxNStep() const
+{ 
+  return fStepManager->GetMaxNStep(); 
+} 
+
+inline Int_t TGeant4::GetMedium() const
+{ 
+  return fStepManager->GetMedium(); 
+} 
+
+inline void TGeant4::TrackPosition(TLorentzVector& position) const
+{ 
+  fStepManager->TrackPosition(position); 
+} 
+
+inline void TGeant4::TrackMomentum(TLorentzVector& momentum) const
+{ 
+  fStepManager->TrackMomentum(momentum); 
+} 
+
+inline void TGeant4::TrackVertexPosition(TLorentzVector& position) const
+{ 
+  fStepManager->TrackVertexPosition(position); 
+} 
+
+inline void TGeant4::TrackVertexMomentum(TLorentzVector& momentum) const
+{ 
+  fStepManager->TrackVertexMomentum(momentum); 
+} 
+
+inline Float_t TGeant4::TrackStep() const
+{ 
+  return fStepManager->TrackStep(); 
+} 
+
+inline Float_t TGeant4::TrackLength() const 
+{ 
+  return fStepManager->TrackLength(); 
+} 
+
+inline Float_t TGeant4::TrackTime() const
+{ 
+  return fStepManager->TrackTime(); 
+} 
+
+inline Float_t TGeant4::Edep() const
+{ 
+  return fStepManager->Edep(); 
+} 
+
+inline Int_t TGeant4::TrackPid() const
+{ 
+  return fStepManager->TrackPid(); 
+} 
+
+inline Float_t TGeant4::TrackCharge() const
+{ 
+  return fStepManager->TrackCharge(); 
+} 
+
+inline Float_t TGeant4::TrackMass() const
+{ 
+  return fStepManager->TrackMass(); 
+} 
+
+inline Float_t TGeant4::Etot() const
+{ 
+  return fStepManager->Etot(); 
+} 
+
+inline Bool_t  TGeant4::IsTrackInside() const
+{   
+  return fStepManager->IsTrackInside(); 
+} 
+
+inline Bool_t  TGeant4::IsTrackEntering() const
+{   
+  return fStepManager->IsTrackEntering(); 
+} 
+
+inline Bool_t  TGeant4::IsTrackExiting() const
+{   
+  return fStepManager->IsTrackExiting(); 
+} 
+
+inline Bool_t  TGeant4::IsTrackOut() const
+{   
+  return fStepManager->IsTrackOut(); 
+} 
+
+inline Bool_t  TGeant4::IsTrackDisappeared() const
+{   
+  return fStepManager->IsTrackDisappeared(); 
+} 
+
+inline Bool_t  TGeant4::IsTrackStop() const
+{  
+  return  fStepManager->IsTrackStop(); 
+} 
+
+inline Bool_t  TGeant4::IsTrackAlive() const
+{   
+  return fStepManager->IsTrackAlive(); 
+} 
+
+inline Bool_t TGeant4::IsNewTrack() const
+{
+  return fStepManager->IsNewTrack();
+}  
+
+inline Int_t TGeant4::NSecondaries() const
+{ 
+  return fStepManager->NSecondaries(); 
+} 
+
+inline void  TGeant4::GetSecondary(Int_t isec, Int_t& particleId, 
+                         TLorentzVector& position, TLorentzVector& momentum)
+{ 
+  fStepManager->GetSecondary(isec, particleId, position, momentum); 
+} 
+
+inline const char* TGeant4::ProdProcess() const 
+{ 
+  return fStepManager->ProdProcess(); 
+} 
diff --git a/TGeant4/TGeant4LinkDef.h b/TGeant4/TGeant4LinkDef.h
new file mode 100644 (file)
index 0000000..13ab092
--- /dev/null
@@ -0,0 +1,12 @@
+// $Id$
+
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+#pragma link C++ class  TGeant4;
+#pragma link C++ class  TG4VRunConfiguration;
+
+#endif