]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliMC.cxx
Trigger input names added to ESD (Plamen)
[u/mrichter/AliRoot.git] / STEER / AliMC.cxx
index c7d6fe88915573b62d192fd4bef7a3710939f315..0cca364f14b10177f629b5bb3dc9db985b99752f 100644 (file)
 //         Federico.Carminati@cern.ch
 
 #include <RVersion.h>
-#include <TBrowser.h>
+#include <TArrayI.h>
 #include <TClonesArray.h>
+#include <TFile.h>
+#include <TGeoGlobalMagField.h>
 #include <TGeoManager.h>
+#include <TParticle.h>
+#include <TROOT.h>
 #include <TStopwatch.h>
 #include <TSystem.h>
 #include <TVirtualMC.h>
-#include <TParticle.h>
-#include <TROOT.h>
-#include <TFile.h>
  
-#include "AliLog.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
 #include "AliDetector.h"
 #include "AliGenerator.h"
+#include "AliGeomManager.h"
 #include "AliHeader.h"
+#include "AliHit.h"
 #include "AliLego.h"
+#include "AliLog.h"
 #include "AliMC.h"
-#include "AliMCQA.h"
+#include "AliMagF.h"
 #include "AliRun.h"
-#include "AliHit.h"
+#include "AliSimulation.h"
 #include "AliStack.h"
-#include "AliMagF.h"
 #include "AliTrackReference.h"
-#include "AliSimulation.h"
-#include "AliGeomManager.h"
-#include "AliCDBManager.h"
-#include "AliCDBStorage.h"
-#include "AliCDBEntry.h"
-
 
 ClassImp(AliMC)
 
@@ -66,7 +65,6 @@ AliMC::AliMC() :
   fDecayPdg(0),
   fImedia(0),
   fTransParName("\0"),
-  fMCQA(0),
   fHitLists(0),
   fTmpTreeTR(0),
   fTmpFileTR(0),
@@ -92,7 +90,6 @@ AliMC::AliMC(const char *name, const char *title) :
   fDecayPdg(0),
   fImedia(new TArrayI(1000)),
   fTransParName("\0"),
-  fMCQA(0),
   fHitLists(new TList()),
   fTmpTreeTR(0),
   fTmpFileTR(0),
@@ -107,51 +104,16 @@ AliMC::AliMC(const char *name, const char *title) :
   for(Int_t i=0;i<1000;i++) (*fImedia)[i]=-99;
 }
 
-//_______________________________________________________________________
-AliMC::AliMC(const AliMC &mc) :
-  TVirtualMCApplication(mc),
-  fGenerator(0),
-  fEventEnergy(0),
-  fSummEnergy(0),
-  fSum2Energy(0),
-  fTrRmax(1.e10),
-  fTrZmax(1.e10),
-  fRDecayMax(1.e10),
-  fRDecayMin(-1.),
-  fDecayPdg(0),
-  fImedia(0),
-  fTransParName("\0"),
-  fMCQA(0),
-  fHitLists(0),
-  fTmpTreeTR(0),
-  fTmpFileTR(0),
-  fTrackReferences(),
-  fTmpTrackReferences()
-{
-  //
-  // Copy constructor for AliMC
-  //
-  mc.Copy(*this);
-}
-
 //_______________________________________________________________________
 AliMC::~AliMC()
 {
   //destructor
   delete fGenerator;
   delete fImedia;
-  delete fMCQA;
   delete fHitLists;
   // Delete track references
 }
 
-//_______________________________________________________________________
-void AliMC::Copy(TObject &) const
-{
-  //dummy Copy function
-  AliFatal("Not implemented!");
-}
-
 //_______________________________________________________________________
 void  AliMC::ConstructGeometry() 
 {
@@ -184,6 +146,7 @@ void  AliMC::ConstructGeometry()
     }
   }else{
     // Create modules, materials, geometry
+    if (!gGeoManager) new TGeoManager("ALICE", "ALICE geometry");
     TStopwatch stw;
     TIter next(gAlice->Modules());
     AliModule *detector;
@@ -210,12 +173,12 @@ Bool_t  AliMC::MisalignGeometry()
      SetAllAlignableVolumes();
    }
    // Misalign geometry via AliSimulation instance
