]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALRecoUtils.cxx
New histos in the task for checks on the MC kinematics
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRecoUtils.cxx
index 842b5e32b1955057703fdb71080c854785db1d01..0df249a3c35846693ee2f4c0d32c4275d6af24db 100644 (file)
 #include "AliEMCALRecoUtils.h"
 #include "AliEMCALGeometry.h"
 #include "AliTrackerBase.h"
-#include "AliEMCALCalibTimeDepCorrection.h" // Run dependent
 #include "AliEMCALPIDUtils.h"
 
-
 ClassImp(AliEMCALRecoUtils)
   
 //_____________________________________
@@ -68,8 +66,7 @@ AliEMCALRecoUtils::AliEMCALRecoUtils():
   fNonLinearityFunction(0),               fNonLinearThreshold(0),
   fSmearClusterEnergy(kFALSE),            fRandom(),
   fCellsRecalibrated(kFALSE),             fRecalibration(kFALSE),                 fEMCALRecalibrationFactors(),
-  fTimeRecalibration(kFALSE),             fEMCALTimeRecalibrationFactors(),
-  fUseRunCorrectionFactors(kFALSE),       fRunCorrectionFactorsSet(kFALSE),
+  fTimeRecalibration(kFALSE),             fEMCALTimeRecalibrationFactors(),       fUseRunCorrectionFactors(kFALSE),       
   fRemoveBadChannels(kFALSE),             fRecalDistToBadChannels(kFALSE),        fEMCALBadChannelMap(),
   fNCellsFromEMCALBorder(0),              fNoEMCALBorderAtEta0(kTRUE),
   fRejectExoticCluster(kFALSE),           fRejectExoticCells(kFALSE), 
@@ -80,10 +77,12 @@ AliEMCALRecoUtils::AliEMCALRecoUtils():
   fCutR(0),                               fCutEta(0),                             fCutPhi(0),
   fClusterWindow(0),                      fMass(0),                           
   fStepSurface(0),                        fStepCluster(0),
+  fITSTrackSA(kFALSE),
   fTrackCutsType(0),                      fCutMinTrackPt(0),                      fCutMinNClusterTPC(0), 
   fCutMinNClusterITS(0),                  fCutMaxChi2PerClusterTPC(0),            fCutMaxChi2PerClusterITS(0),
   fCutRequireTPCRefit(kFALSE),            fCutRequireITSRefit(kFALSE),            fCutAcceptKinkDaughters(kFALSE),
-  fCutMaxDCAToVertexXY(0),                fCutMaxDCAToVertexZ(0),                 fCutDCAToVertex2D(kFALSE)
+  fCutMaxDCAToVertexXY(0),                fCutMaxDCAToVertexZ(0),                 fCutDCAToVertex2D(kFALSE),
+  fCutRequireITSStandAlone(kFALSE),       fCutRequireITSpureSA(kFALSE) 
 {
 //
   // Constructor.
@@ -101,7 +100,6 @@ AliEMCALRecoUtils::AliEMCALRecoUtils():
   fResidualEta           = new TArrayF();
   fPIDUtils              = new AliEMCALPIDUtils();
 
-  InitTrackCuts();
 }
 
 //______________________________________________________________________
@@ -113,7 +111,7 @@ AliEMCALRecoUtils::AliEMCALRecoUtils(const AliEMCALRecoUtils & reco)
   fCellsRecalibrated(reco.fCellsRecalibrated),
   fRecalibration(reco.fRecalibration),                       fEMCALRecalibrationFactors(reco.fEMCALRecalibrationFactors),
   fTimeRecalibration(reco.fTimeRecalibration),               fEMCALTimeRecalibrationFactors(reco.fEMCALTimeRecalibrationFactors),
-  fUseRunCorrectionFactors(reco.fUseRunCorrectionFactors),   fRunCorrectionFactorsSet(reco.fRunCorrectionFactorsSet),
+  fUseRunCorrectionFactors(reco.fUseRunCorrectionFactors),   
   fRemoveBadChannels(reco.fRemoveBadChannels),               fRecalDistToBadChannels(reco.fRecalDistToBadChannels),
   fEMCALBadChannelMap(reco.fEMCALBadChannelMap),
   fNCellsFromEMCALBorder(reco.fNCellsFromEMCALBorder),       fNoEMCALBorderAtEta0(reco.fNoEMCALBorderAtEta0),
@@ -129,12 +127,14 @@ AliEMCALRecoUtils::AliEMCALRecoUtils(const AliEMCALRecoUtils & reco)
   fCutR(reco.fCutR),        fCutEta(reco.fCutEta),           fCutPhi(reco.fCutPhi),
   fClusterWindow(reco.fClusterWindow),
   fMass(reco.fMass),        fStepSurface(reco.fStepSurface), fStepCluster(reco.fStepCluster),
+  fITSTrackSA(reco.fITSTrackSA),
   fTrackCutsType(reco.fTrackCutsType),                       fCutMinTrackPt(reco.fCutMinTrackPt), 
   fCutMinNClusterTPC(reco.fCutMinNClusterTPC),               fCutMinNClusterITS(reco.fCutMinNClusterITS), 
   fCutMaxChi2PerClusterTPC(reco.fCutMaxChi2PerClusterTPC),   fCutMaxChi2PerClusterITS(reco.fCutMaxChi2PerClusterITS),
   fCutRequireTPCRefit(reco.fCutRequireTPCRefit),             fCutRequireITSRefit(reco.fCutRequireITSRefit),
   fCutAcceptKinkDaughters(reco.fCutAcceptKinkDaughters),     fCutMaxDCAToVertexXY(reco.fCutMaxDCAToVertexXY),    
