]> 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 9f94b708c39f7a1e9c16b588a51ef53919d0a711..85efc1e1b1ff5f46d656f48dedc48a4021f3da2c 100644 (file)
 #include <TROOT.h>
 #include <TSystem.h>
 #include <TParticle.h>
-#include <TH1D.h>
 #include <TF1.h>
 #include <TGraph.h>
+//#include <TCanvas.h>
+//#include <TFrame.h>
 
 // --- Standard library ---
 
@@ -95,7 +96,6 @@ AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option
   else 
     fgPhosLoader->SetTitle(version);
   
-  
   // initialize data members
   SetDebug(0) ; 
   fBTE = 0 ; 
@@ -107,23 +107,31 @@ AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option
   fESDFile = 0 ; 
   fESD = 0 ; 
   fESDTree = 0 ; 
+  fRawDigits = kFALSE ;
 }
 
 //____________________________________________________________________________ 
 AliPHOSGetter::~AliPHOSGetter()
 {
   // dtor
-  delete fgPhosLoader ;
-  fgPhosLoader = 0 ;
-  delete fBTE ; 
-  fBTE = 0 ; 
-  fPrimaries->Delete() ; 
-  delete fPrimaries ; 
-  fgObjGetter = 0;
+  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 ; 
+    delete fESDTree ;
+  //  fgObjGetter = 0;
 }
 
 //____________________________________________________________________________ 
@@ -259,62 +267,72 @@ 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") )
+  if( strstr(opt,"E") ){
     ReadTreeE(event) ;
+  }    
 
-  if( strstr(opt,"W") )
+if( strstr(opt,"W")  ){
     ReadRaw(event) ;
+  }    
  
 
-//   if( strstr(opt,"Q") )
+//   if( strstr(opt,"Q")   && (fCurentEvent[9]!=event) )
 //     ReadTreeQA() ;
+//   }    
  
 }
 
@@ -421,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() ) ; 
@@ -521,74 +548,6 @@ Bool_t AliPHOSGetter::OpenESDFile()
   return rv ; 
 }
 
