- added tasks by Jason Kamin to PWGGA/EMCALTasks
authorfbock <friederike.bock@cern.ch>
Tue, 29 Apr 2014 12:34:48 +0000 (14:34 +0200)
committerfbock <friederike.bock@cern.ch>
Tue, 29 Apr 2014 12:34:48 +0000 (14:34 +0200)
-> pi0 & eta in pp, pPb with SDM method
-> photon task for MC

PWGGA/CMakelibPWGGAEMCALTasks.pkg
PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDM.cxx [new file with mode: 0644]
PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDM.h [new file with mode: 0644]
PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDMpPb.cxx [new file with mode: 0644]
PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDMpPb.h [new file with mode: 0644]
PWGGA/EMCALTasks/AliAnalysisTaskSDMGammaMC.cxx [new file with mode: 0644]
PWGGA/EMCALTasks/AliAnalysisTaskSDMGammaMC.h [new file with mode: 0644]
PWGGA/EMCALTasks/macros/AddTaskEMCALMesonGGSDM.C [new file with mode: 0644]
PWGGA/EMCALTasks/macros/AddTaskEMCALMesonGGSDMpPb.C [new file with mode: 0644]
PWGGA/EMCALTasks/macros/AddTaskSDMGammaMC.C [new file with mode: 0644]
PWGGA/PWGGAEMCALTasksLinkDef.h