-  fCutMaxDCAToVertexZ(reco.fCutMaxDCAToVertexZ),             fCutDCAToVertex2D(reco.fCutDCAToVertex2D)
+  fCutMaxDCAToVertexZ(reco.fCutMaxDCAToVertexZ),             fCutDCAToVertex2D(reco.fCutDCAToVertex2D),
+  fCutRequireITSStandAlone(reco.fCutRequireITSStandAlone),   fCutRequireITSpureSA(reco.fCutRequireITSpureSA) 
 {
   //Copy ctor
   
@@ -175,7 +175,6 @@ AliEMCALRecoUtils & AliEMCALRecoUtils::operator = (const AliEMCALRecoUtils & rec
   fEMCALTimeRecalibrationFactors = reco.fEMCALTimeRecalibrationFactors;
 
   fUseRunCorrectionFactors   = reco.fUseRunCorrectionFactors;
-  fRunCorrectionFactorsSet   = reco.fRunCorrectionFactorsSet;
   
   fRemoveBadChannels         = reco.fRemoveBadChannels;
   fRecalDistToBadChannels    = reco.fRecalDistToBadChannels;
@@ -203,7 +202,8 @@ AliEMCALRecoUtils & AliEMCALRecoUtils::operator = (const AliEMCALRecoUtils & rec
   fMass                      = reco.fMass;
   fStepSurface               = reco.fStepSurface;
   fStepCluster               = reco.fStepCluster;
-
+  fITSTrackSA                = reco.fITSTrackSA;  
+  
   fTrackCutsType             = reco.fTrackCutsType;
   fCutMinTrackPt             = reco.fCutMinTrackPt;
   fCutMinNClusterTPC         = reco.fCutMinNClusterTPC;
@@ -216,7 +216,8 @@ AliEMCALRecoUtils & AliEMCALRecoUtils::operator = (const AliEMCALRecoUtils & rec
   fCutMaxDCAToVertexXY       = reco.fCutMaxDCAToVertexXY;
   fCutMaxDCAToVertexZ        = reco.fCutMaxDCAToVertexZ;
   fCutDCAToVertex2D          = reco.fCutDCAToVertex2D;
-  
+  fCutRequireITSStandAlone   = reco.fCutRequireITSStandAlone; 
+  fCutRequireITSpureSA       = reco.fCutRequireITSpureSA; 
   if(reco.fResidualEta)
   {
     // assign or copy construct
@@ -297,18 +298,18 @@ AliEMCALRecoUtils & AliEMCALRecoUtils::operator = (const AliEMCALRecoUtils & rec
 AliEMCALRecoUtils::~AliEMCALRecoUtils()
 {
   //Destructor.
-       
+  
   if(fEMCALRecalibrationFactors) 
   { 
     fEMCALRecalibrationFactors->Clear();
     delete fEMCALRecalibrationFactors;
-  }    
+  }  
   
   if(fEMCALTimeRecalibrationFactors) 
   { 
     fEMCALTimeRecalibrationFactors->Clear();
     delete fEMCALTimeRecalibrationFactors;
-  }    
+  }  
   
   if(fEMCALBadChannelMap) 
   { 
@@ -345,8 +346,8 @@ Bool_t AliEMCALRecoUtils::AcceptCalibrateCell(const Int_t absID, const Int_t bc,
     return kFALSE; 
   }
   
-  geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);       
-  
+  geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);  
+
   // Do not include bad channels found in analysis,
   if( IsBadChannelsRemovalSwitchedOn() && GetEMCALChannelStatus(imod, ieta, iphi)) 
   {
@@ -372,9 +373,9 @@ Bool_t AliEMCALRecoUtils::CheckCellFiducialRegion(const AliEMCALGeometry* geom,
                                                   const AliVCluster* cluster, 
                                                   AliVCaloCells* cells) 
 {
-       // Given the list of AbsId of the cluster, get the maximum cell and 
-       // check if there are fNCellsFromBorder from the calorimeter border
-       
+  // Given the list of AbsId of the cluster, get the maximum cell and 
+  // check if there are fNCellsFromBorder from the calorimeter border
+  
   if(!cluster)
   {
     AliInfo("Cluster pointer null!");
@@ -382,20 +383,20 @@ Bool_t AliEMCALRecoUtils::CheckCellFiducialRegion(const AliEMCALGeometry* geom,
   }
   
   //If the distance to the border is 0 or negative just exit accept all clusters
-       if(cells->GetType()==AliVCaloCells::kEMCALCell && fNCellsFromEMCALBorder <= 0 ) return kTRUE;
+  if(cells->GetType()==AliVCaloCells::kEMCALCell && fNCellsFromEMCALBorder <= 0 ) return kTRUE;
   
-  Int_t absIdMax       = -1, iSM =-1, ieta = -1, iphi = -1;
+  Int_t absIdMax  = -1, iSM =-1, ieta = -1, iphi = -1;
   Bool_t shared = kFALSE;
   GetMaxEnergyCell(geom, cells, cluster, absIdMax,  iSM, ieta, iphi, shared);
   
   AliDebug(2,Form("Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f, Ncells from border %d, EMCAL eta=0 %d\n", 
                   absIdMax, cells->GetCellAmplitude(absIdMax), cluster->E(), fNCellsFromEMCALBorder, fNoEMCALBorderAtEta0));
-       
-       if(absIdMax==-1) return kFALSE;
-       
-       //Check if the cell is close to the borders:
-       Bool_t okrow = kFALSE;
-       Bool_t okcol = kFALSE;
+  
+  if(absIdMax==-1) return kFALSE;
+  
+  //Check if the cell is close to the borders:
+  Bool_t okrow = kFALSE;
+  Bool_t okcol = kFALSE;
   
   if(iSM < 0 || iphi < 0 || ieta < 0 ) 
   {
@@ -426,30 +427,30 @@ Bool_t AliEMCALRecoUtils::CheckCellFiducialRegion(const AliEMCALGeometry* geom,
   {
     if(iSM%2==0)
     {
-      if(ieta >= fNCellsFromEMCALBorder)     okcol = kTRUE;    
+      if(ieta >= fNCellsFromEMCALBorder)     okcol = kTRUE;  
     }
     else 
     {
-      if(ieta <  48-fNCellsFromEMCALBorder)  okcol = kTRUE;    
+      if(ieta <  48-fNCellsFromEMCALBorder)  okcol = kTRUE;  
     }
   }//eta 0 not checked
   
   AliDebug(2,Form("EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d:  column? %d, row? %d\nq",
                   fNCellsFromEMCALBorder, ieta, iphi, iSM, okcol, okrow));
-       
-       if (okcol && okrow) 
+  
+  if (okcol && okrow) 
   {
     //printf("Accept\n");
     return kTRUE;
   }
-       else  
+  else  
   {
     //printf("Reject\n");
     AliDebug(2,Form("Reject cluster in border, max cell : ieta %d, iphi %d, SM %d\n",ieta, iphi, iSM));
     return kFALSE;
   }
-       
-}      
+  
+}  
 
 
 //_______________________________________________________________________________
@@ -459,10 +460,10 @@ Bool_t AliEMCALRecoUtils::ClusterContainsBadChannel(const AliEMCALGeometry* geom
 {
   // Check that in the cluster cells, there is no bad channel of those stored 
   // in fEMCALBadChannelMap or fPHOSBadChannelMap
-       
+  
   if(!fRemoveBadChannels)  return kFALSE;
   if(!fEMCALBadChannelMap) return kFALSE;
-       
+  
   Int_t icol = -1;
   Int_t irow = -1;
   Int_t imod = -1;
@@ -472,66 +473,67 @@ Bool_t AliEMCALRecoUtils::ClusterContainsBadChannel(const AliEMCALGeometry* geom
     Int_t iTower = -1, iIphi = -1, iIeta = -1; 
     geom->GetCellIndex(cellList[iCell],imod,iTower,iIphi,iIeta); 
     if(fEMCALBadChannelMap->GetEntries() <= imod) continue;
-    geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);                     
+    geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);      
     if(GetEMCALChannelStatus(imod, icol, irow))
     {
       AliDebug(2,Form("Cluster with bad channel: SM %d, col %d, row %d\n",imod, icol, irow));
       return kTRUE;
     }
-               
+    
   }// cell cluster loop
-       
+  
   return kFALSE;
 }
 
-//_____________________________________________________________________________________________
-Bool_t AliEMCALRecoUtils::IsExoticCell(const Int_t absID, AliVCaloCells* cells, const Int_t bc)
-{
-  // Look to cell neighbourhood and reject if it seems exotic
-  // Do before recalibrating the cells
 
-  if(!fRejectExoticCells) return kFALSE;
+//___________________________________________________________________________
+Float_t AliEMCALRecoUtils::GetECross(const Int_t absID, const Double_t tcell,
+                                     AliVCaloCells* cells, const Int_t bc)
+{
+  //Calculate the energy in the cross around the energy given cell
   
   AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
   
   Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1; 
   geom->GetCellIndex(absID,imod,iTower,iIphi,iIeta); 
-  geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);       
+  geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);  
   
   //Get close cells index, energy and time, not in corners
   
-  Int_t absID1 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi+1, ieta);
-  Int_t absID2 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi-1, ieta);
+  Int_t absID1 = -1;
+  Int_t absID2 = -1;
+  
+  if( iphi < AliEMCALGeoParams::fgkEMCALRows-1) absID1 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi+1, ieta);
+  if( iphi > 0 )                                absID2 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi-1, ieta);
   
   // In case of cell in eta = 0 border, depending on SM shift the cross cell index
+  
   Int_t absID3 = -1;
   Int_t absID4 = -1;
   
-  if     ( ieta == AliEMCALGeoParams::fgkEMCALCols - 1 && !(imod%2) )
+  if     ( ieta == AliEMCALGeoParams::fgkEMCALCols-1 && !(imod%2) )
   {
-    absID3 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, 0);
-    absID4 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta-1); 
+    absID3 = geom-> GetAbsCellIdFromCellIndexes(imod+1, iphi, 0);
+    absID4 = geom-> GetAbsCellIdFromCellIndexes(imod,   iphi, ieta-1); 
   }
   else if( ieta == 0 && imod%2 )
   {
-    absID3 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta+1);
-    absID4 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, AliEMCALGeoParams::fgkEMCALCols-1); 
+    absID3 = geom-> GetAbsCellIdFromCellIndexes(imod,   iphi, ieta+1);
+    absID4 = geom-> GetAbsCellIdFromCellIndexes(imod-1, iphi, AliEMCALGeoParams::fgkEMCALCols-1); 
   }
   else
   {
-    absID3 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta+1);
-    absID4 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta-1); 
+    if( ieta < AliEMCALGeoParams::fgkEMCALCols-1 ) 
+      absID3 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta+1);
+    if( ieta > 0 )                                 
+      absID4 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta-1); 
   }