-   if (!AliSimulation::GetInstance()) return kFALSE;
+   if (!AliSimulation::Instance()) return kFALSE;
    AliGeomManager::SetGeometry(gGeoManager);
-   if(!AliGeomManager::CheckSymNamesLUT())
+   if(!AliGeomManager::CheckSymNamesLUT("ALL"))
     AliFatal("Current loaded geometry differs in the definition of symbolic names!");
 
-   return AliSimulation::GetInstance()->MisalignGeometry(gAlice->GetRunLoader());
+   return AliSimulation::Instance()->MisalignGeometry(AliRunLoader::Instance());
 }   
 
 //_______________________________________________________________________
@@ -229,6 +192,8 @@ void  AliMC::ConstructOpGeometry()
   AliModule *detector;
   AliInfo("Optical properties definition");
   while((detector = dynamic_cast<AliModule*>(next()))) {
+    // Initialise detector geometry
+    if(gAlice->IsRootGeometry()) detector->CreateMaterials();
     // Initialise detector optical properties
     detector->DefineOpticalProperties();
   }  
@@ -247,8 +212,6 @@ void  AliMC::InitGeometry()
   AliModule *detector;
   while((detector = dynamic_cast<AliModule*>(next()))) {
     stw.Start();
-    // Initialise detector geometry
-    if(gAlice->IsRootGeometry()) detector->CreateMaterials();
     detector->Init();
     AliInfo(Form("%10s R:%.2fs C:%.2fs",
                 detector->GetName(),stw.RealTime(),stw.CpuTime()));
@@ -337,14 +300,13 @@ void AliMC::BeginPrimary()
 void AliMC::PreTrack()
 {
   // Actions before the track's transport
+
      TObjArray &dets = *gAlice->Modules();
      AliModule *module;
 
      for(Int_t i=0; i<=gAlice->GetNdets(); i++)
        if((module = dynamic_cast<AliModule*>(dets[i])))
         module->PreTrack();
-
-     fMCQA->PreTrack();
 }
 
 //_______________________________________________________________________
@@ -370,8 +332,8 @@ void AliMC::Stepping()
   
   //
   // --- If lego option, do it and leave 
-  if (gAlice->Lego())
-    gAlice->Lego()->StepManager();
+  if (AliSimulation::Instance()->Lego())
+    AliSimulation::Instance()->Lego()->StepManager();
   else {
     Int_t copy;
     //Update energy deposition tables
@@ -389,7 +351,6 @@ void AliMC::Stepping()
     //Call the appropriate stepping routine;
     AliModule *det = dynamic_cast<AliModule*>(gAlice->Modules()->At(id));
     if(det && det->StepManagerIsEnabled()) {
-      if(AliLog::GetGlobalDebugLevel()>0) fMCQA->StepManager(id);
       det->StepManager();
     }
   }
@@ -407,7 +368,7 @@ void AliMC::EnergySummary()
   Float_t ed, ed2;
   Int_t kn, i, left, j, id;
   const Float_t kzero=0;
-  Int_t ievent=gAlice->GetRunLoader()->GetHeader()->GetEvent()+1;
+  Int_t ievent=AliRunLoader::Instance()->GetHeader()->GetEvent()+1;
   //
   // Energy loss information
   if(ievent) {
@@ -475,7 +436,7 @@ void AliMC::BeginEvent()
   AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
   AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
     
-  AliRunLoader *runloader=gAlice->GetRunLoader();
+  AliRunLoader *runloader=AliRunLoader::Instance();
 
   /*******************************/    
   /*   Clean after eventual      */
@@ -497,14 +458,14 @@ void AliMC::BeginEvent()
       runloader->MakeStack();//or make a new one
   
   
-  if(gAlice->Lego() == 0x0)
+  if(AliSimulation::Instance()->Lego() == 0x0)
   { 
       AliDebug(1, "fRunLoader->MakeTree(K)");
       runloader->MakeTree("K");
   }
   
   AliDebug(1, "gMC->SetStack(fRunLoader->Stack())");
-  gMC->SetStack(gAlice->GetRunLoader()->Stack());//Was in InitMC - but was moved here 
+  gMC->SetStack(runloader->Stack());//Was in InitMC - but was moved here 
                                      //because we don't have guarantee that 
                                      //stack pointer is not going to change from event to event
                         //since it bellobgs to header and is obtained via RunLoader
@@ -516,9 +477,9 @@ void AliMC::BeginEvent()
                                gAlice->GetEventNrInRun());
 //  fRunLoader->WriteKinematics("OVERWRITE");  is there any reason to rewrite here since MakeTree does so
 
-  if(gAlice->Lego()) 
+  if(AliSimulation::Instance()->Lego()) 
   {
-      gAlice->Lego()->BeginEvent();
+      AliSimulation::Instance()->Lego()->BeginEvent();
       return;
   }
   
@@ -555,10 +516,37 @@ void AliMC::ResetHits()
   }
 }
 
