]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TGeant4/TG4StepManager.cxx
methods NofSensitiveDetectors(), GetVolumeID(), GetVolumeName(), GetLogicalVolume...
[u/mrichter/AliRoot.git] / TGeant4 / TG4StepManager.cxx
index efbb36f1e1ebfd1eb19c00d382e5dc24623eefc8..cbc32ce84666c1b7ca1064cf436e1c19b8bd5fe7 100644 (file)
@@ -5,10 +5,12 @@
 
 #include "TG4StepManager.h"
 #include "TG4GeometryServices.h"
+#include "TG4ParticlesManager.h"
 #include "TG4PhysicsManager.h"
 #include "TG4VSensitiveDetector.h"
+#include "TG4Limits.h"
 #include "TG4Globals.h"
-#include "TG3Units.h"
+#include "TG4G3Units.h"
 
 #include <G4SteppingManager.hh>
 #include <G4UserLimits.hh>
@@ -16,6 +18,9 @@
 #include <G4AffineTransform.hh>
 #include <G4TransportationManager.hh>
 #include <G4Navigator.hh>
+#include <G4VProcess.hh>
+#include <G4ProcessManager.hh>
+#include <G4ProcessVector.hh>
 
 #include <Randomize.hh>
 #include <TLorentzVector.h>
@@ -174,36 +179,29 @@ void TG4StepManager::StopEvent()
   G4UImanager::GetUIpointer()->ApplyCommand("/alStacking/clearStack");
 }
 
-void TG4StepManager::Rndm(Float_t* array, const Int_t size) const
-{   
-// Random numbers array of the specified size.
-// ---
-
-  G4double* const kpDoubleArray = new G4double[size];
-  RandFlat::shootArray(size, kpDoubleArray);
-  for (G4int i=0; i<size; i++) { 
-    array[i] = kpDoubleArray[i]; 
-  } 
-  delete [] kpDoubleArray;
-}
 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 ??
 // ---
 
-  // check this
   G4LogicalVolume* curLogVolume 
     = GetCurrentPhysicalVolume()->GetLogicalVolume();
   G4UserLimits* userLimits 
     = curLogVolume->GetUserLimits();
+
   if (userLimits == 0) {
-    userLimits = new G4UserLimits(step); 
-    curLogVolume->SetUserLimits(userLimits);
+    // create new limits
+    userLimits = new TG4Limits();
+    
+    // set limits to all logical volumes
+    // corresponding to the current "G3" volume 
+    TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
+    G4int nofLV = geometryServices->SetUserLimits(userLimits, curLogVolume);
   }
-  else
-    userLimits->SetMaxAllowedStep(step);
+
+  // set max step
+  userLimits->SetMaxAllowedStep(step*TG4G3Units::Length()); 
+
 }
 
 void TG4StepManager::SetMaxNStep(Int_t maxNofSteps)
@@ -345,11 +343,11 @@ Int_t TG4StepManager::CurrentMaterial(Float_t &a, Float_t &z, Float_t &dens,
       
     // density 
     dens = material->GetDensity();
-    dens /= TG3Units::MassDensity();      
+    dens /= TG4G3Units::MassDensity();      
       
     // radiation length
     radl = material->GetRadlen();
-    radl /= TG3Units::Length();
+    radl /= TG4G3Units::Length();
       
     absl = 0.;  // this parameter is not defined in Geant4
     return nofElements;
@@ -495,7 +493,7 @@ Float_t TG4StepManager::MaxStep() const
   else { 
     const G4Track& trackRef = *(fTrack);
     maxStep = userLimits->GetMaxAllowedStep(trackRef); 
-    maxStep /= TG3Units::Length(); 
+    maxStep /= TG4G3Units::Length(); 
     return maxStep;
   }  
 }
@@ -524,11 +522,11 @@ void TG4StepManager::TrackPosition(TLorentzVector& position) const
   // get position
   // check if this is == to PostStepPoint position !!
   G4ThreeVector positionVector = fTrack->GetPosition();
-  positionVector *= 1./(TG3Units::Length());   
+  positionVector *= 1./(TG4G3Units::Length());   
      
   // local time   
   G4double time = fTrack->GetLocalTime();
-  time /= TG3Units::Time();
+  time /= TG4G3Units::Time();
     
   SetTLorentzVector(positionVector, time, position);
 }
