]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/TenderSupplies/AliEMCALTenderSupply.cxx
Merge branch 'flatdev' of https://git.cern.ch/reps/AliRoot into flatdev
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliEMCALTenderSupply.cxx
index 5bd83bf8f57d20cf38c31db1d1af308ae6ee4c16..4c4d6143e2534d7e3db0a6e049f63921801677cc 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <TROOT.h>
+#include <TClonesArray.h>
 #include <TFile.h>
-#include <TTree.h>
+#include <TGeoGlobalMagField.h>
 #include <TInterpreter.h>
 #include <TObjArray.h>
-#include <TClonesArray.h>
-#include <TGeoGlobalMagField.h>
+#include <TROOT.h>
+#include <TTree.h>
+#include "AliAODEvent.h"
+#include "AliAODMCParticle.h"
+#include "AliAnalysisManager.h"
 #include "AliEMCALAfterBurnerUF.h"
 #include "AliEMCALClusterizer.h"
 #include "AliEMCALClusterizerNxN.h"
 #include "AliEMCALRecParam.h"
 #include "AliEMCALRecPoint.h"
 #include "AliEMCALRecoUtils.h"
-#include "AliEMCALTenderSupply.h"
 #include "AliESDCaloCluster.h"
-#include "AliMagF.h"
-#include "AliOADBContainer.h"
-#include "AliAODEvent.h"
-#include "AliAnalysisManager.h"
 #include "AliESDEvent.h"
 #include "AliLog.h"
+#include "AliMagF.h"
+#include "AliOADBContainer.h"
 #include "AliTender.h"
+#include "AliEMCALTenderSupply.h"
 
 ClassImp(AliEMCALTenderSupply)
 
 AliEMCALTenderSupply::AliEMCALTenderSupply() :
-AliTenderSupply()
-,fTask(0)
-,fRun(0)
-,fEMCALGeo(0x0)
-,fEMCALGeoName("")
-,fEMCALRecoUtils(0)
-,fConfigName("")
-,fDebugLevel(0)
-,fNonLinearFunc(-1) 
-,fNonLinearThreshold(-1)
-,fReCalibCluster(kFALSE)
-,fUpdateCell(kFALSE)  
-,fCalibrateEnergy(kFALSE)
-,fCalibrateTime(kFALSE)
-,fDoNonLinearity(kFALSE)
-,fBadCellRemove(kFALSE)
-,fRejectExoticCells(kFALSE)
-,fRejectExoticClusters(kFALSE)
-,fClusterBadChannelCheck(kFALSE)
-,fRecalClusPos(kFALSE)
-,fFiducial(kFALSE) 
-,fNCellsFromEMCALBorder(-1)
-,fRecalDistToBadChannels(kFALSE)
-,fRecalShowerShape(kFALSE)
-,fInputTree(0)
-,fInputFile(0)
-,fFilepass(0) 
-,fMass(-1)
-,fStep(-1)
-,fCutEtaPhiSum(kTRUE)
-,fCutEtaPhiSeparate(kFALSE)
-,fRcut(-1)
-,fEtacut(-1)
-,fPhicut(-1)
-,fBasePath("")
-,fReClusterize(kFALSE)
-,fClusterizer(0)
-,fGeomMatrixSet(kFALSE)
-,fLoadGeomMatrices(kFALSE)
-,fRecParam(0x0)
-,fDoTrackMatch(kFALSE)
-,fDoUpdateOnly(kFALSE)
-,fUnfolder(0)
-,fDigitsArr(0)
-,fClusterArr(0)
-,fMisalignSurvey(kdefault)  
-,fExoticCellFraction(-1)
-,fExoticCellDiffTime(-1)
-,fExoticCellMinAmplitude(-1)
+  AliTenderSupply()
+  ,fTask(0)
+  ,fRun(0)
+  ,fEMCALGeo(0x0)
+  ,fEMCALGeoName("")
+  ,fEMCALRecoUtils(0)
+  ,fConfigName("")
+  ,fDebugLevel(0)
+  ,fNonLinearFunc(-1) 
+  ,fNonLinearThreshold(-1)
+  ,fReCalibCluster(kFALSE)
+  ,fUpdateCell(kFALSE)  
+  ,fCalibrateEnergy(kFALSE)
+  ,fCalibrateTime(kFALSE)
+  ,fCalibrateTimeParamAvailable(kFALSE)
+  ,fDoNonLinearity(kFALSE)
+  ,fBadCellRemove(kFALSE)
+  ,fRejectExoticCells(kFALSE)
+  ,fRejectExoticClusters(kFALSE)
+  ,fClusterBadChannelCheck(kFALSE)
+  ,fRecalClusPos(kFALSE)
+  ,fFiducial(kFALSE) 
+  ,fNCellsFromEMCALBorder(-1)
+  ,fRecalDistToBadChannels(kFALSE)
+  ,fRecalShowerShape(kFALSE)
+  ,fInputTree(0)
+  ,fInputFile(0)
+  ,fGetPassFromFileName(kTRUE)
+  ,fFilepass(0) 
+  ,fMass(-1)
+  ,fStep(-1)
+  ,fCutEtaPhiSum(kTRUE)
+  ,fCutEtaPhiSeparate(kFALSE)
+  ,fRcut(-1)
+  ,fEtacut(-1)
+  ,fPhicut(-1)
+  ,fBasePath("")
+  ,fReClusterize(kFALSE)
+  ,fClusterizer(0)
+  ,fGeomMatrixSet(kFALSE)
+  ,fLoadGeomMatrices(kFALSE)
+  ,fRecParam(0x0)
+  ,fDoTrackMatch(kFALSE)
+  ,fDoUpdateOnly(kFALSE)
+  ,fUnfolder(0)
+  ,fDigitsArr(0)
+  ,fClusterArr(0)
+  ,fMisalignSurvey(kdefault)  
+  ,fExoticCellFraction(-1)
+  ,fExoticCellDiffTime(-1)
+  ,fExoticCellMinAmplitude(-1)
+  ,fSetCellMCLabelFromCluster(0)
+  ,fTempClusterArr(0)
+  ,fRemapMCLabelForAODs(0)
+  ,fUseAutomaticRecalib(1)
+  ,fUseAutomaticRunDepRecalib(1)
+  ,fUseAutomaticTimeCalib(1)
+  ,fUseAutomaticRecParam(1)
 {
   // Default constructor.
 
-  for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
+  for(Int_t i = 0; i < 12;    i++) fEMCALMatrix[i]      = 0 ;
+  for(Int_t j = 0; j < 12672; j++) fOrgClusterCellId[j] = -1;
 }
 
 //_____________________________________________________
 AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
