]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/TenderSupplies/AliEMCALTenderSupply.cxx
Updates Salvatore Aiola
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliEMCALTenderSupply.cxx
index ddcd5b8e886aebfdce30e9fb5e58d303ef7b561d..9857e1324ba733bd2a3ca5e1fc68128461ef1a7c 100644 (file)
@@ -13,7 +13,6 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
 //  EMCAL tender, apply corrections to EMCAL clusters and do track matching. //
@@ -59,7 +58,7 @@ AliTenderSupply()
 ,fTask(0)
 ,fRun(0)
 ,fEMCALGeo(0x0)
-,fEMCALGeoName("EMCAL_COMPLETEV1")
+,fEMCALGeoName("")
 ,fEMCALRecoUtils(0)
 ,fConfigName("")
 ,fDebugLevel(0)
@@ -81,6 +80,7 @@ AliTenderSupply()
 ,fRecalShowerShape(kFALSE)
 ,fInputTree(0)
 ,fInputFile(0)
+,fGetPassFromFileName(kTRUE)
 ,fFilepass(0) 
 ,fMass(-1)
 ,fStep(-1)
@@ -104,10 +104,11 @@ AliTenderSupply()
 ,fExoticCellFraction(-1)
 ,fExoticCellDiffTime(-1)
 ,fExoticCellMinAmplitude(-1)
+,fSetCellMCLabelFromCluster(kFALSE)
 {
   // Default constructor.
-  for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
-  fEMCALRecoUtils  = new AliEMCALRecoUtils;
+
+  for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
 }
 
 //_____________________________________________________
@@ -116,7 +117,7 @@ AliTenderSupply(name,tender)
 ,fTask(0)
 ,fRun(0)
 ,fEMCALGeo(0x0)
-,fEMCALGeoName("EMCAL_COMPLETEV1")
+,fEMCALGeoName("")
 ,fEMCALRecoUtils(0)
 ,fConfigName("")
 ,fDebugLevel(0)
@@ -138,7 +139,8 @@ AliTenderSupply(name,tender)
 ,fRecalShowerShape(kFALSE)
 ,fInputTree(0)  
 ,fInputFile(0)
-,fFilepass(0) 
+,fGetPassFromFileName(kTRUE)
+,fFilepass("") 
 ,fMass(-1)
 ,fStep(-1)
 ,fCutEtaPhiSum(kTRUE)
@@ -161,11 +163,11 @@ AliTenderSupply(name,tender)
 ,fExoticCellFraction(-1)
 ,fExoticCellDiffTime(-1)
 ,fExoticCellMinAmplitude(-1)
+,fSetCellMCLabelFromCluster(kFALSE)
 {
   // Named constructor
   
-  for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
-  fEMCALRecoUtils  = new AliEMCALRecoUtils;
+  for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
 }
 
 //_____________________________________________________
@@ -174,7 +176,7 @@ AliTenderSupply(name)
 ,fTask(task)
 ,fRun(0)
 ,fEMCALGeo(0x0)
-,fEMCALGeoName("EMCAL_COMPLETEV1")
+,fEMCALGeoName("")
 ,fEMCALRecoUtils(0)
 ,fConfigName("")
 ,fDebugLevel(0)
@@ -196,7 +198,8 @@ AliTenderSupply(name)
 ,fRecalShowerShape(kFALSE)
 ,fInputTree(0)  
 ,fInputFile(0)
-,fFilepass(0) 
+,fGetPassFromFileName(kTRUE)
+,fFilepass("") 
 ,fMass(-1)
 ,fStep(-1)
 ,fCutEtaPhiSum(kTRUE)
@@ -219,11 +222,11 @@ AliTenderSupply(name)
 ,fExoticCellFraction(-1)
 ,fExoticCellDiffTime(-1)
 ,fExoticCellMinAmplitude(-1)
+,fSetCellMCLabelFromCluster(kFALSE)
 {
-  // Named constructor
+  // Named constructor.
   
-  for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
-  fEMCALRecoUtils  = new AliEMCALRecoUtils;
+  for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
 }
 
 //_____________________________________________________