-
-  Float_t  ecell  = 0, ecell1  = 0, ecell2  = 0, ecell3  = 0, ecell4  = 0;
-  Double_t tcell  = 0, tcell1  = 0, tcell2  = 0, tcell3  = 0, tcell4  = 0;
-  Bool_t   accept = 0, accept1 = 0, accept2 = 0, accept3 = 0, accept4 = 0;
   
-  accept  = AcceptCalibrateCell(absID, bc, ecell ,tcell ,cells); 
-    
-  if(!accept) return kTRUE; // reject this cell
+  //printf("IMOD %d, AbsId %d, a %d, b %d, c %d e %d \n",imod,absID,absID1,absID2,absID3,absID4);
   
-  if(ecell < fExoticCellMinAmplitude) return kFALSE; // do not reject low energy cells
+  Float_t  ecell1  = 0, ecell2  = 0, ecell3  = 0, ecell4  = 0;
+  Double_t tcell1  = 0, tcell2  = 0, tcell3  = 0, tcell4  = 0;
+  Bool_t   accept1 = 0, accept2 = 0, accept3 = 0, accept4 = 0;
   
   accept1 = AcceptCalibrateCell(absID1,bc, ecell1,tcell1,cells); 
   accept2 = AcceptCalibrateCell(absID2,bc, ecell2,tcell2,cells); 
@@ -539,26 +541,44 @@ Bool_t AliEMCALRecoUtils::IsExoticCell(const Int_t absID, AliVCaloCells* cells,
   accept4 = AcceptCalibrateCell(absID4,bc, ecell4,tcell4,cells); 
   
   /*
-    printf("Cell absID %d \n",absID);
-    printf("\t  accept1 %d, accept2 %d, accept3 %d, accept4 %d\n",
-           accept1,accept2,accept3,accept4);
-    printf("\t id %d: id1 %d, id2 %d, id3 %d, id4 %d\n",
-           absID,absID1,absID2,absID3,absID4);
-    printf("\t e %f: e1 %f, e2 %f, e3 %f, e4 %f\n",
-           ecell,ecell1,ecell2,ecell3,ecell4);
-    printf("\t t %f: t1 %f, t2 %f, t3 %f, t4 %f;\n dt1 %f, dt2 %f, dt3 %f, dt4 %f\n",
-           tcell*1.e9,tcell1*1.e9,tcell2*1.e9,tcell3*1.e9,tcell4*1.e9,
-           TMath::Abs(tcell-tcell1)*1.e9, TMath::Abs(tcell-tcell2)*1.e9, TMath::Abs(tcell-tcell3)*1.e9, TMath::Abs(tcell-tcell4)*1.e9);
-  */
+   printf("Cell absID %d \n",absID);
+   printf("\t  accept1 %d, accept2 %d, accept3 %d, accept4 %d\n",
+   accept1,accept2,accept3,accept4);
+   printf("\t id %d: id1 %d, id2 %d, id3 %d, id4 %d\n",
+   absID,absID1,absID2,absID3,absID4);
+   printf("\t e %f: e1 %f, e2 %f, e3 %f, e4 %f\n",
+   ecell,ecell1,ecell2,ecell3,ecell4);
+   printf("\t t %f: t1 %f, t2 %f, t3 %f, t4 %f;\n dt1 %f, dt2 %f, dt3 %f, dt4 %f\n",
+   tcell*1.e9,tcell1*1.e9,tcell2*1.e9,tcell3*1.e9,tcell4*1.e9,
+   TMath::Abs(tcell-tcell1)*1.e9, TMath::Abs(tcell-tcell2)*1.e9, TMath::Abs(tcell-tcell3)*1.e9, TMath::Abs(tcell-tcell4)*1.e9);
+   */
   
   if(TMath::Abs(tcell-tcell1)*1.e9 > fExoticCellDiffTime) ecell1 = 0 ;
   if(TMath::Abs(tcell-tcell2)*1.e9 > fExoticCellDiffTime) ecell2 = 0 ;
   if(TMath::Abs(tcell-tcell3)*1.e9 > fExoticCellDiffTime) ecell3 = 0 ;
   if(TMath::Abs(tcell-tcell4)*1.e9 > fExoticCellDiffTime) ecell4 = 0 ;
+  
+  return ecell1+ecell2+ecell3+ecell4;
+  
+}
 