-AliTenderSupply(name,tender)
-,fTask(0)
-,fRun(0)
-,fEMCALGeo(0x0)
-,fEMCALGeoName("")
-,fEMCALRecoUtils(0)
-,fConfigName("")
-,fDebugLevel(0)
-,fNonLinearFunc(-1) 
-,fNonLinearThreshold(-1)        
-,fReCalibCluster(kFALSE)  
-,fUpdateCell(kFALSE)  
-,fCalibrateEnergy(kFALSE)
-,fCalibrateTime(kFALSE)
-,fDoNonLinearity(kFALSE)
-,fBadCellRemove(kFALSE)
-,fRejectExoticCells(kFALSE)
-,fRejectExoticClusters(kFALSE)
-,fClusterBadChannelCheck(kFALSE)
-,fRecalClusPos(kFALSE)
-,fFiducial(kFALSE) 
-,fNCellsFromEMCALBorder(-1)  
-,fRecalDistToBadChannels(kFALSE)  
-,fRecalShowerShape(kFALSE)
-,fInputTree(0)  
-,fInputFile(0)
-,fFilepass(0) 
-,fMass(-1)
-,fStep(-1)
-,fCutEtaPhiSum(kTRUE)
-,fCutEtaPhiSeparate(kFALSE)
-,fRcut(-1)  
-,fEtacut(-1)  
-,fPhicut(-1)  
-,fBasePath("")
-,fReClusterize(kFALSE)
-,fClusterizer(0)
-,fGeomMatrixSet(kFALSE)
-,fLoadGeomMatrices(kFALSE)
-,fRecParam(0x0)
-,fDoTrackMatch(kFALSE)
-,fDoUpdateOnly(kFALSE)
-,fUnfolder(0)
-,fDigitsArr(0)
-,fClusterArr(0)
-,fMisalignSurvey(kdefault)  
-,fExoticCellFraction(-1)
-,fExoticCellDiffTime(-1)
-,fExoticCellMinAmplitude(-1)
+  AliTenderSupply(name,tender)
+  ,fTask(0)
+  ,fRun(0)
+  ,fEMCALGeo(0x0)
+  ,fEMCALGeoName("")
+  ,fEMCALRecoUtils(0)
+  ,fConfigName("")
+  ,fDebugLevel(0)
+  ,fNonLinearFunc(-1) 
+  ,fNonLinearThreshold(-1)        
+  ,fReCalibCluster(kFALSE)  
+  ,fUpdateCell(kFALSE)  
+  ,fCalibrateEnergy(kFALSE)
+  ,fCalibrateTime(kFALSE)
+  ,fCalibrateTimeParamAvailable(kFALSE)
+  ,fDoNonLinearity(kFALSE)
+  ,fBadCellRemove(kFALSE)
+  ,fRejectExoticCells(kFALSE)
+  ,fRejectExoticClusters(kFALSE)
+  ,fClusterBadChannelCheck(kFALSE)
+  ,fRecalClusPos(kFALSE)
+  ,fFiducial(kFALSE) 
+  ,fNCellsFromEMCALBorder(-1)  
+  ,fRecalDistToBadChannels(kFALSE)  
+  ,fRecalShowerShape(kFALSE)
+  ,fInputTree(0)  
+  ,fInputFile(0)
+  ,fGetPassFromFileName(kTRUE)
+  ,fFilepass("") 
+  ,fMass(-1)
+  ,fStep(-1)
+  ,fCutEtaPhiSum(kTRUE)
+  ,fCutEtaPhiSeparate(kFALSE)
+  ,fRcut(-1)  
+  ,fEtacut(-1)  
+  ,fPhicut(-1)  
+  ,fBasePath("")
+  ,fReClusterize(kFALSE)
+  ,fClusterizer(0)
+  ,fGeomMatrixSet(kFALSE)
+  ,fLoadGeomMatrices(kFALSE)
+  ,fRecParam(0x0)
+  ,fDoTrackMatch(kFALSE)
+  ,fDoUpdateOnly(kFALSE)
+  ,fUnfolder(0)
+  ,fDigitsArr(0)
+  ,fClusterArr(0)
+  ,fMisalignSurvey(kdefault)  
+  ,fExoticCellFraction(-1)
+  ,fExoticCellDiffTime(-1)
+  ,fExoticCellMinAmplitude(-1)
+  ,fSetCellMCLabelFromCluster(0)
+  ,fTempClusterArr(0)
+  ,fRemapMCLabelForAODs(0)
+  ,fUseAutomaticRecalib(1)
+  ,fUseAutomaticRunDepRecalib(1)
+  ,fUseAutomaticTimeCalib(1)
+  ,fUseAutomaticRecParam(1)
 {
   // Named constructor
   
-  for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
+  for(Int_t i = 0; i < 12;    i++) fEMCALMatrix[i]      = 0 ;
+  for(Int_t j = 0; j < 12672; j++) fOrgClusterCellId[j] = -1;
 }
 
 //_____________________________________________________
 AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, AliAnalysisTaskSE *task) :