@@ -558,10 +556,10 @@ void TG4StepManager::TrackMomentum(TLorentzVector& momentum) const
 #endif
 
   G4ThreeVector momentumVector = fTrack->GetMomentum(); 
-  momentumVector *= 1./(TG3Units::Energy());   
+  momentumVector *= 1./(TG4G3Units::Energy());   
 
   G4double energy = fTrack->GetDynamicParticle()->GetTotalEnergy();
-  energy /= TG3Units::Energy();  
+  energy /= TG4G3Units::Energy();  
 
   SetTLorentzVector(momentumVector, energy, momentum);
 }
@@ -578,12 +576,12 @@ void TG4StepManager::TrackVertexPosition(TLorentzVector& position) const
 
   // position
   G4ThreeVector positionVector = fTrack->GetVertexPosition();
-  positionVector *= 1./(TG3Units::Length());   
+  positionVector *= 1./(TG4G3Units::Length());   
      
   // local time 
   // to be checked  
   G4double time = fTrack->GetLocalTime();
-  time /= TG3Units::Time();
+  time /= TG4G3Units::Time();
       
   SetTLorentzVector(positionVector, time, position);
 }
@@ -599,10 +597,10 @@ void TG4StepManager::TrackVertexMomentum(TLorentzVector& momentum) const
 #endif
 
   G4ThreeVector momentumVector = fTrack->GetVertexMomentumDirection(); 
-  momentumVector *= 1./(TG3Units::Energy());   
+  momentumVector *= 1./(TG4G3Units::Energy());   
 
   G4double energy = fTrack->GetVertexKineticEnergy();
-  energy /= TG3Units::Energy();  
+  energy /= TG4G3Units::Energy();  
 
   SetTLorentzVector(momentumVector, energy, momentum);
 }
@@ -620,7 +618,7 @@ Float_t TG4StepManager::TrackStep() const
 #endif
 
     length = fStep->GetStepLength();
-    length /= TG3Units::Length();
+    length /= TG4G3Units::Length();
   }  
   else 
     length = 0;
@@ -638,7 +636,7 @@ Float_t TG4StepManager::TrackLength() const
 #endif
 
   G4double length = fTrack->GetTrackLength();
-  length /= TG3Units::Length();
+  length /= TG4G3Units::Length();
   return length;
 }
 
@@ -655,7 +653,7 @@ Float_t TG4StepManager::TrackTime() const
 #endif
   
   G4double time = fTrack->GetLocalTime();
-  time /= TG3Units::Time();
+  time /= TG4G3Units::Time();
   return time;
 }
 
@@ -672,7 +670,7 @@ Float_t TG4StepManager::Edep() const
 #endif
 
     energyDeposit = fStep->GetTotalEnergyDeposit();
-    energyDeposit /= TG3Units::Energy();
+    energyDeposit /= TG4G3Units::Energy();
   }
   else   
     energyDeposit = 0;
@@ -692,11 +690,11 @@ Int_t TG4StepManager::TrackPid() const
   G4ParticleDefinition* particle
     = fTrack->GetDynamicParticle()->GetDefinition();
     
-  // ask TG4PhysicsManager to get PDG encoding 
+  // ask TG4ParticlesManager 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);
+  G4int pdgEncoding 
+    = TG4ParticlesManager::Instance()->GetPDGEncodingFast(particle);
 
   return pdgEncoding;
 }
@@ -713,7 +711,7 @@ Float_t TG4StepManager::TrackCharge() const
   G4double charge
     = fTrack->GetDynamicParticle()->GetDefinition()
       ->GetPDGCharge();
-  charge /= TG3Units::Charge();        
+  charge /= TG4G3Units::Charge();      
   return charge;
 }
 
@@ -729,7 +727,7 @@ Float_t TG4StepManager::TrackMass() const
   G4double mass
     = fTrack->GetDynamicParticle()->GetDefinition()
       ->GetPDGMass();
-  mass /= TG3Units::Mass();    
+  mass /= TG4G3Units::Mass();  
   return mass;
 }
 
@@ -744,7 +742,7 @@ Float_t TG4StepManager::Etot() const
 
   G4double energy
     = fTrack->GetDynamicParticle()->GetTotalEnergy();
-  energy /= TG3Units::Energy();  
+  energy /= TG4G3Units::Energy();  
   return energy;
 }
 