@@ -231,22 +234,44 @@ AliEMCALTenderSupply::~AliEMCALTenderSupply()
 {
   //Destructor
   
-  delete fEMCALRecoUtils;
-  delete fRecParam;
-  delete fUnfolder;
-  if (!fClusterizer) {
-    fDigitsArr->Clear("C");
-    delete fDigitsArr; 
-  } else {
-    delete fClusterizer;
-    fDigitsArr = 0;
+  if (!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) 
+  {
+    delete fEMCALRecoUtils;
+    delete fRecParam;
+    delete fUnfolder;
+    if (!fClusterizer) 
+    {
+      fDigitsArr->Clear("C");
+      delete fDigitsArr; 
+    } else 
+    {
+      delete fClusterizer;
+      fDigitsArr = 0;
+    }
   }
 }
 
+//_____________________________________________________
+void AliEMCALTenderSupply::SetDefaults()
+{
+  // Set default settings.
+
+  SwitchOnBadCellRemove();
+  SwitchOnExoticCellRemove();
+  SwitchOnCalibrateEnergy();
+  SwitchOnCalibrateTime();
+  SwitchOnUpdateCell();
+  SwitchOnReclustering();
+  SwitchOnClusterBadChannelCheck();
+  SwitchOnClusterExoticChannelCheck();
+  SwitchOnTrackMatch();
+}
+
 //_____________________________________________________
 Bool_t AliEMCALTenderSupply::RunChanged() const
 {
-  // Get run number
+  // Get run number.
+
   return (fTender && fTender->RunChanged()) || (fTask && fRun != fTask->InputEvent()->GetRunNumber()); 
 }
 
@@ -298,7 +323,7 @@ void AliEMCALTenderSupply::Init()
     fExoticCellDiffTime     = tender->fExoticCellDiffTime;
     fExoticCellMinAmplitude = tender->fExoticCellMinAmplitude;
 
-    for(Int_t i = 0; i < 10; i++) 
+    for(Int_t i = 0; i < 12; i++) 
       fEMCALMatrix[i] = tender->fEMCALMatrix[i] ;
   }
   
@@ -341,13 +366,19 @@ void AliEMCALTenderSupply::Init()
     AliInfo( "=============================================================" ); 
   }
 
-  // Init geometry  
-  fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
+  // init reco utils
+  
+  if(!fEMCALRecoUtils)
+    fEMCALRecoUtils  = new AliEMCALRecoUtils;
+
+  // init geometry if requested
+  if (fEMCALGeoName.Length()>0) 
+    fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
 
   // digits array
   fDigitsArr       = new TClonesArray("AliEMCALDigit",1000);
 
-  // Initialising non-linearity parameters
+  // initialising non-linearity parameters
   if( fNonLinearThreshold != -1 )
     fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
   if( fNonLinearFunc != -1 )
@@ -370,7 +401,7 @@ void AliEMCALTenderSupply::Init()
   if( fExoticCellMinAmplitude != -1 )
     fEMCALRecoUtils->SetExoticCellMinAmplitudeCut( fExoticCellMinAmplitude );
 
-  // Setting track matching parameters ... mass, step size and residual cut
+  // setting track matching parameters ... mass, step size and residual cut
   if( fMass != -1 )
     fEMCALRecoUtils->SetMass(fMass);
   if( fStep != -1 )
@@ -393,7 +424,7 @@ void AliEMCALTenderSupply::Init()
 //_____________________________________________________
 AliVEvent* AliEMCALTenderSupply::GetEvent()
 {
-  // return the event pointer
+  // Return the event pointer.
   
   if (fTender) {
     return fTender->GetEvent();
@@ -403,14 +434,13 @@ AliVEvent* AliEMCALTenderSupply::GetEvent()
   }
   
   return 0;
-  
 }
 
 //_____________________________________________________
 void AliEMCALTenderSupply::ProcessEvent()
 {
   // Event loop.
-
+  
   AliVEvent *event = GetEvent();
   
   if (!event) {
@@ -418,15 +448,31 @@ void AliEMCALTenderSupply::ProcessEvent()
     return;
   }
   
 // Initialising parameters once per run number
+ // Initialising parameters once per run number
   if (RunChanged()) { 
 
+    AliWarning( "Run changed, initializing parameters" );
     fRun = event->GetRunNumber();
 
-    AliWarning( "Run changed, initializing parameters" );
+    // init geometry if not already done
+    if (fEMCALGeoName.Length()==0) {
+      fEMCALGeoName = "EMCAL_FIRSTYEARV1";
+      if (fRun>139517) {
+        fEMCALGeoName = "EMCAL_COMPLETEV1";
+      } 
+      if (fRun>170593) {
+        fEMCALGeoName = "EMCAL_COMPLETE12SMV1";
+      }
+      fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName);
+      if (!fEMCALGeo) {
+        AliFatal(Form("Can not create geometry: %s", fEMCALGeoName.Data()));
+        return;
+      }
+    } 
 
     // get pass
-    GetPass();
+    if (fGetPassFromFileName)
+      GetPass();
 
     // define what recalib parameters are needed for various switches
     // this is based on implementation in AliEMCALRecoUtils
@@ -460,7 +506,8 @@ void AliEMCALTenderSupply::ProcessEvent()
     }
 
     // init recalibration factors
