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