-  Float_t eCross = ecell1+ecell2+ecell3+ecell4;
+//_____________________________________________________________________________________________
+Bool_t AliEMCALRecoUtils::IsExoticCell(const Int_t absID, AliVCaloCells* cells, const Int_t bc)
+{
+  // Look to cell neighbourhood and reject if it seems exotic
+  // Do before recalibrating the cells
 
-  //printf("\t eCell %f, eCross %f, 1-eCross/eCell %f\n",ecell,eCross,1-eCross/ecell);
+  if(!fRejectExoticCells) return kFALSE;
+  
+  Float_t  ecell  = 0;
+  Double_t tcell  = 0;
+  Bool_t   accept = AcceptCalibrateCell(absID, bc, ecell ,tcell ,cells); 
+  
+  if(!accept) return kTRUE; // reject this cell
+  
+  if(ecell < fExoticCellMinAmplitude) return kFALSE; // do not reject low energy cells
+
+  Float_t eCross = GetECross(absID,tcell,cells,bc);
   
   if(1-eCross/ecell > fExoticCellFraction) 
   {
@@ -632,29 +652,63 @@ Float_t AliEMCALRecoUtils::CorrectClusterEnergyLinearity(AliVCluster* cluster)
   
   Float_t energy = cluster->E();
 
+  if(energy < 0.05)
+  {
+    // Clusters with less than 50 MeV or negative are not possible
+    AliInfo(Form("Too Low Cluster energy!, E = %f < 0.05 GeV",energy));
+    return 0;
+  }
+  
   switch (fNonLinearityFunction) 
   {
       
     case kPi0MC:
     {
       //Non-Linearity correction (from MC with function ([0]*exp(-[1]/E))+(([2]/([3]*2.*TMath::Pi())*exp(-(E-[4])^2/(2.*[3]^2)))))
-      //Double_t fNonLinearityParams[0] = 1.014;
-      //Double_t fNonLinearityParams[1] = -0.03329;
-      //Double_t fNonLinearityParams[2] = -0.3853;
-      //Double_t fNonLinearityParams[3] = 0.5423;
-      //Double_t fNonLinearityParams[4] = -0.4335;
+      //fNonLinearityParams[0] = 1.014;
+      //fNonLinearityParams[1] =-0.03329;
+      //fNonLinearityParams[2] =-0.3853;
+      //fNonLinearityParams[3] = 0.5423;
+      //fNonLinearityParams[4] =-0.4335;
        energy *= (fNonLinearityParams[0]*exp(-fNonLinearityParams[1]/energy))+
                   ((fNonLinearityParams[2]/(fNonLinearityParams[3]*2.*TMath::Pi())*
                     exp(-(energy-fNonLinearityParams[4])*(energy-fNonLinearityParams[4])/(2.*fNonLinearityParams[3]*fNonLinearityParams[3]))));
       break;
     }
      
+    case kPi0MCv2:
+    {
+      //Non-Linearity correction (from MC with function [0]/((x+[1])^[2]))+1;
+      //fNonLinearityParams[0] = 3.11111e-02;
+      //fNonLinearityParams[1] =-5.71666e-02; 
+      //fNonLinearityParams[2] = 5.67995e-01;      
+      
+      energy *= fNonLinearityParams[0]/TMath::Power(energy+fNonLinearityParams[1],fNonLinearityParams[2])+1;
+      break;
+    }
+    
+    case kPi0MCv3:
+    {
+      //Same as beam test corrected, change parameters
+      //fNonLinearityParams[0] =  9.81039e-01
+      //fNonLinearityParams[1] =  1.13508e-01;
+      //fNonLinearityParams[2] =  1.00173e+00; 
+      //fNonLinearityParams[3] =  9.67998e-02;
+      //fNonLinearityParams[4] =  2.19381e+02;
+      //fNonLinearityParams[5] =  6.31604e+01;
+      //fNonLinearityParams[6] =  1;
+      energy *= fNonLinearityParams[6]/(fNonLinearityParams[0]*(1./(1.+fNonLinearityParams[1]*exp(-energy/fNonLinearityParams[2]))*1./(1.+fNonLinearityParams[3]*exp((energy-fNonLinearityParams[4])/fNonLinearityParams[5]))));
+      
+      break;
+    }
+      
+      
     case kPi0GammaGamma:
     {
       //Non-Linearity correction (from Olga Data with function p0+p1*exp(-p2*E))
-      //Double_t fNonLinearityParams[0] = 1.04;
-      //Double_t fNonLinearityParams[1] = -0.1445;
-      //Double_t fNonLinearityParams[2] = 1.046;
+      //fNonLinearityParams[0] = 1.04;
+      //fNonLinearityParams[1] = -0.1445;
+      //fNonLinearityParams[2] = 1.046;
       energy /= (fNonLinearityParams[0]+fNonLinearityParams[1]*exp(-fNonLinearityParams[2]*energy)); //Olga function
       break;
     }
@@ -711,7 +765,7 @@ Float_t AliEMCALRecoUtils::CorrectClusterEnergyLinearity(AliVCluster* cluster)
 void AliEMCALRecoUtils::InitNonLinearityParam()
 {
   //Initialising Non Linearity Parameters
-       
+  
   if(fNonLinearityFunction == kPi0MC) 
   {
     fNonLinearityParams[0] = 1.014;
@@ -721,19 +775,37 @@ void AliEMCALRecoUtils::InitNonLinearityParam()
     fNonLinearityParams[4] = -0.4335;
   }
   
+  if(fNonLinearityFunction == kPi0MCv2) 
+  {
+    fNonLinearityParams[0] = 3.11111e-02;
+    fNonLinearityParams[1] =-5.71666e-02; 
+    fNonLinearityParams[2] = 5.67995e-01;      
+  }
+  
+  if(fNonLinearityFunction == kPi0MCv3) 
+  {
+    fNonLinearityParams[0] =  9.81039e-01;
+    fNonLinearityParams[1] =  1.13508e-01;
+    fNonLinearityParams[2] =  1.00173e+00; 
+    fNonLinearityParams[3] =  9.67998e-02;
+    fNonLinearityParams[4] =  2.19381e+02;
+    fNonLinearityParams[5] =  6.31604e+01;
+    fNonLinearityParams[6] =  1;
+  }
+  
   if(fNonLinearityFunction == kPi0GammaGamma) 
   {
     fNonLinearityParams[0] = 1.04;
     fNonLinearityParams[1] = -0.1445;
     fNonLinearityParams[2] = 1.046;
-  }    
+  }  
 
   if(fNonLinearityFunction == kPi0GammaConversion) 
   {
     fNonLinearityParams[0] = 0.139393;
     fNonLinearityParams[1] = 0.0566186;
     fNonLinearityParams[2] = 0.982133;
-  }    
+  }  
 
   if(fNonLinearityFunction == kBeamTest) 
   {
@@ -780,15 +852,22 @@ Float_t  AliEMCALRecoUtils::GetDepth(const Float_t energy,
   Float_t x0    = 1.31;
   Float_t ecr   = 8;
   Float_t depth = 0;
+  Float_t arg   = energy*1000/ ecr; //Multiply energy by 1000 to transform to MeV
   
   switch ( iParticle )
   {
     case kPhoton:
-      depth = x0 * (TMath::Log(energy*1000/ ecr) + 0.5); //Multiply energy by 1000 to transform to MeV
+      if (arg < 1) 
+       depth = 0;
+      else
+       depth = x0 * (TMath::Log(arg) + 0.5); 
       break;
       
     case kElectron:
-      depth = x0 * (TMath::Log(energy*1000/ ecr) - 0.5); //Multiply energy by 1000 to transform to MeV
+      if (arg < 1) 
+       depth = 0;
+      else
+       depth = x0 * (TMath::Log(arg) - 0.5); 
       break;
       
     case kHadron:
@@ -811,13 +890,19 @@ Float_t  AliEMCALRecoUtils::GetDepth(const Float_t energy,
       }
       else
       {//electron
-        depth = x0 * (TMath::Log(energy*1000 / ecr)  - 0.5); //Multiply energy by 1000 to transform to MeV
+       if (arg < 1) 
+         depth = 0;
+       else
+         depth = x0 * (TMath::Log(arg) - 0.5); 
       }
         
       break;
       
     default://photon
-      depth = x0 * (TMath::Log(energy*1000 / ecr) + 0.5); //Multiply energy by 1000 to transform to MeV
+      if (arg < 1) 
+       depth = 0;
+      else
+       depth = x0 * (TMath::Log(arg) + 0.5);
   }  
   
   return depth;
@@ -941,6 +1026,8 @@ void AliEMCALRecoUtils::InitParameters()
   fCutMaxDCAToVertexZ  = 1e10;              
   fCutDCAToVertex2D    = kFALSE;
   
+  fCutRequireITSStandAlone = kFALSE; //MARCEL
+  fCutRequireITSpureSA     = kFALSE; //Marcel
   
   //Misalignment matrices
   for(Int_t i = 0; i < 15 ; i++) 
@@ -978,7 +1065,7 @@ void AliEMCALRecoUtils::InitEMCALRecalibrationFactors()
 {
   //Init EMCAL recalibration factors
   AliDebug(2,"AliCalorimeterUtils::InitEMCALRecalibrationFactors()");
-       //In order to avoid rewriting the same histograms
+  //In order to avoid rewriting the same histograms
   Bool_t oldStatus = TH1::AddDirectoryStatus();
   TH1::AddDirectory(kFALSE);
   
@@ -1000,9 +1087,9 @@ void AliEMCALRecoUtils::InitEMCALRecalibrationFactors()
   
   fEMCALRecalibrationFactors->SetOwner(kTRUE);
   fEMCALRecalibrationFactors->Compress();
-       
+  
   //In order to avoid rewriting the same histograms
-  TH1::AddDirectory(oldStatus);                
+  TH1::AddDirectory(oldStatus);    
 }
 
 //_________________________________________________________
@@ -1030,7 +1117,7 @@ void AliEMCALRecoUtils::InitEMCALTimeRecalibrationFactors()
   fEMCALTimeRecalibrationFactors->Compress();
   
   //In order to avoid rewriting the same histograms
-  TH1::AddDirectory(oldStatus);                
+  TH1::AddDirectory(oldStatus);    
 }
 
 //____________________________________________________
@@ -1053,7 +1140,7 @@ void AliEMCALRecoUtils::InitEMCALBadChannelStatusMap()
   fEMCALBadChannelMap->Compress();
   
   //In order to avoid rewriting the same histograms
-  TH1::AddDirectory(oldStatus);                
+  TH1::AddDirectory(oldStatus);    
 }
 
 //____________________________________________________________________________
@@ -1065,7 +1152,7 @@ void AliEMCALRecoUtils::RecalibrateClusterEnergy(const AliEMCALGeometry* geom,
   // Recalibrate the cluster energy and Time, considering the recalibration map 
   // and the energy of the cells and time that compose the cluster.
   // bc= bunch crossing number returned by esdevent->GetBunchCrossNumber();
-       
+  
   if(!cluster)
   {
     AliInfo("Cluster pointer null!");
@@ -1076,7 +1163,7 @@ void AliEMCALRecoUtils::RecalibrateClusterEnergy(const AliEMCALGeometry* geom,
   UShort_t * index    = cluster->GetCellsAbsId() ;
   Double_t * fraction = cluster->GetCellsAmplitudeFraction() ;
   Int_t ncells = cluster->GetNCells();
-       
+  
   //Initialize some used variables
   Float_t energy = 0;
   Int_t   absId  =-1;
@@ -1098,7 +1185,7 @@ void AliEMCALRecoUtils::RecalibrateClusterEnergy(const AliEMCALGeometry* geom,
       Int_t iTower = -1, iIphi = -1, iIeta = -1; 
       geom->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
       if(fEMCALRecalibrationFactors->GetEntries() <= imod) continue;
-      geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);                   
+      geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);      
       factor = GetEMCALChannelRecalibrationFactor(imod,icol,irow);
       
       AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - recalibrate cell: module %d, col %d, row %d, cell fraction %f,recalibration factor %f, cell energy %f\n",
@@ -1114,22 +1201,21 @@ void AliEMCALRecoUtils::RecalibrateClusterEnergy(const AliEMCALGeometry* geom,
       absIdMax = absId;
     }
   }
-       
+  
   AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - Energy before %f, after %f \n",cluster->E(),energy));
 
   cluster->SetE(energy);
 
-  // Recalculate time of cluster   
+  // Recalculate time of cluster
   Double_t timeorg = cluster->GetTOF();
+
+  Double_t time = cells->GetCellTime(absIdMax);
   if(!fCellsRecalibrated && IsTimeRecalibrationOn())
-  {
-    Double_t time = timeorg;
     RecalibrateCellTime(absIdMax,bc,time);
-    cluster->SetTOF(time);
-  } 
 
-  AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - Time before %f, after %f \n",timeorg,cluster->GetTOF()));
+  cluster->SetTOF(time);
 
+  AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - Time before %f, after %f \n",timeorg,cluster->GetTOF()));
 }
 
 //_____________________________________________________________
@@ -1140,7 +1226,7 @@ void AliEMCALRecoUtils::RecalibrateCells(AliVCaloCells * cells,
   // of the cells that compose the cluster.
   // bc= bunch crossing number returned by esdevent->GetBunchCrossNumber();
 
-  if(!IsRecalibrationOn() && !IsTimeRecalibrationOn()) return;
+  if(!IsRecalibrationOn() && !IsTimeRecalibrationOn() && !IsBadChannelsRemovalSwitchedOn()) return;
   
   if(!cells)
   {
@@ -1148,25 +1234,29 @@ void AliEMCALRecoUtils::RecalibrateCells(AliVCaloCells * cells,
     return;
   }  
   
-  Int_t    absId  =-1;
+  Short_t  absId  =-1;
   Bool_t   accept = kFALSE;
   Float_t  ecell  = 0;
   Double_t tcell  = 0;
+  Double_t ecellin = 0;
+  Double_t tcellin = 0;
+  Short_t  mclabel = -1;
+  Double_t efrac = 0;
   
   Int_t nEMcell  = cells->GetNumberOfCells() ;  
   for (Int_t iCell = 0; iCell < nEMcell; iCell++) 
   { 
-    absId  = cells->GetCellNumber(iCell);
+    cells->GetCell( iCell, absId, ecellin, tcellin, mclabel, efrac );
     
     accept = AcceptCalibrateCell(absId, bc, ecell ,tcell ,cells); 
     if(!accept) 
     {
       ecell = 0;
-      tcell = 0;
+      tcell = -1;
     }
     
     //Set new values
-    cells->SetCell(iCell,absId,ecell, tcell);
+    cells->SetCell(iCell,absId,ecell, tcell, mclabel, efrac);
   }
 
   fCellsRecalibrated = kTRUE;
@@ -1223,6 +1313,8 @@ void AliEMCALRecoUtils::RecalculateClusterPositionFromTowerGlobal(const AliEMCAL
   Bool_t shared = kFALSE;
 
   Float_t  clEnergy = clu->E(); //Energy already recalibrated previously
+  if (clEnergy <= 0)
+    return;
   GetMaxEnergyCell(geom, cells, clu, absId,  iSupModMax, ieta, iphi,shared);
   Double_t depth = GetDepth(clEnergy,fParticleType,iSupModMax) ;
   
@@ -1237,7 +1329,7 @@ void AliEMCALRecoUtils::RecalculateClusterPositionFromTowerGlobal(const AliEMCAL
     if (!fCellsRecalibrated)
     {
       geom->GetCellIndex(absId,iSM,iTower,iIphi,iIeta); 
-      geom->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);                    
+      geom->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);      
       
       if(IsRecalibrationOn()) 
       {
@@ -1306,6 +1398,8 @@ void AliEMCALRecoUtils::RecalculateClusterPositionFromTowerIndex(const AliEMCALG
   Bool_t shared = kFALSE;
 
   Float_t clEnergy = clu->E(); //Energy already recalibrated previously.
+  if (clEnergy <= 0)
+    return;
   GetMaxEnergyCell(geom, cells, clu, absId,  iSupModMax, ieta, iphi,shared);
   Float_t  depth = GetDepth(clEnergy,fParticleType,iSupMod) ;
 
@@ -1325,7 +1419,7 @@ void AliEMCALRecoUtils::RecalculateClusterPositionFromTowerIndex(const AliEMCALG
     eCell  = cells->GetCellAmplitude(absId);
     
     geom->GetCellIndex(absId,iSupMod,iTower,iIphi,iIeta); 
-    geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);          
+    geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);    
     
     if (!fCellsRecalibrated)
     {
@@ -1379,12 +1473,12 @@ void AliEMCALRecoUtils::RecalculateClusterDistanceToBadChannel(const AliEMCALGeo
   }  
   
   //Get channels map of the supermodule where the cluster is.
-  Int_t absIdMax       = -1, iSupMod =-1, icolM = -1, irowM = -1;
+  Int_t absIdMax  = -1, iSupMod =-1, icolM = -1, irowM = -1;
   Bool_t shared = kFALSE;
   GetMaxEnergyCell(geom, cells, cluster, absIdMax,  iSupMod, icolM, irowM, shared);
   TH2D* hMap  = (TH2D*)fEMCALBadChannelMap->At(iSupMod);
 
-  Int_t dRrow, dRcol;  
+  Int_t dRrow, dRcol;  
   Float_t  minDist = 10000.;
   Float_t  dist    = 0.;
   
@@ -1463,16 +1557,19 @@ void AliEMCALRecoUtils::RecalculateClusterPID(AliVCluster * cluster)
   if ( cluster->GetM02() != 0)
     fPIDUtils->ComputePID(cluster->E(),cluster->GetM02());
   
-  Float_t pidlist[AliPID::kSPECIESN+1];
-       for(Int_t i = 0; i < AliPID::kSPECIESN+1; i++) pidlist[i] = fPIDUtils->GetPIDFinal(i);
+  Float_t pidlist[AliPID::kSPECIESCN+1];
+  for(Int_t i = 0; i < AliPID::kSPECIESCN+1; i++) pidlist[i] = fPIDUtils->GetPIDFinal(i);
         
   cluster->SetPID(pidlist);
 }
 
-//____________________________________________________________________________________________
+//___________________________________________________________________________________________________________________
 void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGeometry * geom, 
                                                                 AliVCaloCells* cells, 
-                                                                AliVCluster * cluster)
+                                                                AliVCluster * cluster,
+                                                                Float_t & l0,   Float_t & l1,   
+                                                                Float_t & disp, Float_t & dEta, Float_t & dPhi,
+                                                                Float_t & sEta, Float_t & sPhi, Float_t & sEtaPhi)
 {
   // Calculates new center of gravity in the local EMCAL-module coordinates 
   // and tranfers into global ALICE coordinates
@@ -1484,28 +1581,24 @@ void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGe
     return;
   }
     
-  Int_t nstat  = 0;
-  Float_t wtot = 0. ;
   Double_t eCell       = 0.;
   Float_t  fraction    = 1.;
   Float_t  recalFactor = 1.;
 
-  Int_t iSupMod = -1;
-  Int_t iTower  = -1;
-  Int_t iIphi   = -1;
-  Int_t iIeta   = -1;
-  Int_t iphi    = -1;
-  Int_t ieta    = -1;
-  Double_t etai = -1.;
-  Double_t phii = -1.;
-  
-  Double_t w     = 0.;
-  Double_t d     = 0.;
-  Double_t dxx   = 0.;
-  Double_t dzz   = 0.;
-  Double_t dxz   = 0.;  
-  Double_t xmean = 0.;
-  Double_t zmean = 0.;
+  Int_t    iSupMod = -1;
+  Int_t    iTower  = -1;
+  Int_t    iIphi   = -1;
+  Int_t    iIeta   = -1;
+  Int_t    iphi    = -1;
+  Int_t    ieta    = -1;
+  Double_t etai    = -1.;
+  Double_t phii    = -1.;
+  
+  Int_t    nstat   = 0 ;
+  Float_t  wtot    = 0.;
+  Double_t w       = 0.;
+  Double_t etaMean = 0.;
+  Double_t phiMean = 0.;
     
   //Loop on cells
   for(Int_t iDigit=0; iDigit < cluster->GetNCells(); iDigit++) 
@@ -1533,33 +1626,34 @@ void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGe
       w  = GetCellWeight(eCell,cluster->E());
       
       etai=(Double_t)ieta;
-      phii=(Double_t)iphi;             
+      phii=(Double_t)iphi;  
+      
       if(w > 0.0) 
       {
         wtot += w ;
-        nstat++;                       
+        nstat++;            
         //Shower shape
-        dxx  += w * etai * etai ;
-        xmean+= w * etai ;
-        dzz  += w * phii * phii ;
-        zmean+= w * phii ; 
-        dxz  += w * etai * phii ; 
+        sEta     += w * etai * etai ;
+        etaMean  += w * etai ;
+        sPhi     += w * phii * phii ;
+        phiMean  += w * phii ; 
+        sEtaPhi  += w * etai * phii ; 
       }
     } 
     else
       AliError(Form("Wrong energy %f and/or amplitude %f\n", eCell, cluster->E()));
   }//cell loop
   
-  //Normalize to the weight    
+  //Normalize to the weight  
   if (wtot > 0) 
   {
-    xmean /= wtot ;
-    zmean /= wtot ;
+    etaMean /= wtot ;
+    phiMean /= wtot ;
   }
   else
     AliError(Form("Wrong weight %f\n", wtot));
   
-  //Calculate dispersion       
+  //Calculate dispersion  
   for(Int_t iDigit=0; iDigit < cluster->GetNCells(); iDigit++) 
   {
     //Get from the absid the supermodule, tower and eta/phi numbers
@@ -1580,8 +1674,13 @@ void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGe
       w  = GetCellWeight(eCell,cluster->E());
       
       etai=(Double_t)ieta;
-      phii=(Double_t)iphi;             
-      if(w > 0.0)  d +=  w*((etai-xmean)*(etai-xmean)+(phii-zmean)*(phii-zmean)); 
+      phii=(Double_t)iphi;    
+      if(w > 0.0) 
+      { 
+        disp +=  w *((etai-etaMean)*(etai-etaMean)+(phii-phiMean)*(phii-phiMean)); 
+        dEta +=  w * (etai-etaMean)*(etai-etaMean) ; 
+        dPhi +=  w * (phii-phiMean)*(phii-phiMean) ; 
+      }
     }
     else
       AliError(Form("Wrong energy %f and/or amplitude %f\n", eCell, cluster->E()));
@@ -1590,29 +1689,52 @@ void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGe
   //Normalize to the weigth and set shower shape parameters
   if (wtot > 0 && nstat > 1) 
   {
-    d /= wtot ;
-    dxx /= wtot ;
-    dzz /= wtot ;
-    dxz /= wtot ;
-    dxx -= xmean * xmean ;
-    dzz -= zmean * zmean ;
-    dxz -= xmean * zmean ;
-    cluster->SetM02(0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ));
-    cluster->SetM20(0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ));
+    disp    /= wtot ;
+    dEta    /= wtot ;
+    dPhi    /= wtot ;
+    sEta    /= wtot ;
+    sPhi    /= wtot ;
+    sEtaPhi /= wtot ;
+    
+    sEta    -= etaMean * etaMean ;
+    sPhi    -= phiMean * phiMean ;
+    sEtaPhi -= etaMean * phiMean ;
+    
+    l0 = (0.5 * (sEta + sPhi) + TMath::Sqrt( 0.25 * (sEta - sPhi) * (sEta - sPhi) + sEtaPhi * sEtaPhi ));
+    l1 = (0.5 * (sEta + sPhi) - TMath::Sqrt( 0.25 * (sEta - sPhi) * (sEta - sPhi) + sEtaPhi * sEtaPhi ));
   }
   else
   {
-    d=0. ;
-    cluster->SetM20(0.) ;
-    cluster->SetM02(0.) ;
-  }    
+    l0   = 0. ;
+    l1   = 0. ;
+    dEta = 0. ; dPhi = 0. ; disp    = 0. ;
+    sEta = 0. ; sPhi = 0. ; sEtaPhi = 0. ;
+  }  
   
