]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSGetter.cxx
Only with TGeo now (A. Gheata)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.cxx
index 929128b3b38eaebba00531961585641ecf2e85c0..6e9bfb620c12cfa3c5a2de2400ab3b7f80a3ab15 100644 (file)
 
 // --- ROOT system ---
 
-#include "TSystem.h"
-#include "TROOT.h"
+#include <TFile.h>
+#include <TROOT.h>
+#include <TSystem.h>
+#include <TParticle.h>
 
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
-#include "AliPHOSGetter.h"
+#include "AliESD.h"
+#include "AliHeader.h"  
+#include "AliMC.h"
 #include "AliPHOS.h"
+#include "AliPHOSBeamTestEvent.h"
+#include "AliPHOSGetter.h"
+#include "AliPHOSLoader.h"
 #include "AliRunLoader.h"
 #include "AliStack.h"  
-#include "AliPHOSLoader.h"
-#include "AliPHOSBeamTestEvent.h"
-#include "AliMC.h"
-#include "AliESD.h"
 
 ClassImp(AliPHOSGetter)
   
@@ -93,8 +96,12 @@ AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option
   fBTE = 0 ; 
   fPrimaries = 0 ; 
   fLoadingStatus = "" ; 
-  fESDFileName = "AliESDs.root" ; 
+  fESDFileName = rl->GetFileName()  ; // this should be the galice.root file
+  fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;  
   fESDFile = 0 ; 
+  fESD = 0 ; 
+  fESDTree = 0 ; 
 }
 
 //____________________________________________________________________________ 
@@ -107,6 +114,25 @@ AliPHOSGetter::~AliPHOSGetter()
   fBTE = 0 ; 
   fPrimaries->Delete() ; 
   delete fPrimaries ; 
+  fgObjGetter = 0;
+  if (fESD) 
+    delete fESD ; 
+  if (fESDTree) 
+    delete fESDTree ; 
+}
+
+//____________________________________________________________________________ 
+void AliPHOSGetter::Reset()
+{
+  // resets things in case the getter is called consecutively with different files
+  // the PHOS Loader is already deleted by the Run Loader
+
+  if (fPrimaries) { 
+    fPrimaries->Delete() ; 
+    delete fPrimaries ;
+  } 
+  fgPhosLoader = 0; 
+  fgObjGetter = 0; 
 }
 
 //____________________________________________________________________________ 
@@ -224,7 +250,7 @@ TClonesArray * AliPHOSGetter::RecParticles()
   return rv ; 
 }
 //____________________________________________________________________________ 
-void AliPHOSGetter::Event(const Int_t event, const char* opt) 
+void AliPHOSGetter::Event(Int_t event, const char* opt) 
 {
   // Reads the content of all Tree's S, D and R
 
@@ -274,7 +300,11 @@ void AliPHOSGetter::Event(const Int_t event, const char* opt)
 
   if( strstr(opt,"P") )
     ReadTreeP() ;
+
+  if( strstr(opt,"E") )
+    ReadTreeE(event) ;
  
+
 //   if( strstr(opt,"Q") )
 //     ReadTreeQA() ;
  
@@ -335,8 +365,12 @@ AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char*
        }
       }
     }
-    else 
+    else {
+      AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ; 
+      if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
+       delete rl ; 
       fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;      
+    }
   }
   if (!fgObjGetter) 
     ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
@@ -441,11 +475,11 @@ void AliPHOSGetter::ReadPrimaries()
   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
   
   // gets kine tree from the root file (Kinematics.root)
-  if ( ! rl->TreeK() )  // load treeK the first time
+  if ( ! rl->TreeK() ) { // load treeK the first time
     rl->LoadKinematics() ;
+  }
   
-  fNPrimaries = rl->Stack()->GetNtrack() ; 
-
+  fNPrimaries = (rl->GetHeader())->GetNtrack(); 
   if (fgDebug) 
     Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ; 
 
@@ -461,25 +495,15 @@ void AliPHOSGetter::ReadPrimaries()
 }
 
 //____________________________________________________________________________ 