-    if( needRecalib ) { 
+    if( needRecalib ) 
+    { 
       Int_t fInitRecalib = InitRecalib();
       if (fInitRecalib==0)
         AliError("InitRecalib returned false, returning");
@@ -468,9 +515,19 @@ void AliEMCALTenderSupply::ProcessEvent()
         AliWarning("InitRecalib OK");
       if (fInitRecalib>1)
         AliWarning(Form("No recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
-        fReCalibCluster = kFALSE;
+      
+      Int_t fInitRunDepRecalib = InitRunDepRecalib();
+      if (fInitRunDepRecalib==0)
+        AliError("InitrunDepRecalib returned false, returning");
+      if (fInitRunDepRecalib==1)
+        AliWarning("InitRecalib OK");
+      if (fInitRunDepRecalib>1)
+        AliWarning(Form("No Temperature recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
+      
     }
     
+    
+    
     // init time calibration
     if( needTimecalib ){
       Int_t initTC = InitTimeCalibration();
@@ -575,7 +632,7 @@ void AliEMCALTenderSupply::ProcessEvent()
   if( fCalibrateEnergy || fCalibrateTime || fBadCellRemove )
     fEMCALRecoUtils->ResetCellsCalibrated();
   
 // CELL RECALIBRATION -------------------------------------------------------
+ // CELL RECALIBRATION -------------------------------------------------------
   // cell objects will be updated
   // the cell calibrations are also processed locally any time those are needed
   // in case that the cell objects are not to be updated here for later use
@@ -603,7 +660,7 @@ void AliEMCALTenderSupply::ProcessEvent()
     Clusterize();
     UpdateClusters();
   }
-  
+
   // Store good clusters
   TClonesArray *clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
   if (!clusArr) 
@@ -688,12 +745,17 @@ void AliEMCALTenderSupply::ProcessEvent()
     // CLUSTER ENERGY ---------------------------------------------
     // does process local cell recalibration energy and time without replacing
     // the global cell values, in case of no cell recalib done yet
-    if( fReCalibCluster ) 
+    if( fReCalibCluster ) {
       fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, clust, cells);
-
+      if (clust->E() < 1e-9) {
+        delete clusArr->RemoveAt(icluster);
+        continue;
+      }
+    }
+    
     // CLUSTER POSITION -------------------------------------------
     // does process local cell energy recalibration, if enabled and cells
-    // not calibratied yet
+    // not calibrated yet
     if( fRecalClusPos ) 
       fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, cells, clust);
     
@@ -741,6 +803,7 @@ void AliEMCALTenderSupply::ProcessEvent()
 Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
 {
   // Initialising misalignment matrices
+
   AliVEvent *event = GetEvent();
   
   if (!event) 
@@ -771,42 +834,42 @@ Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
   Int_t runGM = event->GetRunNumber();
   TObjArray *mobj = 0;
 
- if(fMisalignSurvey == kdefault)
- { //take default alignment corresponding to run no
 if(fMisalignSurvey == kdefault)
 { //take default alignment corresponding to run no
     AliOADBContainer emcalgeoCont(Form("emcal"));
     emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
     mobj=(TObjArray*)emcalgeoCont.GetObject(runGM,"EmcalMatrices");
- }
-
- if(fMisalignSurvey == kSurveybyS)
- { //take alignment at sector level
-  if (runGM <= 140000) { //2010 data
-    AliOADBContainer emcalgeoCont(Form("emcal2010"));
-    emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
-    mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey10");
-    
-  } else if (runGM>140000)
-  { // 2011 LHC11a pass1 data
-    AliOADBContainer emcalgeoCont(Form("emcal2011"));
-    emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
-    mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");      
   }
- }
+  
+  if(fMisalignSurvey == kSurveybyS)
+  { //take alignment at sector level
+    if (runGM <= 140000) { //2010 data
+      AliOADBContainer emcalgeoCont(Form("emcal2010"));
+      emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
+      mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey10");
+    } 
+    else if (runGM>140000)
+    { // 2011 LHC11a pass1 data
+      AliOADBContainer emcalgeoCont(Form("emcal2011"));
+      emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
+      mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");      
+    }
+  }
 
- if(fMisalignSurvey == kSurveybyM)
- { //take alignment at module level
-  if (runGM <= 140000) { //2010 data
-    AliOADBContainer emcalgeoCont(Form("emcal2010"));
-    emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
-    mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey10");
-    
-  } else if (runGM>140000) 
-  { // 2011 LHC11a pass1 data
-    AliOADBContainer emcalgeoCont(Form("emcal2011"));
-    emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
-    mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byM");      
+  if(fMisalignSurvey == kSurveybyM)
+  { //take alignment at module level
+    if (runGM <= 140000) { //2010 data
+      AliOADBContainer emcalgeoCont(Form("emcal2010"));
+      emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
+      mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey10");
+    } 
+    else if (runGM>140000) 
+    { // 2011 LHC11a pass1 data
+      AliOADBContainer emcalgeoCont(Form("emcal2011"));
+      emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
+      mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byM");      
+    }
   }
- }
 
   if(!mobj)
   {
@@ -814,12 +877,12 @@ Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
     return kFALSE;
   }
   
- for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
- {
-   fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
-   fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod); 
-   fEMCALMatrix[mod]->Print();
- }
 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
 {
+    fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
+    fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod); 
+    fEMCALMatrix[mod]->Print();
 }
   
   return kTRUE;
 }
@@ -936,21 +999,21 @@ Int_t AliEMCALTenderSupply::InitRecalib()
     
     contRF->InitFromFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"AliEMCALRecalib");
   }
-    else
-    { // Else choose the one in the $ALICE_ROOT directory
-      if (fDebugLevel>0)  AliInfo("Loading Recalib OADB from $ALICE_ROOT/OADB/EMCAL");
-      
-      TFile *fRecalib= new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root","read");
-      if (!fRecalib || fRecalib->IsZombie()) 
-      {
-        AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root was not found");
-        return 0;
-      }
-      
-      if (fRecalib) delete fRecalib;
-      
-      contRF->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root","AliEMCALRecalib");     
+  else
+  { // Else choose the one in the $ALICE_ROOT directory
+    if (fDebugLevel>0)  AliInfo("Loading Recalib OADB from $ALICE_ROOT/OADB/EMCAL");
+    
+    TFile *fRecalib= new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root","read");
+    if (!fRecalib || fRecalib->IsZombie()) 
+    {
+      AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root was not found");
+      return 0;
     }
+    
+    if (fRecalib) delete fRecalib;
+      
+    contRF->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root","AliEMCALRecalib");     
+  }
 
   TObjArray *recal=(TObjArray*)contRF->GetObject(runRC);
   if (!recal)
@@ -993,6 +1056,106 @@ Int_t AliEMCALTenderSupply::InitRecalib()
   return 1;
 }
 
+//_____________________________________________________
+Int_t AliEMCALTenderSupply::InitRunDepRecalib()
+{
+  // Initialising recalibration factors.
+  
+  AliVEvent *event = GetEvent();
+  
+  if (!event) 
+    return 0;
+  
+  if (fDebugLevel>0) 
+    AliInfo("Initialising recalibration factors");
+  
+  // init default maps first
+  if( !fEMCALRecoUtils->GetEMCALRecalibrationFactorsArray() )
+    fEMCALRecoUtils->InitEMCALRecalibrationFactors() ;
+  
+  Int_t runRC = event->GetRunNumber();
+  
+  AliOADBContainer *contRF=new AliOADBContainer("");
+  if (fBasePath!="") 
+  { //if fBasePath specified in the ->SetBasePath()
+    if (fDebugLevel>0)  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
+    
+    TFile *fRunDepRecalib= new TFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"read");
+    if (!fRunDepRecalib || fRunDepRecalib->IsZombie()) 
+    {
+      AliFatal(Form("EMCALTemperatureCorrCalib.root not found in %s",fBasePath.Data()));
+      return 0;
+    }
+    
+    if (fRunDepRecalib) delete fRunDepRecalib;
+    
+    contRF->InitFromFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"AliEMCALRunDepTempCalibCorrections");
+  }
+  else
+  { // Else choose the one in the $ALICE_ROOT directory
+    if (fDebugLevel>0)  AliInfo("Loading Recalib OADB from $ALICE_ROOT/OADB/EMCAL");
+    
+    TFile *fRunDepRecalib= new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALTemperatureCorrCalib.root","read");
+    if (!fRunDepRecalib || fRunDepRecalib->IsZombie()) 
+    {
+      AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALTemperatureCorrCalib.root was not found");
+      return 0;
+    }
+    
+    if (fRunDepRecalib) delete fRunDepRecalib;
+    
+    contRF->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALTemperatureCorrCalib.root","AliEMCALRunDepTempCalibCorrections");     
+  }
+  
+  TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
+  if (!rundeprecal)
+  {
+    AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runRC));
+    // let's get the closest runnumber instead then..
+    Int_t lower = 0;
+    Int_t ic = 0;
+    Int_t maxEntry = contRF->GetNumberOfEntries();
+
+    while ( (ic < maxEntry) && (contRF->UpperLimit(ic) < runRC) ) {
+      lower = ic;
+      ic++; 
+    }
+
+    Int_t closest = lower;
+    if ( (ic<maxEntry) && 
+        (contRF->LowerLimit(ic)-runRC) < (runRC - contRF->UpperLimit(lower)) ) {
+        closest = ic;
+    }
+
+    AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRF->LowerLimit(closest)));
+    rundeprecal = (TH1S*) contRF->GetObjectByIndex(closest);  
+  } 
+  
+  if (fDebugLevel>0) rundeprecal->Print();
+  
+  Int_t nSM = fEMCALGeo->GetEMCGeometry()->GetNumberOfSuperModules();
+  
+  for (Int_t ism=0; ism<nSM; ++ism) 
+  {        
+    for (Int_t icol=0; icol<48; ++icol) 
+    {        
+      for (Int_t irow=0; irow<24; ++irow) 
+      {
+        Float_t factor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
+        
+        Int_t absID = fEMCALGeo->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
+        factor *= rundeprecal->GetBinContent(absID) / 10000. ; // correction dependent on T
+        //printf("\t ism %d, icol %d, irow %d,absID %d, corrA %2.3f, corrB %2.3f, corrAB %2.3f\n",ism, icol, irow, absID, 
+        //      GetEMCALChannelRecalibrationFactor(ism,icol,irow) , rundeprecal->GetBinContent(absID) / 10000., factor);
+        fEMCALRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
+      } // columns
+    } // rows 
+  } // SM loop
+  
+  return 1;
+}
+
+
 //_____________________________________________________
 Int_t AliEMCALTenderSupply::InitTimeCalibration()
 {
@@ -1006,7 +1169,7 @@ Int_t AliEMCALTenderSupply::InitTimeCalibration()
     AliInfo("Initialising time calibration map");
   
   // init default maps first
-  if( !fEMCALRecoUtils->GetEMCALTimeRecalibrationFactorsArray() )
+  if ( !fEMCALRecoUtils->GetEMCALTimeRecalibrationFactorsArray() )
     fEMCALRecoUtils->InitEMCALTimeRecalibrationFactors() ;
 
   Int_t runBC = event->GetRunNumber();
@@ -1099,19 +1262,23 @@ void AliEMCALTenderSupply::UpdateCells()
   // just like with bad cell rejection in reco utils (inside RecalibrateCells)
   if( fRejectExoticCells )
   {
-    Int_t    absId  =-1;
+    Short_t  absId  =-1;
+    Double_t ecell = 0;
+    Double_t tcell = 0;
+    Double_t efrac = 0;
+    Short_t  mclabel = -1;
     Bool_t   isExot = kFALSE;
   
     // loop through cells
     Int_t nEMcell  = cells->GetNumberOfCells() ;  
     for (Int_t iCell = 0; iCell < nEMcell; iCell++) 
     { 
-      absId  = cells->GetCellNumber(iCell);
+      cells->GetCell( iCell, absId, ecell, tcell, mclabel, efrac );
     
       isExot = fEMCALRecoUtils->IsExoticCell( absId, cells, bunchCrossNo ); 
       // zero if exotic
       if( isExot )
-        cells->SetCell( iCell, absId, 0.0, 0.0 );
+        cells->SetCell( iCell, absId, 0.0, -1.0, mclabel, efrac );
     } // cell loop
   } // reject exotic cells
 
@@ -1121,9 +1288,8 @@ void AliEMCALTenderSupply::UpdateCells()
 //_____________________________________________________
 TString AliEMCALTenderSupply::GetBeamType()
 {
-  
   // Get beam type : pp-AA-pA
-  // ESDs have it directly, AODs we hardcode it
+  // ESDs have it directly, AODs get it from hardcoded run number ranges
   
   AliVEvent *event = GetEvent();
 
@@ -1134,22 +1300,23 @@ TString AliEMCALTenderSupply::GetBeamType()
 
   TString beamType;
 
-  if (event->InheritsFrom("AliESDEvent")) {
-    AliESDEvent *esd = dynamic_cast<AliESDEvent*>(event);
+  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(event);
+  if (esd) {
     const AliESDRun *run = esd->GetESDRun();
     beamType = run->GetBeamType();
   }
-  else if (event->InheritsFrom("AliAODEvent")) {
+  else
+  {
     Int_t runNumber = event->GetRunNumber();
     if ((runNumber >= 136851 && runNumber <= 139517)  // LHC10h
-       || (runNumber >= 166529 && runNumber <= 170593))  // LHC11h
-      {
-       beamType = "A-A";
-      }
+  || (runNumber >= 166529 && runNumber <= 170593))  // LHC11h
+    {
+      beamType = "A-A";
+    }
     else 
-      {
-       beamType = "p-p";
-      }
+    {
+      beamType = "p-p";
+    }
   }
 
   return beamType;    
@@ -1158,7 +1325,8 @@ TString AliEMCALTenderSupply::GetBeamType()
 //_____________________________________________________
 Int_t AliEMCALTenderSupply::InitRecParam()
 {
-  // exit if reco params exist (probably shipped by the user already)
+  // Init reco params if not yet exist (probably shipped by the user already)
+
   if( fRecParam != 0 )
     return 2;
 
@@ -1253,8 +1421,34 @@ void AliEMCALTenderSupply::FillDigitsArray()
   
   AliVEvent *event = GetEvent();
 
 if (!event)
+ if (!event)
     return;
+    
+  // In case of MC productions done before aliroot tag v5-02-Rev09
+  // assing the cluster label to all the cells belonging to this cluster
+  // very rough
+  Int_t cellLabels[12672];
+  if(fSetCellMCLabelFromCluster)
+  {
+    for (Int_t i = 0; i < 12672; i++) cellLabels[i] = 0;
+    
+    Int_t nClusters = event->GetNumberOfCaloClusters();
+    for (Int_t i = 0; i < nClusters; i++)
+    {
+      AliVCluster *clus =  event->GetCaloCluster(i);
+      
+      if(!clus) continue;
+      
+      if(!clus->IsEMCAL()) continue ;
+      
+      Int_t      label = clus->GetLabel();
+      UShort_t * index = clus->GetCellsAbsId() ;
+      
+      for(Int_t icell=0; icell < clus->GetNCells(); icell++ )
+        cellLabels[index[icell]] = label;
+      
+    }// cluster loop
+  }
   
   fDigitsArr->Clear("C");
   AliVCaloCells *cells = event->GetEMCALCells();
@@ -1267,21 +1461,19 @@ void AliEMCALTenderSupply::FillDigitsArray()
     if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime, mcLabel, efrac) != kTRUE)
       break;
 
-    // Do not add if already too low (some cells set to 0 if bad channels)
-    if (cellAmplitude < fRecParam->GetMinECut() ) 
+    // Do not add if energy already too low (some cells set to 0 if bad channels)
+    if (cellAmplitude < fRecParam->GetMinECut())
       continue;
 
     // If requested, do not include exotic cells
    if (fEMCALRecoUtils->IsExoticCell(cellNumber,cells,event->GetBunchCrossNumber())) 
       continue;
-        
-    AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
-    digit->SetId(cellNumber);
-    digit->SetTime(cellTime);
-    digit->SetTimeR(cellTime);
-    digit->SetIndexInList(idigit);
-    digit->SetType(AliEMCALDigit::kHG);
-    digit->SetAmplitude(cellAmplitude);
+    
+    if(fSetCellMCLabelFromCluster) mcLabel = cellLabels[cellNumber];
+    
+    new((*fDigitsArr)[idigit]) AliEMCALDigit(mcLabel, mcLabel, cellNumber,
+                                             (Float_t)cellAmplitude, (Float_t)cellTime,
+                                             AliEMCALDigit::kHG,idigit, 0, 0, 1);
     idigit++;
   }
 }
