]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALDigitizer.cxx
effc++ warnings
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigitizer.cxx
index 275170f0dd850bf4a703697d53ee3fe77293ff8d..dfe5ea132878911c5a4827cc8cc0abc906f7d53e 100644 (file)
 #include <TBrowser.h>
 #include <TObjectTable.h>
 #include <TRandom.h>
+#include <cassert>
 
 // --- AliRoot header files ---
 #include "AliLog.h"
 #include "AliRun.h"
 #include "AliRunDigitizer.h"
 #include "AliRunLoader.h"
+#include "AliCDBManager.h"
+#include "AliCDBEntry.h"
 #include "AliEMCALDigit.h"
 #include "AliEMCAL.h"
 #include "AliEMCALLoader.h"
@@ -110,7 +113,7 @@ AliEMCALDigitizer::AliEMCALDigitizer()
     fFirstEvent(0),
     fLastEvent(0),
     fControlHists(0),
-    fHists(0)
+    fHists(0),fCalibData(0x0)
 {
   // ctor
   InitParameters() ; 
@@ -141,7 +144,7 @@ AliEMCALDigitizer::AliEMCALDigitizer(TString alirunFileName, TString eventFolder
     fFirstEvent(0),
     fLastEvent(0),
     fControlHists(0),
-    fHists(0)
+    fHists(0),fCalibData(0x0)
 {
   // ctor
   InitParameters() ; 
@@ -173,7 +176,7 @@ AliEMCALDigitizer::AliEMCALDigitizer(const AliEMCALDigitizer & d)
     fFirstEvent(d.fFirstEvent),
     fLastEvent(d.fLastEvent),
     fControlHists(d.fControlHists),
-    fHists(d.fHists)
+    fHists(d.fHists),fCalibData(d.fCalibData)
 {
   // copyy ctor 
  }
@@ -202,7 +205,7 @@ AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd)
     fFirstEvent(0),
     fLastEvent(0),
     fControlHists(0),
-    fHists(0)
+    fHists(0),fCalibData(0x0)
 {
   // ctor Init() is called by RunDigitizer
   fManager = rd ; 
@@ -252,17 +255,19 @@ void AliEMCALDigitizer::Digitize(Int_t event)
   rl->GetEvent(readEvent);
 
   TClonesArray * digits = emcalLoader->Digits() ; 
-  digits->Clear() ;
+  digits->Delete() ;  
 
   // Load Geometry
-  // const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
-  rl->LoadgAlice(); 
-  AliRun * gAlice = rl->GetAliRun(); 
-  AliEMCAL * emcal  = (AliEMCAL*)gAlice->GetDetector("EMCAL");
-  AliEMCALGeometry * geom = emcal->GetGeometry();
+  AliEMCALGeometry *geom = 0;
+  if (rl->GetAliRun()) {
+    AliEMCAL * emcal  = (AliEMCAL*)rl->GetAliRun()->GetDetector("EMCAL");
+    geom = emcal->GetGeometry();
+  }
+  else 
+    AliFatal("Could not get AliRun from runLoader");
 
   if(isTrd1Geom < 0) { 
-    AliInfo(Form(" get Geometry %s : %s ", geom->GetName(),geom->GetTitle()));
+    AliDebug(1, Form(" get Geometry %s : %s ", geom->GetName(),geom->GetTitle()));
     TString ng(geom->GetName());
     isTrd1Geom = 0;
     if(ng.Contains("SHISH") &&  ng.Contains("TRD1")) isTrd1Geom = 1;
@@ -422,7 +427,6 @@ void AliEMCALDigitizer::Digitize(Int_t event)
   digits->Compress() ;  
   
   Int_t ndigits = digits->GetEntriesFast() ; 
-  digits->Expand(ndigits) ;
   
   //Set indexes in list of digits and fill hists.
   AliEMCALHistoUtilities::FillH1(fHists, 0, Double_t(ndigits));
@@ -449,16 +453,9 @@ void AliEMCALDigitizer::Digitize(Int_t event)
 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();
+
+  // Load Geometry
+  const AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
 
   if (geom==0)
     AliFatal("Did not get geometry from EMCALLoader");
@@ -476,11 +473,9 @@ Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t AbsId)
     Error("DigitizeEnergy","Wrong cell id number : AbsId %i ", AbsId) ;
   geom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
   
-  if(emcalLoader->CalibData()) {
-    fADCpedestalEC = emcalLoader->CalibData()
-      ->GetADCpedestal(iSupMod,ieta,iphi);
-    fADCchannelEC = emcalLoader->CalibData()
-      ->GetADCchannel(iSupMod,ieta,iphi);
+  if(fCalibData) {
+    fADCpedestalEC = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
+    fADCchannelEC = fCalibData->GetADCchannel(iSupMod,ieta,iphi);
   }
   
   channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalEC)/fADCchannelEC ))  ;
@@ -520,8 +515,9 @@ void AliEMCALDigitizer::Exec(Option_t *option)
   // Post Digitizer to the white board
   emcalLoader->PostDigitizer(this) ;
   
-  if (fLastEvent == -1) 
+  if (fLastEvent == -1)  {
     fLastEvent = rl->GetNumberOfEvents() - 1 ;
+  }
   else if (fManager) 
     fLastEvent = fFirstEvent ; // what is this ??
 
@@ -611,26 +607,29 @@ Bool_t AliEMCALDigitizer::Init()
   emcalLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
 
   //PH  Print();
-  
+  //Calibration instance
+  fCalibData = emcalLoader->CalibData();
   return fInit ;    
 }
 
 //____________________________________________________________________________ 
 void AliEMCALDigitizer::InitParameters()
 { 
-  //parameter initialization for digitizer
-  // Tune parameters - 24-nov-04
+  // Parameter initialization for digitizer
+  // Tune parameters - 24-nov-04; Apr 29, 2007
 
-  fMeanPhotonElectron = 3300 ; // electrons per GeV 
-  fPinNoise           = 0.004; 
+  fMeanPhotonElectron = 3300 // electrons per GeV 
+  fPinNoise           = 0.010; // pin noise in GEV from analysis test beam data 
   if (fPinNoise == 0. ) 
     Warning("InitParameters", "No noise added\n") ; 
   fDigitThreshold     = fPinNoise * 3; // 3 * sigma
   fTimeResolution     = 0.3e-9 ; // 300 psc
   fTimeSignalLength   = 1.0e-9 ;
 
-  fADCchannelEC    = 0.00305; // 200./65536 - width of one ADC channel in GeV
-  fADCpedestalEC   = 0.009 ;  // GeV
+  // These defaults are normally not used. 
+  // Values are read from calibration database instead
+  fADCchannelEC    = 0.0153; // Update 24 Apr 2007: 250./16/1024 - width of one ADC channel in GeV
+  fADCpedestalEC   = 0.0 ;  // GeV
   fNADCEC          = (Int_t) TMath::Power(2,16) ;  // number of channels in Tower ADC - 65536
 
   fTimeThreshold      = 0.001*10000000 ; // Means 1 MeV in terms of SDigits amplitude ??
@@ -676,6 +675,7 @@ void AliEMCALDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
       return ;
     }
     // need to increase the arrays
+    // MvL: This code only works when fInput == 1, I think.
     TString tempo = fInputFileNames[fInput-1] ; 
     delete [] fInputFileNames ; 
     fInputFileNames = new TString[fInput+1] ; 
@@ -821,8 +821,10 @@ void AliEMCALDigitizer::WriteDigits()
   // -- create Digits branch
   Int_t bufferSize = 32000 ;    
   TBranch * digitsBranch = 0;
-  if ((digitsBranch = treeD->GetBranch("EMCAL")))
+  if ((digitsBranch = treeD->GetBranch("EMCAL"))) {
     digitsBranch->SetAddress(&digits);
+    AliWarning("Digits Branch already exists. Not all digits will be visible");
+  }
   else
     treeD->Branch("EMCAL","TClonesArray",&digits,bufferSize);
   //digitsBranch->SetTitle(fEventFolderName);