index 6297131..3f55285 100644 (file)
@@ -42,6 +42,9 @@ set ( SRCS
  EMCALTasks/AliAnalysisTaskEMCALPi0V2ShSh.cxx
  EMCALTasks/AliEMCalpi0ClusterEvaluationTask.cxx
  EMCALTasks/AliAnalysisTaskEMCALIsolation.cxx
+ EMCALTasks/AliAnalysisTaskEMCALMesonGGSDM.cxx
+ EMCALTasks/AliAnalysisTaskEMCALMesonGGSDMpPb.cxx
+ EMCALTasks/AliAnalysisTaskSDMGammaMC.cxx
 )
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
diff --git a/PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDM.cxx b/PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDM.cxx
new file mode 100644 (file)
index 0000000..9a7aa27
--- /dev/null
@@ -0,0 +1,2085 @@
+#include "AliAnalysisTaskEMCALMesonGGSDM.h"
+
+#include <vector>
+#include <Riostream.h>
+#include <TChain.h>
+#include <TTree.h>
+#include <TF1.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TH3F.h>
+#include <TH1D.h>
+#include <TH2D.h>
+#include <TH3D.h>
+#include <TCanvas.h>
+#include <TList.h>
+#include <TFile.h>
+#include <TLorentzVector.h>
+#include <TNtuple.h>
+#include <TRandom3.h>
+
+#include "AliAnalysisTaskSE.h"
+#include "AliAnalysisManager.h"
+#include "AliStack.h"
+#include "AliESDtrackCuts.h"
+#include "AliESDEvent.h"
+#include "AliESDInputHandler.h"
+#include "AliAODEvent.h"
+#include "AliMCEvent.h"
+#include "AliEMCALGeometry.h"
+#include "AliInputEventHandler.h"
+#include "AliESDInputHandler.h"
+#include "AliAODInputHandler.h"
+
+#include "AliEMCALRecoUtils.h"
+#include "AliExternalTrackParam.h"
+
+// ROOT includes
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TGeoBBox.h>
+#include <TH2F.h>
+#include <TArrayI.h>
+#include <TArrayF.h>
+#include <TObjArray.h>
+
+// STEER includes
+#include "AliVCluster.h"
+#include "AliVCaloCells.h"
+#include "AliLog.h"
+#include "AliPID.h"
+#include "AliESDEvent.h"
+#include "AliAODEvent.h"
+#include "AliESDtrack.h"
+#include "AliAODTrack.h"
+#include "AliExternalTrackParam.h"
+#include "AliESDfriendTrack.h"
+#include "AliTrackerBase.h"
+
+// EMCAL includes
+#include "AliEMCALRecoUtils.h"
+#include "AliEMCALGeometry.h"
+#include "AliTrackerBase.h"
+#include "AliEMCALCalibTimeDepCorrection.h" // Run dependent
+#include "AliEMCALPIDUtils.h"
+
+#include "AliGenCocktailEventHeader.h"
+
+ClassImp(AliAnalysisTaskEMCALMesonGGSDM)
+
+//________________________________________________________________________
+AliAnalysisTaskEMCALMesonGGSDM::AliAnalysisTaskEMCALMesonGGSDM() : 
+  AliAnalysisTaskSE(),
+  fOutput(0),
+  fMcMode(0),
+  fMyMCType(0),
+  fRecalibrator(0),
+  fdRmin_ClustTrack(0),
+  fPhimin(0),
+  fPhimax(0),
+  fEtamin(0),
+  fEtamax(0),
+  fTrackCuts(0),
+  fEsdEv(0),
+  fAodEv(0),
+  h1_nClusters(0), 
+  h1_zvtx(0), 
+  h1_trigger(0), 
+  h1_M(0), 
+  h1_M_mix(0), 
+  h1_E(0), 
+  h2_PhiEtaCluster(0), 
+  h2_PhiEtaClusterCut(0), 
+  h2_PhiEtaMaxCell(0), 
+  h2_PhiEtaMaxCellCut(0), 
+  h1_dR_ClustTrk(0),
+  h2_gE_RecTruth(0), 
+  h2_eop_E(0),
+  h2_eop_pT(0),
+  h2_E_time(0),
+  h1_Pi0TruthPt(0), 
+  h1_K0Pi0TruthPt(0), 
+  h1_PriPi0TruthPt(0), 
+  h1_PhysPi0TruthPt(0), 
+  h1_Pi0TruthPtEmcal(0), 
+  h1_K0Pi0TruthPtEmcal(0), 
+  h1_PriPi0TruthPtEmcal(0), 
+  h1_PhysPi0TruthPtEmcal(0), 
+  h1_Pi0TruthPtPhi2piEta065(0), 
+  h1_K0Pi0TruthPtPhi2piEta065(0), 
+  h1_PriPi0TruthPtPhi2piEta065(0), 
+  h1_PhysPi0TruthPtPhi2piEta065(0), 
+  h1_Pi0TruthPtPhi2piEta1(0), 
+  h1_K0Pi0TruthPtPhi2piEta1(0), 
+  h1_PriPi0TruthPtPhi2piEta1(0), 
+  h1_PhysPi0TruthPtPhi2piEta1(0), 
+  h2_Pi0TruthPhiEta(0), 
+  h2_PriPi0TruthPhiEta(0), 
+  h2_Pi0TruthPhiEtaEmcal(0), 
+  h2_PriPi0TruthPhiEtaEmcal(0), 
+  h1_TruthPhotonsEmcal(0), 
+  h2_TruthPhotonsPhiEta(0),
+  h1_PhotonsEmcal(0), 
+  h1_PhotonsNCellsCut(0), 
+  h1_PhotonsTrackMatchCut(0), 
+  h1_PhotonsAllCut(0), 
+  h2_PhotonsPhiEtaIsEmcal(0),
+  h1_dR_RealMC(0),
+  h2_Mpt_Pri(0),
+  h2_Mpt_Sec(0),
+  h3_MptR_Sec(0),
+  h3_MptR_K0s(0),
+  h3_MptR_Mat(0),
+  h2_PtR_MatM(0),
+  h2_Mpt_Pri_conv(0),
+  h2_Mpt_Sec_conv(0),
+  h3_MptR_Sec_conv(0),
+  h3_MptR_K0s_conv(0),
+  h3_MptR_Mat_conv(0),
+  h1_eConversionR(0),
+  h1_PriPi0Mother(0),
+  h1_SecPi0Mother(0),
+  h1_Chi2(0),
+  h1_nTrkMatch(0),
+  h1_nCells(0),
+  h1_ClusterDisp(0),
+  h2_Ellipse(0),
+  h2_EtaPt(0),
+//h2_Mpt(0), 
+  h3_MptAsymm(0), 
+//h2_Mpt_mix(0), 
+  h3_MptAsymm_mix(0), 
+  h2_dphi_deta(0), 
+  h2_dphi_deta_mix(0), 
+  h2_DispRes(0),
+  h2_cells_M02(0),
+  TriggerList(0),
+  fHelperClass(0)
+{
+  // Dummy constructor ALWAYS needed for I/O.
+}
+
+//________________________________________________________________________
+AliAnalysisTaskEMCALMesonGGSDM::AliAnalysisTaskEMCALMesonGGSDM(const char *name) :
+  AliAnalysisTaskSE(name),
+  fOutput(0),
+  fMcMode(0),
+  fMyMCType(0),
+  fRecalibrator(0),
+  fdRmin_ClustTrack(0),
+  fPhimin(0),
+  fPhimax(0),
+  fEtamin(0),
+  fEtamax(0),
+  fTrackCuts(0),
+  fEsdEv(0),
+  fAodEv(0),
+  h1_nClusters(0), 
+  h1_zvtx(0), 
+  h1_trigger(0), 
+  h1_M(0), 
+  h1_M_mix(0), 
+  h1_E(0), 
+  h2_PhiEtaCluster(0), 
+  h2_PhiEtaClusterCut(0), 
+  h2_PhiEtaMaxCell(0), 
+  h2_PhiEtaMaxCellCut(0), 
+  h1_dR_ClustTrk(0),
+  h2_gE_RecTruth(0), 
+  h2_eop_E(0),
+  h2_eop_pT(0),
+  h2_E_time(0),
+  h1_Pi0TruthPt(0), 
+  h1_K0Pi0TruthPt(0),
+  h1_PriPi0TruthPt(0), 
+  h1_PhysPi0TruthPt(0), 
+  h1_Pi0TruthPtEmcal(0), 
+  h1_K0Pi0TruthPtEmcal(0), 
+  h1_PriPi0TruthPtEmcal(0), 
+  h1_PhysPi0TruthPtEmcal(0), 
+  h1_Pi0TruthPtPhi2piEta065(0), 
+  h1_K0Pi0TruthPtPhi2piEta065(0), 
+  h1_PriPi0TruthPtPhi2piEta065(0), 
+  h1_PhysPi0TruthPtPhi2piEta065(0), 
+  h1_Pi0TruthPtPhi2piEta1(0), 
+  h1_K0Pi0TruthPtPhi2piEta1(0), 
+  h1_PriPi0TruthPtPhi2piEta1(0), 
+  h1_PhysPi0TruthPtPhi2piEta1(0), 
+  h2_Pi0TruthPhiEta(0), 
+  h2_PriPi0TruthPhiEta(0), 
+  h2_Pi0TruthPhiEtaEmcal(0), 
+  h2_PriPi0TruthPhiEtaEmcal(0), 
+  h1_TruthPhotonsEmcal(0), 
+  h2_TruthPhotonsPhiEta(0),
+  h1_PhotonsEmcal(0), 
+  h1_PhotonsNCellsCut(0), 
+  h1_PhotonsTrackMatchCut(0), 
+  h1_PhotonsAllCut(0), 
+  h2_PhotonsPhiEtaIsEmcal(0),
+  h1_dR_RealMC(0),
+  h2_Mpt_Pri(0),
+  h2_Mpt_Sec(0),
+  h3_MptR_Sec(0),
+  h3_MptR_K0s(0),
+  h3_MptR_Mat(0),
+  h2_PtR_MatM(0),
+  h2_Mpt_Pri_conv(0),
+  h2_Mpt_Sec_conv(0),
+  h3_MptR_Sec_conv(0),
+  h3_MptR_K0s_conv(0),
+  h3_MptR_Mat_conv(0),
+  h1_eConversionR(0),
+  h1_PriPi0Mother(0),
+  h1_SecPi0Mother(0),
+  h1_Chi2(0),
+  h1_nTrkMatch(0),
+  h1_nCells(0),
+  h1_ClusterDisp(0),
+  h2_Ellipse(0),
+  h2_EtaPt(0),
+//h2_Mpt(0), 
+  h3_MptAsymm(0), 
+//h2_Mpt_mix(0), 
+  h3_MptAsymm_mix(0), 
+  h2_dphi_deta(0), 
+  h2_dphi_deta_mix(0), 
+  h2_DispRes(0), 
+  h2_cells_M02(0),
+  TriggerList(0),
+  fHelperClass(0)
+{
+  // Constructor
+  // Define input and output slots here (never in the dummy constructor)
+  // Input slot #0 works with a TChain - it is connected to the default input container
+  // Output slot #1 writes into a TH1 container
+
+  DefineOutput(1, TList::Class());                                            // for output list
+}
+
+//________________________________________________________________________
+AliAnalysisTaskEMCALMesonGGSDM::~AliAnalysisTaskEMCALMesonGGSDM()
+{
+  // Destructor. Clean-up the output list, but not the histograms that are put inside
+  // (the list is owner and will clean-up these histograms). Protect in PROOF case.
+  if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
+    delete fOutput;
+  }
+  delete fTrackCuts;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEMCALMesonGGSDM::UserCreateOutputObjects()
+{
+  // Create histograms
+  // Called once (on the worker node)
+
+  fOutput = new TList();
+  fOutput->SetOwner();  // IMPORTANT!
+   
+  fTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE);
+
+  cout << "__________AliAnalysisTaskEMCALMesonGGSDM: Input settings__________" << endl;
+  cout << " fMcMode:             " << fMcMode       << endl;
+  cout << " fMyMCType:           " << fMyMCType     << endl;
+  cout << " fRecalibrator:       " << fRecalibrator << endl;
+  cout << " dRmin_ClustTrack:    " << fdRmin_ClustTrack << endl;
+  cout << " phi range:           " << fPhimin << ", " << fPhimax << endl;
+  cout << " eta range:           " << fEtamin << ", " << fEtamax << endl;
+  cout << " number of zvtx bins: " << zvtx_bins     << endl;
+  cout << " number of mult bins: " << mult_bins     << endl;
+  cout << " poolDepth:           " << poolDepth     << endl;
+  cout << endl;
+  
+
+  //AliAnalysisManager  *man = AliAnalysisManager::GetAnalysisManager();
+  //AliInputEventHandler* inputHandler = (AliInputEventHandler*)(man->GetInputEventHandler());
+  //fPIDResponse = (AliPIDResponse*)inputHandler->GetPIDResponse();
+  //
+  //fPIDCombined = new AliPIDCombined();
+  //fPIDCombined->SetSelectedSpecies(AliPID::kSPECIES);
+  //fPIDCombined->SetDetectorMask(AliPIDResponse::kDetEMCAL);
+  //fPIDCombined->SetEnablePriors(kFALSE);
+  
+  double TotalNBins = 0.0;
+
+  // Create histograms
+  Int_t nClustersbins = 501;
+  Float_t nClusterslow = -0.5, nClustersup = 500.5;
+  h1_nClusters = new TH1F("h1_nClusters", "# of clusters", nClustersbins, nClusterslow, nClustersup);
+  h1_nClusters->GetXaxis()->SetTitle("number of clusters/evt");
+  h1_nClusters->GetYaxis()->SetTitle("counts");
+  h1_nClusters->SetMarkerStyle(kFullCircle);
+  TotalNBins+=nClustersbins;
+
+  Int_t nZvertexbins = 501;
+  Float_t Zvertexlow = -50.0, Zvertexup = 50.0;
+  h1_zvtx = new TH1F("h1_zvtx", "# of clusters", nZvertexbins, Zvertexlow, Zvertexup);
+  h1_zvtx->GetXaxis()->SetTitle("z_{vertex}");
+  h1_zvtx->GetYaxis()->SetTitle("counts");
+  h1_zvtx->SetMarkerStyle(kFullCircle);
+  TotalNBins+=nZvertexbins;
+
+  h1_trigger = new TH1F("h1_trigger", "trigger number returned", 1001,-0.5,1000.5);
+  TotalNBins+=1001;
+
+  Int_t Mbins = 3000;
+  Float_t Mlow = 0.0, Mup = 3.0;
+  h1_M = new TH1F("h1_M", "Invariant Mass", Mbins, Mlow, Mup);
+  h1_M->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h1_M->GetYaxis()->SetTitle("counts");
+  h1_M->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Mbins;
+
+  h1_M_mix = new TH1F("h1_M_mix", "Invariant Mass (mixed events)", Mbins, Mlow, Mup);
+  h1_M_mix->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h1_M_mix->GetYaxis()->SetTitle("counts");
+  h1_M_mix->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Mbins;
+
+  Int_t ptbins = 2000;
+  Float_t ptlow = 0.0, ptup = 20.0;
+  Int_t Ebins = 1000;
+  Float_t Elow = 0.0, Eup = 20.0;
+  h1_E = new TH1F("h1_E", "Cluster Energy in EMCal", Ebins, Elow, Eup);
+  h1_E->GetXaxis()->SetTitle("E [GeV]");
+  h1_E->GetYaxis()->SetTitle("counts");
+  h1_E->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Ebins;
+
+  h2_PhiEtaCluster = new TH2F("h2_PhiEtaCluster", "cluster phi vs eta", 400,1.362,3.178, 300,-0.728,0.728);
+  h2_PhiEtaCluster->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhiEtaCluster->GetYaxis()->SetTitle("#eta");
+  h2_PhiEtaCluster->GetZaxis()->SetTitle("hits");
+  h2_PhiEtaCluster->SetMarkerStyle(kFullCircle);
+  TotalNBins+=400*300;
+
+  h2_PhiEtaClusterCut = new TH2F("h2_PhiEtaClusterCut", "cluster phi vs eta (after cuts)", 400,1.362,3.178, 300,-0.728,0.728);
+  h2_PhiEtaClusterCut->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhiEtaClusterCut->GetYaxis()->SetTitle("#eta");
+  h2_PhiEtaClusterCut->GetZaxis()->SetTitle("hits");
+  h2_PhiEtaClusterCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=400*300;
+
+// eta binning
+  Double_t EtaBins[97] = {-0.66687,-0.653,-0.63913,-0.62526,-0.61139,-0.59752,-0.58365,-0.56978,-0.55591,-0.54204,-0.52817,-0.5143,-0.50043,-0.48656,-0.47269,-0.45882,-0.44495,-0.43108,-0.41721,-0.40334,-0.38947,-0.3756,-0.36173,-0.34786,-0.33399,-0.32012,-0.30625,-0.29238,-0.27851,-0.26464,-0.25077,-0.2369,-0.22303,-0.20916,-0.19529,-0.18142,-0.16755,-0.15368,-0.13981,-0.12594,-0.11207,-0.0982,-0.08433,-0.07046,-0.05659,-0.04272,-0.02885,-0.01498,-0.00111,0.01276,0.02663,0.0405,0.05437,0.06824,0.08211,0.09598,0.10985,0.12372,0.13759,0.15146,0.16533,0.1792,0.19307,0.20694,0.22081,0.23468,0.24855,0.26242,0.27629,0.29016,0.30403,0.3179,0.33177,0.34564,0.35951,0.37338,0.38725,0.40112,0.41499,0.42886,0.44273,0.4566,0.47047,0.48434,0.49821,0.51208,0.52595,0.53982,0.55369,0.56756,0.58143,0.5953,0.60917,0.62304,0.63691,0.65078,0.66465};
+  
+  // phi binning
+  Double_t PhiBins[125] = {1.408,1.4215,1.435,1.4485,1.462,1.4755,1.489,1.5025,1.516,1.5295,1.543,1.5565,1.57,1.5835,1.597,1.6105,1.624,1.6375,1.651,1.6645,1.678,1.6915,1.705,1.7185,1.732, 1.758,1.7715,1.785,1.7985,1.812,1.8255,1.839,1.8525,1.866,1.8795,1.893,1.9065,1.92,1.9335,1.947,1.9605,1.974,1.9875,2.001,2.0145,2.028,2.0415,2.055,2.0685,2.082,2.108,2.1215,2.135,2.1485,2.162,2.1755,2.189,2.2025,2.216,2.2295,2.243,2.2565,2.27,2.2835,2.297,2.3105,2.324,2.3375,2.351,2.3645,2.378,2.3915,2.405,2.4185,2.432,2.456,2.4695,2.483,2.4965,2.51,2.5235,2.537,2.5505,2.564,2.5775,2.591,2.6045,2.618,2.6315,2.645,2.6585,2.672,2.6855,2.699,2.7125,2.726,2.7395,2.753,2.7665,2.78,2.804,2.8175,2.831,2.8445,2.858,2.8715,2.885,2.8985,2.912,2.9255,2.939,2.9525,2.966,2.9795,2.993,3.0065,3.02,3.0335,3.047,3.0605,3.074,3.0875,3.101,3.1145,3.128};
+
+  h2_PhiEtaMaxCell = new TH2F("h2_PhiEtaMaxCell", "maxcell phi vs eta", 124,PhiBins, 96,EtaBins);
+  h2_PhiEtaMaxCell->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhiEtaMaxCell->GetYaxis()->SetTitle("#eta");
+  h2_PhiEtaMaxCell->GetZaxis()->SetTitle("hits");
+  h2_PhiEtaMaxCell->SetMarkerStyle(kFullCircle);
+  TotalNBins+=96*124;
+
+  h2_PhiEtaMaxCellCut = new TH2F("h2_PhiEtaMaxCellCut", "maxcell phi vs eta (after cuts)", 124,PhiBins, 96,EtaBins);
+  h2_PhiEtaMaxCellCut->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhiEtaMaxCellCut->GetYaxis()->SetTitle("#eta");
+  h2_PhiEtaMaxCellCut->GetZaxis()->SetTitle("hits");
+  h2_PhiEtaMaxCellCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=96*124;
+
+  h1_dR_ClustTrk = new TH1F("h1_dR_ClustTrk", "Cluster-Track matching", 5000, -0.01, 5);
+  h1_dR_ClustTrk->GetXaxis()->SetTitle("dR [sqrt(d#phi^{2}+d#eta^{2})]");
+  h1_dR_ClustTrk->GetYaxis()->SetTitle("N");
+  h1_dR_ClustTrk->SetMarkerStyle(kFullCircle);
+  TotalNBins+=5000;
+
+  h2_gE_RecTruth = new TH2F("h2_gE_RecTruth", "#gamma E_{truth}/E_{clust} vs E_{clust}", Ebins,Elow,Eup, 500,0,2);
+  h2_gE_RecTruth->GetXaxis()->SetTitle("E^{rec}_{clust} [GeV]");
+  h2_gE_RecTruth->GetYaxis()->SetTitle("E^{rec}_{clust}/E^{truth}_{#gamma}");
+  h2_gE_RecTruth->GetZaxis()->SetTitle("counts");
+  h2_gE_RecTruth->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Ebins*500;
+  
+  h2_eop_E = new TH2F("h2_eop_E","E/p vs E (using built-in track matching)", Ebins, Elow, Eup, 1200,0,3);
+  h2_eop_E->GetXaxis()->SetTitle("cluster Energy [GeV]");
+  h2_eop_E->GetYaxis()->SetTitle("E/p");
+  TotalNBins+=Ebins*1200;
+
+  h2_eop_pT = new TH2F("h2_eop_pT","E/p vs p_{T} (using built-in track matching)", Ebins, Elow, Eup, 1200,0,3);
+  h2_eop_pT->GetXaxis()->SetTitle("cluster Energy [GeV]");
+  h2_eop_pT->GetYaxis()->SetTitle("E/p");
+  TotalNBins+=Ebins*1200;
+
+  h2_E_time = new TH2F("h2_E_time","cluster energy vs time", Ebins, Elow, Eup, 1000,-1e-6,1e-6);
+  h2_E_time->GetXaxis()->SetTitle("cluster Energy [GeV]");
+  h2_E_time->GetYaxis()->SetTitle("time [s]");
+  TotalNBins+=Ebins*1000;
+
+  h1_Pi0TruthPt = new TH1F("h1_Pi0TruthPt", "P_{T} distribution for Truth Pi0's", ptbins, ptlow, ptup);
+  h1_Pi0TruthPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_Pi0TruthPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_Pi0TruthPt->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_K0Pi0TruthPt = new TH1F("h1_K0Pi0TruthPt", "P_{T} distribution for Truth Pi0's from K^{0}_{s} decays", ptbins, ptlow, ptup);
+  h1_K0Pi0TruthPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_K0Pi0TruthPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_K0Pi0TruthPt->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+  
+  h1_PriPi0TruthPt = new TH1F("h1_PriPi0TruthPt", "P_{T} distribution for Truth Primary Pi0's", ptbins, ptlow, ptup);
+  h1_PriPi0TruthPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PriPi0TruthPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PriPi0TruthPt->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PhysPi0TruthPt = new TH1F("h1_PhysPi0TruthPt", "P_{T} distribution for Truth Physical Primary Pi0's", ptbins, ptlow, ptup);
+  h1_PhysPi0TruthPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhysPi0TruthPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhysPi0TruthPt->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_Pi0TruthPtEmcal = new TH1F("h1_Pi0TruthPtEmcal", "P_{T} distribution for Truth Pi0's (hit EMCal)", ptbins, ptlow, ptup);
+  h1_Pi0TruthPtEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_Pi0TruthPtEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_Pi0TruthPtEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_K0Pi0TruthPtEmcal = new TH1F("h1_K0Pi0TruthPtEmcal", "P_{T} distribution for Truth Pi0's from K^{0}_{s} decays (hit EMCal)", ptbins, ptlow, ptup);
+  h1_K0Pi0TruthPtEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_K0Pi0TruthPtEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_K0Pi0TruthPtEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PriPi0TruthPtEmcal = new TH1F("h1_PriPi0TruthPtEmcal", "P_{T} distribution for Truth Primary Pi0's (hit EMCal)", ptbins, ptlow, ptup);
+  h1_PriPi0TruthPtEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PriPi0TruthPtEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PriPi0TruthPtEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PhysPi0TruthPtEmcal = new TH1F("h1_PhysPi0TruthPtEmcal", "P_{T} distribution for Truth Physical Primary Pi0's (hit EMCal)", ptbins, ptlow, ptup);
+  h1_PhysPi0TruthPtEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhysPi0TruthPtEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhysPi0TruthPtEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_Pi0TruthPtPhi2piEta065 = new TH1F("h1_Pi0TruthPtPhi2piEta065", 
+                                      "P_{T} for Truth Pi0's [|#eta_{#pi^{0}}|<0.65 && 0<#phi_{#pi^{0}}<2#pi]", ptbins, ptlow, ptup);
+  h1_Pi0TruthPtPhi2piEta065->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_Pi0TruthPtPhi2piEta065->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_Pi0TruthPtPhi2piEta065->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+        
+  h1_K0Pi0TruthPtPhi2piEta065 = new TH1F("h1_K0Pi0TruthPtPhi2piEta065", 
+                                        "P_{T} for Truth Pi0's (K^{0}_{s} decays) [|#eta_{#pi^{0}}|<0.65 && 0<#phi_{#pi^{0}}<2#pi]", ptbins, ptlow, ptup);
+  h1_K0Pi0TruthPtPhi2piEta065->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_K0Pi0TruthPtPhi2piEta065->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_K0Pi0TruthPtPhi2piEta065->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+        
+  h1_PriPi0TruthPtPhi2piEta065 = new TH1F("h1_PriPi0TruthPtPhi2piEta065",
+                                         "P_{T} for Primary Truth Pi0's [|#eta_{#pi^{0}}|<0.65 && 0<#phi_{#pi^{0}}<2#pi]", ptbins, ptlow, ptup);
+  h1_PriPi0TruthPtPhi2piEta065->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PriPi0TruthPtPhi2piEta065->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PriPi0TruthPtPhi2piEta065->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+        
+  h1_PhysPi0TruthPtPhi2piEta065 = new TH1F("h1_PhysPi0TruthPtPhi2piEta065", 
+                                          "P_{T} for Truth Pi0's (not from material) [|#eta_{#pi^{0}}|<0.65 && 0<#phi_{#pi^{0}}<2#pi]", ptbins, ptlow, ptup);
+  h1_PhysPi0TruthPtPhi2piEta065->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhysPi0TruthPtPhi2piEta065->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhysPi0TruthPtPhi2piEta065->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+  
+  h1_Pi0TruthPtPhi2piEta1 = new TH1F("h1_Pi0TruthPtPhi2piEta1", 
+                                    "P_{T} for Truth Pi0's [|#eta_{#pi^{0}}|<1.0 && 0<#phi_{#pi^{0}}<2#pi]", ptbins, ptlow, ptup);
+  h1_Pi0TruthPtPhi2piEta1->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_Pi0TruthPtPhi2piEta1->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_Pi0TruthPtPhi2piEta1->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+  
+  h1_K0Pi0TruthPtPhi2piEta1 = new TH1F("h1_K0Pi0TruthPtPhi2piEta1", 
+                                      "P_{T} for Truth Pi0's (k^{0}_{s} decays) [|#eta_{#pi^{0}}|<1.0 && 0<#phi_{#pi^{0}}<2#pi]", ptbins, ptlow, ptup);
+  h1_K0Pi0TruthPtPhi2piEta1->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_K0Pi0TruthPtPhi2piEta1->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_K0Pi0TruthPtPhi2piEta1->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+  
+  h1_PriPi0TruthPtPhi2piEta1 = new TH1F("h1_PriPi0TruthPtPhi2piEta1", 
+                                       "P_{T} for Primary Truth Pi0's [|#eta_{#pi^{0}}|<1.0 && 0<#phi_{#pi^{0}}<2#pi]", ptbins, ptlow, ptup);
+  h1_PriPi0TruthPtPhi2piEta1->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PriPi0TruthPtPhi2piEta1->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PriPi0TruthPtPhi2piEta1->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+  
+  h1_PhysPi0TruthPtPhi2piEta1 = new TH1F("h1_PhysPi0TruthPtPhi2piEta1", 
+                                    "P_{T} for Truth Pi0's (not from material) [|#eta_{#pi^{0}}|<1.0 && 0<#phi_{#pi^{0}}<2#pi]", ptbins, ptlow, ptup);
+  h1_PhysPi0TruthPtPhi2piEta1->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhysPi0TruthPtPhi2piEta1->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhysPi0TruthPtPhi2piEta1->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+  
+  h2_Pi0TruthPhiEta = new TH2F("h2_Pi0TruthPhiEta","Pi0Truth Phi vs Eta ", 380,-0.02,6.30, 200,-10,10);
+  h2_Pi0TruthPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_Pi0TruthPhiEta->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*200;
+
+  h2_PriPi0TruthPhiEta = new TH2F("h2_PriPi0TruthPhiEta","Primary Pi0Truth Phi vs Eta ", 380,-0.02,6.30, 200,-10,10);
+  h2_PriPi0TruthPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PriPi0TruthPhiEta->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*200;
+
+  h2_Pi0TruthPhiEtaEmcal = new TH2F("h2_Pi0TruthPhiEtaEmcal","Pi0Truth Phi vs Eta (in EMCal)", 380,-0.02,6.30, 150,-5,5);
+  h2_Pi0TruthPhiEtaEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_Pi0TruthPhiEtaEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+
+  h2_PriPi0TruthPhiEtaEmcal = new TH2F("h2_PriPi0TruthPhiEtaEmcal","Primary Pi0Truth Phi vs Eta (in EMCal)", 380,-0.02,6.30, 150,-5,5);
+  h2_PriPi0TruthPhiEtaEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PriPi0TruthPhiEtaEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+
+  h1_TruthPhotonsEmcal = new TH1F("h1_TruthPhotonsEmcal", "P_{T} distribution for photons (in EMCal)", ptbins, ptlow, ptup);
+  h1_TruthPhotonsEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_TruthPhotonsEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_TruthPhotonsEmcal->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+
+  h2_TruthPhotonsPhiEta = new TH2F("h2_TruthPhotonsPhiEta", 
+                                  "Truth Photons Phi vs Eta (pointed at emcal)", 380,-0.02,6.30, 150,-1.5,1.5);
+  h2_TruthPhotonsPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_TruthPhotonsPhiEta->GetYaxis()->SetTitle("#eta ");
+  h2_TruthPhotonsPhiEta->SetMarkerStyle(kFullCircle);
+  TotalNBins+=380*150;
+
+  h1_PhotonsEmcal = new TH1F("h1_PhotonsEmcal", "P_{T} distribution for photons (in EMCal)", ptbins, ptlow, ptup);
+  h1_PhotonsEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhotonsEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhotonsEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PhotonsNCellsCut = new TH1F("h1_PhotonsNCellsCut", "P_{T} distribution for #gamma's that survive NCells cut", ptbins, ptlow, ptup);
+  h1_PhotonsNCellsCut->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhotonsNCellsCut->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhotonsNCellsCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PhotonsTrackMatchCut = new TH1F("h1_PhotonsTrackMatchCut", "P_{T} distribution for #gamma's that survive TrackMatch cut", ptbins, ptlow, ptup);
+  h1_PhotonsTrackMatchCut->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhotonsTrackMatchCut->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhotonsTrackMatchCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PhotonsAllCut = new TH1F("h1_PhotonsAllCut", "P_{T} distribution for #gamma's that survive All cut", ptbins, ptlow, ptup);
+  h1_PhotonsAllCut->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhotonsAllCut->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhotonsAllCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h2_PhotonsPhiEtaIsEmcal = new TH2F("h2_PhotonsPhiEtaIsEmcal",
+                                    "Photons Phi vs Eta (IsEMCAL()==1)", 380,-0.02,6.30, 100,-1.0,1.0);
+  h2_PhotonsPhiEtaIsEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhotonsPhiEtaIsEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*100;
+  
+  h1_dR_RealMC = new TH1F("h1_dR_RealMC", "P_{T} distribution for #gamma's that survive All cut", 2000, -0.01, 10);
+  h1_dR_RealMC->GetXaxis()->SetTitle("dR sqrt(dx^{2}+dy^{2})");
+  h1_dR_RealMC->GetYaxis()->SetTitle("N");
+  h1_dR_RealMC->SetMarkerStyle(kFullCircle);
+  TotalNBins+=2000;
+
+  h2_Mpt_Pri = new TH2F("h2_Mpt_Pri", "mass vs pT for primary pions", Mbins, Mlow, Mup, ptbins, ptlow, ptup);
+  h2_Mpt_Pri->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h2_Mpt_Pri->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h2_Mpt_Pri->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Mbins*ptbins;
+
+  h2_Mpt_Sec = new TH2F("h2_Mpt_Sec", "mass vs pT for secondary pions", Mbins, Mlow, Mup, ptbins, ptlow, ptup);
+  h2_Mpt_Sec->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h2_Mpt_Sec->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h2_Mpt_Sec->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Mbins*ptbins;
+
+  h3_MptR_Sec = new TH3F("h3_MptR_Sec", "mass vs pT vs production radius for secondary pions", 500,0,0.5, 100,0,20, 300,0,600);
+  h3_MptR_Sec->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h3_MptR_Sec->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h3_MptR_Sec->GetZaxis()->SetTitle("production radius [cm]");
+  h3_MptR_Sec->SetMarkerStyle(kFullCircle);
+  TotalNBins+=500*100*300;
+
+  h3_MptR_K0s = new TH3F("h3_MptR_K0s", "mass vs pT vs production radius for K0s pions", 500,0,0.5, 100,0,20, 300,0,600);
+  h3_MptR_K0s->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h3_MptR_K0s->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h3_MptR_K0s->GetZaxis()->SetTitle("production radius [cm]");
+  h3_MptR_K0s->SetMarkerStyle(kFullCircle);
+  TotalNBins+=500*100*300;
+
+  h3_MptR_Mat = new TH3F("h3_MptR_Mat", "mass vs pT vs production radius for material pions", 500,0,0.5, 100,0,20, 300,0,600);
+  h3_MptR_Mat->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h3_MptR_Mat->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h3_MptR_Mat->GetZaxis()->SetTitle("production radius [cm]");
+  h3_MptR_Mat->SetMarkerStyle(kFullCircle);
+  TotalNBins+=500*100*300;
+
+  h2_PtR_MatM = new TH2F("h2_PtR_MatM", "pT vs production radius for merged material pions (pi mass assumed)", 100,0,20, 300,0,600);
+  h2_PtR_MatM->GetXaxis()->SetTitle("p_{T} [GeV/c]");
+  h2_PtR_MatM->GetYaxis()->SetTitle("production radius [cm]");
+  h2_PtR_MatM->SetMarkerStyle(kFullCircle);
+  TotalNBins+=100*300;
+
+  h2_Mpt_Pri_conv = new TH2F("h2_Mpt_Pri_conv", "mass vs pT for primary pions", Mbins, Mlow, Mup, ptbins, ptlow, ptup);
+  h2_Mpt_Pri_conv->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h2_Mpt_Pri_conv->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h2_Mpt_Pri_conv->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Mbins*ptbins;
+
+  h2_Mpt_Sec_conv = new TH2F("h2_Mpt_Sec_conv", "mass vs pT for secondary pions", Mbins, Mlow, Mup, ptbins, ptlow, ptup);
+  h2_Mpt_Sec_conv->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h2_Mpt_Sec_conv->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h2_Mpt_Sec_conv->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Mbins*ptbins;
+
+  h3_MptR_Sec_conv = new TH3F("h3_MptR_Sec_conv", "mass vs pT vs production radius for secondary pions", 500,0,0.5, 100,0,20, 300,0,600);
+  h3_MptR_Sec_conv->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h3_MptR_Sec_conv->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h3_MptR_Sec_conv->GetZaxis()->SetTitle("production radius [cm]");
+  h3_MptR_Sec_conv->SetMarkerStyle(kFullCircle);
+  TotalNBins+=500*100*300;
+
+  h3_MptR_K0s_conv = new TH3F("h3_MptR_K0s_conv", "mass vs pT vs production radius for K0s pions", 500,0,0.5, 100,0,20, 300,0,600);
+  h3_MptR_K0s_conv->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h3_MptR_K0s_conv->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h3_MptR_K0s_conv->GetZaxis()->SetTitle("production radius [cm]");
+  h3_MptR_K0s_conv->SetMarkerStyle(kFullCircle);
+  TotalNBins+=500*100*300;
+
+  h3_MptR_Mat_conv = new TH3F("h3_MptR_Mat_conv", "mass vs pT vs production radius for material pions", 500,0,0.5, 100,0,20, 300,0,600);
+  h3_MptR_Mat_conv->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h3_MptR_Mat_conv->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h3_MptR_Mat_conv->GetZaxis()->SetTitle("production radius [cm]");
+  h3_MptR_Mat_conv->SetMarkerStyle(kFullCircle);
+  TotalNBins+=500*100*300;
+
+  h1_eConversionR = new TH1F("h1_eConversionR", "conversion point (radius)", 600,0,600);
+  h1_eConversionR->GetXaxis()->SetTitle("production radius [cm]");
+  h1_eConversionR->SetMarkerStyle(kFullCircle);
+  TotalNBins+=600;
+
+  h1_PriPi0Mother = new TH1F("h1_PriPi0Mother", "primary pi0 mother ID", 12001,-6000.5,6000.5);
+  h1_PriPi0Mother->GetXaxis()->SetTitle("#pi^{0} mother ID");
+  h1_PriPi0Mother->SetMarkerStyle(kFullCircle);
+  TotalNBins+=12001;
+
+  h1_SecPi0Mother = new TH1F("h1_SecPi0Mother", "secondray pi0 mother ID", 12001,-6000.5,6000.5);
+  h1_SecPi0Mother->GetXaxis()->SetTitle("#pi^{0} mother ID");
+  h1_SecPi0Mother->SetMarkerStyle(kFullCircle);
+  TotalNBins+=12001;
+
+  Int_t chi2bins = 100;
+  Float_t chi2low = -2, chi2up = 2;
+  h1_Chi2 = new TH1F("h1_Chi2","#chi^{2} distribution for reconstructed",chi2bins, chi2low, chi2up);
+  h1_Chi2->GetXaxis()->SetTitle("#chi^{2}");
+  h1_Chi2->GetYaxis()->SetTitle("counts");
+  TotalNBins+=chi2bins;
+
+  h1_nTrkMatch = new TH1F("h1_nTrkMatch","number of matched tracks",14, -1.5, 5.5);
+  h1_nTrkMatch->GetXaxis()->SetTitle("nTracksMatched");
+  h1_nTrkMatch->GetYaxis()->SetTitle("counts");
+  TotalNBins+=14;
+       
+  h1_ClusterDisp = new TH1F("h1_ClusterDisp","Dispersion of CaloCluster",1000, -1, 3);
+  h1_ClusterDisp->GetXaxis()->SetTitle("cluster->GetClusterDisp()");
+  h1_ClusterDisp->GetYaxis()->SetTitle("counts");
+  TotalNBins+=1000;
+       
+  h2_Ellipse = new TH2F("h2_Ellipse","Ellipse axis M20 vs M02",500, -0.01, 1, 500, -0.01, 1);
+  h2_Ellipse->GetXaxis()->SetTitle("cluster->GetM20()");
+  h2_Ellipse->GetYaxis()->SetTitle("cluster->GetM02()");
+  h2_Ellipse->GetZaxis()->SetTitle("counts");
+  TotalNBins+=500*500;
+
+  Int_t etabins = 150;
+  Float_t etalow = -1.5, etaup = 1.5;
+  h2_EtaPt = new TH2F("h2_EtaPt","Cluster Energy vs ",etabins, etalow, etaup, ptbins, ptlow, ptup);
+  h2_EtaPt->GetXaxis()->SetTitle("E [GeV]");
+  h2_EtaPt->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  TotalNBins+=etabins*ptbins;
+
+  h3_MptAsymm = new TH3F("h3_MptAsymm","mass vs p_{T} vs Asymm cut",Mbins,Mlow,Mup, ptbins,ptlow,ptup, 3,0.5,3.5);
+  h3_MptAsymm->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h3_MptAsymm->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h3_MptAsymm->GetZaxis()->SetTitle("Asymmetry Cut (edges: 0.0, 0.1, 0.7, 1.0)");
+  TotalNBins+=Mbins*ptbins*3.0;
+
+  h3_MptAsymm_mix = new TH3F("h3_MptAsymm_mix","mass vs p_{T} vs Asymm cut (mixed events)",Mbins,Mlow,Mup, ptbins,ptlow,ptup, 3,0.5,3.5);
+  h3_MptAsymm_mix->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+  h3_MptAsymm_mix->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  h3_MptAsymm_mix->GetZaxis()->SetTitle("Asymmetry Cut (edges: 0.0, 0.1, 0.7, 1.0)");
+  TotalNBins+=Mbins*ptbins*3.0;
+
+  h2_dphi_deta = new TH2F("h2_dphi_deta","#Delta#phi vs #Delta#eta", 349,-1.5,5, 400,-2.0,2.0);
+  h2_dphi_deta->GetXaxis()->SetTitle("#Delta#phi");
+  h2_dphi_deta->GetYaxis()->SetTitle("#Delta#eta");
+  TotalNBins+=349*400;
+  
+  h2_dphi_deta_mix = new TH2F("h2_dphi_deta_mix","#Delta#phi vs #Delta#eta (mixed events)", 349,-1.5,5, 400,-2.0,2.0);
+  h2_dphi_deta_mix->GetXaxis()->SetTitle("#Delta#phi");
+  h2_dphi_deta_mix->GetYaxis()->SetTitle("#Delta#eta");
+  TotalNBins+=349*400;
+
+  h2_DispRes = new TH2F("h2_DispRes", "zvtx info", 500,-0.01,1, 500,-0.1,2);
+  h2_DispRes->GetXaxis()->SetTitle("EvtVtx->GetDispersion()");
+  h2_DispRes->GetYaxis()->SetTitle("EvtVtx->GetZRes()");
+  h2_DispRes->GetZaxis()->SetTitle("counts");
+  TotalNBins+=500*500;
+
+  h2_cells_M02 = new TH2F("h2_cells_M02", "nCells vs M02", 204,-1.5,100.5, 500,-1,1.5);
+  h2_cells_M02->GetXaxis()->SetTitle("nCells");
+  h2_cells_M02->GetYaxis()->SetTitle("M02");
+  h2_cells_M02->GetZaxis()->SetTitle("counts");
+  TotalNBins+=204*500;
+
+  cout << endl << "Total number of bins in booked histograms:  " << TotalNBins << endl << endl;
+
+  // Initialize helper class (for vertex selection & pile up correction)
+  fHelperClass = new AliAnalysisUtils();
+
+  //TFile *f = OpenFile(1); 
+  //TDirectory::TContext context(f);
+    
+  fOutput->Add(h1_nClusters);
+  fOutput->Add(h1_zvtx);
+  fOutput->Add(h1_trigger);
+  fOutput->Add(h1_M);
+  fOutput->Add(h1_M_mix);
+  fOutput->Add(h1_E);
+  fOutput->Add(h2_PhiEtaCluster);
+  fOutput->Add(h2_PhiEtaClusterCut);
+  fOutput->Add(h2_PhiEtaMaxCell);
+  fOutput->Add(h2_PhiEtaMaxCellCut);
+  fOutput->Add(h1_dR_ClustTrk);
+  fOutput->Add(h2_gE_RecTruth);
+  fOutput->Add(h2_eop_E);
+  fOutput->Add(h2_eop_pT);
+  fOutput->Add(h2_E_time);
+  fOutput->Add(h1_Pi0TruthPt);
+  fOutput->Add(h1_K0Pi0TruthPt);
+  fOutput->Add(h1_PriPi0TruthPt);
+  fOutput->Add(h1_PhysPi0TruthPt);
+  fOutput->Add(h1_Pi0TruthPtEmcal);
+  fOutput->Add(h1_K0Pi0TruthPtEmcal);
+  fOutput->Add(h1_PriPi0TruthPtEmcal);
+  fOutput->Add(h1_PhysPi0TruthPtEmcal);
+  fOutput->Add(h1_Pi0TruthPtPhi2piEta065);
+  fOutput->Add(h1_K0Pi0TruthPtPhi2piEta065);
+  fOutput->Add(h1_PriPi0TruthPtPhi2piEta065);
+  fOutput->Add(h1_PhysPi0TruthPtPhi2piEta065);
+  fOutput->Add(h1_Pi0TruthPtPhi2piEta1);
+  fOutput->Add(h1_K0Pi0TruthPtPhi2piEta1);
+  fOutput->Add(h1_PriPi0TruthPtPhi2piEta1);
+  fOutput->Add(h1_PhysPi0TruthPtPhi2piEta1);
+  fOutput->Add(h2_Pi0TruthPhiEta);
+  fOutput->Add(h2_PriPi0TruthPhiEta);
+  fOutput->Add(h2_Pi0TruthPhiEtaEmcal);
+  fOutput->Add(h2_PriPi0TruthPhiEtaEmcal);
+  fOutput->Add(h1_TruthPhotonsEmcal);
+  fOutput->Add(h2_TruthPhotonsPhiEta);
+  fOutput->Add(h1_PhotonsEmcal);
+  fOutput->Add(h1_PhotonsNCellsCut);
+  fOutput->Add(h1_PhotonsTrackMatchCut);
+  fOutput->Add(h1_PhotonsAllCut);
+  fOutput->Add(h2_PhotonsPhiEtaIsEmcal);
+  fOutput->Add(h1_dR_RealMC);
+  fOutput->Add(h2_Mpt_Pri);
+  fOutput->Add(h2_Mpt_Sec);
+  fOutput->Add(h3_MptR_Sec);
+  fOutput->Add(h3_MptR_K0s);
+  fOutput->Add(h3_MptR_Mat);
+  fOutput->Add(h2_PtR_MatM);
+  fOutput->Add(h2_Mpt_Pri_conv);
+  fOutput->Add(h2_Mpt_Sec_conv);
+  fOutput->Add(h3_MptR_Sec_conv);
+  fOutput->Add(h3_MptR_K0s_conv);
+  fOutput->Add(h3_MptR_Mat_conv);
+  fOutput->Add(h1_eConversionR);
+  fOutput->Add(h1_PriPi0Mother);
+  fOutput->Add(h1_SecPi0Mother);
+  fOutput->Add(h1_Chi2);
+  fOutput->Add(h1_nTrkMatch);
+  fOutput->Add(h1_ClusterDisp);
+  fOutput->Add(h2_Ellipse);
+  fOutput->Add(h2_EtaPt);
+  fOutput->Add(h3_MptAsymm);
+  fOutput->Add(h3_MptAsymm_mix);
+  fOutput->Add(h2_dphi_deta);
+  fOutput->Add(h2_dphi_deta_mix);
+  fOutput->Add(h2_DispRes);
+  fOutput->Add(h2_cells_M02);
+
+  // Post data for ALL output slots >0 here, 
+  // To get at least an empty histogram 
+  // 1 is the outputnumber of a certain weg of task 1  
+  PostData(1, fOutput); 
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEMCALMesonGGSDM::UserExec(Option_t *) 
+{
+  // Main loop Called for each event
+
+  AliMCEvent *mcEvent = MCEvent();  
+  Bool_t isMC = bool(mcEvent);//is this the right way to do this? 
+  
+  TRandom3 randy; randy.SetSeed(0);
+  unsigned int iskip = -1;
+  TLorentzVector ParentMix;
+
+  double recalScale = 1.0;
+
+  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();    
+  
+  AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (am->GetInputEventHandler());
+  AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (am->GetInputEventHandler());
+  if (!aodH && !esdH)  Printf("ERROR: Could not get ESD or AODInputHandler");
+  
+  if(esdH)      fEsdEv = esdH->GetEvent();    
+  else if(aodH) fAodEv = aodH->GetEvent();  
+  else{
+    AliFatal("Neither ESD nor AOD event found");
+    return;
+  }
+
+  // get pointer to reconstructed event
+  AliVEvent *event = InputEvent();
+  if (!event){
+    AliError("Pointer == 0, this can not happen!");  return;}
+  //AliESDEvent* fEsdEv = dynamic_cast<AliESDEvent*>(event);
+  //AliAODEvent* aod = dynamic_cast<AliAODEvent*>(event);
+  //if (!fEsdEv){
+  //AliError("Cannot get the ESD event");  return;}
+
+  /*
+  fHelperClass->SetCutOnZVertexSPD(kFALSE);//does the zvtx have to match the spd vertex? 
+  fHelperClass->SetMaxVtxZ(1.0e6);//i set this myself later.. 
+  // simply makes sure that there is at least 1 contributer to the zvtx determination.
+  // this should only remove the *extra* events at zvtx==0.
+  if(!fHelperClass->IsVertexSelected2013pA(event))
+    return;
+  */
+
+  Int_t iTrigger = 0;
+  if (fEsdEv)       iTrigger = fEsdEv->GetHeader()->GetL0TriggerInputs();
+  else if (fAodEv)  iTrigger = fAodEv->GetHeader()->GetL0TriggerInputs();
+  
+  char saythis[500];
+  Int_t iTriggerBin = 0;
+  for(unsigned long j=0; j<TriggerList.size(); j++){
+    if(iTrigger==TriggerList[j])
+      iTriggerBin=j+1;
+  }
+  if(iTriggerBin==0){
+    TriggerList.push_back(iTrigger);
+    iTriggerBin=TriggerList.size();
+  }
+  
+  h1_trigger->SetBinContent(iTriggerBin, h1_trigger->GetBinContent(iTriggerBin)+1);
+  sprintf(saythis,"%d",iTrigger);
+  h1_trigger->GetXaxis()->SetBinLabel(iTriggerBin, saythis);
+  
+  if(fEsdEv){
+    TString trigClasses = fEsdEv->GetFiredTriggerClasses();
+    // remove "fast cluster events": 
+    if (trigClasses.Contains("FAST")  && !trigClasses.Contains("ALL"))
+      return;
+  }
+  else if(fAodEv){
+    TString trigClasses = fAodEv->GetFiredTriggerClasses();
+    // remove "fast cluster events": 
+    if (trigClasses.Contains("FAST")  && !trigClasses.Contains("ALL"))
+      return;
+  }
+  
+  if (fEsdEv){
+    if(!(fEsdEv->GetPrimaryVertex()->GetStatus()))   return;
+  }
+  //else if (fAodEv){
+  //if(!(fAodEv->GetPrimaryVertex()->GetStatus()))   return;
+  //}
+
+  Double_t vertDisp=0.0;
+  Double_t vertZres=0.0;
+  Bool_t vertIsfromZ=0;
+  if (fEsdEv){
+    vertDisp    = fEsdEv->GetPrimaryVertex()->GetDispersion();
+    vertZres    = fEsdEv->GetPrimaryVertex()->GetZRes();
+    vertIsfromZ = fEsdEv->GetPrimaryVertex()->IsFromVertexerZ();
+  }
+  else if (fAodEv){
+    vertDisp    = 0;
+    vertZres    = 0;
+    vertIsfromZ = 0;
+  }
+
+  h2_DispRes->Fill(vertDisp, vertZres);  
+  // if vertex is from spd vertexZ, require more stringent cut
+  if (vertIsfromZ) {
+    if (vertDisp>0.02 ||  vertZres>0.25 ) 
+      return; // bad vertex from VertexerZ
+  }
+
+  
+  Int_t nclusters=0;
+  if(fEsdEv){
+    //Int_t evtN      = fEsdEv->GetEventNumberInFile();  
+    //Int_t ntracks   = fEsdEv->GetNumberOfTracks();
+    nclusters = fEsdEv->GetNumberOfCaloClusters();
+  }
+  else if(fAodEv){
+    //Int_t evtN      = fAodEv->GetEventNumberInFile();  
+    //Int_t ntracks   = fAodEv->GetNumberOfTracks();
+    nclusters = fAodEv->GetNumberOfCaloClusters();
+  }
+
+  // EMCal cluster loop for reconstructed event
+  //numberofclusters set above! 
+  TLorentzVector Photon1, Photon2, Parent;
+  Double_t vertex[3]; 
+  Double_t E1=0.0;
+  Double_t E2=0.0;
+  Double_t vertZ=0.0;
+  if (fEsdEv)       vertZ = fEsdEv->GetPrimaryVertex()->GetZ();
+  else if (fAodEv)  vertZ = fAodEv->GetPrimaryVertex()->GetZ();    
+
+  h1_zvtx->Fill(vertZ);
+  //zvertex cut:
+  if(fabs(vertZ)>10.0)
+    return;
+  
+  h1_nClusters->Fill(nclusters);
+
+  int izvtx = GetZvtxBin(vertZ);
+  int imult = GetMultBin(nclusters);
+  
+  //cout << iskip << " " << izvtx << " " << imult << endl;  
+  //cout << "GetNumberOfVertices(): " << fAodEv->GetNumberOfVertices() << endl;
+
+
+
+  //######################### ~~~~~~~~~~~ ##################################
+  //######################### STARTING MC ##################################
+  //######################### ~~~~~~~~~~~ ##################################
+  
+  if(isMC){
+    int isPrimary     = 0;
+    int isMaterialSec    = 0;
+    int isK0sDecay    = 0;
+
+    if (!mcEvent){
+      cout << "no MC event" << endl;
+      return;
+    }
+    
+    const AliVVertex *evtVtx = mcEvent->GetPrimaryVertex();
+    if (!evtVtx)
+      return;
+    
+    mcEvent->PreReadAll();    
+    
+    Int_t nTracksMC  = mcEvent->GetNumberOfTracks();
+    Int_t nPTracksMC = mcEvent->GetNumberOfPrimaries();
+    Int_t MyEMCPion = -1;
+    for (Int_t iTrack = 0; iTrack<nTracksMC; ++iTrack) {
+      AliMCParticle *mcP = static_cast<AliMCParticle*>(mcEvent->GetTrack(iTrack));
+      if (!mcP)
+       continue;
+      
+      if(iTrack<nPTracksMC)  isPrimary = 1;
+      else                   isPrimary = 0;
+      
+      isK0sDecay = 0;
+      if(mcP->GetMother()>-1){
+       if( ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() ==  310 ||
+           ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() == -310  )
+         isK0sDecay = 1;
+      }      
+      
+      // it's a pion !! 
+      if(mcP->PdgCode() != 111)
+       continue;
+       
+      MyEMCPion = 0;
+      if(strcmp(fMyMCType,"ANY")==0)
+       MyEMCPion = 1;
+      else if(IsMyMCHeaderType(iTrack, fMyMCType, mcEvent)){
+       //cout << "evtN: " << fEsdEv->GetEventNumberInFile() << "   i: " << iTrack << "    pdg: " << mcP->PdgCode() << "   pT: " << mcP->Pt() << endl;
+       //cout << "iTrack: " << iTrack << "   nPrimaryMC: " << nPTracksMC << "   nTracksMC: " << nTracksMC << endl;
+       MyEMCPion = 1;
+      }
+
+      //if(MyEMCPion)
+      //cout << "evtN: " << fEsdEv->GetEventNumberInFile() << "   i: " << iTrack << "    pdg: " << mcP->PdgCode() << "   pT: " << mcP->Pt() << endl;
+      //cout << "evtN: " << fEsdEv->GetEventNumberInFile() << "   i: " << iTrack << "    pdg: " << static_cast<AliMCParticle*>(mcEvent->GetTrack(iTrack+1))->PdgCode() << "   pT: " << mcP->Pt() << endl;
+      
+      if(MyEMCPion!=1 && isPrimary==1)
+       continue;
+      
+      
+      if(isPrimary==1 && mcP->GetMother()>-1)
+       h1_PriPi0Mother->Fill( ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() );
+      else if(isPrimary==0 && mcP->GetMother()>-1)
+       h1_SecPi0Mother->Fill( ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() );
+      
+      Int_t daughter[2] = {-1,-1};
+      daughter[0] = mcP->GetFirstDaughter();
+      daughter[1] = mcP->GetLastDaughter();
+      
+      if (daughter[0]<0)  continue;
+      if (daughter[1]<0)  daughter[1]=daughter[0];      
+      if (daughter[1]-daughter[0] != 1)  continue;
+      
+      Int_t eIndexofConvertedPhoton[2] = {-1,-1};
+
+      bool bacc = true;
+      bool binp = true;
+      Double_t eta_d[2] = {0.0,0.0};
+      Double_t phi_d[2] = {0.0,0.0};
+      for (Int_t daughter_index=0; daughter_index<2; daughter_index++){
+        const AliMCParticle *dmc = static_cast<const AliMCParticle *>(mcEvent->GetTrack(daughter[daughter_index]));
+       eta_d[daughter_index] = dmc->Eta();
+       phi_d[daughter_index] = dmc->Phi();
+        if(!(dmc->PdgCode()==22))        binp = false;
+        if(!(dmc->PdgCode()==22 && 
+            eta_d[daughter_index]>fEtamin && eta_d[daughter_index]<fEtamax && 
+            phi_d[daughter_index]>fPhimin && phi_d[daughter_index]<fPhimax))   bacc = false;   
+
+       if(dmc->GetFirstDaughter()>0 && dmc->GetLastDaughter()>0) {
+         // get the photons's daughters... 
+         const AliMCParticle *dmcd1 = static_cast<const AliMCParticle *>(mcEvent->GetTrack(dmc->GetFirstDaughter()));
+         const AliMCParticle *dmcd2 = static_cast<const AliMCParticle *>(mcEvent->GetTrack(dmc->GetLastDaughter()));
+         Double_t productionR1 = TMath::Sqrt(dmcd1->Xv()*dmcd1->Xv() + dmcd1->Yv()*dmcd1->Yv());
+         if(bacc)  h1_eConversionR->Fill(productionR1);
+         // check if this is a conversion... 
+         if( (dmcd1->PdgCode()== -1.0*dmcd2->PdgCode()) &&
+             (dmcd1->PdgCode()==11 || dmcd1->PdgCode()==-11) &&
+             productionR1<440.0){
+           //find the conv e with highest energy, assign it to be that photon decay product.
+           if( dmcd1->E() > dmcd2->E() )
+             eIndexofConvertedPhoton[daughter_index] = dmc->GetFirstDaughter();
+           else
+             eIndexofConvertedPhoton[daughter_index] = dmc->GetLastDaughter();
+         }
+       }
+      }
+
+      if(binp!=true)
+       continue;
+
+      // primary particle
+      //Double_t dR = TMath::Sqrt((mcP->Xv()-evtVtx->GetX())*(mcP->Xv()-evtVtx->GetX()) + 
+      //                          (mcP->Yv()-evtVtx->GetY())*(mcP->Yv()-evtVtx->GetY()));
+      //if(dR <= 0.01)  isPrimary = 1;
+      //else            isPrimary = 0;
+
+      isMaterialSec = 0;
+      if(isPrimary!=1){
+       if(((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() ==  2212 || //proton
+          ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() == -2212 || //anti-proton
+          ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() ==  2112 || //neutron
+          ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() == -2112 || //anti-neutron
+          ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() ==  321  || //K+
+          ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() == -321  || //K-
+          ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() ==  211  || //pi+
+          ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() == -211     //pi-
+          )
+         isMaterialSec = 1;
+      }
+
+      h1_Pi0TruthPt                  ->Fill(mcP->Pt());
+      if(isK0sDecay)  h1_K0Pi0TruthPt->Fill(mcP->Pt());
+      h2_Pi0TruthPhiEta->Fill(mcP->Phi(),mcP->Eta());
+      
+      if(isPrimary==1){
+       h1_PriPi0TruthPt    ->Fill(mcP->Pt());
+       h2_PriPi0TruthPhiEta->Fill(mcP->Phi(),mcP->Eta());
+      }
+      if(isPrimary!=1 && isMaterialSec!=1)   h1_PhysPi0TruthPt->Fill(mcP->Pt());
+     
+      if(mcP->Eta()<-1.0 || mcP->Eta()>1.0)
+       continue;
+      
+      h1_Pi0TruthPtPhi2piEta1         ->Fill(mcP->Pt());
+      if(isPrimary==1)
+       h1_PriPi0TruthPtPhi2piEta1    ->Fill(mcP->Pt());
+      if(isK0sDecay)      
+       h1_K0Pi0TruthPtPhi2piEta1     ->Fill(mcP->Pt());
+      if(isPrimary!=1 && isMaterialSec!=1)
+       h1_PhysPi0TruthPtPhi2piEta1   ->Fill(mcP->Pt());
+      
+      if(mcP->Eta()>fEtamin && mcP->Eta()<fEtamax){
+       h1_Pi0TruthPtPhi2piEta065       ->Fill(mcP->Pt());
+       if(isPrimary==1)
+         h1_PriPi0TruthPtPhi2piEta065  ->Fill(mcP->Pt());
+       if(isK0sDecay)      
+         h1_K0Pi0TruthPtPhi2piEta065   ->Fill(mcP->Pt());
+       if(isPrimary!=1 && isMaterialSec!=1)
+         h1_PhysPi0TruthPtPhi2piEta065 ->Fill(mcP->Pt());
+      }      
+      
+      
+      if(binp && bacc){// 2 Photons hit the EMCAL! 
+       
+       Int_t Nfoundphotons = 0;
+       Int_t iFoundphotons[10] = {0,0,0,0,0,0,0,0,0,0};
+       Int_t Nfoundelectrons = 0;
+       Int_t iFoundelectrons[10] = {0,0,0,0,0,0,0,0,0,0};
+       for (Int_t daughter_index=0; daughter_index<2; daughter_index++){//both truth photons. (also includes conversions..)
+         
+         const AliMCParticle *dmc = static_cast<const AliMCParticle *>(mcEvent->GetTrack(daughter[daughter_index]));
+         
+         h1_TruthPhotonsEmcal->Fill(dmc->Pt());
+         h2_TruthPhotonsPhiEta->Fill(dmc->Phi(),dmc->Eta());
+         
+         for(int i=0; i<nclusters; i++) {          
+           Bool_t matches_pion_photon = 0;
+           
+           AliESDCaloCluster* esdCluster=NULL;
+           AliAODCaloCluster* aodCluster=NULL;
+           if (fEsdEv)       esdCluster = fEsdEv->GetCaloCluster(i); // pointer to EMCal cluster
+           else if (fAodEv)  aodCluster = fAodEv->GetCaloCluster(i); // pointer to EMCal cluster
+
+           Double_t clustMC_phi, clustMC_eta;
+
+           if(fEsdEv){
+
+             if(esdCluster->IsEMCAL()){
+               
+               Float_t pos[3] = {0,0,0};
+               esdCluster->GetPosition(pos);
+               TVector3 vpos(pos);
+               //h1_Phi->Fill(vpos.Phi());
+               clustMC_phi = vpos.Phi();
+               clustMC_eta = vpos.Eta();
+               
+               Double_t dR = TMath::Sqrt((eta_d[daughter_index]-clustMC_eta)*(eta_d[daughter_index]-clustMC_eta) + 
+                                         (phi_d[daughter_index]-clustMC_phi)*(phi_d[daughter_index]-clustMC_phi));
+               h1_dR_RealMC->Fill(dR);
+               matches_pion_photon = 0;
+               //if(dR<=0.04) matches_pion_photon = 1;
+               
+
+               TArrayI *TruthLabelsA = esdCluster->GetLabelsArray();
+               if(TruthLabelsA){
+                 Int_t trackindex = TruthLabelsA->At(0);
+                 if( trackindex==daughter[daughter_index] ){
+                   matches_pion_photon = 1;
+                   iFoundphotons[Nfoundphotons] = i;
+                   Nfoundphotons++;
+                 }
+                 else if( trackindex==eIndexofConvertedPhoton[daughter_index] ){
+                   iFoundelectrons[Nfoundelectrons] = i;
+                   Nfoundelectrons++;
+                 }
+                 AliMCParticle *truthP = (AliMCParticle*)(mcEvent->GetTrack(trackindex));
+                 
+                 if(matches_pion_photon){
+                   
+                   h1_PhotonsEmcal->Fill(esdCluster->E());
+                   h2_PhotonsPhiEtaIsEmcal->Fill(clustMC_phi,clustMC_eta);
+                   if(esdCluster->GetNCells()>=2)
+                     h1_PhotonsNCellsCut->Fill(esdCluster->E());
+                   if(esdCluster->GetNTracksMatched()==0)
+                     h1_PhotonsTrackMatchCut->Fill(esdCluster->E());
+                   if(esdCluster->GetNCells()>=2 && esdCluster->GetNTracksMatched()==0)
+                     h1_PhotonsAllCut->Fill(esdCluster->E());            
+                   
+                   if(esdCluster->GetNCells()>=2){
+                     recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);                      
+                     h2_gE_RecTruth->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()));
+                   }
+                 }//if(matches_pion_photon)
+                 
+               }//if Truthlabels exists
+               vpos.Delete();
+             }//if(IsEMCAL())
+             
+           }//if(fEsdEv)
+           else if(fAodEv){
+             
+             if(aodCluster->IsEMCAL()){
+               
+               Float_t pos[3] = {0,0,0};
+               aodCluster->GetPosition(pos);  
+               TVector3 vpos(pos); 
+               //h1_Phi->Fill(vpos.Phi());
+               clustMC_phi = vpos.Phi();
+               clustMC_eta = vpos.Eta();
+               
+               Double_t dR = TMath::Sqrt((eta_d[daughter_index]-clustMC_eta)*(eta_d[daughter_index]-clustMC_eta) + 
+                                         (phi_d[daughter_index]-clustMC_phi)*(phi_d[daughter_index]-clustMC_phi));
+               h1_dR_RealMC->Fill(dR);
+               matches_pion_photon = 0;
+               if(dR<=0.04) matches_pion_photon = 1;
+               
+               //TArrayI *TruthLabelsA = aodCluster->GetLabelsArray();
+               //if(TruthLabelsA){
+               //  Int_t trackindex = TruthLabelsA->At(0);
+               //  if( trackindex==daughter[daughter_index] )
+               //    matches_pion_photon = 1;
+               //  AliMCParticle *truthP = (AliMCParticle*)(mcEvent->GetTrack(trackindex));
+                                                 
+               if(matches_pion_photon){                
+                 
+                 h1_PhotonsEmcal->Fill(aodCluster->E());
+                 h2_PhotonsPhiEtaIsEmcal->Fill(clustMC_phi,clustMC_eta);
+                 if(aodCluster->GetNCells()>=2)
+                   h1_PhotonsNCellsCut->Fill(aodCluster->E());
+                 if(aodCluster->GetNTracksMatched()==0)
+                   h1_PhotonsTrackMatchCut->Fill(aodCluster->E());
+                 if(aodCluster->GetNCells()>=2 && aodCluster->GetNTracksMatched()==0)
+                   h1_PhotonsAllCut->Fill(aodCluster->E());              
+                 
+                 //if(aodCluster->GetNCells()>=2){
+                 //recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);                        
+                 //h2_gE_RecTruth->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()));
+                 //}
+               }//if(matches_pion_photon)
+               
+               //}//if Truthlabels exists
+               vpos.Delete();
+             }//if(IsEMCAL())        
+             
+           }//if(fAodEv)
+           
+         }//loop over nclusters. 
+         
+       }//both truth photons.
+
+       if(Nfoundphotons>1){
+         AliESDCaloCluster* esdCluster1 = fEsdEv->GetCaloCluster(iFoundphotons[0]); // pointer to EMCal cluster
+         AliESDCaloCluster* esdCluster2 = fEsdEv->GetCaloCluster(iFoundphotons[1]); // pointer to EMCal cluster
+
+         if( isGoodEsdCluster(esdCluster1) && isGoodEsdCluster(esdCluster2) ){
+
+           recalScale = PrivateEnergyRecal(esdCluster1->E(), fRecalibrator);
+           E1 = esdCluster1->E()*recalScale;// TOTAL HACK - JJ
+           fEsdEv->GetVertex()->GetXYZ(vertex);
+           esdCluster1->GetMomentum(Photon1,vertex);
+           Photon1.SetPx(Photon1.Px()*recalScale);// TOTAL HACK - JJ
+           Photon1.SetPy(Photon1.Py()*recalScale);// TOTAL HACK - JJ
+           Photon1.SetPz(Photon1.Pz()*recalScale);// TOTAL HACK - JJ
+
+           recalScale = PrivateEnergyRecal(esdCluster2->E(), fRecalibrator);
+           E2 = esdCluster2->E()*recalScale;// TOTAL HACK - JJ
+           fEsdEv->GetVertex()->GetXYZ(vertex);
+           esdCluster2->GetMomentum(Photon2,vertex);
+           Photon2.SetPx(Photon2.Px()*recalScale);// TOTAL HACK - JJ
+           Photon2.SetPy(Photon2.Py()*recalScale);// TOTAL HACK - JJ
+           Photon2.SetPz(Photon2.Pz()*recalScale);// TOTAL HACK - JJ
+
+           Parent =  TLorentzVector(Photon1.Px(),Photon1.Py(),Photon1.Pz(),E1) + TLorentzVector(Photon2.Px(),Photon2.Py(),Photon2.Pz(),E2);
+                 
+           //double productionR = TMath::Sqrt( mcP->Xv()*mcP->Xv() + mcP->Yv()*mcP->Yv() );
+           Double_t productionR = TMath::Sqrt((mcP->Xv()-evtVtx->GetX())*(mcP->Xv()-evtVtx->GetX()) + 
+                                              (mcP->Yv()-evtVtx->GetY())*(mcP->Yv()-evtVtx->GetY()));
+           if(isPrimary==1){
+             //cout << "Primary production vertex: " << productionR << endl;
+             h2_Mpt_Pri->Fill(Parent.M(),Parent.Pt());
+           }
+           else{
+             //cout << "Secondary production vertex: " << productionR << endl;
+             h2_Mpt_Sec ->Fill(Parent.M(),Parent.Pt());            
+             h3_MptR_Sec->Fill(Parent.M(),Parent.Pt(),productionR);
+             if(isK0sDecay)
+               h3_MptR_K0s->Fill(Parent.M(),Parent.Pt(),productionR);
+             if(isMaterialSec)
+               h3_MptR_Mat->Fill(Parent.M(),Parent.Pt(),productionR);
+           }
+         }//both good clusters
+       }//found 2 photons.
+       else if(Nfoundphotons==1){
+         int mergedPion = 0;
+         AliESDCaloCluster* esdCluster1 = fEsdEv->GetCaloCluster(iFoundphotons[0]); // pointer to EMCal cluster
+         
+         TArrayI *TruthLabelsA = esdCluster1->GetLabelsArray();
+         if(TruthLabelsA){
+           if(TruthLabelsA->GetSize()>1){
+             Int_t trackindex[2];
+             trackindex[0] = TruthLabelsA->At(0);
+             trackindex[1] = TruthLabelsA->At(1);
+             if( (trackindex[0]==daughter[0] && trackindex[1]==daughter[1]) ||
+                 (trackindex[0]==daughter[1] && trackindex[1]==daughter[0]) ){
+               mergedPion = 1;
+             }
+             if(mergedPion==1){
+               recalScale = PrivateEnergyRecal(esdCluster1->E(), fRecalibrator);
+               E1 = esdCluster1->E()*recalScale;// TOTAL HACK - JJ
+               Double_t productionR = TMath::Sqrt((mcP->Xv()-evtVtx->GetX())*(mcP->Xv()-evtVtx->GetX()) + 
+                                                  (mcP->Yv()-evtVtx->GetY())*(mcP->Yv()-evtVtx->GetY()));
+               h2_PtR_MatM->Fill(E1,productionR);
+             }//if merged pion.
+           }//truthlabel.size > 1
+         }//if truthlabels
+       }// Nfoundphotons==1
+
+       if(Nfoundphotons==1 && Nfoundelectrons==1){
+         AliESDCaloCluster* esdCluster1 = fEsdEv->GetCaloCluster(iFoundphotons[0]); // pointer to EMCal cluster
+         AliESDCaloCluster* esdCluster2 = fEsdEv->GetCaloCluster(iFoundelectrons[0]); // pointer to EMCal cluster
+
+         if( isGoodEsdCluster(esdCluster1) && isGoodEsdCluster(esdCluster2) ){
+
+           recalScale = PrivateEnergyRecal(esdCluster1->E(), fRecalibrator);
+           E1 = esdCluster1->E()*recalScale;// TOTAL HACK - JJ
+           fEsdEv->GetVertex()->GetXYZ(vertex);
+           esdCluster1->GetMomentum(Photon1,vertex);
+           Photon1.SetPx(Photon1.Px()*recalScale);// TOTAL HACK - JJ
+           Photon1.SetPy(Photon1.Py()*recalScale);// TOTAL HACK - JJ
+           Photon1.SetPz(Photon1.Pz()*recalScale);// TOTAL HACK - JJ
+
+           recalScale = PrivateEnergyRecal(esdCluster2->E(), fRecalibrator);
+           E2 = esdCluster2->E()*recalScale;// TOTAL HACK - JJ
+           fEsdEv->GetVertex()->GetXYZ(vertex);
+           esdCluster2->GetMomentum(Photon2,vertex);
+           Photon2.SetPx(Photon2.Px()*recalScale);// TOTAL HACK - JJ
+           Photon2.SetPy(Photon2.Py()*recalScale);// TOTAL HACK - JJ
+           Photon2.SetPz(Photon2.Pz()*recalScale);// TOTAL HACK - JJ
+
+           Parent =  TLorentzVector(Photon1.Px(),Photon1.Py(),Photon1.Pz(),E1) + TLorentzVector(Photon2.Px(),Photon2.Py(),Photon2.Pz(),E2);
+                 
+           //double productionR = TMath::Sqrt( mcP->Xv()*mcP->Xv() + mcP->Yv()*mcP->Yv() );
+           Double_t productionR = TMath::Sqrt((mcP->Xv()-evtVtx->GetX())*(mcP->Xv()-evtVtx->GetX()) + 
+                                              (mcP->Yv()-evtVtx->GetY())*(mcP->Yv()-evtVtx->GetY()));
+           if(isPrimary==1){
+             //cout << "Primary production vertex: " << productionR << endl;
+             h2_Mpt_Pri_conv->Fill(Parent.M(),Parent.Pt());
+           }
+           else{
+             //cout << "Secondary production vertex: " << productionR << endl;
+             h2_Mpt_Sec_conv ->Fill(Parent.M(),Parent.Pt());       
+             h3_MptR_Sec_conv->Fill(Parent.M(),Parent.Pt(),productionR);
+             if(isK0sDecay)
+               h3_MptR_K0s_conv->Fill(Parent.M(),Parent.Pt(),productionR);
+             if(isMaterialSec)
+               h3_MptR_Mat_conv->Fill(Parent.M(),Parent.Pt(),productionR);
+           }
+         }//both good clusters
+       }// Nfoundphotons==1 && Nfoundelectrons==1
+       else if(Nfoundelectrons==2){
+         AliESDCaloCluster* esdCluster1 = fEsdEv->GetCaloCluster(iFoundelectrons[0]); // pointer to EMCal cluster
+         AliESDCaloCluster* esdCluster2 = fEsdEv->GetCaloCluster(iFoundelectrons[1]); // pointer to EMCal cluster
+
+         if( isGoodEsdCluster(esdCluster1) && isGoodEsdCluster(esdCluster2) ){
+
+           recalScale = PrivateEnergyRecal(esdCluster1->E(), fRecalibrator);
+           E1 = esdCluster1->E()*recalScale;// TOTAL HACK - JJ
+           fEsdEv->GetVertex()->GetXYZ(vertex);
+           esdCluster1->GetMomentum(Photon1,vertex);
+           Photon1.SetPx(Photon1.Px()*recalScale);// TOTAL HACK - JJ
+           Photon1.SetPy(Photon1.Py()*recalScale);// TOTAL HACK - JJ
+           Photon1.SetPz(Photon1.Pz()*recalScale);// TOTAL HACK - JJ
+
+           recalScale = PrivateEnergyRecal(esdCluster2->E(), fRecalibrator);
+           E2 = esdCluster2->E()*recalScale;// TOTAL HACK - JJ
+           fEsdEv->GetVertex()->GetXYZ(vertex);
+           esdCluster2->GetMomentum(Photon2,vertex);
+           Photon2.SetPx(Photon2.Px()*recalScale);// TOTAL HACK - JJ
+           Photon2.SetPy(Photon2.Py()*recalScale);// TOTAL HACK - JJ
+           Photon2.SetPz(Photon2.Pz()*recalScale);// TOTAL HACK - JJ
+
+           Parent =  TLorentzVector(Photon1.Px(),Photon1.Py(),Photon1.Pz(),E1) + TLorentzVector(Photon2.Px(),Photon2.Py(),Photon2.Pz(),E2);
+                 
+           //double productionR = TMath::Sqrt( mcP->Xv()*mcP->Xv() + mcP->Yv()*mcP->Yv() );
+           Double_t productionR = TMath::Sqrt((mcP->Xv()-evtVtx->GetX())*(mcP->Xv()-evtVtx->GetX()) + 
+                                              (mcP->Yv()-evtVtx->GetY())*(mcP->Yv()-evtVtx->GetY()));
+           if(isPrimary==1){
+             //cout << "Primary production vertex: " << productionR << endl;
+             h2_Mpt_Pri_conv->Fill(Parent.M(),Parent.Pt());
+           }
+           else{
+             //cout << "Secondary production vertex: " << productionR << endl;
+             h2_Mpt_Sec_conv ->Fill(Parent.M(),Parent.Pt());       
+             h3_MptR_Sec_conv->Fill(Parent.M(),Parent.Pt(),productionR);
+             if(isK0sDecay)
+               h3_MptR_K0s_conv->Fill(Parent.M(),Parent.Pt(),productionR);
+             if(isMaterialSec)
+               h3_MptR_Mat_conv->Fill(Parent.M(),Parent.Pt(),productionR);
+           }
+         }//both good clusters
+       }// Nfoundelectrons==2
+       
+       h1_Pi0TruthPtEmcal    ->Fill(mcP->Pt());
+       if(isK0sDecay)
+         h1_K0Pi0TruthPtEmcal    ->Fill(mcP->Pt());
+       h2_Pi0TruthPhiEtaEmcal->Fill(mcP->Phi(),mcP->Eta());    
+       
+       if(isPrimary==1){
+         h1_PriPi0TruthPtEmcal    ->Fill(mcP->Pt());
+         h2_PriPi0TruthPhiEtaEmcal->Fill(mcP->Phi(),mcP->Eta());
+       }
+       if(isPrimary!=1 && isMaterialSec!=1)   h1_PhysPi0TruthPtEmcal->Fill(mcP->Pt());
+       
+       
+      }// 2 Photons hit the EMCAL! 
+      
+    }//for(nTracksMC)    
+    
+  }//if(isMC)
+  
+  //######################### ~~~~~~~~~~~~ ##################################
+  //######################### DONE WITH MC ##################################
+  //######################### ~~~~~~~~~~~~ ##################################
+  
+
+  for(int i=0; i<nclusters; i++) {
+    
+    AliESDCaloCluster* esdCluster=NULL;
+    AliAODCaloCluster* aodCluster=NULL;
+    if (fEsdEv)       esdCluster = fEsdEv->GetCaloCluster(i); // pointer to EMCal cluster
+    else if (fAodEv)  aodCluster = fAodEv->GetCaloCluster(i); // pointer to EMCal cluster
+    if(!esdCluster && !aodCluster) { 
+      AliError(Form("ERROR: Could not retrieve any (ESD or AOD) Cluster %d",i)); 
+      continue; 
+    }
+            
+    if(fEsdEv){
+      
+      recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+
+      //uncomment this to do the track matching (1 of 3 lines, esd part)!! 
+      //Bool_t MatchesToTrack = 0;
+      if(esdCluster->IsEMCAL()){
+       
+       Float_t pos[3] = {0,0,0};
+       Short_t maxCellID = -1;
+       Float_t celleta, cellphi;
+       esdCluster->GetPosition(pos);
+       TVector3 clusterPosition(pos);
+       h2_PhiEtaCluster->Fill(clusterPosition.Phi(),clusterPosition.Eta());
+       GetMaxCellEnergy(esdCluster, maxCellID);
+       AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance();
+       fGeom->EtaPhiFromIndex(maxCellID,celleta,cellphi);
+       h2_PhiEtaMaxCell->Fill(cellphi,celleta);
+       
+       // _______________Track loop for reconstructed event_____________
+       for(Int_t itrk = 0; itrk < fEsdEv->GetNumberOfTracks(); itrk++) {
+         AliESDtrack* esdTrack = fEsdEv->GetTrack(itrk); // pointer to reconstructed to track
+         if(!esdTrack) { 
+           AliError(Form("ERROR: Could not retrieve any (ESD) track %d",itrk)); 
+           continue; 
+         }
+         
+         Double_t posTrk[3] = {0,0,0};
+         esdTrack->GetXYZ(posTrk);
+         TVector3 vposTrk(posTrk);
+         
+         Double_t fMass          = 0.139;
+         Double_t fStepSurface   = 20.;
+         Float_t etaproj, phiproj, pttrackproj;
+         
+         AliExternalTrackParam *trackParam =  const_cast<AliExternalTrackParam*>(esdTrack->GetInnerParam());
+         if(!trackParam) continue;
+         AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(trackParam, 440., fMass, fStepSurface, etaproj, phiproj, pttrackproj);
+         
+         double dR_clusttrk = sqrt((phiproj-clusterPosition.Phi())*(phiproj-clusterPosition.Phi()) + 
+                                   (etaproj-clusterPosition.Eta())*(etaproj-clusterPosition.Eta()) );
+         
+         h1_dR_ClustTrk->Fill(dR_clusttrk);
+         
+         //uncomment this to do the track matching (2 of 3 lines, esd part)!! 
+         //if(dR_clusttrk<fdRmin_ClustTrack)
+         //MatchesToTrack = 1;
+         
+       }//_____________________________nTracks__________________________
+       
+       h2_cells_M02  ->Fill(esdCluster->GetNCells(),esdCluster->GetM02());
+       h2_Ellipse    ->Fill(esdCluster->GetM20(),esdCluster->GetM02());
+       h1_Chi2       ->Fill(esdCluster->Chi2());//always -1. 
+       h1_nTrkMatch  ->Fill(esdCluster->GetNTracksMatched());
+       h1_ClusterDisp->Fill(esdCluster->GetDispersion());
+       h2_E_time     ->Fill(esdCluster->E(),esdCluster->GetTOF());
+       
+       TArrayI *TrackLabels = esdCluster->GetTracksMatched();
+       if(TrackLabels){
+         if(TrackLabels->GetSize()>0){
+           Int_t trackindex = TrackLabels->At(0);
+           AliESDtrack* matchingT = fEsdEv->GetTrack(trackindex); // pointer to reconstructed to track
+           
+           recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+           h2_eop_E ->Fill(esdCluster->E()*recalScale, esdCluster->E()*recalScale/matchingT->P());
+           h2_eop_pT->Fill(matchingT->Pt(),            esdCluster->E()*recalScale/matchingT->P());
+         }
+       }
+
+       //uncomment this to do the track matching (2 of 3 lines, esd part)!! 
+       //if(isGoodEsdCluster(esdCluster) && !MatchesToTrack){
+       if(isGoodEsdCluster(esdCluster)){
+         recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+         E1 = esdCluster->E()*recalScale;// TOTAL HACK - JJ
+         fEsdEv->GetVertex()->GetXYZ(vertex);
+         esdCluster->GetMomentum(Photon1,vertex);
+         Photon1.SetPx(Photon1.Px()*recalScale);// TOTAL HACK - JJ
+         Photon1.SetPy(Photon1.Py()*recalScale);// TOTAL HACK - JJ
+         Photon1.SetPz(Photon1.Pz()*recalScale);// TOTAL HACK - JJ
+         Photons[0][izvtx][imult].push_back( TLorentzVector(Photon1.Px(),Photon1.Py(),Photon1.Pz(),E1) );
+         h1_E->Fill(E1);
+         h2_PhiEtaClusterCut->Fill(clusterPosition.Phi(),clusterPosition.Eta());
+         h2_PhiEtaMaxCellCut->Fill(cellphi,celleta);
+       }
+       clusterPosition.Delete();
+      }//if(esdCluster->isEMCAL())
+    }//if(fEsdEv)
+    else if(fAodEv){
+      
+      recalScale = PrivateEnergyRecal(aodCluster->E(), fRecalibrator);
+            
+      //uncomment this to do the track matching (1 of 3 lines, aod part)!! 
+      //Bool_t MatchesToTrack = 0;
+      if(aodCluster->IsEMCAL()){
+
+       Float_t pos[3] = {0,0,0};
+       Short_t maxCellID = -1;
+       Float_t celleta, cellphi;
+       aodCluster->GetPosition(pos);  
+       TVector3 clusterPosition(pos); 
+       h2_PhiEtaCluster->Fill(clusterPosition.Phi(),clusterPosition.Eta());
+       GetMaxCellEnergy(aodCluster, maxCellID);
+       AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance();
+       fGeom->EtaPhiFromIndex(maxCellID,celleta,cellphi);
+       h2_PhiEtaMaxCell->Fill(cellphi,celleta);
+
+       // _______________Track loop for reconstructed event_____________
+       for(Int_t itrk = 0; itrk < fAodEv->GetNumberOfTracks(); itrk++) {
+         AliAODTrack* aodTrack = fAodEv->GetTrack(itrk); // pointer to reconstructed to track
+         if(!aodTrack) { 
+           AliError(Form("ERROR: Could not retrieve any (AOD) track %d",itrk)); 
+           continue; 
+         }
+
+         Double_t posTrk[3] = {0,0,0};
+         Double_t momTrk[3] = {0,0,0};
+         aodTrack->GetXYZ(posTrk);
+         aodTrack->GetPxPyPz(momTrk);
+         //TVector3 vposTrk(posTrk);
+         
+         //####################################################################################################          
+         //
+         // commented all this stuff just to satisfy aliroot warnings. 
+         // but I may need it again if I want to do the track matching for aods. 
+         /*
+         Double_t fMass          = 0.139;
+         Double_t fStepSurface   = 20.;
+         Float_t etaproj=0.0;
+         Float_t phiproj=0.0;
+         Float_t pttrackproj=0.0;
+
+         Double_t cv[21] = {0.0};        
+         aodTrack->GetCovarianceXYZPxPyPz(cv);
+         AliExternalTrackParam *trackParam = new AliExternalTrackParam(posTrk,momTrk,cv,aodTrack->Charge());     
+         //AliExternalTrackParam emcalParam(*trackParam);
+         //AliExternalTrackParam *trackParam =  const_cast<AliExternalTrackParam*>(aodTrack->GetInnerParam());
+         if(!trackParam) continue;
+         ////AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(trackParam, 440., fMass, fStepSurface, etaproj, phiproj, pttrackproj);
+         //AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&emcalParam, 440., fMass, fStepSurface, etaproj, phiproj, pttrackproj);
+         delete trackParam;
+
+         //Constantin's implementation... gives funny result. 
+         //AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(aodTrack,440.0);
+         //phiproj = aodTrack->GetTrackPhiOnEMCal();
+         //etaproj = aodTrack->GetTrackPhiOnEMCal();
+         
+         double dR_clusttrk = sqrt((phiproj-clusterPosition.Phi())*(phiproj-clusterPosition.Phi()) + 
+                                   (etaproj-clusterPosition.Eta())*(etaproj-clusterPosition.Eta()) );
+
+         h1_dR_ClustTrk->Fill(dR_clusttrk);
+         */
+         //####################################################################################################
+
+         //uncomment this to do the track matching (2 of 3 lines, aod part)!! 
+         //if(dR_clusttrk<fdRmin_ClustTrack)
+         //MatchesToTrack = 1;
+                 
+
+       }//_____________________________nTracks__________________________
+
+       h2_cells_M02  ->Fill(aodCluster->GetNCells(),aodCluster->GetM02());
+       h2_Ellipse    ->Fill(aodCluster->GetM20(),aodCluster->GetM02());
+       h1_Chi2       ->Fill(aodCluster->Chi2());//always -1. 
+       h1_nTrkMatch  ->Fill(aodCluster->GetNTracksMatched());
+       h1_ClusterDisp->Fill(aodCluster->GetDispersion());
+       h2_E_time     ->Fill(aodCluster->E(),aodCluster->GetTOF());
+
+       // #################################################
+       // track matching eop histograms are handled here... 
+       // #################################################
+      
+       //uncomment this to do the track matching (3 of 3 lines, aod part)!! 
+       //if(isGoodAodCluster(aodCluster) && !MatchesToTrack){
+       if(isGoodAodCluster(aodCluster)){
+         recalScale = PrivateEnergyRecal(aodCluster->E(), fRecalibrator);
+         E1 = aodCluster->E()*recalScale;// TOTAL HACK - JJ
+         fAodEv->GetVertex(0)->GetXYZ(vertex);
+         aodCluster->GetMomentum(Photon1,vertex);
+         Photon1.SetPx(Photon1.Px()*recalScale);// TOTAL HACK - JJ
+         Photon1.SetPy(Photon1.Py()*recalScale);// TOTAL HACK - JJ
+         Photon1.SetPz(Photon1.Pz()*recalScale);// TOTAL HACK - JJ
+         Photons[0][izvtx][imult].push_back( TLorentzVector(Photon1.Px(),Photon1.Py(),Photon1.Pz(),E1) );
+         h1_E->Fill(E1);
+         h2_PhiEtaClusterCut->Fill(clusterPosition.Phi(),clusterPosition.Eta());
+         h2_PhiEtaMaxCellCut->Fill(cellphi,celleta);     
+       }
+       clusterPosition.Delete();
+      }//if(aodCluster->IsEMCAL())
+    }//if(fAodEv)
+    
+  }//loop over nclusters. 
+  
+  //Make same event pions... 
+  for(unsigned int i=0; i<Photons[0][izvtx][imult].size(); i++){
+    for(unsigned int j=i+1; j<Photons[0][izvtx][imult].size(); j++){
+      Parent = Photons[0][izvtx][imult][i] + Photons[0][izvtx][imult][j];
+      Double_t deltaphi = getDeltaPhi(Photons[0][izvtx][imult][i],Photons[0][izvtx][imult][j]);
+      Double_t deltaeta = getDeltaEta(Photons[0][izvtx][imult][i],Photons[0][izvtx][imult][j]);
+      Double_t pairasym = fabs(Photons[0][izvtx][imult][i].Pt()-Photons[0][izvtx][imult][j].Pt())/
+                             (Photons[0][izvtx][imult][i].Pt()+Photons[0][izvtx][imult][j].Pt());
+      Int_t asymCut = 0;
+      if     (pairasym<0.1)  asymCut = 1;
+      else if(pairasym<0.7)  asymCut = 2;
+      else                   asymCut = 3;
+      
+      h1_M        ->Fill(Parent.M());
+      h3_MptAsymm ->Fill(Parent.M(),Parent.Pt(),asymCut);
+      h2_dphi_deta->Fill(deltaphi,deltaeta);
+    }
+  }
+  
+  //Make mixed event...
+  for(unsigned int i=0; i<Photons[0][izvtx][imult].size(); i++){
+    for(unsigned int ipool=1; ipool<poolDepth; ipool++){
+      for(unsigned int j=0; j<Photons[ipool][izvtx][imult].size(); j++){
+       iskip = randy.Integer(Photons[0][izvtx][imult].size());
+       if(j==iskip) continue;
+       Parent = Photons[0][izvtx][imult][i]+Photons[ipool][izvtx][imult][j];
+       Double_t deltaphi = getDeltaPhi(Photons[0][izvtx][imult][i],Photons[ipool][izvtx][imult][j]);
+       Double_t deltaeta = getDeltaEta(Photons[0][izvtx][imult][i],Photons[ipool][izvtx][imult][j]);
+       Double_t pairasym = fabs(Photons[0][izvtx][imult][i].Pt()-Photons[ipool][izvtx][imult][j].Pt())/
+                               (Photons[0][izvtx][imult][i].Pt()+Photons[ipool][izvtx][imult][j].Pt());
+       Int_t asymCut = 0;
+       if     (pairasym<0.1)  asymCut = 1;
+       else if(pairasym<0.7)  asymCut = 2;
+       else                   asymCut = 3;
+
+       h1_M_mix        ->Fill(Parent.M());
+       h3_MptAsymm_mix ->Fill(Parent.M(),Parent.Pt(),asymCut);
+       h2_dphi_deta_mix->Fill(deltaphi,deltaeta);
+      }
+    }
+  } 
+    
+  for(int ipool=poolDepth-1; ipool>0; ipool--){
+    Photons[ipool][izvtx][imult].clear();
+    for(unsigned int i=0; i<Photons[ipool-1][izvtx][imult].size(); i++)
+      Photons[ipool][izvtx][imult].push_back(Photons[ipool-1][izvtx][imult][i]);     
+  }
+  Photons[0][izvtx][imult].clear();
+    
+
+  
+  // NEW HISTO should be filled before this point, as PostData puts the
+  // information for this iteration of the UserExec in the container
+  PostData(1, fOutput);
+  }
+
+//________________________________________________________________________
+void AliAnalysisTaskEMCALMesonGGSDM::Terminate(Option_t *) //specify what you want to have done
+{
+  // Called once at the end of the query.
+  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDM::GetZvtxBin(Double_t vertZ)
+{
+  
+  int izvtx = -1;
+  
+  if     (vertZ<-35)
+    izvtx=0;
+  else if(vertZ<-30)
+    izvtx=1;
+  else if(vertZ<-25)
+    izvtx=2;
+  else if(vertZ<-20)
+    izvtx=3;
+  else if(vertZ<-15)
+    izvtx=4;
+  else if(vertZ<-10)
+    izvtx=5;
+  else if(vertZ< -5)
+    izvtx=6;
+  else if(vertZ<  0)
+    izvtx=7;
+  else if(vertZ<  5)
+    izvtx=8;
+  else if(vertZ< 10)
+    izvtx=9;
+  else if(vertZ< 15)
+    izvtx=10;
+  else if(vertZ< 20)
+    izvtx=11;
+  else if(vertZ< 25)
+    izvtx=12;
+  else if(vertZ< 30)
+    izvtx=13;
+  else if(vertZ< 35)
+    izvtx=14;
+  else
+    izvtx=15;
+  
+  return izvtx;  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDM::GetMultBin(Int_t mult){
+
+  int imult = -1;
+  
+  if     (mult<2)
+    imult=0;
+  else if(mult<25)
+    imult=mult-2;
+  else
+    imult=24;
+  
+  return imult;  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDM::isGoodEsdCluster(AliESDCaloCluster* esdclust){
+
+  int pass = 1;
+  int nMinCells  = 2;
+  double MinE    = 0.4;
+  //double MinErat = 0;
+  //double MinEcc  = 0;
+  
+  if (!esdclust)
+    pass = 0;    
+  if (!esdclust->IsEMCAL()) 
+    pass = 0;
+  if (esdclust->E()<MinE)
+    pass = 0;
+  if (esdclust->GetNCells()<nMinCells)
+    pass = 0;
+  //if (GetMaxCellEnergy(esdclust)/esdclust->E()<MinErat)
+  //pass = 0;
+  //if (esdclust->Chi2()<MinEcc) // eccentricity cut
+  //pass = 0;//this is always -1.
+    
+  //if(esdclust->GetM02()<0.1)
+  //  pass = 0;
+  //if(esdclust->GetM02()>0.5)
+  //  pass = 0;
+
+  Float_t pos[3] = {0,0,0};
+  esdclust->GetPosition(pos);
+  TVector3 clusterPosition(pos);
+  if(clusterPosition.Eta()<fEtamin || clusterPosition.Eta()>fEtamax || 
+     clusterPosition.Phi()<fPhimin || clusterPosition.Phi()>fPhimax  )
+    pass = 0;
+  clusterPosition.Delete();
+  
+  //DOING THIS BY HAND NOW... 
+  //if(!esdclust->GetNTracksMatched()==0)
+  //pass = 0;
+  
+  return pass;
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDM::isGoodAodCluster(AliAODCaloCluster* aodclust){
+
+  int pass = 1;
+  int nMinCells  = 2;
+  double MinE    = 0.4;
+  //double MinErat = 0;
+  //double MinEcc  = 0;
+  
+  if (!aodclust)
+    pass = 0;    
+  if (!aodclust->IsEMCAL()) 
+    pass = 0;
+  if (aodclust->E()<MinE)
+    pass = 0;
+  if (aodclust->GetNCells()<nMinCells)
+    pass = 0;
+  //if (GetMaxCellEnergy(aodclust)/aodclust->E()<MinErat)
+  //pass = 0;
+  //if (aodclust->Chi2()<MinEcc) // eccentricity cut
+  //pass = 0;//this is always -1.
+    
+  //if(aodclust->GetM02()<0.1)
+  //pass = 0;
+  //if(aodclust->GetM02()>0.5)
+  //pass = 0;
+  
+  Float_t pos[3] = {0,0,0};
+  aodclust->GetPosition(pos);
+  TVector3 clusterPosition(pos);
+  if(clusterPosition.Eta()<fEtamin || clusterPosition.Eta()>fEtamax || 
+     clusterPosition.Phi()<fPhimin || clusterPosition.Phi()>fPhimax  )
+    pass = 0;
+  clusterPosition.Delete();
+  
+  //DOING THIS BY HAND NOW... 
+  //if(!aodclust->GetNTracksMatched()==0)
+  //pass = 0;
+  
+  return pass;
+}
+//________________________________________________________________________
+Double_t AliAnalysisTaskEMCALMesonGGSDM::getDeltaPhi(TLorentzVector p1, TLorentzVector p2){
+
+  double dphi = p1.Phi() - p2.Phi();
+
+  if(dphi<0.5*TMath::Pi())  
+    dphi = dphi + 2.0*TMath::Pi();
+
+  if(dphi>1.5*TMath::Pi())  
+    dphi = dphi - 2.0*TMath::Pi();
+
+  return dphi;
+}
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskEMCALMesonGGSDM::getDeltaEta(TLorentzVector p1, TLorentzVector p2){
+
+  double deta = p1.PseudoRapidity() - p2.PseudoRapidity();
+
+  return deta;
+}
+
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskEMCALMesonGGSDM::PrivateEnergyRecal(Double_t energy, Int_t iCalib){
+
+  double recalibfactor = 0.0;
+
+  if(iCalib==0){// no recalibration! 
+    recalibfactor = 1.0;
+  }
+  else if(iCalib==1){// just a scale factor: 
+    recalibfactor = 0.984;
+  }
+  else if(iCalib==2){// Symmetric Decay Fit - corrects data to uncorrected MC. 
+    Double_t p[3] = {0.96968, -2.68720, -0.831607};
+    recalibfactor = p[0] + exp(p[1] + p[2]*energy*2.0);
+  }
+  else if(iCalib==3){// Jason's fit to the LHC12f1a MC single photons - 04 Aug 2013 (call it kPi0MCv4??)
+    Double_t p[7] = {1.00000e+00, 3.04925e-02, 4.69043e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.00046e+00};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==4){// Jason's fit to the test beam data - 04 Aug 2013(call it kBTCv3??)
+    Double_t p[7] = {9.78672e-01, 2.39745e-01, 6.41199e-01, 9.13538e-02, 1.46058e+02, 1.99469e+01, 9.72716e-01};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==5){// Based on kSDM/kTBCv3 (call it kPi0MCv4??)
+    Double_t p[10] = {9.78672e-01, 2.39745e-01, 6.41199e-01, 9.13538e-02, 1.46058e+02, 1.99469e+01, 9.72716e-01, 0.96968, -2.68720, -0.831607};
+    recalibfactor = ( (p[6]/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5]))))) ) / ( p[7] + exp(p[8] + p[9]*energy/2.0) );
+  }
+  else if(iCalib==6){// kBeamTestCorrectedv2 - in AliROOT! 
+    Double_t p[7] = {9.83504e-01, 2.10106e-01, 8.97274e-01, 8.29064e-02, 1.52299e+02, 3.15028e+01, 0.968};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==7){// kPi0MCv3 - in AliROOT! 
+    Double_t p[7] = {9.81039e-01, 1.13508e-01, 1.00173e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.0};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==8){// Jason's fit to the noNL MC/data- based on kSDM and kPi0MCv5 - 28 Oct 2013 (call it... ??)
+    Double_t p[10] = {1.0, 6.64778e-02, 1.57000e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.01286, 0.964, -3.132, -0.435};
+    //Double_t p[10] = {1.0, 6.64778e-02, 1.57000e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.01286, 0.96968, -2.68720, -0.831607};//same SDM piece as iCalib==2
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5]))))) * (p[7] + exp(p[8]+p[9]*energy*2.0));
+  }
+  else if(iCalib==9){// Jason's fit to the LHC12f1a/b MC single photons (above 400MeV), including conversions - 28 Oct 2013 (call it kPi0MCv5??)
+    Double_t p[7] = {1.0, 6.64778e-02, 1.57000e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.01286};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==10){// Jason played with test beam data
+    Double_t p[7] = {1.0, 0.237767, 0.651203, 0.183741, 155.427, 17.0335, 0.987054};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==11){// Jason played with test beam MC
+    Double_t p[7] = {1.0, 0.0797873, 1.68322, 0.0806098, 244.586, 116.938, 1.00437};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+
+  return recalibfactor;
+}
+
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskEMCALMesonGGSDM::GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const
+{
+  // Get maximum energy of attached cell.
+
+  id = -1;
+  AliVCaloCells *fVCells=NULL;
+  if(fEsdEv)      fVCells = fEsdEv->GetEMCALCells();
+  else if(fAodEv) fVCells = fAodEv->GetEMCALCells();
+  if(!fVCells)
+    return 0;
+  
+  Double_t maxe = 0;
+  Int_t ncells = cluster->GetNCells();
+  for (Int_t i=0; i<ncells; i++) {
+    Double_t e = fVCells->GetCellAmplitude(TMath::Abs(cluster->GetCellAbsId(i)));
+    if (e>maxe) {
+      maxe = e;
+      id   = cluster->GetCellAbsId(i);
+    }
+  }
+  return maxe;
+}
+
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDM::IsPhysPrimJ(AliMCEvent *mcEvent, Int_t iTrack){
+
+  AliMCParticle *mcP  = static_cast<AliMCParticle*>(mcEvent->GetTrack(iTrack));
+  
+  Int_t nPTracks= mcEvent->GetNumberOfPrimaries();
+  
+  Int_t isPhysPrimary   = 1;
+  Int_t ismHF           = 0;
+  Int_t ismLongLivedOrK = 0;
+
+  if(mcP->GetMother()<0)//if it has no mother... 
+    return isPhysPrimary;
+  
+  Int_t imTrack = mcP->GetMother();
+  AliMCParticle *mcPm = static_cast<AliMCParticle*>(mcEvent->GetTrack(imTrack));
+  
+  if( TMath::Abs(mcPm->PdgCode())<10 )//if mother is a single quark...
+    return isPhysPrimary;
+  
+
+  //############################################
+  //get the PDG digits.... 
+  int num = mcPm->PdgCode();
+  int RevDigits[10] = {0};
+  int nDigits = 0;  
+  while (num >= 1){
+    RevDigits[nDigits++] = num%10;
+    num = num / 10;
+  }
+  //##############################################
+
+
+  if(RevDigits[3]>3)//Baryons
+    ismHF = 1;
+  else if(RevDigits[2]>3)//Mesons
+    ismHF = 1;
+  
+  ismLongLivedOrK = IsLongLivedOrK(mcPm->PdgCode());
+  
+  if(!ismHF && ismLongLivedOrK)
+    isPhysPrimary = 0;
+  else{ // check grandmother, greatgrandmothers, etc... 
+    while(imTrack >= nPTracks){
+
+      if(mcPm->GetMother()<0)//if it has no mother... 
+       break;
+      
+      if( TMath::Abs(mcPm->PdgCode()<10) )//if mother is a single quark...
+       return isPhysPrimary;
+      
+      imTrack = mcPm->GetMother();
+      mcPm = static_cast<AliMCParticle*>(mcEvent->GetTrack(imTrack));      
+      
+      //############################################
+      //get the PDG digits.... 
+      num = mcPm->PdgCode();
+      for(int i=0; i<10; i++)  RevDigits[i] = 0;
+      nDigits = 0;  
+      while (num >= 1){
+       RevDigits[nDigits++] = num%10;
+       num = num / 10;
+      }
+      //##############################################
+      if(RevDigits[3]>3)//Baryons
+       ismHF = 1;
+      else if(RevDigits[2]>3)//Mesons
+       ismHF = 1;
+      
+      ismLongLivedOrK = IsLongLivedOrK(mcPm->PdgCode());
+      
+      if(!ismHF && ismLongLivedOrK)
+       isPhysPrimary = 0;
+      
+    }//while( >=nPTracks)
+  }
+  
+  return isPhysPrimary;
+}
+
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDM::IsLongLivedOrK(Int_t MyPDGcode){
+
+  Int_t MyFlag = 0;
+
+  if(
+     (TMath::Abs(MyPDGcode) == 22  ) ||        // Photon
+     (TMath::Abs(MyPDGcode) == 11  ) ||        // Electron
+     (TMath::Abs(MyPDGcode) == 13  ) ||        // Muon(-) 
+     (TMath::Abs(MyPDGcode) == 211 ) ||        // Pion
+     (TMath::Abs(MyPDGcode) == 321 ) ||        // Kaon
+     (TMath::Abs(MyPDGcode) == 310 ) ||        // K0s
+     (TMath::Abs(MyPDGcode) == 130 ) ||        // K0l
+     (TMath::Abs(MyPDGcode) == 2212) ||        // Proton 
+     (TMath::Abs(MyPDGcode) == 2112) ||        // Neutron
+     (TMath::Abs(MyPDGcode) == 3122) ||        // Lambda_0
+     (TMath::Abs(MyPDGcode) == 3112) ||        // Sigma Minus
+     (TMath::Abs(MyPDGcode) == 3222) ||        // Sigma Plus
+     (TMath::Abs(MyPDGcode) == 3312) ||        // Xsi Minus 
+     (TMath::Abs(MyPDGcode) == 3322) ||        // Xsi 
+     (TMath::Abs(MyPDGcode) == 3334) ||        // Omega
+     (TMath::Abs(MyPDGcode) == 12  ) ||        // Electron Neutrino 
+     (TMath::Abs(MyPDGcode) == 14  ) ||        // Muon Neutrino
+     (TMath::Abs(MyPDGcode) == 16  )   )       // Tau Neutrino
+    MyFlag = 1;
+
+  return MyFlag; 
+}
+
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDM::IsMyMCHeaderType(Int_t iTrack, char *MyType, AliMCEvent *mcEvent) const
+{
+
+  Int_t isMyType = 0;
+
+  AliGenCocktailEventHeader *cocktail = dynamic_cast<AliGenCocktailEventHeader *>(mcEvent->GenEventHeader());
+  if(!cocktail)
+    return 0;
+
+  TList *genHeaders = cocktail->GetHeaders();
+  
+  Int_t nGenerators = genHeaders->GetEntries();
+  Int_t indexMyType = -1;
+  Int_t startParticle=0;
+
+  for(Int_t igen = 0; igen < nGenerators; igen++){
+    AliGenEventHeader* eventHeader2 = (AliGenEventHeader*)genHeaders->At(igen) ;
+    TString name = eventHeader2->GetName();
+    startParticle += eventHeader2->NProduced();
+    //cout << name << endl;
+    if (name.Contains(MyType,TString::kIgnoreCase)){
+      indexMyType = igen;
+      startParticle -= eventHeader2->NProduced();
+      break;
+    }
+  }
+
+  AliGenEventHeader *addedPi0Header = (AliGenEventHeader*)genHeaders->At(indexMyType);
+  Int_t ipi0min = startParticle;
+  Int_t ipi0max = ipi0min+addedPi0Header->NProduced()-1;
+  if(iTrack >= ipi0min && iTrack <= ipi0max)
+    isMyType = 1;
+  
+  return isMyType; 
+}
+
+
diff --git a/PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDM.h b/PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDM.h
new file mode 100644 (file)
index 0000000..a52151b
--- /dev/null
@@ -0,0 +1,164 @@
+#ifndef ALIANALYSISTASKEMCALMESONGGSDM_H
+#define ALIANALYSISTASKEMCALMESONGGSDM_H
+
+class TF1;
+class TH1F;
+class TH2F;
+class TH3F;
+class TH1D;
+class TH2D;
+class TH3D;
+class TNtuple;
+class TList;
+class AliESDEvent;
+class AliAODEvent;
+class AliESDtrackCuts;
+class AliESDCaloCluster;
+class AliAODCaloCluster;
+class AliMCEvent;
+class AliMCParticle;
+class AliEMCALGeometry;
+
+#ifndef ALIANALYSISTASKSE_H
+#include "AliAnalysisTaskSE.h"
+#endif
+#include "AliAnalysisUtils.h"
+
+class AliAnalysisTaskEMCALMesonGGSDM : public AliAnalysisTaskSE {
+ public:
+  AliAnalysisTaskEMCALMesonGGSDM();
+  AliAnalysisTaskEMCALMesonGGSDM(const char *name);
+  virtual ~AliAnalysisTaskEMCALMesonGGSDM();
+    
+  virtual void     UserCreateOutputObjects();
+  virtual void     UserExec(Option_t *option);
+  virtual void     Terminate(Option_t *);
+    
+  void         SetMcMode(Bool_t b)                 { fMcMode       = b;             }
+  void         SetRecalScheme(Int_t kRecalibrator) { fRecalibrator = kRecalibrator; }
+  void         SetMyMCType(char *kMyMCType)        { fMyMCType     = kMyMCType; }
+  void         SetdRmin_ClustTrack(Double_t kdRmin_ClustTrack)    { fdRmin_ClustTrack = kdRmin_ClustTrack; }
+  void         SetFidPhiMinMax(Double_t kPhimin, Double_t kPhimax){ fPhimin = kPhimin; fPhimax = kPhimax; }
+  void         SetFidEtaMinMax(Double_t kEtamin, Double_t kEtamax){ fEtamin = kEtamin; fEtamax = kEtamax; }
+  
+ private:
+  static const int zvtx_bins = 16;
+  static const int mult_bins = 25;
+  static const unsigned int poolDepth = 20;
+  
+  Int_t GetMultBin(Int_t mult);
+  Int_t GetZvtxBin(Double_t vertZ);
+  Int_t isGoodEsdCluster(AliESDCaloCluster* esdclust);
+  Int_t isGoodAodCluster(AliAODCaloCluster* aodclust);
+  Double_t getDeltaPhi(TLorentzVector p1, TLorentzVector p2);
+  Double_t getDeltaEta(TLorentzVector p1, TLorentzVector p2);
+  Double_t PrivateEnergyRecal(Double_t energy, Int_t iCalib);
+  Double_t GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const;
+  Int_t IsPhysPrimJ(AliMCEvent *mcEvent, Int_t iTrack);
+  Int_t IsLongLivedOrK(Int_t MyPDGcode);
+  Int_t IsMyMCHeaderType(Int_t iTrack, char *MyType, AliMCEvent *mcEvent) const;
+
+  TList           *fOutput;        //! Output list
+  Bool_t           fMcMode;                 // monte carlo mode
+  char            *fMyMCType;               // monte carlo primary particles
+  Int_t            fRecalibrator;           // custom recalibrator? 
+  Double_t         fdRmin_ClustTrack; // Cuts. 
+  Double_t         fPhimin;           // Cuts. 
+  Double_t         fPhimax;           // Cuts. 
+  Double_t         fEtamin;           // Cuts. 
+  Double_t         fEtamax;           // Cuts. 
+  AliESDtrackCuts *fTrackCuts;              // Track cuts
+  AliESDEvent     *fEsdEv;                  //!pointer to input esd event
+  AliAODEvent     *fAodEv;                  //!pointer to input aod event
+  TH1F            *h1_nClusters;  //!  # of clusters/evt
+  TH1F            *h1_zvtx;  //!  # of clusters/evt
+  TH1F            *h1_trigger;  //!  # of clusters/evt
+  TH1F            *h1_M;        //!  Mass spectrum
+  TH1F            *h1_M_mix;    //!  Mass spectrum
+  TH1F            *h1_E;        //!  energy spectrum
+  TH2F            *h2_PhiEtaCluster;        //!  phi vs eta for the cluster CoG
+  TH2F            *h2_PhiEtaClusterCut;     //!  phi vs eta for the cluster CoG w/ cuts
+  TH2F            *h2_PhiEtaMaxCell;        //!  phi vs eta for the maximum cell
+  TH2F            *h2_PhiEtaMaxCellCut;     //!  phi vs eta for the maximum cell w/ cuts
+  TH1F            *h1_dR_ClustTrk;        //!  Track Matching
+  TH2F            *h2_gE_RecTruth; //! gamma E, rec/truth, first bin is primaries, second is non-primaries
+  TH2F            *h2_eop_E;        //!  e over p vs E. simple
+  TH2F            *h2_eop_pT;        //!  e over p vs pT. simple
+  TH2F            *h2_E_time;        //!  cluster energy vs time.
+  
+  TH1F            *h1_Pi0TruthPt;        //!  Pt spectrum from MC! 
+  TH1F            *h1_K0Pi0TruthPt;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PriPi0TruthPt;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhysPi0TruthPt;        //!  Pt spectrum from MC! 
+
+  TH1F            *h1_Pi0TruthPtEmcal;        //!  Pt spectrum from MC! 
+  TH1F            *h1_K0Pi0TruthPtEmcal;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PriPi0TruthPtEmcal;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhysPi0TruthPtEmcal;        //!  Pt spectrum from MC! 
+
+  TH1F            *h1_Pi0TruthPtPhi2piEta065;        //!  Pt spectrum from MC! 
+  TH1F            *h1_K0Pi0TruthPtPhi2piEta065;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PriPi0TruthPtPhi2piEta065;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhysPi0TruthPtPhi2piEta065;        //!  Pt spectrum from MC! 
+
+  TH1F            *h1_Pi0TruthPtPhi2piEta1;        //!  Pt spectrum from MC!   
+  TH1F            *h1_K0Pi0TruthPtPhi2piEta1;        //!  Pt spectrum from MC!   
+  TH1F            *h1_PriPi0TruthPtPhi2piEta1;        //!  Pt spectrum from MC!   
+  TH1F            *h1_PhysPi0TruthPtPhi2piEta1;        //!  Pt spectrum from MC!   
+
+  TH2F            *h2_Pi0TruthPhiEta;    //!  etaphi spectrum from MC! 
+  TH2F            *h2_PriPi0TruthPhiEta;    //!  etaphi spectrum from MC! 
+  TH2F            *h2_Pi0TruthPhiEtaEmcal;    //!  etaphi spectrum from MC! 
+  TH2F            *h2_PriPi0TruthPhiEtaEmcal;    //!  etaphi spectrum from MC! 
+
+  TH1F            *h1_TruthPhotonsEmcal;        //!  Pt spectrum from MC! 
+  TH2F            *h2_TruthPhotonsPhiEta;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhotonsEmcal;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhotonsNCellsCut;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhotonsTrackMatchCut;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhotonsAllCut;        //!  Pt spectrum from MC! 
+  TH2F            *h2_PhotonsPhiEtaIsEmcal;        //!  Pt spectrum from MC! 
+
+  TH1F            *h1_dR_RealMC;        //!  Pt spectrum from MC! 
+  TH2F            *h2_Mpt_Pri;       //!  2dimensional mass vs mom primary pions
+  TH2F            *h2_Mpt_Sec;       //!  2dimensional mass vs mom secondary pions
+  TH3F            *h3_MptR_Sec;       //!  2dimensional mass vs production radius, secondary pions
+  TH3F            *h3_MptR_K0s;       //!  2dimensional mass vs production radius, K0s pions
+  TH3F            *h3_MptR_Mat;       //!  2dimensional mass vs production radius, pions from material
+  TH2F            *h2_PtR_MatM;       //!  2dimensional pt vs production radius, pions from material (that merged). pi mass assumed.
+  TH2F            *h2_Mpt_Pri_conv;       //!  2dimensional mass vs mom primary pions
+  TH2F            *h2_Mpt_Sec_conv;       //!  2dimensional mass vs mom secondary pions
+  TH3F            *h3_MptR_Sec_conv;       //!  2dimensional mass vs production radius, secondary pions
+  TH3F            *h3_MptR_K0s_conv;       //!  2dimensional mass vs production radius, K0s pions
+  TH3F            *h3_MptR_Mat_conv;       //!  2dimensional mass vs production radius, pions from material
+  TH1F            *h1_eConversionR;        //!  conversion point (radius)
+  TH1F            *h1_PriPi0Mother;       //!  the parent ID of every sec pi0 mother
+  TH1F            *h1_SecPi0Mother;       //!  the parent ID of every pri pi0 mother
+
+  TH1F            *h1_Chi2;       //!  pseudorapidity spectrum
+  TH1F            *h1_nTrkMatch;       //!  pseudorapidity spectrum
+  TH1F            *h1_nCells;       //!  pseudorapidity spectrum
+  TH1F            *h1_ClusterDisp;       //!  cluster dispersion
+  TH2F            *h2_Ellipse;       //!  ellipse axis?
+  TH2F            *h2_EtaPt;       //!  2d histogram Y - pseudorap spectrum
+  TH3F            *h3_MptAsymm;       //!  2dimensional E vs mom
+  TH3F            *h3_MptAsymm_mix;       //!  2dimensional E vs mom
+  TH2F            *h2_dphi_deta;       //!  2dimensional E vs mom
+  TH2F            *h2_dphi_deta_mix;       //!  2dimensional E vs mom
+  TH2F            *h2_DispRes;       //!  2dimensional E vs mom
+  TH2F            *h2_cells_M02;       //!  
+
+  //AliPIDCombined *fPIDCombined; // for E/p
+  //AliPIDResponse *fPIDResponse; // for E/p
+
+  std::vector<TLorentzVector> Photons[poolDepth][zvtx_bins][mult_bins]; //!
+  std::vector<Int_t> TriggerList; //!
+  
+  AliAnalysisUtils*   fHelperClass;           //! Vertex selection helper
+
+  AliAnalysisTaskEMCALMesonGGSDM(const AliAnalysisTaskEMCALMesonGGSDM&); // not implemented
+  AliAnalysisTaskEMCALMesonGGSDM& operator=(const AliAnalysisTaskEMCALMesonGGSDM&); // not implemented
+    
+  ClassDef(AliAnalysisTaskEMCALMesonGGSDM, 1); // example of analysis
+};
+#endif
diff --git a/PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDMpPb.cxx b/PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDMpPb.cxx
new file mode 100644 (file)
index 0000000..efef542
--- /dev/null
@@ -0,0 +1,1664 @@
+#include "AliAnalysisTaskEMCALMesonGGSDMpPb.h"
+
+// ROOT includes
+#include <vector>
+#include <Riostream.h>
+#include <TChain.h>
+#include <TTree.h>
+#include <TF1.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TH3F.h>
+#include <TH1D.h>
+#include <TH2D.h>
+#include <TH3D.h>
+#include <TCanvas.h>
+#include <TList.h>
+#include <TFile.h>
+#include <TLorentzVector.h>
+#include <TNtuple.h>
+#include <TRandom3.h>
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TGeoBBox.h>
+#include <TArrayI.h>
+#include <TArrayF.h>
+#include <TObjArray.h>
+
+// STEER? includes
+#include "AliAnalysisTaskSE.h"
+#include "AliAnalysisManager.h"
+#include "AliVCluster.h"
+#include "AliVCaloCells.h"
+#include "AliLog.h"
+#include "AliPID.h"
+#include "AliStack.h"
+#include "AliESDtrack.h"
+#include "AliESDtrackCuts.h"
+#include "AliESDEvent.h"
+#include "AliAODEvent.h"
+#include "AliMCEvent.h"
+#include "AliInputEventHandler.h"
+#include "AliESDInputHandler.h"
+#include "AliAODInputHandler.h"
+#include "AliAODTrack.h"
+#include "AliExternalTrackParam.h"
+#include "AliESDfriendTrack.h"
+#include "AliTrackerBase.h"
+
+// EMCAL includes
+#include "AliEMCALRecoUtils.h"
+#include "AliEMCALGeometry.h"
+#include "AliTrackerBase.h"
+#include "AliEMCALCalibTimeDepCorrection.h" // Run dependent
+#include "AliEMCALPIDUtils.h"
+#include "AliExternalTrackParam.h"
+
+#include "AliCentrality.h"
+
+
+
+
+ClassImp(AliAnalysisTaskEMCALMesonGGSDMpPb)
+
+//________________________________________________________________________
+AliAnalysisTaskEMCALMesonGGSDMpPb::AliAnalysisTaskEMCALMesonGGSDMpPb() : 
+  AliAnalysisTaskSE(),
+  fOutput(0),
+  fMcMode(0),
+  fRecalibrator(0),
+  fdRmin_ClustTrack(0),
+  fPhimin(0),
+  fPhimax(0),
+  fEtamin(0),
+  fEtamax(0),
+  fTrackCuts(0),
+  fEsdEv(0),
+  fAodEv(0),
+  h1_zvtx(0), 
+  h1_trigger(0), 
+  h1_centrality(0), 
+  h2_PhiEtaCluster(0), 
+  h2_PhiEtaClusterCut(0), 
+  h2_PhiEtaMaxCell(0), 
+  h2_PhiEtaMaxCellCut(0), 
+  h2_gE_RecTruth(0), 
+  h2_eop_E(0),
+  h2_eop_pT(0),
+  h2_E_time(0),
+  h2_Pi0TruthPhiEta(0), 
+  h2_PriPi0TruthPhiEta(0), 
+  h2_Pi0TruthPhiEtaEmcal(0), 
+  h2_PriPi0TruthPhiEtaEmcal(0), 
+  h2_Pi0TruthPhiEta_Phi2piEta065(0), 
+  h2_Pi0TruthPhiEta_Phi2piEta1(0), 
+  h2_TruthPhotonsPhiEta(0),
+  h2_PhotonsPhiEtaIsEmcal(0),
+  TriggerList(0),
+  fHelperClass(0)
+{
+  // Dummy constructor ALWAYS needed for I/O.
+  for(int i=0; i<cent_bins; i++){
+    h1_nClusters[i] = 0;
+    h1_M[i] = 0;
+    h1_M_mix[i] = 0;
+    h1_E[i] = 0;
+    h1_dR_ClustTrk[i] = 0;
+    h1_Pi0TruthPt[i] = 0;
+    h1_PriPi0TruthPt[i] = 0;
+    h1_Pi0TruthPtEmcal[i] = 0;
+    h1_PriPi0TruthPtEmcal[i] = 0;
+    h1_Pi0TruthPtPhi2piEta065[i] = 0;
+    h1_Pi0TruthPtPhi2piEta1[i] = 0;
+    h1_TruthPhotonsEmcal[i] = 0;
+    h1_PhotonsEmcal[i] = 0;
+    h1_PhotonsNCellsCut[i] = 0;
+    h1_PhotonsTrackMatchCut[i] = 0;
+    h1_PhotonsAllCut[i] = 0;
+    h1_dR_RealMC[i] = 0;
+    h1_Chi2[i] = 0;
+    h1_nTrkMatch[i] = 0;
+    h1_nCells[i] = 0;
+    h1_ClusterDisp[i] = 0;
+    h2_Ellipse[i] = 0;
+    h2_EtaPt[i] = 0;
+    h3_MptAsymm[i] = 0;
+    h3_MptAsymm_mix[i] = 0;
+    h2_dphi_deta[i] = 0;
+    h2_dphi_deta_mix[i] = 0;
+    h2_DispRes[i] = 0;
+    h2_cells_M02[i] = 0;
+  }
+}
+
+//________________________________________________________________________
+AliAnalysisTaskEMCALMesonGGSDMpPb::AliAnalysisTaskEMCALMesonGGSDMpPb(const char *name) :
+  AliAnalysisTaskSE(name),
+  fOutput(0),
+  fMcMode(0),
+  fRecalibrator(0),
+  fdRmin_ClustTrack(0),
+  fPhimin(0),
+  fPhimax(0),
+  fEtamin(0),
+  fEtamax(0),
+  fTrackCuts(0),
+  fEsdEv(0),
+  fAodEv(0),
+  h1_zvtx(0), 
+  h1_trigger(0), 
+  h1_centrality(0), 
+  h2_PhiEtaCluster(0), 
+  h2_PhiEtaClusterCut(0), 
+  h2_PhiEtaMaxCell(0), 
+  h2_PhiEtaMaxCellCut(0), 
+  h2_gE_RecTruth(0), 
+  h2_eop_E(0),
+  h2_eop_pT(0),
+  h2_E_time(0),
+  h2_Pi0TruthPhiEta(0), 
+  h2_PriPi0TruthPhiEta(0), 
+  h2_Pi0TruthPhiEtaEmcal(0), 
+  h2_PriPi0TruthPhiEtaEmcal(0), 
+  h2_Pi0TruthPhiEta_Phi2piEta065(0), 
+  h2_Pi0TruthPhiEta_Phi2piEta1(0), 
+  h2_TruthPhotonsPhiEta(0),
+  h2_PhotonsPhiEtaIsEmcal(0),
+  TriggerList(0),
+  fHelperClass(0)
+{
+  // Constructor
+  // Define input and output slots here (never in the dummy constructor)
+  // Input slot #0 works with a TChain - it is connected to the default input container
+  // Output slot #1 writes into a TH1 container
+  DefineOutput(1, TList::Class());                                            // for output list
+  for(int i=0; i<cent_bins; i++){
+    h1_nClusters[i] = 0;
+    h1_M[i] = 0;
+    h1_M_mix[i] = 0;
+    h1_E[i] = 0;
+    h1_dR_ClustTrk[i] = 0;
+    h1_Pi0TruthPt[i] = 0;
+    h1_PriPi0TruthPt[i] = 0;
+    h1_Pi0TruthPtEmcal[i] = 0;
+    h1_PriPi0TruthPtEmcal[i] = 0;
+    h1_Pi0TruthPtPhi2piEta065[i] = 0;
+    h1_Pi0TruthPtPhi2piEta1[i] = 0;
+    h1_TruthPhotonsEmcal[i] = 0;
+    h1_PhotonsEmcal[i] = 0;
+    h1_PhotonsNCellsCut[i] = 0;
+    h1_PhotonsTrackMatchCut[i] = 0;
+    h1_PhotonsAllCut[i] = 0;
+    h1_dR_RealMC[i] = 0;
+    h1_Chi2[i] = 0;
+    h1_nTrkMatch[i] = 0;
+    h1_nCells[i] = 0;
+    h1_ClusterDisp[i] = 0;
+    h2_Ellipse[i] = 0;
+    h2_EtaPt[i] = 0;
+    h3_MptAsymm[i] = 0;
+    h3_MptAsymm_mix[i] = 0;
+    h2_dphi_deta[i] = 0;
+    h2_dphi_deta_mix[i] = 0;
+    h2_DispRes[i] = 0;
+    h2_cells_M02[i] = 0;
+  }
+}
+
+//________________________________________________________________________
+AliAnalysisTaskEMCALMesonGGSDMpPb::~AliAnalysisTaskEMCALMesonGGSDMpPb()
+{
+  // Destructor. Clean-up the output list, but not the histograms that are put inside
+  // (the list is owner and will clean-up these histograms). Protect in PROOF case.
+  if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
+    delete fOutput;
+  }
+  delete fTrackCuts;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEMCALMesonGGSDMpPb::UserCreateOutputObjects()
+{
+  // Create histograms
+  // Called once (on the worker node)
+
+  fOutput = new TList();
+  fOutput->SetOwner();  // IMPORTANT!
+   
+  fTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE);
+
+  cout << "__________AliAnalysisTaskEMCALMesonGGSDMpPb: Input settings__________" << endl;
+  cout << " fMcMode:             " << fMcMode   << endl;
+  cout << " fRecalibrator:       " << fRecalibrator << endl;
+  cout << " dRmin_ClustTrack:    " << fdRmin_ClustTrack << endl;
+  cout << " phi range:           " << fPhimin << ", " << fPhimax << endl;
+  cout << " eta range:           " << fEtamin << ", " << fEtamax << endl;
+  cout << " number of zvtx bins: " << zvtx_bins << endl;
+  cout << " number of mult bins: " << mult_bins << endl;
+  cout << " poolDepth:           " << poolDepth << endl;
+  cout << endl;
+  
+  char saythis1[500];
+  char saythis2[500];
+
+  double TotalNBins = 0.0;
+
+  // Create histograms
+  Int_t nClustersbins = 501;
+  Float_t nClusterslow = -0.5, nClustersup = 500.5;
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_nClusters_%d",i);
+    sprintf(saythis2,"# of clusters");
+    h1_nClusters[i] = new TH1F(saythis1, saythis2, nClustersbins, nClusterslow, nClustersup);
+    h1_nClusters[i]->GetXaxis()->SetTitle("number of clusters/evt");
+    h1_nClusters[i]->GetYaxis()->SetTitle("counts");
+    h1_nClusters[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=nClustersbins;
+  }
+  
+  Int_t nZvertexbins = 501;
+  Float_t Zvertexlow = -50.0, Zvertexup = 50.0;
+  h1_zvtx = new TH1F("h1_zvtx", "# of clusters", nZvertexbins, Zvertexlow, Zvertexup);
+  h1_zvtx->GetXaxis()->SetTitle("z_{vertex}");
+  h1_zvtx->GetYaxis()->SetTitle("counts");
+  h1_zvtx->SetMarkerStyle(kFullCircle);
+  TotalNBins+=nZvertexbins;
+
+  h1_trigger = new TH1F("h1_trigger", "trigger number returned", 1001,-0.5,1000.5);
+  TotalNBins+=1001;
+
+  h1_centrality = new TH1F("h1_centrality", "centrality", 1001,-0.1,100.1);
+  TotalNBins+=1001;
+
+  Int_t Mbins = 3000;
+  Float_t Mlow = 0.0, Mup = 3.0;
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_M_%d",i);
+    sprintf(saythis2,"Invariant Mass");
+    h1_M[i] = new TH1F(saythis1, saythis2, Mbins, Mlow, Mup);
+    h1_M[i]->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+    h1_M[i]->GetYaxis()->SetTitle("counts");
+    h1_M[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=Mbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_M_mix_%d",i);
+    sprintf(saythis2,"Invariant Mass (mixed events)");
+    h1_M_mix[i] = new TH1F(saythis1, saythis2, Mbins, Mlow, Mup);
+    h1_M_mix[i]->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+    h1_M_mix[i]->GetYaxis()->SetTitle("counts");
+    h1_M_mix[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=Mbins;
+  }
+
+  Int_t ptbins = 2000;
+  Float_t ptlow = 0.0, ptup = 20.0;  
+  Int_t Ebins = 500;
+  Float_t Elow = 0.0, Eup = 20.0;
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_E_%d",i);
+    sprintf(saythis2,"Cluster Energy in EMCal");
+    h1_E[i] = new TH1F(saythis1, saythis2, Ebins, Elow, Eup);
+    h1_E[i]->GetXaxis()->SetTitle("E [GeV]");
+    h1_E[i]->GetYaxis()->SetTitle("counts");
+    h1_E[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=Ebins;
+  }
+
+  h2_PhiEtaCluster = new TH2F("h2_PhiEtaCluster", "cluster phi vs eta", 400,1.362,3.178, 300,-0.728,0.728);
+  h2_PhiEtaCluster->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhiEtaCluster->GetYaxis()->SetTitle("#eta");
+  h2_PhiEtaCluster->GetZaxis()->SetTitle("hits");
+  h2_PhiEtaCluster->SetMarkerStyle(kFullCircle);
+  TotalNBins+=400*300;
+
+  h2_PhiEtaClusterCut = new TH2F("h2_PhiEtaClusterCut", "cluster phi vs eta (after cuts)", 400,1.362,3.178, 300,-0.728,0.728);
+  h2_PhiEtaClusterCut->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhiEtaClusterCut->GetYaxis()->SetTitle("#eta");
+  h2_PhiEtaClusterCut->GetZaxis()->SetTitle("hits");
+  h2_PhiEtaClusterCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=400*300;
+
+// eta binning
+  Double_t EtaBins[97] = {-0.66687,-0.653,-0.63913,-0.62526,-0.61139,-0.59752,-0.58365,-0.56978,-0.55591,-0.54204,-0.52817,-0.5143,-0.50043,-0.48656,-0.47269,-0.45882,-0.44495,-0.43108,-0.41721,-0.40334,-0.38947,-0.3756,-0.36173,-0.34786,-0.33399,-0.32012,-0.30625,-0.29238,-0.27851,-0.26464,-0.25077,-0.2369,-0.22303,-0.20916,-0.19529,-0.18142,-0.16755,-0.15368,-0.13981,-0.12594,-0.11207,-0.0982,-0.08433,-0.07046,-0.05659,-0.04272,-0.02885,-0.01498,-0.00111,0.01276,0.02663,0.0405,0.05437,0.06824,0.08211,0.09598,0.10985,0.12372,0.13759,0.15146,0.16533,0.1792,0.19307,0.20694,0.22081,0.23468,0.24855,0.26242,0.27629,0.29016,0.30403,0.3179,0.33177,0.34564,0.35951,0.37338,0.38725,0.40112,0.41499,0.42886,0.44273,0.4566,0.47047,0.48434,0.49821,0.51208,0.52595,0.53982,0.55369,0.56756,0.58143,0.5953,0.60917,0.62304,0.63691,0.65078,0.66465};
+  
+  // phi binning
+  Double_t PhiBins[125] = {1.408,1.4215,1.435,1.4485,1.462,1.4755,1.489,1.5025,1.516,1.5295,1.543,1.5565,1.57,1.5835,1.597,1.6105,1.624,1.6375,1.651,1.6645,1.678,1.6915,1.705,1.7185,1.732, 1.758,1.7715,1.785,1.7985,1.812,1.8255,1.839,1.8525,1.866,1.8795,1.893,1.9065,1.92,1.9335,1.947,1.9605,1.974,1.9875,2.001,2.0145,2.028,2.0415,2.055,2.0685,2.082,2.108,2.1215,2.135,2.1485,2.162,2.1755,2.189,2.2025,2.216,2.2295,2.243,2.2565,2.27,2.2835,2.297,2.3105,2.324,2.3375,2.351,2.3645,2.378,2.3915,2.405,2.4185,2.432,2.456,2.4695,2.483,2.4965,2.51,2.5235,2.537,2.5505,2.564,2.5775,2.591,2.6045,2.618,2.6315,2.645,2.6585,2.672,2.6855,2.699,2.7125,2.726,2.7395,2.753,2.7665,2.78,2.804,2.8175,2.831,2.8445,2.858,2.8715,2.885,2.8985,2.912,2.9255,2.939,2.9525,2.966,2.9795,2.993,3.0065,3.02,3.0335,3.047,3.0605,3.074,3.0875,3.101,3.1145,3.128};
+
+  h2_PhiEtaMaxCell = new TH2F("h2_PhiEtaMaxCell", "maxcell phi vs eta", 124,PhiBins, 96,EtaBins);
+  h2_PhiEtaMaxCell->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhiEtaMaxCell->GetYaxis()->SetTitle("#eta");
+  h2_PhiEtaMaxCell->GetZaxis()->SetTitle("hits");
+  h2_PhiEtaMaxCell->SetMarkerStyle(kFullCircle);
+  TotalNBins+=96*124;
+
+  h2_PhiEtaMaxCellCut = new TH2F("h2_PhiEtaMaxCellCut", "maxcell phi vs eta (after cuts)", 124,PhiBins, 96,EtaBins);
+  h2_PhiEtaMaxCellCut->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhiEtaMaxCellCut->GetYaxis()->SetTitle("#eta");
+  h2_PhiEtaMaxCellCut->GetZaxis()->SetTitle("hits");
+  h2_PhiEtaMaxCellCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=96*124;
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_dR_ClustTrk_%d",i);
+    sprintf(saythis2,"Cluster-Track matching");
+    h1_dR_ClustTrk[i] = new TH1F(saythis1, saythis2, 5000, -0.01, 5);
+    h1_dR_ClustTrk[i]->GetXaxis()->SetTitle("dR [sqrt(d#phi^{2}+d#eta^{2})]");
+    h1_dR_ClustTrk[i]->GetYaxis()->SetTitle("N");
+    h1_dR_ClustTrk[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=5000;
+  }
+
+  h2_gE_RecTruth = new TH2F("h2_gE_RecTruth", "#gamma E_{truth}/E_{clust} vs E_{clust}", Ebins,Elow,Eup, 500,0,2);
+  h2_gE_RecTruth->GetXaxis()->SetTitle("E^{rec}_{clust} [GeV]");
+  h2_gE_RecTruth->GetYaxis()->SetTitle("E^{rec}_{clust}/E^{truth}_{#gamma}");
+  h2_gE_RecTruth->GetZaxis()->SetTitle("counts");
+  h2_gE_RecTruth->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Ebins*500;
+  
+  h2_eop_E = new TH2F("h2_eop_E","E/p vs E (using built-in track matching)", Ebins, Elow, Eup, 1200,0,3);
+  h2_eop_E->GetXaxis()->SetTitle("cluster Energy [GeV]");
+  h2_eop_E->GetYaxis()->SetTitle("E/p");
+  TotalNBins+=Ebins*1200;
+
+  h2_eop_pT = new TH2F("h2_eop_pT","E/p vs p_{T} (using built-in track matching)", Ebins, Elow, Eup, 1200,0,3);
+  h2_eop_pT->GetXaxis()->SetTitle("cluster Energy [GeV]");
+  h2_eop_pT->GetYaxis()->SetTitle("E/p");
+  TotalNBins+=Ebins*1200;
+
+  h2_E_time = new TH2F("h2_E_time","cluster energy vs time", Ebins, Elow, Eup, 1000,-1e-6,1e-6);
+  h2_E_time->GetXaxis()->SetTitle("cluster Energy [GeV]");
+  h2_E_time->GetYaxis()->SetTitle("time [s]");
+  TotalNBins+=Ebins*1000;
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_Pi0TruthPt_%d",i);
+    sprintf(saythis2,"P_{T} distribution for Truth Pi0's");
+    h1_Pi0TruthPt[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_Pi0TruthPt[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_Pi0TruthPt[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_Pi0TruthPt[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_PriPi0TruthPt_%d",i);
+    sprintf(saythis2,"P_{T} distribution for Truth Primary Pi0's");
+    h1_PriPi0TruthPt[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_PriPi0TruthPt[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_PriPi0TruthPt[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_PriPi0TruthPt[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_Pi0TruthPtEmcal_%d",i);
+    sprintf(saythis2,"P_{T} distribution for Truth Pi0's (hit EMCal)");
+    h1_Pi0TruthPtEmcal[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_Pi0TruthPtEmcal[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_Pi0TruthPtEmcal[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_Pi0TruthPtEmcal[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_PriPi0TruthPtEmcal_%d",i);
+    sprintf(saythis2,"P_{T} distribution for Truth Primary Pi0's (hit EMCal)");
+    h1_PriPi0TruthPtEmcal[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_PriPi0TruthPtEmcal[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_PriPi0TruthPtEmcal[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_PriPi0TruthPtEmcal[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_Pi0TruthPtPhi2piEta065_%d",i);
+    sprintf(saythis2,"P_{T} for Truth Pi0's [|#eta_{#pi^{0}}|<0.65 && 0<#phi_{#pi^{0}}<2#pi]");
+    h1_Pi0TruthPtPhi2piEta065[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_Pi0TruthPtPhi2piEta065[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_Pi0TruthPtPhi2piEta065[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_Pi0TruthPtPhi2piEta065[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+        
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_Pi0TruthPtPhi2piEta1_%d",i);
+    sprintf(saythis2,"P_{T} for Truth Pi0's [|#eta_{#pi^{0}}|<1.0 && 0<#phi_{#pi^{0}}<2#pi]");
+    h1_Pi0TruthPtPhi2piEta1[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_Pi0TruthPtPhi2piEta1[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_Pi0TruthPtPhi2piEta1[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_Pi0TruthPtPhi2piEta1[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+  
+  h2_Pi0TruthPhiEta = new TH2F("h2_Pi0TruthPhiEta","Pi0Truth Phi vs Eta ", 380,-0.02,6.30, 200,-10,10);
+  h2_Pi0TruthPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_Pi0TruthPhiEta->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*200;
+
+  h2_PriPi0TruthPhiEta = new TH2F("h2_PriPi0TruthPhiEta","Primary Pi0Truth Phi vs Eta ", 380,-0.02,6.30, 200,-10,10);
+  h2_PriPi0TruthPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PriPi0TruthPhiEta->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*200;
+
+  h2_Pi0TruthPhiEtaEmcal = new TH2F("h2_Pi0TruthPhiEtaEmcal","Pi0Truth Phi vs Eta (in EMCal)", 380,-0.02,6.30, 150,-1.5,1.5);
+  h2_Pi0TruthPhiEtaEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_Pi0TruthPhiEtaEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+
+  h2_PriPi0TruthPhiEtaEmcal = new TH2F("h2_PriPi0TruthPhiEtaEmcal","Primary Pi0Truth Phi vs Eta (in EMCal)", 380,-0.02,6.30, 150,-5,5);
+  h2_PriPi0TruthPhiEtaEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PriPi0TruthPhiEtaEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+
+  h2_Pi0TruthPhiEta_Phi2piEta065 = new TH2F("h2_Pi0TruthPhiEta_Phi2piEta065",
+                                           "Pi0Truth Phi vs Eta [|#eta_{#pi^{0}}|<0.65 && 0<#phi_{#pi^{0}}<2#pi]", 380,-0.02,6.30, 150,-5,5);
+  h2_Pi0TruthPhiEta_Phi2piEta065->GetXaxis()->SetTitle("#phi [rad]");
+  h2_Pi0TruthPhiEta_Phi2piEta065->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+
+  h2_Pi0TruthPhiEta_Phi2piEta1 = new TH2F("h2_Pi0TruthPhiEta_Phi2piEta1",
+                                           "Pi0Truth Phi vs Eta [|#eta_{#pi^{0}}|<1.0 && 0<#phi_{#pi^{0}}<2#pi]", 380,-0.02,6.30, 150,-1.5,1.5);
+  h2_Pi0TruthPhiEta_Phi2piEta1->GetXaxis()->SetTitle("#phi [rad]");
+  h2_Pi0TruthPhiEta_Phi2piEta1->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+    
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_TruthPhotonsEmcal_%d",i);
+    sprintf(saythis2,"P_{T} distribution for photons (in EMCal)");
+    h1_TruthPhotonsEmcal[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_TruthPhotonsEmcal[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_TruthPhotonsEmcal[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_TruthPhotonsEmcal[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  h2_TruthPhotonsPhiEta = new TH2F("h2_TruthPhotonsPhiEta", 
+                                  "Truth Photons Phi vs Eta (pointed at emcal)", 380,-0.02,6.30, 150,-1.5,1.5);
+  h2_TruthPhotonsPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_TruthPhotonsPhiEta->GetYaxis()->SetTitle("#eta ");
+  h2_TruthPhotonsPhiEta->SetMarkerStyle(kFullCircle);
+  TotalNBins+=380*150;
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_PhotonsEmcal_%d",i);
+    sprintf(saythis2,"P_{T} distribution for photons (in EMCal)");
+    h1_PhotonsEmcal[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_PhotonsEmcal[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_PhotonsEmcal[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_PhotonsEmcal[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_PhotonsNCellsCut_%d",i);
+    sprintf(saythis2,"P_{T} distribution for #gamma's that survive NCells cut");
+    h1_PhotonsNCellsCut[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_PhotonsNCellsCut[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_PhotonsNCellsCut[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_PhotonsNCellsCut[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_PhotonsTrackMatchCut_%d",i);
+    sprintf(saythis2,"P_{T} distribution for #gamma's that survive TrackMatch cut");
+    h1_PhotonsTrackMatchCut[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_PhotonsTrackMatchCut[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_PhotonsTrackMatchCut[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_PhotonsTrackMatchCut[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_PhotonsAllCut_%d",i);
+    sprintf(saythis2,"P_{T} distribution for #gamma's that survive All cut");
+    h1_PhotonsAllCut[i] = new TH1F(saythis1, saythis2, ptbins, ptlow, ptup);
+    h1_PhotonsAllCut[i]->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+    h1_PhotonsAllCut[i]->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+    h1_PhotonsAllCut[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=ptbins;
+  }
+
+  h2_PhotonsPhiEtaIsEmcal = new TH2F("h2_PhotonsPhiEtaIsEmcal",
+                                    "Photons Phi vs Eta (IsEMCAL()==1)", 380,-0.02,6.30, 100,-1.0,1.0);
+  h2_PhotonsPhiEtaIsEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhotonsPhiEtaIsEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*100;
+  
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_dR_RealMC_%d",i);
+    sprintf(saythis2,"P_{T} distribution for #gamma's that survive All cut");
+    h1_dR_RealMC[i] = new TH1F(saythis1, saythis2, 2000, -0.01, 10);
+    h1_dR_RealMC[i]->GetXaxis()->SetTitle("dR sqrt(dx^{2}+dy^{2})");
+    h1_dR_RealMC[i]->GetYaxis()->SetTitle("N");
+    h1_dR_RealMC[i]->SetMarkerStyle(kFullCircle);
+    TotalNBins+=2000;
+  }
+
+  Int_t chi2bins = 100;
+  Float_t chi2low = -2, chi2up = 2;
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_Chi2_%d",i);
+    sprintf(saythis2,"#chi^{2} distribution for reconstructed");
+    h1_Chi2[i] = new TH1F(saythis1,saythis2,chi2bins, chi2low, chi2up);
+    h1_Chi2[i]->GetXaxis()->SetTitle("#chi^{2}");
+    h1_Chi2[i]->GetYaxis()->SetTitle("counts");
+    TotalNBins+=chi2bins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_nTrkMatch_%d",i);
+    sprintf(saythis2,"number of matched tracks");
+    h1_nTrkMatch[i] = new TH1F(saythis1,saythis2,14, -1.5, 5.5);
+    h1_nTrkMatch[i]->GetXaxis()->SetTitle("nTracksMatched");
+    h1_nTrkMatch[i]->GetYaxis()->SetTitle("counts");
+    TotalNBins+=14;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h1_ClusterDisp_%d",i);
+    sprintf(saythis2,"Dispersion of CaloCluster");
+    h1_ClusterDisp[i] = new TH1F(saythis1,saythis2,1000, -1, 3);
+    h1_ClusterDisp[i]->GetXaxis()->SetTitle("cluster->GetClusterDisp()");
+    h1_ClusterDisp[i]->GetYaxis()->SetTitle("counts");
+    TotalNBins+=1000;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h2_Ellipse_%d",i);
+    sprintf(saythis2,"Ellipse axis M20 vs M02");
+    h2_Ellipse[i] = new TH2F(saythis1,saythis2,500, -0.01, 1, 500, -0.01, 1);
+    h2_Ellipse[i]->GetXaxis()->SetTitle("cluster->GetM20()");
+    h2_Ellipse[i]->GetYaxis()->SetTitle("cluster->GetM02()");
+    h2_Ellipse[i]->GetZaxis()->SetTitle("counts");
+    TotalNBins+=500*500;
+  }
+       
+  Int_t etabins = 150;
+  Float_t etalow = -1.5, etaup = 1.5;
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h2_EtaPt_%d",i);
+    sprintf(saythis2,"Cluster Energy vs ");
+    h2_EtaPt[i] = new TH2F(saythis1,saythis2,etabins, etalow, etaup, ptbins, ptlow, ptup);
+    h2_EtaPt[i]->GetXaxis()->SetTitle("E [GeV]");
+    h2_EtaPt[i]->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+    TotalNBins+=etabins*ptbins;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h3_MptAsymm_%d",i);
+    sprintf(saythis2,"mass vs p_{T} vs Asymm cut");
+    h3_MptAsymm[i] = new TH3F(saythis1,saythis2,Mbins,Mlow,Mup, ptbins,ptlow,ptup, 3,0.5,3.5);
+    h3_MptAsymm[i]->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+    h3_MptAsymm[i]->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+    h3_MptAsymm[i]->GetZaxis()->SetTitle("Asymmetry Cut (edges: 0.0, 0.1, 0.7, 1.0)");
+    TotalNBins+=Mbins*ptbins*3.0;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h3_MptAsymm_mix_%d",i);
+    sprintf(saythis2,"mass vs p_{T} vs Asymm cut (mixed events)");
+    h3_MptAsymm_mix[i] = new TH3F(saythis1,saythis2,Mbins,Mlow,Mup, ptbins,ptlow,ptup, 3,0.5,3.5);
+    h3_MptAsymm_mix[i]->GetXaxis()->SetTitle("mass [GeV/c^{2}]");
+    h3_MptAsymm_mix[i]->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+    h3_MptAsymm_mix[i]->GetZaxis()->SetTitle("Asymmetry Cut (edges: 0.0, 0.1, 0.7, 1.0)");
+    TotalNBins+=Mbins*ptbins*3.0;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h2_dphi_deta_%d",i);
+    sprintf(saythis2,"#Delta#phi vs #Delta#eta");
+    h2_dphi_deta[i] = new TH2F(saythis1,saythis2, 349,-1.5,5, 400,-2.0,2.0);
+    h2_dphi_deta[i]->GetXaxis()->SetTitle("#Delta#phi");
+    h2_dphi_deta[i]->GetYaxis()->SetTitle("#Delta#eta");
+    TotalNBins+=349*400;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h2_dphi_deta_mix_%d",i);
+    sprintf(saythis2,"#Delta#phi vs #Delta#eta (mixed events)");
+    h2_dphi_deta_mix[i] = new TH2F(saythis1,saythis2, 349,-1.5,5, 400,-2.0,2.0);
+    h2_dphi_deta_mix[i]->GetXaxis()->SetTitle("#Delta#phi");
+    h2_dphi_deta_mix[i]->GetYaxis()->SetTitle("#Delta#eta");
+    TotalNBins+=349*400;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h2_DispRes_%d",i);
+    sprintf(saythis2,"zvtx info");
+    h2_DispRes[i] = new TH2F(saythis1, saythis2, 500,-0.01,1, 500,-0.1,2);
+    h2_DispRes[i]->GetXaxis()->SetTitle("EvtVtx->GetDispersion()");
+    h2_DispRes[i]->GetYaxis()->SetTitle("EvtVtx->GetZRes()");
+    h2_DispRes[i]->GetZaxis()->SetTitle("counts");
+    TotalNBins+=500*500;
+  }
+
+  for(int i=0; i<cent_bins; i++){
+    sprintf(saythis1,"h2_cells_M02_%d",i);
+    sprintf(saythis2,"nCells vs M02");
+    h2_cells_M02[i] = new TH2F(saythis1, saythis2, 204,-1.5,100.5, 500,-1,1.5);
+    h2_cells_M02[i]->GetXaxis()->SetTitle("nCells");
+    h2_cells_M02[i]->GetYaxis()->SetTitle("M02");
+    h2_cells_M02[i]->GetZaxis()->SetTitle("counts");
+    TotalNBins+=204*500;
+  }
+
+  cout << endl << "Total number of bins in booked histograms:  " << TotalNBins << endl << endl;
+
+  // Initialize helper class (for vertex selection & pile up correction)
+  fHelperClass = new AliAnalysisUtils();
+
+  //TFile *f = OpenFile(1); 
+  //TDirectory::TContext context(f);
+    
+  fOutput->Add(h1_zvtx);
+  fOutput->Add(h1_trigger);
+  fOutput->Add(h1_centrality);
+  fOutput->Add(h2_PhiEtaCluster);
+  fOutput->Add(h2_PhiEtaClusterCut);
+  fOutput->Add(h2_PhiEtaMaxCell);
+  fOutput->Add(h2_PhiEtaMaxCellCut);
+  fOutput->Add(h2_gE_RecTruth);
+  fOutput->Add(h2_eop_E);
+  fOutput->Add(h2_eop_pT);
+  fOutput->Add(h2_E_time);
+
+  for(int i=0; i<cent_bins; i++){
+    fOutput->Add(h1_nClusters[i]);
+    fOutput->Add(h1_M[i]);
+    fOutput->Add(h1_M_mix[i]);
+    fOutput->Add(h1_E[i]);
+    fOutput->Add(h1_dR_ClustTrk[i]);
+    fOutput->Add(h1_Pi0TruthPt[i]);
+    fOutput->Add(h1_PriPi0TruthPt[i]);
+    fOutput->Add(h1_Pi0TruthPtEmcal[i]);
+    fOutput->Add(h1_PriPi0TruthPtEmcal[i]);
+    fOutput->Add(h1_Pi0TruthPtPhi2piEta065[i]);
+    fOutput->Add(h1_Pi0TruthPtPhi2piEta1[i]);
+    fOutput->Add(h1_TruthPhotonsEmcal[i]);
+    fOutput->Add(h1_PhotonsEmcal[i]);
+    fOutput->Add(h1_PhotonsNCellsCut[i]);
+    fOutput->Add(h1_PhotonsTrackMatchCut[i]);
+    fOutput->Add(h1_PhotonsAllCut[i]);
+    fOutput->Add(h1_dR_RealMC[i]);
+    fOutput->Add(h1_Chi2[i]);
+    fOutput->Add(h1_nTrkMatch[i]);
+    fOutput->Add(h1_ClusterDisp[i]);
+    fOutput->Add(h2_Ellipse[i]);
+    fOutput->Add(h2_EtaPt[i]);
+    fOutput->Add(h3_MptAsymm[i]);
+    fOutput->Add(h3_MptAsymm_mix[i]);
+    fOutput->Add(h2_dphi_deta[i]);
+    fOutput->Add(h2_dphi_deta_mix[i]);
+    fOutput->Add(h2_DispRes[i]);
+    fOutput->Add(h2_cells_M02[i]);
+  }
+  fOutput->Add(h2_Pi0TruthPhiEta);
+  fOutput->Add(h2_PriPi0TruthPhiEta);
+  fOutput->Add(h2_Pi0TruthPhiEtaEmcal);
+  fOutput->Add(h2_PriPi0TruthPhiEtaEmcal);
+  fOutput->Add(h2_Pi0TruthPhiEta_Phi2piEta065);
+  fOutput->Add(h2_Pi0TruthPhiEta_Phi2piEta1);
+  fOutput->Add(h2_TruthPhotonsPhiEta);
+  fOutput->Add(h2_PhotonsPhiEtaIsEmcal);
+
+  // Post data for ALL output slots >0 here, 
+  // To get at least an empty histogram 
+  // 1 is the outputnumber of a certain weg of task 1  
+  PostData(1, fOutput); 
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEMCALMesonGGSDMpPb::UserExec(Option_t *) 
+{
+  // Main loop Called for each event
+
+  AliMCEvent *mcEvent = MCEvent();  
+  Bool_t isMC = bool(mcEvent);//is this the right way to do this? 
+  
+  TRandom3 randy; randy.SetSeed(0);
+  unsigned int iskip = -1;
+  TLorentzVector ParentMix;
+
+  double recalScale = 1.0;
+
+  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();    
+  
+  AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (am->GetInputEventHandler());
+  AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (am->GetInputEventHandler());
+  if (!aodH && !esdH)  Printf("ERROR: Could not get ESD or AODInputHandler");
+  
+  if(esdH)      fEsdEv = esdH->GetEvent();    
+  else if(aodH) fAodEv = aodH->GetEvent();  
+  else{
+    AliFatal("Neither ESD nor AOD event found");
+    return;
+  }
+
+  // get pointer to reconstructed event
+  AliVEvent *event = InputEvent();
+  if (!event){
+    AliError("Pointer == 0, this can not happen!");  return;}
+  //AliESDEvent* fEsdEv = dynamic_cast<AliESDEvent*>(event);
+  //AliAODEvent* aod = dynamic_cast<AliAODEvent*>(event);
+  //if (!fEsdEv){
+  //AliError("Cannot get the ESD event");  return;}
+
+  fHelperClass->SetCutOnZVertexSPD(kFALSE);//does the zvtx have to match the spd vertex? 
+  fHelperClass->SetMaxVtxZ(1.0e6);//i set this myself later.. 
+  // simply makes sure that there is at least 1 contributer to the zvtx determination.
+  // this should only remove the *extra* events at zvtx==0.
+  if(!fHelperClass->IsVertexSelected2013pA(event))
+    return;
+
+  Int_t iTrigger = 0;
+  if (fEsdEv)       iTrigger = fEsdEv->GetHeader()->GetL0TriggerInputs();
+  else if (fAodEv)  iTrigger = fAodEv->GetHeader()->GetL0TriggerInputs();
+  
+  char saythis[500];
+  Int_t iTriggerBin = 0;
+  for(unsigned long j=0; j<TriggerList.size(); j++){
+    if(iTrigger==TriggerList[j])
+      iTriggerBin=j+1;
+  }
+  if(iTriggerBin==0){
+    TriggerList.push_back(iTrigger);
+    iTriggerBin=TriggerList.size();
+  }
+  
+  h1_trigger->SetBinContent(iTriggerBin, h1_trigger->GetBinContent(iTriggerBin)+1);
+  sprintf(saythis,"%d",iTrigger);
+  h1_trigger->GetXaxis()->SetBinLabel(iTriggerBin, saythis);
+  
+  Double_t centralityVZERO=0.0;
+  Int_t centBin = 0;
+  AliCentrality *aliCent=NULL;
+
+  Int_t nclusters=0;
+  if(fEsdEv){
+    //Int_t evtN      = fEsdEv->GetEventNumberInFile();  
+    //Int_t ntracks   = fEsdEv->GetNumberOfTracks();
+    nclusters = fEsdEv->GetNumberOfCaloClusters();
+    aliCent   = fEsdEv->GetCentrality();
+  }
+  else if(fAodEv){
+    //Int_t evtN      = fAodEv->GetEventNumberInFile();  
+    //Int_t ntracks   = fAodEv->GetNumberOfTracks();
+    nclusters = fAodEv->GetNumberOfCaloClusters();
+    aliCent   = fAodEv->GetCentrality();
+  }
+  //centBin = aliCent->GetCentralityClass10("V0M");
+  //centralityVZERO = aliCent->GetCentralityPercentile("V0M");
+  //centBin = aliCent->GetCentralityClass10("V0C");
+  //centralityVZERO = aliCent->GetCentralityPercentile("V0C");
+  centBin = aliCent->GetCentralityClass10("V0A");
+  centralityVZERO = aliCent->GetCentralityPercentile("V0A");
+
+  if     (centralityVZERO<20.0)
+    centBin = 0;
+  else if(centralityVZERO<40.0)
+    centBin = 1;
+  else if(centralityVZERO<60.0)
+    centBin = 2;
+  else
+    centBin = 3;
+
+  //cout << "Centrality:  " << centBin << "    " << centralityVZERO << endl;
+  
+  if (fEsdEv){
+    if(!(fEsdEv->GetPrimaryVertex()->GetStatus()))   return;
+  }
+  //else if (fAodEv){
+  //if(!(fAodEv->GetPrimaryVertex()->GetStatus()))   return;
+  //}
+
+  Double_t vertDisp=0.0;
+  Double_t vertZres=0.0;
+  Bool_t vertIsfromZ=0;
+  if (fEsdEv){
+    vertDisp    = fEsdEv->GetPrimaryVertex()->GetDispersion();
+    vertZres    = fEsdEv->GetPrimaryVertex()->GetZRes();
+    vertIsfromZ = fEsdEv->GetPrimaryVertex()->IsFromVertexerZ();
+  }
+  else if (fAodEv){
+    vertDisp    = 0;
+    vertZres    = 0;
+    vertIsfromZ = 0;
+  }
+
+  h2_DispRes[centBin]->Fill(vertDisp, vertZres);  
+  // if vertex is from spd vertexZ, require more stringent cut
+  if (vertIsfromZ) {
+    if (vertDisp>0.02 ||  vertZres>0.25 ) 
+      return; // bad vertex from VertexerZ
+  }
+  
+  // EMCal cluster loop for reconstructed event
+  //numberofclusters set above! 
+  TLorentzVector Photon1, Photon2, Parent;
+  Double_t vertex[3]; 
+  Double_t E1=0.0;
+  Double_t vertZ=0.0;
+  if (fEsdEv)       vertZ = fEsdEv->GetPrimaryVertex()->GetZ();
+  else if (fAodEv)  vertZ = fAodEv->GetPrimaryVertex()->GetZ();    
+  
+  h1_zvtx->Fill(vertZ);
+  //zvertex cut:
+  if(fabs(vertZ)>10.0)
+    return;
+  
+  h1_nClusters[centBin]->Fill(nclusters);
+  h1_centrality->Fill(centralityVZERO);
+
+  int izvtx = GetZvtxBin(vertZ);
+  int imult = GetMultBin(nclusters);
+
+  //cout << iskip << " " << izvtx << " " << imult << endl;  
+  //cout << "GetNumberOfVertices(): " << fAodEv->GetNumberOfVertices() << endl;
+
+
+
+  //######################### ~~~~~~~~~~~ ##################################
+  //######################### STARTING MC ##################################
+  //######################### ~~~~~~~~~~~ ##################################
+  
+  if(isMC){
+    int isPrimary = 0;
+
+    if (!mcEvent){
+      cout << "no MC event" << endl;
+      return;
+    }
+    
+    const AliVVertex *evtVtx = mcEvent->GetPrimaryVertex();
+    if (!evtVtx)
+      return;
+    
+    mcEvent->PreReadAll();    
+    
+    Int_t nTracksMC  = mcEvent->GetNumberOfTracks();
+    Int_t nPTracksMC = mcEvent->GetNumberOfPrimaries();
+    //cout << "We have  " << nPTracksMC << "  primaries of  " << nTracksMC << "  total tracks." << endl;
+    
+    for (Int_t iTrack = 0; iTrack<nTracksMC; ++iTrack) {
+      AliMCParticle *mcP = static_cast<AliMCParticle*>(mcEvent->GetTrack(iTrack));
+      if (!mcP)
+       continue;
+      
+
+      // it's a pion !! 
+      if(mcP->PdgCode() != 111)
+       continue;
+      
+      /*
+      // primary particle
+      Double_t dR = TMath::Sqrt((mcP->Xv()-evtVtx->GetX())*(mcP->Xv()-evtVtx->GetX()) + 
+                                (mcP->Yv()-evtVtx->GetY())*(mcP->Yv()-evtVtx->GetY()));
+      if(dR <= 0.01)  isPrimary = 1;
+      else            isPrimary = 0;
+      */
+      
+      if(iTrack<nPTracksMC)  isPrimary = 1;
+      else                   isPrimary = 0;
+            
+      h1_Pi0TruthPt    [centBin]->Fill(mcP->Pt());
+      h2_Pi0TruthPhiEta->Fill(mcP->Phi(),mcP->Eta());
+
+      if(isPrimary==1){
+       h1_PriPi0TruthPt    [centBin]->Fill(mcP->Pt());
+       h2_PriPi0TruthPhiEta->Fill(mcP->Phi(),mcP->Eta());
+      }
+      
+      if(mcP->Eta()<-1.0 || mcP->Eta()>1.0)
+       continue;
+      
+      h1_Pi0TruthPtPhi2piEta1    [centBin]->Fill(mcP->Pt());
+      h2_Pi0TruthPhiEta_Phi2piEta1->Fill(mcP->Phi(),mcP->Eta());      
+      
+      if(mcP->Eta()>fEtamin && mcP->Eta()<fEtamax){
+       h1_Pi0TruthPtPhi2piEta065    [centBin]->Fill(mcP->Pt());
+       h2_Pi0TruthPhiEta_Phi2piEta065->Fill(mcP->Phi(),mcP->Eta());            
+      }
+      
+      
+      Int_t d1 = mcP->GetFirstDaughter();
+      Int_t d2 = mcP->GetLastDaughter();
+      
+      if (d1<0)  continue;
+      if (d2<0)  d2=d1;      
+      if (d2-d1 != 1)  continue;
+      
+      bool bacc = true;
+      bool binp = true;
+      for (Int_t i=d1;i<=d2;++i){
+        const AliMCParticle *dmc = static_cast<const AliMCParticle *>(mcEvent->GetTrack(i));
+        Double_t eta_d = dmc->Eta();
+        Double_t phi_d = dmc->Phi();
+        if(!(dmc->PdgCode()==22)){
+         binp = false;
+        }
+        if(!(dmc->PdgCode()==22 && eta_d>fEtamin && eta_d<fEtamax && phi_d>fPhimin && phi_d<fPhimax)){
+         bacc = false;
+        }      
+      }
+
+      if(binp && bacc){// 2 Photons hit the EMCAL! 
+       
+       for (Int_t j=d1;j<=d2;++j){//both truth photons.
+         
+         const AliMCParticle *dmc = static_cast<const AliMCParticle *>(mcEvent->GetTrack(j));
+         Double_t eta_d = dmc->Eta();
+         Double_t phi_d = dmc->Phi();
+         
+         if( dmc->PdgCode()==22 && 
+             dmc->Eta()>fEtamin && dmc->Eta()<fEtamax && 
+             dmc->Phi()>fPhimin && dmc->Phi()<fPhimax ){
+           h1_TruthPhotonsEmcal[centBin]->Fill(dmc->Pt());
+           h2_TruthPhotonsPhiEta->Fill(dmc->Phi(),dmc->Eta());
+         }
+
+         for(int i=0; i<nclusters; i++) {
+           
+           Bool_t matches_pion_photon = 0;
+           
+           AliESDCaloCluster* esdCluster=NULL;
+           AliAODCaloCluster* aodCluster=NULL;
+           if (fEsdEv)       esdCluster = fEsdEv->GetCaloCluster(i); // pointer to EMCal cluster
+           else if (fAodEv)  aodCluster = fAodEv->GetCaloCluster(i); // pointer to EMCal cluster
+           
+           Double_t clustMC_phi, clustMC_eta;
+           
+           if(fEsdEv){
+             
+             if(esdCluster->IsEMCAL()){
+               
+               Float_t pos[3] = {0,0,0};
+               esdCluster->GetPosition(pos);
+               TVector3 vpos(pos);
+               //h1_Phi->Fill(vpos.Phi());
+               clustMC_phi = vpos.Phi();
+               clustMC_eta = vpos.Eta();
+               
+               Double_t dR = TMath::Sqrt((eta_d-clustMC_eta)*(eta_d-clustMC_eta) + 
+                                         (phi_d-clustMC_phi)*(phi_d-clustMC_phi));
+               h1_dR_RealMC[centBin]->Fill(dR);
+               if(dR<=0.04) matches_pion_photon = 1;
+               
+               vpos.Delete();
+             }
+             if(matches_pion_photon){          
+               if(esdCluster->IsEMCAL()){
+                 h1_PhotonsEmcal[centBin]->Fill(esdCluster->E());
+                 h2_PhotonsPhiEtaIsEmcal->Fill(clustMC_phi,clustMC_eta);
+               }
+               if(esdCluster->IsEMCAL() && esdCluster->GetNCells()>=2)
+                 h1_PhotonsNCellsCut[centBin]->Fill(esdCluster->E());
+               if(esdCluster->IsEMCAL() && esdCluster->GetNTracksMatched()==0)
+                 h1_PhotonsTrackMatchCut[centBin]->Fill(esdCluster->E());
+               if(esdCluster->IsEMCAL() && esdCluster->GetNCells()>=2 && esdCluster->GetNTracksMatched()==0)
+                 h1_PhotonsAllCut[centBin]->Fill(esdCluster->E());               
+             }//if(matches_pion_photon)
+               
+           }//if(fEsdEv)
+           else if(fAodEv){
+             
+             if(aodCluster->IsEMCAL()){
+               
+               Float_t pos[3] = {0,0,0};
+               aodCluster->GetPosition(pos);  
+               TVector3 vpos(pos); 
+               //h1_Phi->Fill(vpos.Phi());
+               clustMC_phi = vpos.Phi();
+               clustMC_eta = vpos.Eta();
+               
+               Double_t dR = TMath::Sqrt((eta_d-clustMC_eta)*(eta_d-clustMC_eta) + 
+                                         (phi_d-clustMC_phi)*(phi_d-clustMC_phi));
+               h1_dR_RealMC[centBin]->Fill(dR);
+               if(dR<=0.04) matches_pion_photon = 1;
+               
+               vpos.Delete();
+             }
+             if(matches_pion_photon){          
+               if(aodCluster->IsEMCAL()){
+                 h1_PhotonsEmcal[centBin]->Fill(aodCluster->E());
+                 h2_PhotonsPhiEtaIsEmcal->Fill(clustMC_phi,clustMC_eta);
+               }
+               if(aodCluster->IsEMCAL() && aodCluster->GetNCells()>=2)
+                 h1_PhotonsNCellsCut[centBin]->Fill(aodCluster->E());
+               if(aodCluster->IsEMCAL() && aodCluster->GetNTracksMatched()==0)
+                 h1_PhotonsTrackMatchCut[centBin]->Fill(aodCluster->E());
+               if(aodCluster->IsEMCAL() && aodCluster->GetNCells()>=2 && aodCluster->GetNTracksMatched()==0)
+                 h1_PhotonsAllCut[centBin]->Fill(aodCluster->E());
+               
+             }//if(matches_pion_photon)
+             
+           }//if(fAodEv)
+           
+         }//loop over nclusters. 
+         
+       }//both truth photons.
+       
+      }// 2 Photons hit the EMCAL! 
+      
+      
+      if(binp && bacc){// 2 Photons hit the EMCAL! 
+       h1_Pi0TruthPtEmcal    [centBin]->Fill(mcP->Pt());
+       h2_Pi0TruthPhiEtaEmcal->Fill(mcP->Phi(),mcP->Eta());    
+       
+       if(isPrimary==1){
+         h1_PriPi0TruthPtEmcal    [centBin]->Fill(mcP->Pt());
+         h2_PriPi0TruthPhiEtaEmcal->Fill(mcP->Phi(),mcP->Eta());
+       }
+       
+      }//2 photons hit the EMCAL! 
+      
+    }//for(nTracksMC)    
+    
+  }//if(isMC)
+  
+  //######################### ~~~~~~~~~~~~ ##################################
+  //######################### DONE WITH MC ##################################
+  //######################### ~~~~~~~~~~~~ ##################################
+
+
+  for(int i=0; i<nclusters; i++) {
+
+    AliESDCaloCluster* esdCluster=NULL;
+    AliAODCaloCluster* aodCluster=NULL;
+    if (fEsdEv)       esdCluster = fEsdEv->GetCaloCluster(i); // pointer to EMCal cluster
+    else if (fAodEv)  aodCluster = fAodEv->GetCaloCluster(i); // pointer to EMCal cluster
+    if(!esdCluster && !aodCluster) { 
+      AliError(Form("ERROR: Could not retrieve any (ESD or AOD) Cluster %d",i)); 
+      continue; 
+    }
+    
+    if(fEsdEv){
+
+      recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+      
+      //uncomment this to do the track matching (1 of 3 lines, esd part)!! 
+      //Bool_t MatchesToTrack = 0;
+      if(esdCluster->IsEMCAL()){
+       
+       Float_t pos[3] = {0,0,0};
+       Short_t maxCellID = -1;
+       Float_t celleta, cellphi;
+       esdCluster->GetPosition(pos);
+       TVector3 clusterPosition(pos);
+       h2_PhiEtaCluster->Fill(clusterPosition.Phi(),clusterPosition.Eta());
+       GetMaxCellEnergy(esdCluster, maxCellID);
+       AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance();
+       fGeom->EtaPhiFromIndex(maxCellID,celleta,cellphi);
+       h2_PhiEtaMaxCell->Fill(cellphi,celleta);
+       
+       // _______________Track loop for reconstructed event_____________
+       for(Int_t itrk = 0; itrk < fEsdEv->GetNumberOfTracks(); itrk++) {
+         AliESDtrack* esdTrack = fEsdEv->GetTrack(itrk); // pointer to reconstructed to track
+         if(!esdTrack) { 
+           AliError(Form("ERROR: Could not retrieve any (ESD) track %d",itrk)); 
+           continue; 
+         }
+         
+         Double_t posTrk[3] = {0,0,0};
+         esdTrack->GetXYZ(posTrk);
+         TVector3 vposTrk(posTrk);
+         
+         Double_t fMass          = 0.139;
+         Double_t fStepSurface   = 20.;
+         Float_t etaproj, phiproj, pttrackproj;
+
+         AliExternalTrackParam *trackParam =  const_cast<AliExternalTrackParam*>(esdTrack->GetInnerParam());
+         if(!trackParam) continue;
+         AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(trackParam, 440., fMass, fStepSurface, etaproj, phiproj, pttrackproj);
+         
+         double dR_clusttrk = sqrt((phiproj-clusterPosition.Phi())*(phiproj-clusterPosition.Phi()) + 
+                                   (etaproj-clusterPosition.Eta())*(etaproj-clusterPosition.Eta()) );
+         
+         h1_dR_ClustTrk[centBin]->Fill(dR_clusttrk);
+         
+         //uncomment this to do the track matching (2 of 3 lines)!! 
+         //if(dR_clusttrk<fdRmin_ClustTrack)
+         //MatchesToTrack = 1;
+         
+       }//_____________________________nTracks__________________________
+               
+       h2_cells_M02  [centBin]->Fill(esdCluster->GetNCells(),esdCluster->GetM02());
+       h2_Ellipse    [centBin]->Fill(esdCluster->GetM20(),esdCluster->GetM02());
+       h1_Chi2       [centBin]->Fill(esdCluster->Chi2());//always -1. 
+       h1_nTrkMatch  [centBin]->Fill(esdCluster->GetNTracksMatched());
+       h1_ClusterDisp[centBin]->Fill(esdCluster->GetDispersion());
+       h2_E_time              ->Fill(esdCluster->E(),esdCluster->GetTOF());
+
+       TArrayI *TrackLabels = esdCluster->GetTracksMatched();
+       if(TrackLabels){
+         if(TrackLabels->GetSize()>0){
+           Int_t trackindex = TrackLabels->At(0);
+           AliESDtrack* matchingT = fEsdEv->GetTrack(trackindex); // pointer to reconstructed to track
+         
+           recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+           h2_eop_E ->Fill(esdCluster->E()*recalScale, esdCluster->E()*recalScale/matchingT->P());
+           h2_eop_pT->Fill(matchingT->Pt(),            esdCluster->E()*recalScale/matchingT->P());
+         }
+       }
+
+       //uncomment this to do the track matching (3 of 3 lines)!! 
+       //if(isGoodEsdCluster(esdCluster) && !MatchesToTrack){
+       if(isGoodEsdCluster(esdCluster)){
+         recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+         E1 = esdCluster->E()*recalScale;// TOTAL HACK - JJ
+         fEsdEv->GetVertex()->GetXYZ(vertex);
+         esdCluster->GetMomentum(Photon1,vertex);
+         Photon1.SetPx(Photon1.Px()*recalScale);// TOTAL HACK - JJ
+         Photon1.SetPy(Photon1.Py()*recalScale);// TOTAL HACK - JJ
+         Photon1.SetPz(Photon1.Pz()*recalScale);// TOTAL HACK - JJ
+         Photons[0][izvtx][imult].push_back( TLorentzVector(Photon1.Px(),Photon1.Py(),Photon1.Pz(),E1) );
+         h1_E[centBin]->Fill(E1);
+         h2_PhiEtaClusterCut->Fill(clusterPosition.Phi(),clusterPosition.Eta());
+         h2_PhiEtaMaxCellCut->Fill(cellphi,celleta);
+       }
+       clusterPosition.Delete();       
+      }//if(esdCluster->isEMCAL())
+    }//if(fEsdEv)
+    else if(fAodEv){
+      
+      recalScale = PrivateEnergyRecal(aodCluster->E(), fRecalibrator);
+      
+      //uncomment this to do the track matching (1 of 3 lines, aod part)!! 
+      //Bool_t MatchesToTrack = 0;
+      if(aodCluster->IsEMCAL()){
+
+       Float_t pos[3] = {0,0,0};
+       Short_t maxCellID = -1;
+       Float_t celleta, cellphi;
+       aodCluster->GetPosition(pos);  
+       TVector3 clusterPosition(pos); 
+       h2_PhiEtaCluster->Fill(clusterPosition.Phi(),clusterPosition.Eta());
+       GetMaxCellEnergy(aodCluster, maxCellID);
+       AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance();
+       fGeom->EtaPhiFromIndex(maxCellID,celleta,cellphi);
+       h2_PhiEtaMaxCell->Fill(cellphi,celleta);
+
+       // _______________Track loop for reconstructed event_____________
+       for(Int_t itrk = 0; itrk < fAodEv->GetNumberOfTracks(); itrk++) {
+         AliAODTrack* aodTrack = fAodEv->GetTrack(itrk); // pointer to reconstructed to track
+         if(!aodTrack) { 
+           AliError(Form("ERROR: Could not retrieve any (AOD) track %d",itrk)); 
+           continue; 
+         }
+
+         Double_t posTrk[3] = {0,0,0};
+         aodTrack->GetXYZ(posTrk);
+         TVector3 vposTrk(posTrk);
+         
+         Double_t fMass          = 0.139;
+         Double_t fStepSurface   = 20.;
+         Float_t etaproj, phiproj, pttrackproj;
+         
+         AliExternalTrackParam *trackParam =  const_cast<AliExternalTrackParam*>(aodTrack->GetInnerParam());
+         if(!trackParam) continue;
+         AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(trackParam, 440., fMass, fStepSurface, etaproj, phiproj, pttrackproj);
+         
+         double dR_clusttrk = sqrt((phiproj-clusterPosition.Phi())*(phiproj-clusterPosition.Phi()) + 
+                                   (etaproj-clusterPosition.Eta())*(etaproj-clusterPosition.Eta()) );
+         
+         h1_dR_ClustTrk[centBin]->Fill(dR_clusttrk);
+         
+         //uncomment this to do the track matching (2 of 3 lines, aod part)!! 
+         //if(dR_clusttrk<fdRmin_ClustTrack)
+         //MatchesToTrack = 1;
+
+
+       }//_____________________________nTracks__________________________
+
+       h2_cells_M02  [centBin]->Fill(aodCluster->GetNCells(),aodCluster->GetM02());
+       h2_Ellipse    [centBin]->Fill(aodCluster->GetM20(),aodCluster->GetM02());
+       h1_Chi2       [centBin]->Fill(aodCluster->Chi2());//always -1. 
+       h1_nTrkMatch  [centBin]->Fill(aodCluster->GetNTracksMatched());
+       h1_ClusterDisp[centBin]->Fill(aodCluster->GetDispersion());
+       h2_E_time              ->Fill(aodCluster->E(),aodCluster->GetTOF());
+
+       // #################################################
+       // track matching eop histograms are handled here... 
+       // #################################################
+      
+       //uncomment this to do the track matching (3 of 3 lines, aod part)!! 
+       //if(isGoodAodCluster(aodCluster) && !MatchesToTrack){
+       if(isGoodAodCluster(aodCluster)){
+         recalScale = PrivateEnergyRecal(aodCluster->E(), fRecalibrator);
+         E1 = aodCluster->E()*recalScale;// TOTAL HACK - JJ
+         fAodEv->GetVertex(0)->GetXYZ(vertex);
+         aodCluster->GetMomentum(Photon1,vertex);
+         Photon1.SetPx(Photon1.Px()*recalScale);// TOTAL HACK - JJ
+         Photon1.SetPy(Photon1.Py()*recalScale);// TOTAL HACK - JJ
+         Photon1.SetPz(Photon1.Pz()*recalScale);// TOTAL HACK - JJ
+         Photons[0][izvtx][imult].push_back( TLorentzVector(Photon1.Px(),Photon1.Py(),Photon1.Pz(),E1) );
+         h1_E[centBin]->Fill(E1);
+         h2_PhiEtaClusterCut->Fill(clusterPosition.Phi(),clusterPosition.Eta());
+         h2_PhiEtaMaxCellCut->Fill(cellphi,celleta);     
+       }
+       clusterPosition.Delete();
+      }//if(aodCluster->IsEMCAL())
+    }//if(fAodEv)
+    
+  }//loop over nclusters. 
+  
+  //Make same event pions... 
+  for(unsigned int i=0; i<Photons[0][izvtx][imult].size(); i++){
+    for(unsigned int j=i+1; j<Photons[0][izvtx][imult].size(); j++){
+      Parent = Photons[0][izvtx][imult][i] + Photons[0][izvtx][imult][j];
+      Double_t deltaphi = getDeltaPhi(Photons[0][izvtx][imult][i],Photons[0][izvtx][imult][j]);
+      Double_t deltaeta = getDeltaEta(Photons[0][izvtx][imult][i],Photons[0][izvtx][imult][j]);
+      Double_t pairasym = fabs(Photons[0][izvtx][imult][i].Pt()-Photons[0][izvtx][imult][j].Pt())/
+                             (Photons[0][izvtx][imult][i].Pt()+Photons[0][izvtx][imult][j].Pt());
+      Int_t asymCut = 0;
+      if     (pairasym<0.1)  asymCut = 1;
+      else if(pairasym<0.7)  asymCut = 2;
+      else                   asymCut = 3;
+      
+      h1_M        [centBin]->Fill(Parent.M());
+      h3_MptAsymm [centBin]->Fill(Parent.M(),Parent.Pt(),asymCut);
+      h2_dphi_deta[centBin]->Fill(deltaphi,deltaeta);
+    }
+  }
+  
+  //Make mixed event...
+  for(unsigned int i=0; i<Photons[0][izvtx][imult].size(); i++){
+    for(unsigned int ipool=1; ipool<poolDepth; ipool++){
+      for(unsigned int j=0; j<Photons[ipool][izvtx][imult].size(); j++){
+       iskip = randy.Integer(Photons[0][izvtx][imult].size());
+       if(j==iskip) continue;
+       Parent = Photons[0][izvtx][imult][i]+Photons[ipool][izvtx][imult][j];
+       Double_t deltaphi = getDeltaPhi(Photons[0][izvtx][imult][i],Photons[ipool][izvtx][imult][j]);
+       Double_t deltaeta = getDeltaEta(Photons[0][izvtx][imult][i],Photons[ipool][izvtx][imult][j]);
+       Double_t pairasym = fabs(Photons[0][izvtx][imult][i].Pt()-Photons[ipool][izvtx][imult][j].Pt())/
+                               (Photons[0][izvtx][imult][i].Pt()+Photons[ipool][izvtx][imult][j].Pt());
+       Int_t asymCut = 0;
+       if     (pairasym<0.1)  asymCut = 1;
+       else if(pairasym<0.7)  asymCut = 2;
+       else                   asymCut = 3;
+
+       h1_M_mix        [centBin]->Fill(Parent.M());
+       h3_MptAsymm_mix [centBin]->Fill(Parent.M(),Parent.Pt(),asymCut);
+       h2_dphi_deta_mix[centBin]->Fill(deltaphi,deltaeta);
+      }
+    }
+  } 
+    
+  for(int ipool=poolDepth-1; ipool>0; ipool--){
+    Photons[ipool][izvtx][imult].clear();
+    for(unsigned int i=0; i<Photons[ipool-1][izvtx][imult].size(); i++)
+      Photons[ipool][izvtx][imult].push_back(Photons[ipool-1][izvtx][imult][i]);     
+  }
+  Photons[0][izvtx][imult].clear();
+    
+
+  
+  // NEW HISTO should be filled before this point, as PostData puts the
+  // information for this iteration of the UserExec in the container
+  PostData(1, fOutput);
+  }
+
+//________________________________________________________________________
+void AliAnalysisTaskEMCALMesonGGSDMpPb::Terminate(Option_t *) //specify what you want to have done
+{
+  // Called once at the end of the query.
+  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDMpPb::GetZvtxBin(Double_t vertZ)
+{
+  
+  int izvtx = -1;
+  
+  if     (vertZ<-35)
+    izvtx=0;
+  else if(vertZ<-30)
+    izvtx=1;
+  else if(vertZ<-25)
+    izvtx=2;
+  else if(vertZ<-20)
+    izvtx=3;
+  else if(vertZ<-15)
+    izvtx=4;
+  else if(vertZ<-10)
+    izvtx=5;
+  else if(vertZ< -5)
+    izvtx=6;
+  else if(vertZ<  0)
+    izvtx=7;
+  else if(vertZ<  5)
+    izvtx=8;
+  else if(vertZ< 10)
+    izvtx=9;
+  else if(vertZ< 15)
+    izvtx=10;
+  else if(vertZ< 20)
+    izvtx=11;
+  else if(vertZ< 25)
+    izvtx=12;
+  else if(vertZ< 30)
+    izvtx=13;
+  else if(vertZ< 35)
+    izvtx=14;
+  else
+    izvtx=15;
+  
+  return izvtx;  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDMpPb::GetMultBin(Int_t mult){
+
+  int imult = -1;
+  
+  if     (mult<2)
+    imult=0;
+  else if(mult<25)
+    imult=mult-2;
+  else
+    imult=24;
+  
+  return imult;  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDMpPb::isGoodEsdCluster(AliESDCaloCluster* esdclust){
+
+  int pass = 1;
+  int nMinCells  = 2;
+  double MinE    = 0.4;
+  //double MinErat = 0;
+  //double MinEcc  = 0;
+  
+  if (!esdclust)
+    pass = 0;    
+  if (!esdclust->IsEMCAL()) 
+    pass = 0;
+  if (esdclust->E()<MinE)
+    pass = 0;
+  if (esdclust->GetNCells()<nMinCells)
+    pass = 0;
+  //if (GetMaxCellEnergy(esdclust)/esdclust->E()<MinErat)
+  //pass = 0;
+  //if (esdclust->Chi2()<MinEcc) // eccentricity cut
+  //pass = 0;//this is always -1.
+    
+  //if(esdclust->GetM02()<0.1)
+  //  pass = 0;
+  //if(esdclust->GetM02()>0.5)
+  //  pass = 0;
+
+  Float_t pos[3] = {0,0,0};
+  esdclust->GetPosition(pos);
+  TVector3 clusterPosition(pos);
+  if(clusterPosition.Eta()<fEtamin || clusterPosition.Eta()>fEtamax || 
+     clusterPosition.Phi()<fPhimin || clusterPosition.Phi()>fPhimax  )
+    pass = 0;
+  clusterPosition.Delete();
+  
+  //DOING THIS BY HAND NOW... 
+  //if(!esdclust->GetNTracksMatched()==0)
+  //pass = 0;
+  
+  return pass;
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDMpPb::isGoodAodCluster(AliAODCaloCluster* aodclust){
+
+  int pass = 1;
+  int nMinCells  = 2;
+  double MinE    = 0.4;
+  //double MinErat = 0;
+  //double MinEcc  = 0;
+  
+  if (!aodclust)
+    pass = 0;    
+  if (!aodclust->IsEMCAL()) 
+    pass = 0;
+  if (aodclust->E()<MinE)
+    pass = 0;
+  if (aodclust->GetNCells()<nMinCells)
+    pass = 0;
+  //if (GetMaxCellEnergy(aodclust)/aodclust->E()<MinErat)
+  //pass = 0;
+  //if (aodclust->Chi2()<MinEcc) // eccentricity cut
+  //pass = 0;//this is always -1.
+    
+  //if(aodclust->GetM02()<0.1)
+  //pass = 0;
+  //if(aodclust->GetM02()>0.5)
+  //pass = 0;
+
+  Float_t pos[3] = {0,0,0};
+  aodclust->GetPosition(pos);
+  TVector3 clusterPosition(pos);
+  if(clusterPosition.Eta()<fEtamin || clusterPosition.Eta()>fEtamax || 
+     clusterPosition.Phi()<fPhimin || clusterPosition.Phi()>fPhimax  )
+    pass = 0;
+  clusterPosition.Delete();
+  
+  //DOING THIS BY HAND NOW... 
+  //if(!aodclust->GetNTracksMatched()==0)
+  //pass = 0;
+  
+  return pass;
+}
+//________________________________________________________________________
+Double_t AliAnalysisTaskEMCALMesonGGSDMpPb::getDeltaPhi(TLorentzVector p1, TLorentzVector p2){
+
+  double dphi = p1.Phi() - p2.Phi();
+
+  if(dphi<0.5*TMath::Pi())  
+    dphi = dphi + 2.0*TMath::Pi();
+
+  if(dphi>1.5*TMath::Pi())  
+    dphi = dphi - 2.0*TMath::Pi();
+
+  return dphi;
+}
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskEMCALMesonGGSDMpPb::getDeltaEta(TLorentzVector p1, TLorentzVector p2){
+
+  double deta = p1.PseudoRapidity() - p2.PseudoRapidity();
+
+  return deta;
+}
+
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskEMCALMesonGGSDMpPb::PrivateEnergyRecal(Double_t energy, Int_t iCalib){
+
+  double recalibfactor = 0.0;
+
+  if(iCalib==0){// no recalibration! 
+    recalibfactor = 1.0;
+  }
+  else if(iCalib==1){// just a scale factor: 
+    recalibfactor = 0.984;
+  }
+  else if(iCalib==2){// Symmetric Decay Fit - corrects data to uncorrected MC. 
+    Double_t p[3] = {0.96968, -2.68720, -0.831607};
+    recalibfactor = p[0] + exp(p[1] + p[2]*energy*2.0);
+  }
+  else if(iCalib==3){// Jason's fit to the LHC12f1a MC single photons - 04 Aug 2013 (call it kPi0MCv4??)
+    Double_t p[7] = {1.00000e+00, 3.04925e-02, 4.69043e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.00046e+00};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==4){// Jason's fit to the test beam data - 04 Aug 2013(call it kBTCv3??)
+    Double_t p[7] = {9.78672e-01, 2.39745e-01, 6.41199e-01, 9.13538e-02, 1.46058e+02, 1.99469e+01, 9.72716e-01};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==5){// Based on kSDM/kTBCv3 (call it kPi0MCv4??)
+    Double_t p[10] = {9.78672e-01, 2.39745e-01, 6.41199e-01, 9.13538e-02, 1.46058e+02, 1.99469e+01, 9.72716e-01, 0.96968, -2.68720, -0.831607};
+    recalibfactor = ( (p[6]/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5]))))) ) / ( p[7] + exp(p[8] + p[9]*energy/2.0) );
+  }
+  else if(iCalib==6){// kBeamTestCorrectedv2 - in AliROOT! 
+    Double_t p[7] = {9.83504e-01, 2.10106e-01, 8.97274e-01, 8.29064e-02, 1.52299e+02, 3.15028e+01, 0.968};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==7){// kPi0MCv3 - in AliROOT! 
+    Double_t p[7] = {9.81039e-01, 1.13508e-01, 1.00173e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.0};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==8){// Jason's fit to the noNL MC/data- based on kSDM and kPi0MCv5 - 28 Oct 2013 (call it... ??)
+    Double_t p[10] = {1.0, 6.64778e-02, 1.57000e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.01286, 0.964, -3.132, -0.435};
+    //Double_t p[10] = {1.0, 6.64778e-02, 1.57000e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.01286, 0.96968, -2.68720, -0.831607};//same SDM piece as iCalib==2
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5]))))) * (p[7] + exp(p[8]+p[9]*energy*2.0));
+  }
+  else if(iCalib==9){// Jason's fit to the LHC12f1a/b MC single photons (above 400MeV), including conversions - 28 Oct 2013 (call it kPi0MCv5??)
+    Double_t p[7] = {1.0, 6.64778e-02, 1.57000e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.01286};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==10){// Jason played with test beam data
+    Double_t p[7] = {1.0, 0.237767, 0.651203, 0.183741, 155.427, 17.0335, 0.987054};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==11){// Jason played with test beam MC
+    Double_t p[7] = {1.0, 0.0797873, 1.68322, 0.0806098, 244.586, 116.938, 1.00437};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+
+  return recalibfactor;
+}
+
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskEMCALMesonGGSDMpPb::GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const
+{
+  // Get maximum energy of attached cell.
+
+  id = -1;
+  AliVCaloCells *fVCells=NULL;
+  if(fEsdEv)      fVCells = fEsdEv->GetEMCALCells();
+  else if(fAodEv) fVCells = fAodEv->GetEMCALCells();
+  if(!fVCells)
+    return 0;
+  
+  Double_t maxe = 0;
+  Int_t ncells = cluster->GetNCells();
+  for (Int_t i=0; i<ncells; i++) {
+    Double_t e = fVCells->GetCellAmplitude(TMath::Abs(cluster->GetCellAbsId(i)));
+    if (e>maxe) {
+      maxe = e;
+      id   = cluster->GetCellAbsId(i);
+    }
+  }
+  return maxe;
+}
+
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDMpPb::IsPhysPrimJ(AliMCEvent *mcEvent, Int_t iTrack){
+
+  AliMCParticle *mcP  = static_cast<AliMCParticle*>(mcEvent->GetTrack(iTrack));
+  
+  Int_t nPTracks= mcEvent->GetNumberOfPrimaries();
+  
+  Int_t isPhysPrimary   = 1;
+  Int_t ismHF           = 0;
+  Int_t ismLongLivedOrK = 0;
+
+  if(mcP->GetMother()<0)//if it has no mother... 
+    return isPhysPrimary;
+  
+  Int_t imTrack = mcP->GetMother();
+  AliMCParticle *mcPm = static_cast<AliMCParticle*>(mcEvent->GetTrack(imTrack));
+  
+  if( TMath::Abs(mcPm->PdgCode())<10 )//if mother is a single quark...
+    return isPhysPrimary;
+  
+
+  //############################################
+  //get the PDG digits.... 
+  int num = mcPm->PdgCode();
+  int RevDigits[10] = {0};
+  int nDigits = 0;  
+  while (num >= 1){
+    RevDigits[nDigits++] = num%10;
+    num = num / 10;
+  }
+  //##############################################
+
+
+  if(RevDigits[3]>3)//Baryons
+    ismHF = 1;
+  else if(RevDigits[2]>3)//Mesons
+    ismHF = 1;
+  
+  ismLongLivedOrK = IsLongLivedOrK(mcPm->PdgCode());
+  
+  if(!ismHF && ismLongLivedOrK)
+    isPhysPrimary = 0;
+  else{ // check grandmother, greatgrandmothers, etc... 
+    while(imTrack >= nPTracks){
+
+      if(mcPm->GetMother()<0)//if it has no mother... 
+       break;
+      
+      if( TMath::Abs(mcPm->PdgCode()<10) )//if mother is a single quark...
+       return isPhysPrimary;
+      
+      imTrack = mcPm->GetMother();
+      mcPm = static_cast<AliMCParticle*>(mcEvent->GetTrack(imTrack));      
+      
+      //############################################
+      //get the PDG digits.... 
+      num = mcPm->PdgCode();
+      for(int i=0; i<10; i++)  RevDigits[i] = 0;
+      nDigits = 0;  
+      while (num >= 1){
+       RevDigits[nDigits++] = num%10;
+       num = num / 10;
+      }
+      //##############################################
+      if(RevDigits[3]>3)//Baryons
+       ismHF = 1;
+      else if(RevDigits[2]>3)//Mesons
+       ismHF = 1;
+      
+      ismLongLivedOrK = IsLongLivedOrK(mcPm->PdgCode());
+      
+      if(!ismHF && ismLongLivedOrK)
+       isPhysPrimary = 0;
+      
+    }//while( >=nPTracks)
+  }
+  
+  return isPhysPrimary;
+}
+
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEMCALMesonGGSDMpPb::IsLongLivedOrK(Int_t MyPDGcode){
+
+  Int_t MyFlag = 0;
+
+  if(
+     (TMath::Abs(MyPDGcode) == 22  ) ||        // Photon
+     (TMath::Abs(MyPDGcode) == 11  ) ||        // Electron
+     (TMath::Abs(MyPDGcode) == 13  ) ||        // Muon(-) 
+     (TMath::Abs(MyPDGcode) == 211 ) ||        // Pion
+     (TMath::Abs(MyPDGcode) == 321 ) ||        // Kaon
+     (TMath::Abs(MyPDGcode) == 310 ) ||        // K0s
+     (TMath::Abs(MyPDGcode) == 130 ) ||        // K0l
+     (TMath::Abs(MyPDGcode) == 2212) ||        // Proton 
+     (TMath::Abs(MyPDGcode) == 2112) ||        // Neutron
+     (TMath::Abs(MyPDGcode) == 3122) ||        // Lambda_0
+     (TMath::Abs(MyPDGcode) == 3112) ||        // Sigma Minus
+     (TMath::Abs(MyPDGcode) == 3222) ||        // Sigma Plus
+     (TMath::Abs(MyPDGcode) == 3312) ||        // Xsi Minus 
+     (TMath::Abs(MyPDGcode) == 3322) ||        // Xsi 
+     (TMath::Abs(MyPDGcode) == 3334) ||        // Omega
+     (TMath::Abs(MyPDGcode) == 12  ) ||        // Electron Neutrino 
+     (TMath::Abs(MyPDGcode) == 14  ) ||        // Muon Neutrino
+     (TMath::Abs(MyPDGcode) == 16  )   )       // Tau Neutrino
+    MyFlag = 1;
+
+  return MyFlag; 
+}
diff --git a/PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDMpPb.h b/PWGGA/EMCALTasks/AliAnalysisTaskEMCALMesonGGSDMpPb.h
new file mode 100644 (file)
index 0000000..0af5e40
--- /dev/null
@@ -0,0 +1,135 @@
+#ifndef ALIANALYSISTASKEMCALMesonGGSDMPPB_H
+#define ALIANALYSISTASKEMCALMesonGGSDMPPB_H
+
+class TF1;
+class TH1F;
+class TH2F;
+class TH3F;
+class TH1D;
+class TH2D;
+class TH3D;
+class TNtuple;
+class TList;
+class AliESDEvent;
+class AliAODEvent;
+class AliESDtrackCuts;
+class AliESDCaloCluster;
+class AliAODCaloCluster;
+class AliMCEvent;
+class AliMCParticle;
+class AliEMCALGeometry;
+
+#ifndef ALIANALYSISTASKSE_H
+#include "AliAnalysisTaskSE.h"
+#endif
+#include "AliAnalysisUtils.h"
+
+class AliAnalysisTaskEMCALMesonGGSDMpPb : public AliAnalysisTaskSE {
+ public:
+  AliAnalysisTaskEMCALMesonGGSDMpPb();
+  AliAnalysisTaskEMCALMesonGGSDMpPb(const char *name);
+  virtual ~AliAnalysisTaskEMCALMesonGGSDMpPb();
+    
+  virtual void     UserCreateOutputObjects();
+  virtual void     UserExec(Option_t *option);
+  virtual void     Terminate(Option_t *);
+    
+  void         SetMcMode(Bool_t b)                 { fMcMode       = b;             }
+  void         SetRecalScheme(Int_t kRecalibrator) { fRecalibrator = kRecalibrator; }
+  void         SetdRmin_ClustTrack(Double_t kdRmin_ClustTrack)    { fdRmin_ClustTrack = kdRmin_ClustTrack; }
+  void         SetFidPhiMinMax(Double_t kPhimin, Double_t kPhimax){ fPhimin = kPhimin; fPhimax = kPhimax; }
+  void         SetFidEtaMinMax(Double_t kEtamin, Double_t kEtamax){ fEtamin = kEtamin; fEtamax = kEtamax; }
+  
+ private:
+  static const int zvtx_bins = 16;
+  static const int mult_bins = 25;
+  static const unsigned int poolDepth = 25;
+  static const int cent_bins = 4;
+  
+  Int_t GetMultBin(Int_t mult);
+  Int_t GetZvtxBin(Double_t vertZ);
+  Int_t isGoodEsdCluster(AliESDCaloCluster* esdclust);
+  Int_t isGoodAodCluster(AliAODCaloCluster* aodclust);
+  Double_t getDeltaPhi(TLorentzVector p1, TLorentzVector p2);
+  Double_t getDeltaEta(TLorentzVector p1, TLorentzVector p2);
+  Double_t PrivateEnergyRecal(Double_t energy, Int_t iCalib);
+  Double_t GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const;
+  Int_t IsPhysPrimJ(AliMCEvent *mcEvent, Int_t iTrack);
+  Int_t IsLongLivedOrK(Int_t MyPDGcode);
+  
+  TList           *fOutput;        //! Output list
+  Bool_t           fMcMode;                 // monte carlo mode
+  Int_t            fRecalibrator;           // custom recalibrator? 
+  Double_t         fdRmin_ClustTrack; // Cuts. 
+  Double_t         fPhimin;           // Cuts. 
+  Double_t         fPhimax;           // Cuts. 
+  Double_t         fEtamin;           // Cuts. 
+  Double_t         fEtamax;           // Cuts. 
+  AliESDtrackCuts *fTrackCuts;     //! Track cuts
+  AliESDEvent     *fEsdEv;                  //!pointer to input esd event
+  AliAODEvent     *fAodEv;                  //!pointer to input aod event
+  TH1F           * h1_nClusters[cent_bins];  //! # of clusters/evt
+  TH1F            *h1_zvtx;  //! vertex distribution
+  TH1F            *h1_trigger;  //! # of clusters/evt
+  TH1F            *h1_centrality;  //! # of clusters/evt
+  TH1F           * h1_M[cent_bins];        //! Mass spectrum
+  TH1F           * h1_M_mix[cent_bins];    //! Mass spectrum
+  TH1F           * h1_E[cent_bins];        //! energy spectrum
+  TH2F            *h2_PhiEtaCluster;        //!  phi vs eta for the cluster CoG
+  TH2F            *h2_PhiEtaClusterCut;     //!  phi vs eta for the cluster CoG w/ cuts
+  TH2F            *h2_PhiEtaMaxCell;        //!  phi vs eta for the maximum cell
+  TH2F            *h2_PhiEtaMaxCellCut;     //!  phi vs eta for the maximum cell w/ cuts
+  TH1F           * h1_dR_ClustTrk[cent_bins];        //! Track Matching
+  TH2F            *h2_gE_RecTruth; //! gamma E, rec/truth, first bin is primaries, second is non-primaries
+  TH2F            *h2_eop_E;        //!  e over p vs E. simple
+  TH2F            *h2_eop_pT;        //!  e over p vs pT. simple
+  TH2F            *h2_E_time;        //!  cluster energy vs time.
+
+  TH1F           * h1_Pi0TruthPt[cent_bins];        //! Pt spectrum from MC! 
+  TH1F           * h1_PriPi0TruthPt[cent_bins];        //! Pt spectrum from MC! 
+  TH1F           * h1_Pi0TruthPtEmcal[cent_bins];        //! Pt spectrum from MC! 
+  TH1F           * h1_PriPi0TruthPtEmcal[cent_bins];        //! Pt spectrum from MC! 
+  TH1F           * h1_Pi0TruthPtPhi2piEta065[cent_bins];        //! Pt spectrum from MC! 
+  TH1F           * h1_Pi0TruthPtPhi2piEta1[cent_bins];        //! Pt spectrum from MC!   
+
+  TH2F            *h2_Pi0TruthPhiEta;    //! etaphi spectrum from MC! 
+  TH2F            *h2_PriPi0TruthPhiEta;    //! etaphi spectrum from MC! 
+  TH2F            *h2_Pi0TruthPhiEtaEmcal;    //! etaphi spectrum from MC! 
+  TH2F            *h2_PriPi0TruthPhiEtaEmcal;    //! etaphi spectrum from MC! 
+  TH2F            *h2_Pi0TruthPhiEta_Phi2piEta065;        //! Pt spectrum from MC! 
+  TH2F            *h2_Pi0TruthPhiEta_Phi2piEta1;        //! Pt spectrum from MC!   
+
+  TH1F           * h1_TruthPhotonsEmcal[cent_bins];        //! Pt spectrum from MC! 
+  TH2F            *h2_TruthPhotonsPhiEta;        //! Pt spectrum from MC! 
+  TH1F           * h1_PhotonsEmcal[cent_bins];        //! Pt spectrum from MC! 
+  TH1F           * h1_PhotonsNCellsCut[cent_bins];        //! Pt spectrum from MC! 
+  TH1F           * h1_PhotonsTrackMatchCut[cent_bins];        //! Pt spectrum from MC! 
+  TH1F           * h1_PhotonsAllCut[cent_bins];        //! Pt spectrum from MC! 
+  TH2F            *h2_PhotonsPhiEtaIsEmcal;        //! Pt spectrum from MC! 
+
+  TH1F           * h1_dR_RealMC[cent_bins];        //! Pt spectrum from MC! 
+
+  TH1F           * h1_Chi2[cent_bins];       //! pseudorapidity spectrum
+  TH1F           * h1_nTrkMatch[cent_bins];       //! pseudorapidity spectrum
+  TH1F           * h1_nCells[cent_bins];       //! pseudorapidity spectrum
+  TH1F           * h1_ClusterDisp[cent_bins];       //! cluster dispersion
+  TH2F           * h2_Ellipse[cent_bins];       //! ellipse axis?
+  TH2F           * h2_EtaPt[cent_bins];       //! 2d histogram Y - pseudorap spectrum
+  TH3F           * h3_MptAsymm[cent_bins];       //!  3dimensional E vs mom
+  TH3F           * h3_MptAsymm_mix[cent_bins];       //!  3dimensional E vs mom
+  TH2F           * h2_dphi_deta[cent_bins];       //! 2dimensional E vs mom
+  TH2F           * h2_dphi_deta_mix[cent_bins];       //! 2dimensional E vs mom
+  TH2F           * h2_DispRes[cent_bins];       //! 2dimensional E vs mom
+  TH2F           * h2_cells_M02[cent_bins];       //! 
+
+  std::vector<TLorentzVector> Photons[poolDepth][zvtx_bins][mult_bins];
+  std::vector<Int_t> TriggerList;
+  AliAnalysisUtils*   fHelperClass;           //! Vertex selection helper
+
+  AliAnalysisTaskEMCALMesonGGSDMpPb(const AliAnalysisTaskEMCALMesonGGSDMpPb&); // not implemented
+  AliAnalysisTaskEMCALMesonGGSDMpPb& operator=(const AliAnalysisTaskEMCALMesonGGSDMpPb&); // not implemented
+    
+  ClassDef(AliAnalysisTaskEMCALMesonGGSDMpPb, 1); // example of analysis
+};
+#endif
diff --git a/PWGGA/EMCALTasks/AliAnalysisTaskSDMGammaMC.cxx b/PWGGA/EMCALTasks/AliAnalysisTaskSDMGammaMC.cxx
new file mode 100644 (file)
index 0000000..dc703d6
--- /dev/null
@@ -0,0 +1,1120 @@
+#include "AliAnalysisTaskSDMGammaMC.h"
+#include <vector>
+#include <Riostream.h>
+#include <TChain.h>
+#include <TTree.h>
+#include <TF1.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TH3F.h>
+#include <TH1D.h>
+#include <TH2D.h>
+#include <TH3D.h>
+#include <TCanvas.h>
+#include <TList.h>
+#include <TFile.h>
+#include <TLorentzVector.h>
+#include <TNtuple.h>
+#include <TRandom3.h>
+
+#include "AliAnalysisTaskSE.h"
+#include "AliAnalysisManager.h"
+#include "AliStack.h"
+#include "AliESDtrackCuts.h"
+#include "AliESDEvent.h"
+#include "AliESDInputHandler.h"
+#include "AliAODEvent.h"
+#include "AliMCEvent.h"
+#include "AliEMCALGeometry.h"
+#include "AliInputEventHandler.h"
+#include "AliESDInputHandler.h"
+#include "AliAODInputHandler.h"
+
+#include "AliEMCALRecoUtils.h"
+#include "AliExternalTrackParam.h"
+
+// ROOT includes
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TGeoBBox.h>
+#include <TH2F.h>
+#include <TArrayI.h>
+#include <TArrayF.h>
+#include <TObjArray.h>
+
+// STEER includes
+#include "AliVCluster.h"
+#include "AliVCaloCells.h"
+#include "AliLog.h"
+#include "AliPID.h"
+#include "AliESDEvent.h"
+#include "AliAODEvent.h"
+#include "AliESDtrack.h"
+#include "AliAODTrack.h"
+#include "AliExternalTrackParam.h"
+#include "AliESDfriendTrack.h"
+#include "AliTrackerBase.h"
+
+// EMCAL includes
+#include "AliEMCALRecoUtils.h"
+#include "AliEMCALGeometry.h"
+#include "AliTrackerBase.h"
+#include "AliEMCALCalibTimeDepCorrection.h" // Run dependent
+#include "AliEMCALPIDUtils.h"
+
+
+ClassImp(AliAnalysisTaskSDMGammaMC)
+
+//________________________________________________________________________
+AliAnalysisTaskSDMGammaMC::AliAnalysisTaskSDMGammaMC() : 
+  AliAnalysisTaskSE(),
+  fOutput(0),
+  fMcMode(0),
+  fRecalibrator(0),
+  fPhimin(0),
+  fPhimax(0),
+  fEtamin(0),
+  fEtamax(0),
+  fTrackCuts(0),
+  fEsdEv(0),
+  fAodEv(0),
+  h1_nClusters(0), 
+  h1_zvtx(0), 
+  h1_trigger(0), 
+  h1_E(0), 
+  h1_Phi(0), 
+  h2_PiMotherID(0), 
+  h2_GaMotherID(0), 
+  h3_gE_RecTruth(0), 
+  h3_gE_RecTruth_ncellscut(0), 
+  h1_Pi0TruthPt(0), 
+  h1_PriPi0TruthPt(0), 
+  h1_Pi0TruthPtEmcal(0), 
+  h1_PriPi0TruthPtEmcal(0), 
+  h2_Pi0TruthPhiEta(0), 
+  h2_PriPi0TruthPhiEta(0), 
+  h2_Pi0TruthPhiEtaEmcal(0), 
+  h2_PriPi0TruthPhiEtaEmcal(0), 
+  h1_TruthPhotonsEmcal(0), 
+  h2_TruthPhotonsPhiEta(0),
+  h1_PhotonsEmcal(0), 
+  h1_PhotonsNCellsCut(0), 
+  h1_PhotonsTrackMatchCut(0), 
+  h1_PhotonsAllCut(0), 
+  h2_PhotonsPhiEtaIsEmcal(0),
+  h1_dR_RealMC(0),
+  h1_Eta(0),
+  h1_Chi2(0),
+  h1_nTrkMatch(0),
+  h1_nCells(0),
+  h1_ClusterDisp(0),
+  h2_Ellipse(0),
+  h2_EtaPt(0),
+  h2_dphi_deta(0), 
+  h2_dphi_deta_mix(0), 
+  h2_DispRes(0),
+  h2_cells_M02(0),
+  TriggerList(0)
+{
+  // Dummy constructor ALWAYS needed for I/O.
+}
+
+//________________________________________________________________________
+AliAnalysisTaskSDMGammaMC::AliAnalysisTaskSDMGammaMC(const char *name) :
+  AliAnalysisTaskSE(name),
+  fOutput(0),
+  fMcMode(0),
+  fRecalibrator(0),
+  fPhimin(0),
+  fPhimax(0),
+  fEtamin(0),
+  fEtamax(0),
+  fTrackCuts(0),
+  fEsdEv(0),
+  fAodEv(0),
+  h1_nClusters(0), 
+  h1_zvtx(0), 
+  h1_trigger(0), 
+  h1_E(0), 
+  h1_Phi(0), 
+  h2_PiMotherID(0), 
+  h2_GaMotherID(0), 
+  h3_gE_RecTruth(0), 
+  h3_gE_RecTruth_ncellscut(0), 
+  h1_Pi0TruthPt(0), 
+  h1_PriPi0TruthPt(0), 
+  h1_Pi0TruthPtEmcal(0), 
+  h1_PriPi0TruthPtEmcal(0), 
+  h2_Pi0TruthPhiEta(0), 
+  h2_PriPi0TruthPhiEta(0), 
+  h2_Pi0TruthPhiEtaEmcal(0), 
+  h2_PriPi0TruthPhiEtaEmcal(0), 
+  h1_TruthPhotonsEmcal(0), 
+  h2_TruthPhotonsPhiEta(0),
+  h1_PhotonsEmcal(0), 
+  h1_PhotonsNCellsCut(0), 
+  h1_PhotonsTrackMatchCut(0), 
+  h1_PhotonsAllCut(0), 
+  h2_PhotonsPhiEtaIsEmcal(0),
+  h1_dR_RealMC(0),
+  h1_Eta(0),
+  h1_Chi2(0),
+  h1_nTrkMatch(0),
+  h1_nCells(0),
+  h1_ClusterDisp(0),
+  h2_Ellipse(0),
+  h2_EtaPt(0),
+  h2_dphi_deta(0), 
+  h2_dphi_deta_mix(0), 
+  h2_DispRes(0), 
+  h2_cells_M02(0),
+  TriggerList(0)
+{
+  // Constructor
+  // Define input and output slots here (never in the dummy constructor)
+  // Input slot #0 works with a TChain - it is connected to the default input container
+  // Output slot #1 writes into a TH1 container
+
+
+  DefineOutput(1, TList::Class());                                            // for output list
+}
+
+//________________________________________________________________________
+AliAnalysisTaskSDMGammaMC::~AliAnalysisTaskSDMGammaMC()
+{
+  // Destructor. Clean-up the output list, but not the histograms that are put inside
+  // (the list is owner and will clean-up these histograms). Protect in PROOF case.
+  if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
+    delete fOutput;
+  }
+  delete fTrackCuts;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskSDMGammaMC::UserCreateOutputObjects()
+{
+  // Create histograms
+  // Called once (on the worker node)
+
+  fOutput = new TList();
+  fOutput->SetOwner();  // IMPORTANT!
+   
+  fTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE);
+
+  cout << "__________AliAnalysisTaskSDMGammaMC: Input settings__________" << endl;
+  cout << " fMcMode:             " << fMcMode   << endl;
+  cout << " fRecalibrator:       " << fRecalibrator << endl;
+  cout << " phi range:           " << fPhimin << ", " << fPhimax << endl;
+  cout << " eta range:           " << fEtamin << ", " << fEtamax << endl;
+  cout << " number of zvtx bins: " << zvtx_bins << endl;
+  cout << " number of mult bins: " << mult_bins << endl;
+  cout << " poolDepth:           " << poolDepth << endl;
+  cout << endl;
+  
+
+  double TotalNBins = 0.0;
+
+  // Create histograms
+  Int_t nClustersbins = 501;
+  Float_t nClusterslow = -0.5, nClustersup = 500.5;
+  h1_nClusters = new TH1F("h1_nClusters", "# of clusters", nClustersbins, nClusterslow, nClustersup);
+  h1_nClusters->GetXaxis()->SetTitle("number of clusters/evt");
+  h1_nClusters->GetYaxis()->SetTitle("counts");
+  h1_nClusters->SetMarkerStyle(kFullCircle);
+  TotalNBins+=nClustersbins;
+
+  Int_t nZvertexbins = 501;
+  Float_t Zvertexlow = -50.0, Zvertexup = 50.0;
+  h1_zvtx = new TH1F("h1_zvtx", "# of clusters", nZvertexbins, Zvertexlow, Zvertexup);
+  h1_zvtx->GetXaxis()->SetTitle("z_{vertex}");
+  h1_zvtx->GetYaxis()->SetTitle("counts");
+  h1_zvtx->SetMarkerStyle(kFullCircle);
+  TotalNBins+=nZvertexbins;
+
+  h1_trigger = new TH1F("h1_trigger", "trigger number returned", 1001,-0.5,1000.5);
+  TotalNBins+=1001;
+
+  Int_t ptbins = 2000;
+  Float_t ptlow = 0.0, ptup = 20.0;
+  Int_t Ebins = 1000;
+  Float_t Elow = 0.0, Eup = 20.0;
+  h1_E = new TH1F("h1_E", "Cluster Energy in EMCal", Ebins, Elow, Eup);
+  h1_E->GetXaxis()->SetTitle("E [GeV]");
+  h1_E->GetYaxis()->SetTitle("counts");
+  h1_E->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Ebins;
+
+  h1_Phi = new TH1F("h1_Phi", "phi distribution", 1000, -7, 7);
+  h1_Phi->GetXaxis()->SetTitle("#phi [rad]");
+  h1_Phi->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_Phi->SetMarkerStyle(kFullCircle);
+  TotalNBins+=1000;
+
+  h2_PiMotherID = new TH2F("h2_PiMotherID", "Mother ID for Truth Pi0's", 100001, -0.5,100000.5, 2, 0.5,2.5);
+  h2_PiMotherID->GetXaxis()->SetTitle("#pi^{0} Mother Particle ID");
+  h2_PiMotherID->GetYaxis()->SetTitle("primary or non-primary");
+  h2_PiMotherID->GetZaxis()->SetTitle("counts");
+  h2_PiMotherID->SetMarkerStyle(kFullCircle);
+  TotalNBins+=2*100001;
+
+  h2_GaMotherID = new TH2F("h2_GaMotherID", "Mother ID for Truth #gamma's", 100001, -0.5,100000.5, 2, 0.5,2.5);
+  h2_GaMotherID->GetXaxis()->SetTitle("#gamma Mother Particle ID");
+  h2_GaMotherID->GetYaxis()->SetTitle("primary or non-primary");
+  h2_GaMotherID->GetZaxis()->SetTitle("counts");
+  h2_GaMotherID->SetMarkerStyle(kFullCircle);
+  TotalNBins+=2*100001;
+
+  h3_gE_RecTruth = new TH3F("h3_gE_RecTruth", "#gamma E_{truth}/E_{clust} vs E_{clust}", Ebins,Elow,Eup, 1000,0,4, 4,0.5,4.5);
+  h3_gE_RecTruth->GetXaxis()->SetTitle("E^{rec}_{clust} [GeV]");
+  h3_gE_RecTruth->GetYaxis()->SetTitle("E^{rec}_{clust}/E^{truth}_{#gamma}");
+  h3_gE_RecTruth->GetZaxis()->SetTitle("category");
+  h3_gE_RecTruth->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Ebins*1000*4;
+  
+  h3_gE_RecTruth_ncellscut = new TH3F("h3_gE_RecTruth_ncellscut", "#gamma E_{truth}/E_{clust} vs E_{clust} (for nCells>1)", Ebins,Elow,Eup, 1000,0,4, 4,0.5,4.5);
+  h3_gE_RecTruth_ncellscut->GetXaxis()->SetTitle("E^{rec}_{clust} [GeV]");
+  h3_gE_RecTruth_ncellscut->GetYaxis()->SetTitle("E^{rec}_{clust}/E^{truth}_{#gamma}");
+  h3_gE_RecTruth_ncellscut->GetZaxis()->SetTitle("category");
+  h3_gE_RecTruth_ncellscut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=Ebins*1000*4;
+  
+  h1_Pi0TruthPt = new TH1F("h1_Pi0TruthPt", "P_{T} distribution for Truth Pi0's", ptbins, ptlow, ptup);
+  h1_Pi0TruthPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_Pi0TruthPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_Pi0TruthPt->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PriPi0TruthPt = new TH1F("h1_PriPi0TruthPt", "P_{T} distribution for Truth Primary Pi0's", ptbins, ptlow, ptup);
+  h1_PriPi0TruthPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PriPi0TruthPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PriPi0TruthPt->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_Pi0TruthPtEmcal = new TH1F("h1_Pi0TruthPtEmcal", "P_{T} distribution for Truth Pi0's (hit EMCal)", ptbins, ptlow, ptup);
+  h1_Pi0TruthPtEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_Pi0TruthPtEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_Pi0TruthPtEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PriPi0TruthPtEmcal = new TH1F("h1_PriPi0TruthPtEmcal", "P_{T} distribution for Truth Primary Pi0's (hit EMCal)", ptbins, ptlow, ptup);
+  h1_PriPi0TruthPtEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PriPi0TruthPtEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PriPi0TruthPtEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h2_Pi0TruthPhiEta = new TH2F("h2_Pi0TruthPhiEta","Pi0Truth Phi vs Eta ", 380,-0.02,6.30, 200,-10,10);
+  h2_Pi0TruthPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_Pi0TruthPhiEta->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*200;
+
+  h2_PriPi0TruthPhiEta = new TH2F("h2_PriPi0TruthPhiEta","Primary Pi0Truth Phi vs Eta ", 380,-0.02,6.30, 200,-10,10);
+  h2_PriPi0TruthPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PriPi0TruthPhiEta->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*200;
+
+  h2_Pi0TruthPhiEtaEmcal = new TH2F("h2_Pi0TruthPhiEtaEmcal","Pi0Truth Phi vs Eta (in EMCal)", 380,-0.02,6.30, 150,-5,5);
+  h2_Pi0TruthPhiEtaEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_Pi0TruthPhiEtaEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+
+  h2_PriPi0TruthPhiEtaEmcal = new TH2F("h2_PriPi0TruthPhiEtaEmcal","Primary Pi0Truth Phi vs Eta (in EMCal)", 380,-0.02,6.30, 150,-5,5);
+  h2_PriPi0TruthPhiEtaEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PriPi0TruthPhiEtaEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+
+  h1_TruthPhotonsEmcal = new TH1F("h1_TruthPhotonsEmcal", "P_{T} distribution for photons (in EMCal)", ptbins, ptlow, ptup);
+  h1_TruthPhotonsEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_TruthPhotonsEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_TruthPhotonsEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h2_TruthPhotonsPhiEta = new TH2F("h2_TruthPhotonsPhiEta", 
+                                  "Truth Photons Phi vs Eta (pointed at emcal)", 380,-0.02,6.30, 150,-1.5,1.5);
+  h2_TruthPhotonsPhiEta->GetXaxis()->SetTitle("#phi [rad]");
+  h2_TruthPhotonsPhiEta->GetYaxis()->SetTitle("#eta ");
+  h2_TruthPhotonsPhiEta->SetMarkerStyle(kFullCircle);
+  TotalNBins+=380*150;
+
+  h1_PhotonsEmcal = new TH1F("h1_PhotonsEmcal", "P_{T} distribution for photons (in EMCal)", ptbins, ptlow, ptup);
+  h1_PhotonsEmcal->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhotonsEmcal->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhotonsEmcal->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PhotonsNCellsCut = new TH1F("h1_PhotonsNCellsCut", "P_{T} distribution for #gamma's that survive NCells cut", ptbins, ptlow, ptup);
+  h1_PhotonsNCellsCut->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhotonsNCellsCut->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhotonsNCellsCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PhotonsTrackMatchCut = new TH1F("h1_PhotonsTrackMatchCut", "P_{T} distribution for #gamma's that survive TrackMatch cut", ptbins, ptlow, ptup);
+  h1_PhotonsTrackMatchCut->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhotonsTrackMatchCut->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhotonsTrackMatchCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h1_PhotonsAllCut = new TH1F("h1_PhotonsAllCut", "P_{T} distribution for #gamma's that survive All cut", ptbins, ptlow, ptup);
+  h1_PhotonsAllCut->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h1_PhotonsAllCut->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
+  h1_PhotonsAllCut->SetMarkerStyle(kFullCircle);
+  TotalNBins+=ptbins;
+
+  h2_PhotonsPhiEtaIsEmcal = new TH2F("h2_PhotonsPhiEtaIsEmcal",
+                                    "Photons Phi vs Eta (IsEMCAL()==1)", 380,-0.02,6.30, 150,-1.5,1.5);
+  h2_PhotonsPhiEtaIsEmcal->GetXaxis()->SetTitle("#phi [rad]");
+  h2_PhotonsPhiEtaIsEmcal->GetYaxis()->SetTitle("#eta ");
+  TotalNBins+=380*150;
+  
+  h1_dR_RealMC = new TH1F("h1_dR_RealMC", "P_{T} distribution for #gamma's that survive All cut", 2000, -0.01, 10);
+  h1_dR_RealMC->GetXaxis()->SetTitle("dR sqrt(dx^{2}+dy^{2})");
+  h1_dR_RealMC->GetYaxis()->SetTitle("N");
+  h1_dR_RealMC->SetMarkerStyle(kFullCircle);
+  TotalNBins+=2000;
+
+  Int_t etabins = 150;
+  Float_t etalow = -1.5, etaup = 1.5;
+  h1_Eta = new TH1F("h1_Eta","#eta distribution for reconstructed",etabins, etalow, etaup);
+  h1_Eta->GetXaxis()->SetTitle("#eta");
+  h1_Eta->GetYaxis()->SetTitle("counts");
+  TotalNBins+=etabins;
+  
+  Int_t chi2bins = 100;
+  Float_t chi2low = -2, chi2up = 2;
+  h1_Chi2 = new TH1F("h1_Chi2","#chi^{2} distribution for reconstructed",chi2bins, chi2low, chi2up);
+  h1_Chi2->GetXaxis()->SetTitle("#chi^{2}");
+  h1_Chi2->GetYaxis()->SetTitle("counts");
+  TotalNBins+=chi2bins;
+
+  h1_nTrkMatch = new TH1F("h1_nTrkMatch","number of matched tracks",14, -1.5, 5.5);
+  h1_nTrkMatch->GetXaxis()->SetTitle("nTracksMatched");
+  h1_nTrkMatch->GetYaxis()->SetTitle("counts");
+  TotalNBins+=14;
+       
+  h1_ClusterDisp = new TH1F("h1_ClusterDisp","Dispersion of CaloCluster",1000, -1, 3);
+  h1_ClusterDisp->GetXaxis()->SetTitle("cluster->GetClusterDisp()");
+  h1_ClusterDisp->GetYaxis()->SetTitle("counts");
+  TotalNBins+=1000;
+       
+  h2_Ellipse = new TH2F("h2_Ellipse","Ellipse axis M20 vs M02",500, -0.01, 1, 500, -0.01, 1);
+  h2_Ellipse->GetXaxis()->SetTitle("cluster->GetM20()");
+  h2_Ellipse->GetYaxis()->SetTitle("cluster->GetM02()");
+  h2_Ellipse->GetZaxis()->SetTitle("counts");
+  TotalNBins+=500*500;
+       
+  h2_EtaPt = new TH2F("h2_EtaPt","Cluster Energy vs ",etabins, etalow, etaup, ptbins, ptlow, ptup);
+  h2_EtaPt->GetXaxis()->SetTitle("E [GeV]");
+  h2_EtaPt->GetYaxis()->SetTitle("p_{T} [GeV/c]");
+  TotalNBins+=etabins*ptbins;
+
+  h2_dphi_deta = new TH2F("h2_dphi_deta","#Delta#phi vs #Delta#eta", 349,-1.5,5, 400,-2.0,2.0);
+  h2_dphi_deta->GetXaxis()->SetTitle("#Delta#phi");
+  h2_dphi_deta->GetYaxis()->SetTitle("#Delta#eta");
+  TotalNBins+=349*400;
+  
+  h2_dphi_deta_mix = new TH2F("h2_dphi_deta_mix","#Delta#phi vs #Delta#eta (mixed events)", 349,-1.5,5, 400,-2.0,2.0);
+  h2_dphi_deta_mix->GetXaxis()->SetTitle("#Delta#phi");
+  h2_dphi_deta_mix->GetYaxis()->SetTitle("#Delta#eta");
+  TotalNBins+=349*400;
+
+  h2_DispRes = new TH2F("h2_DispRes", "zvtx info", 500,-0.01,1, 500,-0.1,2);
+  h2_DispRes->GetXaxis()->SetTitle("EvtVtx->GetDispersion()");
+  h2_DispRes->GetYaxis()->SetTitle("EvtVtx->GetZRes()");
+  h2_DispRes->GetZaxis()->SetTitle("counts");
+  TotalNBins+=500*500;
+
+  h2_cells_M02 = new TH2F("h2_cells_M02", "nCells vs M02", 204,-1.5,100.5, 500,-1,1.5);
+  h2_cells_M02->GetXaxis()->SetTitle("nCells");
+  h2_cells_M02->GetYaxis()->SetTitle("M02");
+  h2_cells_M02->GetZaxis()->SetTitle("counts");
+  TotalNBins+=204*500;
+
+  cout << endl << "Total number of bins in booked histograms:  " << TotalNBins << endl << endl;
+
+  //TFile *f = OpenFile(1); 
+  //TDirectory::TContext context(f);
+    
+  fOutput->Add(h1_nClusters);
+  fOutput->Add(h1_zvtx);
+  fOutput->Add(h1_trigger);
+  fOutput->Add(h1_E);
+  fOutput->Add(h1_Phi);
+  fOutput->Add(h2_PiMotherID);
+  fOutput->Add(h2_GaMotherID);
+  fOutput->Add(h3_gE_RecTruth);
+  fOutput->Add(h3_gE_RecTruth_ncellscut);
+  fOutput->Add(h1_Pi0TruthPt);
+  fOutput->Add(h1_PriPi0TruthPt);
+  fOutput->Add(h1_Pi0TruthPtEmcal);
+  fOutput->Add(h1_PriPi0TruthPtEmcal);
+  fOutput->Add(h2_Pi0TruthPhiEta);
+  fOutput->Add(h2_PriPi0TruthPhiEta);
+  fOutput->Add(h2_Pi0TruthPhiEtaEmcal);
+  fOutput->Add(h2_PriPi0TruthPhiEtaEmcal);
+  fOutput->Add(h1_TruthPhotonsEmcal);
+  fOutput->Add(h2_TruthPhotonsPhiEta);
+  fOutput->Add(h1_PhotonsEmcal);
+  fOutput->Add(h1_PhotonsNCellsCut);
+  fOutput->Add(h1_PhotonsTrackMatchCut);
+  fOutput->Add(h1_PhotonsAllCut);
+  fOutput->Add(h2_PhotonsPhiEtaIsEmcal);
+  fOutput->Add(h1_dR_RealMC);
+  fOutput->Add(h1_Eta);
+  fOutput->Add(h1_Chi2);
+  fOutput->Add(h1_nTrkMatch);
+  fOutput->Add(h1_ClusterDisp);
+  fOutput->Add(h2_Ellipse);
+  fOutput->Add(h2_EtaPt);
+  fOutput->Add(h2_dphi_deta);
+  fOutput->Add(h2_dphi_deta_mix);
+  fOutput->Add(h2_DispRes);
+  fOutput->Add(h2_cells_M02);
+
+  // Post data for ALL output slots >0 here, 
+  // To get at least an empty histogram 
+  // 1 is the outputnumber of a certain weg of task 1  
+  PostData(1, fOutput); 
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskSDMGammaMC::UserExec(Option_t *) 
+{
+  // Main loop Called for each event
+
+  AliMCEvent *mcEvent = MCEvent();  
+  Bool_t isMC = bool(mcEvent);//is this the right way to do this? 
+  if (!mcEvent){
+    cout << "no MC event" << endl;
+    return;
+  }
+  
+  TRandom3 randy; randy.SetSeed(0);
+
+  double recalScale = 1.0;
+
+  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();    
+  
+  AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (am->GetInputEventHandler());
+  AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (am->GetInputEventHandler());
+  if (!aodH && !esdH)  Printf("ERROR: Could not get ESD or AODInputHandler");
+  
+  if(esdH)      fEsdEv = esdH->GetEvent();    
+  else if(aodH) fAodEv = aodH->GetEvent();  
+  else{
+    AliFatal("Neither ESD nor AOD event found");
+    return;
+  }
+
+
+  // get pointer to reconstructed event
+  AliVEvent *event = InputEvent();
+  if (!event){
+    AliError("Pointer == 0, this can not happen!");  return;}
+  //AliESDEvent* fEsdEv = dynamic_cast<AliESDEvent*>(event);
+  //AliAODEvent* aod = dynamic_cast<AliAODEvent*>(event);
+  //if (!fEsdEv){
+  //AliError("Cannot get the ESD event");  return;}
+  
+  Int_t iTrigger = 0;
+  if (fEsdEv)       iTrigger = fEsdEv->GetHeader()->GetL0TriggerInputs();
+  else if (fAodEv)  iTrigger = fAodEv->GetHeader()->GetL0TriggerInputs();
+  //h1_trigger->Fill(iTrigger);
+  
+  char saythis[500];
+  Int_t iTriggerBin = 0;
+  for(unsigned long j=0; j<TriggerList.size(); j++){
+    if(iTrigger==TriggerList[j])
+      iTriggerBin=j+1;
+  }
+  if(iTriggerBin==0){
+    TriggerList.push_back(iTrigger);
+    iTriggerBin=TriggerList.size();
+  }
+  
+  h1_trigger->SetBinContent(iTriggerBin, h1_trigger->GetBinContent(iTriggerBin)+1);
+  sprintf(saythis,"%d",iTrigger);
+  h1_trigger->GetXaxis()->SetBinLabel(iTriggerBin, saythis);
+  
+  if(fEsdEv){
+    TString trigClasses = fEsdEv->GetFiredTriggerClasses();
+    // remove "fast cluster events": 
+    if (trigClasses.Contains("FAST")  && !trigClasses.Contains("ALL"))
+      return;
+  }
+  else if(fAodEv){
+    TString trigClasses = fAodEv->GetFiredTriggerClasses();
+    // remove "fast cluster events": 
+    if (trigClasses.Contains("FAST")  && !trigClasses.Contains("ALL"))
+      return;
+  }
+  
+  if (fEsdEv){
+    if(!(fEsdEv->GetPrimaryVertex()->GetStatus()))   return;
+  }
+  //else if (fAodEv){
+  //if(!(fAodEv->GetPrimaryVertex()->GetStatus()))   return;
+  //}
+
+  Double_t vertDisp=0.0;
+  Double_t vertZres=0.0;
+  Bool_t vertIsfromZ=0;
+  if (fEsdEv){
+    vertDisp    = fEsdEv->GetPrimaryVertex()->GetDispersion();
+    vertZres    = fEsdEv->GetPrimaryVertex()->GetZRes();
+    vertIsfromZ = fEsdEv->GetPrimaryVertex()->IsFromVertexerZ();
+  }
+  else if (fAodEv){
+    vertDisp    = 0;
+    vertZres    = 0;
+    vertIsfromZ = 0;
+  }    
+
+  h2_DispRes->Fill(vertDisp, vertZres);  
+  // if vertex is from spd vertexZ, require more stringent cut
+  if (vertIsfromZ) {
+    if (vertDisp>0.02 ||  vertZres>0.25 ) 
+      return; // bad vertex from VertexerZ
+  }
+
+  Int_t nclusters=0;
+  if(fEsdEv){
+    //Int_t evtN      = fEsdEv->GetEventNumberInFile();  
+    //Int_t ntracks   = fEsdEv->GetNumberOfTracks();
+    nclusters = fEsdEv->GetNumberOfCaloClusters();
+  }
+  else if(fAodEv){
+    //Int_t evtN      = fAodEv->GetEventNumberInFile();  
+    //Int_t ntracks   = fAodEv->GetNumberOfTracks();
+    nclusters = fAodEv->GetNumberOfCaloClusters();
+  }
+
+  // EMCal cluster loop for reconstructed event
+  //numberofclusters set above! 
+  Double_t vertZ=0.0;
+  if (fEsdEv)       vertZ = fEsdEv->GetPrimaryVertex()->GetZ();
+  else if (fAodEv)  vertZ = fAodEv->GetPrimaryVertex()->GetZ();    
+
+  h1_zvtx->Fill(vertZ);
+  //zvertex cut:
+  if(fabs(vertZ)>10.0)
+    return;
+  
+  h1_nClusters->Fill(nclusters);
+
+  //cout << iskip << " " << izvtx << " " << imult << endl;  
+  //cout << "GetNumberOfVertices(): " << fAodEv->GetNumberOfVertices() << endl;
+
+
+
+  //######################### ~~~~~~~~~~~ ##################################
+  //######################### STARTING MC ##################################
+  //######################### ~~~~~~~~~~~ ##################################
+  
+  if(isMC){
+    int isPrimary  = 0;
+    int isK0sDecay = 0;
+
+    if (!mcEvent){
+      cout << "no MC event" << endl;
+      return;
+    }
+    
+    const AliVVertex *evtVtx = mcEvent->GetPrimaryVertex();
+    if (!evtVtx)
+      return;
+    
+    mcEvent->PreReadAll();    
+    
+    Int_t nTracksMC  = mcEvent->GetNumberOfTracks();
+    Int_t nPTracksMC = mcEvent->GetNumberOfPrimaries();
+
+    for (Int_t iTrack = 0; iTrack<nTracksMC; ++iTrack) {
+      AliMCParticle *mcP = static_cast<AliMCParticle*>(mcEvent->GetTrack(iTrack));
+      if (!mcP)
+       continue;            
+      
+      if(iTrack<nPTracksMC)  isPrimary = 1;
+      else                   isPrimary = 0;
+      
+      if(mcP->PdgCode() == 22){
+       if(isPrimary==1){
+         if(mcP->GetMother()>-1)
+           h2_GaMotherID->Fill(( (AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()) )->PdgCode(), 1);
+         else
+           h2_GaMotherID->Fill(0.0,1);
+       }
+       else
+         h2_GaMotherID->Fill(( (AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()) )->PdgCode(), 2);   
+      }
+      
+      // it's a pion !! 
+      if(mcP->PdgCode() != 111)
+       continue;
+      
+      isK0sDecay = 0;
+      if(mcP->GetMother()>-1){
+       if( ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() ==  310 ||
+           ((AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()))->PdgCode() == -310  )
+         isK0sDecay = 1;
+      }      
+      
+      // primary particle
+      //Double_t dR_vtx = TMath::Sqrt((mcP->Xv()-evtVtx->GetX())*(mcP->Xv()-evtVtx->GetX()) + 
+      //                           (mcP->Yv()-evtVtx->GetY())*(mcP->Yv()-evtVtx->GetY()));
+      //if(dR_vtx <= 0.01)  isPrimary = 1;
+      //else            isPrimary = 0;
+      
+      
+      if(isPrimary==1){
+       if(mcP->GetMother()>-1)
+         h2_PiMotherID->Fill(( (AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()) )->PdgCode(), 1);
+       else
+         h2_PiMotherID->Fill(0.0,1);
+      }
+      else
+       h2_PiMotherID->Fill(( (AliMCParticle*)mcEvent->GetTrack(mcP->GetMother()) )->PdgCode(), 2);
+      
+      h1_Pi0TruthPt    ->Fill(mcP->Pt());
+      h2_Pi0TruthPhiEta->Fill(mcP->Phi(),mcP->Eta());
+      
+      if(isPrimary==1){
+       h1_PriPi0TruthPt    ->Fill(mcP->Pt());
+       h2_PriPi0TruthPhiEta->Fill(mcP->Phi(),mcP->Eta());
+      }
+      
+      if(mcP->Eta()<-1.0 || mcP->Eta()>1.0)
+       continue;
+      
+      Int_t DecayPhotonLabel[2] = {mcP->GetFirstDaughter(),
+                                  mcP->GetLastDaughter() };
+      
+      if (DecayPhotonLabel[0]<0)  continue;
+      if (DecayPhotonLabel[1]<0)  DecayPhotonLabel[1]=DecayPhotonLabel[0];      
+      if (DecayPhotonLabel[1]-DecayPhotonLabel[0] != 1)  continue;
+      
+      bool bacc = true;
+      bool binp = true;
+      bool isConv[2] = {1,1};
+      Int_t convIndices[2][2] = { {-1,-1},{-1,-1} };
+      Double_t eta_d[2] = {0.0,0.0};
+      Double_t phi_d[2] = {0.0,0.0};
+      Int_t daughter_index = -1;
+      for (Int_t iPhoton=DecayPhotonLabel[0];iPhoton<=DecayPhotonLabel[1];++iPhoton){
+       if(iPhoton==DecayPhotonLabel[0]) daughter_index=0;
+       else                             daughter_index=1;
+        const AliMCParticle *dmc = static_cast<const AliMCParticle *>(mcEvent->GetTrack(iPhoton));
+       eta_d[daughter_index] = dmc->Eta();
+       phi_d[daughter_index] = dmc->Phi();
+        if(!(dmc->PdgCode()==22))             binp = false;
+        if(!(eta_d[daughter_index]>fEtamin && eta_d[daughter_index]<fEtamax && 
+            phi_d[daughter_index]>fPhimin && phi_d[daughter_index]<fPhimax   ))   bacc = false;        
+       
+       if( ((TParticle*)dmc->Particle())->GetNDaughters() != 2 )  isConv[daughter_index] = 0;
+       else{//if photon has 2 daughters. 
+         
+         Int_t dd1 = dmc->GetFirstDaughter();
+         Int_t dd2 = dmc->GetLastDaughter();
+         if (dd2-dd1 != 1)  cout << "How can this happen???? " << endl;
+         const AliMCParticle *dd1mc = static_cast<const AliMCParticle *>(mcEvent->GetTrack(dd1));
+         const AliMCParticle *dd2mc = static_cast<const AliMCParticle *>(mcEvent->GetTrack(dd2));
+         if( dd1mc->PdgCode() != -dd2mc->PdgCode() )
+           isConv[daughter_index] = 0;
+         else if( TMath::Abs(dd1mc->PdgCode())!=11 )
+           isConv[daughter_index] = 0;
+         if(isConv[daughter_index]==1){//store the e+e- indices...
+           convIndices[daughter_index][0] = dd1;
+           convIndices[daughter_index][1] = dd2;
+         }//if this photon converted. 
+       }//close else-if photon has 2 daughters.
+      }//loop over 2 decay photons (iPhoton)
+      
+      if(binp && bacc){// 2 Photons hit the EMCAL! 
+
+       h1_Pi0TruthPtEmcal    ->Fill(mcP->Pt());
+       h2_Pi0TruthPhiEtaEmcal->Fill(mcP->Phi(),mcP->Eta());            
+       
+       if(isPrimary==1){
+         h1_PriPi0TruthPtEmcal    ->Fill(mcP->Pt());
+         h2_PriPi0TruthPhiEtaEmcal->Fill(mcP->Phi(),mcP->Eta());
+       }
+       
+       Int_t PhotonClusterMatch[2][3]  = { {0,-1,-1},
+                                           {0,-1,-1} };
+       Int_t PhotonElectronMatch[2][6] = { {0,-1,-1,-1,-1,-1},
+                                           {0,-1,-1,-1,-1,-1} };
+       
+       for(int iCluster=0; iCluster<nclusters; iCluster++) {       
+         
+         AliESDCaloCluster* esdCluster=NULL;
+         AliAODCaloCluster* aodCluster=NULL;
+         if (fEsdEv)       esdCluster = fEsdEv->GetCaloCluster(iCluster); // pointer to EMCal cluster
+         else if (fAodEv)  aodCluster = fAodEv->GetCaloCluster(iCluster); // pointer to EMCal cluster
+         
+         Double_t clustMC_phi, clustMC_eta;      
+         if(fEsdEv){       
+           if(esdCluster->IsEMCAL()){          
+
+             if(!isGoodEsdCluster(esdCluster))
+               continue;
+             
+             Float_t pos[3] = {0,0,0};
+             esdCluster->GetPosition(pos);
+             TVector3 vpos(pos);
+             h1_Phi->Fill(vpos.Phi());
+             clustMC_phi = vpos.Phi();
+             clustMC_eta = vpos.Eta();
+             
+             Double_t dR = TMath::Sqrt((eta_d[daughter_index]-clustMC_eta)*(eta_d[daughter_index]-clustMC_eta) + 
+                                       (phi_d[daughter_index]-clustMC_phi)*(phi_d[daughter_index]-clustMC_phi));
+             h1_dR_RealMC->Fill(dR);
+             //matches_pion_photon = 0;
+             //if(dR<=0.04) matches_pion_photon = 1;
+             
+             TArrayI *TruthLabelsA = esdCluster->GetLabelsArray();
+             if(TruthLabelsA){
+               for(int itl=0; itl<TruthLabelsA->GetSize(); itl++){
+                 
+                 for(int iPhoton=0; iPhoton<2; iPhoton++){
+                   if(TruthLabelsA->At(itl)==DecayPhotonLabel[iPhoton]){
+                     PhotonClusterMatch[iPhoton][0] = 1;
+                     PhotonClusterMatch[iPhoton][1] = DecayPhotonLabel[iPhoton];
+                     PhotonClusterMatch[iPhoton][2] = iCluster;
+                   }
+                 }//loop over truth labels.
+                 
+                 AliMCParticle *elecCandidate = (AliMCParticle*)(mcEvent->GetTrack(TruthLabelsA->At(itl)));
+                 if(TMath::Abs(elecCandidate->PdgCode())==11){//if we have an electron...
+                   Int_t elecMother_index = elecCandidate->GetMother();
+                   if(elecMother_index>1 && elecMother_index<nTracksMC){
+                     AliMCParticle *elecMother   = (AliMCParticle*)(mcEvent->GetTrack(elecMother_index));
+                     if( TMath::Abs(elecMother->PdgCode())==22 ){//if the e's mother is a photon...
+                       Int_t elecGrandMother_index = elecMother->GetMother();
+                       if(elecGrandMother_index==iTrack){//if the e's gMother is THE pi0 in question...
+                         AliMCParticle *elecGrandMother = (AliMCParticle*)(mcEvent->GetTrack(elecGrandMother_index));
+                         if( TMath::Abs(elecGrandMother->PdgCode())!=111 ) cout << "|| This can't happen!!  A pion is a pion is a pion is a pion... ||" << endl;
+                         
+                         for(int iPhoton=0; iPhoton<2; iPhoton++){
+                           //if(convIndices[iPhoton][0]==elecMother_index){
+                           if(convIndices[iPhoton][0]==TruthLabelsA->At(itl) || convIndices[iPhoton][1]==TruthLabelsA->At(itl)){
+                             if(PhotonElectronMatch[iPhoton][1] == DecayPhotonLabel[iPhoton]) PhotonElectronMatch[iPhoton][0] = 2;
+                             else                                                             PhotonElectronMatch[iPhoton][0] = 1;
+                             PhotonElectronMatch[iPhoton][1] = DecayPhotonLabel[iPhoton];
+                             if(PhotonElectronMatch[iPhoton][2]==-1) PhotonElectronMatch[iPhoton][2] = iCluster;//first cluster
+                             else                                    PhotonElectronMatch[iPhoton][3] = iCluster;//second cluster
+                             if(PhotonElectronMatch[iPhoton][2]==-1) PhotonElectronMatch[iPhoton][4] = elecCandidate->PdgCode();
+                             else                                    PhotonElectronMatch[iPhoton][5] = elecCandidate->PdgCode();
+                           }                       
+                         }//loop over both decay photons
+                         
+                       }//if it's THE pi0.
+                     }//if we have a photon.    
+                   }//if we have an electron.
+                 }//if the candidate has a real mother.
+                 
+               }//itl (TruthLabel loop)
+             }//if(TruthLabelsA exists)
+           }//if(isEMCal)
+         }//if(esdEv)
+       }//loop over clusters. 
+
+       
+       for(int iPhoton=0; iPhoton<2; iPhoton++){
+         AliMCParticle *truthP = (AliMCParticle*)(mcEvent->GetTrack(DecayPhotonLabel[iPhoton]));
+         if(!truthP)
+           continue;
+         if(PhotonClusterMatch[iPhoton][0]==1){
+           AliESDCaloCluster *esdCluster = fEsdEv->GetCaloCluster(PhotonClusterMatch[iPhoton][2]);
+           recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+           h3_gE_RecTruth->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 1);
+           if(esdCluster->GetNCells()>=2)
+             h3_gE_RecTruth_ncellscut->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 1);
+         }
+         else if(PhotonElectronMatch[iPhoton][0]==2 && PhotonElectronMatch[iPhoton][2] == PhotonElectronMatch[iPhoton][3]){//merged conv photon
+           AliESDCaloCluster *esdCluster = fEsdEv->GetCaloCluster(PhotonElectronMatch[iPhoton][2]);
+           recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+           h3_gE_RecTruth->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 2);
+           if(esdCluster->GetNCells()>=2)
+             h3_gE_RecTruth_ncellscut->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 2);
+         }
+         else if(PhotonElectronMatch[iPhoton][0]==2){//non-merged conv photon (but both hit emcal)
+           AliESDCaloCluster *esdCluster = fEsdEv->GetCaloCluster(PhotonElectronMatch[iPhoton][2]);
+           recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+           h3_gE_RecTruth->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 4);
+           if(esdCluster->GetNCells()>=2)
+             h3_gE_RecTruth_ncellscut->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 4);
+                              esdCluster = fEsdEv->GetCaloCluster(PhotonElectronMatch[iPhoton][3]);
+           recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+           h3_gE_RecTruth->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 4);
+           if(esdCluster->GetNCells()>=2)
+             h3_gE_RecTruth_ncellscut->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 4);
+         }
+         else if(PhotonElectronMatch[iPhoton][0]==1){//non-merged conv photon (one missed emcal)
+           AliESDCaloCluster *esdCluster = fEsdEv->GetCaloCluster(PhotonElectronMatch[iPhoton][2]);
+           recalScale = PrivateEnergyRecal(esdCluster->E(), fRecalibrator);
+           h3_gE_RecTruth->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 3);
+           if(esdCluster->GetNCells()>=2)
+             h3_gE_RecTruth_ncellscut->Fill(recalScale*esdCluster->E(), truthP->E()/(recalScale*esdCluster->E()), 3);
+         }
+       }//loop over decay photons (iPhoton).     
+       
+      }// 2 Photons pointed at the EMCAL!       
+    }//for(nTracksMC) ie. Truth Pion loop. 
+    
+  }//if(isMC)
+  
+  //######################### ~~~~~~~~~~~~ ##################################
+  //######################### DONE WITH MC ##################################
+  //######################### ~~~~~~~~~~~~ ##################################
+  
+  
+  
+  // NEW HISTO should be filled before this point, as PostData puts the
+  // information for this iteration of the UserExec in the container
+  PostData(1, fOutput);
+  }
+
+//________________________________________________________________________
+void AliAnalysisTaskSDMGammaMC::Terminate(Option_t *) //specify what you want to have done
+{
+  // Called once at the end of the query.
+  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskSDMGammaMC::GetZvtxBin(Double_t vertZ)
+{
+  
+  int izvtx = -1;
+  
+  if     (vertZ<-35)
+    izvtx=0;
+  else if(vertZ<-30)
+    izvtx=1;
+  else if(vertZ<-25)
+    izvtx=2;
+  else if(vertZ<-20)
+    izvtx=3;
+  else if(vertZ<-15)
+    izvtx=4;
+  else if(vertZ<-10)
+    izvtx=5;
+  else if(vertZ< -5)
+    izvtx=6;
+  else if(vertZ<  0)
+    izvtx=7;
+  else if(vertZ<  5)
+    izvtx=8;
+  else if(vertZ< 10)
+    izvtx=9;
+  else if(vertZ< 15)
+    izvtx=10;
+  else if(vertZ< 20)
+    izvtx=11;
+  else if(vertZ< 25)
+    izvtx=12;
+  else if(vertZ< 30)
+    izvtx=13;
+  else if(vertZ< 35)
+    izvtx=14;
+  else
+    izvtx=15;
+  
+  return izvtx;  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskSDMGammaMC::GetMultBin(Int_t mult){
+
+  int imult = -1;
+  
+  if     (mult<2)
+    imult=0;
+  else if(mult<25)
+    imult=mult-2;
+  else
+    imult=24;
+  
+  return imult;  
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskSDMGammaMC::isGoodEsdCluster(AliESDCaloCluster* esdclust){
+
+  int pass = 1;
+  int nMinCells  = 1;
+  double MinE    = 0.4;
+  //double MinErat = 0;
+  //double MinEcc  = 0;
+  
+  if (!esdclust)
+    pass = 0;    
+  if (!esdclust->IsEMCAL()) 
+    pass = 0;//removes ~70% of clusters.
+  if (esdclust->E()<MinE)
+    pass = 0;//does nothing
+  if (esdclust->GetNCells()<nMinCells)
+    pass = 0;//does nothing
+  //if (GetMaxCellEnergy(esdclust)/esdclust->E()<MinErat)
+  //pass = 0;
+  //if (esdclust->Chi2()<MinEcc) // eccentricity cut
+  //pass = 0;//this is always -1.
+    
+  /*
+  //This cuts out more than just 1 cell clusters
+  //and drains the statistics badly.  
+  //haven't figured out what it does yet. 
+  if(esdclust->GetM20()<0.02)
+  pass = 0;
+  */
+  //if(esdclust->GetM02()<0.1)
+  //  pass = 0;
+  //if(esdclust->GetM02()>0.5)
+  //  pass = 0;
+  //if(esdclust->GetNCells()<2)
+  //  pass = 0;    
+
+  Float_t pos[3] = {0,0,0};
+  esdclust->GetPosition(pos);
+  TVector3 clusterPosition(pos);
+  if(clusterPosition.Eta()<fEtamin || clusterPosition.Eta()>fEtamax || 
+     clusterPosition.Phi()<fPhimin || clusterPosition.Phi()>fPhimax  )
+    pass = 0;
+  clusterPosition.Delete();
+
+  //doing this by hand now... 
+  //if(!esdclust->GetNTracksMatched()==0)
+  //pass = 0;
+  
+  return pass;
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskSDMGammaMC::isGoodAodCluster(AliAODCaloCluster* aodclust){
+
+  int pass = 1;
+  int nMinCells  = 1;
+  double MinE    = 0.4;
+  //double MinErat = 0;
+  //double MinEcc  = 0;
+  
+  if (!aodclust)
+    pass = 0;    
+  if (!aodclust->IsEMCAL()) 
+    pass = 0;//removes ~70% of clusters.
+  if (aodclust->E()<MinE)
+    pass = 0;//does nothing
+  if (aodclust->GetNCells()<nMinCells)
+    pass = 0;//does nothing
+  //if (GetMaxCellEnergy(aodclust)/aodclust->E()<MinErat)
+  //pass = 0;
+  //if (aodclust->Chi2()<MinEcc) // eccentricity cut
+  //pass = 0;//this is always -1.
+    
+  /*
+  //This cuts out more than just 1 cell clusters
+  //and drains the statistics badly.  
+  //haven't figured out what it does yet. 
+  if(aodclust->GetM20()<0.02)
+  pass = 0;
+  if(aodclust->GetM02()<0.02)
+  pass = 0;
+  */
+  //if(aodclust->GetM02()<0.1)
+  //  pass = 0;
+  //if(aodclust->GetM02()>0.5)
+  //  pass = 0;
+  //if(aodclust->GetNCells()<2)
+  //  pass = 0;    
+
+  Float_t pos[3] = {0,0,0};
+  aodclust->GetPosition(pos);
+  TVector3 clusterPosition(pos);
+  if(clusterPosition.Eta()<fEtamin || clusterPosition.Eta()>fEtamax || 
+     clusterPosition.Phi()<fPhimin || clusterPosition.Phi()>fPhimax  )
+    pass = 0;
+  clusterPosition.Delete();
+
+  //if(!aodclust->GetNTracksMatched()==0)
+  //pass = 0;
+  
+  return pass;
+}
+//________________________________________________________________________
+Double_t AliAnalysisTaskSDMGammaMC::getDeltaPhi(TLorentzVector p1, TLorentzVector p2){
+
+  double dphi = p1.Phi() - p2.Phi();
+
+  if(dphi<0.5*TMath::Pi())  
+    dphi = dphi + 2.0*TMath::Pi();
+
+  if(dphi>1.5*TMath::Pi())  
+    dphi = dphi - 2.0*TMath::Pi();
+
+  return dphi;
+}
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskSDMGammaMC::getDeltaEta(TLorentzVector p1, TLorentzVector p2){
+
+  double deta = p1.PseudoRapidity() - p2.PseudoRapidity();
+
+  return deta;
+}
+
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskSDMGammaMC::PrivateEnergyRecal(Double_t energy, Int_t iCalib){
+  
+  double recalibfactor = 0.0;
+  
+  if(iCalib==0){// no recalibration! 
+    recalibfactor = 1.0;
+  }
+  else if(iCalib==1){// just a scale factor: 
+    recalibfactor = 0.984;
+  }
+  else if(iCalib==2){// Symmetric Decay Fit - corrects data to uncorrected MC. 
+    Double_t p[3] = {0.96968, -2.68720, -0.831607};
+    recalibfactor = p[0] + exp(p[1] + p[2]*energy*2.0);
+  }
+  else if(iCalib==3){// Jason's fit to the LHC12f1a MC single photons - 04 Aug 2013 (call it kPi0MCv4??)
+    Double_t p[7] = {1.00000e+00, 3.04925e-02, 4.69043e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.00046e+00};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==4){// Jason's fit to the test beam data - 04 Aug 2013(call it kBTCv3??)
+    Double_t p[7] = {9.78672e-01, 2.39745e-01, 6.41199e-01, 9.13538e-02, 1.46058e+02, 1.99469e+01, 9.72716e-01};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==5){// Based on kSDM/kTBCv3 (call it kPi0MCv4??)
+    Double_t p[10] = {9.78672e-01, 2.39745e-01, 6.41199e-01, 9.13538e-02, 1.46058e+02, 1.99469e+01, 9.72716e-01, 0.96968, -2.68720, -0.831607};
+    recalibfactor = ( (p[6]/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5]))))) ) / ( p[7] + exp(p[8] + p[9]*energy/2.0) );
+  }
+  else if(iCalib==6){// kBeamTestCorrectedv2 - in AliROOT! 
+    Double_t p[7] = {9.83504e-01, 2.10106e-01, 8.97274e-01, 8.29064e-02, 1.52299e+02, 3.15028e+01, 0.968};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==7){// kPi0MCv3 - in AliROOT! 
+    Double_t p[7] = {9.81039e-01, 1.13508e-01, 1.00173e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.0};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==8){// Jason's fit to the noNL MC/data- based on kSDM and kPi0MCv5 - 28 Oct 2013 (call it... ??)
+    Double_t p[10] = {1.0, 6.64778e-02, 1.57000e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.01286, 0.964, -3.132, -0.435};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5]))))) * (p[7] + exp(p[8]+p[9]*energy*2.0));
+  }
+  else if(iCalib==9){// Jason's fit to the LHC12f1a/b MC single photons (above 400MeV), including conversions - 28 Oct 2013 (call it kPi0MCv5??)
+    Double_t p[7] = {1.0, 6.64778e-02, 1.57000e+00, 9.67998e-02, 2.19381e+02, 6.31604e+01, 1.01286};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==10){// Jason played with test beam data
+    Double_t p[7] = {1.0, 0.237767, 0.651203, 0.183741, 155.427, 17.0335, 0.987054};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  else if(iCalib==11){// Jason played with test beam MC
+    Double_t p[7] = {1.0, 0.0797873, 1.68322, 0.0806098, 244.586, 116.938, 1.00437};
+    recalibfactor = ((p[6])/(p[0]*(1./(1.+p[1]*exp(-energy/p[2]))*1./(1.+p[3]*exp((energy-p[4])/p[5])))));
+  }
+  
+  return recalibfactor;
+}
+
diff --git a/PWGGA/EMCALTasks/AliAnalysisTaskSDMGammaMC.h b/PWGGA/EMCALTasks/AliAnalysisTaskSDMGammaMC.h
new file mode 100644 (file)
index 0000000..68ffc30
--- /dev/null
@@ -0,0 +1,115 @@
+#ifndef ALIANALYSISTASKSDMGAMMAMC_H
+#define ALIANALYSISTASKSDMGAMMAMC_H
+
+class TF1;
+class TH1F;
+class TH2F;
+class TH3F;
+class TH1D;
+class TH2D;
+class TH3D;
+class TNtuple;
+class TList;
+class AliESDEvent;
+class AliAODEvent;
+class AliESDtrackCuts;
+class AliESDCaloCluster;
+class AliAODCaloCluster;
+class AliMCEvent;
+class AliMCParticle;
+class AliEMCALGeometry;
+
+#ifndef ALIANALYSISTASKSE_H
+#include "AliAnalysisTaskSE.h"
+#endif
+
+class AliAnalysisTaskSDMGammaMC : public AliAnalysisTaskSE {
+ public:
+  AliAnalysisTaskSDMGammaMC();
+  AliAnalysisTaskSDMGammaMC(const char *name);
+  virtual ~AliAnalysisTaskSDMGammaMC();
+    
+  virtual void     UserCreateOutputObjects();
+  virtual void     UserExec(Option_t *option);
+  virtual void     Terminate(Option_t *);
+    
+  void         SetMcMode(Bool_t b) { fMcMode = b; }
+  void         SetRecalScheme(Int_t kRecalibrator) { fRecalibrator = kRecalibrator; }
+  void         SetFidPhiMinMax(Double_t kPhimin, Double_t kPhimax){ fPhimin = kPhimin; fPhimax = kPhimax; }
+  void         SetFidEtaMinMax(Double_t kEtamin, Double_t kEtamax){ fEtamin = kEtamin; fEtamax = kEtamax; }
+  
+ private:
+  static const int zvtx_bins = 16;
+  static const int mult_bins = 25;
+  static const unsigned int poolDepth = 25;
+  
+  Int_t GetMultBin(Int_t mult);
+  Int_t GetZvtxBin(Double_t vertZ);
+  Int_t isGoodEsdCluster(AliESDCaloCluster* esdclust);
+  Int_t isGoodAodCluster(AliAODCaloCluster* aodclust);
+  Double_t getDeltaPhi(TLorentzVector p1, TLorentzVector p2);
+  Double_t getDeltaEta(TLorentzVector p1, TLorentzVector p2);
+  Double_t PrivateEnergyRecal(Double_t energy, Int_t iCalib);
+
+  TList           *fOutput;        //! Output list
+  Bool_t           fMcMode;                 // monte carlo mode
+  Int_t            fRecalibrator;           // custom recalibrator? 
+  Double_t         fPhimin;           // Cuts. 
+  Double_t         fPhimax;           // Cuts. 
+  Double_t         fEtamin;           // Cuts. 
+  Double_t         fEtamax;           // Cuts. 
+  AliESDtrackCuts *fTrackCuts;     // Track cuts
+  AliESDEvent     *fEsdEv;                  //!pointer to input esd event
+  AliAODEvent     *fAodEv;                  //!pointer to input aod event
+  TH1F            *h1_nClusters;  //!  # of clusters/evt
+  TH1F            *h1_zvtx;  //!  # of clusters/evt
+  TH1F            *h1_trigger;  //!  # of clusters/evt
+  TH1F            *h1_E;        //!  energy spectrum
+  TH1F            *h1_Phi;        //!  Pt spectrum
+
+  TH2F            *h2_PiMotherID; //! first bin is primaries, second is non-primaries
+  TH2F            *h2_GaMotherID; //! first bin is primaries, second is non-primaries
+  TH3F            *h3_gE_RecTruth; //! E_in/E_rec vs E_rec (for 4 categories)
+  TH3F            *h3_gE_RecTruth_ncellscut; //! E_in/E_rec vs E_rec (for 4 categories)
+  
+  TH1F            *h1_Pi0TruthPt;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PriPi0TruthPt;        //!  Pt spectrum from MC! 
+  TH1F            *h1_Pi0TruthPtEmcal;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PriPi0TruthPtEmcal;        //!  Pt spectrum from MC! 
+
+  TH2F            *h2_Pi0TruthPhiEta;    //!  etaphi spectrum from MC! 
+  TH2F            *h2_PriPi0TruthPhiEta;    //!  etaphi spectrum from MC! 
+  TH2F            *h2_Pi0TruthPhiEtaEmcal;    //!  etaphi spectrum from MC! 
+  TH2F            *h2_PriPi0TruthPhiEtaEmcal;    //!  etaphi spectrum from MC! 
+
+  TH1F            *h1_TruthPhotonsEmcal;        //!  Pt spectrum from MC! 
+  TH2F            *h2_TruthPhotonsPhiEta;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhotonsEmcal;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhotonsNCellsCut;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhotonsTrackMatchCut;        //!  Pt spectrum from MC! 
+  TH1F            *h1_PhotonsAllCut;        //!  Pt spectrum from MC! 
+  TH2F            *h2_PhotonsPhiEtaIsEmcal;        //!  Pt spectrum from MC! 
+
+  TH1F            *h1_dR_RealMC;        //!  Pt spectrum from MC! 
+
+  TH1F            *h1_Eta;       //!  pseudorapidity spectrum
+  TH1F            *h1_Chi2;       //!  pseudorapidity spectrum
+  TH1F            *h1_nTrkMatch;       //!  pseudorapidity spectrum
+  TH1F            *h1_nCells;       //!  pseudorapidity spectrum
+  TH1F            *h1_ClusterDisp;       //!  cluster dispersion
+  TH2F            *h2_Ellipse;       //!  ellipse axis?
+  TH2F            *h2_EtaPt;       //!  2d histogram Y - pseudorap spectrum
+  TH2F            *h2_dphi_deta;       //!  2dimensional E vs mom
+  TH2F            *h2_dphi_deta_mix;       //!  2dimensional E vs mom
+  TH2F            *h2_DispRes;       //!  2dimensional E vs mom
+  TH2F            *h2_cells_M02;       //!  
+
+  std::vector<TLorentzVector> Photons[poolDepth][zvtx_bins][mult_bins];
+  std::vector<Int_t> TriggerList;
+  
+  AliAnalysisTaskSDMGammaMC(const AliAnalysisTaskSDMGammaMC&); // not implemented
+  AliAnalysisTaskSDMGammaMC& operator=(const AliAnalysisTaskSDMGammaMC&); // not implemented
+    
+  ClassDef(AliAnalysisTaskSDMGammaMC, 1); // example of analysis
+};
+#endif
diff --git a/PWGGA/EMCALTasks/macros/AddTaskEMCALMesonGGSDM.C b/PWGGA/EMCALTasks/macros/AddTaskEMCALMesonGGSDM.C
new file mode 100644 (file)
index 0000000..b6ac68a
--- /dev/null
@@ -0,0 +1,101 @@
+void AddTaskEMCALMesonGGSDM() 
+{
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (!mgr) {
+    ::Error("AddTaskAliEMCALMesonGGSDM", "No analysis manager to connect to.");
+    return NULL;
+  }  
+
+  //#####################################################
+  // Private Recalibrator:
+     Int_t GoodTasks  [4] = {1, 0,0,0};
+     Int_t RecalScheme[4] = {9, 3,5,7};
+  //
+  // 0:  no recalibration! 
+  // 1:  constant scale factor.
+  // 2:  Symmetric Decay Method
+  // 3:  J's fit to LHC12f1a MC single photons, 4 Aug 2013
+  // 4:  J's fit to the test beam data, 4 Aug 2013
+  // 5:  Based on kSDM/kTBCv3 (for MC)
+  // 6:  kBeamTestCorrectedv2 - in AliROOT! 
+  // 7:  kPi0MCv3 - in AliROOT! 
+  // 8:  kSDMv5 - based on J's fit to the noNL MC/data and kPi0MCv5 - 28 Oct 2013 (call it kSDMv5)
+  // 9:  kPi0MCv5 - J's fit to LHC12f1a/b MC single photons, 28 Oct 2013 (call it kPi0MCv5)
+  // 10: kBTCv6 - J played with test beam data - 19 Nov 2013
+  // 11: kPi0MCv6 - J played with test beam mc - 19 Nov 2013
+  //
+  //#####################################################  
+
+  //#####################################################  
+  // MC Generator Types: 
+  //
+     char MyMCType[50] = "";
+  // doesn't work yet... set below!!!!!! 
+  //
+  // for all Primary particles, assign "ANY"
+  // 
+  // lhc13e7: 
+  //         hijing_0
+  //         pi0_1    - flat pT, number varies with centrality
+  //         eta_2    - flat pT, number varies with centrality
+  //         pi0EMC_3 - flat pT, 1 pi0 into EMCal
+  //         pi0PHS_4 - flat pT, 1 pi0 into PHOS
+  //         etaEMC_5 - flat pT, 1 eta into EMCal
+  //         etaPHS_6 - flat pT, 1 eta into PHOS 
+  //
+  // lhc12i3: 
+  //         Pythia
+  //         BOX      - flat pT, 10 pi0 into 2pi
+  //         BOX      - flat pT, 10 eta into 2pi
+  //         PARAM    - flat pT, 1 pi0 into EMCal
+  //         PARAM    - flat pT, 1 pi0 into PHOS 
+  //         PARAM    - flat pT, 1 eta into EMCal
+  //         PARAM    - flat pT, 1 eta into PHOS 
+  //
+  // dangerous... right now, it will only take the first BOX that it finds. 
+  //
+  //#####################################################  
+
+  AliAnalysisTaskEMCALMesonGGSDM* task[4];
+  AliAnalysisDataContainer*  coutput[4];  
+  char saythis[500];
+
+  for(int i=0; i<4; i++){
+    if(GoodTasks[i]==0)
+      continue;
+    
+    sprintf(saythis,"EMCALMesonGGSDM_%d",i);
+    task[i] = new AliAnalysisTaskEMCALMesonGGSDM(saythis);
+    task[i]->SelectCollisionCandidates(AliVEvent::kMB);//LHC11a
+    //task[i]->SelectCollisionCandidates(AliVEvent::kINT7);//LHC13b/c, LHC11c?
+    //task[i]->SelectCollisionCandidates(AliVEvent::kAnyINT);
+    task[i]->SetRecalScheme(RecalScheme[i]);
+
+    task[i]->SetdRmin_ClustTrack(0.025);//not used at the moment! (Gustavo uses 0.04)
+    task[i]->SetFidPhiMinMax(1.39626, 3.15);// from: emc->GetArm1PhiMin()*TMath::DegToRad()=1.39626
+    //task[i]->SetFidPhiMinMax(1.39626, 2.10); //pPb no TRD
+    //task[i]->SetFidPhiMinMax(2.10, 3.15); //pPb with TRD
+    task[i]->SetFidEtaMinMax(-0.65, 0.65);
+
+    //task[i]->SetMyMCType(**MyMCType);
+    //task[i]->SetMyMCType("hijing_0");
+    task[i]->SetMyMCType("Pythia");
+    
+    mgr->AddTask(task[i]);
+    sprintf(saythis,"cont_AliAnalysisTaskEMCALMesonGGSDM_%d",RecalScheme[i]);
+    coutput[i] = 
+      mgr->CreateContainer(saythis,
+                          TList::Class(),
+                          AliAnalysisManager::kOutputContainer,
+                          "EMCALMesonGGSDM.root");
+    mgr->ConnectInput (task[i],0,mgr->GetCommonInputContainer());
+    mgr->ConnectOutput(task[i],1,coutput[i]);
+        
+    RequestMemory(task[i],2000*1024); // request 1.0GB memory for task
+    
+    //AliMCEventHandler* handler = new AliMCEventHandler;
+    //handler->SetReadTR(kFALSE);
+    //mgr->SetMCtruthEventHandler(handler);
+  }
+  
+}
diff --git a/PWGGA/EMCALTasks/macros/AddTaskEMCALMesonGGSDMpPb.C b/PWGGA/EMCALTasks/macros/AddTaskEMCALMesonGGSDMpPb.C
new file mode 100644 (file)
index 0000000..a5dcec0
--- /dev/null
@@ -0,0 +1,67 @@
+void AddTaskEMCALMesonGGSDMpPb() 
+{
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (!mgr) {
+    ::Error("AddTaskAliEMCALMesonGGSDMpPb", "No analysis manager to connect to.");
+    return NULL;
+  }  
+
+  //#####################################################
+  // Private Recalibrator:
+     Int_t GoodTasks  [4] = {1, 0,0,0};
+     Int_t RecalScheme[4] = {8, 3,5,7};
+  //
+  // 0:  no recalibration! 
+  // 1:  constant scale factor.
+  // 2:  Symmetric Decay Method
+  // 3:  J's fit to LHC12f1a MC single photons, 4 Aug 2013
+  // 4:  J's fit to the test beam data, 4 Aug 2013
+  // 5:  Based on kSDM/kTBCv3 (for MC)
+  // 6:  kBeamTestCorrectedv2 - in AliROOT! 
+  // 7:  kPi0MCv3 - in AliROOT! 
+  // 8:  kSDMv5 - based on J's fit to the noNL MC/data and kPi0MCv5 - 28 Oct 2013 (call it kSDMv5)
+  // 9:  kPi0MCv5 - J's fit to LHC12f1a/b MC single photons, 28 Oct 2013 (call it kPi0MCv5)
+  // 10: kBTCv6 - J played with test beam data - 19 Nov 2013
+  // 11: kPi0MCv6 - J played with test beam mc - 19 Nov 2013
+  //
+  //#####################################################  
+
+  AliAnalysisTaskEMCALMesonGGSDMpPb* task[4];
+  AliAnalysisDataContainer*  coutput[4];  
+  char saythis[500];
+
+  for(int i=0; i<4; i++){
+    if(GoodTasks[i]==0)
+      continue;
+    
+    sprintf(saythis,"EMCALMesonGGSDMpPbTask_%d",i);
+    task[i] = new AliAnalysisTaskEMCALMesonGGSDMpPb(saythis);
+    //task[i]->SelectCollisionCandidates(AliVEvent::kAny);
+    //task[i]->SelectCollisionCandidates(AliVEvent::kMB);//LHC11a
+    task[i]->SelectCollisionCandidates(AliVEvent::kINT7);//LHC13b/c
+    task[i]->SetRecalScheme(RecalScheme[i]);
+
+    task[i]->SetdRmin_ClustTrack(0.025);//not used at the moment! (Gustavo uses 0.04)
+    task[i]->SetFidPhiMinMax(1.39626, 3.15); // full emcal. 
+    //task[i]->SetFidPhiMinMax(1.39626, 2.10); //pPb no TRD
+    //task[i]->SetFidPhiMinMax(2.10, 3.15); //pPb with TRD
+    task[i]->SetFidEtaMinMax(-0.65, 0.65);
+    
+    mgr->AddTask(task[i]);
+    sprintf(saythis,"cont_AliAnalysisTaskEMCALMesonGGSDMpPb_%d",RecalScheme[i]);
+    coutput[i] = 
+      mgr->CreateContainer(saythis,
+                          TList::Class(),
+                          AliAnalysisManager::kOutputContainer,
+                          "EMCALMesonGGSDMpPbTask.root");
+    mgr->ConnectInput (task[i],0,mgr->GetCommonInputContainer());
+    mgr->ConnectOutput(task[i],1,coutput[i]);
+        
+    RequestMemory(task[i],2000*1024); // request 2.0GB memory for task
+    
+    //AliMCEventHandler* handler = new AliMCEventHandler;
+    //handler->SetReadTR(kFALSE);
+    //mgr->SetMCtruthEventHandler(handler);
+  }
+
+}
diff --git a/PWGGA/EMCALTasks/macros/AddTaskSDMGammaMC.C b/PWGGA/EMCALTasks/macros/AddTaskSDMGammaMC.C
new file mode 100644 (file)
index 0000000..64cfe88
--- /dev/null
@@ -0,0 +1,62 @@
+void AddTaskAliAnalysisTaskGammaMC() 
+{
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (!mgr) {
+    ::Error("AddTaskAliGammaMC", "No analysis manager to connect to.");
+    return NULL;
+  }  
+
+  //#####################################################
+  // Private Recalibrator:
+     Int_t GoodTasks  [4] = {1,0,0,0};
+     Int_t RecalScheme[4] = {0,3,5,7};
+  //
+  // 0: no recalibration! 
+  // 1: constant scale factor.
+  // 2: Symmetric Decay Method
+  // 3: J's fit to LHC12f1a MC single photons, 4 Aug 2013
+  // 4: J's fit to the test beam data, 4 Aug 2013
+  // 5: Based on kSDM/kTBCv3 (for MC)
+  // 6: kBeamTestCorrectedv2 - in AliROOT! 
+  // 7: kPi0MCv3 - in AliROOT! 
+  //
+  //#####################################################  
+
+  AliAnalysisTaskGammaMC* task[4];
+  AliAnalysisDataContainer*  coutput[4];  
+  char saythis[500];
+
+  for(int i=0; i<4; i++){
+    if(GoodTasks[i]==0)
+      continue;
+    
+    sprintf(saythis,"GammaMCTask_%d",i);
+    task[i] = new AliAnalysisTaskGammaMC(saythis);
+    task[i]->SelectCollisionCandidates(AliVEvent::kINT7);//LHC13b/c
+    //task[i]->SelectCollisionCandidates(AliVEvent::kMB);
+    task[i]->SetRecalScheme(RecalScheme[i]);
+    
+    task[i]->SetFidPhiMinMax(1.39626, 3.15);// my defaults: 1.39626, 3.15
+    //task[i]->SetFidPhiMinMax(1.39626, 2.10); //pPb no TRD
+    //task[i]->SetFidPhiMinMax(2.10, 3.15); //pPb with TRD    
+    task[i]->SetFidEtaMinMax(-0.65, 0.65);
+
+    mgr->AddTask(task[i]);
+    sprintf(saythis,"cont_AliAnalysisTaskGammaMC_%d",RecalScheme[i]);
+    coutput[i] = 
+      mgr->CreateContainer(saythis,
+                          TList::Class(),
+                          AliAnalysisManager::kOutputContainer,
+                          "GammaMCTask.root");
+    mgr->ConnectInput (task[i],0,mgr->GetCommonInputContainer());
+    mgr->ConnectOutput(task[i],1,coutput[i]);
+        
+    RequestMemory(task[i],1000*1024); // request 1.0GB memory for task
+    
+    //AliMCEventHandler* handler = new AliMCEventHandler;
+    //handler->SetReadTR(kFALSE);
+    //mgr->SetMCtruthEventHandler(handler);
+  }
+  
+
+}
index 82f29e4..5b2a209 100644 (file)
@@ -32,5 +32,7 @@
 #pragma link C++ class AliAnalysisTaskEMCALPi0V2ShSh+;
 #pragma link C++ class AliEMCalpi0ClusterEvaluationTask+;
 #pragma link C++ class AliAnalysisTaskEMCALIsolation+;
-
+#pragma link C++ class AliAnalysisTaskEMCALMesonGGSDM+;
+#pragma link C++ class AliAnalysisTaskEMCALMesonGGSDMpPb+;
+#pragma link C++ class AliAnalysisTaskSDMGammaMC+;
 #endif