]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALDigitizer.cxx
New versions of GDC and CDH raw data headers. Some CDH getters are added
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigitizer.cxx
index 7bfc71b69b4e351fdaf8a3957a444e75f86aa1a8..17e1c66a5730b30d8caaf9a2c424ffaa81b512f5 100644 (file)
@@ -69,6 +69,7 @@
 #include "TObjectTable.h"
 
 // --- AliRoot header files ---
+#include "AliRun.h"
 #include "AliRunDigitizer.h"
 #include "AliRunLoader.h"
 #include "AliEMCALDigit.h"
@@ -78,7 +79,7 @@
 #include "AliEMCALSDigitizer.h"
 #include "AliEMCALGeometry.h"
 #include "AliEMCALTick.h"
-#include "AliEMCALJetMicroDst.h"
+#include "AliEMCALHistoUtilities.h"
 
 ClassImp(AliEMCALDigitizer)
 
@@ -146,6 +147,7 @@ AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd):
 //____________________________________________________________________________ 
   AliEMCALDigitizer::~AliEMCALDigitizer()
 {
+  //dtor
   if (AliRunLoader::GetRunLoader()) {
     AliLoader *emcalLoader=0;
     if ((emcalLoader = AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL")))
@@ -155,6 +157,8 @@ AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd):
     AliDebug(1," no runloader present");
   delete [] fInputFileNames ; 
   delete [] fEventNames ; 
+
+  if(fHists) delete fHists;
 }
 
 //____________________________________________________________________________
@@ -172,18 +176,24 @@ void AliEMCALDigitizer::Digitize(Int_t event)
 
   AliRunLoader *rl = AliRunLoader::GetRunLoader();
   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
-  Int_t ReadEvent = event ; 
+  Int_t readEvent = event ; 
   // fManager is data member from AliDigitizer
   if (fManager) 
-    ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ; 
+    readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ; 
   AliDebug(1,Form("Adding event %d from input stream 0 %s %s", 
-                 ReadEvent, GetTitle(), fEventFolderName.Data())) ; 
-  rl->GetEvent(ReadEvent);
+                 readEvent, GetTitle(), fEventFolderName.Data())) ; 
+  rl->GetEvent(readEvent);
 
   TClonesArray * digits = emcalLoader->Digits() ; 
   digits->Clear() ;
 
-  const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
+  // Load Geometry
+  // const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
+  rl->LoadgAlice(); 
+  AliRun * gAlice = rl->GetAliRun(); 
+  AliEMCAL * emcal  = (AliEMCAL*)gAlice->GetDetector("EMCAL");
+  AliEMCALGeometry * geom = emcal->GetGeometry();
+
   if(isTrd1Geom < 0) { 
     TString ng(geom->GetName());
     isTrd1Geom = 0;
@@ -213,13 +223,19 @@ void AliEMCALDigitizer::Digitize(Int_t event)
   for(i = 1 ; i < fInput ; i++){
     TString tempo(fEventNames[i]) ; 
     tempo += i ;
-    rl = AliRunLoader::Open(fInputFileNames[i], tempo) ; 
+
+    AliRunLoader *  rl2 = AliRunLoader::GetRunLoader(tempo) ; 
+
+    if (rl2==0) 
+      rl2 = AliRunLoader::Open(fInputFileNames[i], tempo) ; 
+
     if (fManager) 
-      ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ; 
-    Info("Digitize", "Adding event %d from input stream %d %s %s", ReadEvent, i, fInputFileNames[i].Data(), tempo.Data()) ; 
-    rl->LoadSDigits();
-    rl->GetEvent(ReadEvent);
-    sdigArray->AddAt(emcalLoader->SDigits(), i) ;
+      readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ; 
+    Info("Digitize", "Adding event %d from input stream %d %s %s", readEvent, i, fInputFileNames[i].Data(), tempo.Data()) ; 
+    rl2->LoadSDigits();
+    rl2->GetEvent(readEvent);
+    AliEMCALLoader *emcalLoader2 = dynamic_cast<AliEMCALLoader*>(rl2->GetDetectorLoader("EMCAL"));
+    sdigArray->AddAt(emcalLoader2->SDigits(), i) ;
   }
   
   //Find the first tower with signal
@@ -341,30 +357,65 @@ void AliEMCALDigitizer::Digitize(Int_t event)
   digits->Expand(ndigits) ;
   
   //Set indexes in list of digits and fill hists.
-  sv::FillH1(fHists, 0, Double_t(ndigits));
+  AliEMCALHistoUtilities::FillH1(fHists, 0, Double_t(ndigits));
   Float_t energy=0., esum=0.;
   for (i = 0 ; i < ndigits ; i++) { 
     digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ; 
     digit->SetIndexInList(i) ; 
     energy = sDigitizer->Calibrate(digit->GetAmp()) ;
     esum += energy;
-    digit->SetAmp(DigitizeEnergy(energy) ) ; // for what ??
-    sv::FillH1(fHists, 2, double(digit->GetAmp()));
-    sv::FillH1(fHists, 3, double(energy));
-    sv::FillH1(fHists, 4, double(digit->GetId()));
+    digit->SetAmp(DigitizeEnergy(energy, digit->GetId()) ) ; // for what ??
+    AliEMCALHistoUtilities::FillH1(fHists, 2, double(digit->GetAmp()));
+    AliEMCALHistoUtilities::FillH1(fHists, 3, double(energy));
+    AliEMCALHistoUtilities::FillH1(fHists, 4, double(digit->GetId()));
   }
-  sv::FillH1(fHists, 1, esum);
+  AliEMCALHistoUtilities::FillH1(fHists, 1, esum);
 }
 
