]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGGA/CaloTrackCorrelations/AliAnaPhoton.cxx
add correlation of event BC and trigger BC, differenciate bad clusters with main...
[u/mrichter/AliRoot.git] / PWGGA / CaloTrackCorrelations / AliAnaPhoton.cxx
index 1fe79d754dd4564210b7670086eb1b1f4c2b2d8b..80fbba29e6346203dc7ba25ec42b136af5164be4 100755 (executable)
@@ -44,6 +44,7 @@
 #include "AliAODMCParticle.h"
 #include "AliMixedEvent.h"
 #include "AliAODEvent.h"
+#include "AliESDEvent.h"
 
 // --- Detectors --- 
 #include "AliPHOSGeoUtils.h"
@@ -57,17 +58,46 @@ AliAnaPhoton::AliAnaPhoton() :
     fMinDist(0.),                 fMinDist2(0.),                fMinDist3(0.), 
     fRejectTrackMatch(0),         fFillTMHisto(kFALSE),
     fTimeCutMin(-10000),          fTimeCutMax(10000),         
-    fNCellsCut(0),                fFillSSHistograms(kFALSE),        
+    fNCellsCut(0),                
+    fNLMCutMin(-1),               fNLMCutMax(10), 
+    fFillSSHistograms(kFALSE),    fFillOnlySimpleSSHisto(1),   
     fNOriginHistograms(8),        fNPrimaryHistograms(4),
-
+    fFillPileUpHistograms(0),     fFillEMCALBCHistograms(0),
     // Histograms
     fhNCellsE(0),                 fhCellsE(0),   // Control histograms            
     fhMaxCellDiffClusterE(0),     fhTimeE(0),    // Control histograms
-    fhEPhoton(0),                 fhPtPhoton(0),  
+    fhEtaPhi(0),                  fhEtaPhiEMCALBC0(0),
+    fhEtaPhiEMCALBC1(0),          fhEtaPhiEMCALBCN(0),
+    fhEtaPhiTriggerEMCALBCClusterOverTh(0),
+    fhEtaPhiTriggerEMCALBCUMClusterOverTh(0),
+    fhEtaPhiTriggerEMCALBCClusterBelowTh1(0),
+    fhEtaPhiTriggerEMCALBCUMClusterBelowTh1(0),
+    fhEtaPhiTriggerEMCALBCClusterBelowTh2(0),
+    fhEtaPhiTriggerEMCALBCUMClusterBelowTh2(0),
+    fhEtaPhiTriggerEMCALBCExotic(0),             fhTimeTriggerEMCALBCExotic(0),
+    fhEtaPhiTriggerEMCALBCUMExotic(0),           fhTimeTriggerEMCALBCUMExotic(0), 
+    fhEtaPhiTriggerEMCALBCBad(0),                fhTimeTriggerEMCALBCBad(0),
+    fhEtaPhiTriggerEMCALBCUMBad(0),              fhTimeTriggerEMCALBCUMBad(0),
+    fhEtaPhiTriggerEMCALBCBadExotic(0),          fhTimeTriggerEMCALBCBadExotic(0),
+    fhEtaPhiTriggerEMCALBCUMBadExotic(0),        fhTimeTriggerEMCALBCUMBadExotic(0),
+    fhEtaPhiTriggerEMCALBCExoticCluster(0),      fhTimeTriggerEMCALBCExoticCluster(0),
+    fhEtaPhiTriggerEMCALBCUMExoticCluster(0),    fhTimeTriggerEMCALBCUMExoticCluster(0), 
+    fhEtaPhiTriggerEMCALBCBadCluster(0),         fhTimeTriggerEMCALBCBadCluster(0),
+    fhEtaPhiTriggerEMCALBCUMBadCluster(0),       fhTimeTriggerEMCALBCUMBadCluster(0),
+    fhEtaPhiTriggerEMCALBCBadExoticCluster(0),   fhTimeTriggerEMCALBCBadExoticCluster(0),
+    fhEtaPhiTriggerEMCALBCUMBadExoticCluster(0), fhTimeTriggerEMCALBCUMBadExoticCluster(0),
+    fhTimeTriggerEMCALBCBadMaxCell(0),           fhTimeTriggerEMCALBCUMBadMaxCell(0),
+    fhTimeTriggerEMCALBCBadMaxCellExotic(0),     fhTimeTriggerEMCALBCUMBadMaxCellExotic(0),
+    fhEtaPhiNoTrigger(0),                        fhTimeNoTrigger(0),
+
+    fhEPhoton(0),                 fhPtPhoton(0),
     fhPhiPhoton(0),               fhEtaPhoton(0), 
     fhEtaPhiPhoton(0),            fhEtaPhi05Photon(0),
+    fhEtaPhiPhotonEMCALBC0(0),    fhEtaPhiPhotonEMCALBC1(0),   fhEtaPhiPhotonEMCALBCN(0),
+    fhPtCentralityPhoton(0),      fhPtEventPlanePhoton(0),
 
     // Shower shape histograms
+    fhNLocMax(0),
     fhDispE(0),                   fhLam0E(0),                   fhLam1E(0), 
     fhDispETRD(0),                fhLam0ETRD(0),                fhLam1ETRD(0),
     fhDispETM(0),                 fhLam0ETM(0),                 fhLam1ETM(0), 
@@ -81,6 +111,10 @@ AliAnaPhoton::AliAnaPhoton() :
     fhLam0DispLowE(0),            fhLam0DispHighE(0), 
     fhLam1Lam0LowE(0),            fhLam1Lam0HighE(0), 
     fhDispLam1LowE(0),            fhDispLam1HighE(0),
+    fhDispEtaE(0),                fhDispPhiE(0),
+    fhSumEtaE(0),                 fhSumPhiE(0),                 fhSumEtaPhiE(0),
+    fhDispEtaPhiDiffE(0),         fhSphericityE(0),
+    fhDispSumEtaDiffE(0),         fhDispSumPhiDiffE(0),
 
     // MC histograms
     fhMCPhotonELambda0NoOverlap(0),       fhMCPhotonELambda0TwoOverlap(0),      fhMCPhotonELambda0NOverlap(0),
@@ -89,8 +123,17 @@ AliAnaPhoton::AliAnaPhoton() :
     fhEmbedPhotonELambda0FullSignal(0),   fhEmbedPhotonELambda0MostlySignal(0),  
     fhEmbedPhotonELambda0MostlyBkg(0),    fhEmbedPhotonELambda0FullBkg(0),       
     fhEmbedPi0ELambda0FullSignal(0),      fhEmbedPi0ELambda0MostlySignal(0),    
-    fhEmbedPi0ELambda0MostlyBkg(0),       fhEmbedPi0ELambda0FullBkg(0)
-
+    fhEmbedPi0ELambda0MostlyBkg(0),       fhEmbedPi0ELambda0FullBkg(0),
+    // PileUp
+    fhTimeENoCut(0),                      fhTimeESPD(0),        fhTimeESPDMulti(0),
+    fhTimeNPileUpVertSPD(0),              fhTimeNPileUpVertTrack(0),
+    fhTimeNPileUpVertContributors(0),
+    fhTimePileUpMainVertexZDistance(0),   fhTimePileUpMainVertexZDiamond(0),
+    fhClusterMultSPDPileUp(),             fhClusterMultNoPileUp(),
+    fhEtaPhiBC0(0),  fhEtaPhiBCPlus(0),   fhEtaPhiBCMinus(0),
+    fhEtaPhiBC0PileUpSPD(0),
+    fhEtaPhiBCPlusPileUpSPD(0),
+    fhEtaPhiBCMinusPileUpSPD(0)
  {
   //default ctor
   
@@ -117,6 +160,30 @@ AliAnaPhoton::AliAnaPhoton() :
     fhEPrimMCAcc  [i] = 0;
     fhPhiPrimMCAcc[i] = 0;
     fhYPrimMCAcc  [i] = 0;
+    
+    fhDispEtaDispPhi[i] = 0;
+    fhLambda0DispPhi[i] = 0;
+    fhLambda0DispEta[i] = 0;
+    
+    fhPtPileUp       [i] = 0;
+    fhPtChargedPileUp[i] = 0;
+    fhPtPhotonPileUp [i] = 0;
+
+    fhLambda0PileUp       [i] = 0;
+    fhLambda0ChargedPileUp[i] = 0;
+    
+    fhClusterEFracLongTimePileUp  [i] = 0;
+    
+    fhClusterTimeDiffPileUp       [i] = 0;
+    fhClusterTimeDiffChargedPileUp[i] = 0;
+    fhClusterTimeDiffPhotonPileUp [i] = 0;
+
+    for(Int_t j = 0; j < 6; j++)
+    {
+      fhMCDispEtaDispPhi[i][j] = 0;
+      fhMCLambda0DispEta[i][j] = 0;
+      fhMCLambda0DispPhi[i][j] = 0;
+    }
   }  
   
   for(Int_t i = 0; i < 6; i++)
@@ -126,15 +193,27 @@ AliAnaPhoton::AliAnaPhoton() :
     fhMCEDispersion [i]                  = 0;
     fhMCNCellsE     [i]                  = 0; 
     fhMCMaxCellDiffClusterE[i]           = 0; 
+    fhLambda0DispEta[i]                  = 0;
+    fhLambda0DispPhi[i]                  = 0;
+
     fhMCLambda0vsClusterMaxCellDiffE0[i] = 0;
     fhMCLambda0vsClusterMaxCellDiffE2[i] = 0;
     fhMCLambda0vsClusterMaxCellDiffE6[i] = 0;
     fhMCNCellsvsClusterMaxCellDiffE0 [i] = 0;
     fhMCNCellsvsClusterMaxCellDiffE2 [i] = 0;
     fhMCNCellsvsClusterMaxCellDiffE6 [i] = 0;
+    
+    fhMCEDispEta       [i]               = 0;
+    fhMCEDispPhi       [i]               = 0;
+    fhMCESumEtaPhi     [i]               = 0;
+    fhMCEDispEtaPhiDiff[i]               = 0;
+    fhMCESphericity    [i]               = 0;
   }
   
-  for(Int_t i = 0; i < 5; i++) fhClusterCuts[i] = 0;
+   for(Int_t i = 0; i < 5; i++) 
+   {
+     fhClusterCuts[i] = 0;
+   }
   
    // Track matching residuals
    for(Int_t i = 0; i < 2; i++)
@@ -149,30 +228,317 @@ AliAnaPhoton::AliAnaPhoton() :
      fhEOverPTRD[i] = 0;
    }
    
+   for(Int_t i = 0; i < 4; i++) 
+   {
+     fhClusterMultSPDPileUp[i] = 0;
+     fhClusterMultNoPileUp [i] = 0;
+   }
+   
+   for(Int_t i = 0; i < 11; i++)
+   {
+     fhEtaPhiTriggerEMCALBC             [i] = 0 ;
+     fhTimeTriggerEMCALBC               [i] = 0 ;
+     fhEtaPhiTriggerEMCALBCUM           [i] = 0 ;
+     fhTimeTriggerEMCALBCUM             [i] = 0 ;
+
+     fhEtaPhiPhotonTriggerEMCALBC       [i] = 0 ;
+     fhTimePhotonTriggerEMCALBC         [i] = 0 ;
+     fhEtaPhiPhotonTriggerEMCALBCUM     [i] = 0 ;
+     fhTimePhotonTriggerEMCALBCUM       [i] = 0 ;
+     
+     fhTimePhotonTriggerEMCALBCPileUpSPD[i] = 0 ;
+     fhTimeTriggerEMCALBCPileUpSPD      [i] = 0 ;
+     
+     fhEtaPhiTriggerEMCALBCCluster      [i] = 0 ;
+     fhTimeTriggerEMCALBCCluster        [i] = 0 ;
+     fhEtaPhiTriggerEMCALBCUMCluster    [i] = 0 ;
+     fhTimeTriggerEMCALBCUMCluster      [i] = 0 ;
+
+   }
+   
   //Initialize parameters
   InitParameters();
 
 }
 