-AliESD * AliPHOSGetter::ESD(Int_t event)
-{
-  //Read the ESD
-  if (!fESDFile)
-    OpenESDFile() ; 
-  
-  TString esdEvent("ESD") ;  
-  esdEvent+= event ; 
-  AliESD * esd = dynamic_cast<AliESD *>(fESDFile->Get(esdEvent)) ; 
-  return esd ; 
-}
-
-//____________________________________________________________________________ 
-Bool_t AliPHOSGetter::OpenESDFile(TString name) 
+Bool_t AliPHOSGetter::OpenESDFile() 
 {
+  //Open the ESD file    
   Bool_t rv = kTRUE ; 
-  fESDFileName = name ; 
-  if (!fESDFile)
-    fESDFile = new TFile(fESDFileName) ;
+  if (!fESDFile) {
+    fESDFile = TFile::Open(fESDFileName) ;
+    if (!fESDFile ) 
+      return kFALSE ; 
+  }
   else if (fESDFile->IsOpen()) {
     fESDFile->Close() ; 
     fESDFile = TFile::Open(fESDFileName) ;
@@ -494,13 +518,13 @@ Int_t AliPHOSGetter::ReadTreeD()
 {
   // Read the Digits
   
-  
-  // gets TreeD from the root file (PHOS.SDigits.root)
-  if ( !IsLoaded("D") ) {
+  PhosLoader()->CleanDigits() ;    
+  // gets TreeD from the root file (PHOS.Digits.root)
+  // if ( !IsLoaded("D") ) {
     PhosLoader()->LoadDigits("UPDATE") ;
     PhosLoader()->LoadDigitizer("UPDATE") ;
-    SetLoaded("D") ; 
-  } 
+    //  SetLoaded("D") ; 
+    //
   return Digits()->GetEntries() ; 
 }
 
@@ -508,12 +532,12 @@ Int_t AliPHOSGetter::ReadTreeD()
 Int_t AliPHOSGetter::ReadTreeH()
 {
   // Read the Hits
-    
+  PhosLoader()->CleanHits() ;
   // gets TreeH from the root file (PHOS.Hit.root)
-  if ( !IsLoaded("H") ) {
+  //if ( !IsLoaded("H") ) {
     PhosLoader()->LoadHits("UPDATE") ;
-    SetLoaded("H") ; 
-  }  
+  //  SetLoaded("H") ; 
+  //}  
   return Hits()->GetEntries() ; 
 }
 
@@ -522,13 +546,13 @@ Int_t AliPHOSGetter::ReadTreeR()
 {
   // Read the RecPoints
   
-  
+  PhosLoader()->CleanRecPoints() ;
   // gets TreeR from the root file (PHOS.RecPoints.root)
-  if ( !IsLoaded("R") ) {
+  //if ( !IsLoaded("R") ) {
     PhosLoader()->LoadRecPoints("UPDATE") ;
     PhosLoader()->LoadClusterizer("UPDATE") ;
-    SetLoaded("R") ; 
-  }
+    //  SetLoaded("R") ; 
+    //}
 
   return EmcRecPoints()->GetEntries() ; 
 }
@@ -538,28 +562,29 @@ Int_t AliPHOSGetter::ReadTreeT()
 {
   // Read the TrackSegments
   
-  
+  PhosLoader()->CleanTracks() ; 
   // gets TreeT from the root file (PHOS.TrackSegments.root)
-  if ( !IsLoaded("T") ) {
+  //if ( !IsLoaded("T") ) {
     PhosLoader()->LoadTracks("UPDATE") ;
     PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
-    SetLoaded("T") ; 
-  }
+    //    SetLoaded("T") ; 
+    //}
 
   return TrackSegments()->GetEntries() ; 
 }
 //____________________________________________________________________________ 
 Int_t AliPHOSGetter::ReadTreeP()
 {
-  // Read the TrackSegments
-  
+  // Read the RecParticles
   
+  PhosLoader()->CleanRecParticles() ; 
+
   // gets TreeT from the root file (PHOS.TrackSegments.root)
-  if ( !IsLoaded("P") ) {
+  //  if ( !IsLoaded("P") ) {
     PhosLoader()->LoadRecParticles("UPDATE") ;
     PhosLoader()->LoadPID("UPDATE") ;
-    SetLoaded("P") ; 
-  }
+    //  SetLoaded("P") ; 
+    //}
 
   return RecParticles()->GetEntries() ; 
 }
@@ -568,17 +593,40 @@ Int_t AliPHOSGetter::ReadTreeS()
 {
   // Read the SDigits
   
-  
+  PhosLoader()->CleanSDigits() ; 
   // gets TreeS from the root file (PHOS.SDigits.root)
-  if ( !IsLoaded("S") ) {
-    PhosLoader()->LoadSDigits("UPDATE") ;
-    PhosLoader()->LoadSDigitizer("UPDATE") ;
-    SetLoaded("S") ; 
-  }
+  //if ( !IsLoaded("S") ) {
+    PhosLoader()->LoadSDigits("READ") ;
+    PhosLoader()->LoadSDigitizer("READ") ;
+    //  SetLoaded("S") ; 
+    //}
 
   return SDigits()->GetEntries() ; 
 }
 
+//____________________________________________________________________________ 
+Int_t AliPHOSGetter::ReadTreeE(Int_t event)
+{
+  // Read the ESD
+  
+  // gets esdTree from the root file (AliESDs.root)
+  if (!fESDFile)
+    if ( !OpenESDFile() ) 
+      return -1 ; 
+
+  fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ; 
+  fESD = new AliESD;
+   if (!fESDTree) {
+
+     Error("ReadTreeE", "no ESD tree found");
+     return -1;
+   }
+   fESDTree->SetBranchAddress("ESD", &fESD);
+   fESDTree->GetEvent(event);
+
+   return event ; 
+}
+
 //____________________________________________________________________________ 
 TClonesArray * AliPHOSGetter::SDigits() 
 {
@@ -608,7 +656,7 @@ AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
 }
 
 //____________________________________________________________________________ 
-TParticle * AliPHOSGetter::Secondary(const TParticle* p, const Int_t index) const
+TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
 {
   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
 
@@ -627,7 +675,7 @@ TParticle * AliPHOSGetter::Secondary(const TParticle* p, const Int_t index) cons
 }
 
 //____________________________________________________________________________ 
-void AliPHOSGetter::Track(const Int_t itrack) 
+void AliPHOSGetter::Track(Int_t itrack) 
 {
   // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
  
@@ -744,7 +792,7 @@ Bool_t AliPHOSGetter::VersionExists(TString & opt) const
   if ( opt == "sdigits") {
     // add the version name to the root file name
     TString fileName( PhosLoader()->GetSDigitsFileName() ) ; 
-    if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name 
+    if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
       fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
     if ( !(gSystem->AccessPathName(fileName)) ) { 
       Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
@@ -756,13 +804,12 @@ Bool_t AliPHOSGetter::VersionExists(TString & opt) const
   if ( opt == "digits") {
     // add the version name to the root file name
     TString fileName( PhosLoader()->GetDigitsFileName() ) ; 
-    if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name 
+    if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
       fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
     if ( !(gSystem->AccessPathName(fileName)) ) {
       Warning("VersionExists", "The file %s already exists", fileName.Data()) ;  
       rv = kTRUE ; 
     }
-    PhosLoader()->SetDigitsFileName(fileName) ;
   }
 
   return rv ;