]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskRhoVnModulation.cxx
Reduce memory usage (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.), fUseV0EventPlaneFromHeader(kFALSE), fSetPtSub(kFALSE), 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.), fUseV0EventPlaneFromHeader(kFALSE), fSetPtSub(kFALSE), 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]", 50, 0, TMath::Pi(), 100, -50, 100, i);
339         fHistDeltaPtDeltaPhi3[i] =     BookTH2F("fHistDeltaPtDeltaPhi3", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 50, 0, TMath::TwoPi()/3., 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]", 50, 0, TMath::Pi(), 100, -50, 100, i);
344         fHistDeltaPtDeltaPhi3ExLJ[i] = BookTH2F("fHistDeltaPtDeltaPhi3ExLJ", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 50, 0, TMath::TwoPi()/3., 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]", 50, 0, TMath::Pi(), 100, -50, 100, i); */
348         /* fHistDeltaPtDeltaPhi3Rand[i] =  BookTH2F("fHistDeltaPtDeltaPhi3Rand", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 50, 0, TMath::TwoPi()/3., 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]", 50, 0., TMath::Pi(), 700, -100, 250, i);
358         fHistJetPsiVZEROAPt[i] =       BookTH2F("fHistJetPsiVZEROAPt", "#phi_{jet} - #Psi_{2, VZEROA}", "p_{t} [GeV/c]", 50, 0., TMath::Pi(), 700, -100, 250, i);
359         fHistJetPsiVZEROCPt[i] =       BookTH2F("fHistJetPsiVZEROCPt", "#phi_{jet} - #Psi_{V2, ZEROC}", "p_{t} [GeV/c]", 50, 0., TMath::Pi(), 700, -100, 250, i);
360         // phi minus psi
361         fHistDeltaPhi2VZEROA[i] =       BookTH1F("fHistDeltaPhi2VZEROA", "#phi_{jet} - #Psi_{2, VZEROA}", 50, 0, TMath::Pi(), i);
362         fHistDeltaPhi2VZEROC[i] =       BookTH1F("fHistDeltaPhi2VZEROC", "#phi_{jet} - #Psi_{2, VZEROC}", 50, 0, TMath::Pi(), i);
363         fHistDeltaPhi2TPC[i] =          BookTH1F("fHistDeltaPhi2TPC", "#phi_{jet} - #Psi_{2, TPC}", 50, 0, TMath::Pi(), i);
364         fHistDeltaPhi3VZEROA[i] =       BookTH1F("fHistDeltaPhi3VZEROA", "#phi_{jet} - #Psi_{2, VZEROA}", 50, 0, TMath::TwoPi()/3., i);
365         fHistDeltaPhi3VZEROC[i] =       BookTH1F("fHistDeltaPhi3VZEROC", "#phi_{jet} - #Psi_{2, VZEROC}", 50, 0, TMath::TwoPi()/3., i);
366         fHistDeltaPhi3TPC[i] =          BookTH1F("fHistDeltaPhi3TPC", "#phi_{jet} - #Psi_{2, TPC}", 50, 0, TMath::TwoPi()/3., 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     // get the vzero event plane
585     if(fUseV0EventPlaneFromHeader) {    // use the vzero from the header
586         Double_t a(0), b(0), c(0), d(0), e(0), f(0), g(0), h(0);
587         vzero[0][0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 2, a, b);
588         vzero[1][0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 2, c, d);
589         vzero[0][1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 3, e, f);
590         vzero[1][1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 3, g, h);
591         return;
592     }
593     // grab the vzero event plane without recentering
594     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
595     Double_t qxa2(0), qya2(0), qxc2(0), qyc2(0);    // for psi2
596     Double_t qxa3(0), qya3(0), qxc3(0), qyc3(0);    // for psi3
597     for(Int_t iVZERO(0); iVZERO < 64; iVZERO++) {
598         Double_t phi(TMath::PiOver4()*(.5+iVZERO%8)), /* eta(0), */ weight(InputEvent()->GetVZEROEqMultiplicity(iVZERO));
599 //        (iVZERO<32) ? eta = -3.45+.5*(iVZERO/8) : eta = 4.8-.6*((iVZERO/8)-4);
600         if(iVZERO<32) {
601             qxa2 += weight*TMath::Cos(2.*phi);
602             qya2 += weight*TMath::Sin(2.*phi);
603             qxa3 += weight*TMath::Cos(3.*phi);
604             qya3 += weight*TMath::Sin(3.*phi);
605         }
606         else {
607             qxc2 += weight*TMath::Cos(2.*phi);
608             qyc2 += weight*TMath::Sin(2.*phi);
609             qxc3 += weight*TMath::Cos(3.*phi);
610             qyc3 += weight*TMath::Sin(3.*phi);
611        }
612     }
613     vzero[0][0] = .5*TMath::ATan2(qya2, qxa2);
614     vzero[1][0] = .5*TMath::ATan2(qyc2, qxc2);
615     vzero[0][1] = (1./3.)*TMath::ATan2(qya3, qxa3);
616     vzero[1][1] = (1./3.)*TMath::ATan2(qyc3, qxc3);
617 }
618 //_____________________________________________________________________________
619 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneTPC(Double_t* tpc)
620 {
621    // grab the TPC event plane
622    if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
623    fNAcceptedTracks = 0;                // reset the track counter
624    Double_t qx2(0), qy2(0);     // for psi2
625    Double_t qx3(0), qy3(0);     // for psi3
626    Double_t qx2a(0), qy2a(0), qx2b(0), qy2b(0); // for psi2 a and b
627    Double_t qx3a(0), qy3a(0), qx3b(0), qy3b(0); // for psi3 a and b
628    if(fTracks) {
629        Float_t excludeInEta[] = {-999, -999};
630        if(fExcludeLeadingJetsFromFit > 0 ) {    // remove the leading jet from ep estimate
631            AliEmcalJet* leadingJet[] = {0x0, 0x0};
632            static Int_t lJets[9999] = {-1};
633            GetSortedArray(lJets, fJets);
634            for(Int_t i(0); i < fJets->GetEntriesFast(); i++) {     // get the two leading jets
635                if (1 + i > fJets->GetEntriesFast()) break;
636                leadingJet[0] = static_cast<AliEmcalJet*>(fJets->At(lJets[i]));
637                leadingJet[1] = static_cast<AliEmcalJet*>(fJets->At(lJets[i+1]));
638                if(PassesCuts(leadingJet[0]) && PassesCuts(leadingJet[1])) break;
639            }
640            if(leadingJet[0] && leadingJet[1]) {
641                for(Int_t i(0); i < 2; i++) excludeInEta[i] = leadingJet[i]->Eta();
642            }
643        }
644        Int_t iTracks(fTracks->GetEntriesFast());
645        for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
646            AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
647            if(!PassesCuts(track) || track->Pt() < .15 || track->Pt() > 5.) continue;
648            if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta[0]) < fJetRadius*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - fJetRadius - fJetMaxEta ) > 0 )) continue;
649            fNAcceptedTracks++;
650            qx2+= TMath::Cos(2.*track->Phi());
651            qy2+= TMath::Sin(2.*track->Phi());
652            qx3+= TMath::Cos(3.*track->Phi());
653            qy3+= TMath::Sin(3.*track->Phi());
654            if(track->Eta() < 0) {       // A side, negative eta
655                qx2a+= TMath::Cos(2.*track->Phi());
656                qy2a+= TMath::Sin(2.*track->Phi());
657                qx3a+= TMath::Cos(3.*track->Phi());
658                qy3a+= TMath::Sin(3.*track->Phi());
659            } else {                     // B side, positive eta
660                qx2b+= TMath::Cos(2.*track->Phi());
661                qy2b+= TMath::Sin(2.*track->Phi());
662                qx3b+= TMath::Cos(3.*track->Phi());
663                qy3b+= TMath::Sin(3.*track->Phi());
664            }
665        }
666    }
667    tpc[0] = .5*TMath::ATan2(qy2, qx2);
668    tpc[1] = (1./3.)*TMath::ATan2(qy3, qx3);
669    tpc[2] = .5*TMath::ATan2(qy2a, qx2a);
670    tpc[3] = .5*TMath::ATan2(qy2b, qx2b);
671    tpc[4] = (1./3.)*TMath::ATan2(qy3a, qx3a);
672    tpc[5] = (1./3.)*TMath::ATan2(qy3b, qx3b);
673
674 //_____________________________________________________________________________
675 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneResolution(Double_t vzero[2][2], Double_t* tpc) const
676 {
677     // fill the profiles for the resolution parameters
678     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
679     fProfV2Resolution[fInCentralitySelection]->Fill(0., TMath::Cos(2.*(tpc[2] - tpc[3])));
680     fProfV2Resolution[fInCentralitySelection]->Fill(1., TMath::Cos(2.*(tpc[3] - tpc[2])));
681     fProfV2Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(2.*(vzero[0][0] - vzero[1][0])));
682     fProfV2Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(2.*(vzero[1][0] - vzero[0][0])));
683     fProfV2Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(2.*(vzero[0][0] - tpc[0])));
684     fProfV2Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(2.*(tpc[0] - vzero[0][0])));
685     fProfV2Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(2.*(vzero[1][0] - tpc[0])));
686     fProfV2Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(2.*(tpc[0] - vzero[1][0])));
687     fProfV3Resolution[fInCentralitySelection]->Fill(0., TMath::Cos(3.*(tpc[2] - tpc[3])));
688     fProfV3Resolution[fInCentralitySelection]->Fill(1., TMath::Cos(3.*(tpc[3] - tpc[2])));
689     fProfV3Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(3.*(vzero[0][0] - vzero[1][0])));
690     fProfV3Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(3.*(vzero[1][0] - vzero[0][0])));
691     fProfV3Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(3.*(vzero[0][0] - tpc[0])));
692     fProfV3Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(3.*(tpc[0] - vzero[0][0])));
693     fProfV3Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(3.*(vzero[1][0] - tpc[0])));
694     fProfV3Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(3.*(tpc[0] - vzero[1][0])));
695 }
696 //_____________________________________________________________________________
697 void AliAnalysisTaskRhoVnModulation::CalculateRandomCone(Float_t &pt, Float_t &eta, Float_t &phi, 
698         AliEmcalJet* jet, Bool_t randomize) const
699 {
700     // get a random cone
701     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
702     pt = 0; eta = 0; phi = 0;
703     Float_t etaJet(999), phiJet(999), dJet(999);        // no jet: same as jet very far away
704     if(jet) { // if a leading jet is given, use its kinematic properties
705         etaJet = jet->Eta();
706         phiJet = jet->Phi();
707     }
708     // force the random cones to at least be within detector acceptance
709     Float_t minPhi(fJetMinPhi), maxPhi(fJetMaxPhi);
710     if(maxPhi > TMath::TwoPi()) maxPhi = TMath::TwoPi();
711     if(minPhi < 0 ) minPhi = 0;
712     Float_t diffRcRJR(TMath::Abs(fRandomConeRadius-fJetRadius));
713     // construct a random cone and see if it's far away enough from the leading jet
714     Int_t attempts(1000);
715     while(kTRUE) {
716         attempts--;
717         eta = gRandom->Uniform(fJetMinEta+diffRcRJR, fJetMaxEta-diffRcRJR);
718         phi = gRandom->Uniform(minPhi, maxPhi);
719
720         dJet = TMath::Sqrt((etaJet-eta)*(etaJet-eta)+(phiJet-phi)*(phiJet-phi));
721         if(dJet > fMinDisanceRCtoLJ) break;
722         else if (attempts == 0) {
723             printf(" > No random cone after 1000 tries, giving up ... !\n");
724             return;
725         }
726     }
727     if(fTracks) {
728         Int_t iTracks(fTracks->GetEntriesFast());
729         for(Int_t i(0); i < iTracks; i++) {
730             AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
731             if(!PassesCuts(track)) continue;
732             Float_t etaTrack(track->Eta()), phiTrack(track->Phi()), ptTrack(track->Pt());
733             // if requested, randomize eta and phi to destroy any correlated fluctuations
734             if(randomize) {
735                 etaTrack = gRandom->Uniform(fTrackMinEta, fTrackMaxEta);
736                 phiTrack = gRandom->Uniform(minPhi, maxPhi);
737             }
738             // get distance from cone
739             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi + TMath::TwoPi())) phiTrack+=TMath::TwoPi();
740             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi - TMath::TwoPi())) phiTrack-=TMath::TwoPi();
741             if(TMath::Sqrt(TMath::Abs((etaTrack-eta)*(etaTrack-eta)+(phiTrack-phi)*(phiTrack-phi))) <= fRandomConeRadius) pt+=ptTrack;
742         }
743     }
744 }
745 //_____________________________________________________________________________
746 Bool_t AliAnalysisTaskRhoVnModulation::CorrectRho(Double_t* params, Double_t psi2, Double_t psi3, Double_t psi2b, Double_t psi3b) 
747 {
748     // get rho' -> rho(phi)
749     // two routines are available
750     //  [1]  fitting a fourier expansion to the de/dphi distribution
751     //  [2]  getting vn from a fourier series around dn/dphi (see below for info)
752     //  this function will return kTRUE if the fit passes a set of quality criteria
753     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
754     TString detector("");
755     switch (fDetectorType) {
756         case kTPC : detector+="TPC";
757             break;
758         case kTPCSUB : detector+="kTPCSUB";
759             break;
760         case kVZEROA : detector+="VZEROA";
761             break;
762         case kVZEROC : detector+="VZEROC";
763             break;
764         default: break;
765     }
766     Int_t iTracks(fTracks->GetEntriesFast());
767     Double_t excludeInEta[] = {-999, -999};
768     Double_t excludeInPhi[] = {-999, -999};
769     Double_t excludeInPt[]  = {-999, -999};
770     if(iTracks <= 0 || RhoVal() <= 0 ) return kFALSE;   // no use fitting an empty event ...
771     if(fExcludeLeadingJetsFromFit > 0 ) {
772         AliEmcalJet* leadingJet[] = {0x0, 0x0};
773         static Int_t lJets[9999] = {-1};
774         GetSortedArray(lJets, fJets);
775         for(Int_t i(0); i < fJets->GetEntriesFast(); i++) {     // get the two leading jets
776             if (1 + i > fJets->GetEntriesFast()) break;
777             leadingJet[0] = static_cast<AliEmcalJet*>(fJets->At(lJets[i]));
778             leadingJet[1] = static_cast<AliEmcalJet*>(fJets->At(lJets[i+1]));
779             if(PassesCuts(leadingJet[0]) && PassesCuts(leadingJet[1])) break;
780         }
781         if(leadingJet[0] && leadingJet[1]) {
782             for(Int_t i(0); i < 2; i++) {
783                 excludeInEta[i] = leadingJet[i]->Eta();
784                 excludeInPhi[i] = leadingJet[i]->Phi();
785                 excludeInPt[i]  = leadingJet[i]->Pt();
786             }
787         }
788     }
789     fHistSwap->Reset();                 // clear the histogram
790     TH1F _tempSwap;
791     if(fRebinSwapHistoOnTheFly) {
792         if(fNAcceptedTracks < 49) fNAcceptedTracks = 49;       // avoid aliasing effects
793         _tempSwap = TH1F("_tempSwap", "_tempSwap", TMath::CeilNint(TMath::Sqrt(fNAcceptedTracks)), 0, TMath::TwoPi());
794     }
795     else _tempSwap = *fHistSwap;         // now _tempSwap holds the desired histo
796     for(Int_t i(0); i < iTracks; i++) {
797             AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
798             if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta[0]) < fJetRadius*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - fJetRadius - fJetMaxEta ) > 0 )) continue;
799             if(!PassesCuts(track) || track->Pt() > 5 || track->Pt() < 0.15) continue;
800             if(fDetectorType == kTPCSUB && psi2 > -1000 && track->Eta() < 0 ) continue;
801             else if (fDetectorType == kTPCSUB && psi2 < -1000 && track->Eta() > 0 ) continue;
802             if(fUsePtWeight) _tempSwap.Fill(track->Phi(), track->Pt());
803             else _tempSwap.Fill(track->Phi());
804     }
805     for(Int_t i(0); i < _tempSwap.GetXaxis()->GetNbins(); i++) _tempSwap.SetBinError(1+i, TMath::Sqrt(_tempSwap.GetBinContent(1+i)));
806     fFitModulation->SetParameter(0, RhoVal());
807     switch (fFitModulationType) {
808         case kNoFit : { fFitModulation->FixParameter(0, RhoVal() ); 
809         } break;
810         case kV2 : { 
811             fFitModulation->FixParameter(4, psi2); 
812         } break;
813         case kV3 : { 
814             fFitModulation->FixParameter(4, psi3); 
815         } break;
816         case kCombined : { 
817             fFitModulation->FixParameter(4, psi2); 
818             fFitModulation->FixParameter(6, psi3);
819         } break;
820         case kFourierSeries : {
821             // in this approach, an explicit calculation will be made of vn = sqrt(xn^2+yn^2)
822             // where x[y] = Integrate[r(phi)cos[sin](n phi)dphi, 0, 2pi]
823             Double_t cos2(0), sin2(0), cos3(0), sin3(0), sumPt(0);
824             for(Int_t i(0); i < iTracks; i++) {
825                 AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
826                 if(!PassesCuts(track) || track->Pt() > 5 || track->Pt() < 0.15) continue;
827                 sumPt += track->Pt();
828                 cos2 += track->Pt()*TMath::Cos(2*PhaseShift(track->Phi()-psi2)); 
829                 sin2 += track->Pt()*TMath::Sin(2*PhaseShift(track->Phi()-psi2));
830                 cos3 += track->Pt()*TMath::Cos(3*PhaseShift(track->Phi()-psi3)); 
831                 sin3 += track->Pt()*TMath::Sin(3*PhaseShift(track->Phi()-psi3));
832             }
833             fFitModulation->SetParameter(3, TMath::Sqrt(cos2*cos2+sin2*sin2)/RhoVal());
834             fFitModulation->SetParameter(4, psi2);
835             fFitModulation->SetParameter(6, psi3);
836             fFitModulation->SetParameter(7, TMath::Sqrt(cos3*cos3+sin3*sin3)/RhoVal());
837         }
838         default : break;
839     }
840     if(fDetectorType == kTPCSUB && psi2 > -1000 ) { // do the magic for the subevent case
841         Double_t v2(fFitModulation->GetParameter(3)), v3(fFitModulation->GetParameter(7));
842         CorrectRho(params, -9999, -9999, psi2b, psi3b);
843         v2 += fFitModulation->GetParameter(3);
844         v3 += fFitModulation->GetParameter(7);
845         fFitModulation->SetParameter(3, v2/2.);
846         fFitModulation->SetParameter(7, v3/3.);
847     }
848     _tempSwap.Fit(fFitModulation, fFitModulationOptions.Data(), "", 0, TMath::TwoPi());
849     // the quality of the fit is evaluated from 1 - the cdf of the chi square distribution
850     Double_t CDF(1.-ChiSquareCDF(fFitModulation->GetNDF(), fFitModulation->GetChisquare()));
851 //    Double_t PDF(ChiSquarePDF(fFitModulation->GetNDF(), fFitModulation->GetChisquare()));
852     fHistPvalueCDF->Fill(CDF);
853 //    fHistPvaluePDF->Fill(PDF);
854     if(CDF > fMinPvalue && CDF < fMaxPvalue && ( fAbsVnHarmonics && fFitModulation->GetMinimum(0, TMath::TwoPi()) > 0)) { // fit quality
855         // for LOCAL didactic purposes, save the  best and the worst fits
856         // this routine can produce a lot of output histograms (it's not memory 'safe') and will not work on GRID 
857         // since the output will become unmergeable (i.e. different nodes may produce conflicting output)
858         switch (fRunModeType) {
859             case kLocal : {
860                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
861                 static Int_t didacticCounterBest(0);
862                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
863                 TF1* didactifFit = (TF1*)fFitModulation->Clone(Form("fit_%i_CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
864                 didacticProfile->GetListOfFunctions()->Add(didactifFit);
865                 fOutputListGood->Add(didacticProfile);
866                 didacticCounterBest++;
867                 TH2F* didacticSurface = BookTH2F(Form("surface_%s", didacticProfile->GetName()), "#phi", "#eta", 50, 0, TMath::TwoPi(), 50, -1, 1, -1, kFALSE);
868                 for(Int_t i(0); i < iTracks; i++) {
869                     AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
870                     if(PassesCuts(track)) {
871                         if(fUsePtWeight) didacticSurface->Fill(track->Phi(), track->Eta(), track->Pt());
872                         else didacticSurface->Fill(track->Phi(), track->Eta());
873                     }
874                 }
875                 if(fExcludeLeadingJetsFromFit) {       // visualize the excluded region
876                     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);
877                     f2->SetParameters(excludeInPt[0]/3.,excludeInPhi[0],.1,excludeInEta[0],.1);
878                     didacticSurface->GetListOfFunctions()->Add(f2);
879                     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);
880                     f3->SetParameters(excludeInPt[1]/3.,excludeInPhi[1],.1,excludeInEta[1],.1);
881                     f3->SetLineColor(kGreen);
882                     didacticSurface->GetListOfFunctions()->Add(f3);
883                 }
884                 fOutputListGood->Add(didacticSurface);
885             } break;
886             default : break;
887         }
888     } else {    // if the fit is of poor quality revert to the original rho estimate
889         switch (fRunModeType) { // again see if we want to save the fit
890             case kLocal : {
891                 static Int_t didacticCounterWorst(0);
892                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
893                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data() ));
894                 TF1* didactifFit = (TF1*)fFitModulation->Clone(Form("fit_%i_p_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data()));
895                 didacticProfile->GetListOfFunctions()->Add(didactifFit);
896                 fOutputListBad->Add(didacticProfile);
897                 didacticCounterWorst++;
898                 } break;
899             default : break;
900         }
901         switch (fFitModulationType) {
902             case kNoFit : break;        // nothing to do
903             case kUser : break;         // FIXME not implemented yet
904             case kCombined : fFitModulation->SetParameter(7, 0);        // no break
905             case kFourierSeries : fFitModulation->SetParameter(7, 0);   // no break
906             default : { // needs to be done if there was a poor fit
907                  fFitModulation->SetParameter(3, 0);
908                  fFitModulation->SetParameter(0, RhoVal());
909             } break;
910         }
911         return kFALSE;  // return false if the fit is rejected
912     }
913     for(Int_t i(0); i < fFitModulation->GetNpar(); i++) params[i] = fFitModulation->GetParameter(i);
914     return kTRUE;
915 }
916 //_____________________________________________________________________________
917 Bool_t AliAnalysisTaskRhoVnModulation::PassesCuts(AliVEvent* event)
918 {
919     // event cuts
920     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
921     if(!event) return kFALSE;
922     if(TMath::Abs(InputEvent()->GetPrimaryVertex()->GetZ()) > 10.) return kFALSE;
923     // aod and esd specific checks
924     switch (fDataType) {
925        case kESD: {
926             AliESDEvent* esdEvent = static_cast<AliESDEvent*>(InputEvent());
927             if( (!esdEvent) || (TMath::Abs(esdEvent->GetPrimaryVertexSPD()->GetZ() - esdEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
928        } break;
929        case kAOD: {
930             AliAODEvent* aodEvent = static_cast<AliAODEvent*>(InputEvent());
931             if( (!aodEvent) || (TMath::Abs(aodEvent->GetPrimaryVertexSPD()->GetZ() - aodEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
932        } break;
933        default: break;
934     }
935     fCent = InputEvent()->GetCentrality()->GetCentralityPercentile("V0M");
936     if(fCent <= fCentralityClasses->At(0) || fCent >= fCentralityClasses->At(fCentralityClasses->GetSize()-1) || TMath::Abs(fCent-InputEvent()->GetCentrality()->GetCentralityPercentile("TRK")) > 5.) return kFALSE;
937     // determine centrality class
938     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) {
939         if(fCent >= fCentralityClasses->At(i) && fCent <= fCentralityClasses->At(1+i)) {
940             fInCentralitySelection = i;
941             break; }
942     } 
943     if(fFillQAHistograms) FillQAHistograms(event);
944     return kTRUE;
945 }
946 //_____________________________________________________________________________
947 Bool_t AliAnalysisTaskRhoVnModulation::PassesCuts(const AliVCluster* cluster) const
948 {
949     // cluster cuts
950     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
951     if(!cluster) return kFALSE;
952     return kTRUE;
953 }
954 //_____________________________________________________________________________
955 void AliAnalysisTaskRhoVnModulation::FillHistogramsAfterSubtraction(Double_t vzero[2][2], Double_t* tpc) const
956 {
957     // fill histograms 
958     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
959     FillTrackHistograms();
960     /* FillClusterHistograms(); */
961     FillJetHistograms(vzero, tpc); 
962     /* FillCorrectedClusterHistograms(); */
963     FillEventPlaneHistograms(vzero, tpc);
964     FillRhoHistograms();
965     switch (fDetectorType) {    // determine the detector type for the rho fit
966         case kTPC :     { FillDeltaPtHistograms(tpc[0], tpc[1]); }              break;
967         case kTPCSUB :  { FillDeltaPtHistograms(tpc[2], tpc[4]);
968                           FillDeltaPtHistograms(tpc[3], tpc[5]); }              break;
969         case kVZEROA :  { FillDeltaPtHistograms(vzero[0][0], vzero[0][1]); }    break;
970         case kVZEROC :  { FillDeltaPtHistograms(vzero[1][0], vzero[1][1]); }    break;
971         default : break;
972     }
973     FillDeltaPhiHistograms(vzero, tpc);
974 }
975 //_____________________________________________________________________________
976 void AliAnalysisTaskRhoVnModulation::FillTrackHistograms() const
977 {
978     // fill track histograms
979     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
980     Int_t iTracks(fTracks->GetEntriesFast());
981     for(Int_t i(0); i < iTracks; i++) {
982         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
983         if(!PassesCuts(track)) continue;
984         fHistPicoTrackPt[fInCentralitySelection]->Fill(track->Pt());
985         if(fFillQAHistograms) FillQAHistograms(track);
986     }
987 }
988 //_____________________________________________________________________________
989 void AliAnalysisTaskRhoVnModulation::FillClusterHistograms() const
990 {
991     // fill cluster histograms
992     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
993     /* Int_t iClusters(fCaloClusters->GetEntriesFast());
994     for(Int_t i(0); i < iClusters; i++) {
995         AliVCluster* cluster = static_cast<AliVCluster*>(fCaloClusters->At(iClusters));
996         if (!PassesCuts(cluster)) continue;
997         TLorentzVector clusterLorentzVector;
998         cluster->GetMomentum(clusterLorentzVector, const_cast<Double_t*>(fVertex));
999         fHistClusterPt[fInCentralitySelection]->Fill(clusterLorentzVector.Pt());
1000         fHistClusterEta[fInCentralitySelection]->Fill(clusterLorentzVector.Eta());
1001         fHistClusterPhi[fInCentralitySelection]->Fill(clusterLorentzVector.Phi());
1002     }
1003     return; */
1004 }
1005 //_____________________________________________________________________________
1006 void AliAnalysisTaskRhoVnModulation::FillCorrectedClusterHistograms() const
1007 {
1008     // fill clusters after hadronic correction FIXME implement
1009     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1010 }
1011 //_____________________________________________________________________________
1012 void AliAnalysisTaskRhoVnModulation::FillEventPlaneHistograms(Double_t vzero[2][2], Double_t* tpc) const
1013 {
1014     // fill event plane histograms
1015     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1016     fHistPsiControl->Fill(0.5, vzero[0][0]);    // vzero a psi2
1017     fHistPsiControl->Fill(1.5, vzero[1][0]);    // vzero c psi2
1018     fHistPsiControl->Fill(2.5, tpc[0]);         // tpc psi 2
1019     fHistPsiControl->Fill(3.5, tpc[2]);         // tpc sub a psi 2
1020     fHistPsiControl->Fill(4.5, tpc[3]);         // tpc sub b psi 2
1021     fHistPsiControl->Fill(5.5, vzero[0][1]);    // vzero a psi3
1022     fHistPsiControl->Fill(6.5, vzero[1][1]);    // vzero b psi3
1023     fHistPsiControl->Fill(7.5, tpc[1]);         // tpc psi 3
1024     fHistPsiControl->Fill(8.5, tpc[4]);         // tpc sub a psi3
1025     fHistPsiControl->Fill(9.5, tpc[5]);         // tpc sub b psi3
1026     fHistPsiVZEROA->Fill(vzero[0][0]);
1027     fHistPsiVZEROC->Fill(vzero[1][0]);
1028     fHistPsiTPC->Fill(tpc[0]);
1029     fHistPsiTPCSUBA->Fill(tpc[2]);
1030     fHistPsiTPCSUBB->Fill(tpc[3]);
1031     fHistPsiSpread->Fill(0.5, TMath::Abs(vzero[0][0]-vzero[1][0]));
1032     fHistPsiSpread->Fill(1.5, TMath::Abs(vzero[0][0]-tpc[0]));
1033     fHistPsiSpread->Fill(2.5, TMath::Abs(vzero[1][0]-tpc[0]));
1034     fHistPsiSpread->Fill(3.5, TMath::Abs(tpc[2]-tpc[3]));
1035 }
1036 //_____________________________________________________________________________
1037 void AliAnalysisTaskRhoVnModulation::FillRhoHistograms() const
1038 {
1039     // fill rho histograms
1040     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1041     fHistRhoPackage[fInCentralitySelection]->Fill(RhoVal());    // save the rho estimate from the emcal jet package
1042     // get multiplicity FIXME inefficient
1043     Int_t iTracks(fTracks->GetEntriesFast()), mult(0), iJets(fJets->GetEntriesFast());
1044     for(Int_t i(0); i < iTracks; i ++) { if(PassesCuts(static_cast<AliVTrack*>(fTracks->At(i)))) mult++; }
1045     Double_t rho(RhoVal(TMath::Pi(), TMath::Pi(), fRho->GetVal()));
1046     fHistRho[fInCentralitySelection]->Fill(rho);
1047     fHistRhoVsMult->Fill(mult, rho);
1048     fHistRhoVsCent->Fill(fCent, rho);
1049     for(Int_t i(0); i < iJets; i++) {
1050         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1051         if(!PassesCuts(jet)) continue;
1052         fHistRhoAVsMult->Fill(mult, rho * jet->Area());
1053         fHistRhoAVsCent->Fill(fCent, rho * jet->Area());
1054     }
1055 }
1056 //_____________________________________________________________________________
1057 void AliAnalysisTaskRhoVnModulation::FillDeltaPtHistograms(Double_t psi2, Double_t psi3) const
1058 {
1059     // fill delta pt histograms
1060     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1061     Int_t i(0), maxCones(20);
1062     AliEmcalJet* leadingJet(0x0);
1063     static Int_t sJets[9999] = {-1};
1064     GetSortedArray(sJets, fJets);
1065     do { // get the leading jet 
1066         leadingJet = static_cast<AliEmcalJet*>(fJets->At(sJets[i]));
1067         i++;
1068     }
1069     while (!PassesCuts(leadingJet)&&i<fJets->GetEntriesFast()); 
1070     if(!leadingJet && fDebug > 0) printf(" > failed to retrieve leading jet ! < \n");
1071     const Float_t areaRC = fRandomConeRadius*fRandomConeRadius*TMath::Pi();
1072     // we're retrieved the leading jet, now get a random cone
1073     for(i = 0; i < maxCones; i++) {
1074        Float_t pt(0), eta(0), phi(0);
1075        // get a random cone without constraints on leading jet position
1076        CalculateRandomCone(pt, eta, phi, 0x0);
1077        if(pt > 0) {
1078            fHistRCPhiEta[fInCentralitySelection]->Fill(phi, eta);
1079            fHistRhoVsRCPt[fInCentralitySelection]->Fill(pt, RhoVal(phi, fJetRadius, fRho->GetVal())*areaRC);
1080            fHistRCPt[fInCentralitySelection]->Fill(pt);
1081            fHistDeltaPtDeltaPhi2[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1082            fHistDeltaPtDeltaPhi3[fInCentralitySelection]->Fill(PhaseShift(phi-psi3, 3.), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1083        }
1084        // get a random cone excluding leading jet area
1085        CalculateRandomCone(pt, eta, phi, leadingJet);
1086        if(pt > 0) {
1087            fHistRCPhiEtaExLJ[fInCentralitySelection]->Fill(phi, eta);
1088            fHistRhoVsRCPtExLJ[fInCentralitySelection]->Fill(pt, RhoVal(phi, fJetRadius, fRho->GetVal())*areaRC);
1089            fHistRCPtExLJ[fInCentralitySelection]->Fill(pt);
1090            fHistDeltaPtDeltaPhi2ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1091            fHistDeltaPtDeltaPhi3ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi3, 3.), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1092        }
1093        // get a random cone in an event with randomized phi and eta
1094        /* CalculateRandomCone(pt, eta, phi, 0x0, kTRUE);
1095        if( pt > 0) {
1096            fHistRCPhiEtaRand[fInCentralitySelection]->Fill(phi, eta);
1097            fHistRhoVsRCPtRand[fInCentralitySelection]->Fill(pt, RhoVal(phi, fJetRadius, fRho->GetVal())*areaRC);
1098            fHistRCPtRand[fInCentralitySelection]->Fill(pt);
1099            fHistDeltaPtDeltaPhi2Rand[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1100            fHistDeltaPtDeltaPhi3Rand[fInCentralitySelection]->Fill(PhaseShift(phi-psi3, 3.), pt - areaRC*RhoVal(phi, fJetRadius, fRho->GetVal()));
1101        } */
1102     } 
1103 }
1104 //_____________________________________________________________________________
1105 void AliAnalysisTaskRhoVnModulation::FillJetHistograms(Double_t vzero[2][2], Double_t* tpc) const
1106 {
1107     // fill jet histograms
1108     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1109     Int_t iJets(fJets->GetEntriesFast());
1110     for(Int_t i(0); i < iJets; i++) {
1111         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1112         if(PassesCuts(jet)) {
1113             Double_t pt(jet->Pt()), area(jet->Area()), eta(jet->Eta()), phi(jet->Phi());
1114             Double_t rho(RhoVal(phi, fJetRadius, fRho->GetVal()));
1115             fHistJetPtRaw[fInCentralitySelection]->Fill(pt);
1116             fHistJetPt[fInCentralitySelection]->Fill(pt-area*rho);
1117             fHistJetEtaPhi[fInCentralitySelection]->Fill(eta, phi);
1118             fHistJetPtArea[fInCentralitySelection]->Fill(pt-area*rho, area);
1119             fHistJetPsiTPCPt[fInCentralitySelection]->Fill(PhaseShift(phi-tpc[0], 2.), pt-area*rho);
1120             fHistJetPsiVZEROAPt[fInCentralitySelection]->Fill(PhaseShift(phi-vzero[0][0], 2.), pt-area*rho);
1121             fHistJetPsiVZEROCPt[fInCentralitySelection]->Fill(PhaseShift(phi-vzero[1][0], 2.), pt-area*rho);
1122             fHistJetPtConstituents[fInCentralitySelection]->Fill(pt-area*rho, jet->Nch());
1123             fHistJetEtaRho[fInCentralitySelection]->Fill(eta, pt/area);
1124             if(fSetPtSub) jet->SetPtSub(pt-area*rho);
1125         }
1126         else { // if the jet is rejected, excluded it for the flow analysis
1127             if(fSetPtSub) jet->SetPtSub(-999.);
1128         }
1129     }
1130 }
1131 //_____________________________________________________________________________
1132 void AliAnalysisTaskRhoVnModulation::FillDeltaPhiHistograms(Double_t vzero[2][2], Double_t* tpc) const
1133 {
1134    // fill phi minus psi histograms
1135    if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1136    if(fTracks) {
1137        Int_t iTracks(fTracks->GetEntriesFast());
1138        for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
1139            AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
1140            if(!PassesCuts(track)) continue;
1141            fHistDeltaPhi2VZEROA[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-vzero[0][0], 2.));
1142            fHistDeltaPhi2VZEROC[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-vzero[1][0], 2.));
1143            fHistDeltaPhi2TPC[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-tpc[0], 2.));
1144            fHistDeltaPhi3VZEROA[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-vzero[0][1], 3.));
1145            fHistDeltaPhi3VZEROC[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-vzero[1][1], 3.));
1146            fHistDeltaPhi3TPC[fInCentralitySelection]->Fill(PhaseShift(track->Phi()-tpc[1], 3.));
1147        }
1148    }
1149 }
1150 //_____________________________________________________________________________
1151 void AliAnalysisTaskRhoVnModulation::FillQAHistograms(AliVTrack* vtrack) const
1152 {
1153     // fill qa histograms for pico tracks
1154     if(!vtrack) return;
1155     AliPicoTrack* track = static_cast<AliPicoTrack*>(vtrack);
1156     fHistRunnumbersPhi->Fill(fMappedRunNumber, track->Phi());
1157     fHistRunnumbersEta->Fill(fMappedRunNumber, track->Eta());
1158     Int_t type((int)(track->GetTrackType()));
1159     switch (type) {
1160         case 0:
1161            fHistPicoCat1[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1162            break;
1163         case 1:
1164            fHistPicoCat2[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1165            break;
1166         case 2:
1167            fHistPicoCat3[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1168            break;
1169         default: break;
1170     }
1171 }
1172 //_____________________________________________________________________________
1173 void AliAnalysisTaskRhoVnModulation::FillQAHistograms(AliVEvent* vevent) 
1174 {
1175     // fill qa histograms for events
1176     if(!vevent) return;
1177     fHistVertexz->Fill(vevent->GetPrimaryVertex()->GetZ());
1178     fHistCentrality->Fill(fCent);
1179     Int_t runNumber(InputEvent()->GetRunNumber());
1180     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};
1181     for(fMappedRunNumber = 0; fMappedRunNumber < 64; fMappedRunNumber++) {
1182         if(runs[fMappedRunNumber]==runNumber) break;
1183     }
1184 }
1185 //_____________________________________________________________________________
1186 void AliAnalysisTaskRhoVnModulation::Terminate(Option_t *)
1187 {
1188     // terminate
1189     switch (fRunModeType) {
1190         case kLocal : {
1191         printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1192         if(fFillQAHistograms) {
1193             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};
1194             for(Int_t i(0); i < 64; i++) { 
1195                 fHistRunnumbersPhi->GetXaxis()->SetBinLabel(i+1, Form("%i", runs[i]));
1196                 fHistRunnumbersEta->GetXaxis()->SetBinLabel(i+1, Form("%i", runs[i]));
1197             }
1198             fHistRunnumbersPhi->GetXaxis()->SetBinLabel(65, "undetermined");
1199             fHistRunnumbersEta->GetXaxis()->SetBinLabel(65, "undetermined");
1200         }
1201         AliAnalysisTaskRhoVnModulation::Dump();
1202         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));
1203         } break;
1204         default : break;
1205     }
1206 }
1207 //_____________________________________________________________________________