]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskRhoVnModulation.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[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 // root includes
33 #include <TStyle.h>
34 #include <TRandom3.h>
35 #include <TChain.h>
36 #include <TMath.h>
37 #include <TF1.h>
38 #include <TF2.h>
39 #include <TH1F.h>
40 #include <TH2F.h>
41 #include <TProfile.h>
42 // aliroot includes
43 #include <AliAnalysisTask.h>
44 #include <AliAnalysisManager.h>
45 #include <AliCentrality.h>
46 #include <AliVVertex.h>
47 #include <AliESDEvent.h>
48 #include <AliAODEvent.h>
49 #include <AliAODTrack.h>
50 // emcal jet framework includes
51 #include <AliPicoTrack.h>
52 #include <AliEmcalJet.h>
53 #include <AliRhoParameter.h>
54 #include <AliLocalRhoParameter.h>
55 #include <AliAnalysisTaskRhoVnModulation.h>
56
57 class AliAnalysisTaskRhoVnModulation;
58 using namespace std;
59
60 ClassImp(AliAnalysisTaskRhoVnModulation)
61
62 AliAnalysisTaskRhoVnModulation::AliAnalysisTaskRhoVnModulation() : AliAnalysisTaskEmcalJet("AliAnalysisTaskRhoVnModulation", kTRUE), 
63     fDebug(0), fLocalInit(0), fAttachToEvent(kTRUE), fSemiCentralInclusive(kFALSE), fFillHistograms(kTRUE), fFillQAHistograms(kTRUE), fReduceBinsXByFactor(-1.), fReduceBinsYByFactor(-1.), fNoEventWeightsForQC(kTRUE), fCentralityClasses(0), fPtBinsHybrids(0), fPtBinsJets(0), fUserSuppliedV2(0), fUserSuppliedV3(0), fUserSuppliedR2(0), fUserSuppliedR3(0), fTracksCont(0), fJetsCont(0), fUseScaledRho(0), fNAcceptedTracks(0), fNAcceptedTracksQCn(0), fFitModulationType(kNoFit), fQCRecovery(kTryFit), fUsePtWeight(kTRUE), fDetectorType(kTPC), fFitModulationOptions("QWLI"), fRunModeType(kGrid), fDataType(kESD), fCollisionType(kPbPb), fRandom(0), fMappedRunNumber(0), fInCentralitySelection(-1), fFitModulation(0), fMinPvalue(0.01), fMaxPvalue(1), fNameJetClones(0), fNamePicoTrackClones(0), fNameRho(0), fLocalJetMinEta(-10), fLocalJetMaxEta(-10), fLocalJetMinPhi(-10), fLocalJetMaxPhi(-10), fSoftTrackMinPt(0.15), fSoftTrackMaxPt(5.), fAbsVertexZ(10), fHistCentrality(0), fHistVertexz(0), fHistRunnumbersPhi(0), fHistRunnumbersEta(0), fHistPvaluePDF(0), fHistPvalueCDF(0), fMinDisanceRCtoLJ(0), fRandomConeRadius(-1.), fMaxCones(-1), fAbsVnHarmonics(kTRUE), fExcludeLeadingJetsFromFit(1.), fRebinSwapHistoOnTheFly(kTRUE), fPercentageOfFits(10.), fUseV0EventPlaneFromHeader(kTRUE), fExplicitOutlierCut(-1), fMinLeadingHadronPt(0), fSubtractJetPt(kFALSE), fOutputList(0), fOutputListGood(0), fOutputListBad(0), fHistAnalysisSummary(0), fHistSwap(0), fProfV2(0), fProfV2Cumulant(0), fProfV3(0), fProfV3Cumulant(0), fHistPsiControl(0), fHistPsiSpread(0), fHistPsiVZEROA(0), fHistPsiVZEROC(0), fHistPsiVZERO(0), fHistPsiTPC(0), fHistPsiVZEROAV0M(0), fHistPsiVZEROCV0M(0), fHistPsiVZEROVV0M(0), fHistPsiTPCiV0M(0), fHistPsiVZEROATRK(0), fHistPsiVZEROCTRK(0), fHistPsiVZEROTRK(0), fHistPsiTPCTRK(0), 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         fHistPicoTrackMult[i] = 0;
69         fHistPicoCat1[i] = 0;
70         fHistPicoCat2[i] = 0;
71         fHistPicoCat3[i] = 0;
72         /* fHistClusterPt[i] = 0; */
73         /* fHistClusterPhi[i] = 0; */
74         /* fHistClusterEta[i] = 0; */ 
75         /* fHistClusterCorrPt[i] = 0; */
76         /* fHistClusterCorrPhi[i] = 0; */
77         /* fHistClusterCorrEta[i] = 0; */
78         fHistRhoPackage[i] = 0;
79         fHistRho[i] = 0;
80         fHistRCPhiEta[i] = 0;
81         fHistRhoVsRCPt[i] = 0;
82         fHistRCPt[i] = 0;
83         fHistDeltaPtDeltaPhi2[i] = 0;
84         fHistDeltaPtDeltaPhi3[i] = 0;
85         fHistRCPhiEtaExLJ[i] = 0;
86         fHistRhoVsRCPtExLJ[i] = 0;
87         fHistRCPtExLJ[i] = 0;
88         fHistDeltaPtDeltaPhi2ExLJ[i] = 0;
89         fHistDeltaPtDeltaPhi3ExLJ[i] = 0;
90         /* fHistRCPhiEtaRand[i] = 0; */
91         /* fHistRhoVsRCPtRand[i] = 0; */
92         /* fHistRCPtRand[i] = 0; */
93         /* fHistDeltaPtDeltaPhi2Rand[i] = 0; */
94         /* fHistDeltaPtDeltaPhi3Rand[i] = 0; */
95         fHistJetPtRaw[i] = 0;
96         fHistJetPt[i] = 0;
97         fHistJetEtaPhi[i] = 0;
98         fHistJetPtArea[i] = 0;
99         fHistJetPtConstituents[i] = 0;
100         fHistJetEtaRho[i] = 0;
101         fHistJetPsi2Pt[i] = 0;
102         fHistJetPsi3Pt[i] = 0;
103    }
104     // default constructor
105 }
106 //_____________________________________________________________________________
107 AliAnalysisTaskRhoVnModulation::AliAnalysisTaskRhoVnModulation(const char* name, runModeType type) : AliAnalysisTaskEmcalJet(name, kTRUE),
108   fDebug(0), fLocalInit(0), fAttachToEvent(kTRUE), fSemiCentralInclusive(kFALSE), fFillHistograms(kTRUE), fFillQAHistograms(kTRUE), fReduceBinsXByFactor(-1.), fReduceBinsYByFactor(-1.), fNoEventWeightsForQC(kTRUE), fCentralityClasses(0), fPtBinsHybrids(0), fPtBinsJets(0), fUserSuppliedV2(0), fUserSuppliedV3(0), fUserSuppliedR2(0), fUserSuppliedR3(0), fTracksCont(0), fJetsCont(0), fUseScaledRho(0), fNAcceptedTracks(0), fNAcceptedTracksQCn(0), fFitModulationType(kNoFit), fQCRecovery(kTryFit), fUsePtWeight(kTRUE), fDetectorType(kTPC), fFitModulationOptions("QWLI"), fRunModeType(type), fDataType(kESD), fCollisionType(kPbPb), fRandom(0), fMappedRunNumber(0), fInCentralitySelection(-1), fFitModulation(0), fMinPvalue(0.01), fMaxPvalue(1), fNameJetClones(0), fNamePicoTrackClones(0), fNameRho(0), fLocalJetMinEta(-10), fLocalJetMaxEta(-10), fLocalJetMinPhi(-10), fLocalJetMaxPhi(-10), fSoftTrackMinPt(0.15), fSoftTrackMaxPt(5.), fAbsVertexZ(10), fHistCentrality(0), fHistVertexz(0), fHistRunnumbersPhi(0), fHistRunnumbersEta(0), fHistPvaluePDF(0), fHistPvalueCDF(0), fMinDisanceRCtoLJ(0), fRandomConeRadius(-1.), fMaxCones(-1), fAbsVnHarmonics(kTRUE), fExcludeLeadingJetsFromFit(1.), fRebinSwapHistoOnTheFly(kTRUE), fPercentageOfFits(10.), fUseV0EventPlaneFromHeader(kTRUE), fExplicitOutlierCut(-1), fMinLeadingHadronPt(0), fSubtractJetPt(kFALSE), fOutputList(0), fOutputListGood(0), fOutputListBad(0), fHistAnalysisSummary(0), fHistSwap(0), fProfV2(0), fProfV2Cumulant(0), fProfV3(0), fProfV3Cumulant(0), fHistPsiControl(0), fHistPsiSpread(0), fHistPsiVZEROA(0), fHistPsiVZEROC(0), fHistPsiVZERO(0), fHistPsiTPC(0), fHistPsiVZEROAV0M(0), fHistPsiVZEROCV0M(0), fHistPsiVZEROVV0M(0), fHistPsiTPCiV0M(0), fHistPsiVZEROATRK(0), fHistPsiVZEROCTRK(0), fHistPsiVZEROTRK(0), fHistPsiTPCTRK(0), fHistRhoVsMult(0), fHistRhoVsCent(0), fHistRhoAVsMult(0), fHistRhoAVsCent(0) {
109     for(Int_t i(0); i < 10; i++) {
110         fProfV2Resolution[i] = 0;
111         fProfV3Resolution[i] = 0;
112         fHistPicoTrackPt[i] = 0;
113         fHistPicoTrackMult[i] = 0;
114         fHistPicoCat1[i] = 0;
115         fHistPicoCat2[i] = 0;
116         fHistPicoCat3[i] = 0;
117         /* fHistClusterPt[i] = 0; */
118         /* fHistClusterPhi[i] = 0; */
119         /* fHistClusterEta[i] = 0; */ 
120         /* fHistClusterCorrPt[i] = 0; */
121         /* fHistClusterCorrPhi[i] = 0; */
122         /* fHistClusterCorrEta[i] = 0; */
123         fHistRhoPackage[i] = 0;
124         fHistRho[i] = 0;
125         fHistRCPhiEta[i] = 0;
126         fHistRhoVsRCPt[i] = 0;
127         fHistRCPt[i] = 0;
128         fHistDeltaPtDeltaPhi2[i] = 0;
129         fHistDeltaPtDeltaPhi3[i] = 0;
130         fHistRCPhiEtaExLJ[i] = 0;
131         fHistRhoVsRCPtExLJ[i] = 0;
132         fHistRCPtExLJ[i] = 0;
133         fHistDeltaPtDeltaPhi2ExLJ[i] = 0;
134         fHistDeltaPtDeltaPhi3ExLJ[i] = 0;
135         /* fHistRCPhiEtaRand[i] = 0; */
136         /* fHistRhoVsRCPtRand[i] = 0; */
137         /* fHistRCPtRand[i] = 0; */
138         /* fHistDeltaPtDeltaPhi2Rand[i] = 0; */
139         /* fHistDeltaPtDeltaPhi3Rand[i] = 0; */
140         fHistJetPtRaw[i] = 0;
141         fHistJetPt[i] = 0;
142         fHistJetEtaPhi[i] = 0;
143         fHistJetPtArea[i] = 0;
144         fHistJetPtConstituents[i] = 0;
145         fHistJetEtaRho[i] = 0;
146         fHistJetPsi2Pt[i] = 0;
147         fHistJetPsi3Pt[i] = 0;
148     }
149     // constructor
150     DefineInput(0, TChain::Class());
151     DefineOutput(1, TList::Class());
152     switch (fRunModeType) {
153         case kLocal : {
154             gStyle->SetOptFit(1);
155             DefineOutput(2, TList::Class());
156             DefineOutput(3, TList::Class());
157         } break;
158         default: fDebug = -1;   // suppress debug info explicitely when not running locally
159     }
160     switch (fCollisionType) {
161         case kPythia : {
162             fFitModulationType = kNoFit;
163         } break;
164         default : break;
165     }
166     if(fLocalRhoName=="") fLocalRhoName = Form("LocalRhoFrom_%s", GetName());
167 }
168 //_____________________________________________________________________________
169 AliAnalysisTaskRhoVnModulation::~AliAnalysisTaskRhoVnModulation()
170 {
171     // destructor
172     if(fOutputList)             delete fOutputList;
173     if(fOutputListGood)         delete fOutputListGood;
174     if(fOutputListBad)          delete fOutputListBad;
175     if(fFitModulation)          delete fFitModulation;
176     if(fHistSwap)               delete fHistSwap;
177     if(fCentralityClasses)      delete fCentralityClasses;
178 }
179 //_____________________________________________________________________________
180 void AliAnalysisTaskRhoVnModulation::ExecOnce()
181 {
182     // Init the analysis
183     fLocalRho = new AliLocalRhoParameter(fLocalRhoName.Data(), 0); 
184     if(fAttachToEvent) {
185         if(!(InputEvent()->FindListObject(fLocalRho->GetName()))) {
186             InputEvent()->AddObject(fLocalRho);
187         } else {
188             AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), fLocalRho->GetName()));
189         }
190     }
191     AliAnalysisTaskEmcalJet::ExecOnce();        // init the base class
192     AliAnalysisTaskEmcalJet::SetVzRange(-1.*fAbsVertexZ, fAbsVertexZ);
193     if(fUseScaledRho) {
194         // unscaled rho has been retrieved by the parent class, now we retrieve rho scaled
195         fRho = dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(Form("%s_Scaled", fRho->GetName())));
196         if(!fRho) {
197             AliFatal(Form("%s: Couldn't find container for scaled rho. Aborting !", GetName()));
198         }
199     }
200     if(!GetJetContainer()) AliFatal(Form("%s: Couldn't find jet container. Aborting !", GetName()));
201 }
202 //_____________________________________________________________________________
203 Bool_t AliAnalysisTaskRhoVnModulation::InitializeAnalysis() 
204 {
205     // initialize the anaysis
206     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
207     if(fRandomConeRadius <= 0) fRandomConeRadius = GetJetContainer()->GetJetRadius();
208     if(fMaxCones <= 0) fMaxCones = TMath::Nint(1.8*TMath::TwoPi()/(TMath::Pi()*fRandomConeRadius*fRandomConeRadius));
209     if(fLocalJetMinEta > -10 && fLocalJetMaxEta > -10) GetJetContainer()->SetJetEtaLimits(fLocalJetMinEta, fLocalJetMaxEta);
210     if(fLocalJetMinPhi > -10 && fLocalJetMaxPhi > -10) GetJetContainer()->SetJetPhiLimits(fLocalJetMinPhi, fLocalJetMaxPhi);
211     if(fMinDisanceRCtoLJ==0) fMinDisanceRCtoLJ = .5*GetJetRadius();
212     if(dynamic_cast<AliAODEvent*>(InputEvent())) fDataType = kAOD; // determine the datatype
213     else if(dynamic_cast<AliESDEvent*>(InputEvent())) fDataType = kESD;
214     fHistAnalysisSummary->SetBinContent(36, (int)fDataType);
215     if(!fRandom) fRandom = new TRandom3(0);  // get a randomized if one hasn't been user-supplied
216     switch (fFitModulationType)  {
217         case kNoFit : { SetModulationFit(new TF1("fix_kNoFit", "[0]", 0, TMath::TwoPi())); } break;
218         case kV2 : {
219             SetModulationFit(new TF1("fit_kV2", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
220             fFitModulation->SetParameter(0, 0.);        // normalization
221             fFitModulation->SetParameter(3, 0.2);       // v2
222             fFitModulation->FixParameter(1, 1.);        // constant
223             fFitModulation->FixParameter(2, 2.);        // constant
224         } break;
225         case kV3: {
226             SetModulationFit(new TF1("fit_kV3", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
227             fFitModulation->SetParameter(0, 0.);        // normalization
228             fFitModulation->SetParameter(3, 0.2);       // v3
229             fFitModulation->FixParameter(1, 1.);        // constant
230             fFitModulation->FixParameter(2, 3.);        // constant
231         } break;
232         default : { // for the combined fit, the 'direct fourier series' or the user supplied vn values we use v2 and v3
233              SetModulationFit(new TF1("fit_kCombined", "[0]*([1]+[2]*([3]*TMath::Cos([2]*(x-[4]))+[7]*TMath::Cos([5]*(x-[6]))))", 0, TMath::TwoPi()));
234              fFitModulation->SetParameter(0, 0.);       // normalization
235              fFitModulation->SetParameter(3, 0.2);      // v2
236              fFitModulation->FixParameter(1, 1.);       // constant
237              fFitModulation->FixParameter(2, 2.);       // constant
238              fFitModulation->FixParameter(5, 3.);       // constant
239              fFitModulation->SetParameter(7, 0.2);      // v3
240         } break;
241     }
242     switch (fRunModeType) {
243         case kGrid : { fFitModulationOptions += "N0"; } break;
244         default : break;
245     }
246     FillAnalysisSummaryHistogram();
247     return kTRUE;
248 }
249 //_____________________________________________________________________________
250 TH1F* AliAnalysisTaskRhoVnModulation::BookTH1F(const char* name, const char* x, Int_t bins, Double_t min, Double_t max, Int_t c, Bool_t append)
251 {
252     // book a TH1F and connect it to the output container
253     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
254     if(fReduceBinsXByFactor > 0 ) bins = TMath::Nint(bins/fReduceBinsXByFactor);
255     if(!fOutputList) return 0x0;
256     TString title(name);
257     if(c!=-1) { // format centrality dependent histograms accordingly
258         name = Form("%s_%i", name, c);
259         title += Form("_%i-%i", fCentralityClasses->At(c), fCentralityClasses->At(1+c));
260     }
261     title += Form(";%s;[counts]", x);
262     TH1F* histogram = new TH1F(name, title.Data(), bins, min, max);
263     histogram->Sumw2();
264     if(append) fOutputList->Add(histogram);
265     return histogram;   
266 }
267 //_____________________________________________________________________________
268 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)
269 {
270     // book a TH2F and connect it to the output container
271     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
272     if(fReduceBinsXByFactor > 0 ) binsx = TMath::Nint(binsx/fReduceBinsXByFactor);
273     if(fReduceBinsYByFactor > 0 ) binsy = TMath::Nint(binsy/fReduceBinsYByFactor);
274     if(!fOutputList) return 0x0;
275     TString title(name);
276     if(c!=-1) { // format centrality dependent histograms accordingly
277         name = Form("%s_%i", name, c);
278         title += Form("_%i-%i", fCentralityClasses->At(c), fCentralityClasses->At(1+c));
279     }
280     title += Form(";%s;%s", x, y);
281     TH2F* histogram = new TH2F(name, title.Data(), binsx, minx, maxx, binsy, miny, maxy);
282     histogram->Sumw2();
283     if(append) fOutputList->Add(histogram);
284     return histogram;   
285 }
286 //_____________________________________________________________________________
287 void AliAnalysisTaskRhoVnModulation::UserCreateOutputObjects()
288 {
289     // create output objects
290     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
291     fOutputList = new TList();
292     fOutputList->SetOwner(kTRUE);
293     if(!fCentralityClasses) {   // classes must be defined at this point
294         Int_t c[] = {0, 20, 40, 60, 80, 100};
295         fCentralityClasses = new TArrayI(sizeof(c)/sizeof(c[0]), c);
296     }
297     // global QA
298     fHistCentrality =           BookTH1F("fHistCentrality", "centrality", 102, -2, 100);
299     fHistVertexz =              BookTH1F("fHistVertexz", "vertex z (cm)", 100, -12, 12);
300
301     // pico track kinematics
302     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) { 
303         fHistPicoTrackPt[i] =          BookTH1F("fHistPicoTrackPt", "p_{t} [GeV/c]", 100, 0, 50, i);
304         fHistPicoTrackMult[i] =        BookTH1F("fHistPicoTrackMult", "multiplicity", 100, 0, 5000, i);
305         if(fFillQAHistograms) {
306             fHistPicoCat1[i] =             BookTH2F("fHistPicoCat1", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
307             fHistPicoCat2[i] =             BookTH2F("fHistPicoCat2", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
308             fHistPicoCat3[i] =             BookTH2F("fHistPicoCat3", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
309         }
310         // emcal kinematics
311         /* fHistClusterPt[i] =            BookTH1F("fHistClusterPt", "p_{t} [GeV/c]", 100, 0, 100, i); */
312         /* fHistClusterPhi[i] =           BookTH1F("fHistClusterPhi", "#phi", 100, 0, TMath::TwoPi(), i); */
313         /* fHistClusterEta[i] =           BookTH1F("fHistClusterEta", "#eta", 100, -5, 5); */
314
315         // emcal kinematics after hadronic correction
316         /* fHistClusterCorrPt[i] =        BookTH1F("fHistClusterCorrPt", "p_{t} [GeV/c]", 100, 0, 100, i); */
317         /* fHistClusterCorrPhi[i] =       BookTH1F("fHistClusterCorrPhi", "#phi", 100, 0, TMath::TwoPi(), i); */
318         /* fHistClusterCorrEta[i] =       BookTH1F("fHistClusterCorrEta", "#eta", 100, -5, 5, i); */
319     }
320
321     if(fFillQAHistograms) {
322         // event plane estimates and quality
323         fHistPsiControl =           new TProfile("fHistPsiControl", "fHistPsiControl", 10, 0, 10);
324         fHistPsiControl->Sumw2();
325         fHistPsiSpread =            new TProfile("fHistPsiSpread", "fHistPsiSpread", 4, 0, 4);
326         fHistPsiSpread->Sumw2();
327         fHistPsiControl->GetXaxis()->SetBinLabel(1, "<#Psi_{2, VZEROA}>");
328         fHistPsiControl->GetXaxis()->SetBinLabel(2, "<#Psi_{2, VZEROC}>");
329         fHistPsiControl->GetXaxis()->SetBinLabel(3, "<#Psi_{2, TPC}>");
330         fHistPsiControl->GetXaxis()->SetBinLabel(4, "<#Psi_{2, TPC, #eta < 0}>");
331         fHistPsiControl->GetXaxis()->SetBinLabel(5, "<#Psi_{2, TPC, #eta > 0}>");
332         fHistPsiControl->GetXaxis()->SetBinLabel(6, "<#Psi_{3, VZEROA}>");
333         fHistPsiControl->GetXaxis()->SetBinLabel(7, "<#Psi_{3, VZEROC}>");
334         fHistPsiControl->GetXaxis()->SetBinLabel(8, "<#Psi_{3, TPC}>");
335         fHistPsiControl->GetXaxis()->SetBinLabel(9, "<#Psi_{3, TPC, #eta < 0}>");
336         fHistPsiControl->GetXaxis()->SetBinLabel(10, "<#Psi_{3, TPC, #eta > 0}>");
337         fHistPsiSpread->GetXaxis()->SetBinLabel(1, "<#Psi_{2, VZEROA} - #Psi_{2, VZEROC}>");
338         fHistPsiSpread->GetXaxis()->SetBinLabel(2, "<#Psi_{2, VZEROC} - #Psi_{2, TPC}>");
339         fHistPsiSpread->GetXaxis()->SetBinLabel(3, "<#Psi_{2, VZEROC} - #Psi_{2, TPC}>");
340         fHistPsiSpread->GetXaxis()->SetBinLabel(4, "<#Psi_{2, TPC, #eta < 0} - #Psi_{2, TPC, #eta > 0}>");
341         fOutputList->Add(fHistPsiControl);
342         fOutputList->Add(fHistPsiSpread);
343         fHistPsiVZEROA =            BookTH1F("fHistPsiVZEROA", "#Psi_{VZEROA}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
344         fHistPsiVZEROC =            BookTH1F("fHistPsiVZEROC", "#Psi_{VZEROC}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
345         fHistPsiVZERO =             BookTH1F("fHistPsiVZERO", "#Psi_{VZERO}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
346         fHistPsiTPC =               BookTH1F("fHistPsiTPC", "#Psi_{TPC}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
347         fHistPsiVZEROAV0M =         BookTH2F("fHistPsiVZEROAV0M", "V0M", "#Psi_{2, VZEROA}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
348         fHistPsiVZEROCV0M =         BookTH2F("fHistPsiVZEROCV0M", "V0M", "#Psi_{2, VZEROC}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
349         fHistPsiVZEROVV0M =         BookTH2F("fHistPsiVZEROV0M", "V0M", "#Psi_{2, VZERO}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
350         fHistPsiTPCiV0M =           BookTH2F("fHistPsiTPCV0M", "V0M", "#Psi_{2, TRK}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
351         fHistPsiVZEROATRK =         BookTH2F("fHistPsiVZEROATRK", "TRK", "#Psi_{2, VZEROA}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
352         fHistPsiVZEROCTRK =         BookTH2F("fHistPsiVZEROCTRK", "TRK", "#Psi_{2, VZEROC}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
353         fHistPsiVZEROTRK =          BookTH2F("fHistPsiVZEROTRK", "TRK", "#Psi_{2, VZERO}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
354         fHistPsiTPCTRK =            BookTH2F("fHistPsiTPCTRK", "TRK", "#Psi_{2, TRK}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
355     }
356     // background
357     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i ++) {
358         fHistRhoPackage[i] =           BookTH1F("fHistRhoPackage",  "#rho [GeV/c]", 100, 0, 150, i);
359         fHistRho[i] =                  BookTH1F("fHistRho", "#rho [GeV/c]", 100, 0, 150, i);
360     }
361     fHistRhoVsMult =            BookTH2F("fHistRhoVsMult", "multiplicity", "#rho [GeV/c]", 100, 0, 4000, 100, 0, 250);
362     fHistRhoVsCent =            BookTH2F("fHistRhoVsCent", "centrality", "#rho [GeV/c]", 100, 0, 100, 100, 0, 250);
363     fHistRhoAVsMult =           BookTH2F("fHistRhoAVsMult", "multiplicity", "#rho * A (jet) [GeV/c]", 100, 0, 4000, 100, 0, 50);
364     fHistRhoAVsCent =           BookTH2F("fHistRhoAVsCent", "centrality", "#rho * A (jet) [GeV/c]", 100, 0, 100, 100, 0, 50);
365
366     TString detector("");
367     switch (fDetectorType) {
368         case kTPC : detector+="TPC";
369             break;
370         case kVZEROA : detector+="VZEROA";
371             break;
372         case kVZEROC : detector+="VZEROC";
373             break;
374         case kVZEROComb : detector+="VZEROComb";
375             break; 
376         default: break;
377     }
378     // delta pt distributions
379     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i ++) {
380         if(fFillQAHistograms)   fHistRCPhiEta[i] = BookTH2F("fHistRCPhiEta", "#phi (RC)", "#eta (RC)", 40, 0, TMath::TwoPi(), 40, -1, 1, i);
381         fHistRhoVsRCPt[i] =            BookTH2F("fHistRhoVsRCPt", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
382         fHistRCPt[i] =                 BookTH1F("fHistRCPt", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
383         if(fFillQAHistograms)   fHistRCPhiEtaExLJ[i] = BookTH2F("fHistRCPhiEtaExLJ", "#phi (RC)", "#eta (RC)", 40, 0, TMath::TwoPi(), 40, -1, 1, i);
384         fHistDeltaPtDeltaPhi2[i] =  BookTH2F("fHistDeltaPtDeltaPhi2", Form("#phi - #Psi_{2, %s}", detector.Data()), "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
385         fHistDeltaPtDeltaPhi3[i] =  BookTH2F("fHistDeltaPtDeltaPhi3", Form("#phi - #Psi_{3, %s}", detector.Data()), "#delta p_{t} [GeV/c]", 40, 0, TMath::TwoPi()/3., 400, -70, 130, i);
386         fHistRhoVsRCPtExLJ[i] =        BookTH2F("fHistRhoVsRCPtExLJ", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
387         fHistRCPtExLJ[i] =             BookTH1F("fHistRCPtExLJ", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
388         /* fHistRCPhiEtaRand[i] =         BookTH2F("fHistRCPhiEtaRand", "#phi (RC)", "#eta (RC)", 100, 0, TMath::TwoPi(), 100, -1, 1, i); */
389         fHistDeltaPtDeltaPhi2ExLJ[i] = BookTH2F("fHistDeltaPtDeltaPhi2ExLJ", Form("#phi - #Psi_{2, %s}", detector.Data()),  "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
390         fHistDeltaPtDeltaPhi3ExLJ[i] = BookTH2F("fHistDeltaPtDeltaPhi3ExLJ", Form("#phi - #Psi_{3, %s}", detector.Data()), "#delta p_{t} [GeV/c]", 40, 0, TMath::TwoPi()/3., 400, -70, 130, i);
391         /* fHistRhoVsRCPtRand[i] =        BookTH2F("fHistRhoVsRCPtRand", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i); */
392         /* fHistRCPtRand[i] =             BookTH1F("fHistRCPtRand", "p_{t} (RC) [GeV/c]", 130, -20, 150, i); */
393         /* fHistDeltaPtDeltaPhi2Rand[i] =  BookTH2F("fHistDeltaPtDeltaPhi2Rand", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 50, 0, TMath::Pi(), 100, -50, 100, i); */
394         /* fHistDeltaPtDeltaPhi3Rand[i] =  BookTH2F("fHistDeltaPtDeltaPhi3Rand", "#phi - #Psi_{TPC}", "#delta p_{t} [GeV/c]", 50, 0, TMath::TwoPi()/3., 100, -50, 100, i); */
395         // jet histograms (after kinematic cuts)
396         fHistJetPtRaw[i] =             BookTH1F("fHistJetPtRaw", "p_{t} RAW [GeV/c]", 200, -50, 150, i);
397         fHistJetPt[i] =                BookTH1F("fHistJetPt", "p_{t} [GeV/c]", 350, -100, 250, i);
398         if(fFillQAHistograms)   fHistJetEtaPhi[i] =            BookTH2F("fHistJetEtaPhi", "#eta", "#phi", 100, -1, 1, 100, 0, TMath::TwoPi(), i);
399         fHistJetPtArea[i] =            BookTH2F("fHistJetPtArea", "p_{t} [GeV/c]", "Area", 175, -100, 250, 30, 0, 0.9, i);
400         fHistJetPtConstituents[i] =    BookTH2F("fHistJetPtConstituents", "p_{t} [GeV/c]", "Area", 350, -100, 250, 60, 0, 150, i);
401         fHistJetEtaRho[i] =            BookTH2F("fHistJetEtaRho", "#eta", "#rho", 100, -1, 1, 100, 0, 300, i);
402         // in plane and out of plane spectra
403         fHistJetPsi2Pt[i] =          BookTH2F("fHistJetPsi2Pt", Form("#phi_{jet} - #Psi_{2, %s}", detector.Data()), "p_{t} [GeV/c]", 40, 0., TMath::Pi(), 350, -100, 250, i);
404         fHistJetPsi3Pt[i] =          BookTH2F("fHistJetPsi3Pt", Form("#phi_{jet} - #Psi_{3, %s}", detector.Data()), "p_{t} [GeV/c]", 40, 0., TMath::TwoPi()/3., 350, -100, 250, i);
405         // profiles for all correlator permutations which are necessary to calculate each second and third order event plane resolution
406         fProfV2Resolution[i] = new TProfile(Form("fProfV2Resolution_%i", i), Form("fProfV2Resolution_%i", i), 11, -0.5, 10.5);
407         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(3, "<cos(2(#Psi_{VZEROA} - #Psi_{VZEROC}))>");
408         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(4, "<cos(2(#Psi_{VZEROC} - #Psi_{VZEROA}))>");
409         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(5, "<cos(2(#Psi_{VZEROA} - #Psi_{TPC}))>");
410         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(6, "<cos(2(#Psi_{TPC} - #Psi_{VZEROA}))>");
411         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(7, "<cos(2(#Psi_{VZEROC} - #Psi_{TPC}))>");
412         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(8, "<cos(2(#Psi_{TPC} - #Psi_{VZEROC}))>");
413         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(9, "<cos(2(#Psi_{VZERO} - #Psi_{TPC_A}))>");
414         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(10, "<cos(2(#Psi_{VZERO} - #Psi_{TPC_B}))>");
415         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(11, "<cos(2(#Psi_{TPC_A} - #Psi_{TPC_B}))>");
416         fOutputList->Add(fProfV2Resolution[i]); 
417         fProfV3Resolution[i] = new TProfile(Form("fProfV3Resolution_%i", i), Form("fProfV3Resolution_%i", i), 11, -0.5, 10.5);
418         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(3, "<cos(3(#Psi_{VZEROA} - #Psi_{VZEROC}))>");
419         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(4, "<cos(3(#Psi_{VZEROC} - #Psi_{VZEROA}))>");
420         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(5, "<cos(3(#Psi_{VZEROA} - #Psi_{TPC}))>");
421         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(6, "<cos(3(#Psi_{TPC} - #Psi_{VZEROA}))>");
422         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(7, "<cos(3(#Psi_{VZEROC} - #Psi_{TPC}))>");
423         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(8, "<cos(3(#Psi_{TPC} - #Psi_{VZEROC}))>");
424         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(9, "<cos(3(#Psi_{VZERO} - #Psi_{TPC_A}))>");
425         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(10, "<cos(3(#Psi_{VZERO} - #Psi_{TPC_B}))>");
426         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(11, "<cos(3(#Psi_{TPC_A} - #Psi_{TPC_B}))>");
427         fOutputList->Add(fProfV3Resolution[i]); 
428     }
429     // cdf and pdf of chisquare distribution
430     fHistPvaluePDF = BookTH1F("fHistPvaluePDF", "PDF #chi^{2}", 500, 0, 1);
431     fHistPvalueCDF = BookTH1F("fHistPvalueCDF", "CDF #chi^{2}", 500, 0, 1);
432     // vn profile
433     Float_t temp[fCentralityClasses->GetSize()];
434     for(Int_t i(0); i < fCentralityClasses->GetSize(); i++) temp[i] = fCentralityClasses->At(i);
435     fProfV2 = new TProfile("fProfV2", "fProfV2", fCentralityClasses->GetSize()-1, temp);
436     fProfV3 = new TProfile("fProfV3", "fProfV3", fCentralityClasses->GetSize()-1, temp);
437     fOutputList->Add(fProfV2);
438     fOutputList->Add(fProfV3);
439     switch (fFitModulationType) {
440         case kQC2 : {
441             fProfV2Cumulant = new TProfile("fProfV2Cumulant", "fProfV2Cumulant", fCentralityClasses->GetSize()-1, temp);
442             fProfV3Cumulant = new TProfile("fProfV3Cumulant", "fProfV3Cumulant", fCentralityClasses->GetSize()-1, temp);
443             fOutputList->Add(fProfV2Cumulant);
444             fOutputList->Add(fProfV3Cumulant);
445         } break;
446         case kQC4 : {
447             fProfV2Cumulant = new TProfile("fProfV2Cumulant", "fProfV2Cumulant", fCentralityClasses->GetSize()-1, temp);
448             fProfV3Cumulant = new TProfile("fProfV3Cumulant", "fProfV3Cumulant", fCentralityClasses->GetSize()-1, temp);
449             fOutputList->Add(fProfV2Cumulant);
450             fOutputList->Add(fProfV3Cumulant);
451         } break;
452         default : break;
453     }
454     // for the histograms initialized below, binning is fixed to runnumbers or flags
455     fReduceBinsXByFactor = 1;
456     fReduceBinsYByFactor = 1;
457     if(fFillQAHistograms) {
458         fHistRunnumbersEta = new TH2F("fHistRunnumbersEta", "fHistRunnumbersEta", 100, -.5, 99.5, 100, -1.1, 1.1);
459         fHistRunnumbersEta->Sumw2();
460         fOutputList->Add(fHistRunnumbersEta);
461         fHistRunnumbersPhi = new TH2F("fHistRunnumbersPhi", "fHistRunnumbersPhi", 100, -.5, 99.5, 100, -0.2, TMath::TwoPi()+0.2);
462         fHistRunnumbersPhi->Sumw2();
463         fOutputList->Add(fHistRunnumbersPhi);
464     }
465     fHistAnalysisSummary = BookTH1F("fHistAnalysisSummary", "flag", 52, -0.5, 52.5);
466     fHistSwap = new TH1F("fHistSwap", "fHistSwap", 20, 0, TMath::TwoPi());
467     if(fUsePtWeight) fHistSwap->Sumw2();
468
469     if(fUserSuppliedV2) fOutputList->Add(fUserSuppliedV2);
470     if(fUserSuppliedV3) fOutputList->Add(fUserSuppliedV3);
471     if(fUserSuppliedR2) fOutputList->Add(fUserSuppliedR2);
472     if(fUserSuppliedR3) fOutputList->Add(fUserSuppliedR3);
473     // increase readability of output list
474     fOutputList->Sort();
475     PostData(1, fOutputList);
476
477     switch (fRunModeType) {
478         case kLocal : {
479             fOutputListGood = new TList();
480             fOutputListGood->SetOwner(kTRUE);
481             fOutputListBad = new TList();
482             fOutputListBad->SetOwner(kTRUE);
483             PostData(2, fOutputListGood);
484             PostData(3, fOutputListBad);
485         } break;
486         default: break;
487     }
488
489     // get the containers
490     fTracksCont = GetParticleContainer("Tracks");
491     fJetsCont = GetJetContainer("Jets");
492 }
493 //_____________________________________________________________________________
494 Bool_t AliAnalysisTaskRhoVnModulation::Run()
495 {
496     // user exec: execute once for each event
497     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
498     if(!fTracks||!fJets||!fRho) return kFALSE;
499     if(!fLocalInit) fLocalInit = InitializeAnalysis();
500     // reject the event if expected data is missing
501     if(!PassesCuts(InputEvent())) return kFALSE;
502     if(!fCaloClusters && fDebug > 0) printf(" > Warning: couldn't retreive calo clusters! < \n");
503     // set the rho value 
504     fLocalRho->SetVal(fRho->GetVal());
505     // [0][0] psi2a     [1,0]   psi2c
506     // [0][1] psi3a     [1,1]   psi3c
507     Double_t vzero[2][2];
508     CalculateEventPlaneVZERO(vzero);
509     /* for the combined vzero event plane
510      * [0] psi2         [1] psi3
511      * not fully implmemented yet, use with caution ! */
512     Double_t vzeroComb[2];
513     CalculateEventPlaneCombinedVZERO(vzeroComb);
514     // [0] psi2         [1] psi3
515     Double_t tpc[2];
516     CalculateEventPlaneTPC(tpc);
517     Double_t psi2(-1), psi3(-1);
518     // arrays which will hold the fit parameters
519     switch (fDetectorType) {    // determine the detector type for the rho fit
520         case kTPC :     { psi2 = tpc[0];         psi3 = tpc[1]; }        break;
521         case kVZEROA :  { psi2 = vzero[0][0];    psi3 = vzero[0][1]; }   break;  
522         case kVZEROC :  { psi2 = vzero[1][0];    psi3 = vzero[1][1]; }   break;
523         case kVZEROComb : { psi2 = vzeroComb[0]; psi3 = vzeroComb[1];} break;
524         default : break;
525     }
526     switch (fFitModulationType) { // do the fits
527         case kNoFit : { 
528              switch (fCollisionType) {
529                  case kPythia : { // background is zero for pp jets
530                      fFitModulation->FixParameter(0, 0);
531                      fLocalRho->SetVal(0);
532                  } break;
533                  default :  {
534                      fFitModulation->FixParameter(0, fLocalRho->GetVal()); 
535                  } break;
536              }
537         } break;
538         case kV2 : {    // only v2
539             if(CorrectRho(psi2, psi3)) {
540                 fProfV2->Fill(fCent, fFitModulation->GetParameter(3));
541                 if(fUserSuppliedR2) {
542                     Double_t r(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
543                     if(r > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r);
544                 }
545                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
546             }
547         } break;
548         case kV3 : {    // only v3
549             if(CorrectRho(psi2, psi3)) {
550                 if(fUserSuppliedR3) {
551                     Double_t r(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
552                     if(r > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r);
553                 }
554                 fProfV3->Fill(fCent, fFitModulation->GetParameter(3));
555                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
556             }
557         } break;
558         case kQC2 : {   // qc2 analysis
559             if(CorrectRho(psi2, psi3)) {
560                 if(fUserSuppliedR2 && fUserSuppliedR3) {
561                     // note for the qc method, resolution is REVERSED to go back to v2obs
562                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
563                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
564                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)*r2);
565                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)*r3);
566                 }
567                 if (fUsePtWeight) { // use weighted weights
568                     Double_t dQCnM11 = (fNoEventWeightsForQC) ? 1. : QCnM11();
569                     fProfV2->Fill(fCent, fFitModulation->GetParameter(3), dQCnM11);
570                     fProfV3->Fill(fCent, fFitModulation->GetParameter(7), dQCnM11); 
571                 } else {
572                     Double_t dQCnM = (fNoEventWeightsForQC) ? 2. : QCnM();
573                     fProfV2->Fill(fCent, fFitModulation->GetParameter(3), dQCnM*(dQCnM-1));
574                     fProfV3->Fill(fCent, fFitModulation->GetParameter(7), dQCnM*(dQCnM-1));
575                 }
576                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
577             }
578         } break;
579         case kQC4 : {
580             if(CorrectRho(psi2, psi3)) {
581                 if(fUserSuppliedR2 && fUserSuppliedR3) {
582                     // note for the qc method, resolution is REVERSED to go back to v2obs   
583                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
584                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
585                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)*r2);
586                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)*r3);
587                 }
588                 if (fUsePtWeight) { // use weighted weights
589                     fProfV2->Fill(fCent, TMath::Power(fFitModulation->GetParameter(3),0.5)/*, QCnM1111()*/);
590                     fProfV3->Fill(fCent, TMath::Power(fFitModulation->GetParameter(7),0.5)/*, QCnM1111()*/); 
591                 } else {
592                     fProfV2->Fill(fCent, TMath::Power(fFitModulation->GetParameter(3),0.5)/*, QCnM()*(QCnM()-1)*(QCnM()-2)*(QCnM()-3)*/);
593                     fProfV3->Fill(fCent, TMath::Power(fFitModulation->GetParameter(7),0.5)/*, QCnM()*(QCnM()-1)*(QCnM()-2)*(QCnM()-3)*/);
594                 }
595             }
596             CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
597         } break;
598         default : {
599             if(CorrectRho(psi2, psi3)) {
600                 if(fUserSuppliedR2 && fUserSuppliedR3) {
601                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
602                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
603                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r2);
604                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)/r3);
605                 }
606                 fProfV2->Fill(fCent, fFitModulation->GetParameter(3));
607                 fProfV3->Fill(fCent, fFitModulation->GetParameter(7));
608                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
609             }
610         } break;
611     }
612     // if all went well, update the local rho parameter
613     fLocalRho->SetLocalRho(fFitModulation);
614     // fill a number of histograms 
615     if(fFillHistograms)         FillHistogramsAfterSubtraction(psi2, psi3, vzero, vzeroComb, tpc);
616     if(fFillQAHistograms)       FillQAHistograms(InputEvent());
617     // send the output to the connected output container
618     PostData(1, fOutputList);
619     switch (fRunModeType) {
620         case kLocal : {
621             PostData(2, fOutputListGood);
622             PostData(3, fOutputListBad);
623         } break;
624         default: break;
625     }
626
627     return kTRUE;
628 }
629 //_____________________________________________________________________________
630 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneVZERO(Double_t vzero[2][2]) const 
631 {
632     // get the vzero event plane
633     if(fUseV0EventPlaneFromHeader) {    // use the vzero from the header
634         Double_t a(0), b(0), c(0), d(0), e(0), f(0), g(0), h(0);
635         vzero[0][0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 2, a, b);
636         vzero[1][0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 2, c, d);
637         vzero[0][1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 3, e, f);
638         vzero[1][1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 3, g, h);
639         return;
640     }
641     // grab the vzero event plane without recentering
642     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
643     Double_t qxa2(0), qya2(0), qxc2(0), qyc2(0);    // for psi2
644     Double_t qxa3(0), qya3(0), qxc3(0), qyc3(0);    // for psi3
645     for(Int_t iVZERO(0); iVZERO < 64; iVZERO++) {
646         Double_t phi(TMath::PiOver4()*(.5+iVZERO%8)), /* eta(0), */ weight(InputEvent()->GetVZEROEqMultiplicity(iVZERO));
647 //        (iVZERO<32) ? eta = -3.45+.5*(iVZERO/8) : eta = 4.8-.6*((iVZERO/8)-4);
648         if(iVZERO<32) {
649             qxa2 += weight*TMath::Cos(2.*phi);
650             qya2 += weight*TMath::Sin(2.*phi);
651             qxa3 += weight*TMath::Cos(3.*phi);
652             qya3 += weight*TMath::Sin(3.*phi);
653         }
654         else {
655             qxc2 += weight*TMath::Cos(2.*phi);
656             qyc2 += weight*TMath::Sin(2.*phi);
657             qxc3 += weight*TMath::Cos(3.*phi);
658             qyc3 += weight*TMath::Sin(3.*phi);
659        }
660     }
661     vzero[0][0] = .5*TMath::ATan2(qya2, qxa2);
662     vzero[1][0] = .5*TMath::ATan2(qyc2, qxc2);
663     vzero[0][1] = (1./3.)*TMath::ATan2(qya3, qxa3);
664     vzero[1][1] = (1./3.)*TMath::ATan2(qyc3, qxc3);
665 }
666 //_____________________________________________________________________________
667 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneTPC(Double_t* tpc)
668 {
669    // grab the TPC event plane
670    if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
671    fNAcceptedTracks = 0;                // reset the track counter
672    Double_t qx2(0), qy2(0);     // for psi2
673    Double_t qx3(0), qy3(0);     // for psi3
674    if(fTracks) {
675        Float_t excludeInEta = -999;
676        if(fExcludeLeadingJetsFromFit > 0 ) {    // remove the leading jet from ep estimate
677            AliEmcalJet* leadingJet(GetJetContainer()->GetLeadingJet());
678            if(leadingJet) excludeInEta = leadingJet->Eta();
679        }
680        Int_t iTracks(fTracks->GetEntriesFast());
681        for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
682            AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
683            if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
684            if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta) < GetJetContainer()->GetJetRadius()*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - GetJetContainer()->GetJetRadius() - GetJetContainer()->GetJetEtaMax() ) > 0 )) continue;
685            fNAcceptedTracks++;
686            qx2+= TMath::Cos(2.*track->Phi());
687            qy2+= TMath::Sin(2.*track->Phi());
688            qx3+= TMath::Cos(3.*track->Phi());
689            qy3+= TMath::Sin(3.*track->Phi());
690        }
691    }
692    tpc[0] = .5*TMath::ATan2(qy2, qx2);
693    tpc[1] = (1./3.)*TMath::ATan2(qy3, qx3);
694
695 //_____________________________________________________________________________
696 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneCombinedVZERO(Double_t* comb) const
697 {
698     // grab the combined vzero event plane
699 //    if(fUseV0EventPlaneFromHeader) {    // use the vzero from the header
700         Double_t a(0), b(0), c(0), d(0);
701         comb[0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 10, 2, a, b);
702         comb[1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 10, 3, c, d);
703 //    } else {
704 //        Double_t qx2a(0), qy2a(0), qx2c(0), qy2c(0), qx3a(0), qy3a(0), qx3c(0), qy3c(0);
705 //        InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 2, qx2a, qy2a);
706 //        InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 2, qx2c, qy2c);
707 //        InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 3, qx3a, qy3a);
708 //        InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 3, qx3c, qy3c);
709 // FIXME the rest of this function isn't impelmented yet (as of 01-07-2013)
710 //        Double_t chi2A(-1), chi2C(-1), chi3A(-1), chi3C(-1);     // get chi from the resolution
711 //        Double_t qx2(chi2A*chi2A*qx2a+chi2C*chi2C*qx2c);
712 //        Double_t qy2(chi2A*chi2A*qy2a+chi2C*chi2C*qy2c);
713 //        Double_t qx3(chi3A*chi3A*qx3a+chi3C*chi3C*qx3c);
714 //        Double_t qy3(chi3A*chi3A*qy3a+chi3C*chi3C*qy3c);
715 //        comb[0] = .5*TMath::ATan2(qy2, qx2);
716 //        comb[1] = (1./3.)*TMath::ATan2(qy3, qx3);
717 //    }
718 }
719 //_____________________________________________________________________________
720 void AliAnalysisTaskRhoVnModulation::CalculateEventPlaneResolution(Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc)
721 {
722     // fill the profiles for the resolution parameters
723     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
724     fProfV2Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(2.*(vzero[0][0] - vzero[1][0])));
725     fProfV2Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(2.*(vzero[1][0] - vzero[0][0])));
726     fProfV2Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(2.*(vzero[0][0] - tpc[0])));
727     fProfV2Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(2.*(tpc[0] - vzero[0][0])));
728     fProfV2Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(2.*(vzero[1][0] - tpc[0])));
729     fProfV2Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(2.*(tpc[0] - vzero[1][0])));
730     fProfV3Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(3.*(vzero[0][0] - vzero[1][0])));
731     fProfV3Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(3.*(vzero[1][0] - vzero[0][0])));
732     fProfV3Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(3.*(vzero[0][0] - tpc[0])));
733     fProfV3Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(3.*(tpc[0] - vzero[0][0])));
734     fProfV3Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(3.*(vzero[1][0] - tpc[0])));
735     fProfV3Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(3.*(tpc[0] - vzero[1][0])));
736     // for the resolution of the combined vzero event plane, use two tpc halves as uncorrelated subdetectors
737     Double_t qx2a(0), qy2a(0);     // for psi2a, negative eta
738     Double_t qx3a(0), qy3a(0);     // for psi3a, negative eta
739     Double_t qx2b(0), qy2b(0);     // for psi2a, positive eta
740     Double_t qx3b(0), qy3b(0);     // for psi3a, positive eta
741     if(fTracks) {
742        Int_t iTracks(fTracks->GetEntriesFast());
743        for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
744            AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
745            if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
746            if(track->Eta() < 0 ) {
747                qx2a+= TMath::Cos(2.*track->Phi());
748                qy2a+= TMath::Sin(2.*track->Phi());
749                qx3a+= TMath::Cos(3.*track->Phi());
750                qy3a+= TMath::Sin(3.*track->Phi());
751            } else if (track->Eta() > 0) {
752                qx2b+= TMath::Cos(2.*track->Phi());
753                qy2b+= TMath::Sin(2.*track->Phi());
754                qx3b+= TMath::Cos(3.*track->Phi());
755                qy3b+= TMath::Sin(3.*track->Phi());
756            }
757        }
758    }
759    Double_t tpca2(.5*TMath::ATan2(qy2a, qx2a));
760    Double_t tpca3((1./3.)*TMath::ATan2(qy3a, qx3a));
761    Double_t tpcb2(.5*TMath::ATan2(qy2b, qx2b));
762    Double_t tpcb3((1./3.)*TMath::ATan2(qy3b, qx3b));
763    fProfV2Resolution[fInCentralitySelection]->Fill(8., TMath::Cos(2.*(vzeroComb[0] - tpca2)));
764    fProfV2Resolution[fInCentralitySelection]->Fill(9., TMath::Cos(2.*(vzeroComb[0] - tpcb2)));
765    fProfV2Resolution[fInCentralitySelection]->Fill(10., TMath::Cos(2.*(tpca2 - tpcb2))); 
766    fProfV3Resolution[fInCentralitySelection]->Fill(8., TMath::Cos(3.*(vzeroComb[1] - tpca3)));
767    fProfV3Resolution[fInCentralitySelection]->Fill(9., TMath::Cos(3.*(vzeroComb[1] - tpcb3)));
768    fProfV3Resolution[fInCentralitySelection]->Fill(10., TMath::Cos(3.*(tpca3 - tpcb3))); 
769 }   
770 //_____________________________________________________________________________
771 Double_t AliAnalysisTaskRhoVnModulation::CalculateEventPlaneChi(Double_t resEP) const
772 {
773     // Get Chi from EP resolution (PRC 58 1671)
774     Double_t chi(2.), delta (1.);
775     for (Int_t i(0); i < 15; i++) {
776         chi = ((TMath::Sqrt(TMath::Pi()/2.)/2.)*chi*exp(-chi*chi/4.)*(TMath::BesselI0(chi*chi/4.)+TMath::BesselI1(chi* chi/4.)) < resEP) ? chi+delta : chi-delta;
777         delta/=2.;
778     }
779     return chi;
780 }
781 //_____________________________________________________________________________
782 void AliAnalysisTaskRhoVnModulation::CalculateRandomCone(Float_t &pt, Float_t &eta, Float_t &phi, 
783         AliEmcalJet* jet) const
784 {
785     // get a random cone
786     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
787     pt = 0; eta = 0; phi = 0;
788     Float_t etaJet(999), phiJet(999), dJet(999);        // no jet: same as jet very far away
789     if(jet) { // if a leading jet is given, use its kinematic properties
790         etaJet = jet->Eta();
791         phiJet = jet->Phi();
792     }
793     // force the random cones to at least be within detector acceptance
794     Float_t minPhi(GetJetContainer()->GetJetPhiMin()), maxPhi(GetJetContainer()->GetJetPhiMax());
795     if(maxPhi > TMath::TwoPi()) maxPhi = TMath::TwoPi();
796     if(minPhi < 0 ) minPhi = 0;
797     Float_t diffRcRJR(TMath::Abs(fRandomConeRadius-GetJetContainer()->GetJetRadius()));
798     // construct a random cone and see if it's far away enough from the leading jet
799     Int_t attempts(1000);
800     while(kTRUE) {
801         attempts--;
802         eta = gRandom->Uniform(GetJetContainer()->GetJetEtaMin()+diffRcRJR, GetJetContainer()->GetJetEtaMax()-diffRcRJR);
803         phi = gRandom->Uniform(minPhi, maxPhi);
804
805         dJet = TMath::Sqrt((etaJet-eta)*(etaJet-eta)+(phiJet-phi)*(phiJet-phi));
806         if(dJet > fMinDisanceRCtoLJ) break;
807         else if (attempts == 0) {
808             printf(" > No random cone after 1000 tries, giving up ... !\n");
809             return;
810         }
811     }
812     if(fTracksCont) {
813         AliVParticle* track = fTracksCont->GetNextAcceptParticle(0);
814         while(track) {
815             Float_t etaTrack(track->Eta()), phiTrack(track->Phi()), ptTrack(track->Pt());
816             // get distance from cone
817             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi + TMath::TwoPi())) phiTrack+=TMath::TwoPi();
818             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi - TMath::TwoPi())) phiTrack-=TMath::TwoPi();
819             if(TMath::Sqrt(TMath::Abs((etaTrack-eta)*(etaTrack-eta)+(phiTrack-phi)*(phiTrack-phi))) <= fRandomConeRadius) pt+=ptTrack;
820             track = fTracksCont->GetNextAcceptParticle();
821         }
822     }
823 }
824 //_____________________________________________________________________________
825 Double_t AliAnalysisTaskRhoVnModulation::CalculateQC2(Int_t harm) {
826     // get the second order q-cumulant, a -999 return will be caught in the qa routine of CorrectRho
827     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
828     Double_t reQ(0), imQ(0), modQ(0), M11(0), M(0);
829     if(fUsePtWeight) {  // for the weighted 2-nd order q-cumulant
830         QCnQnk(harm, 1, reQ, imQ);      // get the weighted 2-nd order q-vectors
831         modQ = reQ*reQ+imQ*imQ;         // get abs Q-squared
832         M11 = QCnM11();                 // equals S2,1 - S1,2
833         return (M11 > 0) ? ((modQ - QCnS(1,2))/M11) : -999;
834     } // else return the non-weighted 2-nd order q-cumulant
835     QCnQnk(harm, 0, reQ, imQ);          // get the non-weighted 2-nd order q-vectors
836     modQ = reQ*reQ+imQ*imQ;             // get abs Q-squared
837     M = QCnM();
838     return (M > 1) ? (modQ - M)/(M*(M-1)) : -999;
839 }
840 //_____________________________________________________________________________
841 Double_t AliAnalysisTaskRhoVnModulation::CalculateQC4(Int_t harm) {
842     // get the fourth order q-cumulant, a -999 return will be caught in the qa routine of CorrectRho
843     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
844     Double_t reQn1(0), imQn1(0), reQ2n2(0), imQ2n2(0), reQn3(0), imQn3(0), M1111(0), M(0);
845     Double_t a(0), b(0), c(0), d(0), e(0), f(0), g(0);  // terms of the calculation
846     if(fUsePtWeight) {  // for the weighted 4-th order q-cumulant
847         QCnQnk(harm, 1, reQn1, imQn1);
848         QCnQnk(harm*2, 2, reQ2n2, imQ2n2);
849         QCnQnk(harm, 3, reQn3, imQn3);
850         // fill in the terms ...
851         a = (reQn1*reQn1+imQn1*imQn1)*(reQn1*reQn1+imQn1*imQn1);
852         b = reQ2n2*reQ2n2 + imQ2n2*imQ2n2;
853         c = -2.*(reQ2n2*reQn1*reQn1-reQ2n2*imQn1*imQn1+2.*imQ2n2*reQn1*imQn1);
854         d = 8.*(reQn3*reQn1+imQn3*imQn1);
855         e = -4.*QCnS(1,2)*(reQn1*reQn1+imQn1*imQn1);
856         f = -6.*QCnS(1,4);
857         g = 2.*QCnS(2,2);
858         M1111 = QCnM1111();
859         return (M1111 > 0) ? (a+b+c+d+e+f+g)/M1111 : -999;
860     }   // else return the unweighted case
861     Double_t reQn(0), imQn(0), reQ2n(0), imQ2n(0);
862     QCnQnk(harm, 0, reQn, imQn);
863     QCnQnk(harm*2, 0, reQ2n, imQ2n);
864     // fill in the terms ...
865     M = QCnM();
866     if(M < 4) return -999;
867     a = (reQn*reQn+imQn*imQn)*(reQn*reQn+imQn*imQn);
868     b = reQ2n*reQ2n + imQ2n*imQ2n;
869     c = -2.*(reQ2n*reQn*reQn-reQ2n*imQn*imQn+2.*imQ2n*reQn*imQn);
870     e = -4.*(M-2)*(reQn*reQn+imQn*imQn);
871     f = 2.*M*(M-3);
872     return (a+b+c+e+f)/(M*(M-1)*(M-2)*(M-3));
873 }
874 //_____________________________________________________________________________
875 void AliAnalysisTaskRhoVnModulation::QCnQnk(Int_t n, Int_t k, Double_t &reQ, Double_t &imQ) {
876     // get the weighted n-th order q-vector, pass real and imaginary part as reference
877     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
878     if(!fTracks) return;
879     fNAcceptedTracksQCn = 0;
880     Int_t iTracks(fTracks->GetEntriesFast());
881     for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
882         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
883         if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
884         fNAcceptedTracksQCn++;
885         // for the unweighted case, k equals zero and the weight doesn't contribute to the equation below
886         reQ += TMath::Power(track->Pt(), k) * TMath::Cos(((double)n)*track->Phi());
887         imQ += TMath::Power(track->Pt(), k) * TMath::Sin(((double)n)*track->Phi());
888     }
889 }
890 //_____________________________________________________________________________
891 void AliAnalysisTaskRhoVnModulation::QCnDiffentialFlowVectors(
892         TClonesArray* pois, TArrayD* ptBins, Bool_t vpart, Double_t* repn, Double_t* impn, 
893         Double_t *mp, Double_t *reqn, Double_t *imqn, Double_t* mq, Int_t n) 
894 {
895     // get  unweighted differential flow vectors
896     Int_t iPois(pois->GetEntriesFast());
897     if(vpart) {
898         for(Int_t i(0); i < iPois; i++) {
899             for(Int_t ptBin(0); ptBin < ptBins->GetSize()-1; ptBin++) {
900                 AliVTrack* poi = static_cast<AliVTrack*>(pois->At(i));
901                 if(PassesCuts(poi)) {
902                     if(poi->Pt() >= ptBins->At(ptBin) && poi->Pt() < ptBins->At(ptBin+1)) {
903                             // fill the flow vectors assuming that all poi's are in the rp selection (true by design)
904                             repn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
905                             impn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
906                             mp[ptBin]++;
907                             reqn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
908                             imqn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
909                             mq[ptBin]++;
910                     }
911                 }
912             }
913         }
914     } else {
915         for(Int_t i(0); i < iPois; i++) {
916             for(Int_t ptBin(0); ptBin < ptBins->GetSize()-1; ptBin++) {
917                 AliEmcalJet* poi = static_cast<AliEmcalJet*>(pois->At(i));
918                 if(PassesCuts(poi)) {    
919                     Double_t pt(poi->Pt()-poi->Area()*fLocalRho->GetLocalVal(poi->Phi(), GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
920                     if(pt >= ptBins->At(ptBin) && pt < ptBins->At(ptBin+1)) {    
921                             repn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
922                             impn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
923                             mp[ptBin]++;        // qn isn't filled, no overlap between poi's and rp's
924                     }
925                 }
926             }
927         }
928     }
929 }
930 //_____________________________________________________________________________
931 Double_t AliAnalysisTaskRhoVnModulation::QCnS(Int_t i, Int_t j) {
932     // get the weighted ij-th order autocorrelation correction
933     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
934     if(!fTracks || i <= 0 || j <= 0) return -999;
935     Int_t iTracks(fTracks->GetEntriesFast());
936     Double_t Sij(0);
937     for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
938         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
939         if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
940         Sij+=TMath::Power(track->Pt(), j);
941     }
942     return TMath::Power(Sij, i);
943 }
944 //_____________________________________________________________________________
945 Double_t AliAnalysisTaskRhoVnModulation::QCnM() {
946     // get multiplicity for unweighted q-cumulants. function QCnQnk should be called first
947     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
948     return (Double_t) fNAcceptedTracksQCn;
949 }
950 //_____________________________________________________________________________
951 Double_t AliAnalysisTaskRhoVnModulation::QCnM11() {
952     // get multiplicity weights for the weighted two particle cumulant
953     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
954     return (QCnS(2,1) - QCnS(1,2));
955 }
956 //_____________________________________________________________________________
957 Double_t AliAnalysisTaskRhoVnModulation::QCnM1111() {
958     // get multiplicity weights for the weighted four particle cumulant
959     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
960     return (QCnS(4,1)-6*QCnS(1,2)*QCnS(2,1)+8*QCnS(1,3)*QCnS(1,1)+3*QCnS(2,2)-6*QCnS(1,4));
961 }
962 //_____________________________________________________________________________
963 Bool_t AliAnalysisTaskRhoVnModulation::QCnRecovery(Double_t psi2, Double_t psi3) {
964     // decides how to deal with the situation where c2 or c3 is negative 
965     // returns kTRUE depending on whether or not a modulated rho is used for the jet background
966     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
967     if(TMath::AreEqualAbs(fFitModulation->GetParameter(3), .0, 1e-10) && TMath::AreEqualAbs(fFitModulation->GetParameter(7), .0,1e-10)) {
968         fFitModulation->SetParameter(7, 0);
969         fFitModulation->SetParameter(3, 0);
970         fFitModulation->SetParameter(0, fLocalRho->GetVal());
971         return kTRUE;   // v2 and v3 have physical null values
972     }
973     switch (fQCRecovery) {
974         case kFixedRho : {      // roll back to the original rho
975            fFitModulation->SetParameter(7, 0);
976            fFitModulation->SetParameter(3, 0);
977            fFitModulation->SetParameter(0, fLocalRho->GetVal());
978            return kFALSE;       // rho is forced to be fixed
979         }
980         case kNegativeVn : {
981            Double_t c2(fFitModulation->GetParameter(3));
982            Double_t c3(fFitModulation->GetParameter(7));
983            if( c2 < 0 ) c2 = -1.*TMath::Sqrt(-1.*c2);
984            if( c3 < 0 ) c3 = -1.*TMath::Sqrt(-1.*c3);
985            fFitModulation->SetParameter(3, c2);
986            fFitModulation->SetParameter(7, c3);
987            return kTRUE;        // is this a physical quantity ?
988         }
989         case kTryFit : {
990            fitModulationType tempType(fFitModulationType);  // store temporarily
991            fFitModulationType = kCombined;
992            fFitModulation->SetParameter(7, 0);
993            fFitModulation->SetParameter(3, 0);
994            Bool_t pass(CorrectRho(psi2, psi3));         // do the fit and all quality checks
995            fFitModulationType = tempType;               // roll back for next event
996            return pass;
997         }
998         default : return kFALSE;
999     }
1000     return kFALSE;
1001 }
1002 //_____________________________________________________________________________
1003 Bool_t AliAnalysisTaskRhoVnModulation::CorrectRho(Double_t psi2, Double_t psi3) 
1004 {
1005     // get rho' -> rho(phi)
1006     // two routines are available, both can be used with or without pt weights
1007     //  [1] get vn from q-cumulants or as an integrated value from a user supplied histogram
1008     //      in case of cumulants, both cumulants and vn values are stored. in both cases, v2 and v3
1009     //      are expected. a check is performed to see if rho has no negative local minimum
1010     //      for full description, see Phys. Rev. C 83, 044913
1011     //      since the cn distribution has negative values, vn = sqrt(cn) can be imaginary sometimes
1012     //      in this case one can either roll back to the 'original' rixed rho, do a fit for vn or take use
1013     //      vn = - sqrt(|cn|) 
1014     //  [2] fitting a fourier expansion to the de/dphi distribution
1015     //      the fit can be done with either v2, v3 or a combination.
1016     //      in all cases, a cut can be made on the p-value of the chi-squared value of the fit
1017     //      and a check can be performed to see if rho has no negative local minimum
1018     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1019     switch (fFitModulationType) {       // for approaches where no fitting is required
1020         case kQC2 : {
1021             fFitModulation->FixParameter(4, psi2); 
1022             fFitModulation->FixParameter(6, psi3);
1023             fFitModulation->FixParameter(3, CalculateQC2(2));   // set here with cn, vn = sqrt(cn)
1024             fFitModulation->FixParameter(7, CalculateQC2(3));
1025             // first fill the histos of the raw cumulant distribution
1026             if (fUsePtWeight) { // use weighted weights
1027                 Double_t dQCnM11 = (fNoEventWeightsForQC) ? 1. : QCnM11();
1028                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3), dQCnM11);
1029                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7), dQCnM11);
1030             } else {
1031                 Double_t dQCnM = (fNoEventWeightsForQC) ? 2. : QCnM();
1032                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3), dQCnM*(dQCnM-1));
1033                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7), dQCnM*(dQCnM-1));
1034             }
1035             // then see if one of the cn value is larger than zero and vn is readily available
1036             if(fFitModulation->GetParameter(3) > 0 && fFitModulation->GetParameter(7) > 0) {
1037                 fFitModulation->FixParameter(3, TMath::Sqrt(fFitModulation->GetParameter(3)));
1038                 fFitModulation->FixParameter(7, TMath::Sqrt(fFitModulation->GetParameter(7)));
1039             } else if (!QCnRecovery(psi2, psi3)) return kFALSE;  // try to recover the cumulant, this will set v2 and v3
1040             if(fAbsVnHarmonics && fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) {  // general check 
1041                 fFitModulation->SetParameter(7, 0);
1042                 fFitModulation->SetParameter(3, 0);
1043                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1044                 return kFALSE;
1045             }
1046             return kTRUE;
1047         } break;
1048         case kQC4 : {
1049             fFitModulation->FixParameter(4, psi2); 
1050             fFitModulation->FixParameter(6, psi3);
1051             fFitModulation->FixParameter(3, CalculateQC4(2));   // set here with cn, vn = sqrt(cn)
1052             fFitModulation->FixParameter(7, CalculateQC4(3));
1053             // first fill the histos of the raw cumulant distribution
1054             if (fUsePtWeight) { // use weighted weights
1055                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3)/*, QCnM1111()*/);
1056                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7)/*, QCnM1111()*/);
1057             } else {
1058                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3)/*, QCnM1111()*/);
1059                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7)/*, QCnM1111()*/);
1060             }
1061             // then see if one of the cn value is larger than zero and vn is readily available
1062             if(fFitModulation->GetParameter(3) > 0 && fFitModulation->GetParameter(7) > 0) {
1063                 fFitModulation->FixParameter(3, TMath::Sqrt(fFitModulation->GetParameter(3)));
1064                 fFitModulation->FixParameter(7, TMath::Sqrt(fFitModulation->GetParameter(7)));
1065             } else if (!QCnRecovery(psi2, psi3)) return kFALSE;  // try to recover the cumulant, this will set v2 and v3
1066             if(fAbsVnHarmonics && fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) {  // general check 
1067                 fFitModulation->SetParameter(7, 0);
1068                 fFitModulation->SetParameter(3, 0);
1069                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1070                 return kFALSE;
1071             }
1072         } break;
1073         case kIntegratedFlow : {
1074             // use v2 and v3 values from an earlier iteration over the data
1075             fFitModulation->FixParameter(3, fUserSuppliedV2->GetBinContent(fUserSuppliedV2->GetXaxis()->FindBin(fCent)));
1076             fFitModulation->FixParameter(4, psi2);
1077             fFitModulation->FixParameter(6, psi3);
1078             fFitModulation->FixParameter(7, fUserSuppliedV3->GetBinContent(fUserSuppliedV3->GetXaxis()->FindBin(fCent)));
1079             if(fAbsVnHarmonics && fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) { 
1080                 fFitModulation->SetParameter(7, 0);
1081                 fFitModulation->SetParameter(3, 0);
1082                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1083                 return kFALSE;
1084             }
1085             return kTRUE;
1086         }
1087         default : break;
1088     }
1089     TString detector("");
1090     switch (fDetectorType) {
1091         case kTPC : detector+="TPC";
1092             break;
1093         case kVZEROA : detector+="VZEROA";
1094             break;
1095         case kVZEROC : detector+="VZEROC";
1096             break;
1097         case kVZEROComb : detector+="VZEROComb";
1098             break; 
1099         default: break;
1100     }
1101     Int_t iTracks(fTracks->GetEntriesFast());
1102     Double_t excludeInEta = -999;
1103     Double_t excludeInPhi = -999;
1104     Double_t excludeInPt  = -999;
1105     if(iTracks <= 0 || fLocalRho->GetVal() <= 0 ) return kFALSE;   // no use fitting an empty event ...
1106     if(fExcludeLeadingJetsFromFit > 0 ) {
1107         AliEmcalJet* leadingJet(GetJetContainer()->GetLeadingJet());
1108         if(leadingJet) {
1109             excludeInEta = leadingJet->Eta();
1110             excludeInPhi = leadingJet->Phi();
1111             excludeInPt = leadingJet->Pt();
1112         }
1113     }
1114     fHistSwap->Reset();                 // clear the histogram
1115     TH1F _tempSwap;
1116     if(fRebinSwapHistoOnTheFly) {
1117         if(fNAcceptedTracks < 49) fNAcceptedTracks = 49;       // avoid aliasing effects
1118         _tempSwap = TH1F("_tempSwap", "_tempSwap", TMath::CeilNint(TMath::Sqrt(fNAcceptedTracks)), 0, TMath::TwoPi());
1119         if(fUsePtWeight) _tempSwap.Sumw2();
1120     }
1121     else _tempSwap = *fHistSwap;         // now _tempSwap holds the desired histo
1122     for(Int_t i(0); i < iTracks; i++) {
1123             AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1124             if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta) < GetJetContainer()->GetJetRadius()*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - GetJetContainer()->GetJetRadius() - GetJetContainer()->GetJetEtaMax() ) > 0 )) continue;
1125             if(!PassesCuts(track) || track->Pt() > fSoftTrackMaxPt || track->Pt() < fSoftTrackMinPt) continue;
1126             if(fUsePtWeight) _tempSwap.Fill(track->Phi(), track->Pt());
1127             else _tempSwap.Fill(track->Phi());
1128     }
1129     fFitModulation->SetParameter(0, fLocalRho->GetVal());
1130     switch (fFitModulationType) {
1131         case kNoFit : { fFitModulation->FixParameter(0, fLocalRho->GetVal() ); 
1132         } break;
1133         case kV2 : { 
1134             fFitModulation->FixParameter(4, psi2); 
1135         } break;
1136         case kV3 : { 
1137             fFitModulation->FixParameter(4, psi3); 
1138         } break;
1139         case kCombined : {
1140             fFitModulation->FixParameter(4, psi2); 
1141             fFitModulation->FixParameter(6, psi3);
1142         } break;
1143         case kFourierSeries : {
1144             // in this approach, an explicit calculation will be made of vn = sqrt(xn^2+yn^2)
1145             // where x[y] = Integrate[r(phi)cos[sin](n phi)dphi, 0, 2pi]
1146             Double_t cos2(0), sin2(0), cos3(0), sin3(0), sumPt(0);
1147             for(Int_t i(0); i < iTracks; i++) {
1148                 AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1149                 if(!PassesCuts(track) || track->Pt() > fSoftTrackMaxPt || track->Pt() < fSoftTrackMinPt) continue;
1150                 sumPt += track->Pt();
1151                 cos2 += track->Pt()*TMath::Cos(2*PhaseShift(track->Phi()-psi2)); 
1152                 sin2 += track->Pt()*TMath::Sin(2*PhaseShift(track->Phi()-psi2));
1153                 cos3 += track->Pt()*TMath::Cos(3*PhaseShift(track->Phi()-psi3)); 
1154                 sin3 += track->Pt()*TMath::Sin(3*PhaseShift(track->Phi()-psi3));
1155             }
1156             fFitModulation->SetParameter(3, TMath::Sqrt(cos2*cos2+sin2*sin2)/fLocalRho->GetVal());
1157             fFitModulation->SetParameter(4, psi2);
1158             fFitModulation->SetParameter(6, psi3);
1159             fFitModulation->SetParameter(7, TMath::Sqrt(cos3*cos3+sin3*sin3)/fLocalRho->GetVal());
1160         } break;
1161         default : break;
1162     }
1163     _tempSwap.Fit(fFitModulation, fFitModulationOptions.Data(), "", 0, TMath::TwoPi());
1164     // the quality of the fit is evaluated from 1 - the cdf of the chi square distribution
1165     Double_t CDF(1.-ChiSquareCDF(fFitModulation->GetNDF(), fFitModulation->GetChisquare()));
1166     fHistPvalueCDF->Fill(CDF);
1167     if(CDF > fMinPvalue && CDF < fMaxPvalue && ( fAbsVnHarmonics && fFitModulation->GetMinimum(0, TMath::TwoPi()) > 0)) { // fit quality
1168         // for LOCAL didactic purposes, save the  best and the worst fits
1169         // this routine can produce a lot of output histograms (it's not memory 'safe') and will not work on GRID 
1170         // since the output will become unmergeable (i.e. different nodes may produce conflicting output)
1171         switch (fRunModeType) {
1172             case kLocal : {
1173                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
1174                 static Int_t didacticCounterBest(0);
1175                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
1176                 TF1* didactifFit = (TF1*)fFitModulation->Clone(Form("fit_%i_CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
1177                 didacticProfile->GetListOfFunctions()->Add(didactifFit);
1178                 fOutputListGood->Add(didacticProfile);
1179                 didacticCounterBest++;
1180                 TH2F* didacticSurface = BookTH2F(Form("surface_%s", didacticProfile->GetName()), "#phi", "#eta", 50, 0, TMath::TwoPi(), 50, -1, 1, -1, kFALSE);
1181                 for(Int_t i(0); i < iTracks; i++) {
1182                     AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1183                     if(PassesCuts(track)) {
1184                         if(fUsePtWeight) didacticSurface->Fill(track->Phi(), track->Eta(), track->Pt());
1185                         else didacticSurface->Fill(track->Phi(), track->Eta());
1186                     }
1187                 }
1188                 if(fExcludeLeadingJetsFromFit) {       // visualize the excluded region
1189                     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);
1190                     f2->SetParameters(excludeInPt/3.,excludeInPhi,.1,excludeInEta,.1);
1191                     didacticSurface->GetListOfFunctions()->Add(f2);
1192                 }
1193                 fOutputListGood->Add(didacticSurface);
1194             } break;
1195             default : break;
1196         }
1197     } else {    // if the fit is of poor quality revert to the original rho estimate
1198         switch (fRunModeType) { // again see if we want to save the fit
1199             case kLocal : {
1200                 static Int_t didacticCounterWorst(0);
1201                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
1202                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data() ));
1203                 TF1* didactifFit = (TF1*)fFitModulation->Clone(Form("fit_%i_p_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data()));
1204                 didacticProfile->GetListOfFunctions()->Add(didactifFit);
1205                 fOutputListBad->Add(didacticProfile);
1206                 didacticCounterWorst++;
1207                 } break;
1208             default : break;
1209         }
1210         switch (fFitModulationType) {
1211             case kNoFit : break;        // nothing to do
1212             case kCombined : fFitModulation->SetParameter(7, 0);        // no break
1213             case kFourierSeries : fFitModulation->SetParameter(7, 0);   // no break
1214             default : { // needs to be done if there was a poor fit
1215                  fFitModulation->SetParameter(3, 0);
1216                  fFitModulation->SetParameter(0, fLocalRho->GetVal());
1217             } break;
1218         }
1219         return kFALSE;  // return false if the fit is rejected
1220     }
1221     return kTRUE;
1222 }
1223 //_____________________________________________________________________________
1224 Bool_t AliAnalysisTaskRhoVnModulation::PassesCuts(AliVEvent* event)
1225 {
1226     // event cuts
1227     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1228     if(!event || !AliAnalysisTaskEmcal::IsEventSelected()) return kFALSE;
1229     if(fSemiCentralInclusive && ! (event->GetTriggerMask() & (ULong64_t(1)<<7))) return kFALSE;
1230     if(TMath::Abs(InputEvent()->GetPrimaryVertex()->GetZ()) > 10.) return kFALSE;
1231     // aod and esd specific checks
1232     switch (fDataType) {
1233        case kESD: {
1234             AliESDEvent* esdEvent = static_cast<AliESDEvent*>(InputEvent());
1235             if( (!esdEvent) || (TMath::Abs(esdEvent->GetPrimaryVertexSPD()->GetZ() - esdEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
1236        } break;
1237        case kAOD: {
1238             AliAODEvent* aodEvent = static_cast<AliAODEvent*>(InputEvent());
1239             if( (!aodEvent) || (TMath::Abs(aodEvent->GetPrimaryVertexSPD()->GetZ() - aodEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
1240        } break;
1241        default: break;
1242     }
1243     fCent = InputEvent()->GetCentrality()->GetCentralityPercentile("V0M");
1244     if(fCent <= fCentralityClasses->At(0) || fCent >= fCentralityClasses->At(fCentralityClasses->GetSize()-1) || TMath::Abs(fCent-InputEvent()->GetCentrality()->GetCentralityPercentile("TRK")) > 5.) return kFALSE;
1245     // determine centrality class
1246     fInCentralitySelection = -1;
1247     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) {
1248         if(fCent >= fCentralityClasses->At(i) && fCent <= fCentralityClasses->At(1+i)) {
1249             fInCentralitySelection = i;
1250             break; }
1251     } 
1252     if(fInCentralitySelection<0) return kFALSE;     // should be null op
1253     if(fExplicitOutlierCut == 2010 || fExplicitOutlierCut == 2011) {
1254        if(!PassesCuts(fExplicitOutlierCut)) return kFALSE;
1255     }
1256     if(fRho->GetVal() <= 0 ) return kFALSE;
1257     if(fTracks->GetEntries() < 1) return kFALSE;
1258     return kTRUE;
1259 }
1260 //_____________________________________________________________________________
1261 Bool_t AliAnalysisTaskRhoVnModulation::PassesCuts(Int_t year) 
1262 {
1263     // additional centrality cut based on relation between tpc and global multiplicity
1264     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1265     AliAODEvent* event(dynamic_cast<AliAODEvent*>(InputEvent()));
1266     if(!event) return kFALSE;
1267     Int_t multTPC(0), multGlob(0), nTracks(InputEvent()->GetNumberOfTracks());
1268     for(Int_t iTracks = 0; iTracks < nTracks; iTracks++) { 
1269         AliAODTrack* track = event->GetTrack(iTracks);
1270         if(!track) continue;
1271         if (!track || track->Pt() < .2 || track->Pt() > 5.0 || TMath::Abs(track->Eta()) > .8 || track->GetTPCNcls() < 70 || !track->GetDetPid() || track->GetDetPid()->GetTPCsignal() < 10.0)  continue;  // general quality cut
1272         if (track->TestFilterBit(1) && track->Chi2perNDF() > 0.2) multTPC++;
1273         if (!track->TestFilterBit(16) || track->Chi2perNDF() < 0.1) continue;
1274         Double_t b[2] = {-99., -99.};
1275         Double_t bCov[3] = {-99., -99., -99.};
1276         if (track->PropagateToDCA(event->GetPrimaryVertex(), event->GetMagneticField(), 100., b, bCov) && TMath::Abs(b[0]) < 0.3 && TMath::Abs(b[1]) < 0.3) multGlob++;
1277     }
1278     if(year == 2010 && multTPC > (-40.3+1.22*multGlob) && multTPC < (32.1+1.59*multGlob)) return kTRUE;
1279     if(year == 2011  && multTPC > (-36.73 + 1.48*multGlob) && multTPC < (62.87 + 1.78*multGlob)) return kTRUE;
1280     return kFALSE;
1281 }
1282 //_____________________________________________________________________________
1283 Bool_t AliAnalysisTaskRhoVnModulation::PassesCuts(const AliVCluster* cluster) const
1284 {
1285     // cluster cuts
1286     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1287     if(!cluster) return kFALSE;
1288     return kTRUE;
1289 }
1290 //_____________________________________________________________________________
1291 void AliAnalysisTaskRhoVnModulation::FillHistogramsAfterSubtraction(Double_t psi2, Double_t psi3, Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc)
1292 {
1293     // fill histograms 
1294     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1295     FillTrackHistograms();
1296     /* FillClusterHistograms(); */
1297     FillJetHistograms(psi2, psi3); 
1298     /* FillCorrectedClusterHistograms(); */
1299     if(fFillQAHistograms) FillEventPlaneHistograms(vzero, vzeroComb, tpc);
1300     FillRhoHistograms();
1301     FillDeltaPtHistograms(psi2, psi3);
1302 }
1303 //_____________________________________________________________________________
1304 void AliAnalysisTaskRhoVnModulation::FillTrackHistograms() const
1305 {
1306     // fill track histograms
1307     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1308     Int_t iTracks(fTracks->GetEntriesFast()), iAcceptedTracks(0);
1309     for(Int_t i(0); i < iTracks; i++) {
1310         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1311         if(!PassesCuts(track)) continue;
1312         iAcceptedTracks++;
1313         fHistPicoTrackPt[fInCentralitySelection]->Fill(track->Pt());
1314         if(fFillQAHistograms) FillQAHistograms(track);
1315     }
1316     fHistPicoTrackMult[fInCentralitySelection]->Fill(iAcceptedTracks);
1317 }
1318 //_____________________________________________________________________________
1319 void AliAnalysisTaskRhoVnModulation::FillClusterHistograms() const
1320 {
1321     // fill cluster histograms
1322     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1323     /* Int_t iClusters(fCaloClusters->GetEntriesFast());
1324     for(Int_t i(0); i < iClusters; i++) {
1325         AliVCluster* cluster = static_cast<AliVCluster*>(fCaloClusters->At(iClusters));
1326         if (!PassesCuts(cluster)) continue;
1327         TLorentzVector clusterLorentzVector;
1328         cluster->GetMomentum(clusterLorentzVector, const_cast<Double_t*>(fVertex));
1329         fHistClusterPt[fInCentralitySelection]->Fill(clusterLorentzVector.Pt());
1330         fHistClusterEta[fInCentralitySelection]->Fill(clusterLorentzVector.Eta());
1331         fHistClusterPhi[fInCentralitySelection]->Fill(clusterLorentzVector.Phi());
1332     }
1333     return; */
1334 }
1335 //_____________________________________________________________________________
1336 void AliAnalysisTaskRhoVnModulation::FillCorrectedClusterHistograms() const
1337 {
1338     // fill clusters after hadronic correction FIXME implement
1339     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1340 }
1341 //_____________________________________________________________________________
1342 void AliAnalysisTaskRhoVnModulation::FillEventPlaneHistograms(Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc) const
1343 {
1344     // fill event plane histograms
1345     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1346     fHistPsiControl->Fill(0.5, vzero[0][0]);    // vzero a psi2
1347     fHistPsiControl->Fill(1.5, vzero[1][0]);    // vzero c psi2
1348     fHistPsiControl->Fill(2.5, tpc[0]);         // tpc psi 2
1349     fHistPsiControl->Fill(5.5, vzero[0][1]);    // vzero a psi3
1350     fHistPsiControl->Fill(6.5, vzero[1][1]);    // vzero b psi3
1351     fHistPsiControl->Fill(7.5, tpc[1]);         // tpc psi 3
1352     fHistPsiVZEROA->Fill(vzero[0][0]);
1353     fHistPsiVZEROC->Fill(vzero[1][0]);
1354     fHistPsiVZERO->Fill(vzeroComb[0]);
1355     fHistPsiTPC->Fill(tpc[0]);
1356     fHistPsiSpread->Fill(0.5, TMath::Abs(vzero[0][0]-vzero[1][0]));
1357     fHistPsiSpread->Fill(1.5, TMath::Abs(vzero[0][0]-tpc[0]));
1358     fHistPsiSpread->Fill(2.5, TMath::Abs(vzero[1][0]-tpc[0]));
1359     // event plane vs centrality QA histo's to check recentering
1360     Double_t TRK(InputEvent()->GetCentrality()->GetCentralityPercentile("TRK"));
1361     Double_t V0M(InputEvent()->GetCentrality()->GetCentralityPercentile("V0M"));
1362     fHistPsiVZEROAV0M->Fill(V0M, vzero[0][0]);
1363     fHistPsiVZEROCV0M->Fill(V0M, vzero[1][0]);
1364     fHistPsiVZEROVV0M->Fill(V0M, vzeroComb[0]);
1365     fHistPsiTPCiV0M->Fill(V0M, tpc[0]);
1366     fHistPsiVZEROATRK->Fill(TRK, vzero[0][0]);
1367     fHistPsiVZEROCTRK->Fill(TRK, vzero[1][0]);
1368     fHistPsiVZEROTRK->Fill(TRK, vzeroComb[0]);
1369     fHistPsiTPCTRK->Fill(TRK, tpc[0]);
1370 }
1371 //_____________________________________________________________________________
1372 void AliAnalysisTaskRhoVnModulation::FillRhoHistograms()
1373 {
1374     // fill rho histograms
1375     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1376     fHistRhoPackage[fInCentralitySelection]->Fill(fLocalRho->GetVal());    // save the rho estimate from the emcal jet package
1377     // get multiplicity FIXME inefficient
1378     Int_t iJets(fJets->GetEntriesFast());
1379     Double_t rho(fLocalRho->GetLocalVal(TMath::Pi(), TMath::Pi(), fLocalRho->GetVal()));
1380     fHistRho[fInCentralitySelection]->Fill(rho);
1381     fHistRhoVsMult->Fill(fTracks->GetEntries(), rho);
1382     fHistRhoVsCent->Fill(fCent, rho);
1383     for(Int_t i(0); i < iJets; i++) {
1384         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1385         if(!PassesCuts(jet)) continue;
1386         fHistRhoAVsMult->Fill(fTracks->GetEntries(), rho * jet->Area());
1387         fHistRhoAVsCent->Fill(fCent, rho * jet->Area());
1388     }
1389 }
1390 //_____________________________________________________________________________
1391 void AliAnalysisTaskRhoVnModulation::FillDeltaPtHistograms(Double_t psi2, Double_t psi3) const
1392 {
1393     // fill delta pt histograms
1394     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1395     Int_t i(0);
1396     AliEmcalJet* leadingJet(GetJetContainer()->GetLeadingJet());
1397     if(!leadingJet && fDebug > 0) printf(" > failed to retrieve leading jet ! < \n");
1398     const Float_t areaRC = fRandomConeRadius*fRandomConeRadius*TMath::Pi();
1399     // we're retrieved the leading jet, now get a random cone
1400     for(i = 0; i < fMaxCones; i++) {
1401        Float_t pt(0), eta(0), phi(0);
1402        // get a random cone without constraints on leading jet position
1403        CalculateRandomCone(pt, eta, phi, 0x0);
1404        if(pt > 0) {
1405            if(fFillQAHistograms) fHistRCPhiEta[fInCentralitySelection]->Fill(phi, eta);
1406            fHistRhoVsRCPt[fInCentralitySelection]->Fill(pt, fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal())*areaRC);
1407            fHistRCPt[fInCentralitySelection]->Fill(pt);
1408            fHistDeltaPtDeltaPhi2[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1409            fHistDeltaPtDeltaPhi3[fInCentralitySelection]->Fill(PhaseShift(phi-psi3, 3.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1410        }
1411        // get a random cone excluding leading jet area
1412        CalculateRandomCone(pt, eta, phi, leadingJet);
1413        if(pt > 0) {
1414            if(fFillQAHistograms) fHistRCPhiEtaExLJ[fInCentralitySelection]->Fill(phi, eta);
1415            fHistRhoVsRCPtExLJ[fInCentralitySelection]->Fill(pt, fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal())*areaRC);
1416            fHistRCPtExLJ[fInCentralitySelection]->Fill(pt);
1417            fHistDeltaPtDeltaPhi2ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1418            fHistDeltaPtDeltaPhi3ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi3, 3.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1419        }
1420     } 
1421 }
1422 //_____________________________________________________________________________
1423 void AliAnalysisTaskRhoVnModulation::FillJetHistograms(Double_t psi2, Double_t psi3)
1424 {
1425     // fill jet histograms
1426     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1427     Int_t iJets(fJets->GetEntriesFast());
1428     for(Int_t i(0); i < iJets; i++) {
1429         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1430         if(PassesCuts(jet)) {
1431             Double_t pt(jet->Pt()), area(jet->Area()), eta(jet->Eta()), phi(jet->Phi());
1432             Double_t rho(fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1433             fHistJetPtRaw[fInCentralitySelection]->Fill(pt);
1434             fHistJetPt[fInCentralitySelection]->Fill(pt-area*rho);
1435             if(fFillQAHistograms) fHistJetEtaPhi[fInCentralitySelection]->Fill(eta, phi);
1436             fHistJetPtArea[fInCentralitySelection]->Fill(pt-area*rho, area);
1437             fHistJetPsi2Pt[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt-area*rho);
1438             fHistJetPsi3Pt[fInCentralitySelection]->Fill(PhaseShift(phi-psi3, 3.), pt-area*rho);
1439             fHistJetPtConstituents[fInCentralitySelection]->Fill(pt-area*rho, jet->Nch());
1440             fHistJetEtaRho[fInCentralitySelection]->Fill(eta, pt/area);
1441             if(fSubtractJetPt) jet->SetPtSub(pt-area*rho);      // if requested, save the subtracted jet pt
1442         } else if(fSubtractJetPt) jet->SetPtSub(-999.);
1443     }
1444 }
1445 //_____________________________________________________________________________
1446 void AliAnalysisTaskRhoVnModulation::FillQAHistograms(AliVTrack* vtrack) const
1447 {
1448     // fill qa histograms for pico tracks
1449     if(!vtrack) return;
1450     AliPicoTrack* track = static_cast<AliPicoTrack*>(vtrack);
1451     fHistRunnumbersPhi->Fill(fMappedRunNumber, track->Phi());
1452     fHistRunnumbersEta->Fill(fMappedRunNumber, track->Eta());
1453     Int_t type((int)(track->GetTrackType()));
1454     switch (type) {
1455         case 0:
1456            fHistPicoCat1[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1457            break;
1458         case 1:
1459            fHistPicoCat2[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1460            break;
1461         case 2:
1462            fHistPicoCat3[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1463            break;
1464         default: break;
1465     }
1466 }
1467 //_____________________________________________________________________________
1468 void AliAnalysisTaskRhoVnModulation::FillQAHistograms(AliVEvent* vevent) 
1469 {
1470     // fill qa histograms for events
1471     if(!vevent) return;
1472     fHistVertexz->Fill(vevent->GetPrimaryVertex()->GetZ());
1473     fHistCentrality->Fill(fCent);
1474     Int_t runNumber(InputEvent()->GetRunNumber());
1475     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};
1476     for(fMappedRunNumber = 0; fMappedRunNumber < 64; fMappedRunNumber++) {
1477         if(runs[fMappedRunNumber]==runNumber) break;
1478     }
1479 }
1480 //_____________________________________________________________________________
1481 void AliAnalysisTaskRhoVnModulation::FillAnalysisSummaryHistogram() const
1482 {
1483     // fill the analysis summary histrogram, saves all relevant analysis settigns
1484     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1485     fHistAnalysisSummary->GetXaxis()->SetBinLabel(2, "fJetRadius");
1486     fHistAnalysisSummary->SetBinContent(2, GetJetContainer()->GetJetRadius());
1487     fHistAnalysisSummary->GetXaxis()->SetBinLabel(3, "fJetEtaMin");
1488     fHistAnalysisSummary->SetBinContent(3, GetJetContainer()->GetJetEtaMin());
1489     fHistAnalysisSummary->GetXaxis()->SetBinLabel(4, "fJetEtaMax");
1490     fHistAnalysisSummary->SetBinContent(4, GetJetContainer()->GetJetEtaMax());
1491     fHistAnalysisSummary->GetXaxis()->SetBinLabel(5, "fJetPhiMin");
1492     fHistAnalysisSummary->SetBinContent(5, GetJetContainer()->GetJetPhiMin());
1493     fHistAnalysisSummary->GetXaxis()->SetBinLabel(6, "fJetPhiMax");
1494     fHistAnalysisSummary->SetBinContent(6, GetJetContainer()->GetJetPhiMin());
1495     fHistAnalysisSummary->GetXaxis()->SetBinLabel(16, "fForceBeamType");
1496     fHistAnalysisSummary->SetBinContent(16, fForceBeamType);
1497     fHistAnalysisSummary->GetXaxis()->SetBinLabel(17, "fMinCent");
1498     fHistAnalysisSummary->SetBinContent(17, fMinCent);
1499     fHistAnalysisSummary->GetXaxis()->SetBinLabel(18, "fMaxCent");
1500     fHistAnalysisSummary->SetBinContent(18, fMaxCent);
1501     fHistAnalysisSummary->GetXaxis()->SetBinLabel(19, "fMinVz");
1502     fHistAnalysisSummary->SetBinContent(19, fMinVz);
1503     fHistAnalysisSummary->GetXaxis()->SetBinLabel(20, "fMaxVz");
1504     fHistAnalysisSummary->SetBinContent(20, fMaxVz);
1505     fHistAnalysisSummary->GetXaxis()->SetBinLabel(21, "fOffTrigger");
1506     fHistAnalysisSummary->SetBinContent(21, fOffTrigger);
1507     fHistAnalysisSummary->GetXaxis()->SetBinLabel(33, "fRandomConeRadius");
1508     fHistAnalysisSummary->SetBinContent(33, fRandomConeRadius);
1509     fHistAnalysisSummary->GetXaxis()->SetBinLabel(34, "fitModulationType");
1510     fHistAnalysisSummary->SetBinContent(34, (int)fFitModulationType);
1511     fHistAnalysisSummary->GetXaxis()->SetBinLabel(35, "runModeType");
1512     fHistAnalysisSummary->SetBinContent(35, (int)fRunModeType);
1513     fHistAnalysisSummary->GetXaxis()->SetBinLabel(36, "data type");
1514     fHistAnalysisSummary->SetBinContent(36, (int)fDataType);
1515     fHistAnalysisSummary->GetXaxis()->SetBinLabel(37, "iterator");
1516     fHistAnalysisSummary->SetBinContent(37, 1.);
1517     fHistAnalysisSummary->GetXaxis()->SetBinLabel(38, "fMinPvalue");
1518     fHistAnalysisSummary->SetBinContent(38, fMinPvalue);
1519     fHistAnalysisSummary->GetXaxis()->SetBinLabel(39, "fMaxPvalue");
1520     fHistAnalysisSummary->SetBinContent(39, fMaxPvalue);
1521     fHistAnalysisSummary->GetXaxis()->SetBinLabel(40, "fExcludeLeadingJetsFromFit");
1522     fHistAnalysisSummary->SetBinContent(40, fExcludeLeadingJetsFromFit);
1523     fHistAnalysisSummary->GetXaxis()->SetBinLabel(41, "fRebinSwapHistoOnTheFly");
1524     fHistAnalysisSummary->SetBinContent(41, (int)fRebinSwapHistoOnTheFly);
1525     fHistAnalysisSummary->GetXaxis()->SetBinLabel(42, "fUsePtWeight");
1526     fHistAnalysisSummary->SetBinContent(42, (int)fUsePtWeight);
1527     fHistAnalysisSummary->GetXaxis()->SetBinLabel(43, "fMinLeadingHadronPt");
1528     fHistAnalysisSummary->SetBinContent(43, fMinLeadingHadronPt);
1529     fHistAnalysisSummary->GetXaxis()->SetBinLabel(44, "fExplicitOutlierCut");
1530     fHistAnalysisSummary->SetBinContent(44, fExplicitOutlierCut);
1531     fHistAnalysisSummary->GetXaxis()->SetBinLabel(45, "fLocalJetMinEta");
1532     fHistAnalysisSummary->SetBinContent(45,fLocalJetMinEta );
1533     fHistAnalysisSummary->GetXaxis()->SetBinLabel(46, "fLocalJetMaxEta");
1534     fHistAnalysisSummary->SetBinContent(46, fLocalJetMaxEta);
1535     fHistAnalysisSummary->GetXaxis()->SetBinLabel(47, "fLocalJetMinPhi");
1536     fHistAnalysisSummary->SetBinContent(47, fLocalJetMinPhi);
1537     fHistAnalysisSummary->GetXaxis()->SetBinLabel(48, "fLocalJetMaxPhi");
1538     fHistAnalysisSummary->SetBinContent(48, fLocalJetMaxPhi);
1539     fHistAnalysisSummary->GetXaxis()->SetBinLabel(49, "fSoftTrackMinPt");
1540     fHistAnalysisSummary->SetBinContent(49, fSoftTrackMinPt);
1541     fHistAnalysisSummary->GetXaxis()->SetBinLabel(50, "fSoftTrackMaxPt");
1542     fHistAnalysisSummary->SetBinContent(50, fSoftTrackMaxPt);
1543     fHistAnalysisSummary->GetXaxis()->SetBinLabel(51, "fMaxCones");
1544     fHistAnalysisSummary->SetBinContent(51, fMaxCones);
1545     fHistAnalysisSummary->GetXaxis()->SetBinLabel(52, "fUseScaledRho");
1546     fHistAnalysisSummary->SetBinContent(52, fUseScaledRho);
1547 }
1548 //_____________________________________________________________________________
1549 void AliAnalysisTaskRhoVnModulation::Terminate(Option_t *)
1550 {
1551     // terminate
1552     switch (fRunModeType) {
1553         case kLocal : {
1554         printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1555         if(fFillQAHistograms) {
1556             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};
1557             for(Int_t i(0); i < 64; i++) { 
1558                 fHistRunnumbersPhi->GetXaxis()->SetBinLabel(i+1, Form("%i", runs[i]));
1559                 fHistRunnumbersEta->GetXaxis()->SetBinLabel(i+1, Form("%i", runs[i]));
1560             }
1561             fHistRunnumbersPhi->GetXaxis()->SetBinLabel(65, "undetermined");
1562             fHistRunnumbersEta->GetXaxis()->SetBinLabel(65, "undetermined");
1563         }
1564         AliAnalysisTaskRhoVnModulation::Dump();
1565         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));
1566         } break;
1567         default : break;
1568     }
1569 }
1570 //_____________________________________________________________________________
1571 void AliAnalysisTaskRhoVnModulation::SetModulationFit(TF1* fit) 
1572 {
1573 // set modulation fit
1574     if (fFitModulation) delete fFitModulation;
1575     fFitModulation = fit; 
1576 }
1577 //_____________________________________________________________________________
1578 TH1F* AliAnalysisTaskRhoVnModulation::GetResolutionFromOuptutFile(detectorType det, Int_t h, TArrayD* cen)
1579 {
1580     // INTERFACE METHOD FOR OUTPUTFILE
1581     // get the detector resolution, user has ownership of the returned histogram
1582     if(!fOutputList) {
1583         printf(" > Please add fOutputList first < \n");
1584         return 0x0;
1585     }
1586     TH1F* r(0x0);
1587     (cen) ? r = new TH1F("R", "R", cen->GetSize()-1, cen->GetArray()) : r = new TH1F("R", "R", 10, 0, 10);
1588     if(!cen) r->GetXaxis()->SetTitle("number of centrality bin");
1589     r->GetYaxis()->SetTitle(Form("Resolution #Psi_{%i}", h));
1590     for(Int_t i(0); i < 10; i++) {
1591         TProfile* temp((TProfile*)fOutputList->FindObject(Form("fProfV%iResolution_%i", h, i)));
1592         if(!temp) break;
1593         Double_t a(temp->GetBinContent(3)), b(temp->GetBinContent(5)), c(temp->GetBinContent(7));
1594         Double_t d(temp->GetBinContent(9)), e(temp->GetBinContent(10)), f(temp->GetBinContent(11));
1595         Double_t _a(temp->GetBinError(3)), _b(temp->GetBinError(5)), _c(temp->GetBinError(7));
1596         Double_t _d(temp->GetBinError(9)), _e(temp->GetBinError(10)), _f(temp->GetBinError(11));
1597         if(a <= 0 || b <= 0 || c <= 0 || d <= 0 || e <= 0 || f <= 0) continue;
1598         switch (det) {
1599             case kVZEROA : {
1600                 r->SetBinContent(1+i, TMath::Sqrt((a*b)/c));
1601                 if(i==0) r->SetNameTitle("VZEROA resolution", "VZEROA resolution");
1602                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
1603             } break;
1604             case kVZEROC : {
1605                 r->SetBinContent(1+i, TMath::Sqrt((a*c)/b));
1606                 if(i==0) r->SetNameTitle("VZEROC resolution", "VZEROC resolution");
1607                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
1608             } break;
1609             case kTPC : {
1610                 r->SetBinContent(1+i, TMath::Sqrt((b*c)/a));
1611                 if(i==0) r->SetNameTitle("TPC resolution", "TPC resolution");
1612                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
1613             } break;
1614             case kVZEROComb : {
1615                 r->SetBinContent(1+i, TMath::Sqrt((d*e)/f));
1616                 if(i==0) r->SetNameTitle("VZEROComb resolution", "VZEROComb resolution");
1617                 r->SetBinError(1+i, TMath::Sqrt(_d*_d+_e*_e+_f*_f));
1618             } break;
1619             default : break;
1620         }
1621     }
1622     return r;
1623 }
1624 //_____________________________________________________________________________
1625 TH1F* AliAnalysisTaskRhoVnModulation::CorrectForResolutionDiff(TH1F* v, detectorType det, TArrayD* cen, Int_t c, Int_t h)
1626 {
1627     // INTERFACE METHOD FOR OUTPUT FILE
1628     // correct the supplied differential vn histogram v for detector resolution
1629     TH1F* r(GetResolutionFromOuptutFile(det, h, cen));
1630     if(!r) {
1631         printf(" > Couldn't find resolution < \n");
1632         return 0x0;
1633     }
1634     Double_t res(1./r->GetBinContent(1+r->FindBin(c)));
1635     TF1* line = new TF1("line", "pol0", 0, 200);
1636     line->SetParameter(0, res);
1637     v->Multiply(line);
1638     return v;
1639 }
1640 //_____________________________________________________________________________
1641 TH1F* AliAnalysisTaskRhoVnModulation::CorrectForResolutionInt(TH1F* v, detectorType det, TArrayD* cen, Int_t h)
1642 {
1643     // INTERFACE METHOD FOR OUTPUT FILE
1644     // correct the supplied intetrated vn histogram v for detector resolution
1645     // integrated vn must have the same centrality binning as the resolotion correction
1646     TH1F* r(GetResolutionFromOuptutFile(det, h, cen));
1647     v->Divide(v, r);
1648     return v;
1649 }
1650 //_____________________________________________________________________________
1651 TH1F* AliAnalysisTaskRhoVnModulation::GetDifferentialQC(TProfile* refCumulants, TProfile* diffCumlants, TArrayD* ptBins, Int_t h)
1652 {
1653     // get differential QC
1654     Double_t r(refCumulants->GetBinContent(h-1)); // v2 reference flow
1655     if(r > 0) r = TMath::Sqrt(r);
1656     TH1F* qc = new TH1F(Form("QC2v%i", h), Form("QC2v%i", h), ptBins->GetSize()-1, ptBins->GetArray());
1657     Double_t a(0), b(0), c(0);  // dummy variables
1658     for(Int_t i(0); i < ptBins->GetSize(); i++) {
1659         if(r > 0) {
1660             a = diffCumlants->GetBinContent(1+i);
1661             b = diffCumlants->GetBinError(1+i);
1662             c = a/r;
1663             qc->SetBinContent(1+i, c);
1664             (a <= 0 || b <= 0) ? qc->SetBinError(1+i, b) : qc->SetBinError(1+i, TMath::Sqrt(c*c*b*b/(a*a)));
1665         }
1666     }
1667     return qc;
1668 }
1669
1670 //_____________________________________________________________________________