]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSGetter.cxx
Setting default CDB storage
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.cxx
index 9f94b708c39f7a1e9c16b588a51ef53919d0a711..1badb748a1e4fbf16b23b7ee73c7827cb36dcee8 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 ---
 
 #include "AliPHOSRawStream.h"
 #include "AliRawReaderFile.h"
 #include "AliLog.h"
+#include "AliCDBLocal.h"
+#include "AliCDBStorage.h"
+#include "AliCDBManager.h"
 
 ClassImp(AliPHOSGetter)
   
 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ; 
 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
 Int_t AliPHOSGetter::fgDebug = 0;
+AliPHOSCalibData* AliPHOSGetter::fCalibData = 0;
+AliPHOSAlignData* AliPHOSGetter::fAlignData = 0;
 
 //  TFile * AliPHOSGetter::fgFile = 0 ; 
 
@@ -87,6 +93,7 @@ AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option
     if (rl->GetAliRun() == 0x0) {
       rl->LoadgAlice();
       gAlice = rl->GetAliRun(); // should be removed
+      rl->LoadHeader();
     }
   }
   fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
@@ -95,7 +102,6 @@ AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option
   else 
     fgPhosLoader->SetTitle(version);
   
-  
   // initialize data members
   SetDebug(0) ; 
   fBTE = 0 ; 
@@ -107,23 +113,32 @@ 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 +274,81 @@ 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") )
-    ReadRaw(event) ;
+}
+
+
+//____________________________________________________________________________ 
+void AliPHOSGetter::Event(AliRawReader *rawReader, const char* opt) 
+{
+  // Reads the raw event from rawReader
 
-//   if( strstr(opt,"Q") )
-//     ReadTreeQA() ;
+  AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
+  
+  if( strstr(opt,"W")  ){
+    rawReader->NextEvent(); 
+    Int_t iEvent = rl->GetEventNumber();
+    rl->GetEvent(iEvent);
+    ReadRaw(rawReader) ;
+    rl->SetEventNumber(++iEvent);
+  }    
  
 }
 
@@ -348,8 +382,6 @@ AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char*
   // Creates and returns the pointer of the unique instance
   // Must be called only when the environment has changed
   
-  //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
-  
   if(!fgObjGetter){ // first time the getter is called 
     fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
   }
@@ -421,7 +453,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,18 +562,21 @@ Bool_t AliPHOSGetter::OpenESDFile()
   return rv ; 
 }
 
-
 //____________________________________________________________________________ 
-void AliPHOSGetter::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHighGain, TF1* signalF, Int_t & amp, Double_t & time)
+void AliPHOSGetter::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHighGain, TF1* signalF, Double_t & energy, 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. ; 
+  time   = 0. ; 
+  energy = 0. ; 
 
   if (lowGainFlag) {
+    timezero1 = timezero2 = signalmax = timemax = 0. ;
+    signalF->FixParameter(0, PHOS()->GetRawFormatLowCharge()) ; 
+    signalF->FixParameter(1, PHOS()->GetRawFormatLowGain()) ; 
     Int_t index ; 
     for (index = 0; index < PHOS()->GetRawFormatTimeBins(); index++) {
       gLowGain->GetPoint(index, time, signal) ; 
@@ -580,66 +624,97 @@ void AliPHOSGetter::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHigh
       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 ) ; 
-  }
+  if (time == 0) energy = 0 ; 
 }
 
 //____________________________________________________________________________ 