-AliTenderSupply(name)
-,fTask(task)
-,fRun(0)
-,fEMCALGeo(0x0)
-,fEMCALGeoName("")
-,fEMCALRecoUtils(0)
-,fConfigName("")
-,fDebugLevel(0)
-,fNonLinearFunc(-1) 
-,fNonLinearThreshold(-1)        
-,fReCalibCluster(kFALSE)  
-,fUpdateCell(kFALSE)  
-,fCalibrateEnergy(kFALSE)
-,fCalibrateTime(kFALSE)
-,fDoNonLinearity(kFALSE)
-,fBadCellRemove(kFALSE)
-,fRejectExoticCells(kFALSE)
-,fRejectExoticClusters(kFALSE)
-,fClusterBadChannelCheck(kFALSE)
-,fRecalClusPos(kFALSE)
-,fFiducial(kFALSE) 
-,fNCellsFromEMCALBorder(-1)  
-,fRecalDistToBadChannels(kFALSE)  
-,fRecalShowerShape(kFALSE)
-,fInputTree(0)  
-,fInputFile(0)
-,fFilepass(0) 
-,fMass(-1)
-,fStep(-1)
-,fCutEtaPhiSum(kTRUE)
-,fCutEtaPhiSeparate(kFALSE)
-,fRcut(-1)  
-,fEtacut(-1)  
-,fPhicut(-1)  
-,fBasePath("")
-,fReClusterize(kFALSE)
-,fClusterizer(0)
-,fGeomMatrixSet(kFALSE)
-,fLoadGeomMatrices(kFALSE)
-,fRecParam(0x0)
-,fDoTrackMatch(kFALSE)
-,fDoUpdateOnly(kFALSE)
-,fUnfolder(0)
-,fDigitsArr(0)
-,fClusterArr(0)
-,fMisalignSurvey(kdefault)  
-,fExoticCellFraction(-1)
-,fExoticCellDiffTime(-1)
-,fExoticCellMinAmplitude(-1)
+  AliTenderSupply(name)
+  ,fTask(task)
+  ,fRun(0)
+  ,fEMCALGeo(0x0)
+  ,fEMCALGeoName("")
+  ,fEMCALRecoUtils(0)
+  ,fConfigName("")
+  ,fDebugLevel(0)
+  ,fNonLinearFunc(-1) 
+  ,fNonLinearThreshold(-1)        
+  ,fReCalibCluster(kFALSE)  
+  ,fUpdateCell(kFALSE)  
+  ,fCalibrateEnergy(kFALSE)
+  ,fCalibrateTime(kFALSE)
+  ,fCalibrateTimeParamAvailable(kFALSE)
+  ,fDoNonLinearity(kFALSE)
+  ,fBadCellRemove(kFALSE)
+  ,fRejectExoticCells(kFALSE)
+  ,fRejectExoticClusters(kFALSE)
+  ,fClusterBadChannelCheck(kFALSE)
+  ,fRecalClusPos(kFALSE)
+  ,fFiducial(kFALSE) 
+  ,fNCellsFromEMCALBorder(-1)  
+  ,fRecalDistToBadChannels(kFALSE)  
+  ,fRecalShowerShape(kFALSE)
+  ,fInputTree(0)  
+  ,fInputFile(0)
+  ,fGetPassFromFileName(kTRUE)
+  ,fFilepass("") 
+  ,fMass(-1)
+  ,fStep(-1)
+  ,fCutEtaPhiSum(kTRUE)
+  ,fCutEtaPhiSeparate(kFALSE)
+  ,fRcut(-1)  
+  ,fEtacut(-1)  
+  ,fPhicut(-1)  
+  ,fBasePath("")
+  ,fReClusterize(kFALSE)
+  ,fClusterizer(0)
+  ,fGeomMatrixSet(kFALSE)
+  ,fLoadGeomMatrices(kFALSE)
+  ,fRecParam(0x0)
+  ,fDoTrackMatch(kFALSE)
+  ,fDoUpdateOnly(kFALSE)
+  ,fUnfolder(0)
+  ,fDigitsArr(0)
+  ,fClusterArr(0)
+  ,fMisalignSurvey(kdefault)  
+  ,fExoticCellFraction(-1)
+  ,fExoticCellDiffTime(-1)
+  ,fExoticCellMinAmplitude(-1)
+  ,fSetCellMCLabelFromCluster(0)
+  ,fTempClusterArr(0)
+  ,fRemapMCLabelForAODs(0)
+  ,fUseAutomaticRecalib(1)
+  ,fUseAutomaticRunDepRecalib(1)
+  ,fUseAutomaticTimeCalib(1)
+  ,fUseAutomaticRecParam(1)
 {
   // Named constructor.
   
-  for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
+  for(Int_t i = 0; i < 12;    i++) fEMCALMatrix[i]      = 0 ;
+  for(Int_t j = 0; j < 12672; j++) fOrgClusterCellId[j] = -1;
 }
 
 //_____________________________________________________
 AliEMCALTenderSupply::~AliEMCALTenderSupply()
 {
   //Destructor
-  
-  delete fEMCALRecoUtils;
-  delete fRecParam;
-  delete fUnfolder;
-  if (!fClusterizer) {
-    fDigitsArr->Clear("C");
-    delete fDigitsArr; 
-  } else {
-    delete fClusterizer;
-    fDigitsArr = 0;
+
+  if (!AliAnalysisManager::GetAnalysisManager())  return;  
+
+  if (!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) 
+  {
+    delete fEMCALRecoUtils;
+    delete fRecParam;
+    delete fUnfolder;
+    
+    if (!fClusterizer) 
+    {
+      if (fDigitsArr) 
+      { 
+       fDigitsArr->Clear("C");
+       delete fDigitsArr; 
+      }
+    } 
+    else 
+    {
+      delete fClusterizer;
+      fDigitsArr = 0;
+    }
   }
 }
 
@@ -245,14 +288,7 @@ void AliEMCALTenderSupply::SetDefaults()
 {
   // Set default settings.
 
-  SwitchOnBadCellRemove();
-  SwitchOnExoticCellRemove();
-  SwitchOnCalibrateEnergy();
-  SwitchOnCalibrateTime();
-  SwitchOnUpdateCell();
   SwitchOnReclustering();
-  SwitchOnClusterBadChannelCheck();
-  SwitchOnClusterExoticChannelCheck();
   SwitchOnTrackMatch();
 }
 
@@ -286,6 +322,7 @@ void AliEMCALTenderSupply::Init()
     fRecalClusPos           = tender->fRecalClusPos;
     fCalibrateEnergy        = tender->fCalibrateEnergy;
     fCalibrateTime          = tender->fCalibrateTime;
+    fCalibrateTimeParamAvailable = tender->fCalibrateTimeParamAvailable;
     fFiducial               = tender->fFiducial;
     fNCellsFromEMCALBorder  = tender->fNCellsFromEMCALBorder;
     fRecalDistToBadChannels = tender->fRecalDistToBadChannels;    
@@ -317,46 +354,48 @@ void AliEMCALTenderSupply::Init()
   }
   
   if (fDebugLevel>0){
-    AliInfo( "Emcal Tender settings: ======================================" ); 
-    AliInfo( "------------ Switches --------------------------" ); 
-    AliInfo( Form( "BadCellRemove : %d", fBadCellRemove )); 
-    AliInfo( Form( "ExoticCellRemove : %d", fRejectExoticCells )); 
-    AliInfo( Form( "CalibrateEnergy : %d", fCalibrateEnergy )); 
-    AliInfo( Form( "CalibrateTime : %d", fCalibrateTime )); 
-    AliInfo( Form( "UpdateCell : %d", fUpdateCell )); 
-    AliInfo( Form( "DoUpdateOnly : %d", fDoUpdateOnly )); 
-    AliInfo( Form( "Reclustering : %d", fReClusterize )); 
-    AliInfo( Form( "ClusterBadChannelCheck : %d", fClusterBadChannelCheck )); 
-    AliInfo( Form( "ClusterExoticChannelCheck : %d", fRejectExoticClusters )); 
-    AliInfo( Form( "CellFiducialRegion : %d", fFiducial )); 
-    AliInfo( Form( "ReCalibrateCluster : %d", fReCalibCluster )); 
-    AliInfo( Form( "RecalculateClusPos : %d", fRecalClusPos )); 
-    AliInfo( Form( "RecalShowerShape : %d", fRecalShowerShape )); 
-    AliInfo( Form( "NonLinearityCorrection : %d", fDoNonLinearity )); 
-    AliInfo( Form( "RecalDistBadChannel : %d", fRecalDistToBadChannels )); 
-    AliInfo( Form( "TrackMatch : %d", fDoTrackMatch )); 
-    AliInfo( "------------ Variables -------------------------" ); 
-    AliInfo( Form( "DebugLevel : %d", fDebugLevel )); 
-    AliInfo( Form( "BasePath : %s", fBasePath.Data() )); 
-    AliInfo( Form( "ConfigFileName : %s", fConfigName.Data() )); 
-    AliInfo( Form( "EMCALGeometryName : %s", fEMCALGeoName.Data() )); 
-    AliInfo( Form( "NonLinearityFunction : %d", fNonLinearFunc )); 
-    AliInfo( Form( "NonLinearityThreshold : %d", fNonLinearThreshold )); 
-    AliInfo( Form( "MisalignmentMatrixSurvey : %d", fMisalignSurvey )); 
-    AliInfo( Form( "NumberOfCellsFromEMCALBorder : %d", fNCellsFromEMCALBorder )); 
-    AliInfo( Form( "RCut : %f", fRcut )); 
-    AliInfo( Form( "Mass : %f", fMass )); 
-    AliInfo( Form( "Step : %f", fStep )); 
-    AliInfo( Form( "EtaCut : %f", fEtacut )); 
-    AliInfo( Form( "PhiCut : %f", fPhicut )); 
-    AliInfo( Form( "ExoticCellFraction : %f", fExoticCellFraction )); 
-    AliInfo( Form( "ExoticCellDiffTime : %f", fExoticCellDiffTime )); 
-    AliInfo( Form( "ExoticCellMinAmplitude : %f", fExoticCellMinAmplitude )); 
-    AliInfo( "=============================================================" ); 
+    AliInfo("Emcal Tender settings: ======================================"); 
+    AliInfo("------------ Switches --------------------------"); 
+    AliInfo(Form("BadCellRemove : %d", fBadCellRemove)); 
+    AliInfo(Form("ExoticCellRemove : %d", fRejectExoticCells)); 
+    AliInfo(Form("CalibrateEnergy : %d", fCalibrateEnergy)); 
+    AliInfo(Form("CalibrateTime : %d", fCalibrateTime)); 
+    AliInfo(Form("UpdateCell : %d", fUpdateCell)); 
+    AliInfo(Form("DoUpdateOnly : %d", fDoUpdateOnly)); 
+    AliInfo(Form("Reclustering : %d", fReClusterize)); 
+    AliInfo(Form("ClusterBadChannelCheck : %d", fClusterBadChannelCheck)); 
+    AliInfo(Form("ClusterExoticChannelCheck : %d", fRejectExoticClusters)); 
+    AliInfo(Form("CellFiducialRegion : %d", fFiducial)); 
+    AliInfo(Form("ReCalibrateCluster : %d", fReCalibCluster)); 
+    AliInfo(Form("RecalculateClusPos : %d", fRecalClusPos)); 
+    AliInfo(Form("RecalShowerShape : %d", fRecalShowerShape)); 
+    AliInfo(Form("NonLinearityCorrection : %d", fDoNonLinearity)); 
+    AliInfo(Form("RecalDistBadChannel : %d", fRecalDistToBadChannels)); 
+    AliInfo(Form("TrackMatch : %d", fDoTrackMatch)); 
+    AliInfo("------------ Variables -------------------------"); 
+    AliInfo(Form("DebugLevel : %d", fDebugLevel)); 
+    AliInfo(Form("BasePath : %s", fBasePath.Data())); 
+    AliInfo(Form("ConfigFileName : %s", fConfigName.Data())); 
+    AliInfo(Form("EMCALGeometryName : %s", fEMCALGeoName.Data())); 
+    AliInfo(Form("NonLinearityFunction : %d", fNonLinearFunc)); 
+    AliInfo(Form("NonLinearityThreshold : %d", fNonLinearThreshold)); 
+    AliInfo(Form("MisalignmentMatrixSurvey : %d", fMisalignSurvey)); 
+    AliInfo(Form("NumberOfCellsFromEMCALBorder : %d", fNCellsFromEMCALBorder)); 
+    AliInfo(Form("RCut : %f", fRcut)); 
+    AliInfo(Form("Mass : %f", fMass)); 
+    AliInfo(Form("Step : %f", fStep)); 
+    AliInfo(Form("EtaCut : %f", fEtacut)); 
+    AliInfo(Form("PhiCut : %f", fPhicut)); 
+    AliInfo(Form("ExoticCellFraction : %f", fExoticCellFraction)); 
+    AliInfo(Form("ExoticCellDiffTime : %f", fExoticCellDiffTime)); 
+    AliInfo(Form("ExoticCellMinAmplitude : %f", fExoticCellMinAmplitude)); 
+    AliInfo("============================================================="); 
   }
 
   // init reco utils
