]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrDep/AliAnaCalorimeterQA.cxx
c70da9b567716af9ff7b2f33b2cec58e44ef41db
[u/mrichter/AliRoot.git] / PWG4 / PartCorrDep / AliAnaCalorimeterQA.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 /* $Id: $ */
16
17 //_________________________________________________________________________
18 // Class to check results from simulations or reconstructed real data. 
19 // Fill few histograms and do some checking plots
20 //
21 //-- Author: Gustavo Conesa (INFN-LNF)
22 //_________________________________________________________________________
23
24
25 // --- ROOT system ---
26 //#include "Riostream.h"
27 #include "TObjArray.h"
28 #include "TParticle.h"
29 #include "TDatabasePDG.h"
30 #include "TCanvas.h"
31 #include "TPad.h"
32 #include "TROOT.h"
33 #include "TH3F.h"
34 #include "TH2F.h"
35 #include "TLegend.h"
36 #include "TStyle.h"
37 #include <TObjString.h>
38
39 //---- AliRoot system ----
40 #include "AliAnaCalorimeterQA.h"
41 #include "AliCaloTrackReader.h"
42 #include "AliStack.h"
43 #include "AliVCaloCells.h"
44 #include "AliFiducialCut.h"
45 #include "AliVTrack.h"
46 #include "AliVCluster.h"
47 #include "AliVEvent.h"
48 #include "AliVEventHandler.h"
49 #include "AliAnalysisManager.h"
50 #include "AliAODMCParticle.h"
51 #include "AliMCAnalysisUtils.h"
52 #include "AliAODPid.h"
53 #include "AliExternalTrackParam.h"
54
55 ClassImp(AliAnaCalorimeterQA)
56
57 //____________________________________________________________________________
58 AliAnaCalorimeterQA::AliAnaCalorimeterQA() : 
59 AliAnaPartCorrBaseClass(), fCalorimeter(""), fStyleMacro(""), 
60 fMakePlots(kFALSE), fFillAllPosHisto(kFALSE), fFillAllTH12(kFALSE),
61 fCorrelateCalos(kFALSE), fNModules(12), fNRCU(2),
62 fTimeCutMin(-1), fTimeCutMax(9999999),
63 fHistoFinePtBins(1000),    fHistoFinePtMax(5.),        fHistoFinePtMin(0.),
64 fHistoPOverEBins(100),     fHistoPOverEMax(100.),      fHistoPOverEMin(0.),
65 fHistodEdxBins(100),       fHistodEdxMax(100.),        fHistodEdxMin(0.),
66 fHistodRBins(100),         fHistodRMax(100.),          fHistodRMin(0.),
67 fHistoTimeBins(100),       fHistoTimeMax(100.),        fHistoTimeMin(0.),
68 fHistoNBins(100),          fHistoNMax(100),            fHistoNMin(0),
69 fHistoRatioBins(100),      fHistoRatioMax(100.),       fHistoRatioMin(0.),
70 fHistoVertexDistBins(100), fHistoVertexDistMax(100.),  fHistoVertexDistMin(0.),
71 fHistoRBins(100),          fHistoRMax(1000),           fHistoRMin(-1000),
72 fHistoXBins(100),          fHistoXMax(1000),           fHistoXMin(-1000),
73 fHistoYBins(100),          fHistoYMax(1000),           fHistoYMin(-1000),
74 fHistoZBins(100),          fHistoZMax(1000),           fHistoZMin(-1000),
75 fHistoSSBins(25),          fHistoSSMax(5),             fHistoSSMin(0),
76 fhE(0),fhPt(0),fhPhi(0),fhEta(0),   fhEtaPhiE(0),
77 fhECharged(0),fhPtCharged(0),fhPhiCharged(0),fhEtaCharged(0), fhEtaPhiECharged(0), 
78 fhDeltaE(0), fhDeltaPt(0),fhDeltaPhi(0),fhDeltaEta(0), fhRatioE(0), fhRatioPt(0),fhRatioPhi(0),fhRatioEta(0),
79 fh2E(0),fh2Pt(0),fh2Phi(0),fh2Eta(0),
80 fhLambda(0), fhDispersion(0), 
81 fhIM(0), fhIMCellCut(0),fhAsym(0), 
82 fhNCellsPerCluster(0),fhNCellsPerClusterMIP(0), fhNCellsPerClusterMIPCharged(0), fhNClusters(0), 
83 fhClusterTimeEnergy(0),fhCellTimeSpreadRespectToCellMax(0),fhCellIdCellLargeTimeSpread(0),
84 fhRNCells(0),fhXNCells(0),fhYNCells(0),fhZNCells(0),
85 fhRE(0),     fhXE(0),     fhYE(0),     fhZE(0),    fhXYZ(0),
86 fhRCellE(0), fhXCellE(0), fhYCellE(0), fhZCellE(0),fhXYZCell(0),
87 fhDeltaCellClusterRNCells(0),fhDeltaCellClusterXNCells(0),fhDeltaCellClusterYNCells(0),fhDeltaCellClusterZNCells(0),
88 fhDeltaCellClusterRE(0),     fhDeltaCellClusterXE(0),     fhDeltaCellClusterYE(0),     fhDeltaCellClusterZE(0),
89 fhNCells(0), fhAmplitude(0), fhAmpId(0), fhEtaPhiAmp(0), 
90 fhTime(0), fhTimeId(0), fhTimeAmp(0), //fhT0Time(0), fhT0TimeId(0), fhT0TimeAmp(0), 
91 fhCaloCorrNClusters(0), fhCaloCorrEClusters(0), fhCaloCorrNCells(0), fhCaloCorrECells(0),
92 fhEMod(0), fhNClustersMod(0), fhNCellsPerClusterMod(0), fhNCellsMod(0),  
93 fhGridCellsMod(0), fhGridCellsEMod(0), fhGridCellsTimeMod(0), 
94 fhAmplitudeMod(0), fhAmplitudeModFraction(0),fhTimeAmpPerRCU(0), //fhT0TimeAmpPerRCU(0), fhTimeCorrRCU(0),
95 fhIMMod(0),  fhIMCellCutMod(0),
96 fhGenGamPt(0),fhGenGamEta(0),fhGenGamPhi(0),fhGenPi0Pt(0),fhGenPi0Eta(0),fhGenPi0Phi(0),
97 fhGenEtaPt(0),fhGenEtaEta(0),fhGenEtaPhi(0),fhGenOmegaPt(0),fhGenOmegaEta(0),fhGenOmegaPhi(0),
98 fhGenElePt(0),fhGenEleEta(0),fhGenElePhi(0), fhEMVxyz(0),  fhEMR(0), fhHaVxyz(0),  fhHaR(0),
99 fhGamE(0),fhGamPt(0),fhGamPhi(0),fhGamEta(0), 
100 fhGamDeltaE(0), fhGamDeltaPt(0),fhGamDeltaPhi(0),fhGamDeltaEta(0), 
101 fhGamRatioE(0), fhGamRatioPt(0),fhGamRatioPhi(0),fhGamRatioEta(0),
102 fhEleE(0),fhElePt(0),fhElePhi(0),fhEleEta(0),
103 fhPi0E(0),fhPi0Pt(0),fhPi0Phi(0),fhPi0Eta(0), 
104 fhNeHadE(0),fhNeHadPt(0),fhNeHadPhi(0),fhNeHadEta(0), 
105 fhChHadE(0),fhChHadPt(0),fhChHadPhi(0),fhChHadEta(0),
106 fhGamECharged(0),fhGamPtCharged(0),fhGamPhiCharged(0),fhGamEtaCharged(0), 
107 fhEleECharged(0),fhElePtCharged(0),fhElePhiCharged(0),fhEleEtaCharged(0),
108 fhPi0ECharged(0),fhPi0PtCharged(0),fhPi0PhiCharged(0),fhPi0EtaCharged(0), 
109 fhNeHadECharged(0),fhNeHadPtCharged(0),fhNeHadPhiCharged(0),fhNeHadEtaCharged(0), 
110 fhChHadECharged(0),fhChHadPtCharged(0),fhChHadPhiCharged(0),fhChHadEtaCharged(0),
111 fhGenGamAccE(0),fhGenGamAccPt(0),fhGenGamAccEta(0),fhGenGamAccPhi(0),
112 fhGenPi0AccE(0),fhGenPi0AccPt(0),fhGenPi0AccEta(0),fhGenPi0AccPhi(0),
113 fh1pOverE(0),fh1dR(0),fh2EledEdx(0), fh2MatchdEdx(0),fhMCEle1pOverE(0),fhMCEle1dR(0),fhMCEle2MatchdEdx(0),
114 fhMCChHad1pOverE(0),  fhMCChHad1dR(0),  fhMCChHad2MatchdEdx(0),
115 fhMCNeutral1pOverE(0),fhMCNeutral1dR(0),fhMCNeutral2MatchdEdx(0),
116 fh1pOverER02(0), fhMCEle1pOverER02(0), fhMCChHad1pOverER02(0), fhMCNeutral1pOverER02(0)
117 {
118   //Default Ctor
119   
120   //Initialize parameters
121   InitParameters();
122 }
123
124 //________________________________________________________________________
125 TObjString *  AliAnaCalorimeterQA::GetAnalysisCuts()
126 {       
127   //Save parameters used for analysis
128         TString parList ; //this will be list of parameters used for this analysis.
129         char onePar[255] ;
130         
131         sprintf(onePar,"--- AliAnaCalorimeterQA ---\n") ;
132         parList+=onePar ;       
133         sprintf(onePar,"Calorimeter: %s\n",fCalorimeter.Data()) ;
134         parList+=onePar ;
135         sprintf(onePar,"Time Cut : %2.2f < T < %2.2f ns  \n",fTimeCutMin, fTimeCutMax) ;
136         parList+=onePar ;
137   
138   //Get parameters set in base class.
139   //parList += GetBaseParametersList() ;
140         
141   //Get parameters set in FiducialCut class (not available yet)
142   //parlist += GetFidCut()->GetFidCutParametersList() 
143         
144         return new TObjString(parList) ;
145 }
146
147
148 //________________________________________________________________________
149 TList *  AliAnaCalorimeterQA::GetCreateOutputObjects()
150 {  
151   // Create histograms to be saved in output file and 
152   // store them in outputContainer
153   
154         TList * outputContainer = new TList() ; 
155         outputContainer->SetName("QAHistos") ; 
156         
157   //Histograms
158         Int_t nptbins     = GetHistoPtBins();           Float_t ptmax     = GetHistoPtMax();           Float_t ptmin     = GetHistoPtMin();
159   Int_t nfineptbins = GetHistoFinePtBins();         Float_t ptfinemax = GetHistoFinePtMax();       Float_t ptfinemin = GetHistoFinePtMin();
160         Int_t nphibins    = GetHistoPhiBins();              Float_t phimax    = GetHistoPhiMax();          Float_t phimin    = GetHistoPhiMin();
161         Int_t netabins    = GetHistoEtaBins();          Float_t etamax    = GetHistoEtaMax();          Float_t etamin    = GetHistoEtaMin();    
162         Int_t nmassbins   = GetHistoMassBins();         Float_t massmax   = GetHistoMassMax();         Float_t massmin   = GetHistoMassMin();
163         Int_t nasymbins   = GetHistoAsymmetryBins();    Float_t asymmax   = GetHistoAsymmetryMax();    Float_t asymmin   = GetHistoAsymmetryMin();
164         Int_t nPoverEbins = GetHistoPOverEBins();       Float_t pOverEmax = GetHistoPOverEMax();       Float_t pOverEmin = GetHistoPOverEMin();
165         Int_t ndedxbins   = GetHistodEdxBins();         Float_t dedxmax   = GetHistodEdxMax();         Float_t dedxmin   = GetHistodEdxMin();
166         Int_t ndRbins     = GetHistodRBins();           Float_t dRmax     = GetHistodRMax();           Float_t dRmin     = GetHistodRMin();
167         Int_t ntimebins   = GetHistoTimeBins();         Float_t timemax   = GetHistoTimeMax();         Float_t timemin   = GetHistoTimeMin();       
168         Int_t nbins       = GetHistoNClusterCellBins(); Int_t nmax        = GetHistoNClusterCellMax(); Int_t nmin        = GetHistoNClusterCellMin(); 
169         Int_t nratiobins  = GetHistoRatioBins();        Float_t ratiomax  = GetHistoRatioMax();        Float_t ratiomin  = GetHistoRatioMin();
170         Int_t nvdistbins  = GetHistoVertexDistBins();   Float_t vdistmax  = GetHistoVertexDistMax();   Float_t vdistmin  = GetHistoVertexDistMin();
171         Int_t rbins       = GetHistoRBins();            Float_t rmax      = GetHistoRMax();            Float_t rmin      = GetHistoRMin(); 
172         Int_t xbins       = GetHistoXBins();            Float_t xmax      = GetHistoXMax();            Float_t xmin      = GetHistoXMin(); 
173         Int_t ybins       = GetHistoYBins();            Float_t ymax      = GetHistoYMax();            Float_t ymin      = GetHistoYMin(); 
174         Int_t zbins       = GetHistoZBins();            Float_t zmax      = GetHistoZMax();            Float_t zmin      = GetHistoZMin(); 
175         Int_t ssbins      = GetHistoShowerShapeBins();  Float_t ssmax     = GetHistoShowerShapeMax();  Float_t ssmin     = GetHistoShowerShapeMin();
176         
177   //EMCAL
178         Int_t colmax = 48;
179         Int_t rowmax = 24;
180         fNRCU   = 2 ;
181   //PHOS
182         if(fCalorimeter=="PHOS"){
183                 colmax = 56;
184                 rowmax = 64;
185                 fNRCU   = 4 ;
186         }
187         
188         
189         fhE  = new TH1F ("hE","E reconstructed clusters ", nptbins*5,ptmin,ptmax*5); 
190         fhE->SetXTitle("E (GeV)");
191         outputContainer->Add(fhE);
192   
193         if(fFillAllTH12){
194     fhPt  = new TH1F ("hPt","p_{T} reconstructed clusters", nptbins,ptmin,ptmax); 
195     fhPt->SetXTitle("p_{T} (GeV/c)");
196     outputContainer->Add(fhPt);
197     
198     fhPhi  = new TH1F ("hPhi","#phi reconstructed clusters ",nphibins,phimin,phimax); 
199     fhPhi->SetXTitle("#phi (rad)");
200     outputContainer->Add(fhPhi);
201     
202     fhEta  = new TH1F ("hEta","#eta reconstructed clusters ",netabins,etamin,etamax); 
203     fhEta->SetXTitle("#eta ");
204     outputContainer->Add(fhEta);
205         }
206   
207         fhEtaPhiE  = new TH3F ("hEtaPhiE","#eta vs #phi vs energy, reconstructed clusters",
208                          netabins,etamin,etamax,nphibins,phimin,phimax,nptbins,ptmin,ptmax); 
209         fhEtaPhiE->SetXTitle("#eta ");
210         fhEtaPhiE->SetYTitle("#phi (rad)");
211         fhEtaPhiE->SetZTitle("E (GeV) ");
212         outputContainer->Add(fhEtaPhiE);
213         
214         fhClusterTimeEnergy  = new TH2F ("hClusterTimeEnergy","energy vs TOF, reconstructed clusters",
215                                    nptbins,ptmin,ptmax, ntimebins,timemin,timemax); 
216         fhClusterTimeEnergy->SetXTitle("E (GeV) ");
217         fhClusterTimeEnergy->SetYTitle("TOF (ns)");
218         outputContainer->Add(fhClusterTimeEnergy);
219         
220         
221   //Shower shape
222         fhLambda  = new TH3F ("hLambda","#lambda_{0}^{2} vs #lambda_{1}^{2} vs energy, reconstructed clusters",
223                         ssbins,ssmin,ssmax,ssbins,ssmin,ssmax,nptbins,ptmin,ptmax); 
224         fhLambda->SetXTitle("#lambda_{0}^{2}  ");
225         fhLambda->SetYTitle("#lambda_{1}^{2}  ");
226         fhLambda->SetZTitle("E (GeV) ");
227         outputContainer->Add(fhLambda);
228         
229         fhDispersion  = new TH2F ("hDispersion"," dispersion vs energy, reconstructed clusters",
230                             ssbins,ssmin,ssmax,nptbins,ptmin,ptmax); 
231         fhDispersion->SetXTitle("Dispersion  ");
232         fhDispersion->SetYTitle("E (GeV) ");
233         outputContainer->Add(fhDispersion);
234         
235   //Track Matching
236   if(fFillAllTH12){
237     fhECharged  = new TH1F ("hECharged","E reconstructed clusters, matched with track", nptbins,ptmin,ptmax); 
238     fhECharged->SetXTitle("E (GeV)");
239     outputContainer->Add(fhECharged);
240     
241     fhPtCharged  = new TH1F ("hPtCharged","p_{T} reconstructed clusters, matched with track", nptbins,ptmin,ptmax); 
242     fhPtCharged->SetXTitle("p_{T} (GeV/c)");
243     outputContainer->Add(fhPtCharged);
244     
245     fhPhiCharged  = new TH1F ("hPhiCharged","#phi reconstructed clusters, matched with track",nphibins,phimin,phimax); 
246     fhPhiCharged->SetXTitle("#phi (rad)");
247     outputContainer->Add(fhPhiCharged);
248     
249     fhEtaCharged  = new TH1F ("hEtaCharged","#eta reconstructed clusters, matched with track",netabins,etamin,etamax); 
250     fhEtaCharged->SetXTitle("#eta ");
251     outputContainer->Add(fhEtaCharged);
252   }
253   
254         fhEtaPhiECharged  = new TH3F ("hEtaPhiECharged","#eta vs #phi, reconstructed clusters, matched with track",
255                                 netabins,etamin,etamax,nphibins,phimin,phimax,nptbins,ptmin,ptmax); 
256         fhEtaPhiECharged->SetXTitle("#eta ");
257         fhEtaPhiECharged->SetYTitle("#phi ");
258         fhEtaPhiECharged->SetZTitle("E (GeV) ");
259         outputContainer->Add(fhEtaPhiECharged); 
260   
261         fh1pOverE = new TH2F("h1pOverE","TRACK matches p/E",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
262         fh1pOverE->SetYTitle("p/E");
263         fh1pOverE->SetXTitle("p_{T} (GeV/c)");
264         outputContainer->Add(fh1pOverE);
265         
266         fh1dR = new TH1F("h1dR","TRACK matches dR",ndRbins,dRmin,dRmax);
267         fh1dR->SetXTitle("#Delta R (rad)");
268         outputContainer->Add(fh1dR) ;
269         
270         fh2MatchdEdx = new TH2F("h2MatchdEdx","dE/dx vs. p for all matches",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
271         fh2MatchdEdx->SetXTitle("p (GeV/c)");
272         fh2MatchdEdx->SetYTitle("<dE/dx>");
273         outputContainer->Add(fh2MatchdEdx);
274         
275         fh2EledEdx = new TH2F("h2EledEdx","dE/dx vs. p for electrons",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
276         fh2EledEdx->SetXTitle("p (GeV/c)");
277         fh2EledEdx->SetYTitle("<dE/dx>");
278         outputContainer->Add(fh2EledEdx) ;
279         
280         fh1pOverER02 = new TH2F("h1pOverER02","TRACK matches p/E, all",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
281         fh1pOverER02->SetYTitle("p/E");
282         fh1pOverER02->SetXTitle("p_{T} (GeV/c)");
283         outputContainer->Add(fh1pOverER02);     
284         
285         fhIM  = new TH2F ("hIM","Cluster pairs Invariant mass vs reconstructed pair energy",nptbins,ptmin,ptmax,nmassbins,massmin,massmax); 
286         fhIM->SetXTitle("p_{T, cluster pairs} (GeV) ");
287         fhIM->SetYTitle("M_{cluster pairs} (GeV/c^{2})");
288         outputContainer->Add(fhIM);
289         
290         fhIMCellCut  = new TH2F ("hIMCellCut","Cluster (n cell > 1) pairs Invariant mass vs reconstructed pair energy",nptbins,ptmin,ptmax,nmassbins,massmin,massmax); 
291         fhIMCellCut->SetXTitle("p_{T, cluster pairs} (GeV) ");
292         fhIMCellCut->SetYTitle("M_{cluster pairs} (GeV/c^{2})");
293         outputContainer->Add(fhIMCellCut);
294   
295   fhAsym  = new TH2F ("hAssym","Cluster pairs Asymmetry vs reconstructed pair energy",nptbins,ptmin,ptmax,nasymbins,asymmin,asymmax); 
296   fhAsym->SetXTitle("p_{T, cluster pairs} (GeV) ");
297   fhAsym->SetYTitle("Asymmetry");
298   outputContainer->Add(fhAsym); 
299   
300   
301   Int_t nlargeetabins = 3;
302         if(fCalorimeter=="EMCAL") nlargeetabins = 8;
303   
304         fhNCellsPerCluster  = new TH3F ("hNCellsPerCluster","# cells per cluster vs energy vs #eta",nptbins,ptmin,ptmax, nbins,nmin,nmax, nlargeetabins,etamin,etamax); 
305         fhNCellsPerCluster->SetXTitle("E (GeV)");
306         fhNCellsPerCluster->SetYTitle("n cells");
307         fhNCellsPerCluster->SetZTitle("#eta");
308         outputContainer->Add(fhNCellsPerCluster);
309         
310         
311         fhNCellsPerClusterMIP  = new TH3F ("hNCellsPerClusterMIP","# cells per cluster vs energy vs #eta, smaller bin for MIP search", 
312                                      40,0.,2., 11,0,10,nlargeetabins,etamin,etamax); 
313         fhNCellsPerClusterMIP->SetXTitle("E (GeV)");
314         fhNCellsPerClusterMIP->SetYTitle("n cells");
315         fhNCellsPerClusterMIP->SetZTitle("#eta");
316         outputContainer->Add(fhNCellsPerClusterMIP);
317         
318  
319         fhNCellsPerClusterMIPCharged  = new TH3F ("hNCellsPerClusterMIPCharged","# cells per track-matched cluster vs energy vs #eta, smaller bin for MIP search", 
320                                             40,0.,2., 11,0,10,nlargeetabins,etamin,etamax); 
321         fhNCellsPerClusterMIPCharged->SetXTitle("E (GeV)");
322         fhNCellsPerClusterMIPCharged->SetYTitle("n cells");
323         fhNCellsPerClusterMIPCharged->SetZTitle("#eta");
324         outputContainer->Add(fhNCellsPerClusterMIPCharged);
325         
326         
327         fhNClusters  = new TH1F ("hNClusters","# clusters", nbins,nmin,nmax); 
328         fhNClusters->SetXTitle("number of clusters");
329         outputContainer->Add(fhNClusters);
330   
331   fhXYZ  = new TH3F ("hXYZ","Cluster: x vs y vs z",xbins,xmin,xmax,ybins,ymin,ymax,zbins,zmin,zmax); 
332   fhXYZ->SetXTitle("x (cm)");
333   fhXYZ->SetYTitle("y (cm)");
334   fhXYZ->SetZTitle("z (cm) ");
335   outputContainer->Add(fhXYZ);  
336   
337   fhXNCells  = new TH2F ("hXNCells","Cluster X position vs N Clusters per Cell",xbins,xmin,xmax,nbins,nmin,nmax); 
338   fhXNCells->SetXTitle("x (cm)");
339   fhXNCells->SetYTitle("N cells per cluster");
340   outputContainer->Add(fhXNCells);
341   
342   fhZNCells  = new TH2F ("hZNCells","Cluster Z position vs N Clusters per Cell",zbins,zmin,zmax,nbins,nmin,nmax); 
343   fhZNCells->SetXTitle("z (cm)");
344   fhZNCells->SetYTitle("N cells per cluster");
345   outputContainer->Add(fhZNCells);
346   
347   fhXE  = new TH2F ("hXE","Cluster X position vs cluster energy",xbins,xmin,xmax,nptbins,ptmin,ptmax); 
348   fhXE->SetXTitle("x (cm)");
349   fhXE->SetYTitle("E (GeV)");
350   outputContainer->Add(fhXE);
351   
352   fhZE  = new TH2F ("hZE","Cluster Z position vs cluster energy",zbins,zmin,zmax,nptbins,ptmin,ptmax); 
353   fhZE->SetXTitle("z (cm)");
354   fhZE->SetYTitle("E (GeV)");
355   outputContainer->Add(fhZE);    
356   
357   
358   fhRNCells  = new TH2F ("hRNCells","Cluster R position vs N Clusters per Cell",rbins,rmin,rmax,nbins,nmin,nmax); 
359   fhRNCells->SetXTitle("r = #sqrt{x^{2}+y^{2}} (cm)");
360   fhRNCells->SetYTitle("N cells per cluster");
361   outputContainer->Add(fhRNCells);
362   
363   
364   fhYNCells  = new TH2F ("hYNCells","Cluster Y position vs N Clusters per Cell",ybins,ymin,ymax,nbins,nmin,nmax); 
365   fhYNCells->SetXTitle("y (cm)");
366   fhYNCells->SetYTitle("N cells per cluster");
367   outputContainer->Add(fhYNCells);
368   
369   fhRE  = new TH2F ("hRE","Cluster R position vs cluster energy",rbins,rmin,rmax,nptbins,ptmin,ptmax); 
370   fhRE->SetXTitle("r = #sqrt{x^{2}+y^{2}} (cm)");
371   fhRE->SetYTitle("E (GeV)");
372   outputContainer->Add(fhRE);
373   
374   fhYE  = new TH2F ("hYE","Cluster Y position vs cluster energy",ybins,ymin,ymax,nptbins,ptmin,ptmax); 
375   fhYE->SetXTitle("y (cm)");
376   fhYE->SetYTitle("E (GeV)");
377   outputContainer->Add(fhYE);
378     
379   if(fFillAllPosHisto){
380
381   
382     fhRCellE  = new TH2F ("hRCellE","Cell R position vs cell energy",rbins,rmin,rmax,nptbins,ptmin,ptmax); 
383     fhRCellE->SetXTitle("r = #sqrt{x^{2}+y^{2}} (cm)");
384     fhRCellE->SetYTitle("E (GeV)");
385     outputContainer->Add(fhRCellE);
386     
387     fhXCellE  = new TH2F ("hXCellE","Cell X position vs cell energy",xbins,xmin,xmax,nptbins,ptmin,ptmax); 
388     fhXCellE->SetXTitle("x (cm)");
389     fhXCellE->SetYTitle("E (GeV)");
390     outputContainer->Add(fhXCellE);
391     
392     fhYCellE  = new TH2F ("hYCellE","Cell Y position vs cell energy",ybins,ymin,ymax,nptbins,ptmin,ptmax); 
393     fhYCellE->SetXTitle("y (cm)");
394     fhYCellE->SetYTitle("E (GeV)");
395     outputContainer->Add(fhYCellE);
396     
397     fhZCellE  = new TH2F ("hZCellE","Cell Z position vs cell energy",zbins,zmin,zmax,nptbins,ptmin,ptmax); 
398     fhZCellE->SetXTitle("z (cm)");
399     fhZCellE->SetYTitle("E (GeV)");
400     outputContainer->Add(fhZCellE);
401     
402     fhXYZCell  = new TH3F ("hXYZCell","Cell : x vs y vs z",xbins,xmin,xmax,ybins,ymin,ymax,zbins,zmin,zmax); 
403     fhXYZCell->SetXTitle("x (cm)");
404     fhXYZCell->SetYTitle("y (cm)");
405     fhXYZCell->SetZTitle("z (cm)");
406     outputContainer->Add(fhXYZCell);
407     
408     
409     Float_t dx = TMath::Abs(xmin)+TMath::Abs(xmax);
410     Float_t dy = TMath::Abs(ymin)+TMath::Abs(ymax);
411     Float_t dz = TMath::Abs(zmin)+TMath::Abs(zmax);
412     Float_t dr = TMath::Abs(rmin)+TMath::Abs(rmax);
413     
414     fhDeltaCellClusterRNCells  = new TH2F ("hDeltaCellClusterRNCells","Cluster-Cell R position vs N Clusters per Cell",rbins*2,-dr,dr,nbins,nmin,nmax); 
415     fhDeltaCellClusterRNCells->SetXTitle("r = #sqrt{x^{2}+y^{2}} (cm)");
416     fhDeltaCellClusterRNCells->SetYTitle("N cells per cluster");
417     outputContainer->Add(fhDeltaCellClusterRNCells);
418     
419     fhDeltaCellClusterXNCells  = new TH2F ("hDeltaCellClusterXNCells","Cluster-Cell X position vs N Clusters per Cell",xbins*2,-dx,dx,nbins,nmin,nmax); 
420     fhDeltaCellClusterXNCells->SetXTitle("x (cm)");
421     fhDeltaCellClusterXNCells->SetYTitle("N cells per cluster");
422     outputContainer->Add(fhDeltaCellClusterXNCells);
423     
424     fhDeltaCellClusterYNCells  = new TH2F ("hDeltaCellClusterYNCells","Cluster-Cell Y position vs N Clusters per Cell",ybins*2,-dy,dy,nbins,nmin,nmax); 
425     fhDeltaCellClusterYNCells->SetXTitle("y (cm)");
426     fhDeltaCellClusterYNCells->SetYTitle("N cells per cluster");
427     outputContainer->Add(fhDeltaCellClusterYNCells);
428     
429     fhDeltaCellClusterZNCells  = new TH2F ("hDeltaCellClusterZNCells","Cluster-Cell Z position vs N Clusters per Cell",zbins*2,-dz,dz,nbins,nmin,nmax); 
430     fhDeltaCellClusterZNCells->SetXTitle("z (cm)");
431     fhDeltaCellClusterZNCells->SetYTitle("N cells per cluster");
432     outputContainer->Add(fhDeltaCellClusterZNCells);
433     
434     fhDeltaCellClusterRE  = new TH2F ("hDeltaCellClusterRE","Cluster-Cell R position vs cluster energy",rbins*2,-dr,dr,nptbins,ptmin,ptmax); 
435     fhDeltaCellClusterRE->SetXTitle("r = #sqrt{x^{2}+y^{2}} (cm)");
436     fhDeltaCellClusterRE->SetYTitle("E (GeV)");
437     outputContainer->Add(fhDeltaCellClusterRE);         
438     
439     fhDeltaCellClusterXE  = new TH2F ("hDeltaCellClusterXE","Cluster-Cell X position vs cluster energy",xbins*2,-dx,dx,nptbins,ptmin,ptmax); 
440     fhDeltaCellClusterXE->SetXTitle("x (cm)");
441     fhDeltaCellClusterXE->SetYTitle("E (GeV)");
442     outputContainer->Add(fhDeltaCellClusterXE);
443     
444     fhDeltaCellClusterYE  = new TH2F ("hDeltaCellClusterYE","Cluster-Cell Y position vs cluster energy",ybins*2,-dy,dy,nptbins,ptmin,ptmax); 
445     fhDeltaCellClusterYE->SetXTitle("y (cm)");
446     fhDeltaCellClusterYE->SetYTitle("E (GeV)");
447     outputContainer->Add(fhDeltaCellClusterYE);
448     
449     fhDeltaCellClusterZE  = new TH2F ("hDeltaCellClusterZE","Cluster-Cell Z position vs cluster energy",zbins*2,-dz,dz,nptbins,ptmin,ptmax); 
450     fhDeltaCellClusterZE->SetXTitle("z (cm)");
451     fhDeltaCellClusterZE->SetYTitle("E (GeV)");
452     outputContainer->Add(fhDeltaCellClusterZE);
453     
454     fhEtaPhiAmp  = new TH3F ("hEtaPhiAmp","Cell #eta vs cell #phi vs cell energy",netabins,etamin,etamax,nphibins,phimin,phimax,nptbins,ptmin,ptmax); 
455     fhEtaPhiAmp->SetXTitle("#eta ");
456     fhEtaPhiAmp->SetYTitle("#phi (rad)");
457     fhEtaPhiAmp->SetZTitle("E (GeV) ");
458     outputContainer->Add(fhEtaPhiAmp);          
459     
460         }
461   
462   //Calo cells
463         fhNCells  = new TH1F ("hNCells","# cells", colmax*rowmax*fNModules,0,colmax*rowmax*fNModules); 
464         fhNCells->SetXTitle("n cells");
465         outputContainer->Add(fhNCells);
466   
467         fhAmplitude  = new TH1F ("hAmplitude","Cell Energy", nptbins*2,ptmin,ptmax); 
468         fhAmplitude->SetXTitle("Cell Energy (GeV)");
469         outputContainer->Add(fhAmplitude);
470         
471         fhAmpId  = new TH2F ("hAmpId","Cell Energy", nfineptbins,ptfinemin,ptfinemax,rowmax*colmax*fNModules,0,rowmax*colmax*fNModules); 
472         fhAmpId->SetXTitle("Cell Energy (GeV)");
473         outputContainer->Add(fhAmpId);
474         
475         
476   //Cell Time histograms, time only available in ESDs
477         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
478                 
479                 fhCellTimeSpreadRespectToCellMax = new TH1F ("hCellTimeSpreadRespectToCellMax","t_{cell max}-t_{cell i} per cluster", 100,-200,200); 
480                 fhCellTimeSpreadRespectToCellMax->SetXTitle("#Delta t (ns)");
481                 outputContainer->Add(fhCellTimeSpreadRespectToCellMax);
482                 
483                 fhCellIdCellLargeTimeSpread= new TH1F ("hCellIdCellLargeTimeSpread","", colmax*rowmax*fNModules,0,colmax*rowmax*fNModules); 
484                 fhCellIdCellLargeTimeSpread->SetXTitle("Absolute Cell Id");
485                 outputContainer->Add(fhCellIdCellLargeTimeSpread);
486                 
487                 fhTime  = new TH1F ("hTime","Cell Time",ntimebins,timemin,timemax); 
488                 fhTime->SetXTitle("Cell Time (ns)");
489                 outputContainer->Add(fhTime);
490     
491                 fhTimeId  = new TH2F ("hTimeId","Cell Time vs Absolute Id",ntimebins,timemin,timemax,rowmax*colmax*fNModules,0,rowmax*colmax*fNModules); 
492                 fhTimeId->SetXTitle("Cell Time (ns)");
493                 fhTimeId->SetYTitle("Cell Absolute Id");
494                 outputContainer->Add(fhTimeId);
495     
496                 fhTimeAmp  = new TH2F ("hTimeAmp","Cell Time vs Cell Energy",nptbins*2,ptmin,ptmax,ntimebins,timemin,timemax); 
497                 fhTimeAmp->SetYTitle("Cell Time (ns)");
498                 fhTimeAmp->SetXTitle("Cell Energy (GeV)");
499                 outputContainer->Add(fhTimeAmp);
500                 
501     //          fhT0Time  = new TH1F ("hT0Time","Cell Time",ntimebins,timemin,timemax); 
502     //          fhT0Time->SetXTitle("T_{0} - T_{EMCal} (ns)");
503     //          outputContainer->Add(fhT0Time);
504     //          
505     //          fhT0TimeId  = new TH2F ("hT0TimeId","Cell Time vs Absolute Id",ntimebins,timemin,timemax,rowmax*colmax*fNModules,0,rowmax*colmax*fNModules); 
506     //          fhT0TimeId->SetXTitle("T_{0} - T_{EMCal} (ns)");
507     //          fhT0TimeId->SetYTitle("Cell Absolute Id");
508     //          outputContainer->Add(fhT0TimeId);
509     //          
510     //          fhT0TimeAmp  = new TH2F ("hT0TimeAmp","Cell Time vs Cell Energy",nptbins*2,ptmin,ptmax,ntimebins,timemin,timemax); 
511     //          fhT0TimeAmp->SetYTitle("T_{0} - T_{EMCal} (ns)");
512     //          fhT0TimeAmp->SetXTitle("Cell Energy (GeV)");
513     //          outputContainer->Add(fhT0TimeAmp);
514         }
515         
516         if(fCorrelateCalos){
517                 fhCaloCorrNClusters  = new TH2F ("hCaloCorrNClusters","# clusters in EMCAL vs PHOS", nbins,nmin,nmax,nbins,nmin,nmax); 
518                 fhCaloCorrNClusters->SetXTitle("number of clusters in EMCAL");
519                 fhCaloCorrNClusters->SetYTitle("number of clusters in PHOS");
520                 outputContainer->Add(fhCaloCorrNClusters);
521     
522                 fhCaloCorrEClusters  = new TH2F ("hCaloCorrEClusters","summed energy of clusters in EMCAL vs PHOS", nptbins*2,ptmin,ptmax*2,nptbins,ptmin,ptmax*2); 
523                 fhCaloCorrEClusters->SetXTitle("#Sigma E of clusters in EMCAL (GeV)");
524                 fhCaloCorrEClusters->SetYTitle("#Sigma E of clusters in PHOS (GeV)");
525                 outputContainer->Add(fhCaloCorrEClusters);
526     
527                 fhCaloCorrNCells  = new TH2F ("hCaloCorrNCells","# Cells in EMCAL vs PHOS", nbins,nmin,nmax, nbins,nmin,nmax); 
528                 fhCaloCorrNCells->SetXTitle("number of Cells in EMCAL");
529                 fhCaloCorrNCells->SetYTitle("number of Cells in PHOS");
530                 outputContainer->Add(fhCaloCorrNCells);
531     
532                 fhCaloCorrECells  = new TH2F ("hCaloCorrECells","summed energy of Cells in EMCAL vs PHOS", nptbins*2,ptmin,ptmax*2,nptbins,ptmin,ptmax*2); 
533                 fhCaloCorrECells->SetXTitle("#Sigma E of Cells in EMCAL (GeV)");
534                 fhCaloCorrECells->SetYTitle("#Sigma E of Cells in PHOS (GeV)");
535                 outputContainer->Add(fhCaloCorrECells);
536         }//correlate calorimeters
537         
538   //Module histograms
539         fhEMod                 = new TH1F*[fNModules];
540         fhNClustersMod         = new TH1F*[fNModules];
541         fhNCellsPerClusterMod  = new TH2F*[fNModules];
542         fhNCellsMod            = new TH1F*[fNModules];
543         fhGridCellsMod         = new TH2F*[fNModules];
544         fhGridCellsEMod        = new TH2F*[fNModules];
545         fhGridCellsTimeMod     = new TH2F*[fNModules];
546         fhAmplitudeMod         = new TH1F*[fNModules];
547         if(fCalorimeter=="EMCAL")
548                 fhAmplitudeModFraction = new TH1F*[fNModules*3];
549   
550         fhTimeAmpPerRCU        = new TH2F*[fNModules*fNRCU];
551   //fhT0TimeAmpPerRCU      = new TH2F*[fNModules*fNRCU];
552   //fhTimeCorrRCU          = new TH2F*[fNModules*fNRCU*fNModules*fNRCU];
553         
554         fhIMMod                = new TH2F*[fNModules];
555         fhIMCellCutMod         = new TH2F*[fNModules];
556   
557         for(Int_t imod = 0; imod < fNModules; imod++){
558                 
559                 fhEMod[imod]  = new TH1F (Form("hE_Mod%d",imod),Form("Cluster reconstructed Energy in Module %d ",imod), nptbins,ptmin,ptmax); 
560                 fhEMod[imod]->SetXTitle("E (GeV)");
561                 outputContainer->Add(fhEMod[imod]);
562                 
563                 fhNClustersMod[imod]  = new TH1F (Form("hNClusters_Mod%d",imod),Form("# clusters in Module %d",imod), nbins,nmin,nmax); 
564                 fhNClustersMod[imod]->SetXTitle("number of clusters");
565                 outputContainer->Add(fhNClustersMod[imod]);
566                 
567                 fhNCellsPerClusterMod[imod]  = new TH2F (Form("hNCellsPerCluster_Mod%d",imod),
568                                              Form("# cells per cluster vs cluster energy in Module %d",imod), 
569                                              nptbins,ptmin,ptmax, nbins,nmin,nmax); 
570                 fhNCellsPerClusterMod[imod]->SetXTitle("E (GeV)");
571                 fhNCellsPerClusterMod[imod]->SetYTitle("n cells");
572                 outputContainer->Add(fhNCellsPerClusterMod[imod]);
573                 
574                 fhNCellsMod[imod]  = new TH1F (Form("hNCells_Mod%d",imod),Form("# cells in Module %d",imod), colmax*rowmax,0,colmax*rowmax); 
575                 fhNCellsMod[imod]->SetXTitle("n cells");
576                 outputContainer->Add(fhNCellsMod[imod]);
577                 fhGridCellsMod[imod]  = new TH2F (Form("hGridCells_Mod%d",imod),Form("Entries in grid of cells in Module %d",imod), 
578                                       colmax+2,-1.5,colmax+0.5, rowmax+2,-1.5,rowmax+0.5); 
579                 fhGridCellsMod[imod]->SetYTitle("row (phi direction)");
580                 fhGridCellsMod[imod]->SetXTitle("column (eta direction)");
581                 outputContainer->Add(fhGridCellsMod[imod]);
582     
583                 fhGridCellsEMod[imod]  = new TH2F (Form("hGridCellsE_Mod%d",imod),Form("Accumulated energy in grid of cells in Module %d",imod), 
584                                        colmax+2,-1.5,colmax+0.5, rowmax+2,-1.5,rowmax+0.5); 
585                 fhGridCellsEMod[imod]->SetYTitle("row (phi direction)");
586                 fhGridCellsEMod[imod]->SetXTitle("column (eta direction)");
587                 outputContainer->Add(fhGridCellsEMod[imod]);
588                 
589                 fhGridCellsTimeMod[imod]  = new TH2F (Form("hGridCellsTime_Mod%d",imod),Form("Accumulated time in grid of cells in Module %d, with E > 0.5 GeV",imod), 
590                                           colmax+2,-1.5,colmax+0.5, rowmax+2,-1.5,rowmax+0.5); 
591                 fhGridCellsTimeMod[imod]->SetYTitle("row (phi direction)");
592                 fhGridCellsTimeMod[imod]->SetXTitle("column (eta direction)");
593                 outputContainer->Add(fhGridCellsTimeMod[imod]);
594                 
595                 fhAmplitudeMod[imod]  = new TH1F (Form("hAmplitude_Mod%d",imod),Form("Cell Energy in Module %d",imod), nptbins*2,ptmin,ptmax); 
596                 fhAmplitudeMod[imod]->SetXTitle("Cell Energy (GeV)");
597                 outputContainer->Add(fhAmplitudeMod[imod]);
598                 
599                 if(fCalorimeter == "EMCAL"){
600                         for(Int_t ifrac = 0; ifrac < 3; ifrac++){
601                                 fhAmplitudeModFraction[imod*3+ifrac]  = new TH1F (Form("hAmplitude_Mod%d_Frac%d",imod,ifrac),Form("Cell reconstructed Energy in Module %d, Fraction %d ",imod,ifrac), nptbins,ptmin,ptmax); 
602                                 fhAmplitudeModFraction[imod*3+ifrac]->SetXTitle("E (GeV)");
603                                 outputContainer->Add(fhAmplitudeModFraction[imod*3+ifrac]);
604                         }
605                         
606                 }
607                 
608                 for(Int_t ircu = 0; ircu < fNRCU; ircu++){
609       fhTimeAmpPerRCU[imod*fNRCU+ircu]  = new TH2F (Form("hTimeAmp_Mod%d_RCU%d",imod,ircu),
610                                                     Form("Cell Energy vs Cell Time in Module %d, RCU %d ",imod,ircu), 
611                                                     nptbins,ptmin,ptmax,ntimebins,timemin,timemax); 
612       fhTimeAmpPerRCU[imod*fNRCU+ircu]->SetXTitle("E (GeV)");
613       fhTimeAmpPerRCU[imod*fNRCU+ircu]->SetYTitle("time (ns)");
614       outputContainer->Add(fhTimeAmpPerRCU[imod*fNRCU+ircu]);
615                         
616       //                                fhT0TimeAmpPerRCU[imod*fNRCU+ircu]  = new TH2F (Form("hT0TimeAmp_Mod%d_RCU%d",imod,ircu),
617       //                                                                                                                          Form("Cell Energy vs T0-Cell Time in Module %d, RCU %d ",imod,ircu), 
618       //                                                                                                                          nptbins,ptmin,ptmax,ntimebins,timemin,timemax); 
619       //                                fhT0TimeAmpPerRCU[imod*fNRCU+ircu]->SetXTitle("E (GeV)");
620       //                                fhT0TimeAmpPerRCU[imod*fNRCU+ircu]->SetYTitle("T_{0} - T_{EMCal} (ns)");
621       //                                outputContainer->Add(fhT0TimeAmpPerRCU[imod*fNRCU+ircu]);
622       //                        
623                         
624       //                                for(Int_t imod2 = 0; imod2 < fNModules; imod2++){
625       //                                                for(Int_t ircu2 = 0; ircu2 < fNModules; ircu2++){
626       //                                                        Int_t index =  (imod2*fNRCU+ircu2)+(fNModules*fNRCU)*(ircu+imod)+fNRCU*fNModules*imod; 
627       //                                                        fhTimeCorrRCU[index]  = new TH2F (Form("hTimeCorrRCU_Mod%d_RCU%d_CompareTo_Mod%d_RCU%d",imod, ircu,imod2, ircu2),
628       //                                                                                                                                                        Form("Cell Energy > 0.3, Correlate cell Time in Module %d, RCU %d to Module %d, RCU %d",imod,ircu,imod2, ircu2),
629       //                                                                                                                                                        ntimebins,timemin,timemax,ntimebins,timemin,timemax); 
630       //                                                        fhTimeCorrRCU[index]->SetXTitle("Trigger Cell Time (ns)");
631       //                                                        fhTimeCorrRCU[index]->SetYTitle("Cell Time (ns)");
632       //                                                        outputContainer->Add(fhTimeCorrRCU[index]);
633       //                                                }
634       //                                }
635                 }
636                 
637                 
638                 fhIMMod[imod]  = new TH2F (Form("hIM_Mod%d",imod),
639                                Form("Cluster pairs Invariant mass vs reconstructed pair energy in Module %d",imod),
640                                nptbins,ptmin,ptmax,nmassbins,massmin,massmax); 
641                 fhIMMod[imod]->SetXTitle("p_{T, cluster pairs} (GeV) ");
642                 fhIMMod[imod]->SetYTitle("M_{cluster pairs} (GeV/c^{2})");
643                 outputContainer->Add(fhIMMod[imod]);
644     
645                 fhIMCellCutMod[imod]  = new TH2F (Form("hIMCellCut_Mod%d",imod),
646                                       Form("Cluster (n cells > 1) pairs Invariant mass vs reconstructed pair energy in Module %d",imod),
647                                       nptbins,ptmin,ptmax,nmassbins,massmin,massmax); 
648                 fhIMCellCutMod[imod]->SetXTitle("p_{T, cluster pairs} (GeV) ");
649                 fhIMCellCutMod[imod]->SetYTitle("M_{cluster pairs} (GeV/c^{2})");
650                 outputContainer->Add(fhIMCellCutMod[imod]);
651                 
652         }
653         
654         
655   //Monte Carlo Histograms
656         if(IsDataMC()){
657                 
658                 fhDeltaE  = new TH1F ("hDeltaE","MC - Reco E ", nptbins*2,-ptmax,ptmax); 
659                 fhDeltaE->SetXTitle("#Delta E (GeV)");
660                 outputContainer->Add(fhDeltaE);
661                 
662                 fhDeltaPt  = new TH1F ("hDeltaPt","MC - Reco p_{T} ", nptbins*2,-ptmax,ptmax); 
663                 fhDeltaPt->SetXTitle("#Delta p_{T} (GeV/c)");
664                 outputContainer->Add(fhDeltaPt);
665                 
666                 fhDeltaPhi  = new TH1F ("hDeltaPhi","MC - Reco #phi ",nphibins*2,-phimax,phimax); 
667                 fhDeltaPhi->SetXTitle("#Delta #phi (rad)");
668                 outputContainer->Add(fhDeltaPhi);
669                 
670                 fhDeltaEta  = new TH1F ("hDeltaEta","MC- Reco #eta",netabins*2,-etamax,etamax); 
671                 fhDeltaEta->SetXTitle("#Delta #eta ");
672                 outputContainer->Add(fhDeltaEta);
673                 
674                 fhRatioE  = new TH1F ("hRatioE","Reco/MC E ", nratiobins,ratiomin,ratiomax); 
675                 fhRatioE->SetXTitle("E_{reco}/E_{gen}");
676                 outputContainer->Add(fhRatioE);
677                 
678                 fhRatioPt  = new TH1F ("hRatioPt","Reco/MC p_{T} ", nratiobins,ratiomin,ratiomax); 
679                 fhRatioPt->SetXTitle("p_{T, reco}/p_{T, gen}");
680                 outputContainer->Add(fhRatioPt);
681                 
682                 fhRatioPhi  = new TH1F ("hRatioPhi","Reco/MC #phi ",nratiobins,ratiomin,ratiomax); 
683                 fhRatioPhi->SetXTitle("#phi_{reco}/#phi_{gen}");
684                 outputContainer->Add(fhRatioPhi);
685                 
686                 fhRatioEta  = new TH1F ("hRatioEta","Reco/MC #eta",nratiobins,ratiomin,ratiomax); 
687                 fhRatioEta->SetXTitle("#eta_{reco}/#eta_{gen} ");
688                 outputContainer->Add(fhRatioEta);
689                 
690                 fh2E  = new TH2F ("h2E","E distribution, reconstructed vs generated", nptbins,ptmin,ptmax,nptbins,ptmin,ptmax); 
691                 fh2E->SetXTitle("E_{rec} (GeV)");
692                 fh2E->SetYTitle("E_{gen} (GeV)");
693                 outputContainer->Add(fh2E);       
694                 
695                 fh2Pt  = new TH2F ("h2Pt","p_T distribution, reconstructed vs generated", nptbins,ptmin,ptmax,nptbins,ptmin,ptmax); 
696                 fh2Pt->SetXTitle("p_{T,rec} (GeV/c)");
697                 fh2Pt->SetYTitle("p_{T,gen} (GeV/c)");
698                 outputContainer->Add(fh2Pt);
699                 
700                 fh2Phi  = new TH2F ("h2Phi","#phi distribution, reconstructed vs generated", nphibins,phimin,phimax, nphibins,phimin,phimax); 
701                 fh2Phi->SetXTitle("#phi_{rec} (rad)");
702                 fh2Phi->SetYTitle("#phi_{gen} (rad)");
703                 outputContainer->Add(fh2Phi);
704                 
705                 fh2Eta  = new TH2F ("h2Eta","#eta distribution, reconstructed vs generated", netabins,etamin,etamax,netabins,etamin,etamax); 
706                 fh2Eta->SetXTitle("#eta_{rec} ");
707                 fh2Eta->SetYTitle("#eta_{gen} ");
708                 outputContainer->Add(fh2Eta);
709                 
710     //Fill histos depending on origin of cluster
711                 fhGamE  = new TH2F ("hGamE","E reconstructed vs E generated from #gamma", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
712                 fhGamE->SetXTitle("E_{rec} (GeV)");
713                 fhGamE->SetXTitle("E_{gen} (GeV)");
714                 outputContainer->Add(fhGamE);
715                 
716                 fhGamPt  = new TH2F ("hGamPt","p_{T} reconstructed vs E generated from #gamma", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
717                 fhGamPt->SetXTitle("p_{T rec} (GeV/c)");
718                 fhGamPt->SetYTitle("p_{T gen} (GeV/c)");
719                 outputContainer->Add(fhGamPt);
720                 
721                 fhGamPhi  = new TH2F ("hGamPhi","#phi reconstructed vs E generated from #gamma",nphibins,phimin,phimax,nphibins,phimin,phimax); 
722                 fhGamPhi->SetXTitle("#phi_{rec} (rad)");
723                 fhGamPhi->SetYTitle("#phi_{gen} (rad)");
724                 outputContainer->Add(fhGamPhi);
725                 
726                 fhGamEta  = new TH2F ("hGamEta","#eta reconstructed vs E generated from #gamma",netabins,etamin,etamax,netabins,etamin,etamax); 
727                 fhGamEta->SetXTitle("#eta_{rec} ");
728                 fhGamEta->SetYTitle("#eta_{gen} ");
729                 outputContainer->Add(fhGamEta);
730                 
731                 fhGamDeltaE  = new TH1F ("hGamDeltaE","#gamma MC - Reco E ", nptbins*2,-ptmax,ptmax); 
732                 fhGamDeltaE->SetXTitle("#Delta E (GeV)");
733                 outputContainer->Add(fhGamDeltaE);
734                 
735                 fhGamDeltaPt  = new TH1F ("hGamDeltaPt","#gamma MC - Reco p_{T} ", nptbins*2,-ptmax,ptmax); 
736                 fhGamDeltaPt->SetXTitle("#Delta p_{T} (GeV/c)");
737                 outputContainer->Add(fhGamDeltaPt);
738                 
739                 fhGamDeltaPhi  = new TH1F ("hGamDeltaPhi","#gamma MC - Reco #phi ",nphibins*2,-phimax,phimax); 
740                 fhGamDeltaPhi->SetXTitle("#Delta #phi (rad)");
741                 outputContainer->Add(fhGamDeltaPhi);
742                 
743                 fhGamDeltaEta  = new TH1F ("hGamDeltaEta","#gamma MC- Reco #eta",netabins*2,-etamax,etamax); 
744                 fhGamDeltaEta->SetXTitle("#Delta #eta ");
745                 outputContainer->Add(fhGamDeltaEta);
746                 
747                 fhGamRatioE  = new TH1F ("hGamRatioE","#gamma Reco/MC E ", nratiobins,ratiomin,ratiomax); 
748                 fhGamRatioE->SetXTitle("E_{reco}/E_{gen}");
749                 outputContainer->Add(fhGamRatioE);
750                 
751                 fhGamRatioPt  = new TH1F ("hGamRatioPt","#gamma Reco/MC p_{T} ", nratiobins,ratiomin,ratiomax); 
752                 fhGamRatioPt->SetXTitle("p_{T, reco}/p_{T, gen}");
753                 outputContainer->Add(fhGamRatioPt);
754                 
755                 fhGamRatioPhi  = new TH1F ("hGamRatioPhi","#gamma Reco/MC #phi ",nratiobins,ratiomin,ratiomax); 
756                 fhGamRatioPhi->SetXTitle("#phi_{reco}/#phi_{gen}");
757                 outputContainer->Add(fhGamRatioPhi);
758                 
759                 fhGamRatioEta  = new TH1F ("hGamRatioEta","#gamma Reco/MC #eta",nratiobins,ratiomin,ratiomax); 
760                 fhGamRatioEta->SetXTitle("#eta_{reco}/#eta_{gen} ");
761                 outputContainer->Add(fhGamRatioEta);
762     
763                 fhPi0E  = new TH2F ("hPi0E","E reconstructed vs E generated from #pi^{0}", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
764                 fhPi0E->SetXTitle("E_{rec} (GeV)");
765                 fhPi0E->SetYTitle("E_{gen} (GeV)");
766                 outputContainer->Add(fhPi0E);
767                 
768                 fhPi0Pt  = new TH2F ("hPi0Pt","p_{T} reconstructed vs E generated from #pi^{0}", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
769                 fhPi0Pt->SetXTitle("p_{T rec} (GeV/c)");
770                 fhPi0Pt->SetYTitle("p_{T gen} (GeV/c)");
771                 outputContainer->Add(fhPi0Pt);
772                 
773                 fhPi0Phi  = new TH2F ("hPi0Phi","#phi reconstructed vs E generated from #pi^{0}",nphibins,phimin,phimax,nphibins,phimin,phimax); 
774                 fhPi0Phi->SetXTitle("#phi_{rec} (rad)");
775                 fhPi0Phi->SetYTitle("#phi_{gen} (rad)");
776                 outputContainer->Add(fhPi0Phi);
777                 
778                 fhPi0Eta  = new TH2F ("hPi0Eta","#eta reconstructed vs E generated from #pi^{0}",netabins,etamin,etamax,netabins,etamin,etamax); 
779                 fhPi0Eta->SetXTitle("#eta_{rec} ");
780                 fhPi0Eta->SetYTitle("#eta_{gen} ");
781                 outputContainer->Add(fhPi0Eta);
782                 
783                 fhEleE  = new TH2F ("hEleE","E reconstructed vs E generated from e^{#pm}", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
784                 fhEleE->SetXTitle("E_{rec} (GeV)");
785                 fhEleE->SetXTitle("E_{gen} (GeV)");             
786                 outputContainer->Add(fhEleE);           
787                 
788                 fhElePt  = new TH2F ("hElePt","p_{T} reconstructed vs E generated from e^{#pm}", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
789                 fhElePt->SetXTitle("p_{T rec} (GeV/c)");
790                 fhElePt->SetYTitle("p_{T gen} (GeV/c)");
791                 outputContainer->Add(fhElePt);
792                 
793                 fhElePhi  = new TH2F ("hElePhi","#phi reconstructed vs E generated from e^{#pm}",nphibins,phimin,phimax,nphibins,phimin,phimax); 
794                 fhElePhi->SetXTitle("#phi_{rec} (rad)");
795                 fhElePhi->SetYTitle("#phi_{gen} (rad)");
796                 outputContainer->Add(fhElePhi);
797                 
798                 fhEleEta  = new TH2F ("hEleEta","#eta reconstructed vs E generated from e^{#pm}",netabins,etamin,etamax,netabins,etamin,etamax); 
799                 fhEleEta->SetXTitle("#eta_{rec} ");
800                 fhEleEta->SetYTitle("#eta_{gen} ");
801                 outputContainer->Add(fhEleEta);
802                 
803                 fhNeHadE  = new TH2F ("hNeHadE","E reconstructed vs E generated from neutral hadron", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
804                 fhNeHadE->SetXTitle("E_{rec} (GeV)");
805                 fhNeHadE->SetYTitle("E_{gen} (GeV)");
806                 outputContainer->Add(fhNeHadE);
807                 
808                 fhNeHadPt  = new TH2F ("hNeHadPt","p_{T} reconstructed vs E generated from neutral hadron", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
809                 fhNeHadPt->SetXTitle("p_{T rec} (GeV/c)");
810                 fhNeHadPt->SetYTitle("p_{T gen} (GeV/c)");
811                 outputContainer->Add(fhNeHadPt);
812                 
813                 fhNeHadPhi  = new TH2F ("hNeHadPhi","#phi reconstructed vs E generated from neutral hadron",nphibins,phimin,phimax,nphibins,phimin,phimax); 
814                 fhNeHadPhi->SetXTitle("#phi_{rec} (rad)");
815                 fhNeHadPhi->SetYTitle("#phi_{gen} (rad)");
816                 outputContainer->Add(fhNeHadPhi);
817                 
818                 fhNeHadEta  = new TH2F ("hNeHadEta","#eta reconstructed vs E generated from neutral hadron",netabins,etamin,etamax,netabins,etamin,etamax); 
819                 fhNeHadEta->SetXTitle("#eta_{rec} ");
820                 fhNeHadEta->SetYTitle("#eta_{gen} ");
821                 outputContainer->Add(fhNeHadEta);
822                 
823                 fhChHadE  = new TH2F ("hChHadE","E reconstructed vs E generated from charged hadron", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
824                 fhChHadE->SetXTitle("E_{rec} (GeV)");
825                 fhChHadE->SetYTitle("E_{gen} (GeV)");
826                 outputContainer->Add(fhChHadE);
827                 
828                 fhChHadPt  = new TH2F ("hChHadPt","p_{T} reconstructed vs E generated from charged hadron", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
829                 fhChHadPt->SetXTitle("p_{T rec} (GeV/c)");
830                 fhChHadPt->SetYTitle("p_{T gen} (GeV/c)");
831                 outputContainer->Add(fhChHadPt);
832                 
833                 fhChHadPhi  = new TH2F ("hChHadPhi","#phi reconstructed vs E generated from charged hadron",nphibins,phimin,phimax,nphibins,phimin,phimax); 
834                 fhChHadPhi->SetXTitle("#phi_{rec} (rad)");
835                 fhChHadPhi->SetYTitle("#phi_{gen} (rad)");
836                 outputContainer->Add(fhChHadPhi);
837                 
838                 fhChHadEta  = new TH2F ("hChHadEta","#eta reconstructed vs E generated from charged hadron",netabins,etamin,etamax,netabins,etamin,etamax); 
839                 fhChHadEta->SetXTitle("#eta_{rec} ");
840                 fhChHadEta->SetYTitle("#eta_{gen} ");
841                 outputContainer->Add(fhChHadEta);
842                 
843     //Charged clusters
844                 
845                 fhGamECharged  = new TH2F ("hGamECharged","E reconstructed vs E generated from #gamma, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
846                 fhGamECharged->SetXTitle("E_{rec} (GeV)");
847                 fhGamECharged->SetXTitle("E_{gen} (GeV)");
848                 outputContainer->Add(fhGamECharged);
849                 
850                 fhGamPtCharged  = new TH2F ("hGamPtCharged","p_{T} reconstructed vs E generated from #gamma, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
851                 fhGamPtCharged->SetXTitle("p_{T rec} (GeV/c)");
852                 fhGamPtCharged->SetYTitle("p_{T gen} (GeV/c)");
853                 outputContainer->Add(fhGamPtCharged);
854                 
855                 fhGamPhiCharged  = new TH2F ("hGamPhiCharged","#phi reconstructed vs E generated from #gamma, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
856                 fhGamPhiCharged->SetXTitle("#phi_{rec} (rad)");
857                 fhGamPhiCharged->SetYTitle("#phi_{gen} (rad)");
858                 outputContainer->Add(fhGamPhiCharged);
859                 
860                 fhGamEtaCharged  = new TH2F ("hGamEtaCharged","#eta reconstructed vs E generated from #gamma, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
861                 fhGamEtaCharged->SetXTitle("#eta_{rec} ");
862                 fhGamEtaCharged->SetYTitle("#eta_{gen} ");
863                 outputContainer->Add(fhGamEtaCharged);
864                 
865                 fhPi0ECharged  = new TH2F ("hPi0ECharged","E reconstructed vs E generated from #pi^{0}, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
866                 fhPi0ECharged->SetXTitle("E_{rec} (GeV)");
867                 fhPi0ECharged->SetYTitle("E_{gen} (GeV)");
868                 outputContainer->Add(fhPi0ECharged);
869                 
870                 fhPi0PtCharged  = new TH2F ("hPi0PtCharged","p_{T} reconstructed vs E generated from #pi^{0}, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
871                 fhPi0PtCharged->SetXTitle("p_{T rec} (GeV/c)");
872                 fhPi0PtCharged->SetYTitle("p_{T gen} (GeV/c)");
873                 outputContainer->Add(fhPi0PtCharged);
874                 
875                 fhPi0PhiCharged  = new TH2F ("hPi0PhiCharged","#phi reconstructed vs E generated from #pi^{0}, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
876                 fhPi0PhiCharged->SetXTitle("#phi_{rec} (rad)");
877                 fhPi0PhiCharged->SetYTitle("#phi_{gen} (rad)");
878                 outputContainer->Add(fhPi0PhiCharged);
879                 
880                 fhPi0EtaCharged  = new TH2F ("hPi0EtaCharged","#eta reconstructed vs E generated from #pi^{0}, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
881                 fhPi0EtaCharged->SetXTitle("#eta_{rec} ");
882                 fhPi0EtaCharged->SetYTitle("#eta_{gen} ");
883                 outputContainer->Add(fhPi0EtaCharged);
884                 
885                 fhEleECharged  = new TH2F ("hEleECharged","E reconstructed vs E generated from e^{#pm}, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
886                 fhEleECharged->SetXTitle("E_{rec} (GeV)");
887                 fhEleECharged->SetXTitle("E_{gen} (GeV)");              
888                 outputContainer->Add(fhEleECharged);            
889                 
890                 fhElePtCharged  = new TH2F ("hElePtCharged","p_{T} reconstructed vs E generated from e^{#pm}, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
891                 fhElePtCharged->SetXTitle("p_{T rec} (GeV/c)");
892                 fhElePtCharged->SetYTitle("p_{T gen} (GeV/c)");
893                 outputContainer->Add(fhElePtCharged);
894                 
895                 fhElePhiCharged  = new TH2F ("hElePhiCharged","#phi reconstructed vs E generated from e^{#pm}, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
896                 fhElePhiCharged->SetXTitle("#phi_{rec} (rad)");
897                 fhElePhiCharged->SetYTitle("#phi_{gen} (rad)");
898                 outputContainer->Add(fhElePhiCharged);
899                 
900                 fhEleEtaCharged  = new TH2F ("hEleEtaCharged","#eta reconstructed vs E generated from e^{#pm}, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
901                 fhEleEtaCharged->SetXTitle("#eta_{rec} ");
902                 fhEleEtaCharged->SetYTitle("#eta_{gen} ");
903                 outputContainer->Add(fhEleEtaCharged);
904                 
905                 fhNeHadECharged  = new TH2F ("hNeHadECharged","E reconstructed vs E generated from neutral hadron, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
906                 fhNeHadECharged->SetXTitle("E_{rec} (GeV)");
907                 fhNeHadECharged->SetYTitle("E_{gen} (GeV)");
908                 outputContainer->Add(fhNeHadECharged);
909                 
910                 fhNeHadPtCharged  = new TH2F ("hNeHadPtCharged","p_{T} reconstructed vs E generated from neutral hadron, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
911                 fhNeHadPtCharged->SetXTitle("p_{T rec} (GeV/c)");
912                 fhNeHadPtCharged->SetYTitle("p_{T gen} (GeV/c)");
913                 outputContainer->Add(fhNeHadPtCharged);
914                 
915                 fhNeHadPhiCharged  = new TH2F ("hNeHadPhiCharged","#phi reconstructed vs E generated from neutral hadron, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
916                 fhNeHadPhiCharged->SetXTitle("#phi_{rec} (rad)");
917                 fhNeHadPhiCharged->SetYTitle("#phi_{gen} (rad)");
918                 outputContainer->Add(fhNeHadPhiCharged);
919                 
920                 fhNeHadEtaCharged  = new TH2F ("hNeHadEtaCharged","#eta reconstructed vs E generated from neutral hadron, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
921                 fhNeHadEtaCharged->SetXTitle("#eta_{rec} ");
922                 fhNeHadEtaCharged->SetYTitle("#eta_{gen} ");
923                 outputContainer->Add(fhNeHadEtaCharged);
924                 
925                 fhChHadECharged  = new TH2F ("hChHadECharged","E reconstructed vs E generated from charged hadron, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
926                 fhChHadECharged->SetXTitle("E_{rec} (GeV)");
927                 fhChHadECharged->SetYTitle("E_{gen} (GeV)");
928                 outputContainer->Add(fhChHadECharged);
929                 
930                 fhChHadPtCharged  = new TH2F ("hChHadPtCharged","p_{T} reconstructed vs E generated from charged hadron, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
931                 fhChHadPtCharged->SetXTitle("p_{T rec} (GeV/c)");
932                 fhChHadPtCharged->SetYTitle("p_{T gen} (GeV/c)");
933                 outputContainer->Add(fhChHadPtCharged);
934                 
935                 fhChHadPhiCharged  = new TH2F ("hChHadPhiCharged","#phi reconstructed vs E generated from charged hadron, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
936                 fhChHadPhiCharged->SetXTitle("#phi (rad)");
937                 fhChHadPhiCharged->SetXTitle("#phi_{rec} (rad)");
938                 fhChHadPhiCharged->SetYTitle("#phi_{gen} (rad)");
939                 outputContainer->Add(fhChHadPhiCharged);
940                 
941                 fhChHadEtaCharged  = new TH2F ("hChHadEtaCharged","#eta reconstructed vs E generated from charged hadron, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
942                 fhChHadEtaCharged->SetXTitle("#eta_{rec} ");
943                 fhChHadEtaCharged->SetYTitle("#eta_{gen} ");
944                 outputContainer->Add(fhChHadEtaCharged);
945                 
946     //Vertex of generated particles 
947                 
948                 fhEMVxyz  = new TH2F ("hEMVxyz","Production vertex of reconstructed ElectroMagnetic particles",nvdistbins,vdistmin,vdistmax,nvdistbins,vdistmin,vdistmax);//,100,0,500); 
949                 fhEMVxyz->SetXTitle("v_{x}");
950                 fhEMVxyz->SetYTitle("v_{y}");
951     //fhEMVxyz->SetZTitle("v_{z}");
952                 outputContainer->Add(fhEMVxyz);
953                 
954                 fhHaVxyz  = new TH2F ("hHaVxyz","Production vertex of reconstructed hadrons",nvdistbins,vdistmin,vdistmax,nvdistbins,vdistmin,vdistmax);//,100,0,500); 
955                 fhHaVxyz->SetXTitle("v_{x}");
956                 fhHaVxyz->SetYTitle("v_{y}");
957     //fhHaVxyz->SetZTitle("v_{z}");
958                 outputContainer->Add(fhHaVxyz);
959                 
960                 fhEMR  = new TH2F ("hEMR","Distance to production vertex of reconstructed ElectroMagnetic particles vs E rec",nptbins,ptmin,ptmax,nvdistbins,vdistmin,vdistmax); 
961                 fhEMR->SetXTitle("E (GeV)");
962                 fhEMR->SetYTitle("TMath::Sqrt(v_{x}^{2}+v_{y}^{2})");
963                 outputContainer->Add(fhEMR);
964                 
965                 fhHaR  = new TH2F ("hHaR","Distance to production vertex of reconstructed Hadrons vs E rec",nptbins,ptmin,ptmax,nvdistbins,vdistmin,vdistmax); 
966                 fhHaR->SetXTitle("E (GeV)");
967                 fhHaR->SetYTitle("TMath::Sqrt(v_{x}^{2}+v_{y}^{2})");
968                 outputContainer->Add(fhHaR);
969                 
970     
971                 
972     //Pure MC
973                 fhGenGamPt  = new TH1F("hGenGamPt" ,"p_{T} of generated #gamma",nptbins,ptmin,ptmax);
974                 fhGenGamEta = new TH1F("hGenGamEta","Y of generated #gamma",netabins,etamin,etamax);
975                 fhGenGamPhi = new TH1F("hGenGamPhi","#phi of generated #gamma",nphibins,phimin,phimax);
976                 
977                 fhGenPi0Pt  = new TH1F("hGenPi0Pt" ,"p_{T} of generated #pi^{0}",nptbins,ptmin,ptmax);
978                 fhGenPi0Eta = new TH1F("hGenPi0Eta","Y of generated #pi^{0}",netabins,etamin,etamax);
979                 fhGenPi0Phi = new TH1F("hGenPi0Phi","#phi of generated #pi^{0}",nphibins,phimin,phimax);
980                 
981                 fhGenEtaPt  = new TH1F("hGenEtaPt" ,"p_{T} of generated #eta",nptbins,ptmin,ptmax);
982                 fhGenEtaEta = new TH1F("hGenEtaEta","Y of generated #eta",netabins,etamin,etamax);
983                 fhGenEtaPhi = new TH1F("hGenEtaPhi","#phi of generated #eta",nphibins,phimin,phimax);
984                 
985                 fhGenOmegaPt  = new TH1F("hGenOmegaPt" ,"p_{T} of generated #omega",nptbins,ptmin,ptmax);
986                 fhGenOmegaEta = new TH1F("hGenOmegaEta","Y of generated #omega",netabins,etamin,etamax);
987                 fhGenOmegaPhi = new TH1F("hGenOmegaPhi","#phi of generated #omega",nphibins,phimin,phimax);             
988                 
989                 fhGenElePt  = new TH1F("hGenElePt" ,"p_{T} of generated e^{#pm}",nptbins,ptmin,ptmax);
990                 fhGenEleEta = new TH1F("hGenEleEta","Y of generated  e^{#pm}",netabins,etamin,etamax);
991                 fhGenElePhi = new TH1F("hGenElePhi","#phi of generated  e^{#pm}",nphibins,phimin,phimax);               
992                 
993                 fhGenGamPt->SetXTitle("p_{T} (GeV/c)");
994                 fhGenGamEta->SetXTitle("#eta");
995                 fhGenGamPhi->SetXTitle("#phi (rad)");
996                 outputContainer->Add(fhGenGamPt);
997                 outputContainer->Add(fhGenGamEta);
998                 outputContainer->Add(fhGenGamPhi);
999     
1000                 fhGenPi0Pt->SetXTitle("p_{T} (GeV/c)");
1001                 fhGenPi0Eta->SetXTitle("#eta");
1002                 fhGenPi0Phi->SetXTitle("#phi (rad)");
1003                 outputContainer->Add(fhGenPi0Pt);
1004                 outputContainer->Add(fhGenPi0Eta);
1005                 outputContainer->Add(fhGenPi0Phi);
1006                 
1007                 fhGenEtaPt->SetXTitle("p_{T} (GeV/c)");
1008                 fhGenEtaEta->SetXTitle("#eta");
1009                 fhGenEtaPhi->SetXTitle("#phi (rad)");
1010                 outputContainer->Add(fhGenEtaPt);
1011                 outputContainer->Add(fhGenEtaEta);
1012                 outputContainer->Add(fhGenEtaPhi);
1013     
1014                 fhGenOmegaPt->SetXTitle("p_{T} (GeV/c)");
1015                 fhGenOmegaEta->SetXTitle("#eta");
1016                 fhGenOmegaPhi->SetXTitle("#phi (rad)");
1017                 outputContainer->Add(fhGenOmegaPt);
1018                 outputContainer->Add(fhGenOmegaEta);
1019                 outputContainer->Add(fhGenOmegaPhi);
1020                 
1021                 fhGenElePt->SetXTitle("p_{T} (GeV/c)");
1022                 fhGenEleEta->SetXTitle("#eta");
1023                 fhGenElePhi->SetXTitle("#phi (rad)");
1024                 outputContainer->Add(fhGenElePt);
1025                 outputContainer->Add(fhGenEleEta);
1026                 outputContainer->Add(fhGenElePhi);
1027                 
1028                 fhGenGamAccE   = new TH1F("hGenGamAccE" ,"E of generated #gamma in calorimeter acceptance",nptbins,ptmin,ptmax);
1029                 fhGenGamAccPt  = new TH1F("hGenGamAccPt" ,"p_{T} of generated #gamma in calorimeter acceptance",nptbins,ptmin,ptmax);
1030                 fhGenGamAccEta = new TH1F("hGenGamAccEta","Y of generated #gamma in calorimeter acceptance",netabins,etamin,etamax);
1031                 fhGenGamAccPhi = new TH1F("hGenGamAccPhi","#phi of generated #gamma  in calorimeter acceptance",nphibins,phimin,phimax);
1032                 
1033                 fhGenPi0AccE   = new TH1F("hGenPi0AccE" ,"E of generated #pi^{0} in calorimeter acceptance",nptbins,ptmin,ptmax);
1034                 fhGenPi0AccPt  = new TH1F("hGenPi0AccPt" ,"p_{T} of generated #pi^{0} in calorimeter acceptance",nptbins,ptmin,ptmax);
1035                 fhGenPi0AccEta = new TH1F("hGenPi0AccEta","Y of generated #pi^{0} in calorimeter acceptance",netabins,etamin,etamax);
1036                 fhGenPi0AccPhi = new TH1F("hGenPi0AccPhi","#phi of generated #pi^{0} in calorimeter acceptance",nphibins,phimin,phimax);
1037                 
1038                 fhGenGamAccE  ->SetXTitle("E (GeV)");
1039                 fhGenGamAccPt ->SetXTitle("p_{T} (GeV/c)");
1040                 fhGenGamAccEta->SetXTitle("#eta");
1041                 fhGenGamAccPhi->SetXTitle("#phi (rad)");
1042                 outputContainer->Add(fhGenGamAccE);             
1043                 outputContainer->Add(fhGenGamAccPt);
1044                 outputContainer->Add(fhGenGamAccEta);
1045                 outputContainer->Add(fhGenGamAccPhi);
1046                 
1047                 fhGenPi0AccE  ->SetXTitle("E (GeV)");           
1048                 fhGenPi0AccPt ->SetXTitle("p_{T} (GeV/c)");
1049                 fhGenPi0AccEta->SetXTitle("#eta");
1050                 fhGenPi0AccPhi->SetXTitle("#phi (rad)");
1051                 outputContainer->Add(fhGenPi0AccE);             
1052                 outputContainer->Add(fhGenPi0AccPt);
1053                 outputContainer->Add(fhGenPi0AccEta);
1054                 outputContainer->Add(fhGenPi0AccPhi);
1055                 
1056     //Track Matching 
1057                 
1058           fhMCEle1pOverE = new TH2F("hMCEle1pOverE","TRACK matches p/E, MC electrons",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1059           fhMCEle1pOverE->SetYTitle("p/E");
1060           fhMCEle1pOverE->SetXTitle("p_{T} (GeV/c)");
1061           outputContainer->Add(fhMCEle1pOverE);
1062           
1063           fhMCEle1dR = new TH1F("hMCEle1dR","TRACK matches dR, MC electrons",ndRbins,dRmin,dRmax);
1064           fhMCEle1dR->SetXTitle("#Delta R (rad)");
1065           outputContainer->Add(fhMCEle1dR) ;
1066           
1067           fhMCEle2MatchdEdx = new TH2F("hMCEle2MatchdEdx","dE/dx vs. p for all matches, MC electrons",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
1068           fhMCEle2MatchdEdx->SetXTitle("p (GeV/c)");
1069           fhMCEle2MatchdEdx->SetYTitle("<dE/dx>");
1070           outputContainer->Add(fhMCEle2MatchdEdx);
1071           
1072           fhMCChHad1pOverE = new TH2F("hMCChHad1pOverE","TRACK matches p/E, MC charged hadrons",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1073           fhMCChHad1pOverE->SetYTitle("p/E");
1074           fhMCChHad1pOverE->SetXTitle("p_{T} (GeV/c)");
1075           outputContainer->Add(fhMCChHad1pOverE);
1076           
1077           fhMCChHad1dR = new TH1F("hMCChHad1dR","TRACK matches dR, MC charged hadrons",ndRbins,dRmin,dRmax);
1078           fhMCChHad1dR->SetXTitle("#Delta R (rad)");
1079           outputContainer->Add(fhMCChHad1dR) ;
1080           
1081           fhMCChHad2MatchdEdx = new TH2F("hMCChHad2MatchdEdx","dE/dx vs. p for all matches, MC charged hadrons",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
1082           fhMCChHad2MatchdEdx->SetXTitle("p (GeV/c)");
1083           fhMCChHad2MatchdEdx->SetYTitle("<dE/dx>");
1084           outputContainer->Add(fhMCChHad2MatchdEdx);
1085           
1086           fhMCNeutral1pOverE = new TH2F("hMCNeutral1pOverE","TRACK matches p/E, MC neutrals",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1087           fhMCNeutral1pOverE->SetYTitle("p/E");
1088           fhMCNeutral1pOverE->SetXTitle("p_{T} (GeV/c)");
1089           outputContainer->Add(fhMCNeutral1pOverE);
1090           
1091           fhMCNeutral1dR = new TH1F("hMCNeutral1dR","TRACK matches dR, MC neutrals",ndRbins,dRmin,dRmax);
1092           fhMCNeutral1dR->SetXTitle("#Delta R (rad)");
1093           outputContainer->Add(fhMCNeutral1dR) ;
1094           
1095           fhMCNeutral2MatchdEdx = new TH2F("hMCNeutral2MatchdEdx","dE/dx vs. p for all matches, MC neutrals",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
1096           fhMCNeutral2MatchdEdx->SetXTitle("p (GeV/c)");
1097           fhMCNeutral2MatchdEdx->SetYTitle("<dE/dx>");
1098           outputContainer->Add(fhMCNeutral2MatchdEdx);
1099     
1100           fhMCEle1pOverER02 = new TH2F("hMCEle1pOverER02","TRACK matches p/E, MC electrons",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1101           fhMCEle1pOverER02->SetYTitle("p/E");
1102           fhMCEle1pOverER02->SetXTitle("p_{T} (GeV/c)");
1103           outputContainer->Add(fhMCEle1pOverER02);
1104           
1105           fhMCChHad1pOverER02 = new TH2F("hMCChHad1pOverER02","TRACK matches p/E, MC charged hadrons",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1106           fhMCChHad1pOverER02->SetYTitle("p/E");
1107           fhMCChHad1pOverER02->SetXTitle("p_{T} (GeV/c)");
1108           outputContainer->Add(fhMCChHad1pOverER02);
1109           
1110           fhMCNeutral1pOverER02 = new TH2F("hMCNeutral1pOverER02","TRACK matches p/E, MC neutrals",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1111           fhMCNeutral1pOverER02->SetYTitle("p/E");
1112           fhMCNeutral1pOverER02->SetXTitle("p_{T} (GeV/c)");
1113           outputContainer->Add(fhMCNeutral1pOverER02);
1114         }
1115   
1116         return outputContainer;
1117 }
1118
1119 //_______________________________________________________________________________________________________________________________________
1120 Int_t AliAnaCalorimeterQA::GetNewRebinForRePlotting(TH1D* histo, const Float_t newXmin, const Float_t newXmax,const Int_t newXnbins) const
1121 {
1122   //Calculate the rebinning for the new requested bin size, only used when replotting executing the Terminte
1123   Float_t oldbinsize =  histo->GetBinWidth(0);
1124   Float_t newbinsize = TMath::Abs(newXmax-newXmin) / newXnbins;
1125   //printf("bin size, old %f, new %f\n",oldbinsize,newbinsize);
1126   if(newbinsize > oldbinsize) return (Int_t) (newbinsize/oldbinsize);
1127   else  return 1;
1128 }
1129
1130 //__________________________________________________
1131 void AliAnaCalorimeterQA::Init()
1132
1133   //Check if the data or settings are ok
1134         if(fCalorimeter != "PHOS" && fCalorimeter !="EMCAL"){
1135                 printf("AliAnaCalorimeterQA::Init() - Wrong calorimeter name <%s>, END\n", fCalorimeter.Data());
1136                 abort();
1137         }       
1138         
1139         if(GetReader()->GetDataType()== AliCaloTrackReader::kMC){
1140                 printf("AliAnaCalorimeterQA::Init() - Analysis of reconstructed data, MC reader not aplicable\n");
1141                 abort();
1142         }       
1143         
1144 }
1145
1146
1147 //__________________________________________________
1148 void AliAnaCalorimeterQA::InitParameters()
1149
1150   //Initialize the parameters of the analysis.
1151   AddToHistogramsName("AnaCaloQA_");
1152   
1153   fCalorimeter = "EMCAL"; //or PHOS
1154   fStyleMacro  = "" ;
1155   fNModules    = 12; // set maximum to maximum number of EMCAL modules
1156   fNRCU        = 2;  // set maximum number of RCU in EMCAL per SM
1157   fTimeCutMin  = -1;
1158   fTimeCutMax  = 9999999;
1159         
1160   fHistoPOverEBins     = 100 ;  fHistoPOverEMax     = 10.  ;  fHistoPOverEMin     = 0. ;
1161   fHistodEdxBins       = 200 ;  fHistodEdxMax       = 400. ;  fHistodEdxMin       = 0. ;  
1162   fHistodRBins         = 300 ;  fHistodRMax         = 3.15 ;  fHistodRMin         = 0. ;
1163   fHistoTimeBins       = 1000;  fHistoTimeMax       = 1.e3 ;  fHistoTimeMin       = 0. ;//ns
1164   fHistoNBins          = 300 ;  fHistoNMax          = 300  ;  fHistoNMin          = 0  ;
1165   fHistoRatioBins      = 200 ;  fHistoRatioMax      = 2    ;  fHistoRatioMin      = 0. ;
1166   fHistoVertexDistBins = 100 ;  fHistoVertexDistMax = 500. ;  fHistoVertexDistMin = 0. ;
1167   fHistoRBins          = 100 ;  fHistoRMax          = 500  ;  fHistoRMin          = -500  ;//cm
1168   fHistoXBins          = 100 ;  fHistoXMax          = 500  ;  fHistoXMin          = -500  ;//cm
1169   fHistoYBins          = 100 ;  fHistoYMax          = 500  ;  fHistoYMin          = -500  ;//cm
1170   fHistoZBins          = 100 ;  fHistoZMax          = 600  ;  fHistoZMin          = -500  ;//cm
1171   fHistoSSBins         = 40  ;  fHistoSSMax         = 10  ;   fHistoSSMin         = 0  ;
1172         
1173 }
1174
1175 //__________________________________________________________________
1176 void AliAnaCalorimeterQA::Print(const Option_t * opt) const
1177 {
1178   //Print some relevant parameters set for the analysis
1179   if(! opt)
1180     return;
1181   
1182   printf("**** Print %s %s ****\n", GetName(), GetTitle() ) ;
1183   AliAnaPartCorrBaseClass::Print(" ");
1184   
1185   printf("Select Calorimeter %s \n",fCalorimeter.Data());
1186   printf("Make plots?        %d \n",fMakePlots);        
1187   printf("Plots style macro  %s \n",fStyleMacro.Data()); 
1188   printf("Time Cut: %3.1f < TOF  < %3.1f\n", fTimeCutMin, fTimeCutMax);
1189   printf("Histograms: %3.1f < p/E  < %3.1f, Nbin = %d\n", fHistoPOverEMin, fHistoPOverEMax, fHistoPOverEBins);
1190   printf("Histograms: %3.1f < dEdx < %3.1f, Nbin = %d\n", fHistodEdxMin,   fHistodEdxMax,   fHistodEdxBins);
1191   printf("Histograms: %3.1f < dR (track cluster)   < %3.1f, Nbin = %d\n", fHistodRMin,     fHistodRMax,     fHistodRBins);
1192   printf("Histograms: %3.1f < R=sqrt{x^2+y^2}    < %3.1f, Nbin = %d\n", fHistoRMin,      fHistoRMax,      fHistoRBins);
1193   printf("Histograms: %3.1f < X    < %3.1f, Nbin = %d\n", fHistoXMin,      fHistoXMax,      fHistoXBins);
1194   printf("Histograms: %3.1f < Y    < %3.1f, Nbin = %d\n", fHistoYMin,      fHistoYMax,      fHistoYBins);
1195   printf("Histograms: %3.1f < Z    < %3.1f, Nbin = %d\n", fHistoZMin,      fHistoZMax,      fHistoZBins);
1196   printf("Histograms: %g < Time < %g, Nbin = %d\n"      , fHistoTimeMin,   fHistoTimeMax,   fHistoTimeBins);
1197   printf("Histograms: %d < N    < %d, Nbin = %d\n"      , fHistoNMin,      fHistoNMax,      fHistoNBins);
1198   printf("Histograms: %3.1f < Ratio< %3.1f, Nbin = %d\n", fHistoRatioMin,  fHistoRatioMax,  fHistoRatioBins);
1199   printf("Histograms: %3.1f < Vertex Distance < %3.1f, Nbin = %d\n", fHistoVertexDistMin, fHistoVertexDistMax, fHistoVertexDistBins);
1200   
1201
1202
1203 //__________________________________________________________________
1204 void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms() 
1205 {
1206   //Fill Calorimeter QA histograms
1207         TLorentzVector mom  ;
1208         TLorentzVector mom2 ;
1209         TObjArray * caloClusters = NULL;
1210         Int_t nLabel = 0;
1211         Int_t *labels=0x0;
1212         Int_t nCaloClusters = 0;
1213         Int_t nCaloCellsPerCluster = 0;
1214         Int_t nTracksMatched = 0;
1215         Int_t trackIndex = 0;
1216         Int_t nModule = -1;
1217   
1218   //Play with the MC stack if available 
1219   //Get the MC arrays and do some checks
1220         if(IsDataMC()){
1221                 if(GetReader()->ReadStack()){
1222       
1223                         if(!GetMCStack()) {
1224                                 printf("AliAnaPhoton::MakeAnalysisFillHistograms() - Stack not available, is the MC handler called? STOP\n");
1225                                 abort();
1226                         }
1227       //Fill some pure MC histograms, only primaries.
1228                         for(Int_t i=0 ; i<GetMCStack()->GetNprimary(); i++){//Only primary particles, for all MC transport put GetNtrack()
1229                                 TParticle *primary = GetMCStack()->Particle(i) ;
1230         //printf("i %d, %s: status = %d, primary? %d\n",i, primary->GetName(), primary->GetStatusCode(), primary->IsPrimary());
1231                                 if (primary->GetStatusCode() > 11) continue; //Working for PYTHIA and simple generators, check for HERWIG 
1232                                 primary->Momentum(mom);
1233                                 MCHistograms(mom,TMath::Abs(primary->GetPdgCode()));
1234                         } //primary loop
1235                 }
1236                 else if(GetReader()->ReadAODMCParticles()){
1237       
1238                         if(!GetReader()->GetAODMCParticles(0))  {
1239                                 printf("AliAnaPhoton::MakeAnalysisFillHistograms() -  AODMCParticles not available!\n");
1240                                 abort();
1241                         }
1242       //Fill some pure MC histograms, only primaries.
1243                         for(Int_t i=0 ; i < (GetReader()->GetAODMCParticles(0))->GetEntriesFast(); i++){
1244                                 AliAODMCParticle *aodprimary = (AliAODMCParticle*) (GetReader()->GetAODMCParticles(0))->At(i) ;
1245         //printf("i %d, %s: primary? %d physical primary? %d, flag %d\n",
1246         //         i,(TDatabasePDG::Instance()->GetParticle(aodprimary->GetPdgCode()))->GetName(), 
1247         //         aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary(), aodprimary->GetFlag());
1248                                 if (!aodprimary->IsPrimary()) continue; //accept all which is not MC transport generated. Don't know how to avoid partons
1249         //aodprimary->Momentum(mom);
1250                                 mom.SetPxPyPzE(aodprimary->Px(),aodprimary->Py(),aodprimary->Pz(),aodprimary->E());
1251                                 MCHistograms(mom,TMath::Abs(aodprimary->GetPdgCode()));
1252                         } //primary loop
1253                         
1254                 }
1255         }// is data and MC      
1256         
1257         
1258   //Get List with CaloClusters  
1259   if      (fCalorimeter == "PHOS")  caloClusters = GetAODPHOS();
1260   else if (fCalorimeter == "EMCAL") caloClusters = GetAODEMCAL();
1261  else 
1262       AliFatal(Form("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Wrong calorimeter name <%s>, END\n", fCalorimeter.Data()));
1263   
1264 //  if     (fCalorimeter == "EMCAL") GetReader()->GetInputEvent()->GetEMCALClusters(caloClusters);//GetAODEMCAL();
1265 //  else if(fCalorimeter == "PHOS")  GetReader()->GetInputEvent()->GetPHOSClusters (caloClusters);//GetAODPHOS();
1266 //  else 
1267 //    AliFatal(Form("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Wrong calorimeter name <%s>, END\n", fCalorimeter.Data()));
1268         
1269         if(!caloClusters) 
1270                 AliFatal(Form("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - No CaloClusters available\n"));
1271         
1272   //----------------------------------------------------------
1273   //Correlate Calorimeters
1274   //----------------------------------------------------------
1275         //if(fCorrelateCalos)   CorrelateCalorimeters(caloClusters);
1276   if(fCorrelateCalos)   CorrelateCalorimeters();
1277
1278         
1279   //----------------------------------------------------------
1280   // CALOCLUSTERS
1281   //----------------------------------------------------------
1282         
1283         nCaloClusters = caloClusters->GetEntriesFast() ; 
1284         fhNClusters->Fill(nCaloClusters);
1285         Int_t *nClustersInModule = new Int_t[fNModules];
1286         for(Int_t imod = 0; imod < fNModules; imod++ ) nClustersInModule[imod] = 0;
1287         
1288         if(GetDebug() > 0)
1289                 printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - In %s there are %d clusters \n", fCalorimeter.Data(), nCaloClusters);
1290         
1291   //Get vertex for photon momentum calculation
1292         Double_t v[3] = {0,0,0}; //vertex ;
1293         GetReader()->GetVertex(v);
1294         AliVTrack * track = 0x0;
1295         
1296         Float_t pos[3] ;
1297         Float_t showerShape[3] ;
1298         Double_t tof = 0;
1299   //Loop over CaloClusters
1300   //if(nCaloClusters > 0)printf("QA  : Vertex Cut passed %f, cut %f, entries %d, %s\n",v[2], 40., nCaloClusters, fCalorimeter.Data());
1301         for(Int_t iclus = 0; iclus < nCaloClusters; iclus++){
1302                 
1303                 if(GetDebug() > 0) printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - cluster: %d/%d, data %d \n",
1304                               iclus+1,nCaloClusters,GetReader()->GetDataType());
1305                 
1306                 if(GetReader()->GetDataType()==AliCaloTrackReader::kESD){
1307                         AliVCluster* clus =  (AliVCluster*)caloClusters->At(iclus);
1308                         AliVCaloCells * cell = 0x0; 
1309                         if(fCalorimeter == "PHOS") cell =  GetPHOSCells();
1310                         else                                     cell =  GetEMCALCells();
1311                                                 
1312       //Get cluster kinematics
1313                         clus->GetPosition(pos);
1314                         clus->GetMomentum(mom,v);
1315                         tof = clus->GetTOF()*1e9;
1316                         if(tof < fTimeCutMin || tof > fTimeCutMax) continue;
1317                         
1318       //Check only certain regions
1319                         Bool_t in = kTRUE;
1320                         if(IsFiducialCutOn()) in =  GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
1321                         if(!in) continue;
1322       //Get module of cluster
1323                         nModule = GetModuleNumber(clus);
1324                         if(nModule < fNModules) nClustersInModule[nModule]++;
1325       //MC labels
1326                         nLabel = clus->GetNLabels();
1327                         labels = clus->GetLabels();
1328       //Cells per cluster
1329                         nCaloCellsPerCluster =  clus->GetNCells();
1330       //if(mom.E() > 10 && nCaloCellsPerCluster == 1 ) printf("%s:************** E = %f ********** ncells = %d\n",fCalorimeter.Data(), mom.E(),nCaloCellsPerCluster);
1331       //matched cluster with tracks
1332                         nTracksMatched = clus->GetNTracksMatched();
1333                         trackIndex     = clus->GetTrackMatchedIndex();
1334                         if(trackIndex >= 0){
1335                                 track = (AliVTrack*)GetReader()->GetInputEvent()->GetTrack(trackIndex);
1336                         }
1337                         else{
1338                                 if(nTracksMatched == 1) nTracksMatched = 0;
1339                                 track = 0;
1340                         }
1341                         
1342       //Shower shape parameters
1343                         showerShape[0] = clus->GetM20();
1344                         showerShape[1] = clus->GetM02();
1345                         showerShape[2] = clus->GetDispersion();
1346       
1347       //======================
1348       //Cells in cluster
1349       //======================
1350       
1351       //Get list of contributors
1352                         UShort_t * indexList = clus->GetCellsAbsId() ;
1353       // check time of cells respect to max energy cell
1354       //Get maximum energy cell
1355                         Float_t emax  = -1;
1356                         Double_t tmax = -1;
1357                         Int_t imax    = -1;
1358                         Int_t absId   = -1 ;
1359       //printf("nCaloCellsPerCluster %d\n",nCaloCellsPerCluster);
1360       //Loop on cluster cells
1361                         for (Int_t ipos = 0; ipos < nCaloCellsPerCluster; ipos++) {
1362         //      printf("Index %d\n",ipos);
1363                           absId  = indexList[ipos]; 
1364                           
1365         //Get position of cell compare to cluster
1366         if(fFillAllPosHisto){
1367           if(fCalorimeter=="EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
1368             
1369             Double_t cellpos[] = {0, 0, 0};
1370             GetEMCALGeometry()->GetGlobal(absId, cellpos);
1371             
1372             fhDeltaCellClusterXNCells->Fill(pos[0]-cellpos[0],nCaloCellsPerCluster) ; 
1373             fhDeltaCellClusterYNCells->Fill(pos[1]-cellpos[1],nCaloCellsPerCluster) ; 
1374             fhDeltaCellClusterZNCells->Fill(pos[2]-cellpos[2],nCaloCellsPerCluster) ;
1375             
1376             fhDeltaCellClusterXE->Fill(pos[0]-cellpos[0],mom.E())  ; 
1377             fhDeltaCellClusterYE->Fill(pos[1]-cellpos[1],mom.E())  ; 
1378             fhDeltaCellClusterZE->Fill(pos[2]-cellpos[2],mom.E())  ; 
1379             
1380             Float_t r     = TMath::Sqrt(pos[0]*pos[0]        +pos[1]*pos[1]);//     +pos[2]*pos[2]);
1381             Float_t rcell = TMath::Sqrt(cellpos[0]*cellpos[0]+cellpos[1]*cellpos[1]);//+cellpos[2]*cellpos[2]);
1382             fhDeltaCellClusterRNCells->Fill(r-rcell, nCaloCellsPerCluster) ; 
1383             fhDeltaCellClusterRE     ->Fill(r-rcell, mom.E())  ; 
1384             
1385             //                                  Float_t celleta = 0, cellphi = 0;
1386             //                                  GetEMCALGeometry()->EtaPhiFromIndex(absId, celleta, cellphi); 
1387             //                                  Int_t imod = -1, iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1;
1388             //                                  GetEMCALGeometry()->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
1389             //                                  GetEMCALGeometry()->GetCellPhiEtaIndexInSModule(imod,iTower,
1390             //                                                                                                                                                           iIphi, iIeta,iphi,ieta);
1391             //                                  printf("AbsId %d, SM %d, Index eta %d, phi %d\n", absId, imod, ieta, iphi);
1392             //                                  printf("Cluster E %f, eta %f, phi %f; Cell: Amp %f, eta %f, phi%f\n", mom.E(),mom.Eta(), mom.Phi()*TMath::RadToDeg(), cell->GetCellAmplitude(absId),celleta, cellphi*TMath::RadToDeg());
1393             //                                  printf("x cluster %f, x cell %f, cluster-cell %f\n",pos[0], cellpos[0],pos[0]-cellpos[0]);
1394             //                                  printf("y cluster %f, y cell %f, cluster-cell %f\n",pos[1], cellpos[1],pos[1]-cellpos[1]);
1395             //                                  printf("z cluster %f, z cell %f, cluster-cell %f\n",pos[2], cellpos[2],pos[2]-cellpos[2]);
1396             //                                  printf("r cluster %f, r cell %f, cluster-cell %f\n",r,      rcell,     r-rcell);
1397             //                                  
1398             
1399           }//EMCAL and its matrices are available
1400           else if(fCalorimeter=="PHOS" && GetCaloUtils()->IsPHOSGeoMatrixSet()){
1401             TVector3 xyz;
1402             Int_t relId[4], module;
1403             Float_t xCell, zCell;
1404             
1405             GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
1406             module = relId[0];
1407             GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
1408             GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
1409             
1410             fhDeltaCellClusterXNCells->Fill(pos[0]-xyz.X(),nCaloCellsPerCluster) ; 
1411             fhDeltaCellClusterYNCells->Fill(pos[1]-xyz.Y(),nCaloCellsPerCluster) ; 
1412             fhDeltaCellClusterZNCells->Fill(pos[2]-xyz.Z(),nCaloCellsPerCluster) ;
1413             
1414             fhDeltaCellClusterXE->Fill(pos[0]-xyz.X(),mom.E())  ; 
1415             fhDeltaCellClusterYE->Fill(pos[1]-xyz.Y(),mom.E())  ; 
1416             fhDeltaCellClusterZE->Fill(pos[2]-xyz.Z(),mom.E())  ; 
1417             
1418             Float_t r     = TMath::Sqrt(pos[0]*pos[0]  +pos[1]*pos[1]);//     +pos[2]*pos[2]);
1419             Float_t rcell = TMath::Sqrt(xyz.X()*xyz.X()+xyz.Y()*xyz.Y());//+xyz.Z()*xyz.Z());
1420             fhDeltaCellClusterRNCells->Fill(r-rcell, nCaloCellsPerCluster) ; 
1421             fhDeltaCellClusterRE     ->Fill(r-rcell, mom.E())  ; 
1422             
1423             //                    printf("x cluster %f, x cell %f, cluster-cell %f\n",pos[0], cellpos[0],pos[0]-cellpos[0]);
1424             //                  printf("y cluster %f, y cell %f, cluster-cell %f\n",pos[1], cellpos[1],pos[1]-cellpos[1]);
1425             //                  printf("z cluster %f, z cell %f, cluster-cell %f\n",pos[2], cellpos[2],pos[2]-cellpos[2]);
1426             //                                  printf("r cluster %f, r cell %f, cluster-cell %f\n",r,      rcell,     r-rcell);
1427           }//PHOS and its matrices are available
1428         }//Fill all position histograms
1429         
1430         //Find maximum energy cluster
1431                           if(cell->GetCellAmplitude(absId) > emax) {
1432                             imax = ipos;
1433                             emax = cell->GetCellAmplitude(absId);
1434                             tmax = cell->GetCellTime(absId);
1435                           } 
1436         
1437                         }// cluster cell loop
1438                         
1439       // check time of cells respect to max energy cell
1440                         if(nCaloCellsPerCluster > 1){
1441                           for (Int_t ipos = 0; ipos < nCaloCellsPerCluster; ipos++) {
1442                             if(imax == ipos) continue;
1443                             absId  = indexList[ipos]; 
1444                             Float_t diff = (tmax-cell->GetCellTime(absId))*1e9;
1445                             fhCellTimeSpreadRespectToCellMax->Fill(diff);
1446                             if(TMath::Abs(TMath::Abs(diff) > 100)) fhCellIdCellLargeTimeSpread->Fill(absId);
1447                           }// fill cell-cluster histogram loop
1448                           
1449                         }//check time of cells respect to max energy cell
1450       
1451       //-----------------------------------------------------------
1452       //Fill histograms related to single cluster or track matching
1453       //-----------------------------------------------------------
1454       
1455       ClusterHistograms(mom, tof, pos, showerShape, nCaloCellsPerCluster, nModule, nTracksMatched, track, labels, nLabel);      
1456       
1457       
1458       //-----------------------------------------------------------
1459       //Invariant mass
1460       //-----------------------------------------------------------
1461       if(GetDebug()>1) printf("Invariant mass \n");
1462       
1463       //do not do for bad vertex
1464       Float_t fZvtxCut = 40. ;  
1465       if(v[2]<-fZvtxCut || v[2]> fZvtxCut) continue ; //Event can not be used (vertex, centrality,... cuts not fulfilled)
1466       
1467       Int_t nModule2 = -1;
1468       Int_t nCaloCellsPerCluster2=0;
1469       if (nCaloClusters > 1 ) {
1470         for(Int_t jclus = iclus + 1 ; jclus < nCaloClusters ; jclus++) {
1471                                         AliVCluster* clus2 =  (AliVCluster*)caloClusters->At(jclus);
1472                                         AliVCaloCells  * cell2 = 0x0; 
1473                                         if(fCalorimeter == "PHOS") cell2 =  GetPHOSCells();
1474                                         else                                     cell2 =  GetEMCALCells();
1475           
1476           //Get cluster kinematics
1477                                         clus2->GetMomentum(mom2,v);
1478           //Check only certain regions
1479                                         Bool_t in2 = kTRUE;
1480                                         if(IsFiducialCutOn()) in2 =  GetFiducialCut()->IsInFiducialCut(mom2,fCalorimeter) ;
1481                                         if(!in2) continue;      
1482           //Get module of cluster
1483                                         nModule2 = GetModuleNumber(clus2);
1484           //Cells per cluster
1485                                         nCaloCellsPerCluster2 = clus2->GetNCells();
1486         }
1487         //Fill invariant mass histograms
1488         //All modules
1489         
1490         //printf("QA : Fill inv mass histo: pt1 %f, pt2 %f, pt12 %f, mass %f, calo %s \n",mom.Pt(),mom2.Pt(),(mom+mom2).Pt(),(mom+mom2).M(), fCalorimeter.Data());
1491                                 fhIM  ->Fill((mom+mom2).Pt(),(mom+mom2).M());
1492         //Single module
1493                                 if(nModule == nModule2 && nModule >=0 && nModule < fNModules)
1494                                   fhIMMod[nModule]->Fill((mom+mom2).Pt(),(mom+mom2).M());
1495         
1496         //Select only clusters with at least 2 cells
1497                                 if(nCaloCellsPerCluster > 1 && nCaloCellsPerCluster2 > 1) {
1498           //All modules
1499                                   fhIMCellCut  ->Fill((mom+mom2).Pt(),(mom+mom2).M());
1500           //Single modules
1501                                   if(nModule == nModule2 && nModule >=0 && nModule < fNModules)
1502                                     fhIMCellCutMod[nModule]->Fill((mom+mom2).Pt(),(mom+mom2).M());
1503                                 }
1504         
1505         //Asymetry histograms
1506         fhAsym->Fill((mom+mom2).Pt(),TMath::Abs((mom.E()-mom2.E())/(mom.E()+mom2.E())));
1507         
1508                         }// 2nd cluster loop
1509                 }////more than 1 cluster in calorimeter         
1510         }//cluster loop
1511         
1512   //Number of clusters per module
1513         for(Int_t imod = 0; imod < fNModules; imod++ ){ 
1514                 if(GetDebug() > 1) 
1515                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - module %d calo %s clusters %d\n", imod, fCalorimeter.Data(), nClustersInModule[imod]); 
1516                 fhNClustersMod[imod]->Fill(nClustersInModule[imod]);
1517         }
1518         delete [] nClustersInModule;
1519         //delete caloClusters;
1520   
1521   //----------------------------------------------------------
1522   // CALOCELLS
1523   //----------------------------------------------------------
1524         
1525         Int_t *nCellsInModule = new Int_t[fNModules];
1526         for(Int_t imod = 0; imod < fNModules; imod++ ) nCellsInModule[imod] = 0;
1527         Int_t icol     = -1;
1528         Int_t irow     = -1;
1529         Int_t iRCU     = -1;
1530         Float_t amp    = 0.;
1531         Float_t time   = 0.;
1532         Int_t id       = -1;
1533         Float_t recalF = 1.;
1534         
1535   AliVCaloCells * cell = 0x0; 
1536   Int_t ncells = 0;
1537   if(fCalorimeter == "PHOS") 
1538     cell = GetPHOSCells();
1539   else                        
1540     cell = GetEMCALCells();
1541   
1542   if(!cell) {
1543     printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - STOP: No %s ESD CELLS available for analysis\n",fCalorimeter.Data());
1544     abort();
1545   }
1546   
1547   ncells = cell->GetNumberOfCells() ;
1548   fhNCells->Fill(ncells) ;
1549   if(GetDebug() > 0) 
1550     printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - In ESD %s cell entries %d\n", fCalorimeter.Data(), ncells);    
1551   
1552   for (Int_t iCell = 0; iCell < ncells; iCell++) {      
1553     if(GetDebug() > 2)  printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Cell : amp %f, absId %d \n", cell->GetAmplitude(iCell), cell->GetCellNumber(iCell));
1554     nModule = GetModuleNumberCellIndexes(cell->GetCellNumber(iCell),fCalorimeter, icol, irow, iRCU);
1555     if(GetDebug() > 2) printf("\t module %d, column %d, row %d \n", nModule,icol,irow);
1556     
1557     if(nModule < fNModules) {   
1558       //Check if the cell is a bad channel
1559       if(GetCaloUtils()->IsBadChannelsRemovalSwitchedOn()){
1560         if(fCalorimeter=="EMCAL"){
1561           if(GetCaloUtils()->GetEMCALChannelStatus(nModule,icol,irow)) continue;
1562         }
1563         else {
1564           if(GetCaloUtils()->GetPHOSChannelStatus(nModule,icol,irow)) {
1565             printf("PHOS bad channel\n");
1566             continue;
1567           }
1568         }
1569       }
1570       
1571       //Get Recalibration factor if set
1572       if (GetCaloUtils()->IsRecalibrationOn()) {
1573         if(fCalorimeter == "PHOS") recalF = GetCaloUtils()->GetPHOSChannelRecalibrationFactor(nModule,icol,irow);
1574         else                               recalF = GetCaloUtils()->GetEMCALChannelRecalibrationFactor(nModule,icol,irow);
1575         if(fCalorimeter == "PHOS")printf("Recalibration factor (sm,row,col)=(%d,%d,%d) -  %f\n",nModule,icol,irow,recalF);
1576       }
1577       
1578       amp     = cell->GetAmplitude(iCell)*recalF;
1579       time    = cell->GetTime(iCell)*1e9;//transform time to ns
1580       
1581       //if(amp > 3 && fCalorimeter=="EMCAL") printf("Amp = %f, time = %f, (mod, col, row)= (%d,%d,%d)\n",
1582       //                                                                                   amp,time,nModule,icol,irow);
1583       
1584       if(time < fTimeCutMin || time > fTimeCutMax) continue;
1585       
1586       //printf("%s: time %g\n",fCalorimeter.Data(), time);
1587       id      = cell->GetCellNumber(iCell);
1588       fhAmplitude->Fill(amp);
1589       fhAmpId    ->Fill(amp,id);
1590       fhTime     ->Fill(time);
1591       fhTimeId   ->Fill(time,id);
1592       fhTimeAmp  ->Fill(amp,time);
1593       //Double_t t0 = GetReader()->GetInputEvent()->GetT0();
1594       //printf("---->>> Time EMCal %e, T0 %e, T0 vertex %e, T0 clock %e, T0 trig %d \n",time,t0, 
1595       //           GetReader()->GetInputEvent()->GetT0zVertex(),
1596       //           GetReader()->GetInputEvent()->GetT0clock(),
1597       //           GetReader()->GetInputEvent()->GetT0Trig());
1598       //fhT0Time     ->Fill(time-t0);
1599       //fhT0TimeId   ->Fill(time-t0,id);
1600       //fhT0TimeAmp  ->Fill(amp,time-t0);
1601       
1602       fhAmplitudeMod[nModule]->Fill(amp);
1603       if(fCalorimeter=="EMCAL"){
1604         Int_t ifrac = 0;
1605         if(icol > 15 && icol < 32) ifrac = 1;
1606         else if(icol > 31) ifrac = 2;
1607         fhAmplitudeModFraction[nModule*3+ifrac]->Fill(amp);
1608         
1609         
1610       }
1611       
1612       fhTimeAmpPerRCU  [nModule*fNRCU+iRCU]->Fill(amp, time);
1613       //printf("id %d, nModule %d, iRCU %d: Histo Name %s\n",id, nModule,iRCU, fhTimeAmpPerRCU[nModule*fNRCU+iRCU]->GetName());
1614       //fhT0TimeAmpPerRCU[nModule*fNRCU+iRCU]->Fill(amp, time-t0);
1615       nCellsInModule[nModule]++;
1616       fhGridCellsMod[nModule]    ->Fill(icol,irow);
1617       fhGridCellsEMod[nModule]   ->Fill(icol,irow,amp);
1618       if(amp > 0.3){
1619         fhGridCellsTimeMod[nModule]->Fill(icol,irow,time);
1620         
1621         //                                      AliESDCaloCells * cell2 = 0x0; 
1622         //                                      if(fCalorimeter == "PHOS") cell2 =  GetReader()->GetInputEvent()->GetPHOSCells();
1623         //                                      else                       cell2 = GetReader()->GetInputEvent()->GetEMCALCells();
1624         //                                      Int_t icol2    = -1;
1625         //                                      Int_t irow2    = -1;
1626         //                                      Int_t iRCU2    = -1;
1627         //                                      Float_t amp2   =  0.;
1628         //                                      Float_t time2  =  0.;
1629         //                                      Int_t id2      = -1;
1630         //                                      Int_t nModule2 = -1;
1631         //                                      for (Int_t iCell2 = 0; iCell2 < ncells; iCell2++) {  
1632         //                                              amp2    = cell2->GetAmplitude(iCell2);
1633         //                                              if(amp2 < 0.3) continue;
1634         //                                              if(iCell2 == iCell) continue;
1635         //                                              time2    = cell2->GetTime(iCell2)*1e9;//transform time to ns
1636         //                                              //printf("%s: time %g\n",fCalorimeter.Data(), time);
1637         //                                              id2      = cell2->GetCellNumber(iCell2);
1638         //                                              nModule2 = GetModuleNumberCellIndexes(cell2->GetCellNumber(iCell2), fCalorimeter, icol2, irow2, iRCU2);
1639         //                                              Int_t index = (nModule2*fNRCU+iRCU2)+(fNModules*fNRCU)*(iRCU+fNRCU*nModule); 
1640         //                                              //printf("id %d, nModule %d, iRCU %d, id2 %d, nModule2 %d, iRCU2 %d, index %d: Histo Name %s\n",id, nModule,iRCU,cell2->GetCellNumber(iCell2),nModule2,iRCU2,index, fhTimeCorrRCU[index]->GetName());
1641         //                                              fhTimeCorrRCU[index]->Fill(time,time2); 
1642         //                                              
1643         //                                      }// second cell loop
1644       }// amplitude cut
1645     }//nmodules
1646     
1647     //Get Eta-Phi position of Cell
1648     //if(fFillAllPosHisto)
1649     {
1650       if(fCalorimeter=="EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
1651         Float_t celleta = 0.;
1652         Float_t cellphi = 0.;
1653         GetEMCALGeometry()->EtaPhiFromIndex(id, celleta, cellphi); 
1654         fhEtaPhiAmp->Fill(celleta,cellphi,amp);
1655         Double_t cellpos[] = {0, 0, 0};
1656         GetEMCALGeometry()->GetGlobal(id, cellpos);
1657         fhXCellE->Fill(cellpos[0],amp)  ; 
1658         fhYCellE->Fill(cellpos[1],amp)  ; 
1659         fhZCellE->Fill(cellpos[2],amp)  ;
1660         Float_t rcell = TMath::Sqrt(cellpos[0]*cellpos[0]+cellpos[1]*cellpos[1]);//+cellpos[2]*cellpos[2]);
1661         fhRCellE->Fill(rcell,amp)  ;
1662         fhXYZCell->Fill(cellpos[0],cellpos[1],cellpos[2])  ;
1663       }//EMCAL Cells
1664       else if(fCalorimeter=="PHOS" && GetCaloUtils()->IsPHOSGeoMatrixSet()){
1665         TVector3 xyz;
1666         Int_t relId[4], module;
1667         Float_t xCell, zCell;
1668         
1669         GetPHOSGeometry()->AbsToRelNumbering(id,relId);
1670         module = relId[0];
1671         GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
1672         GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
1673         Float_t rcell = TMath::Sqrt(xyz.X()*xyz.X()+xyz.Y()*xyz.Y());
1674         fhXCellE ->Fill(xyz.X(),amp)  ; 
1675         fhYCellE ->Fill(xyz.Y(),amp)  ; 
1676         fhZCellE ->Fill(xyz.Z(),amp)  ;
1677         fhRCellE ->Fill(rcell  ,amp)  ;
1678         fhXYZCell->Fill(xyz.X(),xyz.Y(),xyz.Z())  ;
1679       }//PHOS cells
1680     }//fill cell position histograms
1681   }//cell loop
1682   
1683   //Number of cells per module
1684         for(Int_t imod = 0; imod < fNModules; imod++ ) {
1685                 if(GetDebug() > 1) 
1686                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - module %d calo %s cells %d\n", imod, fCalorimeter.Data(), nCellsInModule[imod]); 
1687                 fhNCellsMod[imod]->Fill(nCellsInModule[imod]) ;
1688         }
1689         delete [] nCellsInModule;
1690         
1691         if(GetDebug() > 0)
1692                 printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - End \n");
1693 }
1694
1695
1696 //_____________________________________________________________________________________________
1697 void AliAnaCalorimeterQA::ClusterHistograms(const TLorentzVector mom, const Double_t tof, 
1698                                             Float_t *pos, Float_t *showerShape,
1699                                             const Int_t nCaloCellsPerCluster,const Int_t nModule,
1700                                             const Int_t nTracksMatched,  const AliVTrack * track,  
1701                                             const Int_t * labels, const Int_t nLabels){
1702   //Fill CaloCluster related histograms
1703         
1704         AliAODMCParticle * aodprimary  = 0x0;
1705         TParticle * primary = 0x0;
1706   Int_t tag = 0;        
1707         
1708         Float_t e   = mom.E();
1709         Float_t pt  = mom.Pt();
1710         Float_t eta = mom.Eta();
1711         Float_t phi = mom.Phi();
1712         if(phi < 0) phi +=TMath::TwoPi();
1713         if(GetDebug() > 0) {
1714                 printf("AliAnaCalorimeterQA::ClusterHistograms() - cluster: E %2.3f, pT %2.3f, eta %2.3f, phi %2.3f \n",e,pt,eta,phi*TMath::RadToDeg());
1715                 if(IsDataMC()) {
1716       //printf("\t Primaries: nlabels %d, labels pointer %p\n",nLabels,labels);
1717                         printf("\t Primaries: nlabels %d\n",nLabels);
1718                         if(!nLabels || !labels) printf("\t Strange, no labels!!!\n");
1719                 }
1720         }
1721   
1722         fhE     ->Fill(e);      
1723         if(nModule < fNModules) fhEMod[nModule]->Fill(e);
1724   if(fFillAllTH12){
1725     fhPt     ->Fill(pt);
1726     fhPhi    ->Fill(phi);
1727     fhEta    ->Fill(eta);
1728   }
1729         fhEtaPhiE->Fill(eta,phi,e);
1730   
1731   //Cells per cluster
1732         fhNCellsPerCluster   ->Fill(e, nCaloCellsPerCluster,eta);
1733         fhNCellsPerClusterMIP->Fill(e, nCaloCellsPerCluster,eta);
1734   
1735   //Position
1736   //if(fFillAllPosHisto)
1737   {
1738     fhXE     ->Fill(pos[0],e);
1739     fhYE     ->Fill(pos[1],e);
1740     fhZE     ->Fill(pos[2],e);
1741     fhXYZ    ->Fill(pos[0], pos[1],pos[2]);
1742    
1743     fhXNCells->Fill(pos[0],nCaloCellsPerCluster);
1744     fhYNCells->Fill(pos[1],nCaloCellsPerCluster);
1745     fhZNCells->Fill(pos[2],nCaloCellsPerCluster);
1746     Float_t rxyz = TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]);//+pos[2]*pos[2]);
1747     fhRE     ->Fill(rxyz,e);
1748     fhRNCells->Fill(rxyz  ,nCaloCellsPerCluster);
1749   }
1750   
1751         fhClusterTimeEnergy->Fill(e,tof);
1752         
1753   //Shower shape parameters
1754         fhLambda->Fill(showerShape[0], showerShape[1], e);
1755         fhDispersion->Fill(showerShape[2],e);
1756   
1757         if(nModule < fNModules) fhNCellsPerClusterMod[nModule]->Fill(e, nCaloCellsPerCluster);
1758         
1759   //Fill histograms only possible when simulation
1760         if(IsDataMC() && nLabels > 0 && labels){
1761     
1762     //Play with the MC stack if available
1763                 Int_t label = labels[0];
1764     
1765                 if(label < 0) {
1766                         if(GetDebug() >= 0) printf("AliAnaCalorimeterQA::ClusterHistograms() *** bad label ***:  label %d \n", label);
1767                         return;
1768                 }
1769     
1770                 Int_t pdg  =-1; Int_t pdg0  =-1;Int_t status = -1; Int_t iMother = -1; Int_t iParent = -1;
1771                 Float_t vxMC= 0; Float_t vyMC = 0;      
1772                 Float_t eMC = 0; Float_t ptMC= 0; Float_t phiMC =0; Float_t etaMC = 0;
1773                 Int_t charge = 0;       
1774                 
1775     //Check the origin.
1776                 tag = GetMCAnalysisUtils()->CheckOrigin(labels,nLabels, GetReader(),0);
1777     
1778                 if(GetReader()->ReadStack() && !GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCUnknown)){ //it MC stack and known tag
1779       
1780                         if( label >= GetMCStack()->GetNtrack()) {
1781                                 if(GetDebug() >= 0) printf("AliAnaCalorimeterQA::ClusterHistograms() *** large label ***:  label %d, n tracks %d \n", label, GetMCStack()->GetNtrack());
1782                                 return ;
1783                         }
1784                         
1785                         primary = GetMCStack()->Particle(label);
1786                         iMother = label;
1787                         pdg0    = TMath::Abs(primary->GetPdgCode());
1788                         pdg     = pdg0;
1789                         status  = primary->GetStatusCode();
1790                         vxMC    = primary->Vx();
1791                         vyMC    = primary->Vy();
1792                         iParent = primary->GetFirstMother();
1793       
1794                         if(GetDebug() > 1 ) {
1795                                 printf("AliAnaCalorimeterQA::ClusterHistograms() - Cluster most contributing mother: \n");
1796                                 printf("\t Mother label %d, pdg %d, %s, status %d, parent %d \n",iMother, pdg0, primary->GetName(),status, iParent);
1797                         }
1798       
1799       //Get final particle, no conversion products
1800                         if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCConversion)){
1801         //Get the parent
1802                                 primary = GetMCStack()->Particle(iParent);
1803                                 pdg = TMath::Abs(primary->GetPdgCode());
1804                                 if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted cluster!. Find before conversion: \n");
1805                                 while((pdg == 22 || pdg == 11) && status != 1){
1806                                         iMother = iParent;
1807                                         primary = GetMCStack()->Particle(iMother);
1808                                         status  = primary->GetStatusCode();
1809                                         iParent = primary->GetFirstMother();
1810                                         pdg     = TMath::Abs(primary->GetPdgCode());
1811                                         if(GetDebug() > 1 )printf("\t pdg %d, index %d, %s, status %d \n",pdg, iMother,  primary->GetName(),status);    
1812                                 }       
1813         
1814                                 if(GetDebug() > 1 ) {
1815                                         printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted Cluster mother before conversion: \n");
1816                                         printf("\t Mother label %d, pdg %d, %s, status %d, parent %d \n",iMother, pdg, primary->GetName(), status, iParent);
1817                                 }
1818         
1819                         }
1820       
1821       //Overlapped pi0 (or eta, there will be very few), get the meson
1822                         if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1823          GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1824                                 if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped Meson decay!, Find it: \n");
1825                                 while(pdg != 111 && pdg != 221){
1826                                         iMother = iParent;
1827                                         primary = GetMCStack()->Particle(iMother);
1828                                         status  = primary->GetStatusCode();
1829                                         iParent = primary->GetFirstMother();
1830                                         pdg     = TMath::Abs(primary->GetPdgCode());
1831                                         if(GetDebug() > 1 ) printf("\t pdg %d, %s, index %d\n",pdg,  primary->GetName(),iMother);
1832                                         if(iMother==-1) {
1833                                                 printf("AliAnaCalorimeterQA::ClusterHistograms() - Tagged as Overlapped photon but meson not found, why?\n");
1834             //break;
1835                                         }
1836                                 }
1837         
1838                                 if(GetDebug() > 2 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped %s decay, label %d \n", 
1839                                    primary->GetName(),iMother);
1840                         }
1841       
1842                         eMC    = primary->Energy();
1843                         ptMC   = primary->Pt();
1844                         phiMC  = primary->Phi();
1845                         etaMC  = primary->Eta();
1846                         pdg    = TMath::Abs(primary->GetPdgCode());
1847                         charge = (Int_t) TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
1848       
1849                 }
1850                 else if(GetReader()->ReadAODMCParticles() && !GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCUnknown)){//it MC AOD and known tag
1851       //Get the list of MC particles
1852                         if(!GetReader()->GetAODMCParticles(0))  {
1853                                 printf("AliAnaCalorimeterQA::ClusterHistograms() -  MCParticles not available!\n");
1854                                 abort();
1855                         }               
1856                         
1857                         aodprimary = (AliAODMCParticle*) (GetReader()->GetAODMCParticles(0))->At(label);
1858                         iMother = label;
1859                         pdg0    = TMath::Abs(aodprimary->GetPdgCode());
1860                         pdg     = pdg0;
1861                         status  = aodprimary->IsPrimary();
1862                         vxMC    = aodprimary->Xv();
1863                         vyMC    = aodprimary->Yv();
1864                         iParent = aodprimary->GetMother();
1865       
1866                         if(GetDebug() > 1 ) {
1867                                 printf("AliAnaCalorimeterQA::ClusterHistograms() - Cluster most contributing mother: \n");
1868                                 printf("\t Mother label %d, pdg %d, Primary? %d, Physical Primary? %d, parent %d \n",
1869                iMother, pdg0, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary(), iParent);
1870                         }
1871                         
1872       //Get final particle, no conversion products
1873                         if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCConversion)){
1874                                 if(GetDebug() > 1 ) 
1875                                         printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted cluster!. Find before conversion: \n");
1876         //Get the parent
1877                                 aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iParent);
1878                                 pdg = TMath::Abs(aodprimary->GetPdgCode());
1879                                 while ((pdg == 22 || pdg == 11) && !aodprimary->IsPhysicalPrimary()) {
1880                                         iMother    = iParent;
1881                                         aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iMother);
1882                                         status     = aodprimary->IsPrimary();
1883                                         iParent    = aodprimary->GetMother();
1884                                         pdg        = TMath::Abs(aodprimary->GetPdgCode());
1885                                         if(GetDebug() > 1 )
1886                                                 printf("\t pdg %d, index %d, Primary? %d, Physical Primary? %d \n",
1887                    pdg, iMother, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary());     
1888                                 }       
1889                                 
1890                                 if(GetDebug() > 1 ) {
1891                                         printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted Cluster mother before conversion: \n");
1892                                         printf("\t Mother label %d, pdg %d, parent %d, Primary? %d, Physical Primary? %d \n",
1893                  iMother, pdg, iParent, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary());
1894                                 }
1895                                 
1896                         }
1897       
1898       //Overlapped pi0 (or eta, there will be very few), get the meson
1899                         if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1900          GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1901                                 if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped Meson decay!, Find it: PDG %d, mom %d \n",pdg, iMother);
1902                                 while(pdg != 111 && pdg != 221){
1903                                         
1904                                         iMother    = iParent;
1905                                         aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iMother);
1906                                         status     = aodprimary->IsPrimary();
1907                                         iParent    = aodprimary->GetMother();
1908                                         pdg        = TMath::Abs(aodprimary->GetPdgCode());
1909           
1910                                         if(GetDebug() > 1 ) printf("\t pdg %d, index %d\n",pdg, iMother);
1911                                         
1912                                         if(iMother==-1) {
1913                                                 printf("AliAnaCalorimeterQA::ClusterHistograms() - Tagged as Overlapped photon but meson not found, why?\n");
1914             //break;
1915                                         }
1916                                 }       
1917                                 
1918                                 if(GetDebug() > 2 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped %s decay, label %d \n", 
1919                                    aodprimary->GetName(),iMother);
1920                         }       
1921       
1922                         status = aodprimary->IsPrimary();
1923                         eMC    = aodprimary->E();
1924                         ptMC   = aodprimary->Pt();
1925                         phiMC  = aodprimary->Phi();
1926                         etaMC  = aodprimary->Eta();
1927                         pdg    = TMath::Abs(aodprimary->GetPdgCode());
1928                         charge = aodprimary->Charge();
1929       
1930                 }
1931     
1932     //Float_t vz = primary->Vz();
1933                 Float_t rVMC = TMath::Sqrt(vxMC*vxMC + vyMC*vyMC);
1934                 if((pdg == 22 || TMath::Abs(pdg)==11) && status!=1) {
1935                         fhEMVxyz   ->Fill(vxMC,vyMC);//,vz);
1936                         fhEMR      ->Fill(e,rVMC);
1937                 }
1938     
1939     //printf("reco e %f, pt %f, phi %f, eta %f \n", e, pt, phi, eta);
1940     //printf("prim e %f, pt %f, phi %f, eta %f \n", eMC,ptMC,phiMC ,etaMC );
1941     //printf("vertex: vx %f, vy %f, vz %f, r %f \n", vxMC, vyMC, vz, r);
1942     
1943     
1944                 fh2E      ->Fill(e, eMC);
1945                 fh2Pt     ->Fill(pt, ptMC);
1946                 fh2Phi    ->Fill(phi, phiMC);
1947                 fh2Eta    ->Fill(eta, etaMC);
1948                 fhDeltaE  ->Fill(eMC-e);
1949                 fhDeltaPt ->Fill(ptMC-pt);
1950                 fhDeltaPhi->Fill(phiMC-phi);
1951                 fhDeltaEta->Fill(etaMC-eta);
1952                 if(eMC   > 0) fhRatioE  ->Fill(e/eMC);
1953                 if(ptMC  > 0) fhRatioPt ->Fill(pt/ptMC);
1954                 if(phiMC > 0) fhRatioPhi->Fill(phi/phiMC);
1955                 if(etaMC > 0) fhRatioEta->Fill(eta/etaMC);                      
1956     
1957     
1958     //Overlapped pi0 (or eta, there will be very few)
1959                 if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1960        GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1961       fhPi0E     ->Fill(e,eMC); 
1962       fhPi0Pt    ->Fill(pt,ptMC);
1963       fhPi0Eta   ->Fill(eta,etaMC);     
1964       fhPi0Phi   ->Fill(phi,phiMC);
1965       if( nTracksMatched > 0){
1966         fhPi0ECharged     ->Fill(e,eMC);                
1967         fhPi0PtCharged    ->Fill(pt,ptMC);
1968         fhPi0PhiCharged   ->Fill(phi,phiMC);
1969         fhPi0EtaCharged   ->Fill(eta,etaMC);
1970       }
1971                 }//Overlapped pizero decay
1972                 else if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPhoton)){
1973       fhGamE     ->Fill(e,eMC); 
1974       fhGamPt    ->Fill(pt,ptMC);
1975       fhGamEta   ->Fill(eta,etaMC);     
1976       fhGamPhi   ->Fill(phi,phiMC);
1977       fhGamDeltaE  ->Fill(eMC-e);
1978       fhGamDeltaPt ->Fill(ptMC-pt);     
1979       fhGamDeltaPhi->Fill(phiMC-phi);
1980       fhGamDeltaEta->Fill(etaMC-eta);
1981       if(eMC > 0) fhGamRatioE  ->Fill(e/eMC);
1982       if(ptMC     > 0) fhGamRatioPt ->Fill(pt/ptMC);
1983       if(phiMC    > 0) fhGamRatioPhi->Fill(phi/phiMC);
1984       if(etaMC    > 0) fhGamRatioEta->Fill(eta/etaMC);
1985       if( nTracksMatched > 0){
1986         fhGamECharged     ->Fill(e,eMC);                
1987         fhGamPtCharged    ->Fill(pt,ptMC);
1988         fhGamPhiCharged   ->Fill(phi,phiMC);
1989         fhGamEtaCharged   ->Fill(eta,etaMC);
1990       }
1991                 }//photon
1992                 else if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCElectron)){
1993                         fhEleE     ->Fill(e,eMC);       
1994                         fhElePt    ->Fill(pt,ptMC);
1995                         fhEleEta   ->Fill(eta,etaMC);   
1996                         fhElePhi   ->Fill(phi,phiMC);
1997                         fhEMVxyz   ->Fill(vxMC,vyMC);//,vz);
1998                         fhEMR      ->Fill(e,rVMC);
1999                         if( nTracksMatched > 0){
2000                                 fhEleECharged     ->Fill(e,eMC);                
2001                                 fhElePtCharged    ->Fill(pt,ptMC);
2002                                 fhElePhiCharged   ->Fill(phi,phiMC);
2003                                 fhEleEtaCharged   ->Fill(eta,etaMC);
2004                         }
2005                 }
2006                 else if(charge == 0){
2007                         fhNeHadE     ->Fill(e,eMC);     
2008                         fhNeHadPt    ->Fill(pt,ptMC);
2009                         fhNeHadEta   ->Fill(eta,etaMC); 
2010                         fhNeHadPhi   ->Fill(phi,phiMC); 
2011                         fhHaVxyz     ->Fill(vxMC,vyMC);//,vz);
2012                         fhHaR        ->Fill(e,rVMC);
2013                         if( nTracksMatched > 0){
2014                                 fhNeHadECharged     ->Fill(e,eMC);              
2015                                 fhNeHadPtCharged    ->Fill(pt,ptMC);
2016                                 fhNeHadPhiCharged   ->Fill(phi,phiMC);
2017                                 fhNeHadEtaCharged   ->Fill(eta,etaMC);
2018                         }
2019                 }
2020                 else if(charge!=0){
2021                         fhChHadE     ->Fill(e,eMC);     
2022                         fhChHadPt    ->Fill(pt,ptMC);
2023                         fhChHadEta   ->Fill(eta,etaMC); 
2024                         fhChHadPhi   ->Fill(phi,phiMC); 
2025                         fhHaVxyz     ->Fill(vxMC,vyMC);//,vz);
2026                         fhHaR        ->Fill(e,rVMC);
2027                         if( nTracksMatched > 0){
2028                                 fhChHadECharged     ->Fill(e,eMC);              
2029                                 fhChHadPtCharged    ->Fill(pt,ptMC);
2030                                 fhChHadPhiCharged   ->Fill(phi,phiMC);
2031                                 fhChHadEtaCharged   ->Fill(eta,etaMC);
2032                         }
2033                 }
2034         }//Work with MC
2035   
2036         
2037   //Match tracks and clusters
2038   //To be Modified in case of AODs
2039         
2040   //if(ntracksmatched==1 && trackIndex==-1) ntracksmatched=0;
2041         
2042         if( nTracksMatched > 0){
2043     if(fFillAllTH12){
2044       fhECharged      ->Fill(e);        
2045       fhPtCharged     ->Fill(pt);
2046       fhPhiCharged    ->Fill(phi);
2047       fhEtaCharged    ->Fill(eta);
2048     }
2049                 fhEtaPhiECharged->Fill(eta,phi,e);              
2050                 fhNCellsPerClusterMIPCharged->Fill(e, nCaloCellsPerCluster,eta);
2051                 
2052     //printf("track index %d ntracks %d\n", esd->GetNumberOfTracks());  
2053     //Study the track and matched cluster if track exists.
2054                 if(!track) return;
2055                 Double_t emcpos[3] = {0.,0.,0.};
2056                 Double_t emcmom[3] = {0.,0.,0.};
2057                 Double_t radius    = 441.0; //[cm] EMCAL radius +13cm
2058                 Double_t bfield    = 0.;
2059                 Double_t tphi      = 0;
2060                 Double_t teta      = 0;
2061                 Double_t tmom      = 0;
2062                 Double_t tpt       = 0;
2063                 Double_t tmom2     = 0;
2064                 Double_t tpcSignal = 0;
2065                 Bool_t okpos = kFALSE;
2066                 Bool_t okmom = kFALSE;
2067                 Bool_t okout = kFALSE;
2068                 Int_t nITS   = 0;
2069                 Int_t nTPC   = 0;
2070                 
2071     //In case of ESDs get the parameters in this way
2072     //          if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
2073     if (track->GetOuterParam() ) {
2074       okout = kTRUE;
2075       
2076       bfield = GetReader()->GetInputEvent()->GetMagneticField();
2077       okpos = track->GetOuterParam()->GetXYZAt(radius,bfield,emcpos);
2078       okmom = track->GetOuterParam()->GetPxPyPzAt(radius,bfield,emcmom);
2079       if(!(okpos && okmom)) return;
2080       
2081       TVector3 position(emcpos[0],emcpos[1],emcpos[2]);
2082       TVector3 momentum(emcmom[0],emcmom[1],emcmom[2]);
2083       tphi = position.Phi();
2084       teta = position.Eta();
2085       tmom = momentum.Mag();
2086       
2087       //Double_t tphi  = track->GetOuterParam()->Phi();
2088       //Double_t teta  = track->GetOuterParam()->Eta();
2089       //Double_t tmom  = track->GetOuterParam()->P();
2090       tpt       = track->Pt();
2091       tmom2     = track->P();
2092       tpcSignal = track->GetTPCsignal();
2093       
2094       nITS = track->GetNcls(0);
2095       nTPC = track->GetNcls(1);
2096     }//Outer param available 
2097     //}// ESDs
2098     //                  else if(GetReader()->GetDataType()==AliCaloTrackReader::kAOD) {
2099     //                          AliAODPid* pid = (AliAODPid*) ((AliAODTrack *) track)->GetDetPid();
2100     //                          if (pid) {
2101     //                                  okout = kTRUE;
2102     //                                  pid->GetEMCALPosition(emcpos);
2103     //                                  pid->GetEMCALMomentum(emcmom);  
2104     //                                  
2105     //                                  TVector3 position(emcpos[0],emcpos[1],emcpos[2]);
2106     //                                  TVector3 momentum(emcmom[0],emcmom[1],emcmom[2]);
2107     //                                  tphi = position.Phi();
2108     //                                  teta = position.Eta();
2109     //                                  tmom = momentum.Mag();
2110     //                                  
2111     //                                  tpt       = ((AliAODTrack*)track)->Pt();
2112     //                                  tmom2     = ((AliAODTrack*)track)->P();
2113     //                                  tpcSignal = pid->GetTPCsignal();
2114     //                          
2115     //                                  //nITS = ((AliAODTrack*)track)->GetNcls(0);
2116     //                                  //nTPC = ((AliAODTrack*)track)->GetNcls(1);
2117     //                          }//Outer param available 
2118     //                  }//AODs
2119     //                  else return; //Do nothing case not implemented.
2120                 
2121     if(okout){
2122       Double_t deta = teta - eta;
2123       Double_t dphi = tphi - phi;
2124       if(dphi > TMath::Pi()) dphi -= 2*TMath::Pi();
2125       if(dphi < -TMath::Pi()) dphi += 2*TMath::Pi();
2126       Double_t dR = sqrt(dphi*dphi + deta*deta);
2127                         
2128       Double_t pOverE = tmom/e;
2129                         
2130       fh1pOverE->Fill(tpt, pOverE);
2131       if(dR < 0.02) fh1pOverER02->Fill(tpt,pOverE);
2132                         
2133       fh1dR->Fill(dR);
2134       fh2MatchdEdx->Fill(tmom2,tpcSignal);
2135                         
2136       if(IsDataMC() && primary){ 
2137         Int_t pdg = primary->GetPdgCode();
2138         Double_t  charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
2139                                 
2140         if(TMath::Abs(pdg) == 11){
2141           fhMCEle1pOverE->Fill(tpt,pOverE);
2142           fhMCEle1dR->Fill(dR);
2143           fhMCEle2MatchdEdx->Fill(tmom2,tpcSignal);             
2144           if(dR < 0.02) fhMCEle1pOverER02->Fill(tpt,pOverE);
2145         }
2146         else if(charge!=0){
2147           fhMCChHad1pOverE->Fill(tpt,pOverE);
2148           fhMCChHad1dR->Fill(dR);
2149           fhMCChHad2MatchdEdx->Fill(tmom2,tpcSignal);   
2150           if(dR < 0.02) fhMCChHad1pOverER02->Fill(tpt,pOverE);
2151         }
2152         else if(charge == 0){
2153           fhMCNeutral1pOverE->Fill(tpt,pOverE);
2154           fhMCNeutral1dR->Fill(dR);
2155           fhMCNeutral2MatchdEdx->Fill(tmom2,tpcSignal); 
2156           if(dR < 0.02) fhMCNeutral1pOverER02->Fill(tpt,pOverE);
2157         }
2158       }//DataMC
2159       
2160       if(dR < 0.02 && pOverE > 0.5 && pOverE < 1.5
2161          && nCaloCellsPerCluster > 1 && nITS > 3 && nTPC > 20) {
2162         fh2EledEdx->Fill(tmom2,tpcSignal);
2163       }
2164     }
2165     else{//no ESD external param or AODPid
2166       //                                        ULong_t status=AliESDtrack::kTPCrefit;
2167       //                                status|=AliESDtrack::kITSrefit;
2168       //printf("track status %d\n", track->GetStatus() );
2169       //                                fhEChargedNoOut      ->Fill(e);         
2170       //                                fhPtChargedNoOut     ->Fill(pt);
2171       //                                fhPhiChargedNoOut    ->Fill(phi);
2172       //                                fhEtaChargedNoOut    ->Fill(eta);
2173       //                                fhEtaPhiChargedNoOut ->Fill(eta,phi);
2174       //                                if(GetDebug() >= 0 && ((track->GetStatus() & status) == status)) printf("ITS+TPC\n");
2175       if(GetDebug() >= 0) printf("No ESD external param or AliAODPid \n");
2176       
2177     }//No out params
2178         }//matched clusters with tracks
2179   
2180 }// Clusters
2181
2182 //__________________________________
2183 //void AliAnaCalorimeterQA::CorrelateCalorimeters(TRefArray* refArray){
2184 //  // Correlate information from PHOS and EMCAL
2185 //      TRefArray * caloClustersEMCAL = 0;
2186 //      TRefArray * caloClustersPHOS  = 0;
2187 //      
2188 //  // Get once the array of clusters per calorimeter, avoid an extra loop.
2189 //  if(fCalorimeter == "EMCAL"){ 
2190 //    caloClustersPHOS = new TRefArray();
2191 //    GetReader()->GetInputEvent()->GetPHOSClusters(caloClustersPHOS);
2192 //    caloClustersEMCAL = new TRefArray(*refArray);
2193 //  }
2194 //  else if(fCalorimeter == "PHOS") { 
2195 //    caloClustersEMCAL = new TRefArray();
2196 //    GetReader()->GetInputEvent()->GetEMCALClusters (caloClustersEMCAL);
2197 //    caloClustersPHOS = new TRefArray(*refArray);
2198 //  }
2199 //  
2200 //  //Fill histograms with clusters
2201 //  
2202 //  fhCaloCorrNClusters->Fill(caloClustersEMCAL->GetEntriesFast(),caloClustersPHOS->GetEntriesFast());
2203 //  Float_t sumClusterEnergyEMCAL = 0;
2204 //  Float_t sumClusterEnergyPHOS  = 0;
2205 //  Int_t iclus = 0;
2206 //  for(iclus = 0 ; iclus <  caloClustersEMCAL->GetEntriesFast() ; iclus++) 
2207 //    sumClusterEnergyEMCAL += ((AliVCluster*)caloClustersEMCAL->At(iclus))->E();
2208 //  for(iclus = 0 ; iclus <  caloClustersPHOS->GetEntriesFast(); iclus++) 
2209 //    sumClusterEnergyPHOS += ((AliVCluster*)caloClustersPHOS->At(iclus))->E();
2210 //  fhCaloCorrEClusters->Fill(sumClusterEnergyEMCAL,sumClusterEnergyPHOS);
2211 //  
2212 //  //Fill histograms with cells
2213 //  
2214 //  AliVCaloCells * cellsEMCAL = GetReader()->GetInputEvent()->GetEMCALCells();
2215 //  AliVCaloCells * cellsPHOS  = GetReader()->GetInputEvent()->GetPHOSCells();
2216 //  fhCaloCorrNCells   ->Fill(cellsEMCAL->GetNumberOfCells(),cellsPHOS->GetNumberOfCells());
2217 //  
2218 //  Int_t icell = 0;
2219 //  Float_t sumCellEnergyEMCAL = 0;
2220 //  Float_t sumCellEnergyPHOS  = 0;
2221 //  for(icell = 0 ; icell < cellsEMCAL->GetNumberOfCells()  ; icell++) 
2222 //    sumCellEnergyEMCAL += cellsEMCAL->GetAmplitude(icell);
2223 //  for(icell = 0 ; icell <  cellsPHOS->GetNumberOfCells(); icell++) 
2224 //    sumCellEnergyPHOS += cellsPHOS->GetAmplitude(icell);
2225 //  fhCaloCorrECells->Fill(sumCellEnergyEMCAL,sumCellEnergyPHOS);
2226 //  if(GetDebug() > 0 ){
2227 //    printf("AliAnaCalorimeterQA::CorrelateCalorimeters() - ESD: \n");
2228 //    printf("\t EMCAL: N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2229 //           cellsEMCAL->GetNumberOfCells(),caloClustersEMCAL->GetEntriesFast(),sumCellEnergyEMCAL,sumClusterEnergyEMCAL);
2230 //    printf("\t PHOS : N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2231 //           cellsPHOS->GetNumberOfCells(),caloClustersPHOS->GetEntriesFast(),sumCellEnergyPHOS,sumClusterEnergyPHOS);
2232 //  }
2233 //      
2234 //      delete caloClustersEMCAL;
2235 //      delete caloClustersPHOS;
2236 //      
2237 //}
2238
2239 //__________________________________
2240 void AliAnaCalorimeterQA::CorrelateCalorimeters(){
2241   // Correlate information from PHOS and EMCAL
2242         TObjArray * caloClustersEMCAL = GetAODEMCAL();
2243         TObjArray * caloClustersPHOS  = GetAODPHOS();
2244  
2245   //Fill histograms with clusters
2246   
2247   fhCaloCorrNClusters->Fill(caloClustersEMCAL->GetEntriesFast(),caloClustersPHOS->GetEntriesFast());
2248   Float_t sumClusterEnergyEMCAL = 0;
2249   Float_t sumClusterEnergyPHOS  = 0;
2250   Int_t iclus = 0;
2251   for(iclus = 0 ; iclus <  caloClustersEMCAL->GetEntriesFast() ; iclus++) 
2252     sumClusterEnergyEMCAL += ((AliVCluster*)caloClustersEMCAL->At(iclus))->E();
2253   for(iclus = 0 ; iclus <  caloClustersPHOS->GetEntriesFast(); iclus++) 
2254     sumClusterEnergyPHOS += ((AliVCluster*)caloClustersPHOS->At(iclus))->E();
2255   fhCaloCorrEClusters->Fill(sumClusterEnergyEMCAL,sumClusterEnergyPHOS);
2256   
2257   //Fill histograms with cells
2258   
2259   AliVCaloCells * cellsEMCAL = GetEMCALCells();
2260   AliVCaloCells * cellsPHOS  = GetPHOSCells();
2261   fhCaloCorrNCells   ->Fill(cellsEMCAL->GetNumberOfCells(),cellsPHOS->GetNumberOfCells());
2262   
2263   Int_t icell = 0;
2264   Float_t sumCellEnergyEMCAL = 0;
2265   Float_t sumCellEnergyPHOS  = 0;
2266   for(icell = 0 ; icell < cellsEMCAL->GetNumberOfCells()  ; icell++) 
2267     sumCellEnergyEMCAL += cellsEMCAL->GetAmplitude(icell);
2268   for(icell = 0 ; icell <  cellsPHOS->GetNumberOfCells(); icell++) 
2269     sumCellEnergyPHOS += cellsPHOS->GetAmplitude(icell);
2270   fhCaloCorrECells->Fill(sumCellEnergyEMCAL,sumCellEnergyPHOS);
2271   if(GetDebug() > 0 ){
2272     printf("AliAnaCalorimeterQA::CorrelateCalorimeters() - ESD: \n");
2273     printf("\t EMCAL: N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2274            cellsEMCAL->GetNumberOfCells(),caloClustersEMCAL->GetEntriesFast(),sumCellEnergyEMCAL,sumClusterEnergyEMCAL);
2275     printf("\t PHOS : N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2276            cellsPHOS->GetNumberOfCells(),caloClustersPHOS->GetEntriesFast(),sumCellEnergyPHOS,sumClusterEnergyPHOS);
2277   }
2278 }
2279
2280
2281 //______________________________________________________________________________
2282 void AliAnaCalorimeterQA::MCHistograms(const TLorentzVector mom, const Int_t pdg){
2283   //Fill pure monte carlo related histograms
2284         
2285         Float_t eMC    = mom.E();
2286         Float_t ptMC   = mom.Pt();
2287         Float_t phiMC  = mom.Phi();
2288         if(phiMC < 0) 
2289                 phiMC  += TMath::TwoPi();
2290         Float_t etaMC  = mom.Eta();
2291         
2292         if (TMath::Abs(etaMC) > 1) return;
2293   
2294         Bool_t in = kTRUE;
2295         if(IsFiducialCutOn()) in =  GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
2296         
2297         if (pdg==22) {
2298                 fhGenGamPt ->Fill(ptMC);
2299                 fhGenGamEta->Fill(etaMC);
2300                 fhGenGamPhi->Fill(phiMC);
2301                 if(in){
2302                         fhGenGamAccE  ->Fill(eMC);
2303                         fhGenGamAccPt ->Fill(ptMC);
2304                         fhGenGamAccEta->Fill(etaMC);
2305                         fhGenGamAccPhi->Fill(phiMC);                                    
2306                 }
2307         }
2308         else if (pdg==111) {
2309                 fhGenPi0Pt ->Fill(ptMC);
2310                 fhGenPi0Eta->Fill(etaMC);
2311                 fhGenPi0Phi->Fill(phiMC);
2312                 if(in){
2313                         fhGenPi0AccE  ->Fill(eMC);                                      
2314                         fhGenPi0AccPt ->Fill(ptMC);
2315                         fhGenPi0AccEta->Fill(etaMC);
2316                         fhGenPi0AccPhi->Fill(phiMC);                                    
2317                 }
2318         }
2319         else if (pdg==221) {
2320                 fhGenEtaPt ->Fill(ptMC);
2321                 fhGenEtaEta->Fill(etaMC);
2322                 fhGenEtaPhi->Fill(phiMC);
2323         }
2324         else if (pdg==223) {
2325                 fhGenOmegaPt ->Fill(ptMC);
2326                 fhGenOmegaEta->Fill(etaMC);
2327                 fhGenOmegaPhi->Fill(phiMC);
2328         }
2329         else if (TMath::Abs(pdg)==11) {
2330                 fhGenElePt ->Fill(ptMC);
2331                 fhGenEleEta->Fill(etaMC);
2332                 fhGenElePhi->Fill(phiMC);
2333         }       
2334         
2335 }
2336
2337 //________________________________________________________________________
2338 void AliAnaCalorimeterQA::ReadHistograms(TList* outputList)
2339 {
2340   // Needed when Terminate is executed in distributed environment
2341   // Refill analysis histograms of this class with corresponding histograms in output list. 
2342         
2343   // Histograms of this analsys are kept in the same list as other analysis, recover the position of
2344   // the first one and then add the next 
2345         Int_t index = outputList->IndexOf(outputList->FindObject(GetAddedHistogramsStringToName()+"hE"));
2346   //printf("Calo: %s, index: %d, nmodules %d\n",fCalorimeter.Data(),index,fNModules);
2347         
2348   //Read histograms, must be in the same order as in GetCreateOutputObject.
2349         fhE       = (TH1F *) outputList->At(index++);   
2350   if(fFillAllTH12){
2351     fhPt      = (TH1F *) outputList->At(index++); 
2352     fhPhi     = (TH1F *) outputList->At(index++); 
2353     fhEta     = (TH1F *) outputList->At(index++);
2354   }
2355         fhEtaPhiE = (TH3F *) outputList->At(index++);
2356   
2357         fhClusterTimeEnergy = (TH2F*) outputList->At(index++);
2358         
2359         fhLambda      = (TH3F *)  outputList->At(index++);
2360         fhDispersion  = (TH2F *)  outputList->At(index++);
2361   if(fFillAllTH12){
2362     fhECharged       = (TH1F *) outputList->At(index++);        
2363     fhPtCharged      = (TH1F *) outputList->At(index++); 
2364     fhPhiCharged     = (TH1F *) outputList->At(index++); 
2365     fhEtaCharged     = (TH1F *) outputList->At(index++);
2366   }
2367         fhEtaPhiECharged = (TH3F *) outputList->At(index++);
2368         
2369         fh1pOverE =    (TH2F *) outputList->At(index++);
2370         fh1dR =        (TH1F *) outputList->At(index++);
2371         fh2MatchdEdx = (TH2F *) outputList->At(index++);
2372         fh2EledEdx =   (TH2F *) outputList->At(index++);
2373         fh1pOverER02 = (TH2F *) outputList->At(index++);
2374         
2375         fhIM        = (TH2F *) outputList->At(index++);
2376         fhIMCellCut = (TH2F *) outputList->At(index++);
2377   fhAsym      = (TH2F *) outputList->At(index++);
2378         
2379         fhNCellsPerCluster           = (TH3F *) outputList->At(index++);
2380         fhNCellsPerClusterMIP        = (TH3F *) outputList->At(index++);
2381         fhNCellsPerClusterMIPCharged = (TH3F *) outputList->At(index++);
2382         fhNClusters  = (TH1F *) outputList->At(index++); 
2383   
2384     fhRNCells = (TH2F *) outputList->At(index++);
2385     fhXNCells = (TH2F *) outputList->At(index++);
2386     fhYNCells = (TH2F *) outputList->At(index++);
2387     fhZNCells = (TH2F *) outputList->At(index++);
2388     fhRE          = (TH2F *) outputList->At(index++);
2389     fhXE          = (TH2F *) outputList->At(index++);
2390     fhYE          = (TH2F *) outputList->At(index++);
2391     fhZE          = (TH2F *) outputList->At(index++); 
2392     fhXYZ         = (TH3F *) outputList->At(index++);
2393   if(fFillAllPosHisto){
2394     fhRCellE      = (TH2F *) outputList->At(index++);
2395     fhXCellE      = (TH2F *) outputList->At(index++);
2396     fhYCellE      = (TH2F *) outputList->At(index++);
2397     fhZCellE      = (TH2F *) outputList->At(index++); 
2398     fhXYZCell     = (TH3F *) outputList->At(index++); 
2399     fhDeltaCellClusterRNCells = (TH2F *) outputList->At(index++);
2400     fhDeltaCellClusterXNCells = (TH2F *) outputList->At(index++);
2401     fhDeltaCellClusterYNCells = (TH2F *) outputList->At(index++);
2402     fhDeltaCellClusterZNCells = (TH2F *) outputList->At(index++);
2403     fhDeltaCellClusterRE          = (TH2F *) outputList->At(index++);
2404     fhDeltaCellClusterXE          = (TH2F *) outputList->At(index++);
2405     fhDeltaCellClusterYE          = (TH2F *) outputList->At(index++);
2406     fhDeltaCellClusterZE          = (TH2F *) outputList->At(index++); 
2407     fhEtaPhiAmp               = (TH3F *) outputList->At(index++); 
2408         }
2409   
2410         fhNCells     = (TH1F *) outputList->At(index++); 
2411         fhAmplitude  = (TH1F *) outputList->At(index++); 
2412         fhAmpId      = (TH2F *) outputList->At(index++); 
2413   
2414         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
2415                 
2416                 fhCellTimeSpreadRespectToCellMax = (TH1F *) outputList->At(index++);
2417                 fhCellIdCellLargeTimeSpread      = (TH1F *) outputList->At(index++);
2418     
2419                 fhTime       = (TH1F *) outputList->At(index++); 
2420                 fhTimeId     = (TH2F *) outputList->At(index++); 
2421                 fhTimeAmp    = (TH2F *) outputList->At(index++); 
2422                 
2423     //          fhT0Time       = (TH1F *) outputList->At(index++); 
2424     //          fhT0TimeId     = (TH2F *) outputList->At(index++); 
2425     //          fhT0TimeAmp    = (TH2F *) outputList->At(index++); 
2426                 
2427         }
2428         
2429         
2430         if(fCorrelateCalos){
2431                 fhCaloCorrNClusters = (TH2F *) outputList->At(index++);
2432                 fhCaloCorrEClusters = (TH2F *) outputList->At(index++); 
2433                 fhCaloCorrNCells    = (TH2F *) outputList->At(index++); 
2434                 fhCaloCorrECells    = (TH2F *) outputList->At(index++); 
2435         }
2436         
2437   //Module histograms
2438         fhEMod                 = new TH1F*[fNModules];
2439         fhNClustersMod         = new TH1F*[fNModules];
2440         fhNCellsPerClusterMod  = new TH2F*[fNModules];
2441         fhNCellsMod            = new TH1F*[fNModules];
2442         fhGridCellsMod         = new TH2F*[fNModules];
2443         fhGridCellsEMod        = new TH2F*[fNModules];
2444         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) 
2445                 fhGridCellsTimeMod     = new TH2F*[fNModules];
2446         fhAmplitudeMod         = new TH1F*[fNModules];
2447         if(fCalorimeter=="EMCAL")
2448                 fhAmplitudeModFraction = new TH1F*[fNModules*3];
2449         
2450   //EMCAL
2451         fhTimeAmpPerRCU        = new TH2F*[fNModules*fNRCU];
2452         
2453         fhIMMod                = new TH2F*[fNModules];
2454         fhIMCellCutMod         = new TH2F*[fNModules];
2455   
2456         for(Int_t imod = 0 ; imod < fNModules; imod++){
2457                 fhEMod[imod]                 = (TH1F *) outputList->At(index++);
2458                 fhNClustersMod[imod]         = (TH1F *) outputList->At(index++); 
2459                 fhNCellsPerClusterMod[imod]  = (TH2F *) outputList->At(index++); 
2460                 fhNCellsMod[imod]            = (TH1F *) outputList->At(index++);        
2461                 fhGridCellsMod[imod]         = (TH2F *) outputList->At(index++);
2462                 fhGridCellsEMod[imod]        = (TH2F *) outputList->At(index++); 
2463                 if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) 
2464                         fhGridCellsTimeMod[imod]     = (TH2F *) outputList->At(index++); 
2465                 fhAmplitudeMod[imod]         = (TH1F *) outputList->At(index++);
2466                 
2467                 if(fCalorimeter=="EMCAL"){
2468                         for(Int_t ifrac = 0; ifrac < 3; ifrac++){
2469                                 fhAmplitudeModFraction[imod*3+ifrac] = (TH1F *) outputList->At(index++); 
2470                         }
2471                 }
2472                 
2473                 for(Int_t ircu = 0; ircu < fNRCU; ircu++){
2474                         fhTimeAmpPerRCU[imod*fNRCU+ircu] = (TH2F *) outputList->At(index++); 
2475       //fhT0TimeAmpPerRCU[imod*fNRCU+ircu] = (TH2F *) outputList->At(index++); 
2476       //                        for(Int_t imod2 = 0; imod2 < fNModules; imod2++){
2477       //                                for(Int_t ircu2 = 0; ircu2 < fNModules; ircu2++){
2478       //                                        fhTimeCorrRCU[imod*fNRCU+ircu+imod2*fNRCU+ircu2]  = (TH2F *) outputList->At(index++);
2479       //                                }
2480       //                        }
2481                 }
2482                 fhIMMod[imod]                = (TH2F *) outputList->At(index++); 
2483                 fhIMCellCutMod[imod]         = (TH2F *) outputList->At(index++);        
2484     
2485         }
2486         
2487         if(IsDataMC()){
2488                 fhDeltaE   = (TH1F *) outputList->At(index++); 
2489                 fhDeltaPt  = (TH1F *) outputList->At(index++); 
2490                 fhDeltaPhi = (TH1F *) outputList->At(index++); 
2491                 fhDeltaEta = (TH1F *) outputList->At(index++); 
2492                 
2493                 fhRatioE   = (TH1F *) outputList->At(index++); 
2494                 fhRatioPt  = (TH1F *) outputList->At(index++); 
2495                 fhRatioPhi = (TH1F *) outputList->At(index++); 
2496                 fhRatioEta = (TH1F *) outputList->At(index++); 
2497                 
2498                 fh2E       = (TH2F *) outputList->At(index++); 
2499                 fh2Pt      = (TH2F *) outputList->At(index++); 
2500                 fh2Phi     = (TH2F *) outputList->At(index++); 
2501                 fh2Eta     = (TH2F *) outputList->At(index++); 
2502                 
2503                 fhGamE     = (TH2F *) outputList->At(index++); 
2504                 fhGamPt    = (TH2F *) outputList->At(index++); 
2505                 fhGamPhi   = (TH2F *) outputList->At(index++); 
2506                 fhGamEta   = (TH2F *) outputList->At(index++); 
2507                 
2508                 fhGamDeltaE   = (TH1F *) outputList->At(index++); 
2509                 fhGamDeltaPt  = (TH1F *) outputList->At(index++); 
2510                 fhGamDeltaPhi = (TH1F *) outputList->At(index++); 
2511                 fhGamDeltaEta = (TH1F *) outputList->At(index++); 
2512                 
2513                 fhGamRatioE   = (TH1F *) outputList->At(index++); 
2514                 fhGamRatioPt  = (TH1F *) outputList->At(index++); 
2515                 fhGamRatioPhi = (TH1F *) outputList->At(index++); 
2516                 fhGamRatioEta = (TH1F *) outputList->At(index++); 
2517     
2518                 fhPi0E     = (TH2F *) outputList->At(index++); 
2519                 fhPi0Pt    = (TH2F *) outputList->At(index++); 
2520                 fhPi0Phi   = (TH2F *) outputList->At(index++); 
2521                 fhPi0Eta   = (TH2F *) outputList->At(index++);          
2522                 
2523                 fhEleE     = (TH2F *) outputList->At(index++); 
2524                 fhElePt    = (TH2F *) outputList->At(index++); 
2525                 fhElePhi   = (TH2F *) outputList->At(index++); 
2526                 fhEleEta   = (TH2F *) outputList->At(index++);          
2527                 
2528                 fhNeHadE     = (TH2F *) outputList->At(index++); 
2529                 fhNeHadPt    = (TH2F *) outputList->At(index++); 
2530                 fhNeHadPhi   = (TH2F *) outputList->At(index++); 
2531                 fhNeHadEta   = (TH2F *) outputList->At(index++);                
2532                 
2533                 fhChHadE     = (TH2F *) outputList->At(index++); 
2534                 fhChHadPt    = (TH2F *) outputList->At(index++); 
2535                 fhChHadPhi   = (TH2F *) outputList->At(index++); 
2536                 fhChHadEta   = (TH2F *) outputList->At(index++);                                
2537                 
2538                 fhGamECharged     = (TH2F *) outputList->At(index++); 
2539                 fhGamPtCharged    = (TH2F *) outputList->At(index++); 
2540                 fhGamPhiCharged   = (TH2F *) outputList->At(index++); 
2541                 fhGamEtaCharged   = (TH2F *) outputList->At(index++); 
2542     
2543                 fhPi0ECharged     = (TH2F *) outputList->At(index++); 
2544                 fhPi0PtCharged    = (TH2F *) outputList->At(index++); 
2545                 fhPi0PhiCharged   = (TH2F *) outputList->At(index++); 
2546                 fhPi0EtaCharged   = (TH2F *) outputList->At(index++);           
2547                 
2548                 fhEleECharged     = (TH2F *) outputList->At(index++); 
2549                 fhElePtCharged    = (TH2F *) outputList->At(index++); 
2550                 fhElePhiCharged   = (TH2F *) outputList->At(index++); 
2551                 fhEleEtaCharged   = (TH2F *) outputList->At(index++);           
2552                 
2553                 fhNeHadECharged     = (TH2F *) outputList->At(index++); 
2554                 fhNeHadPtCharged    = (TH2F *) outputList->At(index++); 
2555                 fhNeHadPhiCharged   = (TH2F *) outputList->At(index++); 
2556                 fhNeHadEtaCharged   = (TH2F *) outputList->At(index++);                 
2557                 
2558                 fhChHadECharged     = (TH2F *) outputList->At(index++); 
2559                 fhChHadPtCharged    = (TH2F *) outputList->At(index++); 
2560                 fhChHadPhiCharged   = (TH2F *) outputList->At(index++); 
2561                 fhChHadEtaCharged   = (TH2F *) outputList->At(index++);                                 
2562                 
2563     //          fhEMVxyz     = (TH3F *) outputList->At(index++); 
2564     //          fhHaVxyz     = (TH3F *) outputList->At(index++); 
2565                 
2566                 fhEMVxyz     = (TH2F *) outputList->At(index++); 
2567                 fhHaVxyz     = (TH2F *) outputList->At(index++); 
2568                 fhEMR        = (TH2F *) outputList->At(index++); 
2569                 fhHaR        = (TH2F *) outputList->At(index++); 
2570                 
2571                 fhGenGamPt    = (TH1F *) outputList->At(index++); 
2572                 fhGenGamEta   = (TH1F *) outputList->At(index++); 
2573                 fhGenGamPhi   = (TH1F *) outputList->At(index++); 
2574                 
2575                 fhGenPi0Pt    = (TH1F *) outputList->At(index++); 
2576                 fhGenPi0Eta   = (TH1F *) outputList->At(index++); 
2577                 fhGenPi0Phi   = (TH1F *) outputList->At(index++); 
2578                 
2579                 fhGenEtaPt    = (TH1F *) outputList->At(index++); 
2580                 fhGenEtaEta   = (TH1F *) outputList->At(index++); 
2581                 fhGenEtaPhi   = (TH1F *) outputList->At(index++); 
2582                 
2583                 fhGenOmegaPt  = (TH1F *) outputList->At(index++); 
2584                 fhGenOmegaEta = (TH1F *) outputList->At(index++); 
2585                 fhGenOmegaPhi = (TH1F *) outputList->At(index++); 
2586                 
2587                 fhGenElePt    = (TH1F *) outputList->At(index++); 
2588                 fhGenEleEta   = (TH1F *) outputList->At(index++); 
2589                 fhGenElePhi   = (TH1F *) outputList->At(index++); 
2590                 
2591                 fhGenGamAccE   = (TH1F *) outputList->At(index++);              
2592                 fhGenGamAccPt  = (TH1F *) outputList->At(index++); 
2593                 fhGenGamAccEta = (TH1F *) outputList->At(index++); 
2594                 fhGenGamAccPhi = (TH1F *) outputList->At(index++); 
2595                 
2596                 fhGenPi0AccE   = (TH1F *) outputList->At(index++);              
2597                 fhGenPi0AccPt  = (TH1F *) outputList->At(index++); 
2598                 fhGenPi0AccEta = (TH1F *) outputList->At(index++); 
2599                 fhGenPi0AccPhi = (TH1F *) outputList->At(index++); 
2600                 
2601                 fhMCEle1pOverE =    (TH2F *) outputList->At(index++);
2602                 fhMCEle1dR =        (TH1F *) outputList->At(index++);
2603                 fhMCEle2MatchdEdx = (TH2F *) outputList->At(index++);
2604                 
2605                 fhMCChHad1pOverE =    (TH2F *) outputList->At(index++);
2606                 fhMCChHad1dR =        (TH1F *) outputList->At(index++);
2607                 fhMCChHad2MatchdEdx = (TH2F *) outputList->At(index++);
2608                 
2609                 fhMCNeutral1pOverE    = (TH2F *) outputList->At(index++);
2610                 fhMCNeutral1dR        = (TH1F *) outputList->At(index++);
2611                 fhMCNeutral2MatchdEdx = (TH2F *) outputList->At(index++);
2612                 
2613                 fhMCEle1pOverER02     =    (TH2F *) outputList->At(index++);
2614                 fhMCChHad1pOverER02   =    (TH2F *) outputList->At(index++);
2615                 fhMCNeutral1pOverER02 =    (TH2F *) outputList->At(index++);
2616         }
2617 }
2618
2619 //__________________________________________________________________
2620 void  AliAnaCalorimeterQA::Terminate(TList* outputList) 
2621 {
2622   //Do plots if requested       
2623   
2624         if(GetDebug() > 0) printf("AliAnaCalorimeterQA::Terminate() - Make plots for %s? %d\n",fCalorimeter.Data(), fMakePlots);
2625         if(!fMakePlots) return;
2626         
2627   //Do some plots to end
2628   if(fStyleMacro!="")gROOT->Macro(fStyleMacro); 
2629   //Recover histograms from output histograms list, needed for distributed analysis.    
2630         ReadHistograms(outputList);
2631         
2632   //printf(" AliAnaCalorimeterQA::Terminate()  *** %s Report:", GetName()) ; 
2633   //printf(" AliAnaCalorimeterQA::Terminate()        pt         : %5.3f , RMS : %5.3f \n", fhPt->GetMean(),   fhPt->GetRMS() ) ;
2634   
2635         char name[128];
2636         char cname[128];
2637         
2638   //In case terminate is executed after the analysis, in a second step, and we want to rebin or to change the range of the histograms for plotting
2639         Int_t nptbins     = GetHistoPtBins();           Float_t ptmax     = GetHistoPtMax();           Float_t ptmin     = GetHistoPtMin();
2640         Int_t nphibins    = GetHistoPhiBins();          Float_t phimax    = GetHistoPhiMax();          Float_t phimin    = GetHistoPhiMin();
2641         Int_t netabins    = GetHistoEtaBins();          Float_t etamax    = GetHistoEtaMax();          Float_t etamin    = GetHistoEtaMin();    
2642   //    Int_t nmassbins   = GetHistoMassBins();         Float_t massmax   = GetHistoMassMax();         Float_t massmin   = GetHistoMassMin();
2643   //    Int_t nasymbins   = GetHistoAsymmetryBins();    Float_t asymmax   = GetHistoAsymmetryMax();    Float_t asymmin   = GetHistoAsymmetryMin();
2644   //    Int_t nPoverEbins = GetHistoPOverEBins();       Float_t pOverEmax = GetHistoPOverEMax();       Float_t pOverEmin = GetHistoPOverEMin();
2645   //    Int_t ndedxbins   = GetHistodEdxBins();         Float_t dedxmax   = GetHistodEdxMax();         Float_t dedxmin   = GetHistodEdxMin();
2646   //    Int_t ndRbins     = GetHistodRBins();           Float_t dRmax     = GetHistodRMax();           Float_t dRmin     = GetHistodRMin();
2647         Int_t ntimebins   = GetHistoTimeBins();         Float_t timemax   = GetHistoTimeMax();         Float_t timemin   = GetHistoTimeMin();       
2648         Int_t nbins       = GetHistoNClusterCellBins(); Int_t nmax        = GetHistoNClusterCellMax(); Int_t nmin        = GetHistoNClusterCellMin(); 
2649   //    Int_t nratiobins  = GetHistoRatioBins();        Float_t ratiomax  = GetHistoRatioMax();        Float_t ratiomin  = GetHistoRatioMin();
2650   //    Int_t nvdistbins  = GetHistoVertexDistBins();   Float_t vdistmax  = GetHistoVertexDistMax();   Float_t vdistmin  = GetHistoVertexDistMin();
2651         Int_t rbins       = GetHistoRBins();            Float_t rmax        = GetHistoRMax();          Float_t rmin      = GetHistoRMin(); 
2652         Int_t xbins       = GetHistoXBins();            Float_t xmax        = GetHistoXMax();          Float_t xmin      = GetHistoXMin(); 
2653         Int_t ybins       = GetHistoYBins();            Float_t ymax        = GetHistoYMax();          Float_t ymin      = GetHistoYMin(); 
2654         Int_t zbins       = GetHistoZBins();            Float_t zmax        = GetHistoZMax();          Float_t zmin      = GetHistoZMin(); 
2655         
2656   //Color code for the different modules
2657         Int_t modColorIndex[]={2,4,6,8};
2658         
2659   //--------------------------------------------------
2660   // Cluster energy distributions, module dependence
2661   //--------------------------------------------------
2662         sprintf(cname,"QA_%s_ClusterEnergy",fCalorimeter.Data());
2663         TCanvas  * c = new TCanvas(cname, "Energy distributions", 800, 400) ;
2664         c->Divide(2, 1);
2665         Int_t rbE = GetNewRebinForRePlotting((TH1D*)fhE, ptmin, ptmax,nptbins) ;
2666   //printf("new E rb %d\n",rbE);
2667         fhE->Rebin(rbE);
2668         fhE->SetAxisRange(ptmin,ptmax,"X");
2669         c->cd(1) ; 
2670         if(fhE->GetEntries() > 0) gPad->SetLogy();
2671         TLegend pLegendE(0.7,0.6,0.9,0.8);
2672         pLegendE.SetTextSize(0.03);
2673         pLegendE.AddEntry(fhE,"all modules","L");
2674         pLegendE.SetFillColor(10);
2675         pLegendE.SetBorderSize(1);
2676         
2677         fhE->SetMinimum(1);     
2678         fhE->SetLineColor(1);
2679         fhE->Draw("HE");
2680         for(Int_t imod = 0; imod < fNModules; imod++){
2681                 fhEMod[imod]->Rebin(rbE);
2682                 fhEMod[imod]->SetLineColor(modColorIndex[imod]);
2683                 fhEMod[imod]->Draw("HE same");
2684                 pLegendE.AddEntry(fhEMod[imod],Form("module %d",imod),"L");
2685         }
2686         pLegendE.Draw();
2687         
2688   //Ratio of modules
2689         c->cd(2) ; 
2690         TLegend pLegendER(0.55,0.8,0.9,0.9);
2691         pLegendER.SetTextSize(0.03);
2692         pLegendER.SetFillColor(10);
2693         pLegendER.SetBorderSize(1);
2694   
2695         for(Int_t imod = 1; imod < fNModules; imod++){
2696                 TH1D * htmp = (TH1D*)fhEMod[imod]->Clone(Form("hERat%d",imod));
2697                 htmp->Divide(fhEMod[0]);
2698                 htmp->SetLineColor(modColorIndex[imod]);
2699                 if(imod==1){
2700                         htmp->SetTitle("Ratio module X / module 0");
2701                         htmp->SetAxisRange(ptmin,ptmax,"X");
2702                         htmp->SetMaximum(5);
2703                         htmp->SetMinimum(0);
2704                         htmp->SetAxisRange(ptmin,ptmax,"X");
2705                         htmp->Draw("HE");
2706                 }
2707                 else 
2708                         htmp->Draw("same HE");
2709                 
2710                 pLegendER.AddEntry(fhEMod[imod],Form("module %d / module 0",imod),"L");
2711         }
2712         pLegendER.Draw();
2713         
2714         sprintf(name,"QA_%s_ClusterEnergy.eps",fCalorimeter.Data());
2715         c->Print(name); printf("Plot: %s\n",name);
2716         
2717   //--------------------------------------------------
2718   // Cell energy distributions, module dependence
2719   //--------------------------------------------------
2720         sprintf(cname,"%s_QA_CellEnergy",fCalorimeter.Data());
2721         TCanvas  * ca = new TCanvas(cname, "Cell Energy distributions", 800, 400) ;
2722         ca->Divide(2, 1);
2723         
2724         Int_t rbAmp = GetNewRebinForRePlotting((TH1D*)fhAmplitude, ptmin, ptmax,nptbins*2) ;
2725   //printf("new Amp rb %d\n",rbAmp);
2726         fhAmplitude->Rebin(rbAmp);
2727         fhAmplitude->SetAxisRange(ptmin,ptmax,"X");
2728         
2729         ca->cd(1) ; 
2730         if(fhAmplitude->GetEntries() > 0) gPad->SetLogy();
2731         TLegend pLegendA(0.7,0.6,0.9,0.8);
2732         pLegendA.SetTextSize(0.03);
2733         pLegendA.AddEntry(fhE,"all modules","L");
2734         pLegendA.SetFillColor(10);
2735         pLegendA.SetBorderSize(1);
2736         fhAmplitude->SetMinimum(0.1);
2737         fhAmplitude->SetLineColor(1);
2738         fhAmplitude->Draw("HE");
2739         
2740         for(Int_t imod = 0; imod < fNModules; imod++){
2741                 fhAmplitudeMod[imod]->Rebin(rbAmp);
2742                 fhAmplitudeMod[imod]->SetLineColor(modColorIndex[imod]);
2743                 fhAmplitudeMod[imod]->Draw("HE same");
2744                 pLegendA.AddEntry(fhAmplitudeMod[imod],Form("module %d",imod),"L");
2745         }
2746         pLegendA.Draw();
2747         
2748         
2749         ca->cd(2) ; 
2750         TLegend pLegendAR(0.55,0.8,0.9,0.9);
2751         pLegendAR.SetTextSize(0.03);
2752         pLegendAR.SetFillColor(10);
2753         pLegendAR.SetBorderSize(1);
2754         
2755         for(Int_t imod = 1; imod < fNModules; imod++){
2756                 TH1D * htmp = (TH1D*)fhAmplitudeMod[imod]->Clone(Form("hAmpRat%d",imod));
2757                 htmp->Divide(fhAmplitudeMod[0]);
2758                 htmp->SetLineColor(modColorIndex[imod]);
2759                 if(imod==1){
2760                         htmp->SetTitle("Ratio cells energy in  module X / module 0");
2761                         htmp->SetAxisRange(ptmin,ptmax,"X");
2762                         htmp->SetMaximum(5);
2763                         htmp->SetMinimum(0);
2764                         htmp->Draw("HE");
2765                 }
2766                 else 
2767                         htmp->Draw("same HE");
2768                 pLegendAR.AddEntry(fhAmplitudeMod[imod],Form("module %d",imod),"L");
2769         }
2770         
2771         pLegendAR.Draw();
2772         sprintf(name,"QA_%s_CellEnergy.eps",fCalorimeter.Data());
2773         ca->Print(name); printf("Plot: %s\n",name);     
2774   
2775   //----------------------------------------------------------
2776   // Cell energy distributions, FRACTION of module dependence
2777   // See Super Module calibration difference
2778   //---------------------------------------------------------   
2779         if(fCalorimeter=="EMCAL"){
2780     //Close To Eta 0 
2781                 sprintf(cname,"%s_QA_SMThirds",fCalorimeter.Data());
2782                 TCanvas  * cfrac = new TCanvas(cname, "SM Thirds ratios", 800, 1200) ;
2783                 cfrac->Divide(2, 3);
2784                 cfrac->cd(1) ; 
2785                 if(fhAmplitude->GetEntries() > 0) 
2786                         gPad->SetLogy();
2787                 TLegend pLegend1(0.6,0.6,0.9,0.8);
2788                 pLegend1.SetTextSize(0.03);
2789                 pLegend1.SetFillColor(10);
2790                 pLegend1.SetBorderSize(1);
2791                 pLegend1.SetHeader("Third close to Eta=0");
2792                 fhAmplitudeModFraction[0]->SetTitle("Third close to Eta=0");
2793                 fhAmplitudeModFraction[0]->SetAxisRange(ptmin,ptmax,"X");
2794                 fhAmplitudeModFraction[0]->Draw("axis");
2795                 TH1D * hAverageThird1 = (TH1D *)fhAmplitudeModFraction[3*0+2]->Clone("AverageThird1");
2796                 for(Int_t imod = 0; imod < fNModules; imod++){
2797                         Int_t ifrac = 0;
2798                         if(imod%2==0) ifrac = 2;
2799                         if(imod > 0) hAverageThird1->Add( fhAmplitudeModFraction[3*imod+ifrac]);
2800                         fhAmplitudeModFraction[3*imod+ifrac]->SetLineColor(modColorIndex[imod]);
2801                         fhAmplitudeModFraction[3*imod+ifrac]->Draw("HE same");
2802                         pLegend1.AddEntry(fhAmplitudeModFraction[3*imod+ifrac],Form("super module %d",imod),"L");
2803                 }
2804                 hAverageThird1 ->Scale(1./fNModules);
2805                 pLegend1.Draw();
2806     //Ratio
2807                 cfrac->cd(2) ; 
2808                 for(Int_t imod = 0; imod < fNModules; imod++){
2809                         Int_t ifrac = 0;
2810                         if(imod%2==0) ifrac = 2;
2811                         TH1D * htmp =  (TH1D*)fhAmplitudeModFraction[3*imod+ifrac]->Clone(Form("ThirdFractionAverage_%d_%d",imod,ifrac));
2812                         htmp->Divide(hAverageThird1);
2813                         if(imod ==0) {
2814                                 htmp ->SetTitle("Close to eta = 0");
2815                                 htmp ->SetMaximum(5);
2816                                 htmp ->SetMinimum(0);
2817                                 htmp ->SetAxisRange(ptmin,ptmax,"X");
2818                                 htmp ->SetYTitle("ratio third to average");
2819                                 htmp -> Draw("HE");
2820                         }
2821                         else htmp -> Draw("same HE");
2822                 }
2823     //pLegend1.Draw();
2824                 
2825     //Middle Eta
2826                 cfrac->cd(3) ; 
2827                 if(fhAmplitude->GetEntries() > 0) 
2828                         gPad->SetLogy();
2829                 TLegend pLegend2(0.6,0.6,0.9,0.8);
2830                 pLegend2.SetTextSize(0.03);
2831                 pLegend2.SetFillColor(10);
2832                 pLegend2.SetBorderSize(1);
2833                 pLegend2.SetHeader("Middle Third");
2834                 
2835                 fhAmplitudeModFraction[0]->SetTitle("Middle Third");
2836                 fhAmplitudeModFraction[0]->SetAxisRange(ptmin,ptmax,"X");
2837                 fhAmplitudeModFraction[0]->Draw("axis");
2838                 
2839                 TH1D * hAverageThird2 = (TH1D *)fhAmplitudeModFraction[3*0+1]->Clone("AverageThird2");
2840                 for(Int_t imod = 0; imod < fNModules; imod++){
2841                         Int_t ifrac = 1;
2842                         if(imod > 0) hAverageThird2->Add( fhAmplitudeModFraction[3*imod+ifrac]);
2843                         fhAmplitudeModFraction[3*imod+ifrac]->SetLineColor(modColorIndex[imod]);
2844                         fhAmplitudeModFraction[3*imod+ifrac]->Draw("HE same");
2845                         pLegend2.AddEntry(fhAmplitudeModFraction[3*imod+ifrac],Form("super module %d",imod),"L");
2846                 }
2847                 hAverageThird2->Scale(1./fNModules);
2848                 pLegend2.Draw();
2849                 
2850     //Ratio
2851                 cfrac->cd(4) ; 
2852                 
2853                 for(Int_t imod = 0; imod < fNModules; imod++){
2854                         Int_t ifrac = 1;
2855                         TH1D * htmp =  (TH1D*)fhAmplitudeModFraction[3*imod+ifrac]->Clone(Form("ThirdFractionAverage_%d_%d",imod,ifrac));
2856                         htmp->Divide(hAverageThird2);
2857                         if(imod ==0) {
2858                                 htmp ->SetTitle("Middle");
2859                                 htmp ->SetMaximum(5);
2860                                 htmp ->SetMinimum(0);
2861                                 htmp ->SetAxisRange(ptmin,ptmax,"X");
2862                                 htmp ->SetYTitle("ratio third to average");
2863                                 htmp -> Draw("HE");
2864                         }
2865                         else htmp -> Draw("same HE");
2866                 }
2867     //pLegend2.Draw();
2868                 
2869     //Close To Eta 0.7 
2870                 cfrac->cd(5) ; 
2871                 if(fhAmplitude->GetEntries() > 0) 
2872                         gPad->SetLogy();
2873                 TLegend pLegend3(0.6,0.6,0.9,0.8);
2874                 pLegend3.SetTextSize(0.03);
2875                 pLegend3.SetFillColor(10);
2876                 pLegend3.SetBorderSize(1);
2877                 pLegend3.SetHeader("Third close to Eta=0.7");
2878                 
2879                 fhAmplitudeModFraction[0]->SetTitle("Third close to Eta=0.7");
2880                 fhAmplitudeModFraction[0]->SetAxisRange(ptmin,ptmax,"X");
2881                 fhAmplitudeModFraction[0]->Draw("axis");
2882                 
2883                 TH1D * hAverageThird3 = (TH1D *)fhAmplitudeModFraction[3*0+0]->Clone("AverageThird3");
2884                 for(Int_t imod = 0; imod < 4; imod++){
2885                         Int_t ifrac = 2;
2886                         if(imod%2==0) ifrac = 0;
2887                         if(imod > 0) hAverageThird3->Add( fhAmplitudeModFraction[3*imod+ifrac]);
2888                         fhAmplitudeModFraction[3*imod+ifrac]->SetLineColor(modColorIndex[imod]);
2889                         fhAmplitudeModFraction[3*imod+ifrac]->Draw("HE same");
2890                         pLegend3.AddEntry(fhAmplitudeModFraction[3*imod+ifrac],Form("super module %d",imod),"L");
2891                 }
2892                 hAverageThird3 ->Scale(1./fNModules);
2893                 pLegend3.Draw();
2894                 
2895                 cfrac->cd(6) ; 
2896                 
2897                 for(Int_t imod = 0; imod < fNModules; imod++){
2898                         Int_t ifrac = 2;
2899                         if(imod%2==0) ifrac = 0;
2900                         TH1D * htmp =  (TH1D*)fhAmplitudeModFraction[3*imod+ifrac]->Clone(Form("ThirdFractionAverage_%d_%d",imod,ifrac));
2901                         htmp->Divide(hAverageThird3);
2902                         if(imod ==0) {
2903                                 htmp ->SetTitle("Close to eta = 0.7");
2904                                 htmp ->SetMaximum(5);
2905                                 htmp ->SetMinimum(0);
2906                                 htmp ->SetAxisRange(ptmin,ptmax,"X");
2907                                 htmp ->SetYTitle("ratio third to average");
2908                                 htmp ->Draw("HE");
2909                         }
2910                         else htmp ->Draw("same HE");
2911                 }
2912     //pLegend3.Draw();
2913                 
2914                 sprintf(name,"QA_%s_CellEnergyModuleFraction.eps",fCalorimeter.Data());
2915                 cfrac->Print(name); printf("Create plot %s\n",name);
2916         }//EMCAL        
2917         
2918         
2919   //----------------------------------------------------------
2920   // Cluster eta and phi distributions, energy cut dependence
2921   //---------------------------------------------------------   
2922         
2923         sprintf(cname,"%s_QA_EtaPhiCluster",fCalorimeter.Data());
2924         TCanvas  * cetaphic = new TCanvas(cname, "Eta-Phi Reconstructed distributions", 1200, 400) ;
2925         cetaphic->Divide(3, 1);
2926         Int_t binmin = 0;
2927         Int_t rbPhi  = 1;
2928         Int_t rbEta  = 1;
2929         Int_t ncuts  = 7;
2930         Float_t ecut[]     = {0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3};
2931         Int_t   ecutcolor[]= {2, 4, 6, 7, 8, 9, 12};
2932         TH1D * hE = fhEtaPhiE->ProjectionZ();
2933         
2934   //PHI
2935         cetaphic->cd(1) ; 
2936         gPad->SetLogy();
2937         gPad->SetGridy();
2938         
2939         TLegend pLegendPhiCl(0.83,0.6,0.95,0.93);
2940         pLegendPhiCl.SetTextSize(0.03);
2941         pLegendPhiCl.SetFillColor(10);
2942         pLegendPhiCl.SetBorderSize(1);
2943         
2944         TH1D * htmp = fhEtaPhiE->ProjectionY("hphi_cluster_nocut",0,-1,0,-1);
2945         if(htmp){
2946           htmp->SetMinimum(1);
2947           rbPhi =  GetNewRebinForRePlotting(htmp, phimin, phimax,nphibins) ;
2948     //printf("new Phi rb %d\n",rbPhi);
2949           htmp->Rebin(rbPhi);
2950           htmp->SetTitle("#phi of clusters for energy in cluster > threshold");
2951           htmp->SetAxisRange(phimin,phimax,"X");
2952           htmp->Draw("HE");
2953           pLegendPhiCl.AddEntry(htmp,"No cut","L");
2954     
2955           for (Int_t i = 0; i < ncuts; i++) {
2956             binmin =  hE->FindBin(ecut[i]);
2957       //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
2958             htmp = fhEtaPhiE->ProjectionY(Form("hphi_cluster_cut%d",i),0,-1,binmin,-1);
2959             htmp->SetLineColor(ecutcolor[i]);
2960             htmp->Rebin(rbPhi);
2961             htmp->Draw("same HE");
2962             pLegendPhiCl.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L");
2963             
2964           }
2965         }
2966         pLegendPhiCl.Draw();
2967         
2968   //ETA
2969         cetaphic->cd(2) ; 
2970         gPad->SetLogy();
2971         gPad->SetGridy();
2972         
2973         htmp = fhEtaPhiE->ProjectionX("heta_cluster_nocut",0,-1,0,-1);
2974         htmp ->SetLineColor(1);
2975         rbEta =  GetNewRebinForRePlotting(htmp,etamin, etamax,netabins) ;
2976   //printf("new Eta rb %d\n",rbEta);
2977         if(htmp){
2978           htmp->Rebin(rbEta);
2979           htmp->SetMinimum(1);
2980           htmp->SetTitle("#eta of clusters for energy in cluster > threshold");
2981           htmp->SetAxisRange(etamin,etamax,"X");
2982           htmp->Draw("HE");
2983           
2984           for (Int_t i = 0; i < ncuts; i++) {
2985             binmin =  hE->FindBin(ecut[i]);
2986       //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
2987             htmp = fhEtaPhiE->ProjectionX(Form("heta_cluster_cut%d",i),0,-1,binmin,-1);
2988             htmp->SetLineColor(ecutcolor[i]);
2989             htmp->Rebin(rbEta);
2990             htmp->Draw("same HE");      
2991           }
2992         }
2993   //ETA vs PHI  
2994         cetaphic->cd(3) ;
2995         TH2D* hEtaPhiCl = (TH2D*) fhEtaPhiE->Project3D("xy");
2996         hEtaPhiCl->SetAxisRange(etamin,etamax,"X");
2997         hEtaPhiCl->SetAxisRange(phimin,phimax,"Y");
2998         hEtaPhiCl->Draw("colz");
2999   
3000         sprintf(name,"QA_%s_ClusterEtaPhi.eps",fCalorimeter.Data());
3001         cetaphic->Print(name); printf("Create plot %s\n",name);
3002   
3003   //----------------------------------------------------------
3004   // Cell eta and phi distributions, energy cut dependence
3005   //---------------------------------------------------------   
3006         
3007         sprintf(cname,"%s_QA_EtaPhiCell",fCalorimeter.Data());
3008         TCanvas  * cetaphicell = new TCanvas(cname, "Eta-Phi Cells distributions", 1200, 400) ;
3009         cetaphicell->Divide(3, 1);
3010         
3011   //PHI
3012         cetaphicell->cd(1) ; 
3013         gPad->SetLogy();
3014         gPad->SetGridy();
3015         
3016         TLegend pLegendPhiCell(0.83,0.6,0.95,0.93);
3017         pLegendPhiCell.SetTextSize(0.03);
3018         pLegendPhiCell.SetFillColor(10);
3019         pLegendPhiCell.SetBorderSize(1);
3020         
3021         htmp = fhEtaPhiAmp->ProjectionY("hphi_cell_nocut",0,-1,0,-1);
3022         if(htmp){
3023           htmp->SetMinimum(1);
3024           htmp->Rebin(rbPhi);
3025           htmp->SetTitle("#phi of cells for cell energy > threshold");
3026           htmp->SetAxisRange(phimin,phimax,"X");
3027           htmp->Draw("HE");
3028           pLegendPhiCell.AddEntry(htmp,"No cut","L");
3029           
3030           for (Int_t i = 0; i < ncuts; i++) {
3031             binmin =  hE->FindBin(ecut[i]);
3032       //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3033             htmp = fhEtaPhiAmp->ProjectionY(Form("hphi_cell_cut%d",i),0,-1,binmin,-1);
3034             htmp->SetLineColor(ecutcolor[i]);
3035             htmp->Rebin(rbPhi);
3036             htmp->Draw("same HE");
3037             pLegendPhiCl.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L");
3038             
3039           }
3040         }
3041         pLegendPhiCell.Draw();
3042         
3043   //ETA
3044         cetaphicell->cd(2) ; 
3045         gPad->SetLogy();
3046         gPad->SetGridy();
3047         
3048         htmp = fhEtaPhiAmp->ProjectionX("heta_cell_nocut",0,-1,0,-1);
3049         if(htmp){
3050           htmp ->SetLineColor(1);
3051           htmp->Rebin(rbEta);
3052           htmp->SetMinimum(1);
3053           htmp->SetTitle("#eta of cells for cell energy > threshold");
3054           htmp->SetAxisRange(etamin,etamax,"X");
3055           htmp->Draw("HE");
3056           
3057           for (Int_t i = 0; i < ncuts; i++) {
3058             binmin =  hE->FindBin(ecut[i]);
3059       //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3060             htmp = fhEtaPhiAmp->ProjectionX(Form("heta_cell_cut%d",i),0,-1,binmin,-1);
3061             htmp->SetLineColor(ecutcolor[i]);
3062             htmp->Rebin(rbEta);
3063             htmp->Draw("same HE");
3064             
3065           }
3066         }
3067   //ETA vs PHI  
3068         cetaphicell->cd(3) ;
3069         TH2D* hEtaPhiCell = (TH2D*) fhEtaPhiAmp->Project3D("xy");
3070         hEtaPhiCell->SetAxisRange(etamin,etamax,"X");
3071         hEtaPhiCell->SetAxisRange(phimin,phimax,"Y");
3072         hEtaPhiCell->Draw("colz");
3073         
3074         sprintf(name,"QA_%s_CellEtaPhi.eps",fCalorimeter.Data());
3075         cetaphicell->Print(name); printf("Create plot %s\n",name);
3076         
3077   
3078   ////////////////////////////////////////        
3079   ///////// Global Positions /////////////       
3080   ////////////////////////////////////////       
3081         
3082   //CLUSTERS
3083   Int_t rbX = 1;
3084   Int_t rbY = 1;
3085   Int_t rbZ = 1;
3086   //if(fFillAllPosHisto)
3087   {
3088     sprintf(cname,"%s_QA_ClusterXY",fCalorimeter.Data());
3089     TCanvas  * cxyz = new TCanvas(cname, "Cluster XY distributions", 1200, 400) ;
3090     cxyz->Divide(3, 1);
3091     
3092     cxyz->cd(1) ; 
3093     TH2D * hXY = (TH2D*) fhXYZ->Project3D("yx" );
3094     hXY->SetTitle("Cluster X vs Y");
3095     hXY->GetYaxis()->SetTitleOffset(1.6);
3096     hXY->Draw("colz");
3097     cxyz->cd(2) ; 
3098     TH2D * hYZ = (TH2D*) fhXYZ->Project3D("yz" );
3099     hYZ->SetTitle("Cluster Z vs Y");
3100     hYZ->GetYaxis()->SetTitleOffset(1.6);
3101     hYZ->Draw("colz");  
3102     cxyz->cd(3) ; 
3103     TH2D * hXZ = (TH2D*) fhXYZ->Project3D("zx" );
3104     hXZ->SetTitle("Cluster X vs Z");
3105     hXZ->GetYaxis()->SetTitleOffset(1.6);
3106     hXZ->Draw("colz");
3107     
3108     sprintf(name,"QA_%s_ClusterXY_YZ_XZ.eps",fCalorimeter.Data());
3109     cxyz->Print(name); printf("Create plot %s\n",name);
3110     
3111     sprintf(cname,"QA_%s_ClusterX",fCalorimeter.Data());
3112     TCanvas  * cx = new TCanvas(cname, "Cluster X distributions", 1200, 400) ;
3113     cx->Divide(3, 1);
3114     
3115     cx->cd(1) ; 
3116     TH1D * hX = (TH1D*) fhXYZ->Project3D("xe" );
3117     //gPad->SetLogy();
3118     gPad->SetGridy();
3119     hX->SetTitle("Cluster X ");
3120     hX->Draw("HE");
3121     rbX =  GetNewRebinForRePlotting(hX, xmin, xmax,xbins) ;
3122     //printf("new X rb %d\n",rbX);
3123     hX->Rebin(rbX);
3124     hX->SetMinimum(hX->GetMaximum()/2);
3125     hX->SetAxisRange(xmin,xmax);
3126     
3127     cx->cd(2) ; 
3128     TH1D * hY = (TH1D*) fhXYZ->Project3D("ye" );
3129     //gPad->SetLogy();
3130     hY->SetTitle("Cluster Y ");
3131     rbY =  GetNewRebinForRePlotting(hY, ymin, ymax, ybins) ;
3132     //printf("new Y rb %d\n",rbY);
3133     hY->Rebin(rbY);
3134     hY->SetMinimum(1);
3135     hY->SetAxisRange(ymin,ymax);
3136     hY->Draw("HE");     
3137     
3138     cx->cd(3) ; 
3139     TH1D * hZ = (TH1D*) fhXYZ->Project3D("ze" );
3140     //gPad->SetLogy();
3141     gPad->SetGridy();
3142     rbZ =  GetNewRebinForRePlotting(hZ,zmin, zmax,zbins) ;
3143     //printf("new Z rb %d\n",rbZ);
3144     hZ->Rebin(rbZ);     
3145     hZ->SetMinimum(hZ->GetMaximum()/2);
3146     hZ->SetAxisRange(zmin,zmax);
3147     hZ->Draw("HE");
3148     
3149     sprintf(name,"QA_%s_ClusterX_Y_Z.eps",fCalorimeter.Data());
3150     cx->Print(name); printf("Create plot %s\n",name);
3151   }
3152     //CELLS
3153   if(fFillAllPosHisto)
3154   { 
3155     sprintf(cname,"%s_QA_CellXY",fCalorimeter.Data());
3156     TCanvas  * cellxyz = new TCanvas(cname, "Cell XY distributions", 1200, 400) ;
3157     cellxyz->Divide(3, 1);
3158     
3159     cellxyz->cd(1) ; 
3160     TH2D * hXYCell = (TH2D*) fhXYZCell->Project3D("yx" );
3161     hXYCell->SetTitle("Cell X vs Y");
3162     hXYCell->GetYaxis()->SetTitleOffset(1.6);
3163     hXYCell->Draw("colz");
3164     cellxyz->cd(2) ; 
3165     TH2D * hYZCell = (TH2D*) fhXYZCell->Project3D("yz" );
3166     hYZCell->SetTitle("Cell Z vs Y");
3167     hYZCell->GetYaxis()->SetTitleOffset(1.6);
3168     hYZCell->Draw("colz");      
3169     cellxyz->cd(3) ; 
3170     TH2D * hXZCell = (TH2D*) fhXYZCell->Project3D("zx" );
3171     hXZCell->SetTitle("Cell X vs Z");
3172     hXZCell->GetYaxis()->SetTitleOffset(1.6);
3173     hXZCell->Draw("colz");
3174     
3175     sprintf(name,"QA_%s_CellXY_YZ_XZ.eps",fCalorimeter.Data());
3176     cellxyz->Print(name); printf("Create plot %s\n",name);
3177     
3178     
3179     sprintf(cname,"%s_QA_CellX",fCalorimeter.Data());
3180     TCanvas  * cellx = new TCanvas(cname, "Cell X distributions", 1200, 400) ;
3181     cellx->Divide(3, 1);
3182     
3183     cellx->cd(1) ; 
3184     TH1D * hXCell = (TH1D*) fhXYZCell->Project3D("xe" );
3185     //gPad->SetLogy();
3186     gPad->SetGridy();
3187     hXCell->SetTitle("Cell X ");
3188     hXCell->Rebin(rbX);
3189     hXCell->SetMinimum(hXCell->GetMaximum()/2);
3190     hXCell->SetAxisRange(xmin,xmax);
3191     hXCell->Draw("HE");
3192     
3193     cellx->cd(2) ; 
3194     TH1D * hYCell = (TH1D*) fhXYZCell->Project3D("ye" );
3195     //gPad->SetLogy();
3196     hYCell->SetTitle("Cell Y ");
3197     hYCell->Rebin(rbY);
3198     hYCell->SetAxisRange(ymin,ymax);
3199     hYCell->SetMinimum(1);
3200     hYCell->Draw("HE"); 
3201     
3202     cellx->cd(3) ; 
3203     TH1D * hZCell = (TH1D*) fhXYZCell->Project3D("ze" );
3204     //gPad->SetLogy();
3205     gPad->SetGridy();
3206     hZCell->SetAxisRange(zmin,zmax);
3207     hZCell->SetTitle("Cell Z ");
3208     hZCell->Rebin(rbZ);
3209     hZCell->SetMinimum(hZCell->GetMaximum()/2);
3210     hZCell->Draw("HE");
3211     
3212     sprintf(name,"QA_%s_CellX_Y_Z.eps",fCalorimeter.Data());
3213     cellx->Print(name); printf("Create plot %s\n",name);
3214     
3215     
3216     //----------------------------------------------------------
3217     // Cluster X, Y, Z, R, energy cut dependence
3218     //--------------------------------------------------------- 
3219     
3220     sprintf(cname,"%s_QA_ClusterX_Y_Z_R_ECut",fCalorimeter.Data());
3221     TCanvas  * cxe = new TCanvas(cname, "Cluster X Y Z R, E cut", 800, 800) ;
3222     cxe->Divide(2, 2);          
3223     //R
3224     cxe->cd(1) ; 
3225     gPad->SetLogy();
3226     gPad->SetGridy();
3227     
3228     TLegend pLegendXCl(0.83,0.6,0.95,0.93);
3229     pLegendXCl.SetTextSize(0.03);
3230     pLegendXCl.SetFillColor(10);
3231     pLegendXCl.SetBorderSize(1);
3232     
3233     htmp = fhRE->ProjectionX("hre_cluster_nocut",0,-1);
3234     Int_t rbR=1;
3235     if(htmp){
3236       htmp->SetMinimum(1);
3237       rbR =  GetNewRebinForRePlotting(htmp, rmin, rmax,rbins) ;
3238       //printf("new R rb %d\n",rbR);
3239       htmp->Rebin(rbR);
3240       htmp->SetTitle("r of clusters for energy in cluster > threshold");
3241       htmp->SetAxisRange(rmin,rmax,"X");
3242       htmp->Draw("HE");
3243       pLegendXCl.AddEntry(htmp,"No cut","L");
3244       
3245       for (Int_t i = 0; i < ncuts; i++) {
3246         binmin =  hE->FindBin(ecut[i]);
3247         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3248         htmp = fhRE->ProjectionX(Form("hre_cluster_cut%d",i),binmin,-1);
3249         htmp->SetLineColor(ecutcolor[i]);
3250         htmp->Rebin(rbR);
3251         htmp->Draw("same HE");
3252         pLegendXCl.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L");
3253       }
3254     }
3255     pLegendXCl.Draw();
3256     
3257     //X
3258     cxe->cd(2) ; 
3259     gPad->SetLogy();
3260     gPad->SetGridy();
3261     htmp = fhXE->ProjectionX("hxe_cluster_nocut",0,-1);
3262     if(htmp){
3263       htmp->SetMinimum(1);
3264       htmp->Rebin(rbX);
3265       htmp->SetTitle("x of clusters for energy in cluster > threshold");
3266       htmp->SetAxisRange(xmin,xmax,"X");
3267       htmp->Draw("HE");
3268       
3269       for (Int_t i = 0; i < ncuts; i++) {
3270         binmin =  hE->FindBin(ecut[i]);
3271         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3272         htmp = fhXE->ProjectionX(Form("hxe_cluster_cut%d",i),binmin,-1);
3273         htmp->SetLineColor(ecutcolor[i]);
3274         htmp->Rebin(rbX);
3275         htmp->Draw("same HE");
3276       }
3277     }
3278     //Y
3279     cxe->cd(3) ; 
3280     gPad->SetLogy();
3281     gPad->SetGridy();
3282     htmp = fhYE->ProjectionX("hye_cluster_nocut",0,-1);
3283     if(htmp){
3284       htmp->SetMinimum(1);
3285       htmp->Rebin(rbY);
3286       htmp->SetTitle("y of clusters for energy in cluster > threshold");
3287       htmp->SetAxisRange(ymin,ymax,"X");
3288       htmp->Draw("HE");
3289       
3290       for (Int_t i = 0; i < ncuts; i++) {
3291         binmin =  hE->FindBin(ecut[i]);
3292         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3293         htmp = fhYE->ProjectionX(Form("hye_cluster_cut%d",i),binmin,-1);
3294         htmp->SetLineColor(ecutcolor[i]);
3295         htmp->Rebin(rbY);
3296         htmp->Draw("same HE");
3297       }
3298     }
3299     //Z
3300     cxe->cd(4) ; 
3301     gPad->SetLogy();
3302     gPad->SetGridy();
3303     
3304     htmp = fhZE->ProjectionX("hze_cluster_nocut",0,-1);
3305     if(htmp){
3306       htmp->SetMinimum(1);
3307       htmp->Rebin(rbZ);
3308       htmp->SetTitle("z of clusters for energy in cluster > threshold");
3309       htmp->SetAxisRange(zmin,zmax,"X");
3310       htmp->Draw("HE");
3311       
3312       for (Int_t i = 0; i < ncuts; i++) {
3313         binmin =  hE->FindBin(ecut[i]);
3314         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3315         htmp = fhZE->ProjectionX(Form("hze_cluster_cut%d",i),binmin,-1);
3316         htmp->SetLineColor(ecutcolor[i]);
3317         htmp->Rebin(rbZ);
3318         htmp->Draw("same HE"); 
3319       }
3320     }
3321     
3322     sprintf(name,"QA_%s_ClusterX_Y_Z_R_ECut.eps",fCalorimeter.Data());
3323     cxe->Print(name); printf("Create plot %s\n",name);
3324     
3325     
3326     //----------------------------------------------------------
3327     // Cluster X, Y, Z, R, NCells in cluster dependence
3328     //--------------------------------------------------------- 
3329     Int_t ncellcut[]={2, 3, 4};
3330     Int_t ncellcuts = 3;
3331     sprintf(cname,"%s_QA_ClusterX_Y_Z_R_NCellsCut",fCalorimeter.Data());
3332     TCanvas  * cxn = new TCanvas(cname, "Cluster X Y Z R, NCells cut", 800, 800) ;
3333     cxn->Divide(2, 2);          
3334     //R
3335     cxn->cd(1) ; 
3336     gPad->SetLogy();
3337     gPad->SetGridy();
3338     
3339     TLegend pLegendXClN(0.83,0.6,0.95,0.93);
3340     pLegendXClN.SetTextSize(0.03);
3341     pLegendXClN.SetFillColor(10);
3342     pLegendXClN.SetBorderSize(1);
3343     
3344     htmp = fhRNCells->ProjectionX("hrn_cluster_nocut",0,-1);
3345     if(htmp){
3346       htmp->SetMinimum(1);
3347       htmp->Rebin(rbR);
3348       htmp->SetTitle("r of clusters for energy in cluster > threshold");
3349       htmp->SetAxisRange(rmin,rmax,"X");
3350       htmp->Draw("HE");
3351       pLegendXClN.AddEntry(htmp,"No cut","L");
3352       
3353       for (Int_t i = 0; i < ncellcuts; i++) {
3354         if(i < ncellcuts-1) htmp = fhRNCells->ProjectionX(Form("hrn_cluster_cut%d",i),ncellcut[i],ncellcut[i]);
3355         else htmp = fhRNCells->ProjectionX(Form("hrn_cluster_cut%d",i),ncellcut[i],-1);
3356         htmp->SetLineColor(ecutcolor[i]);
3357         htmp->Rebin(rbR);
3358         htmp->Draw("same HE");
3359         if(i < ncellcuts-1) pLegendXClN.AddEntry(htmp,Form("n = %1.1d",ncellcut[i]-1),"L");
3360         else pLegendXClN.AddEntry(htmp,Form("n >= %1.1d",ncellcut[i]-1),"L");
3361         
3362       }
3363     }
3364     pLegendXClN.Draw();
3365     
3366     //X
3367     cxn->cd(2) ; 
3368     gPad->SetLogy();
3369     gPad->SetGridy();
3370     htmp = fhXNCells->ProjectionX("hxn_cluster_nocut",0,-1);
3371     if(htmp){
3372       htmp->SetMinimum(1);
3373       htmp->Rebin(rbX);
3374       htmp->SetTitle("x of clusters for energy in cluster > threshold");
3375       htmp->SetAxisRange(xmin,xmax,"X");
3376       htmp->Draw("HE");
3377       
3378       for (Int_t i = 0; i < ncellcuts; i++) {
3379         if(i < ncellcuts-1)htmp = fhXNCells->ProjectionX(Form("hxn_cluster_cut%d",i),ncellcut[i],ncellcut[i]);
3380         else htmp = fhXNCells->ProjectionX(Form("hxn_cluster_cut%d",i),ncellcut[i],-1);
3381         htmp->SetLineColor(ecutcolor[i]);
3382         htmp->Rebin(rbX);
3383         htmp->Draw("same HE");   
3384       }
3385     }
3386     //Y
3387     cxn->cd(3) ; 
3388     gPad->SetLogy();
3389     gPad->SetGridy();
3390     htmp = fhYNCells->ProjectionX("hyn_cluster_nocut",0,-1);
3391     if(htmp){
3392       htmp->SetMinimum(1);
3393       htmp->Rebin(rbY);
3394       htmp->SetTitle("y of clusters for energy in cluster > threshold");
3395       htmp->SetAxisRange(ymin,ymax,"X");
3396       htmp->Draw("HE");
3397       
3398       for (Int_t i = 0; i < ncellcuts; i++) {
3399         if(i < ncellcuts-1) htmp = fhYNCells->ProjectionX(Form("hyn_cluster_cut%d",i),ncellcut[i],ncellcut[i]);
3400         else htmp = fhYNCells->ProjectionX(Form("hyn_cluster_cut%d",i),ncellcut[i],-1);
3401         htmp->SetLineColor(ecutcolor[i]);
3402         htmp->Rebin(rbY);
3403         htmp->Draw("same HE");  
3404       }
3405     }
3406     //Z
3407     cxn->cd(4) ; 
3408     gPad->SetLogy();
3409     gPad->SetGridy();
3410     
3411     htmp = fhZNCells->ProjectionX("hzn_cluster_nocut",0,-1);
3412     if(htmp){
3413       htmp->SetMinimum(1);
3414       htmp->Rebin(rbZ);
3415       htmp->SetTitle("z of clusters for energy in cluster > threshold");
3416       htmp->SetAxisRange(zmin,zmax,"X");
3417       htmp->Draw("HE");
3418       
3419       for (Int_t i = 0; i < ncellcuts; i++) {
3420         if(i < ncellcuts-1)htmp = fhZNCells->ProjectionX(Form("hzn_cluster_cut%d",i),ncellcut[i],ncellcut[i]);
3421         else htmp = fhZNCells->ProjectionX(Form("hzn_cluster_cut%d",i),ncellcut[i],-1);
3422         htmp->SetLineColor(ecutcolor[i]);
3423         htmp->Rebin(rbZ);
3424         htmp->Draw("same HE");    
3425       }
3426     }
3427     
3428     sprintf(name,"QA_%s_ClusterX_Y_Z_R_NCellsCut.eps",fCalorimeter.Data());
3429     cxn->Print(name); printf("Create plot %s\n",name);
3430     
3431     
3432     //----------------------------------------------------------
3433     // Cell X, Y, Z, R, energy cut dependence
3434     //--------------------------------------------------------- 
3435     
3436     sprintf(cname,"%s_QA_CellX_Y_Z_R_ECut",fCalorimeter.Data());
3437     TCanvas  * cxecell = new TCanvas(cname, "Cell X Y Z R, E cut", 800, 800) ;
3438     cxecell->Divide(2, 2);              
3439     //R
3440     cxecell->cd(1) ; 
3441     gPad->SetLogy();
3442     gPad->SetGridy();
3443     
3444     TLegend pLegendXCell(0.83,0.6,0.95,0.93);
3445     pLegendXCell.SetTextSize(0.03);
3446     pLegendXCell.SetFillColor(10);
3447     pLegendXCell.SetBorderSize(1);
3448     
3449     htmp = fhRCellE->ProjectionX("hre_cell_nocut",0,-1);
3450     if(htmp){
3451       htmp->SetMinimum(1);
3452       htmp->Rebin(rbR);
3453       htmp->SetTitle("r of cells for energy in cluster > threshold");
3454       htmp->SetAxisRange(rmin,rmax,"X");
3455       htmp->Draw("HE");
3456       pLegendXCell.AddEntry(htmp,"No cut","L");
3457       
3458       for (Int_t i = 0; i < ncuts; i++) {
3459         binmin =  hE->FindBin(ecut[i]);
3460         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3461         htmp = fhRCellE->ProjectionX(Form("hre_celr_cut%d",i),binmin,-1);
3462         htmp->SetLineColor(ecutcolor[i]);
3463         htmp->Rebin(rbR);
3464         htmp->Draw("same HE");
3465         pLegendXCell.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L"); 
3466       }
3467     }
3468     pLegendXCell.Draw();
3469     
3470     //X
3471     cxecell->cd(2) ; 
3472     gPad->SetLogy();
3473     gPad->SetGridy();
3474     
3475     htmp = fhXCellE->ProjectionX("hxe_cells_nocut",0,-1);
3476     if(htmp){
3477       htmp->SetMinimum(1);
3478       htmp->Rebin(rbX);
3479       htmp->SetTitle("x of cells for energy in cluster > threshold");
3480       htmp->SetAxisRange(xmin,xmax,"X");
3481       htmp->Draw("HE");
3482       
3483       for (Int_t i = 0; i < ncuts; i++) {
3484         binmin =  hE->FindBin(ecut[i]);
3485         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3486         htmp = fhXCellE->ProjectionX(Form("hxe_cells_cut%d",i),binmin,-1);
3487         htmp->SetLineColor(ecutcolor[i]);
3488         htmp->Rebin(rbX);
3489         htmp->Draw("same HE");
3490       }
3491     }
3492     //Y
3493     cxecell->cd(3) ; 
3494     gPad->SetLogy();
3495     gPad->SetGridy();
3496     htmp = fhYCellE->ProjectionX("hye_cells_nocut",0,-1);
3497     if(htmp){
3498       htmp->SetMinimum(1);
3499       htmp->Rebin(rbY);
3500       htmp->SetTitle("y of cells for energy in cluster > threshold");
3501       htmp->SetAxisRange(ymin,ymax,"X");
3502       htmp->Draw("HE");
3503       
3504       for (Int_t i = 0; i < ncuts; i++) {
3505         binmin =  hE->FindBin(ecut[i]);
3506         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3507         htmp = fhYCellE->ProjectionX(Form("hye_cells_cut%d",i),binmin,-1);
3508         htmp->SetLineColor(ecutcolor[i]);
3509         htmp->Rebin(rbY);
3510         htmp->Draw("same HE");
3511       }
3512     }
3513     //Z
3514     cxecell->cd(4) ; 
3515     gPad->SetLogy();
3516     gPad->SetGridy();
3517     htmp = fhZCellE->ProjectionX("hze_cells_nocut",0,-1);
3518     if(htmp){
3519       htmp->SetMinimum(1);
3520       htmp->Rebin(rbZ);
3521       htmp->SetTitle("z of cells for energy in cluster > threshold");
3522       htmp->SetAxisRange(zmin,zmax,"X");
3523       htmp->Draw("HE");
3524       
3525       for (Int_t i = 0; i < ncuts; i++) {
3526         binmin =  hE->FindBin(ecut[i]);
3527         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3528         htmp = fhZCellE->ProjectionX(Form("hze_cells_cut%d",i),binmin,-1);
3529         htmp->SetLineColor(ecutcolor[i]);
3530         htmp->Rebin(rbZ);
3531         htmp->Draw("same HE"); 
3532       }
3533     }
3534     sprintf(name,"QA_%s_CellX_Y_Z_R_ECut.eps",fCalorimeter.Data());
3535     cxecell->Print(name); printf("Create plot %s\n",name);
3536     
3537     
3538     //----------------------------------------------------------
3539     // Cluster-Cell X, Y, Z, R, cluster energy cut dependence
3540     //--------------------------------------------------------- 
3541     Int_t rbDR= 1;//rbR;
3542     Int_t rbDX= 1;//rbX;
3543     Int_t rbDY= 1;//rbY;
3544     Int_t rbDZ= 1;//rbZ;
3545     
3546     sprintf(cname,"%s_QA_DeltaClusterCellX_Y_Z_R_ECut",fCalorimeter.Data());
3547     TCanvas  * cxde = new TCanvas(cname, "Cluster-Cell X, Y, Z, R, E cut", 800, 800) ;
3548     cxde->Divide(2, 2);         
3549     //R
3550     cxde->cd(1) ; 
3551     gPad->SetLogy();
3552     gPad->SetGridy();
3553     
3554     TLegend pLegendXClD(0.83,0.6,0.95,0.93);
3555     pLegendXClD.SetTextSize(0.03);
3556     pLegendXClD.SetFillColor(10);
3557     pLegendXClD.SetBorderSize(1);
3558     
3559     htmp = fhDeltaCellClusterRE->ProjectionX("hrde_nocut",0,-1);
3560     if(htmp){
3561       htmp->SetMinimum(1);
3562       htmp->Rebin(rbDR);
3563       htmp->SetTitle("r clusters - r cells for energy in cluster > threshold");
3564       htmp->SetAxisRange(-50,50,"X");
3565       htmp->Draw("HE");
3566       pLegendXCl.AddEntry(htmp,"No cut","L");
3567       
3568       for (Int_t i = 0; i < ncuts; i++) {
3569         binmin =  hE->FindBin(ecut[i]);
3570         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3571         htmp = fhDeltaCellClusterRE->ProjectionX(Form("hrde_cut%d",i),binmin,-1);
3572         htmp->SetLineColor(ecutcolor[i]);
3573         htmp->Rebin(rbDR);
3574         htmp->Draw("same HE");
3575         pLegendXClD.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L");
3576       }
3577     }
3578     pLegendXClD.Draw();
3579     
3580     //X
3581     cxde->cd(2) ; 
3582     gPad->SetLogy();
3583     gPad->SetGridy();
3584     htmp = fhDeltaCellClusterXE->ProjectionX("hxde_nocut",0,-1);
3585     if(htmp){
3586       htmp->SetMinimum(1);
3587       htmp->Rebin(rbDX);
3588       htmp->SetTitle("x clusters -x cells for energy in cluster > threshold");
3589       htmp->SetAxisRange(-50,50,"X");
3590       htmp->Draw("HE");
3591       
3592       for (Int_t i = 0; i < ncuts; i++) {
3593         binmin =  hE->FindBin(ecut[i]);
3594         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3595         htmp = fhDeltaCellClusterXE->ProjectionX(Form("hxde_cut%d",i),binmin,-1);
3596         htmp->SetLineColor(ecutcolor[i]);
3597         htmp->Rebin(rbDX);
3598         htmp->Draw("same HE");
3599         
3600       }
3601     }
3602     //Y
3603     cxde->cd(3) ; 
3604     gPad->SetLogy();
3605     gPad->SetGridy();
3606     htmp = fhDeltaCellClusterYE->ProjectionX("hyde_nocut",0,-1);
3607     if(htmp){
3608       htmp->SetMinimum(1);
3609       htmp->Rebin(rbDY);
3610       htmp->SetTitle("y clusters - ycells for energy in cluster > threshold");
3611       htmp->SetAxisRange(-50,50,"X");
3612       htmp->Draw("HE");
3613       
3614       for (Int_t i = 0; i < ncuts; i++) {
3615         binmin =  hE->FindBin(ecut[i]);
3616         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3617         htmp = fhDeltaCellClusterYE->ProjectionX(Form("hyde_cut%d",i),binmin,-1);
3618         htmp->SetLineColor(ecutcolor[i]);
3619         htmp->Rebin(rbDY);
3620         htmp->Draw("same HE");
3621         
3622       }
3623     }
3624     //Z
3625     cxde->cd(4) ; 
3626     gPad->SetLogy();
3627     gPad->SetGridy();
3628     
3629     htmp = fhDeltaCellClusterZE->ProjectionX("hzde_nocut",0,-1);
3630     if(htmp){
3631       htmp->SetMinimum(1);
3632       htmp->Rebin(rbZ);
3633       htmp->SetTitle("z clusters - z cells for energy in cluster > threshold");
3634       htmp->SetAxisRange(-50,50,"X");
3635       htmp->Draw("HE");
3636       
3637       for (Int_t i = 0; i < ncuts; i++) {
3638         binmin =  hE->FindBin(ecut[i]);
3639         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3640         htmp = fhDeltaCellClusterZE->ProjectionX(Form("hzde_cut%d",i),binmin,-1);
3641         htmp->SetLineColor(ecutcolor[i]);
3642         htmp->Rebin(rbZ);
3643         htmp->Draw("same HE");
3644         
3645       }
3646     }
3647     
3648     sprintf(name,"QA_%s_DeltaClusterCellX_Y_Z_R_ECut.eps",fCalorimeter.Data());
3649     cxde->Print(name); printf("Create plot %s\n",name);
3650     
3651     
3652     //----------------------------------------------------------
3653     // Cluster-Cell X, Y, Z, R, NCells in cluster dependence
3654     //--------------------------------------------------------- 
3655     sprintf(cname,"%s_QA_DeltaClusterCellX_Y_Z_R_NCellsCut",fCalorimeter.Data());
3656     TCanvas  * cxdn = new TCanvas(cname, "Cluster-Cell X Y Z R, NCells cut", 800, 800) ;
3657     cxdn->Divide(2, 2);         
3658     //R
3659     cxdn->cd(1) ; 
3660     gPad->SetLogy();
3661     gPad->SetGridy();
3662     
3663     TLegend pLegendXClDN(0.83,0.6,0.95,0.93);
3664     pLegendXClDN.SetTextSize(0.03);
3665     pLegendXClDN.SetFillColor(10);
3666     pLegendXClDN.SetBorderSize(1);
3667     
3668     htmp = fhDeltaCellClusterRNCells->ProjectionX("hrdn_nocut",0,-1);
3669     if(htmp){
3670       htmp->SetMinimum(1);
3671       htmp->Rebin(rbDR);
3672       htmp->SetTitle("r clusters - r cells for n cells in cluster > threshold");
3673       htmp->SetAxisRange(-50,50,"X");
3674       htmp->Draw("HE");
3675       pLegendXClDN.AddEntry(htmp,"No cut","L");
3676       
3677       for (Int_t i = 0; i < ncellcuts; i++) {
3678         if(i < ncellcuts-1) htmp = fhDeltaCellClusterRNCells->ProjectionX(Form("hrdn_cut%d",i),ncellcut[i],ncellcut[i]);
3679         else htmp = fhDeltaCellClusterRNCells->ProjectionX(Form("hrdn_cut%d",i),ncellcut[i],-1);
3680         htmp->SetLineColor(ecutcolor[i]);
3681         htmp->Rebin(rbDR);
3682         htmp->Draw("same HE");
3683         if(i < ncellcuts-1) pLegendXClDN.AddEntry(htmp,Form("n = %1.1d",ncellcut[i]-1),"L");
3684         else pLegendXClDN.AddEntry(htmp,Form("n >= %1.1d",ncellcut[i]-1),"L");
3685         
3686       }
3687     }
3688     pLegendXClDN.Draw();
3689     
3690     //X
3691     cxdn->cd(2) ; 
3692     gPad->SetLogy();
3693     gPad->SetGridy();
3694     htmp = fhDeltaCellClusterXNCells->ProjectionX("hxdn_nocut",0,-1);
3695     if(htmp){
3696       htmp->SetMinimum(1);
3697       htmp->Rebin(rbDX);
3698       htmp->SetTitle("x clusters - x cells for n cells in cluster > threshold");
3699       htmp->SetAxisRange(-50,50,"X");
3700       htmp->Draw("HE");
3701       
3702       for (Int_t i = 0; i < ncellcuts; i++) {
3703         if(i < ncellcuts-1)htmp = fhDeltaCellClusterXNCells->ProjectionX(Form("hxdn_cut%d",i),ncellcut[i],ncellcut[i]);
3704         else htmp = fhDeltaCellClusterXNCells->ProjectionX(Form("hxdn_cut%d",i),ncellcut[i],-1);
3705         htmp->SetLineColor(ecutcolor[i]);
3706         htmp->Rebin(rbDX);
3707         htmp->Draw("same HE");
3708         
3709       }
3710     }
3711     //Y
3712     cxdn->cd(3) ; 
3713     gPad->SetLogy();
3714     gPad->SetGridy();
3715     htmp = fhDeltaCellClusterYNCells->ProjectionX("hydn_nocut",0,-1);
3716     if(htmp){
3717       htmp->SetMinimum(1);
3718       htmp->Rebin(rbDY);
3719       htmp->SetTitle("y clusters - y cells for n cells in cluster > threshold");
3720       htmp->SetAxisRange(-50,50,"X");
3721       htmp->Draw("HE");
3722       
3723       for (Int_t i = 0; i < ncellcuts; i++) {
3724         if(i < ncellcuts-1) htmp = fhDeltaCellClusterYNCells->ProjectionX(Form("hydn_cut%d",i),ncellcut[i],ncellcut[i]);
3725         else htmp = fhDeltaCellClusterYNCells->ProjectionX(Form("hydn_cut%d",i),ncellcut[i],-1);
3726         htmp->SetLineColor(ecutcolor[i]);
3727         htmp->Rebin(rbDY);
3728         htmp->Draw("same HE");
3729         
3730       }
3731     }
3732     //Z
3733     cxdn->cd(4) ; 
3734     gPad->SetLogy();
3735     gPad->SetGridy();
3736     
3737     htmp = fhDeltaCellClusterZNCells->ProjectionX("hzdn_nocut",0,-1);
3738     if(htmp){
3739       htmp->SetMinimum(1);
3740       htmp->Rebin(rbDZ);
3741       htmp->SetTitle("z clusters - z cells for ncells in cluster > threshold");
3742       htmp->SetAxisRange(-50,50,"X");
3743       htmp->Draw("HE");
3744       
3745       for (Int_t i = 0; i < ncellcuts; i++) {
3746         if(i < ncellcuts-1)htmp = fhDeltaCellClusterZNCells->ProjectionX(Form("hzdn_cut%d",i),ncellcut[i],ncellcut[i]);
3747         else htmp = fhDeltaCellClusterZNCells->ProjectionX(Form("hzdn_cut%d",i),ncellcut[i],-1);
3748         htmp->SetLineColor(ecutcolor[i]);
3749         htmp->Rebin(rbDZ);
3750         htmp->Draw("same HE");
3751         
3752       }
3753     }
3754     
3755     sprintf(name,"QA_%s_DeltaClusterCellX_Y_Z_R_NCellsCut.eps",fCalorimeter.Data());
3756     cxdn->Print(name); printf("Create plot %s\n",name);
3757     
3758         }
3759   
3760   //----------------------------------------------------------
3761   //Reconstructed clusters energy-eta-phi distributions, matched with tracks
3762   //----------------------------------------------------------
3763   TH1F *        hEChargedClone   = 0 ;
3764   TH1F *        hPtChargedClone  = 0 ;
3765   TH1F *        hEtaChargedClone = 0 ;
3766   TH1F *        hPhiChargedClone = 0 ;
3767         if(fFillAllTH12){
3768     hEChargedClone   = (TH1F*)   fhECharged->Clone(Form("%sClone",fhECharged->GetName()));
3769     hPtChargedClone  = (TH1F*)   fhPtCharged->Clone(Form("%sClone",fhPtCharged->GetName()));
3770     hEtaChargedClone = (TH1F*)   fhEtaCharged->Clone(Form("%sClone",fhEtaCharged->GetName()));
3771     hPhiChargedClone = (TH1F*)   fhPhiCharged->Clone(Form("%sClone",fhPhiCharged->GetName()));
3772     
3773     sprintf(cname,"QA_%s_rectrackmatch",fCalorimeter.Data());
3774     TCanvas  * ccltm = new TCanvas(cname, "Reconstructed clusters E-Phi-Eta, matched with tracks", 1200, 400) ;
3775     ccltm->Divide(3, 1);
3776     
3777     ccltm->cd(1) ; 
3778     if(fhECharged->GetEntries() > 0) gPad->SetLogy();
3779     fhECharged->Rebin(rbE);
3780     fhECharged->SetAxisRange(ptmin,ptmax,"X");
3781     fhECharged->SetMinimum(1);
3782     fhECharged->Draw();
3783     
3784     ccltm->cd(2) ; 
3785     if(fhPhiCharged->GetEntries() > 0) gPad->SetLogy();
3786     fhPhiCharged->Rebin(rbPhi);
3787     fhPhiCharged->SetAxisRange(phimin,phimax,"X");
3788     fhPhiCharged->Draw();
3789     fhPhiCharged->Draw();
3790     
3791     ccltm->cd(3) ;
3792     if(fhEtaCharged->GetEntries() > 0) gPad->SetLogy();
3793     fhEtaCharged->Rebin(rbEta);
3794     fhEtaCharged->SetAxisRange(etamin,etamax,"X");      
3795     fhEtaCharged->Draw();
3796     fhEtaCharged->Draw();
3797     
3798     sprintf(name,"QA_%s_ClusterEnergyPhiEta_TrackMatched.eps",fCalorimeter.Data());
3799     ccltm->Print(name); printf("Plot: %s\n",name);
3800     
3801     //----------------------------------------------------------
3802     // Ratio  of reconstructed clusters energy-eta-phi distributions, matched with tracks over all
3803     //----------------------------------------------------------
3804     
3805     sprintf(cname,"%s_QA_ChargedRatio",fCalorimeter.Data());
3806     TCanvas  * ccharge = new TCanvas(cname, "Charged clusters over all clusters", 1200, 400) ;
3807     ccharge->Divide(3, 1);
3808     
3809     ccharge->cd(1) ; 
3810     fhECharged->Sumw2();
3811     fhE->Sumw2();
3812     fhECharged->Divide(fhE);
3813     fhECharged->SetAxisRange(ptmin,ptmax,"X");
3814     fhECharged->SetMaximum(0.5);
3815     fhECharged->SetYTitle("track-matched clusters / all clusters");
3816     fhECharged->Draw("HE");
3817     
3818     ccharge->cd(2) ; 
3819     fhPhiCharged->Sumw2();
3820     fhPhi->Rebin(rbPhi);
3821     fhPhi->Sumw2();
3822     fhPhiCharged->Divide(fhPhi);
3823     fhPhiCharged->SetAxisRange(phimin,phimax,"X");
3824     fhPhiCharged->SetMaximum(0.5);
3825     fhPhiCharged->SetYTitle("track-matched clusters / all clusters");
3826     fhPhiCharged->Draw("HE");
3827     
3828     ccharge->cd(3) ; 
3829     fhEtaCharged->Sumw2();
3830     fhEta->Rebin(rbEta);
3831     fhEta->Sumw2();
3832     fhEtaCharged->Divide(fhEta);
3833     fhEtaCharged->SetAxisRange(etamin,etamax,"X");
3834     fhEtaCharged->SetMaximum(0.5);
3835     fhEtaCharged->SetYTitle("track-matched clusters / all clusters");
3836     fhEtaCharged->Draw("HE");
3837     
3838     sprintf(name,"QA_%s_ClustersMatchedToAllRatios.eps",fCalorimeter.Data());
3839     ccharge->Print(name); printf("Create plot %s\n",name);
3840         }
3841   //------------------------------------------- 
3842   // N Cells - N Clusters - N Cells per cluster
3843   //-------------------------------------------
3844         sprintf(cname,"QA_%s_nclustercells",fCalorimeter.Data());
3845         TCanvas  * cN = new TCanvas(cname, " Number of CaloClusters and CaloCells", 800, 1200) ;
3846         cN->Divide(2, 3);
3847         
3848         cN->cd(1) ; 
3849         
3850         TLegend pLegendN(0.7,0.6,0.9,0.8);
3851         pLegendN.SetTextSize(0.03);
3852         pLegendN.AddEntry(fhNClusters,"all modules","L");
3853         pLegendN.SetFillColor(10);
3854         pLegendN.SetBorderSize(1);
3855         
3856         if(fhNClusters->GetEntries() > 0) gPad->SetLogy();
3857         gPad->SetLogx();
3858         fhNClusters->SetLineColor(1);
3859         
3860         Int_t rbN = 1;
3861         if(fhNClusters->GetNbinsX()> nbins) rbN = fhNClusters->GetNbinsX()/nbins;
3862         
3863         fhNClusters->SetAxisRange(nmin,nmax,"X");
3864         fhNClusters->Draw("HE");
3865         for(Int_t imod = 0; imod < fNModules; imod++){
3866                 fhNClustersMod[imod]->SetAxisRange(nmin,nmax,"X");
3867                 fhNClustersMod[imod]->SetLineColor(modColorIndex[imod]);
3868                 fhNClustersMod[imod]->Draw("same");
3869                 pLegendN.AddEntry(fhNClustersMod[imod],Form("module %d",imod),"L");
3870         }
3871         pLegendN.Draw();
3872         
3873         cN->cd(2) ; 
3874         gPad->SetLogx();
3875         for(Int_t imod = 1; imod < fNModules; imod++){
3876                 htmp = (TH1D*)fhNClustersMod[imod]->Clone(Form("hNClustersRat%d",imod));
3877                 htmp->Divide(fhNClustersMod[0]);
3878                 htmp->SetLineColor(modColorIndex[imod]);
3879                 if(imod==1){
3880                         htmp->SetTitle("Ratio # clusters in  module X / module 0");
3881                         htmp->SetMaximum(5);
3882                         htmp->SetMinimum(0);
3883                         htmp->Draw("HE");
3884                 }
3885                 else 
3886                         htmp->Draw("same HE");
3887                 
3888         }
3889         
3890         cN->cd(3) ; 
3891         if(fhNCells->GetEntries() > 0) gPad->SetLogy();
3892         gPad->SetLogx();
3893         fhNCells->SetLineColor(1);
3894         fhNCells->SetAxisRange(nmin,nmax,"X");
3895         fhNCells->Draw("HE");
3896         for(Int_t imod = 0; imod < fNModules; imod++){
3897                 fhNCellsMod[imod]->SetAxisRange(nmin,nmax,"X");
3898                 fhNCellsMod[imod]->SetLineColor(modColorIndex[imod]);
3899                 fhNCellsMod[imod]->Draw("same HE");
3900         }
3901         
3902         
3903         cN->cd(4) ; 
3904         gPad->SetLogx();
3905         for(Int_t imod = 1; imod < fNModules; imod++){
3906                 htmp = (TH1D*)fhNCellsMod[imod]->Clone(Form("hNCellsRat%d",imod));
3907                 htmp->Divide(fhNCellsMod[0]);
3908                 htmp->SetLineColor(modColorIndex[imod]);
3909                 if(imod==1){
3910                         htmp->SetTitle("Ratio # cells in  module X / module 0");
3911                         htmp->SetMaximum(5);
3912                         htmp->SetMinimum(0);
3913                         htmp->Draw("HE");
3914                 }
3915                 else 
3916                         htmp->Draw("same HE");
3917                 
3918         }
3919         
3920         cN->cd(5) ; 
3921         if(fhNCellsPerCluster->GetEntries() > 0) gPad->SetLogy();
3922         gPad->SetLogx();
3923         TH1D *cpc = fhNCellsPerCluster->ProjectionY("cpc",-1,-1,-1,-1);
3924         cpc->SetLineColor(1);
3925         cpc->SetTitle("# cells per cluster");
3926         cpc->Draw("HE"); 
3927         TH1D ** hNCellsCluster1D = new TH1D*[fNModules];
3928         
3929         for(Int_t imod = 0; imod < fNModules; imod++){
3930                 hNCellsCluster1D[imod] = fhNCellsPerClusterMod[imod]->ProjectionY(Form("cpc_%d",imod),-1,-1);
3931                 hNCellsCluster1D[imod]->SetLineColor(modColorIndex[imod]);
3932                 hNCellsCluster1D[imod]->Draw("same HE");
3933         }
3934         
3935         
3936         cN->cd(6) ; 
3937         gPad->SetLogx();
3938         for(Int_t imod = 1; imod < fNModules; imod++){
3939                 htmp = (TH1D*)hNCellsCluster1D[imod]->Clone(Form("hNClustersCells1DRat%d",imod));
3940                 htmp->Divide(hNCellsCluster1D[0]);
3941                 htmp->SetLineColor(modColorIndex[imod]);
3942                 if(imod==1){
3943                         htmp->SetTitle("Ratio # cells per cluster in  module X / module 0");
3944       //htmp->SetAxisRange(ptmin,ptmax,"X");
3945                         htmp->SetMaximum(3.5);
3946                         htmp->SetMinimum(0);
3947                         htmp->Draw("HE");
3948                 }
3949                 else 
3950                         htmp->Draw("same HE");
3951                 
3952         }
3953         sprintf(name,"QA_%s_NumberCaloClustersAndCaloCells.eps",fCalorimeter.Data());
3954         cN->Print(name); printf("Print plot %s\n",name);
3955         
3956   //----------------------------------------------------        
3957   // Cell Time histograms, time only available in ESDs
3958   //----------------------------------------------------
3959         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
3960     
3961                 sprintf(cname,"QA_%s_cellstime",fCalorimeter.Data());
3962                 TCanvas  * ctime = new TCanvas(cname, " Cells time", 1200, 400) ;
3963                 ctime->Divide(3, 1);
3964                 
3965                 Int_t rbTime = 1;
3966                 if(fhTime->GetNbinsX()> ntimebins) rbTime = fhTime->GetNbinsX()/ntimebins;
3967                 
3968                 ctime->cd(1) ; 
3969                 if(fhTime->GetEntries() > 0) gPad->SetLogy();
3970                 fhTime->Rebin(rbTime);
3971                 fhTime->SetAxisRange(timemin,timemax,"X");
3972                 fhTime->Draw();
3973     
3974                 ctime->cd(2) ; 
3975                 fhTimeId->SetTitleOffset(1.8,"Y");
3976                 fhTimeId->SetAxisRange(timemin,timemax,"X");
3977                 fhTimeId->Draw("colz");
3978     
3979                 ctime->cd(3) ; 
3980                 fhTimeAmp->SetTitle("Cell Energy vs Cell Time");
3981                 fhTimeAmp->SetTitleOffset(1.8,"Y");
3982                 fhTimeAmp->SetAxisRange(timemin,timemax,"Y");
3983                 fhTimeAmp->SetAxisRange(ptmin,ptmax,"X");               
3984                 fhTimeAmp->Draw("colz");
3985     
3986                 sprintf(name,"QA_%s_CellsTime.eps",fCalorimeter.Data());
3987                 ctime->Print(name); printf("Plot: %s\n",name);
3988         }
3989         
3990         
3991   //---------------------------------
3992   //Grid of cell per module plots 
3993   //---------------------------------
3994         {
3995     //Number of entries per cell
3996     gStyle->SetPadRightMargin(0.15);
3997     sprintf(cname,"%s_QA_GridCellEntries",fCalorimeter.Data());
3998     TCanvas *cgrid   = new TCanvas("cgrid","Number of entries per cell", 12,12,800,400);
3999     if(fNModules%2 == 0)
4000       cgrid->Divide(fNModules/2,2); 
4001     else
4002       cgrid->Divide(fNModules/2+1,2); 
4003                 
4004     for(Int_t imod = 0; imod < fNModules ; imod++){
4005       cgrid->cd(imod+1);
4006       gPad->SetLogz();
4007       gPad->SetGridy();
4008       gPad->SetGridx();
4009       //fhGridCellsMod[imod]->GetYAxis()->SetTitleColor(1);
4010       fhGridCellsMod[imod]->SetZTitle("Counts    ");
4011       fhGridCellsMod[imod]->SetYTitle("row (phi direction)    ");
4012       //fhGridCellsMod[imod]->SetLabelSize(0.025,"z");
4013       fhGridCellsMod[imod]->Draw("colz");
4014     }
4015     sprintf(name,"QA_%s_GridCellsEntries.eps",fCalorimeter.Data());
4016     cgrid->Print(name); printf("Create plot %s\n",name);
4017     
4018     sprintf(cname,"%s_QA_GridCellAccumEnergy",fCalorimeter.Data());
4019     TCanvas *cgridE   = new TCanvas("cgridE","Summed energy per cell", 12,12,800,400);
4020     if(fNModules%2 == 0)
4021       cgridE->Divide(fNModules/2,2); 
4022     else
4023       cgridE->Divide(fNModules/2+1,2); 
4024     for(Int_t imod = 0; imod < fNModules ; imod++){
4025       cgridE->cd(imod+1);
4026       gPad->SetLogz();
4027       gPad->SetGridy();
4028       gPad->SetGridx();
4029       //fhGridCellsEMod[imod]->SetLabelSize(0.025,"z");
4030       fhGridCellsEMod[imod]->SetZTitle("Accumulated Energy (GeV)    ");
4031       fhGridCellsEMod[imod]->SetYTitle("row (phi direction)    ");
4032       fhGridCellsEMod[imod]->Draw("colz");
4033     }
4034     sprintf(name,"QA_%s_GridCellsAccumEnergy.eps",fCalorimeter.Data());
4035     cgridE->Print(name); printf("Create plot %s\n",name);
4036     
4037     //Accumulated energy per cell
4038     sprintf(cname,"%s_QA_GridCellAverageEnergy",fCalorimeter.Data());
4039     TCanvas *cgridEA   = new TCanvas("cgridEA","Average energy per cell", 12,12,800,400);
4040     if(fNModules%2 == 0)          
4041       cgridEA->Divide(fNModules/2,2);
4042     else
4043       cgridEA->Divide(fNModules/2+1,2);  
4044     for(Int_t imod = 0; imod < fNModules ; imod++){
4045       cgridEA->cd(imod+1);
4046       gPad->SetLogz();
4047       gPad->SetGridy();
4048       gPad->SetGridx();
4049       //fhGridCellsEMod[imod]->SetLabelSize(0.025,"z");
4050       fhGridCellsEMod[imod]->SetZTitle("Average Energy (GeV)    ");
4051       fhGridCellsEMod[imod]->Divide(fhGridCellsMod[imod]);
4052       fhGridCellsEMod[imod]->Draw("colz");
4053     }
4054     sprintf(name,"QA_%s_GridCellsAverageEnergy.eps",fCalorimeter.Data());
4055     cgridEA->Print(name); printf("Create plot %s\n",name);
4056                 
4057     //Accumulated Time per cell, E > 0.5 GeV
4058                 
4059     sprintf(cname,"%s_QA_GridCellAccumTime",fCalorimeter.Data());
4060     TCanvas *cgridT   = new TCanvas("cgridT","Summed time per cell", 12,12,800,400);
4061     if(fNModules%2 == 0)
4062       cgridT->Divide(fNModules/2,2); 
4063     else
4064       cgridE->Divide(fNModules/2+1,2); 
4065     for(Int_t imod = 0; imod < fNModules ; imod++){
4066       cgridT->cd(imod+1);
4067       gPad->SetLogz();
4068       gPad->SetGridy();
4069       gPad->SetGridx();
4070       //fhGridCellsTimeMod[imod]->SetLabelSize(0.025,"z");
4071       fhGridCellsTimeMod[imod]->SetZTitle("Accumulated Time (ns)    ");
4072       fhGridCellsTimeMod[imod]->SetYTitle("row (phi direction)    ");
4073       fhGridCellsTimeMod[imod]->Draw("colz");
4074     }
4075     sprintf(name,"QA_%s_GridCellsAccumTime.eps",fCalorimeter.Data());
4076     cgridT->Print(name); printf("Create plot %s\n",name);
4077                 
4078         }
4079         
4080   //---------------------------------------------
4081   //Calorimeter Correlation, PHOS vs EMCAL
4082   //---------------------------------------------
4083         if(fCorrelateCalos){
4084                 
4085                 sprintf(cname,"QA_%s_CaloCorr_EMCALvsPHOS",fCalorimeter.Data());
4086                 TCanvas  * ccorr = new TCanvas(cname, " EMCAL vs PHOS", 400, 400) ;
4087                 ccorr->Divide(2, 2);
4088     
4089                 ccorr->cd(1) ; 
4090     //gPad->SetLogy();
4091     //gPad->SetLogx();
4092                 fhCaloCorrNClusters->SetAxisRange(nmin,nmax,"X");
4093                 fhCaloCorrNClusters->SetAxisRange(nmin,nmax,"Y");               
4094                 fhCaloCorrNClusters ->Draw();
4095     
4096                 ccorr->cd(2) ; 
4097     //gPad->SetLogy();
4098     //gPad->SetLogx();
4099                 fhCaloCorrNCells->SetAxisRange(nmin,nmax,"X");
4100                 fhCaloCorrNCells->SetAxisRange(nmin,nmax,"Y");          
4101                 fhCaloCorrNCells->Draw();
4102     
4103     //gPad->SetLogy();
4104     //gPad->SetLogx();
4105                 fhCaloCorrEClusters->SetAxisRange(ptmin,ptmax,"X");
4106                 fhCaloCorrEClusters->SetAxisRange(ptmin,ptmax,"Y");             
4107                 fhCaloCorrEClusters->Draw();
4108     
4109                 ccorr->cd(4) ; 
4110     //gPad->SetLogy();
4111     //gPad->SetLogx();
4112                 fhCaloCorrECells->SetAxisRange(ptmin,ptmax,"X");
4113                 fhCaloCorrECells->SetAxisRange(ptmin,ptmax,"Y");                
4114                 fhCaloCorrECells->Draw();
4115     
4116                 sprintf(name,"QA_%s_CaloCorr_EMCALvsPHOS.eps",fCalorimeter.Data());
4117                 ccorr->Print(name); printf("Plot: %s\n",name);
4118         }
4119   
4120   //----------------------------
4121   //Invariant mass
4122   //-----------------------------
4123         
4124         Int_t imbinmin = -1;
4125         Int_t imbinmax = -1;
4126         
4127         if(fhIM->GetEntries() > 1){
4128                 Int_t nebins  = fhIM->GetNbinsX();
4129                 Int_t emax = (Int_t) fhIM->GetXaxis()->GetXmax();
4130                 Int_t emin = (Int_t) fhIM->GetXaxis()->GetXmin();
4131                 if (emin != 0 ) printf("emin != 0 \n");
4132     //printf("IM: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
4133                 
4134                 sprintf(cname,"QA_%s_IM",fCalorimeter.Data());
4135     //  printf("c5\n");
4136                 TCanvas  * c5 = new TCanvas(cname, "Invariant mass", 600, 400) ;
4137                 c5->Divide(2, 3);
4138                 
4139                 c5->cd(1) ; 
4140     //fhIM->SetLineColor(4);
4141     //fhIM->Draw();
4142                 imbinmin = 0;
4143                 imbinmax =  (Int_t) (1-emin)*nebins/emax;
4144                 TH1D *pyim1 = fhIM->ProjectionY(Form("%s_py1",fhIM->GetName()),imbinmin,imbinmax);
4145                 pyim1->SetTitle("E_{pair} < 1 GeV");
4146                 pyim1->SetLineColor(1);
4147                 pyim1->Draw();
4148                 TLegend pLegendIM(0.7,0.6,0.9,0.8);
4149                 pLegendIM.SetTextSize(0.03);
4150                 pLegendIM.AddEntry(pyim1,"all modules","L");
4151                 pLegendIM.SetFillColor(10);
4152                 pLegendIM.SetBorderSize(1);
4153     //FIXME
4154                 for(Int_t imod = 0; imod < fNModules; imod++){
4155                         pyim1 = fhIMMod[imod]->ProjectionY(Form("%s_py1",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4156                         pLegendIM.AddEntry(pyim1,Form("module %d",imod),"L");
4157                         pyim1->SetLineColor(imod+1);
4158                         pyim1->Draw("same");
4159                 }
4160                 pLegendIM.Draw();
4161                 
4162                 c5->cd(2) ; 
4163                 imbinmin =  (Int_t) (1-emin)*nebins/emax;
4164                 imbinmax =  (Int_t) (2-emin)*nebins/emax;
4165                 TH1D *pyim2 = fhIM->ProjectionY(Form("%s_py2",fhIM->GetName()),imbinmin,imbinmax);
4166                 pyim2->SetTitle("1 < E_{pair} < 2 GeV");
4167                 pyim2->SetLineColor(1);
4168                 pyim2->Draw();
4169                 for(Int_t imod = 0; imod < fNModules; imod++){
4170                         pyim2 = fhIMMod[imod]->ProjectionY(Form("%s_py2",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4171                         pyim2->SetLineColor(imod+1);
4172                         pyim2->Draw("same");
4173                 }
4174                 
4175                 c5->cd(3) ; 
4176                 imbinmin =  (Int_t) (2-emin)*nebins/emax;
4177                 imbinmax =  (Int_t) (3-emin)*nebins/emax;
4178                 TH1D *pyim3 = fhIM->ProjectionY(Form("%s_py3",fhIM->GetName()),imbinmin,imbinmax);
4179                 pyim3->SetTitle("2 < E_{pair} < 3 GeV");
4180                 pyim3->SetLineColor(1);
4181                 pyim3->Draw();
4182                 for(Int_t imod = 0; imod < fNModules; imod++){
4183                         pyim3 = fhIMMod[imod]->ProjectionY(Form("%s_py3",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4184                         pyim3->SetLineColor(imod+1);
4185                         pyim3->Draw("same");
4186                 }
4187                 
4188                 c5->cd(4) ;
4189                 imbinmin =  (Int_t) (3-emin)*nebins/emax;
4190                 imbinmax =  (Int_t) (4-emin)*nebins/emax;
4191                 TH1D *pyim4 = fhIM->ProjectionY(Form("%s_py4",fhIM->GetName()),imbinmin,imbinmax);
4192                 pyim4->SetTitle("3 < E_{pair} < 4 GeV");
4193                 pyim4->SetLineColor(1);
4194                 pyim4->Draw();
4195                 for(Int_t imod = 0; imod < fNModules; imod++){
4196                         pyim4 = fhIMMod[imod]->ProjectionY(Form("%s_py4",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4197                         pyim4->SetLineColor(imod+1);
4198                         pyim4->Draw("same");
4199                 }
4200                 
4201                 c5->cd(5) ;
4202                 imbinmin =  (Int_t) (4-emin)*nebins/emax;
4203                 imbinmax =  (Int_t) (5-emin)*nebins/emax;
4204                 TH1D *pyim5 = fhIM->ProjectionY(Form("%s_py5",fhIM->GetName()),imbinmin,imbinmax);
4205                 pyim5->SetTitle("4< E_{pair} < 5 GeV");
4206                 pyim5->SetLineColor(1);
4207                 pyim5->Draw();
4208                 for(Int_t imod = 0; imod < fNModules; imod++){
4209                         pyim5 = fhIMMod[imod]->ProjectionY(Form("%s_py5",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4210                         pyim5->SetLineColor(imod+1);
4211                         pyim5->Draw("same");
4212                 }
4213                 
4214                 c5->cd(6) ;
4215                 imbinmin =  (Int_t) (5-emin)*nebins/emax;
4216                 imbinmax =  -1;
4217                 TH1D *pyim10 = fhIM->ProjectionY(Form("%s_py6",fhIM->GetName()),imbinmin,imbinmax);
4218                 pyim10->SetTitle("E_{pair} > 5 GeV");
4219                 pyim10->SetLineColor(1);
4220                 pyim10->Draw();
4221                 for(Int_t imod = 0; imod < fNModules; imod++){
4222                         pyim10 = fhIMMod[imod]->ProjectionY(Form("%s_py6",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4223                         pyim10->SetLineColor(imod+1);
4224                         pyim10->Draw("same");
4225                 }
4226                 
4227                 sprintf(name,"QA_%s_InvariantMass.eps",fCalorimeter.Data());
4228                 c5->Print(name); printf("Plot: %s\n",name);
4229         }
4230         
4231   //--------------------------------------------------
4232   //Invariant mass, clusters with more than one cell
4233   //-------------------------------------------------
4234         if(fhIMCellCut->GetEntries() > 1){
4235                 Int_t nebins  = fhIMCellCut->GetNbinsX();
4236                 Int_t emax = (Int_t) fhIMCellCut->GetXaxis()->GetXmax();
4237                 Int_t emin = (Int_t) fhIMCellCut->GetXaxis()->GetXmin();
4238                 if (emin != 0 ) printf("emin != 0 \n");
4239     //printf("IMCellCut: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
4240                 
4241                 sprintf(cname,"QA_%s_IMCellCut",fCalorimeter.Data());
4242     //  printf("c5cc\n");
4243                 TCanvas  * c5cc = new TCanvas(cname, "Invariant mass, Cell Cut", 600, 400) ;
4244                 c5cc->Divide(2, 3);
4245                 
4246                 c5cc->cd(1) ; 
4247     //fhIMCellCut->SetLineColor(4);
4248     //fhIMCellCut->Draw();
4249                 imbinmin = 0;
4250                 imbinmax =  (Int_t) (1-emin)*nebins/emax;
4251                 TH1D *pyimcc1 = fhIMCellCut->ProjectionY(Form("%s_py1",fhIMCellCut->GetName()),imbinmin,imbinmax);
4252                 pyimcc1->SetTitle("E_{pair} < 1 GeV");
4253                 pyimcc1->SetLineColor(1);
4254                 pyimcc1->Draw();
4255                 TLegend pLegendIMCellCut(0.7,0.6,0.9,0.8);
4256                 pLegendIMCellCut.SetTextSize(0.03);
4257                 pLegendIMCellCut.AddEntry(pyimcc1,"all modules","L");
4258                 pLegendIMCellCut.SetFillColor(10);
4259                 pLegendIMCellCut.SetBorderSize(1);
4260                 
4261                 for(Int_t imod = 0; imod < fNModules; imod++){
4262                         pyimcc1 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4263                         pLegendIMCellCut.AddEntry(pyimcc1,Form("module %d",imod),"L");
4264                         pyimcc1->SetLineColor(imod+1);
4265                         pyimcc1->Draw("same");
4266                 }
4267                 pLegendIMCellCut.Draw();
4268                 
4269                 c5cc->cd(2) ; 
4270                 imbinmin =  (Int_t) (1-emin)*nebins/emax;
4271                 imbinmax =  (Int_t) (2-emin)*nebins/emax;
4272                 TH1D *pyimcc2 = fhIMCellCut->ProjectionY(Form("%s_py2",fhIMCellCut->GetName()),imbinmin,imbinmax);
4273                 pyimcc2->SetTitle("1 < E_{pair} < 2 GeV");
4274                 pyimcc2->SetLineColor(1);
4275                 pyimcc2->Draw();
4276                 for(Int_t imod = 0; imod < fNModules; imod++){
4277                         pyimcc2 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4278                         pyimcc2->SetLineColor(imod+1);
4279                         pyimcc2->Draw("same");
4280                 }
4281                 
4282                 c5cc->cd(3) ; 
4283                 imbinmin =  (Int_t) (2-emin)*nebins/emax;
4284                 imbinmax =  (Int_t) (3-emin)*nebins/emax;
4285                 TH1D *pyimcc3 = fhIMCellCut->ProjectionY(Form("%s_py3",fhIMCellCut->GetName()),imbinmin,imbinmax);
4286                 pyimcc3->SetTitle("2 < E_{pair} < 3 GeV");
4287                 pyimcc3->SetLineColor(1);
4288                 pyimcc3->Draw();
4289                 for(Int_t imod = 0; imod < fNModules; imod++){
4290                         pyimcc3 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4291                         pyimcc3->SetLineColor(imod+1);
4292                         pyimcc3->Draw("same");
4293                 }
4294                 
4295                 c5cc->cd(4) ;
4296                 imbinmin =  (Int_t) (3-emin)*nebins/emax;
4297                 imbinmax =  (Int_t) (4-emin)*nebins/emax;
4298                 TH1D *pyimcc4 = fhIMCellCut->ProjectionY(Form("%s_py4",fhIMCellCut->GetName()),imbinmin,imbinmax);
4299                 pyimcc4->SetTitle("3 < E_{pair} < 4 GeV");
4300                 pyimcc4->SetLineColor(1);
4301                 pyimcc4->Draw();
4302                 for(Int_t imod = 0; imod < fNModules; imod++){
4303                         pyimcc4 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py5",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4304                         pyimcc4->SetLineColor(imod+1);
4305                         pyimcc4->Draw("same");
4306                 }
4307                 
4308                 c5cc->cd(5) ;
4309                 imbinmin =  (Int_t) (4-emin)*nebins/emax;
4310                 imbinmax =  (Int_t) (5-emin)*nebins/emax;
4311                 TH1D *pyimcc5cc = fhIMCellCut->ProjectionY(Form("%s_py5",fhIMCellCut->GetName()),imbinmin,imbinmax);
4312                 pyimcc5cc->SetTitle("4< E_{pair} < 5 GeV");
4313                 pyimcc5cc->SetLineColor(1);
4314                 pyimcc5cc->Draw();
4315                 for(Int_t imod = 0; imod < fNModules; imod++){
4316                         pyimcc5cc = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py5",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4317                         pyimcc5cc->SetLineColor(imod+1);
4318                         pyimcc5cc->Draw("same");
4319                 }
4320                 
4321                 c5cc->cd(6) ;
4322                 imbinmin =  (Int_t) (5-emin)*nebins/emax;
4323                 imbinmax =  -1;
4324                 TH1D *pyimcc10 = fhIMCellCut->ProjectionY(Form("%s_py6",fhIMCellCut->GetName()),imbinmin,imbinmax);
4325                 pyimcc10->SetTitle("E_{pair} > 5 GeV");
4326                 pyimcc10->SetLineColor(1);
4327                 pyimcc10->Draw();
4328                 for(Int_t imod = 0; imod < fNModules; imod++){
4329                         pyimcc10 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4330                         pyimcc10->SetLineColor(imod+1);
4331                         pyimcc10->Draw("same");
4332                 }
4333                 
4334                 sprintf(name,"QA_%s_InvariantMass_CellCut.eps",fCalorimeter.Data());
4335                 c5cc->Print(name); printf("Plot: %s\n",name);
4336         }
4337         
4338         
4339   //Asymmetry
4340         if(fhAsym->GetEntries() > 1){
4341                 Int_t nebins  = fhAsym->GetNbinsX();
4342                 Int_t emax = (Int_t) fhAsym->GetXaxis()->GetXmax();
4343                 Int_t emin = (Int_t) fhAsym->GetXaxis()->GetXmin();
4344                 if (emin != 0 ) printf("emin != 0 \n");
4345     //printf("Asym: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
4346                 
4347                 sprintf(cname,"QA_%s_Asym",fCalorimeter.Data());
4348     //  printf("c5\n");
4349                 TCanvas  * c5b = new TCanvas(cname, "Asymmetry", 400, 400) ;
4350                 c5b->Divide(2, 2);
4351                 
4352                 c5b->cd(1) ; 
4353                 fhAsym->SetTitleOffset(1.6,"Y");
4354                 fhAsym->SetLineColor(4);
4355                 fhAsym->Draw();
4356                 
4357                 c5b->cd(2) ; 
4358                 imbinmin = 0;
4359                 imbinmax = (Int_t) (5-emin)*nebins/emax;
4360                 TH1D *pyAsym5 = fhAsym->ProjectionY(Form("%s_py5",fhAsym->GetName()),imbinmin,imbinmax);
4361                 pyAsym5->SetTitle("E_{pair} < 5 GeV");
4362                 pyAsym5->SetLineColor(4);
4363                 pyAsym5->Draw();
4364                 
4365                 c5b->cd(3) ; 
4366                 imbinmin = (Int_t) (5-emin)*nebins/emax;
4367                 imbinmax = (Int_t) (10-emin)*nebins/emax;
4368                 TH1D *pyAsym510 = fhAsym->ProjectionY(Form("%s_py510",fhAsym->GetName()),imbinmin,imbinmax);
4369                 pyAsym510->SetTitle("5 < E_{pair} < 10 GeV");
4370                 pyAsym510->SetLineColor(4);
4371                 pyAsym510->Draw();
4372                 
4373                 c5b->cd(4) ;
4374                 imbinmin = (Int_t) (10-emin)*nebins/emax;
4375                 imbinmax = -1;
4376                 TH1D *pyAsym10 = fhAsym->ProjectionY(Form("%s_py10",fhAsym->GetName()),imbinmin,imbinmax);
4377                 pyAsym10->SetTitle("E_{pair} > 10 GeV");
4378                 pyAsym10->SetLineColor(4);
4379                 pyAsym10->Draw();
4380                 
4381                 sprintf(name,"QA_%s_Asymmetry.eps",fCalorimeter.Data());
4382                 c5b->Print(name); printf("Plot: %s\n",name);
4383         }
4384         
4385         
4386         if(IsDataMC()){
4387     //Reconstructed vs MC distributions
4388     //printf("c6\n");
4389     sprintf(cname,"QA_%s_recvsmc",fCalorimeter.Data());
4390     TCanvas  * c6 = new TCanvas(cname, "Reconstructed vs MC distributions", 400, 400) ;
4391     c6->Divide(2, 2);
4392     
4393     c6->cd(1) ; 
4394     fh2E->SetTitleOffset(1.6,"Y");
4395     fh2E->SetLineColor(4);
4396     fh2E->Draw();
4397     
4398     c6->cd(2) ; 
4399     fh2Pt->SetTitleOffset(1.6,"Y");
4400     fh2Pt->SetLineColor(4);
4401     fh2Pt->Draw();
4402     
4403     c6->cd(3) ; 
4404     fh2Phi->SetTitleOffset(1.6,"Y");
4405     fh2Phi->SetLineColor(4);
4406     fh2Phi->Draw();
4407     
4408     c6->cd(4) ; 
4409     fh2Eta->SetTitleOffset(1.6,"Y");
4410     fh2Eta->SetLineColor(4);
4411     fh2Eta->Draw();
4412     
4413     sprintf(name,"QA_%s_ReconstructedVSMCDistributions.eps",fCalorimeter.Data());
4414     c6->Print(name); printf("Plot: %s\n",name); 
4415     
4416     //Reconstructed vs MC distributions
4417     //printf("c6\n");
4418     sprintf(cname,"QA_%s_gamrecvsmc",fCalorimeter.Data());
4419     TCanvas  * c6Gam = new TCanvas(cname, "Reconstructed vs MC distributions", 400, 400) ;
4420     c6Gam->Divide(2, 2);
4421     
4422     c6Gam->cd(1) ; 
4423     fhGamE->Draw();
4424     
4425     c6Gam->cd(2) ; 
4426     fhGamPt->Draw();
4427     
4428     c6Gam->cd(3) ; 
4429     fhGamPhi->Draw();
4430     
4431     c6Gam->cd(4) ; 
4432     fhGamEta->Draw();
4433     
4434     sprintf(name,"QA_%s_GammaReconstructedVSMCDistributions.eps",fCalorimeter.Data());
4435     c6->Print(name); printf("Plot: %s\n",name); 
4436     
4437     //Generated - reconstructed  
4438     //printf("c7\n");
4439     sprintf(cname,"QA_%s_diffgenrec",fCalorimeter.Data());
4440     TCanvas  * c7 = new TCanvas(cname, "generated - reconstructed", 400, 400) ;
4441     c7->Divide(2, 2);
4442     
4443     c7->cd(1) ; 
4444     if(fhDeltaE->GetEntries() > 0) gPad->SetLogy();
4445     fhGamDeltaE->SetLineColor(4);
4446     fhDeltaE->Draw();
4447     fhGamDeltaE->Draw("same");
4448     
4449     TLegend pLegendd(0.65,0.55,0.9,0.8);
4450     pLegendd.SetTextSize(0.06);
4451     pLegendd.AddEntry(fhDeltaE,"all","L");
4452     pLegendd.AddEntry(fhGamDeltaE,"from  #gamma","L");
4453     pLegendd.SetFillColor(10);
4454     pLegendd.SetBorderSize(1);
4455     pLegendd.Draw();
4456     
4457     c7->cd(2) ; 
4458     if(fhDeltaPt->GetEntries() > 0) gPad->SetLogy();
4459     fhGamDeltaPt->SetLineColor(4);
4460     fhDeltaPt->Draw();
4461     fhGamDeltaPt->Draw("same");
4462     
4463     c7->cd(3) ; 
4464     fhGamDeltaPhi->SetLineColor(4);
4465     fhDeltaPhi->Draw();
4466     fhGamDeltaPhi->Draw("same");
4467     
4468     c7->cd(4) ; 
4469     fhGamDeltaEta->SetLineColor(4);
4470     fhDeltaEta->Draw();
4471     fhGamDeltaEta->Draw("same");
4472     
4473     sprintf(name,"QA_%s_DiffGeneratedReconstructed.eps",fCalorimeter.Data());
4474     c7->Print(name); printf("Plot: %s\n",name);
4475     
4476     // Reconstructed / Generated 
4477     //printf("c8\n");
4478     sprintf(cname,"QA_%s_ratiorecgen",fCalorimeter.Data());
4479     TCanvas  * c8 = new TCanvas(cname, " reconstructed / generated", 400, 400) ;
4480     c8->Divide(2, 2);
4481     
4482     c8->cd(1) ; 
4483     if(fhRatioE->GetEntries() > 0) gPad->SetLogy();
4484     fhGamRatioE->SetLineColor(4);
4485     fhRatioE->Draw();
4486     fhGamRatioE->Draw("same");
4487     
4488     TLegend pLegendr(0.65,0.55,0.9,0.8);
4489     pLegendr.SetTextSize(0.06);
4490     pLegendr.AddEntry(fhRatioE,"all","L");
4491     pLegendr.AddEntry(fhGamRatioE,"from  #gamma","L");
4492     pLegendr.SetFillColor(10);
4493     pLegendr.SetBorderSize(1);
4494     pLegendr.Draw();
4495     
4496     c8->cd(2) ; 
4497     if(fhRatioPt->GetEntries() > 0) gPad->SetLogy();
4498     fhGamRatioPt->SetLineColor(4);
4499     fhRatioPt->Draw();
4500     fhGamRatioPt->Draw("same");
4501     
4502     c8->cd(3) ; 
4503     fhGamRatioPhi->SetLineColor(4);
4504     fhRatioPhi->Draw();
4505     fhGamRatioPhi->Draw("same");
4506     
4507     c8->cd(4) ; 
4508     fhGamRatioEta->SetLineColor(4);
4509     fhRatioEta->Draw();
4510     fhGamRatioEta->Draw("same");
4511     
4512     sprintf(name,"QA_%s_ReconstructedDivGenerated.eps",fCalorimeter.Data());
4513     c8->Print(name); printf("Plot: %s\n",name);
4514     
4515     //MC
4516     
4517     //Generated distributions
4518     //printf("c1\n");
4519     sprintf(cname,"QA_%s_gen",fCalorimeter.Data());
4520     TCanvas  * c10 = new TCanvas(cname, "Generated distributions", 600, 200) ;
4521     c10->Divide(3, 1);
4522     
4523     c10->cd(1) ; 
4524     gPad->SetLogy();
4525     TH1F * haxispt  = (TH1F*) fhGenPi0Pt->Clone(Form("%s_axispt",fhGenPi0Pt->GetName()));  
4526     haxispt->SetTitle("Generated Particles p_{T}, |#eta| < 1");
4527     fhGenPi0Pt->SetLineColor(1);
4528     fhGenGamPt->SetLineColor(4);
4529     fhGenEtaPt->SetLineColor(2);
4530     fhGenOmegaPt->SetLineColor(7);
4531     fhGenElePt->SetLineColor(6);
4532     
4533     //Select the maximum of the histogram to show all lines.
4534     if(fhGenPi0Pt->GetMaximum() >= fhGenGamPt->GetMaximum() && fhGenPi0Pt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
4535        fhGenPi0Pt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenPi0Pt->GetMaximum() >= fhGenElePt->GetMaximum())
4536       haxispt->SetMaximum(fhGenPi0Pt->GetMaximum());
4537     else if(fhGenGamPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenGamPt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
4538             fhGenGamPt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenGamPt->GetMaximum() >= fhGenElePt->GetMaximum())
4539       haxispt->SetMaximum(fhGenGamPt->GetMaximum());
4540     else if(fhGenEtaPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenEtaPt->GetMaximum() >= fhGenGamPt->GetMaximum() && 
4541             fhGenEtaPt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenEtaPt->GetMaximum() >= fhGenElePt->GetMaximum())
4542       haxispt->SetMaximum(fhGenEtaPt->GetMaximum());    
4543     else if(fhGenOmegaPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenOmegaPt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
4544             fhGenOmegaPt->GetMaximum() >= fhGenGamPt->GetMaximum() && fhGenOmegaPt->GetMaximum() >= fhGenElePt->GetMaximum())
4545       haxispt->SetMaximum(fhGenOmegaPt->GetMaximum());
4546     else if(fhGenElePt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenElePt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
4547             fhGenElePt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenElePt->GetMaximum() >= fhGenGamPt->GetMaximum())
4548       haxispt->SetMaximum(fhGenElePt->GetMaximum());
4549     haxispt->SetMinimum(1);
4550     haxispt->Draw("axis");
4551     fhGenPi0Pt->Draw("same");
4552     fhGenGamPt->Draw("same");
4553     fhGenEtaPt->Draw("same");
4554     fhGenOmegaPt->Draw("same");
4555     fhGenElePt->Draw("same");
4556     
4557     TLegend pLegend(0.85,0.65,0.95,0.93);
4558     pLegend.SetTextSize(0.06);
4559     pLegend.AddEntry(fhGenPi0Pt,"  #pi^{0}","L");
4560     pLegend.AddEntry(fhGenGamPt,"  #gamma","L");
4561     pLegend.AddEntry(fhGenEtaPt,"  #eta","L");
4562     pLegend.AddEntry(fhGenOmegaPt,"  #omega","L");
4563     pLegend.AddEntry(fhGenElePt,"  e^{#pm}","L");
4564     pLegend.SetFillColor(10);
4565     pLegend.SetBorderSize(1);
4566     pLegend.Draw();
4567     
4568     c10->cd(2) ;
4569     gPad->SetLogy();
4570     TH1F * haxiseta  = (TH1F*) fhGenPi0Eta->Clone(Form("%s_axiseta",fhGenPi0Eta->GetName()));  
4571     haxiseta->SetTitle("Generated Particles #eta, |#eta| < 1");
4572     fhGenPi0Eta->SetLineColor(1);
4573     fhGenGamEta->SetLineColor(4);
4574     fhGenEtaEta->SetLineColor(2);
4575     fhGenOmegaEta->SetLineColor(7);
4576     fhGenEleEta->SetLineColor(6);
4577     //Select the maximum of the histogram to show all lines.
4578     if(fhGenPi0Eta->GetMaximum() >= fhGenGamEta->GetMaximum() && fhGenPi0Eta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
4579        fhGenPi0Eta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenPi0Eta->GetMaximum() >= fhGenEleEta->GetMaximum())
4580       haxiseta->SetMaximum(fhGenPi0Eta->GetMaximum());
4581     else if(fhGenGamEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenGamEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
4582             fhGenGamEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenGamEta->GetMaximum() >= fhGenEleEta->GetMaximum())
4583       haxiseta->SetMaximum(fhGenGamEta->GetMaximum());
4584     else if(fhGenEtaEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenEtaEta->GetMaximum() >= fhGenGamEta->GetMaximum() && 
4585             fhGenEtaEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenEtaEta->GetMaximum() >= fhGenEleEta->GetMaximum())
4586       haxiseta->SetMaximum(fhGenEtaEta->GetMaximum());  
4587     else if(fhGenOmegaEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenOmegaEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
4588             fhGenOmegaEta->GetMaximum() >= fhGenGamEta->GetMaximum() && fhGenOmegaEta->GetMaximum() >= fhGenEleEta->GetMaximum())
4589       haxiseta->SetMaximum(fhGenOmegaEta->GetMaximum());
4590     else if(fhGenEleEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenEleEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
4591             fhGenEleEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenEleEta->GetMaximum() >= fhGenGamEta->GetMaximum())
4592       haxiseta->SetMaximum(fhGenEleEta->GetMaximum());
4593     haxiseta->SetMinimum(100);
4594     haxiseta->Draw("axis");
4595     fhGenPi0Eta->Draw("same");
4596     fhGenGamEta->Draw("same");
4597     fhGenEtaEta->Draw("same");
4598     fhGenOmegaEta->Draw("same");
4599     fhGenEleEta->Draw("same");
4600     
4601     
4602     c10->cd(3) ; 
4603     gPad->SetLogy();
4604     TH1F * haxisphi  = (TH1F*) fhGenPi0Phi->Clone(Form("%s_axisphi",fhGenPi0Phi->GetName()));  
4605     haxisphi->SetTitle("Generated Particles #phi, |#eta| < 1");
4606     fhGenPi0Phi->SetLineColor(1);
4607     fhGenGamPhi->SetLineColor(4);
4608     fhGenEtaPhi->SetLineColor(2);
4609     fhGenOmegaPhi->SetLineColor(7);
4610     fhGenElePhi->SetLineColor(6);
4611     //Select the maximum of the histogram to show all lines.
4612     if(fhGenPi0Phi->GetMaximum() >= fhGenGamPhi->GetMaximum() && fhGenPi0Phi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
4613        fhGenPi0Phi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenPi0Phi->GetMaximum() >= fhGenElePhi->GetMaximum())
4614       haxisphi->SetMaximum(fhGenPi0Phi->GetMaximum());
4615     else if(fhGenGamPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenGamPhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
4616             fhGenGamPhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenGamPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
4617       haxisphi->SetMaximum(fhGenGamPhi->GetMaximum());
4618     else if(fhGenEtaPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenEtaPhi->GetMaximum() >= fhGenGamPhi->GetMaximum() && 
4619             fhGenEtaPhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenEtaPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
4620       haxisphi->SetMaximum(fhGenEtaPhi->GetMaximum());  
4621     else if(fhGenOmegaPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenOmegaPhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
4622             fhGenOmegaPhi->GetMaximum() >= fhGenGamPhi->GetMaximum() && fhGenOmegaPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
4623       haxisphi->SetMaximum(fhGenOmegaPhi->GetMaximum());
4624     else if(fhGenElePhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenElePhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
4625             fhGenElePhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenElePhi->GetMaximum() >= fhGenGamPhi->GetMaximum())
4626       haxisphi->SetMaximum(fhGenElePhi->GetMaximum());
4627     haxisphi->SetMinimum(100);
4628     haxisphi->Draw("axis");
4629     fhGenPi0Phi->Draw("same");
4630     fhGenGamPhi->Draw("same");
4631     fhGenEtaPhi->Draw("same");
4632     fhGenOmegaPhi->Draw("same");
4633     fhGenElePhi->Draw("same");
4634     
4635     sprintf(name,"QA_%s_GeneratedDistributions.eps",fCalorimeter.Data());
4636     c10->Print(name); printf("Plot: %s\n",name);
4637     
4638     
4639     //Reconstructed clusters depending on its original particle.
4640     //printf("c1\n");
4641     sprintf(cname,"QA_%s_recgenid",fCalorimeter.Data());
4642     TCanvas  * c11 = new TCanvas(cname, "Reconstructed particles, function of their original particle ID", 400, 400) ;
4643     c11->Divide(2, 2);
4644     
4645     
4646     c11->cd(1) ; 
4647     gPad->SetLogy();
4648     TH1F * hGamE   = (TH1F*) fhGamE->ProjectionX(Form("%s_px",fhGamE->GetName()),-1,-1);
4649     TH1F * hPi0E   = (TH1F*) fhPi0E->ProjectionX(Form("%s_px",fhPi0E->GetName()),-1,-1);
4650     TH1F * hEleE   = (TH1F*) fhEleE->ProjectionX(Form("%s_px",fhEleE->GetName()),-1,-1);
4651     TH1F * hNeHadE = (TH1F*) fhNeHadE->ProjectionX(Form("%s_px",fhNeHadE->GetName()),-1,-1);
4652     TH1F * hChHadE = (TH1F*) fhChHadE->ProjectionX(Form("%s_px",fhChHadE->GetName()),-1,-1);
4653     TH1F * haxisE  = (TH1F*) hPi0E->Clone(Form("%s_axisE",fhPi0E->GetName()));  
4654     haxisE->SetTitle("Reconstructed particles E, function of their original particle ID");
4655     hPi0E->SetLineColor(1);
4656     hGamE->SetLineColor(4);
4657     hNeHadE->SetLineColor(2);
4658     hChHadE->SetLineColor(7);
4659     hEleE->SetLineColor(6);
4660     
4661     //Select the maximum of the histogram to show all lines.
4662     if(hPi0E->GetMaximum() >= hGamE->GetMaximum() && hPi0E->GetMaximum() >= hNeHadE->GetMaximum() && 
4663        hPi0E->GetMaximum() >= hChHadE->GetMaximum() && hPi0E->GetMaximum() >= hEleE->GetMaximum())
4664       haxisE->SetMaximum(hPi0E->GetMaximum());
4665     else if(hGamE->GetMaximum() >= hPi0E->GetMaximum() && hGamE->GetMaximum() >= hNeHadE->GetMaximum() && 
4666             hGamE->GetMaximum() >= hChHadE->GetMaximum() && hGamE->GetMaximum() >= hEleE->GetMaximum())
4667       haxisE->SetMaximum(hGamE->GetMaximum());
4668     else if(hNeHadE->GetMaximum() >= hPi0E->GetMaximum() && hNeHadE->GetMaximum() >= hGamE->GetMaximum() && 
4669             hNeHadE->GetMaximum() >= hChHadE->GetMaximum() && hNeHadE->GetMaximum() >= hEleE->GetMaximum())
4670       haxisE->SetMaximum(hNeHadE->GetMaximum());        
4671     else if(hChHadE->GetMaximum() >= hPi0E->GetMaximum() && hChHadE->GetMaximum() >= hNeHadE->GetMaximum() && 
4672             hChHadE->GetMaximum() >= hGamE->GetMaximum() && hChHadE->GetMaximum() >= hEleE->GetMaximum())
4673       haxisE->SetMaximum(hChHadE->GetMaximum());
4674     else if(hEleE->GetMaximum() >= hPi0E->GetMaximum() && hEleE->GetMaximum() >= hNeHadE->GetMaximum() && 
4675             hEleE->GetMaximum() >= hChHadE->GetMaximum() && hEleE->GetMaximum() >= hGamE->GetMaximum())
4676       haxisE->SetMaximum(hEleE->GetMaximum());
4677     haxisE->SetXTitle("E (GeV)");
4678     haxisE->SetMinimum(1);
4679     haxisE->Draw("axis");
4680     hPi0E->Draw("same");
4681     hGamE->Draw("same");
4682     hNeHadE->Draw("same");
4683     hChHadE->Draw("same");
4684     hEleE->Draw("same");
4685     
4686     TLegend pLegend2(0.8,0.65,0.95,0.93);
4687     pLegend2.SetTextSize(0.06);
4688     pLegend2.AddEntry(hPi0E,"  #pi^{0}","L");
4689     pLegend2.AddEntry(hGamE,"  #gamma","L");
4690     pLegend2.AddEntry(hEleE,"  e^{#pm}","L");
4691     pLegend2.AddEntry(hChHadE,"  h^{#pm}","L");
4692     pLegend2.AddEntry(hNeHadE,"  h^{0}","L");
4693     pLegend2.SetFillColor(10);
4694     pLegend2.SetBorderSize(1);
4695     pLegend2.Draw();
4696     
4697     
4698     c11->cd(2) ; 
4699     gPad->SetLogy();
4700     //printf("%s, %s, %s, %s, %s\n",fhGamPt->GetName(),fhPi0Pt->GetName(),fhElePt->GetName(),fhNeHadPt->GetName(), fhChHadPt->GetName());
4701     TH1F * hGamPt   = (TH1F*) fhGamPt->ProjectionX(Form("%s_px",fhGamPt->GetName()),-1,-1);
4702     TH1F * hPi0Pt   = (TH1F*) fhPi0Pt->ProjectionX(Form("%s_px",fhPi0Pt->GetName()),-1,-1);
4703     TH1F * hElePt   = (TH1F*) fhElePt->ProjectionX(Form("%s_px",fhElePt->GetName()),-1,-1);
4704     TH1F * hNeHadPt = (TH1F*) fhNeHadPt->ProjectionX(Form("%s_px",fhNeHadPt->GetName()),-1,-1);
4705     TH1F * hChHadPt = (TH1F*) fhChHadPt->ProjectionX(Form("%s_px",fhChHadPt->GetName()),-1,-1);
4706     haxispt  = (TH1F*) hPi0Pt->Clone(Form("%s_axisPt",fhPi0Pt->GetName()));  
4707     haxispt->SetTitle("Reconstructed particles p_{T}, function of their original particle ID");
4708     hPi0Pt->SetLineColor(1);
4709     hGamPt->SetLineColor(4);
4710     hNeHadPt->SetLineColor(2);
4711     hChHadPt->SetLineColor(7);
4712     hElePt->SetLineColor(6);
4713     
4714     //Select the maximum of the histogram to show all lines.
4715     if(hPi0Pt->GetMaximum() >= hGamPt->GetMaximum() && hPi0Pt->GetMaximum() >= hNeHadPt->GetMaximum() && 
4716        hPi0Pt->GetMaximum() >= hChHadPt->GetMaximum() && hPi0Pt->GetMaximum() >= hElePt->GetMaximum())
4717       haxispt->SetMaximum(hPi0Pt->GetMaximum());
4718     else if(hGamPt->GetMaximum() >= hPi0Pt->GetMaximum() && hGamPt->GetMaximum() >= hNeHadPt->GetMaximum() && 
4719             hGamPt->GetMaximum() >= hChHadPt->GetMaximum() && hGamPt->GetMaximum() >= hElePt->GetMaximum())
4720       haxispt->SetMaximum(hGamPt->GetMaximum());
4721     else if(hNeHadPt->GetMaximum() >= hPi0Pt->GetMaximum() && hNeHadPt->GetMaximum() >= hGamPt->GetMaximum() && 
4722             hNeHadPt->GetMaximum() >= hChHadPt->GetMaximum() && hNeHadPt->GetMaximum() >= hElePt->GetMaximum())
4723       haxispt->SetMaximum(hNeHadPt->GetMaximum());      
4724     else if(hChHadPt->GetMaximum() >= hPi0Pt->GetMaximum() && hChHadPt->GetMaximum() >= hNeHadPt->GetMaximum() && 
4725             hChHadPt->GetMaximum() >= hGamPt->GetMaximum() && hChHadPt->GetMaximum() >= hElePt->GetMaximum())
4726       haxispt->SetMaximum(hChHadPt->GetMaximum());
4727     else if(hElePt->GetMaximum() >= hPi0Pt->GetMaximum() && hElePt->GetMaximum() >= hNeHadPt->GetMaximum() && 
4728             hElePt->GetMaximum() >= hChHadPt->GetMaximum() && hElePt->GetMaximum() >= hGamPt->GetMaximum())
4729       haxispt->SetMaximum(hElePt->GetMaximum());
4730     haxispt->SetXTitle("p_{T} (GeV/c)");
4731     haxispt->SetMinimum(1);
4732     haxispt->Draw("axis");
4733     hPi0Pt->Draw("same");
4734     hGamPt->Draw("same");
4735     hNeHadPt->Draw("same");
4736     hChHadPt->Draw("same");
4737     hElePt->Draw("same");
4738     
4739     c11->cd(3) ;
4740     gPad->SetLogy();
4741     
4742     TH1F * hGamEta   = (TH1F*) fhGamEta->ProjectionX(Form("%s_px",fhGamEta->GetName()),-1,-1);
4743     TH1F * hPi0Eta   = (TH1F*) fhPi0Eta->ProjectionX(Form("%s_px",fhPi0Eta->GetName()),-1,-1);
4744     TH1F * hEleEta   = (TH1F*) fhEleEta->ProjectionX(Form("%s_px",fhEleEta->GetName()),-1,-1);
4745     TH1F * hNeHadEta = (TH1F*) fhNeHadEta->ProjectionX(Form("%s_px",fhNeHadEta->GetName()),-1,-1);
4746     TH1F * hChHadEta = (TH1F*) fhChHadEta->ProjectionX(Form("%s_px",fhChHadEta->GetName()),-1,-1);
4747     haxiseta  = (TH1F*) hPi0Eta->Clone(Form("%s_axisEta",fhPi0Eta->GetName()));  
4748     haxiseta->SetTitle("Reconstructed particles #eta, function of their original particle ID");
4749     hPi0Eta->SetLineColor(1);
4750     hGamEta->SetLineColor(4);
4751     hNeHadEta->SetLineColor(2);
4752     hChHadEta->SetLineColor(7);
4753     hEleEta->SetLineColor(6);
4754     //Select the maximum of the histogram to show all lines.
4755     if(hPi0Eta->GetMaximum() >= hGamEta->GetMaximum() && hPi0Eta->GetMaximum() >= hNeHadEta->GetMaximum() && 
4756        hPi0Eta->GetMaximum() >= hChHadEta->GetMaximum() && hPi0Eta->GetMaximum() >= hEleEta->GetMaximum())
4757       haxiseta->SetMaximum(hPi0Eta->GetMaximum());
4758     else if(hGamEta->GetMaximum() >= hPi0Eta->GetMaximum() && hGamEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
4759             hGamEta->GetMaximum() >= hChHadEta->GetMaximum() && hGamEta->GetMaximum() >= hEleEta->GetMaximum())
4760       haxiseta->SetMaximum(hGamEta->GetMaximum());
4761     else if(hNeHadEta->GetMaximum() >= hPi0Eta->GetMaximum() && hNeHadEta->GetMaximum() >= hGamEta->GetMaximum() && 
4762             hNeHadEta->GetMaximum() >= hChHadEta->GetMaximum() && hNeHadEta->GetMaximum() >= hEleEta->GetMaximum())
4763       haxiseta->SetMaximum(hNeHadEta->GetMaximum());    
4764     else if(hChHadEta->GetMaximum() >= hPi0Eta->GetMaximum() && hChHadEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
4765             hChHadEta->GetMaximum() >= hGamEta->GetMaximum() && hChHadEta->GetMaximum() >= hEleEta->GetMaximum())
4766       haxiseta->SetMaximum(hChHadEta->GetMaximum());
4767     else if(hEleEta->GetMaximum() >= hPi0Eta->GetMaximum() && hEleEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
4768             hEleEta->GetMaximum() >= hChHadEta->GetMaximum() && hEleEta->GetMaximum() >= hGamEta->GetMaximum())
4769       haxiseta->SetMaximum(hEleEta->GetMaximum());
4770     
4771     haxiseta->SetXTitle("#eta");
4772     haxiseta->Draw("axis");
4773     hPi0Eta->Draw("same");
4774     hGamEta->Draw("same");
4775     hNeHadEta->Draw("same");
4776     hChHadEta->Draw("same");
4777     hEleEta->Draw("same");
4778     
4779     
4780     c11->cd(4) ; 
4781     gPad->SetLogy();
4782     TH1F * hGamPhi   = (TH1F*) fhGamPhi->ProjectionX(Form("%s_px",fhGamPhi->GetName()),-1,-1);
4783     TH1F * hPi0Phi   = (TH1F*) fhPi0Phi->ProjectionX(Form("%s_px",fhPi0Phi->GetName()),-1,-1);
4784     TH1F * hElePhi   = (TH1F*) fhElePhi->ProjectionX(Form("%s_px",fhElePhi->GetName()),-1,-1);
4785     TH1F * hNeHadPhi = (TH1F*) fhNeHadPhi->ProjectionX(Form("%s_px",fhNeHadPhi->GetName()),-1,-1);
4786     TH1F * hChHadPhi = (TH1F*) fhChHadPhi->ProjectionX(Form("%s_px",fhChHadPhi->GetName()),-1,-1);
4787     haxisphi  = (TH1F*) hPi0Phi->Clone(Form("%s_axisPhi",fhPi0Phi->GetName()));  
4788     haxisphi->SetTitle("Reconstructed particles #phi, function of their original particle ID");
4789     
4790     hPi0Phi->SetLineColor(1);
4791     hGamPhi->SetLineColor(4);
4792     hNeHadPhi->SetLineColor(2);
4793     hChHadPhi->SetLineColor(7);
4794     hElePhi->SetLineColor(6);
4795     //Select the maximum of the histogram to show all lines.
4796     if(hPi0Phi->GetMaximum() >= hGamPhi->GetMaximum() && hPi0Phi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
4797        hPi0Phi->GetMaximum() >= hChHadPhi->GetMaximum() && hPi0Phi->GetMaximum() >= hElePhi->GetMaximum())
4798       haxisphi->SetMaximum(hPi0Phi->GetMaximum());
4799     else if(hGamPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hGamPhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
4800             hGamPhi->GetMaximum() >= hChHadPhi->GetMaximum() && hGamPhi->GetMaximum() >= hElePhi->GetMaximum())
4801       haxisphi->SetMaximum(hGamPhi->GetMaximum());
4802     else if(hNeHadPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hNeHadPhi->GetMaximum() >= hGamPhi->GetMaximum() && 
4803             hNeHadPhi->GetMaximum() >= hChHadPhi->GetMaximum() && hNeHadPhi->GetMaximum() >= hElePhi->GetMaximum())
4804       haxisphi->SetMaximum(hNeHadPhi->GetMaximum());    
4805     else if(hChHadPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hChHadPhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
4806             hChHadPhi->GetMaximum() >= hGamPhi->GetMaximum() && hChHadPhi->GetMaximum() >= hElePhi->GetMaximum())
4807       haxisphi->SetMaximum(hChHadPhi->GetMaximum());
4808     else if(hElePhi->GetMaximum() >= hPi0Phi->GetMaximum() && hElePhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
4809             hElePhi->GetMaximum() >= hChHadPhi->GetMaximum() && hElePhi->GetMaximum() >= hGamPhi->GetMaximum())
4810       haxisphi->SetMaximum(hElePhi->GetMaximum());
4811     haxisphi->SetXTitle("#phi (rad)");
4812     haxisphi->Draw("axis");
4813     hPi0Phi->Draw("same");
4814     hGamPhi->Draw("same");
4815     hNeHadPhi->Draw("same");
4816     hChHadPhi->Draw("same");
4817     hElePhi->Draw("same");
4818     
4819     sprintf(name,"QA_%s_RecDistributionsGenID.eps",fCalorimeter.Data());
4820     c11->Print(name); printf("Plot: %s\n",name);
4821     
4822     
4823     //Ratio reconstructed clusters / generated particles in acceptance, for different particle ID
4824     //printf("c1\n");
4825     
4826     TH1F *      hPi0EClone   = (TH1F*)   hPi0E  ->Clone(Form("%s_Clone",fhPi0E->GetName()));
4827     TH1F *      hGamEClone   = (TH1F*)   hGamE  ->Clone(Form("%s_Clone",fhGamE->GetName()));
4828     TH1F *      hPi0PtClone  = (TH1F*)   hPi0Pt ->Clone(Form("%s_Clone",fhPi0Pt->GetName()));
4829     TH1F *      hGamPtClone  = (TH1F*)   hGamPt ->Clone(Form("%s_Clone",fhGamPt->GetName()));   
4830     TH1F *      hPi0EtaClone = (TH1F*)   hPi0Eta->Clone(Form("%s_Clone",fhPi0Eta->GetName()));
4831     TH1F *      hGamEtaClone = (TH1F*)   hGamEta->Clone(Form("%s_Clone",fhGamEta->GetName()));  
4832     TH1F *      hPi0PhiClone = (TH1F*)   hPi0Phi->Clone(Form("%s_Clone",fhPi0Phi->GetName()));
4833     TH1F *      hGamPhiClone = (TH1F*)   hGamPhi->Clone(Form("%s_Clone",fhGamPhi->GetName()));  
4834     
4835     sprintf(cname,"QA_%s_recgenidratio",fCalorimeter.Data());
4836     TCanvas  * c12 = new TCanvas(cname, "Ratio reconstructed clusters / generated particles in acceptance, for different particle ID", 400, 400) ;
4837     c12->Divide(2, 2);
4838     
4839     c12->cd(1) ; 
4840     gPad->SetLogy();
4841     haxisE->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
4842     hPi0EClone->Divide(fhGenPi0AccE);
4843     hGamEClone->Divide(fhGenGamAccE);
4844     haxisE->SetMaximum(5);
4845     haxisE->SetMinimum(1e-2);
4846     haxisE->SetXTitle("E (GeV)");
4847     haxisE->SetYTitle("ratio = rec/gen");
4848     haxisE->Draw("axis");
4849     hPi0E->Draw("same");
4850     hGamE->Draw("same");
4851     
4852     TLegend pLegend3(0.75,0.2,0.9,0.4);
4853     pLegend3.SetTextSize(0.06);
4854     pLegend3.AddEntry(hPi0EClone,"  #pi^{0}","L");
4855     pLegend3.AddEntry(hGamEClone,"  #gamma","L");
4856     pLegend3.SetFillColor(10);
4857     pLegend3.SetBorderSize(1);
4858     pLegend3.Draw();
4859     
4860     c12->cd(2) ; 
4861     gPad->SetLogy();
4862     haxispt->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
4863     hPi0PtClone->Divide(fhGenPi0AccPt);
4864     hGamPtClone->Divide(fhGenGamAccPt);
4865     haxispt->SetMaximum(5);
4866     haxispt->SetMinimum(1e-2);
4867     haxispt->SetXTitle("p_{T} (GeV/c)");
4868     haxispt->SetYTitle("ratio = rec/gen");
4869     haxispt->Draw("axis");
4870     hPi0PtClone->Draw("same");
4871     hGamPtClone->Draw("same");
4872     
4873     c12->cd(3) ;
4874     gPad->SetLogy();
4875     
4876     haxiseta->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
4877     hPi0EtaClone->Divide(fhGenPi0AccEta);
4878     hGamEtaClone->Divide(fhGenGamAccEta);
4879     haxiseta->SetMaximum(1.2);
4880     haxiseta->SetMinimum(1e-2);
4881     haxiseta->SetYTitle("ratio = rec/gen");
4882     haxiseta->SetXTitle("#eta");
4883     haxiseta->Draw("axis");
4884     hPi0EtaClone->Draw("same");
4885     hGamEtaClone->Draw("same");
4886     
4887     
4888     c12->cd(4) ; 
4889     gPad->SetLogy();
4890     haxisphi->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
4891     hPi0PhiClone->Divide(fhGenPi0AccPhi);
4892     hGamPhiClone->Divide(fhGenGamAccPhi);
4893     haxisphi->SetYTitle("ratio = rec/gen");
4894     haxisphi->SetXTitle("#phi (rad)");
4895     haxisphi->SetMaximum(1.2);
4896     haxisphi->SetMinimum(1e-2);
4897     haxisphi->Draw("axis");
4898     hPi0PhiClone->Draw("same");
4899     hGamPhiClone->Draw("same");
4900     
4901     sprintf(name,"QA_%s_EfficiencyGenID.eps",fCalorimeter.Data());
4902     c12->Print(name); printf("Plot: %s\n",name);
4903     
4904     
4905     
4906     //Reconstructed distributions
4907     //printf("c1\n");
4908     sprintf(cname,"QA_%s_vertex",fCalorimeter.Data());
4909     TCanvas  * c13 = new TCanvas(cname, "Particle vertex", 400, 400) ;
4910     c13->Divide(2, 2);
4911     
4912     c13->cd(1) ; 
4913     //gPad->SetLogy();
4914     fhEMVxyz->SetTitleOffset(1.6,"Y");
4915     fhEMVxyz->Draw();
4916     
4917     c13->cd(2) ; 
4918     //gPad->SetLogy();
4919     fhHaVxyz->SetTitleOffset(1.6,"Y");
4920     fhHaVxyz->Draw();
4921     
4922     c13->cd(3) ;
4923     gPad->SetLogy();
4924     TH1F * hEMR = (TH1F*) fhEMR->ProjectionY(Form("%s_py",fhEMR->GetName()),-1,-1); 
4925     hEMR->SetLineColor(4);
4926     hEMR->Draw();
4927     
4928     c13->cd(4) ; 
4929     gPad->SetLogy();
4930     TH1F * hHaR = (TH1F*) fhHaR->ProjectionY(Form("%s_py",fhHaR->GetName()),-1,-1); 
4931     hHaR->SetLineColor(4);
4932     hHaR->Draw();
4933     
4934     
4935     sprintf(name,"QA_%s_ParticleVertex.eps",fCalorimeter.Data());
4936     c13->Print(name); printf("Plot: %s\n",name);
4937     
4938     
4939     //Track-matching distributions
4940     if(fFillAllTH12){
4941       //Reconstructed distributions, matched with tracks, generated particle dependence
4942       //printf("c2\n");
4943       sprintf(cname,"QA_%s_rectrackmatchGenID",fCalorimeter.Data());
4944       TCanvas  * c22ch = new TCanvas(cname, "Reconstructed distributions, matched with tracks, for different particle ID", 400, 400) ;
4945       c22ch->Divide(2, 2);
4946       
4947       c22ch->cd(1) ; 
4948       
4949       TH1F * hGamECharged   = (TH1F*) fhGamECharged->ProjectionX(Form("%s_px",fhGamECharged->GetName()),-1,-1);
4950       TH1F * hPi0ECharged   = (TH1F*) fhPi0ECharged->ProjectionX(Form("%s_px",fhPi0ECharged->GetName()),-1,-1);
4951       TH1F * hEleECharged   = (TH1F*) fhEleECharged->ProjectionX(Form("%s_px",fhEleECharged->GetName()),-1,-1);
4952       TH1F * hNeHadECharged = (TH1F*) fhNeHadECharged->ProjectionX(Form("%s_px",fhNeHadECharged->GetName()),-1,-1);
4953       TH1F * hChHadECharged = (TH1F*) fhChHadECharged->ProjectionX(Form("%s_px",fhChHadECharged->GetName()),-1,-1);
4954       hPi0ECharged->SetLineColor(1);
4955       hGamECharged->SetLineColor(4);
4956       hNeHadECharged->SetLineColor(2);
4957       hChHadECharged->SetLineColor(7);
4958       hEleECharged->SetLineColor(6);    
4959       gPad->SetLogy();
4960       fhECharged->SetLineColor(3);
4961       fhECharged->SetMinimum(0.5);
4962       fhECharged->Draw();
4963       hPi0ECharged->Draw("same");
4964       hGamECharged->Draw("same");
4965       hNeHadECharged->Draw("same");
4966       hChHadECharged->Draw("same");
4967       hEleECharged->Draw("same");
4968       TLegend pLegend22(0.75,0.45,0.9,0.8);
4969       pLegend22.SetTextSize(0.06);
4970       pLegend22.AddEntry(fhECharged,"all","L");
4971       pLegend22.AddEntry(hPi0ECharged,"#pi^{0}","L");
4972       pLegend22.AddEntry(hGamECharged,"#gamma","L");
4973       pLegend22.AddEntry(hEleECharged,"e^{#pm}","L");
4974       pLegend22.AddEntry(hChHadECharged,"h^{#pm}","L");
4975       pLegend22.AddEntry(hNeHadECharged,"h^{0}","L");
4976       pLegend22.SetFillColor(10);
4977       pLegend22.SetBorderSize(1);
4978       pLegend22.Draw();
4979       
4980       c22ch->cd(2) ; 
4981       
4982       TH1F * hGamPtCharged   = (TH1F*) fhGamPtCharged->ProjectionX(Form("%s_px",fhGamPtCharged->GetName()),-1,-1);
4983       TH1F * hPi0PtCharged   = (TH1F*) fhPi0PtCharged->ProjectionX(Form("%s_px",fhPi0PtCharged->GetName()),-1,-1);
4984       TH1F * hElePtCharged   = (TH1F*) fhElePtCharged->ProjectionX(Form("%s_px",fhElePtCharged->GetName()),-1,-1);
4985       TH1F * hNeHadPtCharged = (TH1F*) fhNeHadPtCharged->ProjectionX(Form("%s_px",fhNeHadPtCharged->GetName()),-1,-1);
4986       TH1F * hChHadPtCharged = (TH1F*) fhChHadPtCharged->ProjectionX(Form("%s_px",fhChHadPtCharged->GetName()),-1,-1);
4987       hPi0PtCharged->SetLineColor(1);
4988       hGamPtCharged->SetLineColor(4);
4989       hNeHadPtCharged->SetLineColor(2);
4990       hChHadPtCharged->SetLineColor(7);
4991       hElePtCharged->SetLineColor(6);   
4992       gPad->SetLogy();
4993       fhPtCharged->SetLineColor(3);
4994       fhPtCharged->SetMinimum(0.5);
4995       fhPtCharged->Draw();
4996       hPi0PtCharged->Draw("same");
4997       hGamPtCharged->Draw("same");
4998       hNeHadPtCharged->Draw("same");
4999       hChHadPtCharged->Draw("same");
5000       hElePtCharged->Draw("same");      
5001       
5002       c22ch->cd(4) ; 
5003       
5004       TH1F * hGamEtaCharged   = (TH1F*) fhGamEtaCharged->ProjectionX(Form("%s_px",fhGamEtaCharged->GetName()),-1,-1);
5005       TH1F * hPi0EtaCharged   = (TH1F*) fhPi0EtaCharged->ProjectionX(Form("%s_px",fhPi0EtaCharged->GetName()),-1,-1);
5006       TH1F * hEleEtaCharged   = (TH1F*) fhEleEtaCharged->ProjectionX(Form("%s_px",fhEleEtaCharged->GetName()),-1,-1);
5007       TH1F * hNeHadEtaCharged = (TH1F*) fhNeHadEtaCharged->ProjectionX(Form("%s_px",fhNeHadEtaCharged->GetName()),-1,-1);
5008       TH1F * hChHadEtaCharged = (TH1F*) fhChHadEtaCharged->ProjectionX(Form("%s_px",fhChHadEtaCharged->GetName()),-1,-1);
5009       hPi0EtaCharged->SetLineColor(1);
5010       hGamEtaCharged->SetLineColor(4);
5011       hNeHadEtaCharged->SetLineColor(2);
5012       hChHadEtaCharged->SetLineColor(7);
5013       hEleEtaCharged->SetLineColor(6);  
5014       gPad->SetLogy();
5015       fhEtaCharged->SetLineColor(3);
5016       fhEtaCharged->SetMinimum(0.5);
5017       fhEtaCharged->Draw();
5018       hPi0EtaCharged->Draw("same");
5019       hGamEtaCharged->Draw("same");
5020       hNeHadEtaCharged->Draw("same");
5021       hChHadEtaCharged->Draw("same");
5022       hEleEtaCharged->Draw("same");
5023       
5024       c22ch->cd(3) ; 
5025       
5026       TH1F * hGamPhiCharged   = (TH1F*) fhGamPhiCharged->ProjectionX(Form("%s_px",fhGamPhiCharged->GetName()),-1,-1);
5027       TH1F * hPi0PhiCharged   = (TH1F*) fhPi0PhiCharged->ProjectionX(Form("%s_px",fhPi0PhiCharged->GetName()),-1,-1);
5028       TH1F * hElePhiCharged   = (TH1F*) fhElePhiCharged->ProjectionX(Form("%s_px",fhElePhiCharged->GetName()),-1,-1);
5029       TH1F * hNeHadPhiCharged = (TH1F*) fhNeHadPhiCharged->ProjectionX(Form("%s_px",fhNeHadPhiCharged->GetName()),-1,-1);
5030       TH1F * hChHadPhiCharged = (TH1F*) fhChHadPhiCharged->ProjectionX(Form("%s_px",fhChHadPhiCharged->GetName()),-1,-1);
5031       hPi0PhiCharged->SetLineColor(1);
5032       hGamPhiCharged->SetLineColor(4);
5033       hNeHadPhiCharged->SetLineColor(2);
5034       hChHadPhiCharged->SetLineColor(7);
5035       hElePhiCharged->SetLineColor(6);  
5036       gPad->SetLogy();
5037       fhPhiCharged->SetLineColor(3);
5038       fhPhiCharged->SetMinimum(0.5);
5039       fhPhiCharged->Draw();
5040       hPi0PhiCharged->Draw("same");
5041       hGamPhiCharged->Draw("same");
5042       hNeHadPhiCharged->Draw("same");
5043       hChHadPhiCharged->Draw("same");
5044       hElePhiCharged->Draw("same");
5045       
5046       
5047       sprintf(name,"QA_%s_ReconstructedDistributions_TrackMatchedGenID.eps",fCalorimeter.Data());
5048       c22ch->Print(name); printf("Plot: %s\n",name);
5049       
5050       TH1F *    hGamEChargedClone   = (TH1F*)   hGamECharged->Clone(Form("%s_Clone",fhGamECharged->GetName()));
5051       TH1F *    hGamPtChargedClone  = (TH1F*)   hGamPtCharged->Clone(Form("%s_Clone",fhGamPtCharged->GetName()));
5052       TH1F *    hGamEtaChargedClone = (TH1F*)   hGamEtaCharged->Clone(Form("%s_Clone",fhGamEtaCharged->GetName()));
5053       TH1F *    hGamPhiChargedClone = (TH1F*)   hGamPhiCharged->Clone(Form("%s_Clone",fhGamPhiCharged->GetName()));
5054       
5055       TH1F *    hPi0EChargedClone   = (TH1F*)   hPi0ECharged->Clone(Form("%s_Clone",fhPi0ECharged->GetName()));
5056       TH1F *    hPi0PtChargedClone  = (TH1F*)   hPi0PtCharged->Clone(Form("%s_Clone",fhPi0PtCharged->GetName()));
5057       TH1F *    hPi0EtaChargedClone = (TH1F*)   hPi0EtaCharged->Clone(Form("%s_Clone",fhPi0EtaCharged->GetName()));
5058       TH1F *    hPi0PhiChargedClone = (TH1F*)   hPi0PhiCharged->Clone(Form("%s_Clone",fhPi0PhiCharged->GetName()));
5059       
5060       TH1F *    hEleEChargedClone   = (TH1F*)   hEleECharged->Clone(Form("%s_Clone",fhEleECharged->GetName()));
5061       TH1F *    hElePtChargedClone  = (TH1F*)   hElePtCharged->Clone(Form("%s_Clone",fhElePtCharged->GetName()));
5062       TH1F *    hEleEtaChargedClone = (TH1F*)   hEleEtaCharged->Clone(Form("%s_Clone",fhEleEtaCharged->GetName()));
5063       TH1F *    hElePhiChargedClone = (TH1F*)   hElePhiCharged->Clone(Form("%s_Clone",fhElePhiCharged->GetName()));     
5064       
5065       TH1F *    hNeHadEChargedClone   = (TH1F*)   hNeHadECharged->Clone(Form("%s_Clone",fhNeHadECharged->GetName()));
5066       TH1F *    hNeHadPtChargedClone  = (TH1F*)   hNeHadPtCharged->Clone(Form("%s_Clone",fhNeHadPtCharged->GetName()));
5067       TH1F *    hNeHadEtaChargedClone = (TH1F*)   hNeHadEtaCharged->Clone(Form("%s_Clone",fhNeHadEtaCharged->GetName()));
5068       TH1F *    hNeHadPhiChargedClone = (TH1F*)   hNeHadPhiCharged->Clone(Form("%s_Clone",fhNeHadPhiCharged->GetName()));
5069       
5070       TH1F *    hChHadEChargedClone   = (TH1F*)   hChHadECharged->Clone(Form("%s_Clone",fhChHadECharged->GetName()));
5071       TH1F *    hChHadPtChargedClone  = (TH1F*)   hChHadPtCharged->Clone(Form("%s_Clone",fhChHadPtCharged->GetName()));
5072       TH1F *    hChHadEtaChargedClone = (TH1F*)   hChHadEtaCharged->Clone(Form("%s_Clone",fhChHadEtaCharged->GetName()));
5073       TH1F *    hChHadPhiChargedClone = (TH1F*)   hChHadPhiCharged->Clone(Form("%s_Clone",fhChHadPhiCharged->GetName()));       
5074       
5075       //Ratio: reconstructed track matched/ all reconstructed
5076       //printf("c3\n");
5077       sprintf(cname,"QA_%s_rectrackmatchratGenID",fCalorimeter.Data());
5078       TCanvas  * c3ch = new TCanvas(cname, "Ratio: reconstructed track matched/ all reconstructed, for different particle ID", 400, 400) ;
5079       c3ch->Divide(2, 2);
5080       
5081       c3ch->cd(1) ;
5082       hEChargedClone->SetMaximum(1.2);
5083       hEChargedClone->SetMinimum(0.001);        
5084       hEChargedClone->SetLineColor(3);
5085       hEChargedClone->SetYTitle("track matched / all");
5086       hPi0EChargedClone->Divide(hPi0E);
5087       hGamEChargedClone->Divide(hGamE);
5088       hEleEChargedClone->Divide(hEleE);
5089       hNeHadEChargedClone->Divide(hNeHadE);
5090       hChHadEChargedClone->Divide(hChHadE);
5091       hEChargedClone->Draw();
5092       hPi0EChargedClone->Draw("same");
5093       hGamEChargedClone->Draw("same");
5094       hEleEChargedClone->Draw("same");
5095       hNeHadEChargedClone->Draw("same");
5096       hChHadEChargedClone->Draw("same");
5097       
5098       TLegend pLegend3ch(0.75,0.45,0.9,0.8);
5099       pLegend3ch.SetTextSize(0.06);
5100       pLegend3ch.AddEntry(hEChargedClone,"all","L");
5101       pLegend3ch.AddEntry(hPi0EChargedClone,"#pi^{0}","L");
5102       pLegend3ch.AddEntry(hGamEChargedClone,"#gamma","L");
5103       pLegend3ch.AddEntry(hEleEChargedClone,"e^{#pm}","L");
5104       pLegend3ch.AddEntry(hChHadEChargedClone,"h^{#pm}","L");
5105       pLegend3ch.AddEntry(hNeHadEChargedClone,"h^{0}","L");
5106       pLegend3ch.SetFillColor(10);
5107       pLegend3ch.SetBorderSize(1);
5108       pLegend3ch.Draw();
5109       
5110       c3ch->cd(2) ;
5111       hPtChargedClone->SetMaximum(1.2);
5112       hPtChargedClone->SetMinimum(0.001);       
5113       hPtChargedClone->SetLineColor(3);
5114       hPtChargedClone->SetYTitle("track matched / all");
5115       hPi0PtChargedClone->Divide(hPi0Pt);
5116       hGamPtChargedClone->Divide(hGamPt);
5117       hElePtChargedClone->Divide(hElePt);
5118       hNeHadPtChargedClone->Divide(hNeHadPt);
5119       hChHadPtChargedClone->Divide(hChHadPt);
5120       hPtChargedClone->Draw();
5121       hPi0PtChargedClone->Draw("same");
5122       hGamPtChargedClone->Draw("same");
5123       hElePtChargedClone->Draw("same");
5124       hNeHadPtChargedClone->Draw("same");
5125       hChHadPtChargedClone->Draw("same");
5126       
5127       c3ch->cd(4) ;
5128       hEtaChargedClone->SetMaximum(1.2);
5129       hEtaChargedClone->SetMinimum(0.001);      
5130       hEtaChargedClone->SetLineColor(3);
5131       hEtaChargedClone->SetYTitle("track matched / all");
5132       hPi0EtaChargedClone->Divide(hPi0Eta);
5133       hGamEtaChargedClone->Divide(hGamEta);
5134       hEleEtaChargedClone->Divide(hEleEta);
5135       hNeHadEtaChargedClone->Divide(hNeHadEta);
5136       hChHadEtaChargedClone->Divide(hChHadEta);
5137       hEtaChargedClone->Draw();
5138       hPi0EtaChargedClone->Draw("same");
5139       hGamEtaChargedClone->Draw("same");
5140       hEleEtaChargedClone->Draw("same");
5141       hNeHadEtaChargedClone->Draw("same");
5142       hChHadEtaChargedClone->Draw("same");
5143       
5144       c3ch->cd(3) ;
5145       hPhiChargedClone->SetMaximum(1.2);
5146       hPhiChargedClone->SetMinimum(0.001);
5147       hPhiChargedClone->SetLineColor(3);
5148       hPhiChargedClone->SetYTitle("track matched / all");
5149       hPi0PhiChargedClone->Divide(hPi0Phi);
5150       hGamPhiChargedClone->Divide(hGamPhi);
5151       hElePhiChargedClone->Divide(hElePhi);
5152       hNeHadPhiChargedClone->Divide(hNeHadPhi);
5153       hChHadPhiChargedClone->Divide(hChHadPhi);
5154       hPhiChargedClone->Draw();
5155       hPi0PhiChargedClone->Draw("same");
5156       hGamPhiChargedClone->Draw("same");
5157       hElePhiChargedClone->Draw("same");
5158       hNeHadPhiChargedClone->Draw("same");
5159       hChHadPhiChargedClone->Draw("same");
5160       
5161       sprintf(name,"QA_%s_RatioReconstructedMatchedDistributionsGenID.eps",fCalorimeter.Data());
5162       c3ch->Print(name); printf("Plot: %s\n",name);
5163       
5164     }   
5165   }
5166   //Track-matching distributions
5167   
5168         sprintf(cname,"QA_%s_trkmatch",fCalorimeter.Data());
5169         TCanvas *cme = new TCanvas(cname,"Track-matching distributions", 400, 400);
5170         cme->Divide(2,2);
5171   
5172         TLegend pLegendpE0(0.6,0.55,0.9,0.8);
5173         pLegendpE0.SetTextSize(0.04);
5174         pLegendpE0.AddEntry(fh1pOverE,"all","L");
5175         pLegendpE0.AddEntry(fh1pOverER02,"dR < 0.02","L");              
5176         pLegendpE0.SetFillColor(10);
5177         pLegendpE0.SetBorderSize(1);
5178   //pLegendpE0.Draw();
5179   
5180         cme->cd(1);
5181         if(fh1pOverE->GetEntries() > 0) gPad->SetLogy();
5182         fh1pOverE->SetTitle("Track matches p/E");
5183         fh1pOverE->Draw();
5184         fh1pOverER02->SetLineColor(4);
5185         fh1pOverER02->Draw("same");
5186         pLegendpE0.Draw();
5187   
5188         cme->cd(2);
5189         if(fh1dR->GetEntries() > 0) gPad->SetLogy();
5190         fh1dR->Draw();
5191         
5192         cme->cd(3);
5193         fh2MatchdEdx->Draw();
5194         
5195         cme->cd(4);
5196         fh2EledEdx->Draw();
5197         
5198         sprintf(name,"QA_%s_TrackMatchingEleDist.eps",fCalorimeter.Data());
5199         cme->Print(name); printf("Plot: %s\n",name);       
5200         
5201         if(IsDataMC()){
5202     sprintf(cname,"QA_%s_trkmatchMCEle",fCalorimeter.Data());
5203     TCanvas *cmemc = new TCanvas(cname,"Track-matching distributions from MC electrons", 600, 200);
5204     cmemc->Divide(3,1);
5205     
5206     cmemc->cd(1);
5207     gPad->SetLogy();
5208     fhMCEle1pOverE->Draw();
5209     fhMCEle1pOverER02->SetLineColor(4);
5210     fhMCEle1pOverE->SetLineColor(1);
5211     fhMCEle1pOverER02->Draw("same");
5212     pLegendpE0.Draw();
5213                 
5214     cmemc->cd(2);
5215     gPad->SetLogy();
5216     fhMCEle1dR->Draw();
5217                 
5218     cmemc->cd(3);
5219     fhMCEle2MatchdEdx->Draw();
5220                 
5221     sprintf(name,"QA_%s_TrackMatchingDistMCEle.eps",fCalorimeter.Data());
5222     cmemc->Print(name); printf("Plot: %s\n",name);  
5223     
5224                 
5225     sprintf(cname,"QA_%s_trkmatchMCChHad",fCalorimeter.Data());
5226     TCanvas *cmemchad = new TCanvas(cname,"Track-matching distributions from MC charged hadrons", 600, 200);
5227     cmemchad->Divide(3,1);
5228                 
5229     cmemchad->cd(1);
5230     gPad->SetLogy();
5231     fhMCChHad1pOverE->Draw();
5232     fhMCChHad1pOverER02->SetLineColor(4);
5233     fhMCChHad1pOverE->SetLineColor(1);
5234     fhMCChHad1pOverER02->Draw("same");
5235     pLegendpE0.Draw();
5236                 
5237     cmemchad->cd(2);
5238     gPad->SetLogy();
5239     fhMCChHad1dR->Draw();
5240     
5241     cmemchad->cd(3);
5242     fhMCChHad2MatchdEdx->Draw();
5243                 
5244     sprintf(name,"QA_%s_TrackMatchingDistMCChHad.eps",fCalorimeter.Data());
5245     cmemchad->Print(name); printf("Plot: %s\n",name);       
5246     
5247     sprintf(cname,"QA_%s_trkmatchMCNeutral",fCalorimeter.Data());
5248     TCanvas *cmemcn = new TCanvas(cname,"Track-matching distributions from MC neutrals", 600, 200);
5249     cmemcn->Divide(3,1);
5250                 
5251     cmemcn->cd(1);
5252     gPad->SetLogy();
5253     fhMCNeutral1pOverE->Draw();
5254     fhMCNeutral1pOverE->SetLineColor(1);
5255     fhMCNeutral1pOverER02->SetLineColor(4);
5256     fhMCNeutral1pOverER02->Draw("same");
5257     pLegendpE0.Draw();
5258                 
5259     cmemcn->cd(2);
5260     gPad->SetLogy();
5261     fhMCNeutral1dR->Draw();
5262                 
5263     cmemcn->cd(3);
5264     fhMCNeutral2MatchdEdx->Draw();
5265                 
5266     sprintf(name,"QA_%s_TrackMatchingDistMCNeutral.eps",fCalorimeter.Data());
5267     cmemcn->Print(name); printf("Plot: %s\n",name);       
5268     
5269     sprintf(cname,"QA_%s_trkmatchpE",fCalorimeter.Data());
5270     TCanvas *cmpoe = new TCanvas(cname,"Track-matching distributions, p/E", 400, 200);
5271     cmpoe->Divide(2,1);
5272                 
5273     cmpoe->cd(1);
5274     gPad->SetLogy();
5275     fh1pOverE->SetLineColor(1);
5276     fhMCEle1pOverE->SetLineColor(4);
5277     fhMCChHad1pOverE->SetLineColor(2);
5278     fhMCNeutral1pOverE->SetLineColor(7);
5279     fh1pOverER02->SetMinimum(0.5);
5280     fh1pOverE->Draw();
5281     fhMCEle1pOverE->Draw("same");
5282     fhMCChHad1pOverE->Draw("same");
5283     fhMCNeutral1pOverE->Draw("same");
5284     TLegend pLegendpE(0.65,0.55,0.9,0.8);
5285     pLegendpE.SetTextSize(0.06);
5286     pLegendpE.AddEntry(fh1pOverE,"all","L");
5287     pLegendpE.AddEntry(fhMCEle1pOverE,"e^{#pm}","L");
5288     pLegendpE.AddEntry(fhMCChHad1pOverE,"h^{#pm}","L");
5289     pLegendpE.AddEntry(fhMCNeutral1pOverE,"neutrals","L");
5290     pLegendpE.SetFillColor(10);
5291     pLegendpE.SetBorderSize(1);
5292     pLegendpE.Draw();
5293     
5294     cmpoe->cd(2);
5295     gPad->SetLogy();
5296     fh1pOverER02->SetTitle("Track matches p/E, dR<0.2");
5297     fh1pOverER02->SetLineColor(1);
5298     fhMCEle1pOverER02->SetLineColor(4);
5299     fhMCChHad1pOverER02->SetLineColor(2);
5300     fhMCNeutral1pOverER02->SetLineColor(7);
5301     fh1pOverER02->SetMaximum(fh1pOverE->GetMaximum());
5302     fh1pOverER02->SetMinimum(0.5);
5303     fh1pOverER02->Draw();
5304     fhMCEle1pOverER02->Draw("same");
5305     fhMCChHad1pOverER02->Draw("same");
5306     fhMCNeutral1pOverER02->Draw("same");
5307     
5308     //          TLegend pLegendpE2(0.65,0.55,0.9,0.8);
5309     //          pLegendpE2.SetTextSize(0.06);
5310     //          pLegendpE2.SetHeader("dR < 0.02");
5311     //          pLegendpE2.SetFillColor(10);
5312     //          pLegendpE2.SetBorderSize(1);
5313     //          pLegendpE2.Draw();
5314     
5315     sprintf(name,"QA_%s_TrackMatchingPOverE.eps",fCalorimeter.Data());
5316     cmpoe->Print(name); printf("Plot: %s\n",name);                              
5317         }
5318         
5319         char line[1024] ; 
5320         sprintf(line, ".!tar -zcf QA_%s_%s.tar.gz *%s*.eps", fCalorimeter.Data(), GetName(),fCalorimeter.Data()) ; 
5321         gROOT->ProcessLine(line);
5322         sprintf(line, ".!rm -fR *.eps"); 
5323         gROOT->ProcessLine(line);
5324         
5325         printf("AliAnaCalorimeterQA::Terminate() - !! All the eps files are in QA_%s_%s.tar.gz !!!\n",  fCalorimeter.Data(), GetName());
5326         
5327 }