]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliMC.cxx
Calculation of number of participants added.
[u/mrichter/AliRoot.git] / STEER / AliMC.cxx
index c331790b2879aee87a46df447ee9c905e39ee63b..f07a2bfee7a6181fb0f87193e5bc511690b5777a 100644 (file)
 
 /* $Id$ */
 
+// This class is extracted from the AliRun class
+// and contains all the MC-related functionality
+// The number of dependencies has to be reduced...
+// Author: F.Carminati
+//         Federico.Carminati@cern.ch
+
 #include <TBrowser.h>
 #include <TStopwatch.h>
 #include <TSystem.h>
@@ -41,6 +47,7 @@ AliMC::AliMC() :
   fSum2Energy(0),
   fTrRmax(1.e10),
   fTrZmax(1.e10),
+  fDebug(0),
   fImedia(0),
   fTransParName("\0"),
   fMCQA(0),
@@ -48,6 +55,7 @@ AliMC::AliMC() :
   fTrackReferences(0)
 
 {
+  //default constructor
 }
 
 //_______________________________________________________________________
@@ -59,13 +67,14 @@ AliMC::AliMC(const char *name, const char *title) :
   fSum2Energy(0),
   fTrRmax(1.e10),
   fTrZmax(1.e10),
+  fDebug(0),
   fImedia(new TArrayI(1000)),
   fTransParName("\0"),
   fMCQA(0),
   fHitLists(new TList()),
   fTrackReferences(new TClonesArray("AliTrackReference", 100))
 {
-
+  //constructor
   // Set transport parameters
   SetTransPar();
 
@@ -83,6 +92,7 @@ AliMC::AliMC(const AliMC &mc) :
   fSum2Energy(0),
   fTrRmax(1.e10),
   fTrZmax(1.e10),
+  fDebug(0),
   fImedia(0),
   fTransParName("\0"),
   fMCQA(0),
@@ -98,6 +108,7 @@ AliMC::AliMC(const AliMC &mc) :
 //_______________________________________________________________________
 AliMC::~AliMC()
 {
+  //destructor
   delete fGenerator;
   delete fImedia;
   delete fMCQA;
@@ -112,8 +123,9 @@ AliMC::~AliMC()
 }
 
 //_______________________________________________________________________
-void AliMC::Copy(AliMC &) const
+void AliMC::Copy(TObject &) const
 {
+  //dummy Copy function
   Fatal("Copy","Not implemented!\n");
 }
 
@@ -203,8 +215,10 @@ void AliMC::FinishRun()
   fGenerator->FinishRun();
 
   //Output energy summary tables
-  if (GetDebug()) Info("FinishRun"," EnergySummary()");
-  EnergySummary();
+  if (GetDebug()) {
+    Info("FinishRun"," EnergySummary()");
+    EnergySummary();
+  }
 
 }
 
@@ -224,6 +238,7 @@ void AliMC::BeginPrimary()
 //_______________________________________________________________________
 void AliMC::PreTrack()
 {
+  // Actions before the track's transport
      TObjArray &dets = *gAlice->Modules();
      AliModule *module;
 
@@ -252,6 +267,11 @@ void AliMC::Stepping()
     Int_t copy;
     //Update energy deposition tables
     AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
+    //
+    // write tracke reference for track which is dissapearing - MI
+    if (gMC->IsTrackDisappeared()) {      
+      if (gMC->Etot()>0.05) AddTrackReference(GetCurrentTrackNumber());
+    }
   
     //Call the appropriate stepping routine;
     AliModule *det = dynamic_cast<AliModule*>(gAlice->Modules()->At(id));
@@ -365,9 +385,13 @@ void AliMC::BeginEvent()
     runloader->Stack()->Reset();//clean stack -> tree is unloaded
   else
     runloader->MakeStack();//or make a new one
-    
-  if (GetDebug()) Info("BeginEvent","  fRunLoader->MakeTree(K)");
-  runloader->MakeTree("K");
+  
+  if(gAlice->Lego() == 0x0)
+   { 
+     if (GetDebug()) Info("BeginEvent","  fRunLoader->MakeTree(K)");
+     runloader->MakeTree("K");
+   }
+   
   if (GetDebug()) Info("BeginEvent","  gMC->SetStack(fRunLoader->Stack())");
   gMC->SetStack(gAlice->GetRunLoader()->Stack());//Was in InitMC - but was moved here 
                                      //because we don't have guarantee that 
@@ -381,20 +405,22 @@ void AliMC::BeginEvent()
     gAlice->GetEventNrInRun());
 //  fRunLoader->WriteKinematics("OVERWRITE");  is there any reason to rewrite here since MakeTree does so
 