-  fEMCALRecoUtils  = new AliEMCALRecoUtils;
+  
+  if (!fEMCALRecoUtils)
+    fEMCALRecoUtils  = new AliEMCALRecoUtils;
 
   // init geometry if requested
   if (fEMCALGeoName.Length()>0) 
@@ -366,9 +405,9 @@ void AliEMCALTenderSupply::Init()
   fDigitsArr       = new TClonesArray("AliEMCALDigit",1000);
 
   // initialising non-linearity parameters
-  if( fNonLinearThreshold != -1 )
+  if (fNonLinearThreshold != -1)
     fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
-  if( fNonLinearFunc != -1 )
+  if (fNonLinearFunc != -1)
     fEMCALRecoUtils->SetNonLinearityFunction(fNonLinearFunc);
 
   // missalignment function
@@ -376,34 +415,34 @@ void AliEMCALTenderSupply::Init()
 
   // fiducial cut
   // do not do the eta0 fiducial cut
-  if( fNCellsFromEMCALBorder != -1 )
+  if (fNCellsFromEMCALBorder != -1)
     fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
   fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
     
   // exotic cell rejection
-  if( fExoticCellFraction != -1 )
-    fEMCALRecoUtils->SetExoticCellFractionCut( fExoticCellFraction );
-  if( fExoticCellDiffTime != -1 )
-    fEMCALRecoUtils->SetExoticCellDiffTimeCut( fExoticCellDiffTime );
-  if( fExoticCellMinAmplitude != -1 )
-    fEMCALRecoUtils->SetExoticCellMinAmplitudeCut( fExoticCellMinAmplitude );
+  if (fExoticCellFraction != -1)
+    fEMCALRecoUtils->SetExoticCellFractionCut(fExoticCellFraction);
+  if (fExoticCellDiffTime != -1)
+    fEMCALRecoUtils->SetExoticCellDiffTimeCut(fExoticCellDiffTime);
+  if (fExoticCellMinAmplitude != -1)
+    fEMCALRecoUtils->SetExoticCellMinAmplitudeCut(fExoticCellMinAmplitude);
 
   // setting track matching parameters ... mass, step size and residual cut
-  if( fMass != -1 )
+  if (fMass != -1)
     fEMCALRecoUtils->SetMass(fMass);
-  if( fStep != -1 )
+  if (fStep != -1)
     fEMCALRecoUtils->SetStep(fStep);
   
   // spatial cut based on separate eta/phi or common processing
-  if(fCutEtaPhiSum)
+  if (fCutEtaPhiSum) 
     fEMCALRecoUtils->SwitchOnCutEtaPhiSum(); 
-    if( fRcut != -1 )
+    if (fRcut != -1)
       fEMCALRecoUtils->SetCutR(fRcut);
   } else if (fCutEtaPhiSeparate) {
     fEMCALRecoUtils->SwitchOnCutEtaPhiSeparate();
-    if( fEtacut != -1 )
+    if (fEtacut != -1)
       fEMCALRecoUtils->SetCutEta(fEtacut);
-    if( fPhicut != -1 )
+    if (fPhicut != -1)
       fEMCALRecoUtils->SetCutPhi(fPhicut);
   }
 }
@@ -415,8 +454,7 @@ AliVEvent* AliEMCALTenderSupply::GetEvent()
   
   if (fTender) {
     return fTender->GetEvent();
-  }
-  else if (fTask) {
+  } else if (fTask) {
     return fTask->InputEvent();
   }
   
@@ -429,17 +467,22 @@ void AliEMCALTenderSupply::ProcessEvent()
   // Event loop.
   
   AliVEvent *event = GetEvent();
-  
+
   if (!event) {
     AliError("Event ptr = 0, returning");
     return;
   }
   
