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