]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSGetter.cxx
preliminary PID in TPC needed by the ITS tracker
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.cxx
index 1b221d9546608558fd2534cf108d1d23f3093d15..85efc1e1b1ff5f46d656f48dedc48a4021f3da2c 100644 (file)
 
 // --- ROOT system ---
 
-#include "TSystem.h"
-#include "TFile.h"
-#include "TROOT.h"
-
+#include <TFile.h>
+#include <TROOT.h>
+#include <TSystem.h>
+#include <TParticle.h>
+#include <TF1.h>
+#include <TGraph.h>
+//#include <TCanvas.h>
+//#include <TFrame.h>
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
-
+#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 "AliPHOSRaw2Digits.h"
-//#include "AliPHOSCalibrationDB.h"
-#include "AliPHOSBeamTestEvent.h"
-#include "AliMC.h"
+#include "AliPHOSRawStream.h"
+#include "AliRawReaderFile.h"
+#include "AliLog.h"
 
 ClassImp(AliPHOSGetter)
   
@@ -89,29 +96,62 @@ AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option
   else 
     fgPhosLoader->SetTitle(version);
   
-  
   // initialize data members
   SetDebug(0) ; 
   fBTE = 0 ; 
   fPrimaries = 0 ; 
   fLoadingStatus = "" ; 