-Int_t AliPHOSGetter::ReadRaw(Int_t event)
+Int_t AliPHOSGetter::CalibrateRaw(Double_t energy, Int_t *relId)
+{
+  // Convert energy into digitized amplitude for a cell relId
+  // It is a user responsilibity to open CDB and set
+  // AliPHOSCalibData object by the following operators:
+  // 
+  // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
+  // AliPHOSCalibData* clb = (AliPHOSCalibData*)AliCDBStorage::Instance()
+  //    ->Get(path_to_calibdata,run_number);
+  // AliPHOSGetter* gime = AliPHOSGetter::Instance("galice.root");
+  // gime->SetCalibData(clb);
+
+  if (CalibData() == 0)
+    Warning("CalibrateRaw","Calibration DB is not initiated!");
+
+  Int_t   module = relId[0];
+  Int_t   column = relId[3];
+  Int_t   row    = relId[2];
+
+  Float_t gainFactor = 0.0015; // width of one Emc ADC channel in GeV
+  Float_t pedestal   = 0.005;  // Emc pedestals
+
+  if(CalibData()) {
+    gainFactor = CalibData()->GetADCchannelEmc (module,column,row);
+    pedestal   = CalibData()->GetADCpedestalEmc(module,column,row);
+  }
+  
+  Int_t   amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ; 
+  return amp;
+}
+//____________________________________________________________________________ 
+Int_t AliPHOSGetter::ReadRaw(AliRawReader *rawReader)
 {
   // reads the raw format data, converts it into digits format and store digits in Digits()
   // container.
 
-  AliRawReaderFile rawReader(event) ; 
-  AliPHOSRawStream in(&rawReader);
-
+  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 ;
+  Int_t relId[4], id =0;
   Bool_t lowGainFlag = kFALSE ; 
  
   TClonesArray * digits = Digits() ;
   digits->Clear() ; 
   Int_t idigit = 0 ; 
-  Int_t amp = 0 ; 
-  Double_t time = 0. ; 
-  
+  Int_t amp    = 0 ; 
+  Double_t energy = 0. ; 
+  Double_t time   = 0. ; 
+
+  TGraph * gLowGain = new TGraph(PHOS()->GetRawFormatTimeBins()) ; 
+  TGraph * gHighGain= new TGraph(PHOS()->GetRawFormatTimeBins()) ;  
+
   while ( in.Next() ) { // PHOS entries loop 
     if ( (in.IsNewRow() || in.IsNewColumn() || in.IsNewModule()) ) {
+      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 (!first) {
-       
-       FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, amp, time) ; 
+       FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, energy, time) ; 
+//     amp = CalibrateRaw(energy,relId);
+       amp = (Int_t)energy;
        if (amp > 0) {
          new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;     
          idigit++ ; 
        }
+       Int_t index ; 
+       for (index = 0; index < PHOS()->GetRawFormatTimeBins(); index++) {
+         gLowGain->SetPoint(index, index * PHOS()->GetRawFormatTimeMax() / PHOS()->GetRawFormatTimeBins(), 0) ;  
+         gHighGain->SetPoint(index, index * PHOS()->GetRawFormatTimeMax() / PHOS()->GetRawFormatTimeBins(), 0) ; 
+       } 
       }
       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.GetTime()* PHOS()->GetRawFormatTimeMax() / PHOS()->GetRawFormatTimeBins()
                     in.GetSignal()) ;
     else 
       gHighGain->SetPoint(in.GetTime(), 
@@ -648,30 +723,61 @@ Int_t AliPHOSGetter::ReadRaw(Int_t event)
 
   } // PHOS entries loop
 
-  FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, amp, time) ; 
+  FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, energy, time) ; 
+//   amp = CalibrateRaw(energy,relId);
+  amp = (Int_t)energy;
   if (amp > 0 ) {
     new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
     idigit++ ; 
   }
+  digits->Sort() ; 
 
   delete signalF ; 
-  delete gLowGain, gHighGain ; 
+  delete gLowGain;
+  delete gHighGain ; 
   
+//   AliInfo(Form("Event %d, digits: %d\n", EventNumber(),digits->GetEntries())); //bvp
   return digits->GetEntriesFast() ; 
 }
 
+//   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
   
   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() ; 
 }
 
@@ -981,3 +1087,23 @@ Float_t AliPHOSGetter::BeamEnergy(void) const
   else
     return 0 ;
 }
+//____________________________________________________________________________ 
+
+AliPHOSCalibData* AliPHOSGetter::CalibData()
+{ 
+  // Check if the instance of AliPHOSCalibData exists, and return it
+
+  if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) )
+    fCalibData=0x0;
+  return fCalibData;
+}
+//____________________________________________________________________________ 
+
+AliPHOSAlignData* AliPHOSGetter::AlignData()
+{ 
+  // Check if the instance of AliPHOSAlignData exists, and return it
+
+  if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) )
+    fAlignData=0x0;
+  return fAlignData;
+}