-  if (GetDebug()) Info("BeginEvent","  fRunLoader->MakeTrackRefsContainer()");
-  runloader->MakeTrackRefsContainer();//for insurance
+  if(gAlice->Lego()) 
+   {
+    gAlice->Lego()->BeginEvent();
+    return;
+   }
+  
 
   if (GetDebug()) Info("BeginEvent","  ResetHits()");
   ResetHits();
+  
   if (GetDebug()) Info("BeginEvent","  fRunLoader->MakeTree(H)");
   runloader->MakeTree("H");
+  
+  if (GetDebug()) Info("BeginEvent","  fRunLoader->MakeTrackRefsContainer()");
+  runloader->MakeTrackRefsContainer();//for insurance
 
-  //
-  if(gAlice->Lego()) 
-   {
-    gAlice->Lego()->BeginEvent();
-    return;
-   }
 
   //create new branches and SetAdresses
   TIter next(gAlice->Modules());
@@ -408,6 +434,16 @@ void AliMC::BeginEvent()
     if (GetDebug()) Info("BeginEvent","  %s->SetTreeAddress()",detector->GetName());
     detector->SetTreeAddress();
    }
+  // make branch for AliRun track References
+  TTree * treeTR = runloader->TreeTR();
+  if (treeTR){
+    // make branch for central track references
+    if (!fTrackReferences) fTrackReferences = new TClonesArray("AliTrackReference",0);
+    TBranch *branch;
+    branch = treeTR->Branch("AliRun",&fTrackReferences);
+    branch->SetAddress(&fTrackReferences);
+  }
+  //
 }
 
 //_______________________________________________________________________
@@ -426,6 +462,7 @@ void AliMC::ResetHits()
 //_______________________________________________________________________
 void AliMC::PostTrack()
 {
+  // Posts tracks for each module
      TObjArray &dets = *gAlice->Modules();
      AliModule *module;
 
@@ -445,13 +482,17 @@ void AliMC::FinishPrimary()
   //  const Int_t times=10;
   // This primary is finished, purify stack
   runloader->Stack()->PurifyKine();
-
+  
   TIter next(gAlice->Modules());
   AliModule *detector;
   while((detector = dynamic_cast<AliModule*>(next()))) {
     detector->FinishPrimary();
-    if(detector->GetLoader())
-       detector->GetLoader()->TreeH()->Fill();
+    AliLoader* loader = detector->GetLoader();
+    if(loader)
+     {
+       TTree* treeH = loader->TreeH();
+       if (treeH) treeH->Fill(); //can be Lego run and treeH can not exist
+     }
   }
 
   // Write out track references if any
@@ -511,10 +552,13 @@ void AliMC::FinishEvent()
     Error("FinishEvent","Can not get TreeE from RL");
    }
   
-  runloader->WriteKinematics("OVERWRITE");
-  runloader->WriteTrackRefs("OVERWRITE");
-  runloader->WriteHits("OVERWRITE");
-
+  if(gAlice->Lego() == 0x0)
+   {
+     runloader->WriteKinematics("OVERWRITE");
+     runloader->WriteTrackRefs("OVERWRITE");
+     runloader->WriteHits("OVERWRITE");
+   }
+   
   if (GetDebug()) 
    { 
      Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
@@ -530,12 +574,14 @@ void AliMC::FinishEvent()
 //_______________________________________________________________________
 void AliMC::Field(const Double_t* x, Double_t* b) const
 {
+  // Calculates field "b" at point "x"
     gAlice->Field(x,b);
 }
     
 //_______________________________________________________________________
 void AliMC::Init()
 {
+  // MC initialization
 
    //=================Create Materials and geometry
    gMC->Init();
@@ -834,6 +880,8 @@ Int_t AliMC::GetPrimary(Int_t track) const
 //_______________________________________________________________________
 TParticle* AliMC::Particle(Int_t i) const
 {
+  // Returns the i-th particle from the stack taking into account
+  // the remaping done by PurifyKine
   AliRunLoader * runloader = gAlice->GetRunLoader();
   if (runloader)
    if (runloader->Stack())
@@ -884,7 +932,7 @@ void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg,
 }
 
 //_______________________________________________________________________
-void AliMC::SetHighWaterMark(const Int_t nt)
+void AliMC::SetHighWaterMark(Int_t nt)
 {
     //
     // Set high water mark for last track in event
@@ -895,7 +943,7 @@ void AliMC::SetHighWaterMark(const Int_t nt)
 }
 
 //_______________________________________________________________________
-void AliMC::KeepTrack(const Int_t track)
+void AliMC::KeepTrack(Int_t track)
 { 
   //
   // Delegate to stack