+  fESDFileName = rl->GetFileName()  ; // this should be the galice.root file
+  fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;  
+  fESDFile = 0 ; 
+  fESD = 0 ; 
+  fESDTree = 0 ; 
+  fRawDigits = kFALSE ;
 }
 
 //____________________________________________________________________________ 
 AliPHOSGetter::~AliPHOSGetter()
 {
   // dtor
-  delete fgPhosLoader ;
-  fgPhosLoader = 0 ;
-  delete fBTE ; 
-  fBTE = 0 ; 
-  fPrimaries->Delete() ; 
-  delete fPrimaries ; 
+  if(fgPhosLoader){
+    delete fgPhosLoader ;
+    fgPhosLoader = 0 ;
+  }
+  if(fBTE){
+    delete fBTE ; 
+    fBTE = 0 ;
+  } 
+  if(fPrimaries){
+    fPrimaries->Delete() ; 
+    delete fPrimaries ;
+  } 
+  if (fESD) 
+    delete fESD ; 
+  if (fESDTree) 
+    delete fESDTree ;
+  //  fgObjGetter = 0;
+}
+
+//____________________________________________________________________________ 
+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; 
 }
 
 //____________________________________________________________________________ 
 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
 { 
+  // Returns pointer to the Clusterizer task 
   AliPHOSClusterizer * rv ; 
   rv =  dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
   if (!rv) {
@@ -154,6 +194,7 @@ TClonesArray * AliPHOSGetter::Digits()
 //____________________________________________________________________________ 
 AliPHOSDigitizer * AliPHOSGetter::Digitizer() 
 { 
+  // Returns pointer to the Digitizer task 
   AliPHOSDigitizer * rv ; 
   rv =  dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
   if (!rv) {
@@ -195,8 +236,9 @@ TClonesArray * AliPHOSGetter::TrackSegments()
 }
 
 //____________________________________________________________________________ 
-AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker() 
+AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
 { 
+  // Returns pointer to the TrackSegmentMaker task 
   AliPHOSTrackSegmentMaker * rv ; 
   rv =  dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
   if (!rv) {
@@ -221,59 +263,76 @@ 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
 
-  if ( event >= MaxEvent() ) {
-    Error("Event", "%d not found in TreeE !", event) ; 
-    return ; 
-  }
+//   if ( event >= MaxEvent() ) {
+//     Error("Event", "%d not found in TreeE !", event) ; 
+//     return ; 
+//   }
 
   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
 
-  // checks if we are dealing with test-beam data
-  TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
-  if(btb){
-    if(!fBTE)
-      fBTE = new AliPHOSBeamTestEvent() ;
-    btb->SetAddress(&fBTE) ;
-    btb->GetEntry(event) ;
-  }
-  else{
-    if(fBTE){
-      delete fBTE ;
-      fBTE = 0 ;
-    }
-  }
+//   // checks if we are dealing with test-beam data
+//   TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
+//   if(btb){
+//     if(!fBTE)
+//       fBTE = new AliPHOSBeamTestEvent() ;
+//     btb->SetAddress(&fBTE) ;
+//     btb->GetEntry(event) ;
+//   }
+//   else{
+//     if(fBTE){
+//       delete fBTE ;
+//       fBTE = 0 ;
+//     }
+//   }
 
   // Loads the type of object(s) requested
   
   rl->GetEvent(event) ;
 
-  if( strstr(opt,"X") || (strcmp(opt,"")==0) )
+  if(strstr(opt,"X") || (strcmp(opt,"")==0)){
     ReadPrimaries() ;
-
-  if(strstr(opt,"H") )
+  }
+  
+  if(strstr(opt,"H")  ){
     ReadTreeH();
-
-  if(strstr(opt,"S") )
+  }
+  
+  if(strstr(opt,"S")  ){
     ReadTreeS() ;
-
-  if( strstr(opt,"D") )
+  }
+  
+  if(strstr(opt,"D") ){
     ReadTreeD() ;
-
-  if( strstr(opt,"R") )
+  }
+  
+  if(strstr(opt,"R") ){
     ReadTreeR() ;
+  }
 
-  if( strstr(opt,"T") )
+  if( strstr(opt,"T") ){
     ReadTreeT() ;
+  }    
 
-  if( strstr(opt,"P") )
+  if( strstr(opt,"P") ){
     ReadTreeP() ;
+  }    
+
+  if( strstr(opt,"E") ){
+    ReadTreeE(event) ;
+  }    
+
+if( strstr(opt,"W")  ){
+    ReadRaw(event) ;
+  }    
 
-//   if( strstr(opt,"Q") )
+//   if( strstr(opt,"Q")   && (fCurentEvent[9]!=event) )
 //     ReadTreeQA() ;
+//   }    
  
 }
 
@@ -332,11 +391,15 @@ 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("Instance", "Failed to create the PHOS Getter object") ;
+    ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
   else 
     if (fgDebug)
       Print() ;
@@ -349,8 +412,8 @@ AliPHOSGetter *  AliPHOSGetter::Instance()
 {
   // Returns the pointer of the unique instance already defined
   
-  if(!fgObjGetter)
-     ::Error("Instance", "Getter not initialized") ;
+  if(!fgObjGetter && fgDebug)
+     ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
 
    return fgObjGetter ;
            
@@ -376,7 +439,16 @@ TParticle * AliPHOSGetter::Primary(Int_t index) const
 AliPHOS * AliPHOSGetter:: PHOS() const  
 {
   // returns the PHOS object 
-  AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;  
+  AliPHOSLoader *    loader = 0;
+  static AliPHOSLoader * oldloader = 0;
+  static AliPHOS * phos = 0;
+
+  loader = PhosLoader();
+
+  if ( loader != oldloader) {
+    phos = dynamic_cast<AliPHOS*>(loader->GetModulesFolder()->FindObject("PHOS")) ;
+    oldloader = loader;
+  }
   if (!phos) 
     if (fgDebug)
       Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ; 
@@ -386,8 +458,9 @@ AliPHOS * AliPHOSGetter:: PHOS() const
 
 
 //____________________________________________________________________________ 
-AliPHOSPID * AliPHOSGetter::PID() 
+AliPHOSPID * AliPHOSGetter::PID()
 { 
+  // Returns pointer to the PID task 
   AliPHOSPID * rv ; 
   rv =  dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
   if (!rv) {
@@ -437,11 +510,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() ) ; 
 
@@ -456,18 +529,72 @@ void AliPHOSGetter::ReadPrimaries()
   }
 }
 
+//____________________________________________________________________________ 
+Bool_t AliPHOSGetter::OpenESDFile() 
+{
+  //Open the ESD file    
+  Bool_t rv = kTRUE ; 
+  if (!fESDFile) {
+    fESDFile = TFile::Open(fESDFileName) ;
+    if (!fESDFile ) 
+      return kFALSE ; 
+  }
+  else if (fESDFile->IsOpen()) {
+    fESDFile->Close() ; 
+    fESDFile = TFile::Open(fESDFileName) ;
+  }
+  if (!fESDFile->IsOpen())
+    rv = kFALSE ; 
+  return rv ; 
+}
+
+//____________________________________________________________________________ 
+Int_t AliPHOSGetter::ReadRaw(Int_t event)
+{
+  // reads the raw format data, converts it into digits format and store digits in Digits()
+  // container.
+
+  AliRawReaderFile rawReader(event) ; 
+  AliPHOSRawStream in(&rawReader);
+  TClonesArray * digits = Digits() ;
+  digits->Clear() ; 
+  Int_t idigit = 0 ; 
+
+  while ( in.Next() ) { // PHOS entries loop 
+    Int_t amp = in.GetSignal() ; 
+    Double_t time = in.GetTime() ; 
+    Int_t relId[4], id ;
+
+    relId[0] = in.GetModule() ;
+    if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) { 
+      relId[0] -=  PHOS()->GetRawFormatLowGainOffset() ; 
+    }
+    relId[1] = 0 ; 
+    relId[2] = in.GetRow() ; 
+    relId[3] = in.GetColumn() ; 
+    PHOSGeometry()->RelToAbsNumbering(relId, id) ;     
+    
+    if (amp > 0 && id >=0 ) {
+      new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;        
+      idigit++ ; 
+    }
+    
+  } // PHOS entries loop
+  
+  digits->Sort() ; 
+  
+  return digits->GetEntriesFast() ; 
+}
 //____________________________________________________________________________ 
 Int_t AliPHOSGetter::ReadTreeD()
 {
   // Read the Digits
   
-  
-  // gets TreeD from the root file (PHOS.SDigits.root)
-  if ( !IsLoaded("D") ) {
-    PhosLoader()->LoadDigits("UPDATE") ;
-    PhosLoader()->LoadDigitizer("UPDATE") ;
-    SetLoaded("D") ; 
-  } 
+  PhosLoader()->CleanDigits() ;    
+  PhosLoader()->LoadDigits("UPDATE") ;
+  PhosLoader()->LoadDigitizer("UPDATE") ;
   return Digits()->GetEntries() ; 
 }
 
@@ -475,12 +602,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() ; 
 }
 
@@ -489,13 +616,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() ; 
 }
@@ -505,28 +632,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() ; 
 }
@@ -535,17 +663,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() 
 {
@@ -562,8 +713,9 @@ TClonesArray * AliPHOSGetter::SDigits()
 }
 
 //____________________________________________________________________________ 
-AliPHOSSDigitizer * AliPHOSGetter::SDigitizer() 
+AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
 { 
+  // Returns pointer to the SDigitizer task 
   AliPHOSSDigitizer * rv ; 
   rv =  dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
   if (!rv) {
@@ -574,7 +726,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 
 
@@ -593,7 +745,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()
  
@@ -615,6 +767,7 @@ void AliPHOSGetter::Track(const Int_t itrack)
 //____________________________________________________________________________ 
 TTree * AliPHOSGetter::TreeD() const 
 {
+  // Returns pointer to the Digits Tree
   TTree * rv = 0 ; 
   rv = PhosLoader()->TreeD() ; 
   if ( !rv ) {
@@ -628,6 +781,7 @@ TTree * AliPHOSGetter::TreeD() const
 //____________________________________________________________________________ 
 TTree * AliPHOSGetter::TreeH() const 
 {
+  // Returns pointer to the Hits Tree
   TTree * rv = 0 ; 
   rv = PhosLoader()->TreeH() ; 
   if ( !rv ) {
@@ -641,6 +795,7 @@ TTree * AliPHOSGetter::TreeH() const
 //____________________________________________________________________________ 
 TTree * AliPHOSGetter::TreeR() const 
 {
+  // Returns pointer to the RecPoints Tree
   TTree * rv = 0 ; 
   rv = PhosLoader()->TreeR() ; 
   if ( !rv ) {
@@ -654,6 +809,7 @@ TTree * AliPHOSGetter::TreeR() const
 //____________________________________________________________________________ 
 TTree * AliPHOSGetter::TreeT() const 
 {
+  // Returns pointer to the TrackSegments Tree
   TTree * rv = 0 ; 
   rv = PhosLoader()->TreeT() ; 
   if ( !rv ) {
@@ -666,6 +822,7 @@ TTree * AliPHOSGetter::TreeT() const
 //____________________________________________________________________________ 
 TTree * AliPHOSGetter::TreeP() const 
 {
+  // Returns pointer to the RecParticles  Tree
   TTree * rv = 0 ; 
   rv = PhosLoader()->TreeP() ; 
   if ( !rv ) {
@@ -678,7 +835,8 @@ TTree * AliPHOSGetter::TreeP() const
 
 //____________________________________________________________________________ 
 TTree * AliPHOSGetter::TreeS() const 
-{
+{ 
+ // Returns pointer to the SDigits Tree
   TTree * rv = 0 ; 
   rv = PhosLoader()->TreeS() ; 
   if ( !rv ) {
@@ -704,7 +862,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()) ;
@@ -716,13 +874,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 ;