-//__________________________________________________________________________
-Bool_t  AliAnaPhoton::ClusterSelected(AliVCluster* calo, TLorentzVector mom) 
+//_____________________________________________________________________________________________________
+Bool_t  AliAnaPhoton::ClusterSelected(AliVCluster* calo, TLorentzVector mom, Int_t nMaxima
 {
   //Select clusters if they pass different cuts
-  if(GetDebug() > 2) 
-    printf("AliAnaPhoton::ClusterSelected() Current Event %d; Before selection : E %2.2f, pT %2.2f, Ecl %2.2f, phi %2.2f, eta %2.2f\n",
+  
+  Float_t ptcluster  = mom.Pt();
+  Float_t ecluster   = mom.E();
+  Float_t l0cluster  = calo->GetM02();
+  Float_t etacluster = mom.Eta();
+  Float_t phicluster = mom.Phi();
+  if(phicluster<0) phicluster+=TMath::TwoPi();
+  Float_t tofcluster   = calo->GetTOF()*1.e9;
+  Float_t tofclusterUS = TMath::Abs(tofcluster);
+  
+  
+  if(GetDebug() > 2)
+    printf("AliAnaPhoton::ClusterSelected() - Current Event %d; Before selection : E %2.2f, pT %2.2f, phi %2.2f, eta %2.2f\n",
            GetReader()->GetEventNumber(),
-           calo->E(), mom.Pt(),calo->E(),mom.Phi()*TMath::RadToDeg(),mom.Eta());
+           ecluster,ptcluster, phicluster*TMath::RadToDeg(),etacluster);
+  
+  fhClusterCuts[1]->Fill(ecluster);
+  
+  if(ecluster > 0.5) fhEtaPhi->Fill(etacluster, phicluster);
+  
+  if(fFillEMCALBCHistograms && fCalorimeter=="EMCAL")
+  {
+    if(ecluster > 2)
+    {
+      if      (tofclusterUS < 25) fhEtaPhiEMCALBC0->Fill(etacluster, phicluster);
+      else if (tofclusterUS < 75) fhEtaPhiEMCALBC1->Fill(etacluster, phicluster);
+      else                        fhEtaPhiEMCALBCN->Fill(etacluster, phicluster);
+    }
     
-  fhClusterCuts[1]->Fill(calo->E());
+    Int_t  bc     = GetReader()->GetTriggerClusterBC();
+    Int_t  id     = GetReader()->GetTriggerClusterId();
+    Bool_t badMax = GetReader()->IsBadMaxCellTriggerEvent();
+
+    if(id==-2)
+    {
+      //printf("AliAnaPhoton::ClusterSelected() - No trigger found bc=%d\n",bc);
+      fhEtaPhiNoTrigger->Fill(etacluster, phicluster);
+      fhTimeNoTrigger  ->Fill(ecluster, tofcluster);
+    }
+    else if(TMath::Abs(bc) < 6)
+    {
+      if(!GetReader()->IsBadCellTriggerEvent() && !GetReader()->IsExoticEvent() )
+      {
+        if(GetReader()->IsTriggerMatched())
+        {
+          if(ecluster > 2) fhEtaPhiTriggerEMCALBC[bc+5]->Fill(etacluster, phicluster);
+          fhTimeTriggerEMCALBC[bc+5]->Fill(ecluster, tofcluster);
+          if(GetReader()->IsPileUpFromSPD()) fhTimeTriggerEMCALBCPileUpSPD[bc+5]->Fill(ecluster, tofcluster);
+          
+          if(calo->GetID() ==  GetReader()->GetTriggerClusterId())
+          {
+            fhEtaPhiTriggerEMCALBCCluster[bc+5]->Fill(etacluster, phicluster);
+            fhTimeTriggerEMCALBCCluster[bc+5]  ->Fill(ecluster, tofcluster);
+            
+            if(bc==0)
+            {
+              Float_t threshold = GetReader()->GetEventTriggerThreshold() ;
+              if(ecluster > threshold)
+                fhEtaPhiTriggerEMCALBCClusterOverTh->Fill(etacluster, phicluster);
+              else if(ecluster > threshold-1)
+                fhEtaPhiTriggerEMCALBCClusterBelowTh1->Fill(etacluster, phicluster);
+              else 
+                fhEtaPhiTriggerEMCALBCClusterBelowTh2->Fill(etacluster, phicluster);
+            }
+          }
+        }
+        else
+        {
+          if(ecluster > 2) fhEtaPhiTriggerEMCALBCUM[bc+5]->Fill(etacluster, phicluster);
+          fhTimeTriggerEMCALBCUM[bc+5]->Fill(ecluster, tofcluster);
+          
+          if(calo->GetID() ==  GetReader()->GetTriggerClusterId())
+          {
+            fhEtaPhiTriggerEMCALBCUMCluster[bc+5]->Fill(etacluster, phicluster);
+            fhTimeTriggerEMCALBCUMCluster[bc+5]  ->Fill(ecluster, tofcluster);
+            if(bc==0)
+            {
+              Float_t threshold = GetReader()->GetEventTriggerThreshold() ;
+              if(ecluster > threshold)
+                fhEtaPhiTriggerEMCALBCUMClusterOverTh->Fill(etacluster, phicluster);
+              else if(ecluster > threshold-1)
+                fhEtaPhiTriggerEMCALBCUMClusterBelowTh1->Fill(etacluster, phicluster);
+              else
+                fhEtaPhiTriggerEMCALBCUMClusterBelowTh2->Fill(etacluster, phicluster);
+            }
+          }
+        }
+      }// neither bad nor exotic
+      else if(GetReader()->IsBadCellTriggerEvent() && GetReader()->IsExoticEvent())
+      {
+        if(GetReader()->IsTriggerMatched())
+        {
+          if(ecluster > 2) fhEtaPhiTriggerEMCALBCBadExotic->Fill(etacluster, phicluster);
+          fhTimeTriggerEMCALBCBadExotic->Fill(ecluster, tofcluster);
+          if(badMax)  fhTimeTriggerEMCALBCBadMaxCellExotic->Fill(ecluster, tofcluster);
+        }
+        else
+        {
+          if(ecluster > 2) fhEtaPhiTriggerEMCALBCUMBadExotic->Fill(etacluster, phicluster);
+          fhTimeTriggerEMCALBCUMBadExotic->Fill(ecluster, tofcluster);
+          if(badMax)  fhTimeTriggerEMCALBCUMBadMaxCellExotic->Fill(ecluster, tofcluster);
+
+        }
+      }// Bad and exotic cluster trigger
+      else if(GetReader()->IsBadCellTriggerEvent() )
+      {
+        if(GetReader()->IsTriggerMatched())
+        {
+          if(ecluster > 2) fhEtaPhiTriggerEMCALBCBad->Fill(etacluster, phicluster);
+          fhTimeTriggerEMCALBCBad->Fill(ecluster, tofcluster);
+          if(badMax)  fhTimeTriggerEMCALBCBadMaxCell->Fill(ecluster, tofcluster);
+        }
+        else
+        {
+          if(ecluster > 2) fhEtaPhiTriggerEMCALBCUMBad->Fill(etacluster, phicluster);
+          fhTimeTriggerEMCALBCUMBad->Fill(ecluster, tofcluster);
+          if(badMax)  fhTimeTriggerEMCALBCUMBadMaxCell->Fill(ecluster, tofcluster);
+        }
+      }// Bad cluster trigger
+      else if(GetReader()->IsExoticEvent() )
+      {
+        if(GetReader()->IsTriggerMatched())
+        {
+          if(ecluster > 2) fhEtaPhiTriggerEMCALBCExotic->Fill(etacluster, phicluster);
+          fhTimeTriggerEMCALBCExotic->Fill(ecluster, tofcluster);
+        }
+        else
+        {
+          if(ecluster > 2) fhEtaPhiTriggerEMCALBCUMExotic->Fill(etacluster, phicluster);
+          fhTimeTriggerEMCALBCUMExotic->Fill(ecluster, tofcluster);
+        }
+      }
+    }
+    else if(TMath::Abs(bc) >= 6)
+      printf("AliAnaPhoton::ClusterSelected() - Trigger BC not expected = %d\n",bc);
+    
+  }
   
   //.......................................
   //If too small or big energy, skip it
-  if(calo->E() < GetMinEnergy() || calo->E() > GetMaxEnergy() ) return kFALSE ; 
+  if(ecluster < GetMinEnergy() || ecluster > GetMaxEnergy() ) return kFALSE ;
   
   if(GetDebug() > 2) printf("\t Cluster %d Pass E Cut \n",calo->GetID());
   
-  fhClusterCuts[2]->Fill(calo->E());
+  fhClusterCuts[2]->Fill(ecluster);
 
+  if(fFillPileUpHistograms)
+  {
+    // Get the fraction of the cluster energy that carries the cell with highest energy and its absId
+    AliVCaloCells* cells = 0;
+    if(fCalorimeter == "EMCAL") cells = GetEMCALCells();
+    else                        cells = GetPHOSCells();
+    
+    Float_t maxCellFraction = 0.;
+    Int_t absIdMax = GetCaloUtils()->GetMaxEnergyCell(cells, calo,maxCellFraction);
+
+    Double_t tmax  = cells->GetCellTime(absIdMax);
+    GetCaloUtils()->RecalibrateCellTime(tmax, fCalorimeter, absIdMax,GetReader()->GetInputEvent()->GetBunchCrossNumber());
+    tmax*=1.e9;
+    
+    Bool_t okPhoton = kFALSE;
+    if( GetCaloPID()->GetIdentifiedParticleType(calo)== AliCaloPID::kPhoton) okPhoton = kTRUE;
+
+    Bool_t matched = IsTrackMatched(calo,GetReader()->GetInputEvent());
+    Float_t clusterLongTimeE = 0;
+    Float_t clusterOKTimeE   = 0;
+    //Loop on cells inside cluster
+    for (Int_t ipos = 0; ipos < calo->GetNCells(); ipos++)
+    {
+      Int_t absId  = calo->GetCellsAbsId()[ipos];
+      //if(absId!=absIdMax && cells->GetCellAmplitude(absIdMax) > 0.01)
+      if(cells->GetCellAmplitude(absIdMax) > 0.1)
+      {
+        Double_t time  = cells->GetCellTime(absId);
+        Float_t  amp   = cells->GetCellAmplitude(absId);
+        Int_t    bc    = GetReader()->GetInputEvent()->GetBunchCrossNumber();
+        GetCaloUtils()->GetEMCALRecoUtils()->AcceptCalibrateCell(absId,bc,amp,time,cells);
+        time*=1e9;
+        
+        Float_t diff = (tmax-time);
+      
+        if(GetReader()->IsInTimeWindow(time,amp)) clusterOKTimeE   += amp;
+        else                                      clusterLongTimeE += amp;
+        
+        if(GetReader()->IsPileUpFromSPD())
+        {
+          fhClusterTimeDiffPileUp[0]->Fill(ecluster, diff);
+          if(!matched)
+          {
+            fhClusterTimeDiffChargedPileUp[0]->Fill(ecluster, diff);
+            if(okPhoton)  fhClusterTimeDiffPhotonPileUp[0]->Fill(ecluster, diff);
+          }
+        }
+        
+        if(GetReader()->IsPileUpFromEMCal())
+        {
+          fhClusterTimeDiffPileUp[1]->Fill(ecluster, diff);
+          if(!matched)
+          {
+            fhClusterTimeDiffChargedPileUp[1]->Fill(ecluster, diff);
+            if(okPhoton)  fhClusterTimeDiffPhotonPileUp[1]->Fill(ecluster, diff);
+          }
+        }
+
+        if(GetReader()->IsPileUpFromSPDOrEMCal())
+        {
+          fhClusterTimeDiffPileUp[2]->Fill(ecluster, diff);
+          if(!matched)
+          {
+            fhClusterTimeDiffChargedPileUp[2]->Fill(ecluster, diff);
+            if(okPhoton)  fhClusterTimeDiffPhotonPileUp[2]->Fill(ecluster, diff);
+          }
+        }
+        
+        if(GetReader()->IsPileUpFromSPDAndEMCal())
+        {
+          fhClusterTimeDiffPileUp[3]->Fill(ecluster, diff);
+          if(!matched)
+          {
+            fhClusterTimeDiffChargedPileUp[3]->Fill(ecluster, diff);
+            if(okPhoton)  fhClusterTimeDiffPhotonPileUp[3]->Fill(ecluster, diff);
+          }
+        }
+        
+        if(GetReader()->IsPileUpFromSPDAndNotEMCal())
+        {
+          fhClusterTimeDiffPileUp[4]->Fill(ecluster, diff);
+          if(!matched)
+          {
+            fhClusterTimeDiffChargedPileUp[4]->Fill(ecluster, diff);
+            if(okPhoton)  fhClusterTimeDiffPhotonPileUp[4]->Fill(ecluster, diff);
+          }
+        }
+        
+        if(GetReader()->IsPileUpFromEMCalAndNotSPD())
+        {
+          fhClusterTimeDiffPileUp[5]->Fill(ecluster, diff);
+          if(!matched)
+          {
+            fhClusterTimeDiffChargedPileUp[5]->Fill(ecluster, diff);
+            if(okPhoton)  fhClusterTimeDiffPhotonPileUp[5]->Fill(ecluster, diff);
+          }
+        }
+
+        if(GetReader()->IsPileUpFromNotSPDAndNotEMCal())
+        {
+          fhClusterTimeDiffPileUp[6]->Fill(ecluster, diff);
+          if(!matched)
+          {
+            fhClusterTimeDiffChargedPileUp[6]->Fill(ecluster, diff);
+            if(okPhoton)  fhClusterTimeDiffPhotonPileUp[6]->Fill(ecluster, diff);
+          }
+        }
+      }// Not max
+    }//loop
+    
+    Float_t frac = 0;
+    if(clusterLongTimeE+clusterOKTimeE > 0.001)
+      frac = clusterLongTimeE/(clusterLongTimeE+clusterOKTimeE);
+    //printf("E long %f, E OK %f, Fraction large time %f, E %f\n",clusterLongTimeE,clusterOKTimeE,frac,ecluster);
+    
+    if(GetReader()->IsPileUpFromSPD())               {fhPtPileUp[0]->Fill(ptcluster); fhLambda0PileUp[0]->Fill(ecluster,l0cluster); fhClusterEFracLongTimePileUp[0]->Fill(ecluster,frac);}
+    if(GetReader()->IsPileUpFromEMCal())             {fhPtPileUp[1]->Fill(ptcluster); fhLambda0PileUp[1]->Fill(ecluster,l0cluster); fhClusterEFracLongTimePileUp[1]->Fill(ecluster,frac);}
+    if(GetReader()->IsPileUpFromSPDOrEMCal())        {fhPtPileUp[2]->Fill(ptcluster); fhLambda0PileUp[2]->Fill(ecluster,l0cluster); fhClusterEFracLongTimePileUp[2]->Fill(ecluster,frac);}
+    if(GetReader()->IsPileUpFromSPDAndEMCal())       {fhPtPileUp[3]->Fill(ptcluster); fhLambda0PileUp[3]->Fill(ecluster,l0cluster); fhClusterEFracLongTimePileUp[3]->Fill(ecluster,frac);}
+    if(GetReader()->IsPileUpFromSPDAndNotEMCal())    {fhPtPileUp[4]->Fill(ptcluster); fhLambda0PileUp[4]->Fill(ecluster,l0cluster); fhClusterEFracLongTimePileUp[4]->Fill(ecluster,frac);}
+    if(GetReader()->IsPileUpFromEMCalAndNotSPD())    {fhPtPileUp[5]->Fill(ptcluster); fhLambda0PileUp[5]->Fill(ecluster,l0cluster); fhClusterEFracLongTimePileUp[5]->Fill(ecluster,frac);}
+    if(GetReader()->IsPileUpFromNotSPDAndNotEMCal()) {fhPtPileUp[6]->Fill(ptcluster); fhLambda0PileUp[6]->Fill(ecluster,l0cluster); fhClusterEFracLongTimePileUp[6]->Fill(ecluster,frac);}
+    
+    if(tmax > -25 && tmax < 25) {fhEtaPhiBC0    ->Fill(mom.Eta(),mom.Phi()); if(GetReader()->IsPileUpFromSPD()) fhEtaPhiBC0PileUpSPD    ->Fill(mom.Eta(),mom.Phi()); }
+    else if (tmax > 25)         {fhEtaPhiBCPlus ->Fill(mom.Eta(),mom.Phi()); if(GetReader()->IsPileUpFromSPD()) fhEtaPhiBCPlusPileUpSPD ->Fill(mom.Eta(),mom.Phi()); }
+    else if (tmax <-25)         {fhEtaPhiBCMinus->Fill(mom.Eta(),mom.Phi()); if(GetReader()->IsPileUpFromSPD()) fhEtaPhiBCMinusPileUpSPD->Fill(mom.Eta(),mom.Phi()); }
+  }
+  
   //.......................................
   // TOF cut, BE CAREFUL WITH THIS CUT
   Double_t tof = calo->GetTOF()*1e9;
@@ -180,25 +546,31 @@ Bool_t  AliAnaPhoton::ClusterSelected(AliVCluster* calo, TLorentzVector mom)
   
   if(GetDebug() > 2)  printf("\t Cluster %d Pass Time Cut \n",calo->GetID());
   
-  fhClusterCuts[3]->Fill(calo->E());
+  fhClusterCuts[3]->Fill(ecluster);
 
   //.......................................
   if(calo->GetNCells() <= fNCellsCut && GetReader()->GetDataType() != AliCaloTrackReader::kMC) return kFALSE;
   
   if(GetDebug() > 2) printf("\t Cluster %d Pass NCell Cut \n",calo->GetID());
   
-  fhClusterCuts[4]->Fill(calo->E());
+  fhClusterCuts[4]->Fill(ecluster);
+
+  if(nMaxima < fNLMCutMin || nMaxima > fNLMCutMax) return kFALSE ;
+  if(GetDebug() > 2) printf(" \t Cluster %d pass NLM %d of out of range \n",calo->GetID(), nMaxima);
+
+  fhClusterCuts[5]->Fill(ecluster);
 
   //.......................................
   //Check acceptance selection
-  if(IsFiducialCutOn()){
+  if(IsFiducialCutOn())
+  {
     Bool_t in = GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
     if(! in ) return kFALSE ;
   }
   
   if(GetDebug() > 2) printf("Fiducial cut passed \n");
   
-  fhClusterCuts[5]->Fill(calo->E());
+  fhClusterCuts[6]->Fill(ecluster);
 
   //.......................................
   //Skip matched clusters with tracks
@@ -206,8 +578,10 @@ Bool_t  AliAnaPhoton::ClusterSelected(AliVCluster* calo, TLorentzVector mom)
   // Fill matching residual histograms before PID cuts
   if(fFillTMHisto) FillTrackMatchingResidualHistograms(calo,0);
   
-  if(fRejectTrackMatch){
-    if(IsTrackMatched(calo,GetReader()->GetInputEvent())) {
+  if(fRejectTrackMatch)
+  {
+    if(IsTrackMatched(calo,GetReader()->GetInputEvent())) 
+    {
       if(GetDebug() > 2) printf("\t Reject track-matched clusters\n");
       return kFALSE ;
     }
@@ -215,61 +589,78 @@ Bool_t  AliAnaPhoton::ClusterSelected(AliVCluster* calo, TLorentzVector mom)
       if(GetDebug() > 2)  printf(" Track-matching cut passed \n");
   }// reject matched clusters
   
-  fhClusterCuts[6]->Fill(calo->E());
+  fhClusterCuts[7]->Fill(ecluster);
 
+  if(fFillPileUpHistograms)
+  {
+    if(GetReader()->IsPileUpFromSPD())               {fhPtChargedPileUp[0]->Fill(ptcluster); fhLambda0ChargedPileUp[0]->Fill(ecluster,l0cluster); }
+    if(GetReader()->IsPileUpFromEMCal())             {fhPtChargedPileUp[1]->Fill(ptcluster); fhLambda0ChargedPileUp[1]->Fill(ecluster,l0cluster); }
+    if(GetReader()->IsPileUpFromSPDOrEMCal())        {fhPtChargedPileUp[2]->Fill(ptcluster); fhLambda0ChargedPileUp[2]->Fill(ecluster,l0cluster); }
+    if(GetReader()->IsPileUpFromSPDAndEMCal())       {fhPtChargedPileUp[3]->Fill(ptcluster); fhLambda0ChargedPileUp[3]->Fill(ecluster,l0cluster); }
+    if(GetReader()->IsPileUpFromSPDAndNotEMCal())    {fhPtChargedPileUp[4]->Fill(ptcluster); fhLambda0ChargedPileUp[4]->Fill(ecluster,l0cluster); }
+    if(GetReader()->IsPileUpFromEMCalAndNotSPD())    {fhPtChargedPileUp[5]->Fill(ptcluster); fhLambda0ChargedPileUp[5]->Fill(ecluster,l0cluster); }
+    if(GetReader()->IsPileUpFromNotSPDAndNotEMCal()) {fhPtChargedPileUp[6]->Fill(ptcluster); fhLambda0ChargedPileUp[6]->Fill(ecluster,l0cluster); }
+  }
+  
   //.......................................
   //Check Distance to Bad channel, set bit.
   Double_t distBad=calo->GetDistanceToBadChannel() ; //Distance to bad channel
   if(distBad < 0.) distBad=9999. ; //workout strange convension dist = -1. ;
-  if(distBad < fMinDist) {//In bad channel (PHOS cristal size 2.2x2.2 cm), EMCAL ( cell units )
+  if(distBad < fMinDist) 
+  {//In bad channel (PHOS cristal size 2.2x2.2 cm), EMCAL ( cell units )
     return kFALSE ;
   }
   else if(GetDebug() > 2) printf("\t Bad channel cut passed %4.2f > %2.2f \n",distBad, fMinDist);
   
-  fhClusterCuts[7]->Fill(calo->E());
+  fhClusterCuts[8]->Fill(ecluster);
   
   if(GetDebug() > 0) 
-    printf("AliAnaPhoton::ClusterSelected() Current Event %d; After  selection : E %2.2f, pT %2.2f, Ecl %2.2f, phi %2.2f, eta %2.2f\n",
+    printf("AliAnaPhoton::ClusterSelected() Current Event %d; After  selection : E %2.2f, pT %2.2f, phi %2.2f, eta %2.2f\n",
            GetReader()->GetEventNumber(), 
-           calo->E(), mom.Pt(),calo->E(),mom.Phi()*TMath::RadToDeg(),mom.Eta());
+           ecluster, ptcluster,mom.Phi()*TMath::RadToDeg(),mom.Eta());
   
   //All checks passed, cluster selected
   return kTRUE;
     
 }
 
-//_____________________________________________________________
-void AliAnaPhoton::FillAcceptanceHistograms(){
+//___________________________________________
+void AliAnaPhoton::FillAcceptanceHistograms()
+{
   //Fill acceptance histograms if MC data is available
   
-  if(GetReader()->ReadStack()){        
+  Double_t photonY   = -100 ;
+  Double_t photonE   = -1 ;
+  Double_t photonPt  = -1 ;
+  Double_t photonPhi =  100 ;
+  Double_t photonEta = -1 ;
+
+  Int_t    pdg       =  0 ;
+  Int_t    tag       =  0 ;
+  Int_t    mcIndex   =  0 ;
+  Bool_t   inacceptance = kFALSE;
+
+  if(GetReader()->ReadStack())
+  {    
     AliStack * stack = GetMCStack();
-    if(stack){
-      for(Int_t i=0 ; i<stack->GetNtrack(); i++){
+    if(stack)
+    {
+      for(Int_t i=0 ; i<stack->GetNtrack(); i++)
+      {
         TParticle * prim = stack->Particle(i) ;
-        Int_t pdg = prim->GetPdgCode();
+        pdg = prim->GetPdgCode();
         //printf("i %d, %s %d  %s %d \n",i, stack->Particle(i)->GetName(), stack->Particle(i)->GetPdgCode(),
         //                             prim->GetName(), prim->GetPdgCode());
         
-        if(pdg == 22){
-          
+        if(pdg == 22)
+        {
           // Get tag of this particle photon from fragmentation, decay, prompt ...
-          Int_t tag = GetMCAnalysisUtils()->CheckOrigin(i,GetReader(), 0);
-          if(!GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPhoton)){
+          tag = GetMCAnalysisUtils()->CheckOrigin(i,GetReader());
+          if(!GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPhoton))
+          {
             //A conversion photon from a hadron, skip this kind of photon
-            //            printf("AliAnaPhoton::FillAcceptanceHistograms() - not a photon, weird!: tag %d, conv %d, pi0 %d, hadron %d, electron %d, unk %d, muon %d,pion %d, proton %d, neutron %d, kaon %d, antiproton %d, antineutron %d\n",tag,
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCConversion),
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0),
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCOther),
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCElectron),
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCUnknown),
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCMuon), 
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPion),
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCProton), 
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCAntiNeutron),
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCKaon), 
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCAntiProton), 
-            //                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCAntiNeutron));
+            // printf("AliAnaPhoton::FillAcceptanceHistograms() - not a photon, weird!\n ");
+            // GetMCAnalysisUtils()->PrintMCTag(tag);
             
             return;
           }
@@ -277,35 +668,38 @@ void AliAnaPhoton::FillAcceptanceHistograms(){
           //Get photon kinematics
           if(prim->Energy() == TMath::Abs(prim->Pz()))  continue ; //Protection against floating point exception         
           
-          Double_t photonY   = 0.5*TMath::Log((prim->Energy()-prim->Pz())/(prim->Energy()+prim->Pz())) ;
-          Double_t photonE   = prim->Energy() ;
-          Double_t photonPt  = prim->Pt() ;
-          Double_t photonPhi = TMath::RadToDeg()*prim->Phi() ;
+          photonY   = 0.5*TMath::Log((prim->Energy()-prim->Pz())/(prim->Energy()+prim->Pz())) ;
+          photonE   = prim->Energy() ;
+          photonPt  = prim->Pt() ;
+          photonPhi = TMath::RadToDeg()*prim->Phi() ;
           if(photonPhi < 0) photonPhi+=TMath::TwoPi();
-          Double_t photonEta = prim->Eta() ;
-          
+          photonEta = prim->Eta() ;
           
           //Check if photons hit the Calorimeter
           TLorentzVector lv;
           prim->Momentum(lv);
-          Bool_t inacceptance = kFALSE;
-          if     (fCalorimeter == "PHOS"){
-            if(GetPHOSGeometry() && GetCaloUtils()->IsPHOSGeoMatrixSet()){
+          inacceptance = kFALSE;
+          if     (fCalorimeter == "PHOS")
+          {
+            if(GetPHOSGeometry() && GetCaloUtils()->IsPHOSGeoMatrixSet())
+            {
               Int_t mod ;
               Double_t x,z ;
               if(GetPHOSGeometry()->ImpactOnEmc(prim,mod,z,x)) 
                 inacceptance = kTRUE;
               if(GetDebug() > 2) printf("In %s Real acceptance? %d\n",fCalorimeter.Data(),inacceptance);
             }
-            else{
+            else
+            {
               if(GetFiducialCut()->IsInFiducialCut(lv,fCalorimeter)) 
                 inacceptance = kTRUE ;
               if(GetDebug() > 2) printf("In %s fiducial cut acceptance? %d\n",fCalorimeter.Data(),inacceptance);
             }
           }       
-          else if(fCalorimeter == "EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
-            if(GetEMCALGeometry()){
-              
+          else if(fCalorimeter == "EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet())
+          {
+            if(GetEMCALGeometry())
+            {
               Int_t absID=0;
               
               GetEMCALGeometry()->GetAbsCellIdFromEtaPhi(prim->Eta(),prim->Phi(),absID);
@@ -317,7 +711,8 @@ void AliAnaPhoton::FillAcceptanceHistograms(){
               //                    inacceptance = kTRUE;
               if(GetDebug() > 2) printf("In %s Real acceptance? %d\n",fCalorimeter.Data(),inacceptance);
             }
-            else{
+            else
+            {
               if(GetFiducialCut()->IsInFiducialCut(lv,fCalorimeter)) 
                 inacceptance = kTRUE ;
               if(GetDebug() > 2) printf("In %s fiducial cut acceptance? %d\n",fCalorimeter.Data(),inacceptance);
@@ -325,154 +720,91 @@ void AliAnaPhoton::FillAcceptanceHistograms(){
           }      //In EMCAL
           
           //Fill histograms
-          
           fhYPrimMC[kmcPPhoton]->Fill(photonPt, photonY) ;
           if(TMath::Abs(photonY) < 1.0)
           {
             fhEPrimMC  [kmcPPhoton]->Fill(photonE ) ;
             fhPtPrimMC [kmcPPhoton]->Fill(photonPt) ;
             fhPhiPrimMC[kmcPPhoton]->Fill(photonE , photonPhi) ;
-            fhYPrimMC[kmcPPhoton]  ->Fill(photonE , photonEta) ;
+            fhYPrimMC  [kmcPPhoton]->Fill(photonE , photonEta) ;
           }
-          if(inacceptance){
-            fhEPrimMCAcc[kmcPPhoton]  ->Fill(photonE ) ;
-            fhPtPrimMCAcc[kmcPPhoton] ->Fill(photonPt) ;
+          if(inacceptance)
+          {
+            fhEPrimMCAcc  [kmcPPhoton]->Fill(photonE ) ;
+            fhPtPrimMCAcc [kmcPPhoton]->Fill(photonPt) ;
             fhPhiPrimMCAcc[kmcPPhoton]->Fill(photonE , photonPhi) ;
-            fhYPrimMCAcc[kmcPPhoton]  ->Fill(photonE , photonY) ;
+            fhYPrimMCAcc  [kmcPPhoton]->Fill(photonE , photonY) ;
           }//Accepted
           
           //Origin of photon
           if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPrompt) && fhEPrimMC[kmcPPrompt])
           {
-            fhYPrimMC[kmcPPrompt]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPPrompt]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPPrompt]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPPrompt]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPPrompt]  ->Fill(photonE , photonEta) ;
-            }   
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPPrompt]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPPrompt] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPPrompt]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPPrompt]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPPrompt;
           }
           else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCFragmentation) && fhEPrimMC[kmcPFragmentation])
           {
-            fhYPrimMC[kmcPFragmentation]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPFragmentation]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPFragmentation]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPFragmentation]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPFragmentation]  ->Fill(photonE , photonEta) ;
-            }  
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPFragmentation]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPFragmentation] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPFragmentation]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPFragmentation]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPFragmentation ;
           }
           else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCISR) && fhEPrimMC[kmcPISR])
           {
-            fhYPrimMC[kmcPISR]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPISR]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPISR]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPISR]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPISR]->Fill(photonE , photonEta) ;
-            }            
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPISR]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPISR] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPISR]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPISR]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPISR;
           }
           else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0Decay)&& fhEPrimMC[kmcPPi0Decay])
           {
-            fhYPrimMC[kmcPPi0Decay]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPPi0Decay]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPPi0Decay]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPPi0Decay]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPPi0Decay]  ->Fill(photonE , photonEta) ;
-            }     
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPPi0Decay]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPPi0Decay] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPPi0Decay]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPPi0Decay]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPPi0Decay;
           }
           else if( (GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEtaDecay) || 
                     GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCOtherDecay)) && fhEPrimMC[kmcPOtherDecay])
           {
-            fhYPrimMC[kmcPOtherDecay]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPOtherDecay]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPOtherDecay]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPOtherDecay]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPOtherDecay]  ->Fill(photonE , photonEta) ;
-            } 
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPOtherDecay]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPOtherDecay] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPOtherDecay]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPOtherDecay]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPOtherDecay;
           }
           else if(fhEPrimMC[kmcPOther])
           {
-            fhYPrimMC[kmcPOther]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPOther]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPOther]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPOther]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPOther]  ->Fill(photonE , photonEta) ;
-            }
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPOther]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPOther] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPOther]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPOther]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPOther;
           }//Other origin
+          
+          fhYPrimMC[mcIndex]->Fill(photonPt, photonY) ;
+          if(TMath::Abs(photonY) < 1.0)
+          {
+            fhEPrimMC  [mcIndex]->Fill(photonE ) ;
+            fhPtPrimMC [mcIndex]->Fill(photonPt) ;
+            fhPhiPrimMC[mcIndex]->Fill(photonE , photonPhi) ;
+            fhYPrimMC  [mcIndex]->Fill(photonE , photonEta) ;
+          }
+          if(inacceptance)
+          {
+            fhEPrimMCAcc  [mcIndex]->Fill(photonE ) ;
+            fhPtPrimMCAcc [mcIndex]->Fill(photonPt) ;
+            fhPhiPrimMCAcc[mcIndex]->Fill(photonE , photonPhi) ;
+            fhYPrimMCAcc  [mcIndex]->Fill(photonE , photonY) ;
+          }//Accepted
+          
         }// Primary photon 
       }//loop on primaries     
     }//stack exists and data is MC
   }//read stack
-  else if(GetReader()->ReadAODMCParticles()){
-    TClonesArray * mcparticles = GetReader()->GetAODMCParticles(0);
-    if(mcparticles){
+  else if(GetReader()->ReadAODMCParticles())
+  {
+    TClonesArray * mcparticles = GetReader()->GetAODMCParticles();
+    if(mcparticles)
+    {
       Int_t nprim = mcparticles->GetEntriesFast();
       
       for(Int_t i=0; i < nprim; i++)
       {
         AliAODMCParticle * prim = (AliAODMCParticle *) mcparticles->At(i);   
         
-        Int_t pdg = prim->GetPdgCode();
+        pdg = prim->GetPdgCode();
         
-        if(pdg == 22){
-          
+        if(pdg == 22)
+        {
           // Get tag of this particle photon from fragmentation, decay, prompt ...
-          Int_t tag = GetMCAnalysisUtils()->CheckOrigin(i,GetReader(), 0);
-          if(!GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPhoton)){
+          tag = GetMCAnalysisUtils()->CheckOrigin(i,GetReader());
+          if(!GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPhoton))
+          {
             //A conversion photon from a hadron, skip this kind of photon
-//            printf("AliAnaPhoton::FillAcceptanceHistograms() - not a photon, weird!: tag %d, conv %d, pi0 %d, hadron %d, electron %d, unk %d, muon %d,pion %d, proton %d, neutron %d, kaon %d, antiproton %d, antineutron %d\n",tag,
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCConversion),
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0),
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCOther),
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCElectron),
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCUnknown),
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCMuon), 
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPion),
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCProton), 
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCAntiNeutron),
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCKaon), 
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCAntiProton), 
-//                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCAntiNeutron));
+            //            printf("AliAnaPhoton::FillAcceptanceHistograms() - not a photon, weird!\n ");
+            //            GetMCAnalysisUtils()->PrintMCTag(tag);
             
             return;
           }
@@ -480,19 +812,21 @@ void AliAnaPhoton::FillAcceptanceHistograms(){
           //Get photon kinematics
           if(prim->E() == TMath::Abs(prim->Pz()))  continue ; //Protection against floating point exception     
           
-          Double_t photonY  = 0.5*TMath::Log((prim->E()-prim->Pz())/(prim->E()+prim->Pz())) ;
-          Double_t photonE   = prim->E() ;
-          Double_t photonPt  = prim->Pt() ;
-          Double_t photonPhi = TMath::RadToDeg()*prim->Phi() ;
+          photonY   = 0.5*TMath::Log((prim->E()-prim->Pz())/(prim->E()+prim->Pz())) ;
+          photonE   = prim->E() ;
+          photonPt  = prim->Pt() ;
+          photonPhi = prim->Phi() ;
           if(photonPhi < 0) photonPhi+=TMath::TwoPi();
-          Double_t photonEta = prim->Eta() ;
+          photonEta = prim->Eta() ;
           
           //Check if photons hit the Calorimeter
           TLorentzVector lv;
           lv.SetPxPyPzE(prim->Px(),prim->Py(),prim->Pz(),prim->E());
-          Bool_t inacceptance = kFALSE;
-          if     (fCalorimeter == "PHOS"){
-            if(GetPHOSGeometry() && GetCaloUtils()->IsPHOSGeoMatrixSet()){
+          inacceptance = kFALSE;
+          if     (fCalorimeter == "PHOS")
+          {
+            if(GetPHOSGeometry() && GetCaloUtils()->IsPHOSGeoMatrixSet())
+            {
               Int_t mod ;
               Double_t x,z ;
               Double_t vtx[]={prim->Xv(),prim->Yv(),prim->Zv()};
@@ -500,15 +834,17 @@ void AliAnaPhoton::FillAcceptanceHistograms(){
                 inacceptance = kTRUE;
               if(GetDebug() > 2) printf("In %s Real acceptance? %d\n",fCalorimeter.Data(),inacceptance);
             }
-            else{
+            else
+            {
               if(GetFiducialCut()->IsInFiducialCut(lv,fCalorimeter)) 
                 inacceptance = kTRUE ;
               if(GetDebug() > 2) printf("In %s fiducial cut acceptance? %d\n",fCalorimeter.Data(),inacceptance);
             }
           }       
-          else if(fCalorimeter == "EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
-            if(GetEMCALGeometry()){
-              
+          else if(fCalorimeter == "EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet())
+          {
+            if(GetEMCALGeometry())
+            {
               Int_t absID=0;
               
               GetEMCALGeometry()->GetAbsCellIdFromEtaPhi(prim->Eta(),prim->Phi(),absID);
@@ -518,7 +854,8 @@ void AliAnaPhoton::FillAcceptanceHistograms(){
               
               if(GetDebug() > 2) printf("In %s Real acceptance? %d\n",fCalorimeter.Data(),inacceptance);
             }
-            else{
+            else
+            {
               if(GetFiducialCut()->IsInFiducialCut(lv,fCalorimeter)) 
                 inacceptance = kTRUE ;
               if(GetDebug() > 2) printf("In %s fiducial cut acceptance? %d\n",fCalorimeter.Data(),inacceptance);
@@ -535,112 +872,58 @@ void AliAnaPhoton::FillAcceptanceHistograms(){
             fhPhiPrimMC[kmcPPhoton]->Fill(photonE , photonPhi) ;
             fhYPrimMC[kmcPPhoton]->Fill(photonE , photonEta) ;
           }
-          if(inacceptance){
+          
+          if(inacceptance)
+          {
             fhEPrimMCAcc[kmcPPhoton]  ->Fill(photonE ) ;
             fhPtPrimMCAcc[kmcPPhoton] ->Fill(photonPt) ;
             fhPhiPrimMCAcc[kmcPPhoton]->Fill(photonE , photonPhi) ;
             fhYPrimMCAcc[kmcPPhoton]  ->Fill(photonE , photonY) ;
           }//Accepted
           
-          
           //Origin of photon
           if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPrompt) && fhEPrimMC[kmcPPrompt])
           {
-            fhYPrimMC[kmcPPrompt]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPPrompt]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPPrompt]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPPrompt]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPPrompt]->Fill(photonE , photonEta) ;
-            }   
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPPrompt]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPPrompt] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPPrompt]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPPrompt]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPPrompt;
           }
-          else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCFragmentation) && fhEPrimMC[kmcPFragmentation] )
+          else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCFragmentation) && fhEPrimMC[kmcPFragmentation])
           {
-            fhYPrimMC[kmcPFragmentation]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPFragmentation]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPFragmentation]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPFragmentation]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPFragmentation]->Fill(photonE , photonEta) ;
-            }  
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPFragmentation]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPFragmentation] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPFragmentation]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPFragmentation]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPFragmentation ;
           }
           else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCISR) && fhEPrimMC[kmcPISR])
           {
-            fhYPrimMC[kmcPISR]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPISR]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPISR]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPISR]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPISR]->Fill(photonE , photonEta) ;
-            }            
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPISR]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPISR] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPISR]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPISR]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPISR;
           }
           else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0Decay)&& fhEPrimMC[kmcPPi0Decay])
           {
-            fhYPrimMC[kmcPPi0Decay]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPPi0Decay]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPPi0Decay]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPPi0Decay]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPPi0Decay]->Fill(photonE , photonEta) ;
-            }     
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPPi0Decay]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPPi0Decay] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPPi0Decay]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPPi0Decay]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPPi0Decay;
           }