@@ -941,7 +939,7 @@ void TG4StepManager::GetSecondary(Int_t index, Int_t& particleId,
 
       // the index of the first secondary of this step
       G4int startIndex 
-        = secondaryTracks->entries() - nofSecondaries;
+        = secondaryTracks->size() - nofSecondaries;
              // (the secondaryTracks vector contains secondaries 
              // produced by the track at previous steps, too)
       G4Track* track 
@@ -953,15 +951,15 @@ void TG4StepManager::GetSecondary(Int_t index, Int_t& particleId,
  
       // position & time
       G4ThreeVector positionVector = track->GetPosition();
-      positionVector *= 1./(TG3Units::Length());
+      positionVector *= 1./(TG4G3Units::Length());
       G4double time = track->GetLocalTime();
-      time /= TG3Units::Time();
+      time /= TG4G3Units::Time();
       SetTLorentzVector(positionVector, time, position);
 
       // momentum & energy
       G4ThreeVector momentumVector = track->GetMomentum();     
       G4double energy = track->GetDynamicParticle()->GetTotalEnergy();
-      energy /= TG3Units::Energy();
+      energy /= TG4G3Units::Energy();
       SetTLorentzVector(momentumVector, energy, momentum);
     }
     else {
@@ -1002,17 +1000,17 @@ AliMCProcess TG4StepManager::ProdProcess(Int_t isec) const
 
     // 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)
+      = secondaryTracks->size() - nofSecondaries;
+           // the secondaryTracks vector contains secondaries 
+           // produced by the track at previous steps, too
 
     // the secondary track with specified isec index
     G4Track* track = (*secondaryTracks)[startIndex + isec]; 
    
-    G4String g4Name = track->GetCreatorProcess()->GetProcessName(); 
+    const G4VProcess* kpProcess = track->GetCreatorProcess(); 
   
-    TG4PhysicsManager* pPhysicsManager = TG4PhysicsManager::Instance();
-    AliMCProcess mcProcess = pPhysicsManager->GetMCProcess(g4Name);
+    AliMCProcess mcProcess 
+     = TG4PhysicsManager::Instance()->GetMCProcess(kpProcess);
   
     // distinguish kPDeltaRay from kPEnergyLoss  
     if (mcProcess == kPEnergyLoss) mcProcess = kPDeltaRay;
@@ -1030,11 +1028,48 @@ AliMCProcess TG4StepManager::ProdProcess(Int_t isec) const
 
 Int_t TG4StepManager::StepProcesses(TArrayI &proc) const
 {
-// Fills the array of processes that were active in the current step.
+// Fills the array of processes that were active in the current step
+// and returns the number of them.
+// TBD: Distinguish between kPDeltaRay and kPEnergyLoss
 // ---
 
-  TG4Globals::Exception(
-     "TG4StepManager::StepProcesses(): not yet implemented.");
-     
-  return 0;   
+ if (fStepStatus == kVertex) {
+   G4cout << "kVertex" << G4endl;
+   G4int nofProcesses = 1;
+   proc.Set(nofProcesses);
+   proc[0] = kPNull;
+   return nofProcesses;
+ }  
+   
+#ifdef TGEANT4_DEBUG
+  CheckSteppingManager();
+  CheckStep("StepProcesses");
+#endif
+
+  // along step processes
+  G4ProcessManager* processManager
+    = fStep->GetTrack()->GetDefinition()->GetProcessManager();
+  G4ProcessVector* alongStepProcessVector 
+    = processManager->GetAlongStepProcessVector();
+  G4int nofProcesses = alongStepProcessVector->entries();
+  
+  // process defined step
+  const G4VProcess* kpLastProcess 
+    = fStep->GetPostStepPoint()->GetProcessDefinedStep();
+
+  // fill the array of processes 
+  proc.Set(nofProcesses);
+  TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
+  G4int i;  
+  for (i=0; i<nofProcesses-1; i++) {
+    G4VProcess* g4Process = (*alongStepProcessVector)[i];    
+    // do not fill transportation along step process
+    if (g4Process->GetProcessName() != "Transportation") {
+      physicsManager->GetMCProcess(g4Process);   
+      proc[i] = physicsManager->GetMCProcess(g4Process);
+    }  
+  }  
+  proc[nofProcesses-1] = physicsManager->GetMCProcess(kpLastProcess);
+    
+  return nofProcesses;  
 }