- // Initialising parameters once per run number
 // Initialising parameters once per run number
   if (RunChanged()) { 
 
-    AliWarning( "Run changed, initializing parameters" );
     fRun = event->GetRunNumber();
+    AliWarning(Form("Run changed, initializing parameters for %d", fRun));
+    if (dynamic_cast<AliAODEvent*>(event)) {
+      AliWarning("============================================================="); 
+      AliWarning("===  Running on AOD is not equivalent to running on ESD!  ===");
+      AliWarning("============================================================="); 
+    }
 
     // init geometry if not already done
     if (fEMCALGeoName.Length()==0) {
@@ -458,7 +501,8 @@ void AliEMCALTenderSupply::ProcessEvent()
     } 
 
     // get pass
-    GetPass();
+    if (fGetPassFromFileName)
+      GetPass();
 
     // define what recalib parameters are needed for various switches
     // this is based on implementation in AliEMCALRecoUtils
@@ -469,19 +513,8 @@ void AliEMCALTenderSupply::ProcessEvent()
     Bool_t needMisalign    = fRecalClusPos    | fReClusterize;
     Bool_t needClusterizer = fReClusterize;
 
-    // initiate reco params with some defaults 
-    // will not overwrite, if those have been provided by user
-    if( needRecoParam ){
-      Int_t initRC = InitRecParam();
-      
-      if( initRC == 0 )
-        AliInfo("Defaults reco params loaded.");
-      if( initRC > 1 )
-        AliWarning("User defined reco params.");
-    }
-
     // init bad channels
-    if( needBadChannels ){
+    if (needBadChannels) {
       Int_t fInitBC = InitBadChannels();
       if (fInitBC==0)
         AliError("InitBadChannels returned false, returning");
@@ -492,58 +525,71 @@ void AliEMCALTenderSupply::ProcessEvent()
     }
 
     // init recalibration factors
-    if( needRecalib ) 
-    { 
-      Int_t fInitRecalib = InitRecalib();
-      if (fInitRecalib==0)
-        AliError("InitRecalib returned false, returning");
-      if (fInitRecalib==1)
-        AliWarning("InitRecalib OK");
-      if (fInitRecalib>1)
-        AliWarning(Form("No recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
-      
-      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()));
-      
-      fReCalibCluster = kFALSE;
+    if (needRecalib) {
+      if(fUseAutomaticRecalib)
+      {
+        Int_t fInitRecalib = InitRecalib();
+        if (fInitRecalib==0)
+          AliError("InitRecalib returned false, returning");
+        if (fInitRecalib==1)
+          AliWarning("InitRecalib OK");
+        if (fInitRecalib>1)
+          AliWarning(Form("No recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
+      }
       
+      if(fUseAutomaticRunDepRecalib)
+      {
+        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 ){
+    if (needTimecalib && fUseAutomaticTimeCalib) {
       Int_t initTC = InitTimeCalibration();
-      if ( !initTC 
+      if (!initTC
         AliError("InitTimeCalibration returned false, returning");
-      if (initTC==1)
+      if (initTC==1) {
+        fCalibrateTimeParamAvailable = kTRUE;
         AliWarning("InitTimeCalib OK");
-      if( initTC > 1 )
-        AliWarning(Form("No external time calibration set: %d - %s", event->GetRunNumber(), fFilepass.Data()));
+      }
+      if (initTC > 1)
+        AliWarning(Form("No external time calibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
     }
 
     // init misalignment matrix
-    if( needMisalign ) { 
+    if (needMisalign) {
       if (!InitMisalignMatrix())
         AliError("InitMisalignmentMatrix returned false, returning");
       else
         AliWarning("InitMisalignMatrix OK");
     }
     
+    // initiate reco params with some defaults
+    // will not overwrite, if those have been provided by user
+    if (needRecoParam && fUseAutomaticRecParam) {
+      Int_t initRC = InitRecParam();
+      
+      if (initRC == 0)
+        AliInfo("Defaults reco params loaded.");
+      if (initRC > 1)
+        AliWarning("User defined reco params.");
+    }
+    
     // init clusterizer
-    if( needClusterizer ) {
+    if (needClusterizer) {
       if (!InitClusterization()) 
         AliError("InitClusterization returned false, returning");
       else
         AliWarning("InitClusterization OK");
     }
     
-    if(fDebugLevel>1) 
+    if (fDebugLevel>1) 
       fEMCALRecoUtils->Print("");
   }
   
@@ -554,7 +600,7 @@ void AliEMCALTenderSupply::ProcessEvent()
     
   // clusterizer does cluster energy recalibration, position recomputation
   // and shower shape
-  if( fReClusterize ){
+  if (fReClusterize) {
     fReCalibCluster   = kFALSE;
     fRecalClusPos     = kFALSE;
     fRecalShowerShape = kFALSE;
@@ -563,37 +609,37 @@ void AliEMCALTenderSupply::ProcessEvent()
   // CONFIGURE THE RECO UTILS -------------------------------------------------
   // configure the reco utils
   // this option does energy recalibration
-  if( fCalibrateEnergy )
+  if (fCalibrateEnergy)
     fEMCALRecoUtils->SwitchOnRecalibration();
   else
     fEMCALRecoUtils->SwitchOffRecalibration();
   
   // allows time calibration
-  if( fCalibrateTime )
+  if (fCalibrateTime)
     fEMCALRecoUtils->SwitchOnTimeRecalibration();
   else
     fEMCALRecoUtils->SwitchOffTimeRecalibration();
 
   // allows to zero bad cells
-  if( fBadCellRemove )
+  if (fBadCellRemove)
     fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
   else
     fEMCALRecoUtils->SwitchOffBadChannelsRemoval();
   
   // distance to bad channel recalibration
-  if( fRecalDistToBadChannels )
+  if (fRecalDistToBadChannels)
     fEMCALRecoUtils->SwitchOnDistToBadChannelRecalculation();
   else
     fEMCALRecoUtils->SwitchOffDistToBadChannelRecalculation();
 
   // exclude exotic cells
-  if( fRejectExoticCells )
+  if (fRejectExoticCells)
     fEMCALRecoUtils->SwitchOnRejectExoticCell();
   else
     fEMCALRecoUtils->SwitchOffRejectExoticCell();
   
   // exclude clusters with exotic cells
-  if( fRejectExoticClusters )
+  if (fRejectExoticClusters)
     fEMCALRecoUtils->SwitchOnRejectExoticCluster();
   else
     fEMCALRecoUtils->SwitchOffRejectExoticCluster();
@@ -607,7 +653,7 @@ void AliEMCALTenderSupply::ProcessEvent()
   AliVCaloCells *cells= event->GetEMCALCells();
   if (cells->GetNumberOfCells()<=0) 
   {
-    if(fDebugLevel>1) 
+    if (fDebugLevel>1) 
       AliWarning(Form("Number of EMCAL cells = %d, returning", cells->GetNumberOfCells()));
     return;
   }
@@ -617,15 +663,14 @@ void AliEMCALTenderSupply::ProcessEvent()
 
   // mark the cells not recalibrated in case of selected
   // time, energy recalibration or bad channel removal
-  if( fCalibrateEnergy || fCalibrateTime || fBadCellRemove )
+  if (fCalibrateEnergy || fCalibrateTime || fBadCellRemove)
     fEMCALRecoUtils->ResetCellsCalibrated();
   
  // 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
-  if( fUpdateCell )
-  {
+  if (fUpdateCell) {
     // do the update
     // includes exotic cell check in the UpdateCells function - is not provided
     // by the reco utils
@@ -671,8 +716,7 @@ void AliEMCALTenderSupply::ProcessEvent()
       continue;
 
     // REMOVE CLUSTERS WITH BAD CELLS -----------------------------
-    if( fClusterBadChannelCheck )
-    {
+    if (fClusterBadChannelCheck) {
       // careful, the the ClusterContainsBadChannel is dependent on
       // SwitchOnBadChannelsRemoval, switching it ON automatically
       // and returning to original value after processing
@@ -682,10 +726,10 @@ void AliEMCALTenderSupply::ProcessEvent()
       Bool_t badResult = fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo, clust->GetCellsAbsId(), clust->GetNCells());
 
       // switch the bad channels removal back
-      if( ! badRemoval )
+      if (!badRemoval)
         fEMCALRecoUtils->SwitchOffBadChannelsRemoval();
       
-      if( badResult )
+      if (badResult)
       {
         delete clusArr->RemoveAt(icluster);
         continue; //TODO is it really needed to remove it? Or should we flag it?
@@ -695,7 +739,7 @@ void AliEMCALTenderSupply::ProcessEvent()
     // REMOVE EXOTIC CLUSTERS -------------------------------------
     // does process local cell recalibration energy and time without replacing
     // the global cell values, in case of no cell recalib done yet
-    if( fRejectExoticClusters )
+    if (fRejectExoticClusters)
     {
       // careful, the IsExoticCluster is dependent on
       // SwitchOnRejectExoticCell, switching it ON automatically
@@ -706,22 +750,20 @@ void AliEMCALTenderSupply::ProcessEvent()
       // get bunch crossing
       Int_t bunchCrossNo = event->GetBunchCrossNumber();
 
-      Bool_t exResult = fEMCALRecoUtils->IsExoticCluster(clust, cells, bunchCrossNo );
+      Bool_t exResult = fEMCALRecoUtils->IsExoticCluster(clust, cells, bunchCrossNo);
 
       // switch the exotic channels removal back
-      if( ! exRemoval )
+      if (!exRemoval)
         fEMCALRecoUtils->SwitchOffRejectExoticCell();
       
-      if( exResult )
-      {
+      if (exResult) {
         delete clusArr->RemoveAt(icluster);
         continue; //TODO is it really needed to remove it? Or should we flag it?
       }
     }
     
     // FIDUCIAL CUT -----------------------------------------------
-    if (fFiducial)
-    {
+    if (fFiducial) {
       // depends on SetNumberOfCellsFromEMCALBorder
       // SwitchOnNoFiducialBorderInEMCALEta0
       if (!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, clust, cells)){
@@ -733,28 +775,32 @@ 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 calibrated yet
-    if( fRecalClusPos 
+    if (fRecalClusPos
       fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, cells, clust);
     
     // SHOWER SHAPE -----------------------------------------------
-    if( fRecalShowerShape )
+    if (fRecalShowerShape)
       fEMCALRecoUtils->RecalculateClusterShowerShapeParameters(fEMCALGeo, cells, clust);  
 
     // NONLINEARITY -----------------------------------------------
-    if( fDoNonLinearity )
-    {
+    if (fDoNonLinearity) {
       Float_t correctedEnergy = fEMCALRecoUtils->CorrectClusterEnergyLinearity(clust);
       clust->SetE(correctedEnergy);
     }
 
     // DISTANCE TO BAD CHANNELS -----------------------------------
-    if( fRecalDistToBadChannels )
+    if (fRecalDistToBadChannels)
       fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, cells, clust);  
   }
 
@@ -765,16 +811,7 @@ void AliEMCALTenderSupply::ProcessEvent()
 
   // TRACK MATCHING -----------------------------------------------------------
   if (!TGeoGlobalMagField::Instance()->GetField()) {
-    AliESDEvent *esd = dynamic_cast<AliESDEvent*>(event);
-    if (esd)
-      esd->InitMagneticField();
-    else {
-      AliAODEvent *aod = dynamic_cast<AliAODEvent*>(event);
-      Double_t curSol = 30000*aod->GetMagneticField()/5.00668;
-      Double_t curDip = 6000 *aod->GetMuonMagFieldScale();
-      AliMagF *field  = AliMagF::CreateFieldMap(curSol,curDip);
-      TGeoGlobalMagField::Instance()->SetField(field);
-    }
+    event->InitMagneticField();
   }
 
   fEMCALRecoUtils->FindMatches(event,0x0,fEMCALGeo);
@@ -805,7 +842,7 @@ Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
     for(Int_t mod=0; mod < fEMCALGeo->GetNumberOfSuperModules(); ++mod)
     {
       if (fEMCALMatrix[mod]){
-        if(fDebugLevel > 2) 
+        if (fDebugLevel > 2) 
           fEMCALMatrix[mod]->Print();
         fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);  
       }
@@ -817,14 +854,14 @@ Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
   Int_t runGM = event->GetRunNumber();
   TObjArray *mobj = 0;
 
-  if(fMisalignSurvey == kdefault)
+  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)
+  if (fMisalignSurvey == kSurveybyS)
   { //take alignment at sector level
     if (runGM <= 140000) { //2010 data
       AliOADBContainer emcalgeoCont(Form("emcal2010"));
@@ -839,7 +876,7 @@ Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
     }
   }
 
-  if(fMisalignSurvey == kSurveybyM)
+  if (fMisalignSurvey == kSurveybyM)
   { //take alignment at module level
     if (runGM <= 140000) { //2010 data
       AliOADBContainer emcalgeoCont(Form("emcal2010"));
@@ -854,8 +891,7 @@ Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
     }
   }
 
-  if(!mobj)
-  {
+  if (!mobj) {
     AliFatal("Geometry matrix array not found");
     return kFALSE;
   }
@@ -884,7 +920,7 @@ Int_t AliEMCALTenderSupply::InitBadChannels()
     AliInfo("Initialising Bad channel map");
   
   // init default maps first
-  if( !fEMCALRecoUtils->GetEMCALBadChannelStatusMapArray() )
+  if (!fEMCALRecoUtils->GetEMCALBadChannelStatusMapArray())
     fEMCALRecoUtils->InitEMCALBadChannelStatusMap() ;
   
   Int_t runBC = event->GetRunNumber();
@@ -961,7 +997,7 @@ Int_t AliEMCALTenderSupply::InitRecalib()
     AliInfo("Initialising recalibration factors");
   
   // init default maps first
-  if( !fEMCALRecoUtils->GetEMCALRecalibrationFactorsArray() )
+  if (!fEMCALRecoUtils->GetEMCALRecalibrationFactorsArray())
     fEMCALRecoUtils->InitEMCALRecalibrationFactors() ;
 
   Int_t runRC = event->GetRunNumber();
@@ -1053,7 +1089,7 @@ Int_t AliEMCALTenderSupply::InitRunDepRecalib()
     AliInfo("Initialising recalibration factors");
   
   // init default maps first
-  if( !fEMCALRecoUtils->GetEMCALRecalibrationFactorsArray() )
+  if (!fEMCALRecoUtils->GetEMCALRecalibrationFactorsArray())
     fEMCALRecoUtils->InitEMCALRecalibrationFactors() ;
   
   Int_t runRC = event->GetRunNumber();
@@ -1093,8 +1129,25 @@ Int_t AliEMCALTenderSupply::InitRunDepRecalib()
   TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
   if (!rundeprecal)
   {
-    AliError(Form("No Objects for run: %d",runRC));
-    return 2;
+    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();
@@ -1111,8 +1164,7 @@ Int_t AliEMCALTenderSupply::InitRunDepRecalib()
         
         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 
@@ -1135,7 +1187,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();
@@ -1180,19 +1232,21 @@ Int_t AliEMCALTenderSupply::InitTimeCalibration()
   }
   
   // Here, it looks for a specific pass
-  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(fFilepass); 
+  TString pass = fFilepass;
+  if (fFilepass=="calo_spc") pass ="pass1";
+  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
   if (!arrayBCpass)
   {
-    AliError(Form("No external time calibration set for: %d -%s", runBC,fFilepass.Data()));
+    AliError(Form("No external time calibration set for: %d -%s", runBC,pass.Data()));
     return 2; 
   }
 
   if (fDebugLevel>0) arrayBCpass->Print();
 
-  for( Int_t i = 0; i < 4; i++ )
+  for(Int_t i = 0; i < 4; i++)
   {
-    TH1F *h = fEMCALRecoUtils->GetEMCALChannelTimeRecalibrationFactors( i );
-    if( h )
+    TH1F *h = fEMCALRecoUtils->GetEMCALChannelTimeRecalibrationFactors(i);
+    if (h)
       delete h;
     
     h = (TH1F*)arrayBCpass->FindObject(Form("hAllTimeAvBC%d",i));
@@ -1217,7 +1271,7 @@ void AliEMCALTenderSupply::UpdateCells()
 
   AliVEvent *event = GetEvent();
 
-  if(!event) return ;
+  if (!event) return ;
   
   AliVCaloCells *cells = event->GetEMCALCells();
   Int_t bunchCrossNo = event->GetBunchCrossNumber();
@@ -1226,25 +1280,25 @@ void AliEMCALTenderSupply::UpdateCells()
   
   // remove exotic cells - loop through cells and zero the exotic ones
   // just like with bad cell rejection in reco utils (inside RecalibrateCells)
-  if( fRejectExoticCells )
+  if (fRejectExoticCells)
   {
     Short_t  absId  =-1;
     Double_t ecell = 0;
     Double_t tcell = 0;
     Double_t efrac = 0;
-    Short_t  mclabel = -1;
+    Int_t  mclabel = -1;
     Bool_t   isExot = kFALSE;
   
     // loop through cells
     Int_t nEMcell  = cells->GetNumberOfCells() ;  
     for (Int_t iCell = 0; iCell < nEMcell; iCell++) 
     { 
-      cells->GetCell( iCell, absId, ecell, tcell, mclabel, efrac );
+      cells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
     
-      isExot = fEMCALRecoUtils->IsExoticCell( absId, cells, bunchCrossNo ); 
+      isExot = fEMCALRecoUtils->IsExoticCell(absId, cells, bunchCrossNo); 
       // zero if exotic
-      if( isExot )
-        cells->SetCell( iCell, absId, 0.0, -1.0, mclabel, efrac );
+      if (isExot)
+        cells->SetCell(iCell, absId, 0.0, -1.0, mclabel, efrac);
     } // cell loop
   } // reject exotic cells
 
@@ -1293,7 +1347,7 @@ Int_t AliEMCALTenderSupply::InitRecParam()
 {
   // Init reco params if not yet exist (probably shipped by the user already)
 
-  if( fRecParam != 0 )
+  if (fRecParam != 0)
     return 2;
 
   TString beamType = GetBeamType();
@@ -1302,13 +1356,20 @@ Int_t AliEMCALTenderSupply::InitRecParam()
   fRecParam = new AliEMCALRecParam();
   fRecParam->SetClusteringThreshold(0.100);
   fRecParam->SetMinECut(0.050);
-  fRecParam->SetTimeCut(250);
-  fRecParam->SetTimeMin(425);
-  fRecParam->SetTimeMax(825);
-  if ( beamType == "A-A") {
+  
+  if (!fCalibrateTimeParamAvailable) {
+    fRecParam->SetTimeCut(250*1.e-9);
+    fRecParam->SetTimeMin(425*1.e-9);
+    fRecParam->SetTimeMax(825*1.e-9);
+  } else {
+    fRecParam->SetTimeCut(100*1.e-9);
+    fRecParam->SetTimeMin(-50*1.e-9);
+    fRecParam->SetTimeMax(50*1.e-9);
+  }
+  
+  if (beamType == "A-A") {
     fRecParam->SetClusterizerFlag(AliEMCALRecParam::kClusterizerv2);
-  } 
-  else {
+  } else {
     fRecParam->SetClusterizerFlag(AliEMCALRecParam::kClusterizerv1);
   }
 
@@ -1329,7 +1390,12 @@ Bool_t AliEMCALTenderSupply::InitClusterization()
     AliInfo(Form("Initialising reclustering parameters: Clusterizer type: %d",fRecParam->GetClusterizerFlag()));
   
   //---setup clusterizer
-  delete fClusterizer;
+  if (fClusterizer) {
+    // avoid deleting fDigitsArr
+    fClusterizer->SetDigitsArr(0);
+    delete fClusterizer;
+    fClusterizer = 0;
+  }
   if     (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
     fClusterizer = new AliEMCALClusterizerv1 (fEMCALGeo);
   else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2) 
@@ -1348,16 +1414,16 @@ Bool_t AliEMCALTenderSupply::InitClusterization()
   }
   
   // Set the clustering parameters
-  fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
-  fClusterizer->SetECALogWeight          ( fRecParam->GetW0()                  );
-  fClusterizer->SetMinECut               ( fRecParam->GetMinECut()             );    
-  fClusterizer->SetUnfolding             ( fRecParam->GetUnfold()              );
-  fClusterizer->SetECALocalMaxCut        ( fRecParam->GetLocMaxCut()           );
-  fClusterizer->SetTimeCut               ( fRecParam->GetTimeCut()             );
-  fClusterizer->SetTimeMin               ( fRecParam->GetTimeMin()             );
-  fClusterizer->SetTimeMax               ( fRecParam->GetTimeMax()             );
-  fClusterizer->SetInputCalibrated       ( kTRUE                               );
-  fClusterizer->SetJustClusters          ( kTRUE                               );  
+  fClusterizer->SetECAClusteringThreshold(fRecParam->GetClusteringThreshold());
+  fClusterizer->SetECALogWeight          (fRecParam->GetW0()                 );
+  fClusterizer->SetMinECut               (fRecParam->GetMinECut()            );    
+  fClusterizer->SetUnfolding             (fRecParam->GetUnfold()             );
+  fClusterizer->SetECALocalMaxCut        (fRecParam->GetLocMaxCut()          );
+  fClusterizer->SetTimeCut               (fRecParam->GetTimeCut()            );
+  fClusterizer->SetTimeMin               (fRecParam->GetTimeMin()            );
+  fClusterizer->SetTimeMax               (fRecParam->GetTimeMax()            );
+  fClusterizer->SetInputCalibrated       (kTRUE                              );
+  fClusterizer->SetJustClusters          (kTRUE                              );  
   
   // In case of unfolding after clusterization is requested, set the corresponding parameters
   if (fRecParam->GetUnfold()) 
@@ -1389,33 +1455,67 @@ void AliEMCALTenderSupply::FillDigitsArray()
 
  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 ;
+      fOrgClusterCellId[i] =-1 ;
+    }
+    
+    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;
+        fOrgClusterCellId[index[icell]] = i ; // index of the original cluster
+      }
+    }// cluster loop
+  }
+
   fDigitsArr->Clear("C");
   AliVCaloCells *cells = event->GetEMCALCells();
   Int_t ncells = cells->GetNumberOfCells();
   for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) 
   {
     Double_t cellAmplitude=0, cellTime=0, efrac = 0;
-    Short_t  cellNumber=0, mcLabel=-1;
+    Short_t  cellNumber=0;
+    Int_t mcLabel=-1;
 
     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((Float_t)cellTime);
-    digit->SetTimeR((Float_t)cellTime);
-    digit->SetIndexInList(idigit);
-    digit->SetType(AliEMCALDigit::kHG);
-    digit->SetAmplitude((Float_t)cellAmplitude);
+    
+    if      (fSetCellMCLabelFromCluster) mcLabel = cellLabels[cellNumber];
+    else if (fRemapMCLabelForAODs     ) RemapMCLabelForAODs(mcLabel);
+    
+    if (mcLabel > 0 && efrac < 1e-6) efrac = 1;
+    
+    new((*fDigitsArr)[idigit]) AliEMCALDigit(mcLabel, mcLabel, cellNumber,
+                                             (Float_t)cellAmplitude, (Float_t)cellTime,
+                                             AliEMCALDigit::kHG,idigit, 0, 0, efrac*cellAmplitude);
     idigit++;
   }
 }
@@ -1446,7 +1546,12 @@ void AliEMCALTenderSupply::UpdateClusters()
     AliError(" Null pointer to calo clusters array, returning");
     return;
   }
-  
+    
+  // Before destroying the orignal list, assign to the rec points the MC labels
+  // of the original clusters, if requested
+  if (fSetCellMCLabelFromCluster == 2) 
+    SetClustersMCLabelFromOriginalClusters() ;
+
   Int_t nents = clus->GetEntriesFast();
   for (Int_t i=0; i < nents; ++i) 
   {
@@ -1454,7 +1559,9 @@ void AliEMCALTenderSupply::UpdateClusters()
     if (!c)
       continue;
     if (c->IsEMCAL())
+    {
       delete clus->RemoveAt(i);
+    }
   }
   
   clus->Compress();
@@ -1523,13 +1630,164 @@ void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
     c->SetM20(elipAxis[1]*elipAxis[1]) ;
     c->SetCellsAbsId(absIds);
     c->SetCellsAmplitudeFraction(ratios);
+
+    //MC labels
+    Int_t  parentMult = 0;
+    Int_t *parentList = recpoint->GetParents(parentMult);
+    if (parentMult > 0) c->SetLabel(parentList, parentMult);
+
+  }
+}
+
+//___________________________________________________________
+void AliEMCALTenderSupply::RemapMCLabelForAODs(Int_t & label)
+{
+  // MC label for Cells not remapped after ESD filtering, do it here.
+  
+  if (label < 0) return;
+  
+  AliAODEvent  * evt = dynamic_cast<AliAODEvent*> (GetEvent()) ;
+  if (!evt) return ;
+  
+  TClonesArray * arr = dynamic_cast<TClonesArray*>(evt->FindListObject("mcparticles")) ;
+  if (!arr) return ;
+  
+  if (label < arr->GetEntriesFast())
+  {
+    AliAODMCParticle * particle = dynamic_cast<AliAODMCParticle *>(arr->At(label));
+    if (!particle) return ;
+    
+    if (label == particle->Label()) return ; // label already OK
+  }
+  
+  // loop on the particles list and check if there is one with the same label
+  for (Int_t ind = 0; ind < arr->GetEntriesFast(); ind++)
+  {
+    AliAODMCParticle * particle = dynamic_cast<AliAODMCParticle *>(arr->At(ind));
+    if (!particle) continue ;
+    
+    if (label == particle->Label())
+    {
+      label = ind;
+      return;
+    }
   }
+  
+  label = -1;
+}
+
+//_____________________________________________________________________________________________
+void AliEMCALTenderSupply::SetClustersMCLabelFromOriginalClusters()
+{
+  // Get the original clusters that contribute to the new rec point cluster,
+  // assign the labels of such clusters to the new rec point cluster.
+  // Only approximatedly valid  when output are V1 clusters, or input/output clusterizer
+  // are the same handle with care
+  // Copy from same method in AliAnalysisTaskEMCALClusterize, but here modify the recpoint and
+  // not the output calocluster
+  
+  Int_t ncls = fClusterArr->GetEntriesFast();
+  for(Int_t irp=0; irp < ncls; ++irp)
+  {
+    TArrayI clArray(300) ; //Weird if more than a few clusters are in the origin ...
+    clArray.Reset();
+    Int_t nClu = 0;
+    Int_t nLabTotOrg = 0;
+    Float_t emax = -1;
+    Int_t idMax = -1;
+    
+    AliEMCALRecPoint *clus = static_cast<AliEMCALRecPoint*>(fClusterArr->At(irp));
+    
+    //Find the clusters that originally had the cells
+    const Int_t ncells = clus->GetMultiplicity();
+    Int_t *digList     = clus->GetDigitsList();
+    
+    for (Int_t iLoopCell = 0 ; iLoopCell < ncells ; iLoopCell++)
+    {
+      AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(digList[iLoopCell]));
+      Int_t idCell = digit->GetId();
+
+      if (idCell>=0)
+      {
+        Int_t idCluster = fOrgClusterCellId[idCell];
+        Bool_t set = kTRUE;
+        for (Int_t icl =0; icl < nClu; icl++)
+        {
+          if (((Int_t)clArray.GetAt(icl))==-1) continue;
+          if (idCluster == ((Int_t)clArray.GetAt(icl))) set = kFALSE;
+        }
+        if (set && idCluster >= 0)
+        {
+          clArray.SetAt(idCluster,nClu++);
+          nLabTotOrg+=(GetEvent()->GetCaloCluster(idCluster))->GetNLabels();
+                    
+          //Search highest E cluster
+          AliVCluster * clOrg = GetEvent()->GetCaloCluster(idCluster);
+          if (emax < clOrg->E())
+          {
+            emax  = clOrg->E();
+            idMax = idCluster;
+          }
+        }
+      }
+    }// cell loop
+        
+    // Put the first in the list the cluster with highest energy
+    if (idMax != ((Int_t)clArray.GetAt(0))) // Max not at first position
+    {
+      Int_t maxIndex = -1;
+      Int_t firstCluster = ((Int_t)clArray.GetAt(0));
+      for (Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
+      {
+        if (idMax == ((Int_t)clArray.GetAt(iLoopCluster))) maxIndex = iLoopCluster;
+      }
+      
+      if (firstCluster >=0 && idMax >=0)
+      {
+        clArray.SetAt(idMax,0);
+        clArray.SetAt(firstCluster,maxIndex);
+      }
+    }
+    
+    // Get the labels list in the original clusters, assign all to the new cluster
+    TArrayI clMCArray(nLabTotOrg) ;
+    clMCArray.Reset();
+    
+    Int_t nLabTot = 0;
+    for (Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
+    {
+      Int_t idCluster = (Int_t) clArray.GetAt(iLoopCluster);
+      AliVCluster * clOrg = GetEvent()->GetCaloCluster(idCluster);
+      Int_t nLab = clOrg->GetNLabels();
+      
+      for (Int_t iLab = 0 ; iLab < nLab ; iLab++)
+      {
+        Int_t lab = clOrg->GetLabelAt(iLab) ;
+        if (lab>=0)
+        {
+          Bool_t set = kTRUE;
+          for(Int_t iLabTot =0; iLabTot < nLabTot; iLabTot++)
+          {
+            if (lab == ((Int_t)clMCArray.GetAt(iLabTot))) set = kFALSE;
+          }
+          if (set) clMCArray.SetAt(lab,nLabTot++);
+        }
+      }
+    }// cluster loop
+    
+    // Set the final list of labels to rec point
+    
+    Int_t *labels = new Int_t[nLabTot];
+    for(Int_t il = 0; il < nLabTot; il++) labels[il] = clMCArray.GetArray()[il];
+    clus->SetParents(nLabTot,labels);
+    
+  } // rec point array
 }
 
 //_____________________________________________________
 void AliEMCALTenderSupply::GetPass()
 {
-  // Get passx from filename.
+  // Get passx from filename
   
   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
   fInputTree = mgr->GetTree();
@@ -1550,7 +1808,18 @@ 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 
+  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
+  else if (fname.Contains("pass5")) fFilepass = TString("pass5");
+  else if (fname.Contains("LHC11c") &&
+           fname.Contains("spc_calo")) fFilepass = TString("spc_calo");
+  else if (fname.Contains("calo") || fname.Contains("high_lumi"))
+
+  {
+    //printf("AliEMCALTenderSupply::GetPass() - Path contains <calo> or <high-lumi>, set as <pass1>\n");
+    fFilepass = TString("pass1");
+  }
+  else if (fname.Contains("LHC14a1a")) fFilepass = TString("LHC14a1a");
+  else
   {
     AliError(Form("Pass number string not found: %s", fname.Data()));
     return;