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