+//_______________________________________________________________________
+void AliMC::ResetDigits()
+{
+  //
+  //  Reset all Detectors digits
+  //
+  TIter next(gAlice->Modules());
+  AliModule *detector;
+  while((detector = dynamic_cast<AliModule*>(next()))) {
+     detector->ResetDigits();
+  }
+}
+
+//_______________________________________________________________________
+void AliMC::ResetSDigits()
+{
+  //
+  //  Reset all Detectors digits
+  //
+  TIter next(gAlice->Modules());
+  AliModule *detector;
+  while((detector = dynamic_cast<AliModule*>(next()))) {
+     detector->ResetSDigits();
+  }
+}
+
 //_______________________________________________________________________
 void AliMC::PostTrack()
 {
   // Posts tracks for each module
+
   TObjArray &dets = *gAlice->Modules();
   AliModule *module;
   
@@ -573,7 +561,8 @@ void AliMC::FinishPrimary()
   //
   // Called  at the end of each primary track
   //
-  AliRunLoader *runloader=gAlice->GetRunLoader();
+
+  AliRunLoader *runloader=AliRunLoader::Instance();
   //  static Int_t count=0;
   //  const Int_t times=10;
   // This primary is finished, purify stack
@@ -604,7 +593,7 @@ void AliMC::RemapHits()
 {
 //    
 // Remaps the track labels of the hits
-    AliRunLoader *runloader=gAlice->GetRunLoader();
+    AliRunLoader *runloader=AliRunLoader::Instance();
     AliStack* stack = runloader->Stack();
     TList* hitLists = GetHitLists();
     TIter next(hitLists);
@@ -641,10 +630,8 @@ void AliMC::FinishEvent()
   //
   // Called at the end of the event.
   //
-  
-  //
     
-  if(gAlice->Lego()) gAlice->Lego()->FinishEvent();
+  if(AliSimulation::Instance()->Lego()) AliSimulation::Instance()->Lego()->FinishEvent();
 
   TIter next(gAlice->Modules());
   AliModule *detector;
@@ -660,7 +647,7 @@ void AliMC::FinishEvent()
     fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
    }
 
-  AliRunLoader *runloader=gAlice->GetRunLoader();
+  AliRunLoader *runloader=AliRunLoader::Instance();
 
   AliHeader* header = runloader->GetHeader();
   AliStack* stack = runloader->Stack();
@@ -674,7 +661,7 @@ void AliMC::FinishEvent()
   header->SetNtrack(stack->GetNtrack());  
 
   // Write out the kinematics
-  if (!gAlice->Lego()) stack->FinishEvent();
+  if (!AliSimulation::Instance()->Lego()) stack->FinishEvent();
 
   // Synchronize the TreeTR with TreeK
   if (fTmpTreeTR) ReorderAndExpandTreeTR();
@@ -691,7 +678,7 @@ void AliMC::FinishEvent()
     AliError("Can not get TreeE from RL");
    }
   