-  if (d>=0)
-    cluster->SetDispersion(TMath::Sqrt(d)) ;
-  else    
-    cluster->SetDispersion(0) ;
 }
 
+//____________________________________________________________________________________________
+void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGeometry * geom, 
+                                                                AliVCaloCells* cells, 
+                                                                AliVCluster * cluster)
+{
+  // Calculates new center of gravity in the local EMCAL-module coordinates 
+  // and tranfers into global ALICE coordinates
+  // Calculates Dispersion and main axis and puts them into the cluster
+  
+  Float_t l0   = 0., l1   = 0.;
+  Float_t disp = 0., dEta = 0., dPhi    = 0.; 
+  Float_t sEta = 0., sPhi = 0., sEtaPhi = 0.;
+  
+  AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(geom,cells,cluster,l0,l1,disp,
+                                                             dEta, dPhi, sEta, sPhi, sEtaPhi);
+  
+  cluster->SetM02(l0);
+  cluster->SetM20(l1);
+  if(disp > 0. ) cluster->SetDispersion(TMath::Sqrt(disp)) ;
+  
+} 
+
 //____________________________________________________________________________
 void AliEMCALRecoUtils::FindMatches(AliVEvent *event,
                                     TObjArray * clusterArr,  
@@ -1658,16 +1780,29 @@ void AliEMCALRecoUtils::FindMatches(AliVEvent *event,
     
   } // Init mag field
   
+  if (esdevent) {
+    UInt_t mask1 = esdevent->GetESDRun()->GetDetectorsInDAQ();
+    UInt_t mask2 = esdevent->GetESDRun()->GetDetectorsInReco();
+    Bool_t desc1 = (mask1 >> 3) & 0x1;
+    Bool_t desc2 = (mask2 >> 3) & 0x1;
+    if (desc1==0 || desc2==0) { 
+      AliError(Form("TPC not in DAQ/RECO: %u (%u)/%u (%u)", 
+      mask1, esdevent->GetESDRun()->GetDetectorsInReco(),
+      mask2, esdevent->GetESDRun()->GetDetectorsInDAQ()));
+      fITSTrackSA=kTRUE;
+    }
+  }
+
   TObjArray *clusterArray = 0x0;
   if(!clusterArr)
     {
       clusterArray = new TObjArray(event->GetNumberOfCaloClusters());
       for(Int_t icl=0; icl<event->GetNumberOfCaloClusters(); icl++)
-       {
-         AliVCluster *cluster = (AliVCluster*) event->GetCaloCluster(icl);
-         if(geom && !IsGoodCluster(cluster,geom,(AliVCaloCells*)event->GetEMCALCells())) continue;
-         clusterArray->AddAt(cluster,icl);
-       }
+  {
+    AliVCluster *cluster = (AliVCluster*) event->GetCaloCluster(icl);
+    if(geom && !IsGoodCluster(cluster,geom,(AliVCaloCells*)event->GetEMCALCells())) continue;
+    clusterArray->AddAt(cluster,icl);
+  }
     }
   
   Int_t    matched=0;
@@ -1688,7 +1823,10 @@ void AliEMCALRecoUtils::FindMatches(AliVEvent *event,
       if(esdTrack->Pt()<fCutMinTrackPt) continue;
       Double_t phi = esdTrack->Phi()*TMath::RadToDeg();
       if(TMath::Abs(esdTrack->Eta())>0.8 || phi <= 20 || phi >= 240 ) continue;
-      trackParam =  const_cast<AliExternalTrackParam*>(esdTrack->GetInnerParam());
+      if(!fITSTrackSA)
+       trackParam =  const_cast<AliExternalTrackParam*>(esdTrack->GetInnerParam());  // if TPC Available
+      else
+       trackParam =  new AliExternalTrackParam(*esdTrack); // If ITS Track Standing alone              
     }
     
     //If the input event is AOD, the starting point for extrapolation is at vertex
@@ -1713,10 +1851,10 @@ void AliEMCALRecoUtils::FindMatches(AliVEvent *event,
     {
       printf("Wrong input data type! Should be \"AOD\" or \"ESD\"\n");
       if(clusterArray)
-       {
-         clusterArray->Clear();
-         delete clusterArray;
-       }
+  {
+    clusterArray->Clear();
+    delete clusterArray;
+  }
       return;
     }
     
@@ -1727,19 +1865,19 @@ void AliEMCALRecoUtils::FindMatches(AliVEvent *event,
     Float_t eta, phi;
     if(!ExtrapolateTrackToEMCalSurface(&emcalParam, 430., fMass, fStepSurface, eta, phi)) 
       {
-       if(aodevent && trackParam) delete trackParam;
-       continue;
+  if(aodevent && trackParam) delete trackParam;
+  continue;
       }
 
 //    if(esdevent)
 //      {
-//     esdTrack->SetOuterParam(&emcalParam,AliExternalTrackParam::kMultSec);
+//  esdTrack->SetOuterParam(&emcalParam,AliExternalTrackParam::kMultSec);
 //      }
 
     if(TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad())
       {
-       if(aodevent && trackParam) delete trackParam;
-       continue;
+  if(aodevent && trackParam) delete trackParam;
+  continue;
       }
 
 
@@ -1748,11 +1886,11 @@ void AliEMCALRecoUtils::FindMatches(AliVEvent *event,
     Float_t dEta = -999, dPhi = -999;
     if(!clusterArr)
       {
-       index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArray, dEta, dPhi);  
+  index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArray, dEta, dPhi);  
       }
     else
       {
-       index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArr, dEta, dPhi);  
+  index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArr, dEta, dPhi);  
       }  
     
     if(index>-1)
