]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskRhoVnModulation.cxx
from redmer
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskRhoVnModulation.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* 
17  * analysis task for jet flow preparation
18  *
19  * this task is part of the emcal jet framework and should be run in the emcaljet train
20  * the following extensions to an accepted AliVEvent are expected:
21  *      - (anti-kt) jets
22  *      - background estimate rho
23  *      - pico tracks
24  *      aod's and esd's are handled transparently
25  * the task will attempt to estimate a phi-dependent background density rho 
26  * by fitting vn harmonics to the dpt/dphi distribution
27  *
28  * author: Redmer Alexander Bertens, Utrecht Univeristy, Utrecht, Netherlands
29  * rbertens@cern.ch, rbertens@nikhef.nl, r.a.bertens@uu.nl 
30  */
31
32 #include <TStyle.h>
33 #include <TRandom3.h>
34 #include <TChain.h>
35 #include <TMath.h>
36 #include <TF1.h>
37 #include <TF2.h>
38 #include <TH1F.h>
39 #include <TH2F.h>
40 #include <TProfile.h>
41
42 #include <AliAnalysisTask.h>
43 #include <AliAnalysisManager.h>
44 #include <AliCentrality.h>
45 #include <AliVVertex.h>
46 #include <AliESDEvent.h>
47 #include <AliAODEvent.h>
48
49 #include <AliPicoTrack.h>
50 #include <AliEmcalJet.h>
51 #include <AliRhoParameter.h>
52
53 #include "AliAnalysisTaskRhoVnModulation.h"
54
55
56 class AliAnalysisTaskRhoVnModulation;
57 using namespace std;
58
59 ClassImp(AliAnalysisTaskRhoVnModulation)
60
61 AliAnalysisTaskRhoVnModulation::AliAnalysisTaskRhoVnModulation() : AliAnalysisTaskEmcalJet("AliAnalysisTaskRhoVnModulation", kTRUE), 
62     fDebug(0), fInitialized(0), fFillQAHistograms(kTRUE), fCentralityClasses(0), fNAcceptedTracks(0), fFitModulationType(kNoFit), fUsePtWeight(kTRUE), fDetectorType(kTPC), fFitModulationOptions("Q"), fRunModeType(kGrid), fDataType(kESD), fRandom(0), fMappedRunNumber(0), fInCentralitySelection(-1), fFitModulation(0), fMinPvalue(0), fMaxPvalue(1), fNameJetClones(0), fNamePicoTrackClones(0), fNameRho(0), fAbsVertexZ(10), fHistCentrality(0), fHistVertexz(0), fHistRunnumbersPhi(0), fHistRunnumbersEta(0), fHistPvaluePDF(0), fHistPvalueCDF(0), fMinDisanceRCtoLJ(0), fRandomConeRadius(0.4), fAbsVnHarmonics(kTRUE), fExcludeLeadingJetsFromFit(1.), fRebinSwapHistoOnTheFly(kTRUE), fPercentageOfFits(10.), fOutputList(0), fOutputListGood(0), fOutputListBad(0), fHistAnalysisSummary(0), fHistSwap(0), fProfV2(0), fProfV3(0), fHistPsiControl(0), fHistPsiSpread(0), fHistPsiVZEROA(0), fHistPsiVZEROC(0), fHistPsiTPC(0), fHistPsiTPCSUBA(0), fHistPsiTPCSUBB(0),
63    fHistRhoVsMult(0), fHistRhoVsCent(0), fHistRhoAVsMult(0), fHistRhoAVsCent(0) {
64     for(Int_t i(0); i < 10; i++) {
65         fProfV2Resolution[i] = 0;
66         fProfV3Resolution[i] = 0;
67         fHistPicoTrackPt[i] = 0;
68         fHistPicoCat1[i] = 0;
69         fHistPicoCat2[i] = 0;
70         fHistPicoCat3[i] = 0;
71         /* fHistClusterPt[i] = 0; */
72         /* fHistClusterPhi[i] = 0; */
73         /* fHistClusterEta[i] = 0; */ 
74         /* fHistClusterCorrPt[i] = 0; */
75         /* fHistClusterCorrPhi[i] = 0; */
76         /* fHistClusterCorrEta[i] = 0; */
77         fHistRhoPackage[i] = 0;
78         fHistRho[i] = 0;
79         fHistRCPhiEta[i] = 0;
80         fHistRhoVsRCPt[i] = 0;
81         fHistRCPt[i] = 0;
82         fHistDeltaPtDeltaPhi2[i] = 0;
83         fHistDeltaPtDeltaPhi3[i] = 0;
84         fHistRCPhiEtaExLJ[i] = 0;
85         fHistRhoVsRCPtExLJ[i] = 0;
86         fHistRCPtExLJ[i] = 0;
87         fHistDeltaPtDeltaPhi2ExLJ[i] = 0;
88         fHistDeltaPtDeltaPhi3ExLJ[i] = 0;
89         fHistRCPhiEtaRand[i] = 0;
90         fHistRhoVsRCPtRand[i] = 0;
91         fHistRCPtRand[i] = 0;
92         fHistDeltaPtDeltaPhi2Rand[i] = 0;
93         fHistDeltaPtDeltaPhi3Rand[i] = 0;
94         fHistJetPtRaw[i] = 0;
95         fHistJetPt[i] = 0;
96         fHistJetEtaPhi[i] = 0;
97         fHistJetPtArea[i] = 0;
98         fHistJetPtConstituents[i] = 0;
99         fHistJetEtaRho[i] = 0;
100         fHistJetPsiTPCPt[i] = 0;
101         fHistJetPsiVZEROAPt[i] = 0;
102         fHistJetPsiVZEROCPt[i] = 0;
103         fHistDeltaPhi2VZEROA[i] = 0;
104         fHistDeltaPhi2VZEROC[i] = 0;
105         fHistDeltaPhi2TPC[i] = 0;
106         fHistDeltaPhi3VZEROA[i] = 0;
107         fHistDeltaPhi3VZEROC[i] = 0;
108         fHistDeltaPhi3TPC[i] = 0;
109    }
110     // default constructor
111 }
112 //_____________________________________________________________________________
113 AliAnalysisTaskRhoVnModulation::AliAnalysisTaskRhoVnModulation(const char* name, runModeType type) : AliAnalysisTaskEmcalJet(name, kTRUE),
114   fDebug(0), fInitialized(0), fFillQAHistograms(kTRUE), fCentralityClasses(0), fNAcceptedTracks(0), fFitModulationType(kNoFit), fUsePtWeight(kTRUE), fDetectorType(kTPC), fFitModulationOptions("Q"), fRunModeType(type), fDataType(kESD), fRandom(0), fMappedRunNumber(0), fInCentralitySelection(-1), fFitModulation(0), fMinPvalue(0), fMaxPvalue(1), fNameJetClones(0), fNamePicoTrackClones(0), fNameRho(0), fAbsVertexZ(10), fHistCentrality(0), fHistVertexz(0), fHistRunnumbersPhi(0), fHistRunnumbersEta(0), fHistPvaluePDF(0), fHistPvalueCDF(0), fMinDisanceRCtoLJ(0), fRandomConeRadius(0.4), fAbsVnHarmonics(kTRUE), fExcludeLeadingJetsFromFit(1.), fRebinSwapHistoOnTheFly(kTRUE), fPercentageOfFits(10.), fOutputList(0), fOutputListGood(0), fOutputListBad(0), fHistAnalysisSummary(0), fHistSwap(0), fProfV2(0), fProfV3(0), fHistPsiControl(0), fHistPsiSpread(0), fHistPsiVZEROA(0), fHistPsiVZEROC(0), fHistPsiTPC(0), fHistPsiTPCSUBA(0), fHistPsiTPCSUBB(0), 
115    fHistRhoVsMult(0), fHistRhoVsCent(0), fHistRhoAVsMult(0), fHistRhoAVsCent(0) {
116     for(Int_t i(0); i < 10; i++) {
117         fProfV2Resolution[i] = 0;
118         fProfV3Resolution[i] = 0;
119         fHistPicoTrackPt[i] = 0;
120         fHistPicoCat1[i] = 0;
121         fHistPicoCat2[i] = 0;
122         fHistPicoCat3[i] = 0;
123         /* fHistClusterPt[i] = 0; */
124         /* fHistClusterPhi[i] = 0; */
125         /* fHistClusterEta[i] = 0; */ 
126         /* fHistClusterCorrPt[i] = 0; */
127         /* fHistClusterCorrPhi[i] = 0; */
128         /* fHistClusterCorrEta[i] = 0; */
129         fHistRhoPackage[i] = 0;
130         fHistRho[i] = 0;
131         fHistRCPhiEta[i] = 0;
132         fHistRhoVsRCPt[i] = 0;
133         fHistRCPt[i] = 0;
134         fHistDeltaPtDeltaPhi2[i] = 0;
135         fHistDeltaPtDeltaPhi3[i] = 0;
136         fHistRCPhiEtaExLJ[i] = 0;
137         fHistRhoVsRCPtExLJ[i] = 0;
138         fHistRCPtExLJ[i] = 0;
139         fHistDeltaPtDeltaPhi2ExLJ[i] = 0;
140         fHistDeltaPtDeltaPhi3ExLJ[i] = 0;
141         fHistRCPhiEtaRand[i] = 0;
142         fHistRhoVsRCPtRand[i] = 0;
143         fHistRCPtRand[i] = 0;
144         fHistDeltaPtDeltaPhi2Rand[i] = 0;
145         fHistDeltaPtDeltaPhi3Rand[i] = 0;
146         fHistJetPtRaw[i] = 0;
147         fHistJetPt[i] = 0;
148         fHistJetEtaPhi[i] = 0;
149         fHistJetPtArea[i] = 0;
150         fHistJetPtConstituents[i] = 0;
151         fHistJetEtaRho[i] = 0;
152         fHistJetPsiTPCPt[i] = 0;
153         fHistJetPsiVZEROAPt[i] = 0;
154         fHistJetPsiVZEROCPt[i] = 0;
155         fHistDeltaPhi2VZEROA[i] = 0;
156         fHistDeltaPhi2VZEROC[i] = 0;
157         fHistDeltaPhi2TPC[i] = 0;
158         fHistDeltaPhi3VZEROA[i] = 0;
159         fHistDeltaPhi3VZEROC[i] = 0;
160         fHistDeltaPhi3TPC[i] = 0;       
161     }
162     // constructor
163     DefineInput(0, TChain::Class());
164     DefineOutput(1, TList::Class());
165     switch (fRunModeType) {
166         case kLocal : {
167             gStyle->SetOptFit(1);
168             DefineOutput(2, TList::Class());
169             DefineOutput(3, TList::Class());
170         } break;
171         default: fDebug = -1;   // suppress debug info explicitely when not running locally
172     }
173 }
174 //_____________________________________________________________________________
175 AliAnalysisTaskRhoVnModulation::~AliAnalysisTaskRhoVnModulation()
176 {
177     // destructor
178     if(fOutputList)             delete fOutputList;
179     if(fOutputListGood)         delete fOutputListGood;
180     if(fOutputListBad)          delete fOutputListBad;
181     if(fFitModulation)          delete fFitModulation;
182     if(fHistSwap)               delete fHistSwap;
183     if(fCentralityClasses)      delete fCentralityClasses;
184 }
185 //_____________________________________________________________________________
186 Bool_t AliAnalysisTaskRhoVnModulation::InitializeAnalysis() 
187 {
188     // initialize the anaysis
189     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
190     if(fMinDisanceRCtoLJ==0) fMinDisanceRCtoLJ = .5*fJetRadius;
191     if(dynamic_cast<AliAODEvent*>(InputEvent())) fDataType = kAOD; // determine the datatype
192     else if(dynamic_cast<AliESDEvent*>(InputEvent())) fDataType = kESD;
193     fHistAnalysisSummary->SetBinContent(36, (int)fDataType);
194     if(!fRandom) fRandom = new TRandom3(0);  // get a randomized if one hasn't been user-supplied
195     switch (fFitModulationType)  {
196         case kNoFit : { SetModulationFit(new TF1("fix_kNoFit", "[0]", 0, TMath::TwoPi())); } break;
197         case kV2 : {
198             SetModulationFit(new TF1("fit_kV2", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
199             fFitModulation->SetParameter(0, 0.);        // normalization
200             fFitModulation->SetParameter(3, 0.2);       // v2
201             fFitModulation->FixParameter(1, 1.);        // constant
202             fFitModulation->FixParameter(2, 2.);        // constant
203         } break;
204         case kV3: {
205             SetModulationFit(new TF1("fit_kV3", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
206             fFitModulation->SetParameter(0, 0.);        // normalization
207             fFitModulation->SetParameter(3, 0.2);       // v3
208             fFitModulation->FixParameter(1, 1.);        // constant
209             fFitModulation->FixParameter(2, 3.);        // constant
210         } break;
211         default : { // for the combined fit and the 'direct fourier series' we use v2 and v3 
212              SetModulationFit(new TF1("fit_kCombined", "[0]*([1]+[2]*([3]*TMath::Cos([2]*(x-[4]))+[7]*TMath::Cos([5]*(x-[6]))))", 0, TMath::TwoPi()));
213              fFitModulation->SetParameter(0, 0.);       // normalization
214              fFitModulation->SetParameter(3, 0.2);      // v2
215              fFitModulation->FixParameter(1, 1.);       // constant
216              fFitModulation->FixParameter(2, 2.);       // constant
217              fFitModulation->FixParameter(5, 3.);       // constant
218              fFitModulation->SetParameter(7, 0.2);      // v3
219         } break;
220     }
221     switch (fRunModeType) {
222         case kGrid : { fFitModulationOptions += "N0"; } break;
223         default : break;
224     }
225     return kTRUE;
226 }
227 //_____________________________________________________________________________
228 TH1F* AliAnalysisTaskRhoVnModulation::BookTH1F(const char* name, const char* x, Int_t bins, Double_t min, Double_t max, Int_t c, Bool_t append)
229 {
230     // book a TH1F and connect it to the output container
231     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
232     if(!fOutputList) return 0x0;
233     TString title(name);
234     if(c!=-1) { // format centrality dependent histograms accordingly
235         name = Form("%s_%i", name, c);
236         title += Form("_%i-%i", fCentralityClasses->At(c), fCentralityClasses->At(1+c));
237     }
238     title += Form(";%s;[counts]", x);
239     TH1F* histogram = new TH1F(name, title.Data(), bins, min, max);
240     histogram->Sumw2();
241     if(append) fOutputList->Add(histogram);
242     return histogram;   
243 }
244 //_____________________________________________________________________________
245 TH2F* AliAnalysisTaskRhoVnModulation::BookTH2F(const char* name, const char* x, const char*y, Int_t binsx, Double_t minx, Double_t maxx, Int_t binsy, Double_t miny, Double_t maxy, Int_t c, Bool_t append)
246 {
247     // book a TH2F and connect it to the output container
248     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
249     if(!fOutputList) return 0x0;
250     TString title(name);
251     if(c!=-1) { // format centrality dependent histograms accordingly
252         name = Form("%s_%i", name, c);
253         title += Form("_%i-%i", fCentralityClasses->At(c), fCentralityClasses->At(1+c));
254     }
255     title += Form(";%s;%s", x, y);
256     TH2F* histogram = new TH2F(name, title.Data(), binsx, minx, maxx, binsy, miny, maxy);
257     histogram->Sumw2();
258     if(append) fOutputList->Add(histogram);
259     return histogram;   
260 }
261 //_____________________________________________________________________________
262 void AliAnalysisTaskRhoVnModulation::UserCreateOutputObjects()
263 {
264     // create output objects
265     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
266     fOutputList = new TList();
267     fOutputList->SetOwner(kTRUE);
268     if(!fCentralityClasses) {   // classes must be defined at this point
269         Int_t c[] = {0, 20, 40, 60, 80, 100};
270         fCentralityClasses = new TArrayI(sizeof(c)/sizeof(c[0]), c);
271     }
272     // global QA
273     fHistCentrality =           BookTH1F("fHistCentrality", "centrality", 102, -2, 100);
274     fHistVertexz =              BookTH1F("fHistVertexz", "vertex z (cm)", 100, -12, 12);
275
276     // pico track kinematics
277     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) { 
278         fHistPicoTrackPt[i] =          BookTH1F("fHistPicoTrackPt", "p_{t} [GeV/c]", 100, 0, 50, i);
279         if(fFillQAHistograms) {
280             fHistPicoCat1[i] =             BookTH2F("fHistPicoCat1", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
281             fHistPicoCat2[i] =             BookTH2F("fHistPicoCat2", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
282             fHistPicoCat3[i] =             BookTH2F("fHistPicoCat3", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
283         }
284         // emcal kinematics
285         /* fHistClusterPt[i] =            BookTH1F("fHistClusterPt", "p_{t} [GeV/c]", 100, 0, 100, i); */
286         /* fHistClusterPhi[i] =           BookTH1F("fHistClusterPhi", "#phi", 100, 0, TMath::TwoPi(), i); */
287         /* fHistClusterEta[i] =           BookTH1F("fHistClusterEta", "#eta", 100, -5, 5); */
288
289         // emcal kinematics after hadronic correction
290         /* fHistClusterCorrPt[i] =        BookTH1F("fHistClusterCorrPt", "p_{t} [GeV/c]", 100, 0, 100, i); */
291         /* fHistClusterCorrPhi[i] =       BookTH1F("fHistClusterCorrPhi", "#phi", 100, 0, TMath::TwoPi(), i); */
292         /* fHistClusterCorrEta[i] =       BookTH1F("fHistClusterCorrEta", "#eta", 100, -5, 5, i); */
293     }
294
295     // event plane estimates and quality
296     fHistPsiControl =           new TProfile("fHistPsiControl", "fHistPsiControl", 10, 0, 10);
297     fHistPsiControl->Sumw2();
298     fHistPsiSpread =            new TProfile("fHistPsiSpread", "fHistPsiSpread", 4, 0, 4);
299     fHistPsiSpread->Sumw2();
300     fHistPsiControl->GetXaxis()->SetBinLabel(1, "<#Psi_{2, VZEROA}>");
301     fHistPsiControl->GetXaxis()->SetBinLabel(2, "<#Psi_{2, VZEROC}>");
302     fHistPsiControl->GetXaxis()->SetBinLabel(3, "<#Psi_{2, TPC}>");
303     fHistPsiControl->GetXaxis()->SetBinLabel(4, "<#Psi_{2, TPC, #eta < 0}>");
304     fHistPsiControl->GetXaxis()->SetBinLabel(5, "<#Psi_{2, TPC, #eta > 0}>");
305     fHistPsiControl->GetXaxis()->SetBinLabel(1, "<#Psi_{3, VZEROA}>");
306     fHistPsiControl->GetXaxis()->SetBinLabel(2, "<#Psi_{3, VZEROC}>");
307     fHistPsiControl->GetXaxis()->SetBinLabel(3, "<#Psi_{3, TPC}>");
308     fHistPsiControl->GetXaxis()->SetBinLabel(4, "<#Psi_{3, TPC, #eta < 0}>");
309     fHistPsiControl->GetXaxis()->SetBinLabel(5, "<#Psi_{3, TPC, #eta > 0}>");
310     fHistPsiSpread->GetXaxis()->SetBinLabel(1, "<#Psi_{2, VZEROA} - #Psi_{2, VZEROC}>");
311     fHistPsiSpread->GetXaxis()->SetBinLabel(2, "<#Psi_{2, VZEROC} - #Psi_{2, TPC}>");
312     fHistPsiSpread->GetXaxis()->SetBinLabel(3, "<#Psi_{2, VZEROC} - #Psi_{2, TPC}>");
313     fHistPsiSpread->GetXaxis()->SetBinLabel(4, "<#Psi_{2, TPC, #eta < 0} - #Psi_{2, TPC, #eta > 0}>");
314     fOutputList->Add(fHistPsiControl);
315     fOutputList->Add(fHistPsiSpread);
316     fHistPsiVZEROA =            BookTH1F("fHistPsiVZEROA", "#Psi_{VZEROA}", 100, -.5*TMath::Pi(), .5*TMath::Pi());
317     fHistPsiVZEROC =            BookTH1F("fHistPsiVZEROC", "#Psi_{VZEROC}", 100, -.5*TMath::Pi(), .5*TMath::Pi());
318     fHistPsiTPC =               BookTH1F("fHistPsiTPC", "#Psi_{TPC}", 100, -.5*TMath::Pi(), .5*TMath::Pi());
319     fHistPsiTPCSUBA =           BookTH1F("fHistPsiTPCSUBA", "#Psi_{TPC, #eta < 0}", 100, -.5*TMath::Pi(), .5*TMath::Pi());
320     fHistPsiTPCSUBB =           BookTH1F("fHistPsiTPCSUBB", "#Psi_{TPC, #eta > 0}", 100, -.5*TMath::Pi(), .5*TMath::Pi());
321
322     // background
323     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i ++) {
324         fHistRhoPackage[i] =           BookTH1F("fHistRhoPackage",  "#rho [GeV/c]", 100, 0, 150, i);
325         fHistRho[i] =                  BookTH1F("fHistRho", "#rho [GeV/c]", 100, 0, 150, i);
326     }
327     fHistRhoVsMult =            BookTH2F("fHistRhoVsMult", "multiplicity", "#rho [GeV/c]", 100, 0, 4000, 100, 0, 250);
328     fHistRhoVsCent =            BookTH2F("fHistRhoVsCent", "centrality", "#rho [GeV/c]", 100, 0, 100, 100, 0, 250);
329     fHistRhoAVsMult =           BookTH2F("fHistRhoAVsMult", "multiplicity", "#rho * A (jet) [GeV/c]", 100, 0, 4000, 100, 0, 50);
330     fHistRhoAVsCent =           BookTH2F("fHistRhoAVsCent", "centrality", "#rho * A (jet) [GeV/c]", 100, 0, 100, 100, 0, 50);
331
332     // delta pt distributions
333     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i ++) {
334         fHistRCPhiEta[i] =             BookTH2F("fHistRCPhiEta", "#phi (RC)", "#eta (RC)", 100, 0, TMath::TwoPi(), 100, -1, 1, i);
335         fHistRhoVsRCPt[i] =            BookTH2F("fHistRhoVsRCPt", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
336         fHistRCPt[i] =                 BookTH1F("fHistRCPt", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
337         fHistRCPhiEtaExLJ[i] =         BookTH2F("fHistRCPhiEtaExLJ", "#phi (RC)", "#eta (RC)", 100, 0, TMath::TwoPi(), 100, -1, 1, i);
338         fHistDeltaPtDeltaPhi2[i] =     BookTH2F("fHistDeltaPtDeltaPhi2", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 100, 0, TMath::TwoPi(), 100, -50, 100, i);
339         fHistDeltaPtDeltaPhi3[i] =     BookTH2F("fHistDeltaPtDeltaPhi3", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 100, 0, TMath::TwoPi(), 100, -50, 100, i);
340         fHistRhoVsRCPtExLJ[i] =        BookTH2F("fHistRhoVsRCPtExLJ", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
341         fHistRCPtExLJ[i] =             BookTH1F("fHistRCPtExLJ", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
342         fHistRCPhiEtaRand[i] =         BookTH2F("fHistRCPhiEtaRand", "#phi (RC)", "#eta (RC)", 100, 0, TMath::TwoPi(), 100, -1, 1, i);
343         fHistDeltaPtDeltaPhi2ExLJ[i] = BookTH2F("fHistDeltaPtDeltaPhi2ExLJ", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 100, 0, TMath::TwoPi(), 100, -50, 100, i);
344         fHistDeltaPtDeltaPhi3ExLJ[i] = BookTH2F("fHistDeltaPtDeltaPhi3ExLJ", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 100, 0, TMath::TwoPi(), 100, -50, 100, i);
345         fHistRhoVsRCPtRand[i] =        BookTH2F("fHistRhoVsRCPtRand", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
346         fHistRCPtRand[i] =             BookTH1F("fHistRCPtRand", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
347         fHistDeltaPtDeltaPhi2Rand[i] =  BookTH2F("fHistDeltaPtDeltaPhi2Rand", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 100, 0, TMath::TwoPi(), 100, -50, 100, i);
348         fHistDeltaPtDeltaPhi3Rand[i] =  BookTH2F("fHistDeltaPtDeltaPhi3Rand", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 100, 0, TMath::TwoPi(), 100, -50, 100, i);
349         // jet histograms (after kinematic cuts)
350         fHistJetPtRaw[i] =             BookTH1F("fHistJetPtRaw", "p_{t} RAW [GeV/c]", 200, -50, 150, i);
351         fHistJetPt[i] =                BookTH1F("fHistJetPt", "p_{t} [GeV/c]", 350, -100, 250, i);
352         fHistJetEtaPhi[i] =            BookTH2F("fHistJetEtaPhi", "#eta", "#phi", 100, -1, 1, 100, 0, TMath::TwoPi(), i);
353         fHistJetPtArea[i] =            BookTH2F("fHistJetPtArea", "p_{t} [GeV/c]", "Area", 350, -100, 250, 60, 0, 0.3, i);
354         fHistJetPtConstituents[i] =    BookTH2F("fHistJetPtConstituents", "p_{t} [GeV/c]", "Area", 350, -100, 250, 60, 0, 150, i);
355         fHistJetEtaRho[i] =            BookTH2F("fHistJetEtaRho", "#eta", "#rho", 100, -1, 1, 100, 0, 300, i);
356         // in plane and out of plane spectra
357         fHistJetPsiTPCPt[i] =          BookTH2F("fHistJetPsiTPCPt", "#phi_{jet} - #Psi_{2, TPC}", "p_{t} [GeV/c]", 100, 0., TMath::TwoPi(), 700, -100, 250, i);
358         fHistJetPsiVZEROAPt[i] =       BookTH2F("fHistJetPsiVZEROAPt", "#phi_{jet} - #Psi_{2, VZEROA}", "p_{t} [GeV/c]", 100, 0., TMath::TwoPi(), 700, -100, 250, i);
359         fHistJetPsiVZEROCPt[i] =       BookTH2F("fHistJetPsiVZEROCPt", "#phi_{jet} - #Psi_{V2, ZEROC}", "p_{t} [GeV/c]", 100, 0., TMath::TwoPi(), 700, -100, 250, i);
360         // phi minus psi
361         fHistDeltaPhi2VZEROA[i] =       BookTH1F("fHistDeltaPhi2VZEROA", "#phi_{jet} - #Psi_{2, VZEROA}", 100, 0, TMath::TwoPi(), i);
362         fHistDeltaPhi2VZEROC[i] =       BookTH1F("fHistDeltaPhi2VZEROC", "#phi_{jet} - #Psi_{2, VZEROC}", 100, 0, TMath::TwoPi(), i);
363         fHistDeltaPhi2TPC[i] =          BookTH1F("fHistDeltaPhi2TPC", "#phi_{jet} - #Psi_{2, TPC}", 100, 0, TMath::TwoPi(), i);
364         fHistDeltaPhi3VZEROA[i] =       BookTH1F("fHistDeltaPhi3VZEROA", "#phi_{jet} - #Psi_{2, VZEROA}", 100, 0, TMath::TwoPi(), i);
365         fHistDeltaPhi3VZEROC[i] =       BookTH1F("fHistDeltaPhi3VZEROC", "#phi_{jet} - #Psi_{2, VZEROC}", 100, 0, TMath::TwoPi(), i);
366         fHistDeltaPhi3TPC[i] =          BookTH1F("fHistDeltaPhi3TPC", "#phi_{jet} - #Psi_{2, TPC}", 100, 0, TMath::TwoPi(), i);
367
368         fProfV2Resolution[i] = new TProfile(Form("fProfV2Resolution_%i", i), Form("fProfV2Resolution_%i", i), 8, -0.5, 7.5);
369         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(1, "<cos(2(#Psi_{a} - #Psi_{b}))>");
370         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(2, "<cos(2(#Psi_{b} - #Psi_{a}))>");
371         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(3, "<cos(2(#Psi_{VZEROA} - #Psi_{VZEROC}))>");
372         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(4, "<cos(2(#Psi_{VZEROC} - #Psi_{VZEROA}))>");
373         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(5, "<cos(2(#Psi_{VZEROA} - #Psi_{TPC}))>");
374         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(6, "<cos(2(#Psi_{TPC} - #Psi_{VZEROA}))>");
375         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(7, "<cos(2(#Psi_{VZEROC} - #Psi_{TPC}))>");
376         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(8, "<cos(2(#Psi_{TPC} - #Psi_{VZEROC}))>");
377         fOutputList->Add(fProfV2Resolution[i]); 
378         fProfV3Resolution[i] = new TProfile(Form("fProfV3Resolution_%i", i), Form("fProfV3Resolution_%i", i), 8, -0.5, 7.5);
379         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(1, "<cos(3(#Psi_{a} - #Psi_{b}))>");
380         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(2, "<cos(3(#Psi_{b} - #Psi_{a}))>");
381         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(3, "<cos(3(#Psi_{VZEROA} - #Psi_{VZEROC}))>");
382         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(4, "<cos(3(#Psi_{VZEROC} - #Psi_{VZEROA}))>");
383         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(5, "<cos(3(#Psi_{VZEROA} - #Psi_{TPC}))>");
384         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(6, "<cos(3(#Psi_{TPC} - #Psi_{VZEROA}))>");
385         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(7, "<cos(3(#Psi_{VZEROC} - #Psi_{TPC}))>");
386         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(8, "<cos(3(#Psi_{TPC} - #Psi_{VZEROC}))>");
387         fOutputList->Add(fProfV3Resolution[i]); 
388     }
389     // cdf and pdf of chisquare distribution
390     fHistPvaluePDF = BookTH1F("fHistPvaluePDF", "PDF #chi^{2}", 500, 0, 1);
391     fHistPvalueCDF = BookTH1F("fHistPvalueCDF", "CDF #chi^{2}", 500, 0, 1);
392     // vn profile
393     Float_t temp[fCentralityClasses->GetSize()];
394     for(Int_t i(0); i < fCentralityClasses->GetSize(); i++) temp[i] = fCentralityClasses->At(i);
395     fProfV2 = new TProfile("fProfV2", "fProfV2", fCentralityClasses->GetSize()-1, temp);
396     fProfV3 = new TProfile("fProfV3", "fProfV3", fCentralityClasses->GetSize()-1, temp);
397     fOutputList->Add(fProfV2);
398     fOutputList->Add(fProfV3);
399
400     // analysis summary histrogram, saves all relevant analysis settigns
401     fHistAnalysisSummary = BookTH1F("fHistAnalysisSummary", "flag", 42, -0.5, 42.5);
402     fHistAnalysisSummary->GetXaxis()->SetBinLabel(1, "fJetRadius"); 
403     fHistAnalysisSummary->SetBinContent(1, fJetRadius);
404     fHistAnalysisSummary->GetXaxis()->SetBinLabel(2, "fPtBiasJetTrack");
405     fHistAnalysisSummary->SetBinContent(2, fPtBiasJetTrack);
406     fHistAnalysisSummary->GetXaxis()->SetBinLabel(3, "fPtBiasJetClus");
407     fHistAnalysisSummary->SetBinContent(3, fPtBiasJetClus);
408     fHistAnalysisSummary->GetXaxis()->SetBinLabel(4, "fJetPtCut");
409     fHistAnalysisSummary->SetBinContent(4, fJetPtCut);
410     fHistAnalysisSummary->GetXaxis()->SetBinLabel(5, "fJetAreaCut");
411     fHistAnalysisSummary->SetBinContent(5, fJetAreaCut);
412     fHistAnalysisSummary->GetXaxis()->SetBinLabel(6, "fPercAreaCut");
413     fHistAnalysisSummary->SetBinContent(6, fPercAreaCut);
414     fHistAnalysisSummary->GetXaxis()->SetBinLabel(7, "fAreaEmcCut");
415     fHistAnalysisSummary->SetBinContent(7, fAreaEmcCut);
416     fHistAnalysisSummary->GetXaxis()->SetBinLabel(8, "fJetMinEta");
417     fHistAnalysisSummary->SetBinContent(8, fJetMinEta);
418     fHistAnalysisSummary->GetXaxis()->SetBinLabel(9, "fJetMaxEta");
419     fHistAnalysisSummary->SetBinContent(9, fJetMaxEta);
420     fHistAnalysisSummary->GetXaxis()->SetBinLabel(10, "fJetMinPhi");
421     fHistAnalysisSummary->SetBinContent(10, fJetMinPhi);
422     fHistAnalysisSummary->GetXaxis()->SetBinLabel(11, "fJetMaxPhi");
423     fHistAnalysisSummary->SetBinContent(11, fJetMaxPhi);
424     fHistAnalysisSummary->GetXaxis()->SetBinLabel(12, "fMaxClusterPt");
425     fHistAnalysisSummary->SetBinContent(12, fMaxClusterPt);
426     fHistAnalysisSummary->GetXaxis()->SetBinLabel(13, "fMaxTrackPt");
427     fHistAnalysisSummary->SetBinContent(13, fMaxTrackPt);
428     fHistAnalysisSummary->GetXaxis()->SetBinLabel(14, "fLeadingHadronType");
429     fHistAnalysisSummary->SetBinContent(14, fLeadingHadronType);
430     fHistAnalysisSummary->GetXaxis()->SetBinLabel(15, "fAnaType");
431     fHistAnalysisSummary->SetBinContent(15, fAnaType);
432     fHistAnalysisSummary->GetXaxis()->SetBinLabel(16, "fForceBeamType");
433     fHistAnalysisSummary->SetBinContent(16, fForceBeamType);
434     fHistAnalysisSummary->GetXaxis()->SetBinLabel(17, "fMinCent");
435     fHistAnalysisSummary->SetBinContent(17, fMinCent);
436     fHistAnalysisSummary->GetXaxis()->SetBinLabel(18, "fMaxCent");
437     fHistAnalysisSummary->SetBinContent(18, fMaxCent);
438     fHistAnalysisSummary->GetXaxis()->SetBinLabel(19, "fMinVz");
439     fHistAnalysisSummary->SetBinContent(19, fMinVz);
440     fHistAnalysisSummary->GetXaxis()->SetBinLabel(20, "fMaxVz");
441     fHistAnalysisSummary->SetBinContent(20, fMaxVz);
442     fHistAnalysisSummary->GetXaxis()->SetBinLabel(21, "fOffTrigger");
443     fHistAnalysisSummary->SetBinContent(21, fOffTrigger);
444     fHistAnalysisSummary->GetXaxis()->SetBinLabel(22, "fClusPtCut");
445     fHistAnalysisSummary->SetBinContent(22, fClusPtCut);
446     fHistAnalysisSummary->GetXaxis()->SetBinLabel(23, "fTrackPtCut");
447     fHistAnalysisSummary->SetBinContent(23, fTrackPtCut);
448     fHistAnalysisSummary->GetXaxis()->SetBinLabel(24, "fTrackMinEta");
449     fHistAnalysisSummary->SetBinContent(24, fTrackMinEta);
450     fHistAnalysisSummary->GetXaxis()->SetBinLabel(25, "fTrackMaxEta");
451     fHistAnalysisSummary->SetBinContent(25, fTrackMaxEta);
452     fHistAnalysisSummary->GetXaxis()->SetBinLabel(26, "fTrackMinPhi");
453     fHistAnalysisSummary->SetBinContent(26, fTrackMinPhi);
454     fHistAnalysisSummary->GetXaxis()->SetBinLabel(27, "fTrackMaxPhi");
455     fHistAnalysisSummary->SetBinContent(27, fTrackMaxPhi);
456     fHistAnalysisSummary->GetXaxis()->SetBinLabel(28, "fClusTimeCutLow");
457     fHistAnalysisSummary->SetBinContent(28, fClusTimeCutLow);
458     fHistAnalysisSummary->GetXaxis()->SetBinLabel(29, "fClusTimeCutUp");
459     fHistAnalysisSummary->SetBinContent(29, fClusTimeCutUp);
460     fHistAnalysisSummary->GetXaxis()->SetBinLabel(30, "fMinPtTrackInEmcal");
461     fHistAnalysisSummary->SetBinContent(30, fMinPtTrackInEmcal);
462     fHistAnalysisSummary->GetXaxis()->SetBinLabel(31, "fEventPlaneVsEmcal");
463     fHistAnalysisSummary->SetBinContent(31, fEventPlaneVsEmcal);
464     fHistAnalysisSummary->GetXaxis()->SetBinLabel(32, "fMinEventPlane");
465     fHistAnalysisSummary->SetBinContent(32, fMaxEventPlane);
466     fHistAnalysisSummary->GetXaxis()->SetBinLabel(33, "fRandomConeRadius");
467     fHistAnalysisSummary->SetBinContent(33, fRandomConeRadius);
468     fHistAnalysisSummary->GetXaxis()->SetBinLabel(34, "fitModulationType");
469     fHistAnalysisSummary->SetBinContent(34, (int)fFitModulationType);
470     fHistAnalysisSummary->GetXaxis()->SetBinLabel(35, "runModeType");
471     fHistAnalysisSummary->SetBinContent(35, (int)fRunModeType);
472     fHistAnalysisSummary->GetXaxis()->SetBinLabel(36, "data type");
473     fHistAnalysisSummary->GetXaxis()->SetBinLabel(37, "iterator");
474     fHistAnalysisSummary->SetBinContent(37, 1.);
475     fHistAnalysisSummary->GetXaxis()->SetBinLabel(38, "fMinPvalue");
476     fHistAnalysisSummary->SetBinContent(38, fMinPvalue);
477     fHistAnalysisSummary->GetXaxis()->SetBinLabel(39, "fMaxPvalue");
478     fHistAnalysisSummary->SetBinContent(39, fMaxPvalue);
479     fHistAnalysisSummary->GetXaxis()->SetBinLabel(40, "fExcludeLeadingJetsFromFit");
480     fHistAnalysisSummary->SetBinContent(40, fExcludeLeadingJetsFromFit);
481     fHistAnalysisSummary->GetXaxis()->SetBinLabel(41, "fRebinSwapHistoOnTheFly");
482     fHistAnalysisSummary->SetBinContent(41, (int)fRebinSwapHistoOnTheFly);
483     fHistAnalysisSummary->GetXaxis()->SetBinLabel(42, "fUsePtWeight");
484     fHistAnalysisSummary->SetBinContent(42, (int)fUsePtWeight);
485
486     if(fFillQAHistograms) {
487         fHistRunnumbersEta = new TH2F("fHistRunnumbersEta", "fHistRunnumbersEta", 100, -.5, 99.5, 100, -1.1, 1.1);
488         fHistRunnumbersEta->Sumw2();
489         fOutputList->Add(fHistRunnumbersEta);
490         fHistRunnumbersPhi = new TH2F("fHistRunnumbersPhi", "fHistRunnumbersPhi", 100, -.5, 99.5, 100, -0.2, TMath::TwoPi()+0.2);
491         fHistRunnumbersPhi->Sumw2();
492         fOutputList->Add(fHistRunnumbersPhi);
493     }
494
495     fHistSwap = new TH1F("fHistSwap", "fHistSwap", 20, 0, TMath::TwoPi());
496     fHistSwap->Sumw2();
497     PostData(1, fOutputList);
498
499     switch (fRunModeType) {
500         case kLocal : {
501             fOutputListGood = new TList();
502             fOutputListGood->SetOwner(kTRUE);
503             fOutputListBad = new TList();
504             fOutputListBad->SetOwner(kTRUE);
505             PostData(2, fOutputListGood);
506             PostData(3, fOutputListBad);
507         } break;
508         default: break;
509     }
510 }
511 //_____________________________________________________________________________
512 Bool_t AliAnalysisTaskRhoVnModulation::Run()
513 {
514     // user exec: execute once for each event
515     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
516     if(!fInitialized) fInitialized = InitializeAnalysis();
517     // reject the event if expected data is missing
518     if(!PassesCuts(InputEvent())) return kFALSE;
519     if(!(fTracks||fJets||fRho)) return kFALSE;
520     if(!fCaloClusters && fDebug > 0) printf(" > Warning: couldn't retreive calo clusters! < \n");
521     // [0][0] psi2a     [1,0]   psi2c
522     // [0][1] psi3a     [1,1]   psi3c
523     Double_t vzero[2][2];
524     CalculateEventPlaneVZERO(vzero);
525     // [0] psi2         [1] psi3
526     // [2] psi2 a       [3] psi2 b
527     // [4] psi3 a       [5] psi3 b
528     Double_t tpc[6];
529     CalculateEventPlaneTPC(tpc);
530     // arrays which will hold the fit parameters
531     Double_t fitParameters[] = {0,0,0,0,0,0,0,0,0};
532     Double_t psi2(-1), psi3(-1), psi2b(-1), psi3b(-1);
533     switch (fDetectorType) {    // determine the detector type for the rho fit
534         case kTPC :     { psi2 = tpc[0];        psi3 = tpc[1]; }        break;
535         case kTPCSUB :  { psi2 = tpc[2];        psi3 = tpc[4];
536                           psi2b = tpc[3];       psi3b = tpc[5]; }       break;
537         case kVZEROA :  { psi2 = vzero[0][0];   psi3 = vzero[0][1]; }   break;  
538         case kVZEROC :  { psi2 = vzero[1][0];   psi3 = vzero[1][1]; }   break;
539         default : break;
540     }
541
542     switch (fFitModulationType) { // do the fits
543         case kNoFit : { fFitModulation->FixParameter(0, RhoVal()); } break;
544         case kV2 : {
545             if(CorrectRho(fitParameters, psi2, psi3, psi2b, psi3b)) {
546                 fProfV2->Fill(fCent, fFitModulation->GetParameter(3));
547                 CalculateEventPlaneResolution(vzero, tpc);
548             }
549         } break;
550         case kV3 : {
551             if(CorrectRho(fitParameters, psi2, psi3, psi2b, psi3b)) {
552                 fProfV3->Fill(fCent, fFitModulation->GetParameter(3));
553                 CalculateEventPlaneResolution(vzero, tpc);
554             }
555         } break;
556         case kUser : {
557              CorrectRho(fitParameters, psi2, psi3, psi2b, psi3b);
558         } break;
559         default : {
560             if(CorrectRho(fitParameters, psi2, psi3, psi2b, psi3b)) {
561                 fProfV2->Fill(fCent, fFitModulation->GetParameter(3));
562                 fProfV3->Fill(fCent, fFitModulation->GetParameter(7));
563                 CalculateEventPlaneResolution(vzero, tpc);
564             }
565         } break;
566     }
567     // fill a number of histograms 
568     FillHistogramsAfterSubtraction(vzero, tpc);
569
570     // send the output to the connected output container
571     PostData(1, fOutputList);
572     switch (fRunModeType) {
573         case kLocal : {
574             PostData(2, fOutputListGood);
575             PostData(3, fOutputListBad);
576         } break;
577         default: break;
578     }
579     return kTRUE;
580 }
581 //_____________________________________________________________________________
582 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneVZERO(Double_t vzero[2][2]) const 
583 {
584     // grab the UNCALIBRATED vzero event plane
585     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
586     Double_t qxa2(0), qya2(0), qxc2(0), qyc2(0);    // for psi2
587     Double_t qxa3(0), qya3(0), qxc3(0), qyc3(0);    // for psi3
588     for(Int_t iVZERO(0); iVZERO < 64; iVZERO++) {
589         Double_t phi(TMath::PiOver4()*(.5+iVZERO%8)), /* eta(0), */ weight(InputEvent()->GetVZEROEqMultiplicity(iVZERO));
590 //        (iVZERO<32) ? eta = -3.45+.5*(iVZERO/8) : eta = 4.8-.6*((iVZERO/8)-4);
591         if(iVZERO<32) {
592             qxa2 += weight*TMath::Cos(2.*phi);
593             qya2 += weight*TMath::Sin(2.*phi);
594             qxa3 += weight*TMath::Cos(3.*phi);
595             qya3 += weight*TMath::Sin(3.*phi);
596         }
597         else {
598             qxc2 += weight*TMath::Cos(2.*phi);
599             qyc2 += weight*TMath::Sin(2.*phi);
600             qxc3 += weight*TMath::Cos(3.*phi);
601             qyc3 += weight*TMath::Sin(3.*phi);
602        }
603     }
604     vzero[0][0] = .5*TMath::ATan2(qya2, qxa2);
605     vzero[1][0] = .5*TMath::ATan2(qyc2, qxc2);
606     vzero[0][1] = (1./3.)*TMath::ATan2(qya3, qxa3);
607     vzero[1][1] = (1./3.)*TMath::ATan2(qyc3, qxc3);
608 }
609 //_____________________________________________________________________________
610 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneTPC(Double_t* tpc)
611 {
612    // grab the TPC event plane
613    if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
614    fNAcceptedTracks = 0;                // reset the track counter
615    Double_t qx2(0), qy2(0);     // for psi2
616    Double_t qx3(0), qy3(0);     // for psi3
617    Double_t qx2a(0), qy2a(0), qx2b(0), qy2b(0); // for psi2 a and b
618    Double_t qx3a(0), qy3a(0), qx3b(0), qy3b(0); // for psi3 a and b
619    if(fTracks) {
620        Float_t excludeInEta[] = {-999, -999};
621        if(fExcludeLeadingJetsFromFit > 0 ) {    // remove the leading jet from ep estimate
622            AliEmcalJet* leadingJet[] = {0x0, 0x0};
623            static Int_t lJets[9999] = {-1};
624            GetSortedArray(lJets, fJets);
625            for(Int_t i(0); i < fJets->GetEntriesFast(); i++) {     // get the two leading jets
626                if (1 + i > fJets->GetEntriesFast()) break;
627                leadingJet[0] = static_cast<AliEmcalJet*>(fJets->At(lJets[i]));
628                leadingJet[1] = static_cast<AliEmcalJet*>(fJets->At(lJets[i+1]));
629                if(PassesCuts(leadingJet[0]) && PassesCuts(leadingJet[1])) break;
630            }
631            if(leadingJet[0] && leadingJet[1]) {
632                for(Int_t i(0); i < 2; i++) excludeInEta[i] = leadingJet[i]->Eta();
633            }
634        }
635        Int_t iTracks(fTracks->GetEntriesFast());
636        for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
637            AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
638            if(!PassesCuts(track) || track->Pt() < .15 || track->Pt() > 5.) continue;
639            if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta[0]) < fJetRadius*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - fJetRadius - fJetMaxEta ) > 0 )) continue;
640            fNAcceptedTracks++;
641            qx2+= TMath::Cos(2.*track->Phi());
642            qy2+= TMath::Sin(2.*track->Phi());
643            qx3+= TMath::Cos(3.*track->Phi());
644            qy3+= TMath::Sin(3.*track->Phi());
645            if(track->Eta() < 0) {       // A side, negative eta
646                qx2a+= TMath::Cos(2.*track->Phi());
647                qy2a+= TMath::Sin(2.*track->Phi());
648                qx3a+= TMath::Cos(3.*track->Phi());
649                qy3a+= TMath::Sin(3.*track->Phi());
650            } else {                     // B side, positive eta
651                qx2b+= TMath::Cos(2.*track->Phi());
652                qy2b+= TMath::Sin(2.*track->Phi());
653                qx3b+= TMath::Cos(3.*track->Phi());
654                qy3b+= TMath::Sin(3.*track->Phi());
655            }
656        }
657    }
658    tpc[0] = .5*TMath::ATan2(qy2, qx2);
659    tpc[1] = (1./3.)*TMath::ATan2(qy3, qx3);
660    tpc[2] = .5*TMath::ATan2(qy2a, qx2a);
661    tpc[3] = .5*TMath::ATan2(qy2b, qx2b);
662    tpc[4] = (1./3.)*TMath::ATan2(qy3a, qx3a);
663    tpc[5] = (1./3.)*TMath::ATan2(qy3b, qx3b);
664
665 //_____________________________________________________________________________
666 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneResolution(Double_t vzero[2][2], Double_t* tpc) const
667 {
668     // fill the profiles for the resolution parameters
669     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
670     fProfV2Resolution[fInCentralitySelection]->Fill(0., TMath::Cos(2.*(tpc[2] - tpc[3])));
671     fProfV2Resolution[fInCentralitySelection]->Fill(1., TMath::Cos(2.*(tpc[3] - tpc[2])));
672     fProfV2Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(2.*(vzero[0][0] - vzero[1][0])));
673     fProfV2Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(2.*(vzero[1][0] - vzero[0][0])));
674     fProfV2Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(2.*(vzero[0][0] - tpc[0])));
675     fProfV2Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(2.*(tpc[0] - vzero[0][0])));
676     fProfV2Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(2.*(vzero[1][0] - tpc[0])));
677     fProfV2Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(2.*(tpc[0] - vzero[1][0])));
678     fProfV3Resolution[fInCentralitySelection]->Fill(0., TMath::Cos(3.*(tpc[2] - tpc[3])));
679     fProfV3Resolution[fInCentralitySelection]->Fill(1., TMath::Cos(3.*(tpc[3] - tpc[2])));
680     fProfV3Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(3.*(vzero[0][0] - vzero[1][0])));
681     fProfV3Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(3.*(vzero[1][0] - vzero[0][0])));
682     fProfV3Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(3.*(vzero[0][0] - tpc[0])));
683     fProfV3Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(3.*(tpc[0] - vzero[0][0])));
684     fProfV3Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(3.*(vzero[1][0] - tpc[0])));
685     fProfV3Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(3.*(tpc[0] - vzero[1][0])));
686 }
687 //_____________________________________________________________________________
688 void AliAnalysisTaskRhoVnModulation::CalculateRandomCone(Float_t &pt, Float_t &eta, Float_t &phi, 
689         AliEmcalJet* jet, Bool_t randomize) const
690 {
691     // get a random cone
692     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
693     pt = 0; eta = 0; phi = 0;
694     Float_t etaJet(999), phiJet(999), dJet(999);        // no jet: same as jet very far away
695     if(jet) { // if a leading jet is given, use its kinematic properties
696         etaJet = jet->Eta();
697         phiJet = jet->Phi();
698     }
699     // force the random cones to at least be within detector acceptance
700     Float_t minPhi(fJetMinPhi), maxPhi(fJetMaxPhi);
701     if(maxPhi > TMath::TwoPi()) maxPhi = TMath::TwoPi();
702     if(minPhi < 0 ) minPhi = 0;
703     Float_t diffRcRJR(TMath::Abs(fRandomConeRadius-fJetRadius));
704     // construct a random cone and see if it's far away enough from the leading jet
705     Int_t attempts(1000);
706     while(kTRUE) {
707         attempts--;
708         eta = gRandom->Uniform(fJetMinEta+diffRcRJR, fJetMaxEta-diffRcRJR);
709         phi = gRandom->Uniform(minPhi, maxPhi);
710
711         dJet = TMath::Sqrt((etaJet-eta)*(etaJet-eta)+(phiJet-phi)*(phiJet-phi));
712         if(dJet > fMinDisanceRCtoLJ) break;
713         else if (attempts == 0) {
714             printf(" > No random cone after 1000 tries, giving up ... !\n");
715             return;
716         }
717     }
718     if(fTracks) {
719         Int_t iTracks(fTracks->GetEntriesFast());
720         for(Int_t i(0); i < iTracks; i++) {
721             AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
722             if(!PassesCuts(track)) continue;
723             Float_t etaTrack(track->Eta()), phiTrack(track->Phi()), ptTrack(track->Pt());
724             // if requested, randomize eta and phi to destroy any correlated fluctuations
725             if(randomize) {
726                 etaTrack = gRandom->Uniform(fTrackMinEta, fTrackMaxEta);
727                 phiTrack = gRandom->Uniform(minPhi, maxPhi);
728             }
729             // get distance from cone
730             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi + TMath::TwoPi())) phiTrack+=TMath::TwoPi();
731             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi - TMath::TwoPi())) phiTrack-=TMath::TwoPi();
732             if(TMath::Sqrt(TMath::Abs((etaTrack-eta)*(etaTrack-eta)+(phiTrack-phi)*(phiTrack-phi))) <= fRandomConeRadius) pt+=ptTrack;
733         }
734     }
735 }
736 //_____________________________________________________________________________
737 Bool_t AliAnalysisTaskRhoVnModulation::CorrectRho(Double_t* params, Double_t psi2, Double_t psi3, Double_t psi2b, Double_t psi3b) 
738 {
739     // get rho' -> rho(phi)
740     // two routines are available
741     //  [1]  fitting a fourier expansion to the de/dphi distribution
742     //  [2]  getting vn from a fourier series around dn/dphi (see below for info)
743     //  this function will return kTRUE if the fit passes a set of quality criteria
744     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
745     TString detector("");
746     switch (fDetectorType) {
747         case kTPC : detector+="TPC";
748             break;
749         case kTPCSUB : detector+="kTPCSUB";
750             break;
751         case kVZEROA : detector+="VZEROA";
752             break;
753         case kVZEROC : detector+="VZEROC";
754             break;
755         default: break;
756     }
757     Int_t iTracks(fTracks->GetEntriesFast());
758     Double_t excludeInEta[] = {-999, -999};
759     Double_t excludeInPhi[] = {-999, -999};
760     Double_t excludeInPt[]  = {-999, -999};
761     if(iTracks <= 0 || RhoVal() <= 0 ) return kFALSE;   // no use fitting an empty event ...
762     if(fExcludeLeadingJetsFromFit > 0 ) {
763         AliEmcalJet* leadingJet[] = {0x0, 0x0};
764         static Int_t lJets[9999] = {-1};
765         GetSortedArray(lJets, fJets);
766         for(Int_t i(0); i < fJets->GetEntriesFast(); i++) {     // get the two leading jets
767             if (1 + i > fJets->GetEntriesFast()) break;
768             leadingJet[0] = static_cast<AliEmcalJet*>(fJets->At(lJets[i]));
769             leadingJet[1] = static_cast<AliEmcalJet*>(fJets->At(lJets[i+1]));
770             if(PassesCuts(leadingJet[0]) && PassesCuts(leadingJet[1])) break;
771         }
772         if(leadingJet[0] && leadingJet[1]) {
773             for(Int_t i(0); i < 2; i++) {
774                 excludeInEta[i] = leadingJet[i]->Eta();
775                 excludeInPhi[i] = leadingJet[i]->Phi();
776                 excludeInPt[i]  = leadingJet[i]->Pt();
777             }
778         }
779     }
780     fHistSwap->Reset();                 // clear the histogram
781     TH1F _tempSwap;
782     if(fRebinSwapHistoOnTheFly) {
783         if(fNAcceptedTracks < 49) fNAcceptedTracks = 49;       // avoid aliasing effects
784         _tempSwap = TH1F("_tempSwap", "_tempSwap", TMath::CeilNint(TMath::Sqrt(fNAcceptedTracks)), 0, TMath::TwoPi());
785     }
786     else _tempSwap = *fHistSwap;         // now _tempSwap holds the desired histo
787     for(Int_t i(0); i < iTracks; i++) {
788             AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
789             if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta[0]) < fJetRadius*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - fJetRadius - fJetMaxEta ) > 0 )) continue;
790             if(!PassesCuts(track) || track->Pt() > 5 || track->Pt() < 0.15) continue;
791             if(fDetectorType == kTPCSUB && psi2 > -1000 && track->Eta() < 0 ) continue;
792             else if (fDetectorType == kTPCSUB && psi2 < -1000 && track->Eta() > 0 ) continue;
793             if(fUsePtWeight) _tempSwap.Fill(track->Phi(), track->Pt());
794             else _tempSwap.Fill(track->Phi());
795     }
796     for(Int_t i(0); i < _tempSwap.GetXaxis()->GetNbins(); i++) _tempSwap.SetBinError(1+i, TMath::Sqrt(_tempSwap.GetBinContent(1+i)));
797     fFitModulation->SetParameter(0, RhoVal());
798     switch (fFitModulationType) {
799         case kNoFit : { fFitModulation->FixParameter(0, RhoVal() ); 
800         } break;
801         case kV2 : { 
802             fFitModulation->FixParameter(4, psi2); 
803         } break;
804         case kV3 : { 
805             fFitModulation->FixParameter(4, psi3); 
806         } break;
807         case kCombined : { 
808             fFitModulation->FixParameter(4, psi2); 
809             fFitModulation->FixParameter(6, psi3);
810         } break;
811         case kFourierSeries : {
812             // in this approach, an explicit calculation will be made of vn = sqrt(xn^2+yn^2)
813             // where x[y] = Integrate[r(phi)cos[sin](n phi)dphi, 0, 2pi]
814             Double_t cos2(0), sin2(0), cos3(0), sin3(0), sumPt(0);
815             for(Int_t i(0); i < iTracks; i++) {
816                 AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
817                 if(!PassesCuts(track) || track->Pt() > 5 || track->Pt() < 0.15) continue;
818                 sumPt += track->Pt();
819                 cos2 += track->Pt()*TMath::Cos(2*PhaseShift(track->Phi()-psi2)); 
820                 sin2 += track->Pt()*TMath::Sin(2*PhaseShift(track->Phi()-psi2));
821                 cos3 += track->Pt()*TMath::Cos(3*PhaseShift(track->Phi()-psi3)); 
822                 sin3 += track->Pt()*TMath::Sin(3*PhaseShift(track->Phi()-psi3));
823             }
824             fFitModulation->SetParameter(3, TMath::Sqrt(cos2*cos2+sin2*sin2)/RhoVal());
825             fFitModulation->SetParameter(4, psi2);
826             fFitModulation->SetParameter(6, psi3);
827             fFitModulation->SetParameter(7, TMath::Sqrt(cos3*cos3+sin3*sin3)/RhoVal());
828         }
829         default : break;
830     }
831     if(fDetectorType == kTPCSUB && psi2 > -1000 ) { // do the magic for the subevent case
832         Double_t v2(fFitModulation->GetParameter(3)), v3(fFitModulation->GetParameter(7));
833         CorrectRho(params, -9999, -9999, psi2b, psi3b);
834         v2 += fFitModulation->GetParameter(3);
835         v3 += fFitModulation->GetParameter(7);
836         fFitModulation->SetParameter(3, v2/2.);
837         fFitModulation->SetParameter(7, v3/3.);
838     }
839     _tempSwap.Fit(fFitModulation, fFitModulationOptions.Data(), "", 0, TMath::TwoPi());
840     // the quality of the fit is evaluated from 1 - the cdf of the chi square distribution
841     Double_t CDF(1.-ChiSquareCDF(fFitModulation->GetNDF(), fFitModulation->GetChisquare()));
842 //    Double_t PDF(ChiSquarePDF(fFitModulation->GetNDF(), fFitModulation->GetChisquare()));
843     fHistPvalueCDF->Fill(CDF);
844 //    fHistPvaluePDF->Fill(PDF);
845     if(CDF > fMinPvalue && CDF < fMaxPvalue && ( fAbsVnHarmonics && fFitModulation->GetMinimum(0, TMath::TwoPi()) > 0)) { // fit quality
846         // for LOCAL didactic purposes, save the  best and the worst fits
847         // this routine can produce a lot of output histograms (it's not memory 'safe') and will not work on GRID 
848         // since the output will become unmergeable (i.e. different nodes may produce conflicting output)
849         switch (fRunModeType) {
850             case kLocal : {
851                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
852                 static Int_t didacticCounterBest(0);
853                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
854                 TF1* didactifFit = (TF1*)fFitModulation->Clone(Form("fit_%i_CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
855                 didacticProfile->GetListOfFunctions()->Add(didactifFit);
856                 fOutputListGood->Add(didacticProfile);
857                 didacticCounterBest++;
858                 TH2F* didacticSurface = BookTH2F(Form("surface_%s", didacticProfile->GetName()), "#phi", "#eta", 50, 0, TMath::TwoPi(), 50, -1, 1, -1, kFALSE);
859                 for(Int_t i(0); i < iTracks; i++) {
860                     AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
861                     if(PassesCuts(track)) {
862                         if(fUsePtWeight) didacticSurface->Fill(track->Phi(), track->Eta(), track->Pt());
863                         else didacticSurface->Fill(track->Phi(), track->Eta());
864                     }
865                 }
866                 if(fExcludeLeadingJetsFromFit) {       // visualize the excluded region
867                     TF2 *f2 = new TF2(Form("%s_LJ", didacticSurface->GetName()),"[0]*TMath::Gaus(x,[1],[2])*TMath::Gaus(y,[3],[4])", 0, TMath::TwoPi(), -1, 1);
868                     f2->SetParameters(excludeInPt[0]/3.,excludeInPhi[0],.1,excludeInEta[0],.1);
869                     didacticSurface->GetListOfFunctions()->Add(f2);
870                     TF2 *f3 = new TF2(Form("%s_NLJ", didacticSurface->GetName()),"[0]*TMath::Gaus(x,[1],[2])*TMath::Gaus(y,[3],[4])", 0, TMath::TwoPi(), -1, 1);
871                     f3->SetParameters(excludeInPt[1]/3.,excludeInPhi[1],.1,excludeInEta[1],.1);
872                     f3->SetLineColor(kGreen);
873                     didacticSurface->GetListOfFunctions()->Add(f3);
874                 }
875                 fOutputListGood->Add(didacticSurface);
876             } break;
877             default : break;
878         }
879     } else {    // if the fit is of poor quality revert to the original rho estimate
880         switch (fRunModeType) { // again see if we want to save the fit
881             case kLocal : {
882                 static Int_t didacticCounterWorst(0);
883                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
884                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data() ));
885                 TF1* didactifFit = (TF1*)fFitModulation->Clone(Form("fit_%i_p_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data()));
886                 didacticProfile->GetListOfFunctions()->Add(didactifFit);
887                 fOutputListBad->Add(didacticProfile);
888                 didacticCounterWorst++;
889                 } break;
890             default : break;
891         }
892         switch (fFitModulationType) {
893             case kNoFit : break;        // nothing to do
894             case kUser : break;         // FIXME not implemented yet
895             case kCombined : fFitModulation->SetParameter(7, 0);        // no break
896             case kFourierSeries : fFitModulation->SetParameter(7, 0);   // no break
897             default : { // needs to be done if there was a poor fit
898                  fFitModulation->SetParameter(3, 0);
899                  fFitModulation->SetParameter(0, RhoVal());
900             } break;
901         }
902         return kFALSE;  // return false if the fit is rejected
903     }
904     for(Int_t i(0); i < fFitModulation->GetNpar(); i++) params[i] = fFitModulation->GetParameter(i);
905     return kTRUE;
906 }
907 //_____________________________________________________________________________
908 Bool_t AliAnalysisTaskRhoVnModulation::PassesCuts(AliVEvent* event)
909 {
910     // event cuts
911     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
912     if(!event) return kFALSE;
913     if(TMath::Abs(InputEvent()->GetPrimaryVertex()->GetZ()) > 10.) return kFALSE;
914     // aod and esd specific checks
915     switch (fDataType) {
916        case kESD: {
917             AliESDEvent* esdEvent = static_cast<AliESDEvent*>(InputEvent());
918             if( (!esdEvent) || (TMath::Abs(esdEvent->GetPrimaryVertexSPD()->GetZ() - esdEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
919        } break;
920        case kAOD: {
921             AliAODEvent* aodEvent = static_cast<AliAODEvent*>(InputEvent());
922             if( (!aodEvent) || (TMath::Abs(aodEvent->GetPrimaryVertexSPD()->GetZ() - aodEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
923        } break;
924        default: break;
925     }
926     fCent = InputEvent()->GetCentrality()->GetCentralityPercentile("V0M");
927     if(fCent <= 0 || fCent >= 100 || TMath::Abs(fCent-InputEvent()->GetCentrality()->GetCentralityPercentile("TRK")) > 5.) return kFALSE;
928     // determine centrality class
929     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) {
930         if(fCent > fCentralityClasses->At(i) && fCent < fCentralityClasses->At(1+i)) {
931             fInCentralitySelection = i;
932             break; }
933     } 
934     if(fFillQAHistograms) FillQAHistograms(event);
935     return kTRUE;
936 }
937 //_____________________________________________________________________________
938 Bool_t AliAnalysisTaskRhoVnModulation::PassesCuts(const AliVCluster* cluster) const
939 {
940     // cluster cuts
941     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
942     if(!cluster) return kFALSE;
943     return kTRUE;
944 }
945 //_____________________________________________________________________________
946 void AliAnalysisTaskRhoVnModulation::FillHistogramsAfterSubtraction(Double_t vzero[2][2], Double_t* tpc) const
947 {
948     // fill histograms 
949     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
950     FillTrackHistograms();
951     /* FillClusterHistograms(); */
952     FillJetHistograms(vzero, tpc); 
953     /* FillCorrectedClusterHistograms(); */
954     FillEventPlaneHistograms(vzero, tpc);
955     FillRhoHistograms();
956     switch (fDetectorType) {    // determine the detector type for the rho fit
957         case kTPC :     { FillDeltaPtHistograms(tpc[0], tpc[1]); }              break;
958         case kTPCSUB :  { FillDeltaPtHistograms(tpc[2], tpc[4]);
959                           FillDeltaPtHistograms(tpc[3], tpc[5]); }              break;
960         case kVZEROA :  { FillDeltaPtHistograms(vzero[0][0], vzero[0][1]); }    break;
961         case kVZEROC :  { FillDeltaPtHistograms(vzero[1][0], vzero[1][1]); }    break;
962         default : break;
963     }
964     FillDeltaPhiHistograms(vzero, tpc);
965 }
966 //_____________________________________________________________________________
967 void AliAnalysisTaskRhoVnModulation::FillTrackHistograms() const
968 {
969     // fill track histograms
970     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
971     Int_t iTracks(fTracks->GetEntriesFast());
972     for(Int_t i(0); i < iTracks; i++) {
973         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
974         if(!PassesCuts(track)) continue;
975         fHistPicoTrackPt[fInCentralitySelection]->Fill(track->Pt());
976         if(fFillQAHistograms) FillQAHistograms(track);
977     }
978 }
979 //_____________________________________________________________________________
980 void AliAnalysisTaskRhoVnModulation::FillClusterHistograms() const
981 {
982     // fill cluster histograms
983     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
984     /* Int_t iClusters(fCaloClusters->GetEntriesFast());
985     for(Int_t i(0); i < iClusters; i++) {
986         AliVCluster* cluster = static_cast<AliVCluster*>(fCaloClusters->At(iClusters));
987         if (!PassesCuts(cluster)) continue;
988         TLorentzVector clusterLorentzVector;
989         cluster->GetMomentum(clusterLorentzVector, const_cast<Double_t*>(fVertex));
990         fHistClusterPt[fInCentralitySelection]->Fill(clusterLorentzVector.Pt());
991         fHistClusterEta[fInCentralitySelection]->Fill(clusterLorentzVector.Eta());
992         fHistClusterPhi[fInCentralitySelection]->Fill(clusterLorentzVector.Phi());
993     }
994     return; */
995 }
996 //_____________________________________________________________________________
997 void AliAnalysisTaskRhoVnModulation::FillCorrectedClusterHistograms() const
998 {
999     // fill clusters after hadronic correction FIXME implement
1000     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1001 }
1002 //_____________________________________________________________________________
1003 void AliAnalysisTaskRhoVnModulation::FillEventPlaneHistograms(Double_t vzero[2][2], Double_t* tpc) const
1004 {
1005     // fill event plane histograms
1006     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1007     fHistPsiControl->Fill(0.5, vzero[0][0]);    // vzero a psi2
1008     fHistPsiControl->Fill(1.5, vzero[1][0]);    // vzero c psi2
1009     fHistPsiControl->Fill(2.5, tpc[0]);         // tpc psi 2
1010     fHistPsiControl->Fill(3.5, tpc[2]);         // tpc sub a psi 2
1011     fHistPsiControl->Fill(4.5, tpc[3]);         // tpc sub b psi 2
1012     fHistPsiControl->Fill(5.5, vzero[0][1]);    // vzero a psi3
1013     fHistPsiControl->Fill(6.5, vzero[1][1]);    // vzero b psi3
1014     fHistPsiControl->Fill(7.5, tpc[1]);         // tpc psi 3
1015     fHistPsiControl->Fill(8.5, tpc[4]);         // tpc sub a psi3
1016     fHistPsiControl->Fill(9.5, tpc[5]);         // tpc sub b psi3
1017     fHistPsiVZEROA->Fill(vzero[0][0]);
1018     fHistPsiVZEROC->Fill(vzero[1][0]);
1019     fHistPsiTPC->Fill(tpc[0]);
1020     fHistPsiTPCSUBA->Fill(tpc[2]);
1021     fHistPsiTPCSUBB->Fill(tpc[3]);
1022     fHistPsiSpread->Fill(0.5, TMath::Abs(vzero[0][0]-vzero[1][0]));
1023     fHistPsiSpread->Fill(1.5, TMath::Abs(vzero[0][0]-tpc[0]));
1024     fHistPsiSpread->Fill(2.5, TMath::Abs(vzero[1][0]-tpc[0]));
1025     fHistPsiSpread->Fill(3.5, TMath::Abs(tpc[2]-tpc[3]));
1026 }
1027 //_____________________________________________________________________________
1028 void AliAnalysisTaskRhoVnModulation::FillRhoHistograms() const
1029 {
1030     // fill rho histograms
1031     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1032     fHistRhoPackage[fInCentralitySelection]->Fill(RhoVal());    // save the rho estimate from the emcal jet package
1033     // get multiplicity FIXME inefficient
1034     Int_t iTracks(fTracks->GetEntriesFast()), mult(0), iJets(fJets->GetEntriesFast());
1035     for(Int_t i(0); i < iTracks; i ++) { if(PassesCuts(static_cast<AliVTrack*>(fTracks->At(i)))) mult++; }
1036     Double_t rho(RhoVal(TMath::Pi(), TMath::Pi(), fRho->GetVal()));
1037     fHistRho[fInCentralitySelection]->Fill(rho);
1038     fHistRhoVsMult->Fill(mult, rho);
1039     fHistRhoVsCent->Fill(fCent, rho);
1040     for(Int_t i(0); i < iJets; i++) {
1041         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1042         if(!PassesCuts(jet)) continue;
1043         fHistRhoAVsMult->Fill(mult, rho * jet->Area());
1044         fHistRhoAVsCent->Fill(fCent, rho * jet->Area());
1045     }
1046 }
1047 //_____________________________________________________________________________
1048 void AliAnalysisTaskRhoVnModulation::FillDeltaPtHistograms(Double_t psi2, Double_t psi3) const
1049 {
1050     // fill delta pt histograms
1051     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1052     Int_t i(0), maxCones(20);
1053     AliEmcalJet* leadingJet(0x0);
1054     static Int_t sJets[9999] = {-1};
1055     GetSortedArray(sJets, fJets);
1056     do { // get the leading jet 
1057         leadingJet = static_cast<AliEmcalJet*>(fJets->At(sJets[i]));
1058         i++;
1059     }
1060     while (!PassesCuts(leadingJet)&&i<fJets->GetEntriesFast()); 
1061     if(!leadingJet && fDebug > 0) printf(" > failed to retrieve leading jet ! < \n");
1062     const Float_t areaRC = fRandomConeRadius*fRandomConeRadius*TMath::Pi();
1063     // we're retrieved the leading jet, now get a random cone
1064     for(i = 0; i < maxCones; i++) {
1065        Float_t pt(0), eta(0), phi(0);
1066        // get a random cone without constraints on leading jet position
1067        CalculateRandomCone(pt, eta, phi, 0x0);
1068        if(pt > 0) {
1069            fHistRCPhiEta[fInCentralitySelection]->Fill(phi, eta);
1070            fHistRhoVsRCPt[fInCentralitySelection]->Fill(pt, RhoVal(phi, fJetRadius, fRho->GetVal())*areaRC);
1071            fHistRCPt[fInCentralitySelection]->Fill(pt);
1072            fHistDeltaPtDeltaPhi2[fInCentralitySelection]->Fill(PhaseShift(phi-psi2), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1073            fHistDeltaPtDeltaPhi3[fInCentralitySelection]->Fill(PhaseShift(phi-psi3), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1074        }
1075        // get a random cone excluding leading jet area
1076        CalculateRandomCone(pt, eta, phi, leadingJet);
1077        if(pt > 0) {
1078            fHistRCPhiEtaExLJ[fInCentralitySelection]->Fill(phi, eta);
1079            fHistRhoVsRCPtExLJ[fInCentralitySelection]->Fill(pt, RhoVal(phi, fJetRadius, fRho->GetVal())*areaRC);
1080            fHistRCPtExLJ[fInCentralitySelection]->Fill(pt);
1081            fHistDeltaPtDeltaPhi2ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi2), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1082            fHistDeltaPtDeltaPhi3ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi3), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1083        }
1084        // get a random cone in an event with randomized phi and eta
1085        CalculateRandomCone(pt, eta, phi, 0x0, kTRUE);
1086        if( pt > 0) {
1087            fHistRCPhiEtaRand[fInCentralitySelection]->Fill(phi, eta);
1088            fHistRhoVsRCPtRand[fInCentralitySelection]->Fill(pt, RhoVal(phi, fJetRadius, fRho->GetVal())*areaRC);
1089            fHistRCPtRand[fInCentralitySelection]->Fill(pt);
1090            fHistDeltaPtDeltaPhi2Rand[fInCentralitySelection]->Fill(PhaseShift(phi-psi2), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1091            fHistDeltaPtDeltaPhi3Rand[fInCentralitySelection]->Fill(PhaseShift(phi-psi3), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1092        }
1093     } 
1094 }
1095 //_____________________________________________________________________________
1096 void AliAnalysisTaskRhoVnModulation::FillJetHistograms(Double_t vzero[2][2], Double_t* tpc) const
1097 {
1098     // fill jet histograms
1099     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1100     Int_t iJets(fJets->GetEntriesFast());
1101     for(Int_t i(0); i < iJets; i++) {
1102         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1103         if(!PassesCuts(jet)) continue;
1104         Double_t pt(jet->Pt()), area(jet->Area()), eta(jet->Eta()), phi(jet->Phi());
1105         Double_t rho(RhoVal(phi, fJetRadius, fRho->GetVal()));
1106         fHistJetPtRaw[fInCentralitySelection]->Fill(pt);
1107         fHistJetPt[fInCentralitySelection]->Fill(pt-area*rho);
1108         fHistJetEtaPhi[fInCentralitySelection]->Fill(eta, phi);
1109         fHistJetPtArea[fInCentralitySelection]->Fill(pt-area*rho, area);
1110         fHistJetPsiTPCPt[fInCentralitySelection]->Fill(PhaseShift(phi-tpc[0]), pt-area*rho);
1111         fHistJetPsiVZEROAPt[fInCentralitySelection]->Fill(PhaseShift(phi-vzero[0][0]), pt-area*rho);
1112         fHistJetPsiVZEROCPt[fInCentralitySelection]->Fill(PhaseShift(phi-vzero[1][0]), pt-area*rho);
1113         fHistJetPtConstituents[fInCentralitySelection]->Fill(pt-area*rho, jet->Nch());
1114         fHistJetEtaRho[fInCentralitySelection]->Fill(eta, pt/area);
1115     }
1116 }
1117 //_____________________________________________________________________________
1118 void AliAnalysisTaskRhoVnModulation::FillDeltaPhiHistograms(Double_t vzero[2][2], Double_t* tpc) const
1119 {
1120    // fill phi minus psi histograms
1121    if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1122    if(fTracks) {
1123        Int_t iTracks(fTracks->GetEntriesFast());
1124        for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
1125            AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
1126            if(!PassesCuts(track)) continue;
1127            fHistDeltaPhi2VZEROA[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-vzero[0][0]));
1128            fHistDeltaPhi2VZEROC[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-vzero[1][0]));
1129            fHistDeltaPhi2TPC[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-tpc[0]));
1130            fHistDeltaPhi3VZEROA[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-vzero[0][1]));
1131            fHistDeltaPhi3VZEROC[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-vzero[1][1]));
1132            fHistDeltaPhi3TPC[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-tpc[1]));
1133        }
1134    }
1135 }
1136 //_____________________________________________________________________________
1137 void AliAnalysisTaskRhoVnModulation::FillQAHistograms(AliVTrack* vtrack) const
1138 {
1139     // fill qa histograms for pico tracks
1140     if(!vtrack) return;
1141     AliPicoTrack* track = static_cast<AliPicoTrack*>(vtrack);
1142     fHistRunnumbersPhi->Fill(fMappedRunNumber, track->Phi());
1143     fHistRunnumbersEta->Fill(fMappedRunNumber, track->Eta());
1144     Int_t type((int)(track->GetTrackType()));
1145     switch (type) {
1146         case 0:
1147            fHistPicoCat1[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1148            break;
1149         case 1:
1150            fHistPicoCat2[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1151            break;
1152         case 2:
1153            fHistPicoCat3[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1154            break;
1155         default: break;
1156     }
1157 }
1158 //_____________________________________________________________________________
1159 void AliAnalysisTaskRhoVnModulation::FillQAHistograms(AliVEvent* vevent) 
1160 {
1161     // fill qa histograms for events
1162     if(!vevent) return;
1163     fHistVertexz->Fill(vevent->GetPrimaryVertex()->GetZ());
1164     fHistCentrality->Fill(fCent);
1165     Int_t runNumber(InputEvent()->GetRunNumber());
1166     Int_t runs[] = {167813, 167988, 168066, 168068, 168069, 168076, 168104, 168212, 168311, 168322, 168325, 168341, 168361, 168362, 168458, 168460, 168461, 168992, 169091, 169094, 169138, 169143, 169167, 169417, 169835, 169837, 169838, 169846, 169855, 169858, 169859, 169923, 169956, 170027, 170036, 170081, 169975, 169981, 170038, 170040, 170083, 170084, 170085, 170088, 170089, 170091, 170152, 170155, 170159, 170163, 170193, 170195, 170203, 170204, 170205, 170228, 170230, 170264, 170268, 170269, 170270, 170306, 170308, 170309};
1167     for(fMappedRunNumber = 0; fMappedRunNumber < 64; fMappedRunNumber++) {
1168         if(runs[fMappedRunNumber]==runNumber) break;
1169     }
1170 }
1171 //_____________________________________________________________________________
1172 void AliAnalysisTaskRhoVnModulation::Terminate(Option_t *)
1173 {
1174     // terminate
1175     switch (fRunModeType) {
1176         case kLocal : {
1177         printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1178         if(fFillQAHistograms) {
1179             Int_t runs[] = {167813, 167988, 168066, 168068, 168069, 168076, 168104, 168212, 168311, 168322, 168325, 168341, 168361, 168362, 168458, 168460, 168461, 168992, 169091, 169094, 169138, 169143, 169167, 169417, 169835, 169837, 169838, 169846, 169855, 169858, 169859, 169923, 169956, 170027, 170036, 170081, 169975, 169981, 170038, 170040, 170083, 170084, 170085, 170088, 170089, 170091, 170152, 170155, 170159, 170163, 170193, 170195, 170203, 170204, 170205, 170228, 170230, 170264, 170268, 170269, 170270, 170306, 170308, 170309};
1180             for(Int_t i(0); i < 64; i++) { 
1181                 fHistRunnumbersPhi->GetXaxis()->SetBinLabel(i+1, Form("%i", runs[i]));
1182                 fHistRunnumbersEta->GetXaxis()->SetBinLabel(i+1, Form("%i", runs[i]));
1183             }
1184             fHistRunnumbersPhi->GetXaxis()->SetBinLabel(65, "undetermined");
1185             fHistRunnumbersEta->GetXaxis()->SetBinLabel(65, "undetermined");
1186         }
1187         AliAnalysisTaskRhoVnModulation::Dump();
1188         for(Int_t i(0); i < fHistAnalysisSummary->GetXaxis()->GetNbins(); i++) printf( " > flag: %s \t content %.2f \n", fHistAnalysisSummary->GetXaxis()->GetBinLabel(1+i), fHistAnalysisSummary->GetBinContent(1+i));
1189         } break;
1190         default : break;
1191     }
1192 }
1193 //_____________________________________________________________________________