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