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