@@ -1316,7 +1508,7 @@ void AliEMCALTenderSupply::UpdateClusters()
   Int_t nents = clus->GetEntriesFast();
   for (Int_t i=0; i < nents; ++i) 
   {
-    AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->At(i));
+    AliVCluster *c = dynamic_cast<AliVCluster*>(clus->At(i));
     if (!c)
       continue;
     if (c->IsEMCAL())
@@ -1326,13 +1518,12 @@ void AliEMCALTenderSupply::UpdateClusters()
   clus->Compress();
   
   RecPoints2Clusters(clus);
-  
 }
 
 //_____________________________________________________
 void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
 {
-  // Convert AliEMCALRecoPoints to AliESDCaloClusters.
+  // Convert AliEMCALRecoPoints to AliESDCaloClusters/AliAODCaloClusters.
   // Cluster energy, global position, cells and their amplitude fractions are restored.
   
   AliVEvent *event = GetEvent();
@@ -1373,7 +1564,7 @@ void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
     Float_t g[3];
     gpos.GetXYZ(g);
     
-    AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->New(nout++));
+    AliVCluster *c = static_cast<AliVCluster*>(clus->New(nout++));
     c->SetID(nout-1); 
     c->SetType(AliVCluster::kEMCALClusterv1);
     c->SetE(recpoint->GetEnergy());
