]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskChargedJetsPA.cxx
fix warnings
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskChargedJetsPA.cxx
1 #ifndef ALIANALYSISTASKSE_H
2 #include <Riostream.h>
3 #include <TROOT.h>
4 #include <TFile.h>
5 #include <TCint.h>
6 #include <TChain.h>
7 #include <TTree.h>
8 #include <TKey.h>
9 #include <TProfile.h>
10 #include <TProfile2D.h>
11 #include <TH1F.h>
12 #include <TH2F.h>
13 #include <TCanvas.h>
14 #include <TList.h>
15 #include <TClonesArray.h>
16 #include <TObject.h>
17 #include <TMath.h>
18 #include <TSystem.h>
19 #include <TInterpreter.h>
20 #include <TH1.h>
21 #include "AliAnalysisTask.h"
22 #include "AliCentrality.h"
23 #include "AliStack.h"
24 #include "AliESDEvent.h"
25 #include "AliESDInputHandler.h"
26 #include "AliAODEvent.h"
27 #include "AliAODHandler.h"
28 #include "AliAnalysisManager.h"
29 #include "AliAnalysisTaskSE.h"
30 #endif
31
32 #include <time.h>
33 #include <TRandom3.h>
34 #include "AliGenPythiaEventHeader.h"
35 #include "AliAODMCHeader.h"
36 #include "AliMCEvent.h"
37 #include "AliLog.h"
38 #include <AliEmcalJet.h>
39 #include <AliPicoTrack.h>
40 #include "AliVEventHandler.h"
41 #include "AliVParticle.h"
42 #include "AliAODMCParticle.h"
43 #include "AliAnalysisUtils.h"
44 #include "AliRhoParameter.h"
45
46 #include "AliAnalysisTaskChargedJetsPA.h"
47 using std::min;
48
49 //TODO: Not accessing the particles when using MC
50 //TODO: FillHistogram can be done better with virtual TH1(?)
51 ClassImp(AliAnalysisTaskChargedJetsPA)
52
53 // ######################################################################################## DEFINE HISTOGRAMS
54 void AliAnalysisTaskChargedJetsPA::Init()
55 {
56   #ifdef DEBUGMODE
57     AliInfo("Creating histograms.");
58   #endif
59
60   TH1D* tmpHisto = AddHistogram1D<TH1D>("hNumberEvents", "Number of events (0 = before cuts, 1 = after cuts)", "", 2, 0, 2, "stage","N^{Events}/cut");
61   tmpHisto->GetXaxis()->SetBinLabel(1, "Before cuts");
62   tmpHisto->GetXaxis()->SetBinLabel(2, "After cuts");
63
64   tmpHisto = AddHistogram1D<TH1D>("hEventAcceptance", "Accepted events (0 = before cuts, 1 = after pile up, 2 = after vertex)", "", 3, 0, 3, "stage","N^{Events}/cut");
65   tmpHisto->GetXaxis()->SetBinLabel(1, "Before cuts");
66   tmpHisto->GetXaxis()->SetBinLabel(2, "After pile up");
67   tmpHisto->GetXaxis()->SetBinLabel(3, "After vertex");
68
69   tmpHisto = AddHistogram1D<TH1D>("hTrackAcceptance", "Accepted tracks (0 = before cuts, 1 = after eta, 2 = after pT)", "", 3, 0, 3, "stage","N^{Tracks}/cut");
70   tmpHisto->GetXaxis()->SetBinLabel(1, "Before cuts");
71   tmpHisto->GetXaxis()->SetBinLabel(2, "After eta");
72   tmpHisto->GetXaxis()->SetBinLabel(3, "After p_{T}");
73
74   tmpHisto = AddHistogram1D<TH1D>("hJetAcceptance", "Accepted jets (0 = before cuts, 1 = after eta, 2 = after pT, 3 = after area)", "", 4, 0, 4, "stage","N^{Jets}/cut");
75   tmpHisto->GetXaxis()->SetBinLabel(1, "Before cuts");
76   tmpHisto->GetXaxis()->SetBinLabel(2, "After eta");
77   tmpHisto->GetXaxis()->SetBinLabel(3, "After p_{T}");
78   tmpHisto->GetXaxis()->SetBinLabel(4, "After area");
79
80   // NOTE: Jet histograms
81   if (fAnalyzeJets)
82   {
83     // ######## Jet spectra
84     AddHistogram1D<TH1D>("hRawJetPt", "Raw jets p_{T} distribution (before cuts)", "", 500, 0., 250., "p_{T} (GeV/c)", "dN^{Jets}/dp_{T}");
85     AddHistogram2D<TH2D>("hJetPt", "Jets p_{T} distribution", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Jets}/dp_{T}");
86     AddHistogram2D<TH2D>("hJetPtBgrdSubtractedKTImprovedCMS", "Jets p_{T} distribution, KT background (Improved CMS) subtracted", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Jets}/dp_{T}");    
87
88     AddHistogram2D<TProfile2D>("hJetPtSubtractedRhoKTImprovedCMS", "Mean subtracted KT (CMS w/o signal) background from jets", "COLZ", 600, 0, 150, fNumberOfCentralityBins, 0, 100, "Jet p_{T}", "Centrality", "#rho mean");
89     AddHistogram2D<TH2D>("hJetPtSubtractedRhoKTImprovedCMS020", "Mean subtracted KT (CMS w/o signal) background from jets, 0-20", "COLZ", 600, 0, 150, 400,0.,40., "Jet p_{T} (GeV/c)", "#rho (GeV/c)", "dN^{Events}/dp_{T}#rho");
90
91     if(fAnalyzeDeprecatedBackgrounds)
92     {
93       AddHistogram2D<TH2D>("hJetPtBgrdSubtractedTR", "Jets p_{T} distribution, TR background (Cone R=0.6 around jets excluded) subtracted", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Jets}/dp_{T}");
94       AddHistogram2D<TH2D>("hJetPtBgrdSubtractedKTPbPb", "Jets p_{T} distribution, KT background (PbPb w/o ghosts) subtracted", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Jets}/dp_{T}");
95       AddHistogram2D<TH2D>("hJetPtBgrdSubtractedKTPbPbWithGhosts", "Jets p_{T} distribution, KT background (PbPb w/ ghosts) subtracted", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Jets}/dp_{T}");
96       AddHistogram2D<TH2D>("hJetPtBgrdSubtractedKTCMS", "Jets p_{T} distribution, KT background (CMS) subtracted", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Jets}/dp_{T}");    
97       AddHistogram2D<TH2D>("hJetPtBgrdSubtractedKTMean", "Jets p_{T} distribution, KT background (Mean) subtracted", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Jets}/dp_{T}");    
98       AddHistogram2D<TH2D>("hJetPtBgrdSubtractedKTTrackLike", "Jets p_{T} distribution, KT background (track-like) subtracted", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Jets}/dp_{T}");
99     }
100
101     // ######## Jet profiles
102     if(fAnalyzeJetProfile)
103     {
104       AddHistogram2D<TH2D>("hJetProfile10GeV", "Jet profile, cone p_{T}/jet p_{T} vs. jet radius, jet p_{T} > 10 GeV", "", 12, 0, 0.6,200, 0., 2., "Cone radius","dN^{Jets}/dR", "Ratio");
105       AddHistogram2D<TH2D>("hJetProfile20GeV", "Jet profile, cone p_{T}/jet p_{T} vs. jet radius, jet p_{T} > 20 GeV", "", 12, 0, 0.6,200, 0., 2., "Cone radius","dN^{Jets}/dR", "Ratio");
106       AddHistogram2D<TH2D>("hJetProfile30GeV", "Jet profile, cone p_{T}/jet p_{T} vs. jet radius, jet p_{T} > 30 GeV", "", 12, 0, 0.6,200, 0., 2., "Cone radius","dN^{Jets}/dR", "Ratio");
107       AddHistogram2D<TH2D>("hJetProfile40GeV", "Jet profile, cone p_{T}/jet p_{T} vs. jet radius, jet p_{T} > 40 GeV", "", 12, 0, 0.6,200, 0., 2., "Cone radius","dN^{Jets}/dR", "Ratio");
108       AddHistogram2D<TH2D>("hJetProfile50GeV", "Jet profile, cone p_{T}/jet p_{T} vs. jet radius, jet p_{T} > 50 GeV", "", 12, 0, 0.6,200, 0., 2., "Cone radius","dN^{Jets}/dR", "Ratio");
109       AddHistogram2D<TH2D>("hJetProfile60GeV", "Jet profile, cone p_{T}/jet p_{T} vs. jet radius, jet p_{T} > 60 GeV", "", 12, 0, 0.6,200, 0., 2., "Cone radius","dN^{Jets}/dR", "Ratio");
110       AddHistogram2D<TH2D>("hJetProfile70GeV", "Jet profile, cone p_{T}/jet p_{T} vs. jet radius, jet p_{T} > 70 GeV", "", 12, 0, 0.6,200, 0., 2., "Cone radius","dN^{Jets}/dR", "Ratio");
111     }
112     // ######## Jet stuff
113     AddHistogram2D<TH2D>("hJetConstituentPt", "Jet constituents p_{T} distribution", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Tracks}/dp_{T}");
114     AddHistogram1D<TH1D>("hJetCountAll", "Number of Jets", "", 200, 0., 200., "N jets","dN^{Events}/dN^{Jets}");
115     AddHistogram1D<TH1D>("hJetCountAccepted", "Number of accepted Jets", "", 200, 0., 200., "N jets","dN^{Events}/dN^{Jets}");
116     AddHistogram2D<TH2D>("hJetCount", "Correlation jets/accepted jets", "", 200, 0., 200., 200, 0., 200., "N jets","N jets accepted", "d^{2}N^{Events}/dN^{Jets dN^{Jets, acc}}");
117     AddHistogram1D<TH1D>("hLeadingJetPt", "Leading jet p_{T}", "", 500, -50., 200., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
118     AddHistogram1D<TH1D>("hSecondLeadingJetPt", "Second leading jet p_{T}", "", 500, -50., 200., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
119     AddHistogram1D<TH1D>("hCorrectedLeadingJetPt", "Corrected leading jet p_{T}", "", 500, -50., 200., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
120     AddHistogram1D<TH1D>("hCorrectedSecondLeadingJetPt", "Corrected second leading jet p_{T}", "", 500, -50., 200., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
121     AddHistogram1D<TH1D>("hJetDeltaPhi", "Jets combinatorial #Delta #phi", "", 250, 0., TMath::Pi(), "#Delta #phi","dN^{Jets}/d(#Delta #phi)");
122     AddHistogram1D<TH1D>("hLeadingJetDeltaPhi", "1st and 2nd leading jet #Delta #phi", "", 250, 0., TMath::Pi(), "#Delta #phi","dN^{Jets}/d(#Delta #phi)");
123
124     // ########## Dijet stuff
125     AddHistogram1D<TH1D>("hDijetLeadingJetPt", "Dijet leading jet p_{T} distribution", "", 500, 0., 100., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
126     AddHistogram1D<TH1D>("hDijetConstituentsPt", "Dijet constituents p_{T} distribution", "", 500, 0., 100., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
127     AddHistogram2D<TH2D>("hDijetPtCorrelation", "Dijet constituents p_{T} correlation", "COLZ", 500, 5., 100., 500, 5., 100., "1st leading jet p_{T} (GeV/c)","2nd leading jet p_{T} (GeV/c)","dN^{Dijets}/d^{2}p_{T}");
128   }
129
130   // NOTE: Jet background histograms
131   if (fAnalyzeBackground)
132   {
133     // ########## Default background estimates
134     AddHistogram2D<TH2D>("hKTBackgroundImprovedCMS", "KT background density (Improved CMS approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
135     AddHistogram2D<TH2D>("hKTBackgroundImprovedCMSExternal", "KT background density (Improved CMS approach from external task)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
136     AddHistogram2D<TH2D>("hDeltaPtKTImprovedCMS", "Background fluctuations #delta p_{T} (KT, Improved CMS-like)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
137     AddHistogram2D<TH2D>("hDeltaPtKTImprovedCMSPartialExclusion", "Background fluctuations #delta p_{T} (KT, Improved CMS-like, partial jet exclusion)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
138     AddHistogram2D<TH2D>("hDeltaPtKTImprovedCMSPartialExclusion_Signal", "Background fluctuations #delta p_{T} (KT, Improved CMS-like, partial jet exclusion w/ 1/N_{sig} probability)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
139     AddHistogram2D<TH2D>("hDeltaPtKTImprovedCMSFullExclusion", "Background fluctuations #delta p_{T} (KT, Improved CMS-like, full leading jet exclusion)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
140     AddHistogram2D<TH2D>("hDeltaPtNoBackground", "Background fluctuations #delta p_{T} (No background)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
141     AddHistogram2D<TH2D>("hDeltaPtNoBackgroundNoEmptyCones", "Background fluctuations #delta p_{T} (No background, no empty cones)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
142
143     AddHistogram1D<TProfile>("hKTMeanBackgroundImprovedCMS", "KT background mean (Improved CMS approach)", "", 100, 0, 100, "Centrality", "#rho mean");
144
145     AddHistogram2D<TH2D>("hDijetBackground", "Background density (dijets excluded)", "", 200, 0., 20., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
146     AddHistogram2D<TH2D>("hDijetBackgroundPerpendicular", "Background density (dijets excluded)", "", 200, 0., 20., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
147
148     if(fAnalyzeDeprecatedBackgrounds)
149     {
150       // ########## Different background estimates
151       AddHistogram2D<TH2D>("hKTBackgroundPbPb", "KT background density (PbPb approach, no ghosts)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
152       AddHistogram2D<TH2D>("hKTBackgroundPbPbWithGhosts", "KT background density (PbPb approach w/ ghosts)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
153       AddHistogram2D<TH2D>("hKTBackgroundCMS", "KT background density (CMS approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
154       AddHistogram2D<TH2D>("hKTBackgroundMean", "KT background density (Mean approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
155       AddHistogram2D<TH2D>("hKTBackgroundTrackLike", "KT background density (Track-like approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
156
157       AddHistogram2D<TH2D>("hTRBackgroundNoExcl", "TR background density (No signal excluded)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
158       AddHistogram2D<TH2D>("hTRBackgroundCone02", "TR background density (Cones R=0.2 around signal jets excluded)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
159       AddHistogram2D<TH2D>("hTRBackgroundCone04", "TR background density (Cones R=0.4 around signal jets excluded)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
160       AddHistogram2D<TH2D>("hTRBackgroundCone06", "TR background density (Cones R=0.6 around signal jets excluded)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
161       AddHistogram2D<TH2D>("hTRBackgroundCone08", "TR background density (Cones R=0.8 around signal jets excluded)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
162       AddHistogram2D<TH2D>("hTRBackgroundExact",  "TR background density (signal jets exactly excluded)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
163
164       // ########## Delta Pt
165       AddHistogram2D<TH2D>("hDeltaPtKTPbPb", "Background fluctuations #delta p_{T} (KT, PbPb w/o ghosts)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
166       AddHistogram2D<TH2D>("hDeltaPtKTPbPbWithGhosts", "Background fluctuations #delta p_{T} (KT, PbPb w/ ghosts)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
167       AddHistogram2D<TH2D>("hDeltaPtKTCMS", "Background fluctuations #delta p_{T} (KT, CMS-like)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
168       AddHistogram2D<TH2D>("hDeltaPtKTMean", "Background fluctuations #delta p_{T} (KT, Mean)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
169       AddHistogram2D<TH2D>("hDeltaPtKTTrackLike", "Background fluctuations #delta p_{T} (KT, track-like)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100, "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
170       AddHistogram2D<TH2D>("hDeltaPtTR", "Background fluctuations #delta p_{T} (TR, cone R=0.6)", "", 1201, -40.0, 40.0, fNumberOfCentralityBins, 0, 100,  "#delta p_{T} (GeV/c)","Centrality","dN^{Jets}/d#delta p_{T}");
171
172       // ########## Profiles for background means vs. centrality
173       AddHistogram1D<TProfile>("hKTMeanBackgroundPbPb", "KT background mean (PbPb approach w/o ghosts)", "", fNumberOfCentralityBins, 0, 100, "Centrality", "#rho mean");
174       AddHistogram1D<TProfile>("hKTMeanBackgroundPbPbWithGhosts", "KT background mean (PbPb approach)", "", fNumberOfCentralityBins, 0, 100, "Centrality", "#rho mean");
175       AddHistogram1D<TProfile>("hKTMeanBackgroundCMS", "KT background mean (CMS approach)", "", fNumberOfCentralityBins, 0, 100, "Centrality", "#rho mean");
176       AddHistogram1D<TProfile>("hKTMeanBackgroundMean", "KT background mean (Mean approach)", "",  fNumberOfCentralityBins, 0, 100, "Centrality", "#rho mean");
177       AddHistogram1D<TProfile>("hKTMeanBackgroundTPC", "KT background mean (Track-like approach)", "", fNumberOfCentralityBins, 0, 100, "Centrality", "#rho mean");
178       AddHistogram1D<TProfile>("hTRMeanBackground", "TR background mean", "", fNumberOfCentralityBins, 0, 100, "Centrality", "#rho mean");
179     }
180   }
181   // NOTE: Jet constituent correlations
182   if(fAnalyzeMassCorrelation)
183   {
184     AddHistogram1D<TH1D>("hJetMassFromConstituents", "Jet mass by mass of charged constituents", "", 200, 0., 200., "N jets","dN^{Jets}/dN^{mass}");
185     AddHistogram1D<TH1D>("hJetMass", "Jet mass from fastjet", "", 200, 0., 200., "N jets","dN^{Jets}/dN^{mass}");
186
187     AddHistogram2D<TH2D>("hJetPtVsMass", "Correlation jet pt/summed constituent jet", "", 400, 0., 100., 400, 0., 100., "p_{T}","Mass", "d^{2}N}/dN^{p_{T}dM");
188     AddHistogram2D<TH2D>("hJetPtVsJetMass", "Correlation jet pt/summed jet", "", 400, 0., 100., 400, 0., 100., "p_{T}","Mass", "d^{2}N}/dN^{p_{T}dM");
189
190     AddHistogram2D<TH2D>("hJetPtVsProtonCount", "Correlation jet pt/amount of proton in jet", "", 400, 0., 100., 20, 0., 1., "p_{T}","Proton percentage", "d^{2}N}/dN^{p_{T}dPercentage");
191     AddHistogram2D<TH2D>("hJetPtVsPionCount", "Correlation jet pt/amount of pion in jet", "", 400, 0., 100., 20, 0., 1., "p_{T}","Pion percentage", "d^{2}N}/dN^{p_{T}dPercentage");
192     AddHistogram2D<TH2D>("hJetPtVsKaonCount", "Correlation jet pt/amount of kaon in jet", "", 400, 0., 100., 20, 0., 1., "p_{T}","Kaon percentage", "d^{2}N}/dN^{p_{T}dPercentage");
193     AddHistogram2D<TH2D>("hJetPtVsElectronCount", "Correlation jet pt/amount of proton in jet", "", 400, 0., 100., 20, 0., 1., "p_{T}","Electron percentage", "d^{2}N}/dN^{p_{T}dPercentage");
194     AddHistogram2D<TH2D>("hJetPtVsOthersCount", "Correlation jet pt/amount of other particles in jet", "", 400, 0., 100., 20, 0., 1., "p_{T}","Others percentage", "d^{2}N}/dN^{p_{T}dPercentage");
195     AddHistogram1D<TH1D>("hJetConstituentProtonCount", "Proton count in jets", "", 100, 0., 100., "N protons","dN^{Jets}/dN^{protons}");
196     AddHistogram1D<TH1D>("hJetConstituentPionCount", "Pion count in jets", "", 100, 0., 100., "N pions","dN^{Jets}/dN^{pions}");
197     AddHistogram1D<TH1D>("hJetConstituentKaonCount", "Kaon count in jets", "", 100, 0., 100., "N kaons","dN^{Jets}/dN^{kaons}");
198     AddHistogram1D<TH1D>("hJetConstituentElectronCount", "Electron count in jets", "", 100, 0., 100., "N electrons","dN^{Jets}/dN^{electrons}");
199     AddHistogram1D<TH1D>("hJetConstituentOthersCount", "Others count in jets", "", 100, 0., 100., "N others","dN^{Jets}/dN^{others}");
200
201     AddHistogram2D<TH2D>("hJetPtVsMass_6_14", "Correlation jet pt/summed constituent jet", "", 400, 0., 100., 400, 0., 100., "p_{T}","Mass", "d^{2}N}/dN^{p_{T}dM");
202     AddHistogram2D<TH2D>("hJetPtVsJetMass_6_14", "Correlation jet pt/summed jet", "", 400, 0., 100., 400, 0., 100., "p_{T}","Mass", "d^{2}N}/dN^{p_{T}dM");
203     AddHistogram2D<TH2D>("hJetPtVsProtonCount_6_14", "Correlation jet pt/amount of proton in jet", "", 400, 0., 100., 8, 6., 14., "p_{T}","Proton count", "d^{2}N}/dN^{p_{T}dN");
204     AddHistogram2D<TH2D>("hJetPtVsPionCount_6_14", "Correlation jet pt/amount of pion in jet", "", 400, 0., 100., 8, 6., 14., "p_{T}","Pion count", "d^{2}N}/dN^{p_{T}dN");
205     AddHistogram2D<TH2D>("hJetPtVsKaonCount_6_14", "Correlation jet pt/amount of kaon in jet", "", 400, 0., 100., 8, 6., 14., "p_{T}","Kaon count", "d^{2}N}/dN^{p_{T}dN");
206     AddHistogram2D<TH2D>("hJetPtVsElectronCount_6_14", "Correlation jet pt/amount of proton in jet", "", 400, 0., 100., 8, 6., 14., "p_{T}","Electron count", "d^{2}N}/dN^{p_{T}dN");
207     AddHistogram2D<TH2D>("hJetPtVsOthersCount_6_14", "Correlation jet pt/amount of other particles in jet", "", 400, 0., 100., 8, 6., 14., "p_{T}","Others count", "d^{2}N}/dN^{p_{T}dN");
208     AddHistogram1D<TH1D>("hJetConstituentProtonCount_6_14", "Proton count in jets", "", 100, 0., 100., "N protons","dN^{Jets}/dN^{protons}");
209     AddHistogram1D<TH1D>("hJetConstituentPionCount_6_14", "Pion count in jets", "", 100, 0., 100., "N pions","dN^{Jets}/dN^{pions}");
210     AddHistogram1D<TH1D>("hJetConstituentKaonCount_6_14", "Kaon count in jets", "", 100, 0., 100., "N kaons","dN^{Jets}/dN^{kaons}");
211     AddHistogram1D<TH1D>("hJetConstituentElectronCount_6_14", "Electron count in jets", "", 100, 0., 100., "N electrons","dN^{Jets}/dN^{electrons}");
212     AddHistogram1D<TH1D>("hJetConstituentOthersCount_6_14", "Others count in jets", "", 100, 0., 100., "N others","dN^{Jets}/dN^{others}");
213
214     AddHistogram2D<TH2D>("hJetPtVsMass_2_X", "Correlation jet pt/summed constituent jet", "", 400, 0., 100., 400, 0., 100., "p_{T}","Mass", "d^{2}N}/dN^{p_{T}dM");
215     AddHistogram2D<TH2D>("hJetPtVsJetMass_2_X", "Correlation jet pt/summed jet", "", 400, 0., 100., 400, 0., 100., "p_{T}","Mass", "d^{2}N}/dN^{p_{T}dM");
216     AddHistogram2D<TH2D>("hJetPtVsProtonCount_2_X", "Correlation jet pt/amount of proton in jet", "", 400, 0., 100., 68, 2., 70., "p_{T}","Proton count", "d^{2}N}/dN^{p_{T}dN");
217     AddHistogram2D<TH2D>("hJetPtVsPionCount_2_X", "Correlation jet pt/amount of pion in jet", "", 400, 0., 100., 68, 2., 70., "p_{T}","Pion count", "d^{2}N}/dN^{p_{T}dN");
218     AddHistogram2D<TH2D>("hJetPtVsKaonCount_2_X", "Correlation jet pt/amount of kaon in jet", "", 400, 0., 100., 68, 2., 70., "p_{T}","Kaon count", "d^{2}N}/dN^{p_{T}dN");
219     AddHistogram2D<TH2D>("hJetPtVsElectronCount_2_X", "Correlation jet pt/amount of proton in jet", "", 400, 0., 100., 68, 2., 70., "p_{T}","Electron count", "d^{2}N}/dN^{p_{T}dN");
220     AddHistogram2D<TH2D>("hJetPtVsOthersCount_2_X", "Correlation jet pt/amount of other particles in jet", "", 400, 0., 100., 68, 2., 70., "p_{T}","Others count", "d^{2}N}/dN^{p_{T}dN");
221     AddHistogram1D<TH1D>("hJetConstituentProtonCount_2_X", "Proton count in jets", "", 100, 0., 100., "N protons","dN^{Jets}/dN^{protons}");
222     AddHistogram1D<TH1D>("hJetConstituentPionCount_2_X", "Pion count in jets", "", 100, 0., 100., "N pions","dN^{Jets}/dN^{pions}");
223     AddHistogram1D<TH1D>("hJetConstituentKaonCount_2_X", "Kaon count in jets", "", 100, 0., 100., "N kaons","dN^{Jets}/dN^{kaons}");
224     AddHistogram1D<TH1D>("hJetConstituentElectronCount_2_X", "Electron count in jets", "", 100, 0., 100., "N electrons","dN^{Jets}/dN^{electrons}");
225     AddHistogram1D<TH1D>("hJetConstituentOthersCount_2_X", "Others count in jets", "", 100, 0., 100., "N others","dN^{Jets}/dN^{others}");
226
227     AddHistogram2D<TH2D>("hJetPtVsMass_2_7", "Correlation jet pt/summed constituent jet", "", 400, 0., 100., 400, 0., 100., "p_{T}","Mass", "d^{2}N}/dN^{p_{T}dM");
228     AddHistogram2D<TH2D>("hJetPtVsJetMass_2_7", "Correlation jet pt/summed jet", "", 400, 0., 100., 400, 0., 100., "p_{T}","Mass", "d^{2}N}/dN^{p_{T}dM");
229     AddHistogram2D<TH2D>("hJetPtVsProtonCount_2_7", "Correlation jet pt/amount of proton in jet", "", 400, 0., 100., 6, 2., 8., "p_{T}","Proton count", "d^{2}N}/dN^{p_{T}dN");
230     AddHistogram2D<TH2D>("hJetPtVsPionCount_2_7", "Correlation jet pt/amount of pion in jet", "", 400, 0., 100., 6, 2., 8., "p_{T}","Pion count", "d^{2}N}/dN^{p_{T}dN");
231     AddHistogram2D<TH2D>("hJetPtVsKaonCount_2_7", "Correlation jet pt/amount of kaon in jet", "", 400, 0., 100., 6, 2., 8., "p_{T}","Kaon count", "d^{2}N}/dN^{p_{T}dN");
232     AddHistogram2D<TH2D>("hJetPtVsElectronCount_2_7", "Correlation jet pt/amount of proton in jet", "", 400, 0., 100., 6, 2., 8., "p_{T}","Electron count", "d^{2}N}/dN^{p_{T}dN");
233     AddHistogram2D<TH2D>("hJetPtVsOthersCount_2_7", "Correlation jet pt/amount of other particles in jet", "", 400, 0., 100., 6, 2., 8., "p_{T}","Others count", "d^{2}N}/dN^{p_{T}dN");
234     AddHistogram1D<TH1D>("hJetConstituentProtonCount_2_7", "Proton count in jets", "", 100, 0., 100., "N protons","dN^{Jets}/dN^{protons}");
235     AddHistogram1D<TH1D>("hJetConstituentPionCount_2_7", "Pion count in jets", "", 100, 0., 100., "N pions","dN^{Jets}/dN^{pions}");
236     AddHistogram1D<TH1D>("hJetConstituentKaonCount_2_7", "Kaon count in jets", "", 100, 0., 100., "N kaons","dN^{Jets}/dN^{kaons}");
237     AddHistogram1D<TH1D>("hJetConstituentElectronCount_2_7", "Electron count in jets", "", 100, 0., 100., "N electrons","dN^{Jets}/dN^{electrons}");
238     AddHistogram1D<TH1D>("hJetConstituentOthersCount_2_7", "Others count in jets", "", 100, 0., 100., "N others","dN^{Jets}/dN^{others}");
239
240   }
241
242   // NOTE: Track & Cluster & QA histograms
243   if (fAnalyzeQA)
244   {
245     AddHistogram1D<TH1D>("hVertexX", "X distribution of the vertex", "", 2000, -1., 1., "#Delta x(cm)","dN^{Events}/dx");
246     AddHistogram1D<TH1D>("hVertexY", "Y distribution of the vertex", "", 2000, -1., 1., "#Delta y(cm)","dN^{Events}/dy");
247     AddHistogram2D<TH2D>("hVertexXY", "XY distribution of the vertex", "COLZ", 500, -1., 1., 500, -1., 1.,"#Delta x(cm)", "#Delta y(cm)","dN^{Events}/dxdy");
248     AddHistogram1D<TH1D>("hVertexZBeforeVertexCut", "Z distribution of the vertex (before std. vertex cut)", "", 200, -20., 20., "#Delta z(cm)","dN^{Events}/dz");
249     AddHistogram1D<TH1D>("hVertexZAfterVertexCut", "Z distribution of the vertex (after std. vertex cut)", "", 200, -20., 20., "#Delta z(cm)","dN^{Events}/dz");
250     AddHistogram1D<TH1D>("hVertexR", "R distribution of the vertex", "", 100, 0., 1., "#Delta r(cm)","dN^{Events}/dr");
251     AddHistogram1D<TH1D>("hCentralityV0M", "Centrality distribution V0M", "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
252     AddHistogram1D<TH1D>("hCentralityV0A", "Centrality distribution V0A", "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
253     AddHistogram1D<TH1D>("hCentralityV0C", "Centrality distribution V0C", "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
254     AddHistogram1D<TH1D>("hCentrality", Form("Centrality distribution %s", fCentralityType.Data()), "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
255
256
257     AddHistogram2D<TH2D>("hTrackCountAcc", "Number of tracks in acceptance vs. centrality", "LEGO2", 750, 0., 750., fNumberOfCentralityBins, 0, 100, "N tracks","Centrality", "dN^{Events}/dN^{Tracks}");
258     AddHistogram2D<TH2D>("hTrackPt", "Tracks p_{T} distribution", "", 1000, 0., 250., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)", "Centrality", "dN^{Tracks}/dp_{T}");
259     AddHistogram2D<TH2D>("hTrackPtNegEta", "Tracks p_{T} distribution (negative #eta)", "", 1000, 0., 250., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Tracks}/dp_{T}");
260     AddHistogram2D<TH2D>("hTrackPtPosEta", "Tracks p_{T} distribution (positive #eta)", "", 1000, 0., 250., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Tracks}/dp_{T}");
261     AddHistogram1D<TH1D>("hTrackCharge", "Charge", "", 11, -5, 5, "Charge (e)","dN^{Tracks}/dq");
262     AddHistogram1D<TH1D>("hTrackPhi", "Track #phi distribution", "", 360, 0, TMath::TwoPi(), "#phi","dN^{Tracks}/d#phi");
263     AddHistogram2D<TH2D>("hTrackPhiEta", "Track angular distribution", "LEGO2", 100, 0., 2*TMath::Pi(),100, -2.5, 2.5, "#phi","#eta","dN^{Tracks}/(d#phi d#eta)");
264
265     AddHistogram2D<TH2D>("hTrackPhiPtCut", "Track #phi distribution for different pT cuts", "LEGO2", 360, 0, TMath::TwoPi(), 20, 0, 20, "#phi", "p_{T} lower cut", "dN^{Tracks}/d#phi dp_{T}");
266     AddHistogram2D<TH2D>("hTrackPhiLabel", "Track #phi distribution for different labels", "LEGO2", 360, 0, TMath::TwoPi(), 3, 0, 3, "#phi", "Label", "dN^{Tracks}/d#phi");
267     AddHistogram2D<TH2D>("hTrackPhiTrackType", "Track #phi distribution for different track types", "LEGO2", 360, 0, TMath::TwoPi(), 3, 0, 3, "#phi", "Label", "dN^{Tracks}/d#phi");
268     AddHistogram2D<TH2D>("hTrackEta", "Track #eta distribution", "COLZ", 180, -fTrackEtaWindow, +fTrackEtaWindow, fNumberOfCentralityBins, 0., 100., "#eta", "Centrality", "dN^{Tracks}/d#eta");
269     if (fAnalyzeJets)
270     {
271       // ######## Jet QA
272       AddHistogram1D<TH1D>("hRawJetArea", "Jets area distribution w/o area cut", "", 200, 0., 2., "Area","dN^{Jets}/dA");
273       AddHistogram1D<TH1D>("hJetArea", "Jets area distribution", "", 200, 0., 2., "Area","dN^{Jets}/dA");
274       AddHistogram2D<TH2D>("hRawJetPhiEta", "Raw Jets angular distribution w/o #eta cut", "LEGO2", 360, 0., 2*TMath::Pi(),100, -1.0, 1.0, "#phi","#eta","dN^{Jets}/(d#phi d#eta)");
275       AddHistogram2D<TH2D>("hJetEta", "Jets #eta distribution", "COLZ", 180, -fTrackEtaWindow, +fTrackEtaWindow, fNumberOfCentralityBins, 0., 100., "#eta", "Centrality", "dN^{Jets}/d#eta");
276       AddHistogram2D<TH2D>("hJetEta2GeVTracks", "Jets #eta distribution, track p_{T} > 2 GeV", "COLZ", 180, -fTrackEtaWindow, +fTrackEtaWindow, fNumberOfCentralityBins, 0., 100., "#eta", "Centrality", "dN^{Jets}/d#eta");
277       AddHistogram2D<TH2D>("hJetEta4GeVTracks", "Jets #eta distribution, track p_{T} > 4 GeV", "COLZ", 180, -fTrackEtaWindow, +fTrackEtaWindow, fNumberOfCentralityBins, 0., 100., "#eta", "Centrality", "dN^{Jets}/d#eta");
278       AddHistogram2D<TH2D>("hJetPhiEta", "Jets angular distribution", "LEGO2", 360, 0., 2*TMath::Pi(),100, -1.0, 1.0, "#phi","#eta","dN^{Jets}/(d#phi d#eta)");
279       AddHistogram2D<TH2D>("hJetPtVsConstituentCount", "Jets number of constituents vs. jet p_{T}", "COLZ", 400, 0., 200., 100, 0., 100., "p_{T}","N^{Tracks}","dN^{Jets}/(dp_{T} dN^{tracks})");
280     }
281   }
282
283   // NOTE: Pythia histograms
284   if (fAnalyzePythia)
285   {
286     AddHistogram1D<TH1D>("hPythiaPtHard", "Pythia p_{T} hard distribution", "", 2000, 0, 400, "p_{T} hard","dN^{Events}/dp_{T,hard}");
287   }
288
289   // register Histograms
290   for (Int_t i = 0; i < fHistCount; i++)
291   {
292     fOutputList->Add(fHistList->At(i));
293   }
294   
295   PostData(1,fOutputList); // important for merging
296
297 }
298
299 //________________________________________________________________________
300 AliAnalysisTaskChargedJetsPA::AliAnalysisTaskChargedJetsPA(const char *name, const char* trackArrayName, const char* jetArrayName, const char* backgroundJetArrayName) : AliAnalysisTaskSE(name), fOutputList(0), fAnalyzeJets(1), fAnalyzeJetProfile(1), fAnalyzeQA(1), fAnalyzeBackground(1), fAnalyzeDeprecatedBackgrounds(1), fAnalyzePythia(0), fAnalyzeMassCorrelation(0), fHasTracks(0), fHasJets(0), fHasBackgroundJets(0), fIsKinematics(0), fUseDefaultVertexCut(1), fUsePileUpCut(1), fSetCentralityToOne(0), fPartialAnalysisNParts(1), fPartialAnalysisIndex(0), fJetArray(0), fTrackArray(0), fBackgroundJetArray(0), fJetArrayName(0), fTrackArrayName(0), fBackgroundJetArrayName(0), fNumPtHardBins(11), fUsePtHardBin(-1), fRhoTaskName(), fNcoll(6.88348), fRandConeRadius(0.4), fSignalJetRadius(0.4), fBackgroundJetRadius(0.4), fTRBackgroundConeRadius(0.6), fNumberRandCones(8), fNumberExcludedJets(-1), fDijetMaxAngleDeviation(10.0), fPhysicalJetRadius(0.6), fSignalJetEtaWindow(0.5), fBackgroundJetEtaWindow(0.5), fTrackEtaWindow(0.9), fMinTrackPt(0.150), fMinJetPt(0.15), fMinJetArea(0.5), fMinBackgroundJetPt(0.0), fMinDijetLeadingPt(10.0), fNumberOfCentralityBins(20), fCentralityType("V0A"), fFirstLeadingJet(0), fSecondLeadingJet(0), fNumberSignalJets(0), fCrossSection(0.0), fTrials(0.0), fRandom(0), fHelperClass(0), fInitialized(0), fTaskInstanceCounter(0), fHistList(0), fHistCount(0), fIsDEBUG(0), fEventCounter(0)
301 {
302   #ifdef DEBUGMODE
303     AliInfo("Calling constructor.");
304   #endif
305
306   // Every instance of this task gets his own number
307   static Int_t instance = 0;
308   fTaskInstanceCounter = instance;
309   instance++;
310
311   fTrackArrayName = new TString(trackArrayName);
312   if (fTrackArrayName->Contains("MCParticles") || fTrackArrayName->Contains("mcparticles"))
313     fIsKinematics = kTRUE;
314
315   fJetArrayName = new TString(jetArrayName);
316   if (strcmp(fJetArrayName->Data(),"") == 0)
317   {
318     fAnalyzeJets = kFALSE;
319     fAnalyzeJetProfile = kFALSE;
320   }
321   else
322     fAnalyzeJets = kTRUE;
323     
324   fBackgroundJetArrayName = new TString(backgroundJetArrayName);
325   if (strcmp(fBackgroundJetArrayName->Data(),"") == 0)
326     fAnalyzeBackground = kFALSE;
327   else
328     fAnalyzeBackground = kTRUE;
329
330   DefineOutput(1, TList::Class());
331  
332   fHistList = new TList();
333
334   for(Int_t i=0;i<1024;i++)
335     fSignalJets[i] = NULL;
336
337
338   #ifdef DEBUGMODE
339     AliInfo("Constructor done.");
340   #endif
341   
342 }
343
344 //________________________________________________________________________
345 inline Double_t AliAnalysisTaskChargedJetsPA::GetConePt(Double_t eta, Double_t phi, Double_t radius)
346 {
347   Double_t tmpConePt = 0.0;
348
349   for (Int_t i = 0; i < fTrackArray->GetEntries(); i++)
350   {
351     AliVTrack* tmpTrack = static_cast<AliVTrack*>(fTrackArray->At(i));
352     if (IsTrackInAcceptance(tmpTrack))
353       if(IsTrackInCone(tmpTrack, eta, phi, radius))
354         tmpConePt = tmpConePt + tmpTrack->Pt();
355   }
356   return tmpConePt;
357 }
358
359
360 //________________________________________________________________________
361 inline Double_t AliAnalysisTaskChargedJetsPA::GetPtHard()
362 {
363   #ifdef DEBUGMODE
364     AliInfo("Starting GetPtHard.");
365   #endif
366   AliGenPythiaEventHeader* pythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(MCEvent()->GenEventHeader());
367   if (MCEvent()) 
368     if (!pythiaHeader)
369     {
370       // Check if AOD
371       AliAODMCHeader* aodMCH = dynamic_cast<AliAODMCHeader*>(InputEvent()->FindListObject(AliAODMCHeader::StdBranchName()));
372
373       if (aodMCH)
374       {
375         for(UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++)
376         {
377           pythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(aodMCH->GetCocktailHeader(i));
378           if (pythiaHeader) break;
379         }
380       }
381     }
382
383   #ifdef DEBUGMODE
384     AliInfo("Ending GetPtHard.");
385   #endif
386   if (pythiaHeader)
387     return pythiaHeader->GetPtHard();
388
389   AliWarning(Form("In task %s: GetPtHard() failed!", GetName()));
390   return -1.0;
391 }
392
393
394 //________________________________________________________________________
395 inline Double_t AliAnalysisTaskChargedJetsPA::GetPythiaTrials()
396 {
397   #ifdef DEBUGMODE
398     AliInfo("Starting GetPythiaTrials.");
399   #endif
400   AliGenPythiaEventHeader* pythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(MCEvent()->GenEventHeader());
401   if (MCEvent()) 
402     if (!pythiaHeader)
403     {
404       // Check if AOD
405       AliAODMCHeader* aodMCH = dynamic_cast<AliAODMCHeader*>(InputEvent()->FindListObject(AliAODMCHeader::StdBranchName()));
406
407       if (aodMCH)
408       {
409         for(UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++)
410         {
411           pythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(aodMCH->GetCocktailHeader(i));
412           if (pythiaHeader) break;
413         }
414       }
415     }
416
417   #ifdef DEBUGMODE
418     AliInfo("Ending GetPythiaTrials.");
419   #endif
420   if (pythiaHeader)
421     return pythiaHeader->Trials();
422
423   AliWarning(Form("In task %s: GetPythiaTrials() failed!", GetName()));
424   return -1.0;
425 }
426
427
428
429 //________________________________________________________________________
430 inline Int_t AliAnalysisTaskChargedJetsPA::GetPtHardBin()
431 {
432   #ifdef DEBUGMODE
433     AliInfo("Starting GetPtHardBin.");
434   #endif
435   // ########## PT HARD BIN EDGES
436   const Int_t kPtHardLowerEdges[] =  { 0, 5,11,21,36,57, 84,117,152,191,234};
437   const Int_t kPtHardHigherEdges[] = { 5,11,21,36,57,84,117,152,191,234,1000000};
438
439   Int_t tmpPtHardBin = 0;
440   Double_t tmpPtHard = GetPtHard();
441  
442   for (tmpPtHardBin = 0; tmpPtHardBin <= fNumPtHardBins; tmpPtHardBin++)
443     if (tmpPtHard >= kPtHardLowerEdges[tmpPtHardBin] && tmpPtHard < kPtHardHigherEdges[tmpPtHardBin])
444       break;
445
446   #ifdef DEBUGMODE
447     AliInfo("Ending GetPtHardBin.");
448   #endif
449   return tmpPtHardBin;
450 }
451
452 //________________________________________________________________________
453 Double_t AliAnalysisTaskChargedJetsPA::GetExternalRho()
454 {
455   // Get rho from event.
456   AliRhoParameter *rho = 0;
457   if (!fRhoTaskName.IsNull()) {
458     rho = dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(fRhoTaskName.Data()));
459     if (!rho) {
460       AliWarning(Form("%s: Could not retrieve rho with name %s!", GetName(), fRhoTaskName.Data())); 
461       return 0;
462     }
463   }
464   else
465     return 0;
466
467   return (rho->GetVal());
468 }
469
470
471 //________________________________________________________________________
472 inline Bool_t AliAnalysisTaskChargedJetsPA::IsTrackInCone(AliVTrack* track, Double_t eta, Double_t phi, Double_t radius)
473 {
474   // This is to use a full cone in phi even at the edges of phi (2pi -> 0) (0 -> 2pi)
475   Double_t trackPhi = 0.0;
476   if (track->Phi() > (TMath::TwoPi() - (radius-phi)))
477     trackPhi = track->Phi() - TMath::TwoPi();
478   else if (track->Phi() < (phi+radius - TMath::TwoPi()))
479     trackPhi = track->Phi() + TMath::TwoPi();
480   else
481     trackPhi = track->Phi();
482   
483   if ( TMath::Abs(trackPhi-phi)*TMath::Abs(trackPhi-phi) + TMath::Abs(track->Eta()-eta)*TMath::Abs(track->Eta()-eta) <= radius*radius)
484     return kTRUE;
485   
486   return kFALSE;
487 }
488
489 //________________________________________________________________________
490 inline Bool_t AliAnalysisTaskChargedJetsPA::IsTrackInJet(AliEmcalJet* jet, Int_t trackIndex)
491 {
492   for (Int_t i = 0; i < jet->GetNumberOfTracks(); ++i)
493   {
494     Int_t jetTrack = jet->TrackAt(i);
495     if (jetTrack == trackIndex)
496       return kTRUE;
497   }
498   return kFALSE;
499 }
500
501 //________________________________________________________________________
502 inline Bool_t AliAnalysisTaskChargedJetsPA::IsJetOverlapping(AliEmcalJet* jet1, AliEmcalJet* jet2)
503 {
504   for (Int_t i = 0; i < jet1->GetNumberOfTracks(); ++i)
505   {
506     Int_t jet1Track = jet1->TrackAt(i);
507     for (Int_t j = 0; j < jet2->GetNumberOfTracks(); ++j)
508     {
509       Int_t jet2Track = jet2->TrackAt(j);
510       if (jet1Track == jet2Track)
511         return kTRUE;
512     }
513   }
514   return kFALSE;
515 }
516
517 //________________________________________________________________________
518 inline Bool_t AliAnalysisTaskChargedJetsPA::IsEventInAcceptance(AliVEvent* event)
519 {
520   if (!event)
521     return kFALSE;
522
523   FillHistogram("hEventAcceptance", 0.5); // number of events before manual cuts
524   if(fUsePileUpCut)
525     if(fHelperClass->IsPileUpEvent(event))
526       return kFALSE;
527
528   FillHistogram("hEventAcceptance", 1.5); // number of events after pileup cuts
529
530   if(fAnalyzeQA)
531     FillHistogram("hVertexZBeforeVertexCut",event->GetPrimaryVertex()->GetZ());
532
533   if(fUseDefaultVertexCut)
534   {
535     if(!fHelperClass->IsVertexSelected2013pA(event))
536       return kFALSE;
537   }
538   else // Failsafe vertex cut
539   {
540     if(TMath::Abs(event->GetPrimaryVertex()->GetZ()) > 10.0)
541       return kFALSE;
542   }
543
544   if(fAnalyzeQA)
545     FillHistogram("hVertexZAfterVertexCut",event->GetPrimaryVertex()->GetZ());
546
547   FillHistogram("hEventAcceptance", 2.5); // number of events after vertex cut
548
549   return kTRUE;
550 }
551
552 //________________________________________________________________________
553 inline Bool_t AliAnalysisTaskChargedJetsPA::IsTrackInAcceptance(AliVParticle* track)
554 {
555   FillHistogram("hTrackAcceptance", 0.5);
556   if (track != 0)
557   {
558     if(fIsKinematics)
559     {
560       // TODO: Only working for AOD MC
561       if((!track->Charge()) || (!(static_cast<AliAODMCParticle*>(track))->IsPhysicalPrimary()) )
562         return kFALSE;
563     }
564     if (TMath::Abs(track->Eta()) <= fTrackEtaWindow)
565     {
566       FillHistogram("hTrackAcceptance", 1.5);
567       if (track->Pt() >= fMinTrackPt)
568       {
569         FillHistogram("hTrackAcceptance", 2.5);
570         return kTRUE;
571       }
572     }
573   }
574   return kFALSE;
575 }
576
577 //________________________________________________________________________
578 inline Bool_t AliAnalysisTaskChargedJetsPA::IsBackgroundJetInAcceptance(AliEmcalJet *jet)
579 {   
580   if (jet != 0)
581     if (TMath::Abs(jet->Eta()) <= fBackgroundJetEtaWindow)
582       if (jet->Pt() >= fMinBackgroundJetPt)
583         return kTRUE;
584
585   return kFALSE;
586 }
587
588 //________________________________________________________________________
589 inline Bool_t AliAnalysisTaskChargedJetsPA::IsSignalJetInAcceptance(AliEmcalJet *jet)
590 {   
591   FillHistogram("hJetAcceptance", 0.5);
592   if (jet != 0)
593     if (TMath::Abs(jet->Eta()) <= fSignalJetEtaWindow)
594     {
595       FillHistogram("hJetAcceptance", 1.5);
596       if (jet->Pt() >= fMinJetPt)
597       {
598         FillHistogram("hJetAcceptance", 2.5);
599         if (jet->Area() >= fMinJetArea)
600         {
601           FillHistogram("hJetAcceptance", 3.5);
602           return kTRUE;
603         }
604       }
605     }
606   return kFALSE;
607 }
608
609 //________________________________________________________________________
610 inline Bool_t AliAnalysisTaskChargedJetsPA::IsDijet(AliEmcalJet *jet1, AliEmcalJet *jet2)
611 {   
612   // Output from GetDeltaPhi is < pi in any case
613   if ((jet1 != 0) && (jet2 != 0))
614     if((TMath::Pi() - GetDeltaPhi(jet1->Phi(),jet2->Phi())) < fDijetMaxAngleDeviation)
615       if ((jet1->Pt() > fMinDijetLeadingPt) && (jet2->Pt() > fMinDijetLeadingPt)) //TODO: Introduce recoil jet?
616         return kTRUE;
617
618   return kFALSE;
619 }
620
621 //________________________________________________________________________
622 void AliAnalysisTaskChargedJetsPA::ExecOnce()
623 {
624   #ifdef DEBUGMODE
625     AliInfo("Starting ExecOnce.");
626   #endif
627   fInitialized = kTRUE;
628
629   // Check for track array
630   if (strcmp(fTrackArrayName->Data(), "") != 0)
631   {
632     fTrackArray = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTrackArrayName->Data()));
633     fHasTracks = kTRUE;
634     if (!fTrackArray) 
635     {
636       AliWarning(Form("%s: Could not retrieve tracks %s! This is OK, if tracks are not demanded.", GetName(), fTrackArrayName->Data())); 
637       fHasTracks = kFALSE;
638     } 
639     else
640     {
641       TClass *cl = fTrackArray->GetClass();
642       if (!cl->GetBaseClass("AliVParticle"))
643       {
644         AliError(Form("%s: Collection %s does not contain AliVParticle objects!", GetName(), fTrackArrayName->Data())); 
645         fTrackArray = 0;
646         fHasTracks = kFALSE;
647       }
648     }
649   }
650
651   // Check for jet array
652   if (strcmp(fJetArrayName->Data(), "") != 0)
653   {
654     fJetArray = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fJetArrayName->Data()));
655     fHasJets = kTRUE;
656
657     if (!fJetArray) 
658     {
659       AliWarning(Form("%s: Could not retrieve jets %s! This is OK, if jets are not demanded.", GetName(), fJetArrayName->Data())); 
660       fHasJets = kFALSE;
661     } 
662     else
663     {
664       if (!fJetArray->GetClass()->GetBaseClass("AliEmcalJet")) 
665       {
666         AliError(Form("%s: Collection %s does not contain AliEmcalJet objects!", GetName(), fJetArrayName->Data())); 
667         fJetArray = 0;
668         fHasJets = kFALSE;
669       }
670     }
671   }
672
673   // Check for background object
674   if (strcmp(fBackgroundJetArrayName->Data(), "") != 0)
675   {
676     fBackgroundJetArray = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fBackgroundJetArrayName->Data()));
677     fHasBackgroundJets = kTRUE;
678     if (!fBackgroundJetArray)
679     {
680       AliInfo(Form("%s: Could not retrieve background jets %s! This is OK, if background is not demanded.", GetName(), fBackgroundJetArrayName->Data())); 
681       fHasBackgroundJets = kFALSE;
682     }
683   }
684
685   // Look, if initialization is OK
686   if (!fHasTracks && fAnalyzeBackground)
687   {
688     AliError(Form("%s: Tracks NOT successfully casted although demanded! Deactivating background analysis",GetName()));
689     fAnalyzeBackground = kFALSE;
690   }
691   if ((!fHasJets && fAnalyzeJets) || (!fHasJets && fAnalyzeBackground))
692   {
693     AliError(Form("%s: Jets NOT successfully casted although demanded!  Deactivating jet- and background analysis",GetName()));
694     fAnalyzeJets = kFALSE;
695     fAnalyzeBackground = kFALSE;
696   }
697   if (!fHasBackgroundJets && fAnalyzeBackground)
698   {
699     AliError(Form("%s: Background NOT successfully casted although demanded!  Deactivating background analysis",GetName()));
700     fAnalyzeBackground = kFALSE;
701   }
702
703   // Initialize helper class (for vertex selection & pile up correction)
704   fHelperClass = new AliAnalysisUtils();
705   fHelperClass->SetCutOnZVertexSPD(kFALSE);
706   // Histogram init
707   Init();
708
709   #ifdef DEBUGMODE
710     AliInfo("ExecOnce done.");
711   #endif
712
713 }
714
715 //________________________________________________________________________
716 void AliAnalysisTaskChargedJetsPA::GetSignalJets()
717 {
718   // Reset vars
719   fFirstLeadingJet = NULL;
720   fSecondLeadingJet = NULL;
721   fNumberSignalJets = 0;
722
723   TList tmpJets;
724   for (Int_t i = 0; i < fJetArray->GetEntries(); i++)
725   {
726     AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJetArray->At(i));
727     if (!jet)
728     {
729       AliError(Form("%s: Could not receive jet %d", GetName(), i));
730       continue;
731     }
732     if (!IsSignalJetInAcceptance(jet))
733       continue;
734
735     for (Int_t j = 0; j <= tmpJets.GetEntries(); j++)
736     {
737       if (j>tmpJets.GetEntries()-1) // When passed last item add the jet at the end
738       {
739         tmpJets.Add(jet);
740         break;
741       }
742
743       AliEmcalJet* listJet = static_cast<AliEmcalJet*>(tmpJets.At(j));
744      
745       if(jet->Pt() < listJet->Pt()) // Insert jet before that one in list if pt smaller
746       {
747         tmpJets.AddAt(jet, j);
748         break;
749       }
750     }
751   }
752
753   for (Int_t i = 0; i < tmpJets.GetEntries(); i++)
754   {
755     AliEmcalJet* jet = static_cast<AliEmcalJet*>(tmpJets.At(i));
756     fSignalJets[fNumberSignalJets] = jet;
757     fNumberSignalJets++;
758   }
759   
760   if (fNumberSignalJets > 0)
761     fFirstLeadingJet  = static_cast<AliEmcalJet*>(tmpJets.At(0));
762   if (fNumberSignalJets > 1)
763     fSecondLeadingJet = static_cast<AliEmcalJet*>(tmpJets.At(1));
764
765 }
766
767 //________________________________________________________________________
768 Int_t AliAnalysisTaskChargedJetsPA::GetLeadingJets(TClonesArray* jetArray, Int_t* jetIDArray, Bool_t isSignalJets)
769 {
770 // Writes first two leading jets into already registered array jetIDArray
771
772   if (!jetArray)
773   {
774     AliError("Could not get the jet array to get leading jets from it!");
775     return 0;
776   }
777
778   Float_t maxJetPts[] = {0, 0};
779   jetIDArray[0] = -1;
780   jetIDArray[1] = -1;
781
782   Int_t jetCount = jetArray->GetEntries();
783   Int_t jetCountAccepted = 0;
784
785   for (Int_t i = 0; i < jetCount; i++)
786   {
787     AliEmcalJet* jet = static_cast<AliEmcalJet*>(jetArray->At(i));
788     if (!jet) 
789     {
790       AliError(Form("%s: Could not receive jet %d", GetName(), i));
791       continue;
792     }
793
794     if(isSignalJets)
795     {
796       if (!IsSignalJetInAcceptance(jet)) continue;
797     }
798     else
799     {
800       if (!IsBackgroundJetInAcceptance(jet)) continue;
801     }    
802
803     if (jet->Pt() > maxJetPts[0]) 
804     {
805       maxJetPts[1] = maxJetPts[0];
806       jetIDArray[1] = jetIDArray[0];
807       maxJetPts[0] = jet->Pt();
808       jetIDArray[0] = i;
809     }
810     else if (jet->Pt() > maxJetPts[1]) 
811     {
812       maxJetPts[1] = jet->Pt();
813       jetIDArray[1] = i;
814     }
815     jetCountAccepted++;
816   }
817   return jetCountAccepted;
818 }
819
820
821 //________________________________________________________________________
822 Double_t AliAnalysisTaskChargedJetsPA::GetCorrectedJetPt(AliEmcalJet* jet, Double_t background)
823 {
824   #ifdef DEBUGMODE
825     AliInfo("Getting corrected jet spectra.");
826   #endif
827
828   if(!jet)
829   {
830     AliError("Jet pointer passed to GetCorrectedJetPt() not valid!");
831     return -1.0;
832   }
833
834   Double_t correctedPt = -1.0;
835
836   // if the passed background is not valid, do not subtract it
837   if(background < 0)
838     background = 0;
839
840   // Subtract background
841   correctedPt = jet->Pt() - background * jet->Area();
842
843   #ifdef DEBUGMODE
844     AliInfo("Got corrected jet spectra.");
845   #endif 
846
847   return correctedPt;
848 }
849
850
851
852 //________________________________________________________________________
853 Double_t AliAnalysisTaskChargedJetsPA::GetDeltaPt(Double_t rho, Double_t leadingJetExclusionProbability)
854 {
855   #ifdef DEBUGMODE
856     AliInfo("Getting Delta Pt.");
857   #endif
858
859   // Define an invalid delta pt
860   Double_t deltaPt = -10000.0;
861
862   // Define eta range
863   Double_t etaMin, etaMax;
864   etaMin = -(fTrackEtaWindow-fRandConeRadius);
865   etaMax = +(fTrackEtaWindow-fRandConeRadius);
866
867   // Define random cone
868   Bool_t coneValid = kTRUE;
869   Double_t tmpRandConeEta = etaMin + fRandom->Rndm()*(etaMax-etaMin);
870   Double_t tmpRandConePhi = fRandom->Rndm()*TMath::TwoPi();
871
872   // if there is a jet, check for overlap if demanded
873   if(leadingJetExclusionProbability)
874   {
875     AliEmcalJet* tmpLeading = dynamic_cast<AliEmcalJet*>(fJetArray->At(0));
876     // Get leading jet (regardless of pT)
877     for (Int_t i = 1; i<fJetArray->GetEntries(); i++)
878     {
879       AliEmcalJet* tmpJet = static_cast<AliEmcalJet*>(fJetArray->At(i));
880       // if jet is in acceptance and higher, take as new leading
881       if (tmpJet)
882         if ((TMath::Abs(tmpJet->Eta()) <= fSignalJetEtaWindow) && (tmpJet->Area() >= fMinJetArea))
883           if((!tmpLeading) || (tmpJet->Pt() > tmpLeading->Pt()))
884             tmpLeading = tmpJet;
885     }
886     if(tmpLeading)
887     {
888       Double_t excludedJetPhi = tmpLeading->Phi();
889       Double_t excludedJetEta = tmpLeading->Eta();
890       Double_t tmpDeltaPhi = GetDeltaPhi(tmpRandConePhi, excludedJetPhi);
891
892       // Check, if cone has overlap with jet
893       if ( tmpDeltaPhi*tmpDeltaPhi + TMath::Abs(tmpRandConeEta-excludedJetEta)*TMath::Abs(tmpRandConeEta-excludedJetEta) <= fRandConeRadius*fRandConeRadius)
894       {
895         // Define probability to exclude the RC
896         Double_t probability = leadingJetExclusionProbability;
897
898         // Only exclude cone with a given probability
899         if (fRandom->Rndm()<=probability)
900           coneValid = kFALSE;
901       }
902     }
903   }
904
905
906   // Get the cones' pt and calculate delta pt
907   if (coneValid)
908     deltaPt = GetConePt(tmpRandConeEta,tmpRandConePhi,fRandConeRadius) - (rho*fRandConeRadius*fRandConeRadius*TMath::Pi());
909
910   return deltaPt;
911   #ifdef DEBUGMODE
912     AliInfo("Got Delta Pt.");
913   #endif
914 }
915
916 //________________________________________________________________________
917 void AliAnalysisTaskChargedJetsPA::GetKTBackgroundDensityAll(Int_t numberExcludeLeadingJets, Double_t& rhoPbPb, Double_t& rhoPbPbWithGhosts, Double_t& rhoCMS, Double_t& rhoImprovedCMS, Double_t& rhoMean, Double_t& rhoTrackLike)
918 {
919   #ifdef DEBUGMODE
920     AliInfo("Getting ALL KT background density.");
921   #endif
922
923   static Double_t tmpRhoPbPb[1024];
924   static Double_t tmpRhoPbPbWithGhosts[1024];
925   static Double_t tmpRhoMean[1024];
926   static Double_t tmpRhoCMS[1024];
927   static Double_t tmpRhoImprovedCMS[1024];
928   Double_t tmpCoveredArea = 0.0;
929   Double_t tmpSummedArea = 0.0;
930   Double_t tmpPtTrackLike = 0.0;
931   Double_t tmpAreaTrackLike = 0.0;
932
933   // Setting invalid values
934   rhoPbPb = 0.0;
935   rhoPbPbWithGhosts = 0.0;
936   rhoCMS = 0.0;
937   rhoImprovedCMS = 0.0;
938   rhoMean = 0.0;
939   rhoTrackLike = 0.0;
940
941   Int_t rhoPbPbJetCount = 0;
942   Int_t rhoPbPbWithGhostsJetCount = 0;
943   Int_t rhoCMSJetCount = 0;
944   Int_t rhoImprovedCMSJetCount = 0;
945   Int_t rhoMeanJetCount = 0;
946
947
948   // Find 2 leading KT jets for the original PbPb approach
949   Int_t leadingKTJets[]   = {-1, -1};
950   GetLeadingJets(fBackgroundJetArray, &leadingKTJets[0], kFALSE);
951
952   // Exclude UP TO numberExcludeLeadingJets
953   if(numberExcludeLeadingJets==-1)
954     numberExcludeLeadingJets = fNumberSignalJets;
955   if (fNumberSignalJets < numberExcludeLeadingJets)
956     numberExcludeLeadingJets = fNumberSignalJets;
957
958   for (Int_t i = 0; i < fBackgroundJetArray->GetEntries(); i++)
959   {
960     AliEmcalJet* backgroundJet = static_cast<AliEmcalJet*>(fBackgroundJetArray->At(i));
961
962     if (!backgroundJet)
963     {
964       AliError(Form("%s: Could not receive jet %d", GetName(), i));
965       continue;
966     } 
967
968     if (!IsBackgroundJetInAcceptance(backgroundJet))
969       continue;
970
971     // Search for overlap with signal jets
972     Bool_t isOverlapping = kFALSE;
973     for(Int_t j=0;j<numberExcludeLeadingJets;j++)
974     {
975       AliEmcalJet* signalJet = fSignalJets[j];
976      
977       if(signalJet->Pt() >= 5.0)
978         if(IsJetOverlapping(signalJet, backgroundJet))
979         {
980           isOverlapping = kTRUE;
981           break;
982         }
983     }
984
985     tmpSummedArea += backgroundJet->Area();
986     if(backgroundJet->Pt() > 0.150)
987       tmpCoveredArea += backgroundJet->Area();
988
989     Double_t tmpRho = 0.0;
990     if(backgroundJet->Area())
991       tmpRho = backgroundJet->Pt() / backgroundJet->Area();
992
993     // PbPb approach (take ghosts into account)
994     if ((i != leadingKTJets[0]) && (i != leadingKTJets[1]))
995     {
996       tmpRhoPbPbWithGhosts[rhoPbPbWithGhostsJetCount] = tmpRho;
997       rhoPbPbWithGhostsJetCount++;
998     }
999
1000     if(backgroundJet->Pt() > 0.150)
1001     {
1002       // CMS approach: don't take ghosts into acount
1003       tmpRhoCMS[rhoCMSJetCount] = tmpRho;
1004       rhoCMSJetCount++;
1005
1006       // Improved CMS approach: like CMS but excluding signal
1007       if(!isOverlapping)
1008       {
1009         tmpRhoImprovedCMS[rhoImprovedCMSJetCount] = tmpRho;
1010         rhoImprovedCMSJetCount++;
1011       }
1012
1013       // PbPb w/o ghosts approach (just neglect ghosts)
1014       if ((i != leadingKTJets[0]) && (i != leadingKTJets[1]))
1015       {  
1016         tmpRhoPbPb[rhoPbPbJetCount] = tmpRho;
1017         rhoPbPbJetCount++;
1018       }
1019     }
1020
1021     // (no overlap with signal jets)
1022     if(!isOverlapping)
1023     {
1024       // Mean approach
1025       tmpRhoMean[rhoMeanJetCount] = tmpRho;
1026       rhoMeanJetCount++;
1027       
1028       // Track like approach approach
1029       tmpPtTrackLike += backgroundJet->Pt();
1030       tmpAreaTrackLike += backgroundJet->Area();
1031     }
1032
1033   }
1034
1035   if (tmpAreaTrackLike > 0)
1036     rhoTrackLike = tmpPtTrackLike/tmpAreaTrackLike;
1037   if (rhoPbPbJetCount > 0)
1038     rhoPbPb = TMath::Median(rhoPbPbJetCount, tmpRhoPbPb);
1039   if (rhoPbPbWithGhostsJetCount > 0)
1040     rhoPbPbWithGhosts = TMath::Median(rhoPbPbWithGhostsJetCount, tmpRhoPbPbWithGhosts);
1041   if (rhoCMSJetCount > 0)
1042     rhoCMS = TMath::Median(rhoCMSJetCount, tmpRhoCMS) * tmpCoveredArea/tmpSummedArea;
1043   if (rhoImprovedCMSJetCount > 0)
1044   {
1045     rhoImprovedCMS = TMath::Median(rhoImprovedCMSJetCount, tmpRhoImprovedCMS) * tmpCoveredArea/tmpSummedArea;
1046   }
1047   if (rhoMeanJetCount > 0)
1048     rhoMean = TMath::Mean(rhoMeanJetCount, tmpRhoMean);
1049
1050   #ifdef DEBUGMODE
1051     AliInfo("Got ALL KT background density.");
1052   #endif
1053 }
1054
1055 //________________________________________________________________________
1056 void AliAnalysisTaskChargedJetsPA::GetKTBackgroundDensity(Int_t numberExcludeLeadingJets, Double_t& rhoImprovedCMS)
1057 {
1058   #ifdef DEBUGMODE
1059     AliInfo("Getting KT background density.");
1060   #endif
1061
1062   static Double_t tmpRhoImprovedCMS[1024];
1063   Double_t tmpCoveredArea = 0.0;
1064   Double_t tmpSummedArea = 0.0;
1065
1066   // Setting invalid values
1067   rhoImprovedCMS = 0.0;
1068
1069   Int_t rhoImprovedCMSJetCount = 0;
1070
1071   // Exclude UP TO numberExcludeLeadingJets
1072   if(numberExcludeLeadingJets==-1)
1073     numberExcludeLeadingJets = fNumberSignalJets;
1074   if (fNumberSignalJets < numberExcludeLeadingJets)
1075     numberExcludeLeadingJets = fNumberSignalJets;
1076
1077   for (Int_t i = 0; i < fBackgroundJetArray->GetEntries(); i++)
1078   {
1079     AliEmcalJet* backgroundJet = static_cast<AliEmcalJet*>(fBackgroundJetArray->At(i));
1080
1081     if (!backgroundJet)
1082     {
1083       AliError(Form("%s: Could not receive jet %d", GetName(), i));
1084       continue;
1085     } 
1086
1087     // Search for overlap with signal jets
1088     Bool_t isOverlapping = kFALSE;
1089     for(Int_t j=0;j<numberExcludeLeadingJets;j++)
1090     {
1091       AliEmcalJet* signalJet = fSignalJets[j];
1092       if(signalJet->Pt() >= 5.0)     
1093         if(IsJetOverlapping(signalJet, backgroundJet))
1094         {
1095           isOverlapping = kTRUE;
1096           break;
1097         }
1098     }
1099
1100     tmpSummedArea += backgroundJet->Area();
1101     if(backgroundJet->Pt() > 0.150)
1102       tmpCoveredArea += backgroundJet->Area();
1103
1104     if (!IsBackgroundJetInAcceptance(backgroundJet))
1105       continue;
1106
1107     Double_t tmpRho = backgroundJet->Pt() / backgroundJet->Area();
1108
1109     if(backgroundJet->Pt() > 0.150)
1110       if(!isOverlapping)
1111       {
1112         tmpRhoImprovedCMS[rhoImprovedCMSJetCount] = tmpRho;
1113         rhoImprovedCMSJetCount++;
1114       }
1115   }
1116
1117   if (rhoImprovedCMSJetCount > 0)
1118   {
1119     rhoImprovedCMS = TMath::Median(rhoImprovedCMSJetCount, tmpRhoImprovedCMS) * tmpCoveredArea/tmpSummedArea;
1120   }
1121   #ifdef DEBUGMODE
1122     AliInfo("Got KT background density.");
1123   #endif
1124 }
1125
1126
1127 //________________________________________________________________________
1128 void AliAnalysisTaskChargedJetsPA::GetTRBackgroundDensity(Int_t numberExcludeLeadingJets, Double_t& rhoNoExclusion, Double_t& rhoConeExclusion02, Double_t& rhoConeExclusion04, Double_t& rhoConeExclusion06, Double_t& rhoConeExclusion08, Double_t& rhoExactExclusion)
1129 {
1130   #ifdef DEBUGMODE
1131     AliInfo("Getting TR background density.");
1132   #endif
1133
1134   Double_t summedTracksPtCone04 = 0.0;
1135   Double_t summedTracksPtCone02 = 0.0;
1136   Double_t summedTracksPtCone06 = 0.0;
1137   Double_t summedTracksPtCone08 = 0.0;
1138   Double_t summedTracksPtWithinJets = 0.0;
1139   Double_t summedTracksPt = 0.0;
1140   
1141   // Setting invalid values
1142   rhoNoExclusion = 0.0;
1143   rhoConeExclusion02 = 0.0;
1144   rhoConeExclusion04 = 0.0;
1145   rhoConeExclusion06 = 0.0;
1146   rhoConeExclusion08 = 0.0; 
1147   rhoExactExclusion  = 0.0;
1148
1149   // Exclude UP TO numberExcludeLeadingJets
1150   if(numberExcludeLeadingJets==-1)
1151     numberExcludeLeadingJets = fNumberSignalJets;
1152   if (fNumberSignalJets < numberExcludeLeadingJets)
1153     numberExcludeLeadingJets = fNumberSignalJets;
1154
1155   Int_t fSignalJetCount5GeV = 0;
1156   for(Int_t j=0;j<numberExcludeLeadingJets;j++)
1157   {
1158     AliEmcalJet* signalJet = fSignalJets[j];
1159     if(signalJet->Pt() < 5.0)
1160       continue;
1161     fSignalJetCount5GeV++;
1162   }
1163
1164   for (Int_t i = 0; i < fTrackArray->GetEntries(); i++)
1165   {
1166     AliVTrack* tmpTrack = static_cast<AliVTrack*>(fTrackArray->At(i));
1167     Bool_t trackWithinJet = kFALSE; Bool_t trackWithin02Cone = kFALSE; Bool_t trackWithin04Cone = kFALSE; Bool_t trackWithin06Cone = kFALSE; Bool_t trackWithin08Cone = kFALSE;
1168
1169     if (IsTrackInAcceptance(tmpTrack))
1170     {
1171       // Check if tracks overlaps with jet
1172       for(Int_t j=0;j<numberExcludeLeadingJets;j++)
1173       {
1174         AliEmcalJet* signalJet = fSignalJets[j];
1175
1176         if(signalJet->Pt() < 5.0)
1177           continue;
1178
1179         // Exact jet exclusion
1180         if (IsTrackInJet(signalJet, i))
1181           trackWithinJet = kTRUE;
1182
1183         // Cone exclusions
1184         if (IsTrackInCone(tmpTrack, signalJet->Eta(), signalJet->Phi(), 0.2))
1185         {
1186           trackWithin02Cone = kTRUE;
1187           trackWithin04Cone = kTRUE;
1188           trackWithin06Cone = kTRUE;
1189           trackWithin08Cone = kTRUE;
1190           break;
1191         }
1192         else if (IsTrackInCone(tmpTrack, signalJet->Eta(), signalJet->Phi(), 0.4))
1193         {
1194           trackWithin04Cone = kTRUE;
1195           trackWithin06Cone = kTRUE;
1196           trackWithin08Cone = kTRUE;
1197         }
1198         else if (IsTrackInCone(tmpTrack, signalJet->Eta(), signalJet->Phi(), 0.6))
1199         {
1200           trackWithin06Cone = kTRUE;
1201           trackWithin08Cone = kTRUE;
1202         }
1203         else if (IsTrackInCone(tmpTrack, signalJet->Eta(), signalJet->Phi(), 0.8))
1204         {
1205           trackWithin08Cone = kTRUE;
1206         }
1207       }
1208
1209       if(!trackWithin08Cone)
1210       {
1211         summedTracksPtCone08 += tmpTrack->Pt();
1212       }
1213       if(!trackWithin06Cone)
1214       {
1215         summedTracksPtCone06 += tmpTrack->Pt();
1216       }
1217       if(!trackWithin04Cone)
1218       {
1219         summedTracksPtCone04 += tmpTrack->Pt();
1220       }
1221       if(!trackWithin02Cone)
1222       {
1223         summedTracksPtCone02 += tmpTrack->Pt();
1224       }
1225       if(!trackWithinJet)
1226       {
1227         summedTracksPtWithinJets += tmpTrack->Pt();
1228       }
1229       summedTracksPt += tmpTrack->Pt();
1230
1231     }
1232   }
1233
1234   // Calculate the correct area where the tracks were taking from
1235
1236   Double_t tmpFullTPCArea = (2.0*fTrackEtaWindow) * TMath::TwoPi();
1237   Double_t tmpAreaCone02     = tmpFullTPCArea;
1238   Double_t tmpAreaCone04     = tmpFullTPCArea;
1239   Double_t tmpAreaCone06     = tmpFullTPCArea;
1240   Double_t tmpAreaCone08     = tmpFullTPCArea;
1241   Double_t tmpAreaWithinJets = tmpFullTPCArea;
1242   std::vector<Double_t> tmpEtas(fSignalJetCount5GeV);
1243   std::vector<Double_t> tmpPhis(fSignalJetCount5GeV);
1244
1245   Int_t iSignal = 0;
1246   for(Int_t i=0;i<numberExcludeLeadingJets;i++)
1247   {
1248     AliEmcalJet* tmpJet = fSignalJets[i];
1249
1250     if(tmpJet->Pt() < 5.0)
1251       continue;
1252
1253     tmpEtas[iSignal] = tmpJet->Eta();
1254     tmpPhis[iSignal] = tmpJet->Phi();
1255     tmpAreaWithinJets -= tmpJet->Area();
1256
1257     iSignal++;
1258   }
1259
1260   tmpAreaCone02 -= tmpFullTPCArea * MCGetOverlapMultipleCirclesRectancle(fSignalJetCount5GeV, tmpEtas, tmpPhis, 0.2, -fTrackEtaWindow, +fTrackEtaWindow, 0., TMath::TwoPi());
1261   tmpAreaCone04 -= tmpFullTPCArea * MCGetOverlapMultipleCirclesRectancle(fSignalJetCount5GeV, tmpEtas, tmpPhis, 0.4, -fTrackEtaWindow, +fTrackEtaWindow, 0., TMath::TwoPi());
1262   tmpAreaCone06 -= tmpFullTPCArea * MCGetOverlapMultipleCirclesRectancle(fSignalJetCount5GeV, tmpEtas, tmpPhis, 0.6, -fTrackEtaWindow, +fTrackEtaWindow, 0., TMath::TwoPi());
1263   tmpAreaCone08 -= tmpFullTPCArea * MCGetOverlapMultipleCirclesRectancle(fSignalJetCount5GeV, tmpEtas, tmpPhis, 0.8, -fTrackEtaWindow, +fTrackEtaWindow, 0., TMath::TwoPi());
1264  
1265   rhoConeExclusion02 = summedTracksPtCone02/tmpAreaCone02;
1266   rhoConeExclusion04 = summedTracksPtCone04/tmpAreaCone04;
1267   rhoConeExclusion06 = summedTracksPtCone06/tmpAreaCone06;
1268   rhoConeExclusion08 = summedTracksPtCone08/tmpAreaCone08;
1269   rhoExactExclusion  = summedTracksPtWithinJets/tmpAreaWithinJets;
1270   rhoNoExclusion     = summedTracksPt/tmpFullTPCArea;
1271
1272
1273   #ifdef DEBUGMODE
1274     AliInfo("Got TR background density.");
1275   #endif
1276 }
1277
1278 //________________________________________________________________________
1279 void AliAnalysisTaskChargedJetsPA::GetTRBackgroundDensity(Int_t numberExcludeLeadingJets, Double_t& rhoMean, Double_t& area, AliEmcalJet* excludeJet1, AliEmcalJet* excludeJet2, Bool_t doSearchPerpendicular)
1280 {
1281   #ifdef DEBUGMODE
1282     AliInfo("Getting TR background density.");
1283   #endif
1284
1285   // Setting invalid values
1286   Double_t summedTracksPt = 0.0;
1287   rhoMean = 0.0;
1288   area = -1.0;
1289
1290   Double_t tmpRadius = 0.0;
1291   if (doSearchPerpendicular)
1292     tmpRadius = 0.4*TMath::Pi(); // exclude 90 degrees around jets
1293   else
1294     tmpRadius = 0.8;
1295     
1296   numberExcludeLeadingJets = 2; // dijet is excluded here in any case
1297
1298
1299
1300   if (!fTrackArray || !fJetArray)
1301   {
1302     AliError("Could not get the track/jet array to calculate track rho!");
1303     return;
1304   }
1305
1306   Int_t   trackCount = fTrackArray->GetEntries();
1307   Int_t   trackCountAccepted = 0;
1308   for (Int_t i = 0; i < trackCount; i++)
1309   {
1310     AliVTrack* tmpTrack = static_cast<AliVTrack*>(fTrackArray->At(i));
1311     if (IsTrackInAcceptance(tmpTrack))
1312     {
1313       if (IsTrackInCone(tmpTrack, excludeJet1->Eta(), excludeJet1->Phi(), tmpRadius))
1314         continue;
1315
1316       if (numberExcludeLeadingJets > 1)
1317         if (IsTrackInCone(tmpTrack, excludeJet2->Eta(), excludeJet2->Phi(), tmpRadius))
1318           continue;
1319
1320         // Add track pt to array
1321         summedTracksPt = summedTracksPt + tmpTrack->Pt();
1322         trackCountAccepted++;
1323     }
1324   }
1325
1326   if (trackCountAccepted > 0)
1327   {
1328     Double_t tmpArea = 2.0*fTrackEtaWindow*TMath::TwoPi()  - 2*(tmpRadius*tmpRadius * TMath::Pi()); //TPC area - excluding jet area
1329     rhoMean = summedTracksPt/tmpArea;
1330     area = tmpArea;
1331   }
1332
1333   #ifdef DEBUGMODE
1334     AliInfo("Got TR background density.");
1335   #endif
1336 }
1337
1338 //________________________________________________________________________
1339 void AliAnalysisTaskChargedJetsPA::Calculate(AliVEvent* event)
1340 {
1341   #ifdef DEBUGMODE
1342     AliInfo("Starting Calculate().");
1343   #endif
1344   ////////////////////// NOTE: initialization & casting
1345
1346   fEventCounter++;
1347
1348   // Check, if analysis should be done in pt hard bins
1349   if(fUsePtHardBin != -1)
1350     if(GetPtHardBin() != fUsePtHardBin)
1351       return;
1352
1353   // This is to take only every Nth event
1354   if((fEventCounter+fPartialAnalysisIndex) % fPartialAnalysisNParts != 0)
1355     return;
1356
1357   FillHistogram("hNumberEvents",0.5);
1358
1359   if(!IsEventInAcceptance(event))
1360     return;
1361
1362   FillHistogram("hNumberEvents",1.5);
1363
1364   #ifdef DEBUGMODE
1365     AliInfo("Calculate()::Init done.");
1366   #endif
1367
1368   ////////////////////// NOTE: Get Centrality, (Leading)Signal jets and Background
1369
1370   // Get centrality
1371   AliCentrality* tmpCentrality = NULL;
1372   tmpCentrality = event->GetCentrality();
1373   Double_t centralityPercentile = -1.0;
1374   Double_t centralityPercentileV0A = 0.0;
1375   Double_t centralityPercentileV0C = 0.0;
1376   Double_t centralityPercentileV0M = 0.0;
1377   if (tmpCentrality != NULL)
1378   {
1379     centralityPercentile = tmpCentrality->GetCentralityPercentile(fCentralityType.Data());
1380     centralityPercentileV0A = tmpCentrality->GetCentralityPercentile("V0A");
1381     centralityPercentileV0C = tmpCentrality->GetCentralityPercentile("V0C");
1382     centralityPercentileV0M = tmpCentrality->GetCentralityPercentile("V0M");
1383   }
1384
1385   if((centralityPercentile < 0.0) || (centralityPercentile > 100.0))
1386     AliWarning(Form("Centrality value not valid (c=%E)",centralityPercentile)); 
1387
1388   if(fSetCentralityToOne)
1389     centralityPercentile = 1.0;
1390
1391   // Get jets
1392   if (fAnalyzeBackground || fAnalyzeJets)
1393     GetSignalJets();
1394
1395   // Get background estimates
1396   Double_t              backgroundKTImprovedCMS = -1.0;
1397   Double_t              backgroundKTImprovedCMSExternal = -1.0;
1398   Double_t              backgroundDijet = -1.0;
1399   Double_t              backgroundDijetPerpendicular = -1.0;
1400
1401   Double_t              backgroundKTPbPb = -1.0;
1402   Double_t              backgroundKTPbPbWithGhosts = -1.0;
1403   Double_t              backgroundKTCMS = -1.0;
1404   Double_t              backgroundKTMean = -1.0;
1405   Double_t              backgroundKTTrackLike = -1.0;
1406   Double_t              backgroundTRNoExcl = -1.0;
1407   Double_t              backgroundTRCone02 = -1.0;
1408   Double_t              backgroundTRCone04 = -1.0;
1409   Double_t              backgroundTRCone06 = -1.0;
1410   Double_t              backgroundTRCone08 = -1.0;
1411   Double_t              backgroundTRExact  = -1.0;
1412
1413   // Calculate background for different jet exclusions
1414
1415   if (fAnalyzeBackground)
1416   {
1417
1418     if(fAnalyzeDeprecatedBackgrounds)
1419       GetKTBackgroundDensityAll    (fNumberExcludedJets, backgroundKTPbPb, backgroundKTPbPbWithGhosts, backgroundKTCMS, backgroundKTImprovedCMS, backgroundKTMean, backgroundKTTrackLike);
1420     else
1421       GetKTBackgroundDensity       (fNumberExcludedJets, backgroundKTImprovedCMS);
1422
1423     if(fAnalyzeDeprecatedBackgrounds)
1424       GetTRBackgroundDensity    (fNumberExcludedJets, backgroundTRNoExcl, backgroundTRCone02, backgroundTRCone04, backgroundTRCone06, backgroundTRCone08, backgroundTRExact);
1425
1426     backgroundKTImprovedCMSExternal = GetExternalRho();
1427   }
1428
1429   #ifdef DEBUGMODE
1430     AliInfo("Calculate()::Centrality&SignalJets&Background-Calculation done.");
1431   #endif
1432
1433   if (fAnalyzeQA)
1434   {
1435     FillHistogram("hVertexX",event->GetPrimaryVertex()->GetX());
1436     FillHistogram("hVertexY",event->GetPrimaryVertex()->GetY());
1437     FillHistogram("hVertexXY",event->GetPrimaryVertex()->GetX(), event->GetPrimaryVertex()->GetY());
1438     FillHistogram("hVertexR",TMath::Sqrt(event->GetPrimaryVertex()->GetX()*event->GetPrimaryVertex()->GetX() + event->GetPrimaryVertex()->GetY()*event->GetPrimaryVertex()->GetY()));
1439     FillHistogram("hCentralityV0M",centralityPercentileV0M);
1440     FillHistogram("hCentralityV0A",centralityPercentileV0A);
1441     FillHistogram("hCentralityV0C",centralityPercentileV0C);
1442     FillHistogram("hCentrality",centralityPercentile);
1443
1444     Int_t trackCountAcc = 0;
1445     Int_t nTracks = fTrackArray->GetEntries();
1446     for (Int_t i = 0; i < nTracks; i++)
1447     {
1448       AliVTrack* track = static_cast<AliVTrack*>(fTrackArray->At(i));
1449
1450       if (track != 0)
1451         if (track->Pt() >= fMinTrackPt)
1452           FillHistogram("hTrackPhiEta", track->Phi(),track->Eta(), 1);
1453
1454       if (IsTrackInAcceptance(track))
1455       {
1456         FillHistogram("hTrackPt", track->Pt(), centralityPercentile);
1457         if(track->Eta() >= 0)
1458           FillHistogram("hTrackPtPosEta", track->Pt(), centralityPercentile);
1459         else
1460           FillHistogram("hTrackPtNegEta", track->Pt(), centralityPercentile);
1461                 
1462         FillHistogram("hTrackEta", track->Eta(), centralityPercentile);
1463         FillHistogram("hTrackPhi", track->Phi());
1464         
1465         if(static_cast<AliPicoTrack*>(track))
1466         {
1467           FillHistogram("hTrackPhiTrackType", track->Phi(), (static_cast<AliPicoTrack*>(track))->GetTrackType());
1468           FillHistogram("hTrackPhiLabel", track->Phi(), (static_cast<AliPicoTrack*>(track))->GetLabel());
1469         }
1470         for(Int_t j=0;j<20;j++)
1471           if(track->Pt() > j)
1472             FillHistogram("hTrackPhiPtCut", track->Phi(), track->Pt());
1473
1474         FillHistogram("hTrackCharge", track->Charge());
1475         trackCountAcc++;
1476       }
1477     }
1478     FillHistogram("hTrackCountAcc", trackCountAcc, centralityPercentile);
1479
1480
1481 /*
1482     // This is code that is run locally to get some special events
1483     TFile* fileOutput = new TFile("SpecialEvents.root", "UPDATE");
1484     if(fSecondLeadingJet&&(fSecondLeadingJet->Pt()>10.))
1485     {
1486       cout << "Event found\n";
1487       TH2D* tmpEvent = new TH2D(Form("Event%lu", fEventCounter), "", 40, -0.9, 0.9, 40, 0., TMath::TwoPi());
1488       tmpEvent->GetXaxis()->SetTitle("#eta");
1489       tmpEvent->GetYaxis()->SetTitle("#phi");
1490       tmpEvent->SetOption("LEGO2");
1491       tmpEvent->Sumw2();
1492
1493       for (Int_t i = 0; i < nTracks; i++)
1494       {
1495         AliVTrack* track = static_cast<AliVTrack*>(fTrackArray->At(i));
1496
1497         if (IsTrackInAcceptance(track))
1498         {
1499           tmpEvent->Fill(track->Eta(), track->Phi(), track->Pt());
1500         }
1501       }
1502       tmpEvent->Write(0, kOverwrite);
1503     }
1504     fileOutput->Close();
1505 */
1506   }
1507   #ifdef DEBUGMODE
1508     AliInfo("Calculate()::QA done.");
1509   #endif
1510
1511   ////////////////////// NOTE: Jet analysis and calculations
1512
1513   if (fAnalyzeJets)
1514   {
1515     for (Int_t i = 0; i<fJetArray->GetEntries(); i++)
1516     {
1517       AliEmcalJet* tmpJet = static_cast<AliEmcalJet*>(fJetArray->At(i));
1518       if (!tmpJet)
1519         continue;
1520
1521       FillHistogram("hRawJetPt", tmpJet->Pt());
1522       if (tmpJet->Pt() >= 5.0)
1523       {
1524       // ### RAW JET ANALYSIS
1525         if (tmpJet->Area() >= fMinJetArea)
1526           FillHistogram("hRawJetPhiEta", tmpJet->Phi(), tmpJet->Eta());
1527         if (TMath::Abs(tmpJet->Eta()) <= fSignalJetEtaWindow)
1528           FillHistogram("hRawJetArea", tmpJet->Area());
1529       }
1530
1531       if(IsSignalJetInAcceptance(tmpJet))
1532       {
1533       // ### SIGNAL JET ANALYSIS
1534         // Jet spectra
1535         FillHistogram("hJetPt", tmpJet->Pt(), centralityPercentile);
1536         FillHistogram("hJetPtBgrdSubtractedKTImprovedCMS", GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS), centralityPercentile);
1537         FillHistogram("hJetPtSubtractedRhoKTImprovedCMS", tmpJet->Pt(), centralityPercentile, backgroundKTImprovedCMS);
1538         if(centralityPercentile<=20.0)
1539           FillHistogram("hJetPtSubtractedRhoKTImprovedCMS020", tmpJet->Pt(), backgroundKTImprovedCMS);
1540         
1541         if(fAnalyzeDeprecatedBackgrounds)
1542         {
1543           FillHistogram("hJetPtBgrdSubtractedTR", GetCorrectedJetPt(tmpJet, backgroundTRCone06), centralityPercentile);
1544           FillHistogram("hJetPtBgrdSubtractedKTPbPb", GetCorrectedJetPt(tmpJet, backgroundKTPbPb), centralityPercentile);
1545           FillHistogram("hJetPtBgrdSubtractedKTPbPbWithGhosts", GetCorrectedJetPt(tmpJet, backgroundKTPbPbWithGhosts), centralityPercentile);
1546           FillHistogram("hJetPtBgrdSubtractedKTCMS", GetCorrectedJetPt(tmpJet, backgroundKTCMS), centralityPercentile);
1547           FillHistogram("hJetPtBgrdSubtractedKTMean", GetCorrectedJetPt(tmpJet, backgroundKTMean), centralityPercentile);
1548           FillHistogram("hJetPtBgrdSubtractedKTTrackLike", GetCorrectedJetPt(tmpJet, backgroundKTTrackLike), centralityPercentile);
1549         }
1550
1551         // Jet profile analysis
1552         if(TMath::Abs(tmpJet->Eta()) <= 0.3)
1553         {
1554           if(tmpJet->Pt()>=70.0)
1555           {
1556             FillHistogram("hJetProfile70GeV", 0.05-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1557             FillHistogram("hJetProfile70GeV", 0.10-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1558             FillHistogram("hJetProfile70GeV", 0.15-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1559             FillHistogram("hJetProfile70GeV", 0.20-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1560             FillHistogram("hJetProfile70GeV", 0.25-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1561             FillHistogram("hJetProfile70GeV", 0.30-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1562             FillHistogram("hJetProfile70GeV", 0.35-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1563             FillHistogram("hJetProfile70GeV", 0.40-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1564             FillHistogram("hJetProfile70GeV", 0.45-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1565             FillHistogram("hJetProfile70GeV", 0.50-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1566             FillHistogram("hJetProfile70GeV", 0.55-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1567             FillHistogram("hJetProfile70GeV", 0.60-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1568           }
1569           else if(GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS)>=60.0)
1570           {
1571             FillHistogram("hJetProfile60GeV", 0.05-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1572             FillHistogram("hJetProfile60GeV", 0.10-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1573             FillHistogram("hJetProfile60GeV", 0.15-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1574             FillHistogram("hJetProfile60GeV", 0.20-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1575             FillHistogram("hJetProfile60GeV", 0.25-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1576             FillHistogram("hJetProfile60GeV", 0.30-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1577             FillHistogram("hJetProfile60GeV", 0.35-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1578             FillHistogram("hJetProfile60GeV", 0.40-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1579             FillHistogram("hJetProfile60GeV", 0.45-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1580             FillHistogram("hJetProfile60GeV", 0.50-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1581             FillHistogram("hJetProfile60GeV", 0.55-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1582             FillHistogram("hJetProfile60GeV", 0.60-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1583           }
1584           else if(GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS)>=50.0)
1585           {
1586             FillHistogram("hJetProfile50GeV", 0.05-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1587             FillHistogram("hJetProfile50GeV", 0.10-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1588             FillHistogram("hJetProfile50GeV", 0.15-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1589             FillHistogram("hJetProfile50GeV", 0.20-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1590             FillHistogram("hJetProfile50GeV", 0.25-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1591             FillHistogram("hJetProfile50GeV", 0.30-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1592             FillHistogram("hJetProfile50GeV", 0.35-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1593             FillHistogram("hJetProfile50GeV", 0.40-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1594             FillHistogram("hJetProfile50GeV", 0.45-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1595             FillHistogram("hJetProfile50GeV", 0.50-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1596             FillHistogram("hJetProfile50GeV", 0.55-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1597             FillHistogram("hJetProfile50GeV", 0.60-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1598           }
1599           else if(GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS)>=40.0)
1600           {
1601             FillHistogram("hJetProfile40GeV", 0.05-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1602             FillHistogram("hJetProfile40GeV", 0.10-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1603             FillHistogram("hJetProfile40GeV", 0.15-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1604             FillHistogram("hJetProfile40GeV", 0.20-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1605             FillHistogram("hJetProfile40GeV", 0.25-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1606             FillHistogram("hJetProfile40GeV", 0.30-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1607             FillHistogram("hJetProfile40GeV", 0.35-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1608             FillHistogram("hJetProfile40GeV", 0.40-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1609             FillHistogram("hJetProfile40GeV", 0.45-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1610             FillHistogram("hJetProfile40GeV", 0.50-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1611             FillHistogram("hJetProfile40GeV", 0.55-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1612             FillHistogram("hJetProfile40GeV", 0.60-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1613           }
1614           else if(GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS)>=30.0)
1615           {
1616             FillHistogram("hJetProfile30GeV", 0.05-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1617             FillHistogram("hJetProfile30GeV", 0.10-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1618             FillHistogram("hJetProfile30GeV", 0.15-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1619             FillHistogram("hJetProfile30GeV", 0.20-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1620             FillHistogram("hJetProfile30GeV", 0.25-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1621             FillHistogram("hJetProfile30GeV", 0.30-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1622             FillHistogram("hJetProfile30GeV", 0.35-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1623             FillHistogram("hJetProfile30GeV", 0.40-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1624             FillHistogram("hJetProfile30GeV", 0.45-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1625             FillHistogram("hJetProfile30GeV", 0.50-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1626             FillHistogram("hJetProfile30GeV", 0.55-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1627             FillHistogram("hJetProfile30GeV", 0.60-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1628           }
1629           else if(GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS)>=20.0)
1630           {
1631             FillHistogram("hJetProfile20GeV", 0.05-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1632             FillHistogram("hJetProfile20GeV", 0.10-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1633             FillHistogram("hJetProfile20GeV", 0.15-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1634             FillHistogram("hJetProfile20GeV", 0.20-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1635             FillHistogram("hJetProfile20GeV", 0.25-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1636             FillHistogram("hJetProfile20GeV", 0.30-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1637             FillHistogram("hJetProfile20GeV", 0.35-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1638             FillHistogram("hJetProfile20GeV", 0.40-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1639             FillHistogram("hJetProfile20GeV", 0.45-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1640             FillHistogram("hJetProfile20GeV", 0.50-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1641             FillHistogram("hJetProfile20GeV", 0.55-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1642             FillHistogram("hJetProfile20GeV", 0.60-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1643           }
1644           else if(GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS)>=10.0)
1645           {
1646             FillHistogram("hJetProfile10GeV", 0.05-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1647             FillHistogram("hJetProfile10GeV", 0.10-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1648             FillHistogram("hJetProfile10GeV", 0.15-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1649             FillHistogram("hJetProfile10GeV", 0.20-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1650             FillHistogram("hJetProfile10GeV", 0.25-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1651             FillHistogram("hJetProfile10GeV", 0.30-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1652             FillHistogram("hJetProfile10GeV", 0.35-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1653             FillHistogram("hJetProfile10GeV", 0.40-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1654             FillHistogram("hJetProfile10GeV", 0.45-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1655             FillHistogram("hJetProfile10GeV", 0.50-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1656             FillHistogram("hJetProfile10GeV", 0.55-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1657             FillHistogram("hJetProfile10GeV", 0.60-0.05/2, (-backgroundKTImprovedCMS+GetConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60))/GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1658           }
1659         }
1660         FillHistogram("hJetPtVsConstituentCount", tmpJet->Pt(),tmpJet->GetNumberOfTracks());
1661
1662         if((fAnalyzeQA) && (tmpJet->Pt() >= 5.0))
1663         {
1664           Double_t lowestTrackPt = 1e99;
1665           Double_t highestTrackPt = 0.0;
1666           for(Int_t j=0; j<tmpJet->GetNumberOfTracks(); j++)
1667           {
1668             FillHistogram("hJetConstituentPt", tmpJet->TrackAt(j, fTrackArray)->Pt(), centralityPercentile);
1669             // Find the lowest pT of a track in the jet
1670             if (tmpJet->TrackAt(j, fTrackArray)->Pt() < lowestTrackPt)
1671               lowestTrackPt = tmpJet->TrackAt(j, fTrackArray)->Pt();
1672             if (tmpJet->TrackAt(j, fTrackArray)->Pt() > highestTrackPt)
1673               highestTrackPt = tmpJet->TrackAt(j, fTrackArray)->Pt();
1674           }
1675           FillHistogram("hJetArea", tmpJet->Area());
1676           // Signal jet vs. signal jet - "Combinatorial"
1677           for (Int_t j = i+1; j<fNumberSignalJets; j++)
1678             FillHistogram("hJetDeltaPhi", GetDeltaPhi(tmpJet->Phi(), fSignalJets[j]->Phi()));
1679
1680           FillHistogram("hJetPhiEta", tmpJet->Phi(),tmpJet->Eta());
1681           FillHistogram("hJetEta", tmpJet->Eta(), centralityPercentile);
1682
1683           if(lowestTrackPt>=2.0)
1684             FillHistogram("hJetEta2GeVTracks", tmpJet->Eta(), centralityPercentile);
1685           if(lowestTrackPt>=4.0)
1686             FillHistogram("hJetEta4GeVTracks", tmpJet->Eta(), centralityPercentile);
1687         }
1688
1689
1690         // Jet constituent mass analyses (for PYTHIA)
1691         if (fAnalyzeMassCorrelation)
1692         {
1693           Double_t jetMass = 0.0;
1694           Int_t constituentCount = tmpJet->GetNumberOfTracks();
1695           Int_t electronCount = 0;
1696           Int_t pionCount = 0;
1697           Int_t protonCount = 0;
1698           Int_t kaonCount = 0;
1699           Int_t othersCount = 0;
1700
1701           for(Int_t j=0; j<tmpJet->GetNumberOfTracks(); j++)
1702           {
1703             AliVParticle* tmpParticle = tmpJet->TrackAt(j, fTrackArray);
1704
1705             jetMass += tmpParticle->M();
1706             if(TMath::Abs(tmpParticle->PdgCode()) == 11) // electron, positron
1707               electronCount++;
1708             else if(TMath::Abs(tmpParticle->PdgCode()) == 211) // p-, p+
1709               pionCount++;
1710             else if(TMath::Abs(tmpParticle->PdgCode()) == 2212) // p, pbar
1711               protonCount++;
1712             else if(TMath::Abs(tmpParticle->PdgCode()) == 321) // kaon+,kaon-
1713               kaonCount++;
1714             else
1715               othersCount++;
1716           }
1717
1718           FillHistogram("hJetMassFromConstituents", jetMass);
1719           FillHistogram("hJetMass", tmpJet->M());
1720
1721           FillHistogram("hJetPtVsMass", tmpJet->Pt(), jetMass);
1722           FillHistogram("hJetPtVsJetMass", tmpJet->Pt(), tmpJet->M());
1723
1724           FillHistogram("hJetPtVsProtonCount", tmpJet->Pt(), protonCount/(static_cast<Double_t>(constituentCount)));
1725           FillHistogram("hJetPtVsPionCount", tmpJet->Pt(), pionCount/(static_cast<Double_t>(constituentCount)));
1726           FillHistogram("hJetPtVsKaonCount", tmpJet->Pt(), kaonCount/(static_cast<Double_t>(constituentCount)));
1727           FillHistogram("hJetPtVsElectronCount", tmpJet->Pt(), electronCount/(static_cast<Double_t>(constituentCount)));
1728           FillHistogram("hJetPtVsOthersCount", tmpJet->Pt(), othersCount/(static_cast<Double_t>(constituentCount)));
1729           FillHistogram("hJetConstituentProtonCount", protonCount);
1730           FillHistogram("hJetConstituentPionCount", pionCount);
1731           FillHistogram("hJetConstituentKaonCount", kaonCount);
1732           FillHistogram("hJetConstituentElectronCount", electronCount);
1733           FillHistogram("hJetConstituentOthersCount", othersCount);
1734
1735           // Results for the "normal" jet (avoiding single particle jets)
1736           if((constituentCount>=6) && (constituentCount<=14))
1737           {
1738             FillHistogram("hJetPtVsMass_6_14", tmpJet->Pt(), jetMass);
1739             FillHistogram("hJetPtVsJetMass_6_14", tmpJet->Pt(), tmpJet->M());
1740
1741             FillHistogram("hJetPtVsProtonCount_6_14", tmpJet->Pt(), protonCount);
1742             FillHistogram("hJetPtVsPionCount_6_14", tmpJet->Pt(), pionCount);
1743             FillHistogram("hJetPtVsKaonCount_6_14", tmpJet->Pt(), kaonCount);
1744             FillHistogram("hJetPtVsElectronCount_6_14", tmpJet->Pt(), electronCount);
1745             FillHistogram("hJetPtVsOthersCount_6_14", tmpJet->Pt(), othersCount);
1746             FillHistogram("hJetConstituentProtonCount_6_14", protonCount);
1747             FillHistogram("hJetConstituentPionCount_6_14", pionCount);
1748             FillHistogram("hJetConstituentKaonCount_6_14", kaonCount);
1749             FillHistogram("hJetConstituentElectronCount_6_14", electronCount);
1750             FillHistogram("hJetConstituentOthersCount_6_14", othersCount);
1751           }
1752           if((constituentCount>=2))
1753           {
1754             FillHistogram("hJetPtVsMass_2_X", tmpJet->Pt(), jetMass);
1755             FillHistogram("hJetPtVsJetMass_2_X", tmpJet->Pt(), tmpJet->M());
1756
1757             FillHistogram("hJetPtVsProtonCount_2_X", tmpJet->Pt(), protonCount);
1758             FillHistogram("hJetPtVsPionCount_2_X", tmpJet->Pt(), pionCount);
1759             FillHistogram("hJetPtVsKaonCount_2_X", tmpJet->Pt(), kaonCount);
1760             FillHistogram("hJetPtVsElectronCount_2_X", tmpJet->Pt(), electronCount);
1761             FillHistogram("hJetPtVsOthersCount_2_X", tmpJet->Pt(), othersCount);
1762             FillHistogram("hJetConstituentProtonCount_2_X", protonCount);
1763             FillHistogram("hJetConstituentPionCount_2_X", pionCount);
1764             FillHistogram("hJetConstituentKaonCount_2_X", kaonCount);
1765             FillHistogram("hJetConstituentElectronCount_2_X", electronCount);
1766             FillHistogram("hJetConstituentOthersCount_2_X", othersCount);
1767           }
1768           if((constituentCount>=2) && (constituentCount<=7))
1769           {
1770             FillHistogram("hJetPtVsMass_2_7", tmpJet->Pt(), jetMass);
1771             FillHistogram("hJetPtVsJetMass_2_7", tmpJet->Pt(), tmpJet->M());
1772
1773             FillHistogram("hJetPtVsProtonCount_2_7", tmpJet->Pt(), protonCount);
1774             FillHistogram("hJetPtVsPionCount_2_7", tmpJet->Pt(), pionCount);
1775             FillHistogram("hJetPtVsKaonCount_2_7", tmpJet->Pt(), kaonCount);
1776             FillHistogram("hJetPtVsElectronCount_2_7", tmpJet->Pt(), electronCount);
1777             FillHistogram("hJetPtVsOthersCount_2_7", tmpJet->Pt(), othersCount);
1778             FillHistogram("hJetConstituentProtonCount_2_7", protonCount);
1779             FillHistogram("hJetConstituentPionCount_2_7", pionCount);
1780             FillHistogram("hJetConstituentKaonCount_2_7", kaonCount);
1781             FillHistogram("hJetConstituentElectronCount_2_7", electronCount);
1782             FillHistogram("hJetConstituentOthersCount_2_7", othersCount);
1783           }
1784         }
1785       }
1786     }
1787
1788     // ### DIJETS
1789     if(fNumberSignalJets >= 2)
1790     {
1791       FillHistogram("hLeadingJetDeltaPhi", GetDeltaPhi(fFirstLeadingJet->Phi(), fSecondLeadingJet->Phi()));
1792
1793       if (IsDijet(fFirstLeadingJet, fSecondLeadingJet))
1794       {
1795         FillHistogram("hDijetConstituentsPt", fFirstLeadingJet->Pt());
1796         FillHistogram("hDijetConstituentsPt", fSecondLeadingJet->Pt());
1797
1798         FillHistogram("hDijetLeadingJetPt", fFirstLeadingJet->Pt());
1799         FillHistogram("hDijetPtCorrelation", fFirstLeadingJet->Pt(), fSecondLeadingJet->Pt());
1800         Double_t dummyArea = 0;
1801         GetTRBackgroundDensity (2, backgroundDijet, dummyArea, fFirstLeadingJet, fSecondLeadingJet, kFALSE);
1802         GetTRBackgroundDensity (2, backgroundDijetPerpendicular, dummyArea, fFirstLeadingJet, fSecondLeadingJet, kTRUE);
1803       }
1804     }
1805
1806     // ### SOME JET PLOTS
1807     FillHistogram("hJetCountAll", fJetArray->GetEntries());
1808     FillHistogram("hJetCountAccepted", fNumberSignalJets);
1809     FillHistogram("hJetCount", fJetArray->GetEntries(), fNumberSignalJets);
1810     if (fFirstLeadingJet)
1811     {
1812       FillHistogram("hLeadingJetPt", fFirstLeadingJet->Pt());
1813       FillHistogram("hCorrectedLeadingJetPt", GetCorrectedJetPt(fFirstLeadingJet,backgroundKTImprovedCMS));
1814     }
1815     if (fSecondLeadingJet)
1816     {
1817       FillHistogram("hSecondLeadingJetPt", fSecondLeadingJet->Pt());
1818       FillHistogram("hCorrectedSecondLeadingJetPt", GetCorrectedJetPt(fSecondLeadingJet,backgroundKTImprovedCMS));
1819     }
1820   } //endif AnalyzeJets
1821
1822   #ifdef DEBUGMODE
1823     AliInfo("Calculate()::Jets done.");
1824   #endif
1825   ////////////////////// NOTE: Background analysis
1826
1827   if (fAnalyzeBackground)
1828   {
1829     // Calculate background in centrality classes
1830     FillHistogram("hKTBackgroundImprovedCMS", backgroundKTImprovedCMS, centralityPercentile);
1831
1832     FillHistogram("hKTBackgroundImprovedCMSExternal", backgroundKTImprovedCMSExternal, centralityPercentile);
1833
1834     FillHistogram("hKTMeanBackgroundImprovedCMS", centralityPercentile, backgroundKTImprovedCMS);
1835
1836     // In case of dijets -> look at the background
1837     if (backgroundDijet >= 0)
1838       FillHistogram("hDijetBackground", backgroundDijet, centralityPercentile); 
1839     if (backgroundDijetPerpendicular >= 0)
1840       FillHistogram("hDijetBackgroundPerpendicular", backgroundDijetPerpendicular, centralityPercentile); 
1841     
1842     if(fAnalyzeDeprecatedBackgrounds)
1843     {
1844       FillHistogram("hKTBackgroundPbPb", backgroundKTPbPb, centralityPercentile);
1845       FillHistogram("hKTBackgroundPbPbWithGhosts", backgroundKTPbPbWithGhosts, centralityPercentile);
1846       FillHistogram("hKTBackgroundCMS", backgroundKTCMS, centralityPercentile);
1847       FillHistogram("hKTBackgroundMean", backgroundKTMean, centralityPercentile);
1848       FillHistogram("hKTBackgroundTrackLike", backgroundKTTrackLike, centralityPercentile);
1849
1850       FillHistogram("hTRBackgroundNoExcl", backgroundTRNoExcl, centralityPercentile);
1851       FillHistogram("hTRBackgroundCone02", backgroundTRCone02, centralityPercentile);
1852       FillHistogram("hTRBackgroundCone04", backgroundTRCone04, centralityPercentile);
1853       FillHistogram("hTRBackgroundCone06", backgroundTRCone06, centralityPercentile);
1854       FillHistogram("hTRBackgroundCone08", backgroundTRCone08, centralityPercentile);
1855       FillHistogram("hTRBackgroundExact", backgroundTRExact, centralityPercentile);
1856
1857       // Calculate background profiles in terms of centrality
1858       FillHistogram("hKTMeanBackgroundPbPb", centralityPercentile,  backgroundKTPbPb);
1859       FillHistogram("hKTMeanBackgroundPbPbWithGhosts", centralityPercentile,  backgroundKTPbPbWithGhosts);
1860       FillHistogram("hKTMeanBackgroundCMS", centralityPercentile, backgroundKTCMS);
1861       FillHistogram("hKTMeanBackgroundMean", centralityPercentile, backgroundKTMean);
1862       FillHistogram("hKTMeanBackgroundTPC", centralityPercentile, backgroundKTTrackLike);
1863       FillHistogram("hTRMeanBackground", centralityPercentile,  backgroundTRCone06);
1864     }
1865
1866
1867     // Calculate the delta pt
1868     Double_t tmpDeltaPtNoBackground = GetDeltaPt(0.0);
1869     Double_t tmpDeltaPtKTImprovedCMS = GetDeltaPt(backgroundKTImprovedCMS);
1870
1871     Double_t tmpDeltaPtKTImprovedCMSPartialExclusion = 0.0;
1872     if(fNcoll)
1873       tmpDeltaPtKTImprovedCMSPartialExclusion = GetDeltaPt(backgroundKTImprovedCMS, 1.0/fNcoll);
1874     else
1875       tmpDeltaPtKTImprovedCMSPartialExclusion = GetDeltaPt(backgroundKTImprovedCMS, 1.0);
1876
1877     Double_t tmpDeltaPtKTImprovedCMSPartialExclusion_Signal = 0.0;
1878     if(fNumberSignalJets)
1879       tmpDeltaPtKTImprovedCMSPartialExclusion_Signal = GetDeltaPt(backgroundKTImprovedCMS, 1.0/fNumberSignalJets);
1880     else
1881       tmpDeltaPtKTImprovedCMSPartialExclusion_Signal = GetDeltaPt(backgroundKTImprovedCMS, 1.0);
1882  
1883     Double_t tmpDeltaPtKTImprovedCMSFullExclusion = GetDeltaPt(backgroundKTImprovedCMS, 1.0);
1884
1885     Double_t tmpDeltaPtKTPbPb = 0;
1886     Double_t tmpDeltaPtKTPbPbWithGhosts = 0;
1887     Double_t tmpDeltaPtKTCMS = 0;
1888     Double_t tmpDeltaPtKTMean = 0;
1889     Double_t tmpDeltaPtKTTrackLike = 0;
1890     Double_t tmpDeltaPtTR = 0;
1891
1892     if(fAnalyzeDeprecatedBackgrounds)
1893     {
1894       tmpDeltaPtKTPbPb = GetDeltaPt(backgroundKTPbPb);
1895       tmpDeltaPtKTPbPbWithGhosts = GetDeltaPt(backgroundKTPbPbWithGhosts);
1896       tmpDeltaPtKTCMS = GetDeltaPt(backgroundKTCMS);
1897       tmpDeltaPtKTMean = GetDeltaPt(backgroundKTMean);
1898       tmpDeltaPtKTTrackLike = GetDeltaPt(backgroundKTTrackLike);
1899       tmpDeltaPtTR = GetDeltaPt(backgroundTRCone06);
1900     }
1901
1902     // If valid, fill the delta pt histograms
1903
1904     if(tmpDeltaPtKTImprovedCMS > -10000.0)
1905       FillHistogram("hDeltaPtKTImprovedCMS", tmpDeltaPtKTImprovedCMS, centralityPercentile);
1906     if(tmpDeltaPtKTImprovedCMSPartialExclusion > -10000.0)
1907       FillHistogram("hDeltaPtKTImprovedCMSPartialExclusion", tmpDeltaPtKTImprovedCMSPartialExclusion, centralityPercentile);
1908     if(tmpDeltaPtKTImprovedCMSPartialExclusion_Signal > -10000.0)
1909       FillHistogram("hDeltaPtKTImprovedCMSPartialExclusion_Signal", tmpDeltaPtKTImprovedCMSPartialExclusion_Signal, centralityPercentile);
1910     if(tmpDeltaPtKTImprovedCMSFullExclusion > -10000.0)
1911       FillHistogram("hDeltaPtKTImprovedCMSFullExclusion", tmpDeltaPtKTImprovedCMSFullExclusion, centralityPercentile);
1912
1913     if(tmpDeltaPtNoBackground > 0.000001)
1914       FillHistogram("hDeltaPtNoBackgroundNoEmptyCones", tmpDeltaPtNoBackground, centralityPercentile);
1915     else if(tmpDeltaPtNoBackground > -10000.0)
1916       FillHistogram("hDeltaPtNoBackground", tmpDeltaPtNoBackground, centralityPercentile);
1917
1918
1919     if(fAnalyzeDeprecatedBackgrounds)
1920     {
1921       if(tmpDeltaPtKTPbPb > -10000.0)
1922         FillHistogram("hDeltaPtKTPbPb", tmpDeltaPtKTPbPb, centralityPercentile);
1923       if(tmpDeltaPtKTPbPbWithGhosts > -10000.0)
1924         FillHistogram("hDeltaPtKTPbPbWithGhosts", tmpDeltaPtKTPbPbWithGhosts, centralityPercentile);
1925       if(tmpDeltaPtKTCMS > -10000.0)
1926         FillHistogram("hDeltaPtKTCMS", tmpDeltaPtKTCMS, centralityPercentile);
1927       if(tmpDeltaPtKTMean > -10000.0)
1928         FillHistogram("hDeltaPtKTMean", tmpDeltaPtKTMean, centralityPercentile);
1929       if(tmpDeltaPtKTTrackLike > -10000.0)
1930         FillHistogram("hDeltaPtKTTrackLike", tmpDeltaPtKTTrackLike, centralityPercentile);
1931
1932       if(tmpDeltaPtTR > -10000.0)
1933         FillHistogram("hDeltaPtTR", tmpDeltaPtTR, centralityPercentile);
1934     }
1935   }
1936   
1937   #ifdef DEBUGMODE
1938     AliInfo("Calculate()::Background done.");
1939   #endif
1940   
1941   ////////////////////// NOTE: Pythia histograms
1942   if(fAnalyzePythia)
1943   {
1944     FillHistogram("hPythiaPtHard", GetPtHard());
1945     FillHistogram("hPythiaNTrials", GetPtHardBin()+0.1, GetPythiaTrials());
1946     FillHistogram("hPythiaXSection", GetPtHardBin()+0.1, fCrossSection);
1947
1948         #ifdef DEBUGMODE
1949       AliInfo("Calculate()::Pythia done.");
1950     #endif
1951   }
1952   #ifdef DEBUGMODE
1953     AliInfo("Calculate() done.");
1954   #endif
1955 }
1956
1957 //________________________________________________________________________
1958 Bool_t AliAnalysisTaskChargedJetsPA::UserNotify()
1959 {
1960   // Implemented Notify() to read the cross sections
1961   // and number of trials from pyxsec.root
1962   // 
1963   #ifdef DEBUGMODE
1964     AliInfo("UserNotify started.");
1965   #endif
1966
1967   if(fAnalyzePythia)
1968   {
1969     TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
1970     TFile *currFile = tree->GetCurrentFile();
1971
1972     TString file(currFile->GetName());
1973
1974     if(file.Contains("root_archive.zip#")){
1975       Ssiz_t pos1 = file.Index("root_archive",12,TString::kExact);
1976       Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
1977       file.Replace(pos+1,20,"");
1978     }
1979     else {
1980       // not an archive take the basename....
1981       file.ReplaceAll(gSystem->BaseName(file.Data()),"");
1982     }
1983    
1984     TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root")); // problem that we cannot really test the existance of a file in a archive so we have to lvie with open error message from root
1985     if(!fxsec){
1986       // next trial fetch the histgram file
1987       fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
1988       if(!fxsec){
1989           // not a severe condition but inciate that we have no information
1990         return kFALSE;
1991       }
1992       else{
1993         // find the tlist we want to be independtent of the name so use the Tkey
1994         TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0); 
1995         if(!key){
1996           fxsec->Close();
1997           return kFALSE;
1998         }
1999         TList *list = dynamic_cast<TList*>(key->ReadObj());
2000         if(!list){
2001           fxsec->Close();
2002           return kFALSE;
2003         }
2004         fCrossSection = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
2005         fTrials  = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
2006         fxsec->Close();
2007       }
2008     } // no tree pyxsec.root
2009     else {
2010       TTree *xtree = (TTree*)fxsec->Get("Xsection");
2011       if(!xtree){
2012         fxsec->Close();
2013         return kFALSE;
2014       }
2015       UInt_t   ntrials  = 0;
2016       Double_t  xsection  = 0;
2017       xtree->SetBranchAddress("xsection",&xsection);
2018       xtree->SetBranchAddress("ntrials",&ntrials);
2019       xtree->GetEntry(0);
2020       fTrials = ntrials;
2021       fCrossSection = xsection;
2022       fxsec->Close();
2023     }
2024   }
2025   #ifdef DEBUGMODE
2026     AliInfo("UserNotify ended.");
2027   #endif
2028   return kTRUE;
2029 }
2030
2031
2032 //________________________________________________________________________
2033 inline Double_t AliAnalysisTaskChargedJetsPA::EtaToTheta(Double_t arg)
2034   {return 2.*atan(exp(-arg));} 
2035 //________________________________________________________________________
2036 inline Double_t AliAnalysisTaskChargedJetsPA::ThetaToEta(Double_t arg)
2037 {
2038   if ((arg > TMath::Pi()) || (arg < 0.0))
2039   {
2040     AliError(Form("ThetaToEta got wrong input! (%f)", arg));
2041     return 0.0;
2042   }
2043   return -log(tan(arg/2.));
2044 }
2045 //________________________________________________________________________
2046 inline Double_t AliAnalysisTaskChargedJetsPA::GetDeltaPhi(Double_t phi1, Double_t phi2)
2047   {return min(TMath::Abs(phi1-phi2),TMath::TwoPi() - TMath::Abs(phi1-phi2));}
2048
2049 //________________________________________________________________________
2050 Double_t AliAnalysisTaskChargedJetsPA::MCGetOverlapCircleRectancle(Double_t cPosX, Double_t cPosY, Double_t cRadius, Double_t rPosXmin, Double_t rPosXmax, Double_t rPosYmin, Double_t rPosYmax)
2051 {
2052   const Int_t kTests = 1000;
2053   Int_t hits = 0;
2054   TRandom3 randomGen(0);
2055  
2056   // Loop over kTests-many tests
2057   for (Int_t i=0; i<kTests; i++)
2058   {
2059     //Choose random position in rectangle for the tester
2060     Double_t tmpTestX = randomGen.Uniform(rPosXmin, rPosXmax);
2061     Double_t tmpTestY = randomGen.Uniform(rPosYmin, rPosYmax);
2062
2063     //Check, if tester is in circle. If yes, increment circle counter.
2064     Double_t tmpDistance = TMath::Sqrt( (tmpTestX - cPosX)*(tmpTestX - cPosX) + (tmpTestY - cPosY)*(tmpTestY - cPosY) );
2065     if(tmpDistance < cRadius)
2066       hits++;
2067   }
2068
2069   // return ratio
2070   return (static_cast<Double_t>(hits)/static_cast<Double_t>(kTests));
2071 }
2072
2073 //________________________________________________________________________
2074 Double_t AliAnalysisTaskChargedJetsPA::MCGetOverlapMultipleCirclesRectancle(Int_t numCircles, std::vector<Double_t> cPosX, std::vector<Double_t> cPosY, Double_t cRadius, Double_t rPosXmin, Double_t rPosXmax, Double_t rPosYmin, Double_t rPosYmax)
2075 {
2076
2077   const Int_t kTests = 1000;
2078   Int_t hits = 0;
2079   TRandom3 randomGen(0);
2080  
2081   // Loop over kTests-many tests
2082   for (Int_t i=0; i<kTests; i++)
2083   {
2084     //Choose random position in rectangle for the tester
2085     Double_t tmpTestX = randomGen.Uniform(rPosXmin, rPosXmax);
2086     Double_t tmpTestY = randomGen.Uniform(rPosYmin, rPosYmax);
2087
2088     //Check, if tester is in one of the circles. If yes, increment circle counter.
2089     for(Int_t j=0; j<numCircles; j++)
2090     {
2091       Double_t tmpDistance = TMath::Sqrt( (tmpTestX - cPosX[j])*(tmpTestX - cPosX[j]) + (tmpTestY - cPosY[j])*(tmpTestY - cPosY[j]) );
2092       if(tmpDistance < cRadius)
2093       {
2094         hits++;
2095         break;
2096       }
2097     }
2098   }
2099
2100   // return ratio
2101   return (static_cast<Double_t>(hits)/static_cast<Double_t>(kTests));
2102
2103 }
2104
2105 //________________________________________________________________________
2106 inline void AliAnalysisTaskChargedJetsPA::FillHistogram(const char * key, Double_t x)
2107 {
2108   TH1* tmpHist = static_cast<TH1*>(fOutputList->FindObject(GetHistoName(key)));
2109   if(!tmpHist)
2110   {
2111     AliError(Form("Cannot find histogram <%s> ",key)) ;
2112     return;
2113   }
2114
2115   tmpHist->Fill(x);
2116 }
2117
2118 //________________________________________________________________________
2119 inline void AliAnalysisTaskChargedJetsPA::FillHistogram(const char * key, Double_t x, Double_t y)
2120 {
2121   TH1* tmpHist = static_cast<TH1*>(fOutputList->FindObject(GetHistoName(key)));
2122   if(!tmpHist)
2123   {
2124     AliError(Form("Cannot find histogram <%s> ",key));
2125     return;
2126   }
2127
2128   if (tmpHist->IsA()->GetBaseClass("TH1"))
2129     static_cast<TH1*>(tmpHist)->Fill(x,y); // Fill x with y
2130   else if (tmpHist->IsA()->GetBaseClass("TH2"))
2131     static_cast<TH2*>(tmpHist)->Fill(x,y); // Fill x,y with 1
2132 }
2133
2134 //________________________________________________________________________
2135 inline void AliAnalysisTaskChargedJetsPA::FillHistogram(const char * key, Double_t x, Double_t y, Double_t add)
2136 {
2137   TH2* tmpHist = static_cast<TH2*>(fOutputList->FindObject(GetHistoName(key)));
2138   if(!tmpHist)
2139   {
2140     AliError(Form("Cannot find histogram <%s> ",key));
2141     return;
2142   }
2143   
2144   tmpHist->Fill(x,y,add);
2145 }
2146 //________________________________________________________________________
2147 template <class T> T* AliAnalysisTaskChargedJetsPA::AddHistogram1D(const char* name, const char* title, const char* options, Int_t xBins, Double_t xMin, Double_t xMax, const char* xTitle, const char* yTitle)
2148 {
2149   T* tmpHist = new T(GetHistoName(name), GetHistoName(title), xBins, xMin, xMax);
2150
2151   tmpHist->GetXaxis()->SetTitle(xTitle);
2152   tmpHist->GetYaxis()->SetTitle(yTitle);
2153   tmpHist->SetOption(options);
2154   tmpHist->SetMarkerStyle(kFullCircle);
2155   tmpHist->Sumw2();
2156
2157   fHistList->Add(tmpHist);
2158   fHistCount++;
2159   
2160   return tmpHist;
2161 }
2162
2163 //________________________________________________________________________
2164 template <class T> T* AliAnalysisTaskChargedJetsPA::AddHistogram2D(const char* name, const char* title, const char* options, Int_t xBins, Double_t xMin, Double_t xMax, Int_t yBins, Double_t yMin, Double_t yMax, const char* xTitle, const char* yTitle, const char* zTitle)
2165 {
2166   T* tmpHist = new T(GetHistoName(name), GetHistoName(title), xBins, xMin, xMax, yBins, yMin, yMax);
2167   tmpHist->GetXaxis()->SetTitle(xTitle);
2168   tmpHist->GetYaxis()->SetTitle(yTitle);
2169   tmpHist->GetZaxis()->SetTitle(zTitle);
2170   tmpHist->SetOption(options);
2171   tmpHist->SetMarkerStyle(kFullCircle);
2172   tmpHist->Sumw2();
2173
2174   fHistList->Add(tmpHist);
2175   fHistCount++;
2176
2177   return tmpHist;
2178 }
2179
2180 //________________________________________________________________________
2181 void AliAnalysisTaskChargedJetsPA::Terminate(Option_t *)
2182 {
2183   PostData(1, fOutputList);
2184
2185   // Mandatory
2186   fOutputList = dynamic_cast<TList*> (GetOutputData(1)); // '1' refers to the output slot
2187   if (!fOutputList) {
2188     printf("ERROR: Output list not available\n");
2189     return;
2190   }
2191 }
2192
2193 //________________________________________________________________________
2194 AliAnalysisTaskChargedJetsPA::~AliAnalysisTaskChargedJetsPA()
2195 {
2196   // Destructor. Clean-up the output list, but not the histograms that are put inside
2197   // (the list is owner and will clean-up these histograms). Protect in PROOF case.
2198   if (fOutputList && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
2199     delete fOutputList;
2200   }
2201 }
2202
2203 //________________________________________________________________________
2204 void AliAnalysisTaskChargedJetsPA::UserCreateOutputObjects()
2205 {
2206   // called once to create user defined output objects like histograms, plots etc. 
2207   // and to put it on the output list.
2208   // Note: Saving to file with e.g. OpenFile(0) is must be before creating other objects.
2209
2210   fRandom = new TRandom3(0);
2211
2212
2213   fOutputList = new TList();
2214   fOutputList->SetOwner(); // otherwise it produces leaks in merging
2215
2216   // NOTE: Pythia histograms
2217   AddHistogram1D<TProfile>("hPythiaXSection", "Pythia cross section distribution", "", fNumPtHardBins+1, 0, fNumPtHardBins+1, "p_{T} hard bin","dN^{Events}/dp_{T,hard}");
2218   AddHistogram1D<TH1D>("hPythiaNTrials", "Pythia trials (no correction for manual cuts)", "", fNumPtHardBins+1, 0, fNumPtHardBins+1, "p_{T} hard bin", "Trials");
2219
2220
2221   PostData(1, fOutputList);
2222 }
2223
2224 //________________________________________________________________________
2225 void AliAnalysisTaskChargedJetsPA::UserExec(Option_t *) 
2226 {
2227   #ifdef DEBUGMODE
2228     AliInfo("UserExec() started.");
2229   #endif
2230
2231   if (!InputEvent())
2232   {
2233     AliError("??? Event pointer == 0 ???");
2234     return;
2235   }
2236
2237   if (!fInitialized)
2238     ExecOnce(); // Get tracks, jets, background from arrays if not already given + Init Histos
2239   
2240   Calculate(InputEvent());
2241         
2242   PostData(1, fOutputList);
2243 }