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