@@ -1388,16 +1579,34 @@ void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
     recpoint->GetElipsAxis(elipAxis);
     c->SetM02(elipAxis[0]*elipAxis[0]) ;
     c->SetM20(elipAxis[1]*elipAxis[1]) ;
-    AliESDCaloCluster *cesd = static_cast<AliESDCaloCluster*>(c);
-    cesd->SetCellsAbsId(absIds);
-    cesd->SetCellsAmplitudeFraction(ratios);
+    c->SetCellsAbsId(absIds);
+    c->SetCellsAmplitudeFraction(ratios);
+
+    //MC
+    AliESDCaloCluster *esdClus = dynamic_cast<AliESDCaloCluster*>(c);
+    if (esdClus) {
+      Int_t  parentMult = 0;
+      Int_t *parentList = recpoint->GetParents(parentMult);
+      if (parentMult > 0) {
+       TArrayI parents(parentMult, parentList);
+       esdClus->AddLabels(parents); 
+      }
+    }
+    else {
+      AliAODCaloCluster *aodClus = dynamic_cast<AliAODCaloCluster*>(c);
+      if (aodClus) {
+       Int_t  parentMult = 0;
+       Int_t *parentList = recpoint->GetParents(parentMult);
+       aodClus->SetLabel(parentList, parentMult); 
+      }
+    }
   }
 }
 
 //_____________________________________________________
 void AliEMCALTenderSupply::GetPass()
 {
-  // Get passx from filename.
+  // Get passx from filename
   
   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
   fInputTree = mgr->GetTree();
@@ -1418,6 +1627,7 @@ void AliEMCALTenderSupply::GetPass()
   if      (fname.Contains("pass1")) fFilepass = TString("pass1");
   else if (fname.Contains("pass2")) fFilepass = TString("pass2");
   else if (fname.Contains("pass3")) fFilepass = TString("pass3");
+  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
   else 
   {
     AliError(Form("Pass number string not found: %s", fname.Data()));