-          else if((GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEtaDecay) || 
-                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCOtherDecay) ) && fhEPrimMC[kmcPOtherDecay])
+          else if( (GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEtaDecay) || 
+                    GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCOtherDecay)) && fhEPrimMC[kmcPOtherDecay])
           {
-            fhYPrimMC[kmcPOtherDecay]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPOtherDecay]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPOtherDecay]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPOtherDecay]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPOtherDecay]->Fill(photonE , photonEta) ;
-            } 
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPOtherDecay]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPOtherDecay] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPOtherDecay]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPOtherDecay]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPOtherDecay;
           }
           else if(fhEPrimMC[kmcPOther])
           {
-            fhYPrimMC[kmcPOther]->Fill(photonPt, photonY) ;
-            if(TMath::Abs(photonY) < 1.0){
-              fhEPrimMC  [kmcPOther]->Fill(photonE ) ;
-              fhPtPrimMC [kmcPOther]->Fill(photonPt) ;
-              fhPhiPrimMC[kmcPOther]->Fill(photonE , photonPhi) ;
-              fhYPrimMC[kmcPOther]->Fill(photonE , photonEta) ;
-            }
-            if(inacceptance){
-              fhEPrimMCAcc[kmcPOther]  ->Fill(photonE ) ;
-              fhPtPrimMCAcc[kmcPOther] ->Fill(photonPt) ;
-              fhPhiPrimMCAcc[kmcPOther]->Fill(photonE , photonPhi) ;
-              fhYPrimMCAcc[kmcPOther]  ->Fill(photonE , photonY) ;
-            }//Accepted
+            mcIndex = kmcPOther;
           }//Other origin
+          
+          fhYPrimMC[mcIndex]->Fill(photonPt, photonY) ;
+          if(TMath::Abs(photonY) < 1.0)
+          {
+            fhEPrimMC  [mcIndex]->Fill(photonE ) ;
+            fhPtPrimMC [mcIndex]->Fill(photonPt) ;
+            fhPhiPrimMC[mcIndex]->Fill(photonE , photonPhi) ;
+            fhYPrimMC  [mcIndex]->Fill(photonE , photonEta) ;
+          }
+          if(inacceptance)
+          {
+            fhEPrimMCAcc  [mcIndex]->Fill(photonE ) ;
+            fhPtPrimMCAcc [mcIndex]->Fill(photonPt) ;
+            fhPhiPrimMCAcc[mcIndex]->Fill(photonE , photonPhi) ;
+            fhYPrimMCAcc  [mcIndex]->Fill(photonE , photonY) ;
+          }//Accepted
+                    
         }// Primary photon 
       }//loop on primaries     
       
@@ -648,10 +931,158 @@ void AliAnaPhoton::FillAcceptanceHistograms(){
   }    // read AOD MC
 }
 