-  if(gAlice->Lego() == 0x0)
+  if(AliSimulation::Instance()->Lego() == 0x0)
    {
      runloader->WriteKinematics("OVERWRITE");
      runloader->WriteTrackRefs("OVERWRITE");
@@ -707,13 +694,6 @@ void AliMC::FinishEvent()
   AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
 }
 
-//_______________________________________________________________________
-void AliMC::Field(const Double_t* x, Double_t* b) const
-{
-  // Calculates field "b" at point "x"
-    gAlice->Field(x,b);
-}
-    
 //_______________________________________________________________________
 void AliMC::Init()
 {
@@ -738,9 +718,6 @@ void AliMC::Init()
    fSummEnergy.Set(gMC->NofVolumes()+1);
    fSum2Energy.Set(gMC->NofVolumes()+1);
 
-   //
-   fMCQA = new AliMCQA(gAlice->GetNdets());
-
    // Register MC in configuration 
    AliConfig::Instance()->Add(gMC);
 
@@ -916,18 +893,6 @@ void AliMC::SetTransPar(const char *filename)
   fTransParName = filename;
 }
 
-//_______________________________________________________________________
-void AliMC::Browse(TBrowser *b)
-{
-  //
-  // Called when the item "Run" is clicked on the left pane
-  // of the Root browser.
-  // It displays the Root Trees and all detectors.
-  //
-  //detectors are in folders anyway
-  b->Add(fMCQA,"AliMCQA");
-}
-
 //_______________________________________________________________________
 void AliMC::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
 {
@@ -953,7 +918,7 @@ Int_t AliMC::GetCurrentTrackNumber() const {
   //
   // Returns current track
   //
-  return gAlice->GetRunLoader()->Stack()->GetCurrentTrackNumber();
+  return AliRunLoader::Instance()->Stack()->GetCurrentTrackNumber();
 }
 
 //_______________________________________________________________________
@@ -962,7 +927,7 @@ void AliMC::DumpPart (Int_t i) const
   //
   // Dumps particle i in the stack
   //
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
    if (runloader->Stack())
     runloader->Stack()->DumpPart(i);
 }
@@ -973,7 +938,7 @@ void AliMC::DumpPStack () const
   //
   // Dumps the particle stack
   //
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
    if (runloader->Stack())
     runloader->Stack()->DumpPStack();
 }
@@ -984,7 +949,7 @@ Int_t AliMC::GetNtrack() const {
   // Returns number of tracks in stack
   //
   Int_t ntracks = -1;
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
    if (runloader->Stack())
      ntracks = runloader->Stack()->GetNtrack();
    return ntracks;
@@ -997,7 +962,7 @@ Int_t AliMC::GetPrimary(Int_t track) const
   // return number of primary that has generated track
   //
   Int_t nprimary = -999;
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader->Stack())
     nprimary = runloader->Stack()->GetPrimary(track);
   return nprimary;
@@ -1008,7 +973,7 @@ 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();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader)
    if (runloader->Stack())
     return runloader->Stack()->Particle(i);
@@ -1020,7 +985,7 @@ const TObjArray* AliMC::Particles() const {
   //
   // Returns pointer to Particles array
   //
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader)
    if (runloader->Stack())
     return runloader->Stack()->Particles();
@@ -1028,13 +993,13 @@ const TObjArray* AliMC::Particles() const {
 }
 
 //_______________________________________________________________________
-void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
-                      Float_t *vpos, Float_t *polar, Float_t tof,
+void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg, const Float_t *pmom,
+                      const Float_t *vpos, const Float_t *polar, Float_t tof,
                       TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is) const
 { 
 // Delegate to stack
 //
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader)
     if (runloader->Stack())
       runloader->Stack()->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
@@ -1050,7 +1015,7 @@ void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg,
 { 
   // Delegate to stack
   //
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader)
     if (runloader->Stack())
       runloader->Stack()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
