]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrDep/AliAnaCalorimeterQA.cxx
5dd2b7cb6b56c968c9492d690eb307d5a194d408
[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), 
63         fHistoPOverEBins(100),     fHistoPOverEMax(100.),     fHistoPOverEMin(0.),
64         fHistodEdxBins(100),       fHistodEdxMax(100.),       fHistodEdxMin(0.),
65         fHistodRBins(100),         fHistodRMax(100.),         fHistodRMin(0.),
66         fHistoTimeBins(100),       fHistoTimeMax(100.),       fHistoTimeMin(0.),
67         fHistoNBins(100),          fHistoNMax(100),           fHistoNMin(0),
68         fHistoRatioBins(100),      fHistoRatioMax(100.),      fHistoRatioMin(0.),
69         fHistoVertexDistBins(100), fHistoVertexDistMax(100.), fHistoVertexDistMin(0.),
70         fhE(0),fhPt(0),fhPhi(0),fhEta(0), fhEtaPhi(0),  fhEtaPhiE(0),
71     fhECharged(0),fhPtCharged(0),fhPhiCharged(0),fhEtaCharged(0), fhEtaPhiCharged(0), 
72     fhEChargedNoOut(0),fhPtChargedNoOut(0),fhPhiChargedNoOut(0),fhEtaChargedNoOut(0), fhEtaPhiChargedNoOut(0), 
73     fhDeltaE(0), fhDeltaPt(0),fhDeltaPhi(0),fhDeltaEta(0), fhRatioE(0), fhRatioPt(0),fhRatioPhi(0),fhRatioEta(0),
74     fh2E(0),fh2Pt(0),fh2Phi(0),fh2Eta(0), fhIM(0), fhIMCellCut(0),fhAsym(0), 
75         fhNCellsPerCluster(0),fhNCellsPerClusterMIP(0), fhNClusters(0), fhNCells(0), 
76         fhAmplitude(0), fhAmpId(0), fhTime(0), fhTimeId(0), fhTimeAmp(0),
77     fhCaloCorrNClusters(0), fhCaloCorrEClusters(0), fhCaloCorrNCells(0), fhCaloCorrECells(0),
78     fhEMod(0),fhNClustersMod(0), fhNCellsPerClusterMod(0), fhNCellsMod(0),  
79     fhGridCellsMod(0),  fhGridCellsEMod(0), fhAmplitudeMod(0), fhIMMod(0),  fhIMCellCutMod(0),
80     fhGenGamPt(0),fhGenGamEta(0),fhGenGamPhi(0),fhGenPi0Pt(0),fhGenPi0Eta(0),fhGenPi0Phi(0),
81     fhGenEtaPt(0),fhGenEtaEta(0),fhGenEtaPhi(0),fhGenOmegaPt(0),fhGenOmegaEta(0),fhGenOmegaPhi(0),
82     fhGenElePt(0),fhGenEleEta(0),fhGenElePhi(0), fhEMVxyz(0),  fhEMR(0), fhHaVxyz(0),  fhHaR(0),
83     fhGamE(0),fhGamPt(0),fhGamPhi(0),fhGamEta(0), 
84     fhGamDeltaE(0), fhGamDeltaPt(0),fhGamDeltaPhi(0),fhGamDeltaEta(0), fhGamRatioE(0), fhGamRatioPt(0),fhGamRatioPhi(0),fhGamRatioEta(0),
85     fhEleE(0),fhElePt(0),fhElePhi(0),fhEleEta(0),
86     fhPi0E(0),fhPi0Pt(0),fhPi0Phi(0),fhPi0Eta(0), fhNeHadE(0),fhNeHadPt(0),fhNeHadPhi(0),fhNeHadEta(0), 
87     fhChHadE(0),fhChHadPt(0),fhChHadPhi(0),fhChHadEta(0),
88     fhGamECharged(0),fhGamPtCharged(0),fhGamPhiCharged(0),fhGamEtaCharged(0), 
89     fhEleECharged(0),fhElePtCharged(0),fhElePhiCharged(0),fhEleEtaCharged(0),
90     fhPi0ECharged(0),fhPi0PtCharged(0),fhPi0PhiCharged(0),fhPi0EtaCharged(0), 
91     fhNeHadECharged(0),fhNeHadPtCharged(0),fhNeHadPhiCharged(0),fhNeHadEtaCharged(0), 
92     fhChHadECharged(0),fhChHadPtCharged(0),fhChHadPhiCharged(0),fhChHadEtaCharged(0),
93     fhGenGamAccE(0),fhGenGamAccPt(0),fhGenGamAccEta(0),fhGenGamAccPhi(0),
94     fhGenPi0AccE(0),fhGenPi0AccPt(0),fhGenPi0AccEta(0),fhGenPi0AccPhi(0),
95     fh1pOverE(0),fh1dR(0),fh2EledEdx(0), fh2MatchdEdx(0),fhMCEle1pOverE(0),fhMCEle1dR(0),fhMCEle2MatchdEdx(0),
96     fhMCChHad1pOverE(0),fhMCChHad1dR(0),fhMCChHad2MatchdEdx(0),fhMCNeutral1pOverE(0),fhMCNeutral1dR(0),fhMCNeutral2MatchdEdx(0),
97     fh1pOverER02(0), fhMCEle1pOverER02(0), fhMCChHad1pOverER02(0), fhMCNeutral1pOverER02(0)
98 {
99   //Default Ctor
100   
101   //Initialize parameters
102   InitParameters();
103 }
104
105 //____________________________________________________________________________
106 AliAnaCalorimeterQA::AliAnaCalorimeterQA(const AliAnaCalorimeterQA & qa) :   
107   AliAnaPartCorrBaseClass(qa), fCalorimeter(qa.fCalorimeter), fStyleMacro(qa.fStyleMacro), 
108   fMakePlots(qa.fMakePlots), fCorrelateCalos(qa.fCorrelateCalos), fNModules(qa.fNModules),
109   fHistoPOverEBins(qa.fHistoPOverEBins), fHistoPOverEMax(qa.fHistoPOverEMax), fHistoPOverEMin(qa.fHistoPOverEMin),
110   fHistodEdxBins(qa.fHistodEdxBins), fHistodEdxMax(qa.fHistodEdxMax), fHistodEdxMin(qa.fHistodEdxMin), 
111   fHistodRBins(qa.fHistodRBins), fHistodRMax(qa.fHistodRMax), fHistodRMin(qa.fHistodRMin),
112   fHistoTimeBins(qa.fHistoTimeBins), fHistoTimeMax(qa.fHistoTimeMax), fHistoTimeMin(qa.fHistoTimeMin),
113   fHistoNBins(qa.fHistoNBins), fHistoNMax(qa.fHistoNMax), fHistoNMin(qa.fHistoNMin),
114   fHistoRatioBins(qa.fHistoRatioBins), fHistoRatioMax(qa.fHistoRatioMax), fHistoRatioMin(qa.fHistoRatioMin),
115   fHistoVertexDistBins(qa.fHistoVertexDistBins), fHistoVertexDistMax(qa.fHistoVertexDistMax), fHistoVertexDistMin(qa.fHistoVertexDistMin),
116   fhE(qa.fhE),fhPt(qa.fhPt), fhPhi(qa.fhPhi), fhEta(qa.fhEta), 
117   fhEtaPhi(qa.fhEtaPhi),  fhEtaPhiE(qa.fhEtaPhiE), fhECharged(qa.fhECharged),fhPtCharged(qa.fhPtCharged),fhPhiCharged(qa.fhPhiCharged),
118   fhEtaCharged(qa.fhEtaCharged), fhEtaPhiCharged(qa.fhEtaPhiCharged), 
119   fhEChargedNoOut(qa.fhEChargedNoOut),fhPtChargedNoOut(qa.fhPtChargedNoOut),fhPhiChargedNoOut(qa.fhPhiChargedNoOut),
120   fhEtaChargedNoOut(qa.fhEtaChargedNoOut), fhEtaPhiChargedNoOut(qa.fhEtaPhiChargedNoOut), 
121   fhDeltaE(qa.fhDeltaE), fhDeltaPt(qa.fhDeltaPt), fhDeltaPhi(qa.fhDeltaPhi), fhDeltaEta(qa.fhDeltaEta),
122   fhRatioE(qa.fhRatioE), fhRatioPt(qa.fhRatioPt), fhRatioPhi(qa.fhRatioPhi), fhRatioEta(qa.fhRatioEta),
123   fh2E(qa.fh2E), fh2Pt(qa.fh2Pt), fh2Phi(qa.fh2Phi),fh2Eta(qa.fh2Eta), 
124   fhIM(qa.fhIM), fhIMCellCut(qa.fhIMCellCut), fhAsym(qa.fhAsym), 
125   fhNCellsPerCluster(qa.fhNCellsPerCluster), fhNCellsPerClusterMIP(qa.fhNCellsPerClusterMIP),
126   fhNClusters(qa.fhNClusters), fhNCells(qa.fhNCells), fhAmplitude(qa.fhAmplitude), fhAmpId(fhAmpId),
127   fhTime(qa.fhTime), fhTimeId(qa.fhTimeId),fhTimeAmp(qa.fhTimeAmp),
128   fhCaloCorrNClusters(qa.fhCaloCorrNClusters), fhCaloCorrEClusters(qa.fhCaloCorrEClusters),
129   fhCaloCorrNCells(qa.fhCaloCorrNCells), fhCaloCorrECells(qa.fhCaloCorrECells),
130   fhEMod(qa.fhEMod),fhNClustersMod(qa.fhNClustersMod), fhNCellsPerClusterMod(qa.fhNCellsPerClusterMod), fhNCellsMod(qa.fhNCellsMod),  
131   fhGridCellsMod(qa.fhGridCellsMod),  fhGridCellsEMod(qa.fhGridCellsEMod), fhAmplitudeMod(qa.fhAmplitudeMod), 
132   fhIMMod(qa.fhIMMod),fhIMCellCutMod(qa.fhIMCellCutMod),
133   fhGenGamPt(qa.fhGenGamPt), fhGenGamEta(qa.fhGenGamEta), fhGenGamPhi(qa.fhGenGamPhi),
134   fhGenPi0Pt(qa.fhGenPi0Pt), fhGenPi0Eta(qa.fhGenPi0Eta), fhGenPi0Phi(qa.fhGenPi0Phi),
135   fhGenEtaPt(qa.fhGenEtaPt), fhGenEtaEta(qa.fhGenEtaEta), fhGenEtaPhi(qa.fhGenEtaPhi),
136   fhGenOmegaPt(qa.fhGenOmegaPt), fhGenOmegaEta(qa.fhGenOmegaEta), fhGenOmegaPhi(qa.fhGenOmegaPhi),
137   fhGenElePt(qa.fhGenElePt), fhGenEleEta(qa.fhGenEleEta), fhGenElePhi(qa.fhGenElePhi), 
138   fhEMVxyz(qa.fhEMVxyz),  fhEMR(qa.fhEMR), fhHaVxyz(qa.fhHaVxyz),  fhHaR(qa.fhHaR),
139   fhGamE(qa.fhGamE),fhGamPt(qa.fhGamPt),fhGamPhi(qa.fhGamPhi),fhGamEta(qa.fhGamEta), 
140   fhGamDeltaE(qa.fhGamDeltaE), fhGamDeltaPt(qa.fhGamDeltaPt), fhGamDeltaPhi(qa.fhGamDeltaPhi), fhGamDeltaEta(qa.fhGamDeltaEta),
141   fhGamRatioE(qa.fhGamRatioE), fhGamRatioPt(qa.fhGamRatioPt), fhGamRatioPhi(qa.fhGamRatioPhi), fhGamRatioEta(qa.fhGamRatioEta),
142   fhEleE(qa.fhEleE),fhElePt(qa.fhElePt),fhElePhi(qa.fhElePhi),fhEleEta(qa.fhEleEta),
143   fhPi0E(qa.fhPi0E),fhPi0Pt(qa.fhPi0Pt),fhPi0Phi(qa.fhPi0Phi),fhPi0Eta(qa.fhPi0Eta), 
144   fhNeHadE(qa.fhNeHadE),fhNeHadPt(qa.fhNeHadPt),fhNeHadPhi(qa.fhNeHadPhi),fhNeHadEta(qa.fhNeHadEta), 
145   fhChHadE(qa.fhChHadE),fhChHadPt(qa.fhChHadPt),fhChHadPhi(qa.fhChHadPhi),fhChHadEta(qa.fhChHadEta),
146   fhGamECharged(qa.fhGamECharged),fhGamPtCharged(qa.fhGamPtCharged),fhGamPhiCharged(qa.fhGamPhiCharged),fhGamEtaCharged(qa.fhGamEtaCharged), 
147   fhEleECharged(qa.fhEleECharged),fhElePtCharged(qa.fhElePtCharged),fhElePhiCharged(qa.fhElePhiCharged),fhEleEtaCharged(qa.fhEleEtaCharged),
148   fhPi0ECharged(qa.fhPi0ECharged),fhPi0PtCharged(qa.fhPi0PtCharged),fhPi0PhiCharged(qa.fhPi0PhiCharged),fhPi0EtaCharged(qa.fhPi0EtaCharged), 
149   fhNeHadECharged(qa.fhNeHadECharged),fhNeHadPtCharged(qa.fhNeHadPtCharged),fhNeHadPhiCharged(qa.fhNeHadPhiCharged),fhNeHadEtaCharged(qa.fhNeHadEtaCharged), 
150   fhChHadECharged(qa.fhChHadECharged),fhChHadPtCharged(qa.fhChHadPtCharged),fhChHadPhiCharged(qa.fhChHadPhiCharged),fhChHadEtaCharged(qa.fhChHadEtaCharged),
151   fhGenGamAccE(qa.fhGenGamAccE),fhGenGamAccPt(qa.fhGenGamAccPt),fhGenGamAccEta(qa.fhGenGamAccEta),fhGenGamAccPhi(qa.fhGenGamAccPhi),
152   fhGenPi0AccE(qa.fhGenPi0AccE),fhGenPi0AccPt(qa.fhGenPi0AccPt),fhGenPi0AccEta(qa.fhGenPi0AccEta),fhGenPi0AccPhi(qa.fhGenPi0AccPhi),
153   fh1pOverE(qa.fh1pOverE),fh1dR(qa.fh1dR),fh2EledEdx(qa.fh2EledEdx), fh2MatchdEdx(qa.fh2MatchdEdx),
154   fhMCEle1pOverE(qa.fhMCEle1pOverE),fhMCEle1dR(qa.fhMCEle1dR), fhMCEle2MatchdEdx(qa.fhMCEle2MatchdEdx),
155   fhMCChHad1pOverE(qa.fhMCChHad1pOverE),fhMCChHad1dR(qa.fhMCChHad1dR), fhMCChHad2MatchdEdx(qa.fhMCChHad2MatchdEdx),
156   fhMCNeutral1pOverE(qa.fhMCNeutral1pOverE),fhMCNeutral1dR(qa.fhMCNeutral1dR), fhMCNeutral2MatchdEdx(qa.fhMCNeutral2MatchdEdx),
157   fh1pOverER02(qa.fh1pOverER02), fhMCEle1pOverER02(qa.fhMCEle1pOverER02),fhMCChHad1pOverER02(qa.fhMCChHad1pOverER02), fhMCNeutral1pOverER02(qa.fhMCNeutral1pOverER02)
158 {
159   // cpy ctor
160   
161 }
162
163 //_________________________________________________________________________
164 AliAnaCalorimeterQA & AliAnaCalorimeterQA::operator = (const AliAnaCalorimeterQA & qa)
165 {
166   // assignment operator
167
168   if(this == &qa)return *this;
169   ((AliAnaPartCorrBaseClass *)this)->operator=(qa);
170
171   fCalorimeter     = qa.fCalorimeter;
172   fStyleMacro      = qa.fStyleMacro;    
173   fMakePlots       = qa.fMakePlots;
174   fCorrelateCalos  = qa.fCorrelateCalos;
175   fNModules        = qa.fNModules; 
176         
177   fHistoPOverEBins = qa.fHistoPOverEBins;  fHistoPOverEMax = qa.fHistoPOverEMax;  fHistoPOverEMin = qa.fHistoPOverEMin; 
178   fHistodEdxBins = qa.fHistodEdxBins;  fHistodEdxMax = qa.fHistodEdxMax;  fHistodEdxMin = qa.fHistodEdxMin;  
179   fHistodRBins = qa.fHistodRBins;  fHistodRMax = qa.fHistodRMax;  fHistodRMin = qa.fHistodRMin; 
180   fHistoTimeBins = qa.fHistoTimeBins;  fHistoTimeMax = qa.fHistoTimeMax;  fHistoTimeMin = qa.fHistoTimeMin; 
181   fHistoNBins = qa.fHistoNBins;  fHistoNMax = qa.fHistoNMax;  fHistoNMin = qa.fHistoNMin;  
182   fHistoRatioBins = qa.fHistoRatioBins;  fHistoRatioMax = qa.fHistoRatioMax;  fHistoRatioMin = qa.fHistoRatioMin; 
183   fHistoVertexDistBins = qa.fHistoVertexDistBins;  fHistoVertexDistMax = qa.fHistoVertexDistMax;  fHistoVertexDistMin = qa.fHistoVertexDistMin; 
184         
185   fhE      = qa.fhE;
186   fhPt     = qa.fhPt;
187   fhPhi    = qa.fhPhi;
188   fhEta    = qa.fhEta;
189   fhEtaPhi = qa.fhEtaPhi;
190   fhEtaPhiE= qa.fhEtaPhiE;
191         
192   fhECharged      = qa.fhECharged;
193   fhPtCharged     = qa.fhPtCharged;
194   fhPhiCharged    = qa.fhPhiCharged;
195   fhEtaCharged    = qa.fhEtaCharged;
196   fhEtaPhiCharged = qa.fhEtaPhiCharged;
197
198   fhEChargedNoOut      = qa.fhEChargedNoOut;
199   fhPtChargedNoOut     = qa.fhPtChargedNoOut;
200   fhPhiChargedNoOut    = qa.fhPhiChargedNoOut;
201   fhEtaChargedNoOut    = qa.fhEtaChargedNoOut;
202   fhEtaPhiChargedNoOut = qa.fhEtaPhiChargedNoOut;
203         
204   fhIM   = qa.fhIM;   fhIMCellCut   = qa.fhIMCellCut;
205   fhAsym = qa.fhAsym;
206         
207   fhNCellsPerCluster    = qa.fhNCellsPerCluster;
208   fhNCellsPerClusterMIP = qa.fhNCellsPerClusterMIP;
209   fhNClusters           = qa.fhNClusters;
210         
211   fhDeltaE   = qa.fhDeltaE;     
212   fhDeltaPt  = qa.fhDeltaPt;
213   fhDeltaPhi = qa.fhDeltaPhi;
214   fhDeltaEta = qa.fhDeltaEta;
215         
216   fhRatioE   = qa.fhRatioE;     
217   fhRatioPt  = qa.fhRatioPt;
218   fhRatioPhi = qa.fhRatioPhi;
219   fhRatioEta = qa.fhRatioEta;
220         
221         
222   fh2E   = qa.fh2E;     
223   fh2Pt  = qa.fh2Pt;
224   fh2Phi = qa.fh2Phi;
225   fh2Eta = qa.fh2Eta;
226         
227   fhNCells    = qa.fhNCells;
228   fhAmplitude = qa.fhAmplitude;
229   fhAmpId     = qa.fhAmpId;
230   fhTime      = qa.fhTime;
231   fhTimeId    = qa.fhTimeId;
232   fhTimeAmp   = qa.fhTimeAmp;
233
234   fhCaloCorrNClusters = qa.fhCaloCorrNClusters; fhCaloCorrEClusters = qa.fhCaloCorrEClusters;
235   fhCaloCorrNCells = qa.fhCaloCorrNCells;  fhCaloCorrECells = qa.fhCaloCorrECells;
236         
237   fhEMod = qa.fhEMod; fhNClustersMod = qa.fhNClustersMod; 
238   fhNCellsPerClusterMod = qa.fhNCellsPerClusterMod; fhNCellsMod = qa.fhNCellsMod;  
239   fhGridCellsMod = qa.fhGridCellsMod;  fhGridCellsEMod = qa.fhGridCellsEMod; 
240   fhAmplitudeMod = qa.fhAmplitudeMod; fhIMMod=qa.fhIMMod; fhIMCellCutMod=qa.fhIMCellCutMod;
241         
242   fhGenGamPt = qa.fhGenGamPt  ; fhGenGamEta = qa.fhGenGamEta  ; fhGenGamPhi = qa.fhGenGamPhi  ;
243   fhGenPi0Pt = qa.fhGenPi0Pt  ; fhGenPi0Eta = qa.fhGenPi0Eta  ; fhGenPi0Phi = qa.fhGenPi0Phi  ;
244   fhGenEtaPt = qa.fhGenEtaPt  ; fhGenEtaEta = qa.fhGenEtaEta  ; fhGenEtaPhi = qa.fhGenEtaPhi  ;
245   fhGenOmegaPt = qa.fhGenOmegaPt  ; fhGenOmegaEta = qa.fhGenOmegaEta  ; fhGenOmegaPhi = qa.fhGenOmegaPhi  ;
246   fhGenElePt = qa.fhGenElePt  ; fhGenEleEta = qa.fhGenEleEta  ; fhGenElePhi = qa.fhGenElePhi ;  
247
248   fhEMVxyz = qa.fhEMVxyz ;  fhEMR = qa.fhEMR ; fhHaVxyz = qa.fhHaVxyz ;  fhHaR = qa.fhHaR ;
249   fhGamE = qa.fhGamE ;fhGamPt = qa.fhGamPt ;fhGamPhi = qa.fhGamPhi ;fhGamEta = qa.fhGamEta ; 
250   fhGamDeltaE   = qa.fhDeltaE; fhGamDeltaPt  = qa.fhDeltaPt; fhGamDeltaPhi = qa.fhDeltaPhi; fhGamDeltaEta = qa.fhDeltaEta;
251         
252   fhGamRatioE   = qa.fhGamRatioE;  fhGamRatioPt  = qa.fhGamRatioPt;  fhGamRatioPhi = qa.fhGamRatioPhi;  fhGamRatioEta = qa.fhGamRatioEta;
253
254   fhEleE = qa.fhEleE ;fhElePt = qa.fhElePt ;fhElePhi = qa.fhElePhi ;fhEleEta = qa.fhEleEta ;
255   fhPi0E = qa.fhPi0E ;fhPi0Pt = qa.fhPi0Pt ;fhPi0Phi = qa.fhPi0Phi ;fhPi0Eta = qa.fhPi0Eta ; 
256   fhNeHadE = qa.fhNeHadE ;fhNeHadPt = qa.fhNeHadPt ;fhNeHadPhi = qa.fhNeHadPhi ;fhNeHadEta = qa.fhNeHadEta ; 
257   fhChHadE = qa.fhChHadE ;fhChHadPt = qa.fhChHadPt ;fhChHadPhi = qa.fhChHadPhi ;fhChHadEta = qa.fhChHadEta ;
258   fhGenGamAccE = qa.fhGenGamAccE ;  fhGenPi0AccE = qa.fhGenPi0AccE ;
259   fhGenGamAccPt = qa.fhGenGamAccPt ;fhGenGamAccEta = qa.fhGenGamAccEta ;fhGenGamAccPhi = qa.fhGenGamAccPhi ;
260   fhGenPi0AccPt = qa.fhGenPi0AccPt ;fhGenPi0AccEta = qa.fhGenPi0AccEta; fhGenPi0AccPhi = qa.fhGenPi0AccPhi ;    
261                 
262   fhGamECharged = qa.fhGamECharged; fhGamPtCharged = qa.fhGamPtCharged; fhGamPhiCharged = qa.fhGamPhiCharged; fhGamEtaCharged = qa.fhGamEtaCharged;  
263   fhEleECharged = qa.fhEleECharged; fhElePtCharged = qa.fhElePtCharged; fhElePhiCharged = qa.fhElePhiCharged; fhEleEtaCharged = qa.fhEleEtaCharged; 
264   fhPi0ECharged = qa.fhPi0ECharged; fhPi0PtCharged = qa.fhPi0PtCharged; fhPi0PhiCharged = qa.fhPi0PhiCharged; fhPi0EtaCharged = qa.fhPi0EtaCharged;  
265   fhNeHadECharged = qa.fhNeHadECharged; fhNeHadPtCharged = qa.fhNeHadPtCharged; fhNeHadPhiCharged = qa.fhNeHadPhiCharged; fhNeHadEtaCharged = qa.fhNeHadEtaCharged;  
266   fhChHadECharged = qa.fhChHadECharged; fhChHadPtCharged = qa.fhChHadPtCharged; fhChHadPhiCharged = qa.fhChHadPhiCharged; fhChHadEtaCharged = qa.fhChHadEtaCharged;     
267         
268   fh1pOverE    = qa.fh1pOverE;
269   fh1dR        = qa.fh1dR;
270   fh2MatchdEdx = qa.fh2MatchdEdx;
271   fh2EledEdx   = qa.fh2EledEdx; 
272         
273   fhMCEle1pOverE    = qa.fhMCEle1pOverE; 
274   fhMCEle1dR        = qa.fhMCEle1dR; 
275   fhMCEle2MatchdEdx = qa.fhMCEle2MatchdEdx ;
276         
277   fhMCChHad1pOverE = qa.fhMCChHad1pOverE; fhMCChHad1dR = qa.fhMCChHad1dR;  fhMCChHad2MatchdEdx = qa.fhMCChHad2MatchdEdx; 
278   fhMCNeutral1pOverE = qa.fhMCNeutral1pOverE; fhMCNeutral1dR = qa.fhMCNeutral1dR;  fhMCNeutral2MatchdEdx = qa.fhMCNeutral2MatchdEdx; 
279   fh1pOverER02 = qa.fh1pOverER02;  fhMCEle1pOverER02 = qa.fhMCEle1pOverER02;  fhMCChHad1pOverER02 = qa.fhMCChHad1pOverER02;  
280   fhMCNeutral1pOverER02 = qa.fhMCNeutral1pOverER02;
281         
282   return *this;
283
284 }
285
286 //________________________________________________________________________________________________________________________________________________
287 //AliAnaCalorimeterQA::~AliAnaCalorimeterQA() {
288         // dtor
289         
290 //}
291
292
293 //________________________________________________________________________
294 TList *  AliAnaCalorimeterQA::GetCreateOutputObjects()
295 {  
296         // Create histograms to be saved in output file and 
297         // store them in outputContainer
298     
299         //If Geometry library loaded, do geometry selection during analysis.
300         if(fCalorimeter=="PHOS"){
301                 if(!GetReader()->GetPHOSGeometry()) printf("AliAnaPi0::GetCreateOutputObjects() - Initialize PHOS geometry!\n");
302                 GetReader()->InitPHOSGeometry();
303                 
304         }
305         else if(fCalorimeter=="EMCAL"){
306                 if(!GetReader()->GetEMCALGeometry()) printf("AliAnaPi0::GetCreateOutputObjects() - Initialize EMCAL geometry!\n");
307                 GetReader()->InitEMCALGeometry();
308         }
309         
310         
311         TList * outputContainer = new TList() ; 
312         outputContainer->SetName("QAHistos") ; 
313         
314         //Histograms
315         Int_t nptbins     = GetHistoPtBins();           Float_t ptmax     = GetHistoPtMax();           Float_t ptmin     = GetHistoPtMin();
316         Int_t nphibins    = GetHistoPhiBins();              Float_t phimax    = GetHistoPhiMax();          Float_t phimin    = GetHistoPhiMin();
317         Int_t netabins    = GetHistoEtaBins();          Float_t etamax    = GetHistoEtaMax();          Float_t etamin    = GetHistoEtaMin();    
318         Int_t nmassbins   = GetHistoMassBins();         Float_t massmax   = GetHistoMassMax();         Float_t massmin   = GetHistoMassMin();
319         Int_t nasymbins   = GetHistoAsymmetryBins();    Float_t asymmax   = GetHistoAsymmetryMax();    Float_t asymmin   = GetHistoAsymmetryMin();
320         Int_t nPoverEbins = GetHistoPOverEBins();       Float_t pOverEmax = GetHistoPOverEMax();       Float_t pOverEmin = GetHistoPOverEMin();
321         Int_t ndedxbins   = GetHistodEdxBins();         Float_t dedxmax   = GetHistodEdxMax();         Float_t dedxmin   = GetHistodEdxMin();
322         Int_t ndRbins     = GetHistodRBins();           Float_t dRmax     = GetHistodRMax();           Float_t dRmin     = GetHistodRMin();
323         Int_t ntimebins   = GetHistoTimeBins();         Float_t timemax   = GetHistoTimeMax();         Float_t timemin   = GetHistoTimeMin();       
324         Int_t nbins       = GetHistoNClusterCellBins(); Int_t nmax        = GetHistoNClusterCellMax(); Int_t nmin        = GetHistoNClusterCellMin(); 
325         Int_t nratiobins  = GetHistoRatioBins();        Float_t ratiomax  = GetHistoRatioMax();        Float_t ratiomin  = GetHistoRatioMin();
326         Int_t nvdistbins  = GetHistoVertexDistBins();   Float_t vdistmax  = GetHistoVertexDistMax();   Float_t vdistmin  = GetHistoVertexDistMin();
327         
328         //EMCAL
329         Int_t colmax = 48;
330         Int_t rowmax = 24;
331         //PHOS
332         if(fCalorimeter=="PHOS"){
333                 colmax=56;
334                 rowmax=64;
335         }
336         
337         
338         fhE  = new TH1F ("hE","E reconstructed clusters ", nptbins,ptmin,ptmax); 
339         fhE->SetXTitle("E (GeV)");
340         outputContainer->Add(fhE);
341         
342         fhPt  = new TH1F ("hPt","p_{T} reconstructed clusters", nptbins,ptmin,ptmax); 
343         fhPt->SetXTitle("p_{T} (GeV/c)");
344         outputContainer->Add(fhPt);
345         
346         fhPhi  = new TH1F ("hPhi","#phi reconstructed clusters ",nphibins,phimin,phimax); 
347         fhPhi->SetXTitle("#phi (rad)");
348         outputContainer->Add(fhPhi);
349         
350         fhEta  = new TH1F ("hEta","#eta reconstructed clusters ",netabins,etamin,etamax); 
351         fhEta->SetXTitle("#eta ");
352         outputContainer->Add(fhEta);
353         
354         fhEtaPhi  = new TH2F ("hEtaPhi","#eta vs #phi, reconstructed clusters ",netabins,etamin,etamax,nphibins,phimin,phimax); 
355         fhEtaPhi->SetXTitle("#eta ");
356         fhEtaPhi->SetYTitle("#phi ");
357         outputContainer->Add(fhEtaPhi);
358         
359         fhEtaPhiE  = new TH3F ("hEtaPhiE","#eta vs #phi vs energy, reconstructed clusters",netabins,etamin,etamax,nphibins,phimin,phimax,nptbins,ptmin,ptmax); 
360         fhEtaPhiE->SetXTitle("#eta ");
361         fhEtaPhiE->SetYTitle("#phi (rad)");
362         fhEtaPhiE->SetZTitle("E (GeV) ");
363         outputContainer->Add(fhEtaPhiE);
364         
365         //Track Matching
366
367         fhECharged  = new TH1F ("hECharged","E reconstructed clusters, matched with track", nptbins,ptmin,ptmax); 
368         fhECharged->SetXTitle("E (GeV)");
369         outputContainer->Add(fhECharged);
370         
371         fhPtCharged  = new TH1F ("hPtCharged","p_{T} reconstructed clusters, matched with track", nptbins,ptmin,ptmax); 
372         fhPtCharged->SetXTitle("p_{T} (GeV/c)");
373         outputContainer->Add(fhPtCharged);
374         
375         fhPhiCharged  = new TH1F ("hPhiCharged","#phi reconstructed clusters, matched with track",nphibins,phimin,phimax); 
376         fhPhiCharged->SetXTitle("#phi (rad)");
377         outputContainer->Add(fhPhiCharged);
378         
379         fhEtaCharged  = new TH1F ("hEtaCharged","#eta reconstructed clusters, matched with track",netabins,etamin,etamax); 
380         fhEtaCharged->SetXTitle("#eta ");
381         outputContainer->Add(fhEtaCharged);
382         
383         fhEtaPhiCharged  = new TH2F ("hEtaPhiCharged","#eta vs #phi, reconstructed clusters, matched with track",netabins,etamin,etamax,nphibins,phimin,phimax); 
384         fhEtaPhiCharged->SetXTitle("#eta ");
385         fhEtaPhiCharged->SetYTitle("#phi ");
386         outputContainer->Add(fhEtaPhiCharged);  
387
388         fhEChargedNoOut  = new TH1F ("hEChargedNoOut","E reconstructed clusters, matched with track, no output track params", nptbins,ptmin,ptmax); 
389         fhEChargedNoOut->SetXTitle("E (GeV)");
390         outputContainer->Add(fhEChargedNoOut);
391         
392         fhPtChargedNoOut  = new TH1F ("hPtChargedNoOut","p_{T} reconstructed clusters, matched with track, no output track params", nptbins,ptmin,ptmax); 
393         fhPtChargedNoOut->SetXTitle("p_{T} (GeV/c)");
394         outputContainer->Add(fhPtChargedNoOut);
395         
396         fhPhiChargedNoOut  = new TH1F ("hPhiChargedNoOut","#phi reconstructed clusters, matched with track, no output track params",nphibins,phimin,phimax); 
397         fhPhiChargedNoOut->SetXTitle("#phi (rad)");
398         outputContainer->Add(fhPhiChargedNoOut);
399         
400         fhEtaChargedNoOut  = new TH1F ("hEtaChargedNoOut","#eta reconstructed clusters, matched with track, no output track params",netabins,etamin,etamax); 
401         fhEtaChargedNoOut->SetXTitle("#eta ");
402         outputContainer->Add(fhEtaChargedNoOut);
403         
404         fhEtaPhiChargedNoOut  = new TH2F ("hEtaPhiChargedNoOut","#eta vs #phi, reconstructed clusters, matched with track, no output track params",netabins,etamin,etamax,nphibins,phimin,phimax); 
405         fhEtaPhiChargedNoOut->SetXTitle("#eta ");
406         fhEtaPhiChargedNoOut->SetYTitle("#phi ");
407         outputContainer->Add(fhEtaPhiChargedNoOut);     
408
409         fh1pOverE = new TH2F("h1pOverE","TRACK matches p/E",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
410         fh1pOverE->SetYTitle("p/E");
411         fh1pOverE->SetXTitle("p_{T} (GeV/c)");
412         outputContainer->Add(fh1pOverE);
413         
414         fh1dR = new TH1F("h1dR","TRACK matches dR",ndRbins,dRmin,dRmax);
415         fh1dR->SetXTitle("#Delta R (rad)");
416         outputContainer->Add(fh1dR) ;
417         
418         fh2MatchdEdx = new TH2F("h2MatchdEdx","dE/dx vs. p for all matches",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
419         fh2MatchdEdx->SetXTitle("p (GeV/c)");
420         fh2MatchdEdx->SetYTitle("<dE/dx>");
421         outputContainer->Add(fh2MatchdEdx);
422         
423         fh2EledEdx = new TH2F("h2EledEdx","dE/dx vs. p for electrons",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
424         fh2EledEdx->SetXTitle("p (GeV/c)");
425         fh2EledEdx->SetYTitle("<dE/dx>");
426         outputContainer->Add(fh2EledEdx) ;
427         
428         fh1pOverER02 = new TH2F("h1pOverER02","TRACK matches p/E, all",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
429         fh1pOverER02->SetYTitle("p/E");
430         fh1pOverER02->SetXTitle("p_{T} (GeV/c)");
431         outputContainer->Add(fh1pOverER02);     
432         
433         fhIM  = new TH2F ("hIM","Cluster pairs Invariant mass vs reconstructed pair energy",nptbins,ptmin,ptmax,nmassbins,massmin,massmax); 
434         fhIM->SetXTitle("p_{T, cluster pairs} (GeV) ");
435         fhIM->SetYTitle("M_{cluster pairs} (GeV/c^{2})");
436         outputContainer->Add(fhIM);
437         
438         fhIMCellCut  = new TH2F ("hIMCellCut","Cluster (n cell > 1) pairs Invariant mass vs reconstructed pair energy",nptbins,ptmin,ptmax,nmassbins,massmin,massmax); 
439         fhIMCellCut->SetXTitle("p_{T, cluster pairs} (GeV) ");
440         fhIMCellCut->SetYTitle("M_{cluster pairs} (GeV/c^{2})");
441         outputContainer->Add(fhIMCellCut);
442         
443         fhAsym  = new TH2F ("hAssym","Cluster pairs Asymmetry vs reconstructed pair energy",nptbins,ptmin,ptmax,nasymbins,asymmin,asymmax); 
444         fhAsym->SetXTitle("p_{T, cluster pairs} (GeV) ");
445         fhAsym->SetYTitle("Asymmetry");
446         outputContainer->Add(fhAsym);   
447         
448         fhNCellsPerCluster  = new TH2F ("hNCellsPerCluster","# cells per cluster vs cluster energy", nptbins,ptmin,ptmax, nbins,nmin,nmax); 
449         fhNCellsPerCluster->SetXTitle("E (GeV)");
450         fhNCellsPerCluster->SetYTitle("n cells");
451         outputContainer->Add(fhNCellsPerCluster);
452         
453         fhNCellsPerClusterMIP  = new TH2F ("hNCellsPerClusterMIP","# cells per cluster vs cluster energy, smaller bin for MIP search", 400,0.,2., nbins,nmin,nmax); 
454         fhNCellsPerClusterMIP->SetXTitle("E (GeV)");
455         fhNCellsPerClusterMIP->SetYTitle("n cells");
456         outputContainer->Add(fhNCellsPerClusterMIP);
457         
458         fhNClusters  = new TH1F ("hNClusters","# clusters", nbins,nmin,nmax); 
459         fhNClusters->SetXTitle("number of clusters");
460         outputContainer->Add(fhNClusters);
461         
462         //Calo cells
463         fhNCells  = new TH1F ("hNCells","# cells", colmax*rowmax*fNModules,0,colmax*rowmax*fNModules); 
464         fhNCells->SetXTitle("n cells");
465         outputContainer->Add(fhNCells);
466     
467         fhAmplitude  = new TH1F ("hAmplitude","Cell Energy", nptbins*5,ptmin,ptmax); 
468         fhAmplitude->SetXTitle("Cell Energy (GeV)");
469         outputContainer->Add(fhAmplitude);
470         
471         fhAmpId  = new TH2F ("hAmpId","Cell Energy", nptbins*2,ptmin,ptmax,rowmax*colmax,0,rowmax*colmax); 
472         fhAmpId->SetXTitle("Cell Energy (GeV)");
473         outputContainer->Add(fhAmpId);
474         
475         //Cell Time histograms, time only available in ESDs
476         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
477                 fhTime  = new TH1F ("hTime","Cell Time",ntimebins,timemin,timemax); 
478                 fhTime->SetXTitle("Cell Time (ns)");
479                 outputContainer->Add(fhTime);
480
481                 fhTimeId  = new TH2F ("hTimeId","Cell Time vs Absolute Id",ntimebins,timemin,timemax,rowmax*colmax,0,rowmax*colmax); 
482                 fhTimeId->SetXTitle("Cell Time (ns)");
483                 fhTimeId->SetYTitle("Cell Absolute Id");
484                 outputContainer->Add(fhTimeId);
485         
486                 fhTimeAmp  = new TH2F ("hTimeAmp","Cell Time vs Cell Energy",nptbins*2,ptmin,ptmax,ntimebins,timemin,timemax); 
487                 fhTimeAmp->SetYTitle("Cell Time (ns)");
488                 fhTimeAmp->SetXTitle("Cell Energy (GeV)");
489                 outputContainer->Add(fhTimeAmp);
490         }
491         
492         if(fCorrelateCalos){
493                 fhCaloCorrNClusters  = new TH2F ("hCaloCorrNClusters","# clusters in EMCAL vs PHOS", nbins,nmin,nmax,nbins,nmin,nmax); 
494                 fhCaloCorrNClusters->SetXTitle("number of clusters in EMCAL");
495                 fhCaloCorrNClusters->SetYTitle("number of clusters in PHOS");
496                 outputContainer->Add(fhCaloCorrNClusters);
497         
498                 fhCaloCorrEClusters  = new TH2F ("hCaloCorrEClusters","summed energy of clusters in EMCAL vs PHOS", nptbins*2,ptmin,ptmax*2,nptbins,ptmin,ptmax*2); 
499                 fhCaloCorrEClusters->SetXTitle("#Sigma E of clusters in EMCAL (GeV)");
500                 fhCaloCorrEClusters->SetYTitle("#Sigma E of clusters in PHOS (GeV)");
501                 outputContainer->Add(fhCaloCorrEClusters);
502         
503                 fhCaloCorrNCells  = new TH2F ("hCaloCorrNCells","# Cells in EMCAL vs PHOS", nbins,nmin,nmax, nbins,nmin,nmax); 
504                 fhCaloCorrNCells->SetXTitle("number of Cells in EMCAL");
505                 fhCaloCorrNCells->SetYTitle("number of Cells in PHOS");
506                 outputContainer->Add(fhCaloCorrNCells);
507         
508                 fhCaloCorrECells  = new TH2F ("hCaloCorrECells","summed energy of Cells in EMCAL vs PHOS", nptbins*2,ptmin,ptmax*2,nptbins,ptmin,ptmax*2); 
509                 fhCaloCorrECells->SetXTitle("#Sigma E of Cells in EMCAL (GeV)");
510                 fhCaloCorrECells->SetYTitle("#Sigma E of Cells in PHOS (GeV)");
511                 outputContainer->Add(fhCaloCorrECells);
512         }//correlate calorimeters
513         
514         //Module histograms
515         fhEMod                = new TH1F*[fNModules];
516         fhNClustersMod        = new TH1F*[fNModules];
517         fhNCellsPerClusterMod = new TH2F*[fNModules];
518         fhNCellsMod           = new TH1F*[fNModules];
519         fhGridCellsMod        = new TH2F*[fNModules];
520         fhGridCellsEMod       = new TH2F*[fNModules];
521         fhAmplitudeMod        = new TH1F*[fNModules];
522         fhIMMod               = new TH2F*[fNModules];
523         fhIMCellCutMod        = new TH2F*[fNModules];
524
525         for(Int_t imod = 0; imod < fNModules; imod++){
526                 
527                 fhEMod[imod]  = new TH1F (Form("hE_Mod%d",imod),Form("Cluster reconstructed Energy in Module %d ",imod), nptbins,ptmin,ptmax); 
528                 fhEMod[imod]->SetXTitle("E (GeV)");
529                 outputContainer->Add(fhEMod[imod]);
530                 
531                 fhNClustersMod[imod]  = new TH1F (Form("hNClusters_Mod%d",imod),Form("# clusters in Module %d",imod), nbins,nmin,nmax); 
532                 fhNClustersMod[imod]->SetXTitle("number of clusters");
533                 outputContainer->Add(fhNClustersMod[imod]);
534                 
535                 fhNCellsPerClusterMod[imod]  = new TH2F (Form("hNCellsPerCluster_Mod%d",imod),
536                                                                                                  Form("# cells per cluster vs cluster energy in Module %d",imod), 
537                                                                                                  nptbins,ptmin,ptmax, nbins,nmin,nmax); 
538                 fhNCellsPerClusterMod[imod]->SetXTitle("E (GeV)");
539                 fhNCellsPerClusterMod[imod]->SetYTitle("n cells");
540                 outputContainer->Add(fhNCellsPerClusterMod[imod]);
541                 
542                 fhNCellsMod[imod]  = new TH1F (Form("hNCells_Mod%d",imod),Form("# cells in Module %d",imod), colmax*rowmax,0,colmax*rowmax); 
543                 fhNCellsMod[imod]->SetXTitle("n cells");
544                 outputContainer->Add(fhNCellsMod[imod]);
545                 fhGridCellsMod[imod]  = new TH2F (Form("hGridCells_Mod%d",imod),Form("Entries in grid of cells in Module %d",imod), 
546                                                                                   colmax+2,-1.5,colmax+0.5, rowmax+2,-1.5,rowmax+0.5); 
547                 fhGridCellsMod[imod]->SetYTitle("row (phi direction)");
548                 fhGridCellsMod[imod]->SetXTitle("column (eta direction)");
549                 outputContainer->Add(fhGridCellsMod[imod]);
550
551                 fhGridCellsEMod[imod]  = new TH2F (Form("hGridCellsE_Mod%d",imod),Form("Accumulated energy in grid of cells in Module %d",imod), 
552                                                                                    colmax+2,-1.5,colmax+0.5, rowmax+2,-1.5,rowmax+0.5); 
553                 fhGridCellsEMod[imod]->SetYTitle("row (phi direction)");
554                 fhGridCellsEMod[imod]->SetXTitle("column (eta direction)");
555                 outputContainer->Add(fhGridCellsEMod[imod]);
556                 
557                 fhAmplitudeMod[imod]  = new TH1F (Form("hAmplitude_Mod%d",imod),Form("Cell Energy in Module %d",imod), nptbins*2,ptmin,ptmax); 
558                 fhAmplitudeMod[imod]->SetXTitle("Cell Energy (GeV)");
559                 outputContainer->Add(fhAmplitudeMod[imod]);
560                 
561                 fhIMMod[imod]  = new TH2F (Form("hIM_Mod%d",imod),
562                                                                    Form("Cluster pairs Invariant mass vs reconstructed pair energy in Module %d",imod),
563                                                                    nptbins,ptmin,ptmax,nmassbins,massmin,massmax); 
564                 fhIMMod[imod]->SetXTitle("p_{T, cluster pairs} (GeV) ");
565                 fhIMMod[imod]->SetYTitle("M_{cluster pairs} (GeV/c^{2})");
566                 outputContainer->Add(fhIMMod[imod]);
567                                 
568                 fhIMCellCutMod[imod]  = new TH2F (Form("hIMCellCut_Mod%d",imod),
569                                                                    Form("Cluster (n cells > 1) pairs Invariant mass vs reconstructed pair energy in Module %d",imod),
570                                                                    nptbins,ptmin,ptmax,nmassbins,massmin,massmax); 
571                 fhIMCellCutMod[imod]->SetXTitle("p_{T, cluster pairs} (GeV) ");
572                 fhIMCellCutMod[imod]->SetYTitle("M_{cluster pairs} (GeV/c^{2})");
573                 outputContainer->Add(fhIMCellCutMod[imod]);
574                 
575         }
576         
577         
578         //Monte Carlo Histograms
579         if(IsDataMC()){
580                 
581                 fhDeltaE  = new TH1F ("hDeltaE","MC - Reco E ", nptbins*2,-ptmax,ptmax); 
582                 fhDeltaE->SetXTitle("#Delta E (GeV)");
583                 outputContainer->Add(fhDeltaE);
584                 
585                 fhDeltaPt  = new TH1F ("hDeltaPt","MC - Reco p_{T} ", nptbins*2,-ptmax,ptmax); 
586                 fhDeltaPt->SetXTitle("#Delta p_{T} (GeV/c)");
587                 outputContainer->Add(fhDeltaPt);
588                 
589                 fhDeltaPhi  = new TH1F ("hDeltaPhi","MC - Reco #phi ",nphibins*2,-phimax,phimax); 
590                 fhDeltaPhi->SetXTitle("#Delta #phi (rad)");
591                 outputContainer->Add(fhDeltaPhi);
592                 
593                 fhDeltaEta  = new TH1F ("hDeltaEta","MC- Reco #eta",netabins*2,-etamax,etamax); 
594                 fhDeltaEta->SetXTitle("#Delta #eta ");
595                 outputContainer->Add(fhDeltaEta);
596                 
597                 fhRatioE  = new TH1F ("hRatioE","Reco/MC E ", nratiobins,ratiomin,ratiomax); 
598                 fhRatioE->SetXTitle("E_{reco}/E_{gen}");
599                 outputContainer->Add(fhRatioE);
600                 
601                 fhRatioPt  = new TH1F ("hRatioPt","Reco/MC p_{T} ", nratiobins,ratiomin,ratiomax); 
602                 fhRatioPt->SetXTitle("p_{T, reco}/p_{T, gen}");
603                 outputContainer->Add(fhRatioPt);
604                 
605                 fhRatioPhi  = new TH1F ("hRatioPhi","Reco/MC #phi ",nratiobins,ratiomin,ratiomax); 
606                 fhRatioPhi->SetXTitle("#phi_{reco}/#phi_{gen}");
607                 outputContainer->Add(fhRatioPhi);
608                 
609                 fhRatioEta  = new TH1F ("hRatioEta","Reco/MC #eta",nratiobins,ratiomin,ratiomax); 
610                 fhRatioEta->SetXTitle("#eta_{reco}/#eta_{gen} ");
611                 outputContainer->Add(fhRatioEta);
612                 
613                 fh2E  = new TH2F ("h2E","E distribution, reconstructed vs generated", nptbins,ptmin,ptmax,nptbins,ptmin,ptmax); 
614                 fh2E->SetXTitle("E_{rec} (GeV)");
615                 fh2E->SetYTitle("E_{gen} (GeV)");
616                 outputContainer->Add(fh2E);       
617                 
618                 fh2Pt  = new TH2F ("h2Pt","p_T distribution, reconstructed vs generated", nptbins,ptmin,ptmax,nptbins,ptmin,ptmax); 
619                 fh2Pt->SetXTitle("p_{T,rec} (GeV/c)");
620                 fh2Pt->SetYTitle("p_{T,gen} (GeV/c)");
621                 outputContainer->Add(fh2Pt);
622                 
623                 fh2Phi  = new TH2F ("h2Phi","#phi distribution, reconstructed vs generated", nphibins,phimin,phimax, nphibins,phimin,phimax); 
624                 fh2Phi->SetXTitle("#phi_{rec} (rad)");
625                 fh2Phi->SetYTitle("#phi_{gen} (rad)");
626                 outputContainer->Add(fh2Phi);
627                 
628                 fh2Eta  = new TH2F ("h2Eta","#eta distribution, reconstructed vs generated", netabins,etamin,etamax,netabins,etamin,etamax); 
629                 fh2Eta->SetXTitle("#eta_{rec} ");
630                 fh2Eta->SetYTitle("#eta_{gen} ");
631                 outputContainer->Add(fh2Eta);
632                 
633                 //Fill histos depending on origin of cluster
634                 fhGamE  = new TH2F ("hGamE","E reconstructed vs E generated from #gamma", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
635                 fhGamE->SetXTitle("E_{rec} (GeV)");
636                 fhGamE->SetXTitle("E_{gen} (GeV)");
637                 outputContainer->Add(fhGamE);
638                 
639                 fhGamPt  = new TH2F ("hGamPt","p_{T} reconstructed vs E generated from #gamma", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
640                 fhGamPt->SetXTitle("p_{T rec} (GeV/c)");
641                 fhGamPt->SetYTitle("p_{T gen} (GeV/c)");
642                 outputContainer->Add(fhGamPt);
643                 
644                 fhGamPhi  = new TH2F ("hGamPhi","#phi reconstructed vs E generated from #gamma",nphibins,phimin,phimax,nphibins,phimin,phimax); 
645                 fhGamPhi->SetXTitle("#phi_{rec} (rad)");
646                 fhGamPhi->SetYTitle("#phi_{gen} (rad)");
647                 outputContainer->Add(fhGamPhi);
648                 
649                 fhGamEta  = new TH2F ("hGamEta","#eta reconstructed vs E generated from #gamma",netabins,etamin,etamax,netabins,etamin,etamax); 
650                 fhGamEta->SetXTitle("#eta_{rec} ");
651                 fhGamEta->SetYTitle("#eta_{gen} ");
652                 outputContainer->Add(fhGamEta);
653                 
654                 fhGamDeltaE  = new TH1F ("hGamDeltaE","#gamma MC - Reco E ", nptbins*2,-ptmax,ptmax); 
655                 fhGamDeltaE->SetXTitle("#Delta E (GeV)");
656                 outputContainer->Add(fhGamDeltaE);
657                 
658                 fhGamDeltaPt  = new TH1F ("hGamDeltaPt","#gamma MC - Reco p_{T} ", nptbins*2,-ptmax,ptmax); 
659                 fhGamDeltaPt->SetXTitle("#Delta p_{T} (GeV/c)");
660                 outputContainer->Add(fhGamDeltaPt);
661                 
662                 fhGamDeltaPhi  = new TH1F ("hGamDeltaPhi","#gamma MC - Reco #phi ",nphibins*2,-phimax,phimax); 
663                 fhGamDeltaPhi->SetXTitle("#Delta #phi (rad)");
664                 outputContainer->Add(fhGamDeltaPhi);
665                 
666                 fhGamDeltaEta  = new TH1F ("hGamDeltaEta","#gamma MC- Reco #eta",netabins*2,-etamax,etamax); 
667                 fhGamDeltaEta->SetXTitle("#Delta #eta ");
668                 outputContainer->Add(fhGamDeltaEta);
669                 
670                 fhGamRatioE  = new TH1F ("hGamRatioE","#gamma Reco/MC E ", nratiobins,ratiomin,ratiomax); 
671                 fhGamRatioE->SetXTitle("E_{reco}/E_{gen}");
672                 outputContainer->Add(fhGamRatioE);
673                 
674                 fhGamRatioPt  = new TH1F ("hGamRatioPt","#gamma Reco/MC p_{T} ", nratiobins,ratiomin,ratiomax); 
675                 fhGamRatioPt->SetXTitle("p_{T, reco}/p_{T, gen}");
676                 outputContainer->Add(fhGamRatioPt);
677                 
678                 fhGamRatioPhi  = new TH1F ("hGamRatioPhi","#gamma Reco/MC #phi ",nratiobins,ratiomin,ratiomax); 
679                 fhGamRatioPhi->SetXTitle("#phi_{reco}/#phi_{gen}");
680                 outputContainer->Add(fhGamRatioPhi);
681                 
682                 fhGamRatioEta  = new TH1F ("hGamRatioEta","#gamma Reco/MC #eta",nratiobins,ratiomin,ratiomax); 
683                 fhGamRatioEta->SetXTitle("#eta_{reco}/#eta_{gen} ");
684                 outputContainer->Add(fhGamRatioEta);
685
686                 fhPi0E  = new TH2F ("hPi0E","E reconstructed vs E generated from #pi^{0}", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
687                 fhPi0E->SetXTitle("E_{rec} (GeV)");
688                 fhPi0E->SetYTitle("E_{gen} (GeV)");
689                 outputContainer->Add(fhPi0E);
690                 
691                 fhPi0Pt  = new TH2F ("hPi0Pt","p_{T} reconstructed vs E generated from #pi^{0}", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
692                 fhPi0Pt->SetXTitle("p_{T rec} (GeV/c)");
693                 fhPi0Pt->SetYTitle("p_{T gen} (GeV/c)");
694                 outputContainer->Add(fhPi0Pt);
695                 
696                 fhPi0Phi  = new TH2F ("hPi0Phi","#phi reconstructed vs E generated from #pi^{0}",nphibins,phimin,phimax,nphibins,phimin,phimax); 
697                 fhPi0Phi->SetXTitle("#phi_{rec} (rad)");
698                 fhPi0Phi->SetYTitle("#phi_{gen} (rad)");
699                 outputContainer->Add(fhPi0Phi);
700                 
701                 fhPi0Eta  = new TH2F ("hPi0Eta","#eta reconstructed vs E generated from #pi^{0}",netabins,etamin,etamax,netabins,etamin,etamax); 
702                 fhPi0Eta->SetXTitle("#eta_{rec} ");
703                 fhPi0Eta->SetYTitle("#eta_{gen} ");
704                 outputContainer->Add(fhPi0Eta);
705                 
706                 fhEleE  = new TH2F ("hEleE","E reconstructed vs E generated from e^{#pm}", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
707                 fhEleE->SetXTitle("E_{rec} (GeV)");
708                 fhEleE->SetXTitle("E_{gen} (GeV)");             
709                 outputContainer->Add(fhEleE);           
710                 
711                 fhElePt  = new TH2F ("hElePt","p_{T} reconstructed vs E generated from e^{#pm}", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
712                 fhElePt->SetXTitle("p_{T rec} (GeV/c)");
713                 fhElePt->SetYTitle("p_{T gen} (GeV/c)");
714                 outputContainer->Add(fhElePt);
715                 
716                 fhElePhi  = new TH2F ("hElePhi","#phi reconstructed vs E generated from e^{#pm}",nphibins,phimin,phimax,nphibins,phimin,phimax); 
717                 fhElePhi->SetXTitle("#phi_{rec} (rad)");
718                 fhElePhi->SetYTitle("#phi_{gen} (rad)");
719                 outputContainer->Add(fhElePhi);
720                 
721                 fhEleEta  = new TH2F ("hEleEta","#eta reconstructed vs E generated from e^{#pm}",netabins,etamin,etamax,netabins,etamin,etamax); 
722                 fhEleEta->SetXTitle("#eta_{rec} ");
723                 fhEleEta->SetYTitle("#eta_{gen} ");
724                 outputContainer->Add(fhEleEta);
725                 
726                 fhNeHadE  = new TH2F ("hNeHadE","E reconstructed vs E generated from neutral hadron", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
727                 fhNeHadE->SetXTitle("E_{rec} (GeV)");
728                 fhNeHadE->SetYTitle("E_{gen} (GeV)");
729                 outputContainer->Add(fhNeHadE);
730                 
731                 fhNeHadPt  = new TH2F ("hNeHadPt","p_{T} reconstructed vs E generated from neutral hadron", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
732                 fhNeHadPt->SetXTitle("p_{T rec} (GeV/c)");
733                 fhNeHadPt->SetYTitle("p_{T gen} (GeV/c)");
734                 outputContainer->Add(fhNeHadPt);
735                 
736                 fhNeHadPhi  = new TH2F ("hNeHadPhi","#phi reconstructed vs E generated from neutral hadron",nphibins,phimin,phimax,nphibins,phimin,phimax); 
737                 fhNeHadPhi->SetXTitle("#phi_{rec} (rad)");
738                 fhNeHadPhi->SetYTitle("#phi_{gen} (rad)");
739                 outputContainer->Add(fhNeHadPhi);
740                 
741                 fhNeHadEta  = new TH2F ("hNeHadEta","#eta reconstructed vs E generated from neutral hadron",netabins,etamin,etamax,netabins,etamin,etamax); 
742                 fhNeHadEta->SetXTitle("#eta_{rec} ");
743                 fhNeHadEta->SetYTitle("#eta_{gen} ");
744                 outputContainer->Add(fhNeHadEta);
745                 
746                 fhChHadE  = new TH2F ("hChHadE","E reconstructed vs E generated from charged hadron", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
747                 fhChHadE->SetXTitle("E_{rec} (GeV)");
748                 fhChHadE->SetYTitle("E_{gen} (GeV)");
749                 outputContainer->Add(fhChHadE);
750                 
751                 fhChHadPt  = new TH2F ("hChHadPt","p_{T} reconstructed vs E generated from charged hadron", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
752                 fhChHadPt->SetXTitle("p_{T rec} (GeV/c)");
753                 fhChHadPt->SetYTitle("p_{T gen} (GeV/c)");
754                 outputContainer->Add(fhChHadPt);
755                 
756                 fhChHadPhi  = new TH2F ("hChHadPhi","#phi reconstructed vs E generated from charged hadron",nphibins,phimin,phimax,nphibins,phimin,phimax); 
757                 fhChHadPhi->SetXTitle("#phi_{rec} (rad)");
758                 fhChHadPhi->SetYTitle("#phi_{gen} (rad)");
759                 outputContainer->Add(fhChHadPhi);
760                 
761                 fhChHadEta  = new TH2F ("hChHadEta","#eta reconstructed vs E generated from charged hadron",netabins,etamin,etamax,netabins,etamin,etamax); 
762                 fhChHadEta->SetXTitle("#eta_{rec} ");
763                 fhChHadEta->SetYTitle("#eta_{gen} ");
764                 outputContainer->Add(fhChHadEta);
765                 
766                 //Charged clusters
767                 
768                 fhGamECharged  = new TH2F ("hGamECharged","E reconstructed vs E generated from #gamma, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
769                 fhGamECharged->SetXTitle("E_{rec} (GeV)");
770                 fhGamECharged->SetXTitle("E_{gen} (GeV)");
771                 outputContainer->Add(fhGamECharged);
772                 
773                 fhGamPtCharged  = new TH2F ("hGamPtCharged","p_{T} reconstructed vs E generated from #gamma, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
774                 fhGamPtCharged->SetXTitle("p_{T rec} (GeV/c)");
775                 fhGamPtCharged->SetYTitle("p_{T gen} (GeV/c)");
776                 outputContainer->Add(fhGamPtCharged);
777                 
778                 fhGamPhiCharged  = new TH2F ("hGamPhiCharged","#phi reconstructed vs E generated from #gamma, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
779                 fhGamPhiCharged->SetXTitle("#phi_{rec} (rad)");
780                 fhGamPhiCharged->SetYTitle("#phi_{gen} (rad)");
781                 outputContainer->Add(fhGamPhiCharged);
782                 
783                 fhGamEtaCharged  = new TH2F ("hGamEtaCharged","#eta reconstructed vs E generated from #gamma, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
784                 fhGamEtaCharged->SetXTitle("#eta_{rec} ");
785                 fhGamEtaCharged->SetYTitle("#eta_{gen} ");
786                 outputContainer->Add(fhGamEtaCharged);
787                 
788                 fhPi0ECharged  = new TH2F ("hPi0ECharged","E reconstructed vs E generated from #pi^{0}, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
789                 fhPi0ECharged->SetXTitle("E_{rec} (GeV)");
790                 fhPi0ECharged->SetYTitle("E_{gen} (GeV)");
791                 outputContainer->Add(fhPi0ECharged);
792                 
793                 fhPi0PtCharged  = new TH2F ("hPi0PtCharged","p_{T} reconstructed vs E generated from #pi^{0}, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
794                 fhPi0PtCharged->SetXTitle("p_{T rec} (GeV/c)");
795                 fhPi0PtCharged->SetYTitle("p_{T gen} (GeV/c)");
796                 outputContainer->Add(fhPi0PtCharged);
797                 
798                 fhPi0PhiCharged  = new TH2F ("hPi0PhiCharged","#phi reconstructed vs E generated from #pi^{0}, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
799                 fhPi0PhiCharged->SetXTitle("#phi_{rec} (rad)");
800                 fhPi0PhiCharged->SetYTitle("#phi_{gen} (rad)");
801                 outputContainer->Add(fhPi0PhiCharged);
802                 
803                 fhPi0EtaCharged  = new TH2F ("hPi0EtaCharged","#eta reconstructed vs E generated from #pi^{0}, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
804                 fhPi0EtaCharged->SetXTitle("#eta_{rec} ");
805                 fhPi0EtaCharged->SetYTitle("#eta_{gen} ");
806                 outputContainer->Add(fhPi0EtaCharged);
807                 
808                 fhEleECharged  = new TH2F ("hEleECharged","E reconstructed vs E generated from e^{#pm}, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
809                 fhEleECharged->SetXTitle("E_{rec} (GeV)");
810                 fhEleECharged->SetXTitle("E_{gen} (GeV)");              
811                 outputContainer->Add(fhEleECharged);            
812                 
813                 fhElePtCharged  = new TH2F ("hElePtCharged","p_{T} reconstructed vs E generated from e^{#pm}, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
814                 fhElePtCharged->SetXTitle("p_{T rec} (GeV/c)");
815                 fhElePtCharged->SetYTitle("p_{T gen} (GeV/c)");
816                 outputContainer->Add(fhElePtCharged);
817                 
818                 fhElePhiCharged  = new TH2F ("hElePhiCharged","#phi reconstructed vs E generated from e^{#pm}, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
819                 fhElePhiCharged->SetXTitle("#phi_{rec} (rad)");
820                 fhElePhiCharged->SetYTitle("#phi_{gen} (rad)");
821                 outputContainer->Add(fhElePhiCharged);
822                 
823                 fhEleEtaCharged  = new TH2F ("hEleEtaCharged","#eta reconstructed vs E generated from e^{#pm}, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
824                 fhEleEtaCharged->SetXTitle("#eta_{rec} ");
825                 fhEleEtaCharged->SetYTitle("#eta_{gen} ");
826                 outputContainer->Add(fhEleEtaCharged);
827                 
828                 fhNeHadECharged  = new TH2F ("hNeHadECharged","E reconstructed vs E generated from neutral hadron, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
829                 fhNeHadECharged->SetXTitle("E_{rec} (GeV)");
830                 fhNeHadECharged->SetYTitle("E_{gen} (GeV)");
831                 outputContainer->Add(fhNeHadECharged);
832                 
833                 fhNeHadPtCharged  = new TH2F ("hNeHadPtCharged","p_{T} reconstructed vs E generated from neutral hadron, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
834                 fhNeHadPtCharged->SetXTitle("p_{T rec} (GeV/c)");
835                 fhNeHadPtCharged->SetYTitle("p_{T gen} (GeV/c)");
836                 outputContainer->Add(fhNeHadPtCharged);
837                 
838                 fhNeHadPhiCharged  = new TH2F ("hNeHadPhiCharged","#phi reconstructed vs E generated from neutral hadron, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
839                 fhNeHadPhiCharged->SetXTitle("#phi_{rec} (rad)");
840                 fhNeHadPhiCharged->SetYTitle("#phi_{gen} (rad)");
841                 outputContainer->Add(fhNeHadPhiCharged);
842                 
843                 fhNeHadEtaCharged  = new TH2F ("hNeHadEtaCharged","#eta reconstructed vs E generated from neutral hadron, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
844                 fhNeHadEtaCharged->SetXTitle("#eta_{rec} ");
845                 fhNeHadEtaCharged->SetYTitle("#eta_{gen} ");
846                 outputContainer->Add(fhNeHadEtaCharged);
847                 
848                 fhChHadECharged  = new TH2F ("hChHadECharged","E reconstructed vs E generated from charged hadron, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
849                 fhChHadECharged->SetXTitle("E_{rec} (GeV)");
850                 fhChHadECharged->SetYTitle("E_{gen} (GeV)");
851                 outputContainer->Add(fhChHadECharged);
852                 
853                 fhChHadPtCharged  = new TH2F ("hChHadPtCharged","p_{T} reconstructed vs E generated from charged hadron, track matched cluster", nptbins,ptmin,ptmax, nptbins,ptmin,ptmax); 
854                 fhChHadPtCharged->SetXTitle("p_{T rec} (GeV/c)");
855                 fhChHadPtCharged->SetYTitle("p_{T gen} (GeV/c)");
856                 outputContainer->Add(fhChHadPtCharged);
857                 
858                 fhChHadPhiCharged  = new TH2F ("hChHadPhiCharged","#phi reconstructed vs E generated from charged hadron, track matched cluster",nphibins,phimin,phimax,nphibins,phimin,phimax); 
859                 fhChHadPhiCharged->SetXTitle("#phi (rad)");
860                 fhChHadPhiCharged->SetXTitle("#phi_{rec} (rad)");
861                 fhChHadPhiCharged->SetYTitle("#phi_{gen} (rad)");
862                 outputContainer->Add(fhChHadPhiCharged);
863                 
864                 fhChHadEtaCharged  = new TH2F ("hChHadEtaCharged","#eta reconstructed vs E generated from charged hadron, track matched cluster",netabins,etamin,etamax,netabins,etamin,etamax); 
865                 fhChHadEtaCharged->SetXTitle("#eta_{rec} ");
866                 fhChHadEtaCharged->SetYTitle("#eta_{gen} ");
867                 outputContainer->Add(fhChHadEtaCharged);
868                 
869                 //Vertex of generated particles 
870                 
871                 fhEMVxyz  = new TH2F ("hEMVxyz","Production vertex of reconstructed ElectroMagnetic particles",nvdistbins,vdistmin,vdistmax,nvdistbins,vdistmin,vdistmax);//,100,0,500); 
872                 fhEMVxyz->SetXTitle("v_{x}");
873                 fhEMVxyz->SetYTitle("v_{y}");
874                 //fhEMVxyz->SetZTitle("v_{z}");
875                 outputContainer->Add(fhEMVxyz);
876                 
877                 fhHaVxyz  = new TH2F ("hHaVxyz","Production vertex of reconstructed hadrons",nvdistbins,vdistmin,vdistmax,nvdistbins,vdistmin,vdistmax);//,100,0,500); 
878                 fhHaVxyz->SetXTitle("v_{x}");
879                 fhHaVxyz->SetYTitle("v_{y}");
880                 //fhHaVxyz->SetZTitle("v_{z}");
881                 outputContainer->Add(fhHaVxyz);
882                 
883                 fhEMR  = new TH2F ("hEMR","Distance to production vertex of reconstructed ElectroMagnetic particles vs E rec",nptbins,ptmin,ptmax,nvdistbins,vdistmin,vdistmax); 
884                 fhEMR->SetXTitle("E (GeV)");
885                 fhEMR->SetYTitle("TMath::Sqrt(v_{x}^{2}+v_{y}^{2})");
886                 outputContainer->Add(fhEMR);
887                 
888                 fhHaR  = new TH2F ("hHaR","Distance to production vertex of reconstructed Hadrons vs E rec",nptbins,ptmin,ptmax,nvdistbins,vdistmin,vdistmax); 
889                 fhHaR->SetXTitle("E (GeV)");
890                 fhHaR->SetYTitle("TMath::Sqrt(v_{x}^{2}+v_{y}^{2})");
891                 outputContainer->Add(fhHaR);
892                 
893
894                 
895                 //Pure MC
896                 fhGenGamPt  = new TH1F("hGenGamPt" ,"p_{T} of generated #gamma",nptbins,ptmin,ptmax);
897                 fhGenGamEta = new TH1F("hGenGamEta","Y of generated #gamma",netabins,etamin,etamax);
898                 fhGenGamPhi = new TH1F("hGenGamPhi","#phi of generated #gamma",nphibins,phimin,phimax);
899                 
900                 fhGenPi0Pt  = new TH1F("hGenPi0Pt" ,"p_{T} of generated #pi^{0}",nptbins,ptmin,ptmax);
901                 fhGenPi0Eta = new TH1F("hGenPi0Eta","Y of generated #pi^{0}",netabins,etamin,etamax);
902                 fhGenPi0Phi = new TH1F("hGenPi0Phi","#phi of generated #pi^{0}",nphibins,phimin,phimax);
903                 
904                 fhGenEtaPt  = new TH1F("hGenEtaPt" ,"p_{T} of generated #eta",nptbins,ptmin,ptmax);
905                 fhGenEtaEta = new TH1F("hGenEtaEta","Y of generated #eta",netabins,etamin,etamax);
906                 fhGenEtaPhi = new TH1F("hGenEtaPhi","#phi of generated #eta",nphibins,phimin,phimax);
907                 
908                 fhGenOmegaPt  = new TH1F("hGenOmegaPt" ,"p_{T} of generated #omega",nptbins,ptmin,ptmax);
909                 fhGenOmegaEta = new TH1F("hGenOmegaEta","Y of generated #omega",netabins,etamin,etamax);
910                 fhGenOmegaPhi = new TH1F("hGenOmegaPhi","#phi of generated #omega",nphibins,phimin,phimax);             
911                 
912                 fhGenElePt  = new TH1F("hGenElePt" ,"p_{T} of generated e^{#pm}",nptbins,ptmin,ptmax);
913                 fhGenEleEta = new TH1F("hGenEleEta","Y of generated  e^{#pm}",netabins,etamin,etamax);
914                 fhGenElePhi = new TH1F("hGenElePhi","#phi of generated  e^{#pm}",nphibins,phimin,phimax);               
915                 
916                 fhGenGamPt->SetXTitle("p_{T} (GeV/c)");
917                 fhGenGamEta->SetXTitle("#eta");
918                 fhGenGamPhi->SetXTitle("#phi (rad)");
919                 outputContainer->Add(fhGenGamPt);
920                 outputContainer->Add(fhGenGamEta);
921                 outputContainer->Add(fhGenGamPhi);
922
923                 fhGenPi0Pt->SetXTitle("p_{T} (GeV/c)");
924                 fhGenPi0Eta->SetXTitle("#eta");
925                 fhGenPi0Phi->SetXTitle("#phi (rad)");
926                 outputContainer->Add(fhGenPi0Pt);
927                 outputContainer->Add(fhGenPi0Eta);
928                 outputContainer->Add(fhGenPi0Phi);
929                 
930                 fhGenEtaPt->SetXTitle("p_{T} (GeV/c)");
931                 fhGenEtaEta->SetXTitle("#eta");
932                 fhGenEtaPhi->SetXTitle("#phi (rad)");
933                 outputContainer->Add(fhGenEtaPt);
934                 outputContainer->Add(fhGenEtaEta);
935                 outputContainer->Add(fhGenEtaPhi);
936                                 
937                 fhGenOmegaPt->SetXTitle("p_{T} (GeV/c)");
938                 fhGenOmegaEta->SetXTitle("#eta");
939                 fhGenOmegaPhi->SetXTitle("#phi (rad)");
940                 outputContainer->Add(fhGenOmegaPt);
941                 outputContainer->Add(fhGenOmegaEta);
942                 outputContainer->Add(fhGenOmegaPhi);
943                 
944                 fhGenElePt->SetXTitle("p_{T} (GeV/c)");
945                 fhGenEleEta->SetXTitle("#eta");
946                 fhGenElePhi->SetXTitle("#phi (rad)");
947                 outputContainer->Add(fhGenElePt);
948                 outputContainer->Add(fhGenEleEta);
949                 outputContainer->Add(fhGenElePhi);
950                 
951                 fhGenGamAccE   = new TH1F("hGenGamAccE" ,"E of generated #gamma in calorimeter acceptance",nptbins,ptmin,ptmax);
952                 fhGenGamAccPt  = new TH1F("hGenGamAccPt" ,"p_{T} of generated #gamma in calorimeter acceptance",nptbins,ptmin,ptmax);
953                 fhGenGamAccEta = new TH1F("hGenGamAccEta","Y of generated #gamma in calorimeter acceptance",netabins,etamin,etamax);
954                 fhGenGamAccPhi = new TH1F("hGenGamAccPhi","#phi of generated #gamma  in calorimeter acceptance",nphibins,phimin,phimax);
955                 
956                 fhGenPi0AccE  = new TH1F("hGenPi0AccE" ,"E of generated #pi^{0} in calorimeter acceptance",nptbins,ptmin,ptmax);
957                 fhGenPi0AccPt  = new TH1F("hGenPi0AccPt" ,"p_{T} of generated #pi^{0} in calorimeter acceptance",nptbins,ptmin,ptmax);
958                 fhGenPi0AccEta = new TH1F("hGenPi0AccEta","Y of generated #pi^{0} in calorimeter acceptance",netabins,etamin,etamax);
959                 fhGenPi0AccPhi = new TH1F("hGenPi0AccPhi","#phi of generated #pi^{0} in calorimeter acceptance",nphibins,phimin,phimax);
960                 
961                 fhGenGamAccE  ->SetXTitle("E (GeV)");
962                 fhGenGamAccPt ->SetXTitle("p_{T} (GeV/c)");
963                 fhGenGamAccEta->SetXTitle("#eta");
964                 fhGenGamAccPhi->SetXTitle("#phi (rad)");
965                 outputContainer->Add(fhGenGamAccE);             
966                 outputContainer->Add(fhGenGamAccPt);
967                 outputContainer->Add(fhGenGamAccEta);
968                 outputContainer->Add(fhGenGamAccPhi);
969                 
970                 fhGenPi0AccE  ->SetXTitle("E (GeV)");           
971                 fhGenPi0AccPt ->SetXTitle("p_{T} (GeV/c)");
972                 fhGenPi0AccEta->SetXTitle("#eta");
973                 fhGenPi0AccPhi->SetXTitle("#phi (rad)");
974                 outputContainer->Add(fhGenPi0AccE);             
975                 outputContainer->Add(fhGenPi0AccPt);
976                 outputContainer->Add(fhGenPi0AccEta);
977                 outputContainer->Add(fhGenPi0AccPhi);
978                 
979                 //Track Matching 
980                 
981           fhMCEle1pOverE = new TH2F("hMCEle1pOverE","TRACK matches p/E, MC electrons",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
982           fhMCEle1pOverE->SetYTitle("p/E");
983           fhMCEle1pOverE->SetXTitle("p_{T} (GeV/c)");
984           outputContainer->Add(fhMCEle1pOverE);
985           
986           fhMCEle1dR = new TH1F("hMCEle1dR","TRACK matches dR, MC electrons",ndRbins,dRmin,dRmax);
987           fhMCEle1dR->SetXTitle("#Delta R (rad)");
988           outputContainer->Add(fhMCEle1dR) ;
989           
990           fhMCEle2MatchdEdx = new TH2F("hMCEle2MatchdEdx","dE/dx vs. p for all matches, MC electrons",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
991           fhMCEle2MatchdEdx->SetXTitle("p (GeV/c)");
992           fhMCEle2MatchdEdx->SetYTitle("<dE/dx>");
993           outputContainer->Add(fhMCEle2MatchdEdx);
994           
995           fhMCChHad1pOverE = new TH2F("hMCChHad1pOverE","TRACK matches p/E, MC charged hadrons",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
996           fhMCChHad1pOverE->SetYTitle("p/E");
997           fhMCChHad1pOverE->SetXTitle("p_{T} (GeV/c)");
998           outputContainer->Add(fhMCChHad1pOverE);
999           
1000           fhMCChHad1dR = new TH1F("hMCChHad1dR","TRACK matches dR, MC charged hadrons",ndRbins,dRmin,dRmax);
1001           fhMCChHad1dR->SetXTitle("#Delta R (rad)");
1002           outputContainer->Add(fhMCChHad1dR) ;
1003           
1004           fhMCChHad2MatchdEdx = new TH2F("hMCChHad2MatchdEdx","dE/dx vs. p for all matches, MC charged hadrons",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
1005           fhMCChHad2MatchdEdx->SetXTitle("p (GeV/c)");
1006           fhMCChHad2MatchdEdx->SetYTitle("<dE/dx>");
1007           outputContainer->Add(fhMCChHad2MatchdEdx);
1008           
1009           fhMCNeutral1pOverE = new TH2F("hMCNeutral1pOverE","TRACK matches p/E, MC neutrals",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1010           fhMCNeutral1pOverE->SetYTitle("p/E");
1011           fhMCNeutral1pOverE->SetXTitle("p_{T} (GeV/c)");
1012           outputContainer->Add(fhMCNeutral1pOverE);
1013           
1014           fhMCNeutral1dR = new TH1F("hMCNeutral1dR","TRACK matches dR, MC neutrals",ndRbins,dRmin,dRmax);
1015           fhMCNeutral1dR->SetXTitle("#Delta R (rad)");
1016           outputContainer->Add(fhMCNeutral1dR) ;
1017           
1018           fhMCNeutral2MatchdEdx = new TH2F("hMCNeutral2MatchdEdx","dE/dx vs. p for all matches, MC neutrals",nptbins,ptmin,ptmax,ndedxbins,dedxmin,dedxmax);
1019           fhMCNeutral2MatchdEdx->SetXTitle("p (GeV/c)");
1020           fhMCNeutral2MatchdEdx->SetYTitle("<dE/dx>");
1021           outputContainer->Add(fhMCNeutral2MatchdEdx);
1022                   
1023           fhMCEle1pOverER02 = new TH2F("hMCEle1pOverER02","TRACK matches p/E, MC electrons",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1024           fhMCEle1pOverER02->SetYTitle("p/E");
1025           fhMCEle1pOverER02->SetXTitle("p_{T} (GeV/c)");
1026           outputContainer->Add(fhMCEle1pOverER02);
1027           
1028           fhMCChHad1pOverER02 = new TH2F("hMCChHad1pOverER02","TRACK matches p/E, MC charged hadrons",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1029           fhMCChHad1pOverER02->SetYTitle("p/E");
1030           fhMCChHad1pOverER02->SetXTitle("p_{T} (GeV/c)");
1031           outputContainer->Add(fhMCChHad1pOverER02);
1032           
1033           fhMCNeutral1pOverER02 = new TH2F("hMCNeutral1pOverER02","TRACK matches p/E, MC neutrals",nptbins,ptmin,ptmax, nPoverEbins,pOverEmin,pOverEmax);
1034           fhMCNeutral1pOverER02->SetYTitle("p/E");
1035           fhMCNeutral1pOverER02->SetXTitle("p_{T} (GeV/c)");
1036           outputContainer->Add(fhMCNeutral1pOverER02);
1037         }
1038
1039         return outputContainer;
1040 }
1041
1042 //____________________________________________________________________________________________________________________________________________________
1043 Int_t AliAnaCalorimeterQA::GetModuleNumber(AliESDCaloCluster * cluster) 
1044 {
1045         //Get the EMCAL/PHOS module number that corresponds to this cluster
1046         TLorentzVector lv;
1047         Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
1048         cluster->GetMomentum(lv,v);
1049         Float_t phi = lv.Phi();
1050         if(phi < 0) phi+=TMath::TwoPi();        
1051         Int_t absId = -1;
1052         if(fCalorimeter=="EMCAL"){
1053                 GetReader()->GetEMCALGeometry()->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
1054                 if(GetDebug() > 2) 
1055                         printf("AliAnaCalorimeterQA::GetModuleNumber(ESD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
1056                                    lv.Eta(), phi*TMath::RadToDeg(),absId, GetReader()->GetEMCALGeometry()->GetSuperModuleNumber(absId));
1057                 return GetReader()->GetEMCALGeometry()->GetSuperModuleNumber(absId) ;
1058         }//EMCAL
1059         else{//PHOS
1060                 Int_t    relId[4];
1061                 if ( cluster->GetNCells() > 0) {
1062                         absId = cluster->GetCellAbsId(0);
1063                         if(GetDebug() > 2) 
1064                                 printf("AliAnaCalorimeterQA::GetModuleNumber(ESD) - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
1065                                                 lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
1066                 }
1067                 else return -1;
1068                 
1069                 if ( absId >= 0) {
1070                         GetReader()->GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
1071                         if(GetDebug() > 2) 
1072                                 printf("AliAnaCalorimeterQA::GetModuleNumber(ESD) - PHOS: Module %d\n",relId[0]-1);
1073                         return relId[0]-1;
1074                 }
1075                 else return -1;
1076         }//PHOS
1077         
1078         return -1;
1079 }
1080
1081 //____________________________________________________________________________________________________________________________________________________
1082 Int_t AliAnaCalorimeterQA::GetModuleNumber(AliAODCaloCluster * cluster) 
1083 {
1084         //Get the EMCAL/PHOS module number that corresponds to this cluster
1085         TLorentzVector lv;
1086         Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
1087         cluster->GetMomentum(lv,v);
1088         Float_t phi = lv.Phi();
1089         if(phi < 0) phi+=TMath::TwoPi();        
1090         Int_t absId = -1;
1091         if(fCalorimeter=="EMCAL"){
1092                 GetReader()->GetEMCALGeometry()->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
1093                 if(GetDebug() > 2) 
1094                         printf("AliAnaCalorimeterQA::GetModuleNumber(ESD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
1095                                    lv.Eta(), phi*TMath::RadToDeg(),absId, GetReader()->GetEMCALGeometry()->GetSuperModuleNumber(absId));
1096                 return GetReader()->GetEMCALGeometry()->GetSuperModuleNumber(absId) ;
1097         }//EMCAL
1098         else{//PHOS
1099                 Int_t    relId[4];
1100                 if ( cluster->GetNCells() > 0) {
1101                         absId = cluster->GetCellAbsId(0);
1102                         if(GetDebug() > 2) 
1103                                 printf("AliAnaCalorimeterQA::GetModuleNumber(AOD) - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
1104                                            lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
1105                 }
1106                 else return -1;
1107                 
1108                 if ( absId >= 0) {
1109                         GetReader()->GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
1110                         if(GetDebug() > 2) 
1111                                 printf("AliAnaCalorimeterQA::GetModuleNumber(AOD) - PHOS: Module %d\n",relId[0]-1);
1112                         return relId[0]-1;
1113                 }
1114                 else return -1;
1115         }//PHOS
1116         
1117         return -1;
1118 }
1119 //____________________________________________________________________________________________________________________________________________________
1120 Int_t AliAnaCalorimeterQA::GetModuleNumberCellIndexes(const Int_t absId, Int_t & icol, Int_t & irow) 
1121 {
1122         //Get the EMCAL/PHOS module number that corresponds to this absId
1123         Int_t imod = -1;
1124         if ( absId >= 0) {
1125                 if(fCalorimeter=="EMCAL"){
1126                         Int_t iTower = -1, iIphi = -1, iIeta = -1; 
1127                         GetReader()->GetEMCALGeometry()->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
1128             GetReader()->GetEMCALGeometry()->GetCellPhiEtaIndexInSModule(imod,iTower,
1129                                               iIphi, iIeta,irow,icol);
1130                         return imod ;
1131                 }//EMCAL
1132                 else{//PHOS
1133                         Int_t    relId[4];
1134                         GetReader()->GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
1135                         irow = relId[2];
1136                         icol = relId[3];
1137                         imod = relId[0]-1;
1138                         return imod;
1139                 }//PHOS 
1140         }
1141         
1142         return -1;
1143 }
1144
1145
1146 //__________________________________________________
1147 void AliAnaCalorimeterQA::Init()
1148
1149         //Check if the data or settings are ok
1150         if(fCalorimeter != "PHOS" && fCalorimeter !="EMCAL"){
1151                 printf("AliAnaCalorimeterQA::Init() - Wrong calorimeter name <%s>, END\n", fCalorimeter.Data());
1152                 abort();
1153         }       
1154         
1155         if(GetReader()->GetDataType()== AliCaloTrackReader::kMC){
1156                 printf("AliAnaCalorimeterQA::Init() - Analysis of reconstructed data, MC reader not aplicable\n");
1157                 abort();
1158         }       
1159         
1160 }
1161
1162
1163 //__________________________________________________
1164 void AliAnaCalorimeterQA::InitParameters()
1165
1166   //Initialize the parameters of the analysis.
1167   AddToHistogramsName("AnaCaloQA_");
1168
1169   fCalorimeter = "EMCAL"; //or PHOS
1170   fStyleMacro  = "" ;
1171   fNModules    = 12; // set maximum to maximum number of EMCAL modules
1172          
1173   fHistoPOverEBins     = 100 ;  fHistoPOverEMax     = 10.  ;  fHistoPOverEMin     = 0. ;
1174   fHistodEdxBins       = 200 ;  fHistodEdxMax       = 400. ;  fHistodEdxMin       = 0. ;  
1175   fHistodRBins         = 300 ;  fHistodRMax         = 3.15 ;  fHistodRMin         = 0. ;
1176   fHistoTimeBins       = 1000;  fHistoTimeMax       = 1.e3 ;  fHistoTimeMin       = 0. ;//ns
1177   fHistoNBins          = 300 ;  fHistoNMax          = 300  ;  fHistoNMin          = 0  ;
1178   fHistoRatioBins      = 200 ;  fHistoRatioMax      = 2    ;  fHistoRatioMin      = 0. ;
1179   fHistoVertexDistBins = 100 ;  fHistoVertexDistMax = 500. ;  fHistoVertexDistMin = 0. ;
1180         
1181
1182 }
1183
1184 //__________________________________________________________________
1185 void AliAnaCalorimeterQA::Print(const Option_t * opt) const
1186 {
1187   //Print some relevant parameters set for the analysis
1188   if(! opt)
1189     return;
1190   
1191   printf("**** Print %s %s ****\n", GetName(), GetTitle() ) ;
1192   AliAnaPartCorrBaseClass::Print(" ");
1193
1194   printf("Select Calorimeter %s \n",fCalorimeter.Data());
1195   printf("Make plots?        %d \n",fMakePlots);        
1196   printf("Plots style macro  %s \n",fStyleMacro.Data()); 
1197   printf("Histograms: %3.1f < p/E  < %3.1f, Nbin = %d\n", fHistoPOverEMin, fHistoPOverEMax, fHistoPOverEBins);
1198   printf("Histograms: %3.1f < dEdx < %3.1f, Nbin = %d\n", fHistodEdxMin,   fHistodEdxMax,   fHistodEdxBins);
1199   printf("Histograms: %3.1f < dR   < %3.1f, Nbin = %d\n", fHistodRMin,     fHistodRMax,     fHistodRBins);
1200   printf("Histograms: %g < Time < %g, Nbin = %d\n"      , fHistoTimeMin,   fHistoTimeMax,   fHistoTimeBins);
1201   printf("Histograms: %d < N    < %d, Nbin = %d\n"      , fHistoNMin,      fHistoNMax,      fHistoNBins);
1202   printf("Histograms: %3.1f < Ratio< %3.1f, Nbin = %d\n", fHistoRatioMin,  fHistoRatioMax,  fHistoRatioBins);
1203   printf("Histograms: %3.1f < Vertex Distance < %3.1f, Nbin = %d\n", fHistoVertexDistMin, fHistoVertexDistMax, fHistoVertexDistBins);
1204
1205
1206
1207 //__________________________________________________________________
1208 void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms() 
1209 {
1210         //Fill Calorimeter QA histograms
1211         
1212         TLorentzVector mom ;
1213         TLorentzVector mom2 ;
1214         TRefArray * caloClusters = new TRefArray();
1215         Int_t nLabel = 0;
1216         Int_t *labels=0x0;
1217         Int_t nCaloClusters = 0;
1218         Int_t nCaloCellsPerCluster = 0;
1219         Int_t nTracksMatched = 0;
1220         Int_t trackIndex = 0;
1221         Int_t nModule = -1;
1222
1223         //Play with the MC stack if available   
1224         //Get the MC arrays and do some checks
1225         if(IsDataMC()){
1226                 if(GetReader()->ReadStack()){
1227
1228                         if(!GetMCStack()) {
1229                                 printf("AliAnaPhoton::MakeAnalysisFillHistograms() - Stack not available, is the MC handler called? STOP\n");
1230                                 abort();
1231                         }
1232                         //Fill some pure MC histograms, only primaries.
1233                         for(Int_t i=0 ; i<GetMCStack()->GetNprimary(); i++){//Only primary particles, for all MC transport put GetNtrack()
1234                                 TParticle *primary = GetMCStack()->Particle(i) ;
1235                                 //printf("i %d, %s: status = %d, primary? %d\n",i, primary->GetName(), primary->GetStatusCode(), primary->IsPrimary());
1236                                 if (primary->GetStatusCode() > 11) continue; //Working for PYTHIA and simple generators, check for HERWIG 
1237                                 primary->Momentum(mom);
1238                                 MCHistograms(mom,TMath::Abs(primary->GetPdgCode()));
1239                         } //primary loop
1240                 }
1241                 else if(GetReader()->ReadAODMCParticles()){
1242
1243                         if(!GetReader()->GetAODMCParticles(0))  {
1244                                 printf("AliAnaPhoton::MakeAnalysisFillHistograms() -  AODMCParticles not available!\n");
1245                                 abort();
1246                         }
1247                         //Fill some pure MC histograms, only primaries.
1248                         for(Int_t i=0 ; i < (GetReader()->GetAODMCParticles(0))->GetEntriesFast(); i++){
1249                                 AliAODMCParticle *aodprimary = (AliAODMCParticle*) (GetReader()->GetAODMCParticles(0))->At(i) ;
1250                                 //printf("i %d, %s: primary? %d physical primary? %d, flag %d\n",
1251                                 //         i,(TDatabasePDG::Instance()->GetParticle(aodprimary->GetPdgCode()))->GetName(), 
1252                                 //         aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary(), aodprimary->GetFlag());
1253                                 if (!aodprimary->IsPrimary()) continue; //accept all which is not MC transport generated. Don't know how to avoid partons
1254                                 //aodprimary->Momentum(mom);
1255                                 mom.SetPxPyPzE(aodprimary->Px(),aodprimary->Py(),aodprimary->Pz(),aodprimary->E());
1256                                 MCHistograms(mom,TMath::Abs(aodprimary->GetPdgCode()));
1257                         } //primary loop
1258                         
1259                 }
1260         }// is data and MC      
1261         
1262         
1263         //Get List with CaloClusters  
1264         
1265         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
1266                 if     (fCalorimeter == "EMCAL") ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALClusters(caloClusters);//GetAODEMCAL();
1267                 else if(fCalorimeter == "PHOS")  ((AliESDEvent*)GetReader()->GetInputEvent())->GetPHOSClusters (caloClusters);//GetAODPHOS();
1268                 else {
1269                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Wrong calorimeter name <%s>, END\n", fCalorimeter.Data());
1270                         abort();
1271                 }
1272         }
1273         else if(GetReader()->GetDataType()==AliCaloTrackReader::kAOD) {
1274                 if     (fCalorimeter == "EMCAL") ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALClusters(caloClusters);//GetAODEMCAL();
1275                 else if(fCalorimeter == "PHOS")  ((AliAODEvent*)GetReader()->GetInputEvent())->GetPHOSClusters (caloClusters);//GetAODPHOS();
1276                 else {
1277                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Wrong calorimeter name <%s>, END\n", fCalorimeter.Data());
1278                         abort();
1279                 }
1280         }
1281         
1282         if(!caloClusters) {
1283                 printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - No CaloClusters available\n");
1284                 abort();
1285         }
1286         
1287         //Correlate Calorimeters
1288         if(fCorrelateCalos)     CorrelateCalorimeters(caloClusters);
1289                 
1290         nCaloClusters = caloClusters->GetEntriesFast() ; 
1291         fhNClusters->Fill(nCaloClusters);
1292         Int_t *nClustersInModule = new Int_t[fNModules];
1293         for(Int_t imod = 0; imod < fNModules; imod++ ) nClustersInModule[imod] = 0;
1294         
1295         if(GetDebug() > 0)
1296                 printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - In %s there are %d clusters \n", fCalorimeter.Data(), nCaloClusters);
1297         
1298         //Get vertex for photon momentum calculation
1299         Double_t v[3] ; //vertex ;
1300         GetReader()->GetVertex(v);
1301         TObject * track = 0x0;
1302         //Loop over CaloClusters
1303         for(Int_t iclus = 0; iclus < nCaloClusters; iclus++){
1304                 
1305                 if(GetDebug() > 0) printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - cluster: %d/%d, data %d \n",
1306                                                                         iclus+1,nCaloClusters,GetReader()->GetDataType());
1307                 
1308                 if(GetReader()->GetDataType()==AliCaloTrackReader::kESD){
1309                         AliESDCaloCluster* clus =  (AliESDCaloCluster*) (caloClusters->At(iclus));
1310                         //Get cluster kinematics
1311                         clus->GetMomentum(mom,v);
1312                         //Check only certain regions
1313                         Bool_t in = kTRUE;
1314                         if(IsFiducialCutOn()) in =  GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
1315                         if(!in) continue;
1316                         //Get module of cluster
1317                         nModule = GetModuleNumber(clus);
1318                         if(nModule < fNModules) nClustersInModule[nModule]++;
1319                         //MC labels
1320                         nLabel = clus->GetNLabels();
1321                         if(clus->GetLabels()) labels =  (clus->GetLabels())->GetArray();
1322                         //Cells per cluster
1323                         nCaloCellsPerCluster =  clus->GetNCells();                      
1324                         //matched cluster with tracks
1325                         nTracksMatched = clus->GetNTracksMatched();
1326                         trackIndex     = clus->GetTrackMatched();
1327                         if(trackIndex >= 0){
1328                                 track = (AliESDtrack*) ((AliESDEvent*)GetReader()->GetInputEvent())->GetTrack(trackIndex);
1329                         }
1330                         else{
1331                                 if(nTracksMatched == 1) nTracksMatched = 0;
1332                                 track = 0;
1333                         }
1334                 }
1335                 else{
1336                         AliAODCaloCluster* clus =  (AliAODCaloCluster*) (caloClusters->At(iclus));
1337
1338                         //Get cluster kinematics
1339                         clus->GetMomentum(mom,v);
1340                         //Check only certain regions
1341                         Bool_t in = kTRUE;
1342                         if(IsFiducialCutOn()) in =  GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
1343                         if(!in) continue;                       
1344                         //Get module of cluster
1345                         nModule = GetModuleNumber(clus);
1346                         if(nModule < fNModules)  nClustersInModule[nModule]++;
1347                         //MC labels
1348                         nLabel = clus->GetNLabel();
1349                         if(clus->GetLabels()) labels =  clus->GetLabels();
1350                         //Cells per cluster
1351                         nCaloCellsPerCluster = clus->GetNCells();
1352                         //matched cluster with tracks
1353                         nTracksMatched = clus->GetNTracksMatched();
1354                         if(nTracksMatched > 0)
1355                                 track  = (AliAODTrack*)clus->GetTrackMatched(0);
1356                 }
1357
1358         //Fill histograms related to single cluster or track matching
1359                 ClusterHistograms(mom, nCaloCellsPerCluster, nModule, nTracksMatched, track, labels, nLabel);   
1360                 if(GetDebug()>1) printf("Invariant mass \n");
1361                 //Invariant mass
1362                 Int_t nModule2 = -1;
1363                 Int_t nCaloCellsPerCluster2=0;
1364                 if (nCaloClusters > 1 ) {
1365                         for(Int_t jclus = iclus + 1 ; jclus < nCaloClusters-1 ; jclus++) {
1366                                 if(GetReader()->GetDataType()==AliCaloTrackReader::kESD){
1367                                         AliESDCaloCluster* clus2 =  (AliESDCaloCluster*) (caloClusters->At(jclus));
1368                                         //Get cluster kinematics
1369                                         clus2->GetMomentum(mom2,v);
1370                                         //Check only certain regions
1371                                         Bool_t in2 = kTRUE;
1372                                         if(IsFiducialCutOn()) in2 =  GetFiducialCut()->IsInFiducialCut(mom2,fCalorimeter) ;
1373                                         if(!in2) continue;      
1374                                         //Get module of cluster
1375                                         nModule2 = GetModuleNumber(clus2);
1376                                         //Cells per cluster
1377                                         nCaloCellsPerCluster2 = clus2->GetNCells();
1378
1379                                 }
1380                                 else if(GetReader()->GetDataType()==AliCaloTrackReader::kAOD){
1381                                         AliAODCaloCluster* clus2 =  (AliAODCaloCluster*) (caloClusters->At(jclus));
1382                                         //Get cluster kinematics
1383                                         clus2->GetMomentum(mom2,v);
1384                                         //Check only certain regions
1385                                         Bool_t in2 = kTRUE;
1386                                         if(IsFiducialCutOn()) in2 =  GetFiducialCut()->IsInFiducialCut(mom2,fCalorimeter) ;
1387                                         if(!in2) continue;                                              
1388                                         //Get module of cluster
1389                                         nModule2 = GetModuleNumber(clus2);
1390                                         //Cells per cluster
1391                                         nCaloCellsPerCluster2 = clus2->GetNCells();
1392                                 }
1393
1394                                 //Fill invariant mass histograms
1395                                 //All modules
1396                                 fhIM  ->Fill((mom+mom2).Pt(),(mom+mom2).M());
1397                                 //Single module
1398                                 if(nModule == nModule2 && nModule >=0 && nModule < fNModules)
1399                                   fhIMMod[nModule]->Fill((mom+mom2).Pt(),(mom+mom2).M());
1400
1401                                 //Select only clusters with at least 2 cells
1402                                 if(nCaloCellsPerCluster > 1 && nCaloCellsPerCluster2 > 1) {
1403                                   //All modules
1404                                   fhIMCellCut  ->Fill((mom+mom2).Pt(),(mom+mom2).M());
1405                                   //Single modules
1406                                   if(nModule == nModule2 && nModule >=0 && nModule < fNModules)
1407                                     fhIMCellCutMod[nModule]->Fill((mom+mom2).Pt(),(mom+mom2).M());
1408                                 }
1409
1410                                 //Asymetry histograms
1411                                 fhAsym->Fill((mom+mom2).Pt(),TMath::Abs((mom.E()-mom2.E())/(mom.E()+mom2.E())));
1412                                         
1413                         }// 2nd cluster loop
1414                 }////more than 1 cluster in calorimeter         
1415         }//cluster loop
1416         
1417         //Number of clusters per module
1418         for(Int_t imod = 0; imod < fNModules; imod++ ){ 
1419                 if(GetDebug() > 1) 
1420                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - module %d calo %s clusters %d\n", imod, fCalorimeter.Data(), nClustersInModule[imod]); 
1421                 fhNClustersMod[imod]->Fill(nClustersInModule[imod]);
1422         }
1423         
1424         //CaloCells
1425         Int_t *nCellsInModule = new Int_t[fNModules];
1426         for(Int_t imod = 0; imod < fNModules; imod++ ) nCellsInModule[imod] = 0;
1427         Int_t icol = -1;
1428         Int_t irow = -1;
1429         Float_t amp  = 0.;
1430         Float_t time = 0.;
1431         Float_t id   = -1;
1432         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD){
1433                 AliESDCaloCells * cell = 0x0; 
1434                 Int_t ncells = 0;
1435                 if(fCalorimeter == "PHOS") cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
1436                 else                                       cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
1437                 
1438                 if(!cell) {
1439                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - STOP: No CELLS available for analysis");
1440                         abort();
1441                 }
1442                 
1443                 ncells = cell->GetNumberOfCells() ;
1444                 fhNCells->Fill(ncells) ;
1445                 if(GetDebug() > 0) 
1446                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - In ESD %s cell entries %d\n", fCalorimeter.Data(), ncells);    
1447                 
1448                 for (Int_t iCell = 0; iCell < ncells; iCell++) {      
1449                         if(GetDebug() > 2)  printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Cell : amp %f, absId %d \n", cell->GetAmplitude(iCell), cell->GetCellNumber(iCell));
1450                         nModule = GetModuleNumberCellIndexes(cell->GetCellNumber(iCell), icol, irow);
1451                     if(GetDebug() > 2) printf("\t module %d, column %d, row %d \n", nModule,icol,irow);
1452                         
1453                         if(nModule < fNModules) {       
1454                                 amp     = cell->GetAmplitude(iCell);
1455                                 time    = cell->GetTime(iCell)*1e9;//transform time to ns
1456                                 //printf("%s: time %g\n",fCalorimeter.Data(), time);
1457                                 id      = cell->GetCellNumber(iCell);
1458                                 fhAmplitude->Fill(amp);
1459                                 fhAmpId    ->Fill(amp,id);
1460                                 fhTime     ->Fill(time);
1461                                 fhTimeId   ->Fill(time,id);
1462                                 fhTimeAmp  ->Fill(amp,time);
1463                                 fhAmplitudeMod[nModule]->Fill(cell->GetAmplitude(iCell));
1464                                 nCellsInModule[nModule]++;
1465                                 fhGridCellsMod[nModule] ->Fill(icol,irow);
1466                                 fhGridCellsEMod[nModule]->Fill(icol,irow,amp);
1467                         }//nmodules
1468                 }//cell loop
1469         }//ESD
1470         else{//AOD
1471                 AliAODCaloCells * cell = 0x0; 
1472                 Int_t ncells = 0;
1473                 
1474                 if(fCalorimeter == "PHOS") cell = ((AliAODEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
1475                 else                                       cell = ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALCells();        
1476                 
1477                 if(!cell) {
1478                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - STOP: No CELLS available for analysis");
1479                         abort();
1480                 }
1481                 
1482                 ncells = cell->GetNumberOfCells() ;
1483                 fhNCells->Fill(ncells) ;
1484                 if(GetDebug() > 0) 
1485                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - In ESD %s cell entries %d\n", fCalorimeter.Data(), ncells); 
1486         
1487                 for (Int_t iCell = 0; iCell < ncells; iCell++) {      
1488                         if(GetDebug() > 2 )  printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - Cell : amp %f, absId %d \n", cell->GetAmplitude(iCell), cell->GetCellNumber(iCell));
1489                         nModule = GetModuleNumberCellIndexes(cell->GetCellNumber(iCell), icol, irow);
1490                         if(GetDebug() > 2) printf("\t module %d, column %d, row %d \n", nModule,icol,irow);
1491                         
1492                         if(nModule < fNModules) {       
1493                                 amp     = cell->GetAmplitude(iCell);
1494                                 fhAmplitude->Fill(amp);
1495                                 fhAmpId    ->Fill(amp,id);
1496                                 fhAmplitudeMod[nModule]->Fill(cell->GetAmplitude(iCell));
1497                                 nCellsInModule[nModule]++;
1498                                 fhGridCellsMod[nModule]->Fill(icol,irow);
1499                                 fhGridCellsEMod[nModule]->Fill(icol,irow,amp);
1500                         }//nmodules
1501                 }//cell loop
1502         }//AOD
1503
1504         //Number of cells per module
1505         for(Int_t imod = 0; imod < fNModules; imod++ ) {
1506                 if(GetDebug() > 1) 
1507                         printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - module %d calo %s cells %d\n", imod, fCalorimeter.Data(), nCellsInModule[imod]); 
1508                 fhNCellsMod[imod]->Fill(nCellsInModule[imod]) ;
1509         }
1510
1511         if(GetDebug() > 0)
1512                 printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - End \n");
1513 }
1514
1515
1516 //__________________________________
1517 void AliAnaCalorimeterQA::ClusterHistograms(const TLorentzVector mom, const Int_t nCaloCellsPerCluster,const Int_t nModule,
1518                                                                                         const Int_t nTracksMatched,  const TObject * track,  
1519                                                                                         const Int_t * labels, const Int_t nLabels){
1520         //Fill CaloCluster related histograms
1521         
1522         AliAODMCParticle * aodprimary  = 0x0;
1523         TParticle * primary = 0x0;
1524     Int_t tag = 0;      
1525         
1526         Float_t e   = mom.E();
1527         Float_t pt  = mom.Pt();
1528         Float_t eta = mom.Eta();
1529         Float_t phi = mom.Phi();
1530         if(phi < 0) phi +=TMath::TwoPi();
1531         if(GetDebug() > 0) {
1532                 printf("AliAnaCalorimeterQA::ClusterHistograms() - cluster: E %2.3f, pT %2.3f, eta %2.3f, phi %2.3f \n",e,pt,eta,phi*TMath::RadToDeg());
1533                 if(IsDataMC()) {
1534                         //printf("\t Primaries: nlabels %d, labels pointer %p\n",nLabels,labels);
1535                         printf("\t Primaries: nlabels %d\n",nLabels);
1536                         if(!nLabels || !labels) printf("\t Strange, no labels!!!\n");
1537                 }
1538         }
1539
1540         fhE     ->Fill(e);      
1541         if(nModule < fNModules) fhEMod[nModule]->Fill(e);
1542         fhPt    ->Fill(pt);
1543         fhPhi   ->Fill(phi);
1544         fhEta   ->Fill(eta);
1545         fhEtaPhi->Fill(eta,phi);
1546         fhEtaPhiE->Fill(eta,phi,e);
1547         //Cells per cluster
1548         fhNCellsPerCluster   ->Fill(e, nCaloCellsPerCluster);
1549         fhNCellsPerClusterMIP->Fill(e, nCaloCellsPerCluster);
1550         if(nModule < fNModules) fhNCellsPerClusterMod[nModule]->Fill(e, nCaloCellsPerCluster);
1551
1552         //Fill histograms only possible when simulation
1553         if(IsDataMC() && nLabels > 0 && labels){
1554
1555                 //Play with the MC stack if available
1556                 Int_t label = labels[0];
1557
1558                 if(label < 0) {
1559                         if(GetDebug() >= 0) printf("AliAnaCalorimeterQA::ClusterHistograms() *** bad label ***:  label %d \n", label);
1560                         return;
1561                 }
1562
1563                 Int_t pdg  =-1; Int_t pdg0  =-1;Int_t status = -1; Int_t iMother = -1; Int_t iParent = -1;
1564                 Float_t vxMC= 0; Float_t vyMC = 0;      
1565                 Float_t eMC = 0; Float_t ptMC= 0; Float_t phiMC =0; Float_t etaMC = 0;
1566                 Int_t charge = 0;       
1567                 
1568                 //Check the origin.
1569                 tag = GetMCAnalysisUtils()->CheckOrigin(labels,nLabels, GetReader(),0);
1570
1571                 if(GetReader()->ReadStack() && !GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCUnknown)){ //it MC stack and known tag
1572
1573                         if( label >= GetMCStack()->GetNtrack()) {
1574                                 if(GetDebug() >= 0) printf("AliAnaCalorimeterQA::ClusterHistograms() *** large label ***:  label %d, n tracks %d \n", label, GetMCStack()->GetNtrack());
1575                                 return ;
1576                         }
1577                         
1578                         primary = GetMCStack()->Particle(label);
1579                         iMother = label;
1580                         pdg0    = TMath::Abs(primary->GetPdgCode());
1581                         pdg     = pdg0;
1582                         status  = primary->GetStatusCode();
1583                         vxMC    = primary->Vx();
1584                         vyMC    = primary->Vy();
1585                         iParent = primary->GetFirstMother();
1586                                 
1587                         if(GetDebug() > 1 ) {
1588                                 printf("AliAnaCalorimeterQA::ClusterHistograms() - Cluster most contributing mother: \n");
1589                                 printf("\t Mother label %d, pdg %d, %s, status %d, parent %d \n",iMother, pdg0, primary->GetName(),status, iParent);
1590                         }
1591                                 
1592                         //Get final particle, no conversion products
1593                         if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCConversion)){
1594                                 //Get the parent
1595                                 primary = GetMCStack()->Particle(iParent);
1596                                 pdg = TMath::Abs(primary->GetPdgCode());
1597                                 if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted cluster!. Find before conversion: \n");
1598                                 while((pdg == 22 || pdg == 11) && status != 1){
1599                                         iMother = iParent;
1600                                         primary = GetMCStack()->Particle(iMother);
1601                                         status  = primary->GetStatusCode();
1602                                         iParent = primary->GetFirstMother();
1603                                         pdg     = TMath::Abs(primary->GetPdgCode());
1604                                         if(GetDebug() > 1 )printf("\t pdg %d, index %d, %s, status %d \n",pdg, iMother,  primary->GetName(),status);    
1605                                 }       
1606                                         
1607                                 if(GetDebug() > 1 ) {
1608                                         printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted Cluster mother before conversion: \n");
1609                                         printf("\t Mother label %d, pdg %d, %s, status %d, parent %d \n",iMother, pdg, primary->GetName(), status, iParent);
1610                                 }
1611                                         
1612                         }
1613                                 
1614                         //Overlapped pi0 (or eta, there will be very few), get the meson
1615                         if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1616                                 GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1617                                 if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped Meson decay!, Find it: \n");
1618                                 while(pdg != 111 && pdg != 221){
1619                                         iMother = iParent;
1620                                         primary = GetMCStack()->Particle(iMother);
1621                                         status  = primary->GetStatusCode();
1622                                         iParent = primary->GetFirstMother();
1623                                         pdg     = TMath::Abs(primary->GetPdgCode());
1624                                         if(GetDebug() > 1 ) printf("\t pdg %d, %s, index %d\n",pdg,  primary->GetName(),iMother);
1625                                         if(iMother==-1) {
1626                                                 printf("AliAnaCalorimeterQA::ClusterHistograms() - Tagged as Overlapped photon but meson not found, why?\n");
1627                                                 //break;
1628                                         }
1629                                 }
1630
1631                                 if(GetDebug() > 2 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped %s decay, label %d \n", 
1632                                                                                 primary->GetName(),iMother);
1633                         }
1634                                 
1635                         eMC    = primary->Energy();
1636                         ptMC   = primary->Pt();
1637                         phiMC  = primary->Phi();
1638                         etaMC  = primary->Eta();
1639                         pdg    = TMath::Abs(primary->GetPdgCode());
1640                         charge = (Int_t) TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
1641
1642                 }
1643                 else if(GetReader()->ReadAODMCParticles() && !GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCUnknown)){//it MC AOD and known tag
1644                         //Get the list of MC particles
1645                         if(!GetReader()->GetAODMCParticles(0))  {
1646                                 printf("AliAnaCalorimeterQA::ClusterHistograms() -  MCParticles not available!\n");
1647                                 abort();
1648                         }               
1649                         
1650                         aodprimary = (AliAODMCParticle*) (GetReader()->GetAODMCParticles(0))->At(label);
1651                         iMother = label;
1652                         pdg0    = TMath::Abs(aodprimary->GetPdgCode());
1653                         pdg     = pdg0;
1654                         status  = aodprimary->IsPrimary();
1655                         vxMC    = aodprimary->Xv();
1656                         vyMC    = aodprimary->Yv();
1657                         iParent = aodprimary->GetMother();
1658                                 
1659                         if(GetDebug() > 1 ) {
1660                                 printf("AliAnaCalorimeterQA::ClusterHistograms() - Cluster most contributing mother: \n");
1661                                 printf("\t Mother label %d, pdg %d, Primary? %d, Physical Primary? %d, parent %d \n",
1662                                            iMother, pdg0, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary(), iParent);
1663                         }
1664                         
1665                         //Get final particle, no conversion products
1666                         if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCConversion)){
1667                                 if(GetDebug() > 1 ) 
1668                                         printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted cluster!. Find before conversion: \n");
1669                                 //Get the parent
1670                                 aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iParent);
1671                                 pdg = TMath::Abs(aodprimary->GetPdgCode());
1672                                 while ((pdg == 22 || pdg == 11) && !aodprimary->IsPhysicalPrimary()) {
1673                                         iMother    = iParent;
1674                                         aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iMother);
1675                                         status     = aodprimary->IsPrimary();
1676                                         iParent    = aodprimary->GetMother();
1677                                         pdg        = TMath::Abs(aodprimary->GetPdgCode());
1678                                         if(GetDebug() > 1 )
1679                                                 printf("\t pdg %d, index %d, Primary? %d, Physical Primary? %d \n",
1680                                                                 pdg, iMother, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary());        
1681                                 }       
1682                                 
1683                                 if(GetDebug() > 1 ) {
1684                                         printf("AliAnaCalorimeterQA::ClusterHistograms() - Converted Cluster mother before conversion: \n");
1685                                         printf("\t Mother label %d, pdg %d, parent %d, Primary? %d, Physical Primary? %d \n",
1686                                                    iMother, pdg, iParent, aodprimary->IsPrimary(), aodprimary->IsPhysicalPrimary());
1687                                 }
1688                                 
1689                         }
1690                                 
1691                         //Overlapped pi0 (or eta, there will be very few), get the meson
1692                         if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1693                                 GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1694                                 if(GetDebug() > 1 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped Meson decay!, Find it: PDG %d, mom %d \n",pdg, iMother);
1695                                 while(pdg != 111 && pdg != 221){
1696                                         
1697                                         iMother    = iParent;
1698                                         aodprimary = (AliAODMCParticle*)(GetReader()->GetAODMCParticles(0))->At(iMother);
1699                                         status     = aodprimary->IsPrimary();
1700                                         iParent    = aodprimary->GetMother();
1701                                         pdg        = TMath::Abs(aodprimary->GetPdgCode());
1702
1703                                         if(GetDebug() > 1 ) printf("\t pdg %d, index %d\n",pdg, iMother);
1704                                         
1705                                         if(iMother==-1) {
1706                                                 printf("AliAnaCalorimeterQA::ClusterHistograms() - Tagged as Overlapped photon but meson not found, why?\n");
1707                                                 //break;
1708                                         }
1709                                 }       
1710                                 
1711                                 if(GetDebug() > 2 ) printf("AliAnaCalorimeterQA::ClusterHistograms() - Overlapped %s decay, label %d \n", 
1712                                                                                    aodprimary->GetName(),iMother);
1713                         }       
1714                                                 
1715                         status = aodprimary->IsPrimary();
1716                         eMC    = aodprimary->E();
1717                         ptMC   = aodprimary->Pt();
1718                         phiMC  = aodprimary->Phi();
1719                         etaMC  = aodprimary->Eta();
1720                         pdg    = TMath::Abs(aodprimary->GetPdgCode());
1721                         charge = aodprimary->Charge();
1722                                 
1723                 }
1724         
1725                 //Float_t vz = primary->Vz();
1726                 Float_t r = TMath::Sqrt(vxMC*vxMC + vyMC*vyMC);
1727                 if((pdg == 22 || TMath::Abs(pdg)==11) && status!=1) {
1728                         fhEMVxyz   ->Fill(vxMC,vyMC);//,vz);
1729                         fhEMR      ->Fill(e,r);
1730                 }
1731                     
1732                 //printf("reco e %f, pt %f, phi %f, eta %f \n", e, pt, phi, eta);
1733                 //printf("prim e %f, pt %f, phi %f, eta %f \n", eMC,ptMC,phiMC ,etaMC );
1734                 //printf("vertex: vx %f, vy %f, vz %f, r %f \n", vxMC, vyMC, vz, r);
1735                         
1736
1737                 fh2E      ->Fill(e, eMC);
1738                 fh2Pt     ->Fill(pt, ptMC);
1739                 fh2Phi    ->Fill(phi, phiMC);
1740                 fh2Eta    ->Fill(eta, etaMC);
1741                 fhDeltaE  ->Fill(eMC-e);
1742                 fhDeltaPt ->Fill(ptMC-pt);
1743                 fhDeltaPhi->Fill(phiMC-phi);
1744                 fhDeltaEta->Fill(etaMC-eta);
1745                 if(eMC   > 0) fhRatioE  ->Fill(e/eMC);
1746                 if(ptMC  > 0) fhRatioPt ->Fill(pt/ptMC);
1747                 if(phiMC > 0) fhRatioPhi->Fill(phi/phiMC);
1748                 if(etaMC > 0) fhRatioEta->Fill(eta/etaMC);                      
1749                         
1750                         
1751                 //Overlapped pi0 (or eta, there will be very few)
1752                 if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPi0) || 
1753                         GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCEta)){
1754                         //cout<<"Fill pi0"<< "E  "<< e <<" prim E "<<eMC<<endl;
1755                                 fhPi0E     ->Fill(e,eMC);       
1756                                 fhPi0Pt    ->Fill(pt,ptMC);
1757                                 fhPi0Eta   ->Fill(eta,etaMC);   
1758                                 fhPi0Phi   ->Fill(phi,phiMC);
1759                                 if( nTracksMatched > 0){
1760                                         fhPi0ECharged     ->Fill(e,eMC);                
1761                                         fhPi0PtCharged    ->Fill(pt,ptMC);
1762                                         fhPi0PhiCharged   ->Fill(phi,phiMC);
1763                                         fhPi0EtaCharged   ->Fill(eta,etaMC);
1764                                 }
1765                 }//Overlapped pizero decay
1766                 else if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCPhoton)){
1767                                 fhGamE     ->Fill(e,eMC);       
1768                                 fhGamPt    ->Fill(pt,ptMC);
1769                                 fhGamEta   ->Fill(eta,etaMC);   
1770                                 fhGamPhi   ->Fill(phi,phiMC);
1771                                 fhGamDeltaE  ->Fill(eMC-e);
1772                                 fhGamDeltaPt ->Fill(ptMC-pt);   
1773                                 fhGamDeltaPhi->Fill(phiMC-phi);
1774                                 fhGamDeltaEta->Fill(etaMC-eta);
1775                                 if(eMC > 0) fhGamRatioE  ->Fill(e/eMC);
1776                                 if(ptMC     > 0) fhGamRatioPt ->Fill(pt/ptMC);
1777                                 if(phiMC    > 0) fhGamRatioPhi->Fill(phi/phiMC);
1778                                 if(etaMC    > 0) fhGamRatioEta->Fill(eta/etaMC);
1779                                 if( nTracksMatched > 0){
1780                                         fhGamECharged     ->Fill(e,eMC);                
1781                                         fhGamPtCharged    ->Fill(pt,ptMC);
1782                                         fhGamPhiCharged   ->Fill(phi,phiMC);
1783                                         fhGamEtaCharged   ->Fill(eta,etaMC);
1784                                 }
1785                 }//photon
1786                 else if(GetMCAnalysisUtils()->CheckTagBit(tag, AliMCAnalysisUtils::kMCElectron)){
1787                         fhEleE     ->Fill(e,eMC);       
1788                         fhElePt    ->Fill(pt,ptMC);
1789                         fhEleEta   ->Fill(eta,etaMC);   
1790                         fhElePhi   ->Fill(phi,phiMC);
1791                         fhEMVxyz   ->Fill(vxMC,vyMC);//,vz);
1792                         fhEMR      ->Fill(e,r);
1793                         if( nTracksMatched > 0){
1794                                 fhEleECharged     ->Fill(e,eMC);                
1795                                 fhElePtCharged    ->Fill(pt,ptMC);
1796                                 fhElePhiCharged   ->Fill(phi,phiMC);
1797                                 fhEleEtaCharged   ->Fill(eta,etaMC);
1798                         }
1799                 }
1800                 else if(charge == 0){
1801                         fhNeHadE     ->Fill(e,eMC);     
1802                         fhNeHadPt    ->Fill(pt,ptMC);
1803                         fhNeHadEta   ->Fill(eta,etaMC); 
1804                         fhNeHadPhi   ->Fill(phi,phiMC); 
1805                         fhHaVxyz     ->Fill(vxMC,vyMC);//,vz);
1806                         fhHaR        ->Fill(e,r);
1807                         if( nTracksMatched > 0){
1808                                 fhNeHadECharged     ->Fill(e,eMC);              
1809                                 fhNeHadPtCharged    ->Fill(pt,ptMC);
1810                                 fhNeHadPhiCharged   ->Fill(phi,phiMC);
1811                                 fhNeHadEtaCharged   ->Fill(eta,etaMC);
1812                         }
1813                 }
1814                 else if(charge!=0){
1815                         fhChHadE     ->Fill(e,eMC);     
1816                         fhChHadPt    ->Fill(pt,ptMC);
1817                         fhChHadEta   ->Fill(eta,etaMC); 
1818                         fhChHadPhi   ->Fill(phi,phiMC); 
1819                         fhHaVxyz     ->Fill(vxMC,vyMC);//,vz);
1820                         fhHaR        ->Fill(e,r);
1821                         if( nTracksMatched > 0){
1822                                 fhChHadECharged     ->Fill(e,eMC);              
1823                                 fhChHadPtCharged    ->Fill(pt,ptMC);
1824                                 fhChHadPhiCharged   ->Fill(phi,phiMC);
1825                                 fhChHadEtaCharged   ->Fill(eta,etaMC);
1826                         }
1827                 }
1828         }//Work with MC
1829                 
1830         
1831         //Match tracks and clusters
1832         //To be Modified in case of AODs
1833         
1834         //if(ntracksmatched==1 && trackIndex==-1) ntracksmatched=0;
1835         
1836         if( nTracksMatched > 0){
1837                 fhECharged     ->Fill(e);               
1838                 fhPtCharged    ->Fill(pt);
1839                 fhPhiCharged   ->Fill(phi);
1840                 fhEtaCharged   ->Fill(eta);
1841                 fhEtaPhiCharged->Fill(eta,phi);         
1842                 
1843                 //printf("track index %d ntracks %d\n", esd->GetNumberOfTracks());      
1844                 //Study the track and matched cluster if track exists.
1845                 if(!track) return;
1846                 Double_t emcpos[3] = {0.,0.,0.};
1847                 Double_t emcmom[3] = {0.,0.,0.};
1848                 Double_t radius    = 441.0; //[cm] EMCAL radius +13cm
1849                 Double_t bfield    = 0.;
1850                 Double_t tphi      = 0;
1851                 Double_t teta      = 0;
1852                 Double_t tmom      = 0;
1853                 Double_t tpt       = 0;
1854                 Double_t tmom2     = 0;
1855                 Double_t tpcSignal = 0;
1856                 Bool_t okpos = kFALSE;
1857                 Bool_t okmom = kFALSE;
1858                 Bool_t okout = kFALSE;
1859                 Int_t nITS   = 0;
1860                 Int_t nTPC   = 0;
1861                 
1862                 //In case of ESDs get the parameters in this way
1863                 if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
1864                         if (((AliESDtrack*)track)->GetOuterParam() ) {
1865                                 okout = kTRUE;
1866                                 
1867                                 bfield = ((AliESDEvent*)GetReader()->GetInputEvent())->GetMagneticField();
1868                                 okpos = ((AliESDtrack*)track)->GetOuterParam()->GetXYZAt(radius,bfield,emcpos);
1869                                 okmom = ((AliESDtrack*)track)->GetOuterParam()->GetPxPyPzAt(radius,bfield,emcmom);
1870                                 if(!(okpos && okmom)) return;
1871
1872                                 TVector3 position(emcpos[0],emcpos[1],emcpos[2]);
1873                                 TVector3 momentum(emcmom[0],emcmom[1],emcmom[2]);
1874                                 tphi = position.Phi();
1875                                 teta = position.Eta();
1876                                 tmom = momentum.Mag();
1877                                 
1878                                 //Double_t tphi  = ((AliESDtrack*)track)->GetOuterParam()->Phi();
1879                                 //Double_t teta  = ((AliESDtrack*)track)->GetOuterParam()->Eta();
1880                                 //Double_t tmom  = ((AliESDtrack*)track)->GetOuterParam()->P();
1881                                 tpt       = ((AliESDtrack*)track)->Pt();
1882                                 tmom2     = ((AliESDtrack*)track)->P();
1883                                 tpcSignal = ((AliESDtrack*)track)->GetTPCsignal();
1884                                 
1885                                 nITS = ((AliESDtrack*)track)->GetNcls(0);
1886                                 nTPC = ((AliESDtrack*)track)->GetNcls(1);
1887                                 }//Outer param available 
1888                         }// ESDs
1889                         else if(GetReader()->GetDataType()==AliCaloTrackReader::kAOD) {
1890                                 AliAODPid* pid = (AliAODPid*) ((AliAODTrack *) track)->GetDetPid();
1891                                 if (pid) {
1892                                         okout = kTRUE;
1893                                         pid->GetEMCALPosition(emcpos);
1894                                         pid->GetEMCALMomentum(emcmom);  
1895                                         
1896                                         TVector3 position(emcpos[0],emcpos[1],emcpos[2]);
1897                                         TVector3 momentum(emcmom[0],emcmom[1],emcmom[2]);
1898                                         tphi = position.Phi();
1899                                         teta = position.Eta();
1900                                         tmom = momentum.Mag();
1901                                         
1902                                         tpt       = ((AliAODTrack*)track)->Pt();
1903                                         tmom2     = ((AliAODTrack*)track)->P();
1904                                         tpcSignal = pid->GetTPCsignal();
1905                                 
1906                                         //nITS = ((AliAODTrack*)track)->GetNcls(0);
1907                                         //nTPC = ((AliAODTrack*)track)->GetNcls(1);
1908                                 }//Outer param available 
1909                         }//AODs
1910                         else return; //Do nothing case not implemented.
1911                 
1912                         if(okout){
1913                                 Double_t deta = teta - eta;
1914                                 Double_t dphi = tphi - phi;
1915                                 if(dphi > TMath::Pi()) dphi -= 2*TMath::Pi();
1916                                 if(dphi < -TMath::Pi()) dphi += 2*TMath::Pi();
1917                                 Double_t dR = sqrt(dphi*dphi + deta*deta);
1918                         
1919                                 Double_t pOverE = tmom/e;
1920                         
1921                                 fh1pOverE->Fill(tpt, pOverE);
1922                                 if(dR < 0.02) fh1pOverER02->Fill(tpt,pOverE);
1923                         
1924                                 fh1dR->Fill(dR);
1925                                 fh2MatchdEdx->Fill(tmom2,tpcSignal);
1926                         
1927                                 if(IsDataMC() && primary){ 
1928                                         Int_t pdg = primary->GetPdgCode();
1929                                         Double_t  charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
1930                                 
1931                                         if(TMath::Abs(pdg) == 11){
1932                                                 fhMCEle1pOverE->Fill(tpt,pOverE);
1933                                                 fhMCEle1dR->Fill(dR);
1934                                                 fhMCEle2MatchdEdx->Fill(tmom2,tpcSignal);               
1935                                                 if(dR < 0.02) fhMCEle1pOverER02->Fill(tpt,pOverE);
1936                                         }
1937                                         else if(charge!=0){
1938                                                 fhMCChHad1pOverE->Fill(tpt,pOverE);
1939                                                 fhMCChHad1dR->Fill(dR);
1940                                                 fhMCChHad2MatchdEdx->Fill(tmom2,tpcSignal);     
1941                                                 if(dR < 0.02) fhMCChHad1pOverER02->Fill(tpt,pOverE);
1942                                         }
1943                                         else if(charge == 0){
1944                                                 fhMCNeutral1pOverE->Fill(tpt,pOverE);
1945                                                 fhMCNeutral1dR->Fill(dR);
1946                                                 fhMCNeutral2MatchdEdx->Fill(tmom2,tpcSignal);   
1947                                                 if(dR < 0.02) fhMCNeutral1pOverER02->Fill(tpt,pOverE);
1948                                         }
1949                                 }//DataMC
1950
1951                                 if(dR < 0.02 && pOverE > 0.5 && pOverE < 1.5
1952                                    && nCaloCellsPerCluster > 1 && nITS > 3 && nTPC > 20) {
1953                                         fh2EledEdx->Fill(tmom2,tpcSignal);
1954                                 }
1955                         }
1956                         else{//no ESD external param or AODPid
1957                                         ULong_t status=AliESDtrack::kTPCrefit;
1958                                 status|=AliESDtrack::kITSrefit;
1959                                 //printf("track status %d\n", track->GetStatus() );
1960                                 fhEChargedNoOut      ->Fill(e);         
1961                                 fhPtChargedNoOut     ->Fill(pt);
1962                                 fhPhiChargedNoOut    ->Fill(phi);
1963                                 fhEtaChargedNoOut    ->Fill(eta);
1964                                 fhEtaPhiChargedNoOut ->Fill(eta,phi);   
1965                                 if(GetDebug() >= 0 && ((((AliESDtrack*)track)->GetStatus() & status) == status)) printf("ITS+TPC\n");
1966                         }//No out params
1967         }//matched clusters with tracks
1968         
1969 }// Clusters
1970         
1971 //__________________________________
1972 void AliAnaCalorimeterQA::CorrelateCalorimeters(TRefArray* refArray){
1973         // Correlate information from PHOS and EMCAL
1974         TRefArray * caloClustersEMCAL = new TRefArray;
1975         TRefArray * caloClustersPHOS  = new TRefArray;
1976         
1977         // Get once the array of clusters per calorimeter, avoid an extra loop.
1978         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
1979                 if(fCalorimeter == "EMCAL"){ 
1980                         ((AliESDEvent*)GetReader()->GetInputEvent())->GetPHOSClusters(caloClustersPHOS);
1981                         caloClustersEMCAL = refArray;
1982                 }
1983                 else if(fCalorimeter == "PHOS") { 
1984                         ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALClusters (caloClustersEMCAL);
1985                         caloClustersEMCAL = refArray;
1986                 }
1987                 
1988                 //Fill histograms with clusters
1989                 
1990                 fhCaloCorrNClusters->Fill(caloClustersEMCAL->GetEntriesFast(),caloClustersPHOS->GetEntriesFast());
1991                 Float_t sumClusterEnergyEMCAL = 0;
1992                 Float_t sumClusterEnergyPHOS  = 0;
1993                 Int_t iclus = 0;
1994                 for(iclus = 0 ; iclus <  caloClustersEMCAL->GetEntriesFast() ; iclus++) 
1995                                 sumClusterEnergyEMCAL += ((AliESDCaloCluster*) (caloClustersEMCAL->At(iclus)))->E();
1996                 for(iclus = 0 ; iclus <  caloClustersPHOS->GetEntriesFast(); iclus++) 
1997                         sumClusterEnergyPHOS += ((AliESDCaloCluster*) (caloClustersPHOS->At(iclus)))->E();
1998                 fhCaloCorrEClusters->Fill(sumClusterEnergyEMCAL,sumClusterEnergyPHOS);
1999                 
2000                 //Fill histograms with cells
2001                 
2002                 AliESDCaloCells * cellsEMCAL = ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
2003                 AliESDCaloCells * cellsPHOS  = ((AliESDEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
2004                 fhCaloCorrNCells   ->Fill(cellsEMCAL->GetNumberOfCells(),cellsPHOS->GetNumberOfCells());
2005                 
2006                 Int_t icell = 0;
2007                 Float_t sumCellEnergyEMCAL = 0;
2008                 Float_t sumCellEnergyPHOS  = 0;
2009                 for(icell = 0 ; icell < cellsEMCAL->GetNumberOfCells()  ; icell++) 
2010                         sumCellEnergyEMCAL += cellsEMCAL->GetAmplitude(icell);
2011                 for(icell = 0 ; icell <  cellsPHOS->GetNumberOfCells(); icell++) 
2012                         sumCellEnergyPHOS += cellsPHOS->GetAmplitude(icell);
2013                 fhCaloCorrECells->Fill(sumCellEnergyEMCAL,sumCellEnergyPHOS);
2014                 if(GetDebug() > 0 ){
2015                         printf("AliAnaCalorimeterQA::CorrelateCalorimeters() - ESD: \n");
2016                         printf("\t EMCAL: N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2017                                    cellsEMCAL->GetNumberOfCells(),caloClustersEMCAL->GetEntriesFast(),sumCellEnergyEMCAL,sumClusterEnergyEMCAL);
2018                         printf("\t PHOS : N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2019                                    cellsPHOS->GetNumberOfCells(),caloClustersPHOS->GetEntriesFast(),sumCellEnergyPHOS,sumClusterEnergyPHOS);
2020                 }
2021         }//ESD
2022         else if(GetReader()->GetDataType()==AliCaloTrackReader::kAOD) {
2023                 if(fCalorimeter == "EMCAL"){ 
2024                         ((AliAODEvent*)GetReader()->GetInputEvent())->GetPHOSClusters(caloClustersPHOS);
2025                         caloClustersEMCAL = refArray;
2026                 }
2027                 else if(fCalorimeter == "PHOS") { 
2028                         ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALClusters (caloClustersEMCAL);
2029                         caloClustersEMCAL = refArray;
2030                 }
2031                 
2032                 //Fill histograms with clusters
2033                 
2034                 fhCaloCorrNClusters->Fill(caloClustersEMCAL->GetEntriesFast(),caloClustersPHOS->GetEntriesFast());
2035                 Float_t sumClusterEnergyEMCAL = 0;
2036                 Float_t sumClusterEnergyPHOS  = 0;
2037                 Int_t iclus = 0;
2038                 for(iclus = 0 ; iclus <  caloClustersEMCAL->GetEntriesFast() ; iclus++) 
2039                         sumClusterEnergyEMCAL += ((AliAODCaloCluster*) (caloClustersEMCAL->At(iclus)))->E();
2040                 for(iclus = 0 ; iclus <  caloClustersPHOS->GetEntriesFast(); iclus++) 
2041                         sumClusterEnergyPHOS += ((AliAODCaloCluster*) (caloClustersPHOS->At(iclus)))->E();
2042                 fhCaloCorrEClusters->Fill(sumClusterEnergyEMCAL,sumClusterEnergyPHOS);
2043                 
2044                 //Fill histograms with cells
2045                 
2046                 AliAODCaloCells * cellsEMCAL = ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
2047                 AliAODCaloCells * cellsPHOS  = ((AliAODEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
2048                 fhCaloCorrNCells   ->Fill(cellsEMCAL->GetNumberOfCells(),cellsPHOS->GetNumberOfCells());
2049                 
2050                 Int_t icell = 0;
2051                 Float_t sumCellEnergyEMCAL = 0;
2052                 Float_t sumCellEnergyPHOS  = 0;
2053                 for(icell = 0 ; icell < cellsEMCAL->GetNumberOfCells()  ; icell++) 
2054                         sumCellEnergyEMCAL += cellsEMCAL->GetAmplitude(icell);
2055                 for(icell = 0 ; icell <  cellsPHOS->GetNumberOfCells(); icell++) 
2056                         sumCellEnergyPHOS += cellsPHOS->GetAmplitude(icell);
2057                 fhCaloCorrECells->Fill(sumCellEnergyEMCAL,sumCellEnergyPHOS);           
2058                 if(GetDebug() > 0 ){
2059                         printf("AliAnaCalorimeterQA::CorrelateCalorimeters() - ESD: \n");
2060                         printf("\t EMCAL: N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2061                                    cellsEMCAL->GetNumberOfCells(),caloClustersEMCAL->GetEntriesFast(),sumCellEnergyEMCAL,sumClusterEnergyEMCAL);
2062                         printf("\t PHOS : N cells %d, N clusters  %d, summed E cells %f, summed E clusters %f \n",
2063                                    cellsPHOS->GetNumberOfCells(),caloClustersPHOS->GetEntriesFast(),sumCellEnergyPHOS,sumClusterEnergyPHOS);
2064                 }
2065         }//AOD  
2066         
2067 }
2068
2069 //______________________________________________________________________________
2070 void AliAnaCalorimeterQA::MCHistograms(const TLorentzVector mom, const Int_t pdg){
2071         //Fill pure monte carlo related histograms
2072         
2073         Float_t eMC    = mom.E();
2074         Float_t ptMC   = mom.Pt();
2075         Float_t phiMC  = mom.Phi();
2076         if(phiMC < 0) 
2077                 phiMC  += TMath::TwoPi();
2078         Float_t etaMC  = mom.Eta();
2079         
2080         if (TMath::Abs(etaMC) > 1) return;
2081
2082         Bool_t in = kTRUE;
2083         if(IsFiducialCutOn()) in =  GetFiducialCut()->IsInFiducialCut(mom,fCalorimeter) ;
2084         
2085         if (pdg==22) {
2086                 fhGenGamPt ->Fill(ptMC);
2087                 fhGenGamEta->Fill(etaMC);
2088                 fhGenGamPhi->Fill(phiMC);
2089                 if(in){
2090                         fhGenGamAccE  ->Fill(eMC);
2091                         fhGenGamAccPt ->Fill(ptMC);
2092                         fhGenGamAccEta->Fill(etaMC);
2093                         fhGenGamAccPhi->Fill(phiMC);                                    
2094                 }
2095         }
2096         else if (pdg==111) {
2097                 fhGenPi0Pt ->Fill(ptMC);
2098                 fhGenPi0Eta->Fill(etaMC);
2099                 fhGenPi0Phi->Fill(phiMC);
2100                 if(in){
2101                         fhGenPi0AccE  ->Fill(eMC);                                      
2102                         fhGenPi0AccPt ->Fill(ptMC);
2103                         fhGenPi0AccEta->Fill(etaMC);
2104                         fhGenPi0AccPhi->Fill(phiMC);                                    
2105                 }
2106         }
2107         else if (pdg==221) {
2108                 fhGenEtaPt ->Fill(ptMC);
2109                 fhGenEtaEta->Fill(etaMC);
2110                 fhGenEtaPhi->Fill(phiMC);
2111         }
2112         else if (pdg==223) {
2113                 fhGenOmegaPt ->Fill(ptMC);
2114                 fhGenOmegaEta->Fill(etaMC);
2115                 fhGenOmegaPhi->Fill(phiMC);
2116         }
2117         else if (TMath::Abs(pdg)==11) {
2118                 fhGenElePt ->Fill(ptMC);
2119                 fhGenEleEta->Fill(etaMC);
2120                 fhGenElePhi->Fill(phiMC);
2121         }       
2122         
2123 }
2124         
2125 //________________________________________________________________________
2126 void AliAnaCalorimeterQA::ReadHistograms(TList* outputList)
2127 {
2128         // Needed when Terminate is executed in distributed environment
2129         // Refill analysis histograms of this class with corresponding histograms in output list. 
2130         
2131         // Histograms of this analsys are kept in the same list as other analysis, recover the position of
2132         // the first one and then add the next 
2133         Int_t index = outputList->IndexOf(outputList->FindObject(GetAddedHistogramsStringToName()+"hE"));
2134         printf("Calo: %s, index: %d, nmodules %d\n",fCalorimeter.Data(),index,fNModules);
2135         
2136         //Read histograms, must be in the same order as in GetCreateOutputObject.
2137         fhE       = (TH1F *) outputList->At(index++);   
2138         fhPt      = (TH1F *) outputList->At(index++); 
2139         fhPhi     = (TH1F *) outputList->At(index++); 
2140         fhEta     = (TH1F *) outputList->At(index++);
2141         fhEtaPhi  = (TH2F *) outputList->At(index++);
2142         fhEtaPhiE = (TH3F *) outputList->At(index++);
2143         
2144         fhECharged      = (TH1F *) outputList->At(index++);     
2145         fhPtCharged     = (TH1F *) outputList->At(index++); 
2146         fhPhiCharged    = (TH1F *) outputList->At(index++); 
2147         fhEtaCharged    = (TH1F *) outputList->At(index++);
2148         fhEtaPhiCharged = (TH2F *) outputList->At(index++);
2149         
2150         fhEChargedNoOut      = (TH1F *) outputList->At(index++);        
2151         fhPtChargedNoOut     = (TH1F *) outputList->At(index++); 
2152         fhPhiChargedNoOut    = (TH1F *) outputList->At(index++); 
2153         fhEtaChargedNoOut    = (TH1F *) outputList->At(index++);
2154         fhEtaPhiChargedNoOut = (TH2F *) outputList->At(index++);
2155
2156         fh1pOverE =    (TH2F *) outputList->At(index++);
2157         fh1dR =        (TH1F *) outputList->At(index++);
2158         fh2MatchdEdx = (TH2F *) outputList->At(index++);
2159         fh2EledEdx =   (TH2F *) outputList->At(index++);
2160         fh1pOverER02 = (TH2F *) outputList->At(index++);
2161         
2162         fhIM        = (TH2F *) outputList->At(index++);
2163         fhIMCellCut = (TH2F *) outputList->At(index++);
2164         fhAsym      = (TH2F *) outputList->At(index++);
2165         
2166         fhNCellsPerCluster    = (TH2F *) outputList->At(index++);
2167         fhNCellsPerClusterMIP = (TH2F *) outputList->At(index++);
2168         fhNClusters  = (TH1F *) outputList->At(index++); 
2169         fhNCells     = (TH1F *) outputList->At(index++); 
2170         fhAmplitude  = (TH1F *) outputList->At(index++); 
2171         fhAmpId      = (TH2F *) outputList->At(index++); 
2172
2173         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
2174                 fhTime       = (TH1F *) outputList->At(index++); 
2175                 fhTimeId     = (TH2F *) outputList->At(index++); 
2176                 fhTimeAmp    = (TH2F *) outputList->At(index++); 
2177         }
2178         
2179         if(fCorrelateCalos){
2180                 fhCaloCorrNClusters = (TH2F *) outputList->At(index++);
2181                 fhCaloCorrEClusters = (TH2F *) outputList->At(index++); 
2182                 fhCaloCorrNCells    = (TH2F *) outputList->At(index++); 
2183                 fhCaloCorrECells    = (TH2F *) outputList->At(index++); 
2184         }
2185         
2186         //Module histograms
2187         fhEMod                = new TH1F*[fNModules];
2188         fhNClustersMod        = new TH1F*[fNModules];
2189         fhNCellsPerClusterMod = new TH2F*[fNModules];
2190         fhNCellsMod           = new TH1F*[fNModules];
2191         fhGridCellsMod        = new TH2F*[fNModules];
2192         fhGridCellsEMod       = new TH2F*[fNModules];
2193         fhAmplitudeMod        = new TH1F*[fNModules];
2194         fhIMMod               = new TH2F*[fNModules];
2195         fhIMCellCutMod        = new TH2F*[fNModules];
2196                 
2197         for(Int_t imod = 0 ; imod < fNModules; imod++){
2198                 fhEMod[imod]                = (TH1F *) outputList->At(index++);
2199                 fhNClustersMod[imod]        = (TH1F *) outputList->At(index++); 
2200                 fhNCellsPerClusterMod[imod] = (TH2F *) outputList->At(index++); 
2201                 fhNCellsMod[imod]           = (TH1F *) outputList->At(index++);         
2202                 fhGridCellsMod[imod]        = (TH2F *) outputList->At(index++);
2203                 fhGridCellsEMod[imod]       = (TH2F *) outputList->At(index++); 
2204                 fhAmplitudeMod[imod]        = (TH1F *) outputList->At(index++); 
2205                 fhIMMod[imod]               = (TH2F *) outputList->At(index++); 
2206                 fhIMCellCutMod[imod]        = (TH2F *) outputList->At(index++);         
2207
2208         }
2209         
2210         if(IsDataMC()){
2211                 fhDeltaE   = (TH1F *) outputList->At(index++); 
2212                 fhDeltaPt  = (TH1F *) outputList->At(index++); 
2213                 fhDeltaPhi = (TH1F *) outputList->At(index++); 
2214                 fhDeltaEta = (TH1F *) outputList->At(index++); 
2215                 
2216                 fhRatioE   = (TH1F *) outputList->At(index++); 
2217                 fhRatioPt  = (TH1F *) outputList->At(index++); 
2218                 fhRatioPhi = (TH1F *) outputList->At(index++); 
2219                 fhRatioEta = (TH1F *) outputList->At(index++); 
2220                 
2221                 fh2E       = (TH2F *) outputList->At(index++); 
2222                 fh2Pt      = (TH2F *) outputList->At(index++); 
2223                 fh2Phi     = (TH2F *) outputList->At(index++); 
2224                 fh2Eta     = (TH2F *) outputList->At(index++); 
2225                 
2226                 fhGamE     = (TH2F *) outputList->At(index++); 
2227                 fhGamPt    = (TH2F *) outputList->At(index++); 
2228                 fhGamPhi   = (TH2F *) outputList->At(index++); 
2229                 fhGamEta   = (TH2F *) outputList->At(index++); 
2230                 
2231                 fhGamDeltaE   = (TH1F *) outputList->At(index++); 
2232                 fhGamDeltaPt  = (TH1F *) outputList->At(index++); 
2233                 fhGamDeltaPhi = (TH1F *) outputList->At(index++); 
2234                 fhGamDeltaEta = (TH1F *) outputList->At(index++); 
2235                 
2236                 fhGamRatioE   = (TH1F *) outputList->At(index++); 
2237                 fhGamRatioPt  = (TH1F *) outputList->At(index++); 
2238                 fhGamRatioPhi = (TH1F *) outputList->At(index++); 
2239                 fhGamRatioEta = (TH1F *) outputList->At(index++); 
2240
2241                 fhPi0E     = (TH2F *) outputList->At(index++); 
2242                 fhPi0Pt    = (TH2F *) outputList->At(index++); 
2243                 fhPi0Phi   = (TH2F *) outputList->At(index++); 
2244                 fhPi0Eta   = (TH2F *) outputList->At(index++);          
2245                 
2246                 fhEleE     = (TH2F *) outputList->At(index++); 
2247                 fhElePt    = (TH2F *) outputList->At(index++); 
2248                 fhElePhi   = (TH2F *) outputList->At(index++); 
2249                 fhEleEta   = (TH2F *) outputList->At(index++);          
2250                 
2251                 fhNeHadE     = (TH2F *) outputList->At(index++); 
2252                 fhNeHadPt    = (TH2F *) outputList->At(index++); 
2253                 fhNeHadPhi   = (TH2F *) outputList->At(index++); 
2254                 fhNeHadEta   = (TH2F *) outputList->At(index++);                
2255                 
2256                 fhChHadE     = (TH2F *) outputList->At(index++); 
2257                 fhChHadPt    = (TH2F *) outputList->At(index++); 
2258                 fhChHadPhi   = (TH2F *) outputList->At(index++); 
2259                 fhChHadEta   = (TH2F *) outputList->At(index++);                                
2260                 
2261                 fhGamECharged     = (TH2F *) outputList->At(index++); 
2262                 fhGamPtCharged    = (TH2F *) outputList->At(index++); 
2263                 fhGamPhiCharged   = (TH2F *) outputList->At(index++); 
2264                 fhGamEtaCharged   = (TH2F *) outputList->At(index++); 
2265                                 
2266                 fhPi0ECharged     = (TH2F *) outputList->At(index++); 
2267                 fhPi0PtCharged    = (TH2F *) outputList->At(index++); 
2268                 fhPi0PhiCharged   = (TH2F *) outputList->At(index++); 
2269                 fhPi0EtaCharged   = (TH2F *) outputList->At(index++);           
2270                 
2271                 fhEleECharged     = (TH2F *) outputList->At(index++); 
2272                 fhElePtCharged    = (TH2F *) outputList->At(index++); 
2273                 fhElePhiCharged   = (TH2F *) outputList->At(index++); 
2274                 fhEleEtaCharged   = (TH2F *) outputList->At(index++);           
2275                 
2276                 fhNeHadECharged     = (TH2F *) outputList->At(index++); 
2277                 fhNeHadPtCharged    = (TH2F *) outputList->At(index++); 
2278                 fhNeHadPhiCharged   = (TH2F *) outputList->At(index++); 
2279                 fhNeHadEtaCharged   = (TH2F *) outputList->At(index++);                 
2280                 
2281                 fhChHadECharged     = (TH2F *) outputList->At(index++); 
2282                 fhChHadPtCharged    = (TH2F *) outputList->At(index++); 
2283                 fhChHadPhiCharged   = (TH2F *) outputList->At(index++); 
2284                 fhChHadEtaCharged   = (TH2F *) outputList->At(index++);                                 
2285                 
2286 //              fhEMVxyz     = (TH3F *) outputList->At(index++); 
2287 //              fhHaVxyz     = (TH3F *) outputList->At(index++); 
2288                 
2289                 fhEMVxyz     = (TH2F *) outputList->At(index++); 
2290                 fhHaVxyz     = (TH2F *) outputList->At(index++); 
2291                 fhEMR        = (TH2F *) outputList->At(index++); 
2292                 fhHaR        = (TH2F *) outputList->At(index++); 
2293                 
2294                 fhGenGamPt    = (TH1F *) outputList->At(index++); 
2295                 fhGenGamEta   = (TH1F *) outputList->At(index++); 
2296                 fhGenGamPhi   = (TH1F *) outputList->At(index++); 
2297                 
2298                 fhGenPi0Pt    = (TH1F *) outputList->At(index++); 
2299                 fhGenPi0Eta   = (TH1F *) outputList->At(index++); 
2300                 fhGenPi0Phi   = (TH1F *) outputList->At(index++); 
2301                 
2302                 fhGenEtaPt    = (TH1F *) outputList->At(index++); 
2303                 fhGenEtaEta   = (TH1F *) outputList->At(index++); 
2304                 fhGenEtaPhi   = (TH1F *) outputList->At(index++); 
2305                 
2306                 fhGenOmegaPt  = (TH1F *) outputList->At(index++); 
2307                 fhGenOmegaEta = (TH1F *) outputList->At(index++); 
2308                 fhGenOmegaPhi = (TH1F *) outputList->At(index++); 
2309                 
2310                 fhGenElePt    = (TH1F *) outputList->At(index++); 
2311                 fhGenEleEta   = (TH1F *) outputList->At(index++); 
2312                 fhGenElePhi   = (TH1F *) outputList->At(index++); 
2313                 
2314                 fhGenGamAccE   = (TH1F *) outputList->At(index++);              
2315                 fhGenGamAccPt  = (TH1F *) outputList->At(index++); 
2316                 fhGenGamAccEta = (TH1F *) outputList->At(index++); 
2317                 fhGenGamAccPhi = (TH1F *) outputList->At(index++); 
2318                 
2319                 fhGenPi0AccE   = (TH1F *) outputList->At(index++);              
2320                 fhGenPi0AccPt  = (TH1F *) outputList->At(index++); 
2321                 fhGenPi0AccEta = (TH1F *) outputList->At(index++); 
2322                 fhGenPi0AccPhi = (TH1F *) outputList->At(index++); 
2323                 
2324                 fhMCEle1pOverE =    (TH2F *) outputList->At(index++);
2325                 fhMCEle1dR =        (TH1F *) outputList->At(index++);
2326                 fhMCEle2MatchdEdx = (TH2F *) outputList->At(index++);
2327                 
2328                 fhMCChHad1pOverE =    (TH2F *) outputList->At(index++);
2329                 fhMCChHad1dR =        (TH1F *) outputList->At(index++);
2330                 fhMCChHad2MatchdEdx = (TH2F *) outputList->At(index++);
2331                 
2332                 fhMCNeutral1pOverE    = (TH2F *) outputList->At(index++);
2333                 fhMCNeutral1dR        = (TH1F *) outputList->At(index++);
2334                 fhMCNeutral2MatchdEdx = (TH2F *) outputList->At(index++);
2335                 
2336                 fhMCEle1pOverER02     =    (TH2F *) outputList->At(index++);
2337                 fhMCChHad1pOverER02   =    (TH2F *) outputList->At(index++);
2338                 fhMCNeutral1pOverER02 =    (TH2F *) outputList->At(index++);
2339         }
2340         //for(Int_t i = 0;  i<index ; i++) cout<<outputList->At(i)->GetName()<<endl;
2341 }
2342
2343 //__________________________________________________________________
2344 void  AliAnaCalorimeterQA::Terminate(TList* outputList) 
2345 {
2346         //Do plots if requested 
2347
2348         if(GetDebug() > 0) printf("AliAnaCalorimeterQA::Terminate() - Make plots for %s? %d\n",fCalorimeter.Data(), fMakePlots);
2349         if(!fMakePlots) return;
2350         
2351         //Do some plots to end
2352          if(fStyleMacro!="")gROOT->Macro(fStyleMacro); 
2353         //Recover histograms from output histograms list, needed for distributed analysis.      
2354         ReadHistograms(outputList);
2355         
2356         printf(" AliAnaCalorimeterQA::Terminate()  *** %s Report:", GetName()) ; 
2357         printf(" AliAnaCalorimeterQA::Terminate()        pt         : %5.3f , RMS : %5.3f \n", fhPt->GetMean(),   fhPt->GetRMS() ) ;
2358
2359         char name[128];
2360         char cname[128];
2361                 
2362         //CaloCells
2363         //printf("c9\n");
2364         sprintf(cname,"QA_%s_nclustercellsamp",fCalorimeter.Data());
2365         TCanvas  * c9 = new TCanvas(cname, " CaloClusters and CaloCells", 400, 400) ;
2366         c9->Divide(2, 2);
2367         
2368         c9->cd(1) ; 
2369         
2370         TLegend pLegendN(0.7,0.6,0.9,0.8);
2371         pLegendN.SetTextSize(0.03);
2372         pLegendN.AddEntry(fhNClusters,"all modules","L");
2373         pLegendN.SetFillColor(10);
2374         pLegendN.SetBorderSize(1);
2375         
2376         if(fhNClusters->GetEntries() > 0) gPad->SetLogy();
2377         gPad->SetLogx();
2378         fhNClusters->SetLineColor(1);
2379         fhNClusters->Draw();
2380         for(Int_t imod = 0; imod < fNModules; imod++){
2381                 fhNClustersMod[imod]->SetLineColor(imod+1);
2382                 fhNClustersMod[imod]->Draw("same");
2383                 pLegendN.AddEntry(fhNClustersMod[imod],Form("module %d",imod),"L");
2384         }
2385         pLegendN.Draw();
2386
2387         c9->cd(2) ; 
2388         if(fhNCells->GetEntries() > 0) gPad->SetLogy();
2389         gPad->SetLogx();
2390         fhNCells->SetLineColor(1);
2391         fhNCells->Draw();
2392         for(Int_t imod = 0; imod < fNModules; imod++){
2393                 fhNCellsMod[imod]->SetLineColor(imod+1);
2394                 fhNCellsMod[imod]->Draw("same");
2395         }
2396         c9->cd(3) ; 
2397         if(fhNCellsPerCluster->GetEntries() > 0) gPad->SetLogy();
2398         gPad->SetLogx();
2399         TH1D *cpc = fhNCellsPerCluster->ProjectionY(Form("%s_py",fhNCellsPerCluster->GetName()),-1,-1);
2400         cpc->SetLineColor(1);
2401         cpc->Draw();
2402         for(Int_t imod = 0; imod < fNModules; imod++){
2403                 cpc = fhNCellsPerClusterMod[imod]->ProjectionY(Form("%s_py",fhNCellsPerClusterMod[imod]->GetName()),-1,-1);
2404                 cpc->SetLineColor(imod+1);
2405                 cpc->Draw("same");
2406         }
2407         
2408         c9->cd(4) ; 
2409         if(fhAmplitude->GetEntries() > 0) gPad->SetLogy();
2410         gPad->SetLogx();
2411         fhAmplitude->SetLineColor(1);
2412         fhAmplitude->Draw();
2413         for(Int_t imod = 0; imod < fNModules; imod++){
2414                 fhAmplitudeMod[imod]->SetLineColor(imod+1);
2415                 fhAmplitudeMod[imod]->Draw("same");
2416         }
2417         
2418         sprintf(name,"QA_%s_CaloClustersAndCaloCells.eps",fCalorimeter.Data());
2419         c9->Print(name); printf("Plot: %s\n",name);
2420         
2421         //Cell Time histograms, time only available in ESDs
2422         if(GetReader()->GetDataType()==AliCaloTrackReader::kESD) {
2423
2424                 sprintf(cname,"QA_%s_cellstime",fCalorimeter.Data());
2425                 TCanvas  * ctime = new TCanvas(cname, " Cells time", 1200, 400) ;
2426                 ctime->Divide(3, 1);
2427         
2428                 ctime->cd(1) ; 
2429                 if(fhTime->GetEntries() > 0) gPad->SetLogy();
2430                 fhTime->Draw();
2431         
2432                 ctime->cd(2) ; 
2433                 //if(fhTimeId->GetEntries() > 0) gPad->SetLogy();
2434                 fhTimeId->Draw("colz");
2435         
2436                 ctime->cd(3) ; 
2437                 //if(fhTimeAmp->GetEntries() > 0) gPad->SetLogy();
2438                 fhTimeAmp->Draw("surf");
2439         
2440                 sprintf(name,"QA_%s_CellsTime.eps",fCalorimeter.Data());
2441                 ctime->Print(name); printf("Plot: %s\n",name);
2442         }
2443         
2444         if(fCorrelateCalos){
2445                 //Calorimeter Correlation, PHOS vs EMCAL
2446                 //printf("c9\n");
2447                 sprintf(cname,"QA_%s_CaloCorr_EMCALvsPHOS",fCalorimeter.Data());
2448                 TCanvas  * ccorr = new TCanvas(cname, " EMCAL vs PHOS", 400, 400) ;
2449                 ccorr->Divide(2, 2);
2450         
2451                 ccorr->cd(1) ; 
2452                 //gPad->SetLogy();
2453                 //gPad->SetLogx();
2454                 fhCaloCorrNClusters ->Draw();
2455         
2456                 ccorr->cd(2) ; 
2457                 //gPad->SetLogy();
2458                 //gPad->SetLogx();
2459                 fhCaloCorrNCells->Draw();
2460         
2461                 ccorr->cd(3) ; 
2462                 //gPad->SetLogy();
2463                 //gPad->SetLogx();
2464                 fhCaloCorrEClusters->Draw();
2465         
2466                 ccorr->cd(4) ; 
2467                 //gPad->SetLogy();
2468                 //gPad->SetLogx();
2469                 fhCaloCorrECells->Draw();
2470         
2471                 sprintf(name,"QA_%s_CaloCorr_EMCALvsPHOS.eps",fCalorimeter.Data());
2472                 ccorr->Print(name); printf("Plot: %s\n",name);
2473         }
2474         
2475         //Reconstructed distributions
2476         //printf("c1\n");
2477         sprintf(cname,"QA_%s_rec",fCalorimeter.Data());
2478         TCanvas  * c = new TCanvas(cname, "Reconstructed distributions", 400, 400) ;
2479         c->Divide(2, 2);
2480         
2481         c->cd(1) ; 
2482         if(fhE->GetEntries() > 0) gPad->SetLogy();
2483         TLegend pLegendE(0.7,0.6,0.9,0.8);
2484         pLegendE.SetTextSize(0.03);
2485         pLegendE.AddEntry(fhE,"all modules","L");
2486         pLegendE.SetFillColor(10);
2487         pLegendE.SetBorderSize(1);
2488         
2489         fhE->SetLineColor(1);
2490         fhE->Draw();
2491         for(Int_t imod = 0; imod < fNModules; imod++){
2492                 fhEMod[imod]->SetLineColor(imod+1);
2493                 fhEMod[imod]->Draw("same");
2494                 pLegendE.AddEntry(fhEMod[imod],Form("module %d",imod),"L");
2495         }
2496         pLegendE.Draw();
2497         
2498         c->cd(2) ; 
2499         if(fhPt->GetEntries() > 0) gPad->SetLogy();
2500         fhPt->SetLineColor(4);
2501         fhPt->Draw();
2502         
2503         c->cd(3) ; 
2504         fhPhi->SetLineColor(4);
2505         fhPhi->Draw();
2506         
2507         c->cd(4) ; 
2508         fhEta->SetLineColor(4);
2509         fhEta->Draw();
2510         
2511         sprintf(name,"QA_%s_ReconstructedDistributions.eps",fCalorimeter.Data());
2512         c->Print(name); printf("Plot: %s\n",name);
2513         
2514         //Reconstructed distributions, matched with tracks
2515         //printf("c2\n");
2516         sprintf(cname,"QA_%s_rectrackmatch",fCalorimeter.Data());
2517         TCanvas  * c2 = new TCanvas(cname, "Reconstructed distributions, matched with tracks", 400, 400) ;
2518         c2->Divide(2, 2);
2519         
2520         c2->cd(1) ; 
2521         if(fhECharged->GetEntries() > 0) gPad->SetLogy();
2522         fhECharged->SetLineColor(4);
2523         fhECharged->Draw();
2524         
2525         c2->cd(2) ; 
2526         if(fhPtCharged->GetEntries() > 0) gPad->SetLogy();
2527         fhPtCharged->SetLineColor(4);
2528         fhPtCharged->Draw();
2529         
2530         c2->cd(3) ; 
2531         fhPhiCharged->SetLineColor(4);
2532         fhPhiCharged->Draw();
2533         
2534         c2->cd(4) ; 
2535         fhEtaCharged->SetLineColor(4);
2536         fhEtaCharged->Draw();
2537         
2538         sprintf(name,"QA_%s_ReconstructedDistributions_TrackMatched.eps",fCalorimeter.Data());
2539         c2->Print(name); printf("Plot: %s\n",name);
2540         
2541         TH1F *  hEChargedClone   = (TH1F*)   fhECharged->Clone(Form("%sClone",fhECharged->GetName()));
2542         TH1F *  hPtChargedClone  = (TH1F*)   fhPtCharged->Clone(Form("%sClone",fhPtCharged->GetName()));
2543         TH1F *  hEtaChargedClone = (TH1F*)   fhEtaCharged->Clone(Form("%sClone",fhEtaCharged->GetName()));
2544         TH1F *  hPhiChargedClone = (TH1F*)   fhPhiCharged->Clone(Form("%sClone",fhPhiCharged->GetName()));
2545         
2546         TH1F *  hEChargedClone2   = (TH1F*)   fhECharged->Clone(Form("%sClone2",fhECharged->GetName()));
2547         TH1F *  hPtChargedClone2  = (TH1F*)   fhPtCharged->Clone(Form("%sClone2",fhPtCharged->GetName()));
2548         TH1F *  hEtaChargedClone2 = (TH1F*)   fhEtaCharged->Clone(Form("%sClone2",fhEtaCharged->GetName()));
2549         TH1F *  hPhiChargedClone2 = (TH1F*)   fhPhiCharged->Clone(Form("%sClone2",fhPhiCharged->GetName()));
2550         
2551         //Ratio: reconstructed track matched/ all reconstructed
2552         //printf("c3\n");
2553         sprintf(cname,"QA_%s_rectrackmatchrat",fCalorimeter.Data());
2554         TCanvas  * c3 = new TCanvas(cname, "Ratio: reconstructed track matched/ all reconstructed", 400, 400) ;
2555         c3->Divide(2, 2);
2556         
2557         c3->cd(1) ;
2558         if(hEChargedClone->GetEntries() > 0) gPad->SetLogy();
2559         hEChargedClone->SetTitleOffset(1.6,"Y");
2560     hEChargedClone->SetYTitle("track matched / all   ");
2561         hEChargedClone->SetXTitle("E (GeV)");
2562         hEChargedClone->Divide(fhE);
2563         hEChargedClone->Draw();
2564         
2565         c3->cd(2) ; 
2566         if(hPtChargedClone->GetEntries() > 0) gPad->SetLogy();
2567         hPtChargedClone->SetTitleOffset(1.6,"Y");
2568         hPtChargedClone->SetYTitle("track matched / all   ");
2569     hPtChargedClone->SetXTitle("p_{T} (GeV/c)");
2570         hPtChargedClone->Divide(fhPt);
2571         hPtChargedClone->Draw();
2572         
2573         c3->cd(3) ;
2574         if(hPhiChargedClone->GetEntries() > 0) gPad->SetLogy();
2575         hPhiChargedClone->SetTitleOffset(1.6,"Y");
2576         hPhiChargedClone->SetYTitle("track matched / all   ");
2577         hPhiChargedClone->SetXTitle("#phi (rad)");
2578         hPhiChargedClone->Divide(fhPhi);
2579         hPhiChargedClone->Draw();
2580         
2581         c3->cd(4) ; 
2582         if(hEtaChargedClone->GetEntries() > 0) gPad->SetLogy();
2583         hEtaChargedClone->SetTitleOffset(1.6,"Y");
2584         hEtaChargedClone->SetYTitle("track matched / all   ");
2585         hEtaChargedClone->SetXTitle("#eta");
2586     hEtaChargedClone->Divide(fhEta);
2587         hEtaChargedClone->Draw();
2588         
2589         sprintf(name,"QA_%s_RatioReconstructedMatchedDistributions.eps",fCalorimeter.Data());
2590         c3->Print(name); printf("Plot: %s\n",name);
2591         
2592         //Ratio: reconstructed track matched (minus no track param) / all
2593         //printf("c3\n");
2594         sprintf(cname,"QA_%s_rectrackmatchratout",fCalorimeter.Data());
2595         TCanvas  * c333 = new TCanvas(cname, "Ratio: reconstructed track matched (with outer track param)/ all", 400, 400) ;
2596         c333->Divide(2, 2);
2597         
2598         c333->cd(1) ;
2599         hEChargedClone2->Add(fhEChargedNoOut,-1);
2600         hEChargedClone2->SetYTitle("track matched / all");
2601         hEChargedClone2->SetXTitle("E (GeV)");
2602         hEChargedClone2->Divide(fhE);
2603         hEChargedClone2->Draw();
2604         
2605         c333->cd(2) ; 
2606         hPtChargedClone2->Add(fhPtChargedNoOut,-1);
2607         hPtChargedClone2->SetYTitle("track matched / all");
2608         hPtChargedClone2->SetXTitle("p_{T} (GeV/c)");
2609         hPtChargedClone2->Divide(fhPt);
2610         hPtChargedClone2->Draw();
2611         
2612         c333->cd(3) ;
2613         hPhiChargedClone2->Add(fhPhiChargedNoOut,-1);
2614         hPhiChargedClone2->SetYTitle("track matched / all");
2615         hPhiChargedClone2->SetXTitle("#phi (rad)");
2616         hPhiChargedClone2->Divide(fhPhi);
2617         hPhiChargedClone2->Draw();
2618         
2619         c333->cd(4) ; 
2620         hEtaChargedClone2->Add(fhEtaChargedNoOut,-1);
2621         hEtaChargedClone2->SetYTitle("track matched / all");
2622         hEtaChargedClone2->SetXTitle("#eta");
2623         hEtaChargedClone2->Divide(fhEta);
2624         hEtaChargedClone2->Draw();
2625         
2626         sprintf(name,"QA_%s_RatioReconstructedMatchedDistributionsOuter.eps",fCalorimeter.Data());
2627         c333->Print(name); printf("Plot: %s\n",name);
2628         
2629         //Reconstructed distributions, matched with tracks but no outer param
2630         //printf("c2\n");
2631         sprintf(cname,"QA_%s_rectrackmatch_noout",fCalorimeter.Data());
2632         TCanvas  * c22 = new TCanvas(cname, "Reconstructed distributions, matched with tracks, no outer track param", 400, 400) ;
2633         c22->Divide(2, 2);
2634         
2635         c22->cd(1) ; 
2636         if(fhEChargedNoOut->GetEntries() > 0) gPad->SetLogy();
2637         fhEChargedNoOut->SetLineColor(4);
2638         fhEChargedNoOut->Draw();
2639         
2640         c22->cd(2) ; 
2641         if(fhEChargedNoOut->GetEntries() > 0) gPad->SetLogy();
2642         fhPtChargedNoOut->SetLineColor(4);
2643         fhPtChargedNoOut->Draw();
2644         
2645         c22->cd(3) ; 
2646         fhPhiChargedNoOut->SetLineColor(4);
2647         fhPhiChargedNoOut->Draw();
2648         
2649         c22->cd(4) ; 
2650         fhEtaChargedNoOut->SetLineColor(4);
2651         fhEtaChargedNoOut->Draw();
2652         
2653         sprintf(name,"QA_%s_ReconstructedDistributions_TrackMatched_NoOutParam.eps",fCalorimeter.Data());
2654         c22->Print(name); printf("Plot: %s\n",name);
2655         
2656         //Ratio: reconstructed track matched/ all reconstructed
2657         //printf("c3\n");
2658         
2659 //      TH1F *  hEChargedNoOutClone   = (TH1F*)   fhEChargedNoOut->Clone("EChargedNoOutClone");
2660 //      TH1F *  hPtChargedNoOutClone  = (TH1F*)   fhPtChargedNoOut->Clone("PtChargedNoOutClone");
2661 //      TH1F *  hEtaChargedNoOutClone = (TH1F*)   fhEtaChargedNoOut->Clone("EtaChargedNoOutClone");
2662 //      TH1F *  hPhiChargedNoOutClone = (TH1F*)   fhPhiChargedNoOut->Clone("PhiChargedNoOutClone");     
2663         
2664 //      sprintf(cname,"QA_%s_rectrackmatchratnoout",fCalorimeter.Data());
2665 //      TCanvas  * c33 = new TCanvas(cname, "Ratio: reconstructed track matched/ all reconstructed", 400, 400) ;
2666 //      c33->Divide(2, 2);
2667 //      
2668 //      c33->cd(1) ;
2669 //      hEChargedNoOutClone->SetYTitle("track matched no out/ all matched");
2670 //      hEChargedNoOutClone->SetXTitle("E (GeV)");
2671 //      hEChargedNoOutClone->Divide(fhECharged);
2672 //      hEChargedNoOutClone->Draw();
2673 //      
2674 //      c33->cd(2) ; 
2675 //      hPtChargedNoOutClone->SetYTitle("track matched no out / all matched");
2676 //      hPtChargedNoOutClone->SetXTitle("p_{T} (GeV/c)");
2677 //      hPtChargedNoOutClone->Divide(fhPtCharged);
2678 //      hPtChargedNoOutClone->Draw();
2679 //      
2680 //      c33->cd(3) ;
2681 //      hPhiChargedNoOutClone->SetYTitle("track matched no out/ all matched");
2682 //      hPhiChargedNoOutClone->SetXTitle("#phi (rad)");
2683 //      hPhiChargedNoOutClone->Divide(fhPhiCharged);
2684 //      hPhiChargedNoOutClone->Draw();
2685 //      
2686 //      c33->cd(4) ; 
2687 //      hEtaChargedNoOutClone->SetYTitle("track matched no out/ all matched");
2688 //      hEtaChargedNoOutClone->SetXTitle("#eta");
2689 //      hEtaChargedNoOutClone->Divide(fhEtaCharged);
2690 //      hEtaChargedNoOutClone->Draw();
2691 //      
2692 //      sprintf(name,"QA_%s_RatioMatchedDistributionsAllToNoOut.eps",fCalorimeter.Data());
2693 //      c33->Print(name); printf("Plot: %s\n",name);
2694         
2695         
2696         //eta vs phi
2697         //printf("c4\n");
2698         sprintf(cname,"QA_%s_etavsphivse",fCalorimeter.Data());
2699         //      TCanvas  * c4 = new TCanvas(cname, "reconstructed #eta vs #phi", 600, 200) ;
2700         //      c4->Divide(3, 1);
2701         
2702         TCanvas  * c4 = new TCanvas(cname, "reconstructed #eta vs #phi vs E", 600, 600) ;
2703         /*
2704         c4->Divide(3, 1);
2705         
2706         c4->cd(1) ;
2707         fhEtaPhi->Draw("contz");
2708         c4->cd(2) ;
2709         fhEtaPhiE->Draw();
2710         c4->cd(3) ; 
2711         fhEtaPhiCharged->Draw("contz");
2712         //c4->Divide(3, 1);
2713          */  
2714         {gStyle->SetOptStat(0);
2715         fhEtaPhi->Draw("contz");}
2716         //fhEtaPhiE->Draw();
2717         
2718         
2719         //      c4->cd(3) ; 
2720         //      fhEtaPhiChargedNoOut->Draw("cont");
2721         
2722         sprintf(name,"QA_%s_ReconstructedEtaVsPhiVsE.eps",fCalorimeter.Data());
2723         c4->Print(name); printf("Plot: %s\n",name);
2724         
2725         //Invariant mass
2726         Int_t binmin = -1;
2727         Int_t binmax = -1;
2728         
2729         if(fhIM->GetEntries() > 1){
2730                 Int_t nebins  = fhIM->GetNbinsX();
2731                 Int_t emax = (Int_t) fhIM->GetXaxis()->GetXmax();
2732                 Int_t emin = (Int_t) fhIM->GetXaxis()->GetXmin();
2733                 if (emin != 0 ) printf("emin != 0 \n");
2734                 //printf("IM: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
2735                 
2736                 sprintf(cname,"QA_%s_IM",fCalorimeter.Data());
2737                 //      printf("c5\n");
2738                 TCanvas  * c5 = new TCanvas(cname, "Invariant mass", 600, 400) ;
2739                 c5->Divide(2, 3);
2740                 
2741                 c5->cd(1) ; 
2742                 //fhIM->SetLineColor(4);
2743                 //fhIM->Draw();
2744                 binmin = 0;
2745                 binmax =  (Int_t) (1-emin)*nebins/emax;
2746                 TH1D *pyim1 = fhIM->ProjectionY(Form("%s_py1",fhIM->GetName()),binmin,binmax);
2747                 pyim1->SetTitle("E_{pair} < 1 GeV");
2748                 pyim1->SetLineColor(1);
2749                 pyim1->Draw();
2750                 TLegend pLegendIM(0.7,0.6,0.9,0.8);
2751                 pLegendIM.SetTextSize(0.03);
2752                 pLegendIM.AddEntry(pyim1,"all modules","L");
2753                 pLegendIM.SetFillColor(10);
2754                 pLegendIM.SetBorderSize(1);
2755                 for(Int_t imod = 0; imod < fNModules; imod++){
2756                         pyim1 = fhIMMod[imod]->ProjectionY(Form("%s_py1",fhIMMod[imod]->GetName()),binmin,binmax);
2757                         pLegendIM.AddEntry(pyim1,Form("module %d",imod),"L");
2758                         pyim1->SetLineColor(imod+1);
2759                         pyim1->Draw("same");
2760                 }
2761                 pLegendIM.Draw();
2762                 
2763                 c5->cd(2) ; 
2764                 binmin =  (Int_t) (1-emin)*nebins/emax;
2765                 binmax =  (Int_t) (2-emin)*nebins/emax;
2766                 TH1D *pyim2 = fhIM->ProjectionY(Form("%s_py2",fhIM->GetName()),binmin,binmax);
2767                 pyim2->SetTitle("1 < E_{pair} < 2 GeV");
2768                 pyim2->SetLineColor(1);
2769                 pyim2->Draw();
2770                 for(Int_t imod = 0; imod < fNModules; imod++){
2771                         pyim2 = fhIMMod[imod]->ProjectionY(Form("%s_py2",fhIMMod[imod]->GetName()),binmin,binmax);
2772                         pyim2->SetLineColor(imod+1);
2773                         pyim2->Draw("same");
2774                 }
2775                 
2776                 c5->cd(3) ; 
2777                 binmin =  (Int_t) (2-emin)*nebins/emax;
2778                 binmax =  (Int_t) (3-emin)*nebins/emax;
2779                 TH1D *pyim3 = fhIM->ProjectionY(Form("%s_py3",fhIM->GetName()),binmin,binmax);
2780                 pyim3->SetTitle("2 < E_{pair} < 3 GeV");
2781                 pyim3->SetLineColor(1);
2782                 pyim3->Draw();
2783                 for(Int_t imod = 0; imod < fNModules; imod++){
2784                         pyim3 = fhIMMod[imod]->ProjectionY(Form("%s_py3",fhIMMod[imod]->GetName()),binmin,binmax);
2785                         pyim3->SetLineColor(imod+1);
2786                         pyim3->Draw("same");
2787                 }
2788                 
2789                 c5->cd(4) ;
2790                 binmin =  (Int_t) (3-emin)*nebins/emax;
2791                 binmax =  (Int_t) (4-emin)*nebins/emax;
2792                 TH1D *pyim4 = fhIM->ProjectionY(Form("%s_py4",fhIM->GetName()),binmin,binmax);
2793                 pyim4->SetTitle("3 < E_{pair} < 4 GeV");
2794                 pyim4->SetLineColor(1);
2795                 pyim4->Draw();
2796                 for(Int_t imod = 0; imod < fNModules; imod++){
2797                         pyim4 = fhIMMod[imod]->ProjectionY(Form("%s_py4",fhIMMod[imod]->GetName()),binmin,binmax);
2798                         pyim4->SetLineColor(imod+1);
2799                         pyim4->Draw("same");
2800                 }
2801                 
2802                 c5->cd(5) ;
2803                 binmin =  (Int_t) (4-emin)*nebins/emax;
2804                 binmax =  (Int_t) (5-emin)*nebins/emax;
2805                 TH1D *pyim5 = fhIM->ProjectionY(Form("%s_py5",fhIM->GetName()),binmin,binmax);
2806                 pyim5->SetTitle("4< E_{pair} < 5 GeV");
2807                 pyim5->SetLineColor(1);
2808                 pyim5->Draw();
2809                 for(Int_t imod = 0; imod < fNModules; imod++){
2810                         pyim5 = fhIMMod[imod]->ProjectionY(Form("%s_py5",fhIMMod[imod]->GetName()),binmin,binmax);
2811                         pyim5->SetLineColor(imod+1);
2812                         pyim5->Draw("same");
2813                 }
2814                 
2815                 c5->cd(6) ;
2816                 binmin =  (Int_t) (5-emin)*nebins/emax;
2817                 binmax =  -1;
2818                 TH1D *pyim10 = fhIM->ProjectionY(Form("%s_py6",fhIM->GetName()),binmin,binmax);
2819                 pyim10->SetTitle("E_{pair} > 5 GeV");
2820                 pyim10->SetLineColor(1);
2821                 pyim10->Draw();
2822                 for(Int_t imod = 0; imod < fNModules; imod++){
2823                         pyim10 = fhIMMod[imod]->ProjectionY(Form("%s_py6",fhIMMod[imod]->GetName()),binmin,binmax);
2824                         pyim10->SetLineColor(imod+1);
2825                         pyim10->Draw("same");
2826                 }
2827                 
2828                 sprintf(name,"QA_%s_InvariantMass.eps",fCalorimeter.Data());
2829                 c5->Print(name); printf("Plot: %s\n",name);
2830         }
2831         
2832         
2833         if(fhIMCellCut->GetEntries() > 1){
2834                 Int_t nebins  = fhIMCellCut->GetNbinsX();
2835                 Int_t emax = (Int_t) fhIMCellCut->GetXaxis()->GetXmax();
2836                 Int_t emin = (Int_t) fhIMCellCut->GetXaxis()->GetXmin();
2837                 if (emin != 0 ) printf("emin != 0 \n");
2838                 //printf("IMCellCut: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
2839                 
2840                 sprintf(cname,"QA_%s_IMCellCut",fCalorimeter.Data());
2841                 //      printf("c5cc\n");
2842                 TCanvas  * c5cc = new TCanvas(cname, "Invariant mass, Cell Cut", 600, 400) ;
2843                 c5cc->Divide(2, 3);
2844                 
2845                 c5cc->cd(1) ; 
2846                 //fhIMCellCut->SetLineColor(4);
2847                 //fhIMCellCut->Draw();
2848                 binmin = 0;
2849                 binmax =  (Int_t) (1-emin)*nebins/emax;
2850                 TH1D *pyimcc1 = fhIMCellCut->ProjectionY(Form("%s_py1",fhIMCellCut->GetName()),binmin,binmax);
2851                 pyimcc1->SetTitle("E_{pair} < 1 GeV");
2852                 pyimcc1->SetLineColor(1);
2853                 pyimcc1->Draw();
2854                 TLegend pLegendIMCellCut(0.7,0.6,0.9,0.8);
2855                 pLegendIMCellCut.SetTextSize(0.03);
2856                 pLegendIMCellCut.AddEntry(pyimcc1,"all modules","L");
2857                 pLegendIMCellCut.SetFillColor(10);
2858                 pLegendIMCellCut.SetBorderSize(1);
2859                 for(Int_t imod = 0; imod < fNModules; imod++){
2860                         pyimcc1 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),binmin,binmax);
2861                         pLegendIMCellCut.AddEntry(pyimcc1,Form("module %d",imod),"L");
2862                         pyimcc1->SetLineColor(imod+1);
2863                         pyimcc1->Draw("same");
2864                 }
2865                 pLegendIMCellCut.Draw();
2866                 
2867                 c5cc->cd(2) ; 
2868                 binmin =  (Int_t) (1-emin)*nebins/emax;
2869                 binmax =  (Int_t) (2-emin)*nebins/emax;
2870                 TH1D *pyimcc2 = fhIMCellCut->ProjectionY(Form("%s_py2",fhIMCellCut->GetName()),binmin,binmax);
2871                 pyimcc2->SetTitle("1 < E_{pair} < 2 GeV");
2872                 pyimcc2->SetLineColor(1);
2873                 pyimcc2->Draw();
2874                 for(Int_t imod = 0; imod < fNModules; imod++){
2875                         pyimcc2 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),binmin,binmax);
2876                         pyimcc2->SetLineColor(imod+1);
2877                         pyimcc2->Draw("same");
2878                 }
2879                 
2880                 c5cc->cd(3) ; 
2881                 binmin =  (Int_t) (2-emin)*nebins/emax;
2882                 binmax =  (Int_t) (3-emin)*nebins/emax;
2883                 TH1D *pyimcc3 = fhIMCellCut->ProjectionY(Form("%s_py3",fhIMCellCut->GetName()),binmin,binmax);
2884                 pyimcc3->SetTitle("2 < E_{pair} < 3 GeV");
2885                 pyimcc3->SetLineColor(1);
2886                 pyimcc3->Draw();
2887                 for(Int_t imod = 0; imod < fNModules; imod++){
2888                         pyimcc3 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),binmin,binmax);
2889                         pyimcc3->SetLineColor(imod+1);
2890                         pyimcc3->Draw("same");
2891                 }
2892                 
2893                 c5cc->cd(4) ;
2894                 binmin =  (Int_t) (3-emin)*nebins/emax;
2895                 binmax =  (Int_t) (4-emin)*nebins/emax;
2896                 TH1D *pyimcc4 = fhIMCellCut->ProjectionY(Form("%s_py4",fhIMCellCut->GetName()),binmin,binmax);
2897                 pyimcc4->SetTitle("3 < E_{pair} < 4 GeV");
2898                 pyimcc4->SetLineColor(1);
2899                 pyimcc4->Draw();
2900                 for(Int_t imod = 0; imod < fNModules; imod++){
2901                         pyimcc4 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py5",fhIMCellCutMod[imod]->GetName()),binmin,binmax);
2902                         pyimcc4->SetLineColor(imod+1);
2903                         pyimcc4->Draw("same");
2904                 }
2905                 
2906                 c5cc->cd(5) ;
2907                 binmin =  (Int_t) (4-emin)*nebins/emax;
2908                 binmax =  (Int_t) (5-emin)*nebins/emax;
2909                 TH1D *pyimcc5cc = fhIMCellCut->ProjectionY(Form("%s_py5",fhIMCellCut->GetName()),binmin,binmax);
2910                 pyimcc5cc->SetTitle("4< E_{pair} < 5 GeV");
2911                 pyimcc5cc->SetLineColor(1);
2912                 pyimcc5cc->Draw();
2913                 for(Int_t imod = 0; imod < fNModules; imod++){
2914                         pyimcc5cc = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py5",fhIMCellCutMod[imod]->GetName()),binmin,binmax);
2915                         pyimcc5cc->SetLineColor(imod+1);
2916                         pyimcc5cc->Draw("same");
2917                 }
2918                 
2919                 c5cc->cd(6) ;
2920                 binmin =  (Int_t) (5-emin)*nebins/emax;
2921                 binmax =  -1;
2922                 TH1D *pyimcc10 = fhIMCellCut->ProjectionY(Form("%s_py6",fhIMCellCut->GetName()),binmin,binmax);
2923                 pyimcc10->SetTitle("E_{pair} > 5 GeV");
2924                 pyimcc10->SetLineColor(1);
2925                 pyimcc10->Draw();
2926                 for(Int_t imod = 0; imod < fNModules; imod++){
2927                         pyimcc10 = fhIMCellCutMod[imod]->ProjectionY(Form("%s_py1",fhIMCellCutMod[imod]->GetName()),binmin,binmax);
2928                         pyimcc10->SetLineColor(imod+1);
2929                         pyimcc10->Draw("same");
2930                 }
2931                 
2932                 sprintf(name,"QA_%s_InvariantMass_CellCut.eps",fCalorimeter.Data());
2933                 c5cc->Print(name); printf("Plot: %s\n",name);
2934         }
2935         
2936         
2937         //Asymmetry
2938         if(fhAsym->GetEntries() > 1){
2939                 Int_t nebins  = fhAsym->GetNbinsX();
2940                 Int_t emax = (Int_t) fhAsym->GetXaxis()->GetXmax();
2941                 Int_t emin = (Int_t) fhAsym->GetXaxis()->GetXmin();
2942                 if (emin != 0 ) printf("emin != 0 \n");
2943                 //printf("Asym: nBinsX %d, emin %2.2f, emax %2.2f\n",nebins,emin,emax);
2944                 
2945                 sprintf(cname,"QA_%s_Asym",fCalorimeter.Data());
2946                 //      printf("c5\n");
2947                 TCanvas  * c5b = new TCanvas(cname, "Asymmetry", 400, 400) ;
2948                 c5b->Divide(2, 2);
2949                 
2950                 c5b->cd(1) ; 
2951                 fhAsym->SetTitleOffset(1.6,"Y");
2952                 fhAsym->SetLineColor(4);
2953                 fhAsym->Draw();
2954                 
2955                 c5b->cd(2) ; 
2956                 binmin = 0;
2957                 binmax = (Int_t) (5-emin)*nebins/emax;
2958                 TH1D *pyAsym5 = fhAsym->ProjectionY(Form("%s_py5",fhAsym->GetName()),binmin,binmax);
2959                 pyAsym5->SetTitle("E_{pair} < 5 GeV");
2960                 pyAsym5->SetLineColor(4);
2961                 pyAsym5->Draw();
2962                 
2963                 c5b->cd(3) ; 
2964                 binmin = (Int_t) (5-emin)*nebins/emax;
2965                 binmax = (Int_t) (10-emin)*nebins/emax;
2966                 TH1D *pyAsym510 = fhAsym->ProjectionY(Form("%s_py510",fhAsym->GetName()),binmin,binmax);
2967                 pyAsym510->SetTitle("5 < E_{pair} < 10 GeV");
2968                 pyAsym510->SetLineColor(4);
2969                 pyAsym510->Draw();
2970                 
2971                 c5b->cd(4) ;
2972                 binmin = (Int_t) (10-emin)*nebins/emax;
2973                 binmax = -1;
2974                 TH1D *pyAsym10 = fhAsym->ProjectionY(Form("%s_py10",fhAsym->GetName()),binmin,binmax);
2975                 pyAsym10->SetTitle("E_{pair} > 10 GeV");
2976                 pyAsym10->SetLineColor(4);
2977                 pyAsym10->Draw();
2978                 
2979                 sprintf(name,"QA_%s_Asymmetry.eps",fCalorimeter.Data());
2980                 c5b->Print(name); printf("Plot: %s\n",name);
2981         }
2982         
2983         //Grid of cell per module plots 
2984     {
2985                 gStyle->SetOptStat(0);
2986                 sprintf(cname,"QA_%s_GridCellEntries",fCalorimeter.Data());
2987                 //      printf("c5\n");
2988                 TCanvas *cgrid   = new TCanvas("cgrid","Number of entries per cell", 12,12,800,400);
2989                 if(fNModules%2 == 0)
2990                         cgrid->Divide(fNModules/2,2); 
2991                 else
2992                         cgrid->Divide(fNModules/2+1,2); 
2993
2994                 for(Int_t imod = 0; imod < fNModules ; imod++){
2995                         cgrid->cd(imod+1);
2996                         gPad->SetLogz();
2997                         gPad->SetGridy();
2998                         gPad->SetGridx();
2999                         fhGridCellsMod[imod]->SetLabelSize(0.025,"z");
3000                         fhGridCellsMod[imod]->Draw("colz");
3001                 }
3002                 sprintf(name,"QA_%s_GridCellsEntries.eps",fCalorimeter.Data());
3003                 cgrid->Print(name); printf("Plot: %s\n",name);
3004                 
3005                 sprintf(cname,"QA_%s_GridCellAccumEnergy",fCalorimeter.Data());
3006                 //      printf("c5\n");
3007                 TCanvas *cgridE   = new TCanvas("cgridE","Summed energy per cell", 12,12,800,400);
3008                 cgridE->Divide(fNModules/2,2); 
3009                 for(Int_t imod = 0; imod < fNModules ; imod++){
3010                         cgridE->cd(imod+1);
3011                         gPad->SetLogz();
3012                         gPad->SetGridy();
3013                         gPad->SetGridx();
3014                         fhGridCellsEMod[imod]->SetLabelSize(0.025,"z");
3015                         fhGridCellsEMod[imod]->Draw("colz");
3016                 }
3017                 sprintf(name,"QA_%s_GridCellsAccumEnergy.eps",fCalorimeter.Data());
3018                 cgridE->Print(name); printf("Plot: %s\n",name);
3019                 
3020                 sprintf(cname,"QA_%s_GridCellAverageEnergy",fCalorimeter.Data());
3021                 //      printf("c5\n");
3022                 TCanvas *cgridEA   = new TCanvas("cgridEA","Average energy per cell", 12,12,800,400);
3023                 cgridEA->Divide(fNModules/2,2); 
3024                 for(Int_t imod = 0; imod < fNModules ; imod++){
3025                         cgridEA->cd(imod+1);
3026                         gPad->SetLogz();
3027                         gPad->SetGridy();
3028                         gPad->SetGridx();
3029                         fhGridCellsEMod[imod]->SetLabelSize(0.025,"z");
3030                         fhGridCellsEMod[imod]->Divide(fhGridCellsMod[imod]);
3031                         fhGridCellsEMod[imod]->Draw("colz");
3032                 }
3033                 sprintf(name,"QA_%s_GridCellsAverageEnergy.eps",fCalorimeter.Data());
3034                 cgridEA->Print(name); printf("Plot: %s\n",name);
3035                 
3036         }
3037         
3038         if(IsDataMC()){
3039         //Reconstructed vs MC distributions
3040         //printf("c6\n");
3041         sprintf(cname,"QA_%s_recvsmc",fCalorimeter.Data());
3042         TCanvas  * c6 = new TCanvas(cname, "Reconstructed vs MC distributions", 400, 400) ;
3043         c6->Divide(2, 2);
3044         
3045         c6->cd(1) ; 
3046         fh2E->SetTitleOffset(1.6,"Y");
3047         fh2E->SetLineColor(4);
3048         fh2E->Draw();
3049         
3050         c6->cd(2) ; 
3051         fh2Pt->SetTitleOffset(1.6,"Y");
3052         fh2Pt->SetLineColor(4);
3053         fh2Pt->Draw();
3054         
3055         c6->cd(3) ; 
3056         fh2Phi->SetTitleOffset(1.6,"Y");
3057         fh2Phi->SetLineColor(4);
3058         fh2Phi->Draw();
3059         
3060         c6->cd(4) ; 
3061         fh2Eta->SetTitleOffset(1.6,"Y");
3062         fh2Eta->SetLineColor(4);
3063         fh2Eta->Draw();
3064         
3065         sprintf(name,"QA_%s_ReconstructedVSMCDistributions.eps",fCalorimeter.Data());
3066         c6->Print(name); printf("Plot: %s\n",name);     
3067         
3068         //Reconstructed vs MC distributions
3069         //printf("c6\n");
3070         sprintf(cname,"QA_%s_gamrecvsmc",fCalorimeter.Data());
3071         TCanvas  * c6Gam = new TCanvas(cname, "Reconstructed vs MC distributions", 400, 400) ;
3072         c6Gam->Divide(2, 2);
3073         
3074         c6Gam->cd(1) ; 
3075         fhGamE->Draw();
3076         
3077         c6Gam->cd(2) ; 
3078         fhGamPt->Draw();
3079         
3080         c6Gam->cd(3) ; 
3081         fhGamPhi->Draw();
3082         
3083         c6Gam->cd(4) ; 
3084         fhGamEta->Draw();
3085         
3086         sprintf(name,"QA_%s_GammaReconstructedVSMCDistributions.eps",fCalorimeter.Data());
3087         c6->Print(name); printf("Plot: %s\n",name);     
3088         
3089         //Generated - reconstructed  
3090         //printf("c7\n");
3091         sprintf(cname,"QA_%s_diffgenrec",fCalorimeter.Data());
3092         TCanvas  * c7 = new TCanvas(cname, "generated - reconstructed", 400, 400) ;
3093         c7->Divide(2, 2);
3094         
3095         c7->cd(1) ; 
3096         if(fhDeltaE->GetEntries() > 0) gPad->SetLogy();
3097         fhGamDeltaE->SetLineColor(4);
3098         fhDeltaE->Draw();
3099         fhGamDeltaE->Draw("same");
3100         
3101         TLegend pLegendd(0.65,0.55,0.9,0.8);
3102         pLegendd.SetTextSize(0.06);
3103         pLegendd.AddEntry(fhDeltaE,"all","L");
3104         pLegendd.AddEntry(fhGamDeltaE,"from  #gamma","L");
3105         pLegendd.SetFillColor(10);
3106         pLegendd.SetBorderSize(1);
3107         pLegendd.Draw();
3108         
3109         c7->cd(2) ; 
3110         if(fhDeltaPt->GetEntries() > 0) gPad->SetLogy();
3111         fhGamDeltaPt->SetLineColor(4);
3112         fhDeltaPt->Draw();
3113         fhGamDeltaPt->Draw("same");
3114         
3115         c7->cd(3) ; 
3116         fhGamDeltaPhi->SetLineColor(4);
3117         fhDeltaPhi->Draw();
3118         fhGamDeltaPhi->Draw("same");
3119         
3120         c7->cd(4) ; 
3121         fhGamDeltaEta->SetLineColor(4);
3122         fhDeltaEta->Draw();
3123         fhGamDeltaEta->Draw("same");
3124         
3125         sprintf(name,"QA_%s_DiffGeneratedReconstructed.eps",fCalorimeter.Data());
3126         c7->Print(name); printf("Plot: %s\n",name);
3127         
3128         // Reconstructed / Generated 
3129         //printf("c8\n");
3130         sprintf(cname,"QA_%s_ratiorecgen",fCalorimeter.Data());
3131         TCanvas  * c8 = new TCanvas(cname, " reconstructed / generated", 400, 400) ;
3132         c8->Divide(2, 2);
3133         
3134         c8->cd(1) ; 
3135         if(fhRatioE->GetEntries() > 0) gPad->SetLogy();
3136         fhGamRatioE->SetLineColor(4);
3137         fhRatioE->Draw();
3138         fhGamRatioE->Draw("same");
3139         
3140         TLegend pLegendr(0.65,0.55,0.9,0.8);
3141         pLegendr.SetTextSize(0.06);
3142         pLegendr.AddEntry(fhRatioE,"all","L");
3143         pLegendr.AddEntry(fhGamRatioE,"from  #gamma","L");
3144         pLegendr.SetFillColor(10);
3145         pLegendr.SetBorderSize(1);
3146         pLegendr.Draw();
3147         
3148         c8->cd(2) ; 
3149         if(fhRatioPt->GetEntries() > 0) gPad->SetLogy();
3150         fhGamRatioPt->SetLineColor(4);
3151         fhRatioPt->Draw();
3152         fhGamRatioPt->Draw("same");
3153         
3154         c8->cd(3) ; 
3155         fhGamRatioPhi->SetLineColor(4);
3156         fhRatioPhi->Draw();
3157         fhGamRatioPhi->Draw("same");
3158         
3159         c8->cd(4) ; 
3160         fhGamRatioEta->SetLineColor(4);
3161         fhRatioEta->Draw();
3162         fhGamRatioEta->Draw("same");
3163         
3164         sprintf(name,"QA_%s_ReconstructedDivGenerated.eps",fCalorimeter.Data());
3165         c8->Print(name); printf("Plot: %s\n",name);
3166         
3167         //MC
3168         
3169         //Generated distributions
3170         //printf("c1\n");
3171         sprintf(cname,"QA_%s_gen",fCalorimeter.Data());
3172         TCanvas  * c10 = new TCanvas(cname, "Generated distributions", 600, 200) ;
3173         c10->Divide(3, 1);
3174         
3175         c10->cd(1) ; 
3176         gPad->SetLogy();
3177         TH1F * haxispt  = (TH1F*) fhGenPi0Pt->Clone(Form("%s_axispt",fhGenPi0Pt->GetName()));  
3178         haxispt->SetTitle("Generated Particles p_{T}, |#eta| < 1");
3179         fhGenPi0Pt->SetLineColor(1);
3180         fhGenGamPt->SetLineColor(4);
3181         fhGenEtaPt->SetLineColor(2);
3182         fhGenOmegaPt->SetLineColor(7);
3183         fhGenElePt->SetLineColor(6);
3184         
3185         //Select the maximum of the histogram to show all lines.
3186         if(fhGenPi0Pt->GetMaximum() >= fhGenGamPt->GetMaximum() && fhGenPi0Pt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
3187            fhGenPi0Pt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenPi0Pt->GetMaximum() >= fhGenElePt->GetMaximum())
3188                 haxispt->SetMaximum(fhGenPi0Pt->GetMaximum());
3189         else if(fhGenGamPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenGamPt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
3190                         fhGenGamPt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenGamPt->GetMaximum() >= fhGenElePt->GetMaximum())
3191                 haxispt->SetMaximum(fhGenGamPt->GetMaximum());
3192         else if(fhGenEtaPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenEtaPt->GetMaximum() >= fhGenGamPt->GetMaximum() && 
3193                         fhGenEtaPt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenEtaPt->GetMaximum() >= fhGenElePt->GetMaximum())
3194                 haxispt->SetMaximum(fhGenEtaPt->GetMaximum());  
3195         else if(fhGenOmegaPt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenOmegaPt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
3196                         fhGenOmegaPt->GetMaximum() >= fhGenGamPt->GetMaximum() && fhGenOmegaPt->GetMaximum() >= fhGenElePt->GetMaximum())
3197                 haxispt->SetMaximum(fhGenOmegaPt->GetMaximum());
3198         else if(fhGenElePt->GetMaximum() >= fhGenPi0Pt->GetMaximum() && fhGenElePt->GetMaximum() >= fhGenEtaPt->GetMaximum() && 
3199                         fhGenElePt->GetMaximum() >= fhGenOmegaPt->GetMaximum() && fhGenElePt->GetMaximum() >= fhGenGamPt->GetMaximum())
3200                 haxispt->SetMaximum(fhGenElePt->GetMaximum());
3201         haxispt->SetMinimum(1);
3202         haxispt->Draw("axis");
3203         fhGenPi0Pt->Draw("same");
3204         fhGenGamPt->Draw("same");
3205         fhGenEtaPt->Draw("same");
3206         fhGenOmegaPt->Draw("same");
3207         fhGenElePt->Draw("same");
3208         
3209         TLegend pLegend(0.85,0.65,0.95,0.93);
3210         pLegend.SetTextSize(0.06);
3211         pLegend.AddEntry(fhGenPi0Pt,"  #pi^{0}","L");
3212         pLegend.AddEntry(fhGenGamPt,"  #gamma","L");
3213         pLegend.AddEntry(fhGenEtaPt,"  #eta","L");
3214         pLegend.AddEntry(fhGenOmegaPt,"  #omega","L");
3215         pLegend.AddEntry(fhGenElePt,"  e^{#pm}","L");
3216         pLegend.SetFillColor(10);
3217         pLegend.SetBorderSize(1);
3218         pLegend.Draw();
3219         
3220         c10->cd(2) ;
3221         gPad->SetLogy();
3222         TH1F * haxiseta  = (TH1F*) fhGenPi0Eta->Clone(Form("%s_axiseta",fhGenPi0Eta->GetName()));  
3223         haxiseta->SetTitle("Generated Particles #eta, |#eta| < 1");
3224         fhGenPi0Eta->SetLineColor(1);
3225         fhGenGamEta->SetLineColor(4);
3226         fhGenEtaEta->SetLineColor(2);
3227         fhGenOmegaEta->SetLineColor(7);
3228         fhGenEleEta->SetLineColor(6);
3229         //Select the maximum of the histogram to show all lines.
3230         if(fhGenPi0Eta->GetMaximum() >= fhGenGamEta->GetMaximum() && fhGenPi0Eta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
3231            fhGenPi0Eta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenPi0Eta->GetMaximum() >= fhGenEleEta->GetMaximum())
3232                 haxiseta->SetMaximum(fhGenPi0Eta->GetMaximum());
3233         else if(fhGenGamEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenGamEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
3234                         fhGenGamEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenGamEta->GetMaximum() >= fhGenEleEta->GetMaximum())
3235                 haxiseta->SetMaximum(fhGenGamEta->GetMaximum());
3236         else if(fhGenEtaEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenEtaEta->GetMaximum() >= fhGenGamEta->GetMaximum() && 
3237                         fhGenEtaEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenEtaEta->GetMaximum() >= fhGenEleEta->GetMaximum())
3238                 haxiseta->SetMaximum(fhGenEtaEta->GetMaximum());        
3239         else if(fhGenOmegaEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenOmegaEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
3240                         fhGenOmegaEta->GetMaximum() >= fhGenGamEta->GetMaximum() && fhGenOmegaEta->GetMaximum() >= fhGenEleEta->GetMaximum())
3241                 haxiseta->SetMaximum(fhGenOmegaEta->GetMaximum());
3242         else if(fhGenEleEta->GetMaximum() >= fhGenPi0Eta->GetMaximum() && fhGenEleEta->GetMaximum() >= fhGenEtaEta->GetMaximum() && 
3243                         fhGenEleEta->GetMaximum() >= fhGenOmegaEta->GetMaximum() && fhGenEleEta->GetMaximum() >= fhGenGamEta->GetMaximum())
3244                 haxiseta->SetMaximum(fhGenEleEta->GetMaximum());
3245         haxiseta->SetMinimum(100);
3246         haxiseta->Draw("axis");
3247         fhGenPi0Eta->Draw("same");
3248         fhGenGamEta->Draw("same");
3249         fhGenEtaEta->Draw("same");
3250         fhGenOmegaEta->Draw("same");
3251         fhGenEleEta->Draw("same");
3252         
3253         
3254         c10->cd(3) ; 
3255         gPad->SetLogy();
3256         TH1F * haxisphi  = (TH1F*) fhGenPi0Phi->Clone(Form("%s_axisphi",fhGenPi0Phi->GetName()));  
3257         haxisphi->SetTitle("Generated Particles #phi, |#eta| < 1");
3258         fhGenPi0Phi->SetLineColor(1);
3259         fhGenGamPhi->SetLineColor(4);
3260         fhGenEtaPhi->SetLineColor(2);
3261         fhGenOmegaPhi->SetLineColor(7);
3262         fhGenElePhi->SetLineColor(6);
3263         //Select the maximum of the histogram to show all lines.
3264         if(fhGenPi0Phi->GetMaximum() >= fhGenGamPhi->GetMaximum() && fhGenPi0Phi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
3265            fhGenPi0Phi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenPi0Phi->GetMaximum() >= fhGenElePhi->GetMaximum())
3266                 haxisphi->SetMaximum(fhGenPi0Phi->GetMaximum());
3267         else if(fhGenGamPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenGamPhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
3268                         fhGenGamPhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenGamPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
3269                 haxisphi->SetMaximum(fhGenGamPhi->GetMaximum());
3270         else if(fhGenEtaPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenEtaPhi->GetMaximum() >= fhGenGamPhi->GetMaximum() && 
3271                         fhGenEtaPhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenEtaPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
3272                 haxisphi->SetMaximum(fhGenEtaPhi->GetMaximum());        
3273         else if(fhGenOmegaPhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenOmegaPhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
3274                         fhGenOmegaPhi->GetMaximum() >= fhGenGamPhi->GetMaximum() && fhGenOmegaPhi->GetMaximum() >= fhGenElePhi->GetMaximum())
3275                 haxisphi->SetMaximum(fhGenOmegaPhi->GetMaximum());
3276         else if(fhGenElePhi->GetMaximum() >= fhGenPi0Phi->GetMaximum() && fhGenElePhi->GetMaximum() >= fhGenEtaPhi->GetMaximum() && 
3277                         fhGenElePhi->GetMaximum() >= fhGenOmegaPhi->GetMaximum() && fhGenElePhi->GetMaximum() >= fhGenGamPhi->GetMaximum())
3278                 haxisphi->SetMaximum(fhGenElePhi->GetMaximum());
3279         haxisphi->SetMinimum(100);
3280         haxisphi->Draw("axis");
3281         fhGenPi0Phi->Draw("same");
3282         fhGenGamPhi->Draw("same");
3283         fhGenEtaPhi->Draw("same");
3284         fhGenOmegaPhi->Draw("same");
3285         fhGenElePhi->Draw("same");
3286         
3287         sprintf(name,"QA_%s_GeneratedDistributions.eps",fCalorimeter.Data());
3288         c10->Print(name); printf("Plot: %s\n",name);
3289         
3290         
3291         //Reconstructed clusters depending on its original particle.
3292         //printf("c1\n");
3293         sprintf(cname,"QA_%s_recgenid",fCalorimeter.Data());
3294         TCanvas  * c11 = new TCanvas(cname, "Reconstructed particles, function of their original particle ID", 400, 400) ;
3295         c11->Divide(2, 2);
3296         
3297         
3298         c11->cd(1) ; 
3299         gPad->SetLogy();
3300         TH1F * hGamE   = (TH1F*) fhGamE->ProjectionX(Form("%s_px",fhGamE->GetName()),-1,-1);
3301         TH1F * hPi0E   = (TH1F*) fhPi0E->ProjectionX(Form("%s_px",fhPi0E->GetName()),-1,-1);
3302         TH1F * hEleE   = (TH1F*) fhEleE->ProjectionX(Form("%s_px",fhEleE->GetName()),-1,-1);
3303         TH1F * hNeHadE = (TH1F*) fhNeHadE->ProjectionX(Form("%s_px",fhNeHadE->GetName()),-1,-1);
3304         TH1F * hChHadE = (TH1F*) fhChHadE->ProjectionX(Form("%s_px",fhChHadE->GetName()),-1,-1);
3305         TH1F * haxisE  = (TH1F*) hPi0E->Clone(Form("%s_axisE",fhPi0E->GetName()));  
3306         haxisE->SetTitle("Reconstructed particles E, function of their original particle ID");
3307         hPi0E->SetLineColor(1);
3308         hGamE->SetLineColor(4);
3309         hNeHadE->SetLineColor(2);
3310         hChHadE->SetLineColor(7);
3311         hEleE->SetLineColor(6);
3312         
3313         //Select the maximum of the histogram to show all lines.
3314         if(hPi0E->GetMaximum() >= hGamE->GetMaximum() && hPi0E->GetMaximum() >= hNeHadE->GetMaximum() && 
3315            hPi0E->GetMaximum() >= hChHadE->GetMaximum() && hPi0E->GetMaximum() >= hEleE->GetMaximum())
3316                 haxisE->SetMaximum(hPi0E->GetMaximum());
3317         else if(hGamE->GetMaximum() >= hPi0E->GetMaximum() && hGamE->GetMaximum() >= hNeHadE->GetMaximum() && 
3318                         hGamE->GetMaximum() >= hChHadE->GetMaximum() && hGamE->GetMaximum() >= hEleE->GetMaximum())
3319                 haxisE->SetMaximum(hGamE->GetMaximum());
3320         else if(hNeHadE->GetMaximum() >= hPi0E->GetMaximum() && hNeHadE->GetMaximum() >= hGamE->GetMaximum() && 
3321                         hNeHadE->GetMaximum() >= hChHadE->GetMaximum() && hNeHadE->GetMaximum() >= hEleE->GetMaximum())
3322                 haxisE->SetMaximum(hNeHadE->GetMaximum());      
3323         else if(hChHadE->GetMaximum() >= hPi0E->GetMaximum() && hChHadE->GetMaximum() >= hNeHadE->GetMaximum() && 
3324                         hChHadE->GetMaximum() >= hGamE->GetMaximum() && hChHadE->GetMaximum() >= hEleE->GetMaximum())
3325                 haxisE->SetMaximum(hChHadE->GetMaximum());
3326         else if(hEleE->GetMaximum() >= hPi0E->GetMaximum() && hEleE->GetMaximum() >= hNeHadE->GetMaximum() && 
3327                         hEleE->GetMaximum() >= hChHadE->GetMaximum() && hEleE->GetMaximum() >= hGamE->GetMaximum())
3328                 haxisE->SetMaximum(hEleE->GetMaximum());
3329         haxisE->SetXTitle("E (GeV)");
3330         haxisE->SetMinimum(1);
3331         haxisE->Draw("axis");
3332         hPi0E->Draw("same");
3333         hGamE->Draw("same");
3334         hNeHadE->Draw("same");
3335         hChHadE->Draw("same");
3336         hEleE->Draw("same");
3337         
3338         TLegend pLegend2(0.8,0.65,0.95,0.93);
3339         pLegend2.SetTextSize(0.06);
3340         pLegend2.AddEntry(hPi0E,"  #pi^{0}","L");
3341         pLegend2.AddEntry(hGamE,"  #gamma","L");
3342         pLegend2.AddEntry(hEleE,"  e^{#pm}","L");
3343         pLegend2.AddEntry(hChHadE,"  h^{#pm}","L");
3344         pLegend2.AddEntry(hNeHadE,"  h^{0}","L");
3345         pLegend2.SetFillColor(10);
3346         pLegend2.SetBorderSize(1);
3347         pLegend2.Draw();
3348         
3349         
3350         c11->cd(2) ; 
3351         gPad->SetLogy();
3352         //printf("%s, %s, %s, %s, %s\n",fhGamPt->GetName(),fhPi0Pt->GetName(),fhElePt->GetName(),fhNeHadPt->GetName(), fhChHadPt->GetName());
3353         TH1F * hGamPt   = (TH1F*) fhGamPt->ProjectionX(Form("%s_px",fhGamPt->GetName()),-1,-1);
3354         TH1F * hPi0Pt   = (TH1F*) fhPi0Pt->ProjectionX(Form("%s_px",fhPi0Pt->GetName()),-1,-1);
3355         TH1F * hElePt   = (TH1F*) fhElePt->ProjectionX(Form("%s_px",fhElePt->GetName()),-1,-1);
3356         TH1F * hNeHadPt = (TH1F*) fhNeHadPt->ProjectionX(Form("%s_px",fhNeHadPt->GetName()),-1,-1);
3357         TH1F * hChHadPt = (TH1F*) fhChHadPt->ProjectionX(Form("%s_px",fhChHadPt->GetName()),-1,-1);
3358         haxispt  = (TH1F*) hPi0Pt->Clone(Form("%s_axisPt",fhPi0Pt->GetName()));  
3359         haxispt->SetTitle("Reconstructed particles p_{T}, function of their original particle ID");
3360         hPi0Pt->SetLineColor(1);
3361         hGamPt->SetLineColor(4);
3362         hNeHadPt->SetLineColor(2);
3363         hChHadPt->SetLineColor(7);
3364         hElePt->SetLineColor(6);
3365         
3366         //Select the maximum of the histogram to show all lines.
3367         if(hPi0Pt->GetMaximum() >= hGamPt->GetMaximum() && hPi0Pt->GetMaximum() >= hNeHadPt->GetMaximum() && 
3368            hPi0Pt->GetMaximum() >= hChHadPt->GetMaximum() && hPi0Pt->GetMaximum() >= hElePt->GetMaximum())
3369                 haxispt->SetMaximum(hPi0Pt->GetMaximum());
3370         else if(hGamPt->GetMaximum() >= hPi0Pt->GetMaximum() && hGamPt->GetMaximum() >= hNeHadPt->GetMaximum() && 
3371                         hGamPt->GetMaximum() >= hChHadPt->GetMaximum() && hGamPt->GetMaximum() >= hElePt->GetMaximum())
3372                 haxispt->SetMaximum(hGamPt->GetMaximum());
3373         else if(hNeHadPt->GetMaximum() >= hPi0Pt->GetMaximum() && hNeHadPt->GetMaximum() >= hGamPt->GetMaximum() && 
3374                         hNeHadPt->GetMaximum() >= hChHadPt->GetMaximum() && hNeHadPt->GetMaximum() >= hElePt->GetMaximum())
3375                 haxispt->SetMaximum(hNeHadPt->GetMaximum());    
3376         else if(hChHadPt->GetMaximum() >= hPi0Pt->GetMaximum() && hChHadPt->GetMaximum() >= hNeHadPt->GetMaximum() && 
3377                         hChHadPt->GetMaximum() >= hGamPt->GetMaximum() && hChHadPt->GetMaximum() >= hElePt->GetMaximum())
3378                 haxispt->SetMaximum(hChHadPt->GetMaximum());
3379         else if(hElePt->GetMaximum() >= hPi0Pt->GetMaximum() && hElePt->GetMaximum() >= hNeHadPt->GetMaximum() && 
3380                         hElePt->GetMaximum() >= hChHadPt->GetMaximum() && hElePt->GetMaximum() >= hGamPt->GetMaximum())
3381                 haxispt->SetMaximum(hElePt->GetMaximum());
3382         haxispt->SetXTitle("p_{T} (GeV/c)");
3383         haxispt->SetMinimum(1);
3384         haxispt->Draw("axis");
3385         hPi0Pt->Draw("same");
3386         hGamPt->Draw("same");
3387         hNeHadPt->Draw("same");
3388         hChHadPt->Draw("same");
3389     hElePt->Draw("same");
3390         
3391         
3392         c11->cd(3) ;
3393         gPad->SetLogy();
3394         
3395         TH1F * hGamEta   = (TH1F*) fhGamEta->ProjectionX(Form("%s_px",fhGamEta->GetName()),-1,-1);
3396         TH1F * hPi0Eta   = (TH1F*) fhPi0Eta->ProjectionX(Form("%s_px",fhPi0Eta->GetName()),-1,-1);
3397         TH1F * hEleEta   = (TH1F*) fhEleEta->ProjectionX(Form("%s_px",fhEleEta->GetName()),-1,-1);
3398         TH1F * hNeHadEta = (TH1F*) fhNeHadEta->ProjectionX(Form("%s_px",fhNeHadEta->GetName()),-1,-1);
3399         TH1F * hChHadEta = (TH1F*) fhChHadEta->ProjectionX(Form("%s_px",fhChHadEta->GetName()),-1,-1);
3400         haxiseta  = (TH1F*) hPi0Eta->Clone(Form("%s_axisEta",fhPi0Eta->GetName()));  
3401         haxiseta->SetTitle("Reconstructed particles #eta, function of their original particle ID");
3402         hPi0Eta->SetLineColor(1);
3403         hGamEta->SetLineColor(4);
3404         hNeHadEta->SetLineColor(2);
3405         hChHadEta->SetLineColor(7);
3406         hEleEta->SetLineColor(6);
3407         //Select the maximum of the histogram to show all lines.
3408         if(hPi0Eta->GetMaximum() >= hGamEta->GetMaximum() && hPi0Eta->GetMaximum() >= hNeHadEta->GetMaximum() && 
3409            hPi0Eta->GetMaximum() >= hChHadEta->GetMaximum() && hPi0Eta->GetMaximum() >= hEleEta->GetMaximum())
3410                 haxiseta->SetMaximum(hPi0Eta->GetMaximum());
3411         else if(hGamEta->GetMaximum() >= hPi0Eta->GetMaximum() && hGamEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
3412                         hGamEta->GetMaximum() >= hChHadEta->GetMaximum() && hGamEta->GetMaximum() >= hEleEta->GetMaximum())
3413                 haxiseta->SetMaximum(hGamEta->GetMaximum());
3414         else if(hNeHadEta->GetMaximum() >= hPi0Eta->GetMaximum() && hNeHadEta->GetMaximum() >= hGamEta->GetMaximum() && 
3415                         hNeHadEta->GetMaximum() >= hChHadEta->GetMaximum() && hNeHadEta->GetMaximum() >= hEleEta->GetMaximum())
3416                 haxiseta->SetMaximum(hNeHadEta->GetMaximum());  
3417         else if(hChHadEta->GetMaximum() >= hPi0Eta->GetMaximum() && hChHadEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
3418                         hChHadEta->GetMaximum() >= hGamEta->GetMaximum() && hChHadEta->GetMaximum() >= hEleEta->GetMaximum())
3419                 haxiseta->SetMaximum(hChHadEta->GetMaximum());
3420         else if(hEleEta->GetMaximum() >= hPi0Eta->GetMaximum() && hEleEta->GetMaximum() >= hNeHadEta->GetMaximum() && 
3421                         hEleEta->GetMaximum() >= hChHadEta->GetMaximum() && hEleEta->GetMaximum() >= hGamEta->GetMaximum())
3422                 haxiseta->SetMaximum(hEleEta->GetMaximum());
3423         
3424     haxiseta->SetXTitle("#eta");
3425         haxiseta->Draw("axis");
3426         hPi0Eta->Draw("same");
3427         hGamEta->Draw("same");
3428         hNeHadEta->Draw("same");
3429         hChHadEta->Draw("same");
3430         hEleEta->Draw("same");
3431         
3432         
3433         c11->cd(4) ; 
3434         gPad->SetLogy();
3435         TH1F * hGamPhi   = (TH1F*) fhGamPhi->ProjectionX(Form("%s_px",fhGamPhi->GetName()),-1,-1);
3436         TH1F * hPi0Phi   = (TH1F*) fhPi0Phi->ProjectionX(Form("%s_px",fhPi0Phi->GetName()),-1,-1);
3437         TH1F * hElePhi   = (TH1F*) fhElePhi->ProjectionX(Form("%s_px",fhElePhi->GetName()),-1,-1);
3438         TH1F * hNeHadPhi = (TH1F*) fhNeHadPhi->ProjectionX(Form("%s_px",fhNeHadPhi->GetName()),-1,-1);
3439         TH1F * hChHadPhi = (TH1F*) fhChHadPhi->ProjectionX(Form("%s_px",fhChHadPhi->GetName()),-1,-1);
3440         haxisphi  = (TH1F*) hPi0Phi->Clone(Form("%s_axisPhi",fhPi0Phi->GetName()));  
3441         haxisphi->SetTitle("Reconstructed particles #phi, function of their original particle ID");
3442         
3443         hPi0Phi->SetLineColor(1);
3444         hGamPhi->SetLineColor(4);
3445         hNeHadPhi->SetLineColor(2);
3446         hChHadPhi->SetLineColor(7);
3447         hElePhi->SetLineColor(6);
3448         //Select the maximum of the histogram to show all lines.
3449         if(hPi0Phi->GetMaximum() >= hGamPhi->GetMaximum() && hPi0Phi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
3450            hPi0Phi->GetMaximum() >= hChHadPhi->GetMaximum() && hPi0Phi->GetMaximum() >= hElePhi->GetMaximum())
3451                 haxisphi->SetMaximum(hPi0Phi->GetMaximum());
3452         else if(hGamPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hGamPhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
3453                         hGamPhi->GetMaximum() >= hChHadPhi->GetMaximum() && hGamPhi->GetMaximum() >= hElePhi->GetMaximum())
3454                 haxisphi->SetMaximum(hGamPhi->GetMaximum());
3455         else if(hNeHadPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hNeHadPhi->GetMaximum() >= hGamPhi->GetMaximum() && 
3456                         hNeHadPhi->GetMaximum() >= hChHadPhi->GetMaximum() && hNeHadPhi->GetMaximum() >= hElePhi->GetMaximum())
3457                 haxisphi->SetMaximum(hNeHadPhi->GetMaximum());  
3458         else if(hChHadPhi->GetMaximum() >= hPi0Phi->GetMaximum() && hChHadPhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
3459                         hChHadPhi->GetMaximum() >= hGamPhi->GetMaximum() && hChHadPhi->GetMaximum() >= hElePhi->GetMaximum())
3460                 haxisphi->SetMaximum(hChHadPhi->GetMaximum());
3461         else if(hElePhi->GetMaximum() >= hPi0Phi->GetMaximum() && hElePhi->GetMaximum() >= hNeHadPhi->GetMaximum() && 
3462                         hElePhi->GetMaximum() >= hChHadPhi->GetMaximum() && hElePhi->GetMaximum() >= hGamPhi->GetMaximum())
3463                 haxisphi->SetMaximum(hElePhi->GetMaximum());
3464         haxisphi->SetXTitle("#phi (rad)");
3465         haxisphi->Draw("axis");
3466         hPi0Phi->Draw("same");
3467         hGamPhi->Draw("same");
3468         hNeHadPhi->Draw("same");
3469         hChHadPhi->Draw("same");
3470         hElePhi->Draw("same");
3471         
3472         sprintf(name,"QA_%s_RecDistributionsGenID.eps",fCalorimeter.Data());
3473         c11->Print(name); printf("Plot: %s\n",name);
3474         
3475         
3476         //Ratio reconstructed clusters / generated particles in acceptance, for different particle ID
3477         //printf("c1\n");
3478         
3479         TH1F *  hPi0EClone   = (TH1F*)   hPi0E  ->Clone(Form("%s_Clone",fhPi0E->GetName()));
3480         TH1F *  hGamEClone   = (TH1F*)   hGamE  ->Clone(Form("%s_Clone",fhGamE->GetName()));
3481         TH1F *  hPi0PtClone  = (TH1F*)   hPi0Pt ->Clone(Form("%s_Clone",fhPi0Pt->GetName()));
3482         TH1F *  hGamPtClone  = (TH1F*)   hGamPt ->Clone(Form("%s_Clone",fhGamPt->GetName()));   
3483         TH1F *  hPi0EtaClone = (TH1F*)   hPi0Eta->Clone(Form("%s_Clone",fhPi0Eta->GetName()));
3484         TH1F *  hGamEtaClone = (TH1F*)   hGamEta->Clone(Form("%s_Clone",fhGamEta->GetName()));  
3485         TH1F *  hPi0PhiClone = (TH1F*)   hPi0Phi->Clone(Form("%s_Clone",fhPi0Phi->GetName()));
3486         TH1F *  hGamPhiClone = (TH1F*)   hGamPhi->Clone(Form("%s_Clone",fhGamPhi->GetName()));  
3487         
3488         sprintf(cname,"QA_%s_recgenidratio",fCalorimeter.Data());
3489         TCanvas  * c12 = new TCanvas(cname, "Ratio reconstructed clusters / generated particles in acceptance, for different particle ID", 400, 400) ;
3490         c12->Divide(2, 2);
3491         
3492         c12->cd(1) ; 
3493         gPad->SetLogy();
3494         haxisE->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
3495         hPi0EClone->Divide(fhGenPi0AccE);
3496         hGamEClone->Divide(fhGenGamAccE);
3497         haxisE->SetMaximum(5);
3498         haxisE->SetMinimum(1e-2);
3499         haxisE->SetXTitle("E (GeV)");
3500         haxisE->SetYTitle("ratio = rec/gen");
3501         haxisE->Draw("axis");
3502         hPi0E->Draw("same");
3503         hGamE->Draw("same");
3504         
3505         TLegend pLegend3(0.75,0.2,0.9,0.4);
3506         pLegend3.SetTextSize(0.06);
3507         pLegend3.AddEntry(hPi0EClone,"  #pi^{0}","L");
3508         pLegend3.AddEntry(hGamEClone,"  #gamma","L");
3509         pLegend3.SetFillColor(10);
3510         pLegend3.SetBorderSize(1);
3511         pLegend3.Draw();
3512         
3513         c12->cd(2) ; 
3514         gPad->SetLogy();
3515         haxispt->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
3516         hPi0PtClone->Divide(fhGenPi0AccPt);
3517         hGamPtClone->Divide(fhGenGamAccPt);
3518         haxispt->SetMaximum(5);
3519         haxispt->SetMinimum(1e-2);
3520         haxispt->SetXTitle("p_{T} (GeV/c)");
3521         haxispt->SetYTitle("ratio = rec/gen");
3522         haxispt->Draw("axis");
3523         hPi0PtClone->Draw("same");
3524         hGamPtClone->Draw("same");
3525         
3526         c12->cd(3) ;
3527         gPad->SetLogy();
3528         
3529         haxiseta->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
3530         hPi0EtaClone->Divide(fhGenPi0AccEta);
3531         hGamEtaClone->Divide(fhGenGamAccEta);
3532         haxiseta->SetMaximum(1.2);
3533         haxiseta->SetMinimum(1e-2);
3534         haxiseta->SetYTitle("ratio = rec/gen");
3535         haxiseta->SetXTitle("#eta");
3536         haxiseta->Draw("axis");
3537         hPi0EtaClone->Draw("same");
3538         hGamEtaClone->Draw("same");
3539         
3540         
3541         c12->cd(4) ; 
3542         gPad->SetLogy();
3543         haxisphi->SetTitle("Ratio reconstructed clusters / generated particles in acceptance, for different particle ID");
3544         hPi0PhiClone->Divide(fhGenPi0AccPhi);
3545         hGamPhiClone->Divide(fhGenGamAccPhi);
3546     haxisphi->SetYTitle("ratio = rec/gen");
3547         haxisphi->SetXTitle("#phi (rad)");
3548         haxisphi->SetMaximum(1.2);
3549         haxisphi->SetMinimum(1e-2);
3550         haxisphi->Draw("axis");
3551         hPi0PhiClone->Draw("same");
3552         hGamPhiClone->Draw("same");
3553         
3554         sprintf(name,"QA_%s_EfficiencyGenID.eps",fCalorimeter.Data());
3555         c12->Print(name); printf("Plot: %s\n",name);
3556         
3557         
3558         
3559         //Reconstructed distributions
3560         //printf("c1\n");
3561         sprintf(cname,"QA_%s_vertex",fCalorimeter.Data());
3562         TCanvas  * c13 = new TCanvas(cname, "Particle vertex", 400, 400) ;
3563         c13->Divide(2, 2);
3564         
3565         c13->cd(1) ; 
3566         //gPad->SetLogy();
3567         fhEMVxyz->SetTitleOffset(1.6,"Y");
3568     fhEMVxyz->Draw();
3569         
3570         c13->cd(2) ; 
3571         //gPad->SetLogy();
3572         fhHaVxyz->SetTitleOffset(1.6,"Y");
3573         fhHaVxyz->Draw();
3574         
3575         c13->cd(3) ;
3576         gPad->SetLogy();
3577         TH1F * hEMR = (TH1F*) fhEMR->ProjectionY(Form("%s_py",fhEMR->GetName()),-1,-1); 
3578         hEMR->SetLineColor(4);
3579         hEMR->Draw();
3580         
3581         c13->cd(4) ; 
3582         gPad->SetLogy();
3583         TH1F * hHaR = (TH1F*) fhHaR->ProjectionY(Form("%s_py",fhHaR->GetName()),-1,-1); 
3584         hHaR->SetLineColor(4);
3585         hHaR->Draw();
3586         
3587         
3588         sprintf(name,"QA_%s_ParticleVertex.eps",fCalorimeter.Data());
3589         c13->Print(name); printf("Plot: %s\n",name);
3590         
3591         
3592         //Track-matching distributions
3593
3594         //Reconstructed distributions, matched with tracks, generated particle dependence
3595         //printf("c2\n");
3596         sprintf(cname,"QA_%s_rectrackmatchGenID",fCalorimeter.Data());
3597         TCanvas  * c22ch = new TCanvas(cname, "Reconstructed distributions, matched with tracks, for different particle ID", 400, 400) ;
3598         c22ch->Divide(2, 2);
3599         
3600         c22ch->cd(1) ; 
3601         
3602         TH1F * hGamECharged   = (TH1F*) fhGamECharged->ProjectionX(Form("%s_px",fhGamECharged->GetName()),-1,-1);
3603         TH1F * hPi0ECharged   = (TH1F*) fhPi0ECharged->ProjectionX(Form("%s_px",fhPi0ECharged->GetName()),-1,-1);
3604         TH1F * hEleECharged   = (TH1F*) fhEleECharged->ProjectionX(Form("%s_px",fhEleECharged->GetName()),-1,-1);
3605         TH1F * hNeHadECharged = (TH1F*) fhNeHadECharged->ProjectionX(Form("%s_px",fhNeHadECharged->GetName()),-1,-1);
3606         TH1F * hChHadECharged = (TH1F*) fhChHadECharged->ProjectionX(Form("%s_px",fhChHadECharged->GetName()),-1,-1);
3607         hPi0ECharged->SetLineColor(1);
3608         hGamECharged->SetLineColor(4);
3609         hNeHadECharged->SetLineColor(2);
3610         hChHadECharged->SetLineColor(7);
3611         hEleECharged->SetLineColor(6);  
3612         gPad->SetLogy();
3613         fhECharged->SetLineColor(3);
3614         fhECharged->SetMinimum(0.5);
3615         fhECharged->Draw();
3616         hPi0ECharged->Draw("same");
3617         hGamECharged->Draw("same");
3618         hNeHadECharged->Draw("same");
3619         hChHadECharged->Draw("same");
3620         hEleECharged->Draw("same");
3621         TLegend pLegend22(0.75,0.45,0.9,0.8);
3622         pLegend22.SetTextSize(0.06);
3623         pLegend22.AddEntry(fhECharged,"all","L");
3624         pLegend22.AddEntry(hPi0ECharged,"#pi^{0}","L");
3625         pLegend22.AddEntry(hGamECharged,"#gamma","L");
3626         pLegend22.AddEntry(hEleECharged,"e^{#pm}","L");
3627         pLegend22.AddEntry(hChHadECharged,"h^{#pm}","L");
3628         pLegend22.AddEntry(hNeHadECharged,"h^{0}","L");
3629         pLegend22.SetFillColor(10);
3630         pLegend22.SetBorderSize(1);
3631         pLegend22.Draw();
3632         
3633         c22ch->cd(2) ; 
3634         
3635         TH1F * hGamPtCharged   = (TH1F*) fhGamPtCharged->ProjectionX(Form("%s_px",fhGamPtCharged->GetName()),-1,-1);
3636         TH1F * hPi0PtCharged   = (TH1F*) fhPi0PtCharged->ProjectionX(Form("%s_px",fhPi0PtCharged->GetName()),-1,-1);
3637         TH1F * hElePtCharged   = (TH1F*) fhElePtCharged->ProjectionX(Form("%s_px",fhElePtCharged->GetName()),-1,-1);
3638         TH1F * hNeHadPtCharged = (TH1F*) fhNeHadPtCharged->ProjectionX(Form("%s_px",fhNeHadPtCharged->GetName()),-1,-1);
3639         TH1F * hChHadPtCharged = (TH1F*) fhChHadPtCharged->ProjectionX(Form("%s_px",fhChHadPtCharged->GetName()),-1,-1);
3640         hPi0PtCharged->SetLineColor(1);
3641         hGamPtCharged->SetLineColor(4);
3642         hNeHadPtCharged->SetLineColor(2);
3643         hChHadPtCharged->SetLineColor(7);
3644         hElePtCharged->SetLineColor(6); 
3645         gPad->SetLogy();
3646         fhPtCharged->SetLineColor(3);
3647         fhPtCharged->SetMinimum(0.5);
3648         fhPtCharged->Draw();
3649         hPi0PtCharged->Draw("same");
3650         hGamPtCharged->Draw("same");
3651         hNeHadPtCharged->Draw("same");
3652         hChHadPtCharged->Draw("same");
3653         hElePtCharged->Draw("same");    
3654         
3655         c22ch->cd(4) ; 
3656         
3657         TH1F * hGamEtaCharged   = (TH1F*) fhGamEtaCharged->ProjectionX(Form("%s_px",fhGamEtaCharged->GetName()),-1,-1);
3658         TH1F * hPi0EtaCharged   = (TH1F*) fhPi0EtaCharged->ProjectionX(Form("%s_px",fhPi0EtaCharged->GetName()),-1,-1);
3659         TH1F * hEleEtaCharged   = (TH1F*) fhEleEtaCharged->ProjectionX(Form("%s_px",fhEleEtaCharged->GetName()),-1,-1);
3660         TH1F * hNeHadEtaCharged = (TH1F*) fhNeHadEtaCharged->ProjectionX(Form("%s_px",fhNeHadEtaCharged->GetName()),-1,-1);
3661         TH1F * hChHadEtaCharged = (TH1F*) fhChHadEtaCharged->ProjectionX(Form("%s_px",fhChHadEtaCharged->GetName()),-1,-1);
3662         hPi0EtaCharged->SetLineColor(1);
3663         hGamEtaCharged->SetLineColor(4);
3664         hNeHadEtaCharged->SetLineColor(2);
3665         hChHadEtaCharged->SetLineColor(7);
3666         hEleEtaCharged->SetLineColor(6);        
3667         gPad->SetLogy();
3668         fhEtaCharged->SetLineColor(3);
3669         fhEtaCharged->SetMinimum(0.5);
3670         fhEtaCharged->Draw();
3671         hPi0EtaCharged->Draw("same");
3672         hGamEtaCharged->Draw("same");
3673         hNeHadEtaCharged->Draw("same");
3674         hChHadEtaCharged->Draw("same");
3675         hEleEtaCharged->Draw("same");
3676         
3677         c22ch->cd(3) ; 
3678         
3679         TH1F * hGamPhiCharged   = (TH1F*) fhGamPhiCharged->ProjectionX(Form("%s_px",fhGamPhiCharged->GetName()),-1,-1);
3680         TH1F * hPi0PhiCharged   = (TH1F*) fhPi0PhiCharged->ProjectionX(Form("%s_px",fhPi0PhiCharged->GetName()),-1,-1);
3681         TH1F * hElePhiCharged   = (TH1F*) fhElePhiCharged->ProjectionX(Form("%s_px",fhElePhiCharged->GetName()),-1,-1);
3682         TH1F * hNeHadPhiCharged = (TH1F*) fhNeHadPhiCharged->ProjectionX(Form("%s_px",fhNeHadPhiCharged->GetName()),-1,-1);
3683         TH1F * hChHadPhiCharged = (TH1F*) fhChHadPhiCharged->ProjectionX(Form("%s_px",fhChHadPhiCharged->GetName()),-1,-1);
3684         hPi0PhiCharged->SetLineColor(1);
3685         hGamPhiCharged->SetLineColor(4);
3686         hNeHadPhiCharged->SetLineColor(2);
3687         hChHadPhiCharged->SetLineColor(7);
3688         hElePhiCharged->SetLineColor(6);        
3689         gPad->SetLogy();
3690         fhPhiCharged->SetLineColor(3);
3691         fhPhiCharged->SetMinimum(0.5);
3692         fhPhiCharged->Draw();
3693         hPi0PhiCharged->Draw("same");
3694         hGamPhiCharged->Draw("same");
3695         hNeHadPhiCharged->Draw("same");
3696         hChHadPhiCharged->Draw("same");
3697         hElePhiCharged->Draw("same");
3698         
3699         
3700         sprintf(name,"QA_%s_ReconstructedDistributions_TrackMatchedGenID.eps",fCalorimeter.Data());
3701         c22ch->Print(name); printf("Plot: %s\n",name);
3702         
3703         TH1F *  hGamEChargedClone   = (TH1F*)   hGamECharged->Clone(Form("%s_Clone",fhGamECharged->GetName()));
3704         TH1F *  hGamPtChargedClone  = (TH1F*)   hGamPtCharged->Clone(Form("%s_Clone",fhGamPtCharged->GetName()));
3705         TH1F *  hGamEtaChargedClone = (TH1F*)   hGamEtaCharged->Clone(Form("%s_Clone",fhGamEtaCharged->GetName()));
3706         TH1F *  hGamPhiChargedClone = (TH1F*)   hGamPhiCharged->Clone(Form("%s_Clone",fhGamPhiCharged->GetName()));
3707         
3708         TH1F *  hPi0EChargedClone   = (TH1F*)   hPi0ECharged->Clone(Form("%s_Clone",fhPi0ECharged->GetName()));
3709         TH1F *  hPi0PtChargedClone  = (TH1F*)   hPi0PtCharged->Clone(Form("%s_Clone",fhPi0PtCharged->GetName()));
3710         TH1F *  hPi0EtaChargedClone = (TH1F*)   hPi0EtaCharged->Clone(Form("%s_Clone",fhPi0EtaCharged->GetName()));
3711         TH1F *  hPi0PhiChargedClone = (TH1F*)   hPi0PhiCharged->Clone(Form("%s_Clone",fhPi0PhiCharged->GetName()));
3712         
3713         TH1F *  hEleEChargedClone   = (TH1F*)   hEleECharged->Clone(Form("%s_Clone",fhEleECharged->GetName()));
3714         TH1F *  hElePtChargedClone  = (TH1F*)   hElePtCharged->Clone(Form("%s_Clone",fhElePtCharged->GetName()));
3715         TH1F *  hEleEtaChargedClone = (TH1F*)   hEleEtaCharged->Clone(Form("%s_Clone",fhEleEtaCharged->GetName()));
3716         TH1F *  hElePhiChargedClone = (TH1F*)   hElePhiCharged->Clone(Form("%s_Clone",fhElePhiCharged->GetName()));     
3717         
3718         TH1F *  hNeHadEChargedClone   = (TH1F*)   hNeHadECharged->Clone(Form("%s_Clone",fhNeHadECharged->GetName()));
3719         TH1F *  hNeHadPtChargedClone  = (TH1F*)   hNeHadPtCharged->Clone(Form("%s_Clone",fhNeHadPtCharged->GetName()));
3720         TH1F *  hNeHadEtaChargedClone = (TH1F*)   hNeHadEtaCharged->Clone(Form("%s_Clone",fhNeHadEtaCharged->GetName()));
3721         TH1F *  hNeHadPhiChargedClone = (TH1F*)   hNeHadPhiCharged->Clone(Form("%s_Clone",fhNeHadPhiCharged->GetName()));
3722         
3723         TH1F *  hChHadEChargedClone   = (TH1F*)   hChHadECharged->Clone(Form("%s_Clone",fhChHadECharged->GetName()));
3724         TH1F *  hChHadPtChargedClone  = (TH1F*)   hChHadPtCharged->Clone(Form("%s_Clone",fhChHadPtCharged->GetName()));
3725         TH1F *  hChHadEtaChargedClone = (TH1F*)   hChHadEtaCharged->Clone(Form("%s_Clone",fhChHadEtaCharged->GetName()));
3726         TH1F *  hChHadPhiChargedClone = (TH1F*)   hChHadPhiCharged->Clone(Form("%s_Clone",fhChHadPhiCharged->GetName()));       
3727         
3728         //Ratio: reconstructed track matched/ all reconstructed
3729         //printf("c3\n");
3730         sprintf(cname,"QA_%s_rectrackmatchratGenID",fCalorimeter.Data());
3731         TCanvas  * c3ch = new TCanvas(cname, "Ratio: reconstructed track matched/ all reconstructed, for different particle ID", 400, 400) ;
3732         c3ch->Divide(2, 2);
3733         
3734         c3ch->cd(1) ;
3735         hEChargedClone->SetMaximum(1.2);
3736         hEChargedClone->SetMinimum(0.001);      
3737         hEChargedClone->SetLineColor(3);
3738         hEChargedClone->SetYTitle("track matched / all");
3739         hPi0EChargedClone->Divide(hPi0E);
3740         hGamEChargedClone->Divide(hGamE);
3741         hEleEChargedClone->Divide(hEleE);
3742         hNeHadEChargedClone->Divide(hNeHadE);
3743         hChHadEChargedClone->Divide(hChHadE);
3744         hEChargedClone->Draw();
3745         hPi0EChargedClone->Draw("same");
3746         hGamEChargedClone->Draw("same");
3747         hEleEChargedClone->Draw("same");
3748         hNeHadEChargedClone->Draw("same");
3749         hChHadEChargedClone->Draw("same");
3750         
3751         TLegend pLegend3ch(0.75,0.45,0.9,0.8);
3752         pLegend3ch.SetTextSize(0.06);
3753         pLegend3ch.AddEntry(hEChargedClone,"all","L");
3754         pLegend3ch.AddEntry(hPi0EChargedClone,"#pi^{0}","L");
3755         pLegend3ch.AddEntry(hGamEChargedClone,"#gamma","L");
3756         pLegend3ch.AddEntry(hEleEChargedClone,"e^{#pm}","L");
3757         pLegend3ch.AddEntry(hChHadEChargedClone,"h^{#pm}","L");
3758         pLegend3ch.AddEntry(hNeHadEChargedClone,"h^{0}","L");
3759         pLegend3ch.SetFillColor(10);
3760         pLegend3ch.SetBorderSize(1);
3761         pLegend3ch.Draw();
3762         
3763         c3ch->cd(2) ;
3764         hPtChargedClone->SetMaximum(1.2);
3765         hPtChargedClone->SetMinimum(0.001);     
3766         hPtChargedClone->SetLineColor(3);
3767         hPtChargedClone->SetYTitle("track matched / all");
3768         hPi0PtChargedClone->Divide(hPi0Pt);
3769         hGamPtChargedClone->Divide(hGamPt);
3770         hElePtChargedClone->Divide(hElePt);
3771         hNeHadPtChargedClone->Divide(hNeHadPt);
3772         hChHadPtChargedClone->Divide(hChHadPt);
3773         hPtChargedClone->Draw();
3774         hPi0PtChargedClone->Draw("same");
3775         hGamPtChargedClone->Draw("same");
3776         hElePtChargedClone->Draw("same");
3777         hNeHadPtChargedClone->Draw("same");
3778         hChHadPtChargedClone->Draw("same");
3779         
3780         c3ch->cd(4) ;
3781         hEtaChargedClone->SetMaximum(1.2);
3782         hEtaChargedClone->SetMinimum(0.001);    
3783         hEtaChargedClone->SetLineColor(3);
3784         hEtaChargedClone->SetYTitle("track matched / all");
3785         hPi0EtaChargedClone->Divide(hPi0Eta);
3786         hGamEtaChargedClone->Divide(hGamEta);
3787         hEleEtaChargedClone->Divide(hEleEta);
3788         hNeHadEtaChargedClone->Divide(hNeHadEta);
3789         hChHadEtaChargedClone->Divide(hChHadEta);
3790         hEtaChargedClone->Draw();
3791         hPi0EtaChargedClone->Draw("same");
3792         hGamEtaChargedClone->Draw("same");
3793         hEleEtaChargedClone->Draw("same");
3794         hNeHadEtaChargedClone->Draw("same");
3795         hChHadEtaChargedClone->Draw("same");
3796         
3797         c3ch->cd(3) ;
3798         hPhiChargedClone->SetMaximum(1.2);
3799         hPhiChargedClone->SetMinimum(0.001);
3800         hPhiChargedClone->SetLineColor(3);
3801         hPhiChargedClone->SetYTitle("track matched / all");
3802         hPi0PhiChargedClone->Divide(hPi0Phi);
3803         hGamPhiChargedClone->Divide(hGamPhi);
3804         hElePhiChargedClone->Divide(hElePhi);
3805         hNeHadPhiChargedClone->Divide(hNeHadPhi);
3806         hChHadPhiChargedClone->Divide(hChHadPhi);
3807         hPhiChargedClone->Draw();
3808         hPi0PhiChargedClone->Draw("same");
3809         hGamPhiChargedClone->Draw("same");
3810         hElePhiChargedClone->Draw("same");
3811         hNeHadPhiChargedClone->Draw("same");
3812         hChHadPhiChargedClone->Draw("same");
3813         
3814         sprintf(name,"QA_%s_RatioReconstructedMatchedDistributionsGenID.eps",fCalorimeter.Data());
3815         c3ch->Print(name); printf("Plot: %s\n",name);
3816         
3817         }       
3818         //Track-matching distributions
3819                 
3820         sprintf(cname,"QA_%s_trkmatch",fCalorimeter.Data());
3821         TCanvas *cme = new TCanvas(cname,"Track-matching distributions", 400, 400);
3822         cme->Divide(2,2);
3823                 
3824         TLegend pLegendpE0(0.6,0.55,0.9,0.8);
3825         pLegendpE0.SetTextSize(0.04);
3826         pLegendpE0.AddEntry(fh1pOverE,"all","L");
3827         pLegendpE0.AddEntry(fh1pOverER02,"dR < 0.02","L");              
3828         pLegendpE0.SetFillColor(10);
3829         pLegendpE0.SetBorderSize(1);
3830         //pLegendpE0.Draw();
3831                 
3832         cme->cd(1);
3833         if(fh1pOverE->GetEntries() > 0) gPad->SetLogy();
3834         fh1pOverE->SetTitle("Track matches p/E");
3835         fh1pOverE->Draw();
3836         fh1pOverER02->SetLineColor(4);
3837         fh1pOverER02->Draw("same");
3838         pLegendpE0.Draw();
3839                 
3840         cme->cd(2);
3841         if(fh1dR->GetEntries() > 0) gPad->SetLogy();
3842         fh1dR->Draw();
3843         
3844         cme->cd(3);
3845         fh2MatchdEdx->Draw();
3846         
3847         cme->cd(4);
3848         fh2EledEdx->Draw();
3849         
3850         sprintf(name,"QA_%s_TrackMatchingEleDist.eps",fCalorimeter.Data());
3851         cme->Print(name); printf("Plot: %s\n",name);       
3852         
3853         if(IsDataMC()){
3854         sprintf(cname,"QA_%s_trkmatchMCEle",fCalorimeter.Data());
3855         TCanvas *cmemc = new TCanvas(cname,"Track-matching distributions from MC electrons", 600, 200);
3856         cmemc->Divide(3,1);
3857         
3858         cmemc->cd(1);
3859         gPad->SetLogy();
3860         fhMCEle1pOverE->Draw();
3861         fhMCEle1pOverER02->SetLineColor(4);
3862         fhMCEle1pOverE->SetLineColor(1);
3863         fhMCEle1pOverER02->Draw("same");
3864         pLegendpE0.Draw();
3865                 
3866         cmemc->cd(2);
3867         gPad->SetLogy();
3868         fhMCEle1dR->Draw();
3869                 
3870         cmemc->cd(3);
3871         fhMCEle2MatchdEdx->Draw();
3872                 
3873         sprintf(name,"QA_%s_TrackMatchingDistMCEle.eps",fCalorimeter.Data());
3874         cmemc->Print(name); printf("Plot: %s\n",name);  
3875         
3876                 
3877         sprintf(cname,"QA_%s_trkmatchMCChHad",fCalorimeter.Data());
3878         TCanvas *cmemchad = new TCanvas(cname,"Track-matching distributions from MC charged hadrons", 600, 200);
3879         cmemchad->Divide(3,1);
3880                 
3881         cmemchad->cd(1);
3882         gPad->SetLogy();
3883         fhMCChHad1pOverE->Draw();
3884         fhMCChHad1pOverER02->SetLineColor(4);
3885         fhMCChHad1pOverE->SetLineColor(1);
3886         fhMCChHad1pOverER02->Draw("same");
3887         pLegendpE0.Draw();
3888                 
3889         cmemchad->cd(2);
3890         gPad->SetLogy();
3891         fhMCChHad1dR->Draw();
3892
3893         cmemchad->cd(3);
3894         fhMCChHad2MatchdEdx->Draw();
3895                 
3896         sprintf(name,"QA_%s_TrackMatchingDistMCChHad.eps",fCalorimeter.Data());
3897         cmemchad->Print(name); printf("Plot: %s\n",name);       
3898         
3899         sprintf(cname,"QA_%s_trkmatchMCNeutral",fCalorimeter.Data());
3900         TCanvas *cmemcn = new TCanvas(cname,"Track-matching distributions from MC neutrals", 600, 200);
3901         cmemcn->Divide(3,1);
3902                 
3903         cmemcn->cd(1);
3904         gPad->SetLogy();
3905         fhMCNeutral1pOverE->Draw();
3906         fhMCNeutral1pOverE->SetLineColor(1);
3907         fhMCNeutral1pOverER02->SetLineColor(4);
3908         fhMCNeutral1pOverER02->Draw("same");
3909         pLegendpE0.Draw();
3910                 
3911         cmemcn->cd(2);
3912         gPad->SetLogy();
3913         fhMCNeutral1dR->Draw();
3914                 
3915         cmemcn->cd(3);
3916         fhMCNeutral2MatchdEdx->Draw();
3917                 
3918         sprintf(name,"QA_%s_TrackMatchingDistMCNeutral.eps",fCalorimeter.Data());
3919         cmemcn->Print(name); printf("Plot: %s\n",name);       
3920         
3921         sprintf(cname,"QA_%s_trkmatchpE",fCalorimeter.Data());
3922         TCanvas *cmpoe = new TCanvas(cname,"Track-matching distributions, p/E", 400, 200);
3923         cmpoe->Divide(2,1);
3924                 
3925         cmpoe->cd(1);
3926         gPad->SetLogy();
3927         fh1pOverE->SetLineColor(1);
3928         fhMCEle1pOverE->SetLineColor(4);
3929         fhMCChHad1pOverE->SetLineColor(2);
3930         fhMCNeutral1pOverE->SetLineColor(7);
3931         fh1pOverER02->SetMinimum(0.5);
3932         fh1pOverE->Draw();
3933         fhMCEle1pOverE->Draw("same");
3934         fhMCChHad1pOverE->Draw("same");
3935         fhMCNeutral1pOverE->Draw("same");
3936         TLegend pLegendpE(0.65,0.55,0.9,0.8);
3937         pLegendpE.SetTextSize(0.06);
3938         pLegendpE.AddEntry(fh1pOverE,"all","L");
3939         pLegendpE.AddEntry(fhMCEle1pOverE,"e^{#pm}","L");
3940         pLegendpE.AddEntry(fhMCChHad1pOverE,"h^{#pm}","L");
3941         pLegendpE.AddEntry(fhMCNeutral1pOverE,"neutrals","L");
3942         pLegendpE.SetFillColor(10);
3943         pLegendpE.SetBorderSize(1);
3944         pLegendpE.Draw();
3945         
3946         cmpoe->cd(2);
3947         gPad->SetLogy();
3948         fh1pOverER02->SetTitle("Track matches p/E, dR<0.2");
3949         fh1pOverER02->SetLineColor(1);
3950         fhMCEle1pOverER02->SetLineColor(4);
3951         fhMCChHad1pOverER02->SetLineColor(2);
3952         fhMCNeutral1pOverER02->SetLineColor(7);
3953         fh1pOverER02->SetMaximum(fh1pOverE->GetMaximum());
3954         fh1pOverER02->SetMinimum(0.5);
3955         fh1pOverER02->Draw();
3956         fhMCEle1pOverER02->Draw("same");
3957         fhMCChHad1pOverER02->Draw("same");
3958         fhMCNeutral1pOverER02->Draw("same");
3959         
3960         //              TLegend pLegendpE2(0.65,0.55,0.9,0.8);
3961         //              pLegendpE2.SetTextSize(0.06);
3962         //              pLegendpE2.SetHeader("dR < 0.02");
3963         //              pLegendpE2.SetFillColor(10);
3964         //              pLegendpE2.SetBorderSize(1);
3965         //              pLegendpE2.Draw();
3966         
3967         sprintf(name,"QA_%s_TrackMatchingPOverE.eps",fCalorimeter.Data());
3968         cmpoe->Print(name); printf("Plot: %s\n",name);                          
3969         }
3970         
3971         char line[1024] ; 
3972         sprintf(line, ".!tar -zcf QA_%s_%s.tar.gz *%s*.eps", fCalorimeter.Data(), GetName(),fCalorimeter.Data()) ; 
3973         gROOT->ProcessLine(line);
3974         sprintf(line, ".!rm -fR *.eps"); 
3975         gROOT->ProcessLine(line);
3976         
3977         printf("AliAnaCalorimeterQA::Terminate() - !! All the eps files are in QA_%s_%s.tar.gz !!!\n",  fCalorimeter.Data(), GetName());
3978         
3979 }