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