@@ -1062,7 +1027,7 @@ void AliMC::SetHighWaterMark(Int_t nt) const
 {
     //
     // Set high water mark for last track in event
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader)
     if (runloader->Stack())
       runloader->Stack()->SetHighWaterMark(nt);
@@ -1074,7 +1039,7 @@ void AliMC::KeepTrack(Int_t track) const
   //
   // Delegate to stack
   //
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader)
     if (runloader->Stack())
       runloader->Stack()->KeepTrack(track);
@@ -1085,7 +1050,7 @@ void AliMC::FlagTrack(Int_t track) const
 {
   // Delegate to stack
   //
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader)
     if (runloader->Stack())
       runloader->Stack()->FlagTrack(track);
@@ -1097,7 +1062,7 @@ void AliMC::SetCurrentTrack(Int_t track) const
   //
   // Set current track number
   //
-  AliRunLoader * runloader = gAlice->GetRunLoader();
+  AliRunLoader * runloader = AliRunLoader::Instance();
   if (runloader)
     if (runloader->Stack())
       runloader->Stack()->SetCurrentTrack(track); 
@@ -1126,6 +1091,7 @@ void AliMC::ResetTrackReferences()
     fTmpTrackReferences.Clear();
 }
 
+//_______________________________________________________________________
 void AliMC::RemapTrackReferencesIDs(Int_t *map)
 {
   // 
@@ -1148,6 +1114,7 @@ void AliMC::RemapTrackReferencesIDs(Int_t *map)
   fTmpTrackReferences.Compress();
 }
 
+//_______________________________________________________________________
 void AliMC::FixParticleDecaytime()
 {
     //
@@ -1162,7 +1129,7 @@ void AliMC::FixParticleDecaytime()
     // Transverse velocity 
     Double_t vt    = p.Pt() / p.E();
     
-    if ((b = gAlice->Field()->SolenoidField()) > 0.) {     // [kG]
+    if ((b = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->SolenoidField()) > 0.) {     // [kG]
 
        // Radius of helix
        
@@ -1175,12 +1142,13 @@ void AliMC::FixParticleDecaytime()
        // Maximum and minimum decay time
        //
        // Check for curlers first
-       if (fRDecayMax * fRDecayMax / rho / rho / 2. > 1.) return;
+       const Double_t kOvRhoSqr2 = 1./(rho*TMath::Sqrt(2.));
+       if (fRDecayMax * kOvRhoSqr2 > 1.) return;
        
        //
  
-       tmax  = TMath::ACos(1. - fRDecayMax * fRDecayMax / rho / rho / 2.) / omega;   // [ct]
-       tmin  = TMath::ACos(1. - fRDecayMin * fRDecayMin / rho / rho / 2.) / omega;   // [ct]
+       tmax  = TMath::ACos((1.-fRDecayMax*kOvRhoSqr2)*(1.+fRDecayMax*kOvRhoSqr2)) / omega;   // [ct]
+       tmin  = TMath::ACos((1.-fRDecayMin*kOvRhoSqr2)*(1.+fRDecayMin*kOvRhoSqr2)) / omega;   // [ct]
     } else {
        tmax =  fRDecayMax / vt;                                                      // [ct] 
        tmin =  fRDecayMin / vt;                                                      // [ct]
@@ -1205,13 +1173,14 @@ void AliMC::MakeTmpTrackRefsTree()
     fTmpTreeTR->Branch("TrackReferences", "TClonesArray", &pRef, 4000);
 }
 
+//_______________________________________________________________________
 void AliMC::ReorderAndExpandTreeTR()
 {
 //
 //  Reorder and expand the temporary track reference tree in order to match the kinematics tree
 //
 
-    AliRunLoader *rl = gAlice->GetRunLoader();
+    AliRunLoader *rl = AliRunLoader::Instance();
 //
 //  TreeTR
     AliDebug(1, "fRunLoader->MakeTrackRefsContainer()");