Charged jets (pPb): Bugfix
[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 <THn.h>
32 #include "TFormula.h"
33 #include "AliESDtrackCuts.h"
34 #include <time.h>
35 #include <TRandom3.h>
36 #include "AliGenPythiaEventHeader.h"
37 #include "AliAODMCHeader.h"
38 #include "AliMCEvent.h"
39 #include "AliLog.h"
40 #include <AliEmcalJet.h>
41 #include <AliPicoTrack.h>
42 #include "AliVEventHandler.h"
43 #include "AliVParticle.h"
44 #include "AliAODMCParticle.h"
45 #include "AliAnalysisUtils.h"
46 #include "AliRhoParameter.h"
47 #include "TVector3.h"
48
49 #include "AliAnalysisTaskChargedJetsPA.h"
50 using std::min;
51
52 //TODO: FillHistogram can be done better with virtual TH1(?)
53 ClassImp(AliAnalysisTaskChargedJetsPA)
54
55 // ######################################################################################## DEFINE HISTOGRAMS
56 void AliAnalysisTaskChargedJetsPA::Init()
57 {
58   #ifdef DEBUGMODE
59     AliInfo("Creating histograms.");
60   #endif
61
62   SetCurrentOutputList(0);
63
64   // Cuts
65   TH1D* tmpHisto = AddHistogram1D<TH1D>("hNumberEvents", "Number of events (0 = before cuts, 1 = after cuts)", "", 2, 0, 2, "stage","N^{Events}/cut");
66   tmpHisto->GetXaxis()->SetBinLabel(1, "Before cuts");
67   tmpHisto->GetXaxis()->SetBinLabel(2, "After cuts");
68   tmpHisto = AddHistogram1D<TH1D>("hEventAcceptance", "Accepted events (0 = before cuts, 1 = after pile up, 2 = after vertex)", "", 3, 0, 3, "stage","N^{Events}/cut");
69   tmpHisto->GetXaxis()->SetBinLabel(1, "Before cuts");
70   tmpHisto->GetXaxis()->SetBinLabel(2, "After pile up");
71   tmpHisto->GetXaxis()->SetBinLabel(3, "After vertex");
72   tmpHisto = AddHistogram1D<TH1D>("hTrackAcceptance", "Accepted tracks (0 = before cuts, 1 = after eta, 2 = after pT)", "", 3, 0, 3, "stage","N^{Tracks}/cut");
73   tmpHisto->GetXaxis()->SetBinLabel(1, "Before cuts");
74   tmpHisto->GetXaxis()->SetBinLabel(2, "After eta");
75   tmpHisto->GetXaxis()->SetBinLabel(3, "After p_{T}");
76   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");
77   tmpHisto->GetXaxis()->SetBinLabel(1, "Before cuts");
78   tmpHisto->GetXaxis()->SetBinLabel(2, "After eta");
79   tmpHisto->GetXaxis()->SetBinLabel(3, "After p_{T}");
80   tmpHisto->GetXaxis()->SetBinLabel(4, "After area");
81   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}");
82   tmpHisto2D->GetYaxis()->SetBinLabel(1, "Before cuts");
83   tmpHisto2D->GetYaxis()->SetBinLabel(2, "After eta");
84   tmpHisto2D->GetYaxis()->SetBinLabel(3, "After p_{T}");
85   tmpHisto2D->GetYaxis()->SetBinLabel(4, "After area");
86
87   AddHistogram1D<TH1D>("hVertexX", "X distribution of the vertex", "", 2000, -1., 1., "#Delta x(cm)","dN^{Events}/dx");
88   AddHistogram1D<TH1D>("hVertexY", "Y distribution of the vertex", "", 2000, -1., 1., "#Delta y(cm)","dN^{Events}/dy");
89   AddHistogram2D<TH2D>("hVertexXY", "XY distribution of the vertex", "COLZ", 500, -1., 1., 500, -1., 1.,"#Delta x(cm)", "#Delta y(cm)","dN^{Events}/dxdy");
90   AddHistogram1D<TH1D>("hVertexZBeforeVertexCut", "Z distribution of the vertex (before std. vertex cut)", "", 200, -20., 20., "#Delta z(cm)","dN^{Events}/dz");
91   AddHistogram1D<TH1D>("hVertexZAfterVertexCut", "Z distribution of the vertex (after std. vertex cut)", "", 200, -20., 20., "#Delta z(cm)","dN^{Events}/dz");
92   AddHistogram1D<TH1D>("hVertexR", "R distribution of the vertex", "", 100, 0., 1., "#Delta r(cm)","dN^{Events}/dr");
93   AddHistogram1D<TH1D>("hCentralityV0M", "Centrality distribution V0M", "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
94   AddHistogram1D<TH1D>("hCentralityV0A", "Centrality distribution V0A", "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
95   AddHistogram1D<TH1D>("hCentralityV0C", "Centrality distribution V0C", "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
96   AddHistogram1D<TH1D>("hCentralityZNA", "Centrality distribution ZNA", "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
97   AddHistogram1D<TH1D>("hCentrality", Form("Centrality distribution %s", fCentralityType.Data()), "", fNumberOfCentralityBins, 0., 100., "Centrality","dN^{Events}");
98
99   if(fDoJetAnalysis)
100   {
101     // Background corrected jet spectra
102     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}");    
103     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}");
104     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}");    
105     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}");    
106     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}");
107     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}");
108     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}");
109     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}");
110     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}");    
111     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}");    
112     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}");
113
114     AddHistogram2D<TProfile2D>("hJetPtSubtractedRhoExternal", "Mean subtracted KT (External) background from jets", "COLZ", 600, 0, 150, fNumberOfCentralityBins, 0, 100, "Jet p_{T}", "Centrality", "#rho mean");
115     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");
116     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");
117
118     // Jet QA plots
119     AddHistogram2D<TH2D>("hJetConstituentPt", "Jet constituents p_{T} distribution", "", 500, -50., 200., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Tracks}/dp_{T}");
120     AddHistogram2D<TH2D>("hJetConstituentPtVsJetPt", "Jet constituents p_{T} distribution", "", 500, -50., 200., 200, 0, 200, "#it{p}_{T} (GeV/c)","#it{p}_{T}^{jet} (GeV/c)","dN^{Tracks}/dp_{T}");
121     AddHistogram1D<TH1D>("hJetCountAll", "Number of Jets", "", 200, 0., 200., "N jets","dN^{Events}/dN^{Jets}");
122     AddHistogram1D<TH1D>("hJetCountAccepted", "Number of accepted Jets", "", 200, 0., 200., "N jets","dN^{Events}/dN^{Jets}");
123     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}}");
124     AddHistogram1D<TH1D>("hLeadingJetPt", "Leading jet p_{T}", "", 500, -50., 200., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
125     AddHistogram1D<TH1D>("hSecondLeadingJetPt", "Second leading jet p_{T}", "", 500, -50., 200., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
126     AddHistogram1D<TH1D>("hCorrectedLeadingJetPt", "Corrected leading jet p_{T}", "", 500, -50., 200., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
127     AddHistogram1D<TH1D>("hCorrectedSecondLeadingJetPt", "Corrected second leading jet p_{T}", "", 500, -50., 200., "p_{T} (GeV/c)","dN^{Jets}/dp_{T}");
128     AddHistogram1D<TH1D>("hJetDeltaPhi", "Jets combinatorial #Delta #phi", "", 250, 0., TMath::Pi(), "#Delta #phi","dN^{Jets}/d(#Delta #phi)");
129     AddHistogram1D<TH1D>("hLeadingJetDeltaPhi", "1st and 2nd leading jet #Delta #phi", "", 250, 0., TMath::Pi(), "#Delta #phi","dN^{Jets}/d(#Delta #phi)");
130
131     // Background distributions
132     AddHistogram2D<TH2D>("hKTBackgroundExternal", "KT background density (External task)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
133     AddHistogram2D<TH2D>("hKTBackgroundExternal20GeV", "KT background density (External task, jet p_{T} > 20 GeV)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
134     AddHistogram2D<TH2D>("hKTBackgroundImprovedCMS", "KT background density (Improved CMS approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
135     AddHistogram2D<TH2D>("hPPBackground", "PP background density (Michals approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
136     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");
137     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");
138     AddHistogram2D<TH2D>("hKTBackgroundCMS", "KT background density (CMS approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
139     AddHistogram2D<TH2D>("hKTBackgroundMean", "KT background density (Mean approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
140     AddHistogram2D<TH2D>("hKTBackgroundTrackLike", "KT background density (Track-like approach)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
141     AddHistogram2D<TH2D>("hTRBackgroundNoExcl", "TR background density (No signal excluded)", "LEGO2", 400, 0., 40., fNumberOfCentralityBins, 0, 100, "#rho (GeV/c)","Centrality", "dN^{Events}/d#rho");
142     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");
143     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");
144     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");
145     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");
146     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");
147
148     // Delta pt distributions
149     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}");
150     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}");
151     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}");
152     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}");
153     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}");
154     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}");
155     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}");
156     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}");
157     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}");
158     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}");
159     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}");
160
161     // Track QA plots
162     AddHistogram2D<TH2D>("hTrackCountAcc", "Number of tracks in acceptance vs. centrality", "LEGO2", 750, 0., 750., fNumberOfCentralityBins, 0, 100, "N tracks","Centrality", "dN^{Events}/dN^{Tracks}");
163     AddHistogram2D<TH2D>("hTrackPt", "Tracks p_{T} distribution", "", 1000, 0., 250., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)", "Centrality", "dN^{Tracks}/dp_{T}");
164     AddHistogram2D<TH2D>("hTrackPtNegEta", "Tracks p_{T} distribution (negative #eta)", "", 1000, 0., 250., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Tracks}/dp_{T}");
165     AddHistogram2D<TH2D>("hTrackPtPosEta", "Tracks p_{T} distribution (positive #eta)", "", 1000, 0., 250., fNumberOfCentralityBins, 0, 100, "p_{T} (GeV/c)","Centrality","dN^{Tracks}/dp_{T}");
166     AddHistogram1D<TH1D>("hTrackCharge", "Charge", "", 11, -5, 5, "Charge (e)","dN^{Tracks}/dq");
167     AddHistogram1D<TH1D>("hTrackPhi", "Track #phi distribution", "", 360, 0, TMath::TwoPi(), "#phi","dN^{Tracks}/d#phi");
168     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)");
169     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)");
170     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}");
171     AddHistogram2D<TH2D>("hTrackPhiTrackType", "Track #phi distribution for different track types", "LEGO2", 360, 0, TMath::TwoPi(), 3, 0, 3, "#phi", "Label", "dN^{Tracks}/d#phi");
172     AddHistogram2D<TH2D>("hTrackEta", "Track #eta distribution", "COLZ", 180, fMinEta, fMaxEta, fNumberOfCentralityBins, 0., 100., "#eta", "Centrality", "dN^{Tracks}/d#eta");
173
174     // Jet QA plots
175     AddHistogram1D<TH1D>("hRawJetArea", "Jets area distribution w/o area cut", "", 200, 0., 2., "Area","dN^{Jets}/dA");
176     AddHistogram2D<TH2D>("hJetArea", "Jets area distribution", "COLZ", 200, 0., 2.,  500, -50., 200, "Area","Jet p_{T}","dN^{Jets}/dA");
177     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)");
178     AddHistogram2D<TH2D>("hJetEta", "Jets #eta distribution", "COLZ", 180, fMinEta, fMaxEta, fNumberOfCentralityBins, 0., 100., "#eta", "Centrality", "dN^{Jets}/d#eta");
179     AddHistogram2D<TH2D>("hJetEta2GeVTracks", "Jets #eta distribution, track p_{T} > 2 GeV", "COLZ", 180, fMinEta, fMaxEta, fNumberOfCentralityBins, 0., 100., "#eta", "Centrality", "dN^{Jets}/d#eta");
180     AddHistogram2D<TH2D>("hJetEta4GeVTracks", "Jets #eta distribution, track p_{T} > 4 GeV", "COLZ", 180, fMinEta, fMaxEta, fNumberOfCentralityBins, 0., 100., "#eta", "Centrality", "dN^{Jets}/d#eta");
181     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)");
182     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)");
183     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})");
184
185     // ######## Jet profiles
186     if(fAnalyzeJetProfile)
187     {
188       SetCurrentOutputList(1);
189       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");
190       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");
191       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");
192       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");
193       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");
194       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");
195       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");
196       SetCurrentOutputList(0);
197     }
198   }
199   // ######## Jet track cuts
200   if(fAnalyzeTrackcuts)
201   {
202     SetCurrentOutputList(2);
203
204     AddCutHistogram("hCutsNumberClusters", "Trackcut histogram: Number of clusters", "Number of clusters", 40, 20, 160);
205     AddCutHistogram("hCutsChi2TPC", "Trackcut histogram: #chi^{2} per TPC cluster", "#chi^{2}", 40, 0, 8);
206     AddCutHistogram("hCutsChi2ITS", "Trackcut histogram: #chi^{2} per ITS cluster", "#chi^{2}", 25, 0., 50);
207     AddCutHistogram("hCutsChi2Constrained", "Trackcut histogram: #chi^{2} for global constrained tracks", "#chi^{2}", 60, 0, 60);
208     AddCutHistogram("hCutsDCAZ", "Trackcut histogram: Max. DCA z for prim. vertex", "DCA z", 20, 0, 4);
209     AddCutHistogram("hCutsSPDHit", "Trackcut histogram: Hit in SPD layer", "Hit or not", 2, -0.5, 1.5);
210     AddCutHistogram("hCutsNumberCrossedRows", "Trackcut histogram: Number of crossed rows", "Number of crossed rows", 40, 20, 160);
211     AddCutHistogram("hCutsNumberCrossedRowsOverFindableClusters", "Trackcut histogram: Number of crossed rows over findable clusters", "Number of crossed rows over findable clusters", 26, 0.4, 1.8);
212     AddCutHistogram("hCutsSharedTPC", "Trackcut histogram: Shared TPC clusters", "Shared fraction", 40, 0, 1);
213     AddCutHistogram("hCutsTPCRefit", "Trackcut histogram: TPC refit", "Has TPC refit", 2, -0.5, 1.5);
214     AddCutHistogram("hCutsTPCLength", "Trackcut histogram: TPC length", "TPC length", 40, 0, 170);
215     AddCutHistogram("hCutsTrackConstrained", "Trackcut histogram: Tracks constrained to vertex", "Track is constrained", 2, -0.5, 1.5);
216     AddCutHistogram("hCutsClustersPtDependence", "Trackcut histogram: Use pT dependence for Number of clusters cut", "Use pT dependence", 2, -0.5, 1.5);
217
218     SetCurrentOutputList(0);
219   }
220
221   PostData(1, fOutputLists[0]);
222   if(fAnalyzeJetProfile)
223     PostData(2, fOutputLists[1]);
224   if(fAnalyzeTrackcuts)
225   {
226     if(fAnalyzeJetProfile)
227       PostData(3, fOutputLists[2]);
228     else
229       PostData(2, fOutputLists[1]);
230   }
231
232 }
233
234 //________________________________________________________________________
235 AliAnalysisTaskChargedJetsPA::AliAnalysisTaskChargedJetsPA(const char *name, const char* trackArrayName, const char* jetArrayName, const char* backgroundJetArrayName, Bool_t analyzeJetProfile, Bool_t analyzeTrackcuts) : AliAnalysisTaskSE(name), fOutputLists(), fCurrentOutputList(0), fDoJetAnalysis(1), fAnalyzeJetProfile(0), fAnalyzeTrackcuts(0), fParticleLevel(0), fUseDefaultVertexCut(1), fUsePileUpCut(1), fSetCentralityToOne(0), fNoExternalBackground(0), fBackgroundForJetProfile(0), fPartialAnalysisNParts(1), fPartialAnalysisIndex(0), fJetArray(0), fTrackArray(0), fBackgroundJetArray(0), fJetArrayName(), fTrackArrayName(), fBackgroundJetArrayName(), fRhoTaskName(), fRandConeRadius(0.4), fSignalJetRadius(0.4), fBackgroundJetRadius(0.4), fNumberExcludedJets(-1), fMinEta(-0.9), fMaxEta(0.9), fMinJetEta(-0.5), fMaxJetEta(0.5), fMinTrackPt(0.150), fMinJetPt(5.0), fMinJetArea(0.5), fMinBackgroundJetPt(0.0), fNumberOfCentralityBins(20), fCentralityType("V0A"), fPrimaryVertex(0), fFirstLeadingJet(0), fSecondLeadingJet(0), fFirstLeadingKTJet(0), fSecondLeadingKTJet(0), fNumberSignalJets(0), fNumberSignalJetsAbove5GeV(0), fRandom(0), fHelperClass(0), fInitialized(0), fTaskInstanceCounter(0), fIsDEBUG(0), fIsPA(1), fEventCounter(0), fHybridESDtrackCuts(0), fHybridESDtrackCuts_noPtDep(0)
236 {
237   #ifdef DEBUGMODE
238     AliInfo("Calling constructor.");
239   #endif
240
241   // Every instance of this task gets his own number
242   static Int_t instance = 0;
243   fTaskInstanceCounter = instance;
244   instance++;
245
246   fAnalyzeJetProfile = analyzeJetProfile;
247   fAnalyzeTrackcuts  = analyzeTrackcuts; 
248
249   // Save the observables array names
250   fTrackArrayName  = trackArrayName;
251   fJetArrayName = jetArrayName;
252   fBackgroundJetArrayName = backgroundJetArrayName;
253
254   if (fTrackArrayName.Contains("MCParticles") || fTrackArrayName.Contains("mcparticles"))
255     fParticleLevel = kTRUE;
256
257   DefineOutput(1, TList::Class());
258   if(fAnalyzeJetProfile)
259     DefineOutput(2, TList::Class());
260   if(fAnalyzeTrackcuts)
261   {
262     if(fAnalyzeJetProfile)
263       DefineOutput(3, TList::Class());
264     else
265       DefineOutput(2, TList::Class());
266   }
267
268   #ifdef DEBUGMODE
269     AliInfo("Constructor done.");
270   #endif
271 }
272
273 //________________________________________________________________________
274 void AliAnalysisTaskChargedJetsPA::InitializeTrackcuts()
275 {
276   AliESDtrackCuts* commonTrackCuts = new AliESDtrackCuts;
277   commonTrackCuts->SetMaxChi2PerClusterTPC(4);
278   commonTrackCuts->SetMaxChi2PerClusterITS(36);
279   commonTrackCuts->SetAcceptKinkDaughters(kFALSE);
280   commonTrackCuts->SetRequireTPCRefit(kTRUE);
281   commonTrackCuts->SetRequireITSRefit(kTRUE);
282   commonTrackCuts->SetRequireSigmaToVertex(kFALSE);
283   commonTrackCuts->SetMaxDCAToVertexXY(2.4);
284   commonTrackCuts->SetMaxDCAToVertexZ(3.2);
285   commonTrackCuts->SetDCAToVertex2D(kTRUE);
286   commonTrackCuts->SetMaxFractionSharedTPCClusters(0.4);
287   commonTrackCuts->SetMaxChi2TPCConstrainedGlobal(36);
288   commonTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kAny);
289
290   AliESDtrackCuts*    fTrackCutsPA_global = NULL;
291   AliESDtrackCuts*    fTrackCutsPA_complementary = NULL;
292   AliESDtrackCuts*    fTrackCutsPP_global = NULL;
293   AliESDtrackCuts*    fTrackCutsPP_complementary = NULL;
294   AliESDtrackCuts*    fTrackCutsPP_global_noPtDep = NULL;
295   AliESDtrackCuts*    fTrackCutsPP_complementary_noPtDep = NULL;
296
297   //pPb
298   fTrackCutsPA_global = static_cast<AliESDtrackCuts*>(commonTrackCuts->Clone("fTrackCutsPA_global"));
299   fTrackCutsPA_global->SetMinNCrossedRowsTPC(70);
300   fTrackCutsPA_global->SetMinRatioCrossedRowsOverFindableClustersTPC(0.8);
301   fTrackCutsPA_complementary = static_cast<AliESDtrackCuts*>(fTrackCutsPA_global->Clone("fTrackCutsPA_complementary"));
302   fTrackCutsPA_complementary->SetRequireITSRefit(kFALSE);
303   fTrackCutsPA_complementary->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kOff);
304
305   //pp 
306   fTrackCutsPP_global = static_cast<AliESDtrackCuts*>(commonTrackCuts->Clone("fTrackCutsPP_global"));
307   TFormula *f1NClustersTPCLinearPtDep = new TFormula("f1NClustersTPCLinearPtDep","70.+30./20.*x");
308   fTrackCutsPP_global->SetMinNClustersTPCPtDep(f1NClustersTPCLinearPtDep,20.);
309   fTrackCutsPP_global->SetMinNClustersTPC(70);
310   fTrackCutsPP_global->SetRequireTPCStandAlone(kTRUE); //cut on NClustersTPC and chi2TPC Iter1
311   fTrackCutsPP_global->SetEtaRange(-0.9,0.9);
312   fTrackCutsPP_global->SetPtRange(0.15, 1e15);
313   fTrackCutsPP_complementary = static_cast<AliESDtrackCuts*>(fTrackCutsPP_global->Clone("fTrackCutsPP_complementary"));
314   fTrackCutsPP_complementary->SetRequireITSRefit(kFALSE);
315   fTrackCutsPP_complementary->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kOff);
316
317   //pp, no pT dependence
318
319   fTrackCutsPP_global_noPtDep = static_cast<AliESDtrackCuts*>(commonTrackCuts->Clone("fTrackCutsPP_global_noPtDep"));
320   fTrackCutsPP_global_noPtDep->SetMinNClustersTPC(70);
321   fTrackCutsPP_global_noPtDep->SetRequireTPCStandAlone(kTRUE); //cut on NClustersTPC and chi2TPC Iter1
322   fTrackCutsPP_global_noPtDep->SetEtaRange(-0.9,0.9);
323   fTrackCutsPP_global_noPtDep->SetPtRange(0.15, 1e15);
324   fTrackCutsPP_complementary_noPtDep = static_cast<AliESDtrackCuts*>(fTrackCutsPP_global_noPtDep->Clone("fTrackCutsPP_complementary_noPtDep"));
325   fTrackCutsPP_complementary_noPtDep->SetRequireITSRefit(kFALSE);
326   fTrackCutsPP_complementary_noPtDep->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kOff);
327
328   fHybridESDtrackCuts = new AliESDHybridTrackcuts();
329   fHybridESDtrackCuts_noPtDep = new AliESDHybridTrackcuts();
330   if(fIsPA)
331   {
332     fHybridESDtrackCuts->SetMainCuts(fTrackCutsPA_global);
333     fHybridESDtrackCuts->SetAdditionalCuts(fTrackCutsPA_complementary);
334     fHybridESDtrackCuts_noPtDep->SetMainCuts(fTrackCutsPA_global);
335     fHybridESDtrackCuts_noPtDep->SetAdditionalCuts(fTrackCutsPA_complementary);
336   }
337   else
338   {
339     fHybridESDtrackCuts->SetMainCuts(fTrackCutsPP_global);
340     fHybridESDtrackCuts->SetAdditionalCuts(fTrackCutsPP_complementary);
341     fHybridESDtrackCuts_noPtDep->SetMainCuts(fTrackCutsPP_global_noPtDep);
342     fHybridESDtrackCuts_noPtDep->SetAdditionalCuts(fTrackCutsPP_complementary_noPtDep);
343   }
344
345   delete commonTrackCuts;
346 }
347
348 //________________________________________________________________________
349 void AliAnalysisTaskChargedJetsPA::CreateCutHistograms()
350 {
351
352   AliESDEvent* fESD = dynamic_cast<AliESDEvent*>( InputEvent() );
353   if (!fESD)
354   {
355     AliError("For cut analysis, ESDs must be processed!");
356     return;
357   }
358
359
360   Float_t dca[2], cov[3]; // dca_xy, dca_z, sigma_xy, sigma_xy_z, sigma_z for the vertex cut
361   for (Int_t i=0;i < fESD->GetNumberOfTracks(); i++)
362   {
363     AliESDtrack* track = fESD->GetTrack(i);
364
365     // Basics kinematic variables
366     Double_t pT                  = track->Pt();
367     Double_t eta                 = track->Eta();
368     Double_t phi                 = track->Phi();
369
370     // Number of clusters
371     Double_t nclsTPC             = track->GetTPCncls();
372     Double_t nclsITS             = track->GetITSclusters(0);
373
374     // Crossed rows
375     Double_t ncrTPC              = track->GetTPCCrossedRows();
376     Double_t nCRoverFC           = 0;
377     if(track->GetTPCNclsF())
378       nCRoverFC = track->GetTPCCrossedRows()/track->GetTPCNclsF();
379
380     // Chi2 of tracks
381     Double_t chi2ITS             = 999.; 
382     if (nclsITS)
383       chi2ITS = track->GetITSchi2()/nclsITS; 
384     Double_t chi2TPC             = 999.;
385     if (nclsTPC)
386       chi2TPC = track->GetTPCchi2()/nclsTPC; 
387     Double_t chi2TPCConstrained  = track->GetChi2TPCConstrainedVsGlobal(static_cast<const AliESDVertex*>(fPrimaryVertex));
388
389     // Misc
390     Double_t SharedTPCClusters = 999.;
391     Double_t nClustersTPC = 0;
392     if(fHybridESDtrackCuts->GetMainCuts()->GetRequireTPCStandAlone()) {
393       nClustersTPC = track->GetTPCNclsIter1();
394     }
395     else {
396       nClustersTPC = track->GetTPCclusters(0);
397     }
398
399     if(track->GetTPCncls())
400       SharedTPCClusters = static_cast<Double_t>(track->GetTPCnclsS())/static_cast<Double_t>(nClustersTPC);
401     Double_t tpcLength   = 0.;
402     if (track->GetInnerParam() && track->GetESDEvent()) {
403       tpcLength = track->GetLengthInActiveZone(1, 1.8, 220, track->GetESDEvent()->GetMagneticField());
404     }
405     track->GetImpactParameters(dca, cov);
406
407     // Basic kinematic cuts
408     if((pT<0.15) || (TMath::Abs(eta)>0.9))
409       continue;
410
411     SetCurrentOutputList(2);
412
413     Int_t trackType = 0;
414
415     // ################################################################
416     // ################################################################
417     Int_t minNclsTPC = fHybridESDtrackCuts->GetMainCuts()->GetMinNClusterTPC();
418     Int_t minNclsTPC_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMinNClusterTPC();
419     fHybridESDtrackCuts->GetMainCuts()->SetMinNClustersTPC(0);
420     fHybridESDtrackCuts->GetAdditionalCuts()->SetMinNClustersTPC(0);
421     
422     trackType = fHybridESDtrackCuts->AcceptTrack(track);
423     if (trackType)
424       FillCutHistogram("hCutsNumberClusters", nclsTPC, pT, eta, phi, trackType-1);
425
426     fHybridESDtrackCuts->GetMainCuts()->SetMinNClustersTPC(minNclsTPC);
427     fHybridESDtrackCuts->GetAdditionalCuts()->SetMinNClustersTPC(minNclsTPC_Additional);
428     // ################################################################
429     // ################################################################
430     Float_t maxChi2 = fHybridESDtrackCuts->GetMainCuts()->GetMaxChi2PerClusterTPC();
431     Float_t maxChi2_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMaxChi2PerClusterTPC();
432     fHybridESDtrackCuts->GetMainCuts()->SetMaxChi2PerClusterTPC(999.);
433     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxChi2PerClusterTPC(999.);
434
435     trackType = fHybridESDtrackCuts->AcceptTrack(track);
436     if (trackType)
437       FillCutHistogram("hCutsChi2TPC", chi2TPC, pT, eta, phi, trackType-1);
438
439     fHybridESDtrackCuts->GetMainCuts()->SetMaxChi2PerClusterTPC(maxChi2);
440     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxChi2PerClusterTPC(maxChi2_Additional);
441
442     // ################################################################
443     // ################################################################
444     Float_t maxChi2TPCConstrained = fHybridESDtrackCuts->GetMainCuts()->GetMaxChi2TPCConstrainedGlobal();
445     Float_t maxChi2TPCConstrained_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMaxChi2TPCConstrainedGlobal();
446     fHybridESDtrackCuts->GetMainCuts()->SetMaxChi2TPCConstrainedGlobal(999.);
447     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxChi2TPCConstrainedGlobal(999.);
448
449     trackType = fHybridESDtrackCuts->AcceptTrack(track);
450     if (trackType)
451       FillCutHistogram("hCutsChi2Constrained", chi2TPCConstrained, pT, eta, phi, trackType-1);
452
453     fHybridESDtrackCuts->GetMainCuts()->SetMaxChi2TPCConstrainedGlobal(maxChi2TPCConstrained);
454     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxChi2TPCConstrainedGlobal(maxChi2TPCConstrained_Additional);
455
456     // ################################################################
457     // ################################################################
458     Float_t maxDcaZ = fHybridESDtrackCuts->GetMainCuts()->GetMaxDCAToVertexZ();
459     Float_t maxDcaZ_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMaxDCAToVertexZ();
460     fHybridESDtrackCuts->GetMainCuts()->SetMaxDCAToVertexZ(999.);
461     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxDCAToVertexZ(999.);
462
463     trackType = fHybridESDtrackCuts->AcceptTrack(track);
464     if (trackType)
465       FillCutHistogram("hCutsDCAZ", TMath::Abs(dca[1]), pT, eta, phi, trackType-1);
466
467     fHybridESDtrackCuts->GetMainCuts()->SetMaxDCAToVertexZ(maxDcaZ);
468     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxDCAToVertexZ(maxDcaZ_Additional);
469     // ################################################################
470     // ################################################################
471     AliESDtrackCuts::ITSClusterRequirement clusterReq = fHybridESDtrackCuts->GetMainCuts()->GetClusterRequirementITS(AliESDtrackCuts::kSPD);
472     AliESDtrackCuts::ITSClusterRequirement clusterReq_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetClusterRequirementITS(AliESDtrackCuts::kSPD);
473     fHybridESDtrackCuts->GetMainCuts()->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kOff);
474     fHybridESDtrackCuts->GetAdditionalCuts()->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kOff);
475
476     Int_t hasPoint = 0;
477     if (track->HasPointOnITSLayer(0) || track->HasPointOnITSLayer(1)) hasPoint = 1;
478     trackType = fHybridESDtrackCuts->AcceptTrack(track);
479     if (trackType)
480       FillCutHistogram("hCutsSPDHit", hasPoint, pT, eta, phi, trackType-1);
481
482     fHybridESDtrackCuts->GetMainCuts()->SetClusterRequirementITS(AliESDtrackCuts::kSPD, clusterReq);
483     fHybridESDtrackCuts->GetAdditionalCuts()->SetClusterRequirementITS(AliESDtrackCuts::kSPD, clusterReq_Additional);
484
485     // ################################################################
486     // ################################################################
487     Float_t minNcrTPC = fHybridESDtrackCuts->GetMainCuts()->GetMinNCrossedRowsTPC();
488     Float_t minNcrTPC_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMinNCrossedRowsTPC();
489     fHybridESDtrackCuts->GetMainCuts()->SetMinNCrossedRowsTPC(0);
490     fHybridESDtrackCuts->GetAdditionalCuts()->SetMinNCrossedRowsTPC(0);
491
492     trackType = fHybridESDtrackCuts->AcceptTrack(track);
493     if (trackType)
494       FillCutHistogram("hCutsNumberCrossedRows", ncrTPC, pT, eta, phi, trackType-1);
495
496     fHybridESDtrackCuts->GetMainCuts()->SetMinNCrossedRowsTPC(minNcrTPC);
497     fHybridESDtrackCuts->GetAdditionalCuts()->SetMinNCrossedRowsTPC(minNcrTPC_Additional);
498
499     // ################################################################
500     // ################################################################
501     Float_t minCRoverFC = fHybridESDtrackCuts->GetMainCuts()->GetMinRatioCrossedRowsOverFindableClustersTPC();
502     Float_t minCRoverFC_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMinRatioCrossedRowsOverFindableClustersTPC();
503     fHybridESDtrackCuts->GetMainCuts()->SetMinRatioCrossedRowsOverFindableClustersTPC(0.);
504     fHybridESDtrackCuts->GetAdditionalCuts()->SetMinRatioCrossedRowsOverFindableClustersTPC(0.);
505
506     trackType = fHybridESDtrackCuts->AcceptTrack(track);
507     if (trackType)
508       FillCutHistogram("hCutsNumberCrossedRowsOverFindableClusters", nCRoverFC, pT, eta, phi, trackType-1);
509
510     fHybridESDtrackCuts->GetMainCuts()->SetMinRatioCrossedRowsOverFindableClustersTPC(minCRoverFC);
511     fHybridESDtrackCuts->GetAdditionalCuts()->SetMinRatioCrossedRowsOverFindableClustersTPC(minCRoverFC_Additional);
512
513     // ################################################################
514     // ################################################################
515     Float_t maxSharedTPC = fHybridESDtrackCuts->GetMainCuts()->GetMaxFractionSharedTPCClusters();
516     Float_t maxSharedTPC_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMaxFractionSharedTPCClusters();
517     fHybridESDtrackCuts->GetMainCuts()->SetMaxFractionSharedTPCClusters(999.);
518     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxFractionSharedTPCClusters(999.);
519
520     trackType = fHybridESDtrackCuts->AcceptTrack(track);
521     if (trackType)
522       FillCutHistogram("hCutsSharedTPC", SharedTPCClusters, pT, eta, phi, trackType-1);
523
524     fHybridESDtrackCuts->GetMainCuts()->SetMaxFractionSharedTPCClusters(maxSharedTPC);
525     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxFractionSharedTPCClusters(maxSharedTPC_Additional);
526
527     // ################################################################
528     // ################################################################
529     Bool_t reqTPCRefit = fHybridESDtrackCuts->GetMainCuts()->GetRequireTPCRefit();
530     Bool_t reqTPCRefit_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetRequireTPCRefit();
531
532     fHybridESDtrackCuts->GetMainCuts()->SetRequireTPCRefit(1);
533     fHybridESDtrackCuts->GetAdditionalCuts()->SetRequireTPCRefit(1);
534     trackType = fHybridESDtrackCuts->AcceptTrack(track);
535     if (trackType)
536       FillCutHistogram("hCutsTPCRefit", 1, pT, eta, phi, trackType-1);
537     else // track is not accepted as global hybrid with TPC refit requirement
538     {
539       fHybridESDtrackCuts->GetMainCuts()->SetRequireTPCRefit(0);
540       fHybridESDtrackCuts->GetAdditionalCuts()->SetRequireTPCRefit(0);
541       trackType = fHybridESDtrackCuts->AcceptTrack(track);
542       if (trackType)
543         FillCutHistogram("hCutsTPCRefit", 0, pT, eta, phi, trackType-1);
544     }
545     fHybridESDtrackCuts->GetMainCuts()->SetRequireTPCRefit(reqTPCRefit);
546     fHybridESDtrackCuts->GetAdditionalCuts()->SetRequireTPCRefit(reqTPCRefit_Additional);
547
548     // ################################################################
549     // ################################################################
550     Float_t maxChi2ITS = fHybridESDtrackCuts->GetMainCuts()->GetMaxChi2PerClusterITS();
551     Float_t maxChi2ITS_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMaxChi2PerClusterITS();
552     fHybridESDtrackCuts->GetMainCuts()->SetMaxChi2PerClusterITS(999.);
553     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxChi2PerClusterITS(999.);
554
555     trackType = fHybridESDtrackCuts->AcceptTrack(track);
556     if (trackType)
557       FillCutHistogram("hCutsChi2ITS", chi2ITS, pT, eta, phi, trackType-1);
558
559     fHybridESDtrackCuts->GetMainCuts()->SetMaxChi2PerClusterITS(maxChi2ITS);
560     fHybridESDtrackCuts->GetAdditionalCuts()->SetMaxChi2PerClusterITS(maxChi2ITS_Additional);
561
562     // ################################################################
563     // ################################################################
564     Float_t minTpcLength = fHybridESDtrackCuts->GetMainCuts()->GetMinLengthActiveVolumeTPC(); // Active length TPC
565     Float_t minTpcLength_Additional = fHybridESDtrackCuts->GetAdditionalCuts()->GetMinLengthActiveVolumeTPC();
566     fHybridESDtrackCuts->GetMainCuts()->SetMinLengthActiveVolumeTPC(0);
567     fHybridESDtrackCuts->GetAdditionalCuts()->SetMinLengthActiveVolumeTPC(0);
568
569     trackType = fHybridESDtrackCuts->AcceptTrack(track);
570     if (trackType)
571       FillCutHistogram("hCutsTPCLength", tpcLength, pT, eta, phi, trackType-1);
572
573     fHybridESDtrackCuts->GetMainCuts()->SetMinLengthActiveVolumeTPC(minTpcLength);
574     fHybridESDtrackCuts->GetAdditionalCuts()->SetMinLengthActiveVolumeTPC(minTpcLength_Additional);
575
576     // ################################################################
577     // ################################################################
578
579     if(!fIsPA)
580     {
581       trackType = fHybridESDtrackCuts->AcceptTrack(track);
582       if (trackType)
583         FillCutHistogram("hCutsClustersPtDependence", 1, pT, eta, phi, trackType-1);
584
585       trackType = fHybridESDtrackCuts_noPtDep->AcceptTrack(track);
586       if (trackType)
587         FillCutHistogram("hCutsClustersPtDependence", 0, pT, eta, phi, trackType-1);
588     }
589     // ################################################################
590     // ################################################################
591     if((fHybridESDtrackCuts->GetMainCuts()->GetClusterRequirementITS(AliESDtrackCuts::kSPD) == AliESDtrackCuts::kOff)
592     || (fHybridESDtrackCuts->GetAdditionalCuts() && (fHybridESDtrackCuts->GetAdditionalCuts()->GetClusterRequirementITS(AliESDtrackCuts::kSPD) == AliESDtrackCuts::kOff))) 
593     {
594       Bool_t isConstrainedWithITSRefit = static_cast<Bool_t>(track->GetConstrainedParam()) && ((track->GetStatus())&AliESDtrack::kITSrefit);
595       if (trackType)
596         FillCutHistogram("hCutsTrackConstrained", isConstrainedWithITSRefit, pT, eta, phi, trackType-1);
597     }
598   }
599
600   SetCurrentOutputList(0);
601 }
602
603
604 //________________________________________________________________________
605 Double_t AliAnalysisTaskChargedJetsPA::GetExternalRho()
606 {
607   // Get rho from event.
608   AliRhoParameter *rho = 0;
609   if (!fRhoTaskName.IsNull()) {
610     rho = dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(fRhoTaskName.Data()));
611     if (!rho) {
612       AliWarning(Form("%s: Could not retrieve rho with name %s!", GetName(), fRhoTaskName.Data())); 
613       return 0;
614     }
615   }
616   else
617     return 0;
618
619   return (rho->GetVal());
620 }
621
622 //________________________________________________________________________
623 inline Bool_t AliAnalysisTaskChargedJetsPA::IsEventInAcceptance(AliVEvent* event)
624 {
625   if (!event)
626     return kFALSE;
627
628   FillHistogram("hEventAcceptance", 0.5); // number of events before manual cuts
629   if(fUsePileUpCut)
630     if(fHelperClass->IsPileUpEvent(event))
631       return kFALSE;
632
633   FillHistogram("hEventAcceptance", 1.5); // number of events after pileup cuts
634
635   fPrimaryVertex = event->GetPrimaryVertex();
636
637   FillHistogram("hVertexZBeforeVertexCut",fPrimaryVertex->GetZ());
638
639   if(fUseDefaultVertexCut)
640   {
641     if(!fHelperClass->IsVertexSelected2013pA(event))
642       return kFALSE;
643   }
644   else // Failsafe vertex cut
645   {
646     if(!fPrimaryVertex || (TMath::Abs(fPrimaryVertex->GetZ()) > 10.0) || (fPrimaryVertex->GetNContributors()<1)) 
647       return kFALSE;
648   }
649
650
651   FillHistogram("hVertexZAfterVertexCut",fPrimaryVertex->GetZ());
652
653   FillHistogram("hEventAcceptance", 2.5); // number of events after vertex cut
654
655   return kTRUE;
656 }
657
658 //________________________________________________________________________
659 inline Bool_t AliAnalysisTaskChargedJetsPA::IsTrackInAcceptance(AliVParticle* track)
660 {
661   FillHistogram("hTrackAcceptance", 0.5);
662   if (track != 0)
663   {
664     if ((track->Eta() < fMaxEta) && (track->Eta() >= fMinEta))
665     {
666       FillHistogram("hTrackAcceptance", 1.5);
667       if (track->Pt() >= fMinTrackPt)
668       {
669         FillHistogram("hTrackAcceptance", 2.5);
670         return kTRUE;
671       }
672     }
673   }
674   return kFALSE;
675 }
676
677 //________________________________________________________________________
678 inline Bool_t AliAnalysisTaskChargedJetsPA::IsBackgroundJetInAcceptance(AliEmcalJet *jet)
679 {   
680   if (jet != 0)
681     if ((jet->Eta() >= fMinJetEta) && (jet->Eta() < fMaxJetEta))
682       if (jet->Pt() >= fMinBackgroundJetPt)
683         return kTRUE;
684
685   return kFALSE;
686 }
687
688 //________________________________________________________________________
689 inline Bool_t AliAnalysisTaskChargedJetsPA::IsSignalJetInAcceptance(AliEmcalJet *jet, Bool_t usePtCut)
690 {
691   Bool_t acceptedWithPtCut = kFALSE;
692   Bool_t acceptedWithoutPtCut = kFALSE;
693
694   FillHistogram("hJetAcceptance", 0.5);
695   if (jet != 0)
696     if ((jet->Eta() >= fMinJetEta) && (jet->Eta() < fMaxJetEta))
697     {
698       FillHistogram("hJetAcceptance", 1.5);
699       if (jet->Pt() >= fMinJetPt) // jet fulfills pt cut
700       {
701         FillHistogram("hJetAcceptance", 2.5);
702         if (jet->Area() >= fMinJetArea)
703         {
704           FillHistogram("hJetAcceptance", 3.5);
705           acceptedWithPtCut = kTRUE;
706         }
707       }
708       else if(!usePtCut) // jet does not fulfill pt cut
709       {
710         if (jet->Area() >= fMinJetArea)
711           acceptedWithoutPtCut = kTRUE;
712       }
713     }
714
715   if(usePtCut)
716     return (acceptedWithPtCut);
717   else
718     return (acceptedWithPtCut || acceptedWithoutPtCut);
719 }
720
721 //________________________________________________________________________
722 void AliAnalysisTaskChargedJetsPA::ExecOnce()
723 {
724   #ifdef DEBUGMODE
725     AliInfo("Starting ExecOnce.");
726   #endif
727   fInitialized = kTRUE;
728
729   // Check for track array
730   if (strcmp(fTrackArrayName.Data(), "") != 0)
731   {
732     fTrackArray = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTrackArrayName.Data()));
733     if (!fTrackArray) 
734       AliWarning(Form("%s: Could not retrieve tracks %s!", GetName(), fTrackArrayName.Data())); 
735     else
736     {
737       TClass *cl = fTrackArray->GetClass();
738       if (!cl->GetBaseClass("AliVParticle"))
739       {
740         AliError(Form("%s: Collection %s does not contain AliVParticle objects!", GetName(), fTrackArrayName.Data())); 
741         fTrackArray = 0;
742       }
743     }
744   }
745
746   // Check for jet array
747   if (strcmp(fJetArrayName.Data(), "") != 0)
748   {
749     fJetArray = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fJetArrayName.Data()));
750     if (!fJetArray) 
751       AliWarning(Form("%s: Could not retrieve jets %s!", GetName(), fJetArrayName.Data())); 
752     else
753     {
754       if (!fJetArray->GetClass()->GetBaseClass("AliEmcalJet")) 
755       {
756         AliError(Form("%s: Collection %s does not contain AliEmcalJet objects!", GetName(), fJetArrayName.Data())); 
757         fJetArray = 0;
758       }
759     }
760   }
761
762   // Check for background object
763   if (strcmp(fBackgroundJetArrayName.Data(), "") != 0)
764   {
765     fBackgroundJetArray = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fBackgroundJetArrayName.Data()));
766     if (!fBackgroundJetArray)
767       AliInfo(Form("%s: Could not retrieve background jets %s!", GetName(), fBackgroundJetArrayName.Data())); 
768   }
769
770   // Initialize helper class (for vertex selection & pile up correction)
771   fHelperClass = new AliAnalysisUtils();
772   fHelperClass->SetCutOnZVertexSPD(kFALSE);
773   // Histogram init
774   Init();
775   // Trackcut initialization
776   InitializeTrackcuts();
777
778   #ifdef DEBUGMODE
779     AliInfo("ExecOnce done.");
780   #endif
781
782 }
783
784 //________________________________________________________________________
785 void AliAnalysisTaskChargedJetsPA::GetLeadingJets()
786 {
787   // Reset vars
788   fFirstLeadingJet = NULL;
789   fSecondLeadingJet = NULL;
790   fFirstLeadingKTJet = NULL;
791   fSecondLeadingKTJet = NULL;
792
793   fNumberSignalJets = 0;
794   fNumberSignalJetsAbove5GeV = 0;
795
796   Int_t jetIDArray[]   = {-1, -1};
797   Float_t maxJetPts[] = {0, 0};
798   jetIDArray[0] = -1;
799   jetIDArray[1] = -1;
800
801   Int_t jetIDArrayKT[]   = {-1, -1};
802   Float_t maxJetPtsKT[] = {0, 0};
803   jetIDArrayKT[0] = -1;
804   jetIDArrayKT[1] = -1;
805
806   // Find leading signal jets
807   for (Int_t i = 0; i < fJetArray->GetEntries(); i++)
808   {
809     AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJetArray->At(i));
810     if (!jet) 
811     {
812       AliError(Form("%s: Could not receive jet %d", GetName(), i));
813       continue;
814     }
815
816     if (!IsSignalJetInAcceptance(jet)) continue;
817
818     if (jet->Pt() > maxJetPts[0]) 
819     {
820       maxJetPts[1] = maxJetPts[0];
821       jetIDArray[1] = jetIDArray[0];
822       maxJetPts[0] = jet->Pt();
823       jetIDArray[0] = i;
824     }
825     else if (jet->Pt() > maxJetPts[1]) 
826     {
827       maxJetPts[1] = jet->Pt();
828       jetIDArray[1] = i;
829     }
830     fNumberSignalJets++;
831     if(jet->Pt() >= 5.)
832       fNumberSignalJetsAbove5GeV++;
833   }
834
835   // Find leading background jets
836   for (Int_t i = 0; i < fBackgroundJetArray->GetEntries(); i++)
837   {
838     AliEmcalJet* jet = static_cast<AliEmcalJet*>(fBackgroundJetArray->At(i));
839     if (!jet) 
840     {
841       AliError(Form("%s: Could not receive jet %d", GetName(), i));
842       continue;
843     }
844
845     if (!IsBackgroundJetInAcceptance(jet)) continue;
846
847     if (jet->Pt() > maxJetPtsKT[0]) 
848     {
849       maxJetPtsKT[1] = maxJetPtsKT[0];
850       jetIDArrayKT[1] = jetIDArrayKT[0];
851       maxJetPtsKT[0] = jet->Pt();
852       jetIDArrayKT[0] = i;
853     }
854     else if (jet->Pt() > maxJetPtsKT[1]) 
855     {
856       maxJetPtsKT[1] = jet->Pt();
857       jetIDArrayKT[1] = i;
858     }
859   }
860
861   if (jetIDArray[0] > -1)
862     fFirstLeadingJet  = static_cast<AliEmcalJet*>(fJetArray->At(jetIDArray[0]));
863   if (jetIDArray[1] > -1)
864     fSecondLeadingJet = static_cast<AliEmcalJet*>(fJetArray->At(jetIDArray[1]));
865   if (jetIDArrayKT[0] > -1)
866     fFirstLeadingKTJet  = static_cast<AliEmcalJet*>(fBackgroundJetArray->At(jetIDArrayKT[0]));
867   if (jetIDArrayKT[1] > -1)
868     fSecondLeadingKTJet = static_cast<AliEmcalJet*>(fBackgroundJetArray->At(jetIDArrayKT[1]));
869 }
870
871 //________________________________________________________________________
872 inline Double_t AliAnalysisTaskChargedJetsPA::GetConePt(Double_t eta, Double_t phi, Double_t radius)
873 {
874   Double_t tmpConePt = 0.0;
875
876   for (Int_t i = 0; i < fTrackArray->GetEntries(); i++)
877   {
878     AliVTrack* tmpTrack = static_cast<AliVTrack*>(fTrackArray->At(i));
879     if (IsTrackInAcceptance(tmpTrack))
880       if(IsTrackInCone(tmpTrack, eta, phi, radius))
881         tmpConePt = tmpConePt + tmpTrack->Pt();
882   }
883   return tmpConePt;
884 }
885
886 //________________________________________________________________________
887 inline Double_t AliAnalysisTaskChargedJetsPA::GetCorrectedConePt(Double_t eta, Double_t phi, Double_t radius, Double_t background)
888 {
889   Double_t tmpConePt = 0.0;
890
891   for (Int_t i = 0; i < fTrackArray->GetEntries(); i++)
892   {
893     AliVTrack* tmpTrack = static_cast<AliVTrack*>(fTrackArray->At(i));
894     if (IsTrackInAcceptance(tmpTrack))
895       if(IsTrackInCone(tmpTrack, eta, phi, radius))
896         tmpConePt = tmpConePt + tmpTrack->Pt();
897   }
898   Double_t realConeArea = (1.0*(fMaxEta-fMinEta)) * TMath::TwoPi() * MCGetOverlapCircleRectancle(eta, phi, radius, fMinEta, fMaxEta, 0., TMath::TwoPi());
899   tmpConePt -= background * realConeArea; // subtract background
900
901   return tmpConePt;
902 }
903
904 //________________________________________________________________________
905 inline Bool_t AliAnalysisTaskChargedJetsPA::IsTrackInCone(AliVTrack* track, Double_t eta, Double_t phi, Double_t radius)
906 {
907   // This is to use a full cone in phi even at the edges of phi (2pi -> 0) (0 -> 2pi)
908   Double_t trackPhi = 0.0;
909   if (track->Phi() > (TMath::TwoPi() - (radius-phi)))
910     trackPhi = track->Phi() - TMath::TwoPi();
911   else if (track->Phi() < (phi+radius - TMath::TwoPi()))
912     trackPhi = track->Phi() + TMath::TwoPi();
913   else
914     trackPhi = track->Phi();
915   
916   if ( TMath::Abs(trackPhi-phi)*TMath::Abs(trackPhi-phi) + TMath::Abs(track->Eta()-eta)*TMath::Abs(track->Eta()-eta) <= radius*radius)
917     return kTRUE;
918   
919   return kFALSE;
920 }
921
922 //________________________________________________________________________
923 inline Bool_t AliAnalysisTaskChargedJetsPA::IsTrackInJet(AliEmcalJet* jet, Int_t trackIndex)
924 {
925   for (Int_t i = 0; i < jet->GetNumberOfTracks(); ++i)
926   {
927     Int_t jetTrack = jet->TrackAt(i);
928     if (jetTrack == trackIndex)
929       return kTRUE;
930   }
931   return kFALSE;
932 }
933
934 //________________________________________________________________________
935 inline Bool_t AliAnalysisTaskChargedJetsPA::IsJetOverlapping(AliEmcalJet* jet1, AliEmcalJet* jet2)
936 {
937   for (Int_t i = 0; i < jet1->GetNumberOfTracks(); ++i)
938   {
939     Int_t jet1Track = jet1->TrackAt(i);
940     for (Int_t j = 0; j < jet2->GetNumberOfTracks(); ++j)
941     {
942       Int_t jet2Track = jet2->TrackAt(j);
943       if (jet1Track == jet2Track)
944         return kTRUE;
945     }
946   }
947   return kFALSE;
948 }
949
950 //________________________________________________________________________
951 Double_t AliAnalysisTaskChargedJetsPA::GetCorrectedJetPt(AliEmcalJet* jet, Double_t background)
952 {
953   #ifdef DEBUGMODE
954     AliInfo("Getting corrected jet spectra.");
955   #endif
956
957   Double_t correctedPt = -1.0;
958   // if the passed background is not valid, do not subtract it
959   if(background < 0)
960     background = 0;
961
962   // Subtract background
963   correctedPt = jet->Pt() - background * jet->Area();
964
965   #ifdef DEBUGMODE
966     AliInfo("Got corrected jet spectra.");
967   #endif 
968
969   return correctedPt;
970 }
971
972
973
974 //________________________________________________________________________
975 Double_t AliAnalysisTaskChargedJetsPA::GetDeltaPt(Double_t rho, Double_t leadingJetExclusionProbability)
976 {
977   #ifdef DEBUGMODE
978     AliInfo("Getting Delta Pt.");
979   #endif
980
981   // Define an invalid delta pt
982   Double_t deltaPt = -10000.0;
983
984   // Define eta range
985   Double_t etaMin, etaMax;
986   etaMin = fMinEta+fRandConeRadius;
987   etaMax = fMaxEta-fRandConeRadius;
988
989   // Define random cone
990   Bool_t coneValid = kTRUE;
991   Double_t tmpRandConeEta = etaMin + fRandom->Rndm()*(etaMax-etaMin);
992   Double_t tmpRandConePhi = fRandom->Rndm()*TMath::TwoPi();
993
994   // if there is a jet, check for overlap if demanded
995   if(leadingJetExclusionProbability)
996   {
997     AliEmcalJet* tmpLeading = dynamic_cast<AliEmcalJet*>(fJetArray->At(0));
998     // Get leading jet (regardless of pT)
999     for (Int_t i = 1; i<fJetArray->GetEntries(); i++)
1000     {
1001       AliEmcalJet* tmpJet = static_cast<AliEmcalJet*>(fJetArray->At(i));
1002       // if jet is in acceptance and higher, take as new leading
1003       if (tmpJet)
1004         if ( ((tmpJet->Eta() >= fMinJetEta) && (tmpJet->Eta() < fMaxJetEta)) && (tmpJet->Area() >= fMinJetArea))
1005           if((!tmpLeading) || (tmpJet->Pt() > tmpLeading->Pt()))
1006             tmpLeading = tmpJet;
1007     }
1008     if(tmpLeading)
1009     {
1010       Double_t excludedJetPhi = tmpLeading->Phi();
1011       Double_t excludedJetEta = tmpLeading->Eta();
1012       Double_t tmpDeltaPhi = GetDeltaPhi(tmpRandConePhi, excludedJetPhi);
1013
1014       // Check, if cone has overlap with jet
1015       if ( tmpDeltaPhi*tmpDeltaPhi + TMath::Abs(tmpRandConeEta-excludedJetEta)*TMath::Abs(tmpRandConeEta-excludedJetEta) <= fRandConeRadius*fRandConeRadius)
1016       {
1017         // Define probability to exclude the RC
1018         Double_t probability = leadingJetExclusionProbability;
1019
1020         // Only exclude cone with a given probability
1021         if (fRandom->Rndm()<=probability)
1022           coneValid = kFALSE;
1023       }
1024     }
1025   }
1026
1027   // Get the cones' pt and calculate delta pt
1028   if (coneValid)
1029     deltaPt = GetConePt(tmpRandConeEta,tmpRandConePhi,fRandConeRadius) - (rho*fRandConeRadius*fRandConeRadius*TMath::Pi());
1030
1031   return deltaPt;
1032   #ifdef DEBUGMODE
1033     AliInfo("Got Delta Pt.");
1034   #endif
1035 }
1036
1037 //________________________________________________________________________
1038 void AliAnalysisTaskChargedJetsPA::GetKTBackgroundDensityAll(Int_t numberExcludeLeadingJets, Double_t& rhoPbPb, Double_t& rhoPbPbWithGhosts, Double_t& rhoCMS, Double_t& rhoImprovedCMS, Double_t& rhoMean, Double_t& rhoTrackLike)
1039 {
1040   #ifdef DEBUGMODE
1041     AliInfo("Getting ALL KT background density.");
1042   #endif
1043
1044   static Double_t tmpRhoPbPb[1024];
1045   static Double_t tmpRhoPbPbWithGhosts[1024];
1046   static Double_t tmpRhoMean[1024];
1047   static Double_t tmpRhoCMS[1024];
1048   static Double_t tmpRhoImprovedCMS[1024];
1049   Double_t tmpCoveredArea = 0.0;
1050   Double_t tmpSummedArea = 0.0;
1051   Double_t tmpPtTrackLike = 0.0;
1052   Double_t tmpAreaTrackLike = 0.0;
1053
1054   // Setting invalid values
1055   rhoPbPb = 0.0;
1056   rhoPbPbWithGhosts = 0.0;
1057   rhoCMS = 0.0;
1058   rhoImprovedCMS = 0.0;
1059   rhoMean = 0.0;
1060   rhoTrackLike = 0.0;
1061
1062   Int_t rhoPbPbJetCount = 0;
1063   Int_t rhoPbPbWithGhostsJetCount = 0;
1064   Int_t rhoCMSJetCount = 0;
1065   Int_t rhoImprovedCMSJetCount = 0;
1066   Int_t rhoMeanJetCount = 0;
1067
1068
1069   // Exclude UP TO numberExcludeLeadingJets
1070   if(numberExcludeLeadingJets==-1)
1071     numberExcludeLeadingJets = fNumberSignalJets;
1072   if (fNumberSignalJets < numberExcludeLeadingJets)
1073     numberExcludeLeadingJets = fNumberSignalJets;
1074
1075   for (Int_t i = 0; i < fBackgroundJetArray->GetEntries(); i++)
1076   {
1077     AliEmcalJet* backgroundJet = static_cast<AliEmcalJet*>(fBackgroundJetArray->At(i));
1078
1079     if (!backgroundJet)
1080     {
1081       AliError(Form("%s: Could not receive jet %d", GetName(), i));
1082       continue;
1083     } 
1084
1085     tmpSummedArea += backgroundJet->Area();
1086     if(backgroundJet->Pt() > 0.150)
1087       tmpCoveredArea += backgroundJet->Area();
1088
1089     if (!IsBackgroundJetInAcceptance(backgroundJet))
1090       continue;
1091
1092     // Search for overlap with signal jets
1093     Bool_t isOverlapping = kFALSE;
1094     for(Int_t j=0;j<numberExcludeLeadingJets;j++)
1095     {
1096       AliEmcalJet* signalJet = fFirstLeadingJet;
1097       if(j==1)
1098         signalJet = fSecondLeadingJet;
1099
1100       if(signalJet->Pt() < 5.0)
1101           continue;
1102
1103       if(IsJetOverlapping(signalJet, backgroundJet))
1104       {
1105         isOverlapping = kTRUE;
1106         break;
1107       }
1108     }
1109
1110     Double_t tmpRho = 0.0;
1111     if(backgroundJet->Area())
1112       tmpRho = backgroundJet->Pt() / backgroundJet->Area();
1113
1114     // PbPb approach (take ghosts into account)
1115     if((backgroundJet != fFirstLeadingKTJet) || (backgroundJet != fSecondLeadingKTJet))
1116     {
1117       tmpRhoPbPbWithGhosts[rhoPbPbWithGhostsJetCount] = tmpRho;
1118       rhoPbPbWithGhostsJetCount++;
1119     }
1120
1121     if(backgroundJet->Pt() > 0.150)
1122     {
1123       // CMS approach: don't take ghosts into acount
1124       tmpRhoCMS[rhoCMSJetCount] = tmpRho;
1125       rhoCMSJetCount++;
1126
1127       // Improved CMS approach: like CMS but excluding signal
1128       if((backgroundJet != fFirstLeadingKTJet) || (backgroundJet != fSecondLeadingKTJet))
1129       {
1130         tmpRhoImprovedCMS[rhoImprovedCMSJetCount] = tmpRho;
1131         rhoImprovedCMSJetCount++;
1132       }
1133
1134       // PbPb w/o ghosts approach (just neglect ghosts)
1135       if((backgroundJet != fFirstLeadingKTJet) || (backgroundJet != fSecondLeadingKTJet))
1136       {  
1137         tmpRhoPbPb[rhoPbPbJetCount] = tmpRho;
1138         rhoPbPbJetCount++;
1139       }
1140     }
1141
1142     // (no overlap with signal jets)
1143     if(!isOverlapping)
1144     {
1145       // Mean approach
1146       tmpRhoMean[rhoMeanJetCount] = tmpRho;
1147       rhoMeanJetCount++;
1148       
1149       // Track like approach approach
1150       tmpPtTrackLike += backgroundJet->Pt();
1151       tmpAreaTrackLike += backgroundJet->Area();
1152     }
1153
1154   }
1155
1156   if (tmpAreaTrackLike > 0)
1157     rhoTrackLike = tmpPtTrackLike/tmpAreaTrackLike;
1158   if (rhoPbPbJetCount > 0)
1159     rhoPbPb = TMath::Median(rhoPbPbJetCount, tmpRhoPbPb);
1160   if (rhoPbPbWithGhostsJetCount > 0)
1161     rhoPbPbWithGhosts = TMath::Median(rhoPbPbWithGhostsJetCount, tmpRhoPbPbWithGhosts);
1162   if (rhoCMSJetCount > 0)
1163     rhoCMS = TMath::Median(rhoCMSJetCount, tmpRhoCMS) * tmpCoveredArea/tmpSummedArea;
1164   if (rhoImprovedCMSJetCount > 0)
1165   {
1166     rhoImprovedCMS = TMath::Median(rhoImprovedCMSJetCount, tmpRhoImprovedCMS) * tmpCoveredArea/tmpSummedArea;
1167   }
1168   if (rhoMeanJetCount > 0)
1169     rhoMean = TMath::Mean(rhoMeanJetCount, tmpRhoMean);
1170
1171   #ifdef DEBUGMODE
1172     AliInfo("Got ALL KT background density.");
1173   #endif
1174 }
1175
1176 //________________________________________________________________________
1177 void AliAnalysisTaskChargedJetsPA::GetTRBackgroundDensity(Int_t numberExcludeLeadingJets, Double_t& rhoNoExclusion, Double_t& rhoConeExclusion02, Double_t& rhoConeExclusion04, Double_t& rhoConeExclusion06, Double_t& rhoConeExclusion08, Double_t& rhoExactExclusion)
1178 {
1179   #ifdef DEBUGMODE
1180     AliInfo("Getting TR background density.");
1181   #endif
1182
1183   Double_t summedTracksPtCone04 = 0.0;
1184   Double_t summedTracksPtCone02 = 0.0;
1185   Double_t summedTracksPtCone06 = 0.0;
1186   Double_t summedTracksPtCone08 = 0.0;
1187   Double_t summedTracksPtWithinJets = 0.0;
1188   Double_t summedTracksPt = 0.0;
1189   
1190   // Setting invalid values
1191   rhoNoExclusion = 0.0;
1192   rhoConeExclusion02 = 0.0;
1193   rhoConeExclusion04 = 0.0;
1194   rhoConeExclusion06 = 0.0;
1195   rhoConeExclusion08 = 0.0; 
1196   rhoExactExclusion  = 0.0;
1197
1198   // Exclude UP TO numberExcludeLeadingJets
1199   if(numberExcludeLeadingJets==-1)
1200     numberExcludeLeadingJets = fNumberSignalJetsAbove5GeV;
1201   if (fNumberSignalJets < numberExcludeLeadingJets)
1202     numberExcludeLeadingJets = fNumberSignalJetsAbove5GeV;
1203   if(numberExcludeLeadingJets>2)
1204   {
1205     AliWarning("Warning: GetTRBackgroundDensity() can only exclude up to 2 leading jets!");
1206     numberExcludeLeadingJets = 2;
1207   }
1208
1209   for (Int_t i = 0; i < fTrackArray->GetEntries(); i++)
1210   {
1211     AliVTrack* tmpTrack = static_cast<AliVTrack*>(fTrackArray->At(i));
1212     Bool_t trackWithinJet = kFALSE; Bool_t trackWithin02Cone = kFALSE; Bool_t trackWithin04Cone = kFALSE; Bool_t trackWithin06Cone = kFALSE; Bool_t trackWithin08Cone = kFALSE;
1213
1214     if (IsTrackInAcceptance(tmpTrack))
1215     {
1216       // Check if tracks overlaps with jet
1217       for(Int_t j=0;j<numberExcludeLeadingJets;j++)
1218       {
1219         AliEmcalJet* signalJet = fFirstLeadingJet;
1220         if(j==1)
1221           signalJet = fSecondLeadingJet;
1222
1223         if(signalJet->Pt() < 5.0)
1224           continue;
1225
1226         // Exact jet exclusion
1227         if (IsTrackInJet(signalJet, i))
1228           trackWithinJet = kTRUE;
1229
1230         // Cone exclusions
1231         if (IsTrackInCone(tmpTrack, signalJet->Eta(), signalJet->Phi(), 0.2))
1232         {
1233           trackWithin02Cone = kTRUE;
1234           trackWithin04Cone = kTRUE;
1235           trackWithin06Cone = kTRUE;
1236           trackWithin08Cone = kTRUE;
1237           break;
1238         }
1239         else if (IsTrackInCone(tmpTrack, signalJet->Eta(), signalJet->Phi(), 0.4))
1240         {
1241           trackWithin04Cone = kTRUE;
1242           trackWithin06Cone = kTRUE;
1243           trackWithin08Cone = kTRUE;
1244         }
1245         else if (IsTrackInCone(tmpTrack, signalJet->Eta(), signalJet->Phi(), 0.6))
1246         {
1247           trackWithin06Cone = kTRUE;
1248           trackWithin08Cone = kTRUE;
1249         }
1250         else if (IsTrackInCone(tmpTrack, signalJet->Eta(), signalJet->Phi(), 0.8))
1251         {
1252           trackWithin08Cone = kTRUE;
1253         }
1254       }
1255
1256       if(!trackWithin08Cone)
1257       {
1258         summedTracksPtCone08 += tmpTrack->Pt();
1259       }
1260       if(!trackWithin06Cone)
1261       {
1262         summedTracksPtCone06 += tmpTrack->Pt();
1263       }
1264       if(!trackWithin04Cone)
1265       {
1266         summedTracksPtCone04 += tmpTrack->Pt();
1267       }
1268       if(!trackWithin02Cone)
1269       {
1270         summedTracksPtCone02 += tmpTrack->Pt();
1271       }
1272       if(!trackWithinJet)
1273       {
1274         summedTracksPtWithinJets += tmpTrack->Pt();
1275       }
1276       summedTracksPt += tmpTrack->Pt();
1277
1278     }
1279   }
1280
1281   // Calculate the correct area where the tracks were taking from
1282
1283   Double_t tmpFullTPCArea = (1.0*(fMaxEta-fMinEta)) * TMath::TwoPi();
1284   Double_t tmpAreaCone02     = tmpFullTPCArea;
1285   Double_t tmpAreaCone04     = tmpFullTPCArea;
1286   Double_t tmpAreaCone06     = tmpFullTPCArea;
1287   Double_t tmpAreaCone08     = tmpFullTPCArea;
1288   Double_t tmpAreaWithinJets = tmpFullTPCArea;
1289   std::vector<Double_t> tmpEtas(fNumberSignalJetsAbove5GeV);
1290   std::vector<Double_t> tmpPhis(fNumberSignalJetsAbove5GeV);
1291
1292   Int_t iSignal = 0;
1293   for(Int_t i=0;i<numberExcludeLeadingJets;i++)
1294   {
1295     AliEmcalJet* signalJet = fFirstLeadingJet;
1296     if(i==1)
1297       signalJet = fSecondLeadingJet;
1298
1299     if(signalJet->Pt() < 5.0)
1300       continue;
1301
1302     tmpEtas[iSignal] = signalJet->Eta();
1303     tmpPhis[iSignal] = signalJet->Phi();
1304     tmpAreaWithinJets -= signalJet->Area();
1305
1306     iSignal++;
1307   }
1308
1309   tmpAreaCone02 -= tmpFullTPCArea * MCGetOverlapMultipleCirclesRectancle(fNumberSignalJetsAbove5GeV, tmpEtas, tmpPhis, 0.2, fMinEta, fMaxEta, 0., TMath::TwoPi());
1310   tmpAreaCone04 -= tmpFullTPCArea * MCGetOverlapMultipleCirclesRectancle(fNumberSignalJetsAbove5GeV, tmpEtas, tmpPhis, 0.4, fMinEta, fMaxEta, 0., TMath::TwoPi());
1311   tmpAreaCone06 -= tmpFullTPCArea * MCGetOverlapMultipleCirclesRectancle(fNumberSignalJetsAbove5GeV, tmpEtas, tmpPhis, 0.6, fMinEta, fMaxEta, 0., TMath::TwoPi());
1312   tmpAreaCone08 -= tmpFullTPCArea * MCGetOverlapMultipleCirclesRectancle(fNumberSignalJetsAbove5GeV, tmpEtas, tmpPhis, 0.8, fMinEta, fMaxEta, 0., TMath::TwoPi());
1313  
1314   rhoConeExclusion02 = summedTracksPtCone02/tmpAreaCone02;
1315   rhoConeExclusion04 = summedTracksPtCone04/tmpAreaCone04;
1316   rhoConeExclusion06 = summedTracksPtCone06/tmpAreaCone06;
1317   rhoConeExclusion08 = summedTracksPtCone08/tmpAreaCone08;
1318   rhoExactExclusion  = summedTracksPtWithinJets/tmpAreaWithinJets;
1319   rhoNoExclusion     = summedTracksPt/tmpFullTPCArea;
1320
1321
1322   #ifdef DEBUGMODE
1323     AliInfo("Got TR background density.");
1324   #endif
1325 }
1326
1327 //________________________________________________________________________
1328 void AliAnalysisTaskChargedJetsPA::GetPPBackgroundDensity(Double_t& background)
1329 {
1330   // This is the background that was used for the pp 7 TeV ALICE paper
1331   // The background is estimated using the leading jet
1332
1333   background = 0;
1334
1335   AliEmcalJet* jet = NULL;
1336   if(fFirstLeadingJet)
1337     jet = fFirstLeadingJet;
1338   else
1339     return;
1340
1341   Double_t jetMom[3] = { jet->Px(), jet->Py(), jet->Pz() };
1342   TVector3 jet3mom1(jetMom);
1343   TVector3 jet3mom2(jetMom);
1344
1345   jet3mom1.RotateZ(TMath::Pi());
1346   jet3mom2.RotateZ(-TMath::Pi());
1347
1348   for (int i = 0; i < fTrackArray->GetEntries(); i++)
1349   {
1350     AliVTrack* track = static_cast<AliVTrack*>(fTrackArray->At(i));
1351     if (!IsTrackInAcceptance(track))
1352       continue;
1353
1354     Double_t trackMom[3] = { track->Px(), track->Py(), track->Pz() };
1355     TVector3 track3mom(trackMom);
1356
1357     Double_t dR1 = jet3mom1.DeltaR(track3mom);
1358     Double_t dR2 = jet3mom2.DeltaR(track3mom);
1359
1360     if (dR1 <= fSignalJetRadius || dR2 <= fSignalJetRadius)
1361       background += track3mom.Pt();
1362   }
1363
1364   background /= (2 * TMath::Pi() * fSignalJetRadius * fSignalJetRadius);
1365 }
1366
1367 //________________________________________________________________________
1368 void AliAnalysisTaskChargedJetsPA::Calculate(AliVEvent* event)
1369 {
1370   #ifdef DEBUGMODE
1371     AliInfo("Starting Calculate().");
1372   #endif
1373   ////////////////////// NOTE: initialization & casting
1374
1375   fEventCounter++;
1376
1377   // This is to take only every Nth event
1378   if((fEventCounter+fPartialAnalysisIndex) % fPartialAnalysisNParts != 0)
1379     return;
1380
1381   FillHistogram("hNumberEvents",0.5);
1382
1383   if(!IsEventInAcceptance(event))
1384     return;
1385
1386   FillHistogram("hNumberEvents",1.5);
1387
1388   #ifdef DEBUGMODE
1389     AliInfo("Calculate()::Init done.");
1390   #endif
1391
1392   ////////////////////// NOTE: Create cut histograms
1393
1394   if(fAnalyzeTrackcuts)
1395     CreateCutHistograms();
1396
1397   ////////////////////// NOTE: Get Centrality, (Leading)Signal jets and Background
1398
1399   // Get centrality
1400   AliCentrality* tmpCentrality = NULL;
1401   tmpCentrality = event->GetCentrality();
1402   Double_t centralityPercentile = -1.0;
1403   Double_t centralityPercentileV0A = 0.0;
1404   Double_t centralityPercentileV0C = 0.0;
1405   Double_t centralityPercentileV0M = 0.0;
1406   Double_t centralityPercentileZNA = 0.0;
1407   if (tmpCentrality != NULL)
1408   {
1409     centralityPercentile = tmpCentrality->GetCentralityPercentile(fCentralityType.Data());
1410     centralityPercentileV0A = tmpCentrality->GetCentralityPercentile("V0A");
1411     centralityPercentileV0C = tmpCentrality->GetCentralityPercentile("V0C");
1412     centralityPercentileV0M = tmpCentrality->GetCentralityPercentile("V0M");
1413     centralityPercentileZNA = tmpCentrality->GetCentralityPercentile("ZNA");
1414   }
1415
1416   if((centralityPercentile < 0.0) || (centralityPercentile > 100.0))
1417     AliWarning(Form("Centrality value not valid (c=%E)",centralityPercentile)); 
1418
1419   if(fSetCentralityToOne)
1420     centralityPercentile = 1.0;
1421
1422   ////////////////////// NOTE: Get event QA histograms
1423
1424   FillHistogram("hVertexX",fPrimaryVertex->GetX());
1425   FillHistogram("hVertexY",fPrimaryVertex->GetY());
1426   FillHistogram("hVertexXY",fPrimaryVertex->GetX(), fPrimaryVertex->GetY());
1427   FillHistogram("hVertexR",TMath::Sqrt(fPrimaryVertex->GetX()*fPrimaryVertex->GetX() + fPrimaryVertex->GetY()*fPrimaryVertex->GetY()));
1428   FillHistogram("hCentralityV0M",centralityPercentileV0M);
1429   FillHistogram("hCentralityV0A",centralityPercentileV0A);
1430   FillHistogram("hCentralityV0C",centralityPercentileV0C);
1431   FillHistogram("hCentralityZNA",centralityPercentileZNA);
1432   FillHistogram("hCentrality",centralityPercentile);
1433
1434   if(!fDoJetAnalysis)
1435     return;
1436
1437   GetLeadingJets();
1438
1439   // ##################### Calculate background densities
1440   Double_t              backgroundKTImprovedCMS = -1.0;
1441   Double_t              backgroundExternal = -1.0;
1442   Double_t              backgroundKTPbPb = -1.0;
1443   Double_t              backgroundKTPbPbWithGhosts = -1.0;
1444   Double_t              backgroundKTCMS = -1.0;
1445   Double_t              backgroundKTMean = -1.0;
1446   Double_t              backgroundKTTrackLike = -1.0;
1447   Double_t              backgroundTRNoExcl = -1.0;
1448   Double_t              backgroundTRCone02 = -1.0;
1449   Double_t              backgroundTRCone04 = -1.0;
1450   Double_t              backgroundTRCone06 = -1.0;
1451   Double_t              backgroundTRCone08 = -1.0;
1452   Double_t              backgroundTRExact  = -1.0;
1453   Double_t              backgroundPP       = -1.0;
1454   Double_t              backgroundJetProfile = -1.0;
1455
1456   // Get background estimates
1457   GetKTBackgroundDensityAll (fNumberExcludedJets, backgroundKTPbPb, backgroundKTPbPbWithGhosts, backgroundKTCMS, backgroundKTImprovedCMS, backgroundKTMean, backgroundKTTrackLike);
1458   GetTRBackgroundDensity    (fNumberExcludedJets, backgroundTRNoExcl, backgroundTRCone02, backgroundTRCone04, backgroundTRCone06, backgroundTRCone08, backgroundTRExact);
1459   GetPPBackgroundDensity(backgroundPP);
1460
1461   backgroundExternal = GetExternalRho();
1462   if(fNoExternalBackground)
1463     backgroundExternal = 0;
1464
1465   if(fBackgroundForJetProfile==0)
1466     backgroundJetProfile = backgroundExternal;
1467   else if(fBackgroundForJetProfile==1)
1468     backgroundJetProfile = backgroundKTImprovedCMS;
1469   else if(fBackgroundForJetProfile==2)
1470     backgroundJetProfile = backgroundKTCMS;
1471   else if(fBackgroundForJetProfile==3)
1472     backgroundJetProfile = backgroundPP;
1473   else if(fBackgroundForJetProfile==4)
1474     backgroundJetProfile = backgroundTRCone06;
1475   else if(fBackgroundForJetProfile==5)
1476     backgroundJetProfile = 0;
1477
1478   #ifdef DEBUGMODE
1479     AliInfo("Calculate()::Centrality&SignalJets&Background-Calculation done.");
1480   #endif
1481
1482   // ##################### Fill event QA histograms
1483
1484   Int_t trackCountAcc = 0;
1485   Int_t nTracks = fTrackArray->GetEntries();
1486   for (Int_t i = 0; i < nTracks; i++)
1487   {
1488     AliVTrack* track = static_cast<AliVTrack*>(fTrackArray->At(i));
1489
1490     if (track != 0)
1491       if (track->Pt() >= fMinTrackPt)
1492       {
1493         FillHistogram("hTrackPhiEta", track->Phi(),track->Eta(), 1);
1494         FillHistogram("hTrackPtPhiEta", track->Phi(),track->Eta(), track->Pt());
1495       }
1496
1497     if (IsTrackInAcceptance(track))
1498     {
1499       FillHistogram("hTrackPt", track->Pt(), centralityPercentile);
1500       if(track->Eta() >= 0)
1501         FillHistogram("hTrackPtPosEta", track->Pt(), centralityPercentile);
1502       else
1503         FillHistogram("hTrackPtNegEta", track->Pt(), centralityPercentile);
1504               
1505       FillHistogram("hTrackEta", track->Eta(), centralityPercentile);
1506       FillHistogram("hTrackPhi", track->Phi());
1507       
1508       if(static_cast<AliPicoTrack*>(track))
1509         FillHistogram("hTrackPhiTrackType", track->Phi(), (static_cast<AliPicoTrack*>(track))->GetTrackType());
1510
1511       for(Int_t j=0;j<20;j++)
1512         if(track->Pt() > j)
1513           FillHistogram("hTrackPhiPtCut", track->Phi(), track->Pt());
1514
1515       FillHistogram("hTrackCharge", track->Charge());
1516       trackCountAcc++;
1517     }
1518   }
1519   FillHistogram("hTrackCountAcc", trackCountAcc, centralityPercentile);
1520
1521   #ifdef DEBUGMODE
1522     AliInfo("Calculate()::QA done.");
1523   #endif
1524
1525   // ##################### Fill jet histograms
1526
1527   FillHistogram("hJetCountAll", fJetArray->GetEntries());
1528   FillHistogram("hJetCountAccepted", fNumberSignalJets);
1529   FillHistogram("hJetCount", fJetArray->GetEntries(), fNumberSignalJets);
1530   if (fFirstLeadingJet)
1531   {
1532     FillHistogram("hLeadingJetPt", fFirstLeadingJet->Pt());
1533     FillHistogram("hCorrectedLeadingJetPt", GetCorrectedJetPt(fFirstLeadingJet,backgroundExternal));
1534   }
1535   if (fSecondLeadingJet)
1536   {
1537     FillHistogram("hSecondLeadingJetPt", fSecondLeadingJet->Pt());
1538     FillHistogram("hCorrectedSecondLeadingJetPt", GetCorrectedJetPt(fSecondLeadingJet,backgroundExternal));
1539   }
1540
1541   for (Int_t i = 0; i<fJetArray->GetEntries(); i++)
1542   {
1543     AliEmcalJet* tmpJet = static_cast<AliEmcalJet*>(fJetArray->At(i));
1544     if (!tmpJet)
1545       continue;
1546
1547     // ### JETS BEFORE ANY CUTS
1548     if (tmpJet->Area() >= fMinJetArea)
1549       FillHistogram("hRawJetPhiEta", tmpJet->Phi(), tmpJet->Eta());
1550     if ((tmpJet->Eta() >= fMinJetEta) && (tmpJet->Eta() < fMaxJetEta))
1551       FillHistogram("hRawJetArea", tmpJet->Area());
1552
1553     FillHistogram("hJetPtCutStages", tmpJet->Pt(), 0.5);
1554     if ((tmpJet->Eta() >= fMinJetEta) && (tmpJet->Eta() < fMaxJetEta))
1555     {
1556       FillHistogram("hJetPtCutStages", tmpJet->Pt(), 1.5);
1557       if (tmpJet->Pt() >= fMinJetPt)
1558       {
1559         FillHistogram("hJetPtCutStages", tmpJet->Pt(), 2.5);
1560         if (tmpJet->Area() >= fMinJetArea)
1561         {
1562           FillHistogram("hJetPtCutStages", tmpJet->Pt(), 3.5);
1563         }
1564       }
1565     }
1566
1567     // ### JETS AFTER CUTS
1568     if(IsSignalJetInAcceptance(tmpJet))
1569     {
1570       // Background corrected jet spectra
1571       FillHistogram("hJetPtBgrdSubtractedExternal", GetCorrectedJetPt(tmpJet, backgroundExternal), centralityPercentile);
1572       FillHistogram("hJetPtBgrdSubtractedKTImprovedCMS", GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS), centralityPercentile);
1573       FillHistogram("hJetPtBgrdSubtractedPP", GetCorrectedJetPt(tmpJet, backgroundPP), centralityPercentile);
1574       if(tmpJet->Phi() >= TMath::Pi())
1575         FillHistogram("hJetPtBgrdSubtractedExternal_Phi2", GetCorrectedJetPt(tmpJet, backgroundExternal), centralityPercentile);
1576       else          
1577         FillHistogram("hJetPtBgrdSubtractedExternal_Phi1", GetCorrectedJetPt(tmpJet, backgroundExternal), centralityPercentile);
1578       FillHistogram("hJetPtBgrdSubtractedTR", GetCorrectedJetPt(tmpJet, backgroundTRCone06), centralityPercentile);
1579       FillHistogram("hJetPtBgrdSubtractedKTPbPb", GetCorrectedJetPt(tmpJet, backgroundKTPbPb), centralityPercentile);
1580       FillHistogram("hJetPtBgrdSubtractedKTPbPbWithGhosts", GetCorrectedJetPt(tmpJet, backgroundKTPbPbWithGhosts), centralityPercentile);
1581       FillHistogram("hJetPtBgrdSubtractedKTCMS", GetCorrectedJetPt(tmpJet, backgroundKTCMS), centralityPercentile);
1582       FillHistogram("hJetPtBgrdSubtractedKTMean", GetCorrectedJetPt(tmpJet, backgroundKTMean), centralityPercentile);
1583       FillHistogram("hJetPtBgrdSubtractedKTTrackLike", GetCorrectedJetPt(tmpJet, backgroundKTTrackLike), centralityPercentile);
1584
1585       FillHistogram("hJetPtSubtractedRhoExternal", tmpJet->Pt(), centralityPercentile, tmpJet->Pt() - GetCorrectedJetPt(tmpJet, backgroundExternal));
1586       FillHistogram("hJetPtSubtractedRhoKTImprovedCMS", tmpJet->Pt(), centralityPercentile, tmpJet->Pt() - GetCorrectedJetPt(tmpJet, backgroundKTImprovedCMS));
1587       FillHistogram("hJetPtSubtractedRhoPP", tmpJet->Pt(), centralityPercentile, tmpJet->Pt() - GetCorrectedJetPt(tmpJet, backgroundPP));
1588       FillHistogram("hDeltaPtExternalBgrdVsPt", GetDeltaPt(backgroundExternal), GetCorrectedJetPt(tmpJet, backgroundExternal));
1589
1590       FillHistogram("hJetPtVsConstituentCount", tmpJet->Pt(),tmpJet->GetNumberOfTracks());
1591
1592       for(Int_t j=0; j<tmpJet->GetNumberOfTracks(); j++)
1593         FillHistogram("hJetConstituentPtVsJetPt", tmpJet->TrackAt(j, fTrackArray)->Pt(), tmpJet->Pt());
1594
1595       if(tmpJet->Pt() >= 5.0)
1596       {
1597         Double_t lowestTrackPt = 1e99;
1598         Double_t highestTrackPt = 0.0;
1599         for(Int_t j=0; j<tmpJet->GetNumberOfTracks(); j++)
1600         {
1601           FillHistogram("hJetConstituentPt", tmpJet->TrackAt(j, fTrackArray)->Pt(), centralityPercentile);
1602           // Find the lowest pT of a track in the jet
1603           if (tmpJet->TrackAt(j, fTrackArray)->Pt() < lowestTrackPt)
1604             lowestTrackPt = tmpJet->TrackAt(j, fTrackArray)->Pt();
1605           if (tmpJet->TrackAt(j, fTrackArray)->Pt() > highestTrackPt)
1606             highestTrackPt = tmpJet->TrackAt(j, fTrackArray)->Pt();
1607         }
1608         FillHistogram("hJetArea", tmpJet->Area(), tmpJet->Pt());
1609         // Signal jet vs. signal jet - "Combinatorial"
1610         for (Int_t j = 0; j<fJetArray->GetEntries(); j++)
1611         {
1612           AliEmcalJet* tmpJet2 = static_cast<AliEmcalJet*>(fJetArray->At(j));
1613           if (!tmpJet2)
1614             continue;
1615           if(tmpJet2->Pt() >= 5.0)
1616             FillHistogram("hJetDeltaPhi", GetDeltaPhi(tmpJet->Phi(), tmpJet2->Phi()));
1617         }
1618
1619         FillHistogram("hJetPhiEta", tmpJet->Phi(),tmpJet->Eta());
1620         FillHistogram("hJetPtPhiEta", tmpJet->Phi(),tmpJet->Eta(),tmpJet->Pt());
1621         FillHistogram("hJetEta", tmpJet->Eta(), centralityPercentile);
1622
1623         if(lowestTrackPt>=2.0)
1624           FillHistogram("hJetEta2GeVTracks", tmpJet->Eta(), centralityPercentile);
1625         if(lowestTrackPt>=4.0)
1626           FillHistogram("hJetEta4GeVTracks", tmpJet->Eta(), centralityPercentile);
1627       }
1628     }
1629   } // end of jet loop
1630
1631   if(fAnalyzeJetProfile)
1632     CreateJetProfilePlots(backgroundJetProfile);
1633
1634   #ifdef DEBUGMODE
1635     AliInfo("Calculate()::Jets done.");
1636   #endif
1637
1638   // ##################### Fill background plots
1639
1640   FillHistogram("hKTBackgroundExternal", backgroundExternal, centralityPercentile);
1641   if(fFirstLeadingJet && (fFirstLeadingJet->Pt()>=20.))
1642     FillHistogram("hKTBackgroundExternal20GeV", backgroundExternal, centralityPercentile);
1643
1644   FillHistogram("hKTBackgroundImprovedCMS", backgroundKTImprovedCMS, centralityPercentile);
1645   FillHistogram("hPPBackground", backgroundPP, centralityPercentile);
1646   FillHistogram("hKTBackgroundPbPb", backgroundKTPbPb, centralityPercentile);
1647   FillHistogram("hKTBackgroundPbPbWithGhosts", backgroundKTPbPbWithGhosts, centralityPercentile);
1648   FillHistogram("hKTBackgroundCMS", backgroundKTCMS, centralityPercentile);
1649   FillHistogram("hKTBackgroundMean", backgroundKTMean, centralityPercentile);
1650   FillHistogram("hKTBackgroundTrackLike", backgroundKTTrackLike, centralityPercentile);
1651   FillHistogram("hTRBackgroundNoExcl", backgroundTRNoExcl, centralityPercentile);
1652   FillHistogram("hTRBackgroundCone02", backgroundTRCone02, centralityPercentile);
1653   FillHistogram("hTRBackgroundCone04", backgroundTRCone04, centralityPercentile);
1654   FillHistogram("hTRBackgroundCone06", backgroundTRCone06, centralityPercentile);
1655   FillHistogram("hTRBackgroundCone08", backgroundTRCone08, centralityPercentile);
1656   FillHistogram("hTRBackgroundExact", backgroundTRExact, centralityPercentile);
1657
1658   // Calculate the delta pt
1659   Double_t tmpDeltaPtNoBackground = GetDeltaPt(0.0);
1660   Double_t tmpDeltaPtExternalBgrd = GetDeltaPt(backgroundExternal);
1661   Double_t tmpDeltaPtKTImprovedCMS = GetDeltaPt(backgroundKTImprovedCMS);
1662   Double_t tmpDeltaPtKTImprovedCMSFullExclusion = GetDeltaPt(backgroundKTImprovedCMS, 1.0);
1663
1664   Double_t tmpDeltaPtKTPbPb = 0;
1665   Double_t tmpDeltaPtKTPbPbWithGhosts = 0;
1666   Double_t tmpDeltaPtKTCMS = 0;
1667   Double_t tmpDeltaPtKTMean = 0;
1668   Double_t tmpDeltaPtKTTrackLike = 0;
1669   Double_t tmpDeltaPtTR = 0;
1670
1671   tmpDeltaPtKTPbPb = GetDeltaPt(backgroundKTPbPb);
1672   tmpDeltaPtKTPbPbWithGhosts = GetDeltaPt(backgroundKTPbPbWithGhosts);
1673   tmpDeltaPtKTCMS = GetDeltaPt(backgroundKTCMS);
1674   tmpDeltaPtKTMean = GetDeltaPt(backgroundKTMean);
1675   tmpDeltaPtKTTrackLike = GetDeltaPt(backgroundKTTrackLike);
1676   tmpDeltaPtTR = GetDeltaPt(backgroundTRCone06);
1677
1678
1679   // If valid, fill the delta pt histograms
1680
1681   if(tmpDeltaPtExternalBgrd > -10000.0)
1682     FillHistogram("hDeltaPtExternalBgrd", tmpDeltaPtExternalBgrd, centralityPercentile);
1683   if(tmpDeltaPtKTImprovedCMS > -10000.0)
1684     FillHistogram("hDeltaPtKTImprovedCMS", tmpDeltaPtKTImprovedCMS, centralityPercentile);
1685   if(tmpDeltaPtKTImprovedCMSFullExclusion > -10000.0)
1686     FillHistogram("hDeltaPtKTImprovedCMSFullExclusion", tmpDeltaPtKTImprovedCMSFullExclusion, centralityPercentile);
1687
1688   if(tmpDeltaPtNoBackground > -10000.0)
1689     FillHistogram("hDeltaPtNoBackground", tmpDeltaPtNoBackground, centralityPercentile);
1690
1691   if(tmpDeltaPtKTPbPb > -10000.0)
1692     FillHistogram("hDeltaPtKTPbPb", tmpDeltaPtKTPbPb, centralityPercentile);
1693   if(tmpDeltaPtKTPbPbWithGhosts > -10000.0)
1694     FillHistogram("hDeltaPtKTPbPbWithGhosts", tmpDeltaPtKTPbPbWithGhosts, centralityPercentile);
1695   if(tmpDeltaPtKTCMS > -10000.0)
1696     FillHistogram("hDeltaPtKTCMS", tmpDeltaPtKTCMS, centralityPercentile);
1697   if(tmpDeltaPtKTMean > -10000.0)
1698     FillHistogram("hDeltaPtKTMean", tmpDeltaPtKTMean, centralityPercentile);
1699   if(tmpDeltaPtKTTrackLike > -10000.0)
1700     FillHistogram("hDeltaPtKTTrackLike", tmpDeltaPtKTTrackLike, centralityPercentile);
1701   if(tmpDeltaPtTR > -10000.0)
1702     FillHistogram("hDeltaPtTR", tmpDeltaPtTR, centralityPercentile);
1703
1704   #ifdef DEBUGMODE
1705     AliInfo("Calculate()::Background done.");
1706   #endif
1707   
1708   #ifdef DEBUGMODE
1709     AliInfo("Calculate() done.");
1710   #endif
1711 }
1712
1713 //________________________________________________________________________
1714 Bool_t AliAnalysisTaskChargedJetsPA::UserNotify()
1715 {
1716   return kTRUE;
1717 }
1718
1719 //________________________________________________________________________
1720 void AliAnalysisTaskChargedJetsPA::CreateJetProfilePlots(Double_t bgrd)
1721 {
1722   for (Int_t i = 0; i<fJetArray->GetEntries(); i++)
1723   {
1724     AliEmcalJet* tmpJet = static_cast<AliEmcalJet*>(fJetArray->At(i));
1725     if (!tmpJet)
1726       continue;
1727     if(!IsSignalJetInAcceptance(tmpJet))
1728       continue;
1729
1730     SetCurrentOutputList(1);
1731     // Jet profile analysis
1732     if(TMath::Abs(tmpJet->Eta()) <= 0.3)
1733     {
1734       if(tmpJet->Pt()>=70.0)
1735       {
1736         FillHistogram("hJetProfile70GeV", 0.05-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1737         FillHistogram("hJetProfile70GeV", 0.10-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1738         FillHistogram("hJetProfile70GeV", 0.15-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1739         FillHistogram("hJetProfile70GeV", 0.20-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1740         FillHistogram("hJetProfile70GeV", 0.25-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1741         FillHistogram("hJetProfile70GeV", 0.30-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1742         FillHistogram("hJetProfile70GeV", 0.35-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1743         FillHistogram("hJetProfile70GeV", 0.40-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1744         FillHistogram("hJetProfile70GeV", 0.45-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1745         FillHistogram("hJetProfile70GeV", 0.50-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1746         FillHistogram("hJetProfile70GeV", 0.55-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1747         FillHistogram("hJetProfile70GeV", 0.60-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1748       }
1749       else if(GetCorrectedJetPt(tmpJet, bgrd)>=60.0)
1750       {
1751         FillHistogram("hJetProfile60GeV", 0.05-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1752         FillHistogram("hJetProfile60GeV", 0.10-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1753         FillHistogram("hJetProfile60GeV", 0.15-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1754         FillHistogram("hJetProfile60GeV", 0.20-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1755         FillHistogram("hJetProfile60GeV", 0.25-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1756         FillHistogram("hJetProfile60GeV", 0.30-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1757         FillHistogram("hJetProfile60GeV", 0.35-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1758         FillHistogram("hJetProfile60GeV", 0.40-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1759         FillHistogram("hJetProfile60GeV", 0.45-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1760         FillHistogram("hJetProfile60GeV", 0.50-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1761         FillHistogram("hJetProfile60GeV", 0.55-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1762         FillHistogram("hJetProfile60GeV", 0.60-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1763       }
1764       else if(GetCorrectedJetPt(tmpJet, bgrd)>=50.0)
1765       {
1766         FillHistogram("hJetProfile50GeV", 0.05-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1767         FillHistogram("hJetProfile50GeV", 0.10-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1768         FillHistogram("hJetProfile50GeV", 0.15-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1769         FillHistogram("hJetProfile50GeV", 0.20-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1770         FillHistogram("hJetProfile50GeV", 0.25-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1771         FillHistogram("hJetProfile50GeV", 0.30-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1772         FillHistogram("hJetProfile50GeV", 0.35-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1773         FillHistogram("hJetProfile50GeV", 0.40-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1774         FillHistogram("hJetProfile50GeV", 0.45-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1775         FillHistogram("hJetProfile50GeV", 0.50-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1776         FillHistogram("hJetProfile50GeV", 0.55-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1777         FillHistogram("hJetProfile50GeV", 0.60-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1778       }
1779       else if(GetCorrectedJetPt(tmpJet, bgrd)>=40.0)
1780       {
1781         FillHistogram("hJetProfile40GeV", 0.05-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1782         FillHistogram("hJetProfile40GeV", 0.10-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1783         FillHistogram("hJetProfile40GeV", 0.15-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1784         FillHistogram("hJetProfile40GeV", 0.20-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1785         FillHistogram("hJetProfile40GeV", 0.25-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1786         FillHistogram("hJetProfile40GeV", 0.30-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1787         FillHistogram("hJetProfile40GeV", 0.35-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1788         FillHistogram("hJetProfile40GeV", 0.40-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1789         FillHistogram("hJetProfile40GeV", 0.45-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1790         FillHistogram("hJetProfile40GeV", 0.50-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1791         FillHistogram("hJetProfile40GeV", 0.55-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1792         FillHistogram("hJetProfile40GeV", 0.60-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1793       }
1794       else if(GetCorrectedJetPt(tmpJet, bgrd)>=30.0)
1795       {
1796         FillHistogram("hJetProfile30GeV", 0.05-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1797         FillHistogram("hJetProfile30GeV", 0.10-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1798         FillHistogram("hJetProfile30GeV", 0.15-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1799         FillHistogram("hJetProfile30GeV", 0.20-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1800         FillHistogram("hJetProfile30GeV", 0.25-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1801         FillHistogram("hJetProfile30GeV", 0.30-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1802         FillHistogram("hJetProfile30GeV", 0.35-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1803         FillHistogram("hJetProfile30GeV", 0.40-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1804         FillHistogram("hJetProfile30GeV", 0.45-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1805         FillHistogram("hJetProfile30GeV", 0.50-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1806         FillHistogram("hJetProfile30GeV", 0.55-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1807         FillHistogram("hJetProfile30GeV", 0.60-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1808       }
1809       else if(GetCorrectedJetPt(tmpJet, bgrd)>=20.0)
1810       {
1811         FillHistogram("hJetProfile20GeV", 0.05-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1812         FillHistogram("hJetProfile20GeV", 0.10-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1813         FillHistogram("hJetProfile20GeV", 0.15-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1814         FillHistogram("hJetProfile20GeV", 0.20-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1815         FillHistogram("hJetProfile20GeV", 0.25-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1816         FillHistogram("hJetProfile20GeV", 0.30-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1817         FillHistogram("hJetProfile20GeV", 0.35-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1818         FillHistogram("hJetProfile20GeV", 0.40-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1819         FillHistogram("hJetProfile20GeV", 0.45-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1820         FillHistogram("hJetProfile20GeV", 0.50-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1821         FillHistogram("hJetProfile20GeV", 0.55-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1822         FillHistogram("hJetProfile20GeV", 0.60-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1823       }
1824       else if(GetCorrectedJetPt(tmpJet, bgrd)>=10.0)
1825       {
1826         FillHistogram("hJetProfile10GeV", 0.05-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.05, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1827         FillHistogram("hJetProfile10GeV", 0.10-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.10, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1828         FillHistogram("hJetProfile10GeV", 0.15-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.15, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1829         FillHistogram("hJetProfile10GeV", 0.20-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.20, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1830         FillHistogram("hJetProfile10GeV", 0.25-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.25, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1831         FillHistogram("hJetProfile10GeV", 0.30-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.30, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1832         FillHistogram("hJetProfile10GeV", 0.35-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.35, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1833         FillHistogram("hJetProfile10GeV", 0.40-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.40, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1834         FillHistogram("hJetProfile10GeV", 0.45-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.45, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1835         FillHistogram("hJetProfile10GeV", 0.50-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.50, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1836         FillHistogram("hJetProfile10GeV", 0.55-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.55, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1837         FillHistogram("hJetProfile10GeV", 0.60-0.05/2, (GetCorrectedConePt(tmpJet->Eta(), tmpJet->Phi(), 0.60, bgrd))/GetCorrectedJetPt(tmpJet, bgrd));
1838       }
1839     }
1840     SetCurrentOutputList(0);
1841   }
1842 }
1843
1844 //________________________________________________________________________
1845 inline Double_t AliAnalysisTaskChargedJetsPA::EtaToTheta(Double_t arg)
1846   {return 2.*atan(exp(-arg));} 
1847 //________________________________________________________________________
1848 inline Double_t AliAnalysisTaskChargedJetsPA::ThetaToEta(Double_t arg)
1849 {
1850   if ((arg > TMath::Pi()) || (arg < 0.0))
1851   {
1852     AliError(Form("ThetaToEta got wrong input! (%f)", arg));
1853     return 0.0;
1854   }
1855   return -log(tan(arg/2.));
1856 }
1857 //________________________________________________________________________
1858 inline Double_t AliAnalysisTaskChargedJetsPA::GetDeltaPhi(Double_t phi1, Double_t phi2)
1859   {return min(TMath::Abs(phi1-phi2),TMath::TwoPi() - TMath::Abs(phi1-phi2));}
1860
1861 //________________________________________________________________________
1862 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)
1863 {
1864   const Int_t kTests = 1000;
1865   Int_t hits = 0;
1866   TRandom3 randomGen(0);
1867  
1868   // Loop over kTests-many tests
1869   for (Int_t i=0; i<kTests; i++)
1870   {
1871     //Choose random position in rectangle for the tester
1872     Double_t tmpTestX = randomGen.Uniform(rPosXmin, rPosXmax);
1873     Double_t tmpTestY = randomGen.Uniform(rPosYmin, rPosYmax);
1874
1875     //Check, if tester is in circle. If yes, increment circle counter.
1876     Double_t tmpDistance = TMath::Sqrt( (tmpTestX - cPosX)*(tmpTestX - cPosX) + (tmpTestY - cPosY)*(tmpTestY - cPosY) );
1877     if(tmpDistance < cRadius)
1878       hits++;
1879   }
1880
1881   // return ratio
1882   return (static_cast<Double_t>(hits)/static_cast<Double_t>(kTests));
1883 }
1884
1885 //________________________________________________________________________
1886 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)
1887 {
1888
1889   const Int_t kTests = 1000;
1890   Int_t hits = 0;
1891   TRandom3 randomGen(0);
1892  
1893   // Loop over kTests-many tests
1894   for (Int_t i=0; i<kTests; i++)
1895   {
1896     //Choose random position in rectangle for the tester
1897     Double_t tmpTestX = randomGen.Uniform(rPosXmin, rPosXmax);
1898     Double_t tmpTestY = randomGen.Uniform(rPosYmin, rPosYmax);
1899
1900     //Check, if tester is in one of the circles. If yes, increment circle counter.
1901     for(Int_t j=0; j<numCircles; j++)
1902     {
1903       Double_t tmpDistance = TMath::Sqrt( (tmpTestX - cPosX[j])*(tmpTestX - cPosX[j]) + (tmpTestY - cPosY[j])*(tmpTestY - cPosY[j]) );
1904       if(tmpDistance < cRadius)
1905       {
1906         hits++;
1907         break;
1908       }
1909     }
1910   }
1911
1912   // return ratio
1913   return (static_cast<Double_t>(hits)/static_cast<Double_t>(kTests));
1914
1915 }
1916
1917 //________________________________________________________________________
1918 inline void AliAnalysisTaskChargedJetsPA::FillHistogram(const char * key, Double_t x)
1919 {
1920   TH1* tmpHist = static_cast<TH1*>(fCurrentOutputList->FindObject(GetHistoName(key)));
1921   if(!tmpHist)
1922   {
1923     AliError(Form("Cannot find histogram <%s> ",key)) ;
1924     return;
1925   }
1926
1927   tmpHist->Fill(x);
1928 }
1929
1930 //________________________________________________________________________
1931 inline void AliAnalysisTaskChargedJetsPA::FillHistogram(const char * key, Double_t x, Double_t y)
1932 {
1933   TH1* tmpHist = static_cast<TH1*>(fCurrentOutputList->FindObject(GetHistoName(key)));
1934   if(!tmpHist)
1935   {
1936     AliError(Form("Cannot find histogram <%s> ",key));
1937     return;
1938   }
1939
1940   if (tmpHist->IsA()->GetBaseClass("TH1"))
1941     static_cast<TH1*>(tmpHist)->Fill(x,y); // Fill x with y
1942   else if (tmpHist->IsA()->GetBaseClass("TH2"))
1943     static_cast<TH2*>(tmpHist)->Fill(x,y); // Fill x,y with 1
1944 }
1945
1946 //________________________________________________________________________
1947 inline void AliAnalysisTaskChargedJetsPA::FillHistogram(const char * key, Double_t x, Double_t y, Double_t add)
1948 {
1949   TH2* tmpHist = static_cast<TH2*>(fCurrentOutputList->FindObject(GetHistoName(key)));
1950   if(!tmpHist)
1951   {
1952     AliError(Form("Cannot find histogram <%s> ",key));
1953     return;
1954   }
1955   
1956   tmpHist->Fill(x,y,add);
1957 }
1958
1959 //________________________________________________________________________
1960 inline void AliAnalysisTaskChargedJetsPA::FillCutHistogram(const char * key, Double_t cut, Double_t pT, Double_t eta, Double_t phi, Int_t isAdditionalTrack)
1961 {
1962   THnF* tmpHist = static_cast<THnF*>(fCurrentOutputList->FindObject(GetHistoName(key)));
1963   if(!tmpHist)
1964   {
1965     AliError(Form("Cannot find histogram <%s> ",key));
1966     return;
1967   }
1968
1969   Double_t tmpVec[5] = {cut, pT, eta, phi, static_cast<Double_t>(isAdditionalTrack)};
1970   tmpHist->Fill(tmpVec);
1971 }
1972
1973 //________________________________________________________________________
1974 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)
1975 {
1976   T* tmpHist = new T(GetHistoName(name), GetHistoName(title), xBins, xMin, xMax);
1977
1978   tmpHist->GetXaxis()->SetTitle(xTitle);
1979   tmpHist->GetYaxis()->SetTitle(yTitle);
1980   tmpHist->SetOption(options);
1981   tmpHist->SetMarkerStyle(kFullCircle);
1982   tmpHist->Sumw2();
1983
1984   fCurrentOutputList->Add(tmpHist);
1985
1986   return tmpHist;
1987 }
1988
1989 //________________________________________________________________________
1990 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)
1991 {
1992   T* tmpHist = new T(GetHistoName(name), GetHistoName(title), xBins, xMin, xMax, yBins, yMin, yMax);
1993   tmpHist->GetXaxis()->SetTitle(xTitle);
1994   tmpHist->GetYaxis()->SetTitle(yTitle);
1995   tmpHist->GetZaxis()->SetTitle(zTitle);
1996   tmpHist->SetOption(options);
1997   tmpHist->SetMarkerStyle(kFullCircle);
1998   tmpHist->Sumw2();
1999
2000   fCurrentOutputList->Add(tmpHist);
2001
2002   return tmpHist;
2003 }
2004
2005 //________________________________________________________________________
2006 THnF* AliAnalysisTaskChargedJetsPA::AddCutHistogram(const char* name, const char* title, const char* cutName, Int_t nBins, Double_t xMin, Double_t xMax)
2007 {
2008   //                        Cut,      pT,  eta,           phi,  type 
2009   Int_t    bins [5]     = { nBins,   100,   20,            18,     2};
2010   Double_t minEdges[5]  = { xMin,    0.1,   -1,             0,  -0.5};
2011   Double_t maxEdges[5]  = { xMax,     40,   +1, 2*TMath::Pi(),   1.5};
2012
2013   TString axisName[5]  = {cutName,"#it{p}_{T}","#eta","#phi","Track type"};
2014   TString axisTitle[5] = {cutName,"#it{p}_{T}","#eta","#phi","Track type"};
2015
2016   THnF * histo = new THnF(name, title, 5, bins, minEdges, maxEdges);
2017   BinLogAxis(histo, 1);
2018
2019   for (Int_t iaxis=0; iaxis<5;iaxis++){
2020     histo->GetAxis(iaxis)->SetName(axisName[iaxis]);
2021     histo->GetAxis(iaxis)->SetTitle(axisTitle[iaxis]);
2022   }
2023
2024   fCurrentOutputList->Add(histo);
2025   return histo;
2026 }
2027
2028 //________________________________________________________________________
2029 void AliAnalysisTaskChargedJetsPA::BinLogAxis(const THn *h, Int_t axisNumber)
2030 {
2031   // Method for the correct logarithmic binning of histograms
2032   TAxis *axis = h->GetAxis(axisNumber);
2033   int bins = axis->GetNbins();
2034
2035   Double_t from = axis->GetXmin();
2036   Double_t to = axis->GetXmax();
2037   Double_t *newBins = new Double_t[bins + 1];
2038    
2039   newBins[0] = from;
2040   Double_t factor = pow(to/from, 1./bins);
2041   
2042   for (int i = 1; i <= bins; i++) {
2043    newBins[i] = factor * newBins[i-1];
2044   }
2045   axis->Set(bins, newBins);
2046   delete [] newBins;
2047 }
2048
2049 //________________________________________________________________________
2050 void AliAnalysisTaskChargedJetsPA::Terminate(Option_t *)
2051 {
2052   PostData(1, fOutputLists[0]);
2053   fOutputLists[0] = dynamic_cast<TList*> (GetOutputData(1)); // >1 refers to output slots
2054
2055   if(fAnalyzeJetProfile)
2056   {
2057     PostData(2, fOutputLists[1]);
2058     fOutputLists[1] = dynamic_cast<TList*> (GetOutputData(2)); // >1 refers to output slots
2059   }
2060   if(fAnalyzeTrackcuts)
2061   {
2062     if(fAnalyzeJetProfile)
2063     {
2064       PostData(3, fOutputLists[2]);
2065       fOutputLists[2] = dynamic_cast<TList*> (GetOutputData(3)); // >1 refers to output slots
2066     }
2067     else
2068     {
2069       PostData(2, fOutputLists[1]);
2070       fOutputLists[1] = dynamic_cast<TList*> (GetOutputData(2)); // >1 refers to output slots
2071     }
2072   }
2073 }
2074
2075 //________________________________________________________________________
2076 AliAnalysisTaskChargedJetsPA::~AliAnalysisTaskChargedJetsPA()
2077 {
2078   // Destructor. Clean-up the output list, but not the histograms that are put inside
2079   // (the list is owner and will clean-up these histograms). Protect in PROOF case.
2080   delete fHybridESDtrackCuts;
2081   delete fHybridESDtrackCuts_noPtDep;
2082
2083   for(Int_t i=0; i<static_cast<Int_t>(fOutputLists.size()); i++)
2084     if (fOutputLists[i] && !AliAnalysisManager::GetAnalysisManager()->IsProofMode())
2085       delete fOutputLists[i];
2086 }
2087
2088 //________________________________________________________________________
2089 void AliAnalysisTaskChargedJetsPA::UserCreateOutputObjects()
2090 {
2091   // called once to create user defined output objects like histograms, plots etc. 
2092   // and to put it on the output list.
2093   // Note: Saving to file with e.g. OpenFile(0) is must be before creating other objects.
2094
2095   fRandom = new TRandom3(0);
2096
2097
2098   Int_t tmpListCount = 1;
2099   if(fAnalyzeJetProfile)
2100     tmpListCount++;
2101   if(fAnalyzeTrackcuts)
2102     tmpListCount++;
2103
2104   fOutputLists.resize(tmpListCount);
2105   for(Int_t i=0; i<tmpListCount; i++)
2106   {
2107     fOutputLists[i] = new TList();
2108     fOutputLists[i]->SetOwner(); // otherwise it produces leaks in merging
2109     PostData(i+1, fOutputLists[i]);
2110   }
2111 }
2112
2113 //________________________________________________________________________
2114 void AliAnalysisTaskChargedJetsPA::UserExec(Option_t *) 
2115 {
2116   #ifdef DEBUGMODE
2117     AliInfo("UserExec() started.");
2118   #endif
2119
2120   if (!InputEvent())
2121   {
2122     AliError("??? Event pointer == 0 ???");
2123     return;
2124   }
2125
2126   if (!fInitialized)
2127     ExecOnce(); // Get tracks, jets, background from arrays if not already given + Init Histos
2128   
2129   Calculate(InputEvent());
2130
2131   PostData(1, fOutputLists[0]);
2132   if(fAnalyzeJetProfile)
2133     PostData(2, fOutputLists[1]);
2134   if(fAnalyzeTrackcuts)
2135   {
2136     if(fAnalyzeJetProfile)
2137       PostData(3, fOutputLists[2]);
2138     else
2139       PostData(2, fOutputLists[1]);
2140   }
2141
2142 }