@@ -1792,7 +1930,12 @@ Int_t AliEMCALRecoUtils::FindMatchedClusterInEvent(const AliESDtrack *track,
   Int_t index = -1;
   Double_t phiV = track->Phi()*TMath::RadToDeg();
   if(TMath::Abs(track->Eta())>0.8 || phiV <= 20 || phiV >= 240 ) return index;
-  AliExternalTrackParam *trackParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
+  AliExternalTrackParam *trackParam = 0;
+  if(!fITSTrackSA)
+    trackParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());  // If TPC
+  else
+    trackParam = new AliExternalTrackParam(*track);
+    
   if(!trackParam) return index;
   AliExternalTrackParam emcalParam(*trackParam);
   Float_t eta, phi;
@@ -1846,21 +1989,21 @@ Int_t  AliEMCALRecoUtils::FindMatchedClusterInClusterArr(const AliExternalTrackP
         {
           Float_t tmpR=TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi);
           if(tmpR<dRMax)
-           {
-             dRMax=tmpR;
-             dEtaMax=tmpEta;
-             dPhiMax=tmpPhi;
-             index=icl;
-           }
+      {
+        dRMax=tmpR;
+        dEtaMax=tmpEta;
+        dPhiMax=tmpPhi;
+        index=icl;
+      }
         }
       else if(fCutEtaPhiSeparate)
         {
           if(TMath::Abs(tmpEta)<TMath::Abs(dEtaMax) && TMath::Abs(tmpPhi)<TMath::Abs(dPhiMax))
-           {
-             dEtaMax = tmpEta;
-             dPhiMax = tmpPhi;
-             index=icl;
-           }
+      {
+        dEtaMax = tmpEta;
+        dPhiMax = tmpPhi;
+        index=icl;
+      }
         }
       else
         {
@@ -2202,9 +2345,24 @@ Bool_t AliEMCALRecoUtils::IsAccepted(AliESDtrack *esdTrack)
     {
       //Require at least one SPD point + anything else in ITS
       if( (esdTrack->HasPointOnITSLayer(0) || esdTrack->HasPointOnITSLayer(1)) == kFALSE)
-       cuts[10] = kTRUE;
+  cuts[10] = kTRUE;
     }
 
+      // ITS
+  if(fCutRequireITSStandAlone || fCutRequireITSpureSA){
+    if ((status & AliESDtrack::kITSin) == 0 || (status & AliESDtrack::kTPCin)){
+      // TPC tracks
+      cuts[11] = kTRUE; 
+    }else{
+      // ITS standalone tracks
+      if(fCutRequireITSStandAlone && !fCutRequireITSpureSA){
+       if(status & AliESDtrack::kITSpureSA) cuts[11] = kTRUE;
+      }else if(fCutRequireITSpureSA){
+       if(!(status & AliESDtrack::kITSpureSA)) cuts[11] = kTRUE;
+      }
+    }
+  }
+  
   Bool_t cut=kFALSE;
   for (Int_t i=0; i<kNCuts; i++)
     if (cuts[i]) { cut = kTRUE ; }
@@ -2269,44 +2427,65 @@ void AliEMCALRecoUtils::InitTrackCuts()
       
       break;
     }