-//__________________________________________________________________
-void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t mcTag){
+//___________________________________________________________________
+void AliAnaPhoton::FillPileUpHistogramsPerEvent(TObjArray * clusters) 
+{
+  // Fill some histograms per event to understand pile-up
+  // Open the time cut in the reader to be more meaningful
   
-  //Fill cluster Shower Shape histograms
+  if(!fFillPileUpHistograms) return;
+    
+  // Loop on clusters, get the maximum energy cluster as reference
+  Int_t nclusters = clusters->GetEntriesFast();
+  Int_t   idMax = 0; 
+  Float_t  eMax = 0;
+  Float_t  tMax = 0;
+  for(Int_t iclus = 0; iclus < nclusters ; iclus++)
+  {
+         AliVCluster * clus =  (AliVCluster*) (clusters->At(iclus));   
+    if(clus->E() > eMax && TMath::Abs(clus->GetTOF()*1e9) < 20)
+    {
+      eMax  = clus->E();
+      tMax  = clus->GetTOF()*1e9;
+      idMax = iclus;
+    }
+  }
+
+  if(eMax < 5) return;
+  
+  // Loop again on clusters to compare this max cluster t and the rest of the clusters, if E > 0.3
+  Int_t n20  = 0;
+  Int_t n40  = 0;
+  Int_t n    = 0;
+  Int_t nOK  = 0;
+
+  for(Int_t iclus = 0; iclus < nclusters ; iclus++)
+  {
+         AliVCluster * clus =  (AliVCluster*) (clusters->At(iclus));   
+    
+    if(clus->E() < 0.3 || iclus==idMax) continue;
+    
+    Float_t tdiff = TMath::Abs(tMax-clus->GetTOF()*1e9);
+    n++;
+    if(tdiff < 20) nOK++;
+    else
+    {
+      n20++;
+      if(tdiff > 40 ) n40++;
+    }
+  }
+  
+  // Check pile-up and fill histograms depending on the different cluster multiplicities
+  if(GetReader()->IsPileUpFromSPD())
+  {    
+    fhClusterMultSPDPileUp[0]->Fill(eMax,n  );
+    fhClusterMultSPDPileUp[1]->Fill(eMax,nOK);
+    fhClusterMultSPDPileUp[2]->Fill(eMax,n20);
+    fhClusterMultSPDPileUp[3]->Fill(eMax,n40);
+  }
+  else 
+  {
+    fhClusterMultNoPileUp[0]->Fill(eMax,n  );
+    fhClusterMultNoPileUp[1]->Fill(eMax,nOK);
+    fhClusterMultNoPileUp[2]->Fill(eMax,n20);
+    fhClusterMultNoPileUp[3]->Fill(eMax,n40);    
+  }  
+  
+}
+
+
+//_________________________________________________________________________________________________
+void AliAnaPhoton::FillPileUpHistograms(Float_t energy, Float_t pt, Float_t time)
+{
+  // Fill some histograms to understand pile-up
+  if(!fFillPileUpHistograms) return;
+  
+  //printf("E %f, time %f\n",energy,time);
+  AliVEvent * event = GetReader()->GetInputEvent();
+  
+  if(GetReader()->IsPileUpFromSPD())               fhPtPhotonPileUp[0]->Fill(pt);
+  if(GetReader()->IsPileUpFromEMCal())             fhPtPhotonPileUp[1]->Fill(pt);
+  if(GetReader()->IsPileUpFromSPDOrEMCal())        fhPtPhotonPileUp[2]->Fill(pt);
+  if(GetReader()->IsPileUpFromSPDAndEMCal())       fhPtPhotonPileUp[3]->Fill(pt);
+  if(GetReader()->IsPileUpFromSPDAndNotEMCal())    fhPtPhotonPileUp[4]->Fill(pt);
+  if(GetReader()->IsPileUpFromEMCalAndNotSPD())    fhPtPhotonPileUp[5]->Fill(pt);
+  if(GetReader()->IsPileUpFromNotSPDAndNotEMCal()) fhPtPhotonPileUp[6]->Fill(pt);
+  
+  fhTimeENoCut->Fill(energy,time);
+  if(GetReader()->IsPileUpFromSPD())     fhTimeESPD     ->Fill(energy,time);
+  if(event->IsPileupFromSPDInMultBins()) fhTimeESPDMulti->Fill(energy,time);
+  
+  if(energy < 8) return; // Fill time figures for high energy clusters not too close to trigger threshold
+  
+  AliESDEvent* esdEv = dynamic_cast<AliESDEvent*> (event);
+  AliAODEvent* aodEv = dynamic_cast<AliAODEvent*> (event);
+  
+  // N pile up vertices
+  Int_t nVerticesSPD    = -1;
+  Int_t nVerticesTracks = -1;
+  
+  if      (esdEv)
+  {
+    nVerticesSPD    = esdEv->GetNumberOfPileupVerticesSPD();
+    nVerticesTracks = esdEv->GetNumberOfPileupVerticesTracks();
+
+  }//ESD
+  else if (aodEv)
+  {
+    nVerticesSPD    = aodEv->GetNumberOfPileupVerticesSPD();
+    nVerticesTracks = aodEv->GetNumberOfPileupVerticesTracks();
+  }//AOD
+  
+  fhTimeNPileUpVertSPD  ->Fill(time,nVerticesSPD);
+  fhTimeNPileUpVertTrack->Fill(time,nVerticesTracks);
+  
+  //printf("Is SPD %d, Is SPD Multi %d, n spd %d, n track %d\n", 
+  //       GetReader()->IsPileUpFromSPD(),event->IsPileupFromSPDInMultBins(),nVerticesSPD,nVerticesTracks);
+  
+  Int_t ncont = -1;
+  Float_t z1 = -1, z2 = -1;
+  Float_t diamZ = -1;
+  for(Int_t iVert=0; iVert<nVerticesSPD;iVert++)
+  {
+    if      (esdEv)
+    {
+      const AliESDVertex* pv=esdEv->GetPileupVertexSPD(iVert);
+      ncont=pv->GetNContributors();
+      z1 = esdEv->GetPrimaryVertexSPD()->GetZ();
+      z2 = pv->GetZ();
+      diamZ = esdEv->GetDiamondZ();
+    }//ESD
+    else if (aodEv)
+    {
+      AliAODVertex *pv=aodEv->GetVertex(iVert);
+      if(pv->GetType()!=AliAODVertex::kPileupSPD) continue;
+      ncont=pv->GetNContributors();
+      z1=aodEv->GetPrimaryVertexSPD()->GetZ();
+      z2=pv->GetZ();
+      diamZ = aodEv->GetDiamondZ();
+    }// AOD
+    
+    Double_t distZ  = TMath::Abs(z2-z1);
+    diamZ  = TMath::Abs(z2-diamZ);
+
+    fhTimeNPileUpVertContributors  ->Fill(time,ncont);
+    fhTimePileUpMainVertexZDistance->Fill(time,distZ);
+    fhTimePileUpMainVertexZDiamond ->Fill(time,diamZ);
+
+  }// loop
+}
+
+//____________________________________________________________________________________
+void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, Int_t mcTag)
+{
+    //Fill cluster Shower Shape histograms
   
   if(!fFillSSHistograms || GetMixedEvent()) return;
 
@@ -662,9 +1093,12 @@ void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t
   Float_t disp    = cluster->GetDispersion()*cluster->GetDispersion();
   
   TLorentzVector mom;
-  if(GetReader()->GetDataType() != AliCaloTrackReader::kMC){
-    cluster->GetMomentum(mom,GetVertex(0)) ;}//Assume that come from vertex in straight line
-  else{
+  if(GetReader()->GetDataType() != AliCaloTrackReader::kMC)
+  {
+    cluster->GetMomentum(mom,GetVertex(0)) ;
+  }//Assume that come from vertex in straight line
+  else
+  {
     Double_t vertex[]={0,0,0};
     cluster->GetMomentum(mom,vertex) ;
   }
@@ -677,19 +1111,57 @@ void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t
   fhLam1E ->Fill(energy,lambda1);
   fhDispE ->Fill(energy,disp);
     
-  if(fCalorimeter == "EMCAL" && GetModuleNumber(cluster) > 5){
+  if(fCalorimeter == "EMCAL" && GetModuleNumber(cluster) > 5)
+  {
     fhLam0ETRD->Fill(energy,lambda0);
     fhLam1ETRD->Fill(energy,lambda1);
     fhDispETRD->Fill(energy,disp);
   }
   
+  Float_t l0   = 0., l1   = 0.;
+  Float_t dispp= 0., dEta = 0., dPhi    = 0.; 
+  Float_t sEta = 0., sPhi = 0., sEtaPhi = 0.;  
+  if(fCalorimeter == "EMCAL" && !fFillOnlySimpleSSHisto)
+  {
+    GetCaloUtils()->GetEMCALRecoUtils()->RecalculateClusterShowerShapeParameters(GetEMCALGeometry(), GetReader()->GetInputEvent()->GetEMCALCells(), cluster,
+                                                                                 l0, l1, dispp, dEta, dPhi, sEta, sPhi, sEtaPhi);
+    //printf("AliAnaPhoton::FillShowerShapeHistogram - l0 %2.6f, l1 %2.6f, disp %2.6f, dEta %2.6f, dPhi %2.6f, sEta %2.6f, sPhi %2.6f, sEtaPhi %2.6f \n",
+    //       l0, l1, dispp, dEta, dPhi, sEta, sPhi, sEtaPhi );
+    //printf("AliAnaPhoton::FillShowerShapeHistogram - dispersion %f, dispersion eta+phi %f \n",
+    //       disp, dPhi+dEta );
+    fhDispEtaE        -> Fill(energy,dEta);
+    fhDispPhiE        -> Fill(energy,dPhi);
+    fhSumEtaE         -> Fill(energy,sEta);
+    fhSumPhiE         -> Fill(energy,sPhi);
+    fhSumEtaPhiE      -> Fill(energy,sEtaPhi);
+    fhDispEtaPhiDiffE -> Fill(energy,dPhi-dEta);
+    if(dEta+dPhi>0)fhSphericityE     -> Fill(energy,(dPhi-dEta)/(dEta+dPhi));
+    if(dEta+sEta>0)fhDispSumEtaDiffE -> Fill(energy,(dEta-sEta)/((dEta+sEta)/2.));
+    if(dPhi+sPhi>0)fhDispSumPhiDiffE -> Fill(energy,(dPhi-sPhi)/((dPhi+sPhi)/2.));  
+    
+    Int_t ebin = -1;
+    if      (energy < 2 ) ebin = 0;
+    else if (energy < 4 ) ebin = 1;
+    else if (energy < 6 ) ebin = 2;
+    else if (energy < 10) ebin = 3;
+    else if (energy < 15) ebin = 4;  
+    else if (energy < 20) ebin = 5;  
+    else                  ebin = 6;  
+    
+    fhDispEtaDispPhi[ebin]->Fill(dEta   ,dPhi);
+    fhLambda0DispEta[ebin]->Fill(lambda0,dEta);
+    fhLambda0DispPhi[ebin]->Fill(lambda0,dPhi);
+    
+  }
+  
   // if track-matching was of, check effect of track-matching residual cut 
   
   if(!fRejectTrackMatch)
   {
     Float_t dZ  = cluster->GetTrackDz();
     Float_t dR  = cluster->GetTrackDx();
-    if(cluster->IsEMCAL() && GetCaloUtils()->IsRecalculationOfClusterTrackMatchingOn()){
+    if(cluster->IsEMCAL() && GetCaloUtils()->IsRecalculationOfClusterTrackMatchingOn())
+    {
       dR = 2000., dZ = 2000.;
       GetCaloUtils()->GetEMCALRecoUtils()->GetMatchedResiduals(cluster->GetID(),dZ,dR);
     }   
@@ -700,7 +1172,8 @@ void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t
       fhLam1ETM ->Fill(energy,lambda1);
       fhDispETM ->Fill(energy,disp);
       
-      if(fCalorimeter == "EMCAL" && GetModuleNumber(cluster) > 5){
+      if(fCalorimeter == "EMCAL" && GetModuleNumber(cluster) > 5)
+      {
         fhLam0ETMTRD->Fill(energy,lambda0);
         fhLam1ETMTRD->Fill(energy,lambda1);
         fhDispETMTRD->Fill(energy,disp);
@@ -708,43 +1181,50 @@ void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t
     }
   }// if track-matching was of, check effect of matching residual cut  
   
-  if(energy < 2){
-    fhNCellsLam0LowE ->Fill(ncells,lambda0);
-    fhNCellsLam1LowE ->Fill(ncells,lambda1);
-    fhNCellsDispLowE ->Fill(ncells,disp);
-    
-    fhLam1Lam0LowE  ->Fill(lambda1,lambda0);
-    fhLam0DispLowE  ->Fill(lambda0,disp);
-    fhDispLam1LowE  ->Fill(disp,lambda1);
-    fhEtaLam0LowE   ->Fill(eta,lambda0);
-    fhPhiLam0LowE   ->Fill(phi,lambda0);  
-    
-  }
-  else {
-    fhNCellsLam0HighE ->Fill(ncells,lambda0);
-    fhNCellsLam1HighE ->Fill(ncells,lambda1);
-    fhNCellsDispHighE ->Fill(ncells,disp);
-
-    fhLam1Lam0HighE  ->Fill(lambda1,lambda0);
-    fhLam0DispHighE  ->Fill(lambda0,disp);
-    fhDispLam1HighE  ->Fill(disp,lambda1);
-    fhEtaLam0HighE   ->Fill(eta, lambda0);
-    fhPhiLam0HighE   ->Fill(phi, lambda0);
-  }
   
-  if(IsDataMC()){
-
+  if(!fFillOnlySimpleSSHisto){
+    if(energy < 2)
+    {
+      fhNCellsLam0LowE ->Fill(ncells,lambda0);
+      fhNCellsLam1LowE ->Fill(ncells,lambda1);
+      fhNCellsDispLowE ->Fill(ncells,disp);
+      
+      fhLam1Lam0LowE  ->Fill(lambda1,lambda0);
+      fhLam0DispLowE  ->Fill(lambda0,disp);
+      fhDispLam1LowE  ->Fill(disp,lambda1);
+      fhEtaLam0LowE   ->Fill(eta,lambda0);
+      fhPhiLam0LowE   ->Fill(phi,lambda0);  
+    }
+    else 
+    {
+      fhNCellsLam0HighE ->Fill(ncells,lambda0);
+      fhNCellsLam1HighE ->Fill(ncells,lambda1);
+      fhNCellsDispHighE ->Fill(ncells,disp);
+      
+      fhLam1Lam0HighE  ->Fill(lambda1,lambda0);
+      fhLam0DispHighE  ->Fill(lambda0,disp);
+      fhDispLam1HighE  ->Fill(disp,lambda1);
+      fhEtaLam0HighE   ->Fill(eta, lambda0);
+      fhPhiLam0HighE   ->Fill(phi, lambda0);
+    }
+  }
+  if(IsDataMC())
+  {
     AliVCaloCells* cells = 0;
     if(fCalorimeter == "EMCAL") cells = GetEMCALCells();
     else                        cells = GetPHOSCells();
     
     //Fill histograms to check shape of embedded clusters
     Float_t fraction = 0;
-    if(GetReader()->IsEmbeddedClusterSelectionOn()){//Only working for EMCAL
-
+   // printf("check embedding %i\n",GetReader()->IsEmbeddedClusterSelectionOn());
+  
+    if(GetReader()->IsEmbeddedClusterSelectionOn())
+    {//Only working for EMCAL
+   //  printf("embedded\n");
       Float_t clusterE = 0; // recalculate in case corrections applied.
       Float_t cellE    = 0;
-      for(Int_t icell = 0; icell < cluster->GetNCells(); icell++){
+      for(Int_t icell  = 0; icell < cluster->GetNCells(); icell++)
+      {
         cellE    = cells->GetCellAmplitude(cluster->GetCellAbsId(icell));
         clusterE+=cellE;  
         fraction+=cellE*cluster->GetCellAmplitudeFraction(icell);
@@ -761,36 +1241,24 @@ void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t
     }  // embedded fraction    
     
     // Get the fraction of the cluster energy that carries the cell with highest energy
-    Int_t absID             =-1 ;
+    Int_t   absID           =-1 ;
     Float_t maxCellFraction = 0.;
     
     absID = GetCaloUtils()->GetMaxEnergyCell(cells, cluster,maxCellFraction);
     
     // Check the origin and fill histograms
-    if( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCPhoton) && 
+    
+    Int_t mcIndex = -1;
+    
+    if( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCPhoton)     && 
        !GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCConversion) &&
-       !GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCPi0) &&
-       !GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCEta)){
-      fhMCELambda0[kmcssPhoton]    ->Fill(energy, lambda0);
-      fhMCELambda1[kmcssPhoton]    ->Fill(energy, lambda1);
-      fhMCEDispersion[kmcssPhoton] ->Fill(energy, disp);
-      fhMCNCellsE[kmcssPhoton]     ->Fill(energy, ncells);
-      fhMCMaxCellDiffClusterE[kmcssPhoton]->Fill(energy,maxCellFraction);
-            
-      if     (energy < 2.){
-        fhMCLambda0vsClusterMaxCellDiffE0[kmcssPhoton]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE0[kmcssPhoton] ->Fill(ncells,  maxCellFraction);
-      }
-      else if(energy < 6.){
-        fhMCLambda0vsClusterMaxCellDiffE2[kmcssPhoton]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE2[kmcssPhoton] ->Fill(ncells,  maxCellFraction);
-      }
-      else{
-        fhMCLambda0vsClusterMaxCellDiffE6[kmcssPhoton]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE6[kmcssPhoton] ->Fill(ncells,  maxCellFraction);
-      }
-      
-      if(!GetReader()->IsEmbeddedClusterSelectionOn()){
+       !GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCPi0)        &&
+       !GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCEta))
+    {
+      mcIndex = kmcssPhoton ;
+
+      if(!GetReader()->IsEmbeddedClusterSelectionOn())
+      {
         //Check particle overlaps in cluster
         
         // Compare the primary depositing more energy with the rest, 
@@ -799,29 +1267,35 @@ void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t
         TLorentzVector momentum; TVector3 prodVertex;
         Int_t ancLabel = 0;
         Int_t noverlaps = 1;      
-        for (UInt_t ilab = 0; ilab < cluster->GetNLabels(); ilab++ ) {
-          ancLabel = GetMCAnalysisUtils()->CheckCommonAncestor(cluster->GetLabels()[0],cluster->GetLabels()[ilab], GetReader(),ancPDG,ancStatus,momentum,prodVertex);
+        for (UInt_t ilab = 0; ilab < cluster->GetNLabels(); ilab++ ) 
+        {
+          ancLabel = GetMCAnalysisUtils()->CheckCommonAncestor(cluster->GetLabels()[0],cluster->GetLabels()[ilab], 
+                                                               GetReader(),ancPDG,ancStatus,momentum,prodVertex);
           if(ancPDG!=22 && TMath::Abs(ancPDG)!=11) noverlaps++;
         }
         //printf("N overlaps %d \n",noverlaps);
         
-        if(noverlaps == 1){
+        if(noverlaps == 1)
+        {
           fhMCPhotonELambda0NoOverlap  ->Fill(energy, lambda0);
         }
-        else if(noverlaps == 2){        
+        else if(noverlaps == 2)
+        {        
           fhMCPhotonELambda0TwoOverlap ->Fill(energy, lambda0);
         }
-        else if(noverlaps > 2){          
+        else if(noverlaps > 2)
+        {          
           fhMCPhotonELambda0NOverlap   ->Fill(energy, lambda0);
         }
-        else {
+        else 
+        {
           printf("AliAnaPhoton::FillShowerShapeHistogram() - n overlaps = %d!!", noverlaps);
         }
       }//No embedding
       
       //Fill histograms to check shape of embedded clusters
-      if(GetReader()->IsEmbeddedClusterSelectionOn()){
-        
+      if(GetReader()->IsEmbeddedClusterSelectionOn())
+      {
         if     (fraction > 0.9) 
         {
           fhEmbedPhotonELambda0FullSignal   ->Fill(energy, lambda0);
@@ -841,71 +1315,22 @@ void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t
       } // embedded
       
     }//photon   no conversion
-    else if  ( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCElectron)){
-      fhMCELambda0[kmcssElectron]    ->Fill(energy, lambda0);
-      fhMCELambda1[kmcssElectron]    ->Fill(energy, lambda1);
-      fhMCEDispersion[kmcssElectron] ->Fill(energy, disp);
-      fhMCNCellsE[kmcssElectron]     ->Fill(energy, ncells);
-      fhMCMaxCellDiffClusterE[kmcssElectron]->Fill(energy,maxCellFraction);
-
-      if     (energy < 2.){
-        fhMCLambda0vsClusterMaxCellDiffE0[kmcssElectron]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE0[kmcssElectron] ->Fill(ncells,  maxCellFraction);
-      }
-      else if(energy < 6.){
-        fhMCLambda0vsClusterMaxCellDiffE2[kmcssElectron]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE2[kmcssElectron] ->Fill(ncells,  maxCellFraction);
-      }
-      else{
-        fhMCLambda0vsClusterMaxCellDiffE6[kmcssElectron]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE6[kmcssElectron] ->Fill(ncells,  maxCellFraction);
-      }
+    else if  ( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCElectron))
+    {
+      mcIndex = kmcssElectron ;
     }//electron
     else if  ( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCPhoton) && 
-              GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCConversion) ){
-      fhMCELambda0[kmcssConversion]    ->Fill(energy, lambda0);
-      fhMCELambda1[kmcssConversion]    ->Fill(energy, lambda1);
-      fhMCEDispersion[kmcssConversion] ->Fill(energy, disp);
-      fhMCNCellsE[kmcssConversion]     ->Fill(energy, ncells);
-      fhMCMaxCellDiffClusterE[kmcssConversion]->Fill(energy,maxCellFraction);
-
-      if     (energy < 2.){
-        fhMCLambda0vsClusterMaxCellDiffE0[kmcssConversion]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE0[kmcssConversion] ->Fill(ncells,  maxCellFraction);
-      }
-      else if(energy < 6.){
-        fhMCLambda0vsClusterMaxCellDiffE2[kmcssConversion]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE2[kmcssConversion] ->Fill(ncells,  maxCellFraction);
-      }
-      else{
-        fhMCLambda0vsClusterMaxCellDiffE6[kmcssConversion]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE6[kmcssConversion] ->Fill(ncells,  maxCellFraction);
-      }      
-      
+               GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCConversion) )
+    {
+      mcIndex = kmcssConversion ;
     }//conversion photon
-    else if  ( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCPi0)  ){
-      fhMCELambda0[kmcssPi0]    ->Fill(energy, lambda0);
-      fhMCELambda1[kmcssPi0]    ->Fill(energy, lambda1);
-      fhMCEDispersion[kmcssPi0] ->Fill(energy, disp);
-      fhMCNCellsE[kmcssPi0]     ->Fill(energy, ncells);
-      fhMCMaxCellDiffClusterE[kmcssPi0]->Fill(energy,maxCellFraction);
-
-      if     (energy < 2.){
-        fhMCLambda0vsClusterMaxCellDiffE0[kmcssPi0]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE0[kmcssPi0] ->Fill(ncells,  maxCellFraction);
-      }
-      else if(energy < 6.){
-        fhMCLambda0vsClusterMaxCellDiffE2[kmcssPi0]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE2[kmcssPi0] ->Fill(ncells,  maxCellFraction);
-      }
-      else{
-        fhMCLambda0vsClusterMaxCellDiffE6[kmcssPi0]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE6[kmcssPi0] ->Fill(ncells,  maxCellFraction);
-      }      
+    else if  ( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCPi0)  )
+    {
+      mcIndex = kmcssPi0 ;
       
       //Fill histograms to check shape of embedded clusters
-      if(GetReader()->IsEmbeddedClusterSelectionOn()){
-        
+      if(GetReader()->IsEmbeddedClusterSelectionOn())
+      {
         if     (fraction > 0.9) 
         {
           fhEmbedPi0ELambda0FullSignal   ->Fill(energy, lambda0);
@@ -925,56 +1350,68 @@ void  AliAnaPhoton::FillShowerShapeHistograms(AliVCluster* cluster, const Int_t
       } // embedded      
       
     }//pi0
-    else if  ( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCEta)  ){
-      fhMCELambda0[kmcssEta]    ->Fill(energy, lambda0);
-      fhMCELambda1[kmcssEta]    ->Fill(energy, lambda1);
-      fhMCEDispersion[kmcssEta] ->Fill(energy, disp);
-      fhMCNCellsE[kmcssEta]     ->Fill(energy, ncells);
-      fhMCMaxCellDiffClusterE[kmcssEta]->Fill(energy,maxCellFraction);
-
-      if     (energy < 2.){
-        fhMCLambda0vsClusterMaxCellDiffE0[kmcssEta]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE0[kmcssEta] ->Fill(ncells,  maxCellFraction);
+    else if  ( GetMCAnalysisUtils()->CheckTagBit(mcTag,AliMCAnalysisUtils::kMCEta)  )
+    {
+      mcIndex = kmcssEta ;
+    }//eta    
+    else 
+    {
+      mcIndex = kmcssOther ; 
+    }//other particles 
+    
+    fhMCELambda0           [mcIndex]->Fill(energy, lambda0);
+    fhMCELambda1           [mcIndex]->Fill(energy, lambda1);
+    fhMCEDispersion        [mcIndex]->Fill(energy, disp);
+    fhMCNCellsE            [mcIndex]->Fill(energy, ncells);
+    fhMCMaxCellDiffClusterE[mcIndex]->Fill(energy, maxCellFraction);
+    
+    if(!fFillOnlySimpleSSHisto)
+    {
+      if     (energy < 2.)
+      {
+        fhMCLambda0vsClusterMaxCellDiffE0[mcIndex]->Fill(lambda0, maxCellFraction);
+        fhMCNCellsvsClusterMaxCellDiffE0 [mcIndex]->Fill(ncells,  maxCellFraction);
       }
-      else if(energy < 6.){
-        fhMCLambda0vsClusterMaxCellDiffE2[kmcssEta]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE2[kmcssEta] ->Fill(ncells,  maxCellFraction);
+      else if(energy < 6.)
+      {
+        fhMCLambda0vsClusterMaxCellDiffE2[mcIndex]->Fill(lambda0, maxCellFraction);
+        fhMCNCellsvsClusterMaxCellDiffE2 [mcIndex]->Fill(ncells,  maxCellFraction);
       }
-      else{
-        fhMCLambda0vsClusterMaxCellDiffE6[kmcssEta]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE6[kmcssEta] ->Fill(ncells,  maxCellFraction);
+      else
+      {
+        fhMCLambda0vsClusterMaxCellDiffE6[mcIndex]->Fill(lambda0, maxCellFraction);
+        fhMCNCellsvsClusterMaxCellDiffE6 [mcIndex]->Fill(ncells,  maxCellFraction);
       }
       
-    }//eta    
-    else {
-      fhMCELambda0[kmcssOther]    ->Fill(energy, lambda0);
-      fhMCELambda1[kmcssOther]    ->Fill(energy, lambda1);
-      fhMCEDispersion[kmcssOther] ->Fill(energy, disp);
-      fhMCNCellsE[kmcssOther]     ->Fill(energy, ncells);
-      fhMCMaxCellDiffClusterE[kmcssOther]->Fill(energy,maxCellFraction);
-
-      if     (energy < 2.){
-        fhMCLambda0vsClusterMaxCellDiffE0[kmcssOther]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE0[kmcssOther] ->Fill(ncells,  maxCellFraction);
-      }
-      else if(energy < 6.){
-        fhMCLambda0vsClusterMaxCellDiffE2[kmcssOther]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE2[kmcssOther] ->Fill(ncells,  maxCellFraction);
+      if(fCalorimeter == "EMCAL")
+      {
+        fhMCEDispEta        [mcIndex]-> Fill(energy,dEta);
+        fhMCEDispPhi        [mcIndex]-> Fill(energy,dPhi);
+        fhMCESumEtaPhi      [mcIndex]-> Fill(energy,sEtaPhi);
+        fhMCEDispEtaPhiDiff [mcIndex]-> Fill(energy,dPhi-dEta);
+        if(dEta+dPhi>0)fhMCESphericity[mcIndex]-> Fill(energy,(dPhi-dEta)/(dEta+dPhi));  
+        
+        Int_t ebin = -1;
+        if      (energy < 2 ) ebin = 0;
+        else if (energy < 4 ) ebin = 1;
+        else if (energy < 6 ) ebin = 2;
+        else if (energy < 10) ebin = 3;
+        else if (energy < 15) ebin = 4;  
+        else if (energy < 20) ebin = 5;  
+        else                  ebin = 6;  
+        
+        fhMCDispEtaDispPhi[ebin][mcIndex]->Fill(dEta   ,dPhi);
+        fhMCLambda0DispEta[ebin][mcIndex]->Fill(lambda0,dEta);
+        fhMCLambda0DispPhi[ebin][mcIndex]->Fill(lambda0,dPhi);      
       }
-      else{
-        fhMCLambda0vsClusterMaxCellDiffE6[kmcssOther]->Fill(lambda0, maxCellFraction);
-        fhMCNCellsvsClusterMaxCellDiffE6[kmcssOther] ->Fill(ncells,  maxCellFraction);
-      }            
-      
-    }//other particles 
-    
+    }
   }//MC data
   
 }
 
 //__________________________________________________________________________
 void AliAnaPhoton::FillTrackMatchingResidualHistograms(AliVCluster* cluster, 
-                                                       const Int_t cut)
+                                                       Int_t cut)
 {
   // If selected, fill histograms with residuals of matched clusters, help to define track matching cut
   // Residual filled for different cuts 0 (No cut), after 1 PID cut
@@ -1032,7 +1469,7 @@ void AliAnaPhoton::FillTrackMatchingResidualHistograms(AliVCluster* cluster,
       if(IsDataMC())
       {
         
-        Int_t tag = GetMCAnalysisUtils()->CheckOrigin(cluster->GetLabels(),cluster->GetNLabels(),GetReader(), 0);
+        Int_t tag = GetMCAnalysisUtils()->CheckOrigin(cluster->GetLabels(),cluster->GetNLabels(),GetReader());
         
         if  ( !GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCConversion)  )
         {
@@ -1044,7 +1481,8 @@ void AliAnaPhoton::FillTrackMatchingResidualHistograms(AliVCluster* cluster,
           
           // Check if several particles contributed to cluster and discard overlapped mesons
           if(!GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0) || 
-             !GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEta)){
+             !GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEta))
+          {
             if(cluster->GetNLabels()==1)
             {
               fhTrackMatchedDEtaMCNoOverlap[cut]->Fill(cluster->E(),dZ);
@@ -1069,8 +1507,8 @@ void AliAnaPhoton::FillTrackMatchingResidualHistograms(AliVCluster* cluster,
           
           // Check if several particles contributed to cluster
           if(!GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0) || 
-             !GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEta)){
-            
+             !GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEta))
+          {
             fhTrackMatchedDEtaMCConversion[cut]->Fill(cluster->E(),dZ);
             fhTrackMatchedDPhiMCConversion[cut]->Fill(cluster->E(),dR);
             
@@ -1121,7 +1559,7 @@ TObjString *  AliAnaPhoton::GetAnalysisCuts()
 
 //________________________________________________________________________
 TList *  AliAnaPhoton::GetCreateOutputObjects()
-{  
+{
   // Create histograms to be saved in output file and 
   // store them in outputContainer
   TList * outputContainer = new TList() ; 
@@ -1148,8 +1586,10 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
   Float_t pOverEmax   = GetHistogramRanges()->GetHistoPOverEMax();       
   Float_t pOverEmin   = GetHistogramRanges()->GetHistoPOverEMin();
   
-  TString cut[] = {"Open","Reader","E","Time","NCells","Fidutial","Matching","Bad","PID"};
-  for (Int_t i = 0; i < 9 ;  i++) 
+  Int_t bin[] = {0,2,4,6,10,15,20,100}; // energy bins for SS studies
+  
+  TString cut[] = {"Open","Reader","E","Time","NCells","NLM","Fidutial","Matching","Bad","PID"};
+  for (Int_t i = 0; i < 10 ;  i++) 
   {
     fhClusterCuts[i] = new TH1F(Form("hCut_%d_%s", i, cut[i].Data()),
                                 Form("Number of clusters that pass cuts <= %d, %s", i, cut[i].Data()),
@@ -1189,9 +1629,411 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
   fhPtPhoton->SetYTitle("N");
   fhPtPhoton->SetXTitle("p_{T #gamma}(GeV/c)");
   outputContainer->Add(fhPtPhoton) ; 
+
+  fhPtCentralityPhoton  = new TH2F("hPtCentralityPhoton","centrality vs p_{T}",nptbins,ptmin,ptmax, 100,0,100);
+  fhPtCentralityPhoton->SetYTitle("Centrality");
+  fhPtCentralityPhoton->SetXTitle("p_{T}(GeV/c)");
+  outputContainer->Add(fhPtCentralityPhoton) ;
+  
+  fhPtEventPlanePhoton  = new TH2F("hPtEventPlanePhoton","centrality vs p_{T}",nptbins,ptmin,ptmax, 100,0,TMath::Pi());
+  fhPtEventPlanePhoton->SetYTitle("Event plane angle (rad)");
+  fhPtEventPlanePhoton->SetXTitle("p_{T} (GeV/c)");
+  outputContainer->Add(fhPtEventPlanePhoton) ;
+
+  fhEtaPhi  = new TH2F
+  ("hEtaPhi","cluster,E > 0.5 GeV, #eta vs #phi",netabins,etamin,etamax,nphibins,phimin,phimax);
+  fhEtaPhi->SetYTitle("#phi (rad)");
+  fhEtaPhi->SetXTitle("#eta");
+  outputContainer->Add(fhEtaPhi) ;
+
+  if(fCalorimeter=="EMCAL" && fFillEMCALBCHistograms)
+  {
+    fhEtaPhiEMCALBC0  = new TH2F
+    ("hEtaPhiEMCALBC0","cluster,E > 2 GeV, #eta vs #phi, for clusters with |time| < 25 ns, EMCAL-BC=0",netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiEMCALBC0->SetYTitle("#phi (rad)");
+    fhEtaPhiEMCALBC0->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiEMCALBC0) ;
+    
+    fhEtaPhiEMCALBC1  = new TH2F
+    ("hEtaPhiEMCALBC1","cluster,E > 2 GeV, #eta vs #phi, for clusters with 25 < |time| < 75 ns, EMCAL-BC=1",netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiEMCALBC1->SetYTitle("#phi (rad)");
+    fhEtaPhiEMCALBC1->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiEMCALBC1) ;
+    
+    fhEtaPhiEMCALBCN  = new TH2F
+    ("hEtaPhiEMCALBCN","cluster,E > 2 GeV, #eta vs #phi, for clusters with |time| > 75 ns, EMCAL-BC>1",netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiEMCALBCN->SetYTitle("#phi (rad)");
+    fhEtaPhiEMCALBCN->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiEMCALBCN) ;
+    
+    for(Int_t i = 0; i < 11; i++)
+    {
+      fhEtaPhiTriggerEMCALBC[i] = new TH2F
+      (Form("hEtaPhiTriggerEMCALBC%d",i-5),
+       Form("cluster E > 2 GeV, #eta vs #phi, Trigger EMCAL-BC=%d",i-5),
+       netabins,etamin,etamax,nphibins,phimin,phimax);
+      fhEtaPhiTriggerEMCALBC[i]->SetYTitle("#phi (rad)");
+      fhEtaPhiTriggerEMCALBC[i]->SetXTitle("#eta");
+      outputContainer->Add(fhEtaPhiTriggerEMCALBC[i]) ;
+      
+      fhTimeTriggerEMCALBC[i] = new TH2F
+      (Form("hTimeTriggerEMCALBC%d",i-5),
+       Form("cluster time vs E of clusters, Trigger EMCAL-BC=%d",i-5),
+       nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+      fhTimeTriggerEMCALBC[i]->SetXTitle("E (GeV)");
+      fhTimeTriggerEMCALBC[i]->SetYTitle("time (ns)");
+      outputContainer->Add(fhTimeTriggerEMCALBC[i]);
+      
+      fhTimeTriggerEMCALBCPileUpSPD[i] = new TH2F
+      (Form("hTimeTriggerEMCALBC%dPileUpSPD",i-5),
+       Form("cluster time vs E of clusters, Trigger EMCAL-BC=%d",i-5),
+       nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+      fhTimeTriggerEMCALBCPileUpSPD[i]->SetXTitle("E (GeV)");
+      fhTimeTriggerEMCALBCPileUpSPD[i]->SetYTitle("time (ns)");
+      outputContainer->Add(fhTimeTriggerEMCALBCPileUpSPD[i]);
+      
+      fhEtaPhiTriggerEMCALBCUM[i] = new TH2F
+      (Form("hEtaPhiTriggerEMCALBC%d_UnMatch",i-5),
+       Form("cluster E > 2 GeV, #eta vs #phi, unmatched trigger EMCAL-BC=%d",i-5),
+       netabins,etamin,etamax,nphibins,phimin,phimax);
+      fhEtaPhiTriggerEMCALBCUM[i]->SetYTitle("#phi (rad)");
+      fhEtaPhiTriggerEMCALBCUM[i]->SetXTitle("#eta");
+      outputContainer->Add(fhEtaPhiTriggerEMCALBCUM[i]) ;
+      
+      fhTimeTriggerEMCALBCUM[i] = new TH2F
+      (Form("hTimeTriggerEMCALBC%d_UnMatch",i-5),
+       Form("cluster time vs E of clusters, unmatched trigger EMCAL-BC=%d",i-5),
+       nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+      fhTimeTriggerEMCALBCUM[i]->SetXTitle("E (GeV)");
+      fhTimeTriggerEMCALBCUM[i]->SetYTitle("time (ns)");
+      outputContainer->Add(fhTimeTriggerEMCALBCUM[i]);
+      
+      fhEtaPhiTriggerEMCALBCCluster[i] = new TH2F
+      (Form("hEtaPhiTriggerEMCALBC%d_OnlyTrigger",i-5),
+       Form("trigger cluster, #eta vs #phi, Trigger EMCAL-BC=%d",i-5),
+       netabins,etamin,etamax,nphibins,phimin,phimax);
+      fhEtaPhiTriggerEMCALBCCluster[i]->SetYTitle("#phi (rad)");
+      fhEtaPhiTriggerEMCALBCCluster[i]->SetXTitle("#eta");
+      outputContainer->Add(fhEtaPhiTriggerEMCALBCCluster[i]) ;
+      
+      fhTimeTriggerEMCALBCCluster[i] = new TH2F
+      (Form("hTimeTriggerEMCALBC%d_OnlyTrigger",i-5),
+       Form("trigger cluster time vs E of clusters, Trigger EMCAL-BC=%d",i-5),
+       nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+      fhTimeTriggerEMCALBCCluster[i]->SetXTitle("E (GeV)");
+      fhTimeTriggerEMCALBCCluster[i]->SetYTitle("time (ns)");
+      outputContainer->Add(fhTimeTriggerEMCALBCCluster[i]);
+            
+      fhEtaPhiTriggerEMCALBCUMCluster[i] = new TH2F
+      (Form("hEtaPhiTriggerEMCALBC%d_OnlyTrigger_UnMatch",i-5),
+       Form("trigger cluster, #eta vs #phi, unmatched trigger EMCAL-BC=%d",i-5),
+       netabins,etamin,etamax,nphibins,phimin,phimax);
+      fhEtaPhiTriggerEMCALBCUMCluster[i]->SetYTitle("#phi (rad)");
+      fhEtaPhiTriggerEMCALBCUMCluster[i]->SetXTitle("#eta");
+      outputContainer->Add(fhEtaPhiTriggerEMCALBCUMCluster[i]) ;
+      
+      fhTimeTriggerEMCALBCUMCluster[i] = new TH2F
+      (Form("hTimeTriggerEMCALBC%d_OnlyTrigger_UnMatch",i-5),
+       Form("trigger cluster time vs E of clusters, unmatched trigger EMCAL-BC=%d",i-5),
+       nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+      fhTimeTriggerEMCALBCUMCluster[i]->SetXTitle("E (GeV)");
+      fhTimeTriggerEMCALBCUMCluster[i]->SetYTitle("time (ns)");
+      outputContainer->Add(fhTimeTriggerEMCALBCUMCluster[i]);
+    }
+    
+    fhEtaPhiTriggerEMCALBCClusterOverTh = new TH2F
+    ("hEtaPhiTriggerEMCALBC0_OnlyTrigger_OverThreshold",
+     "trigger cluster E > trigger threshold, #eta vs #phi, Trigger EMCAL-BC=0",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCClusterOverTh->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCClusterOverTh->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCClusterOverTh) ;
+        
+    fhEtaPhiTriggerEMCALBCUMClusterOverTh = new TH2F
+    ("hEtaPhiTriggerEMCALBC0_OnlyTrigger_OverThreshold_UnMatch",
+     "trigger cluster E > trigger threshold, #eta vs #phi, unmatched trigger EMCAL-BC=0",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMClusterOverTh->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMClusterOverTh->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMClusterOverTh) ;
+
+    fhEtaPhiTriggerEMCALBCClusterBelowTh1 = new TH2F
+    ("hEtaPhiTriggerEMCALBC0_OnlyTrigger_BelowThreshold1",
+     "trigger cluster thresh-1 < E < thres, #eta vs #phi, Trigger EMCAL-BC=0",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCClusterBelowTh1->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCClusterBelowTh1->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCClusterBelowTh1) ;
+    
+    fhEtaPhiTriggerEMCALBCUMClusterBelowTh1 = new TH2F
+    ("hEtaPhiTriggerEMCALBC0_OnlyTrigger_BelowThreshold1_UnMatch",
+     "trigger cluster thresh-1 < E < thres, #eta vs #phi, unmatched trigger EMCAL-BC=0",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMClusterBelowTh1->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMClusterBelowTh1->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMClusterBelowTh1) ;
+
+    fhEtaPhiTriggerEMCALBCClusterBelowTh2 = new TH2F
+    ("hEtaPhiTriggerEMCALBC0_OnlyTrigger_BelowThreshold2",
+     "trigger cluster thresh-2 < E < thres, #eta vs #phi, Trigger EMCAL-BC=0",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCClusterBelowTh2->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCClusterBelowTh2->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCClusterBelowTh2) ;
+    
+    fhEtaPhiTriggerEMCALBCUMClusterBelowTh2 = new TH2F
+    ("hEtaPhiTriggerEMCALBC0_OnlyTrigger_BelowThreshold2_UnMatch",
+     "trigger cluster thresh-2 < E < thres, #eta vs #phi, unmatched trigger EMCAL-BC=0",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMClusterBelowTh2->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMClusterBelowTh2->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMClusterBelowTh2) ;
+
+    fhEtaPhiTriggerEMCALBCExotic = new TH2F
+    ("hEtaPhiTriggerExotic",
+     "cluster E > 2 GeV, #eta vs #phi, Trigger Exotic",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCExotic->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCExotic->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCExotic) ;
+    
+    fhTimeTriggerEMCALBCExotic = new TH2F
+    ("hTimeTriggerExotic",
+     "cluster time vs E of clusters, Trigger Exotic ",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCExotic->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCExotic->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCExotic);
+        
+    fhEtaPhiTriggerEMCALBCUMExotic = new TH2F
+    ("hEtaPhiTriggerExotic_UnMatch",
+     "cluster E > 2 GeV, #eta vs #phi, unmatched trigger Exotic",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMExotic->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMExotic->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMExotic) ;
+    
+    fhTimeTriggerEMCALBCUMExotic = new TH2F
+    ("hTimeTriggerExotic_UnMatch",
+     "cluster time vs E of clusters, unmatched trigger Exotic",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCUMExotic->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCUMExotic->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCUMExotic);
+    
+    fhEtaPhiTriggerEMCALBCExoticCluster = new TH2F
+    ("hEtaPhiTriggerExotic_OnlyTrigger",
+     "trigger cluster E > 2 GeV, #eta vs #phi, Trigger Exotic",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCExoticCluster->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCExoticCluster->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCExoticCluster) ;
+    
+    fhTimeTriggerEMCALBCExoticCluster = new TH2F
+    ("hTimeTriggerExotic_OnlyTrigger",
+     "trigger cluster time vs E of clusters, Trigger Exotic",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCExoticCluster->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCExoticCluster->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCExoticCluster);
+    
+    fhEtaPhiTriggerEMCALBCUMExoticCluster = new TH2F
+    ("hEtaPhiTriggerExotic_OnlyTrigger_UnMatch",
+     "trigger cluster E > 2 GeV, #eta vs #phi, unmatched trigger Exotic",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMExoticCluster->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMExoticCluster->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMExoticCluster) ;
+    
+    fhTimeTriggerEMCALBCUMExoticCluster = new TH2F
+    ("hTimeTriggerExotic_OnlyTrigger_UnMatch",
+     "trigger cluster time vs E of clusters, unmatched trigger Exotic",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCUMExoticCluster->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCUMExoticCluster->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCUMExoticCluster);
+    
+    fhEtaPhiTriggerEMCALBCBad = new TH2F
+    ("hEtaPhiTriggerBad",
+     "cluster E > 2 GeV, #eta vs #phi, Trigger Bad",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCBad->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCBad->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCBad) ;
+    
+    fhTimeTriggerEMCALBCBad = new TH2F
+    ("hTimeTriggerBad",
+     "cluster time vs E of clusters, Trigger Bad ",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCBad->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCBad->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCBad);
+    
+    fhEtaPhiTriggerEMCALBCUMBad = new TH2F
+    ("hEtaPhiTriggerBad_UnMatch",
+     "cluster E > 2 GeV, #eta vs #phi, unmatched trigger Bad",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMBad->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMBad->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMBad) ;
+    
+    fhTimeTriggerEMCALBCUMBad = new TH2F
+    ("hTimeTriggerBad_UnMatch",
+     "cluster time vs E of clusters, unmatched trigger Bad",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCUMBad->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCUMBad->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCUMBad);
+    
+    fhEtaPhiTriggerEMCALBCBadCluster = new TH2F
+    ("hEtaPhiTriggerBad_OnlyTrigger",
+     "trigger cluster E > 2 GeV, #eta vs #phi, Trigger Bad",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCBadCluster->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCBadCluster->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCBadCluster) ;
+    
+    fhTimeTriggerEMCALBCBadCluster = new TH2F
+    ("hTimeTriggerBad_OnlyTrigger",
+     "trigger cluster time vs E of clusters, Trigger Bad",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCBadCluster->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCBadCluster->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCBadCluster);
+    
+    fhEtaPhiTriggerEMCALBCUMBadCluster = new TH2F
+    ("hEtaPhiTriggerBad_OnlyTrigger_UnMatch",
+     "trigger cluster E > 2 GeV, #eta vs #phi, unmatched trigger Bad",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMBadCluster->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMBadCluster->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMBadCluster) ;
+    
+    fhTimeTriggerEMCALBCUMBadCluster = new TH2F
+    ("hTimeTriggerBad_OnlyTrigger_UnMatch",
+     "trigger cluster time vs E of clusters, unmatched trigger Bad",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCUMBadCluster->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCUMBadCluster->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCUMBadCluster);
+    
+    fhEtaPhiTriggerEMCALBCBadExotic = new TH2F
+    ("hEtaPhiTriggerBadExotic",
+     "cluster E > 2 GeV, #eta vs #phi, Trigger Bad&Exotic",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCBadExotic->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCBadExotic->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCBadExotic) ;
+    
+    fhTimeTriggerEMCALBCBadExotic = new TH2F
+    ("hTimeTriggerBadExotic",
+     "cluster time vs E of clusters, Trigger Bad&Exotic ",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCBadExotic->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCBadExotic->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCBadExotic);
+    
+    fhEtaPhiTriggerEMCALBCUMBadExotic = new TH2F
+    ("hEtaPhiTriggerBadExotic_UnMatch",
+     "cluster E > 2 GeV, #eta vs #phi, unmatched trigger Bad&Exotic",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMBadExotic->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMBadExotic->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMBadExotic) ;
+    
+    fhTimeTriggerEMCALBCUMBadExotic = new TH2F
+    ("hTimeTriggerBadExotic_UnMatch",
+     "cluster time vs E of clusters, unmatched trigger Bad&Exotic",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCUMBadExotic->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCUMBadExotic->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCUMBadExotic);
+    
+    fhEtaPhiTriggerEMCALBCBadExoticCluster = new TH2F
+    ("hEtaPhiTriggerBadExotic_OnlyTrigger",
+     "trigger cluster E > 2 GeV, #eta vs #phi, Trigger Bad&Exotic",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCBadExoticCluster->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCBadExoticCluster->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCBadExoticCluster) ;
+    
+    fhTimeTriggerEMCALBCBadExoticCluster = new TH2F
+    ("hTimeTriggerBadExotic_OnlyTrigger",
+     "trigger cluster time vs E of clusters, Trigger Bad&Exotic",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCBadExoticCluster->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCBadExoticCluster->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCBadExoticCluster);
+    
+    fhEtaPhiTriggerEMCALBCUMBadExoticCluster = new TH2F
+    ("hEtaPhiTriggerBadExotic_OnlyTrigger_UnMatch",
+     "trigger cluster E > 2 GeV, #eta vs #phi, unmatched trigger Bad&Exotic",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiTriggerEMCALBCUMBadExoticCluster->SetYTitle("#phi (rad)");
+    fhEtaPhiTriggerEMCALBCUMBadExoticCluster->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiTriggerEMCALBCUMBadExoticCluster) ;
+    
+    fhTimeTriggerEMCALBCUMBadExoticCluster = new TH2F
+    ("hTimeTriggerBadExotic_OnlyTrigger_UnMatch",
+     "trigger cluster time vs E of clusters, unmatched trigger Bad&Exotic",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCUMBadExoticCluster->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCUMBadExoticCluster->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCUMBadExoticCluster);
+    
+    fhTimeTriggerEMCALBCBadMaxCell = new TH2F
+    ("hTimeTriggerBadMaxCell",
+     "cluster time vs E of clusters, Trigger BadMaxCell",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCBadMaxCell->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCBadMaxCell->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCBadMaxCell);
+
+    fhTimeTriggerEMCALBCUMBadMaxCell = new TH2F
+    ("hTimeTriggerBadMaxCell_UnMatch",
+     "cluster time vs E of clusters, unmatched trigger BadMaxCell",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCUMBadMaxCell->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCUMBadMaxCell->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCUMBadMaxCell);
+    
+    
+    fhTimeTriggerEMCALBCBadMaxCellExotic = new TH2F
+    ("hTimeTriggerBadMaxCellExotic",
+     "cluster time vs E of clusters, Trigger BadMaxCell&Exotic",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCBadMaxCellExotic->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCBadMaxCellExotic->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCBadMaxCellExotic);
+    
+    fhTimeTriggerEMCALBCUMBadMaxCellExotic = new TH2F
+    ("hTimeTriggerBadMaxCellExotic_UnMatch",
+     "cluster time vs E of clusters, unmatched trigger BadMaxCell&Exotic",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeTriggerEMCALBCUMBadMaxCellExotic->SetXTitle("E (GeV)");
+    fhTimeTriggerEMCALBCUMBadMaxCellExotic->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeTriggerEMCALBCUMBadMaxCellExotic);
+
+    fhTimeNoTrigger = new TH2F
+    ("hTimeNoTrigger",
+     "events with no foundable trigger, time vs e of clusters",
+     nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeNoTrigger->SetXTitle("E (GeV)");
+    fhTimeNoTrigger->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeNoTrigger);
+
+    fhEtaPhiNoTrigger = new TH2F
+    ("hEtaPhiNoTrigger",
+     "events with no foundable trigger, eta vs phi of clusters",
+     netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiNoTrigger->SetYTitle("#phi (rad)");
+    fhEtaPhiNoTrigger->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiNoTrigger) ;
+
+  }
   
   fhPhiPhoton  = new TH2F
-    ("hPhiPhoton","#phi_{#gamma} vs p_{T}",nptbins,ptmin,ptmax,nphibins,phimin,phimax); 
+    ("hPhiPhoton","#phi_{#gamma} vs p_{T}",nptbins,ptmin,ptmax,nphibins,phimin,phimax);
   fhPhiPhoton->SetYTitle("#phi (rad)");
   fhPhiPhoton->SetXTitle("p_{T #gamma} (GeV/c)");
   outputContainer->Add(fhPhiPhoton) ; 
@@ -1207,17 +2049,89 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
   fhEtaPhiPhoton->SetYTitle("#phi (rad)");
   fhEtaPhiPhoton->SetXTitle("#eta");
   outputContainer->Add(fhEtaPhiPhoton) ;
-  if(GetMinPt() < 0.5){
+  if(GetMinPt() < 0.5)
+  {
     fhEtaPhi05Photon  = new TH2F
     ("hEtaPhi05Photon","#eta vs #phi, E > 0.5",netabins,etamin,etamax,nphibins,phimin,phimax); 
     fhEtaPhi05Photon->SetYTitle("#phi (rad)");
     fhEtaPhi05Photon->SetXTitle("#eta");
     outputContainer->Add(fhEtaPhi05Photon) ;
   }
+
+  if(fCalorimeter=="EMCAL" && fFillEMCALBCHistograms)
+  {
+    fhEtaPhiPhotonEMCALBC0  = new TH2F
+    ("hEtaPhiPhotonEMCALBC0","identified photon, E > 2 GeV, #eta vs #phi, for clusters with |time| < 25 ns, EMCAL-BC=0",netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiPhotonEMCALBC0->SetYTitle("#phi (rad)");
+    fhEtaPhiPhotonEMCALBC0->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiPhotonEMCALBC0) ;
+    
+    fhEtaPhiPhotonEMCALBC1  = new TH2F
+    ("hEtaPhiPhotonEMCALBC1","identified photon, E > 2 GeV, #eta vs #phi, for clusters with 25 < |time| < 75 ns, EMCAL-BC=1",netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiPhotonEMCALBC1->SetYTitle("#phi (rad)");
+    fhEtaPhiPhotonEMCALBC1->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiPhotonEMCALBC1) ;
+    
+    fhEtaPhiPhotonEMCALBCN  = new TH2F
+    ("hEtaPhiPhotonEMCALBCN","identified photon, E > 2 GeV, #eta vs #phi, for clusters with |time| > 75 ns, EMCAL-BC>1",netabins,etamin,etamax,nphibins,phimin,phimax);
+    fhEtaPhiPhotonEMCALBCN->SetYTitle("#phi (rad)");
+    fhEtaPhiPhotonEMCALBCN->SetXTitle("#eta");
+    outputContainer->Add(fhEtaPhiPhotonEMCALBCN) ;
+    
+    for(Int_t i = 0; i < 11; i++)
+    {
+      fhEtaPhiPhotonTriggerEMCALBC[i] = new TH2F
+      (Form("hEtaPhiPhotonTriggerEMCALBC%d",i-5),
+       Form("photon E > 2 GeV, #eta vs #phi, PhotonTrigger EMCAL-BC=%d",i-5),
+       netabins,etamin,etamax,nphibins,phimin,phimax);
+      fhEtaPhiPhotonTriggerEMCALBC[i]->SetYTitle("#phi (rad)");
+      fhEtaPhiPhotonTriggerEMCALBC[i]->SetXTitle("#eta");
+      outputContainer->Add(fhEtaPhiPhotonTriggerEMCALBC[i]) ;
+      
+      fhTimePhotonTriggerEMCALBC[i] = new TH2F
+      (Form("hTimePhotonTriggerEMCALBC%d",i-5),
+       Form("photon time vs E of clusters, PhotonTrigger EMCAL-BC=%d",i-5),
+       nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+      fhTimePhotonTriggerEMCALBC[i]->SetXTitle("E (GeV)");
+      fhTimePhotonTriggerEMCALBC[i]->SetYTitle("time (ns)");
+      outputContainer->Add(fhTimePhotonTriggerEMCALBC[i]);
+      
+      fhTimePhotonTriggerEMCALBCPileUpSPD[i] = new TH2F
+      (Form("hTimePhotonTriggerEMCALBC%dPileUpSPD",i-5),
+       Form("photon time vs E, PhotonTrigger EMCAL-BC=%d",i-5),
+       nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+      fhTimePhotonTriggerEMCALBCPileUpSPD[i]->SetXTitle("E (GeV)");
+      fhTimePhotonTriggerEMCALBCPileUpSPD[i]->SetYTitle("time (ns)");
+      outputContainer->Add(fhTimePhotonTriggerEMCALBCPileUpSPD[i]);
+      
+      fhEtaPhiPhotonTriggerEMCALBCUM[i] = new TH2F
+      (Form("hEtaPhiPhotonTriggerEMCALBC%d_UnMatch",i-5),
+       Form("photon E > 2 GeV, #eta vs #phi, unmatched trigger EMCAL-BC=%d",i-5),
+       netabins,etamin,etamax,nphibins,phimin,phimax);
+      fhEtaPhiPhotonTriggerEMCALBCUM[i]->SetYTitle("#phi (rad)");
+      fhEtaPhiPhotonTriggerEMCALBCUM[i]->SetXTitle("#eta");
+      outputContainer->Add(fhEtaPhiPhotonTriggerEMCALBCUM[i]) ;
+      
+      fhTimePhotonTriggerEMCALBCUM[i] = new TH2F
+      (Form("hTimePhotonTriggerEMCALBC%d_UnMatch",i-5),
+       Form("photon time vs E, unmatched trigger EMCAL-BC=%d",i-5),
+       nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+      fhTimePhotonTriggerEMCALBCUM[i]->SetXTitle("E (GeV)");
+      fhTimePhotonTriggerEMCALBCUM[i]->SetYTitle("time (ns)");
+      outputContainer->Add(fhTimePhotonTriggerEMCALBCUM[i]);
+      
+    }
+  }
+  
+  fhNLocMax = new TH2F("hNLocMax","Number of local maxima in cluster",
+                       nptbins,ptmin,ptmax,10,0,10); 
+  fhNLocMax ->SetYTitle("N maxima");
+  fhNLocMax ->SetXTitle("E (GeV)");
+  outputContainer->Add(fhNLocMax) ;  
   
   //Shower shape
-  if(fFillSSHistograms){
-    
+  if(fFillSSHistograms)
+  {
     fhLam0E  = new TH2F ("hLam0E","#lambda_{0}^{2} vs E", nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
     fhLam0E->SetYTitle("#lambda_{0}^{2}");
     fhLam0E->SetXTitle("E (GeV)");
@@ -1287,93 +2201,167 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
       } 
     } 
     
-    fhNCellsLam0LowE  = new TH2F ("hNCellsLam0LowE","N_{cells} in cluster vs #lambda_{0}^{2}, E < 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
-    fhNCellsLam0LowE->SetXTitle("N_{cells}");
-    fhNCellsLam0LowE->SetYTitle("#lambda_{0}^{2}");
-    outputContainer->Add(fhNCellsLam0LowE);  
-    
-    fhNCellsLam0HighE  = new TH2F ("hNCellsLam0HighE","N_{cells} in cluster vs #lambda_{0}^{2}, E > 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
-    fhNCellsLam0HighE->SetXTitle("N_{cells}");
-    fhNCellsLam0HighE->SetYTitle("#lambda_{0}^{2}");
-    outputContainer->Add(fhNCellsLam0HighE);  
-    
-    fhNCellsLam1LowE  = new TH2F ("hNCellsLam1LowE","N_{cells} in cluster vs #lambda_{1}^{2}, E < 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
-    fhNCellsLam1LowE->SetXTitle("N_{cells}");
-    fhNCellsLam1LowE->SetYTitle("#lambda_{0}^{2}");
-    outputContainer->Add(fhNCellsLam1LowE);  
-    
-    fhNCellsLam1HighE  = new TH2F ("hNCellsLam1HighE","N_{cells} in cluster vs #lambda_{1}^{2}, E > 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
-    fhNCellsLam1HighE->SetXTitle("N_{cells}");
-    fhNCellsLam1HighE->SetYTitle("#lambda_{0}^{2}");
-    outputContainer->Add(fhNCellsLam1HighE);  
-    
-    fhNCellsDispLowE  = new TH2F ("hNCellsDispLowE","N_{cells} in cluster vs dispersion^{2}, E < 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
-    fhNCellsDispLowE->SetXTitle("N_{cells}");
-    fhNCellsDispLowE->SetYTitle("D^{2}");
-    outputContainer->Add(fhNCellsDispLowE);  
-    
-    fhNCellsDispHighE  = new TH2F ("hNCellsDispHighE","N_{cells} in cluster vs dispersion^{2}, E < 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
-    fhNCellsDispHighE->SetXTitle("N_{cells}");
-    fhNCellsDispHighE->SetYTitle("D^{2}");
-    outputContainer->Add(fhNCellsDispHighE);  
-    
-    fhEtaLam0LowE  = new TH2F ("hEtaLam0LowE","#eta vs #lambda_{0}^{2}, E < 2 GeV", netabins,etamin,etamax, ssbins,ssmin,ssmax); 
-    fhEtaLam0LowE->SetYTitle("#lambda_{0}^{2}");
-    fhEtaLam0LowE->SetXTitle("#eta");
-    outputContainer->Add(fhEtaLam0LowE);  
-    
-    fhPhiLam0LowE  = new TH2F ("hPhiLam0LowE","#phi vs #lambda_{0}^{2}, E < 2 GeV", nphibins,phimin,phimax, ssbins,ssmin,ssmax); 
-    fhPhiLam0LowE->SetYTitle("#lambda_{0}^{2}");
-    fhPhiLam0LowE->SetXTitle("#phi");
-    outputContainer->Add(fhPhiLam0LowE);  
-    
-    fhEtaLam0HighE  = new TH2F ("hEtaLam0HighE","#eta vs #lambda_{0}^{2}, E > 2 GeV", netabins,etamin,etamax, ssbins,ssmin,ssmax); 
-    fhEtaLam0HighE->SetYTitle("#lambda_{0}^{2}");
-    fhEtaLam0HighE->SetXTitle("#eta");
-    outputContainer->Add(fhEtaLam0HighE);  
-    
-    fhPhiLam0HighE  = new TH2F ("hPhiLam0HighE","#phi vs #lambda_{0}^{2}, E > 2 GeV", nphibins,phimin,phimax, ssbins,ssmin,ssmax); 
-    fhPhiLam0HighE->SetYTitle("#lambda_{0}^{2}");
-    fhPhiLam0HighE->SetXTitle("#phi");
-    outputContainer->Add(fhPhiLam0HighE);  
-    
-    fhLam1Lam0LowE  = new TH2F ("hLam1Lam0LowE","#lambda_{0}^{2} vs #lambda_{1}^{2} in cluster of E < 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
-    fhLam1Lam0LowE->SetYTitle("#lambda_{0}^{2}");
-    fhLam1Lam0LowE->SetXTitle("#lambda_{1}^{2}");
-    outputContainer->Add(fhLam1Lam0LowE);  
-    
-    fhLam1Lam0HighE  = new TH2F ("hLam1Lam0HighE","#lambda_{0}^{2} vs #lambda_{1}^{2} in cluster of E > 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
-    fhLam1Lam0HighE->SetYTitle("#lambda_{0}^{2}");
-    fhLam1Lam0HighE->SetXTitle("#lambda_{1}^{2}");
-    outputContainer->Add(fhLam1Lam0HighE);  
-    
-    fhLam0DispLowE  = new TH2F ("hLam0DispLowE","#lambda_{0}^{2} vs dispersion^{2} in cluster of E < 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
-    fhLam0DispLowE->SetXTitle("#lambda_{0}^{2}");
-    fhLam0DispLowE->SetYTitle("D^{2}");
-    outputContainer->Add(fhLam0DispLowE);  
-    
-    fhLam0DispHighE  = new TH2F ("hLam0DispHighE","#lambda_{0}^{2} vs dispersion^{2} in cluster of E > 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
-    fhLam0DispHighE->SetXTitle("#lambda_{0}^{2}");
-    fhLam0DispHighE->SetYTitle("D^{2}");
-    outputContainer->Add(fhLam0DispHighE);  
-    
-    fhDispLam1LowE  = new TH2F ("hDispLam1LowE","Dispersion^{2} vs #lambda_{1}^{2} in cluster of E < 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
-    fhDispLam1LowE->SetXTitle("D^{2}");
-    fhDispLam1LowE->SetYTitle("#lambda_{1}^{2}");
-    outputContainer->Add(fhDispLam1LowE);  
-    
-    fhDispLam1HighE  = new TH2F ("hDispLam1HighE","Dispersion^{2} vs #lambda_{1^{2}} in cluster of E > 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
-    fhDispLam1HighE->SetXTitle("D^{2}");
-    fhDispLam1HighE->SetYTitle("#lambda_{1}^{2}");
-    outputContainer->Add(fhDispLam1HighE);  
-    
+    if(!fFillOnlySimpleSSHisto)
+    {
+      fhNCellsLam0LowE  = new TH2F ("hNCellsLam0LowE","N_{cells} in cluster vs #lambda_{0}^{2}, E < 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
+      fhNCellsLam0LowE->SetXTitle("N_{cells}");
+      fhNCellsLam0LowE->SetYTitle("#lambda_{0}^{2}");
+      outputContainer->Add(fhNCellsLam0LowE);  
+      
+      fhNCellsLam0HighE  = new TH2F ("hNCellsLam0HighE","N_{cells} in cluster vs #lambda_{0}^{2}, E > 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
+      fhNCellsLam0HighE->SetXTitle("N_{cells}");
+      fhNCellsLam0HighE->SetYTitle("#lambda_{0}^{2}");
+      outputContainer->Add(fhNCellsLam0HighE);  
+      
+      fhNCellsLam1LowE  = new TH2F ("hNCellsLam1LowE","N_{cells} in cluster vs #lambda_{1}^{2}, E < 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
+      fhNCellsLam1LowE->SetXTitle("N_{cells}");
+      fhNCellsLam1LowE->SetYTitle("#lambda_{0}^{2}");
+      outputContainer->Add(fhNCellsLam1LowE);  
+      
+      fhNCellsLam1HighE  = new TH2F ("hNCellsLam1HighE","N_{cells} in cluster vs #lambda_{1}^{2}, E > 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
+      fhNCellsLam1HighE->SetXTitle("N_{cells}");
+      fhNCellsLam1HighE->SetYTitle("#lambda_{0}^{2}");
+      outputContainer->Add(fhNCellsLam1HighE);  
+      
+      fhNCellsDispLowE  = new TH2F ("hNCellsDispLowE","N_{cells} in cluster vs dispersion^{2}, E < 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
+      fhNCellsDispLowE->SetXTitle("N_{cells}");
+      fhNCellsDispLowE->SetYTitle("D^{2}");
+      outputContainer->Add(fhNCellsDispLowE);  
+      
+      fhNCellsDispHighE  = new TH2F ("hNCellsDispHighE","N_{cells} in cluster vs dispersion^{2}, E < 2 GeV", nbins,nmin, nmax, ssbins,ssmin,ssmax); 
+      fhNCellsDispHighE->SetXTitle("N_{cells}");
+      fhNCellsDispHighE->SetYTitle("D^{2}");
+      outputContainer->Add(fhNCellsDispHighE);  
+      
+      fhEtaLam0LowE  = new TH2F ("hEtaLam0LowE","#eta vs #lambda_{0}^{2}, E < 2 GeV", netabins,etamin,etamax, ssbins,ssmin,ssmax); 
+      fhEtaLam0LowE->SetYTitle("#lambda_{0}^{2}");
+      fhEtaLam0LowE->SetXTitle("#eta");
+      outputContainer->Add(fhEtaLam0LowE);  
+      
+      fhPhiLam0LowE  = new TH2F ("hPhiLam0LowE","#phi vs #lambda_{0}^{2}, E < 2 GeV", nphibins,phimin,phimax, ssbins,ssmin,ssmax); 
+      fhPhiLam0LowE->SetYTitle("#lambda_{0}^{2}");
+      fhPhiLam0LowE->SetXTitle("#phi");
+      outputContainer->Add(fhPhiLam0LowE);  
+      
+      fhEtaLam0HighE  = new TH2F ("hEtaLam0HighE","#eta vs #lambda_{0}^{2}, E > 2 GeV", netabins,etamin,etamax, ssbins,ssmin,ssmax); 
+      fhEtaLam0HighE->SetYTitle("#lambda_{0}^{2}");
+      fhEtaLam0HighE->SetXTitle("#eta");
+      outputContainer->Add(fhEtaLam0HighE);  
+      
+      fhPhiLam0HighE  = new TH2F ("hPhiLam0HighE","#phi vs #lambda_{0}^{2}, E > 2 GeV", nphibins,phimin,phimax, ssbins,ssmin,ssmax); 
+      fhPhiLam0HighE->SetYTitle("#lambda_{0}^{2}");
+      fhPhiLam0HighE->SetXTitle("#phi");
+      outputContainer->Add(fhPhiLam0HighE);  
+      
+      fhLam1Lam0LowE  = new TH2F ("hLam1Lam0LowE","#lambda_{0}^{2} vs #lambda_{1}^{2} in cluster of E < 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
+      fhLam1Lam0LowE->SetYTitle("#lambda_{0}^{2}");
+      fhLam1Lam0LowE->SetXTitle("#lambda_{1}^{2}");
+      outputContainer->Add(fhLam1Lam0LowE);  
+      
+      fhLam1Lam0HighE  = new TH2F ("hLam1Lam0HighE","#lambda_{0}^{2} vs #lambda_{1}^{2} in cluster of E > 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
+      fhLam1Lam0HighE->SetYTitle("#lambda_{0}^{2}");
+      fhLam1Lam0HighE->SetXTitle("#lambda_{1}^{2}");
+      outputContainer->Add(fhLam1Lam0HighE);  
+      
+      fhLam0DispLowE  = new TH2F ("hLam0DispLowE","#lambda_{0}^{2} vs dispersion^{2} in cluster of E < 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
+      fhLam0DispLowE->SetXTitle("#lambda_{0}^{2}");
+      fhLam0DispLowE->SetYTitle("D^{2}");
+      outputContainer->Add(fhLam0DispLowE);  
+      
+      fhLam0DispHighE  = new TH2F ("hLam0DispHighE","#lambda_{0}^{2} vs dispersion^{2} in cluster of E > 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
+      fhLam0DispHighE->SetXTitle("#lambda_{0}^{2}");
+      fhLam0DispHighE->SetYTitle("D^{2}");
+      outputContainer->Add(fhLam0DispHighE);  
+      
+      fhDispLam1LowE  = new TH2F ("hDispLam1LowE","Dispersion^{2} vs #lambda_{1}^{2} in cluster of E < 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
+      fhDispLam1LowE->SetXTitle("D^{2}");
+      fhDispLam1LowE->SetYTitle("#lambda_{1}^{2}");
+      outputContainer->Add(fhDispLam1LowE);  
+      
+      fhDispLam1HighE  = new TH2F ("hDispLam1HighE","Dispersion^{2} vs #lambda_{1^{2}} in cluster of E > 2 GeV",  ssbins,ssmin,ssmax, ssbins,ssmin,ssmax); 
+      fhDispLam1HighE->SetXTitle("D^{2}");
+      fhDispLam1HighE->SetYTitle("#lambda_{1}^{2}");
+      outputContainer->Add(fhDispLam1HighE);  
+      
+      if(fCalorimeter == "EMCAL")
+      {
+        fhDispEtaE  = new TH2F ("hDispEtaE","#sigma^{2}_{#eta #eta} = #Sigma w_{i}(#eta_{i} - <#eta>)^{2}/ #Sigma w_{i} vs E",  nptbins,ptmin,ptmax, ssbins,ssmin,ssmax); 
+        fhDispEtaE->SetXTitle("E (GeV)");
+        fhDispEtaE->SetYTitle("#sigma^{2}_{#eta #eta}");
+        outputContainer->Add(fhDispEtaE);     
+        
+        fhDispPhiE  = new TH2F ("hDispPhiE","#sigma^{2}_{#phi #phi} = #Sigma w_{i}(#phi_{i} - <#phi>)^{2} / #Sigma w_{i} vs E",  nptbins,ptmin,ptmax, ssbins,ssmin,ssmax); 
+        fhDispPhiE->SetXTitle("E (GeV)");
+        fhDispPhiE->SetYTitle("#sigma^{2}_{#phi #phi}");
+        outputContainer->Add(fhDispPhiE);  
+        
+        fhSumEtaE  = new TH2F ("hSumEtaE","#delta^{2}_{#eta #eta} = #Sigma w_{i}(#eta_{i})^{2} / #Sigma w_{i} - <#eta>^{2} vs E",  nptbins,ptmin,ptmax, ssbins,ssmin,ssmax); 
+        fhSumEtaE->SetXTitle("E (GeV)");
+        fhSumEtaE->SetYTitle("#delta^{2}_{#eta #eta}");
+        outputContainer->Add(fhSumEtaE);     
+        
+        fhSumPhiE  = new TH2F ("hSumPhiE","#delta^{2}_{#phi #phi} = #Sigma w_{i}(#phi_{i})^{2}/ #Sigma w_{i} - <#phi>^{2} vs E",  
+                               nptbins,ptmin,ptmax, ssbins,ssmin,ssmax); 
+        fhSumPhiE->SetXTitle("E (GeV)");
+        fhSumPhiE->SetYTitle("#delta^{2}_{#phi #phi}");
+        outputContainer->Add(fhSumPhiE);  
+        
+        fhSumEtaPhiE  = new TH2F ("hSumEtaPhiE","#delta^{2}_{#eta #phi} = #Sigma w_{i}(#phi_{i} #eta_{i} ) / #Sigma w_{i} - <#phi><#eta> vs E",  
+                                  nptbins,ptmin,ptmax, 2*ssbins,-ssmax,ssmax); 
+        fhSumEtaPhiE->SetXTitle("E (GeV)");
+        fhSumEtaPhiE->SetYTitle("#delta^{2}_{#eta #phi}");
+        outputContainer->Add(fhSumEtaPhiE);
+        
+        fhDispEtaPhiDiffE  = new TH2F ("hDispEtaPhiDiffE","#sigma^{2}_{#phi #phi} - #sigma^{2}_{#eta #eta} vs E", 
+                                       nptbins,ptmin,ptmax,200, -10,10); 
+        fhDispEtaPhiDiffE->SetXTitle("E (GeV)");
+        fhDispEtaPhiDiffE->SetYTitle("#sigma^{2}_{#phi #phi}-#sigma^{2}_{#eta #eta}");
+        outputContainer->Add(fhDispEtaPhiDiffE);    
+        
+        fhSphericityE  = new TH2F ("hSphericityE","(#sigma^{2}_{#phi #phi} - #sigma^{2}_{#eta #eta}) / (#sigma^{2}_{#eta #eta} + #sigma^{2}_{#phi #phi}) vs E",  
+                                   nptbins,ptmin,ptmax, 200, -1,1); 
+        fhSphericityE->SetXTitle("E (GeV)");
+        fhSphericityE->SetYTitle("s = (#sigma^{2}_{#phi #phi} - #sigma^{2}_{#eta #eta}) / (#sigma^{2}_{#eta #eta} + #sigma^{2}_{#phi #phi})");
+        outputContainer->Add(fhSphericityE);
+        
+        fhDispSumEtaDiffE  = new TH2F ("hDispSumEtaDiffE","#sigma^{2}_{#eta #eta} - #delta^{2}_{#eta #eta} / average vs E",  nptbins,ptmin,ptmax, 200,-0.01,0.01); 
+        fhDispSumEtaDiffE->SetXTitle("E (GeV)");
+        fhDispSumEtaDiffE->SetYTitle("#sigma^{2}_{#eta #eta} - #delta^{2}_{#eta #eta} / average");
+        outputContainer->Add(fhDispSumEtaDiffE);     
+        
+        fhDispSumPhiDiffE  = new TH2F ("hDispSumPhiDiffE","#sigma^{2}_{#phi #phi} - #delta^{2}_{#phi #phi} / average vs E",  nptbins,ptmin,ptmax, 200,-0.01,0.01); 
+        fhDispSumPhiDiffE->SetXTitle("E (GeV)");
+        fhDispSumPhiDiffE->SetYTitle("#sigma^{2}_{#phi #phi} - #delta^{2}_{#phi #phi} / average");
+        outputContainer->Add(fhDispSumPhiDiffE);  
+        
+        for(Int_t i = 0; i < 7; i++)
+        {
+          fhDispEtaDispPhi[i] = new TH2F (Form("hDispEtaDispPhi_EBin%d",i),Form("#sigma^{2}_{#phi #phi} vs #sigma^{2}_{#eta #eta} for %d < E < %d GeV",bin[i],bin[i+1]), 
+                                          ssbins,ssmin,ssmax , ssbins,ssmin,ssmax); 
+          fhDispEtaDispPhi[i]->SetXTitle("#sigma^{2}_{#eta #eta}");
+          fhDispEtaDispPhi[i]->SetYTitle("#sigma^{2}_{#phi #phi}");
+          outputContainer->Add(fhDispEtaDispPhi[i]); 
+          
+          fhLambda0DispEta[i] = new TH2F (Form("hLambda0DispEta_EBin%d",i),Form("#lambda^{2}_{0} vs #sigma^{2}_{#eta #eta} for %d < E < %d GeV",bin[i],bin[i+1]), 
+                                          ssbins,ssmin,ssmax , ssbins,ssmin,ssmax); 
+          fhLambda0DispEta[i]->SetXTitle("#lambda^{2}_{0}");
+          fhLambda0DispEta[i]->SetYTitle("#sigma^{2}_{#eta #eta}");
+          outputContainer->Add(fhLambda0DispEta[i]);       
+          
+          fhLambda0DispPhi[i] = new TH2F (Form("hLambda0DispPhi_EBin%d",i),Form("#lambda^{2}_{0}} vs #sigma^{2}_{#phi #phi} for %d < E < %d GeV",bin[i],bin[i+1]), 
+                                          ssbins,ssmin,ssmax , ssbins,ssmin,ssmax); 
+          fhLambda0DispPhi[i]->SetXTitle("#lambda^{2}_{0}");
+          fhLambda0DispPhi[i]->SetYTitle("#sigma^{2}_{#phi #phi}");
+          outputContainer->Add(fhLambda0DispPhi[i]);         
+        }
+      }
+    }
   } // Shower shape
   
   // Track Matching
   
   if(fFillTMHisto)
   {
-        
     fhTrackMatchedDEta[0]  = new TH2F
     ("hTrackMatchedDEtaNoCut",
      "d#eta of cluster-track vs cluster energy, no photon cuts",
@@ -1450,7 +2438,6 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
     
     if(fCalorimeter=="EMCAL")
     {
-      
       fhTrackMatchedDEtaTRD[0]  = new TH2F
       ("hTrackMatchedDEtaTRDNoCut",
        "d#eta of cluster-track vs cluster energy, SM behind TRD, no photon cuts",
@@ -1501,7 +2488,6 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
     
     if(IsDataMC())
     {
-      
       fhTrackMatchedDEtaMCNoOverlap[0]  = new TH2F
       ("hTrackMatchedDEtaMCNoOverlapNoCut",
        "d#eta of cluster-track vs cluster energy, no other MC particles overlap",
@@ -1644,9 +2630,165 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
     }
   }  
   
+  if(fFillPileUpHistograms)
+  {
+    
+    TString pileUpName[] = {"SPD","EMCAL","SPDOrEMCAL","SPDAndEMCAL","SPDAndNotEMCAL","EMCALAndNotSPD","NotSPDAndNotEMCAL"} ;
+    
+    for(Int_t i = 0 ; i < 7 ; i++)
+    {
+      fhPtPileUp[i]  = new TH1F(Form("hPtPileUp%s",pileUpName[i].Data()),
+                                       Form("Cluster  p_{T} distribution, %s Pile-Up event",pileUpName[i].Data()), nptbins,ptmin,ptmax);
+      fhPtPileUp[i]->SetXTitle("p_{T} (GeV/c)");
+      outputContainer->Add(fhPtPileUp[i]);
+      
+      fhPtChargedPileUp[i]  = new TH1F(Form("hPtChargedPileUp%s",pileUpName[i].Data()),
+                                      Form("Charged clusters p_{T} distribution, %s Pile-Up event",pileUpName[i].Data()), nptbins,ptmin,ptmax);
+      fhPtChargedPileUp[i]->SetXTitle("p_{T} (GeV/c)");
+      outputContainer->Add(fhPtChargedPileUp[i]);
+
+      fhPtPhotonPileUp[i]  = new TH1F(Form("hPtPhotonPileUp%s",pileUpName[i].Data()),
+                                      Form("Selected photon p_{T} distribution, %s Pile-Up event",pileUpName[i].Data()), nptbins,ptmin,ptmax);
+      fhPtPhotonPileUp[i]->SetXTitle("p_{T} (GeV/c)");
+      outputContainer->Add(fhPtPhotonPileUp[i]);
+      
+      
+      fhClusterEFracLongTimePileUp[i]  = new TH2F(Form("hClusterEFracLongTimePileUp%s",pileUpName[i].Data()),
+                                             Form("Cluster E vs fraction of cluster energy from large T cells, %s Pile-Up event",pileUpName[i].Data()),
+                                             nptbins,ptmin,ptmax,200,0,1);
+      fhClusterEFracLongTimePileUp[i]->SetXTitle("E (GeV)");
+      fhClusterEFracLongTimePileUp[i]->SetYTitle("E(large time) / E");
+      outputContainer->Add(fhClusterEFracLongTimePileUp[i]);
+      
+      fhClusterTimeDiffPileUp[i]  = new TH2F(Form("hClusterTimeDiffPileUp%s",pileUpName[i].Data()),
+                                Form("Cluster E vs t_{max}-t_{cell} in cluster, %s Pile-Up event",pileUpName[i].Data()),
+                                             nptbins,ptmin,ptmax,200,-100,100);
+      fhClusterTimeDiffPileUp[i]->SetXTitle("E (GeV)");
+      fhClusterTimeDiffPileUp[i]->SetYTitle("t_{max}-t_{cell} (ns)");
+      outputContainer->Add(fhClusterTimeDiffPileUp[i]);
+      
+      fhClusterTimeDiffChargedPileUp[i]  = new TH2F(Form("hClusterTimeDiffChargedPileUp%s",pileUpName[i].Data()),
+                                       Form("Charged clusters E vs t_{max}-t_{cell} in cluster, %s Pile-Up event",pileUpName[i].Data()),
+                                                    nptbins,ptmin,ptmax,200,-100,100);
+      fhClusterTimeDiffChargedPileUp[i]->SetXTitle("E (GeV)");
+      fhClusterTimeDiffChargedPileUp[i]->SetYTitle("t_{max}-t_{cell} (ns)");
+      outputContainer->Add(fhClusterTimeDiffChargedPileUp[i]);
+      
+      fhClusterTimeDiffPhotonPileUp[i]  = new TH2F(Form("hClusterTimeDiffPhotonPileUp%s",pileUpName[i].Data()),
+                                      Form("Selected photon E vs t_{max}-t_{cell} in cluster, %s Pile-Up event",pileUpName[i].Data()),
+                                                   nptbins,ptmin,ptmax,200,-100,100);
+      fhClusterTimeDiffPhotonPileUp[i]->SetXTitle("E (GeV)");
+      fhClusterTimeDiffPhotonPileUp[i]->SetYTitle("t_{max}-t_{cell} (ns)");
+      outputContainer->Add(fhClusterTimeDiffPhotonPileUp[i]);
+
+      fhLambda0PileUp[i]  = new TH2F(Form("hLambda0PileUp%s",pileUpName[i].Data()),
+                                     Form("Cluster E vs #lambda^{2}_{0} in cluster, %s Pile-Up event",pileUpName[i].Data()),
+                                     nptbins,ptmin,ptmax,ssbins,ssmin,ssmax);
+      fhLambda0PileUp[i]->SetXTitle("E (GeV)");
+      fhLambda0PileUp[i]->SetYTitle("#lambda^{2}_{0}");
+      outputContainer->Add(fhLambda0PileUp[i]);
+      
+      fhLambda0ChargedPileUp[i]  = new TH2F(Form("hLambda0ChargedPileUp%s",pileUpName[i].Data()),
+                                                    Form("Charged clusters E vs #lambda^{2}_{0}in cluster, %s Pile-Up event",pileUpName[i].Data()), nptbins,ptmin,ptmax,ssbins,ssmin,ssmax);
+      fhLambda0ChargedPileUp[i]->SetXTitle("E (GeV)");
+      fhLambda0ChargedPileUp[i]->SetYTitle("#lambda^{2}_{0}");
+      outputContainer->Add(fhLambda0ChargedPileUp[i]);
+
+    }
+    
+    fhEtaPhiBC0  = new TH2F ("hEtaPhiBC0","eta-phi for clusters tof corresponding to BC=0",netabins,etamin,etamax, nphibins,phimin,phimax);
+    fhEtaPhiBC0->SetXTitle("#eta ");
+    fhEtaPhiBC0->SetYTitle("#phi (rad)");
+    outputContainer->Add(fhEtaPhiBC0);
+    
+    fhEtaPhiBCPlus  = new TH2F ("hEtaPhiBCPlus","eta-phi for clusters tof corresponding to BC>0",netabins,etamin,etamax, nphibins,phimin,phimax);
+    fhEtaPhiBCPlus->SetXTitle("#eta ");
+    fhEtaPhiBCPlus->SetYTitle("#phi (rad)");
+    outputContainer->Add(fhEtaPhiBCPlus);
+    
+    fhEtaPhiBCMinus  = new TH2F ("hEtaPhiBCMinus","eta-phi for clusters tof corresponding to BC<0",netabins,etamin,etamax, nphibins,phimin,phimax);
+    fhEtaPhiBCMinus->SetXTitle("#eta ");
+    fhEtaPhiBCMinus->SetYTitle("#phi (rad)");
+    outputContainer->Add(fhEtaPhiBCMinus);
+    
+    fhEtaPhiBC0PileUpSPD  = new TH2F ("hEtaPhiBC0PileUpSPD","eta-phi for clusters tof corresponding to BC=0, SPD pile-up",netabins,etamin,etamax, nphibins,phimin,phimax);
+    fhEtaPhiBC0PileUpSPD->SetXTitle("#eta ");
+    fhEtaPhiBC0PileUpSPD->SetYTitle("#phi (rad)");
+    outputContainer->Add(fhEtaPhiBC0PileUpSPD);
+    
+    fhEtaPhiBCPlusPileUpSPD  = new TH2F ("hEtaPhiBCPlusPileUpSPD","eta-phi for clusters tof corresponding to BC>0, SPD pile-up",netabins,etamin,etamax, nphibins,phimin,phimax);
+    fhEtaPhiBCPlusPileUpSPD->SetXTitle("#eta ");
+    fhEtaPhiBCPlusPileUpSPD->SetYTitle("#phi (rad)");
+    outputContainer->Add(fhEtaPhiBCPlusPileUpSPD);
+    
+    fhEtaPhiBCMinusPileUpSPD  = new TH2F ("hEtaPhiBCMinusPileUpSPD","eta-phi for clusters tof corresponding to BC<0, SPD pile-up",netabins,etamin,etamax, nphibins,phimin,phimax);
+    fhEtaPhiBCMinusPileUpSPD->SetXTitle("#eta ");
+    fhEtaPhiBCMinusPileUpSPD->SetYTitle("#phi (rad)");
+    outputContainer->Add(fhEtaPhiBCMinusPileUpSPD);
+
+    fhTimeENoCut  = new TH2F ("hTimeE_NoCut","time of cluster vs E of clusters, no cut", nptbins,ptmin,ptmax, ntimebins,timemin,timemax);
+    fhTimeENoCut->SetXTitle("E (GeV)");
+    fhTimeENoCut->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeENoCut);  
+    
+    fhTimeESPD  = new TH2F ("hTimeE_SPD","time of cluster vs E of clusters, SPD cut", nptbins,ptmin,ptmax, ntimebins,timemin,timemax); 
+    fhTimeESPD->SetXTitle("E (GeV)");
+    fhTimeESPD->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeESPD);  
+    
+    fhTimeESPDMulti  = new TH2F ("hTimeE_SPDMulti","time of cluster vs E of clusters, SPD multi cut", nptbins,ptmin,ptmax, ntimebins,timemin,timemax); 
+    fhTimeESPDMulti->SetXTitle("E (GeV)");
+    fhTimeESPDMulti->SetYTitle("time (ns)");
+    outputContainer->Add(fhTimeESPDMulti);  
+    
+    fhTimeNPileUpVertSPD  = new TH2F ("hTime_NPileUpVertSPD","time of cluster vs N pile-up SPD vertex", ntimebins,timemin,timemax,50,0,50); 
+    fhTimeNPileUpVertSPD->SetYTitle("# vertex ");
+    fhTimeNPileUpVertSPD->SetXTitle("time (ns)");
+    outputContainer->Add(fhTimeNPileUpVertSPD);
+    
+    fhTimeNPileUpVertTrack  = new TH2F ("hTime_NPileUpVertTracks","time of cluster vs N pile-up Tracks vertex", ntimebins,timemin,timemax, 50,0,50 ); 
+    fhTimeNPileUpVertTrack->SetYTitle("# vertex ");
+    fhTimeNPileUpVertTrack->SetXTitle("time (ns)");
+    outputContainer->Add(fhTimeNPileUpVertTrack);  
+    
+    fhTimeNPileUpVertContributors  = new TH2F ("hTime_NPileUpVertContributors","time of cluster vs N constributors to pile-up SPD vertex", ntimebins,timemin,timemax,50,0,50); 
+    fhTimeNPileUpVertContributors->SetYTitle("# vertex ");
+    fhTimeNPileUpVertContributors->SetXTitle("time (ns)");
+    outputContainer->Add(fhTimeNPileUpVertContributors);  
+    
+    fhTimePileUpMainVertexZDistance  = new TH2F ("hTime_PileUpMainVertexZDistance","time of cluster vs distance in Z pile-up SPD vertex - main SPD vertex",ntimebins,timemin,timemax,100,0,50); 
+    fhTimePileUpMainVertexZDistance->SetYTitle("distance Z (cm) ");
+    fhTimePileUpMainVertexZDistance->SetXTitle("time (ns)");
+    outputContainer->Add(fhTimePileUpMainVertexZDistance);  
+    
+    fhTimePileUpMainVertexZDiamond  = new TH2F ("hTime_PileUpMainVertexZDiamond","time of cluster vs distance in Z pile-up SPD vertex - z diamond",ntimebins,timemin,timemax,100,0,50); 
+    fhTimePileUpMainVertexZDiamond->SetYTitle("diamond distance Z (cm) ");
+    fhTimePileUpMainVertexZDiamond->SetXTitle("time (ns)");
+    outputContainer->Add(fhTimePileUpMainVertexZDiamond); 
+    
+    TString title[] = {"no |t diff| cut","|t diff|<20 ns","|t diff|>20 ns","|t diff|>40 ns"};
+    TString name [] = {"TDiffNoCut","TDiffSmaller20ns","TDiffLarger20ns","TDiffLarger40ns"};
+    for(Int_t i = 0; i < 4; i++) 
+    {      
+      fhClusterMultSPDPileUp[i] = new TH2F(Form("fhClusterMultSPDPileUp_%s", name[i].Data()),
+                                           Form("Number of clusters per pile up event with E > 0.5 and %s respect cluster max vs cluster max E ",title[i].Data()),
+                                           nptbins,ptmin,ptmax,100,0,100); 
+      fhClusterMultSPDPileUp[i]->SetYTitle("n clusters ");
+      fhClusterMultSPDPileUp[i]->SetXTitle("E_{cluster max} (GeV)");
+      outputContainer->Add(fhClusterMultSPDPileUp[i]) ;   
+      
+      fhClusterMultNoPileUp[i] = new TH2F(Form("fhClusterMultNoPileUp_%s", name[i].Data()),
+                                          Form("Number of clusters per non pile up event with E > 0.5 and %s respect cluster max vs cluster max E ",title[i].Data()),
+                                          nptbins,ptmin,ptmax,100,0,100); 
+      fhClusterMultNoPileUp[i]->SetYTitle("n clusters ");
+      fhClusterMultNoPileUp[i]->SetXTitle("E_{cluster max} (GeV)");
+      outputContainer->Add(fhClusterMultNoPileUp[i]) ;         
+    }
+    
+  }
   
-  if(IsDataMC()){
-   
+  if(IsDataMC())
+  {
     TString ptype[] = { "#gamma", "#gamma_{#pi decay}","#gamma_{other decay}", "#pi^{0}","#eta",
                         "e^{#pm}","#gamma->e^{#pm}","hadron?","Anti-N","Anti-P",
                         "#gamma_{prompt}","#gamma_{fragmentation}","#gamma_{ISR}","String"                                } ; 
@@ -1655,8 +2797,8 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
                         "Conversion", "Hadron", "AntiNeutron","AntiProton",
                         "PhotonPrompt","PhotonFragmentation","PhotonISR","String" } ;
     
-    for(Int_t i = 0; i < fNOriginHistograms; i++)
-      
+    for(Int_t i = 0; i < fNOriginHistograms; i++)
+    { 
       fhMCE[i]  = new TH1F(Form("hE_MC%s",pname[i].Data()),
                                 Form("cluster from %s : E ",ptype[i].Data()),
                                 nptbins,ptmin,ptmax); 
@@ -1719,7 +2861,8 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
     TString ppname[] = { "Photon","PhotonPi0Decay","PhotonOtherDecay","Hadron",
                          "PhotonPrompt","PhotonFragmentation","PhotonISR"} ;
     
-    for(Int_t i = 0; i < fNPrimaryHistograms; i++){ 
+    for(Int_t i = 0; i < fNPrimaryHistograms; i++)
+    { 
       fhEPrimMC[i]  = new TH1F(Form("hEPrim_MC%s",ppname[i].Data()),
                            Form("primary photon %s : E ",pptype[i].Data()),
                            nptbins,ptmin,ptmax); 
@@ -1775,14 +2918,14 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
       
     }
                
-    if(fFillSSHistograms){
-      
+    if(fFillSSHistograms)
+    {
       TString ptypess[] = { "#gamma","hadron?","#pi^{0}","#eta","#gamma->e^{#pm}","e^{#pm}"} ; 
       
       TString pnamess[] = { "Photon","Hadron","Pi0","Eta","Conversion","Electron"} ;
       
-      for(Int_t i = 0; i < 6; i++)
-        
+      for(Int_t i = 0; i < 6; i++)
+      { 
         fhMCELambda0[i]  = new TH2F(Form("hELambda0_MC%s",pnamess[i].Data()),
                                     Form("cluster from %s : E vs #lambda_{0}^{2}",ptypess[i].Data()),
                                     nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
@@ -1796,71 +2939,135 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
         fhMCELambda1[i]->SetYTitle("#lambda_{1}^{2}");
         fhMCELambda1[i]->SetXTitle("E (GeV)");
         outputContainer->Add(fhMCELambda1[i]) ; 
-              
+        
         fhMCEDispersion[i]  = new TH2F(Form("hEDispersion_MC%s",pnamess[i].Data()),
                                        Form("cluster from %s : E vs dispersion^{2}",ptypess[i].Data()),
                                        nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhMCEDispersion[i]->SetYTitle("D^{2}");
         fhMCEDispersion[i]->SetXTitle("E (GeV)");
         outputContainer->Add(fhMCEDispersion[i]) ; 
-                
+        
         fhMCNCellsE[i]  = new TH2F (Form("hNCellsE_MC%s",pnamess[i].Data()),
-                               Form("# of cells in cluster from %s vs E of clusters",ptypess[i].Data()), 
+                                    Form("# of cells in cluster from %s vs E of clusters",ptypess[i].Data()), 
                                     nptbins,ptmin,ptmax, nbins,nmin,nmax); 
         fhMCNCellsE[i]->SetXTitle("E (GeV)");
         fhMCNCellsE[i]->SetYTitle("# of cells in cluster");
         outputContainer->Add(fhMCNCellsE[i]);  
         
         fhMCMaxCellDiffClusterE[i]  = new TH2F (Form("hMaxCellDiffClusterE_MC%s",pnamess[i].Data()),
-                                             Form("energy vs difference of cluster energy from %s - max cell energy / cluster energy, good clusters",ptypess[i].Data()),
-                                           nptbins,ptmin,ptmax, 500,0,1.); 
+                                                Form("energy vs difference of cluster energy from %s - max cell energy / cluster energy, good clusters",ptypess[i].Data()),
+                                                nptbins,ptmin,ptmax, 500,0,1.); 
         fhMCMaxCellDiffClusterE[i]->SetXTitle("E_{cluster} (GeV) ");
         fhMCMaxCellDiffClusterE[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
         outputContainer->Add(fhMCMaxCellDiffClusterE[i]);  
         
-        fhMCLambda0vsClusterMaxCellDiffE0[i]  = new TH2F(Form("hLambda0vsClusterMaxCellDiffE0_MC%s",pnamess[i].Data()),
-                                    Form("cluster from %s : #lambda^{2}_{0} vs fraction of energy carried by max cell, E < 2 GeV",ptypess[i].Data()),
-                                    ssbins,ssmin,ssmax,500,0,1.); 
-        fhMCLambda0vsClusterMaxCellDiffE0[i]->SetXTitle("#lambda_{0}^{2}");
-        fhMCLambda0vsClusterMaxCellDiffE0[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
-        outputContainer->Add(fhMCLambda0vsClusterMaxCellDiffE0[i]) ; 
-        
-        fhMCLambda0vsClusterMaxCellDiffE2[i]  = new TH2F(Form("hLambda0vsClusterMaxCellDiffE2_MC%s",pnamess[i].Data()),
-                                                         Form("cluster from %s : #lambda^{2}_{0} vs fraction of energy carried by max cell, 2< E < 6 GeV",ptypess[i].Data()),
-                                                         ssbins,ssmin,ssmax,500,0,1.); 
-        fhMCLambda0vsClusterMaxCellDiffE2[i]->SetXTitle("#lambda_{0}^{2}");
-        fhMCLambda0vsClusterMaxCellDiffE2[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
-        outputContainer->Add(fhMCLambda0vsClusterMaxCellDiffE2[i]) ; 
-        
-        fhMCLambda0vsClusterMaxCellDiffE6[i]  = new TH2F(Form("hLambda0vsClusterMaxCellDiffE6_MC%s",pnamess[i].Data()),
-                                                         Form("cluster from %s : #lambda^{2}_{0} vs fraction of energy carried by max cell, E > 6 GeV",ptypess[i].Data()),
-                                                         ssbins,ssmin,ssmax,500,0,1.); 
-        fhMCLambda0vsClusterMaxCellDiffE6[i]->SetXTitle("#lambda_{0}^{2}");
-        fhMCLambda0vsClusterMaxCellDiffE6[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
-        outputContainer->Add(fhMCLambda0vsClusterMaxCellDiffE6[i]) ; 
-        
-        fhMCNCellsvsClusterMaxCellDiffE0[i]  = new TH2F(Form("hNCellsvsClusterMaxCellDiffE0_MC%s",pnamess[i].Data()),
-                                                         Form("cluster from %s : N cells in cluster vs fraction of energy carried by max cell, E < 2 GeV",ptypess[i].Data()),
-                                                         nbins/5,nmin,nmax/5,500,0,1.); 
-        fhMCNCellsvsClusterMaxCellDiffE0[i]->SetXTitle("N cells in cluster");
-        fhMCNCellsvsClusterMaxCellDiffE0[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
-        outputContainer->Add(fhMCNCellsvsClusterMaxCellDiffE0[i]) ; 
-        
-        fhMCNCellsvsClusterMaxCellDiffE2[i]  = new TH2F(Form("hNCellsvsClusterMaxCellDiffE2_MC%s",pnamess[i].Data()),
-                                                         Form("cluster from %s : N cells in cluster vs fraction of energy carried by max cell, 2< E < 6 GeV",ptypess[i].Data()),
-                                                         nbins/5,nmin,nmax/5,500,0,1.); 
-        fhMCNCellsvsClusterMaxCellDiffE2[i]->SetXTitle("N cells in cluster");
-        fhMCNCellsvsClusterMaxCellDiffE2[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
-        outputContainer->Add(fhMCNCellsvsClusterMaxCellDiffE2[i]) ; 
-        
-        fhMCNCellsvsClusterMaxCellDiffE6[i]  = new TH2F(Form("hNCellsvsClusterMaxCellDiffE6_MC%s",pnamess[i].Data()),
-                                                         Form("cluster from %s : N cells in cluster vs fraction of energy carried by max cell, E > 6 GeV",ptypess[i].Data()),
-                                                         nbins/5,nmin,nmax/5,500,0,1.); 
-        fhMCNCellsvsClusterMaxCellDiffE6[i]->SetXTitle("N cells in cluster");
-        fhMCNCellsvsClusterMaxCellDiffE6[i]->SetYTitle("E (GeV)");
-        outputContainer->Add(fhMCNCellsvsClusterMaxCellDiffE6[i]) ; 
-        
-       }// loop    
+        if(!fFillOnlySimpleSSHisto)
+        {
+          fhMCLambda0vsClusterMaxCellDiffE0[i]  = new TH2F(Form("hLambda0vsClusterMaxCellDiffE0_MC%s",pnamess[i].Data()),
+                                                           Form("cluster from %s : #lambda^{2}_{0} vs fraction of energy carried by max cell, E < 2 GeV",ptypess[i].Data()),
+                                                           ssbins,ssmin,ssmax,500,0,1.); 
+          fhMCLambda0vsClusterMaxCellDiffE0[i]->SetXTitle("#lambda_{0}^{2}");
+          fhMCLambda0vsClusterMaxCellDiffE0[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
+          outputContainer->Add(fhMCLambda0vsClusterMaxCellDiffE0[i]) ; 
+          
+          fhMCLambda0vsClusterMaxCellDiffE2[i]  = new TH2F(Form("hLambda0vsClusterMaxCellDiffE2_MC%s",pnamess[i].Data()),
+                                                           Form("cluster from %s : #lambda^{2}_{0} vs fraction of energy carried by max cell, 2< E < 6 GeV",ptypess[i].Data()),
+                                                           ssbins,ssmin,ssmax,500,0,1.); 
+          fhMCLambda0vsClusterMaxCellDiffE2[i]->SetXTitle("#lambda_{0}^{2}");
+          fhMCLambda0vsClusterMaxCellDiffE2[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
+          outputContainer->Add(fhMCLambda0vsClusterMaxCellDiffE2[i]) ; 
+          
+          fhMCLambda0vsClusterMaxCellDiffE6[i]  = new TH2F(Form("hLambda0vsClusterMaxCellDiffE6_MC%s",pnamess[i].Data()),
+                                                           Form("cluster from %s : #lambda^{2}_{0} vs fraction of energy carried by max cell, E > 6 GeV",ptypess[i].Data()),
+                                                           ssbins,ssmin,ssmax,500,0,1.); 
+          fhMCLambda0vsClusterMaxCellDiffE6[i]->SetXTitle("#lambda_{0}^{2}");
+          fhMCLambda0vsClusterMaxCellDiffE6[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
+          outputContainer->Add(fhMCLambda0vsClusterMaxCellDiffE6[i]) ; 
+          
+          fhMCNCellsvsClusterMaxCellDiffE0[i]  = new TH2F(Form("hNCellsvsClusterMaxCellDiffE0_MC%s",pnamess[i].Data()),
+                                                          Form("cluster from %s : N cells in cluster vs fraction of energy carried by max cell, E < 2 GeV",ptypess[i].Data()),
+                                                          nbins/5,nmin,nmax/5,500,0,1.); 
+          fhMCNCellsvsClusterMaxCellDiffE0[i]->SetXTitle("N cells in cluster");
+          fhMCNCellsvsClusterMaxCellDiffE0[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
+          outputContainer->Add(fhMCNCellsvsClusterMaxCellDiffE0[i]) ; 
+          
+          fhMCNCellsvsClusterMaxCellDiffE2[i]  = new TH2F(Form("hNCellsvsClusterMaxCellDiffE2_MC%s",pnamess[i].Data()),
+                                                          Form("cluster from %s : N cells in cluster vs fraction of energy carried by max cell, 2< E < 6 GeV",ptypess[i].Data()),
+                                                          nbins/5,nmin,nmax/5,500,0,1.); 
+          fhMCNCellsvsClusterMaxCellDiffE2[i]->SetXTitle("N cells in cluster");
+          fhMCNCellsvsClusterMaxCellDiffE2[i]->SetYTitle("(E_{cluster} - E_{cell max})/ E_{cluster}");
+          outputContainer->Add(fhMCNCellsvsClusterMaxCellDiffE2[i]) ; 
+          
+          fhMCNCellsvsClusterMaxCellDiffE6[i]  = new TH2F(Form("hNCellsvsClusterMaxCellDiffE6_MC%s",pnamess[i].Data()),
+                                                          Form("cluster from %s : N cells in cluster vs fraction of energy carried by max cell, E > 6 GeV",ptypess[i].Data()),
+                                                          nbins/5,nmin,nmax/5,500,0,1.); 
+          fhMCNCellsvsClusterMaxCellDiffE6[i]->SetXTitle("N cells in cluster");
+          fhMCNCellsvsClusterMaxCellDiffE6[i]->SetYTitle("E (GeV)");
+          outputContainer->Add(fhMCNCellsvsClusterMaxCellDiffE6[i]) ; 
+          
+          if(fCalorimeter=="EMCAL")
+          {
+            fhMCEDispEta[i]  = new TH2F (Form("hEDispEtaE_MC%s",pnamess[i].Data()),
+                                         Form("cluster from %s : #sigma^{2}_{#eta #eta} = #Sigma w_{i}(#eta_{i} - <#eta>)^{2}/ #Sigma w_{i} vs E",ptypess[i].Data()),
+                                         nptbins,ptmin,ptmax, ssbins,ssmin,ssmax); 
+            fhMCEDispEta[i]->SetXTitle("E (GeV)");
+            fhMCEDispEta[i]->SetYTitle("#sigma^{2}_{#eta #eta}");
+            outputContainer->Add(fhMCEDispEta[i]);     
+            
+            fhMCEDispPhi[i]  = new TH2F (Form("hEDispPhiE_MC%s",pnamess[i].Data()),
+                                         Form("cluster from %s : #sigma^{2}_{#phi #phi} = #Sigma w_{i}(#phi_{i} - <#phi>)^{2} / #Sigma w_{i} vs E",ptypess[i].Data()),
+                                         nptbins,ptmin,ptmax, ssbins,ssmin,ssmax); 
+            fhMCEDispPhi[i]->SetXTitle("E (GeV)");
+            fhMCEDispPhi[i]->SetYTitle("#sigma^{2}_{#phi #phi}");
+            outputContainer->Add(fhMCEDispPhi[i]);  
+            
+            fhMCESumEtaPhi[i]  = new TH2F (Form("hESumEtaPhiE_MC%s",pnamess[i].Data()),
+                                           Form("cluster from %s : #delta^{2}_{#eta #phi} = #Sigma w_{i}(#phi_{i} #eta_{i} ) / #Sigma w_{i} - <#phi><#eta> vs E",ptypess[i].Data()),  
+                                           nptbins,ptmin,ptmax, 2*ssbins,-ssmax,ssmax); 
+            fhMCESumEtaPhi[i]->SetXTitle("E (GeV)");
+            fhMCESumEtaPhi[i]->SetYTitle("#delta^{2}_{#eta #phi}");
+            outputContainer->Add(fhMCESumEtaPhi[i]);
+            
+            fhMCEDispEtaPhiDiff[i]  = new TH2F (Form("hEDispEtaPhiDiffE_MC%s",pnamess[i].Data()),
+                                                Form("cluster from %s : #sigma^{2}_{#phi #phi} - #sigma^{2}_{#eta #eta} vs E",ptypess[i].Data()),  
+                                                nptbins,ptmin,ptmax,200,-10,10); 
+            fhMCEDispEtaPhiDiff[i]->SetXTitle("E (GeV)");
+            fhMCEDispEtaPhiDiff[i]->SetYTitle("#sigma^{2}_{#phi #phi}-#sigma^{2}_{#eta #eta}");
+            outputContainer->Add(fhMCEDispEtaPhiDiff[i]);    
+            
+            fhMCESphericity[i]  = new TH2F (Form("hESphericity_MC%s",pnamess[i].Data()),
+                                            Form("cluster from %s : (#sigma^{2}_{#phi #phi} - #sigma^{2}_{#eta #eta}) / (#sigma^{2}_{#eta #eta} + #sigma^{2}_{#phi #phi}) vs E",ptypess[i].Data()),  
+                                            nptbins,ptmin,ptmax, 200,-1,1); 
+            fhMCESphericity[i]->SetXTitle("E (GeV)");
+            fhMCESphericity[i]->SetYTitle("s = (#sigma^{2}_{#phi #phi} - #sigma^{2}_{#eta #eta}) / (#sigma^{2}_{#eta #eta} + #sigma^{2}_{#phi #phi})");
+            outputContainer->Add(fhMCESphericity[i]);
+            
+            for(Int_t ie = 0; ie < 7; ie++)
+            {
+              fhMCDispEtaDispPhi[ie][i] = new TH2F (Form("hMCDispEtaDispPhi_EBin%d_MC%s",ie,pnamess[i].Data()),
+                                                    Form("cluster from %s : #sigma^{2}_{#phi #phi} vs #sigma^{2}_{#eta #eta} for %d < E < %d GeV",pnamess[i].Data(),bin[ie],bin[ie+1]), 
+                                                    ssbins,ssmin,ssmax , ssbins,ssmin,ssmax); 
+              fhMCDispEtaDispPhi[ie][i]->SetXTitle("#sigma^{2}_{#eta #eta}");
+              fhMCDispEtaDispPhi[ie][i]->SetYTitle("#sigma^{2}_{#phi #phi}");
+              outputContainer->Add(fhMCDispEtaDispPhi[ie][i]); 
+              
+              fhMCLambda0DispEta[ie][i] = new TH2F (Form("hMCLambda0DispEta_EBin%d_MC%s",ie,pnamess[i].Data()),
+                                                    Form("cluster from %s : #lambda^{2}_{0} vs #sigma^{2}_{#eta #eta} for %d < E < %d GeV",pnamess[i].Data(),bin[ie],bin[ie+1]), 
+                                                    ssbins,ssmin,ssmax , ssbins,ssmin,ssmax); 
+              fhMCLambda0DispEta[ie][i]->SetXTitle("#lambda^{2}_{0}");
+              fhMCLambda0DispEta[ie][i]->SetYTitle("#sigma^{2}_{#phi #phi}");
+              outputContainer->Add(fhMCLambda0DispEta[ie][i]);       
+              
+              fhMCLambda0DispPhi[ie][i] = new TH2F (Form("hMCLambda0DispPhi_EBin%d_MC%s",ie,pnamess[i].Data()),
+                                                    Form("cluster from %s :#lambda^{2}_{0} vs #sigma^{2}_{#phi #phi} for %d < E < %d GeV",pnamess[i].Data(),bin[ie],bin[ie+1]), 
+                                                    ssbins,ssmin,ssmax , ssbins,ssmin,ssmax); 
+              fhMCLambda0DispPhi[ie][i]->SetXTitle("#lambda^{2}_{0}");
+              fhMCLambda0DispPhi[ie][i]->SetYTitle("#sigma^{2}_{#phi #phi}");
+              outputContainer->Add(fhMCLambda0DispPhi[ie][i]); 
+            }
+          }
+        }
+      }// loop    
       
       if(!GetReader()->IsEmbeddedClusterSelectionOn())
       {
@@ -1887,95 +3094,96 @@ TList *  AliAnaPhoton::GetCreateOutputObjects()
         
       } //No embedding     
       
-      //Fill histograms to check shape of embedded clusters
       if(GetReader()->IsEmbeddedClusterSelectionOn())
       {
         
         fhEmbeddedSignalFractionEnergy  = new TH2F("hEmbeddedSignal_FractionEnergy",
-                                                    "Energy Fraction of embedded signal versus cluster energy",
-                                                    nptbins,ptmin,ptmax,100,0.,1.); 
+                                                   "Energy Fraction of embedded signal versus cluster energy",
+                                                   nptbins,ptmin,ptmax,100,0.,1.); 
         fhEmbeddedSignalFractionEnergy->SetYTitle("Fraction");
         fhEmbeddedSignalFractionEnergy->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbeddedSignalFractionEnergy) ; 
         
         fhEmbedPhotonELambda0FullSignal  = new TH2F("hELambda0_EmbedPhoton_FullSignal",
-                                                "cluster from Photon embedded with more than 90% energy in cluster : E vs #lambda_{0}^{2}",
-                                                nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
+                                                    "cluster from Photon embedded with more than 90% energy in cluster : E vs #lambda_{0}^{2}",
+                                                    nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhEmbedPhotonELambda0FullSignal->SetYTitle("#lambda_{0}^{2}");
         fhEmbedPhotonELambda0FullSignal->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbedPhotonELambda0FullSignal) ; 
-                
+        
         fhEmbedPhotonELambda0MostlySignal  = new TH2F("hELambda0_EmbedPhoton_MostlySignal",
-                                          "cluster from Photon embedded with 50% to 90% energy in cluster : E vs #lambda_{0}^{2}",
-                                          nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
+                                                      "cluster from Photon embedded with 50% to 90% energy in cluster : E vs #lambda_{0}^{2}",
+                                                      nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhEmbedPhotonELambda0MostlySignal->SetYTitle("#lambda_{0}^{2}");
         fhEmbedPhotonELambda0MostlySignal->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbedPhotonELambda0MostlySignal) ; 
         
         fhEmbedPhotonELambda0MostlyBkg  = new TH2F("hELambda0_EmbedPhoton_MostlyBkg",
-                                          "cluster from Photon embedded with 10% to 50% energy in cluster : E vs #lambda_{0}^{2}",
-                                          nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
+                                                   "cluster from Photon embedded with 10% to 50% energy in cluster : E vs #lambda_{0}^{2}",
+                                                   nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhEmbedPhotonELambda0MostlyBkg->SetYTitle("#lambda_{0}^{2}");
         fhEmbedPhotonELambda0MostlyBkg->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbedPhotonELambda0MostlyBkg) ; 
-                
+        
         fhEmbedPhotonELambda0FullBkg  = new TH2F("hELambda0_EmbedPhoton_FullBkg",
-                                                   "cluster from Photonm embedded with 0% to 10% energy in cluster : E vs #lambda_{0}^{2}",
-                                                   nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
+                                                 "cluster from Photonm embedded with 0% to 10% energy in cluster : E vs #lambda_{0}^{2}",
+                                                 nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhEmbedPhotonELambda0FullBkg->SetYTitle("#lambda_{0}^{2}");
         fhEmbedPhotonELambda0FullBkg->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbedPhotonELambda0FullBkg) ; 
         
         fhEmbedPi0ELambda0FullSignal  = new TH2F("hELambda0_EmbedPi0_FullSignal",
-                                                    "cluster from Pi0 embedded with more than 90% energy in cluster : E vs #lambda_{0}^{2}",
-                                                    nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
+                                                 "cluster from Pi0 embedded with more than 90% energy in cluster : E vs #lambda_{0}^{2}",
+                                                 nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhEmbedPi0ELambda0FullSignal->SetYTitle("#lambda_{0}^{2}");
         fhEmbedPi0ELambda0FullSignal->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbedPi0ELambda0FullSignal) ; 
-                
+        
         fhEmbedPi0ELambda0MostlySignal  = new TH2F("hELambda0_EmbedPi0_MostlySignal",
-                                                      "cluster from Pi0 embedded with 50% to 90% energy in cluster : E vs #lambda_{0}^{2}",
-                                                      nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
+                                                   "cluster from Pi0 embedded with 50% to 90% energy in cluster : E vs #lambda_{0}^{2}",
+                                                   nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhEmbedPi0ELambda0MostlySignal->SetYTitle("#lambda_{0}^{2}");
         fhEmbedPi0ELambda0MostlySignal->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbedPi0ELambda0MostlySignal) ; 
         
         fhEmbedPi0ELambda0MostlyBkg  = new TH2F("hELambda0_EmbedPi0_MostlyBkg",
-                                                   "cluster from Pi0 embedded with 10% to 50% energy in cluster : E vs #lambda_{0}^{2}",
-                                                   nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
+                                                "cluster from Pi0 embedded with 10% to 50% energy in cluster : E vs #lambda_{0}^{2}",
+                                                nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhEmbedPi0ELambda0MostlyBkg->SetYTitle("#lambda_{0}^{2}");
         fhEmbedPi0ELambda0MostlyBkg->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbedPi0ELambda0MostlyBkg) ; 
         
         fhEmbedPi0ELambda0FullBkg  = new TH2F("hELambda0_EmbedPi0_FullBkg",
-                                                 "cluster from Pi0 embedded with 0% to 10% energy in cluster : E vs #lambda_{0}^{2}",
-                                                 nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
+                                              "cluster from Pi0 embedded with 0% to 10% energy in cluster : E vs #lambda_{0}^{2}",
+                                              nptbins,ptmin,ptmax,ssbins,ssmin,ssmax); 
         fhEmbedPi0ELambda0FullBkg->SetYTitle("#lambda_{0}^{2}");
         fhEmbedPi0ELambda0FullBkg->SetXTitle("E (GeV)");
         outputContainer->Add(fhEmbedPi0ELambda0FullBkg) ; 
-  
+        
       }// embedded histograms
       
       
     }// Fill SS MC histograms
     
   }//Histos with MC
-      
+  
   return outputContainer ;
   
 }
 
-//____________________________________________________________________________
+//_______________________
 void AliAnaPhoton::Init()
 {
   
   //Init
   //Do some checks
-  if(fCalorimeter == "PHOS" && !GetReader()->IsPHOSSwitchedOn() && NewOutputAOD()){
+  if(fCalorimeter == "PHOS" && !GetReader()->IsPHOSSwitchedOn() && NewOutputAOD())
+  {
     printf("AliAnaPhoton::Init() - !!STOP: You want to use PHOS in analysis but it is not read!! \n!!Check the configuration file!!\n");
     abort();
   }
-  else  if(fCalorimeter == "EMCAL" && !GetReader()->IsEMCALSwitchedOn() && NewOutputAOD()){
+  else  if(fCalorimeter == "EMCAL" && !GetReader()->IsEMCALSwitchedOn() && NewOutputAOD())
+  {
     printf("AliAnaPhoton::Init() - !!STOP: You want to use EMCAL in analysis but it is not read!! \n!!Check the configuration file!!\n");
     abort();
   }
@@ -2027,29 +3235,119 @@ void  AliAnaPhoton::MakeAnalysisFillAOD()
     cells = GetEMCALCells();
   }
   
-  if(!pl) {
+  if(!pl) 
+  {
     Info("MakeAnalysisFillAOD","TObjArray with %s clusters is NULL!\n",fCalorimeter.Data());
     return;
   }
   
+  FillPileUpHistogramsPerEvent(pl); 
+  
   // Loop on raw clusters before filtering in the reader and fill control histogram
-  if((GetReader()->GetEMCALClusterListName()=="" && fCalorimeter=="EMCAL") || fCalorimeter=="PHOS"){
-    for(Int_t iclus = 0; iclus < GetReader()->GetInputEvent()->GetNumberOfCaloClusters(); iclus++ ){
+  if((GetReader()->GetEMCALClusterListName()=="" && fCalorimeter=="EMCAL") || fCalorimeter=="PHOS")
+  {
+    for(Int_t iclus = 0; iclus < GetReader()->GetInputEvent()->GetNumberOfCaloClusters(); iclus++ )
+    {
       AliVCluster * clus = GetReader()->GetInputEvent()->GetCaloCluster(iclus);
       if     (fCalorimeter == "PHOS"  && clus->IsPHOS()  && clus->E() > GetReader()->GetPHOSPtMin() ) fhClusterCuts[0]->Fill(clus->E());
       else if(fCalorimeter == "EMCAL" && clus->IsEMCAL() && clus->E() > GetReader()->GetEMCALPtMin()) fhClusterCuts[0]->Fill(clus->E());
     }
   }
-  else { // reclusterized
+  else 
+  { // reclusterized
     TClonesArray * clusterList = 0;
-    if(GetReader()->GetOutputEvent())
+
+    if(GetReader()->GetInputEvent()->FindListObject(GetReader()->GetEMCALClusterListName()))
+      clusterList = dynamic_cast<TClonesArray*> (GetReader()->GetInputEvent()->FindListObject(GetReader()->GetEMCALClusterListName()));
+    else if(GetReader()->GetOutputEvent())
       clusterList = dynamic_cast<TClonesArray*> (GetReader()->GetOutputEvent()->FindListObject(GetReader()->GetEMCALClusterListName()));
-    if(clusterList){
+    
+    if(clusterList)
+    {
       Int_t nclusters = clusterList->GetEntriesFast();
-      for (Int_t iclus =  0; iclus <  nclusters; iclus++) {
+      for (Int_t iclus =  0; iclus <  nclusters; iclus++) 
+      {
         AliVCluster * clus = dynamic_cast<AliVCluster*> (clusterList->At(iclus));        
         if(clus)fhClusterCuts[0]->Fill(clus->E());
-      }  
+      }
+    }
+  }
+  
+  // Fill some trigger related histograms
+  Int_t  idTrig = GetReader()->GetTriggerClusterIndex();
+  Bool_t exotic = GetReader()->IsExoticEvent();
+  Bool_t bad    = GetReader()->IsBadCellTriggerEvent();
+
+  if( fFillEMCALBCHistograms && fCalorimeter=="EMCAL" &&
+      ( bad || exotic )  && idTrig >= 0)
+  {
+//    printf("Index %d, Id %d,  bad %d, exo %d\n",
+//           GetReader()->GetTriggerClusterIndex(),
+//           GetReader()->GetTriggerClusterId(),
+//           GetReader()->IsBadCellTriggerEvent(),
+//           GetReader()->IsExoticEvent() );
+    
+    TClonesArray * clusterList = 0;
+    TString  clusterListName   = GetReader()->GetEMCALClusterListName();
+    if     (GetReader()->GetInputEvent()->FindListObject(clusterListName))
+      clusterList = dynamic_cast<TClonesArray*> (GetReader()->GetInputEvent() ->FindListObject(clusterListName));
+    else if(GetReader()->GetOutputEvent())
+      clusterList = dynamic_cast<TClonesArray*> (GetReader()->GetOutputEvent()->FindListObject(clusterListName));
+    
+    AliVCluster  *  badClusTrig = 0;
+    if(clusterList) badClusTrig = (AliVCluster*) clusterList->At(idTrig);
+    else            badClusTrig = GetReader()->GetInputEvent()->GetCaloCluster(idTrig);
+
+    if(!badClusTrig) printf("AliAnaPhoton::MakeAnalysisFillAOD() - No cluster (bad-exotic trigger) found with requested index %d \n",idTrig);
+    
+    TLorentzVector momBadClus;
+    badClusTrig->GetMomentum(momBadClus,GetVertex(0));
+  
+    Float_t etaclusterBad = momBadClus.Eta();
+    Float_t phiclusterBad = momBadClus.Phi();
+    if( phiclusterBad < 0 ) phiclusterBad+=TMath::TwoPi();
+    Float_t tofclusterBad = badClusTrig->GetTOF()*1.e9;
+    Float_t eclusterBad   = badClusTrig->E();
+
+    if( bad && exotic )
+    {
+      if(GetReader()->IsTriggerMatched())
+      {
+        fhEtaPhiTriggerEMCALBCBadExoticCluster->Fill(etaclusterBad, phiclusterBad);
+        fhTimeTriggerEMCALBCBadExoticCluster  ->Fill(eclusterBad,   tofclusterBad);
+      }
+      else
+      {
+        fhEtaPhiTriggerEMCALBCUMBadExoticCluster->Fill(etaclusterBad, phiclusterBad);
+        fhTimeTriggerEMCALBCUMBadExoticCluster  ->Fill(eclusterBad,   tofclusterBad);
+      }
+    }
+    else if( bad && !exotic )
+    {
+      if(GetReader()->IsTriggerMatched())
+      {
+        fhEtaPhiTriggerEMCALBCBadCluster->Fill(etaclusterBad, phiclusterBad);
+        fhTimeTriggerEMCALBCBadCluster  ->Fill(eclusterBad,   tofclusterBad);
+      }
+      else
+      {
+        fhEtaPhiTriggerEMCALBCUMBadCluster->Fill(etaclusterBad, phiclusterBad);
+        fhTimeTriggerEMCALBCUMBadCluster  ->Fill(eclusterBad,   tofclusterBad);
+      }
+    }// Bad cluster trigger
+    else if( !bad && exotic )
+    {
+      if(GetReader()->IsTriggerMatched())
+      {
+        fhEtaPhiTriggerEMCALBCExoticCluster->Fill(etaclusterBad, phiclusterBad);
+        fhTimeTriggerEMCALBCExoticCluster  ->Fill(eclusterBad, tofclusterBad);
+      }
+      else
+      {
+        fhEtaPhiTriggerEMCALBCUMExoticCluster->Fill(etaclusterBad, phiclusterBad);
+        fhTimeTriggerEMCALBCUMExoticCluster  ->Fill(eclusterBad, tofclusterBad);
+      }
     }
   }
   
@@ -2063,23 +3361,27 @@ void  AliAnaPhoton::MakeAnalysisFillAOD()
   // Fill AOD with PHOS/EMCAL AliAODPWG4Particle objects
   //----------------------------------------------------
   // Loop on clusters
-  for(Int_t icalo = 0; icalo < nCaloClusters; icalo++){    
-         
+  for(Int_t icalo = 0; icalo < nCaloClusters; icalo++)
+  {    
          AliVCluster * calo =  (AliVCluster*) (pl->At(icalo)); 
     //printf("calo %d, %f\n",icalo,calo->E());
     
     //Get the index where the cluster comes, to retrieve the corresponding vertex
     Int_t evtIndex = 0 ; 
-    if (GetMixedEvent()) {
+    if (GetMixedEvent()) 
+    {
       evtIndex=GetMixedEvent()->EventIndexForCaloCluster(calo->GetID()) ; 
       //Get the vertex and check it is not too large in z
       if(TMath::Abs(GetVertex(evtIndex)[2])> GetZvertexCut()) continue;
     }
     
     //Cluster selection, not charged, with photon id and in fiducial cut         
-    if(GetReader()->GetDataType() != AliCaloTrackReader::kMC){
-      calo->GetMomentum(mom,GetVertex(evtIndex)) ;}//Assume that come from vertex in straight line
-    else{
+    if(GetReader()->GetDataType() != AliCaloTrackReader::kMC)
+    {
+      calo->GetMomentum(mom,GetVertex(evtIndex)) ;
+    }//Assume that come from vertex in straight line
+    else
+    {
       Double_t vertex[]={0,0,0};
       calo->GetMomentum(mom,vertex) ;
     }
@@ -2087,8 +3389,9 @@ void  AliAnaPhoton::MakeAnalysisFillAOD()
     //--------------------------------------
     // Cluster selection
     //--------------------------------------
-    if(!ClusterSelected(calo,mom)) continue;
-    
+    Int_t nMaxima = GetCaloUtils()->GetNumberOfLocalMaxima(calo, cells); // NLM
+    if(!ClusterSelected(calo,mom,nMaxima)) continue;
+
     //----------------------------
     //Create AOD for analysis
     //----------------------------
@@ -2117,9 +3420,9 @@ void  AliAnaPhoton::MakeAnalysisFillAOD()
     //Check origin of the candidates
     Int_t tag = -1;
     
-    if(IsDataMC()){
-      
-      tag = GetMCAnalysisUtils()->CheckOrigin(calo->GetLabels(),calo->GetNLabels(),GetReader(), aodph.GetInputFileIndex());
+    if(IsDataMC())
+    {
+      tag = GetMCAnalysisUtils()->CheckOrigin(calo->GetLabels(),calo->GetNLabels(),GetReader());
       aodph.SetTag(tag);
       
       if(GetDebug() > 0)
@@ -2152,7 +3455,7 @@ void  AliAnaPhoton::MakeAnalysisFillAOD()
       if(aodph.GetIdentifiedParticleType() != AliCaloPID::kPhoton) continue ;                  
       
     }
-    
+
     //...............................................
     // Data, PID check off
     else
@@ -2168,16 +3471,53 @@ void  AliAnaPhoton::MakeAnalysisFillAOD()
     if(GetDebug() > 1) printf("AliAnaPhoton::MakeAnalysisFillAOD() - Photon selection cuts passed: pT %3.2f, pdg %d\n",
                               aodph.Pt(), aodph.GetIdentifiedParticleType());
     
-    fhClusterCuts[8]->Fill(calo->E());
-    
+    fhClusterCuts[9]->Fill(calo->E());
+
+    fhNLocMax->Fill(calo->E(),nMaxima);
+
     // Matching after cuts
     if(fFillTMHisto) FillTrackMatchingResidualHistograms(calo,1);
     
+    // Fill histograms to undertand pile-up before other cuts applied
+    // Remember to relax time cuts in the reader
+    FillPileUpHistograms(calo->E(),mom.Pt(),calo->GetTOF()*1e9);
+    
     // Add number of local maxima to AOD, method name in AOD to be FIXED
+    aodph.SetFiducialArea(nMaxima);
     
-    aodph.SetFiducialArea(GetCaloUtils()->GetNumberOfLocalMaxima(calo, cells));
+    if(fFillEMCALBCHistograms && fCalorimeter=="EMCAL" && idTrig >= 0)
+    {
+      Double_t calotof   = calo->GetTOF()*1e9;
+      Float_t  calotofUS = TMath::Abs(calotof);
+      Float_t phicluster = aodph.Phi();
+      if(phicluster < 0) phicluster+=TMath::TwoPi();
+      
+      if(calo->E() > 2)
+      {
+        if      (calotofUS < 25) fhEtaPhiPhotonEMCALBC0->Fill(aodph.Eta(), phicluster);
+        else if (calotofUS < 75) fhEtaPhiPhotonEMCALBC1->Fill(aodph.Eta(), phicluster);
+        else                     fhEtaPhiPhotonEMCALBCN->Fill(aodph.Eta(), phicluster);
+      }
+      
+      Int_t bc = GetReader()->GetTriggerClusterBC();
+      if(TMath::Abs(bc) < 6 && !GetReader()->IsBadCellTriggerEvent() && !GetReader()->IsExoticEvent())
+      {
+        if(GetReader()->IsTriggerMatched())
+        {
+          if(calo->E() > 2) fhEtaPhiPhotonTriggerEMCALBC[bc+5]->Fill(aodph.Eta(), phicluster);
+          fhTimePhotonTriggerEMCALBC[bc+5]->Fill(calo->E(), calotof);
+          if(GetReader()->IsPileUpFromSPD()) fhTimePhotonTriggerEMCALBCPileUpSPD[bc+5]->Fill(calo->E(), calotof);
+        }
+        else
+        {
+          if(calo->E() > 2) fhEtaPhiPhotonTriggerEMCALBCUM[bc+5]->Fill(aodph.Eta(), phicluster);
+          fhTimePhotonTriggerEMCALBCUM[bc+5]->Fill(calo->E(), calotof);
+        }
+      }
+      else if(TMath::Abs(bc) >= 6)
+        printf("AliAnaPhoton::MakeAnalysisFillAOD() - Trigger BC not expected = %d\n",bc);
+    }
     
-
     //Add AOD with photon object to aod branch
     AddAODParticle(aodph);
     
@@ -2191,35 +3531,7 @@ void  AliAnaPhoton::MakeAnalysisFillAOD()
 void  AliAnaPhoton::MakeAnalysisFillHistograms() 
 {
   //Fill histograms
-  
-  //-------------------------------------------------------------------
-  // Access MC information in stack if requested, check that it exists.        
-  AliStack         * stack       = 0x0;
-  TParticle        * primary     = 0x0;   
-  TClonesArray     * mcparticles = 0x0;
-  AliAODMCParticle * aodprimary  = 0x0; 
-  
-  if(IsDataMC()){
-    
-    if(GetReader()->ReadStack()){
-      stack =  GetMCStack() ;
-      if(!stack) {
-        printf("AliAnaPhoton::MakeAnalysisFillHistograms() - Stack not available, is the MC handler called? STOP\n");
-        abort();
-      }
-      
-    }
-    else if(GetReader()->ReadAODMCParticles()){
       
-      //Get the list of MC particles
-      mcparticles = GetReader()->GetAODMCParticles(0);
-      if(!mcparticles && GetDebug() > 0)       {
-        printf("AliAnaPhoton::MakeAnalysisFillHistograms() -  Standard MCParticles not available!\n");
-      }        
-    }
-  }// is data and MC
-  
-  
   // Get vertex
   Double_t v[3] = {0,0,0}; //vertex ;
   GetReader()->GetVertex(v);
@@ -2231,6 +3543,11 @@ void  AliAnaPhoton::MakeAnalysisFillHistograms()
   Int_t naod = GetOutputAODBranch()->GetEntriesFast();
   if(GetDebug() > 0) printf("AliAnaPhoton::MakeAnalysisFillHistograms() - aod branch entries %d\n", naod);
   
+  Float_t cen = GetEventCentrality();
+ // printf("++++++++++ GetEventCentrality() %f\n",cen);
+  Float_t ep  = GetEventPlaneAngle();
+  
   for(Int_t iaod = 0; iaod < naod ; iaod++)
   {
     AliAODPWG4Particle* ph =  (AliAODPWG4Particle*) (GetOutputAODBranch()->At(iaod));
@@ -2258,20 +3575,24 @@ void  AliAnaPhoton::MakeAnalysisFillHistograms()
     fhPtPhoton  ->Fill(ptcluster);
     fhPhiPhoton ->Fill(ptcluster,phicluster);
     fhEtaPhoton ->Fill(ptcluster,etacluster);    
-    if     (ecluster > 0.5)   fhEtaPhiPhoton  ->Fill(etacluster, phicluster);
+    if     (ecluster   > 0.5) fhEtaPhiPhoton  ->Fill(etacluster, phicluster);
     else if(GetMinPt() < 0.5) fhEtaPhi05Photon->Fill(etacluster, phicluster);
-    
 
+    fhPtCentralityPhoton ->Fill(ptcluster,cen) ;
+    fhPtEventPlanePhoton ->Fill(ptcluster,ep ) ;
+    
     //Get original cluster, to recover some information
     Int_t absID             = 0; 
     Float_t maxCellFraction = 0;
     AliVCaloCells* cells    = 0;
     TObjArray * clusters    = 0; 
-    if(fCalorimeter == "EMCAL"){
+    if(fCalorimeter == "EMCAL")
+    {
       cells    = GetEMCALCells();
       clusters = GetEMCALClusters();
     }
-    else{
+    else
+    {
       cells    = GetPHOSCells();
       clusters = GetPHOSClusters();
     }
@@ -2295,62 +3616,44 @@ void  AliAnaPhoton::MakeAnalysisFillHistograms()
     
     //.......................................
     //Play with the MC data if available
-    if(IsDataMC()){
+    if(IsDataMC())
+    {
+      if(GetDebug()>0)
+      {
+        if(GetReader()->ReadStack() && !GetMCStack())
+        {
+          printf("AliAnaPhoton::MakeAnalysisFillHistograms() - Stack not available, is the MC handler called?\n");
+        }
+        else if(GetReader()->ReadAODMCParticles() && !GetReader()->GetAODMCParticles())
+        {
+          printf("AliAnaPhoton::MakeAnalysisFillHistograms() -  Standard MCParticles not available!\n");
+        }      
+      }    
       
       FillAcceptanceHistograms();
       
       //....................................................................
       // Access MC information in stack if requested, check that it exists.
       Int_t label =ph->GetLabel();
-      if(label < 0) {
+      
+      if(label < 0) 
+      {
         if(GetDebug() > 1) printf("AliAnaPhoton::MakeAnalysisFillHistograms() *** bad label ***:  label %d \n", label);
         continue;
       }
       
       Float_t eprim   = 0;
       Float_t ptprim  = 0;
-      if(GetReader()->ReadStack()){
-        
-        if(label >=  stack->GetNtrack()) {
-          if(GetDebug() > 2)  printf("AliAnaPhoton::MakeAnalysisFillHistograms() *** large label ***:  label %d, n tracks %d \n", label, stack->GetNtrack());
-          continue ;
-        }
-        
-        primary = stack->Particle(label);
-        if(!primary){
-          printf("AliAnaPhoton::MakeAnalysisFillHistograms() *** no primary ***:  label %d \n", label);
-          continue;
-        }
-        eprim   = primary->Energy();
-        ptprim  = primary->Pt();               
-        
-      }
-      else if(GetReader()->ReadAODMCParticles()){
-        //Check which is the input
-        if(ph->GetInputFileIndex() == 0){
-          if(!mcparticles) continue;
-          if(label >=  mcparticles->GetEntriesFast()) {
-            if(GetDebug() > 2)  printf("AliAnaPhoton::MakeAnalysisFillHistograms() *** large label ***:  label %d, n tracks %d \n", 
-                                       label, mcparticles->GetEntriesFast());
-            continue ;
-          }
-          //Get the particle
-          aodprimary = (AliAODMCParticle*) mcparticles->At(label);
-          
-        }
-        
-        if(!aodprimary){
-          printf("AliAnaPhoton::MakeAnalysisFillHistograms() *** no primary ***:  label %d \n", label);
-          continue;
-        }
-        
-        eprim   = aodprimary->E();
-        ptprim  = aodprimary->Pt();
-        
+      Bool_t ok = kFALSE;
+      TLorentzVector primary = GetMCAnalysisUtils()->GetMother(label,GetReader(),ok);
+      if(ok)
+      {
+        eprim   = primary.Energy();
+        ptprim  = primary.Pt();                
       }
       
       Int_t tag =ph->GetTag();
-      
+      Int_t mcParticleTag = -1;
       if( GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPhoton) && fhMCE[kmcPhoton])
       {
         fhMCE  [kmcPhoton] ->Fill(ecluster);
@@ -2358,165 +3661,73 @@ void  AliAnaPhoton::MakeAnalysisFillHistograms()
         fhMCPhi[kmcPhoton] ->Fill(ecluster,phicluster);
         fhMCEta[kmcPhoton] ->Fill(ecluster,etacluster);
         
-        fhMC2E[kmcPhoton]     ->Fill(ecluster, eprim);
-        fhMC2Pt[kmcPhoton]    ->Fill(ptcluster, ptprim);     
-        fhMCDeltaE[kmcPhoton] ->Fill(ecluster,eprim-ecluster);
-        fhMCDeltaPt[kmcPhoton]->Fill(ptcluster,ptprim-ptcluster);     
+        fhMC2E     [kmcPhoton] ->Fill(ecluster, eprim);
+        fhMC2Pt    [kmcPhoton] ->Fill(ptcluster, ptprim);     
+        fhMCDeltaE [kmcPhoton] ->Fill(ecluster,eprim-ecluster);
+        fhMCDeltaPt[kmcPhoton] ->Fill(ptcluster,ptprim-ptcluster); 
         
-        if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCConversion) && fhMCE[kmcConversion])
+        if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCConversion) && 
+           GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPhoton)     &&
+           fhMCE[kmcConversion])
         {
           fhMCE  [kmcConversion] ->Fill(ecluster);
           fhMCPt [kmcConversion] ->Fill(ptcluster);
           fhMCPhi[kmcConversion] ->Fill(ecluster,phicluster);
           fhMCEta[kmcConversion] ->Fill(ecluster,etacluster);
           
-          fhMC2E[kmcConversion]     ->Fill(ecluster, eprim);
-          fhMC2Pt[kmcConversion]    ->Fill(ptcluster, ptprim);     
-          fhMCDeltaE[kmcConversion] ->Fill(ecluster,eprim-ecluster);
-          fhMCDeltaPt[kmcConversion]->Fill(ptcluster,ptprim-ptcluster);     
+          fhMC2E     [kmcConversion] ->Fill(ecluster, eprim);
+          fhMC2Pt    [kmcConversion] ->Fill(ptcluster, ptprim);     
+          fhMCDeltaE [kmcConversion] ->Fill(ecluster,eprim-ecluster);
+          fhMCDeltaPt[kmcConversion] ->Fill(ptcluster,ptprim-ptcluster); 
         }                      
         
-        if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPrompt) && fhMCE[kmcPrompt]){
-          fhMCE  [kmcPrompt] ->Fill(ecluster);
-          fhMCPt [kmcPrompt] ->Fill(ptcluster);
-          fhMCPhi[kmcPrompt] ->Fill(ecluster,phicluster);
-          fhMCEta[kmcPrompt] ->Fill(ecluster,etacluster);      
-          
-          fhMC2E[kmcPrompt]     ->Fill(ecluster, eprim);
-          fhMC2Pt[kmcPrompt]    ->Fill(ptcluster, ptprim);     
-          fhMCDeltaE[kmcPrompt] ->Fill(ecluster,eprim-ecluster);
-          fhMCDeltaPt[kmcPrompt]->Fill(ptcluster,ptprim-ptcluster);     
-          
+        if     (GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPrompt) && fhMCE[kmcPrompt])
+        {
+          mcParticleTag = kmcPrompt;
         }
         else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCFragmentation)&& fhMCE[kmcFragmentation])
         {
-          fhMCE  [kmcFragmentation] ->Fill(ecluster);
-          fhMCPt [kmcFragmentation] ->Fill(ptcluster);
-          fhMCPhi[kmcFragmentation] ->Fill(ecluster,phicluster);
-          fhMCEta[kmcFragmentation] ->Fill(ecluster,etacluster);
-          
-          fhMC2E[kmcFragmentation]     ->Fill(ecluster, eprim);
-          fhMC2Pt[kmcFragmentation]    ->Fill(ptcluster, ptprim);     
-          fhMCDeltaE[kmcFragmentation] ->Fill(ecluster,eprim-ecluster);
-          fhMCDeltaPt[kmcFragmentation]->Fill(ptcluster,ptprim-ptcluster);     
-          
+          mcParticleTag = kmcFragmentation;
         }
         else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCISR)&& fhMCE[kmcISR])
         {
-          fhMCE  [kmcISR] ->Fill(ecluster);
-          fhMCPt [kmcISR] ->Fill(ptcluster);
-          fhMCPhi[kmcISR] ->Fill(ecluster,phicluster);
-          fhMCEta[kmcISR] ->Fill(ecluster,etacluster);    
-          
-          fhMC2E[kmcISR]     ->Fill(ecluster, eprim);
-          fhMC2Pt[kmcISR]    ->Fill(ptcluster, ptprim);     
-          fhMCDeltaE[kmcISR] ->Fill(ecluster,eprim-ecluster);
-          fhMCDeltaPt[kmcISR]->Fill(ptcluster,ptprim-ptcluster);     
-          
+          mcParticleTag = kmcISR; 
         }
         else if( GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0Decay) && 
                 !GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0) && fhMCE[kmcPi0Decay])
         {
-          fhMCE  [kmcPi0Decay] ->Fill(ecluster);
-          fhMCPt [kmcPi0Decay] ->Fill(ptcluster);
-          fhMCPhi[kmcPi0Decay] ->Fill(ecluster,phicluster);
-          fhMCEta[kmcPi0Decay] ->Fill(ecluster,etacluster);
-          
-          fhMC2E[kmcPi0Decay]     ->Fill(ecluster, eprim);
-          fhMC2Pt[kmcPi0Decay]    ->Fill(ptcluster, ptprim);     
-          fhMCDeltaE[kmcPi0Decay] ->Fill(ecluster,eprim-ecluster);
-          fhMCDeltaPt[kmcPi0Decay]->Fill(ptcluster,ptprim-ptcluster);     
-          
+          mcParticleTag = kmcPi0Decay;
         }
-        else if( (GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEtaDecay) || 
-                  GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCOtherDecay) ) && fhMCE[kmcOtherDecay])
+        else if((( GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEtaDecay) && 
+                  !GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEta)        ) || 
+                   GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCOtherDecay) ) && fhMCE[kmcOtherDecay])
         {
-          fhMCE  [kmcOtherDecay] ->Fill(ecluster);
-          fhMCPt [kmcOtherDecay] ->Fill(ptcluster);
-          fhMCPhi[kmcOtherDecay] ->Fill(ecluster,phicluster);
-          fhMCEta[kmcOtherDecay] ->Fill(ecluster,etacluster);
-          
-          fhMC2E[kmcOtherDecay]     ->Fill(ecluster, eprim);
-          fhMC2Pt[kmcOtherDecay]    ->Fill(ptcluster, ptprim);     
-          fhMCDeltaE[kmcOtherDecay] ->Fill(ecluster,eprim-ecluster);
-          fhMCDeltaPt[kmcOtherDecay]->Fill(ptcluster,ptprim-ptcluster);     
-          
+          mcParticleTag = kmcOtherDecay;
         }
-        else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0) && fhMCE  [kmcPi0])
+        else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCPi0) && fhMCE[kmcPi0])
         {
-          fhMCE  [kmcPi0] ->Fill(ecluster);
-          fhMCPt [kmcPi0] ->Fill(ptcluster);
-          fhMCPhi[kmcPi0] ->Fill(ecluster,phicluster);
-          fhMCEta[kmcPi0] ->Fill(ecluster,etacluster);
-          
-          fhMC2E[kmcPi0]     ->Fill(ecluster, eprim);
-          fhMC2Pt[kmcPi0]    ->Fill(ptcluster, ptprim);     
-          fhMCDeltaE[kmcPi0] ->Fill(ecluster,eprim-ecluster);
-          fhMCDeltaPt[kmcPi0]->Fill(ptcluster,ptprim-ptcluster);     
-          
+          mcParticleTag = kmcPi0;   
         } 
         else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCEta) && fhMCE[kmcEta])
         {
-          fhMCE  [kmcEta] ->Fill(ecluster);
-          fhMCPt [kmcEta] ->Fill(ptcluster);
-          fhMCPhi[kmcEta] ->Fill(ecluster,phicluster);
-          fhMCEta[kmcEta] ->Fill(ecluster,etacluster);
-          
-          fhMC2E[kmcEta]     ->Fill(ecluster, eprim);
-          fhMC2Pt[kmcEta]    ->Fill(ptcluster, ptprim);     
-          fhMCDeltaE[kmcEta] ->Fill(ecluster,eprim-ecluster);
-          fhMCDeltaPt[kmcEta]->Fill(ptcluster,ptprim-ptcluster);     
-          
+          mcParticleTag = kmcEta;
         }      
       }
       else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCAntiNeutron) && fhMCE[kmcAntiNeutron])
       {
-        fhMCE  [kmcAntiNeutron] ->Fill(ecluster);
-        fhMCPt [kmcAntiNeutron] ->Fill(ptcluster);
-        fhMCPhi[kmcAntiNeutron] ->Fill(ecluster,phicluster);
-        fhMCEta[kmcAntiNeutron] ->Fill(ecluster,etacluster);
-        
-        fhMC2E[kmcAntiNeutron]     ->Fill(ecluster, eprim);
-        fhMC2Pt[kmcAntiNeutron]    ->Fill(ptcluster, ptprim);     
-        fhMCDeltaE[kmcAntiNeutron] ->Fill(ecluster,eprim-ecluster);
-        fhMCDeltaPt[kmcAntiNeutron]->Fill(ptcluster,ptprim-ptcluster);     
-        
+        mcParticleTag = kmcAntiNeutron;
       }
       else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCAntiProton) && fhMCE[kmcAntiProton])
       {
-        fhMCE  [kmcAntiProton] ->Fill(ecluster);
-        fhMCPt [kmcAntiProton] ->Fill(ptcluster);
-        fhMCPhi[kmcAntiProton] ->Fill(ecluster,phicluster);
-        fhMCEta[kmcAntiProton] ->Fill(ecluster,etacluster);
-        
-        fhMC2E[kmcAntiProton]     ->Fill(ecluster, eprim);
-        fhMC2Pt[kmcAntiProton]    ->Fill(ptcluster, ptprim);     
-        fhMCDeltaE[kmcAntiProton] ->Fill(ecluster,eprim-ecluster);
-        fhMCDeltaPt[kmcAntiProton]->Fill(ecluster,ptprim-ptcluster);     
-        
+        mcParticleTag = kmcAntiProton; 
       } 
       else if(GetMCAnalysisUtils()->CheckTagBit(tag,AliMCAnalysisUtils::kMCElectron) && fhMCE[kmcElectron])
       {
-        fhMCE  [kmcElectron] ->Fill(ecluster);
-        fhMCPt [kmcElectron] ->Fill(ptcluster);
-        fhMCPhi[kmcElectron] ->Fill(ecluster,phicluster);
-        fhMCEta[kmcElectron] ->Fill(ecluster,etacluster);
-        
-        fhMC2E[kmcElectron]     ->Fill(ecluster, eprim);
-        fhMC2Pt[kmcElectron]    ->Fill(ptcluster, ptprim);     
-        fhMCDeltaE[kmcElectron] ->Fill(ecluster,eprim-ecluster);
-        fhMCDeltaPt[kmcElectron]->Fill(ecluster,ptprim-ptcluster);             
+        mcParticleTag = kmcElectron;            
       }     
-      else if( fhMCE[kmcOther]){
-        fhMCE  [kmcOther] ->Fill(ecluster);
-        fhMCPt [kmcOther] ->Fill(ptcluster);
-        fhMCPhi[kmcOther] ->Fill(ecluster,phicluster);
-        fhMCEta[kmcOther] ->Fill(ecluster,etacluster);
-        
-        fhMC2E[kmcOther]     ->Fill(ecluster, eprim);
-        fhMC2Pt[kmcOther]    ->Fill(ptcluster, ptprim);     
-        fhMCDeltaE[kmcOther] ->Fill(ecluster,eprim-ecluster);
-        fhMCDeltaPt[kmcOther]->Fill(ecluster,ptprim-ptcluster);     
+      else if( fhMCE[kmcOther])
+      {
+        mcParticleTag = kmcOther;
         
         //              printf(" AliAnaPhoton::MakeAnalysisFillHistograms() - Label %d, pT %2.3f Unknown, bits set: ",
         //                                     ph->GetLabel(),ph->Pt());
@@ -2527,6 +3738,16 @@ void  AliAnaPhoton::MakeAnalysisFillHistograms()
         
       }
       
+      fhMCE  [mcParticleTag] ->Fill(ecluster);
+      fhMCPt [mcParticleTag] ->Fill(ptcluster);
+      fhMCPhi[mcParticleTag] ->Fill(ecluster,phicluster);
+      fhMCEta[mcParticleTag] ->Fill(ecluster,etacluster);
+      
+      fhMC2E[mcParticleTag]     ->Fill(ecluster, eprim);
+      fhMC2Pt[mcParticleTag]    ->Fill(ptcluster, ptprim);     
+      fhMCDeltaE[mcParticleTag] ->Fill(ecluster,eprim-ecluster);
+      fhMCDeltaPt[mcParticleTag]->Fill(ptcluster,ptprim-ptcluster); 
+      
     }//Histograms with MC
     
   }// aod loop