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