+
+    case kITSStandAlone:
+    {
+      AliInfo(Form("Track cuts for matching: ITS Stand Alone tracks cut w/o DCA cut"));
+      SetRequireITSRefit(kTRUE);
+      SetRequireITSStandAlone(kTRUE);
+      SetITSTrackSA(kTRUE);
+      break;
+    }
+    
   }
 }
 
 
 //________________________________________________________________________
-void AliEMCALRecoUtils::SetClusterMatchedToTrack(const AliESDEvent *event)
+void AliEMCALRecoUtils::SetClusterMatchedToTrack(const AliVEvent *event)
 {
   // Checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track. 
-  
+
   Int_t nTracks = event->GetNumberOfTracks();
   for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack) 
   {
-    AliESDtrack* track = event->GetTrack(iTrack);
+    AliVTrack* track = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
     if (!track) 
     {
       AliWarning(Form("Could not receive track %d", iTrack));
       continue;
     }
     
-    Int_t matchClusIndex = GetMatchedClusterIndex(iTrack);                
+    Int_t matchClusIndex = GetMatchedClusterIndex(iTrack);       
     track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
-    if(matchClusIndex != -1) 
-      track->SetStatus(AliESDtrack::kEMCALmatch);
-    else
-      track->ResetStatus(AliESDtrack::kEMCALmatch);
+    /*the following can be done better if AliVTrack::SetStatus will be there. Patch pending with Andreas/Peter*/
+    AliESDtrack* esdtrack = dynamic_cast<AliESDtrack*>(track);
+    if (esdtrack) { 
+      if(matchClusIndex != -1) 
+        esdtrack->SetStatus(AliESDtrack::kEMCALmatch);
+      else
+        esdtrack->ResetStatus(AliESDtrack::kEMCALmatch);
+    } else {
+      AliAODTrack* aodtrack = dynamic_cast<AliAODTrack*>(track);
+      if(matchClusIndex != -1) 
+        aodtrack->SetStatus(AliESDtrack::kEMCALmatch);
+      else
+        aodtrack->ResetStatus(AliESDtrack::kEMCALmatch);
+    }
+
   }