-
-//____________________________________________________________________________ 
-void AliPHOSGetter::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHighGain, TF1* signalF, Int_t & amp, Double_t & time)
-{
-  // Fits the raw signal time distribution 
-
-  const Int_t kNoiseThreshold = 0 ;
-  Double_t timezero1 = 0., timezero2 = 0., timemax = 0. ;
-  Double_t signal = 0., signalmax = 0. ;       
-  Double_t energy = time = 0. ; 
-
-  if (lowGainFlag) {
-    Int_t index ; 
-    for (index = 0; index < PHOS()->GetRawFormatTimeBins(); index++) {
-      gLowGain->GetPoint(index, time, signal) ; 
-      if (signal > kNoiseThreshold && timezero1 == 0.) 
-       timezero1 = time ;
-      if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
-       timezero2 = time ; 
-      if (signal > signalmax) {
-       signalmax = signal ; 
-       timemax   = time ; 
-      }
-    }
-    signalmax /= PHOS()->RawResponseFunctionMax(PHOS()->GetRawFormatLowCharge(), 
-                                               PHOS()->GetRawFormatLowGain()) ;
-    if ( timezero1 + PHOS()->GetRawFormatTimePeak() < PHOS()->GetRawFormatTimeMax() * 0.4 ) { // else its noise 
-      signalF->SetParameter(2, signalmax) ; 
-      signalF->SetParameter(3, timezero1) ;                
-      gLowGain->Fit(signalF, "QRON", "", 0., timezero2); //, "QRON") ; 
-      energy = signalF->GetParameter(2) ; 
-      time   = signalF->GetMaximumX() - PHOS()->GetRawFormatTimePeak() - PHOS()->GetRawFormatTimeTrigger() ;
-    }
-  } else {
-    timezero1 = timezero2 = signalmax = timemax = 0. ;
-    signalF->FixParameter(0, PHOS()->GetRawFormatHighCharge()) ; 
-    signalF->FixParameter(1, PHOS()->GetRawFormatHighGain()) ; 
-    Int_t index ; 
-    for (index = 0; index < PHOS()->GetRawFormatTimeBins(); index++) {
-      gHighGain->GetPoint(index, time, signal) ;               
-      if (signal > kNoiseThreshold && timezero1 == 0.) 
-       timezero1 = time ;
-      if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
-       timezero2 = time ; 
-      if (signal > signalmax) {
-       signalmax = signal ;   
-       timemax   = time ; 
-      }
-    }
-    signalmax /= PHOS()->RawResponseFunctionMax(PHOS()->GetRawFormatHighCharge(), 
-                                               PHOS()->GetRawFormatHighGain()) ;;
-    if ( timezero1 + PHOS()->GetRawFormatTimePeak() < PHOS()->GetRawFormatTimeMax() * 0.4 ) { // else its noise  
-      signalF->SetParameter(2, signalmax) ; 
-      signalF->SetParameter(3, timezero1) ;               
-      gHighGain->Fit(signalF, "QRON", "", 0., timezero2) ; 
-      energy = signalF->GetParameter(2) ; 
-      time   = signalF->GetMaximumX() - PHOS()->GetRawFormatTimePeak() - PHOS()->GetRawFormatTimeTrigger() ;
-    }
-  }
-  
-  if (time == 0. && energy == 0.) 
-    amp = 0 ; 
-  else {
-  AliPHOSDigitizer * digitizer = Digitizer() ; 
-  amp = static_cast<Int_t>( (energy - digitizer->GetEMCpedestal()) / digitizer->GetEMCchannel() + 0.5 ) ; 
-  }
-}
-
 //____________________________________________________________________________ 
 Int_t AliPHOSGetter::ReadRaw(Int_t event)
 {
@@ -597,81 +556,45 @@ Int_t AliPHOSGetter::ReadRaw(Int_t event)
 
   AliRawReaderFile rawReader(event) ; 
   AliPHOSRawStream in(&rawReader);
-
-  Bool_t first = kTRUE ;
-  
-  TGraph * gLowGain  = new TGraph(PHOS()->GetRawFormatTimeBins()) ; 
-  TGraph * gHighGain = new TGraph(PHOS()->GetRawFormatTimeBins()) ; 
-  TF1 * signalF = new TF1("signal", AliPHOS::RawResponseFunction, 0, PHOS()->GetRawFormatTimeMax(), 4);
-  signalF->SetParNames("Charge", "Gain", "Amplitude", "TimeZero") ; 
-
-  Int_t relId[4], id ;
-  Bool_t lowGainFlag = kFALSE ; 
  
   TClonesArray * digits = Digits() ;
   digits->Clear() ; 
   Int_t idigit = 0 ; 
-  Int_t amp = 0 ; 
-  Double_t time = 0. ; 
-  
+
   while ( in.Next() ) { // PHOS entries loop 
-    if ( (in.IsNewRow() || in.IsNewColumn() || in.IsNewModule()) ) {
-      if (!first) {
-       
-       FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, amp, time) ; 
-       if (amp > 0) {
-         new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;     
-         idigit++ ; 
-       }
-      }
-      first = kFALSE ; 
-      relId[0] = in.GetModule() ;
-      if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) { 
-       relId[0] -=  PHOS()->GetRawFormatLowGainOffset() ; 
-       lowGainFlag = kTRUE ; 
-      } else 
-       lowGainFlag = kFALSE ; 
-      relId[1] = 0 ; 
-      relId[2] = in.GetRow() ; 
-      relId[3] = in.GetColumn() ; 
-      PHOSGeometry()->RelToAbsNumbering(relId, id) ;   
-    }
-    if (lowGainFlag)
-      gLowGain->SetPoint(in.GetTime(), 
-                    in.GetTime(), 
-                    in.GetSignal()) ;
-    else 
-      gHighGain->SetPoint(in.GetTime(), 
-                        in.GetTime() * PHOS()->GetRawFormatTimeMax() / PHOS()->GetRawFormatTimeBins(), 
-                        in.GetSignal() ) ;
+    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
-
-  FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, amp, time) ; 
-  if (amp > 0 ) {
-    new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
-    idigit++ ; 
-  }
-
-  delete signalF ; 
-  delete gLowGain, gHighGain ; 
+  
+  digits->Sort() ; 
   
   return digits->GetEntriesFast() ; 
 }
-
 //____________________________________________________________________________ 
 Int_t AliPHOSGetter::ReadTreeD()
 {
   // Read the Digits
   
   PhosLoader()->CleanDigits() ;    
-  // gets TreeD from the root file (PHOS.Digits.root)
-  // if ( !IsLoaded("D") ) {
-    PhosLoader()->LoadDigits("UPDATE") ;
-    PhosLoader()->LoadDigitizer("UPDATE") ;
-    //  SetLoaded("D") ; 
-    //} 
+  PhosLoader()->LoadDigits("UPDATE") ;
+  PhosLoader()->LoadDigitizer("UPDATE") ;
   return Digits()->GetEntries() ; 
 }