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