-  AliDebug(2,"Track matched to closest cluster");      
+  AliDebug(2,"Track matched to closest cluster");  
 }
 
 //_________________________________________________________________________
-void AliEMCALRecoUtils::SetTracksMatchedToCluster(const AliESDEvent *event)
+void AliEMCALRecoUtils::SetTracksMatchedToCluster(const AliVEvent *event)
 {
   // Checks if EMC clusters are matched to ESD track.
   // Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster.
   
   for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); ++iClus) 
   {
-    AliESDCaloCluster *cluster = event->GetCaloCluster(iClus);
+    AliVCluster *cluster = event->GetCaloCluster(iClus);
     if (!cluster->IsEMCAL()) 
       continue;
     
@@ -2325,7 +2504,7 @@ void AliEMCALRecoUtils::SetTracksMatchedToCluster(const AliESDEvent *event)
     // Get all other tracks matched to the cluster
     for(Int_t iTrk=0; iTrk<nTracks; ++iTrk) 
     {
-      AliESDtrack* track = event->GetTrack(iTrk);
+      AliVTrack* track = dynamic_cast<AliVTrack*>(event->GetTrack(iTrk));
       if(iTrk == matchTrackIndex) continue;
       if(track->GetEMCALcluster() == iClus)
       {
@@ -2337,7 +2516,14 @@ void AliEMCALRecoUtils::SetTracksMatchedToCluster(const AliESDEvent *event)
     //printf("Tender::SetTracksMatchedToCluster - cluster E %f, N matches %d, first match %d\n",cluster->E(),nMatched,arrayTrackMatched[0]);
     
     arrayTrackMatched.Set(nMatched);
-    cluster->AddTracksMatched(arrayTrackMatched);
+    AliESDCaloCluster *esdcluster = dynamic_cast<AliESDCaloCluster*>(cluster);
+    if (esdcluster) 
+      esdcluster->AddTracksMatched(arrayTrackMatched);
+    else if (nMatched>0) {
+      AliAODCaloCluster *aodcluster = dynamic_cast<AliAODCaloCluster*>(cluster);
+      if (aodcluster)
+        aodcluster->AddTrackMatched(event->GetTrack(arrayTrackMatched.At(0)));
+    }
     
     Float_t eta= -999, phi = -999;
     if (matchTrackIndex != -1) 
@@ -2345,10 +2531,9 @@ void AliEMCALRecoUtils::SetTracksMatchedToCluster(const AliESDEvent *event)
     cluster->SetTrackDistance(phi, eta);
   }
   
-  AliDebug(2,"Cluster matched to tracks");     
+  AliDebug(2,"Cluster matched to tracks");  
 }
 
-
 //___________________________________________________
 void AliEMCALRecoUtils::Print(const Option_t *) const 
 {
@@ -2394,40 +2579,3 @@ void AliEMCALRecoUtils::Print(const Option_t *) const
   printf("DCSToVertex2D = %d, MaxDCAToVertexXY = %2.2f, MaxDCAToVertexZ = %2.2f\n",fCutDCAToVertex2D,fCutMaxDCAToVertexXY,fCutMaxDCAToVertexZ);
 }
 
-//_________________________________________________________________
-void AliEMCALRecoUtils::SetRunDependentCorrections(Int_t runnumber)
-{
-  //Get EMCAL time dependent corrections from file and put them in the recalibration histograms
-  //Do it only once and only if it is requested
-  
-  if(!fUseRunCorrectionFactors) return;
-  if(fRunCorrectionFactorsSet)  return;
-  
-  AliInfo(Form("AliEMCALRecoUtils::GetRunDependentCorrections() - Get Correction Factors for Run number %d\n",runnumber));
-  AliEMCALCalibTimeDepCorrection  *corr =  new AliEMCALCalibTimeDepCorrection();
-  corr->ReadRootInfo(Form("CorrectionFiles/Run%d_Correction.root",runnumber));
-  
-  SwitchOnRecalibration();
-  
-  AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance();
-  
-  for(Int_t ism = 0; ism < geom->GetNumberOfSuperModules(); ism++)
-  {
-    for(Int_t icol = 0; icol < 48; icol++)
-    {
-      for(Int_t irow = 0; irow < 24; irow++)
-      {
-        Float_t orgRecalFactor = GetEMCALChannelRecalibrationFactors(ism)->GetBinContent(icol,irow);
-        Float_t newRecalFactor = orgRecalFactor*corr->GetCorrection(ism, icol,irow,0);
-        GetEMCALChannelRecalibrationFactors(ism)->SetBinContent(icol,irow,newRecalFactor);
-        //printf("ism %d, icol %d, irow %d, corrections : org %f, time dep %f, final %f (org*time %f)\n",ism, icol, irow, 
-        //        orgRecalFactor, corr->GetCorrection(ism, icol,irow,0),
-        //       (GetEMCALChannelRecalibrationFactors(ism))->GetBinContent(icol,irow),newRecalFactor);
-      }
-    }
-  }
-  
-  fRunCorrectionFactorsSet = kTRUE;
-  
-}