-//____________________________________________________________________________
-
-Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy)
+// //_____________________________________________________________________
+Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t AbsId)
 { 
+  // Returns digitized value of the energy in a cell absId
+  // Loader
+  AliRunLoader *rl = AliRunLoader::GetRunLoader();
+  AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
+    (rl->GetDetectorLoader("EMCAL"));
+  
+  // Load EMCAL Geometry
+  rl->LoadgAlice(); 
+  AliRun * gAlice = rl->GetAliRun(); 
+  AliEMCAL * emcal  = (AliEMCAL*)gAlice->GetDetector("EMCAL");
+  AliEMCALGeometry * geom = emcal->GetGeometry();
+
+  if (geom==0)
+    AliFatal("Did not get geometry from EMCALLoader") ;
+
+  Int_t iSupMod = -1;
+  Int_t nTower  = -1;
+  Int_t nIphi   = -1;
+  Int_t nIeta   = -1;
+  Int_t iphi    = -1;
+  Int_t ieta    = -1;
   Int_t channel = -999; 
+
+  Bool_t bCell = geom->GetCellIndex(AbsId, iSupMod, nTower, nIphi, nIeta) ;
+  if(!bCell)
+    Error("DigitizeEnergy","Wrong cell id number") ;
+  geom->GetCellPhiEtaIndexInSModule(iSupMod,nTower,nIphi, nIeta,iphi,ieta);
+  
+  if(emcalLoader->CalibData()) {
+    fADCpedestalEC = emcalLoader->CalibData()
+      ->GetADCpedestal(iSupMod,ieta,iphi);
+    fADCchannelEC = emcalLoader->CalibData()
+      ->GetADCchannel(iSupMod,ieta,iphi);
+  }
+  
   channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalEC)/fADCchannelEC ))  ;
+  
   if(channel > fNADCEC ) 
     channel =  fNADCEC ; 
   return channel ;
+  
 }
 
 //____________________________________________________________________________
@@ -405,7 +456,7 @@ void AliEMCALDigitizer::Exec(Option_t *option)
 
   rl->LoadSDigits("EMCAL");
   for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
-    //gime->Event(ievent,"S") ; 
+    
     rl->GetEvent(ievent);
 
     Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
@@ -419,8 +470,7 @@ void AliEMCALDigitizer::Exec(Option_t *option)
     //increment the total number of Digits per run 
     fDigitsInRun += emcalLoader->Digits()->GetEntriesFast() ;  
   }
-  //  gime->WriteDigitizer("OVERWRITE");
-
+  
   emcalLoader->CleanDigitizer() ;
 
   if(strstr(option,"tim")){
@@ -485,13 +535,17 @@ Bool_t AliEMCALDigitizer::Init()
   
   //to prevent cleaning of this object while GetEvent is called
   emcalLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
+
+  //PH  Print();
   
   return fInit ;    
 }
 
 //____________________________________________________________________________ 
 void AliEMCALDigitizer::InitParameters()
-{ // Tune parameters - 24-nov-04
+{ 
+  //parameter initialization for digitizer
+  // Tune parameters - 24-nov-04
 
   fMeanPhotonElectron = 3300 ; // electrons per GeV 
   fPinNoise           = 0.004; 
@@ -539,7 +593,6 @@ void AliEMCALDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
     return ; 
   }
   // looking for the file which contains SDigits
-  //AliEMCALGetter * gime = AliEMCALGetter::Instance() ; 
   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
   TString fileName( emcalLoader->GetSDigitsFileName() ) ; 
     if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
@@ -615,7 +668,10 @@ void AliEMCALDigitizer::Print(Option_t*)const
 }
 
 //__________________________________________________________________
-void AliEMCALDigitizer::PrintDigits(Option_t * option){
+void AliEMCALDigitizer::PrintDigits(Option_t * option)
+{
+  //utility method for printing digit information
+
   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
   TClonesArray * digits  = emcalLoader->Digits() ;
   TClonesArray * sdigits = emcalLoader->SDigits() ;
@@ -712,7 +768,10 @@ void AliEMCALDigitizer::Browse(TBrowser* b)
 }
 
 TList *AliEMCALDigitizer::BookControlHists(int var)
-{ // 22-nov-04
+{ 
+  // 22-nov-04
+  // histograms for monitoring digitizer performance
+
   Info("BookControlHists"," started ");
   gROOT->cd();
   const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
@@ -725,12 +784,13 @@ TList *AliEMCALDigitizer::BookControlHists(int var)
     new TH1F("hDigiAbsId","EMCAL absId cells with fAmp > fDigitThreshold ",
     geom->GetNCells(), 0.5, Double_t(geom->GetNCells())+0.5);
   }
-  fHists = sv::MoveHistsToList("EmcalDigiControlHists", kFALSE);
-  fHists = 0;
+
+  fHists = AliEMCALHistoUtilities::MoveHistsToList("EmcalDigiControlHists", kFALSE);
+  fHists = 0; //huh? JLK 03-Mar-2006
   return fHists;
 }
 
 void AliEMCALDigitizer::SaveHists(const char* name, Bool_t kSingleKey, const char* opt)
 {
-  sv::SaveListOfHists(fHists, name, kSingleKey, opt); 
+  AliEMCALHistoUtilities::SaveListOfHists(fHists, name, kSingleKey, opt); 
 }