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