]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGGA/PHOSTasks/PHOS_PbPb/AliAnalysisTaskPi0Flow.cxx
Fix: add enable/disable module to streamer.
[u/mrichter/AliRoot.git] / PWGGA / PHOSTasks / PHOS_PbPb / AliAnalysisTaskPi0Flow.cxx
index 4627a492fa57d95d6d99dc7439ce4317d0daa908..e6b1b2fb76ab6d2e88ad3445ae2a9092642d585a 100644 (file)
@@ -53,7 +53,7 @@
 #include "AliEventplane.h"
 #include "TProfile.h"
 #include "AliOADBContainer.h"
-#include "AliPHOSEPFlattener.h"
+#include "AliEPFlattener.h"
 
 // Analysis task to fill histograms with PHOS ESD or AOD clusters and cells
 // Authors : Dmitri Peressounko
@@ -81,6 +81,7 @@ AliAnalysisTaskPi0Flow::AliAnalysisTaskPi0Flow(const char *name, Period period)
   fCentNMixed(10),
   fNEMRPBins(9),
   fPeriod(period),
+  fMaxAbsVertexZ(10.),
   fManualV0EPCalc(false),
   fOutputContainer(0x0),
   fNonLinCorr(0),
@@ -113,10 +114,14 @@ AliAnalysisTaskPi0Flow::AliAnalysisTaskPi0Flow(const char *name, Period period)
 {
   const int nbins = 9;
   Double_t edges[nbins+1] = {0., 5., 10., 20., 30., 40., 50., 60., 70., 80.};
-  fCentEdges = TArrayD(nbins+1, edges);
+  TArrayD centEdges(nbins+1, edges);
   Int_t nMixed[nbins] = {4,4,6,10,20,30,50,100,100};
-  fCentNMixed = TArrayI(nbins, nMixed);
+  TArrayI centNMixed(nbins, nMixed);
+  SetCentralityBinning(centEdges, centNMixed);
   
+  for(int mod=1; mod <= kNMod; ++mod)
+    fModuleEnabled[mod-1] = kTRUE;
+
   for(Int_t i=0;i<kNCenBins;i++){
     for(Int_t j=0;j<2; j++)
       for(Int_t k=0; k<2; k++) {
@@ -244,8 +249,8 @@ void AliAnalysisTaskPi0Flow::UserCreateOutputObjects()
 
 
   //Single photon and pi0 spectrum
-  const Int_t nPtPhot = 300 ;
-  const Double_t ptPhotMax = 30 ;
+  const Int_t nPtPhot = 400 ;
+  const Double_t ptPhotMax = 40 ;
   const Int_t nM       = 500;
   const Double_t mMin  = 0.0;
   const Double_t mMax  = 1.0;
@@ -259,58 +264,61 @@ void AliAnalysisTaskPi0Flow::UserCreateOutputObjects()
   fOutputContainer->Add(new TH2F("hPi0M33","Pairs in modules",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
 
   // Histograms for different centralities
-  char key[55] ;
-  for(Int_t cent=0; cent < fCentEdges.GetSize(); cent++){
-    snprintf(key,55,"hPhotAll_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"All clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotAllcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"All clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotAllwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"All clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotDisp_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"Disp clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotDisp2_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"Disp clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotDispcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"Disp clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotDispwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"Disp clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotCPV_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"CPV clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotCPVcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"CPV clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotCPV2_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"CPV clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotBoth_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"Both clusters",nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPhotBothcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH1F(key,"Both clusters",nPtPhot,0.,ptPhotMax));
-
-    snprintf(key,55,"hPi0All_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0Allcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0Allwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0Disp_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0Disp2_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0Dispcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0Dispwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0CPV_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0CPVcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0CPV2_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0Both_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hPi0Bothcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-
+  const int kNPID = 16;
+  const char* pidNames[kNPID] = {"All", "Allcore", "Allwou", "Disp", "Disp2", "Dispcore",  "Disp2core", "Dispwou", "CPV", "CPVcore", "CPV2", "CPV2core", "Both", "Bothcore", "Both2", "Both2core"};
+  char key[55];
+  TString name, title;
+  for(Int_t cent=0; cent < fCentEdges.GetSize()-1; cent++){
+    for(Int_t ipid=0; ipid < kNPID; ipid++){
+      name = Form("hPhot%s_cen%i", pidNames[ipid], cent );
+      title = Form("%s clusters", pidNames[ipid]);
+      fOutputContainer->Add(new TH1F(name.Data(), title.Data(), nPtPhot,0.,ptPhotMax));
+
+      name = Form("hPi0%s_cen%i", pidNames[ipid], cent );
+      title = Form("%s clusters", pidNames[ipid]);
+      fOutputContainer->Add(new TH2F(name.Data(), title.Data(), nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
+
+      name = Form("hSingle%s_cen%i", pidNames[ipid], cent );
+      title = Form("%s clusters", pidNames[ipid]);
+      fOutputContainer->Add(new TH2F(name.Data(), title.Data(), nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
+
+      name = Form("hMiPi0%s_cen%i", pidNames[ipid], cent );
+      title = Form("%s clusters", pidNames[ipid]);
+      fOutputContainer->Add(new TH2F(name.Data(), title.Data(), nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
+
+      name = Form("hMiSingle%s_cen%i", pidNames[ipid], cent );
+      title = Form("%s clusters", pidNames[ipid]);
+      fOutputContainer->Add(new TH2F(name.Data(), title.Data(), nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
+
+      // PhotPhi histograms
+      const Int_t nPt      = 20;
+      const Double_t xPt[21]={0.6,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.,5.5,6.,7.,8.,9.,10.,12.,14.,16.,18.,20.} ;
+      const Int_t nPhi=10 ;
+      Double_t xPhi[nPhi+1] ;
+      for(Int_t i=0;i<=nPhi;i++)
+       xPhi[i]=i*TMath::Pi() /nPhi ;
+      const Int_t nMm=200 ;
+      Double_t xM[nMm+1] ;
+      for(Int_t i=0;i<=nMm;i++)
+       xM[i]=i*0.5 /nMm;
+      const Int_t kNPhiTitles = 3;
+      const char* phiTitles[kNPhiTitles] = {"TPC", "V0A", "V0C"};
+      for(Int_t iRP=0; iRP<3; iRP++){
+       name = Form("hPhotPhi%s%s_cen%i", phiTitles[iRP], pidNames[ipid], cent );
+       title = Form("(M,p_{T},d#phi)_{#gamma#gamma}");
+       fOutputContainer->Add(new TH2F(name.Data(), title.Data(), nPt,xPt,nPhi,xPhi));
+    
+       name = Form("hMassPt%s%s_cen%i", phiTitles[iRP], pidNames[ipid], cent );
+       title = Form("(M,p_{T},d#phi)_{#gamma#gamma}");
+       fOutputContainer->Add(new TH3F(name.Data(), title.Data(), nMm,xM,nPt,xPt,nPhi,xPhi));
+    
+       name = Form("hMiMassPt%s%s_cen%i", phiTitles[iRP], pidNames[ipid], cent );
+       title = Form("(M,p_{T},d#phi)_{#gamma#gamma}");
+       fOutputContainer->Add(new TH3F(name.Data(), title.Data(), nMm,xM,nPt,xPt,nPhi,xPhi));
+      }
+    }
+    
+    // a07 histograms
     snprintf(key,55,"hPi0All_a07_cen%d",cent) ;
     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
     snprintf(key,55,"hPi0Disp_a07_cen%d",cent) ;
@@ -322,57 +330,6 @@ void AliAnalysisTaskPi0Flow::UserCreateOutputObjects()
     snprintf(key,55,"hPi0Both_a07_cen%d",cent) ;
     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
 
-    snprintf(key,55,"hSingleAll_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleAllcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleAllwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleDisp_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleDisp2_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleDispcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleDispwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleCPV_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleCPVcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleCPV2_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleBoth_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hSingleBothcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-
-
-    snprintf(key,55,"hMiPi0All_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0Allcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0Allwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0Disp_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0Disp2_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0Dispwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0Dispcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0CPV_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0CPVcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0CPV2_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0Both_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiPi0Bothcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-
     snprintf(key,55,"hMiPi0All_a07_cen%d",cent) ;
     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
     snprintf(key,55,"hMiPi0Disp_a07_cen%d",cent) ;
@@ -383,108 +340,6 @@ void AliAnalysisTaskPi0Flow::UserCreateOutputObjects()
     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
     snprintf(key,55,"hMiPi0Both_a07_cen%d",cent) ;
     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-
-    snprintf(key,55,"hMiSingleAll_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleAllwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleAllcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleDisp_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleDisp2_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleDispwou_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleDispcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleCPV_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleCPVcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleCPV2_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleBoth_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-    snprintf(key,55,"hMiSingleBothcore_cen%d",cent) ;
-    fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
-  }
-
-
-
-  const Int_t nPt      = 20;
-  const Double_t xPt[21]={0.6,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.,5.5,6.,7.,8.,9.,10.,12.,14.,16.,18.,20.} ;
-  const Int_t nPhi=10 ;
-  Double_t xPhi[nPhi+1] ;
-  for(Int_t i=0;i<=nPhi;i++)
-    xPhi[i]=i*TMath::Pi() /nPhi ;
-  const Int_t nMm=200 ;
-  Double_t xM[nMm+1] ;
-  for(Int_t i=0;i<=nMm;i++)
-    xM[i]=i*0.5 /nMm;
-
-  char phiTitle[15] ;
-  for(Int_t iRP=0; iRP<3; iRP++){
-    if(iRP==0)
-      snprintf(phiTitle,15,"TPC") ;
-    if(iRP==1)
-      snprintf(phiTitle,15,"V0A") ;
-    if(iRP==2)
-      snprintf(phiTitle,15,"V0C") ;
-    for(Int_t cent=0; cent<fCentEdges.GetSize(); cent++){
-      snprintf(key,55,"hPhotPhi%sAll_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hPhotPhi%sAllcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hPhotPhi%sDisp_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hPhotPhi%sDispcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hPhotPhi%sCPV_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hPhotPhi%sCPVcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hPhotPhi%sBoth_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hPhotPhi%sBothcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
-
-      //Pions
-      snprintf(key,55,"hMassPt%sAll_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMassPt%sAllcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMassPt%sCPV_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMassPt%sCPVcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMassPt%sDisp_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMassPt%sDispcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMassPt%sBoth_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMassPt%sBothcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-
-      //Mixed
-      snprintf(key,55,"hMiMassPt%sAll_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMiMassPt%sAllcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMiMassPt%sCPV_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMiMassPt%sCPVcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMiMassPt%sDisp_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMiMassPt%sDispcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMiMassPt%sBoth_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-      snprintf(key,55,"hMiMassPt%sBothcore_cen%d",phiTitle,cent) ;
-      fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
-    }
   }
   
   // Setup photon lists
@@ -581,6 +436,12 @@ void AliAnalysisTaskPi0Flow::UserExec(Option_t *)
   FillSelectedClusterHistograms();
   LogProgress(8);
 
+  if( ! fCaloPhotonsPHOS->GetEntriesFast() )
+    return;
+  else
+    LogSelection(6, fInternalRunNumber);
+
+
   // Step 9: Consider pi0 (photon/cluster) pairs.
   ConsiderPi0s();
   LogProgress(9);
@@ -608,29 +469,29 @@ void AliAnalysisTaskPi0Flow::UserExec(Option_t *)
 //   // hTotSelEvents->Draw();
 // }
 //________________________________________________________________________
-void AliAnalysisTaskPi0Flow::SetCentralityBinning(const TArrayD& edges)
+void AliAnalysisTaskPi0Flow::SetCentralityBinning(const TArrayD& edges, const TArrayI& nMixed)
 {
   // Define centrality bins by their edges
-
-  int last = edges.GetSize()-1;
-  if( edges.At(0) < 0.) 
-    AliError("lower edge less then 0");
-  if( 90. < edges.At(last)  )
-    AliError("upper edge larger then 90.");
-  for(int i=0; i<last-1; ++i)
-    if(edges.At(i) > edges.At(i+1))
-      AliError("edges are not sorted");
+  if( edges.At(0) < 0.) AliFatal("lower edge less then 0");
+  if( 90. < edges.At(edges.GetSize()-1)  ) AliFatal("upper edge larger then 90.");
+  for(int i=0; i<edges.GetSize()-1; ++i)
+    if(edges.At(i) > edges.At(i+1)) AliFatal("edges are not sorted");
+  if( edges.GetSize() != nMixed.GetSize()+1) AliFatal("edges and nMixed don't have appropriate relative sizes");
   
   fCentEdges = edges;
+  fCentNMixed = nMixed;
 }
-//________________________________________________________________________
-void AliAnalysisTaskPi0Flow::SetNMixedPerCentrality(const TArrayI& nMixed)
-{
-  // Set number of mixed events for all centrality bins
 
-  fCentNMixed = nMixed;
+//_____________________________________________________________________________
+void AliAnalysisTaskPi0Flow::SetEnablePHOSModule(int module, Bool_t enable)
+{
+  if( module < 1 || kNMod < module )
+    AliFatal(Form("PHOS Module must be between 1 and %i", kNMod));
+  else
+    fModuleEnabled[module-1] = enable;
 }
 
+
 //________________________________________________________________________
 void AliAnalysisTaskPi0Flow::SetPHOSBadMap(Int_t mod, TH2I* badMapHist)
   {
@@ -714,6 +575,7 @@ void AliAnalysisTaskPi0Flow::FillPHOSCellQAHists()
       FillHistogram("hCellEXZM3",cellX,cellZ,energy);
     }
   }
+  FillHistogram("hCellMultEvent",nCellModule[0]+nCellModule[1]+nCellModule[2]);
   FillHistogram("hCellMultEventM1",nCellModule[0]);
   FillHistogram("hCellMultEventM2",nCellModule[1]);
   FillHistogram("hCellMultEventM3",nCellModule[2]);
@@ -737,6 +599,8 @@ void AliAnalysisTaskPi0Flow::SelectPhotonClusters()
 
     if ( !clu->IsPHOS() || clu->E()< kMinClusterEnergy) continue; // reject cluster
 
+
+
     // check if cell/channel is good.
     Float_t  position[3];
     clu->GetPosition(position);
@@ -746,10 +610,15 @@ void AliAnalysisTaskPi0Flow::SelectPhotonClusters()
     Int_t mod  = relId[0] ;
     Int_t cellX = relId[2];
     Int_t cellZ = relId[3] ;
+    if ( ! fModuleEnabled[mod-1] )
+      continue;
     if ( !IsGoodChannel("PHOS",mod,cellX,cellZ) )
       continue ; // reject if not.
 
-
+    Double_t distBC=clu->GetDistanceToBadChannel();
+    if(distBC<kMinBCDistance)
+      continue ;
+      
     FillHistogram("hCluEvsClu", clu->E(), clu->GetNCells()) ;
 
     if(clu->GetNCells() < kMinNCells) continue ;
@@ -763,7 +632,7 @@ void AliAnalysisTaskPi0Flow::SelectPhotonClusters()
     Double_t origo[3] = {0,0,0}; // don't rely on event vertex, assume (0,0,0)
     if( fEventESD ) {
       AliPHOSEsdCluster cluPHOS1( *(AliESDCaloCluster*) (clu) );
-      cluPHOS1.Recalibrate(fPHOSCalibData, dynamic_cast<AliESDCaloCells*> (cells)); // modify the cell energies
+      cluPHOS1.Recalibrate(fPHOSCalibData, static_cast<AliESDCaloCells*> (cells)); // modify the cell energies
       Reclusterize(&cluPHOS1) ;
       cluPHOS1.EvalAll(kLogWeight, fVertexVector);         // recalculate the cluster parameters
       cluPHOS1.SetE(fNonLinCorr->Eval(cluPHOS1.E()));// Users's nonlinearity
@@ -800,12 +669,9 @@ void AliAnalysisTaskPi0Flow::SelectPhotonClusters()
     }
 
 
-    char skey[55];
-    snprintf(skey,55,"hCluLowM%d",mod) ;
-    FillHistogram(skey,cellX,cellZ,1.);
+    FillHistogram(Form("hCluLowM%d",mod),cellX,cellZ,1.);
     if(lorentzMomentum.E()>1.5){
-      sprintf(skey,"hCluHighM%d",mod) ;
-      FillHistogram(skey,cellX,cellZ,1.);
+      FillHistogram(Form("hCluHighM%d",mod),cellX,cellZ,1.);
     }
 
     fCaloPhotonsPHOS->Add(new  AliCaloPhoton(lorentzMomentum.X(),lorentzMomentum.Py(),lorentzMomentum.Z(),lorentzMomentum.E()) );
@@ -816,16 +682,19 @@ void AliAnalysisTaskPi0Flow::SelectPhotonClusters()
     ph->SetMomV2(&lorentzMomentum) ;
     ph->SetNCells(clu->GetNCells());
     ph->SetDispBit(TestLambda(clu->E(),clu->GetM20(),clu->GetM02())) ;
-    ph->SetDisp2Bit(TestLambda2(clu->E(),clu->GetM20(),clu->GetM02())) ;
+    //Evaluate CoreDispersion
+    Double_t m02=0.,m20=0. ;
+    EvalCoreLambdas(clu, cells, m02, m20) ;
+    ph->SetDisp2Bit(TestCoreLambda(clu->E(),m20,m02)) ; //Correct order m20,m02
+//    ph->SetDisp2Bit(TestCoreLambda(clu->E(),clu->GetM20(),clu->GetM02())) ;
     if(ph->IsDispOK()){
-      sprintf(skey,"hCluDispM%d",mod) ;
-      FillHistogram(skey,cellX,cellZ,1.);
+      FillHistogram(Form("hCluDispM%d",mod),cellX,cellZ,1.);
     }
 
     // Track Matching
     Double_t dx=clu->GetTrackDx() ;
     Double_t dz=clu->GetTrackDz() ;
-    Bool_t cpvBit=kTRUE ; //No track matched by default
+    Bool_t cpvBit=kTRUE ; //No track matched by default. True means: not from charged, according to veto.
     Bool_t cpvBit2=kTRUE ; //More Strict criterion
     if( fEventESD ) {
       
@@ -858,8 +727,7 @@ void AliAnalysisTaskPi0Flow::SelectPhotonClusters()
     ph->SetCPVBit(cpvBit) ;
     ph->SetCPV2Bit(cpvBit2) ;
     if(cpvBit){
-      sprintf(skey,"hCluVetoM%d",mod) ;
-      FillHistogram(skey,cellX,cellZ,1.);
+      FillHistogram(Form("hCluVetoM%d",mod),cellX,cellZ,1.);
     }
     ph->SetEMCx(float(cellX)) ;
     ph->SetEMCz(float(cellZ)) ;
@@ -886,66 +754,118 @@ void AliAnalysisTaskPi0Flow::FillSelectedClusterHistograms()
     Double_t dphiT=ph1->Phi()-fRP ;
     while(dphiT<0)dphiT+=TMath::Pi() ;
     while(dphiT>TMath::Pi())dphiT-=TMath::Pi() ;
+    
+    Double_t pt = ph1->Pt() ;
+    Double_t ptcore = ph1->GetMomV2()->Pt() ;
 
-    FillHistogram(Form("hPhotPhiV0AAll_cen%d",fCentBin),ph1->Pt(),dphiA) ;
-    FillHistogram(Form("hPhotPhiV0CAll_cen%d",fCentBin),ph1->Pt(),dphiC) ;
+    FillHistogram(Form("hPhotPhiV0AAll_cen%d",fCentBin),pt,dphiA) ;
+    FillHistogram(Form("hPhotPhiV0CAll_cen%d",fCentBin),pt,dphiC) ;
+    if(fHaveTPCRP)
+      FillHistogram(Form("hPhotPhiTPCAll_cen%d",fCentBin),pt,dphiT) ;
+    FillHistogram(Form("hPhotPhiV0AAllcore_cen%d",fCentBin),ptcore,dphiA) ;
+    FillHistogram(Form("hPhotPhiV0CAllcore_cen%d",fCentBin),ptcore,dphiC) ;
     if(fHaveTPCRP)
-      FillHistogram(Form("hPhotPhiTPCAll_cen%d",fCentBin),ph1->Pt(),dphiT) ;
+      FillHistogram(Form("hPhotPhiTPCAllcore_cen%d",fCentBin),ptcore,dphiT) ;
 
-    FillHistogram(Form("hPhotAll_cen%d",fCentBin),ph1->Pt()) ;
-    FillHistogram(Form("hPhotAllcore_cen%d",fCentBin),ph1->GetMomV2()->Pt()) ;
+    FillHistogram(Form("hPhotAll_cen%d",fCentBin),pt) ;
+    FillHistogram(Form("hPhotAllcore_cen%d",fCentBin),ptcore) ;
     if(ph1->IsntUnfolded()){
-      FillHistogram(Form("hPhotAllwou_cen%d",fCentBin),ph1->Pt()) ;
+      FillHistogram(Form("hPhotAllwou_cen%d",fCentBin),pt) ;
+      FillHistogram(Form("hPhotPhiV0AAllwou_cen%d",fCentBin),pt,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CAllwou_cen%d",fCentBin),pt,dphiC) ;
+      if(fHaveTPCRP)
+        FillHistogram(Form("hPhotPhiTPCAllwou_cen%d",fCentBin),pt,dphiT) ;
     }
     if(ph1->IsCPVOK()){
-      FillHistogram(Form("hPhotPhiV0ACPV_cen%d",fCentBin),ph1->Pt(),dphiA) ;
-      FillHistogram(Form("hPhotPhiV0CCPV_cen%d",fCentBin),ph1->Pt(),dphiC) ;
+      FillHistogram(Form("hPhotPhiV0ACPV_cen%d",fCentBin),pt,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CCPV_cen%d",fCentBin),pt,dphiC) ;
       if(fHaveTPCRP)
-        FillHistogram(Form("hPhotPhiTPCCPV_cen%d",fCentBin),ph1->Pt(),dphiT) ;
+        FillHistogram(Form("hPhotPhiTPCCPV_cen%d",fCentBin),pt,dphiT) ;
 
-      FillHistogram(Form("hPhotPhiV0ACPVcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiA) ;
-      FillHistogram(Form("hPhotPhiV0CCPVcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiC) ;
+      FillHistogram(Form("hPhotPhiV0ACPVcore_cen%d",fCentBin),ptcore,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CCPVcore_cen%d",fCentBin),ptcore,dphiC) ;
       if(fHaveTPCRP)
-        FillHistogram(Form("hPhotPhiTPCCPVcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiT) ;
+        FillHistogram(Form("hPhotPhiTPCCPVcore_cen%d",fCentBin),ptcore,dphiT) ;
 
-      FillHistogram(Form("hPhotCPV_cen%d",fCentBin),ph1->Pt()) ;
-      FillHistogram(Form("hPhotCPVcore_cen%d",fCentBin),ph1->GetMomV2()->Pt()) ;
+      FillHistogram(Form("hPhotCPV_cen%d",fCentBin),pt) ;
+      FillHistogram(Form("hPhotCPVcore_cen%d",fCentBin),ptcore) ;
     }
     if(ph1->IsCPV2OK()){
-      FillHistogram(Form("hPhotCPV2_cen%d",fCentBin),ph1->Pt()) ;
+      FillHistogram(Form("hPhotPhiV0ACPV2_cen%d",fCentBin),pt,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CCPV2_cen%d",fCentBin),pt,dphiC) ;
+      if(fHaveTPCRP)
+        FillHistogram(Form("hPhotPhiTPCCPV2_cen%d",fCentBin),pt,dphiT) ;
+
+      FillHistogram(Form("hPhotPhiV0ACPV2core_cen%d",fCentBin),ptcore,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CCPV2core_cen%d",fCentBin),ptcore,dphiC) ;
+      if(fHaveTPCRP)
+        FillHistogram(Form("hPhotPhiTPCCPV2core_cen%d",fCentBin),ptcore,dphiT) ;
+      FillHistogram(Form("hPhotCPV2_cen%d",fCentBin),pt) ;
+      FillHistogram(Form("hPhotCPV2core_cen%d",fCentBin),ptcore) ;
     }
     if(ph1->IsDispOK()){
-      FillHistogram(Form("hPhotPhiV0ADisp_cen%d",fCentBin),ph1->Pt(),dphiA) ;
-      FillHistogram(Form("hPhotPhiV0CDisp_cen%d",fCentBin),ph1->Pt(),dphiC) ;
+      FillHistogram(Form("hPhotPhiV0ADisp_cen%d",fCentBin),pt,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CDisp_cen%d",fCentBin),pt,dphiC) ;
       if(fHaveTPCRP)
-        FillHistogram(Form("hPhotPhiTPCDisp_cen%d",fCentBin),ph1->Pt(),dphiT) ;
+        FillHistogram(Form("hPhotPhiTPCDisp_cen%d",fCentBin),pt,dphiT) ;
 
-      FillHistogram(Form("hPhotPhiV0ADispcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiA) ;
-      FillHistogram(Form("hPhotPhiV0CDispcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiC) ;
+      FillHistogram(Form("hPhotPhiV0ADispcore_cen%d",fCentBin),ptcore,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CDispcore_cen%d",fCentBin),ptcore,dphiC) ;
       if(fHaveTPCRP)
-        FillHistogram(Form("hPhotPhiTPCDispcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiT) ;
+        FillHistogram(Form("hPhotPhiTPCDispcore_cen%d",fCentBin),ptcore,dphiT) ;
+
+      if(ph1->IsntUnfolded()){
+        FillHistogram(Form("hPhotPhiV0ADispwou_cen%d",fCentBin),pt,dphiA) ;
+        FillHistogram(Form("hPhotPhiV0CDispwou_cen%d",fCentBin),pt,dphiC) ;
+        if(fHaveTPCRP)
+          FillHistogram(Form("hPhotPhiTPCDispwou_cen%d",fCentBin),pt,dphiT) ;
 
-      FillHistogram(Form("hPhotDisp_cen%d",fCentBin),ph1->Pt()) ;
-      if(ph1->IsDisp2OK()){
-        FillHistogram(Form("hPhotDisp2_cen%d",fCentBin),ph1->Pt()) ;
       }
-      FillHistogram(Form("hPhotDispcore_cen%d",fCentBin),ph1->GetMomV2()->Pt()) ;
+      FillHistogram(Form("hPhotDisp_cen%d",fCentBin),pt) ;
+      FillHistogram(Form("hPhotDispcore_cen%d",fCentBin),ptcore) ;
       if(ph1->IsntUnfolded()){
-        FillHistogram(Form("hPhotDispwou_cen%d",fCentBin),ph1->Pt()) ;
+        FillHistogram(Form("hPhotDispwou_cen%d",fCentBin),pt) ;
       }
       if(ph1->IsCPVOK()){
-       FillHistogram(Form("hPhotPhiV0ABoth_cen%d",fCentBin),ph1->Pt(),dphiA) ;
-       FillHistogram(Form("hPhotPhiV0CBoth_cen%d",fCentBin),ph1->Pt(),dphiC) ;
+       FillHistogram(Form("hPhotPhiV0ABoth_cen%d",fCentBin),pt,dphiA) ;
+       FillHistogram(Form("hPhotPhiV0CBoth_cen%d",fCentBin),pt,dphiC) ;
         if(fHaveTPCRP)
-         FillHistogram(Form("hPhotPhiTPCBoth_cen%d",fCentBin),ph1->Pt(),dphiT) ;
+         FillHistogram(Form("hPhotPhiTPCBoth_cen%d",fCentBin),pt,dphiT) ;
 
-       FillHistogram(Form("hPhotPhiV0ABothcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiA) ;
-       FillHistogram(Form("hPhotPhiV0CBothcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiC) ;
+       FillHistogram(Form("hPhotPhiV0ABothcore_cen%d",fCentBin),ptcore,dphiA) ;
+       FillHistogram(Form("hPhotPhiV0CBothcore_cen%d",fCentBin),ptcore,dphiC) ;
         if(fHaveTPCRP)
-         FillHistogram(Form("hPhotPhiTPCBothcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiT) ;
+         FillHistogram(Form("hPhotPhiTPCBothcore_cen%d",fCentBin),ptcore,dphiT) ;
 
-       FillHistogram(Form("hPhotBoth_cen%d",fCentBin),ph1->Pt()) ;
-       FillHistogram(Form("hPhotBothcore_cen%d",fCentBin),ph1->GetMomV2()->Pt()) ;
+       FillHistogram(Form("hPhotBoth_cen%d",fCentBin),pt) ;
+       FillHistogram(Form("hPhotBothcore_cen%d",fCentBin),ptcore) ;
+      }
+    }
+    if(ph1->IsDisp2OK()){
+      FillHistogram(Form("hPhotPhiV0ADisp2_cen%d",fCentBin),pt,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CDisp2_cen%d",fCentBin),pt,dphiC) ;
+      if(fHaveTPCRP)
+        FillHistogram(Form("hPhotPhiTPCDisp2_cen%d",fCentBin),pt,dphiT) ;
+      FillHistogram(Form("hPhotPhiV0ADisp2core_cen%d",fCentBin),ptcore,dphiA) ;
+      FillHistogram(Form("hPhotPhiV0CDisp2core_cen%d",fCentBin),ptcore,dphiC) ;
+      if(fHaveTPCRP)
+        FillHistogram(Form("hPhotPhiTPCDisp2core_cen%d",fCentBin),ptcore,dphiT) ;
+
+      FillHistogram(Form("hPhotDisp2_cen%d",fCentBin),pt) ;
+      FillHistogram(Form("hPhotDisp2core_cen%d",fCentBin),ptcore) ;
+      if(ph1->IsCPVOK()){
+       FillHistogram(Form("hPhotPhiV0ABoth2_cen%d",fCentBin),pt,dphiA) ;
+       FillHistogram(Form("hPhotPhiV0CBoth2_cen%d",fCentBin),pt,dphiC) ;
+        if(fHaveTPCRP)
+         FillHistogram(Form("hPhotPhiTPCBoth2_cen%d",fCentBin),pt,dphiT) ;
+
+       FillHistogram(Form("hPhotPhiV0ABoth2core_cen%d",fCentBin),ptcore,dphiA) ;
+       FillHistogram(Form("hPhotPhiV0CBoth2core_cen%d",fCentBin),ptcore,dphiC) ;
+        if(fHaveTPCRP)
+         FillHistogram(Form("hPhotPhiTPCBoth2core_cen%d",fCentBin),ptcore,dphiT) ;
+
+       FillHistogram(Form("hPhotBoth2_cen%d",fCentBin),pt) ;
+       FillHistogram(Form("hPhotBoth2core_cen%d",fCentBin),ptcore) ;
       }
     }
   }
@@ -974,164 +894,231 @@ void AliAnalysisTaskPi0Flow::ConsiderPi0s()
       while(dphiT>TMath::Pi())dphiT-=TMath::Pi() ;
 
       Double_t a=TMath::Abs((ph1->E()-ph2->E())/(ph1->E()+ph2->E())) ;
-
-      FillHistogram(Form("hMassPtV0AAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
-      FillHistogram(Form("hMassPtV0CAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
+      Double_t m=p12.M() ;
+      Double_t mcore=pv12.M() ;
+      Double_t pt=p12.Pt() ;
+      Double_t ptcore=pv12.Pt() ;
+      Double_t pt1=ph1->Pt() ;
+      Double_t pt2=ph2->Pt() ;
+      Double_t ptcore1=ph1->GetMomV2()->Pt() ;
+      Double_t ptcore2=ph2->GetMomV2()->Pt() ;
+
+      FillHistogram(Form("hMassPtV0AAll_cen%d",fCentBin),m,pt,dphiA) ;
+      FillHistogram(Form("hMassPtV0CAll_cen%d",fCentBin),m,pt,dphiC) ;
       if(fHaveTPCRP)
-        FillHistogram(Form("hMassPtTPCAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
+        FillHistogram(Form("hMassPtTPCAll_cen%d",fCentBin),m,pt,dphiT) ;
 
-      FillHistogram(Form("hMassPtV0AAllcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiA) ;
-      FillHistogram(Form("hMassPtV0CAllcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiC) ;
+      FillHistogram(Form("hMassPtV0AAllcore_cen%d",fCentBin),mcore,ptcore,dphiA) ;
+      FillHistogram(Form("hMassPtV0CAllcore_cen%d",fCentBin),mcore,ptcore,dphiC) ;
       if(fHaveTPCRP)
-        FillHistogram(Form("hMassPtTPCAllcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiT) ;
+        FillHistogram(Form("hMassPtTPCAllcore_cen%d",fCentBin),mcore,ptcore,dphiT) ;
 
 
-      FillHistogram(Form("hPi0All_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
-      FillHistogram(Form("hPi0Allcore_cen%d",fCentBin),pv12.M() ,pv12.Pt()) ;
+      FillHistogram(Form("hPi0All_cen%d",fCentBin),m,pt) ;
+      FillHistogram(Form("hPi0Allcore_cen%d",fCentBin),mcore,ptcore) ;
       if(ph1->IsntUnfolded() && ph2->IsntUnfolded()){
-        FillHistogram(Form("hPi0Allwou_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+        FillHistogram(Form("hPi0Allwou_cen%d",fCentBin),m,pt) ;
+        FillHistogram(Form("hMassPtV0AAllwou_cen%d",fCentBin),m,pt,dphiA) ;
+        FillHistogram(Form("hMassPtV0CAllwou_cen%d",fCentBin),m,pt,dphiC) ;
+        if(fHaveTPCRP)
+          FillHistogram(Form("hMassPtTPCAllwou_cen%d",fCentBin),m,pt,dphiT) ;
       }
 
-      FillHistogram(Form("hSingleAll_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
-      FillHistogram(Form("hSingleAll_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
-      FillHistogram(Form("hSingleAllcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
-      FillHistogram(Form("hSingleAllcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
+      FillHistogram(Form("hSingleAll_cen%d",fCentBin),m,pt1) ;
+      FillHistogram(Form("hSingleAll_cen%d",fCentBin),m,pt2) ;
+      FillHistogram(Form("hSingleAllcore_cen%d",fCentBin),mcore,ptcore1) ;
+      FillHistogram(Form("hSingleAllcore_cen%d",fCentBin),mcore,ptcore2) ;
       if(ph1->IsntUnfolded())
-        FillHistogram(Form("hSingleAllwou_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+        FillHistogram(Form("hSingleAllwou_cen%d",fCentBin),m,pt1) ;
       if(ph2->IsntUnfolded())
-        FillHistogram(Form("hSingleAllwou_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+        FillHistogram(Form("hSingleAllwou_cen%d",fCentBin),m,pt2) ;
       if(ph1->IsCPVOK()){
-        FillHistogram(Form("hSingleCPV_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
-        FillHistogram(Form("hSingleCPVcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
+        FillHistogram(Form("hSingleCPV_cen%d",fCentBin),m,pt1) ;
+        FillHistogram(Form("hSingleCPVcore_cen%d",fCentBin),mcore,ptcore1) ;
       }
       if(ph2->IsCPVOK()){
-        FillHistogram(Form("hSingleCPV_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
-        FillHistogram(Form("hSingleCPV_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
+        FillHistogram(Form("hSingleCPV_cen%d",fCentBin),m,pt2) ;
+        FillHistogram(Form("hSingleCPVcore_cen%d",fCentBin),mcore,ptcore2) ;
       }
       if(ph1->IsCPV2OK()){
-        FillHistogram(Form("hSingleCPV2_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+        FillHistogram(Form("hSingleCPV2_cen%d",fCentBin),m,pt1) ;
+        FillHistogram(Form("hSingleCPV2core_cen%d",fCentBin),mcore,ptcore2) ;
       }
       if(ph2->IsCPV2OK()){
-        FillHistogram(Form("hSingleCPV2_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+        FillHistogram(Form("hSingleCPV2_cen%d",fCentBin),m,pt2) ;
+        FillHistogram(Form("hSingleCPV2core_cen%d",fCentBin),mcore,ptcore2) ;
       }
       if(ph1->IsDispOK()){
-        FillHistogram(Form("hSingleDisp_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+        FillHistogram(Form("hSingleDisp_cen%d",fCentBin),m,pt1) ;
         if(ph1->IsntUnfolded()){
-          FillHistogram(Form("hSingleDispwou_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+          FillHistogram(Form("hSingleDispwou_cen%d",fCentBin),m,pt1) ;
        }
-        FillHistogram(Form("hSingleDispcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
+        FillHistogram(Form("hSingleDispcore_cen%d",fCentBin),mcore,ptcore1) ;
       }
       if(ph2->IsDispOK()){
-        FillHistogram(Form("hSingleDisp_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+        FillHistogram(Form("hSingleDisp_cen%d",fCentBin),m,pt2) ;
         if(ph1->IsntUnfolded()){
-          FillHistogram(Form("hSingleDispwou_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+          FillHistogram(Form("hSingleDispwou_cen%d",fCentBin),m,pt2) ;
        }
-        FillHistogram(Form("hSingleDispcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
+        FillHistogram(Form("hSingleDispcore_cen%d",fCentBin),mcore,ptcore2) ;
       }
       if(ph1->IsDisp2OK()){
-        FillHistogram(Form("hSingleDisp2_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+        FillHistogram(Form("hSingleDisp2_cen%d",fCentBin),m,pt1) ;
+        FillHistogram(Form("hSingleDisp2core_cen%d",fCentBin),mcore,ptcore1) ;
       }
       if(ph2->IsDisp2OK()){
-        FillHistogram(Form("hSingleDisp2_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+        FillHistogram(Form("hSingleDisp2_cen%d",fCentBin),m,pt2) ;
+        FillHistogram(Form("hSingleDisp2core_cen%d",fCentBin),mcore,ptcore1) ;
       }
       if(ph1->IsDispOK() && ph1->IsCPVOK()){
-        FillHistogram(Form("hSingleBoth_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
-        FillHistogram(Form("hSingleBothcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
+        FillHistogram(Form("hSingleBoth_cen%d",fCentBin),m,pt1) ;
+        FillHistogram(Form("hSingleBothcore_cen%d",fCentBin),mcore,ptcore1) ;
       }
       if(ph2->IsDispOK() && ph2->IsCPVOK()){
-        FillHistogram(Form("hSingleBoth_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
-        FillHistogram(Form("hSingleBothcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
+        FillHistogram(Form("hSingleBoth_cen%d",fCentBin),m,pt2) ;
+        FillHistogram(Form("hSingleBothcore_cen%d",fCentBin),mcore,ptcore2) ;
+      }
+      if(ph1->IsDisp2OK() && ph1->IsCPVOK()){
+        FillHistogram(Form("hSingleBoth2_cen%d",fCentBin),m,pt1) ;
+        FillHistogram(Form("hSingleBoth2core_cen%d",fCentBin),mcore,ptcore1) ;
+      }
+      if(ph2->IsDisp2OK() && ph2->IsCPVOK()){
+        FillHistogram(Form("hSingleBoth2_cen%d",fCentBin),m,pt2) ;
+        FillHistogram(Form("hSingleBoth2core_cen%d",fCentBin),mcore,ptcore2) ;
       }
 
 
       if(a<kAlphaCut){
-        FillHistogram(Form("hPi0All_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+        FillHistogram(Form("hPi0All_a07_cen%d",fCentBin),m,pt) ;
       }
 
       if(ph1->IsCPVOK() && ph2->IsCPVOK()){
        snprintf(key,55,"hMassPtCPV_cen%d",fCentBin) ;
-       FillHistogram(Form("hMassPtV0ACPV_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
-       FillHistogram(Form("hMassPtV0CCPV_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
+       FillHistogram(Form("hMassPtV0ACPV_cen%d",fCentBin),m,pt,dphiA) ;
+       FillHistogram(Form("hMassPtV0CCPV_cen%d",fCentBin),m,pt,dphiC) ;
        if(fHaveTPCRP)
-         FillHistogram(Form("hMassPtTPCCPV_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
+         FillHistogram(Form("hMassPtTPCCPV_cen%d",fCentBin),m,pt,dphiT) ;
 
-       FillHistogram(Form("hMassPtV0ACPVcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiA) ;
-       FillHistogram(Form("hMassPtV0CCPVcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiC) ;
+       FillHistogram(Form("hMassPtV0ACPVcore_cen%d",fCentBin),mcore,ptcore,dphiA) ;
+       FillHistogram(Form("hMassPtV0CCPVcore_cen%d",fCentBin),mcore,ptcore,dphiC) ;
        if(fHaveTPCRP)
-         FillHistogram(Form("hMassPtTPCCPVcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiT) ;
+         FillHistogram(Form("hMassPtTPCCPVcore_cen%d",fCentBin),mcore,ptcore,dphiT) ;
 
-       FillHistogram(Form("hPi0CPV_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
-       FillHistogram(Form("hPi0CPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt()) ;
+       FillHistogram(Form("hPi0CPV_cen%d",fCentBin),m,pt) ;
+       FillHistogram(Form("hPi0CPVcore_cen%d",fCentBin),mcore, ptcore) ;
 
         if(a<kAlphaCut){
-          FillHistogram(Form("hPi0CPV_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+          FillHistogram(Form("hPi0CPV_a07_cen%d",fCentBin),m,pt) ;
         }
       }
       if(ph1->IsCPV2OK() && ph2->IsCPV2OK()){
-       FillHistogram(Form("hPi0CPV2_cen%d",fCentBin),p12.M(),p12.Pt()) ;
+       FillHistogram(Form("hMassPtV0ACPV2_cen%d",fCentBin),m,pt,dphiA) ;
+       FillHistogram(Form("hMassPtV0CCPV2_cen%d",fCentBin),m,pt,dphiC) ;
+       if(fHaveTPCRP)
+         FillHistogram(Form("hMassPtTPCCPV2_cen%d",fCentBin),m,pt,dphiT) ;
+       FillHistogram(Form("hMassPtV0ACPV2core_cen%d",fCentBin),mcore,ptcore,dphiA) ;
+       FillHistogram(Form("hMassPtV0CCPV2core_cen%d",fCentBin),mcore,ptcore,dphiC) ;
+       if(fHaveTPCRP)
+         FillHistogram(Form("hMassPtTPCCPV2core_cen%d",fCentBin),mcore,ptcore,dphiT) ;
+       
+       FillHistogram(Form("hPi0CPV2_cen%d",fCentBin),m,pt) ;
+       FillHistogram(Form("hPi0CPV2core_cen%d",fCentBin),mcore, ptcore) ;
         if(a<kAlphaCut){
-          FillHistogram(Form("hPi0CPV2_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+          FillHistogram(Form("hPi0CPV2_a07_cen%d",fCentBin),m,pt) ;
         }
       }
       if(ph1->IsDispOK() && ph2->IsDispOK()){
        snprintf(key,55,"hMassPtDisp_cen%d",fCentBin) ;
-       FillHistogram(Form("hMassPtV0ADisp_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
-       FillHistogram(Form("hMassPtV0CDisp_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
+       FillHistogram(Form("hMassPtV0ADisp_cen%d",fCentBin),m,pt,dphiA) ;
+       FillHistogram(Form("hMassPtV0CDisp_cen%d",fCentBin),m,pt,dphiC) ;
        if(fHaveTPCRP)
-         FillHistogram(Form("hMassPtTPCDisp_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
-
-       FillHistogram(Form("hMassPtV0ADispcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiA) ;
-       FillHistogram(Form("hMassPtV0CDispcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiC) ;
+         FillHistogram(Form("hMassPtTPCDisp_cen%d",fCentBin),m,pt,dphiT) ;
+       
+       FillHistogram(Form("hMassPtV0ADispcore_cen%d",fCentBin),mcore, ptcore,dphiA) ;
+       FillHistogram(Form("hMassPtV0CDispcore_cen%d",fCentBin),mcore, ptcore,dphiC) ;
        if(fHaveTPCRP)
-         FillHistogram(Form("hMassPtTPCDispcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiT) ;
+         FillHistogram(Form("hMassPtTPCDispcore_cen%d",fCentBin),mcore, ptcore,dphiT) ;
 
-       FillHistogram(Form("hPi0Disp_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
-       FillHistogram(Form("hPi0Dispcore_cen%d",fCentBin),pv12.M(), pv12.Pt()) ;
-        if(ph1->IsDisp2OK() && ph2->IsDisp2OK()){
-         FillHistogram(Form("hPi0Disp2_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
-       }
+       FillHistogram(Form("hPi0Disp_cen%d",fCentBin),m,pt) ;
+       FillHistogram(Form("hPi0Dispcore_cen%d",fCentBin),mcore, ptcore) ;
+       
        if(ph1->IsntUnfolded() && ph2->IsntUnfolded()){
-         FillHistogram(Form("hPi0Dispwou_cen%d",fCentBin),p12.M(), p12.Pt()) ;
+         FillHistogram(Form("hPi0Dispwou_cen%d",fCentBin),m,pt) ;
+
+         FillHistogram(Form("hMassPtV0ADispwou_cen%d",fCentBin),m,pt,dphiA) ;
+         FillHistogram(Form("hMassPtV0CDispwou_cen%d",fCentBin),m,pt,dphiC) ;
+         if(fHaveTPCRP)
+           FillHistogram(Form("hMassPtTPCDispwou_cen%d",fCentBin),m,pt,dphiT) ;
        }
 
         if(a<kAlphaCut){
-          FillHistogram(Form("hPi0Disp_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+          FillHistogram(Form("hPi0Disp_a07_cen%d",fCentBin),m,pt) ;
         }
-
        if(ph1->IsCPVOK() && ph2->IsCPVOK()){
-         FillHistogram(Form("hMassPtV0ABoth_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
-         FillHistogram(Form("hMassPtV0CBoth_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
+         FillHistogram(Form("hMassPtV0ABoth_cen%d",fCentBin),m,pt,dphiA) ;
+         FillHistogram(Form("hMassPtV0CBoth_cen%d",fCentBin),m,pt,dphiC) ;
           if(fHaveTPCRP)
-           FillHistogram(Form("hMassPtTPCBoth_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
+           FillHistogram(Form("hMassPtTPCBoth_cen%d",fCentBin),m,pt,dphiT) ;
 
-         FillHistogram(Form("hMassPtV0ABothcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiA) ;
-         FillHistogram(Form("hMassPtV0CBothcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiC) ;
+         FillHistogram(Form("hMassPtV0ABothcore_cen%d",fCentBin),mcore,ptcore,dphiA) ;
+         FillHistogram(Form("hMassPtV0CBothcore_cen%d",fCentBin),mcore,ptcore,dphiC) ;
           if(fHaveTPCRP)
-           FillHistogram(Form("hMassPtTPCBothcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiT) ;
+           FillHistogram(Form("hMassPtTPCBothcore_cen%d",fCentBin),mcore,ptcore,dphiT) ;
 
-         FillHistogram(Form("hPi0Both_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
-         FillHistogram(Form("hPi0Bothcore_cen%d",fCentBin),pv12.M() ,pv12.Pt()) ;
+         FillHistogram(Form("hPi0Both_cen%d",fCentBin),m,pt) ;
+         FillHistogram(Form("hPi0Bothcore_cen%d",fCentBin),mcore,ptcore) ;
 
           if(a<kAlphaCut){
             snprintf(key,55,"hPi0Both_a07_cen%d",fCentBin) ;
-            FillHistogram(Form("hPi0Both_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+            FillHistogram(Form("hPi0Both_a07_cen%d",fCentBin),m,pt) ;
           }
-         if(fCentralityV0M>20.){
           if(ph1->Module()==1 && ph2->Module()==1)
-           FillHistogram("hPi0M11",p12.M(),p12.Pt() );
+           FillHistogram("hPi0M11",m,pt );
           else if(ph1->Module()==2 && ph2->Module()==2)
-           FillHistogram("hPi0M22",p12.M(),p12.Pt() );
+           FillHistogram("hPi0M22",m,pt );
           else if(ph1->Module()==3 && ph2->Module()==3)
-           FillHistogram("hPi0M33",p12.M(),p12.Pt() );
+           FillHistogram("hPi0M33",m,pt );
           else if(ph1->Module()==1 && ph2->Module()==2)
-           FillHistogram("hPi0M12",p12.M(),p12.Pt() );
+           FillHistogram("hPi0M12",m,pt );
           else if(ph1->Module()==1 && ph2->Module()==3)
-           FillHistogram("hPi0M13",p12.M(),p12.Pt() );
+           FillHistogram("hPi0M13",m,pt );
           else if(ph1->Module()==2 && ph2->Module()==3)
-           FillHistogram("hPi0M23",p12.M(),p12.Pt() );
-         }
+           FillHistogram("hPi0M23",m,pt );
 
         }
+       
+      }
+      
+      
+      if(ph1->IsDisp2OK() && ph2->IsDisp2OK()){
+       FillHistogram(Form("hPi0Disp2_cen%d",fCentBin),m,pt) ;
+       FillHistogram(Form("hPi0Disp2core_cen%d",fCentBin),mcore, ptcore) ;     
+
+       FillHistogram(Form("hMassPtV0ADisp2_cen%d",fCentBin),m,pt,dphiA) ;
+       FillHistogram(Form("hMassPtV0CDisp2_cen%d",fCentBin),m,pt,dphiC) ;
+       if(fHaveTPCRP)
+         FillHistogram(Form("hMassPtTPCDisp2_cen%d",fCentBin),m,pt,dphiT) ;
+
+       FillHistogram(Form("hMassPtV0ADisp2core_cen%d",fCentBin),mcore, ptcore,dphiA) ;
+       FillHistogram(Form("hMassPtV0CDisp2core_cen%d",fCentBin),mcore, ptcore,dphiC) ;
+       if(fHaveTPCRP)
+         FillHistogram(Form("hMassPtTPCDisp2core_cen%d",fCentBin),mcore, ptcore,dphiT) ;
+         
+       if(ph1->IsCPVOK() && ph2->IsCPVOK()){
+         FillHistogram(Form("hMassPtV0ABoth2_cen%d",fCentBin),m,pt,dphiA) ;
+         FillHistogram(Form("hMassPtV0CBoth2_cen%d",fCentBin),m,pt,dphiC) ;
+          if(fHaveTPCRP)
+           FillHistogram(Form("hMassPtTPCBoth2_cen%d",fCentBin),m,pt,dphiT) ;
+
+         FillHistogram(Form("hMassPtV0ABoth2core_cen%d",fCentBin),mcore,ptcore,dphiA) ;
+         FillHistogram(Form("hMassPtV0CBoth2core_cen%d",fCentBin),mcore,ptcore,dphiC) ;
+          if(fHaveTPCRP)
+           FillHistogram(Form("hMassPtTPCBoth2core_cen%d",fCentBin),mcore,ptcore,dphiT) ;
+
+         FillHistogram(Form("hPi0Both2_cen%d",fCentBin),m,pt) ;
+         FillHistogram(Form("hPi0Both2core_cen%d",fCentBin),mcore,ptcore) ;
+       }
+
       }
     } // end of loop i2
   } // end of loop i1
@@ -1166,115 +1153,149 @@ void AliAnalysisTaskPi0Flow::ConsiderPi0sMix()
 
 
         Double_t a=TMath::Abs((ph1->E()-ph2->E())/(ph1->E()+ph2->E())) ;
+        Double_t m=p12.M() ;
+        Double_t mcore=pv12.M() ;
+        Double_t pt=p12.Pt() ;
+        Double_t ptcore=pv12.Pt() ;
+        Double_t pt1=ph1->Pt() ;
+        Double_t pt2=ph2->Pt() ;
+        Double_t ptcore1=ph1->GetMomV2()->Pt() ;
+        Double_t ptcore2=ph2->GetMomV2()->Pt() ;
+
 
        snprintf(key,55,"hMiMassPtAll_cen%d",fCentBin) ;
-       FillHistogram(Form("hMiMassPtV0AAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
-       FillHistogram(Form("hMiMassPtV0CAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
+       FillHistogram(Form("hMiMassPtV0AAll_cen%d",fCentBin),m,pt,dphiA) ;
+       FillHistogram(Form("hMiMassPtV0CAll_cen%d",fCentBin),m,pt,dphiC) ;
        if(fHaveTPCRP)
-         FillHistogram(Form("hMiMassPtTPCAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
+         FillHistogram(Form("hMiMassPtTPCAll_cen%d",fCentBin),m,pt,dphiT) ;
 
-       FillHistogram(Form("hMiMassPtV0AAllcore_cen%d",fCentBin),pv12.M(), pv12.Pt(), dphiA) ;
-       FillHistogram(Form("hMiMassPtV0CAllcore_cen%d",fCentBin),pv12.M(), pv12.Pt(), dphiC) ;
+       FillHistogram(Form("hMiMassPtV0AAllcore_cen%d",fCentBin),mcore, ptcore, dphiA) ;
+       FillHistogram(Form("hMiMassPtV0CAllcore_cen%d",fCentBin),mcore, ptcore, dphiC) ;
         if(fHaveTPCRP)
-         FillHistogram(Form("hMiMassPtTPCAllcore_cen%d",fCentBin),pv12.M(), pv12.Pt(), dphiT) ;
+         FillHistogram(Form("hMiMassPtTPCAllcore_cen%d",fCentBin),mcore, ptcore, dphiT) ;
 
-       FillHistogram(Form("hMiPi0All_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
-       FillHistogram(Form("hMiPi0Allcore_cen%d",fCentBin),pv12.M() ,pv12.Pt()) ;
+       FillHistogram(Form("hMiPi0All_cen%d",fCentBin),m,pt) ;
+       FillHistogram(Form("hMiPi0Allcore_cen%d",fCentBin),mcore,ptcore) ;
        if(ph1->IsntUnfolded() && ph2->IsntUnfolded()){
-         FillHistogram(Form("hMiPi0Allwou_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+         FillHistogram(Form("hMiPi0Allwou_cen%d",fCentBin),m,pt) ;
+          FillHistogram(Form("hMiMassPtV0AAllwou_cen%d",fCentBin),m,pt,dphiA) ;
+          FillHistogram(Form("hMiMassPtV0CAllwou_cen%d",fCentBin),m,pt,dphiC) ;
+          if(fHaveTPCRP)
+            FillHistogram(Form("hMiMassPtTPCAllwou_cen%d",fCentBin),m,pt,dphiT) ;
        }
 
-        FillHistogram(Form("hMiSingleAll_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
-        FillHistogram(Form("hMiSingleAll_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
-        FillHistogram(Form("hMiSingleAllcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
-        FillHistogram(Form("hMiSingleAllcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
+        FillHistogram(Form("hMiSingleAll_cen%d",fCentBin),m,pt1) ;
+        FillHistogram(Form("hMiSingleAll_cen%d",fCentBin),m,pt2) ;
+        FillHistogram(Form("hMiSingleAllcore_cen%d",fCentBin),mcore,ptcore1) ;
+        FillHistogram(Form("hMiSingleAllcore_cen%d",fCentBin),mcore,ptcore2) ;
         if(ph1->IsntUnfolded())
-          FillHistogram(Form("hMiSingleAllwou_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+          FillHistogram(Form("hMiSingleAllwou_cen%d",fCentBin),m,pt1) ;
         if(ph2->IsntUnfolded())
-          FillHistogram(Form("hMiSingleAllwou_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+          FillHistogram(Form("hMiSingleAllwou_cen%d",fCentBin),m,pt2) ;
         if(ph1->IsCPVOK()){
-          FillHistogram(Form("hMiSingleCPV_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
-          FillHistogram(Form("hMiSingleCPVcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
+          FillHistogram(Form("hMiSingleCPV_cen%d",fCentBin),m,pt1) ;
+          FillHistogram(Form("hMiSingleCPVcore_cen%d",fCentBin),mcore,ptcore1) ;
         }
         if(ph2->IsCPVOK()){
-          FillHistogram(Form("hMiSingleCPV_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
-          FillHistogram(Form("hMiSingleCPVcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
+          FillHistogram(Form("hMiSingleCPV_cen%d",fCentBin),m,pt2) ;
+          FillHistogram(Form("hMiSingleCPVcore_cen%d",fCentBin),mcore,ptcore2) ;
         }
         if(ph1->IsCPV2OK()){
-          FillHistogram(Form("hMiSingleCPV2_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+          FillHistogram(Form("hMiSingleCPV2_cen%d",fCentBin),m,pt1) ;
+          FillHistogram(Form("hMiSingleCPV2core_cen%d",fCentBin),mcore,ptcore1) ;
         }
         if(ph2->IsCPV2OK()){
-          FillHistogram(Form("hMiSingleCPV2_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+          FillHistogram(Form("hMiSingleCPV2_cen%d",fCentBin),m,pt2) ;
+          FillHistogram(Form("hMiSingleCPV2core_cen%d",fCentBin),mcore,ptcore2) ;
         }
         if(ph1->IsDispOK()){
-          FillHistogram(Form("hMiSingleDisp_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+          FillHistogram(Form("hMiSingleDisp_cen%d",fCentBin),m,pt1) ;
           if(ph1->IsntUnfolded()){
-            FillHistogram(Form("hMiSingleDispwou_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+            FillHistogram(Form("hMiSingleDispwou_cen%d",fCentBin),m,pt1) ;
          }
-          FillHistogram(Form("hMiSingleDispcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
+          FillHistogram(Form("hMiSingleDispcore_cen%d",fCentBin),mcore,ptcore1) ;
         }
         if(ph2->IsDispOK()){
-          FillHistogram(Form("hMiSingleDisp_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+          FillHistogram(Form("hMiSingleDisp_cen%d",fCentBin),m,pt2) ;
           if(ph1->IsntUnfolded()){
-            FillHistogram(Form("hMiSingleDispwou_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+            FillHistogram(Form("hMiSingleDispwou_cen%d",fCentBin),m,pt2) ;
          }
-          FillHistogram(Form("hMiSingleDispcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
+          FillHistogram(Form("hMiSingleDispcore_cen%d",fCentBin),mcore,ptcore2) ;
         }
         if(ph1->IsDisp2OK()){
-          FillHistogram(Form("hMiSingleDisp2_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
+          FillHistogram(Form("hMiSingleDisp2_cen%d",fCentBin),m,pt1) ;
+          FillHistogram(Form("hMiSingleDisp2core_cen%d",fCentBin),mcore,ptcore1) ;
         }
         if(ph2->IsDisp2OK()){
-          FillHistogram(Form("hMiSingleDisp2_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
+          FillHistogram(Form("hMiSingleDisp2_cen%d",fCentBin),m,pt2) ;
+          FillHistogram(Form("hMiSingleDisp2core_cen%d",fCentBin),mcore,ptcore2) ;
         }
         if(ph1->IsDispOK() && ph1->IsCPVOK()){
           snprintf(key,55,"hMiSingleBoth_cen%d",fCentBin) ;
-          FillHistogram(key,p12.M(),ph1->Pt()) ;
+          FillHistogram(key,m,pt1) ;
           snprintf(key,55,"hMiSingleBothcore_cen%d",fCentBin) ;
-          FillHistogram(key,pv12.M(),ph1->GetMomV2()->Pt()) ;
+          FillHistogram(key,mcore,ptcore1) ;
         }
         if(ph2->IsDispOK() && ph2->IsCPVOK()){
           snprintf(key,55,"hMiSingleBoth_cen%d",fCentBin) ;
-          FillHistogram(key,p12.M(),ph2->Pt()) ;
+          FillHistogram(key,m,pt2) ;
           snprintf(key,55,"hMiSingleBothcore_cen%d",fCentBin) ;
-          FillHistogram(key,pv12.M(),ph2->GetMomV2()->Pt()) ;
+          FillHistogram(key,mcore,ptcore2) ;
+        }
+        if(ph1->IsDisp2OK() && ph1->IsCPVOK()){
+          FillHistogram(Form("hMiSingleBoth2_cen%d",fCentBin),m,pt1) ;
+          FillHistogram(Form("hMiSingleBoth2core_cen%d",fCentBin),mcore,ptcore1) ;
+        }
+        if(ph2->IsDisp2OK() && ph2->IsCPVOK()){
+          FillHistogram(Form("hMiSingleBoth2_cen%d",fCentBin),m,pt2) ;
+          FillHistogram(Form("hMiSingleBoth2core_cen%d",fCentBin),mcore,ptcore2) ;
         }
 
 
 
         if(a<kAlphaCut){
-          snprintf(key,55,"hMiPi0All_a07_cen%d",fCentBin) ;
-          FillHistogram(key,p12.M() ,p12.Pt()) ;
+          FillHistogram(Form("hMiPi0All_a07_cen%d",fCentBin),m,pt) ;
         }
        if(ph1->IsCPVOK() && ph2->IsCPVOK()){
-         FillHistogram(Form("hMiMassPtV0ACPV_cen%d",fCentBin),p12.M(), p12.Pt(),dphiA) ;
-         FillHistogram(Form("hMiMassPtV0CCPV_cen%d",fCentBin),p12.M(), p12.Pt(),dphiC) ;
+         FillHistogram(Form("hMiMassPtV0ACPV_cen%d",fCentBin),m,pt,dphiA) ;
+         FillHistogram(Form("hMiMassPtV0CCPV_cen%d",fCentBin),m,pt,dphiC) ;
          if(fHaveTPCRP)
-           FillHistogram(Form("hMiMassPtTPCCPV_cen%d",fCentBin),p12.M(), p12.Pt(),dphiT) ;
+           FillHistogram(Form("hMiMassPtTPCCPV_cen%d",fCentBin),m,pt,dphiT) ;
 
-         FillHistogram(Form("hMiMassPtV0ACPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiA) ;
-         FillHistogram(Form("hMiMassPtV0CCPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiC) ;
+         FillHistogram(Form("hMiMassPtV0ACPVcore_cen%d",fCentBin),mcore, ptcore,dphiA) ;
+         FillHistogram(Form("hMiMassPtV0CCPVcore_cen%d",fCentBin),mcore, ptcore,dphiC) ;
          if(fHaveTPCRP)
-           FillHistogram(Form("hMiMassPtTPCCPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiT) ;
+           FillHistogram(Form("hMiMassPtTPCCPVcore_cen%d",fCentBin),mcore, ptcore,dphiT) ;
 
-         FillHistogram(Form("hMiPi0CPV_cen%d",fCentBin),p12.M(), p12.Pt()) ;
-         FillHistogram(Form("hMiPi0CPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt()) ;
+         FillHistogram(Form("hMiPi0CPV_cen%d",fCentBin),m,pt) ;
+         FillHistogram(Form("hMiPi0CPVcore_cen%d",fCentBin),mcore, ptcore) ;
 
          if(a<kAlphaCut){
-            FillHistogram(Form("hMiPi0CPV_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+            FillHistogram(Form("hMiPi0CPV_a07_cen%d",fCentBin),m,pt) ;
           }
        }
        if(ph1->IsCPV2OK() && ph2->IsCPV2OK()){
-         FillHistogram(Form("hMiPi0CPV2_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+         FillHistogram(Form("hMiPi0CPV2_cen%d",fCentBin),m,pt) ;
+         FillHistogram(Form("hMiPi0CPV2core_cen%d",fCentBin),mcore, ptcore) ;
+
+         FillHistogram(Form("hMiMassPtV0ACPV2_cen%d",fCentBin),m,pt,dphiA) ;
+         FillHistogram(Form("hMiMassPtV0CCPV2_cen%d",fCentBin),m,pt,dphiC) ;
+         if(fHaveTPCRP)
+           FillHistogram(Form("hMiMassPtTPCCPV2_cen%d",fCentBin),m,pt,dphiT) ;
+         FillHistogram(Form("hMiMassPtV0ACPV2core_cen%d",fCentBin),mcore,ptcore,dphiA) ;
+         FillHistogram(Form("hMiMassPtV0CCPV2core_cen%d",fCentBin),mcore,ptcore,dphiC) ;
+         if(fHaveTPCRP)
+           FillHistogram(Form("hMiMassPtTPCCPV2core_cen%d",fCentBin),mcore,ptcore,dphiT) ;
 
          if(a<kAlphaCut){
-            FillHistogram(Form("hMiPi0CPV2_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+            FillHistogram(Form("hMiPi0CPV2_a07_cen%d",fCentBin),m,pt) ;
           }
        }
        if(ph1->IsDispOK() && ph2->IsDispOK()){
-         FillHistogram(Form("hMiMassPtV0ADisp_cen%d",fCentBin),p12.M(),p12.Pt(),dphiA) ;
-         FillHistogram(Form("hMiMassPtV0CDisp_cen%d",fCentBin),p12.M(),p12.Pt(),dphiC) ;
+         FillHistogram(Form("hMiMassPtV0ADisp_cen%d",fCentBin),m,pt,dphiA) ;
+         FillHistogram(Form("hMiMassPtV0CDisp_cen%d",fCentBin),m,pt,dphiC) ;
           if(fHaveTPCRP)
-           FillHistogram(Form("hMiMassPtTPCDisp_cen%d",fCentBin),p12.M(),p12.Pt(),dphiT) ;
+           FillHistogram(Form("hMiMassPtTPCDisp_cen%d",fCentBin),m,pt,dphiT) ;
 
          FillHistogram(Form("hMiMassPtV0ADispcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiA) ;
          FillHistogram(Form("hMiMassPtV0CDispcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiC) ;
@@ -1282,34 +1303,70 @@ void AliAnalysisTaskPi0Flow::ConsiderPi0sMix()
            FillHistogram(Form("hMiMassPtTPCDispcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiT) ;
 
 
-         FillHistogram(Form("hMiPi0Disp_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+         FillHistogram(Form("hMiPi0Disp_cen%d",fCentBin),m,pt) ;
          FillHistogram(Form("hMiPi0Dispcore_cen%d",fCentBin),pv12.M(),pv12.Pt()) ;
           if(ph1->IsntUnfolded() && ph2->IsntUnfolded()){
-           FillHistogram(Form("hMiPi0Dispwou_cen%d",fCentBin),p12.M(),p12.Pt()) ;
+           FillHistogram(Form("hMiPi0Dispwou_cen%d",fCentBin),m,pt) ;
+           FillHistogram(Form("hMiMassPtV0ADispwou_cen%d",fCentBin),m,pt,dphiA) ;
+           FillHistogram(Form("hMiMassPtV0CDispwou_cen%d",fCentBin),m,pt,dphiC) ;
+            if(fHaveTPCRP)
+             FillHistogram(Form("hMiMassPtTPCDispwou_cen%d",fCentBin),m,pt,dphiT) ;
          }
 
          if(a<kAlphaCut){
-            FillHistogram(Form("hMiPi0Disp_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+            FillHistogram(Form("hMiPi0Disp_a07_cen%d",fCentBin),m,pt) ;
           }
          if(ph1->IsCPVOK() && ph2->IsCPVOK()){
-           FillHistogram(Form("hMiMassPtV0ABoth_cen%d",fCentBin),p12.M(),p12.Pt(),dphiA) ;
-           FillHistogram(Form("hMiMassPtV0CBoth_cen%d",fCentBin),p12.M(),p12.Pt(),dphiC) ;
+           FillHistogram(Form("hMiMassPtV0ABoth_cen%d",fCentBin),m,pt,dphiA) ;
+           FillHistogram(Form("hMiMassPtV0CBoth_cen%d",fCentBin),m,pt,dphiC) ;
            if(fHaveTPCRP)
-             FillHistogram(Form("hMiMassPtTPCBoth_cen%d",fCentBin),p12.M(),p12.Pt(),dphiT) ;
+             FillHistogram(Form("hMiMassPtTPCBoth_cen%d",fCentBin),m,pt,dphiT) ;
 
            FillHistogram(Form("hMiMassPtV0ABothcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiA) ;
            FillHistogram(Form("hMiMassPtV0CBothcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiC) ;
            if(fHaveTPCRP)
              FillHistogram(Form("hMiMassPtTPCBothcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiT) ;
 
-           FillHistogram(Form("hMiPi0Both_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+           FillHistogram(Form("hMiPi0Both_cen%d",fCentBin),m,pt) ;
            FillHistogram(Form("hMiPi0Bothcore_cen%d",fCentBin),pv12.M(),pv12.Pt()) ;
 
            if(a<kAlphaCut){
-              FillHistogram(Form("hMiPi0Both_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
+              FillHistogram(Form("hMiPi0Both_a07_cen%d",fCentBin),m,pt) ;
             }
          }
        }
+       
+       if(ph1->IsDisp2OK() && ph2->IsDisp2OK()){
+         FillHistogram(Form("hMiMassPtV0ADisp2_cen%d",fCentBin),m,pt,dphiA) ;
+         FillHistogram(Form("hMiMassPtV0CDisp2_cen%d",fCentBin),m,pt,dphiC) ;
+          if(fHaveTPCRP)
+           FillHistogram(Form("hMiMassPtTPCDisp2_cen%d",fCentBin),m,pt,dphiT) ;
+
+         FillHistogram(Form("hMiMassPtV0ADisp2core_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiA) ;
+         FillHistogram(Form("hMiMassPtV0CDisp2core_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiC) ;
+          if(fHaveTPCRP)
+           FillHistogram(Form("hMiMassPtTPCDisp2core_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiT) ;
+
+
+         FillHistogram(Form("hMiPi0Disp2_cen%d",fCentBin),m,pt) ;
+         FillHistogram(Form("hMiPi0Disp2core_cen%d",fCentBin),pv12.M(),pv12.Pt()) ;
+
+         if(ph1->IsCPVOK() && ph2->IsCPVOK()){
+           FillHistogram(Form("hMiMassPtV0ABoth2_cen%d",fCentBin),m,pt,dphiA) ;
+           FillHistogram(Form("hMiMassPtV0CBoth2_cen%d",fCentBin),m,pt,dphiC) ;
+           if(fHaveTPCRP)
+             FillHistogram(Form("hMiMassPtTPCBoth2_cen%d",fCentBin),m,pt,dphiT) ;
+
+           FillHistogram(Form("hMiMassPtV0ABoth2core_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiA) ;
+           FillHistogram(Form("hMiMassPtV0CBoth2core_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiC) ;
+           if(fHaveTPCRP)
+             FillHistogram(Form("hMiMassPtTPCBoth2core_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiT) ;
+
+           FillHistogram(Form("hMiPi0Both2_cen%d",fCentBin),m,pt) ;
+           FillHistogram(Form("hMiPi0Both2core_cen%d",fCentBin),pv12.M(),pv12.Pt()) ;
+
+         }
+       }
       } // end of loop i2
     }
   } // end of loop i1
@@ -1429,9 +1486,10 @@ Int_t AliAnalysisTaskPi0Flow::GetRPBin()
 {
   Double_t averageRP;
   if(fHaveTPCRP)
-    averageRP = fRPV0A+fRPV0C+fRP /3.;
+    averageRP = fRP ;// If possible, it is better to have EP bin from TPC
+                     // to have similar events for miximng (including jets etc)   (fRPV0A+fRPV0C+fRP) /3.;
   else
-    averageRP = fRPV0A+fRPV0C /2.;
+    averageRP = (fRPV0A+fRPV0C) /2.;
 
   fEMRPBin = Int_t(fNEMRPBins*(averageRP)/TMath::Pi());
 
@@ -1798,7 +1856,7 @@ Int_t AliAnalysisTaskPi0Flow::ConvertToInternalRunNumber(Int_t run){
     default : return 199;
     }
   }
-  if(kUndefinedPeriod && fDebug >= 1 ) {
+  if((fPeriod == kUndefinedPeriod) && (fDebug >= 1) ) {
     AliWarning("Period not defined");
   }
   return 1;
@@ -1861,9 +1919,10 @@ Double_t AliAnalysisTaskPi0Flow::TestCPV(Double_t dx, Double_t dz, Double_t pt,
   Double_t sx=TMath::Min(5.4,2.59719e+02*TMath::Exp(-pt/1.02053e-01)+
                         6.58365e-01*5.91917e-01*5.91917e-01/((pt-9.61306e-01)*(pt-9.61306e-01)+5.91917e-01*5.91917e-01)+1.59219);
   Double_t sz=TMath::Min(2.75,4.90341e+02*1.91456e-02*1.91456e-02/(pt*pt+1.91456e-02*1.91456e-02)+1.60) ;
-  AliVEvent *event = InputEvent();
   Double_t mf = 0.; //
-  if(event) mf = event->GetMagneticField(); //Positive for ++ and negative for --
+  if(fEventAOD) mf = fEventAOD->GetMagneticField(); //Positive for ++ and negative for -- 
+  else if(fEventESD) mf = fEventESD->GetMagneticField(); //Positive for ++ and negative for --
+  
 
   if(mf<0.){ //field --
     meanZ = -0.468318 ;
@@ -1895,17 +1954,17 @@ void AliAnalysisTaskPi0Flow::SetFlatteningData(){
   }
   else{
     AliInfo(Form("Setting PHOS flattening with name %s \n",maps->GetName())) ;
-    AliPHOSEPFlattener * h = (AliPHOSEPFlattener*)maps->At(0) ;  
+    AliEPFlattener * h = (AliEPFlattener*)maps->At(0) ;  
     if(fTPCFlat) delete fTPCFlat ;
-    fTPCFlat = new AliPHOSEPFlattener() ;
+    fTPCFlat = new AliEPFlattener() ;
     fTPCFlat = h ;
-    h = (AliPHOSEPFlattener*)maps->At(1) ;  
+    h = (AliEPFlattener*)maps->At(1) ;  
     if(fV0AFlat) delete fV0AFlat ;
-    fV0AFlat = new AliPHOSEPFlattener() ;
+    fV0AFlat = new AliEPFlattener() ;
     fV0AFlat = h ;
-    h = (AliPHOSEPFlattener*)maps->At(2) ;  
+    h = (AliEPFlattener*)maps->At(2) ;  
     if(fV0CFlat) delete fV0CFlat ;
-    fV0CFlat = new AliPHOSEPFlattener() ;
+    fV0CFlat = new AliEPFlattener() ;
     fV0CFlat = h ;
   }    
   
@@ -1944,14 +2003,15 @@ Double_t  AliAnalysisTaskPi0Flow::CoreEnergy(AliVCluster * clu, AliVCaloCells *
   const Double_t distanceCut =3.5 ;
   const Double_t logWeight=4.5 ;
 
-  Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
+  const Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
 // Calculates the center of gravity in the local PHOS-module coordinates
   Float_t wtot = 0;
-  Double_t xc[100]={0} ;
-  Double_t zc[100]={0} ;
+  const Int_t mulDigit=clu->GetNCells() ;
+  Double_t xc[mulDigit] ;
+  Double_t zc[mulDigit] ;
+  Double_t ei[mulDigit] ;
   Double_t x = 0 ;
   Double_t z = 0 ;
-  Int_t mulDigit=TMath::Min(100,clu->GetNCells()) ;
   for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
     Int_t relid[4] ;
     Float_t xi ;
@@ -1960,11 +2020,11 @@ Double_t  AliAnalysisTaskPi0Flow::CoreEnergy(AliVCluster * clu, AliVCaloCells *
     fPHOSGeo->RelPosInModule(relid, xi, zi);
     xc[iDigit]=xi ;
     zc[iDigit]=zi ;
-    elist[iDigit] *= cells->GetCellAmplitude(clu->GetCellsAbsId()[iDigit]);
+    ei[iDigit]=elist[iDigit]*cells->GetCellAmplitude(clu->GetCellsAbsId()[iDigit]);
     if( fDebug >= 3 )
-      printf("%f ",elist[iDigit]);
-    if (clu->E()>0 && elist[iDigit]>0) {
-      Float_t w = TMath::Max( 0., logWeight + TMath::Log( elist[iDigit] / clu->E() ) ) ;
+      printf("%f ",ei[iDigit]);
+    if (clu->E()>0 && ei[iDigit]>0) {
+      Float_t w = TMath::Max( 0., logWeight + TMath::Log( ei[iDigit] / clu->E() ) ) ;
       x    += xc[iDigit] * w ;
       z    += zc[iDigit] * w ;
       wtot += w ;
@@ -1978,7 +2038,7 @@ Double_t  AliAnalysisTaskPi0Flow::CoreEnergy(AliVCluster * clu, AliVCaloCells *
   for(Int_t iDigit=0; iDigit < mulDigit; iDigit++) {
     Double_t distance = TMath::Sqrt((xc[iDigit]-x)*(xc[iDigit]-x)+(zc[iDigit]-z)*(zc[iDigit]-z)) ;
     if(distance < distanceCut)
-      coreE += elist[iDigit] ;
+      coreE += ei[iDigit] ;
   }
   //Apply non-linearity correction
   return fNonLinCorr->Eval(coreE) ;
@@ -2230,9 +2290,9 @@ void AliAnalysisTaskPi0Flow::SetGeometry()
     fPHOSGeo =  AliPHOSGeometry::GetInstance("IHEP") ;
     for(Int_t mod=0; mod<5; mod++) {
       if(!matrixes->At(mod)) {
-       continue;
        if( fDebug )
          AliInfo(Form("No PHOS Matrix for mod:%d, geo=%p\n", mod, fPHOSGeo));
+       continue;
       }
       else {
        fPHOSGeo->SetMisalMatrix(((TGeoHMatrix*)matrixes->At(mod)),mod) ;
@@ -2294,7 +2354,7 @@ Bool_t AliAnalysisTaskPi0Flow::RejectEventVertex()
     return true; // reject
   LogSelection(1, fInternalRunNumber);
 
-  if ( TMath::Abs(fVertexVector.z()) > 10. )
+  if ( TMath::Abs(fVertexVector.z()) > fMaxAbsVertexZ )
     return true; // reject
   LogSelection(2, fInternalRunNumber);
 
@@ -2491,3 +2551,99 @@ void  AliAnalysisTaskPi0Flow::EvalV0ReactionPlane(){
     FillHistogram("cos2V0CTPC",TMath::Cos(2.*(fRP-fRPV0C)),fCentralityV0M) ;
   }
 }
+//____________________________________________________________________________
+void  AliAnalysisTaskPi0Flow::EvalCoreLambdas(AliVCluster * clu, AliVCaloCells * cells,Double_t &m02, Double_t &m20){ 
+  //calculate dispecrsion of the cluster in the circle with radius distanceCut around the maximum
+    
+  const Double_t rCut=4.5 ;  
+    
+  const Double32_t * elist = clu->GetCellsAmplitudeFraction() ;  
+// Calculates the center of gravity in the local PHOS-module coordinates
+  Float_t wtot = 0;
+  const Int_t mulDigit=clu->GetNCells() ;
+  Double_t xc[mulDigit] ;
+  Double_t zc[mulDigit] ;
+  Double_t wi[mulDigit] ;
+  Double_t x = 0 ;
+  Double_t z = 0 ;
+  const Double_t logWeight=4.5 ;
+  for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
+    Int_t relid[4] ;
+    Float_t xi=0. ;
+    Float_t zi=0. ;
+    Int_t absId = clu->GetCellAbsId(iDigit) ;
+    fPHOSGeo->AbsToRelNumbering(absId, relid) ;
+    fPHOSGeo->RelPosInModule(relid, xi, zi);
+    xc[iDigit]=xi ;
+    zc[iDigit]=zi ;
+    Double_t ei = elist[iDigit]*cells->GetCellAmplitude(absId) ;
+    wi[iDigit]=0. ;
+    if (clu->E()>0 && ei>0) {
+      wi[iDigit] = TMath::Max( 0., logWeight + TMath::Log( ei / clu->E() ) ) ;
+      Double_t w=wi[iDigit];
+      x    += xc[iDigit] * w ;
+      z    += zc[iDigit] * w ;
+      wtot += w ;
+    }
+  }
+  if (wtot>0) {
+    x /= wtot ;
+    z /= wtot ;
+  }
+     
+  wtot = 0. ;
+  Double_t dxx  = 0.;
+  Double_t dzz  = 0.;
+  Double_t dxz  = 0.;
+  Double_t xCut = 0. ;
+  Double_t zCut = 0. ;
+  for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
+    Double_t w=wi[iDigit];
+    if (w>0.) {
+        Double_t xi= xc[iDigit] ;
+        Double_t zi= zc[iDigit] ;
+       if((xi-x)*(xi-x)+(zi-z)*(zi-z) < rCut*rCut){
+          xCut += w * xi ;
+          zCut += w * zi ; 
+          dxx  += w * xi * xi ;
+          dzz  += w * zi * zi ;
+          dxz  += w * xi * zi ; 
+          wtot += w ;
+       }
+    }
+    
+  }
+  if (wtot>0) {
+    xCut/= wtot ;
+    zCut/= wtot ;
+    dxx /= wtot ;
+    dzz /= wtot ;
+    dxz /= wtot ;
+    dxx -= xCut * xCut ;
+    dzz -= zCut * zCut ;
+    dxz -= xCut * zCut ;
+
+    m02 =  0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz )  ;
+    m20 =  0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz )  ;
+  }
+  else {
+    m20=m02=0.;
+  }
+
+}
+//____________________________________________________________________________
+Bool_t AliAnalysisTaskPi0Flow::TestCoreLambda(Double_t pt,Double_t l1,Double_t l2){
+  //Evaluates if lambdas correspond to photon cluster
+  //Tuned using pp date 
+  //For core radius R=4.5
+  Double_t   l1Mean  = 1.150200 + 0.097886/(1.+1.486645*pt+0.000038*pt*pt) ;
+  Double_t   l2Mean = 1.574706 + 0.997966*exp(-0.895075*pt)-0.010666*pt ;
+  Double_t   l1Sigma = 0.100255 + 0.337177*exp(-0.517684*pt)+0.001170*pt ;
+  Double_t   l2Sigma = 0.232580 + 0.573401*exp(-0.735903*pt)-0.002325*pt ;
+  Double_t   c = -0.110983 -0.017353/(1.-1.836995*pt+0.934517*pt*pt) ;
+
+  Double_t R2=0.5*(l1-l1Mean)*(l1-l1Mean)/l1Sigma/l1Sigma + 
+              0.5*(l2-l2Mean)*(l2-l2Mean)/l2Sigma/l2Sigma +
+              0.5*c*(l1-l1Mean)*(l2-l2Mean)/l1Sigma/l2Sigma ;
+  return (R2<2.5*2.5) ;  
+}