]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrDep/AliAnaCalorimeterQA.cxx
915f051ce70b1d272925cc98c05b01b6d7033110
[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   //Play with the MC stack if available 
1226   //Get the MC arrays and do some checks
1227   if(IsDataMC()){
1228     if(GetReader()->ReadStack()){
1229       
1230       if(!GetMCStack()) {
1231         printf("AliAnaPhoton::MakeAnalysisFillHistograms() - Stack not available, is the MC handler called? STOP\n");
1232         abort();
1233       }
1234       //Fill some pure MC histograms, only primaries.
1235       for(Int_t i=0 ; i<GetMCStack()->GetNprimary(); i++){//Only primary particles, for all MC transport put GetNtrack()
1236         TParticle *primary = GetMCStack()->Particle(i) ;
1237         //printf("i %d, %s: status = %d, primary? %d\n",i, primary->GetName(), primary->GetStatusCode(), primary->IsPrimary());
1238         if (primary->GetStatusCode() > 11) continue; //Working for PYTHIA and simple generators, check for HERWIG 
1239         primary->Momentum(mom);
1240         MCHistograms(mom,TMath::Abs(primary->GetPdgCode()));
1241       } //primary loop
1242     }
1243     else if(GetReader()->ReadAODMCParticles()){
1244       
1245       if(!GetReader()->GetAODMCParticles(0))    {
1246         printf("AliAnaPhoton::MakeAnalysisFillHistograms() -  AODMCParticles not available!\n");
1247         abort();
1248       }
1249       //Fill some pure MC histograms, only primaries.
1250       for(Int_t i=0 ; i < (GetReader()->GetAODMCParticles(0))->GetEntriesFast(); i++){
1251         AliAODMCParticle *aodprimary = (AliAODMCParticle*) (GetReader()->GetAODMCParticles(0))->At(i) ;
1252         //printf("i %d, %s: primary? %d physical primary? %d, flag %d\n",
1253         //         i,(TDatabasePDG::Instance()->GetParticle(aodprimary->GetPdgCode()))->GetName(), 
1254         //         aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary(), aodprimary->GetFlag());
1255         if (!aodprimary->IsPrimary()) continue; //accept all which is not MC transport generated. Don't know how to avoid partons
1256         //aodprimary->Momentum(mom);
1257         mom.SetPxPyPzE(aodprimary->Px(),aodprimary->Py(),aodprimary->Pz(),aodprimary->E());
1258         MCHistograms(mom,TMath::Abs(aodprimary->GetPdgCode()));
1259       } //primary loop
1260       
1261     }
1262   }// is data and MC    
1263   
1264   
1265   //Get List with CaloClusters  
1266   if      (fCalorimeter == "PHOS")  caloClusters = GetAODPHOS();
1267   else if (fCalorimeter == "EMCAL") caloClusters = GetAODEMCAL();
1268   else 
1269     AliFatal(Form("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Wrong calorimeter name <%s>, END\n", fCalorimeter.Data()));
1270   
1271   //  if     (fCalorimeter == "EMCAL") GetReader()->GetInputEvent()->GetEMCALClusters(caloClusters);//GetAODEMCAL();
1272   //  else if(fCalorimeter == "PHOS")  GetReader()->GetInputEvent()->GetPHOSClusters (caloClusters);//GetAODPHOS();
1273   //  else 
1274   //    AliFatal(Form("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Wrong calorimeter name <%s>, END\n", fCalorimeter.Data()));
1275   
1276   if(!caloClusters) {
1277     AliFatal(Form("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - No CaloClusters available\n"));
1278   }
1279   else{
1280     //----------------------------------------------------------
1281     //Correlate Calorimeters
1282     //----------------------------------------------------------
1283     //if(fCorrelateCalos)       CorrelateCalorimeters(caloClusters);
1284     if(fCorrelateCalos) CorrelateCalorimeters();
1285     
1286     
1287     //----------------------------------------------------------
1288     // CALOCLUSTERS
1289     //----------------------------------------------------------
1290     
1291     nCaloClusters = caloClusters->GetEntriesFast() ; 
1292     Int_t *nClustersInModule = new Int_t[fNModules];
1293     for(Int_t imod = 0; imod < fNModules; imod++ ) nClustersInModule[imod] = 0;
1294     
1295     if(GetDebug() > 0)
1296       printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - In %s there are %d clusters \n", fCalorimeter.Data(), nCaloClusters);
1297     
1298     //Get vertex for photon momentum calculation
1299     Double_t v[3] = {0,0,0}; //vertex ;
1300     GetReader()->GetVertex(v);
1301     AliVTrack * track = 0x0;
1302     
1303     Float_t pos[3] ;
1304     Float_t showerShape[3] ;
1305     Double_t tof = 0;
1306     //Loop over CaloClusters
1307     //if(nCaloClusters > 0)printf("QA  : Vertex Cut passed %f, cut %f, entries %d, %s\n",v[2], 40., nCaloClusters, fCalorimeter.Data());
1308     for(Int_t iclus = 0; iclus < nCaloClusters; iclus++){
1309       
1310       if(GetDebug() > 0) printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - cluster: %d/%d, data %d \n",
1311                                 iclus+1,nCaloClusters,GetReader()->GetDataType());
1312       
1313       if(GetReader()->GetDataType()==AliCaloTrackReader::kESD){
1314         AliVCluster* clus =  (AliVCluster*)caloClusters->At(iclus);
1315         AliVCaloCells * cell = 0x0; 
1316         if(fCalorimeter == "PHOS") cell =  GetPHOSCells();
1317         else                                     cell =  GetEMCALCells();
1318         
1319         //Get cluster kinematics
1320         clus->GetPosition(pos);
1321         clus->GetMomentum(mom,v);
1322         tof = clus->GetTOF()*1e9;
1323         if(tof < fTimeCutMin || tof > fTimeCutMax) continue;
1324         
1325         //Check only certain regions
1326         Bool_t in = kTRUE;
1327         if(IsFiducialCutOn()) in =  GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
1328         if(!in) continue;
1329                 
1330         //Get module of cluster
1331         nCaloClustersAccepted++;
1332         nModule = GetModuleNumber(clus);
1333         if(nModule >=0 && nModule < fNModules) nClustersInModule[nModule]++;
1334         
1335         //MC labels
1336         nLabel = clus->GetNLabels();
1337         labels = clus->GetLabels();
1338         
1339         //Cells per cluster
1340         nCaloCellsPerCluster =  clus->GetNCells();
1341         //if(mom.E() > 10 && nCaloCellsPerCluster == 1 ) printf("%s:************** E = %f ********** ncells = %d\n",fCalorimeter.Data(), mom.E(),nCaloCellsPerCluster);
1342    
1343         //matched cluster with tracks
1344         nTracksMatched = clus->GetNTracksMatched();
1345         trackIndex     = clus->GetTrackMatchedIndex();
1346         if(trackIndex >= 0){
1347           track = (AliVTrack*)GetReader()->GetInputEvent()->GetTrack(trackIndex);
1348         }
1349         else{
1350           if(nTracksMatched == 1) nTracksMatched = 0;
1351           track = 0;
1352         }
1353         
1354         //Shower shape parameters
1355         showerShape[0] = clus->GetM20();
1356         showerShape[1] = clus->GetM02();
1357         showerShape[2] = clus->GetDispersion();
1358         
1359         //======================
1360         //Cells in cluster
1361         //======================
1362         
1363         //Get list of contributors
1364         UShort_t * indexList = clus->GetCellsAbsId() ;
1365         // check time of cells respect to max energy cell
1366         //Get maximum energy cell
1367         Float_t emax  = -1;
1368         Double_t tmax = -1;
1369         Int_t imax    = -1;
1370         Int_t absId   = -1 ;
1371         //printf("nCaloCellsPerCluster %d\n",nCaloCellsPerCluster);
1372         //Loop on cluster cells
1373         for (Int_t ipos = 0; ipos < nCaloCellsPerCluster; ipos++) {
1374           //    printf("Index %d\n",ipos);
1375           absId  = indexList[ipos]; 
1376           
1377           //Get position of cell compare to cluster
1378           if(fFillAllPosHisto){
1379             if(fCalorimeter=="EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
1380               
1381               Double_t cellpos[] = {0, 0, 0};
1382               GetEMCALGeometry()->GetGlobal(absId, cellpos);
1383               
1384               fhDeltaCellClusterXNCells->Fill(pos[0]-cellpos[0],nCaloCellsPerCluster) ; 
1385               fhDeltaCellClusterYNCells->Fill(pos[1]-cellpos[1],nCaloCellsPerCluster) ; 
1386               fhDeltaCellClusterZNCells->Fill(pos[2]-cellpos[2],nCaloCellsPerCluster) ;
1387               
1388               fhDeltaCellClusterXE->Fill(pos[0]-cellpos[0],mom.E())  ; 
1389               fhDeltaCellClusterYE->Fill(pos[1]-cellpos[1],mom.E())  ; 
1390               fhDeltaCellClusterZE->Fill(pos[2]-cellpos[2],mom.E())  ; 
1391               
1392               Float_t r     = TMath::Sqrt(pos[0]*pos[0]        +pos[1]*pos[1]);//     +pos[2]*pos[2]);
1393               Float_t rcell = TMath::Sqrt(cellpos[0]*cellpos[0]+cellpos[1]*cellpos[1]);//+cellpos[2]*cellpos[2]);
1394               fhDeltaCellClusterRNCells->Fill(r-rcell, nCaloCellsPerCluster) ; 
1395               fhDeltaCellClusterRE     ->Fill(r-rcell, mom.E())  ; 
1396               
1397               //                                        Float_t celleta = 0, cellphi = 0;
1398               //                                        GetEMCALGeometry()->EtaPhiFromIndex(absId, celleta, cellphi); 
1399               //                                        Int_t imod = -1, iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1;
1400               //                                        GetEMCALGeometry()->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
1401               //                                        GetEMCALGeometry()->GetCellPhiEtaIndexInSModule(imod,iTower,
1402               //                                                                                                                                                                 iIphi, iIeta,iphi,ieta);
1403               //                                        printf("AbsId %d, SM %d, Index eta %d, phi %d\n", absId, imod, ieta, iphi);
1404               //                                        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());
1405               //                                        printf("x cluster %f, x cell %f, cluster-cell %f\n",pos[0], cellpos[0],pos[0]-cellpos[0]);
1406               //                                        printf("y cluster %f, y cell %f, cluster-cell %f\n",pos[1], cellpos[1],pos[1]-cellpos[1]);
1407               //                                        printf("z cluster %f, z cell %f, cluster-cell %f\n",pos[2], cellpos[2],pos[2]-cellpos[2]);
1408               //                                        printf("r cluster %f, r cell %f, cluster-cell %f\n",r,      rcell,     r-rcell);
1409               //                                        
1410               
1411             }//EMCAL and its matrices are available
1412             else if(fCalorimeter=="PHOS" && GetCaloUtils()->IsPHOSGeoMatrixSet()){
1413               TVector3 xyz;
1414               Int_t relId[4], module;
1415               Float_t xCell, zCell;
1416               
1417               GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
1418               module = relId[0];
1419               GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
1420               GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
1421               
1422               fhDeltaCellClusterXNCells->Fill(pos[0]-xyz.X(),nCaloCellsPerCluster) ; 
1423               fhDeltaCellClusterYNCells->Fill(pos[1]-xyz.Y(),nCaloCellsPerCluster) ; 
1424               fhDeltaCellClusterZNCells->Fill(pos[2]-xyz.Z(),nCaloCellsPerCluster) ;
1425               
1426               fhDeltaCellClusterXE->Fill(pos[0]-xyz.X(),mom.E())  ; 
1427               fhDeltaCellClusterYE->Fill(pos[1]-xyz.Y(),mom.E())  ; 
1428               fhDeltaCellClusterZE->Fill(pos[2]-xyz.Z(),mom.E())  ; 
1429               
1430               Float_t r     = TMath::Sqrt(pos[0]*pos[0]  +pos[1]*pos[1]);//     +pos[2]*pos[2]);
1431               Float_t rcell = TMath::Sqrt(xyz.X()*xyz.X()+xyz.Y()*xyz.Y());//+xyz.Z()*xyz.Z());
1432               fhDeltaCellClusterRNCells->Fill(r-rcell, nCaloCellsPerCluster) ; 
1433               fhDeltaCellClusterRE     ->Fill(r-rcell, mom.E())  ; 
1434               
1435               //                          printf("x cluster %f, x cell %f, cluster-cell %f\n",pos[0], cellpos[0],pos[0]-cellpos[0]);
1436               //                        printf("y cluster %f, y cell %f, cluster-cell %f\n",pos[1], cellpos[1],pos[1]-cellpos[1]);
1437               //                        printf("z cluster %f, z cell %f, cluster-cell %f\n",pos[2], cellpos[2],pos[2]-cellpos[2]);
1438               //                                printf("r cluster %f, r cell %f, cluster-cell %f\n",r,      rcell,     r-rcell);
1439             }//PHOS and its matrices are available
1440           }//Fill all position histograms
1441           
1442           //Find maximum energy cluster
1443           if(cell->GetCellAmplitude(absId) > emax) {
1444             imax = ipos;
1445             emax = cell->GetCellAmplitude(absId);
1446             tmax = cell->GetCellTime(absId);
1447           } 
1448           
1449         }// cluster cell loop
1450         
1451         // check time of cells respect to max energy cell
1452         if(nCaloCellsPerCluster > 1){
1453           for (Int_t ipos = 0; ipos < nCaloCellsPerCluster; ipos++) {
1454             if(imax == ipos) continue;
1455             absId  = indexList[ipos]; 
1456             Float_t diff = (tmax-cell->GetCellTime(absId))*1e9;
1457             fhCellTimeSpreadRespectToCellMax->Fill(diff);
1458             if(TMath::Abs(TMath::Abs(diff) > 100)) fhCellIdCellLargeTimeSpread->Fill(absId);
1459           }// fill cell-cluster histogram loop
1460           
1461         }//check time of cells respect to max energy cell
1462         
1463         //-----------------------------------------------------------
1464         //Fill histograms related to single cluster or track matching
1465         //-----------------------------------------------------------
1466         
1467         ClusterHistograms(mom, tof, pos, showerShape, nCaloCellsPerCluster, nModule, nTracksMatched, track, labels, nLabel);    
1468         
1469         
1470         //-----------------------------------------------------------
1471         //Invariant mass
1472         //-----------------------------------------------------------
1473         if(GetDebug()>1) printf("Invariant mass \n");
1474         
1475         //do not do for bad vertex
1476         Float_t fZvtxCut = 40. ;        
1477         if(v[2]<-fZvtxCut || v[2]> fZvtxCut) continue ; //Event can not be used (vertex, centrality,... cuts not fulfilled)
1478         
1479         Int_t nModule2 = -1;
1480         Int_t nCaloCellsPerCluster2=0;
1481         if (nCaloClusters > 1 ) {
1482           for(Int_t jclus = iclus + 1 ; jclus < nCaloClusters ; jclus++) {
1483             AliVCluster* clus2 =  (AliVCluster*)caloClusters->At(jclus);
1484             
1485             //Get cluster kinematics
1486             clus2->GetMomentum(mom2,v);
1487             //Check only certain regions
1488             Bool_t in2 = kTRUE;
1489             if(IsFiducialCutOn()) in2 =  GetFiducialCut()->IsInFiducialCut(mom2,fCalorimeter) ;
1490             if(!in2) continue;  
1491             //Get module of cluster
1492             nModule2 = GetModuleNumber(clus2);
1493             //Cells per cluster
1494             nCaloCellsPerCluster2 = clus2->GetNCells();
1495           }
1496           //Fill invariant mass histograms
1497           //All modules
1498           
1499           //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());
1500           fhIM  ->Fill((mom+mom2).Pt(),(mom+mom2).M());
1501           //Single module
1502           if(nModule == nModule2 && nModule >=0 && nModule < fNModules)
1503             fhIMMod[nModule]->Fill((mom+mom2).Pt(),(mom+mom2).M());
1504           
1505           //Select only clusters with at least 2 cells
1506           if(nCaloCellsPerCluster > 1 && nCaloCellsPerCluster2 > 1) {
1507             //All modules
1508             fhIMCellCut  ->Fill((mom+mom2).Pt(),(mom+mom2).M());
1509             //Single modules
1510             if(nModule == nModule2 && nModule >=0 && nModule < fNModules)
1511               fhIMCellCutMod[nModule]->Fill((mom+mom2).Pt(),(mom+mom2).M());
1512           }
1513           
1514           //Asymetry histograms
1515           fhAsym->Fill((mom+mom2).Pt(),TMath::Abs((mom.E()-mom2.E())/(mom.E()+mom2.E())));
1516           
1517         }// 2nd cluster loop
1518       }////more than 1 cluster in calorimeter   
1519     }//cluster loop
1520     
1521     //Number of clusters histograms
1522     if(nCaloClustersAccepted > 0) fhNClusters->Fill(nCaloClustersAccepted);
1523     //  Number of clusters per module
1524     for(Int_t imod = 0; imod < fNModules; imod++ ){ 
1525       if(GetDebug() > 1) 
1526         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - module %d calo %s clusters %d\n", imod, fCalorimeter.Data(), nClustersInModule[imod]); 
1527       fhNClustersMod[imod]->Fill(nClustersInModule[imod]);
1528     }
1529     delete [] nClustersInModule;
1530     //delete caloClusters;
1531   }// calo clusters array exists
1532   
1533   //----------------------------------------------------------
1534   // CALOCELLS
1535   //----------------------------------------------------------
1536         
1537   Int_t *nCellsInModule = new Int_t[fNModules];
1538   for(Int_t imod = 0; imod < fNModules; imod++ ) nCellsInModule[imod] = 0;
1539   Int_t icol     = -1;
1540   Int_t irow     = -1;
1541   Int_t iRCU     = -1;
1542   Float_t amp    = 0.;
1543   Float_t time   = 0.;
1544   Int_t id       = -1;
1545   Float_t recalF = 1.;
1546   
1547   AliVCaloCells * cell = 0x0; 
1548   Int_t ncells = 0;
1549   if(fCalorimeter == "PHOS") 
1550     cell = GetPHOSCells();
1551   else                        
1552     cell = GetEMCALCells();
1553   
1554   if(!cell) {
1555     printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - STOP: No %s ESD CELLS available for analysis\n",fCalorimeter.Data());
1556     abort();
1557   }
1558   
1559   if(GetDebug() > 0) 
1560     printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - In ESD %s cell entries %d\n", fCalorimeter.Data(), cell->GetNumberOfCells());    
1561   
1562   for (Int_t iCell = 0; iCell < cell->GetNumberOfCells(); iCell++) {      
1563     if(GetDebug() > 2)  printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Cell : amp %f, absId %d \n", cell->GetAmplitude(iCell), cell->GetCellNumber(iCell));
1564     nModule = GetModuleNumberCellIndexes(cell->GetCellNumber(iCell),fCalorimeter, icol, irow, iRCU);
1565     if(GetDebug() > 2) printf("\t module %d, column %d, row %d \n", nModule,icol,irow);
1566     
1567     if(nModule < fNModules) {   
1568       //Check if the cell is a bad channel
1569       if(GetCaloUtils()->IsBadChannelsRemovalSwitchedOn()){
1570         if(fCalorimeter=="EMCAL"){
1571           if(GetCaloUtils()->GetEMCALChannelStatus(nModule,icol,irow)) continue;
1572         }
1573         else {
1574           if(GetCaloUtils()->GetPHOSChannelStatus(nModule,icol,irow)) {
1575             printf("PHOS bad channel\n");
1576             continue;
1577           }
1578         }
1579       }
1580       
1581       //Get Recalibration factor if set
1582       if (GetCaloUtils()->IsRecalibrationOn()) {
1583         if(fCalorimeter == "PHOS") recalF = GetCaloUtils()->GetPHOSChannelRecalibrationFactor(nModule,icol,irow);
1584         else                               recalF = GetCaloUtils()->GetEMCALChannelRecalibrationFactor(nModule,icol,irow);
1585         //if(fCalorimeter == "PHOS")printf("Recalibration factor (sm,row,col)=(%d,%d,%d) -  %f\n",nModule,icol,irow,recalF);
1586       }
1587       
1588       amp     = cell->GetAmplitude(iCell)*recalF;
1589       time    = cell->GetTime(iCell)*1e9;//transform time to ns
1590       if(time < fTimeCutMin || time > fTimeCutMax) continue;
1591       
1592       //if(amp > 3 && fCalorimeter=="EMCAL") printf("Amp = %f, time = %f, (mod, col, row)= (%d,%d,%d)\n",
1593       //                                                                                   amp,time,nModule,icol,irow);
1594       
1595       //printf("%s: time %g\n",fCalorimeter.Data(), time);
1596       id      = cell->GetCellNumber(iCell);
1597       fhAmplitude->Fill(amp);
1598       fhAmpId    ->Fill(amp,id);
1599       fhTime     ->Fill(time);
1600       fhTimeId   ->Fill(time,id);
1601       fhTimeAmp  ->Fill(amp,time);
1602       //Double_t t0 = GetReader()->GetInputEvent()->GetT0();
1603       //printf("---->>> Time EMCal %e, T0 %e, T0 vertex %e, T0 clock %e, T0 trig %d \n",time,t0, 
1604       //           GetReader()->GetInputEvent()->GetT0zVertex(),
1605       //           GetReader()->GetInputEvent()->GetT0clock(),
1606       //           GetReader()->GetInputEvent()->GetT0Trig());
1607       //fhT0Time     ->Fill(time-t0);
1608       //fhT0TimeId   ->Fill(time-t0,id);
1609       //fhT0TimeAmp  ->Fill(amp,time-t0);
1610       
1611       fhAmplitudeMod[nModule]->Fill(amp);
1612       if(fCalorimeter=="EMCAL"){
1613         Int_t ifrac = 0;
1614         if(icol > 15 && icol < 32) ifrac = 1;
1615         else if(icol > 31) ifrac = 2;
1616         fhAmplitudeModFraction[nModule*3+ifrac]->Fill(amp);
1617       }
1618       
1619       fhTimeAmpPerRCU  [nModule*fNRCU+iRCU]->Fill(amp, time);
1620       //printf("id %d, nModule %d, iRCU %d: Histo Name %s\n",id, nModule,iRCU, fhTimeAmpPerRCU[nModule*fNRCU+iRCU]->GetName());
1621       //fhT0TimeAmpPerRCU[nModule*fNRCU+iRCU]->Fill(amp, time-t0);
1622       nCellsInModule[nModule]++;
1623       fhGridCellsMod[nModule]    ->Fill(icol,irow);
1624       fhGridCellsEMod[nModule]   ->Fill(icol,irow,amp);
1625       if(amp > 0.3){
1626         fhGridCellsTimeMod[nModule]->Fill(icol,irow,time);
1627         
1628         //                                      AliESDCaloCells * cell2 = 0x0; 
1629         //                                      if(fCalorimeter == "PHOS") cell2 =  GetReader()->GetInputEvent()->GetPHOSCells();
1630         //                                      else                       cell2 = GetReader()->GetInputEvent()->GetEMCALCells();
1631         //                                      Int_t icol2    = -1;
1632         //                                      Int_t irow2    = -1;
1633         //                                      Int_t iRCU2    = -1;
1634         //                                      Float_t amp2   =  0.;
1635         //                                      Float_t time2  =  0.;
1636         //                                      Int_t id2      = -1;
1637         //                                      Int_t nModule2 = -1;
1638         //                                      for (Int_t iCell2 = 0; iCell2 < ncells; iCell2++) {  
1639         //                                              amp2    = cell2->GetAmplitude(iCell2);
1640         //                                              if(amp2 < 0.3) continue;
1641         //                                              if(iCell2 == iCell) continue;
1642         //                                              time2    = cell2->GetTime(iCell2)*1e9;//transform time to ns
1643         //                                              //printf("%s: time %g\n",fCalorimeter.Data(), time);
1644         //                                              id2      = cell2->GetCellNumber(iCell2);
1645         //                                              nModule2 = GetModuleNumberCellIndexes(cell2->GetCellNumber(iCell2), fCalorimeter, icol2, irow2, iRCU2);
1646         //                                              Int_t index = (nModule2*fNRCU+iRCU2)+(fNModules*fNRCU)*(iRCU+fNRCU*nModule); 
1647         //                                              //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());
1648         //                                              fhTimeCorrRCU[index]->Fill(time,time2); 
1649         //                                              
1650         //                                      }// second cell loop
1651       }// amplitude cut
1652     }//nmodules
1653     
1654     //Get Eta-Phi position of Cell
1655     //if(fFillAllPosHisto)
1656     {
1657       if(fCalorimeter=="EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
1658         Float_t celleta = 0.;
1659         Float_t cellphi = 0.;
1660         GetEMCALGeometry()->EtaPhiFromIndex(id, celleta, cellphi); 
1661         fhEtaPhiAmp->Fill(celleta,cellphi,amp);
1662         Double_t cellpos[] = {0, 0, 0};
1663         GetEMCALGeometry()->GetGlobal(id, cellpos);
1664         fhXCellE->Fill(cellpos[0],amp)  ; 
1665         fhYCellE->Fill(cellpos[1],amp)  ; 
1666         fhZCellE->Fill(cellpos[2],amp)  ;
1667         Float_t rcell = TMath::Sqrt(cellpos[0]*cellpos[0]+cellpos[1]*cellpos[1]);//+cellpos[2]*cellpos[2]);
1668         fhRCellE->Fill(rcell,amp)  ;
1669         fhXYZCell->Fill(cellpos[0],cellpos[1],cellpos[2])  ;
1670       }//EMCAL Cells
1671       else if(fCalorimeter=="PHOS" && GetCaloUtils()->IsPHOSGeoMatrixSet()){
1672         TVector3 xyz;
1673         Int_t relId[4], module;
1674         Float_t xCell, zCell;
1675         
1676         GetPHOSGeometry()->AbsToRelNumbering(id,relId);
1677         module = relId[0];
1678         GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
1679         GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
1680         Float_t rcell = TMath::Sqrt(xyz.X()*xyz.X()+xyz.Y()*xyz.Y());
1681         fhXCellE ->Fill(xyz.X(),amp)  ; 
1682         fhYCellE ->Fill(xyz.Y(),amp)  ; 
1683         fhZCellE ->Fill(xyz.Z(),amp)  ;
1684         fhRCellE ->Fill(rcell  ,amp)  ;
1685         fhXYZCell->Fill(xyz.X(),xyz.Y(),xyz.Z())  ;
1686       }//PHOS cells
1687     }//fill cell position histograms
1688     if     (fCalorimeter=="EMCAL" && amp > fEMCALCellAmpMin) ncells ++ ;
1689     else if(fCalorimeter=="PHOS"  && amp > fPHOSCellAmpMin)  ncells ++ ;
1690     //else  
1691     //  printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - no %s CELLS passed the analysis cut\n",fCalorimeter.Data());       
1692   }//cell loop
1693   if(ncells > 0 )fhNCells->Fill(ncells) ; //fill the cells after the cut 
1694   
1695   //Number of cells per module
1696         for(Int_t imod = 0; imod < fNModules; imod++ ) {
1697                 if(GetDebug() > 1) 
1698                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - module %d calo %s cells %d\n", imod, fCalorimeter.Data(), nCellsInModule[imod]); 
1699                 fhNCellsMod[imod]->Fill(nCellsInModule[imod]) ;
1700         }
1701         delete [] nCellsInModule;
1702         
1703         if(GetDebug() > 0)
1704                 printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - End \n");
1705 }
1706
1707
1708 //_____________________________________________________________________________________________
1709 void AliAnaCalorimeterQA::ClusterHistograms(const TLorentzVector mom, const Double_t tof, 
1710                                             Float_t *pos, Float_t *showerShape,
1711                                             const Int_t nCaloCellsPerCluster,const Int_t nModule,
1712                                             const Int_t nTracksMatched,  const AliVTrack * track,  
1713                                             const Int_t * labels, const Int_t nLabels){
1714   //Fill CaloCluster related histograms
1715         
1716   AliAODMCParticle * aodprimary  = 0x0;
1717   TParticle * primary = 0x0;
1718   Int_t tag = 0;        
1719   
1720   Float_t e   = mom.E();
1721   Float_t pt  = mom.Pt();
1722   Float_t eta = mom.Eta();
1723   Float_t phi = mom.Phi();
1724   if(phi < 0) phi +=TMath::TwoPi();
1725   if(GetDebug() > 0) {
1726     printf("AliAnaCalorimeterQA::ClusterHistograms() - cluster: E %2.3f, pT %2.3f, eta %2.3f, phi %2.3f \n",e,pt,eta,phi*TMath::RadToDeg());
1727     if(IsDataMC()) {
1728       //printf("\t Primaries: nlabels %d, labels pointer %p\n",nLabels,labels);
1729       printf("\t Primaries: nlabels %d\n",nLabels);
1730       if(!nLabels || !labels) printf("\t Strange, no labels!!!\n");
1731     }
1732   }
1733   
1734   fhE     ->Fill(e);    
1735   if(nModule >=0 && nModule < fNModules) fhEMod[nModule]->Fill(e);
1736   if(fFillAllTH12){
1737     fhPt     ->Fill(pt);
1738     fhPhi    ->Fill(phi);
1739     fhEta    ->Fill(eta);
1740   }
1741   fhEtaPhiE->Fill(eta,phi,e);
1742   
1743   //Cells per cluster
1744   fhNCellsPerCluster   ->Fill(e, nCaloCellsPerCluster,eta);
1745   fhNCellsPerClusterMIP->Fill(e, nCaloCellsPerCluster,eta);
1746   
1747   //Position
1748   //if(fFillAllPosHisto)
1749   {
1750     fhXE     ->Fill(pos[0],e);
1751     fhYE     ->Fill(pos[1],e);
1752     fhZE     ->Fill(pos[2],e);
1753     fhXYZ    ->Fill(pos[0], pos[1],pos[2]);
1754    
1755     fhXNCells->Fill(pos[0],nCaloCellsPerCluster);
1756     fhYNCells->Fill(pos[1],nCaloCellsPerCluster);
1757     fhZNCells->Fill(pos[2],nCaloCellsPerCluster);
1758     Float_t rxyz = TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]);//+pos[2]*pos[2]);
1759     fhRE     ->Fill(rxyz,e);
1760     fhRNCells->Fill(rxyz  ,nCaloCellsPerCluster);
1761   }
1762   
1763   fhClusterTimeEnergy->Fill(e,tof);
1764         
1765   //Shower shape parameters
1766   fhLambda->Fill(showerShape[0], showerShape[1], e);
1767   fhDispersion->Fill(showerShape[2],e);
1768   
1769   if(nModule >=0 && nModule < fNModules) fhNCellsPerClusterMod[nModule]->Fill(e, nCaloCellsPerCluster);
1770   
1771   //Fill histograms only possible when simulation
1772   if(IsDataMC() && nLabels > 0 && labels){
1773     
1774     //Play with the MC stack if available
1775     Int_t label = labels[0];
1776     
1777     if(label < 0) {
1778       if(GetDebug() >= 0) printf("AliAnaCalorimeterQA::ClusterHistograms() *** bad label ***:  label %d \n", label);
1779       return;
1780     }
1781     
1782     Int_t pdg  =-1; Int_t pdg0  =-1;Int_t status = -1; Int_t iMother = -1; Int_t iParent = -1;
1783     Float_t vxMC= 0; Float_t vyMC = 0;  
1784     Float_t eMC = 0; Float_t ptMC= 0; Float_t phiMC =0; Float_t etaMC = 0;
1785     Int_t charge = 0;   
1786     
1787     //Check the origin.
1788     tag = GetMCAnalysisUtils()->CheckOrigin(labels,nLabels, GetReader(),0);
1789     
1790     if(GetReader()->ReadStack() && !GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCUnknown)){ //it MC stack and known tag
1791       
1792       if( label >= GetMCStack()->GetNtrack()) {
1793         if(GetDebug() >= 0) printf("AliAnaCalorimeterQA::ClusterHistograms() *** large label ***:  label %d, n tracks %d \n", label, GetMCStack()->GetNtrack());
1794         return ;
1795       }
1796       
1797       primary = GetMCStack()->Particle(label);
1798       iMother = label;
1799       pdg0    = TMath::Abs(primary->GetPdgCode());
1800       pdg     = pdg0;
1801       status  = primary->GetStatusCode();
1802       vxMC    = primary->Vx();
1803       vyMC    = primary->Vy();
1804       iParent = primary->GetFirstMother();
1805       
1806       if(GetDebug() > 1 ) {
1807         printf("AliAnaCalorimeterQA::ClusterHistograms() - Cluster most contributing mother: \n");
1808         printf("\t Mother label %d, pdg %d, %s, status %d, parent %d \n",iMother, pdg0, primary->GetName(),status, iParent);
1809       }
1810       
1811       //Get final particle, no conversion products
1812       if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCConversion)){
1813         //Get the parent
1814         primary = GetMCStack()->Particle(iParent);
1815         pdg = TMath::Abs(primary->GetPdgCode());
1816         if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted cluster!. Find before conversion: \n");
1817         while((pdg == 22 || pdg == 11) && status != 1){
1818           iMother = iParent;
1819           primary = GetMCStack()->Particle(iMother);
1820           status  = primary->GetStatusCode();
1821           iParent = primary->GetFirstMother();
1822           pdg     = TMath::Abs(primary->GetPdgCode());
1823           if(GetDebug() > 1 )printf("\t pdg %d, index %d, %s, status %d \n",pdg, iMother,  primary->GetName(),status);  
1824         }       
1825         
1826         if(GetDebug() > 1 ) {
1827           printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted Cluster mother before conversion: \n");
1828           printf("\t Mother label %d, pdg %d, %s, status %d, parent %d \n",iMother, pdg, primary->GetName(), status, iParent);
1829         }
1830         
1831       }
1832       
1833       //Overlapped pi0 (or eta, there will be very few), get the meson
1834       if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1835          GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1836         if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped Meson decay!, Find it: \n");
1837         while(pdg != 111 && pdg != 221){
1838           iMother = iParent;
1839           primary = GetMCStack()->Particle(iMother);
1840           status  = primary->GetStatusCode();
1841           iParent = primary->GetFirstMother();
1842           pdg     = TMath::Abs(primary->GetPdgCode());
1843           if(GetDebug() > 1 ) printf("\t pdg %d, %s, index %d\n",pdg,  primary->GetName(),iMother);
1844           if(iMother==-1) {
1845             printf("AliAnaCalorimeterQA::ClusterHistograms() - Tagged as Overlapped photon but meson not found, why?\n");
1846             //break;
1847           }
1848         }
1849         
1850         if(GetDebug() > 2 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped %s decay, label %d \n", 
1851                                    primary->GetName(),iMother);
1852       }
1853       
1854       eMC    = primary->Energy();
1855       ptMC   = primary->Pt();
1856       phiMC  = primary->Phi();
1857       etaMC  = primary->Eta();
1858       pdg    = TMath::Abs(primary->GetPdgCode());
1859       charge = (Int_t) TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
1860       
1861     }
1862     else if(GetReader()->ReadAODMCParticles() && !GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCUnknown)){//it MC AOD and known tag
1863       //Get the list of MC particles
1864       if(!GetReader()->GetAODMCParticles(0))    {
1865         printf("AliAnaCalorimeterQA::ClusterHistograms() -  MCParticles not available!\n");
1866         abort();
1867       }         
1868       
1869       aodprimary = (AliAODMCParticle*) (GetReader()->GetAODMCParticles(0))->At(label);
1870       iMother = label;
1871       pdg0    = TMath::Abs(aodprimary->GetPdgCode());
1872       pdg     = pdg0;
1873       status  = aodprimary->IsPrimary();
1874       vxMC    = aodprimary->Xv();
1875       vyMC    = aodprimary->Yv();
1876       iParent = aodprimary->GetMother();
1877       
1878       if(GetDebug() > 1 ) {
1879         printf("AliAnaCalorimeterQA::ClusterHistograms() - Cluster most contributing mother: \n");
1880         printf("\t Mother label %d, pdg %d, Primary? %d, Physical Primary? %d, parent %d \n",
1881                iMother, pdg0, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary(), iParent);
1882       }
1883       
1884       //Get final particle, no conversion products
1885       if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCConversion)){
1886         if(GetDebug() > 1 ) 
1887           printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted cluster!. Find before conversion: \n");
1888         //Get the parent
1889         aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iParent);
1890         pdg = TMath::Abs(aodprimary->GetPdgCode());
1891         while ((pdg == 22 || pdg == 11) && !aodprimary->IsPhysicalPrimary()) {
1892           iMother    = iParent;
1893           aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iMother);
1894           status     = aodprimary->IsPrimary();
1895           iParent    = aodprimary->GetMother();
1896           pdg        = TMath::Abs(aodprimary->GetPdgCode());
1897           if(GetDebug() > 1 )
1898             printf("\t pdg %d, index %d, Primary? %d, Physical Primary? %d \n",
1899                    pdg, iMother, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary());     
1900         }       
1901         
1902         if(GetDebug() > 1 ) {
1903           printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted Cluster mother before conversion: \n");
1904           printf("\t Mother label %d, pdg %d, parent %d, Primary? %d, Physical Primary? %d \n",
1905                  iMother, pdg, iParent, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary());
1906         }
1907         
1908       }
1909       
1910       //Overlapped pi0 (or eta, there will be very few), get the meson
1911       if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1912          GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1913         if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped Meson decay!, Find it: PDG %d, mom %d \n",pdg, iMother);
1914         while(pdg != 111 && pdg != 221){
1915           
1916           iMother    = iParent;
1917           aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iMother);
1918           status     = aodprimary->IsPrimary();
1919           iParent    = aodprimary->GetMother();
1920           pdg        = TMath::Abs(aodprimary->GetPdgCode());
1921           
1922           if(GetDebug() > 1 ) printf("\t pdg %d, index %d\n",pdg, iMother);
1923           
1924           if(iMother==-1) {
1925             printf("AliAnaCalorimeterQA::ClusterHistograms() - Tagged as Overlapped photon but meson not found, why?\n");
1926             //break;
1927           }
1928         }       
1929         
1930         if(GetDebug() > 2 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped %s decay, label %d \n", 
1931                                    aodprimary->GetName(),iMother);
1932       } 
1933       
1934       status = aodprimary->IsPrimary();
1935       eMC    = aodprimary->E();
1936       ptMC   = aodprimary->Pt();
1937       phiMC  = aodprimary->Phi();
1938       etaMC  = aodprimary->Eta();
1939       pdg    = TMath::Abs(aodprimary->GetPdgCode());
1940       charge = aodprimary->Charge();
1941       
1942     }
1943     
1944     //Float_t vz = primary->Vz();
1945     Float_t rVMC = TMath::Sqrt(vxMC*vxMC + vyMC*vyMC);
1946     if((pdg == 22 || TMath::Abs(pdg)==11) && status!=1) {
1947       fhEMVxyz   ->Fill(vxMC,vyMC);//,vz);
1948       fhEMR      ->Fill(e,rVMC);
1949     }
1950     
1951     //printf("reco e %f, pt %f, phi %f, eta %f \n", e, pt, phi, eta);
1952     //printf("prim e %f, pt %f, phi %f, eta %f \n", eMC,ptMC,phiMC ,etaMC );
1953     //printf("vertex: vx %f, vy %f, vz %f, r %f \n", vxMC, vyMC, vz, r);
1954     
1955     
1956     fh2E      ->Fill(e, eMC);
1957     fh2Pt     ->Fill(pt, ptMC);
1958     fh2Phi    ->Fill(phi, phiMC);
1959     fh2Eta    ->Fill(eta, etaMC);
1960     fhDeltaE  ->Fill(eMC-e);
1961     fhDeltaPt ->Fill(ptMC-pt);
1962     fhDeltaPhi->Fill(phiMC-phi);
1963     fhDeltaEta->Fill(etaMC-eta);
1964     if(eMC   > 0) fhRatioE  ->Fill(e/eMC);
1965     if(ptMC  > 0) fhRatioPt ->Fill(pt/ptMC);
1966     if(phiMC > 0) fhRatioPhi->Fill(phi/phiMC);
1967     if(etaMC > 0) fhRatioEta->Fill(eta/etaMC);                  
1968     
1969     
1970     //Overlapped pi0 (or eta, there will be very few)
1971     if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1972        GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1973       fhPi0E     ->Fill(e,eMC); 
1974       fhPi0Pt    ->Fill(pt,ptMC);
1975       fhPi0Eta   ->Fill(eta,etaMC);     
1976       fhPi0Phi   ->Fill(phi,phiMC);
1977       if( nTracksMatched > 0){
1978         fhPi0ECharged     ->Fill(e,eMC);                
1979         fhPi0PtCharged    ->Fill(pt,ptMC);
1980         fhPi0PhiCharged   ->Fill(phi,phiMC);
1981         fhPi0EtaCharged   ->Fill(eta,etaMC);
1982       }
1983     }//Overlapped pizero decay
1984     else if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPhoton)){
1985       fhGamE     ->Fill(e,eMC); 
1986       fhGamPt    ->Fill(pt,ptMC);
1987       fhGamEta   ->Fill(eta,etaMC);     
1988       fhGamPhi   ->Fill(phi,phiMC);
1989       fhGamDeltaE  ->Fill(eMC-e);
1990       fhGamDeltaPt ->Fill(ptMC-pt);     
1991       fhGamDeltaPhi->Fill(phiMC-phi);
1992       fhGamDeltaEta->Fill(etaMC-eta);
1993       if(eMC > 0) fhGamRatioE  ->Fill(e/eMC);
1994       if(ptMC     > 0) fhGamRatioPt ->Fill(pt/ptMC);
1995       if(phiMC    > 0) fhGamRatioPhi->Fill(phi/phiMC);
1996       if(etaMC    > 0) fhGamRatioEta->Fill(eta/etaMC);
1997       if( nTracksMatched > 0){
1998         fhGamECharged     ->Fill(e,eMC);                
1999         fhGamPtCharged    ->Fill(pt,ptMC);
2000         fhGamPhiCharged   ->Fill(phi,phiMC);
2001         fhGamEtaCharged   ->Fill(eta,etaMC);
2002       }
2003     }//photon
2004     else if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCElectron)){
2005       fhEleE     ->Fill(e,eMC); 
2006       fhElePt    ->Fill(pt,ptMC);
2007       fhEleEta   ->Fill(eta,etaMC);     
2008       fhElePhi   ->Fill(phi,phiMC);
2009       fhEMVxyz   ->Fill(vxMC,vyMC);//,vz);
2010       fhEMR      ->Fill(e,rVMC);
2011       if( nTracksMatched > 0){
2012         fhEleECharged     ->Fill(e,eMC);                
2013         fhElePtCharged    ->Fill(pt,ptMC);
2014         fhElePhiCharged   ->Fill(phi,phiMC);
2015         fhEleEtaCharged   ->Fill(eta,etaMC);
2016       }
2017     }
2018     else if(charge == 0){
2019       fhNeHadE     ->Fill(e,eMC);       
2020       fhNeHadPt    ->Fill(pt,ptMC);
2021       fhNeHadEta   ->Fill(eta,etaMC);   
2022       fhNeHadPhi   ->Fill(phi,phiMC);   
2023       fhHaVxyz     ->Fill(vxMC,vyMC);//,vz);
2024       fhHaR        ->Fill(e,rVMC);
2025       if( nTracksMatched > 0){
2026         fhNeHadECharged     ->Fill(e,eMC);              
2027         fhNeHadPtCharged    ->Fill(pt,ptMC);
2028         fhNeHadPhiCharged   ->Fill(phi,phiMC);
2029         fhNeHadEtaCharged   ->Fill(eta,etaMC);
2030       }
2031     }
2032     else if(charge!=0){
2033       fhChHadE     ->Fill(e,eMC);       
2034       fhChHadPt    ->Fill(pt,ptMC);
2035       fhChHadEta   ->Fill(eta,etaMC);   
2036       fhChHadPhi   ->Fill(phi,phiMC);   
2037       fhHaVxyz     ->Fill(vxMC,vyMC);//,vz);
2038       fhHaR        ->Fill(e,rVMC);
2039       if( nTracksMatched > 0){
2040         fhChHadECharged     ->Fill(e,eMC);              
2041         fhChHadPtCharged    ->Fill(pt,ptMC);
2042         fhChHadPhiCharged   ->Fill(phi,phiMC);
2043         fhChHadEtaCharged   ->Fill(eta,etaMC);
2044       }
2045     }
2046   }//Work with MC
2047   
2048         
2049   //Match tracks and clusters
2050   //To be Modified in case of AODs
2051         
2052   //if(ntracksmatched==1 && trackIndex==-1) ntracksmatched=0;
2053         
2054   if( nTracksMatched > 0){
2055     if(fFillAllTH12){
2056       fhECharged      ->Fill(e);        
2057       fhPtCharged     ->Fill(pt);
2058       fhPhiCharged    ->Fill(phi);
2059       fhEtaCharged    ->Fill(eta);
2060     }
2061     fhEtaPhiECharged->Fill(eta,phi,e);          
2062     fhNCellsPerClusterMIPCharged->Fill(e, nCaloCellsPerCluster,eta);
2063     
2064     //printf("track index %d ntracks %d\n", esd->GetNumberOfTracks());  
2065     //Study the track and matched cluster if track exists.
2066     if(!track) return;
2067     Double_t emcpos[3] = {0.,0.,0.};
2068     Double_t emcmom[3] = {0.,0.,0.};
2069     Double_t radius    = 441.0; //[cm] EMCAL radius +13cm
2070     Double_t bfield    = 0.;
2071     Double_t tphi      = 0;
2072     Double_t teta      = 0;
2073     Double_t tmom      = 0;
2074     Double_t tpt       = 0;
2075     Double_t tmom2     = 0;
2076     Double_t tpcSignal = 0;
2077     Bool_t okpos = kFALSE;
2078     Bool_t okmom = kFALSE;
2079     Bool_t okout = kFALSE;
2080     Int_t nITS   = 0;
2081     Int_t nTPC   = 0;
2082     
2083     //In case of ESDs get the parameters in this way
2084     //          if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
2085     if (track->GetOuterParam() ) {
2086       okout = kTRUE;
2087       
2088       bfield = GetReader()->GetInputEvent()->GetMagneticField();
2089       okpos = track->GetOuterParam()->GetXYZAt(radius,bfield,emcpos);
2090       okmom = track->GetOuterParam()->GetPxPyPzAt(radius,bfield,emcmom);
2091       if(!(okpos && okmom)) return;
2092       
2093       TVector3 position(emcpos[0],emcpos[1],emcpos[2]);
2094       TVector3 momentum(emcmom[0],emcmom[1],emcmom[2]);
2095       tphi = position.Phi();
2096       teta = position.Eta();
2097       tmom = momentum.Mag();
2098       
2099       //Double_t tphi  = track->GetOuterParam()->Phi();
2100       //Double_t teta  = track->GetOuterParam()->Eta();
2101       //Double_t tmom  = track->GetOuterParam()->P();
2102       tpt       = track->Pt();
2103       tmom2     = track->P();
2104       tpcSignal = track->GetTPCsignal();
2105       
2106       nITS = track->GetNcls(0);
2107       nTPC = track->GetNcls(1);
2108     }//Outer param available 
2109     //}// ESDs
2110     //                  else if(GetReader()->GetDataType()==AliCaloTrackReader::kAOD) {
2111     //                          AliAODPid* pid = (AliAODPid*) ((AliAODTrack *) track)->GetDetPid();
2112     //                          if (pid) {
2113     //                                  okout = kTRUE;
2114     //                                  pid->GetEMCALPosition(emcpos);
2115     //                                  pid->GetEMCALMomentum(emcmom);  
2116     //                                  
2117     //                                  TVector3 position(emcpos[0],emcpos[1],emcpos[2]);
2118     //                                  TVector3 momentum(emcmom[0],emcmom[1],emcmom[2]);
2119     //                                  tphi = position.Phi();
2120     //                                  teta = position.Eta();
2121     //                                  tmom = momentum.Mag();
2122     //                                  
2123     //                                  tpt       = ((AliAODTrack*)track)->Pt();
2124     //                                  tmom2     = ((AliAODTrack*)track)->P();
2125     //                                  tpcSignal = pid->GetTPCsignal();
2126     //                          
2127     //                                  //nITS = ((AliAODTrack*)track)->GetNcls(0);
2128     //                                  //nTPC = ((AliAODTrack*)track)->GetNcls(1);
2129     //                          }//Outer param available 
2130     //                  }//AODs
2131     //                  else return; //Do nothing case not implemented.
2132                 
2133     if(okout){
2134       Double_t deta = teta - eta;
2135       Double_t dphi = tphi - phi;
2136       if(dphi > TMath::Pi()) dphi -= 2*TMath::Pi();
2137       if(dphi < -TMath::Pi()) dphi += 2*TMath::Pi();
2138       Double_t dR = sqrt(dphi*dphi + deta*deta);
2139                         
2140       Double_t pOverE = tmom/e;
2141                         
2142       fh1pOverE->Fill(tpt, pOverE);
2143       if(dR < 0.02) fh1pOverER02->Fill(tpt,pOverE);
2144                         
2145       fh1dR->Fill(dR);
2146       fh2MatchdEdx->Fill(tmom2,tpcSignal);
2147                         
2148       if(IsDataMC() && primary){ 
2149         Int_t pdg = primary->GetPdgCode();
2150         Double_t  charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
2151                                 
2152         if(TMath::Abs(pdg) == 11){
2153           fhMCEle1pOverE->Fill(tpt,pOverE);
2154           fhMCEle1dR->Fill(dR);
2155           fhMCEle2MatchdEdx->Fill(tmom2,tpcSignal);             
2156           if(dR < 0.02) fhMCEle1pOverER02->Fill(tpt,pOverE);
2157         }
2158         else if(charge!=0){
2159           fhMCChHad1pOverE->Fill(tpt,pOverE);
2160           fhMCChHad1dR->Fill(dR);
2161           fhMCChHad2MatchdEdx->Fill(tmom2,tpcSignal);   
2162           if(dR < 0.02) fhMCChHad1pOverER02->Fill(tpt,pOverE);
2163         }
2164         else if(charge == 0){
2165           fhMCNeutral1pOverE->Fill(tpt,pOverE);
2166           fhMCNeutral1dR->Fill(dR);
2167           fhMCNeutral2MatchdEdx->Fill(tmom2,tpcSignal); 
2168           if(dR < 0.02) fhMCNeutral1pOverER02->Fill(tpt,pOverE);
2169         }
2170       }//DataMC
2171       
2172       if(dR < 0.02 && pOverE > 0.5 && pOverE < 1.5
2173          && nCaloCellsPerCluster > 1 && nITS > 3 && nTPC > 20) {
2174         fh2EledEdx->Fill(tmom2,tpcSignal);
2175       }
2176     }
2177     else{//no ESD external param or AODPid
2178       //                                        ULong_t status=AliESDtrack::kTPCrefit;
2179       //                                status|=AliESDtrack::kITSrefit;
2180       //printf("track status %d\n", track->GetStatus() );
2181       //                                fhEChargedNoOut      ->Fill(e);         
2182       //                                fhPtChargedNoOut     ->Fill(pt);
2183       //                                fhPhiChargedNoOut    ->Fill(phi);
2184       //                                fhEtaChargedNoOut    ->Fill(eta);
2185       //                                fhEtaPhiChargedNoOut ->Fill(eta,phi);
2186       //                                if(GetDebug() >= 0 && ((track->GetStatus() & status) == status)) printf("ITS+TPC\n");
2187       if(GetDebug() >= 0) printf("No ESD external param or AliAODPid \n");
2188       
2189     }//No out params
2190   }//matched clusters with tracks
2191   
2192 }// Clusters
2193
2194 //__________________________________
2195 //void AliAnaCalorimeterQA::CorrelateCalorimeters(TRefArray* refArray){
2196 //  // Correlate information from PHOS and EMCAL
2197 //      TRefArray * caloClustersEMCAL = 0;
2198 //      TRefArray * caloClustersPHOS  = 0;
2199 //      
2200 //  // Get once the array of clusters per calorimeter, avoid an extra loop.
2201 //  if(fCalorimeter == "EMCAL"){ 
2202 //    caloClustersPHOS = new TRefArray();
2203 //    GetReader()->GetInputEvent()->GetPHOSClusters(caloClustersPHOS);
2204 //    caloClustersEMCAL = new TRefArray(*refArray);
2205 //  }
2206 //  else if(fCalorimeter == "PHOS") { 
2207 //    caloClustersEMCAL = new TRefArray();
2208 //    GetReader()->GetInputEvent()->GetEMCALClusters (caloClustersEMCAL);
2209 //    caloClustersPHOS = new TRefArray(*refArray);
2210 //  }
2211 //  
2212 //  //Fill histograms with clusters
2213 //  
2214 //  fhCaloCorrNClusters->Fill(caloClustersEMCAL->GetEntriesFast(),caloClustersPHOS->GetEntriesFast());
2215 //  Float_t sumClusterEnergyEMCAL = 0;
2216 //  Float_t sumClusterEnergyPHOS  = 0;
2217 //  Int_t iclus = 0;
2218 //  for(iclus = 0 ; iclus <  caloClustersEMCAL->GetEntriesFast() ; iclus++) 
2219 //    sumClusterEnergyEMCAL += ((AliVCluster*)caloClustersEMCAL->At(iclus))->E();
2220 //  for(iclus = 0 ; iclus <  caloClustersPHOS->GetEntriesFast(); iclus++) 
2221 //    sumClusterEnergyPHOS += ((AliVCluster*)caloClustersPHOS->At(iclus))->E();
2222 //  fhCaloCorrEClusters->Fill(sumClusterEnergyEMCAL,sumClusterEnergyPHOS);
2223 //  
2224 //  //Fill histograms with cells
2225 //  
2226 //  AliVCaloCells * cellsEMCAL = GetReader()->GetInputEvent()->GetEMCALCells();
2227 //  AliVCaloCells * cellsPHOS  = GetReader()->GetInputEvent()->GetPHOSCells();
2228 //  fhCaloCorrNCells   ->Fill(cellsEMCAL->GetNumberOfCells(),cellsPHOS->GetNumberOfCells());
2229 //  
2230 //  Int_t icell = 0;
2231 //  Float_t sumCellEnergyEMCAL = 0;
2232 //  Float_t sumCellEnergyPHOS  = 0;
2233 //  for(icell = 0 ; icell < cellsEMCAL->GetNumberOfCells()  ; icell++) 
2234 //    sumCellEnergyEMCAL += cellsEMCAL->GetAmplitude(icell);
2235 //  for(icell = 0 ; icell <  cellsPHOS->GetNumberOfCells(); icell++) 
2236 //    sumCellEnergyPHOS += cellsPHOS->GetAmplitude(icell);
2237 //  fhCaloCorrECells->Fill(sumCellEnergyEMCAL,sumCellEnergyPHOS);
2238 //  if(GetDebug() > 0 ){
2239 //    printf("AliAnaCalorimeterQA::CorrelateCalorimeters() - ESD: \n");
2240 //    printf("\t EMCAL: N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2241 //           cellsEMCAL->GetNumberOfCells(),caloClustersEMCAL->GetEntriesFast(),sumCellEnergyEMCAL,sumClusterEnergyEMCAL);
2242 //    printf("\t PHOS : N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2243 //           cellsPHOS->GetNumberOfCells(),caloClustersPHOS->GetEntriesFast(),sumCellEnergyPHOS,sumClusterEnergyPHOS);
2244 //  }
2245 //      
2246 //      delete caloClustersEMCAL;
2247 //      delete caloClustersPHOS;
2248 //      
2249 //}
2250
2251 //__________________________________
2252 void AliAnaCalorimeterQA::CorrelateCalorimeters(){
2253   // Correlate information from PHOS and EMCAL
2254   TObjArray * caloClustersEMCAL = GetAODEMCAL();
2255   TObjArray * caloClustersPHOS  = GetAODPHOS();
2256   
2257   //Fill histograms with clusters
2258   
2259   fhCaloCorrNClusters->Fill(caloClustersEMCAL->GetEntriesFast(),caloClustersPHOS->GetEntriesFast());
2260   Float_t sumClusterEnergyEMCAL = 0;
2261   Float_t sumClusterEnergyPHOS  = 0;
2262   Int_t iclus = 0;
2263   for(iclus = 0 ; iclus <  caloClustersEMCAL->GetEntriesFast() ; iclus++) 
2264     sumClusterEnergyEMCAL += ((AliVCluster*)caloClustersEMCAL->At(iclus))->E();
2265   for(iclus = 0 ; iclus <  caloClustersPHOS->GetEntriesFast(); iclus++) 
2266     sumClusterEnergyPHOS += ((AliVCluster*)caloClustersPHOS->At(iclus))->E();
2267   fhCaloCorrEClusters->Fill(sumClusterEnergyEMCAL,sumClusterEnergyPHOS);
2268   
2269   //Fill histograms with cells
2270   
2271   AliVCaloCells * cellsEMCAL = GetEMCALCells();
2272   AliVCaloCells * cellsPHOS  = GetPHOSCells();
2273   fhCaloCorrNCells   ->Fill(cellsEMCAL->GetNumberOfCells(),cellsPHOS->GetNumberOfCells());
2274   
2275   Int_t icell = 0;
2276   Float_t sumCellEnergyEMCAL = 0;
2277   Float_t sumCellEnergyPHOS  = 0;
2278   for(icell = 0 ; icell < cellsEMCAL->GetNumberOfCells()  ; icell++) 
2279     sumCellEnergyEMCAL += cellsEMCAL->GetAmplitude(icell);
2280   for(icell = 0 ; icell <  cellsPHOS->GetNumberOfCells(); icell++) 
2281     sumCellEnergyPHOS += cellsPHOS->GetAmplitude(icell);
2282   fhCaloCorrECells->Fill(sumCellEnergyEMCAL,sumCellEnergyPHOS);
2283   if(GetDebug() > 0 ){
2284     printf("AliAnaCalorimeterQA::CorrelateCalorimeters() - ESD: \n");
2285     printf("\t EMCAL: N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2286            cellsEMCAL->GetNumberOfCells(),caloClustersEMCAL->GetEntriesFast(),sumCellEnergyEMCAL,sumClusterEnergyEMCAL);
2287     printf("\t PHOS : N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2288            cellsPHOS->GetNumberOfCells(),caloClustersPHOS->GetEntriesFast(),sumCellEnergyPHOS,sumClusterEnergyPHOS);
2289   }
2290 }
2291
2292
2293 //______________________________________________________________________________
2294 void AliAnaCalorimeterQA::MCHistograms(const TLorentzVector mom, const Int_t pdg){
2295   //Fill pure monte carlo related histograms
2296         
2297   Float_t eMC    = mom.E();
2298   Float_t ptMC   = mom.Pt();
2299   Float_t phiMC  = mom.Phi();
2300   if(phiMC < 0) 
2301     phiMC  += TMath::TwoPi();
2302   Float_t etaMC  = mom.Eta();
2303   
2304   if (TMath::Abs(etaMC) > 1) return;
2305   
2306   Bool_t in = kTRUE;
2307   if(IsFiducialCutOn()) in =  GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
2308   
2309   if (pdg==22) {
2310     fhGenGamPt ->Fill(ptMC);
2311     fhGenGamEta->Fill(etaMC);
2312     fhGenGamPhi->Fill(phiMC);
2313     if(in){
2314       fhGenGamAccE  ->Fill(eMC);
2315       fhGenGamAccPt ->Fill(ptMC);
2316       fhGenGamAccEta->Fill(etaMC);
2317       fhGenGamAccPhi->Fill(phiMC);                                      
2318     }
2319   }
2320   else if (pdg==111) {
2321     fhGenPi0Pt ->Fill(ptMC);
2322     fhGenPi0Eta->Fill(etaMC);
2323     fhGenPi0Phi->Fill(phiMC);
2324     if(in){
2325       fhGenPi0AccE  ->Fill(eMC);                                        
2326       fhGenPi0AccPt ->Fill(ptMC);
2327       fhGenPi0AccEta->Fill(etaMC);
2328       fhGenPi0AccPhi->Fill(phiMC);                                      
2329     }
2330   }
2331   else if (pdg==221) {
2332     fhGenEtaPt ->Fill(ptMC);
2333     fhGenEtaEta->Fill(etaMC);
2334     fhGenEtaPhi->Fill(phiMC);
2335   }
2336   else if (pdg==223) {
2337     fhGenOmegaPt ->Fill(ptMC);
2338     fhGenOmegaEta->Fill(etaMC);
2339     fhGenOmegaPhi->Fill(phiMC);
2340   }
2341   else if (TMath::Abs(pdg)==11) {
2342     fhGenElePt ->Fill(ptMC);
2343     fhGenEleEta->Fill(etaMC);
2344     fhGenElePhi->Fill(phiMC);
2345   }     
2346   
2347 }
2348
2349 //________________________________________________________________________
2350 void AliAnaCalorimeterQA::ReadHistograms(TList* outputList)
2351 {
2352   // Needed when Terminate is executed in distributed environment
2353   // Refill analysis histograms of this class with corresponding histograms in output list. 
2354         
2355   // Histograms of this analsys are kept in the same list as other analysis, recover the position of
2356   // the first one and then add the next 
2357   Int_t index = outputList->IndexOf(outputList->FindObject(GetAddedHistogramsStringToName()+"hE"));
2358   //printf("Calo: %s, index: %d, nmodules %d\n",fCalorimeter.Data(),index,fNModules);
2359   
2360   //Read histograms, must be in the same order as in GetCreateOutputObject.
2361   fhE       = (TH1F *) outputList->At(index++);         
2362   if(fFillAllTH12){
2363     fhPt      = (TH1F *) outputList->At(index++); 
2364     fhPhi     = (TH1F *) outputList->At(index++); 
2365     fhEta     = (TH1F *) outputList->At(index++);
2366   }
2367   fhEtaPhiE = (TH3F *) outputList->At(index++);
2368   
2369   fhClusterTimeEnergy = (TH2F*) outputList->At(index++);
2370   
2371   fhLambda      = (TH3F *)  outputList->At(index++);
2372   fhDispersion  = (TH2F *)  outputList->At(index++);
2373   if(fFillAllTH12){
2374     fhECharged       = (TH1F *) outputList->At(index++);        
2375     fhPtCharged      = (TH1F *) outputList->At(index++); 
2376     fhPhiCharged     = (TH1F *) outputList->At(index++); 
2377     fhEtaCharged     = (TH1F *) outputList->At(index++);
2378   }
2379   fhEtaPhiECharged = (TH3F *) outputList->At(index++);
2380   
2381   fh1pOverE =    (TH2F *) outputList->At(index++);
2382   fh1dR =        (TH1F *) outputList->At(index++);
2383   fh2MatchdEdx = (TH2F *) outputList->At(index++);
2384   fh2EledEdx =   (TH2F *) outputList->At(index++);
2385   fh1pOverER02 = (TH2F *) outputList->At(index++);
2386   
2387   fhIM        = (TH2F *) outputList->At(index++);
2388   fhIMCellCut = (TH2F *) outputList->At(index++);
2389   fhAsym      = (TH2F *) outputList->At(index++);
2390   
2391   fhNCellsPerCluster           = (TH3F *) outputList->At(index++);
2392   fhNCellsPerClusterMIP        = (TH3F *) outputList->At(index++);
2393   fhNCellsPerClusterMIPCharged = (TH3F *) outputList->At(index++);
2394   fhNClusters  = (TH1F *) outputList->At(index++); 
2395   
2396   fhRNCells = (TH2F *) outputList->At(index++);
2397   fhXNCells = (TH2F *) outputList->At(index++);
2398   fhYNCells = (TH2F *) outputList->At(index++);
2399   fhZNCells = (TH2F *) outputList->At(index++);
2400   fhRE    = (TH2F *) outputList->At(index++);
2401   fhXE    = (TH2F *) outputList->At(index++);
2402   fhYE    = (TH2F *) outputList->At(index++);
2403   fhZE    = (TH2F *) outputList->At(index++); 
2404   fhXYZ   = (TH3F *) outputList->At(index++);
2405   if(fFillAllPosHisto){
2406     fhRCellE      = (TH2F *) outputList->At(index++);
2407     fhXCellE      = (TH2F *) outputList->At(index++);
2408     fhYCellE      = (TH2F *) outputList->At(index++);
2409     fhZCellE      = (TH2F *) outputList->At(index++); 
2410     fhXYZCell     = (TH3F *) outputList->At(index++); 
2411     fhDeltaCellClusterRNCells = (TH2F *) outputList->At(index++);
2412     fhDeltaCellClusterXNCells = (TH2F *) outputList->At(index++);
2413     fhDeltaCellClusterYNCells = (TH2F *) outputList->At(index++);
2414     fhDeltaCellClusterZNCells = (TH2F *) outputList->At(index++);
2415     fhDeltaCellClusterRE          = (TH2F *) outputList->At(index++);
2416     fhDeltaCellClusterXE          = (TH2F *) outputList->At(index++);
2417     fhDeltaCellClusterYE          = (TH2F *) outputList->At(index++);
2418     fhDeltaCellClusterZE          = (TH2F *) outputList->At(index++); 
2419     fhEtaPhiAmp               = (TH3F *) outputList->At(index++); 
2420   }
2421   
2422   fhNCells     = (TH1F *) outputList->At(index++); 
2423   fhAmplitude  = (TH1F *) outputList->At(index++); 
2424   fhAmpId      = (TH2F *) outputList->At(index++); 
2425   
2426   if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
2427     
2428     fhCellTimeSpreadRespectToCellMax = (TH1F *) outputList->At(index++);
2429     fhCellIdCellLargeTimeSpread      = (TH1F *) outputList->At(index++);
2430     
2431     fhTime       = (TH1F *) outputList->At(index++); 
2432     fhTimeId     = (TH2F *) outputList->At(index++); 
2433     fhTimeAmp    = (TH2F *) outputList->At(index++); 
2434     
2435     //          fhT0Time       = (TH1F *) outputList->At(index++); 
2436     //          fhT0TimeId     = (TH2F *) outputList->At(index++); 
2437     //          fhT0TimeAmp    = (TH2F *) outputList->At(index++); 
2438     
2439   }
2440   
2441   
2442   if(fCorrelateCalos){
2443     fhCaloCorrNClusters = (TH2F *) outputList->At(index++);
2444     fhCaloCorrEClusters = (TH2F *) outputList->At(index++); 
2445     fhCaloCorrNCells    = (TH2F *) outputList->At(index++); 
2446     fhCaloCorrECells    = (TH2F *) outputList->At(index++); 
2447   }
2448   
2449   //Module histograms
2450   fhEMod                 = new TH1F*[fNModules];
2451   fhNClustersMod         = new TH1F*[fNModules];
2452   fhNCellsPerClusterMod  = new TH2F*[fNModules];
2453   fhNCellsMod            = new TH1F*[fNModules];
2454   fhGridCellsMod         = new TH2F*[fNModules];
2455   fhGridCellsEMod        = new TH2F*[fNModules];
2456   if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) 
2457     fhGridCellsTimeMod     = new TH2F*[fNModules];
2458   fhAmplitudeMod         = new TH1F*[fNModules];
2459   if(fCalorimeter=="EMCAL")
2460     fhAmplitudeModFraction = new TH1F*[fNModules*3];
2461   
2462   //EMCAL
2463   fhTimeAmpPerRCU        = new TH2F*[fNModules*fNRCU];
2464   
2465   fhIMMod                = new TH2F*[fNModules];
2466   fhIMCellCutMod         = new TH2F*[fNModules];
2467   
2468   for(Int_t imod = 0 ; imod < fNModules; imod++){
2469     fhEMod[imod]                 = (TH1F *) outputList->At(index++);
2470     fhNClustersMod[imod]         = (TH1F *) outputList->At(index++); 
2471     fhNCellsPerClusterMod[imod]  = (TH2F *) outputList->At(index++); 
2472     fhNCellsMod[imod]            = (TH1F *) outputList->At(index++);    
2473     fhGridCellsMod[imod]         = (TH2F *) outputList->At(index++);
2474     fhGridCellsEMod[imod]        = (TH2F *) outputList->At(index++); 
2475     if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) 
2476       fhGridCellsTimeMod[imod]     = (TH2F *) outputList->At(index++); 
2477     fhAmplitudeMod[imod]         = (TH1F *) outputList->At(index++);
2478     
2479     if(fCalorimeter=="EMCAL"){
2480       for(Int_t ifrac = 0; ifrac < 3; ifrac++){
2481         fhAmplitudeModFraction[imod*3+ifrac] = (TH1F *) outputList->At(index++); 
2482       }
2483     }
2484     
2485     for(Int_t ircu = 0; ircu < fNRCU; ircu++){
2486       fhTimeAmpPerRCU[imod*fNRCU+ircu] = (TH2F *) outputList->At(index++); 
2487       //fhT0TimeAmpPerRCU[imod*fNRCU+ircu] = (TH2F *) outputList->At(index++); 
2488       //                        for(Int_t imod2 = 0; imod2 < fNModules; imod2++){
2489       //                                for(Int_t ircu2 = 0; ircu2 < fNModules; ircu2++){
2490       //                                        fhTimeCorrRCU[imod*fNRCU+ircu+imod2*fNRCU+ircu2]  = (TH2F *) outputList->At(index++);
2491       //                                }
2492       //                        }
2493     }
2494     fhIMMod[imod]                = (TH2F *) outputList->At(index++); 
2495     fhIMCellCutMod[imod]         = (TH2F *) outputList->At(index++);    
2496     
2497   }
2498   
2499   if(IsDataMC()){
2500     fhDeltaE   = (TH1F *) outputList->At(index++); 
2501     fhDeltaPt  = (TH1F *) outputList->At(index++); 
2502     fhDeltaPhi = (TH1F *) outputList->At(index++); 
2503     fhDeltaEta = (TH1F *) outputList->At(index++); 
2504     
2505     fhRatioE   = (TH1F *) outputList->At(index++); 
2506     fhRatioPt  = (TH1F *) outputList->At(index++); 
2507     fhRatioPhi = (TH1F *) outputList->At(index++); 
2508     fhRatioEta = (TH1F *) outputList->At(index++); 
2509     
2510     fh2E       = (TH2F *) outputList->At(index++); 
2511     fh2Pt      = (TH2F *) outputList->At(index++); 
2512     fh2Phi     = (TH2F *) outputList->At(index++); 
2513     fh2Eta     = (TH2F *) outputList->At(index++); 
2514     
2515     fhGamE     = (TH2F *) outputList->At(index++); 
2516     fhGamPt    = (TH2F *) outputList->At(index++); 
2517     fhGamPhi   = (TH2F *) outputList->At(index++); 
2518     fhGamEta   = (TH2F *) outputList->At(index++); 
2519     
2520     fhGamDeltaE   = (TH1F *) outputList->At(index++); 
2521     fhGamDeltaPt  = (TH1F *) outputList->At(index++); 
2522     fhGamDeltaPhi = (TH1F *) outputList->At(index++); 
2523     fhGamDeltaEta = (TH1F *) outputList->At(index++); 
2524     
2525     fhGamRatioE   = (TH1F *) outputList->At(index++); 
2526     fhGamRatioPt  = (TH1F *) outputList->At(index++); 
2527     fhGamRatioPhi = (TH1F *) outputList->At(index++); 
2528     fhGamRatioEta = (TH1F *) outputList->At(index++); 
2529     
2530     fhPi0E     = (TH2F *) outputList->At(index++); 
2531     fhPi0Pt    = (TH2F *) outputList->At(index++); 
2532     fhPi0Phi   = (TH2F *) outputList->At(index++); 
2533     fhPi0Eta   = (TH2F *) outputList->At(index++);              
2534     
2535     fhEleE     = (TH2F *) outputList->At(index++); 
2536     fhElePt    = (TH2F *) outputList->At(index++); 
2537     fhElePhi   = (TH2F *) outputList->At(index++); 
2538     fhEleEta   = (TH2F *) outputList->At(index++);              
2539     
2540     fhNeHadE     = (TH2F *) outputList->At(index++); 
2541     fhNeHadPt    = (TH2F *) outputList->At(index++); 
2542     fhNeHadPhi   = (TH2F *) outputList->At(index++); 
2543     fhNeHadEta   = (TH2F *) outputList->At(index++);            
2544     
2545     fhChHadE     = (TH2F *) outputList->At(index++); 
2546     fhChHadPt    = (TH2F *) outputList->At(index++); 
2547     fhChHadPhi   = (TH2F *) outputList->At(index++); 
2548     fhChHadEta   = (TH2F *) outputList->At(index++);                            
2549     
2550     fhGamECharged     = (TH2F *) outputList->At(index++); 
2551     fhGamPtCharged    = (TH2F *) outputList->At(index++); 
2552     fhGamPhiCharged   = (TH2F *) outputList->At(index++); 
2553     fhGamEtaCharged   = (TH2F *) outputList->At(index++); 
2554     
2555     fhPi0ECharged     = (TH2F *) outputList->At(index++); 
2556     fhPi0PtCharged    = (TH2F *) outputList->At(index++); 
2557     fhPi0PhiCharged   = (TH2F *) outputList->At(index++); 
2558     fhPi0EtaCharged   = (TH2F *) outputList->At(index++);               
2559     
2560     fhEleECharged     = (TH2F *) outputList->At(index++); 
2561     fhElePtCharged    = (TH2F *) outputList->At(index++); 
2562     fhElePhiCharged   = (TH2F *) outputList->At(index++); 
2563     fhEleEtaCharged   = (TH2F *) outputList->At(index++);               
2564     
2565     fhNeHadECharged     = (TH2F *) outputList->At(index++); 
2566     fhNeHadPtCharged    = (TH2F *) outputList->At(index++); 
2567     fhNeHadPhiCharged   = (TH2F *) outputList->At(index++); 
2568     fhNeHadEtaCharged   = (TH2F *) outputList->At(index++);             
2569     
2570     fhChHadECharged     = (TH2F *) outputList->At(index++); 
2571     fhChHadPtCharged    = (TH2F *) outputList->At(index++); 
2572     fhChHadPhiCharged   = (TH2F *) outputList->At(index++); 
2573     fhChHadEtaCharged   = (TH2F *) outputList->At(index++);                             
2574                 
2575     //          fhEMVxyz     = (TH3F *) outputList->At(index++); 
2576     //          fhHaVxyz     = (TH3F *) outputList->At(index++); 
2577                 
2578     fhEMVxyz     = (TH2F *) outputList->At(index++); 
2579     fhHaVxyz     = (TH2F *) outputList->At(index++); 
2580     fhEMR        = (TH2F *) outputList->At(index++); 
2581     fhHaR        = (TH2F *) outputList->At(index++); 
2582     
2583     fhGenGamPt    = (TH1F *) outputList->At(index++); 
2584     fhGenGamEta   = (TH1F *) outputList->At(index++); 
2585     fhGenGamPhi   = (TH1F *) outputList->At(index++); 
2586     
2587     fhGenPi0Pt    = (TH1F *) outputList->At(index++); 
2588     fhGenPi0Eta   = (TH1F *) outputList->At(index++); 
2589     fhGenPi0Phi   = (TH1F *) outputList->At(index++); 
2590     
2591     fhGenEtaPt    = (TH1F *) outputList->At(index++); 
2592     fhGenEtaEta   = (TH1F *) outputList->At(index++); 
2593     fhGenEtaPhi   = (TH1F *) outputList->At(index++); 
2594     
2595     fhGenOmegaPt  = (TH1F *) outputList->At(index++); 
2596     fhGenOmegaEta = (TH1F *) outputList->At(index++); 
2597     fhGenOmegaPhi = (TH1F *) outputList->At(index++); 
2598     
2599     fhGenElePt    = (TH1F *) outputList->At(index++); 
2600     fhGenEleEta   = (TH1F *) outputList->At(index++); 
2601     fhGenElePhi   = (TH1F *) outputList->At(index++); 
2602     
2603     fhGenGamAccE   = (TH1F *) outputList->At(index++);          
2604     fhGenGamAccPt  = (TH1F *) outputList->At(index++); 
2605     fhGenGamAccEta = (TH1F *) outputList->At(index++); 
2606     fhGenGamAccPhi = (TH1F *) outputList->At(index++); 
2607     
2608     fhGenPi0AccE   = (TH1F *) outputList->At(index++);          
2609     fhGenPi0AccPt  = (TH1F *) outputList->At(index++); 
2610     fhGenPi0AccEta = (TH1F *) outputList->At(index++); 
2611     fhGenPi0AccPhi = (TH1F *) outputList->At(index++); 
2612     
2613     fhMCEle1pOverE =    (TH2F *) outputList->At(index++);
2614     fhMCEle1dR =        (TH1F *) outputList->At(index++);
2615     fhMCEle2MatchdEdx = (TH2F *) outputList->At(index++);
2616     
2617     fhMCChHad1pOverE =    (TH2F *) outputList->At(index++);
2618     fhMCChHad1dR =        (TH1F *) outputList->At(index++);
2619     fhMCChHad2MatchdEdx = (TH2F *) outputList->At(index++);
2620     
2621     fhMCNeutral1pOverE    = (TH2F *) outputList->At(index++);
2622     fhMCNeutral1dR        = (TH1F *) outputList->At(index++);
2623     fhMCNeutral2MatchdEdx = (TH2F *) outputList->At(index++);
2624     
2625     fhMCEle1pOverER02     =    (TH2F *) outputList->At(index++);
2626     fhMCChHad1pOverER02   =    (TH2F *) outputList->At(index++);
2627     fhMCNeutral1pOverER02 =    (TH2F *) outputList->At(index++);
2628   }
2629 }
2630
2631 //__________________________________________________________________
2632 void  AliAnaCalorimeterQA::Terminate(TList* outputList) 
2633 {
2634   //Do plots if requested       
2635   
2636         if(GetDebug() > 0) printf("AliAnaCalorimeterQA::Terminate() - Make plots for %s? %d\n",fCalorimeter.Data(), fMakePlots);
2637         if(!fMakePlots) return;
2638         
2639   //Do some plots to end
2640   if(fStyleMacro!="")gROOT->Macro(fStyleMacro); 
2641   //Recover histograms from output histograms list, needed for distributed analysis.    
2642         ReadHistograms(outputList);
2643         
2644   //printf(" AliAnaCalorimeterQA::Terminate()  *** %s Report:", GetName()) ; 
2645   //printf(" AliAnaCalorimeterQA::Terminate()        pt         : %5.3f , RMS : %5.3f \n", fhPt->GetMean(),   fhPt->GetRMS() ) ;
2646   
2647   const Int_t buffersize = 255;
2648         char name[buffersize];
2649         char cname[buffersize];
2650         
2651   //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
2652         Int_t nptbins     = GetHistoPtBins();           Float_t ptmax     = GetHistoPtMax();           Float_t ptmin     = GetHistoPtMin();
2653         Int_t nphibins    = GetHistoPhiBins();          Float_t phimax    = GetHistoPhiMax();          Float_t phimin    = GetHistoPhiMin();
2654         Int_t netabins    = GetHistoEtaBins();          Float_t etamax    = GetHistoEtaMax();          Float_t etamin    = GetHistoEtaMin();    
2655   //    Int_t nmassbins   = GetHistoMassBins();         Float_t massmax   = GetHistoMassMax();         Float_t massmin   = GetHistoMassMin();
2656   //    Int_t nasymbins   = GetHistoAsymmetryBins();    Float_t asymmax   = GetHistoAsymmetryMax();    Float_t asymmin   = GetHistoAsymmetryMin();
2657   //    Int_t nPoverEbins = GetHistoPOverEBins();       Float_t pOverEmax = GetHistoPOverEMax();       Float_t pOverEmin = GetHistoPOverEMin();
2658   //    Int_t ndedxbins   = GetHistodEdxBins();         Float_t dedxmax   = GetHistodEdxMax();         Float_t dedxmin   = GetHistodEdxMin();
2659   //    Int_t ndRbins     = GetHistodRBins();           Float_t dRmax     = GetHistodRMax();           Float_t dRmin     = GetHistodRMin();
2660         Int_t ntimebins   = GetHistoTimeBins();         Float_t timemax   = GetHistoTimeMax();         Float_t timemin   = GetHistoTimeMin();       
2661         Int_t nbins       = GetHistoNClusterCellBins(); Int_t nmax        = GetHistoNClusterCellMax(); Int_t nmin        = GetHistoNClusterCellMin(); 
2662   //    Int_t nratiobins  = GetHistoRatioBins();        Float_t ratiomax  = GetHistoRatioMax();        Float_t ratiomin  = GetHistoRatioMin();
2663   //    Int_t nvdistbins  = GetHistoVertexDistBins();   Float_t vdistmax  = GetHistoVertexDistMax();   Float_t vdistmin  = GetHistoVertexDistMin();
2664         Int_t rbins       = GetHistoRBins();            Float_t rmax        = GetHistoRMax();          Float_t rmin      = GetHistoRMin(); 
2665         Int_t xbins       = GetHistoXBins();            Float_t xmax        = GetHistoXMax();          Float_t xmin      = GetHistoXMin(); 
2666         Int_t ybins       = GetHistoYBins();            Float_t ymax        = GetHistoYMax();          Float_t ymin      = GetHistoYMin(); 
2667         Int_t zbins       = GetHistoZBins();            Float_t zmax        = GetHistoZMax();          Float_t zmin      = GetHistoZMin(); 
2668         
2669   //Color code for the different modules
2670         Int_t modColorIndex[]={2,4,6,8};
2671         
2672   //--------------------------------------------------
2673   // Cluster energy distributions, module dependence
2674   //--------------------------------------------------
2675         snprintf(cname,buffersize,"QA_%s_ClusterEnergy",fCalorimeter.Data());
2676         TCanvas  * c = new TCanvas(cname, "Energy distributions", 800, 400) ;
2677         c->Divide(2, 1);
2678         Int_t rbE = GetNewRebinForRePlotting((TH1D*)fhE, ptmin, ptmax,nptbins) ;
2679   //printf("new E rb %d\n",rbE);
2680         fhE->Rebin(rbE);
2681         fhE->SetAxisRange(ptmin,ptmax,"X");
2682         c->cd(1) ; 
2683         if(fhE->GetEntries() > 0) gPad->SetLogy();
2684         TLegend pLegendE(0.7,0.6,0.9,0.8);
2685         pLegendE.SetTextSize(0.03);
2686         pLegendE.AddEntry(fhE,"all modules","L");
2687         pLegendE.SetFillColor(10);
2688         pLegendE.SetBorderSize(1);
2689         
2690         fhE->SetMinimum(1);     
2691         fhE->SetLineColor(1);
2692         fhE->Draw("HE");
2693         for(Int_t imod = 0; imod < fNModules; imod++){
2694                 fhEMod[imod]->Rebin(rbE);
2695                 fhEMod[imod]->SetLineColor(modColorIndex[imod]);
2696                 fhEMod[imod]->Draw("HE same");
2697                 pLegendE.AddEntry(fhEMod[imod],Form("module %d",imod),"L");
2698         }
2699         pLegendE.Draw();
2700         
2701   //Ratio of modules
2702         c->cd(2) ; 
2703         TLegend pLegendER(0.55,0.8,0.9,0.9);
2704         pLegendER.SetTextSize(0.03);
2705         pLegendER.SetFillColor(10);
2706         pLegendER.SetBorderSize(1);
2707   
2708         for(Int_t imod = 1; imod < fNModules; imod++){
2709                 TH1D * htmp = (TH1D*)fhEMod[imod]->Clone(Form("hERat%d",imod));
2710                 htmp->Divide(fhEMod[0]);
2711                 htmp->SetLineColor(modColorIndex[imod]);
2712                 if(imod==1){
2713                         htmp->SetTitle("Ratio module X / module 0");
2714                         htmp->SetAxisRange(ptmin,ptmax,"X");
2715                         htmp->SetMaximum(5);
2716                         htmp->SetMinimum(0);
2717                         htmp->SetAxisRange(ptmin,ptmax,"X");
2718                         htmp->Draw("HE");
2719                 }
2720                 else 
2721                         htmp->Draw("same HE");
2722                 
2723                 pLegendER.AddEntry(fhEMod[imod],Form("module %d / module 0",imod),"L");
2724         }
2725         pLegendER.Draw();
2726         
2727         snprintf(name,buffersize,"QA_%s_ClusterEnergy.eps",fCalorimeter.Data());
2728         c->Print(name); printf("Plot: %s\n",name);
2729         
2730   //--------------------------------------------------
2731   // Cell energy distributions, module dependence
2732   //--------------------------------------------------
2733         snprintf(cname,buffersize,"%s_QA_CellEnergy",fCalorimeter.Data());
2734         TCanvas  * ca = new TCanvas(cname, "Cell Energy distributions", 800, 400) ;
2735         ca->Divide(2, 1);
2736         
2737         Int_t rbAmp = GetNewRebinForRePlotting((TH1D*)fhAmplitude, ptmin, ptmax,nptbins*2) ;
2738   //printf("new Amp rb %d\n",rbAmp);
2739         fhAmplitude->Rebin(rbAmp);
2740         fhAmplitude->SetAxisRange(ptmin,ptmax,"X");
2741         
2742         ca->cd(1) ; 
2743         if(fhAmplitude->GetEntries() > 0) gPad->SetLogy();
2744         TLegend pLegendA(0.7,0.6,0.9,0.8);
2745         pLegendA.SetTextSize(0.03);
2746         pLegendA.AddEntry(fhE,"all modules","L");
2747         pLegendA.SetFillColor(10);
2748         pLegendA.SetBorderSize(1);
2749         fhAmplitude->SetMinimum(0.1);
2750         fhAmplitude->SetLineColor(1);
2751         fhAmplitude->Draw("HE");
2752         
2753         for(Int_t imod = 0; imod < fNModules; imod++){
2754                 fhAmplitudeMod[imod]->Rebin(rbAmp);
2755                 fhAmplitudeMod[imod]->SetLineColor(modColorIndex[imod]);
2756                 fhAmplitudeMod[imod]->Draw("HE same");
2757                 pLegendA.AddEntry(fhAmplitudeMod[imod],Form("module %d",imod),"L");
2758         }
2759         pLegendA.Draw();
2760         
2761         
2762         ca->cd(2) ; 
2763         TLegend pLegendAR(0.55,0.8,0.9,0.9);
2764         pLegendAR.SetTextSize(0.03);
2765         pLegendAR.SetFillColor(10);
2766         pLegendAR.SetBorderSize(1);
2767         
2768         for(Int_t imod = 1; imod < fNModules; imod++){
2769                 TH1D * htmp = (TH1D*)fhAmplitudeMod[imod]->Clone(Form("hAmpRat%d",imod));
2770                 htmp->Divide(fhAmplitudeMod[0]);
2771                 htmp->SetLineColor(modColorIndex[imod]);
2772                 if(imod==1){
2773                         htmp->SetTitle("Ratio cells energy in  module X / module 0");
2774                         htmp->SetAxisRange(ptmin,ptmax,"X");
2775                         htmp->SetMaximum(5);
2776                         htmp->SetMinimum(0);
2777                         htmp->Draw("HE");
2778                 }
2779                 else 
2780                         htmp->Draw("same HE");
2781                 pLegendAR.AddEntry(fhAmplitudeMod[imod],Form("module %d",imod),"L");
2782         }
2783         
2784         pLegendAR.Draw();
2785         snprintf(name,buffersize,"QA_%s_CellEnergy.eps",fCalorimeter.Data());
2786         ca->Print(name); printf("Plot: %s\n",name);     
2787   
2788   //----------------------------------------------------------
2789   // Cell energy distributions, FRACTION of module dependence
2790   // See Super Module calibration difference
2791   //---------------------------------------------------------   
2792         if(fCalorimeter=="EMCAL"){
2793     //Close To Eta 0 
2794                 snprintf(cname,buffersize,"%s_QA_SMThirds",fCalorimeter.Data());
2795                 TCanvas  * cfrac = new TCanvas(cname, "SM Thirds ratios", 800, 1200) ;
2796                 cfrac->Divide(2, 3);
2797                 cfrac->cd(1) ; 
2798                 if(fhAmplitude->GetEntries() > 0) 
2799                         gPad->SetLogy();
2800                 TLegend pLegend1(0.6,0.6,0.9,0.8);
2801                 pLegend1.SetTextSize(0.03);
2802                 pLegend1.SetFillColor(10);
2803                 pLegend1.SetBorderSize(1);
2804                 pLegend1.SetHeader("Third close to Eta=0");
2805                 fhAmplitudeModFraction[0]->SetTitle("Third close to Eta=0");
2806                 fhAmplitudeModFraction[0]->SetAxisRange(ptmin,ptmax,"X");
2807                 fhAmplitudeModFraction[0]->Draw("axis");
2808                 TH1D * hAverageThird1 = (TH1D *)fhAmplitudeModFraction[3*0+2]->Clone("AverageThird1");
2809                 for(Int_t imod = 0; imod < fNModules; imod++){
2810                         Int_t ifrac = 0;
2811                         if(imod%2==0) ifrac = 2;
2812                         if(imod > 0) hAverageThird1->Add( fhAmplitudeModFraction[3*imod+ifrac]);
2813                         fhAmplitudeModFraction[3*imod+ifrac]->SetLineColor(modColorIndex[imod]);
2814                         fhAmplitudeModFraction[3*imod+ifrac]->Draw("HE same");
2815                         pLegend1.AddEntry(fhAmplitudeModFraction[3*imod+ifrac],Form("super module %d",imod),"L");
2816                 }
2817                 hAverageThird1 ->Scale(1./fNModules);
2818                 pLegend1.Draw();
2819     //Ratio
2820                 cfrac->cd(2) ; 
2821                 for(Int_t imod = 0; imod < fNModules; imod++){
2822                         Int_t ifrac = 0;
2823                         if(imod%2==0) ifrac = 2;
2824                         TH1D * htmp =  (TH1D*)fhAmplitudeModFraction[3*imod+ifrac]->Clone(Form("ThirdFractionAverage_%d_%d",imod,ifrac));
2825                         htmp->Divide(hAverageThird1);
2826                         if(imod ==0) {
2827                                 htmp ->SetTitle("Close to eta = 0");
2828                                 htmp ->SetMaximum(5);
2829                                 htmp ->SetMinimum(0);
2830                                 htmp ->SetAxisRange(ptmin,ptmax,"X");
2831                                 htmp ->SetYTitle("ratio third to average");
2832                                 htmp -> Draw("HE");
2833                         }
2834                         else htmp -> Draw("same HE");
2835                 }
2836     //pLegend1.Draw();
2837                 
2838     //Middle Eta
2839                 cfrac->cd(3) ; 
2840                 if(fhAmplitude->GetEntries() > 0) 
2841                         gPad->SetLogy();
2842                 TLegend pLegend2(0.6,0.6,0.9,0.8);
2843                 pLegend2.SetTextSize(0.03);
2844                 pLegend2.SetFillColor(10);
2845                 pLegend2.SetBorderSize(1);
2846                 pLegend2.SetHeader("Middle Third");
2847                 
2848                 fhAmplitudeModFraction[0]->SetTitle("Middle Third");
2849                 fhAmplitudeModFraction[0]->SetAxisRange(ptmin,ptmax,"X");
2850                 fhAmplitudeModFraction[0]->Draw("axis");
2851                 
2852                 TH1D * hAverageThird2 = (TH1D *)fhAmplitudeModFraction[3*0+1]->Clone("AverageThird2");
2853                 for(Int_t imod = 0; imod < fNModules; imod++){
2854                         Int_t ifrac = 1;
2855                         if(imod > 0) hAverageThird2->Add( fhAmplitudeModFraction[3*imod+ifrac]);
2856                         fhAmplitudeModFraction[3*imod+ifrac]->SetLineColor(modColorIndex[imod]);
2857                         fhAmplitudeModFraction[3*imod+ifrac]->Draw("HE same");
2858                         pLegend2.AddEntry(fhAmplitudeModFraction[3*imod+ifrac],Form("super module %d",imod),"L");
2859                 }
2860                 hAverageThird2->Scale(1./fNModules);
2861                 pLegend2.Draw();
2862                 
2863     //Ratio
2864                 cfrac->cd(4) ; 
2865                 
2866                 for(Int_t imod = 0; imod < fNModules; imod++){
2867                         Int_t ifrac = 1;
2868                         TH1D * htmp =  (TH1D*)fhAmplitudeModFraction[3*imod+ifrac]->Clone(Form("ThirdFractionAverage_%d_%d",imod,ifrac));
2869                         htmp->Divide(hAverageThird2);
2870                         if(imod ==0) {
2871                                 htmp ->SetTitle("Middle");
2872                                 htmp ->SetMaximum(5);
2873                                 htmp ->SetMinimum(0);
2874                                 htmp ->SetAxisRange(ptmin,ptmax,"X");
2875                                 htmp ->SetYTitle("ratio third to average");
2876                                 htmp -> Draw("HE");
2877                         }
2878                         else htmp -> Draw("same HE");
2879                 }
2880     //pLegend2.Draw();
2881                 
2882     //Close To Eta 0.7 
2883                 cfrac->cd(5) ; 
2884                 if(fhAmplitude->GetEntries() > 0) 
2885                         gPad->SetLogy();
2886                 TLegend pLegend3(0.6,0.6,0.9,0.8);
2887                 pLegend3.SetTextSize(0.03);
2888                 pLegend3.SetFillColor(10);
2889                 pLegend3.SetBorderSize(1);
2890                 pLegend3.SetHeader("Third close to Eta=0.7");
2891                 
2892                 fhAmplitudeModFraction[0]->SetTitle("Third close to Eta=0.7");
2893                 fhAmplitudeModFraction[0]->SetAxisRange(ptmin,ptmax,"X");
2894                 fhAmplitudeModFraction[0]->Draw("axis");
2895                 
2896                 TH1D * hAverageThird3 = (TH1D *)fhAmplitudeModFraction[3*0+0]->Clone("AverageThird3");
2897                 for(Int_t imod = 0; imod < 4; imod++){
2898                         Int_t ifrac = 2;
2899                         if(imod%2==0) ifrac = 0;
2900                         if(imod > 0) hAverageThird3->Add( fhAmplitudeModFraction[3*imod+ifrac]);
2901                         fhAmplitudeModFraction[3*imod+ifrac]->SetLineColor(modColorIndex[imod]);
2902                         fhAmplitudeModFraction[3*imod+ifrac]->Draw("HE same");
2903                         pLegend3.AddEntry(fhAmplitudeModFraction[3*imod+ifrac],Form("super module %d",imod),"L");
2904                 }
2905                 hAverageThird3 ->Scale(1./fNModules);
2906                 pLegend3.Draw();
2907                 
2908                 cfrac->cd(6) ; 
2909                 
2910                 for(Int_t imod = 0; imod < fNModules; imod++){
2911                         Int_t ifrac = 2;
2912                         if(imod%2==0) ifrac = 0;
2913                         TH1D * htmp =  (TH1D*)fhAmplitudeModFraction[3*imod+ifrac]->Clone(Form("ThirdFractionAverage_%d_%d",imod,ifrac));
2914                         htmp->Divide(hAverageThird3);
2915                         if(imod ==0) {
2916                                 htmp ->SetTitle("Close to eta = 0.7");
2917                                 htmp ->SetMaximum(5);
2918                                 htmp ->SetMinimum(0);
2919                                 htmp ->SetAxisRange(ptmin,ptmax,"X");
2920                                 htmp ->SetYTitle("ratio third to average");
2921                                 htmp ->Draw("HE");
2922                         }
2923                         else htmp ->Draw("same HE");
2924                 }
2925     //pLegend3.Draw();
2926                 
2927                 snprintf(name,buffersize,"QA_%s_CellEnergyModuleFraction.eps",fCalorimeter.Data());
2928                 cfrac->Print(name); printf("Create plot %s\n",name);
2929         }//EMCAL        
2930         
2931         
2932   //----------------------------------------------------------
2933   // Cluster eta and phi distributions, energy cut dependence
2934   //---------------------------------------------------------   
2935         
2936         snprintf(cname,buffersize,"%s_QA_EtaPhiCluster",fCalorimeter.Data());
2937         TCanvas  * cetaphic = new TCanvas(cname, "Eta-Phi Reconstructed distributions", 1200, 400) ;
2938         cetaphic->Divide(3, 1);
2939         Int_t binmin = 0;
2940         Int_t rbPhi  = 1;
2941         Int_t rbEta  = 1;
2942         Int_t ncuts  = 7;
2943         Float_t ecut[]     = {0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3};
2944         Int_t   ecutcolor[]= {2, 4, 6, 7, 8, 9, 12};
2945         TH1D * hE = fhEtaPhiE->ProjectionZ();
2946         
2947   //PHI
2948         cetaphic->cd(1) ; 
2949         gPad->SetLogy();
2950         gPad->SetGridy();
2951         
2952         TLegend pLegendPhiCl(0.83,0.6,0.95,0.93);
2953         pLegendPhiCl.SetTextSize(0.03);
2954         pLegendPhiCl.SetFillColor(10);
2955         pLegendPhiCl.SetBorderSize(1);
2956         
2957         TH1D * htmp = fhEtaPhiE->ProjectionY("hphi_cluster_nocut",0,-1,0,-1);
2958         if(htmp){
2959           htmp->SetMinimum(1);
2960           rbPhi =  GetNewRebinForRePlotting(htmp, phimin, phimax,nphibins) ;
2961     //printf("new Phi rb %d\n",rbPhi);
2962           htmp->Rebin(rbPhi);
2963           htmp->SetTitle("#phi of clusters for energy in cluster > threshold");
2964           htmp->SetAxisRange(phimin,phimax,"X");
2965           htmp->Draw("HE");
2966           pLegendPhiCl.AddEntry(htmp,"No cut","L");
2967     
2968           for (Int_t i = 0; i < ncuts; i++) {
2969             binmin =  hE->FindBin(ecut[i]);
2970       //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
2971             htmp = fhEtaPhiE->ProjectionY(Form("hphi_cluster_cut%d",i),0,-1,binmin,-1);
2972             htmp->SetLineColor(ecutcolor[i]);
2973             htmp->Rebin(rbPhi);
2974             htmp->Draw("same HE");
2975             pLegendPhiCl.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L");
2976             
2977           }
2978         }
2979         pLegendPhiCl.Draw();
2980         
2981   //ETA
2982         cetaphic->cd(2) ; 
2983         gPad->SetLogy();
2984         gPad->SetGridy();
2985   
2986         htmp = fhEtaPhiE->ProjectionX("heta_cluster_nocut",0,-1,0,-1);
2987         htmp ->SetLineColor(1);
2988         rbEta =  GetNewRebinForRePlotting(htmp,etamin, etamax,netabins) ;
2989   //printf("new Eta rb %d\n",rbEta);
2990         if(htmp){
2991           htmp->Rebin(rbEta);
2992           htmp->SetMinimum(1);
2993           htmp->SetTitle("#eta of clusters for energy in cluster > threshold");
2994           htmp->SetAxisRange(etamin,etamax,"X");
2995           htmp->Draw("HE");
2996           
2997           for (Int_t i = 0; i < ncuts; i++) {
2998             binmin =  hE->FindBin(ecut[i]);
2999       //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3000             htmp = fhEtaPhiE->ProjectionX(Form("heta_cluster_cut%d",i),0,-1,binmin,-1);
3001             htmp->SetLineColor(ecutcolor[i]);
3002             htmp->Rebin(rbEta);
3003             htmp->Draw("same HE");      
3004           }
3005         }
3006   //ETA vs PHI  
3007         cetaphic->cd(3) ;
3008         TH2D* hEtaPhiCl = (TH2D*) fhEtaPhiE->Project3D("xy");
3009         hEtaPhiCl->SetAxisRange(etamin,etamax,"X");
3010         hEtaPhiCl->SetAxisRange(phimin,phimax,"Y");
3011         hEtaPhiCl->Draw("colz");
3012   
3013         snprintf(name,buffersize,"QA_%s_ClusterEtaPhi.eps",fCalorimeter.Data());
3014         cetaphic->Print(name); printf("Create plot %s\n",name);
3015   
3016   //----------------------------------------------------------
3017   // Cell eta and phi distributions, energy cut dependence
3018   //---------------------------------------------------------   
3019         
3020         snprintf(cname,buffersize,"%s_QA_EtaPhiCell",fCalorimeter.Data());
3021         TCanvas  * cetaphicell = new TCanvas(cname, "Eta-Phi Cells distributions", 1200, 400) ;
3022         cetaphicell->Divide(3, 1);
3023         
3024   //PHI
3025         cetaphicell->cd(1) ; 
3026         gPad->SetLogy();
3027         gPad->SetGridy();
3028         
3029         TLegend pLegendPhiCell(0.83,0.6,0.95,0.93);
3030         pLegendPhiCell.SetTextSize(0.03);
3031         pLegendPhiCell.SetFillColor(10);
3032         pLegendPhiCell.SetBorderSize(1);
3033         
3034         htmp = fhEtaPhiAmp->ProjectionY("hphi_cell_nocut",0,-1,0,-1);
3035         if(htmp){
3036           htmp->SetMinimum(1);
3037           htmp->Rebin(rbPhi);
3038           htmp->SetTitle("#phi of cells for cell energy > threshold");
3039           htmp->SetAxisRange(phimin,phimax,"X");
3040           htmp->Draw("HE");
3041           pLegendPhiCell.AddEntry(htmp,"No cut","L");
3042           
3043           for (Int_t i = 0; i < ncuts; i++) {
3044             binmin =  hE->FindBin(ecut[i]);
3045       //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3046             htmp = fhEtaPhiAmp->ProjectionY(Form("hphi_cell_cut%d",i),0,-1,binmin,-1);
3047             htmp->SetLineColor(ecutcolor[i]);
3048             htmp->Rebin(rbPhi);
3049             htmp->Draw("same HE");
3050             pLegendPhiCl.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L");
3051             
3052           }
3053         }
3054         pLegendPhiCell.Draw();
3055         
3056   //ETA
3057         cetaphicell->cd(2) ; 
3058         gPad->SetLogy();
3059         gPad->SetGridy();
3060         
3061         htmp = fhEtaPhiAmp->ProjectionX("heta_cell_nocut",0,-1,0,-1);
3062         if(htmp){
3063           htmp ->SetLineColor(1);
3064           htmp->Rebin(rbEta);
3065           htmp->SetMinimum(1);
3066           htmp->SetTitle("#eta of cells for cell energy > threshold");
3067           htmp->SetAxisRange(etamin,etamax,"X");
3068           htmp->Draw("HE");
3069           
3070           for (Int_t i = 0; i < ncuts; i++) {
3071             binmin =  hE->FindBin(ecut[i]);
3072       //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3073             htmp = fhEtaPhiAmp->ProjectionX(Form("heta_cell_cut%d",i),0,-1,binmin,-1);
3074             htmp->SetLineColor(ecutcolor[i]);
3075             htmp->Rebin(rbEta);
3076             htmp->Draw("same HE");
3077             
3078           }
3079         }
3080   //ETA vs PHI  
3081         cetaphicell->cd(3) ;
3082         TH2D* hEtaPhiCell = (TH2D*) fhEtaPhiAmp->Project3D("xy");
3083         hEtaPhiCell->SetAxisRange(etamin,etamax,"X");
3084         hEtaPhiCell->SetAxisRange(phimin,phimax,"Y");
3085         hEtaPhiCell->Draw("colz");
3086         
3087         snprintf(name,buffersize,"QA_%s_CellEtaPhi.eps",fCalorimeter.Data());
3088         cetaphicell->Print(name); printf("Create plot %s\n",name);
3089         
3090   
3091   ////////////////////////////////////////        
3092   ///////// Global Positions /////////////       
3093   ////////////////////////////////////////       
3094         
3095   //CLUSTERS
3096   Int_t rbX = 1;
3097   Int_t rbY = 1;
3098   Int_t rbZ = 1;
3099   //if(fFillAllPosHisto)
3100   {
3101     snprintf(cname,buffersize,"%s_QA_ClusterXY",fCalorimeter.Data());
3102     TCanvas  * cxyz = new TCanvas(cname, "Cluster XY distributions", 1200, 400) ;
3103     cxyz->Divide(3, 1);
3104     
3105     cxyz->cd(1) ; 
3106     TH2D * hXY = (TH2D*) fhXYZ->Project3D("yx" );
3107     hXY->SetTitle("Cluster X vs Y");
3108     hXY->GetYaxis()->SetTitleOffset(1.6);
3109     hXY->Draw("colz");
3110     cxyz->cd(2) ; 
3111     TH2D * hYZ = (TH2D*) fhXYZ->Project3D("yz" );
3112     hYZ->SetTitle("Cluster Z vs Y");
3113     hYZ->GetYaxis()->SetTitleOffset(1.6);
3114     hYZ->Draw("colz");  
3115     cxyz->cd(3) ; 
3116     TH2D * hXZ = (TH2D*) fhXYZ->Project3D("zx" );
3117     hXZ->SetTitle("Cluster X vs Z");
3118     hXZ->GetYaxis()->SetTitleOffset(1.6);
3119     hXZ->Draw("colz");
3120     
3121     snprintf(name,buffersize,"QA_%s_ClusterXY_YZ_XZ.eps",fCalorimeter.Data());
3122     cxyz->Print(name); printf("Create plot %s\n",name);
3123     
3124     snprintf(cname,buffersize,"QA_%s_ClusterX",fCalorimeter.Data());
3125     TCanvas  * cx = new TCanvas(cname, "Cluster X distributions", 1200, 400) ;
3126     cx->Divide(3, 1);
3127     
3128     cx->cd(1) ; 
3129     TH1D * hX = (TH1D*) fhXYZ->Project3D("xe" );
3130     //gPad->SetLogy();
3131     gPad->SetGridy();
3132     hX->SetTitle("Cluster X ");
3133     hX->Draw("HE");
3134     rbX =  GetNewRebinForRePlotting(hX, xmin, xmax,xbins) ;
3135     //printf("new X rb %d\n",rbX);
3136     hX->Rebin(rbX);
3137     hX->SetMinimum(hX->GetMaximum()/2);
3138     hX->SetAxisRange(xmin,xmax);
3139     
3140     cx->cd(2) ; 
3141     TH1D * hY = (TH1D*) fhXYZ->Project3D("ye" );
3142     //gPad->SetLogy();
3143     hY->SetTitle("Cluster Y ");
3144     rbY =  GetNewRebinForRePlotting(hY, ymin, ymax, ybins) ;
3145     //printf("new Y rb %d\n",rbY);
3146     hY->Rebin(rbY);
3147     hY->SetMinimum(1);
3148     hY->SetAxisRange(ymin,ymax);
3149     hY->Draw("HE");     
3150     
3151     cx->cd(3) ; 
3152     TH1D * hZ = (TH1D*) fhXYZ->Project3D("ze" );
3153     //gPad->SetLogy();
3154     gPad->SetGridy();
3155     rbZ =  GetNewRebinForRePlotting(hZ,zmin, zmax,zbins) ;
3156     //printf("new Z rb %d\n",rbZ);
3157     hZ->Rebin(rbZ);     
3158     hZ->SetMinimum(hZ->GetMaximum()/2);
3159     hZ->SetAxisRange(zmin,zmax);
3160     hZ->Draw("HE");
3161     
3162     snprintf(name,buffersize,"QA_%s_ClusterX_Y_Z.eps",fCalorimeter.Data());
3163     cx->Print(name); printf("Create plot %s\n",name);
3164   }
3165     //CELLS
3166   if(fFillAllPosHisto)
3167   { 
3168     snprintf(cname,buffersize,"%s_QA_CellXY",fCalorimeter.Data());
3169     TCanvas  * cellxyz = new TCanvas(cname, "Cell XY distributions", 1200, 400) ;
3170     cellxyz->Divide(3, 1);
3171     
3172     cellxyz->cd(1) ; 
3173     TH2D * hXYCell = (TH2D*) fhXYZCell->Project3D("yx" );
3174     hXYCell->SetTitle("Cell X vs Y");
3175     hXYCell->GetYaxis()->SetTitleOffset(1.6);
3176     hXYCell->Draw("colz");
3177     cellxyz->cd(2) ; 
3178     TH2D * hYZCell = (TH2D*) fhXYZCell->Project3D("yz" );
3179     hYZCell->SetTitle("Cell Z vs Y");
3180     hYZCell->GetYaxis()->SetTitleOffset(1.6);
3181     hYZCell->Draw("colz");      
3182     cellxyz->cd(3) ; 
3183     TH2D * hXZCell = (TH2D*) fhXYZCell->Project3D("zx" );
3184     hXZCell->SetTitle("Cell X vs Z");
3185     hXZCell->GetYaxis()->SetTitleOffset(1.6);
3186     hXZCell->Draw("colz");
3187     
3188     snprintf(name,buffersize,"QA_%s_CellXY_YZ_XZ.eps",fCalorimeter.Data());
3189     cellxyz->Print(name); printf("Create plot %s\n",name);
3190     
3191     
3192     snprintf(cname,buffersize,"%s_QA_CellX",fCalorimeter.Data());
3193     TCanvas  * cellx = new TCanvas(cname, "Cell X distributions", 1200, 400) ;
3194     cellx->Divide(3, 1);
3195     
3196     cellx->cd(1) ; 
3197     TH1D * hXCell = (TH1D*) fhXYZCell->Project3D("xe" );
3198     //gPad->SetLogy();
3199     gPad->SetGridy();
3200     hXCell->SetTitle("Cell X ");
3201     hXCell->Rebin(rbX);
3202     hXCell->SetMinimum(hXCell->GetMaximum()/2);
3203     hXCell->SetAxisRange(xmin,xmax);
3204     hXCell->Draw("HE");
3205     
3206     cellx->cd(2) ; 
3207     TH1D * hYCell = (TH1D*) fhXYZCell->Project3D("ye" );
3208     //gPad->SetLogy();
3209     hYCell->SetTitle("Cell Y ");
3210     hYCell->Rebin(rbY);
3211     hYCell->SetAxisRange(ymin,ymax);
3212     hYCell->SetMinimum(1);
3213     hYCell->Draw("HE"); 
3214     
3215     cellx->cd(3) ; 
3216     TH1D * hZCell = (TH1D*) fhXYZCell->Project3D("ze" );
3217     //gPad->SetLogy();
3218     gPad->SetGridy();
3219     hZCell->SetAxisRange(zmin,zmax);
3220     hZCell->SetTitle("Cell Z ");
3221     hZCell->Rebin(rbZ);
3222     hZCell->SetMinimum(hZCell->GetMaximum()/2);
3223     hZCell->Draw("HE");
3224     
3225     snprintf(name,buffersize,"QA_%s_CellX_Y_Z.eps",fCalorimeter.Data());
3226     cellx->Print(name); printf("Create plot %s\n",name);
3227     
3228     
3229     //----------------------------------------------------------
3230     // Cluster X, Y, Z, R, energy cut dependence
3231     //--------------------------------------------------------- 
3232     
3233     snprintf(cname,buffersize,"%s_QA_ClusterX_Y_Z_R_ECut",fCalorimeter.Data());
3234     TCanvas  * cxe = new TCanvas(cname, "Cluster X Y Z R, E cut", 800, 800) ;
3235     cxe->Divide(2, 2);          
3236     //R
3237     cxe->cd(1) ; 
3238     gPad->SetLogy();
3239     gPad->SetGridy();
3240     
3241     TLegend pLegendXCl(0.83,0.6,0.95,0.93);
3242     pLegendXCl.SetTextSize(0.03);
3243     pLegendXCl.SetFillColor(10);
3244     pLegendXCl.SetBorderSize(1);
3245     
3246     htmp = fhRE->ProjectionX("hre_cluster_nocut",0,-1);
3247     Int_t rbR=1;
3248     if(htmp){
3249       htmp->SetMinimum(1);
3250       rbR =  GetNewRebinForRePlotting(htmp, rmin, rmax,rbins) ;
3251       //printf("new R rb %d\n",rbR);
3252       htmp->Rebin(rbR);
3253       htmp->SetTitle("r of clusters for energy in cluster > threshold");
3254       htmp->SetAxisRange(rmin,rmax,"X");
3255       htmp->Draw("HE");
3256       pLegendXCl.AddEntry(htmp,"No cut","L");
3257       
3258       for (Int_t i = 0; i < ncuts; i++) {
3259         binmin =  hE->FindBin(ecut[i]);
3260         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3261         htmp = fhRE->ProjectionX(Form("hre_cluster_cut%d",i),binmin,-1);
3262         htmp->SetLineColor(ecutcolor[i]);
3263         htmp->Rebin(rbR);
3264         htmp->Draw("same HE");
3265         pLegendXCl.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L");
3266       }
3267     }
3268     pLegendXCl.Draw();
3269     
3270     //X
3271     cxe->cd(2) ; 
3272     gPad->SetLogy();
3273     gPad->SetGridy();
3274     htmp = fhXE->ProjectionX("hxe_cluster_nocut",0,-1);
3275     if(htmp){
3276       htmp->SetMinimum(1);
3277       htmp->Rebin(rbX);
3278       htmp->SetTitle("x of clusters for energy in cluster > threshold");
3279       htmp->SetAxisRange(xmin,xmax,"X");
3280       htmp->Draw("HE");
3281       
3282       for (Int_t i = 0; i < ncuts; i++) {
3283         binmin =  hE->FindBin(ecut[i]);
3284         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3285         htmp = fhXE->ProjectionX(Form("hxe_cluster_cut%d",i),binmin,-1);
3286         htmp->SetLineColor(ecutcolor[i]);
3287         htmp->Rebin(rbX);
3288         htmp->Draw("same HE");
3289       }
3290     }
3291     //Y
3292     cxe->cd(3) ; 
3293     gPad->SetLogy();
3294     gPad->SetGridy();
3295     htmp = fhYE->ProjectionX("hye_cluster_nocut",0,-1);
3296     if(htmp){
3297       htmp->SetMinimum(1);
3298       htmp->Rebin(rbY);
3299       htmp->SetTitle("y of clusters for energy in cluster > threshold");
3300       htmp->SetAxisRange(ymin,ymax,"X");
3301       htmp->Draw("HE");
3302       
3303       for (Int_t i = 0; i < ncuts; i++) {
3304         binmin =  hE->FindBin(ecut[i]);
3305         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3306         htmp = fhYE->ProjectionX(Form("hye_cluster_cut%d",i),binmin,-1);
3307         htmp->SetLineColor(ecutcolor[i]);
3308         htmp->Rebin(rbY);
3309         htmp->Draw("same HE");
3310       }
3311     }
3312     //Z
3313     cxe->cd(4) ; 
3314     gPad->SetLogy();
3315     gPad->SetGridy();
3316     
3317     htmp = fhZE->ProjectionX("hze_cluster_nocut",0,-1);
3318     if(htmp){
3319       htmp->SetMinimum(1);
3320       htmp->Rebin(rbZ);
3321       htmp->SetTitle("z of clusters for energy in cluster > threshold");
3322       htmp->SetAxisRange(zmin,zmax,"X");
3323       htmp->Draw("HE");
3324       
3325       for (Int_t i = 0; i < ncuts; i++) {
3326         binmin =  hE->FindBin(ecut[i]);
3327         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3328         htmp = fhZE->ProjectionX(Form("hze_cluster_cut%d",i),binmin,-1);
3329         htmp->SetLineColor(ecutcolor[i]);
3330         htmp->Rebin(rbZ);
3331         htmp->Draw("same HE"); 
3332       }
3333     }
3334     
3335     snprintf(name,buffersize,"QA_%s_ClusterX_Y_Z_R_ECut.eps",fCalorimeter.Data());
3336     cxe->Print(name); printf("Create plot %s\n",name);
3337     
3338     
3339     //----------------------------------------------------------
3340     // Cluster X, Y, Z, R, NCells in cluster dependence
3341     //--------------------------------------------------------- 
3342     Int_t ncellcut[]={2, 3, 4};
3343     Int_t ncellcuts = 3;
3344     snprintf(cname,buffersize,"%s_QA_ClusterX_Y_Z_R_NCellsCut",fCalorimeter.Data());
3345     TCanvas  * cxn = new TCanvas(cname, "Cluster X Y Z R, NCells cut", 800, 800) ;
3346     cxn->Divide(2, 2);          
3347     //R
3348     cxn->cd(1) ; 
3349     gPad->SetLogy();
3350     gPad->SetGridy();
3351     
3352     TLegend pLegendXClN(0.83,0.6,0.95,0.93);
3353     pLegendXClN.SetTextSize(0.03);
3354     pLegendXClN.SetFillColor(10);
3355     pLegendXClN.SetBorderSize(1);
3356     
3357     htmp = fhRNCells->ProjectionX("hrn_cluster_nocut",0,-1);
3358     if(htmp){
3359       htmp->SetMinimum(1);
3360       htmp->Rebin(rbR);
3361       htmp->SetTitle("r of clusters for energy in cluster > threshold");
3362       htmp->SetAxisRange(rmin,rmax,"X");
3363       htmp->Draw("HE");
3364       pLegendXClN.AddEntry(htmp,"No cut","L");
3365       
3366       for (Int_t i = 0; i < ncellcuts; i++) {
3367         if(i < ncellcuts-1) htmp = fhRNCells->ProjectionX(Form("hrn_cluster_cut%d",i),ncellcut[i],ncellcut[i]);
3368         else htmp = fhRNCells->ProjectionX(Form("hrn_cluster_cut%d",i),ncellcut[i],-1);
3369         htmp->SetLineColor(ecutcolor[i]);
3370         htmp->Rebin(rbR);
3371         htmp->Draw("same HE");
3372         if(i < ncellcuts-1) pLegendXClN.AddEntry(htmp,Form("n = %1.1d",ncellcut[i]-1),"L");
3373         else pLegendXClN.AddEntry(htmp,Form("n >= %1.1d",ncellcut[i]-1),"L");
3374         
3375       }
3376     }
3377     pLegendXClN.Draw();
3378     
3379     //X
3380     cxn->cd(2) ; 
3381     gPad->SetLogy();
3382     gPad->SetGridy();
3383     htmp = fhXNCells->ProjectionX("hxn_cluster_nocut",0,-1);
3384     if(htmp){
3385       htmp->SetMinimum(1);
3386       htmp->Rebin(rbX);
3387       htmp->SetTitle("x of clusters for energy in cluster > threshold");
3388       htmp->SetAxisRange(xmin,xmax,"X");
3389       htmp->Draw("HE");
3390       
3391       for (Int_t i = 0; i < ncellcuts; i++) {
3392         if(i < ncellcuts-1)htmp = fhXNCells->ProjectionX(Form("hxn_cluster_cut%d",i),ncellcut[i],ncellcut[i]);
3393         else htmp = fhXNCells->ProjectionX(Form("hxn_cluster_cut%d",i),ncellcut[i],-1);
3394         htmp->SetLineColor(ecutcolor[i]);
3395         htmp->Rebin(rbX);
3396         htmp->Draw("same HE");   
3397       }
3398     }
3399     //Y
3400     cxn->cd(3) ; 
3401     gPad->SetLogy();
3402     gPad->SetGridy();
3403     htmp = fhYNCells->ProjectionX("hyn_cluster_nocut",0,-1);
3404     if(htmp){
3405       htmp->SetMinimum(1);
3406       htmp->Rebin(rbY);
3407       htmp->SetTitle("y of clusters for energy in cluster > threshold");
3408       htmp->SetAxisRange(ymin,ymax,"X");
3409       htmp->Draw("HE");
3410       
3411       for (Int_t i = 0; i < ncellcuts; i++) {
3412         if(i < ncellcuts-1) htmp = fhYNCells->ProjectionX(Form("hyn_cluster_cut%d",i),ncellcut[i],ncellcut[i]);
3413         else htmp = fhYNCells->ProjectionX(Form("hyn_cluster_cut%d",i),ncellcut[i],-1);
3414         htmp->SetLineColor(ecutcolor[i]);
3415         htmp->Rebin(rbY);
3416         htmp->Draw("same HE");  
3417       }
3418     }
3419     //Z
3420     cxn->cd(4) ; 
3421     gPad->SetLogy();
3422     gPad->SetGridy();
3423     
3424     htmp = fhZNCells->ProjectionX("hzn_cluster_nocut",0,-1);
3425     if(htmp){
3426       htmp->SetMinimum(1);
3427       htmp->Rebin(rbZ);
3428       htmp->SetTitle("z of clusters for energy in cluster > threshold");
3429       htmp->SetAxisRange(zmin,zmax,"X");
3430       htmp->Draw("HE");
3431       
3432       for (Int_t i = 0; i < ncellcuts; i++) {
3433         if(i < ncellcuts-1)htmp = fhZNCells->ProjectionX(Form("hzn_cluster_cut%d",i),ncellcut[i],ncellcut[i]);
3434         else htmp = fhZNCells->ProjectionX(Form("hzn_cluster_cut%d",i),ncellcut[i],-1);
3435         htmp->SetLineColor(ecutcolor[i]);
3436         htmp->Rebin(rbZ);
3437         htmp->Draw("same HE");    
3438       }
3439     }
3440     
3441     snprintf(name,buffersize,"QA_%s_ClusterX_Y_Z_R_NCellsCut.eps",fCalorimeter.Data());
3442     cxn->Print(name); printf("Create plot %s\n",name);
3443     
3444     
3445     //----------------------------------------------------------
3446     // Cell X, Y, Z, R, energy cut dependence
3447     //--------------------------------------------------------- 
3448     
3449     snprintf(cname,buffersize,"%s_QA_CellX_Y_Z_R_ECut",fCalorimeter.Data());
3450     TCanvas  * cxecell = new TCanvas(cname, "Cell X Y Z R, E cut", 800, 800) ;
3451     cxecell->Divide(2, 2);              
3452     //R
3453     cxecell->cd(1) ; 
3454     gPad->SetLogy();
3455     gPad->SetGridy();
3456     
3457     TLegend pLegendXCell(0.83,0.6,0.95,0.93);
3458     pLegendXCell.SetTextSize(0.03);
3459     pLegendXCell.SetFillColor(10);
3460     pLegendXCell.SetBorderSize(1);
3461     
3462     htmp = fhRCellE->ProjectionX("hre_cell_nocut",0,-1);
3463     if(htmp){
3464       htmp->SetMinimum(1);
3465       htmp->Rebin(rbR);
3466       htmp->SetTitle("r of cells for energy in cluster > threshold");
3467       htmp->SetAxisRange(rmin,rmax,"X");
3468       htmp->Draw("HE");
3469       pLegendXCell.AddEntry(htmp,"No cut","L");
3470       
3471       for (Int_t i = 0; i < ncuts; i++) {
3472         binmin =  hE->FindBin(ecut[i]);
3473         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3474         htmp = fhRCellE->ProjectionX(Form("hre_celr_cut%d",i),binmin,-1);
3475         htmp->SetLineColor(ecutcolor[i]);
3476         htmp->Rebin(rbR);
3477         htmp->Draw("same HE");
3478         pLegendXCell.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L"); 
3479       }
3480     }
3481     pLegendXCell.Draw();
3482     
3483     //X
3484     cxecell->cd(2) ; 
3485     gPad->SetLogy();
3486     gPad->SetGridy();
3487     
3488     htmp = fhXCellE->ProjectionX("hxe_cells_nocut",0,-1);
3489     if(htmp){
3490       htmp->SetMinimum(1);
3491       htmp->Rebin(rbX);
3492       htmp->SetTitle("x of cells for energy in cluster > threshold");
3493       htmp->SetAxisRange(xmin,xmax,"X");
3494       htmp->Draw("HE");
3495       
3496       for (Int_t i = 0; i < ncuts; i++) {
3497         binmin =  hE->FindBin(ecut[i]);
3498         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3499         htmp = fhXCellE->ProjectionX(Form("hxe_cells_cut%d",i),binmin,-1);
3500         htmp->SetLineColor(ecutcolor[i]);
3501         htmp->Rebin(rbX);
3502         htmp->Draw("same HE");
3503       }
3504     }
3505     //Y
3506     cxecell->cd(3) ; 
3507     gPad->SetLogy();
3508     gPad->SetGridy();
3509     htmp = fhYCellE->ProjectionX("hye_cells_nocut",0,-1);
3510     if(htmp){
3511       htmp->SetMinimum(1);
3512       htmp->Rebin(rbY);
3513       htmp->SetTitle("y of cells for energy in cluster > threshold");
3514       htmp->SetAxisRange(ymin,ymax,"X");
3515       htmp->Draw("HE");
3516       
3517       for (Int_t i = 0; i < ncuts; i++) {
3518         binmin =  hE->FindBin(ecut[i]);
3519         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3520         htmp = fhYCellE->ProjectionX(Form("hye_cells_cut%d",i),binmin,-1);
3521         htmp->SetLineColor(ecutcolor[i]);
3522         htmp->Rebin(rbY);
3523         htmp->Draw("same HE");
3524       }
3525     }
3526     //Z
3527     cxecell->cd(4) ; 
3528     gPad->SetLogy();
3529     gPad->SetGridy();
3530     htmp = fhZCellE->ProjectionX("hze_cells_nocut",0,-1);
3531     if(htmp){
3532       htmp->SetMinimum(1);
3533       htmp->Rebin(rbZ);
3534       htmp->SetTitle("z of cells for energy in cluster > threshold");
3535       htmp->SetAxisRange(zmin,zmax,"X");
3536       htmp->Draw("HE");
3537       
3538       for (Int_t i = 0; i < ncuts; i++) {
3539         binmin =  hE->FindBin(ecut[i]);
3540         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3541         htmp = fhZCellE->ProjectionX(Form("hze_cells_cut%d",i),binmin,-1);
3542         htmp->SetLineColor(ecutcolor[i]);
3543         htmp->Rebin(rbZ);
3544         htmp->Draw("same HE"); 
3545       }
3546     }
3547     snprintf(name,buffersize,"QA_%s_CellX_Y_Z_R_ECut.eps",fCalorimeter.Data());
3548     cxecell->Print(name); printf("Create plot %s\n",name);
3549     
3550     
3551     //----------------------------------------------------------
3552     // Cluster-Cell X, Y, Z, R, cluster energy cut dependence
3553     //--------------------------------------------------------- 
3554     Int_t rbDR= 1;//rbR;
3555     Int_t rbDX= 1;//rbX;
3556     Int_t rbDY= 1;//rbY;
3557     Int_t rbDZ= 1;//rbZ;
3558     
3559     snprintf(cname,buffersize,"%s_QA_DeltaClusterCellX_Y_Z_R_ECut",fCalorimeter.Data());
3560     TCanvas  * cxde = new TCanvas(cname, "Cluster-Cell X, Y, Z, R, E cut", 800, 800) ;
3561     cxde->Divide(2, 2);         
3562     //R
3563     cxde->cd(1) ; 
3564     gPad->SetLogy();
3565     gPad->SetGridy();
3566     
3567     TLegend pLegendXClD(0.83,0.6,0.95,0.93);
3568     pLegendXClD.SetTextSize(0.03);
3569     pLegendXClD.SetFillColor(10);
3570     pLegendXClD.SetBorderSize(1);
3571     
3572     htmp = fhDeltaCellClusterRE->ProjectionX("hrde_nocut",0,-1);
3573     if(htmp){
3574       htmp->SetMinimum(1);
3575       htmp->Rebin(rbDR);
3576       htmp->SetTitle("r clusters - r cells for energy in cluster > threshold");
3577       htmp->SetAxisRange(-50,50,"X");
3578       htmp->Draw("HE");
3579       pLegendXCl.AddEntry(htmp,"No cut","L");
3580       
3581       for (Int_t i = 0; i < ncuts; i++) {
3582         binmin =  hE->FindBin(ecut[i]);
3583         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3584         htmp = fhDeltaCellClusterRE->ProjectionX(Form("hrde_cut%d",i),binmin,-1);
3585         htmp->SetLineColor(ecutcolor[i]);
3586         htmp->Rebin(rbDR);
3587         htmp->Draw("same HE");
3588         pLegendXClD.AddEntry(htmp,Form("E>%1.1f",ecut[i]),"L");
3589       }
3590     }
3591     pLegendXClD.Draw();
3592     
3593     //X
3594     cxde->cd(2) ; 
3595     gPad->SetLogy();
3596     gPad->SetGridy();
3597     htmp = fhDeltaCellClusterXE->ProjectionX("hxde_nocut",0,-1);
3598     if(htmp){
3599       htmp->SetMinimum(1);
3600       htmp->Rebin(rbDX);
3601       htmp->SetTitle("x clusters -x cells for energy in cluster > threshold");
3602       htmp->SetAxisRange(-50,50,"X");
3603       htmp->Draw("HE");
3604       
3605       for (Int_t i = 0; i < ncuts; i++) {
3606         binmin =  hE->FindBin(ecut[i]);
3607         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3608         htmp = fhDeltaCellClusterXE->ProjectionX(Form("hxde_cut%d",i),binmin,-1);
3609         htmp->SetLineColor(ecutcolor[i]);
3610         htmp->Rebin(rbDX);
3611         htmp->Draw("same HE");
3612         
3613       }
3614     }
3615     //Y
3616     cxde->cd(3) ; 
3617     gPad->SetLogy();
3618     gPad->SetGridy();
3619     htmp = fhDeltaCellClusterYE->ProjectionX("hyde_nocut",0,-1);
3620     if(htmp){
3621       htmp->SetMinimum(1);
3622       htmp->Rebin(rbDY);
3623       htmp->SetTitle("y clusters - ycells for energy in cluster > threshold");
3624       htmp->SetAxisRange(-50,50,"X");
3625       htmp->Draw("HE");
3626       
3627       for (Int_t i = 0; i < ncuts; i++) {
3628         binmin =  hE->FindBin(ecut[i]);
3629         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3630         htmp = fhDeltaCellClusterYE->ProjectionX(Form("hyde_cut%d",i),binmin,-1);
3631         htmp->SetLineColor(ecutcolor[i]);
3632         htmp->Rebin(rbDY);
3633         htmp->Draw("same HE");
3634         
3635       }
3636     }
3637     //Z
3638     cxde->cd(4) ; 
3639     gPad->SetLogy();
3640     gPad->SetGridy();
3641     
3642     htmp = fhDeltaCellClusterZE->ProjectionX("hzde_nocut",0,-1);
3643     if(htmp){
3644       htmp->SetMinimum(1);
3645       htmp->Rebin(rbZ);
3646       htmp->SetTitle("z clusters - z cells for energy in cluster > threshold");
3647       htmp->SetAxisRange(-50,50,"X");
3648       htmp->Draw("HE");
3649       
3650       for (Int_t i = 0; i < ncuts; i++) {
3651         binmin =  hE->FindBin(ecut[i]);
3652         //printf(" bins %d for e %f\n",binmin[i],ecut[i]);
3653         htmp = fhDeltaCellClusterZE->ProjectionX(Form("hzde_cut%d",i),binmin,-1);
3654         htmp->SetLineColor(ecutcolor[i]);
3655         htmp->Rebin(rbZ);
3656         htmp->Draw("same HE");
3657         
3658       }
3659     }
3660     
3661     snprintf(name,buffersize,"QA_%s_DeltaClusterCellX_Y_Z_R_ECut.eps",fCalorimeter.Data());
3662     cxde->Print(name); printf("Create plot %s\n",name);
3663     
3664     
3665     //----------------------------------------------------------
3666     // Cluster-Cell X, Y, Z, R, NCells in cluster dependence
3667     //--------------------------------------------------------- 
3668     snprintf(cname,buffersize,"%s_QA_DeltaClusterCellX_Y_Z_R_NCellsCut",fCalorimeter.Data());
3669     TCanvas  * cxdn = new TCanvas(cname, "Cluster-Cell X Y Z R, NCells cut", 800, 800) ;
3670     cxdn->Divide(2, 2);         
3671     //R
3672     cxdn->cd(1) ; 
3673     gPad->SetLogy();
3674     gPad->SetGridy();
3675     
3676     TLegend pLegendXClDN(0.83,0.6,0.95,0.93);
3677     pLegendXClDN.SetTextSize(0.03);
3678     pLegendXClDN.SetFillColor(10);
3679     pLegendXClDN.SetBorderSize(1);
3680     
3681     htmp = fhDeltaCellClusterRNCells->ProjectionX("hrdn_nocut",0,-1);
3682     if(htmp){
3683       htmp->SetMinimum(1);
3684       htmp->Rebin(rbDR);
3685       htmp->SetTitle("r clusters - r cells for n cells in cluster > threshold");
3686       htmp->SetAxisRange(-50,50,"X");
3687       htmp->Draw("HE");
3688       pLegendXClDN.AddEntry(htmp,"No cut","L");
3689       
3690       for (Int_t i = 0; i < ncellcuts; i++) {
3691         if(i < ncellcuts-1) htmp = fhDeltaCellClusterRNCells->ProjectionX(Form("hrdn_cut%d",i),ncellcut[i],ncellcut[i]);
3692         else htmp = fhDeltaCellClusterRNCells->ProjectionX(Form("hrdn_cut%d",i),ncellcut[i],-1);
3693         htmp->SetLineColor(ecutcolor[i]);
3694         htmp->Rebin(rbDR);
3695         htmp->Draw("same HE");
3696         if(i < ncellcuts-1) pLegendXClDN.AddEntry(htmp,Form("n = %1.1d",ncellcut[i]-1),"L");
3697         else pLegendXClDN.AddEntry(htmp,Form("n >= %1.1d",ncellcut[i]-1),"L");
3698         
3699       }
3700     }
3701     pLegendXClDN.Draw();
3702     
3703     //X
3704     cxdn->cd(2) ; 
3705     gPad->SetLogy();
3706     gPad->SetGridy();
3707     htmp = fhDeltaCellClusterXNCells->ProjectionX("hxdn_nocut",0,-1);
3708     if(htmp){
3709       htmp->SetMinimum(1);
3710       htmp->Rebin(rbDX);
3711       htmp->SetTitle("x clusters - x cells for n cells in cluster > threshold");
3712       htmp->SetAxisRange(-50,50,"X");
3713       htmp->Draw("HE");
3714       
3715       for (Int_t i = 0; i < ncellcuts; i++) {
3716         if(i < ncellcuts-1)htmp = fhDeltaCellClusterXNCells->ProjectionX(Form("hxdn_cut%d",i),ncellcut[i],ncellcut[i]);
3717         else htmp = fhDeltaCellClusterXNCells->ProjectionX(Form("hxdn_cut%d",i),ncellcut[i],-1);
3718         htmp->SetLineColor(ecutcolor[i]);
3719         htmp->Rebin(rbDX);
3720         htmp->Draw("same HE");
3721         
3722       }
3723     }
3724     //Y
3725     cxdn->cd(3) ; 
3726     gPad->SetLogy();
3727     gPad->SetGridy();
3728     htmp = fhDeltaCellClusterYNCells->ProjectionX("hydn_nocut",0,-1);
3729     if(htmp){
3730       htmp->SetMinimum(1);
3731       htmp->Rebin(rbDY);
3732       htmp->SetTitle("y clusters - y cells for n cells in cluster > threshold");
3733       htmp->SetAxisRange(-50,50,"X");
3734       htmp->Draw("HE");
3735       
3736       for (Int_t i = 0; i < ncellcuts; i++) {
3737         if(i < ncellcuts-1) htmp = fhDeltaCellClusterYNCells->ProjectionX(Form("hydn_cut%d",i),ncellcut[i],ncellcut[i]);
3738         else htmp = fhDeltaCellClusterYNCells->ProjectionX(Form("hydn_cut%d",i),ncellcut[i],-1);
3739         htmp->SetLineColor(ecutcolor[i]);
3740         htmp->Rebin(rbDY);
3741         htmp->Draw("same HE");
3742         
3743       }
3744     }
3745     //Z
3746     cxdn->cd(4) ; 
3747     gPad->SetLogy();
3748     gPad->SetGridy();
3749     
3750     htmp = fhDeltaCellClusterZNCells->ProjectionX("hzdn_nocut",0,-1);
3751     if(htmp){
3752       htmp->SetMinimum(1);
3753       htmp->Rebin(rbDZ);
3754       htmp->SetTitle("z clusters - z cells for ncells in cluster > threshold");
3755       htmp->SetAxisRange(-50,50,"X");
3756       htmp->Draw("HE");
3757       
3758       for (Int_t i = 0; i < ncellcuts; i++) {
3759         if(i < ncellcuts-1)htmp = fhDeltaCellClusterZNCells->ProjectionX(Form("hzdn_cut%d",i),ncellcut[i],ncellcut[i]);
3760         else htmp = fhDeltaCellClusterZNCells->ProjectionX(Form("hzdn_cut%d",i),ncellcut[i],-1);
3761         htmp->SetLineColor(ecutcolor[i]);
3762         htmp->Rebin(rbDZ);
3763         htmp->Draw("same HE");
3764         
3765       }
3766     }
3767     
3768     snprintf(name,buffersize,"QA_%s_DeltaClusterCellX_Y_Z_R_NCellsCut.eps",fCalorimeter.Data());
3769     cxdn->Print(name); printf("Create plot %s\n",name);
3770     
3771         }
3772   
3773   //----------------------------------------------------------
3774   //Reconstructed clusters energy-eta-phi distributions, matched with tracks
3775   //----------------------------------------------------------
3776   TH1F *        hEChargedClone   = 0 ;
3777   TH1F *        hPtChargedClone  = 0 ;
3778   TH1F *        hEtaChargedClone = 0 ;
3779   TH1F *        hPhiChargedClone = 0 ;
3780         if(fFillAllTH12){
3781     hEChargedClone   = (TH1F*)   fhECharged->Clone(Form("%sClone",fhECharged->GetName()));
3782     hPtChargedClone  = (TH1F*)   fhPtCharged->Clone(Form("%sClone",fhPtCharged->GetName()));
3783     hEtaChargedClone = (TH1F*)   fhEtaCharged->Clone(Form("%sClone",fhEtaCharged->GetName()));
3784     hPhiChargedClone = (TH1F*)   fhPhiCharged->Clone(Form("%sClone",fhPhiCharged->GetName()));
3785     
3786     snprintf(cname,buffersize,"QA_%s_rectrackmatch",fCalorimeter.Data());
3787     TCanvas  * ccltm = new TCanvas(cname, "Reconstructed clusters E-Phi-Eta, matched with tracks", 1200, 400) ;
3788     ccltm->Divide(3, 1);
3789     
3790     ccltm->cd(1) ; 
3791     if(fhECharged->GetEntries() > 0) gPad->SetLogy();
3792     fhECharged->Rebin(rbE);
3793     fhECharged->SetAxisRange(ptmin,ptmax,"X");
3794     fhECharged->SetMinimum(1);
3795     fhECharged->Draw();
3796     
3797     ccltm->cd(2) ; 
3798     if(fhPhiCharged->GetEntries() > 0) gPad->SetLogy();
3799     fhPhiCharged->Rebin(rbPhi);
3800     fhPhiCharged->SetAxisRange(phimin,phimax,"X");
3801     fhPhiCharged->Draw();
3802     fhPhiCharged->Draw();
3803     
3804     ccltm->cd(3) ;
3805     if(fhEtaCharged->GetEntries() > 0) gPad->SetLogy();
3806     fhEtaCharged->Rebin(rbEta);
3807     fhEtaCharged->SetAxisRange(etamin,etamax,"X");      
3808     fhEtaCharged->Draw();
3809     fhEtaCharged->Draw();
3810     
3811     snprintf(name,buffersize,"QA_%s_ClusterEnergyPhiEta_TrackMatched.eps",fCalorimeter.Data());
3812     ccltm->Print(name); printf("Plot: %s\n",name);
3813     
3814     //----------------------------------------------------------
3815     // Ratio  of reconstructed clusters energy-eta-phi distributions, matched with tracks over all
3816     //----------------------------------------------------------
3817     
3818     snprintf(cname,buffersize,"%s_QA_ChargedRatio",fCalorimeter.Data());
3819     TCanvas  * ccharge = new TCanvas(cname, "Charged clusters over all clusters", 1200, 400) ;
3820     ccharge->Divide(3, 1);
3821     
3822     ccharge->cd(1) ; 
3823     fhECharged->Sumw2();
3824     fhE->Sumw2();
3825     fhECharged->Divide(fhE);
3826     fhECharged->SetAxisRange(ptmin,ptmax,"X");
3827     fhECharged->SetMaximum(0.5);
3828     fhECharged->SetYTitle("track-matched clusters / all clusters");
3829     fhECharged->Draw("HE");
3830     
3831     ccharge->cd(2) ; 
3832     fhPhiCharged->Sumw2();
3833     fhPhi->Rebin(rbPhi);
3834     fhPhi->Sumw2();
3835     fhPhiCharged->Divide(fhPhi);
3836     fhPhiCharged->SetAxisRange(phimin,phimax,"X");
3837     fhPhiCharged->SetMaximum(0.5);
3838     fhPhiCharged->SetYTitle("track-matched clusters / all clusters");
3839     fhPhiCharged->Draw("HE");
3840     
3841     ccharge->cd(3) ; 
3842     fhEtaCharged->Sumw2();
3843     fhEta->Rebin(rbEta);
3844     fhEta->Sumw2();
3845     fhEtaCharged->Divide(fhEta);
3846     fhEtaCharged->SetAxisRange(etamin,etamax,"X");
3847     fhEtaCharged->SetMaximum(0.5);
3848     fhEtaCharged->SetYTitle("track-matched clusters / all clusters");
3849     fhEtaCharged->Draw("HE");
3850     
3851     snprintf(name,buffersize,"QA_%s_ClustersMatchedToAllRatios.eps",fCalorimeter.Data());
3852     ccharge->Print(name); printf("Create plot %s\n",name);
3853         }
3854   //------------------------------------------- 
3855   // N Cells - N Clusters - N Cells per cluster
3856   //-------------------------------------------
3857         snprintf(cname,buffersize,"QA_%s_nclustercells",fCalorimeter.Data());
3858         TCanvas  * cN = new TCanvas(cname, " Number of CaloClusters and CaloCells", 800, 1200) ;
3859         cN->Divide(2, 3);
3860         
3861         cN->cd(1) ; 
3862         
3863         TLegend pLegendN(0.7,0.6,0.9,0.8);
3864         pLegendN.SetTextSize(0.03);
3865         pLegendN.AddEntry(fhNClusters,"all modules","L");
3866         pLegendN.SetFillColor(10);
3867         pLegendN.SetBorderSize(1);
3868         
3869         if(fhNClusters->GetEntries() > 0) gPad->SetLogy();
3870         gPad->SetLogx();
3871         fhNClusters->SetLineColor(1);
3872         
3873         Int_t rbN = 1;
3874         if(fhNClusters->GetNbinsX()> nbins) rbN = fhNClusters->GetNbinsX()/nbins;
3875         
3876         fhNClusters->SetAxisRange(nmin,nmax,"X");
3877         fhNClusters->Draw("HE");
3878         for(Int_t imod = 0; imod < fNModules; imod++){
3879                 fhNClustersMod[imod]->SetAxisRange(nmin,nmax,"X");
3880                 fhNClustersMod[imod]->SetLineColor(modColorIndex[imod]);
3881                 fhNClustersMod[imod]->Draw("same");
3882                 pLegendN.AddEntry(fhNClustersMod[imod],Form("module %d",imod),"L");
3883         }
3884         pLegendN.Draw();
3885         
3886         cN->cd(2) ; 
3887         gPad->SetLogx();
3888         for(Int_t imod = 1; imod < fNModules; imod++){
3889                 htmp = (TH1D*)fhNClustersMod[imod]->Clone(Form("hNClustersRat%d",imod));
3890                 htmp->Divide(fhNClustersMod[0]);
3891                 htmp->SetLineColor(modColorIndex[imod]);
3892                 if(imod==1){
3893                         htmp->SetTitle("Ratio # clusters in  module X / module 0");
3894                         htmp->SetMaximum(5);
3895                         htmp->SetMinimum(0);
3896                         htmp->Draw("HE");
3897                 }
3898                 else 
3899                         htmp->Draw("same HE");
3900                 
3901         }
3902         
3903         cN->cd(3) ; 
3904         if(fhNCells->GetEntries() > 0) gPad->SetLogy();
3905         gPad->SetLogx();
3906         fhNCells->SetLineColor(1);
3907         fhNCells->SetAxisRange(nmin,nmax,"X");
3908         fhNCells->Draw("HE");
3909         for(Int_t imod = 0; imod < fNModules; imod++){
3910                 fhNCellsMod[imod]->SetAxisRange(nmin,nmax,"X");
3911                 fhNCellsMod[imod]->SetLineColor(modColorIndex[imod]);
3912                 fhNCellsMod[imod]->Draw("same HE");
3913         }
3914         
3915         
3916         cN->cd(4) ; 
3917         gPad->SetLogx();
3918         for(Int_t imod = 1; imod < fNModules; imod++){
3919                 htmp = (TH1D*)fhNCellsMod[imod]->Clone(Form("hNCellsRat%d",imod));
3920                 htmp->Divide(fhNCellsMod[0]);
3921                 htmp->SetLineColor(modColorIndex[imod]);
3922                 if(imod==1){
3923                         htmp->SetTitle("Ratio # cells in  module X / module 0");
3924                         htmp->SetMaximum(5);
3925                         htmp->SetMinimum(0);
3926                         htmp->Draw("HE");
3927                 }
3928                 else 
3929                         htmp->Draw("same HE");
3930                 
3931         }
3932         
3933         cN->cd(5) ; 
3934         if(fhNCellsPerCluster->GetEntries() > 0) gPad->SetLogy();
3935         gPad->SetLogx();
3936         TH1D *cpc = fhNCellsPerCluster->ProjectionY("cpc",-1,-1,-1,-1);
3937         cpc->SetLineColor(1);
3938         cpc->SetTitle("# cells per cluster");
3939         cpc->Draw("HE"); 
3940         TH1D ** hNCellsCluster1D = new TH1D*[fNModules];
3941         
3942         for(Int_t imod = 0; imod < fNModules; imod++){
3943                 hNCellsCluster1D[imod] = fhNCellsPerClusterMod[imod]->ProjectionY(Form("cpc_%d",imod),-1,-1);
3944                 hNCellsCluster1D[imod]->SetLineColor(modColorIndex[imod]);
3945                 hNCellsCluster1D[imod]->Draw("same HE");
3946         }
3947         
3948         
3949         cN->cd(6) ; 
3950         gPad->SetLogx();
3951         for(Int_t imod = 1; imod < fNModules; imod++){
3952                 htmp = (TH1D*)hNCellsCluster1D[imod]->Clone(Form("hNClustersCells1DRat%d",imod));
3953                 htmp->Divide(hNCellsCluster1D[0]);
3954                 htmp->SetLineColor(modColorIndex[imod]);
3955                 if(imod==1){
3956                         htmp->SetTitle("Ratio # cells per cluster in  module X / module 0");
3957       //htmp->SetAxisRange(ptmin,ptmax,"X");
3958                         htmp->SetMaximum(3.5);
3959                         htmp->SetMinimum(0);
3960                         htmp->Draw("HE");
3961                 }
3962                 else 
3963                         htmp->Draw("same HE");
3964                 
3965     delete [] hNCellsCluster1D;
3966     
3967         }
3968         snprintf(name,buffersize,"QA_%s_NumberCaloClustersAndCaloCells.eps",fCalorimeter.Data());
3969         cN->Print(name); printf("Print plot %s\n",name);
3970         
3971   //----------------------------------------------------        
3972   // Cell Time histograms, time only available in ESDs
3973   //----------------------------------------------------
3974         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
3975     
3976                 snprintf(cname,buffersize,"QA_%s_cellstime",fCalorimeter.Data());
3977                 TCanvas  * ctime = new TCanvas(cname, " Cells time", 1200, 400) ;
3978                 ctime->Divide(3, 1);
3979                 
3980                 Int_t rbTime = 1;
3981                 if(fhTime->GetNbinsX()> ntimebins) rbTime = fhTime->GetNbinsX()/ntimebins;
3982                 
3983                 ctime->cd(1) ; 
3984                 if(fhTime->GetEntries() > 0) gPad->SetLogy();
3985                 fhTime->Rebin(rbTime);
3986                 fhTime->SetAxisRange(timemin,timemax,"X");
3987                 fhTime->Draw();
3988     
3989                 ctime->cd(2) ; 
3990                 fhTimeId->SetTitleOffset(1.8,"Y");
3991                 fhTimeId->SetAxisRange(timemin,timemax,"X");
3992                 fhTimeId->Draw("colz");
3993     
3994                 ctime->cd(3) ; 
3995                 fhTimeAmp->SetTitle("Cell Energy vs Cell Time");
3996                 fhTimeAmp->SetTitleOffset(1.8,"Y");
3997                 fhTimeAmp->SetAxisRange(timemin,timemax,"Y");
3998                 fhTimeAmp->SetAxisRange(ptmin,ptmax,"X");               
3999                 fhTimeAmp->Draw("colz");
4000     
4001                 snprintf(name,buffersize,"QA_%s_CellsTime.eps",fCalorimeter.Data());
4002                 ctime->Print(name); printf("Plot: %s\n",name);
4003         }
4004         
4005         
4006   //---------------------------------
4007   //Grid of cell per module plots 
4008   //---------------------------------
4009         {
4010     //Number of entries per cell
4011     gStyle->SetPadRightMargin(0.15);
4012     snprintf(cname,buffersize,"%s_QA_GridCellEntries",fCalorimeter.Data());
4013     TCanvas *cgrid   = new TCanvas("cgrid","Number of entries per cell", 12,12,800,400);
4014     if(fNModules%2 == 0)
4015       cgrid->Divide(fNModules/2,2); 
4016     else
4017       cgrid->Divide(fNModules/2+1,2); 
4018                 
4019     for(Int_t imod = 0; imod < fNModules ; imod++){
4020       cgrid->cd(imod+1);
4021       gPad->SetLogz();
4022       gPad->SetGridy();
4023       gPad->SetGridx();
4024       //fhGridCellsMod[imod]->GetYAxis()->SetTitleColor(1);
4025       fhGridCellsMod[imod]->SetZTitle("Counts    ");
4026       fhGridCellsMod[imod]->SetYTitle("row (phi direction)    ");
4027       //fhGridCellsMod[imod]->SetLabelSize(0.025,"z");
4028       fhGridCellsMod[imod]->Draw("colz");
4029     }
4030     snprintf(name,buffersize,"QA_%s_GridCellsEntries.eps",fCalorimeter.Data());
4031     cgrid->Print(name); printf("Create plot %s\n",name);
4032     
4033     snprintf(cname,buffersize,"%s_QA_GridCellAccumEnergy",fCalorimeter.Data());
4034     TCanvas *cgridE   = new TCanvas("cgridE","Summed energy per cell", 12,12,800,400);
4035     if(fNModules%2 == 0)
4036       cgridE->Divide(fNModules/2,2); 
4037     else
4038       cgridE->Divide(fNModules/2+1,2); 
4039     for(Int_t imod = 0; imod < fNModules ; imod++){
4040       cgridE->cd(imod+1);
4041       gPad->SetLogz();
4042       gPad->SetGridy();
4043       gPad->SetGridx();
4044       //fhGridCellsEMod[imod]->SetLabelSize(0.025,"z");
4045       fhGridCellsEMod[imod]->SetZTitle("Accumulated Energy (GeV)    ");
4046       fhGridCellsEMod[imod]->SetYTitle("row (phi direction)    ");
4047       fhGridCellsEMod[imod]->Draw("colz");
4048     }
4049     snprintf(name,buffersize,"QA_%s_GridCellsAccumEnergy.eps",fCalorimeter.Data());
4050     cgridE->Print(name); printf("Create plot %s\n",name);
4051     
4052     //Accumulated energy per cell
4053     snprintf(cname,buffersize,"%s_QA_GridCellAverageEnergy",fCalorimeter.Data());
4054     TCanvas *cgridEA   = new TCanvas("cgridEA","Average energy per cell", 12,12,800,400);
4055     if(fNModules%2 == 0)          
4056       cgridEA->Divide(fNModules/2,2);
4057     else
4058       cgridEA->Divide(fNModules/2+1,2);  
4059     for(Int_t imod = 0; imod < fNModules ; imod++){
4060       cgridEA->cd(imod+1);
4061       gPad->SetLogz();
4062       gPad->SetGridy();
4063       gPad->SetGridx();
4064       //fhGridCellsEMod[imod]->SetLabelSize(0.025,"z");
4065       fhGridCellsEMod[imod]->SetZTitle("Average Energy (GeV)    ");
4066       fhGridCellsEMod[imod]->Divide(fhGridCellsMod[imod]);
4067       fhGridCellsEMod[imod]->Draw("colz");
4068     }
4069     snprintf(name,buffersize,"QA_%s_GridCellsAverageEnergy.eps",fCalorimeter.Data());
4070     cgridEA->Print(name); printf("Create plot %s\n",name);
4071                 
4072     //Accumulated Time per cell, E > 0.5 GeV
4073                 
4074     snprintf(cname,buffersize,"%s_QA_GridCellAccumTime",fCalorimeter.Data());
4075     TCanvas *cgridT   = new TCanvas("cgridT","Summed time per cell", 12,12,800,400);
4076     if(fNModules%2 == 0)
4077       cgridT->Divide(fNModules/2,2); 
4078     else
4079       cgridE->Divide(fNModules/2+1,2); 
4080     for(Int_t imod = 0; imod < fNModules ; imod++){
4081       cgridT->cd(imod+1);
4082       gPad->SetLogz();
4083       gPad->SetGridy();
4084       gPad->SetGridx();
4085       //fhGridCellsTimeMod[imod]->SetLabelSize(0.025,"z");
4086       fhGridCellsTimeMod[imod]->SetZTitle("Accumulated Time (ns)    ");
4087       fhGridCellsTimeMod[imod]->SetYTitle("row (phi direction)    ");
4088       fhGridCellsTimeMod[imod]->Draw("colz");
4089     }
4090     snprintf(name,buffersize,"QA_%s_GridCellsAccumTime.eps",fCalorimeter.Data());
4091     cgridT->Print(name); printf("Create plot %s\n",name);
4092                 
4093         }
4094         
4095   //---------------------------------------------
4096   //Calorimeter Correlation, PHOS vs EMCAL
4097   //---------------------------------------------
4098         if(fCorrelateCalos){
4099                 
4100                 snprintf(cname,buffersize,"QA_%s_CaloCorr_EMCALvsPHOS",fCalorimeter.Data());
4101                 TCanvas  * ccorr = new TCanvas(cname, " EMCAL vs PHOS", 400, 400) ;
4102                 ccorr->Divide(2, 2);
4103     
4104                 ccorr->cd(1) ; 
4105     //gPad->SetLogy();
4106     //gPad->SetLogx();
4107                 fhCaloCorrNClusters->SetAxisRange(nmin,nmax,"X");
4108                 fhCaloCorrNClusters->SetAxisRange(nmin,nmax,"Y");               
4109                 fhCaloCorrNClusters ->Draw();
4110     
4111                 ccorr->cd(2) ; 
4112     //gPad->SetLogy();
4113     //gPad->SetLogx();
4114                 fhCaloCorrNCells->SetAxisRange(nmin,nmax,"X");
4115                 fhCaloCorrNCells->SetAxisRange(nmin,nmax,"Y");          
4116                 fhCaloCorrNCells->Draw();
4117     
4118     //gPad->SetLogy();
4119     //gPad->SetLogx();
4120                 fhCaloCorrEClusters->SetAxisRange(ptmin,ptmax,"X");
4121                 fhCaloCorrEClusters->SetAxisRange(ptmin,ptmax,"Y");             
4122                 fhCaloCorrEClusters->Draw();
4123     
4124                 ccorr->cd(4) ; 
4125     //gPad->SetLogy();
4126     //gPad->SetLogx();
4127                 fhCaloCorrECells->SetAxisRange(ptmin,ptmax,"X");
4128                 fhCaloCorrECells->SetAxisRange(ptmin,ptmax,"Y");                
4129                 fhCaloCorrECells->Draw();
4130     
4131                 snprintf(name,buffersize,"QA_%s_CaloCorr_EMCALvsPHOS.eps",fCalorimeter.Data());
4132                 ccorr->Print(name); printf("Plot: %s\n",name);
4133         }
4134   
4135   //----------------------------
4136   //Invariant mass
4137   //-----------------------------
4138         
4139         Int_t imbinmin = -1;
4140         Int_t imbinmax = -1;
4141         
4142         if(fhIM->GetEntries() > 1){
4143                 Int_t nebins  = fhIM->GetNbinsX();
4144                 Int_t emax = (Int_t) fhIM->GetXaxis()->GetXmax();
4145                 Int_t emin = (Int_t) fhIM->GetXaxis()->GetXmin();
4146                 if (emin != 0 ) printf("emin != 0 \n");
4147     //printf("IM: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
4148                 
4149                 snprintf(cname,buffersize,"QA_%s_IM",fCalorimeter.Data());
4150     //  printf("c5\n");
4151                 TCanvas  * c5 = new TCanvas(cname, "Invariant mass", 600, 400) ;
4152                 c5->Divide(2, 3);
4153                 
4154                 c5->cd(1) ; 
4155     //fhIM->SetLineColor(4);
4156     //fhIM->Draw();
4157                 imbinmin = 0;
4158                 imbinmax =  (Int_t) (1-emin)*nebins/emax;
4159                 TH1D *pyim1 = fhIM->ProjectionY(Form("%s_py1",fhIM->GetName()),imbinmin,imbinmax);
4160                 pyim1->SetTitle("E_{pair} < 1 GeV");
4161                 pyim1->SetLineColor(1);
4162                 pyim1->Draw();
4163                 TLegend pLegendIM(0.7,0.6,0.9,0.8);
4164                 pLegendIM.SetTextSize(0.03);
4165                 pLegendIM.AddEntry(pyim1,"all modules","L");
4166                 pLegendIM.SetFillColor(10);
4167                 pLegendIM.SetBorderSize(1);
4168     //FIXME
4169                 for(Int_t imod = 0; imod < fNModules; imod++){
4170                         pyim1 = fhIMMod[imod]->ProjectionY(Form("%s_py1",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4171                         pLegendIM.AddEntry(pyim1,Form("module %d",imod),"L");
4172                         pyim1->SetLineColor(imod+1);
4173                         pyim1->Draw("same");
4174                 }
4175                 pLegendIM.Draw();
4176                 
4177                 c5->cd(2) ; 
4178                 imbinmin =  (Int_t) (1-emin)*nebins/emax;
4179                 imbinmax =  (Int_t) (2-emin)*nebins/emax;
4180                 TH1D *pyim2 = fhIM->ProjectionY(Form("%s_py2",fhIM->GetName()),imbinmin,imbinmax);
4181                 pyim2->SetTitle("1 < E_{pair} < 2 GeV");
4182                 pyim2->SetLineColor(1);
4183                 pyim2->Draw();
4184                 for(Int_t imod = 0; imod < fNModules; imod++){
4185                         pyim2 = fhIMMod[imod]->ProjectionY(Form("%s_py2",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4186                         pyim2->SetLineColor(imod+1);
4187                         pyim2->Draw("same");
4188                 }
4189                 
4190                 c5->cd(3) ; 
4191                 imbinmin =  (Int_t) (2-emin)*nebins/emax;
4192                 imbinmax =  (Int_t) (3-emin)*nebins/emax;
4193                 TH1D *pyim3 = fhIM->ProjectionY(Form("%s_py3",fhIM->GetName()),imbinmin,imbinmax);
4194                 pyim3->SetTitle("2 < E_{pair} < 3 GeV");
4195                 pyim3->SetLineColor(1);
4196                 pyim3->Draw();
4197                 for(Int_t imod = 0; imod < fNModules; imod++){
4198                         pyim3 = fhIMMod[imod]->ProjectionY(Form("%s_py3",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4199                         pyim3->SetLineColor(imod+1);
4200                         pyim3->Draw("same");
4201                 }
4202                 
4203                 c5->cd(4) ;
4204                 imbinmin =  (Int_t) (3-emin)*nebins/emax;
4205                 imbinmax =  (Int_t) (4-emin)*nebins/emax;
4206                 TH1D *pyim4 = fhIM->ProjectionY(Form("%s_py4",fhIM->GetName()),imbinmin,imbinmax);
4207                 pyim4->SetTitle("3 < E_{pair} < 4 GeV");
4208                 pyim4->SetLineColor(1);
4209                 pyim4->Draw();
4210                 for(Int_t imod = 0; imod < fNModules; imod++){
4211                         pyim4 = fhIMMod[imod]->ProjectionY(Form("%s_py4",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4212                         pyim4->SetLineColor(imod+1);
4213                         pyim4->Draw("same");
4214                 }
4215                 
4216                 c5->cd(5) ;
4217                 imbinmin =  (Int_t) (4-emin)*nebins/emax;
4218                 imbinmax =  (Int_t) (5-emin)*nebins/emax;
4219                 TH1D *pyim5 = fhIM->ProjectionY(Form("%s_py5",fhIM->GetName()),imbinmin,imbinmax);
4220                 pyim5->SetTitle("4< E_{pair} < 5 GeV");
4221                 pyim5->SetLineColor(1);
4222                 pyim5->Draw();
4223                 for(Int_t imod = 0; imod < fNModules; imod++){
4224                         pyim5 = fhIMMod[imod]->ProjectionY(Form("%s_py5",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4225                         pyim5->SetLineColor(imod+1);
4226                         pyim5->Draw("same");
4227                 }
4228                 
4229                 c5->cd(6) ;
4230                 imbinmin =  (Int_t) (5-emin)*nebins/emax;
4231                 imbinmax =  -1;
4232                 TH1D *pyim10 = fhIM->ProjectionY(Form("%s_py6",fhIM->GetName()),imbinmin,imbinmax);
4233                 pyim10->SetTitle("E_{pair} > 5 GeV");
4234                 pyim10->SetLineColor(1);
4235                 pyim10->Draw();
4236                 for(Int_t imod = 0; imod < fNModules; imod++){
4237                         pyim10 = fhIMMod[imod]->ProjectionY(Form("%s_py6",fhIMMod[imod]->GetName()),imbinmin,imbinmax);
4238                         pyim10->SetLineColor(imod+1);
4239                         pyim10->Draw("same");
4240                 }
4241                 
4242                 snprintf(name,buffersize,"QA_%s_InvariantMass.eps",fCalorimeter.Data());
4243                 c5->Print(name); printf("Plot: %s\n",name);
4244         }
4245         
4246   //--------------------------------------------------
4247   //Invariant mass, clusters with more than one cell
4248   //-------------------------------------------------
4249         if(fhIMCellCut->GetEntries() > 1){
4250                 Int_t nebins  = fhIMCellCut->GetNbinsX();
4251                 Int_t emax = (Int_t) fhIMCellCut->GetXaxis()->GetXmax();
4252                 Int_t emin = (Int_t) fhIMCellCut->GetXaxis()->GetXmin();
4253                 if (emin != 0 ) printf("emin != 0 \n");
4254     //printf("IMCellCut: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
4255                 
4256                 snprintf(cname,buffersize,"QA_%s_IMCellCut",fCalorimeter.Data());
4257     //  printf("c5cc\n");
4258                 TCanvas  * c5cc = new TCanvas(cname, "Invariant mass, Cell Cut", 600, 400) ;
4259                 c5cc->Divide(2, 3);
4260                 
4261                 c5cc->cd(1) ; 
4262     //fhIMCellCut->SetLineColor(4);
4263     //fhIMCellCut->Draw();
4264                 imbinmin = 0;
4265                 imbinmax =  (Int_t) (1-emin)*nebins/emax;
4266                 TH1D *pyimcc1 = fhIMCellCut->ProjectionY(Form("%s_py1",fhIMCellCut->GetName()),imbinmin,imbinmax);
4267                 pyimcc1->SetTitle("E_{pair} < 1 GeV");
4268                 pyimcc1->SetLineColor(1);
4269                 pyimcc1->Draw();
4270                 TLegend pLegendIMCellCut(0.7,0.6,0.9,0.8);
4271                 pLegendIMCellCut.SetTextSize(0.03);
4272                 pLegendIMCellCut.AddEntry(pyimcc1,"all modules","L");
4273                 pLegendIMCellCut.SetFillColor(10);
4274                 pLegendIMCellCut.SetBorderSize(1);
4275                 
4276                 for(Int_t imod = 0; imod < fNModules; imod++){
4277                         pyimcc1 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4278                         pLegendIMCellCut.AddEntry(pyimcc1,Form("module %d",imod),"L");
4279                         pyimcc1->SetLineColor(imod+1);
4280                         pyimcc1->Draw("same");
4281                 }
4282                 pLegendIMCellCut.Draw();
4283                 
4284                 c5cc->cd(2) ; 
4285                 imbinmin =  (Int_t) (1-emin)*nebins/emax;
4286                 imbinmax =  (Int_t) (2-emin)*nebins/emax;
4287                 TH1D *pyimcc2 = fhIMCellCut->ProjectionY(Form("%s_py2",fhIMCellCut->GetName()),imbinmin,imbinmax);
4288                 pyimcc2->SetTitle("1 < E_{pair} < 2 GeV");
4289                 pyimcc2->SetLineColor(1);
4290                 pyimcc2->Draw();
4291                 for(Int_t imod = 0; imod < fNModules; imod++){
4292                         pyimcc2 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4293                         pyimcc2->SetLineColor(imod+1);
4294                         pyimcc2->Draw("same");
4295                 }
4296                 
4297                 c5cc->cd(3) ; 
4298                 imbinmin =  (Int_t) (2-emin)*nebins/emax;
4299                 imbinmax =  (Int_t) (3-emin)*nebins/emax;
4300                 TH1D *pyimcc3 = fhIMCellCut->ProjectionY(Form("%s_py3",fhIMCellCut->GetName()),imbinmin,imbinmax);
4301                 pyimcc3->SetTitle("2 < E_{pair} < 3 GeV");
4302                 pyimcc3->SetLineColor(1);
4303                 pyimcc3->Draw();
4304                 for(Int_t imod = 0; imod < fNModules; imod++){
4305                         pyimcc3 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4306                         pyimcc3->SetLineColor(imod+1);
4307                         pyimcc3->Draw("same");
4308                 }
4309                 
4310                 c5cc->cd(4) ;
4311                 imbinmin =  (Int_t) (3-emin)*nebins/emax;
4312                 imbinmax =  (Int_t) (4-emin)*nebins/emax;
4313                 TH1D *pyimcc4 = fhIMCellCut->ProjectionY(Form("%s_py4",fhIMCellCut->GetName()),imbinmin,imbinmax);
4314                 pyimcc4->SetTitle("3 < E_{pair} < 4 GeV");
4315                 pyimcc4->SetLineColor(1);
4316                 pyimcc4->Draw();
4317                 for(Int_t imod = 0; imod < fNModules; imod++){
4318                         pyimcc4 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py5",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4319                         pyimcc4->SetLineColor(imod+1);
4320                         pyimcc4->Draw("same");
4321                 }
4322                 
4323                 c5cc->cd(5) ;
4324                 imbinmin =  (Int_t) (4-emin)*nebins/emax;
4325                 imbinmax =  (Int_t) (5-emin)*nebins/emax;
4326                 TH1D *pyimcc5cc = fhIMCellCut->ProjectionY(Form("%s_py5",fhIMCellCut->GetName()),imbinmin,imbinmax);
4327                 pyimcc5cc->SetTitle("4< E_{pair} < 5 GeV");
4328                 pyimcc5cc->SetLineColor(1);
4329                 pyimcc5cc->Draw();
4330                 for(Int_t imod = 0; imod < fNModules; imod++){
4331                         pyimcc5cc = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py5",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4332                         pyimcc5cc->SetLineColor(imod+1);
4333                         pyimcc5cc->Draw("same");
4334                 }
4335                 
4336                 c5cc->cd(6) ;
4337                 imbinmin =  (Int_t) (5-emin)*nebins/emax;
4338                 imbinmax =  -1;
4339                 TH1D *pyimcc10 = fhIMCellCut->ProjectionY(Form("%s_py6",fhIMCellCut->GetName()),imbinmin,imbinmax);
4340                 pyimcc10->SetTitle("E_{pair} > 5 GeV");
4341                 pyimcc10->SetLineColor(1);
4342                 pyimcc10->Draw();
4343                 for(Int_t imod = 0; imod < fNModules; imod++){
4344                         pyimcc10 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),imbinmin,imbinmax);
4345                         pyimcc10->SetLineColor(imod+1);
4346                         pyimcc10->Draw("same");
4347                 }
4348                 
4349                 snprintf(name,buffersize,"QA_%s_InvariantMass_CellCut.eps",fCalorimeter.Data());
4350                 c5cc->Print(name); printf("Plot: %s\n",name);
4351         }
4352         
4353         
4354   //Asymmetry
4355         if(fhAsym->GetEntries() > 1){
4356                 Int_t nebins  = fhAsym->GetNbinsX();
4357                 Int_t emax = (Int_t) fhAsym->GetXaxis()->GetXmax();
4358                 Int_t emin = (Int_t) fhAsym->GetXaxis()->GetXmin();
4359                 if (emin != 0 ) printf("emin != 0 \n");
4360     //printf("Asym: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
4361                 
4362                 snprintf(cname,buffersize,"QA_%s_Asym",fCalorimeter.Data());
4363     //  printf("c5\n");
4364                 TCanvas  * c5b = new TCanvas(cname, "Asymmetry", 400, 400) ;
4365                 c5b->Divide(2, 2);
4366                 
4367                 c5b->cd(1) ; 
4368                 fhAsym->SetTitleOffset(1.6,"Y");
4369                 fhAsym->SetLineColor(4);
4370                 fhAsym->Draw();
4371                 
4372                 c5b->cd(2) ; 
4373                 imbinmin = 0;
4374                 imbinmax = (Int_t) (5-emin)*nebins/emax;
4375                 TH1D *pyAsym5 = fhAsym->ProjectionY(Form("%s_py5",fhAsym->GetName()),imbinmin,imbinmax);
4376                 pyAsym5->SetTitle("E_{pair} < 5 GeV");
4377                 pyAsym5->SetLineColor(4);
4378                 pyAsym5->Draw();
4379                 
4380                 c5b->cd(3) ; 
4381                 imbinmin = (Int_t) (5-emin)*nebins/emax;
4382                 imbinmax = (Int_t) (10-emin)*nebins/emax;
4383                 TH1D *pyAsym510 = fhAsym->ProjectionY(Form("%s_py510",fhAsym->GetName()),imbinmin,imbinmax);
4384                 pyAsym510->SetTitle("5 < E_{pair} < 10 GeV");
4385                 pyAsym510->SetLineColor(4);
4386                 pyAsym510->Draw();
4387                 
4388                 c5b->cd(4) ;
4389                 imbinmin = (Int_t) (10-emin)*nebins/emax;
4390                 imbinmax = -1;
4391                 TH1D *pyAsym10 = fhAsym->ProjectionY(Form("%s_py10",fhAsym->GetName()),imbinmin,imbinmax);
4392                 pyAsym10->SetTitle("E_{pair} > 10 GeV");
4393                 pyAsym10->SetLineColor(4);
4394                 pyAsym10->Draw();
4395                 
4396                 snprintf(name,buffersize,"QA_%s_Asymmetry.eps",fCalorimeter.Data());
4397                 c5b->Print(name); printf("Plot: %s\n",name);
4398         }
4399         
4400         
4401         if(IsDataMC()){
4402     //Reconstructed vs MC distributions
4403     //printf("c6\n");
4404     snprintf(cname,buffersize,"QA_%s_recvsmc",fCalorimeter.Data());
4405     TCanvas  * c6 = new TCanvas(cname, "Reconstructed vs MC distributions", 400, 400) ;
4406     c6->Divide(2, 2);
4407     
4408     c6->cd(1) ; 
4409     fh2E->SetTitleOffset(1.6,"Y");
4410     fh2E->SetLineColor(4);
4411     fh2E->Draw();
4412     
4413     c6->cd(2) ; 
4414     fh2Pt->SetTitleOffset(1.6,"Y");
4415     fh2Pt->SetLineColor(4);
4416     fh2Pt->Draw();
4417     
4418     c6->cd(3) ; 
4419     fh2Phi->SetTitleOffset(1.6,"Y");
4420     fh2Phi->SetLineColor(4);
4421     fh2Phi->Draw();
4422     
4423     c6->cd(4) ; 
4424     fh2Eta->SetTitleOffset(1.6,"Y");
4425     fh2Eta->SetLineColor(4);
4426     fh2Eta->Draw();
4427     
4428     snprintf(name,buffersize,"QA_%s_ReconstructedVSMCDistributions.eps",fCalorimeter.Data());
4429     c6->Print(name); printf("Plot: %s\n",name); 
4430     
4431     //Reconstructed vs MC distributions
4432     //printf("c6\n");
4433     snprintf(cname,buffersize,"QA_%s_gamrecvsmc",fCalorimeter.Data());
4434     TCanvas  * c6Gam = new TCanvas(cname, "Reconstructed vs MC distributions", 400, 400) ;
4435     c6Gam->Divide(2, 2);
4436     
4437     c6Gam->cd(1) ; 
4438     fhGamE->Draw();
4439     
4440     c6Gam->cd(2) ; 
4441     fhGamPt->Draw();
4442     
4443     c6Gam->cd(3) ; 
4444     fhGamPhi->Draw();
4445     
4446     c6Gam->cd(4) ; 
4447     fhGamEta->Draw();
4448     
4449     snprintf(name,buffersize,"QA_%s_GammaReconstructedVSMCDistributions.eps",fCalorimeter.Data());
4450     c6->Print(name); printf("Plot: %s\n",name); 
4451     
4452     //Generated - reconstructed  
4453     //printf("c7\n");
4454     snprintf(cname,buffersize,"QA_%s_diffgenrec",fCalorimeter.Data());
4455     TCanvas  * c7 = new TCanvas(cname, "generated - reconstructed", 400, 400) ;
4456     c7->Divide(2, 2);
4457     
4458     c7->cd(1) ; 
4459     if(fhDeltaE->GetEntries() > 0) gPad->SetLogy();
4460     fhGamDeltaE->SetLineColor(4);
4461     fhDeltaE->Draw();
4462     fhGamDeltaE->Draw("same");
4463     
4464     TLegend pLegendd(0.65,0.55,0.9,0.8);
4465     pLegendd.SetTextSize(0.06);
4466     pLegendd.AddEntry(fhDeltaE,"all","L");
4467     pLegendd.AddEntry(fhGamDeltaE,"from  #gamma","L");
4468     pLegendd.SetFillColor(10);
4469     pLegendd.SetBorderSize(1);
4470     pLegendd.Draw();
4471     
4472     c7->cd(2) ; 
4473     if(fhDeltaPt->GetEntries() > 0) gPad->SetLogy();
4474     fhGamDeltaPt->SetLineColor(4);
4475     fhDeltaPt->Draw();
4476     fhGamDeltaPt->Draw("same");
4477     
4478     c7->cd(3) ; 
4479     fhGamDeltaPhi->SetLineColor(4);
4480     fhDeltaPhi->Draw();
4481     fhGamDeltaPhi->Draw("same");
4482     
4483     c7->cd(4) ; 
4484     fhGamDeltaEta->SetLineColor(4);
4485     fhDeltaEta->Draw();
4486     fhGamDeltaEta->Draw("same");
4487     
4488     snprintf(name,buffersize,"QA_%s_DiffGeneratedReconstructed.eps",fCalorimeter.Data());
4489     c7->Print(name); printf("Plot: %s\n",name);
4490     
4491     // Reconstructed / Generated 
4492     //printf("c8\n");
4493     snprintf(cname,buffersize,"QA_%s_ratiorecgen",fCalorimeter.Data());
4494     TCanvas  * c8 = new TCanvas(cname, " reconstructed / generated", 400, 400) ;
4495     c8->Divide(2, 2);
4496     
4497     c8->cd(1) ; 
4498     if(fhRatioE->GetEntries() > 0) gPad->SetLogy();
4499     fhGamRatioE->SetLineColor(4);
4500     fhRatioE->Draw();
4501     fhGamRatioE->Draw("same");
4502     
4503     TLegend pLegendr(0.65,0.55,0.9,0.8);
4504     pLegendr.SetTextSize(0.06);
4505     pLegendr.AddEntry(fhRatioE,"all","L");
4506     pLegendr.AddEntry(fhGamRatioE,"from  #gamma","L");
4507     pLegendr.SetFillColor(10);
4508     pLegendr.SetBorderSize(1);
4509     pLegendr.Draw();
4510     
4511     c8->cd(2) ; 
4512     if(fhRatioPt->GetEntries() > 0) gPad->SetLogy();
4513     fhGamRatioPt->SetLineColor(4);
4514     fhRatioPt->Draw();
4515     fhGamRatioPt->Draw("same");
4516     
4517     c8->cd(3) ; 
4518     fhGamRatioPhi->SetLineColor(4);
4519     fhRatioPhi->Draw();
4520     fhGamRatioPhi->Draw("same");
4521     
4522     c8->cd(4) ; 
4523     fhGamRatioEta->SetLineColor(4);
4524     fhRatioEta->Draw();
4525     fhGamRatioEta->Draw("same");
4526     
4527     snprintf(name,buffersize,"QA_%s_ReconstructedDivGenerated.eps",fCalorimeter.Data());
4528     c8->Print(name); printf("Plot: %s\n",name);
4529     
4530     //MC
4531     
4532     //Generated distributions
4533     //printf("c1\n");
4534     snprintf(cname,buffersize,"QA_%s_gen",fCalorimeter.Data());
4535     TCanvas  * c10 = new TCanvas(cname, "Generated distributions", 600, 200) ;
4536     c10->Divide(3, 1);
4537     
4538     c10->cd(1) ; 
4539     gPad->SetLogy();
4540     TH1F * haxispt  = (TH1F*) fhGenPi0Pt->Clone(Form("%s_axispt",fhGenPi0Pt->GetName()));  
4541     haxispt->SetTitle("Generated Particles p_{T}, |#eta| < 1");
4542     fhGenPi0Pt->SetLineColor(1);
4543     fhGenGamPt->SetLineColor(4);
4544     fhGenEtaPt->SetLineColor(2);
4545     fhGenOmegaPt->SetLineColor(7);
4546     fhGenElePt->SetLineColor(6);
4547     
4548     //Select the maximum of the histogram to show all lines.
4549     if(fhGenPi0Pt->GetMaximum() >= fhGenGamPt->GetMaximum() && fhGenPi0Pt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
4550        fhGenPi0Pt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenPi0Pt->GetMaximum() >= fhGenElePt->GetMaximum())
4551       haxispt->SetMaximum(fhGenPi0Pt->GetMaximum());
4552     else if(fhGenGamPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenGamPt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
4553             fhGenGamPt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenGamPt->GetMaximum() >= fhGenElePt->GetMaximum())
4554       haxispt->SetMaximum(fhGenGamPt->GetMaximum());
4555     else if(fhGenEtaPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenEtaPt->GetMaximum() >= fhGenGamPt->GetMaximum() && 
4556             fhGenEtaPt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenEtaPt->GetMaximum() >= fhGenElePt->GetMaximum())
4557       haxispt->SetMaximum(fhGenEtaPt->GetMaximum());    
4558     else if(fhGenOmegaPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenOmegaPt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
4559             fhGenOmegaPt->GetMaximum() >= fhGenGamPt->GetMaximum() && fhGenOmegaPt->GetMaximum() >= fhGenElePt->GetMaximum())
4560       haxispt->SetMaximum(fhGenOmegaPt->GetMaximum());
4561     else if(fhGenElePt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenElePt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
4562             fhGenElePt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenElePt->GetMaximum() >= fhGenGamPt->GetMaximum())
4563       haxispt->SetMaximum(fhGenElePt->GetMaximum());
4564     haxispt->SetMinimum(1);
4565     haxispt->Draw("axis");
4566     fhGenPi0Pt->Draw("same");
4567     fhGenGamPt->Draw("same");
4568     fhGenEtaPt->Draw("same");
4569     fhGenOmegaPt->Draw("same");
4570     fhGenElePt->Draw("same");
4571     
4572     TLegend pLegend(0.85,0.65,0.95,0.93);
4573     pLegend.SetTextSize(0.06);
4574     pLegend.AddEntry(fhGenPi0Pt,"  #pi^{0}","L");
4575     pLegend.AddEntry(fhGenGamPt,"  #gamma","L");
4576     pLegend.AddEntry(fhGenEtaPt,"  #eta","L");
4577     pLegend.AddEntry(fhGenOmegaPt,"  #omega","L");
4578     pLegend.AddEntry(fhGenElePt,"  e^{#pm}","L");
4579     pLegend.SetFillColor(10);
4580     pLegend.SetBorderSize(1);
4581     pLegend.Draw();
4582     
4583     c10->cd(2) ;
4584     gPad->SetLogy();
4585     TH1F * haxiseta  = (TH1F*) fhGenPi0Eta->Clone(Form("%s_axiseta",fhGenPi0Eta->GetName()));  
4586     haxiseta->SetTitle("Generated Particles #eta, |#eta| < 1");
4587     fhGenPi0Eta->SetLineColor(1);
4588     fhGenGamEta->SetLineColor(4);
4589     fhGenEtaEta->SetLineColor(2);
4590     fhGenOmegaEta->SetLineColor(7);
4591     fhGenEleEta->SetLineColor(6);
4592     //Select the maximum of the histogram to show all lines.
4593     if(fhGenPi0Eta->GetMaximum() >= fhGenGamEta->GetMaximum() && fhGenPi0Eta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
4594        fhGenPi0Eta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenPi0Eta->GetMaximum() >= fhGenEleEta->GetMaximum())
4595       haxiseta->SetMaximum(fhGenPi0Eta->GetMaximum());
4596     else if(fhGenGamEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenGamEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
4597             fhGenGamEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenGamEta->GetMaximum() >= fhGenEleEta->GetMaximum())
4598       haxiseta->SetMaximum(fhGenGamEta->GetMaximum());
4599     else if(fhGenEtaEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenEtaEta->GetMaximum() >= fhGenGamEta->GetMaximum() && 
4600             fhGenEtaEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenEtaEta->GetMaximum() >= fhGenEleEta->GetMaximum())
4601       haxiseta->SetMaximum(fhGenEtaEta->GetMaximum());  
4602     else if(fhGenOmegaEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenOmegaEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
4603             fhGenOmegaEta->GetMaximum() >= fhGenGamEta->GetMaximum() && fhGenOmegaEta->GetMaximum() >= fhGenEleEta->GetMaximum())
4604       haxiseta->SetMaximum(fhGenOmegaEta->GetMaximum());
4605     else if(fhGenEleEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenEleEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
4606             fhGenEleEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenEleEta->GetMaximum() >= fhGenGamEta->GetMaximum())
4607       haxiseta->SetMaximum(fhGenEleEta->GetMaximum());
4608     haxiseta->SetMinimum(100);
4609     haxiseta->Draw("axis");
4610     fhGenPi0Eta->Draw("same");
4611     fhGenGamEta->Draw("same");
4612     fhGenEtaEta->Draw("same");
4613     fhGenOmegaEta->Draw("same");
4614     fhGenEleEta->Draw("same");
4615     
4616     
4617     c10->cd(3) ; 
4618     gPad->SetLogy();
4619     TH1F * haxisphi  = (TH1F*) fhGenPi0Phi->Clone(Form("%s_axisphi",fhGenPi0Phi->GetName()));  
4620     haxisphi->SetTitle("Generated Particles #phi, |#eta| < 1");
4621     fhGenPi0Phi->SetLineColor(1);
4622     fhGenGamPhi->SetLineColor(4);
4623     fhGenEtaPhi->SetLineColor(2);
4624     fhGenOmegaPhi->SetLineColor(7);
4625     fhGenElePhi->SetLineColor(6);
4626     //Select the maximum of the histogram to show all lines.
4627     if(fhGenPi0Phi->GetMaximum() >= fhGenGamPhi->GetMaximum() && fhGenPi0Phi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
4628        fhGenPi0Phi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenPi0Phi->GetMaximum() >= fhGenElePhi->GetMaximum())
4629       haxisphi->SetMaximum(fhGenPi0Phi->GetMaximum());
4630     else if(fhGenGamPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenGamPhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
4631             fhGenGamPhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenGamPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
4632       haxisphi->SetMaximum(fhGenGamPhi->GetMaximum());
4633     else if(fhGenEtaPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenEtaPhi->GetMaximum() >= fhGenGamPhi->GetMaximum() && 
4634             fhGenEtaPhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenEtaPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
4635       haxisphi->SetMaximum(fhGenEtaPhi->GetMaximum());  
4636     else if(fhGenOmegaPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenOmegaPhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
4637             fhGenOmegaPhi->GetMaximum() >= fhGenGamPhi->GetMaximum() && fhGenOmegaPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
4638       haxisphi->SetMaximum(fhGenOmegaPhi->GetMaximum());
4639     else if(fhGenElePhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenElePhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
4640             fhGenElePhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenElePhi->GetMaximum() >= fhGenGamPhi->GetMaximum())
4641       haxisphi->SetMaximum(fhGenElePhi->GetMaximum());
4642     haxisphi->SetMinimum(100);
4643     haxisphi->Draw("axis");
4644     fhGenPi0Phi->Draw("same");
4645     fhGenGamPhi->Draw("same");
4646     fhGenEtaPhi->Draw("same");
4647     fhGenOmegaPhi->Draw("same");
4648     fhGenElePhi->Draw("same");
4649     
4650     snprintf(name,buffersize,"QA_%s_GeneratedDistributions.eps",fCalorimeter.Data());
4651     c10->Print(name); printf("Plot: %s\n",name);
4652     
4653     
4654     //Reconstructed clusters depending on its original particle.
4655     //printf("c1\n");
4656     snprintf(cname,buffersize,"QA_%s_recgenid",fCalorimeter.Data());
4657     TCanvas  * c11 = new TCanvas(cname, "Reconstructed particles, function of their original particle ID", 400, 400) ;
4658     c11->Divide(2, 2);
4659     
4660     
4661     c11->cd(1) ; 
4662     gPad->SetLogy();
4663     TH1F * hGamE   = (TH1F*) fhGamE->ProjectionX(Form("%s_px",fhGamE->GetName()),-1,-1);
4664     TH1F * hPi0E   = (TH1F*) fhPi0E->ProjectionX(Form("%s_px",fhPi0E->GetName()),-1,-1);
4665     TH1F * hEleE   = (TH1F*) fhEleE->ProjectionX(Form("%s_px",fhEleE->GetName()),-1,-1);
4666     TH1F * hNeHadE = (TH1F*) fhNeHadE->ProjectionX(Form("%s_px",fhNeHadE->GetName()),-1,-1);
4667     TH1F * hChHadE = (TH1F*) fhChHadE->ProjectionX(Form("%s_px",fhChHadE->GetName()),-1,-1);
4668     TH1F * haxisE  = (TH1F*) hPi0E->Clone(Form("%s_axisE",fhPi0E->GetName()));  
4669     haxisE->SetTitle("Reconstructed particles E, function of their original particle ID");
4670     hPi0E->SetLineColor(1);
4671     hGamE->SetLineColor(4);
4672     hNeHadE->SetLineColor(2);
4673     hChHadE->SetLineColor(7);
4674     hEleE->SetLineColor(6);
4675     
4676     //Select the maximum of the histogram to show all lines.
4677     if(hPi0E->GetMaximum() >= hGamE->GetMaximum() && hPi0E->GetMaximum() >= hNeHadE->GetMaximum() && 
4678        hPi0E->GetMaximum() >= hChHadE->GetMaximum() && hPi0E->GetMaximum() >= hEleE->GetMaximum())
4679       haxisE->SetMaximum(hPi0E->GetMaximum());
4680     else if(hGamE->GetMaximum() >= hPi0E->GetMaximum() && hGamE->GetMaximum() >= hNeHadE->GetMaximum() && 
4681             hGamE->GetMaximum() >= hChHadE->GetMaximum() && hGamE->GetMaximum() >= hEleE->GetMaximum())
4682       haxisE->SetMaximum(hGamE->GetMaximum());
4683     else if(hNeHadE->GetMaximum() >= hPi0E->GetMaximum() && hNeHadE->GetMaximum() >= hGamE->GetMaximum() && 
4684             hNeHadE->GetMaximum() >= hChHadE->GetMaximum() && hNeHadE->GetMaximum() >= hEleE->GetMaximum())
4685       haxisE->SetMaximum(hNeHadE->GetMaximum());        
4686     else if(hChHadE->GetMaximum() >= hPi0E->GetMaximum() && hChHadE->GetMaximum() >= hNeHadE->GetMaximum() && 
4687             hChHadE->GetMaximum() >= hGamE->GetMaximum() && hChHadE->GetMaximum() >= hEleE->GetMaximum())
4688       haxisE->SetMaximum(hChHadE->GetMaximum());
4689     else if(hEleE->GetMaximum() >= hPi0E->GetMaximum() && hEleE->GetMaximum() >= hNeHadE->GetMaximum() && 
4690             hEleE->GetMaximum() >= hChHadE->GetMaximum() && hEleE->GetMaximum() >= hGamE->GetMaximum())
4691       haxisE->SetMaximum(hEleE->GetMaximum());
4692     haxisE->SetXTitle("E (GeV)");
4693     haxisE->SetMinimum(1);
4694     haxisE->Draw("axis");
4695     hPi0E->Draw("same");
4696     hGamE->Draw("same");
4697     hNeHadE->Draw("same");
4698     hChHadE->Draw("same");
4699     hEleE->Draw("same");
4700     
4701     TLegend pLegend2(0.8,0.65,0.95,0.93);
4702     pLegend2.SetTextSize(0.06);
4703     pLegend2.AddEntry(hPi0E,"  #pi^{0}","L");
4704     pLegend2.AddEntry(hGamE,"  #gamma","L");
4705     pLegend2.AddEntry(hEleE,"  e^{#pm}","L");
4706     pLegend2.AddEntry(hChHadE,"  h^{#pm}","L");
4707     pLegend2.AddEntry(hNeHadE,"  h^{0}","L");
4708     pLegend2.SetFillColor(10);
4709     pLegend2.SetBorderSize(1);
4710     pLegend2.Draw();
4711     
4712     
4713     c11->cd(2) ; 
4714     gPad->SetLogy();
4715     //printf("%s, %s, %s, %s, %s\n",fhGamPt->GetName(),fhPi0Pt->GetName(),fhElePt->GetName(),fhNeHadPt->GetName(), fhChHadPt->GetName());
4716     TH1F * hGamPt   = (TH1F*) fhGamPt->ProjectionX(Form("%s_px",fhGamPt->GetName()),-1,-1);
4717     TH1F * hPi0Pt   = (TH1F*) fhPi0Pt->ProjectionX(Form("%s_px",fhPi0Pt->GetName()),-1,-1);
4718     TH1F * hElePt   = (TH1F*) fhElePt->ProjectionX(Form("%s_px",fhElePt->GetName()),-1,-1);
4719     TH1F * hNeHadPt = (TH1F*) fhNeHadPt->ProjectionX(Form("%s_px",fhNeHadPt->GetName()),-1,-1);
4720     TH1F * hChHadPt = (TH1F*) fhChHadPt->ProjectionX(Form("%s_px",fhChHadPt->GetName()),-1,-1);
4721     haxispt  = (TH1F*) hPi0Pt->Clone(Form("%s_axisPt",fhPi0Pt->GetName()));  
4722     haxispt->SetTitle("Reconstructed particles p_{T}, function of their original particle ID");
4723     hPi0Pt->SetLineColor(1);
4724     hGamPt->SetLineColor(4);
4725     hNeHadPt->SetLineColor(2);
4726     hChHadPt->SetLineColor(7);
4727     hElePt->SetLineColor(6);
4728     
4729     //Select the maximum of the histogram to show all lines.
4730     if(hPi0Pt->GetMaximum() >= hGamPt->GetMaximum() && hPi0Pt->GetMaximum() >= hNeHadPt->GetMaximum() && 
4731        hPi0Pt->GetMaximum() >= hChHadPt->GetMaximum() && hPi0Pt->GetMaximum() >= hElePt->GetMaximum())
4732       haxispt->SetMaximum(hPi0Pt->GetMaximum());
4733     else if(hGamPt->GetMaximum() >= hPi0Pt->GetMaximum() && hGamPt->GetMaximum() >= hNeHadPt->GetMaximum() && 
4734             hGamPt->GetMaximum() >= hChHadPt->GetMaximum() && hGamPt->GetMaximum() >= hElePt->GetMaximum())
4735       haxispt->SetMaximum(hGamPt->GetMaximum());
4736     else if(hNeHadPt->GetMaximum() >= hPi0Pt->GetMaximum() && hNeHadPt->GetMaximum() >= hGamPt->GetMaximum() && 
4737             hNeHadPt->GetMaximum() >= hChHadPt->GetMaximum() && hNeHadPt->GetMaximum() >= hElePt->GetMaximum())
4738       haxispt->SetMaximum(hNeHadPt->GetMaximum());      
4739     else if(hChHadPt->GetMaximum() >= hPi0Pt->GetMaximum() && hChHadPt->GetMaximum() >= hNeHadPt->GetMaximum() && 
4740             hChHadPt->GetMaximum() >= hGamPt->GetMaximum() && hChHadPt->GetMaximum() >= hElePt->GetMaximum())
4741       haxispt->SetMaximum(hChHadPt->GetMaximum());
4742     else if(hElePt->GetMaximum() >= hPi0Pt->GetMaximum() && hElePt->GetMaximum() >= hNeHadPt->GetMaximum() && 
4743             hElePt->GetMaximum() >= hChHadPt->GetMaximum() && hElePt->GetMaximum() >= hGamPt->GetMaximum())
4744       haxispt->SetMaximum(hElePt->GetMaximum());
4745     haxispt->SetXTitle("p_{T} (GeV/c)");
4746     haxispt->SetMinimum(1);
4747     haxispt->Draw("axis");
4748     hPi0Pt->Draw("same");
4749     hGamPt->Draw("same");
4750     hNeHadPt->Draw("same");
4751     hChHadPt->Draw("same");
4752     hElePt->Draw("same");
4753     
4754     c11->cd(3) ;
4755     gPad->SetLogy();
4756     
4757     TH1F * hGamEta   = (TH1F*) fhGamEta->ProjectionX(Form("%s_px",fhGamEta->GetName()),-1,-1);
4758     TH1F * hPi0Eta   = (TH1F*) fhPi0Eta->ProjectionX(Form("%s_px",fhPi0Eta->GetName()),-1,-1);
4759     TH1F * hEleEta   = (TH1F*) fhEleEta->ProjectionX(Form("%s_px",fhEleEta->GetName()),-1,-1);
4760     TH1F * hNeHadEta = (TH1F*) fhNeHadEta->ProjectionX(Form("%s_px",fhNeHadEta->GetName()),-1,-1);
4761     TH1F * hChHadEta = (TH1F*) fhChHadEta->ProjectionX(Form("%s_px",fhChHadEta->GetName()),-1,-1);
4762     haxiseta  = (TH1F*) hPi0Eta->Clone(Form("%s_axisEta",fhPi0Eta->GetName()));  
4763     haxiseta->SetTitle("Reconstructed particles #eta, function of their original particle ID");
4764     hPi0Eta->SetLineColor(1);
4765     hGamEta->SetLineColor(4);
4766     hNeHadEta->SetLineColor(2);
4767     hChHadEta->SetLineColor(7);
4768     hEleEta->SetLineColor(6);
4769     //Select the maximum of the histogram to show all lines.
4770     if(hPi0Eta->GetMaximum() >= hGamEta->GetMaximum() && hPi0Eta->GetMaximum() >= hNeHadEta->GetMaximum() && 
4771        hPi0Eta->GetMaximum() >= hChHadEta->GetMaximum() && hPi0Eta->GetMaximum() >= hEleEta->GetMaximum())
4772       haxiseta->SetMaximum(hPi0Eta->GetMaximum());
4773     else if(hGamEta->GetMaximum() >= hPi0Eta->GetMaximum() && hGamEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
4774             hGamEta->GetMaximum() >= hChHadEta->GetMaximum() && hGamEta->GetMaximum() >= hEleEta->GetMaximum())
4775       haxiseta->SetMaximum(hGamEta->GetMaximum());
4776     else if(hNeHadEta->GetMaximum() >= hPi0Eta->GetMaximum() && hNeHadEta->GetMaximum() >= hGamEta->GetMaximum() && 
4777             hNeHadEta->GetMaximum() >= hChHadEta->GetMaximum() && hNeHadEta->GetMaximum() >= hEleEta->GetMaximum())
4778       haxiseta->SetMaximum(hNeHadEta->GetMaximum());    
4779     else if(hChHadEta->GetMaximum() >= hPi0Eta->GetMaximum() && hChHadEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
4780             hChHadEta->GetMaximum() >= hGamEta->GetMaximum() && hChHadEta->GetMaximum() >= hEleEta->GetMaximum())
4781       haxiseta->SetMaximum(hChHadEta->GetMaximum());
4782     else if(hEleEta->GetMaximum() >= hPi0Eta->GetMaximum() && hEleEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
4783             hEleEta->GetMaximum() >= hChHadEta->GetMaximum() && hEleEta->GetMaximum() >= hGamEta->GetMaximum())
4784       haxiseta->SetMaximum(hEleEta->GetMaximum());
4785     
4786     haxiseta->SetXTitle("#eta");
4787     haxiseta->Draw("axis");
4788     hPi0Eta->Draw("same");
4789     hGamEta->Draw("same");
4790     hNeHadEta->Draw("same");
4791     hChHadEta->Draw("same");
4792     hEleEta->Draw("same");
4793     
4794     
4795     c11->cd(4) ; 
4796     gPad->SetLogy();
4797     TH1F * hGamPhi   = (TH1F*) fhGamPhi->ProjectionX(Form("%s_px",fhGamPhi->GetName()),-1,-1);
4798     TH1F * hPi0Phi   = (TH1F*) fhPi0Phi->ProjectionX(Form("%s_px",fhPi0Phi->GetName()),-1,-1);
4799     TH1F * hElePhi   = (TH1F*) fhElePhi->ProjectionX(Form("%s_px",fhElePhi->GetName()),-1,-1);
4800     TH1F * hNeHadPhi = (TH1F*) fhNeHadPhi->ProjectionX(Form("%s_px",fhNeHadPhi->GetName()),-1,-1);
4801     TH1F * hChHadPhi = (TH1F*) fhChHadPhi->ProjectionX(Form("%s_px",fhChHadPhi->GetName()),-1,-1);
4802     haxisphi  = (TH1F*) hPi0Phi->Clone(Form("%s_axisPhi",fhPi0Phi->GetName()));  
4803     haxisphi->SetTitle("Reconstructed particles #phi, function of their original particle ID");
4804     
4805     hPi0Phi->SetLineColor(1);
4806     hGamPhi->SetLineColor(4);
4807     hNeHadPhi->SetLineColor(2);
4808     hChHadPhi->SetLineColor(7);
4809     hElePhi->SetLineColor(6);
4810     //Select the maximum of the histogram to show all lines.
4811     if(hPi0Phi->GetMaximum() >= hGamPhi->GetMaximum() && hPi0Phi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
4812        hPi0Phi->GetMaximum() >= hChHadPhi->GetMaximum() && hPi0Phi->GetMaximum() >= hElePhi->GetMaximum())
4813       haxisphi->SetMaximum(hPi0Phi->GetMaximum());
4814     else if(hGamPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hGamPhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
4815             hGamPhi->GetMaximum() >= hChHadPhi->GetMaximum() && hGamPhi->GetMaximum() >= hElePhi->GetMaximum())
4816       haxisphi->SetMaximum(hGamPhi->GetMaximum());
4817     else if(hNeHadPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hNeHadPhi->GetMaximum() >= hGamPhi->GetMaximum() && 
4818             hNeHadPhi->GetMaximum() >= hChHadPhi->GetMaximum() && hNeHadPhi->GetMaximum() >= hElePhi->GetMaximum())
4819       haxisphi->SetMaximum(hNeHadPhi->GetMaximum());    
4820     else if(hChHadPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hChHadPhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
4821             hChHadPhi->GetMaximum() >= hGamPhi->GetMaximum() && hChHadPhi->GetMaximum() >= hElePhi->GetMaximum())
4822       haxisphi->SetMaximum(hChHadPhi->GetMaximum());
4823     else if(hElePhi->GetMaximum() >= hPi0Phi->GetMaximum() && hElePhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
4824             hElePhi->GetMaximum() >= hChHadPhi->GetMaximum() && hElePhi->GetMaximum() >= hGamPhi->GetMaximum())
4825       haxisphi->SetMaximum(hElePhi->GetMaximum());
4826     haxisphi->SetXTitle("#phi (rad)");
4827     haxisphi->Draw("axis");
4828     hPi0Phi->Draw("same");
4829     hGamPhi->Draw("same");
4830     hNeHadPhi->Draw("same");
4831     hChHadPhi->Draw("same");
4832     hElePhi->Draw("same");
4833     
4834     snprintf(name,buffersize,"QA_%s_RecDistributionsGenID.eps",fCalorimeter.Data());
4835     c11->Print(name); printf("Plot: %s\n",name);
4836     
4837     
4838     //Ratio reconstructed clusters / generated particles in acceptance, for different particle ID
4839     //printf("c1\n");
4840     
4841     TH1F *      hPi0EClone   = (TH1F*)   hPi0E  ->Clone(Form("%s_Clone",fhPi0E->GetName()));
4842     TH1F *      hGamEClone   = (TH1F*)   hGamE  ->Clone(Form("%s_Clone",fhGamE->GetName()));
4843     TH1F *      hPi0PtClone  = (TH1F*)   hPi0Pt ->Clone(Form("%s_Clone",fhPi0Pt->GetName()));
4844     TH1F *      hGamPtClone  = (TH1F*)   hGamPt ->Clone(Form("%s_Clone",fhGamPt->GetName()));   
4845     TH1F *      hPi0EtaClone = (TH1F*)   hPi0Eta->Clone(Form("%s_Clone",fhPi0Eta->GetName()));
4846     TH1F *      hGamEtaClone = (TH1F*)   hGamEta->Clone(Form("%s_Clone",fhGamEta->GetName()));  
4847     TH1F *      hPi0PhiClone = (TH1F*)   hPi0Phi->Clone(Form("%s_Clone",fhPi0Phi->GetName()));
4848     TH1F *      hGamPhiClone = (TH1F*)   hGamPhi->Clone(Form("%s_Clone",fhGamPhi->GetName()));  
4849     
4850     snprintf(cname,buffersize,"QA_%s_recgenidratio",fCalorimeter.Data());
4851     TCanvas  * c12 = new TCanvas(cname, "Ratio reconstructed clusters / generated particles in acceptance, for different particle ID", 400, 400) ;
4852     c12->Divide(2, 2);
4853     
4854     c12->cd(1) ; 
4855     gPad->SetLogy();
4856     haxisE->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
4857     hPi0EClone->Divide(fhGenPi0AccE);
4858     hGamEClone->Divide(fhGenGamAccE);
4859     haxisE->SetMaximum(5);
4860     haxisE->SetMinimum(1e-2);
4861     haxisE->SetXTitle("E (GeV)");
4862     haxisE->SetYTitle("ratio = rec/gen");
4863     haxisE->Draw("axis");
4864     hPi0E->Draw("same");
4865     hGamE->Draw("same");
4866     
4867     TLegend pLegend3(0.75,0.2,0.9,0.4);
4868     pLegend3.SetTextSize(0.06);
4869     pLegend3.AddEntry(hPi0EClone,"  #pi^{0}","L");
4870     pLegend3.AddEntry(hGamEClone,"  #gamma","L");
4871     pLegend3.SetFillColor(10);
4872     pLegend3.SetBorderSize(1);
4873     pLegend3.Draw();
4874     
4875     c12->cd(2) ; 
4876     gPad->SetLogy();
4877     haxispt->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
4878     hPi0PtClone->Divide(fhGenPi0AccPt);
4879     hGamPtClone->Divide(fhGenGamAccPt);
4880     haxispt->SetMaximum(5);
4881     haxispt->SetMinimum(1e-2);
4882     haxispt->SetXTitle("p_{T} (GeV/c)");
4883     haxispt->SetYTitle("ratio = rec/gen");
4884     haxispt->Draw("axis");
4885     hPi0PtClone->Draw("same");
4886     hGamPtClone->Draw("same");
4887     
4888     c12->cd(3) ;
4889     gPad->SetLogy();
4890     
4891     haxiseta->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
4892     hPi0EtaClone->Divide(fhGenPi0AccEta);
4893     hGamEtaClone->Divide(fhGenGamAccEta);
4894     haxiseta->SetMaximum(1.2);
4895     haxiseta->SetMinimum(1e-2);
4896     haxiseta->SetYTitle("ratio = rec/gen");
4897     haxiseta->SetXTitle("#eta");
4898     haxiseta->Draw("axis");
4899     hPi0EtaClone->Draw("same");
4900     hGamEtaClone->Draw("same");
4901     
4902     
4903     c12->cd(4) ; 
4904     gPad->SetLogy();
4905     haxisphi->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
4906     hPi0PhiClone->Divide(fhGenPi0AccPhi);
4907     hGamPhiClone->Divide(fhGenGamAccPhi);
4908     haxisphi->SetYTitle("ratio = rec/gen");
4909     haxisphi->SetXTitle("#phi (rad)");
4910     haxisphi->SetMaximum(1.2);
4911     haxisphi->SetMinimum(1e-2);
4912     haxisphi->Draw("axis");
4913     hPi0PhiClone->Draw("same");
4914     hGamPhiClone->Draw("same");
4915     
4916     snprintf(name,buffersize,"QA_%s_EfficiencyGenID.eps",fCalorimeter.Data());
4917     c12->Print(name); printf("Plot: %s\n",name);
4918     
4919     
4920     
4921     //Reconstructed distributions
4922     //printf("c1\n");
4923     snprintf(cname,buffersize,"QA_%s_vertex",fCalorimeter.Data());
4924     TCanvas  * c13 = new TCanvas(cname, "Particle vertex", 400, 400) ;
4925     c13->Divide(2, 2);
4926     
4927     c13->cd(1) ; 
4928     //gPad->SetLogy();
4929     fhEMVxyz->SetTitleOffset(1.6,"Y");
4930     fhEMVxyz->Draw();
4931     
4932     c13->cd(2) ; 
4933     //gPad->SetLogy();
4934     fhHaVxyz->SetTitleOffset(1.6,"Y");
4935     fhHaVxyz->Draw();
4936     
4937     c13->cd(3) ;
4938     gPad->SetLogy();
4939     TH1F * hEMR = (TH1F*) fhEMR->ProjectionY(Form("%s_py",fhEMR->GetName()),-1,-1); 
4940     hEMR->SetLineColor(4);
4941     hEMR->Draw();
4942     
4943     c13->cd(4) ; 
4944     gPad->SetLogy();
4945     TH1F * hHaR = (TH1F*) fhHaR->ProjectionY(Form("%s_py",fhHaR->GetName()),-1,-1); 
4946     hHaR->SetLineColor(4);
4947     hHaR->Draw();
4948     
4949     
4950     snprintf(name,buffersize,"QA_%s_ParticleVertex.eps",fCalorimeter.Data());
4951     c13->Print(name); printf("Plot: %s\n",name);
4952     
4953     
4954     //Track-matching distributions
4955     if(fFillAllTH12){
4956       //Reconstructed distributions, matched with tracks, generated particle dependence
4957       //printf("c2\n");
4958       snprintf(cname,buffersize,"QA_%s_rectrackmatchGenID",fCalorimeter.Data());
4959       TCanvas  * c22ch = new TCanvas(cname, "Reconstructed distributions, matched with tracks, for different particle ID", 400, 400) ;
4960       c22ch->Divide(2, 2);
4961       
4962       c22ch->cd(1) ; 
4963       
4964       TH1F * hGamECharged   = (TH1F*) fhGamECharged->ProjectionX(Form("%s_px",fhGamECharged->GetName()),-1,-1);
4965       TH1F * hPi0ECharged   = (TH1F*) fhPi0ECharged->ProjectionX(Form("%s_px",fhPi0ECharged->GetName()),-1,-1);
4966       TH1F * hEleECharged   = (TH1F*) fhEleECharged->ProjectionX(Form("%s_px",fhEleECharged->GetName()),-1,-1);
4967       TH1F * hNeHadECharged = (TH1F*) fhNeHadECharged->ProjectionX(Form("%s_px",fhNeHadECharged->GetName()),-1,-1);
4968       TH1F * hChHadECharged = (TH1F*) fhChHadECharged->ProjectionX(Form("%s_px",fhChHadECharged->GetName()),-1,-1);
4969       hPi0ECharged->SetLineColor(1);
4970       hGamECharged->SetLineColor(4);
4971       hNeHadECharged->SetLineColor(2);
4972       hChHadECharged->SetLineColor(7);
4973       hEleECharged->SetLineColor(6);    
4974       gPad->SetLogy();
4975       fhECharged->SetLineColor(3);
4976       fhECharged->SetMinimum(0.5);
4977       fhECharged->Draw();
4978       hPi0ECharged->Draw("same");
4979       hGamECharged->Draw("same");
4980       hNeHadECharged->Draw("same");
4981       hChHadECharged->Draw("same");
4982       hEleECharged->Draw("same");
4983       TLegend pLegend22(0.75,0.45,0.9,0.8);
4984       pLegend22.SetTextSize(0.06);
4985       pLegend22.AddEntry(fhECharged,"all","L");
4986       pLegend22.AddEntry(hPi0ECharged,"#pi^{0}","L");
4987       pLegend22.AddEntry(hGamECharged,"#gamma","L");
4988       pLegend22.AddEntry(hEleECharged,"e^{#pm}","L");
4989       pLegend22.AddEntry(hChHadECharged,"h^{#pm}","L");
4990       pLegend22.AddEntry(hNeHadECharged,"h^{0}","L");
4991       pLegend22.SetFillColor(10);
4992       pLegend22.SetBorderSize(1);
4993       pLegend22.Draw();
4994       
4995       c22ch->cd(2) ; 
4996       
4997       TH1F * hGamPtCharged   = (TH1F*) fhGamPtCharged->ProjectionX(Form("%s_px",fhGamPtCharged->GetName()),-1,-1);
4998       TH1F * hPi0PtCharged   = (TH1F*) fhPi0PtCharged->ProjectionX(Form("%s_px",fhPi0PtCharged->GetName()),-1,-1);
4999       TH1F * hElePtCharged   = (TH1F*) fhElePtCharged->ProjectionX(Form("%s_px",fhElePtCharged->GetName()),-1,-1);
5000       TH1F * hNeHadPtCharged = (TH1F*) fhNeHadPtCharged->ProjectionX(Form("%s_px",fhNeHadPtCharged->GetName()),-1,-1);
5001       TH1F * hChHadPtCharged = (TH1F*) fhChHadPtCharged->ProjectionX(Form("%s_px",fhChHadPtCharged->GetName()),-1,-1);
5002       hPi0PtCharged->SetLineColor(1);
5003       hGamPtCharged->SetLineColor(4);
5004       hNeHadPtCharged->SetLineColor(2);
5005       hChHadPtCharged->SetLineColor(7);
5006       hElePtCharged->SetLineColor(6);   
5007       gPad->SetLogy();
5008       fhPtCharged->SetLineColor(3);
5009       fhPtCharged->SetMinimum(0.5);
5010       fhPtCharged->Draw();
5011       hPi0PtCharged->Draw("same");
5012       hGamPtCharged->Draw("same");
5013       hNeHadPtCharged->Draw("same");
5014       hChHadPtCharged->Draw("same");
5015       hElePtCharged->Draw("same");      
5016       
5017       c22ch->cd(4) ; 
5018       
5019       TH1F * hGamEtaCharged   = (TH1F*) fhGamEtaCharged->ProjectionX(Form("%s_px",fhGamEtaCharged->GetName()),-1,-1);
5020       TH1F * hPi0EtaCharged   = (TH1F*) fhPi0EtaCharged->ProjectionX(Form("%s_px",fhPi0EtaCharged->GetName()),-1,-1);
5021       TH1F * hEleEtaCharged   = (TH1F*) fhEleEtaCharged->ProjectionX(Form("%s_px",fhEleEtaCharged->GetName()),-1,-1);
5022       TH1F * hNeHadEtaCharged = (TH1F*) fhNeHadEtaCharged->ProjectionX(Form("%s_px",fhNeHadEtaCharged->GetName()),-1,-1);
5023       TH1F * hChHadEtaCharged = (TH1F*) fhChHadEtaCharged->ProjectionX(Form("%s_px",fhChHadEtaCharged->GetName()),-1,-1);
5024       hPi0EtaCharged->SetLineColor(1);
5025       hGamEtaCharged->SetLineColor(4);
5026       hNeHadEtaCharged->SetLineColor(2);
5027       hChHadEtaCharged->SetLineColor(7);
5028       hEleEtaCharged->SetLineColor(6);  
5029       gPad->SetLogy();
5030       fhEtaCharged->SetLineColor(3);
5031       fhEtaCharged->SetMinimum(0.5);
5032       fhEtaCharged->Draw();
5033       hPi0EtaCharged->Draw("same");
5034       hGamEtaCharged->Draw("same");
5035       hNeHadEtaCharged->Draw("same");
5036       hChHadEtaCharged->Draw("same");
5037       hEleEtaCharged->Draw("same");
5038       
5039       c22ch->cd(3) ; 
5040       
5041       TH1F * hGamPhiCharged   = (TH1F*) fhGamPhiCharged->ProjectionX(Form("%s_px",fhGamPhiCharged->GetName()),-1,-1);
5042       TH1F * hPi0PhiCharged   = (TH1F*) fhPi0PhiCharged->ProjectionX(Form("%s_px",fhPi0PhiCharged->GetName()),-1,-1);
5043       TH1F * hElePhiCharged   = (TH1F*) fhElePhiCharged->ProjectionX(Form("%s_px",fhElePhiCharged->GetName()),-1,-1);
5044       TH1F * hNeHadPhiCharged = (TH1F*) fhNeHadPhiCharged->ProjectionX(Form("%s_px",fhNeHadPhiCharged->GetName()),-1,-1);
5045       TH1F * hChHadPhiCharged = (TH1F*) fhChHadPhiCharged->ProjectionX(Form("%s_px",fhChHadPhiCharged->GetName()),-1,-1);
5046       hPi0PhiCharged->SetLineColor(1);
5047       hGamPhiCharged->SetLineColor(4);
5048       hNeHadPhiCharged->SetLineColor(2);
5049       hChHadPhiCharged->SetLineColor(7);
5050       hElePhiCharged->SetLineColor(6);  
5051       gPad->SetLogy();
5052       fhPhiCharged->SetLineColor(3);
5053       fhPhiCharged->SetMinimum(0.5);
5054       fhPhiCharged->Draw();
5055       hPi0PhiCharged->Draw("same");
5056       hGamPhiCharged->Draw("same");
5057       hNeHadPhiCharged->Draw("same");
5058       hChHadPhiCharged->Draw("same");
5059       hElePhiCharged->Draw("same");
5060       
5061       
5062       snprintf(name,buffersize,"QA_%s_ReconstructedDistributions_TrackMatchedGenID.eps",fCalorimeter.Data());
5063       c22ch->Print(name); printf("Plot: %s\n",name);
5064       
5065       TH1F *    hGamEChargedClone   = (TH1F*)   hGamECharged->Clone(Form("%s_Clone",fhGamECharged->GetName()));
5066       TH1F *    hGamPtChargedClone  = (TH1F*)   hGamPtCharged->Clone(Form("%s_Clone",fhGamPtCharged->GetName()));
5067       TH1F *    hGamEtaChargedClone = (TH1F*)   hGamEtaCharged->Clone(Form("%s_Clone",fhGamEtaCharged->GetName()));
5068       TH1F *    hGamPhiChargedClone = (TH1F*)   hGamPhiCharged->Clone(Form("%s_Clone",fhGamPhiCharged->GetName()));
5069       
5070       TH1F *    hPi0EChargedClone   = (TH1F*)   hPi0ECharged->Clone(Form("%s_Clone",fhPi0ECharged->GetName()));
5071       TH1F *    hPi0PtChargedClone  = (TH1F*)   hPi0PtCharged->Clone(Form("%s_Clone",fhPi0PtCharged->GetName()));
5072       TH1F *    hPi0EtaChargedClone = (TH1F*)   hPi0EtaCharged->Clone(Form("%s_Clone",fhPi0EtaCharged->GetName()));
5073       TH1F *    hPi0PhiChargedClone = (TH1F*)   hPi0PhiCharged->Clone(Form("%s_Clone",fhPi0PhiCharged->GetName()));
5074       
5075       TH1F *    hEleEChargedClone   = (TH1F*)   hEleECharged->Clone(Form("%s_Clone",fhEleECharged->GetName()));
5076       TH1F *    hElePtChargedClone  = (TH1F*)   hElePtCharged->Clone(Form("%s_Clone",fhElePtCharged->GetName()));
5077       TH1F *    hEleEtaChargedClone = (TH1F*)   hEleEtaCharged->Clone(Form("%s_Clone",fhEleEtaCharged->GetName()));
5078       TH1F *    hElePhiChargedClone = (TH1F*)   hElePhiCharged->Clone(Form("%s_Clone",fhElePhiCharged->GetName()));     
5079       
5080       TH1F *    hNeHadEChargedClone   = (TH1F*)   hNeHadECharged->Clone(Form("%s_Clone",fhNeHadECharged->GetName()));
5081       TH1F *    hNeHadPtChargedClone  = (TH1F*)   hNeHadPtCharged->Clone(Form("%s_Clone",fhNeHadPtCharged->GetName()));
5082       TH1F *    hNeHadEtaChargedClone = (TH1F*)   hNeHadEtaCharged->Clone(Form("%s_Clone",fhNeHadEtaCharged->GetName()));
5083       TH1F *    hNeHadPhiChargedClone = (TH1F*)   hNeHadPhiCharged->Clone(Form("%s_Clone",fhNeHadPhiCharged->GetName()));
5084       
5085       TH1F *    hChHadEChargedClone   = (TH1F*)   hChHadECharged->Clone(Form("%s_Clone",fhChHadECharged->GetName()));
5086       TH1F *    hChHadPtChargedClone  = (TH1F*)   hChHadPtCharged->Clone(Form("%s_Clone",fhChHadPtCharged->GetName()));
5087       TH1F *    hChHadEtaChargedClone = (TH1F*)   hChHadEtaCharged->Clone(Form("%s_Clone",fhChHadEtaCharged->GetName()));
5088       TH1F *    hChHadPhiChargedClone = (TH1F*)   hChHadPhiCharged->Clone(Form("%s_Clone",fhChHadPhiCharged->GetName()));       
5089       
5090       //Ratio: reconstructed track matched/ all reconstructed
5091       //printf("c3\n");
5092       snprintf(cname,buffersize,"QA_%s_rectrackmatchratGenID",fCalorimeter.Data());
5093       TCanvas  * c3ch = new TCanvas(cname, "Ratio: reconstructed track matched/ all reconstructed, for different particle ID", 400, 400) ;
5094       c3ch->Divide(2, 2);
5095       
5096       c3ch->cd(1) ;
5097       hEChargedClone->SetMaximum(1.2);
5098       hEChargedClone->SetMinimum(0.001);        
5099       hEChargedClone->SetLineColor(3);
5100       hEChargedClone->SetYTitle("track matched / all");
5101       hPi0EChargedClone->Divide(hPi0E);
5102       hGamEChargedClone->Divide(hGamE);
5103       hEleEChargedClone->Divide(hEleE);
5104       hNeHadEChargedClone->Divide(hNeHadE);
5105       hChHadEChargedClone->Divide(hChHadE);
5106       hEChargedClone->Draw();
5107       hPi0EChargedClone->Draw("same");
5108       hGamEChargedClone->Draw("same");
5109       hEleEChargedClone->Draw("same");
5110       hNeHadEChargedClone->Draw("same");
5111       hChHadEChargedClone->Draw("same");
5112       
5113       TLegend pLegend3ch(0.75,0.45,0.9,0.8);
5114       pLegend3ch.SetTextSize(0.06);
5115       pLegend3ch.AddEntry(hEChargedClone,"all","L");
5116       pLegend3ch.AddEntry(hPi0EChargedClone,"#pi^{0}","L");
5117       pLegend3ch.AddEntry(hGamEChargedClone,"#gamma","L");
5118       pLegend3ch.AddEntry(hEleEChargedClone,"e^{#pm}","L");
5119       pLegend3ch.AddEntry(hChHadEChargedClone,"h^{#pm}","L");
5120       pLegend3ch.AddEntry(hNeHadEChargedClone,"h^{0}","L");
5121       pLegend3ch.SetFillColor(10);
5122       pLegend3ch.SetBorderSize(1);
5123       pLegend3ch.Draw();
5124       
5125       c3ch->cd(2) ;
5126       hPtChargedClone->SetMaximum(1.2);
5127       hPtChargedClone->SetMinimum(0.001);       
5128       hPtChargedClone->SetLineColor(3);
5129       hPtChargedClone->SetYTitle("track matched / all");
5130       hPi0PtChargedClone->Divide(hPi0Pt);
5131       hGamPtChargedClone->Divide(hGamPt);
5132       hElePtChargedClone->Divide(hElePt);
5133       hNeHadPtChargedClone->Divide(hNeHadPt);
5134       hChHadPtChargedClone->Divide(hChHadPt);
5135       hPtChargedClone->Draw();
5136       hPi0PtChargedClone->Draw("same");
5137       hGamPtChargedClone->Draw("same");
5138       hElePtChargedClone->Draw("same");
5139       hNeHadPtChargedClone->Draw("same");
5140       hChHadPtChargedClone->Draw("same");
5141       
5142       c3ch->cd(4) ;
5143       hEtaChargedClone->SetMaximum(1.2);
5144       hEtaChargedClone->SetMinimum(0.001);      
5145       hEtaChargedClone->SetLineColor(3);
5146       hEtaChargedClone->SetYTitle("track matched / all");
5147       hPi0EtaChargedClone->Divide(hPi0Eta);
5148       hGamEtaChargedClone->Divide(hGamEta);
5149       hEleEtaChargedClone->Divide(hEleEta);
5150       hNeHadEtaChargedClone->Divide(hNeHadEta);
5151       hChHadEtaChargedClone->Divide(hChHadEta);
5152       hEtaChargedClone->Draw();
5153       hPi0EtaChargedClone->Draw("same");
5154       hGamEtaChargedClone->Draw("same");
5155       hEleEtaChargedClone->Draw("same");
5156       hNeHadEtaChargedClone->Draw("same");
5157       hChHadEtaChargedClone->Draw("same");
5158       
5159       c3ch->cd(3) ;
5160       hPhiChargedClone->SetMaximum(1.2);
5161       hPhiChargedClone->SetMinimum(0.001);
5162       hPhiChargedClone->SetLineColor(3);
5163       hPhiChargedClone->SetYTitle("track matched / all");
5164       hPi0PhiChargedClone->Divide(hPi0Phi);
5165       hGamPhiChargedClone->Divide(hGamPhi);
5166       hElePhiChargedClone->Divide(hElePhi);
5167       hNeHadPhiChargedClone->Divide(hNeHadPhi);
5168       hChHadPhiChargedClone->Divide(hChHadPhi);
5169       hPhiChargedClone->Draw();
5170       hPi0PhiChargedClone->Draw("same");
5171       hGamPhiChargedClone->Draw("same");
5172       hElePhiChargedClone->Draw("same");
5173       hNeHadPhiChargedClone->Draw("same");
5174       hChHadPhiChargedClone->Draw("same");
5175       
5176       snprintf(name,buffersize,"QA_%s_RatioReconstructedMatchedDistributionsGenID.eps",fCalorimeter.Data());
5177       c3ch->Print(name); printf("Plot: %s\n",name);
5178       
5179     }   
5180   }
5181   //Track-matching distributions
5182   
5183         snprintf(cname,buffersize,"QA_%s_trkmatch",fCalorimeter.Data());
5184         TCanvas *cme = new TCanvas(cname,"Track-matching distributions", 400, 400);
5185         cme->Divide(2,2);
5186   
5187         TLegend pLegendpE0(0.6,0.55,0.9,0.8);
5188         pLegendpE0.SetTextSize(0.04);
5189         pLegendpE0.AddEntry(fh1pOverE,"all","L");
5190         pLegendpE0.AddEntry(fh1pOverER02,"dR < 0.02","L");              
5191         pLegendpE0.SetFillColor(10);
5192         pLegendpE0.SetBorderSize(1);
5193   //pLegendpE0.Draw();
5194   
5195         cme->cd(1);
5196         if(fh1pOverE->GetEntries() > 0) gPad->SetLogy();
5197         fh1pOverE->SetTitle("Track matches p/E");
5198         fh1pOverE->Draw();
5199         fh1pOverER02->SetLineColor(4);
5200         fh1pOverER02->Draw("same");
5201         pLegendpE0.Draw();
5202   
5203         cme->cd(2);
5204         if(fh1dR->GetEntries() > 0) gPad->SetLogy();
5205         fh1dR->Draw();
5206         
5207         cme->cd(3);
5208         fh2MatchdEdx->Draw();
5209         
5210         cme->cd(4);
5211         fh2EledEdx->Draw();
5212         
5213         snprintf(name,buffersize,"QA_%s_TrackMatchingEleDist.eps",fCalorimeter.Data());
5214         cme->Print(name); printf("Plot: %s\n",name);       
5215         
5216         if(IsDataMC()){
5217     snprintf(cname,buffersize,"QA_%s_trkmatchMCEle",fCalorimeter.Data());
5218     TCanvas *cmemc = new TCanvas(cname,"Track-matching distributions from MC electrons", 600, 200);
5219     cmemc->Divide(3,1);
5220     
5221     cmemc->cd(1);
5222     gPad->SetLogy();
5223     fhMCEle1pOverE->Draw();
5224     fhMCEle1pOverER02->SetLineColor(4);
5225     fhMCEle1pOverE->SetLineColor(1);
5226     fhMCEle1pOverER02->Draw("same");
5227     pLegendpE0.Draw();
5228                 
5229     cmemc->cd(2);
5230     gPad->SetLogy();
5231     fhMCEle1dR->Draw();
5232                 
5233     cmemc->cd(3);
5234     fhMCEle2MatchdEdx->Draw();
5235                 
5236     snprintf(name,buffersize,"QA_%s_TrackMatchingDistMCEle.eps",fCalorimeter.Data());
5237     cmemc->Print(name); printf("Plot: %s\n",name);  
5238     
5239                 
5240     snprintf(cname,buffersize,"QA_%s_trkmatchMCChHad",fCalorimeter.Data());
5241     TCanvas *cmemchad = new TCanvas(cname,"Track-matching distributions from MC charged hadrons", 600, 200);
5242     cmemchad->Divide(3,1);
5243                 
5244     cmemchad->cd(1);
5245     gPad->SetLogy();
5246     fhMCChHad1pOverE->Draw();
5247     fhMCChHad1pOverER02->SetLineColor(4);
5248     fhMCChHad1pOverE->SetLineColor(1);
5249     fhMCChHad1pOverER02->Draw("same");
5250     pLegendpE0.Draw();
5251                 
5252     cmemchad->cd(2);
5253     gPad->SetLogy();
5254     fhMCChHad1dR->Draw();
5255     
5256     cmemchad->cd(3);
5257     fhMCChHad2MatchdEdx->Draw();
5258                 
5259     snprintf(name,buffersize,"QA_%s_TrackMatchingDistMCChHad.eps",fCalorimeter.Data());
5260     cmemchad->Print(name); printf("Plot: %s\n",name);       
5261     
5262     snprintf(cname,buffersize,"QA_%s_trkmatchMCNeutral",fCalorimeter.Data());
5263     TCanvas *cmemcn = new TCanvas(cname,"Track-matching distributions from MC neutrals", 600, 200);
5264     cmemcn->Divide(3,1);
5265                 
5266     cmemcn->cd(1);
5267     gPad->SetLogy();
5268     fhMCNeutral1pOverE->Draw();
5269     fhMCNeutral1pOverE->SetLineColor(1);
5270     fhMCNeutral1pOverER02->SetLineColor(4);
5271     fhMCNeutral1pOverER02->Draw("same");
5272     pLegendpE0.Draw();
5273                 
5274     cmemcn->cd(2);
5275     gPad->SetLogy();
5276     fhMCNeutral1dR->Draw();
5277                 
5278     cmemcn->cd(3);
5279     fhMCNeutral2MatchdEdx->Draw();
5280                 
5281     snprintf(name,buffersize,"QA_%s_TrackMatchingDistMCNeutral.eps",fCalorimeter.Data());
5282     cmemcn->Print(name); printf("Plot: %s\n",name);       
5283     
5284     snprintf(cname,buffersize,"QA_%s_trkmatchpE",fCalorimeter.Data());
5285     TCanvas *cmpoe = new TCanvas(cname,"Track-matching distributions, p/E", 400, 200);
5286     cmpoe->Divide(2,1);
5287                 
5288     cmpoe->cd(1);
5289     gPad->SetLogy();
5290     fh1pOverE->SetLineColor(1);
5291     fhMCEle1pOverE->SetLineColor(4);
5292     fhMCChHad1pOverE->SetLineColor(2);
5293     fhMCNeutral1pOverE->SetLineColor(7);
5294     fh1pOverER02->SetMinimum(0.5);
5295     fh1pOverE->Draw();
5296     fhMCEle1pOverE->Draw("same");
5297     fhMCChHad1pOverE->Draw("same");
5298     fhMCNeutral1pOverE->Draw("same");
5299     TLegend pLegendpE(0.65,0.55,0.9,0.8);
5300     pLegendpE.SetTextSize(0.06);
5301     pLegendpE.AddEntry(fh1pOverE,"all","L");
5302     pLegendpE.AddEntry(fhMCEle1pOverE,"e^{#pm}","L");
5303     pLegendpE.AddEntry(fhMCChHad1pOverE,"h^{#pm}","L");
5304     pLegendpE.AddEntry(fhMCNeutral1pOverE,"neutrals","L");
5305     pLegendpE.SetFillColor(10);
5306     pLegendpE.SetBorderSize(1);
5307     pLegendpE.Draw();
5308     
5309     cmpoe->cd(2);
5310     gPad->SetLogy();
5311     fh1pOverER02->SetTitle("Track matches p/E, dR<0.2");
5312     fh1pOverER02->SetLineColor(1);
5313     fhMCEle1pOverER02->SetLineColor(4);
5314     fhMCChHad1pOverER02->SetLineColor(2);
5315     fhMCNeutral1pOverER02->SetLineColor(7);
5316     fh1pOverER02->SetMaximum(fh1pOverE->GetMaximum());
5317     fh1pOverER02->SetMinimum(0.5);
5318     fh1pOverER02->Draw();
5319     fhMCEle1pOverER02->Draw("same");
5320     fhMCChHad1pOverER02->Draw("same");
5321     fhMCNeutral1pOverER02->Draw("same");
5322     
5323     //          TLegend pLegendpE2(0.65,0.55,0.9,0.8);
5324     //          pLegendpE2.SetTextSize(0.06);
5325     //          pLegendpE2.SetHeader("dR < 0.02");
5326     //          pLegendpE2.SetFillColor(10);
5327     //          pLegendpE2.SetBorderSize(1);
5328     //          pLegendpE2.Draw();
5329     
5330     snprintf(name,buffersize,"QA_%s_TrackMatchingPOverE.eps",fCalorimeter.Data());
5331     cmpoe->Print(name); printf("Plot: %s\n",name);                              
5332         }
5333         
5334         char line[buffersize] ; 
5335         snprintf(line, buffersize,".!tar -zcf QA_%s_%s.tar.gz *%s*.eps", fCalorimeter.Data(), GetName(),fCalorimeter.Data()) ; 
5336         gROOT->ProcessLine(line);
5337         snprintf(line, buffersize,".!rm -fR *.eps"); 
5338         gROOT->ProcessLine(line);
5339         
5340         printf("AliAnaCalorimeterQA::Terminate() - !! All the eps files are in QA_%s_%s.tar.gz !!!\n",  fCalorimeter.Data(), GetName());
5341         
5342 }