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