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