]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskJetV2.cxx
added dijet matching (geometric and (sub)leading jet) for correlation studies
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskJetV2.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  * Jet V2 task
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 <TH3F.h>
42 #include <TProfile.h>
43 #include <TFile.h>
44 // aliroot includes
45 #include <AliAnalysisTask.h>
46 #include <AliAnalysisManager.h>
47 #include <AliCentrality.h>
48 #include <AliVVertex.h>
49 #include <AliVTrack.h>
50 #include <AliVVZERO.h>
51 #include <AliESDEvent.h>
52 #include <AliAODEvent.h>
53 #include <AliAODTrack.h>
54 #include <AliOADBContainer.h>
55 // emcal jet framework includes
56 #include <AliPicoTrack.h>
57 #include <AliEmcalJet.h>
58 #include <AliRhoParameter.h>
59 #include <AliLocalRhoParameter.h>
60 #include <AliAnalysisTaskJetV2.h>
61 #include <AliClusterContainer.h>
62
63 class AliAnalysisTaskJetV2;
64 using namespace std;
65
66 ClassImp(AliAnalysisTaskJetV2)
67
68 AliAnalysisTaskJetV2::AliAnalysisTaskJetV2() : AliAnalysisTaskEmcalJet("AliAnalysisTaskJetV2", kTRUE), 
69     fDebug(0), fRunToyMC(kFALSE), fLocalInit(0), fAttachToEvent(kTRUE), fFillHistograms(kTRUE), fFillQAHistograms(kTRUE), fReduceBinsXByFactor(-1.), fReduceBinsYByFactor(-1.), fNoEventWeightsForQC(kTRUE), fCentralityClasses(0), fExpectedRuns(0), fExpectedSemiGoodRuns(0), fUserSuppliedV2(0), fUserSuppliedV3(0), fUserSuppliedR2(0), fUserSuppliedR3(0), fEventPlaneWeights(0), fEventPlaneWeight(1.), fTracksCont(0), fClusterCont(0), fJetsCont(0), fLeadingJet(0), fLeadingJetAfterSub(0), fNAcceptedTracks(0), fNAcceptedTracksQCn(0), fFitModulationType(kNoFit), fFitGoodnessTest(kChi2Poisson), fQCRecovery(kTryFit), fUsePtWeight(kTRUE), fUsePtWeightErrorPropagation(kTRUE), fDetectorType(kVZEROComb), fAnalysisType(kCharged), 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), fNameSmallRho(""), fCachedRho(0), 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), fMaxCones(-1), fExcludeLeadingJetsFromFit(1.), fRebinSwapHistoOnTheFly(kTRUE), fPercentageOfFits(10.), 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), fHistPsiTPCV0M(0), fHistPsiVZEROATRK(0), fHistPsiVZEROCTRK(0), fHistPsiVZEROTRK(0), fHistPsiTPCTRK(0), fHistRhoVsMult(0), fHistRhoVsCent(0), fHistRhoAVsMult(0), fHistRhoAVsCent(0), fVZEROgainEqualization(0x0), fVZEROgainEqualizationPerRing(kFALSE), fChi2A(0x0), fChi2C(0x0), fChi3A(0x0), fChi3C(0x0), fOADB(0x0)
70 {
71     for(Int_t i(0); i < 10; i++) {
72         fProfV2Resolution[i] = 0;
73         fProfV3Resolution[i] = 0;
74         fHistPicoTrackPt[i] = 0;
75         fHistPicoTrackMult[i] = 0;
76         fHistPicoCat1[i] = 0;
77         fHistPicoCat2[i] = 0;
78         fHistPicoCat3[i] = 0;
79         fHistClusterPt[i] = 0;
80         fHistClusterEtaPhi[i] = 0;
81         fHistClusterEtaPhiWeighted[i] = 0;
82         fHistPsiTPCLeadingJet[i] = 0;
83         fHistPsiVZEROALeadingJet[i] = 0;  
84         fHistPsiVZEROCLeadingJet[i] = 0;
85         fHistPsiVZEROCombLeadingJet[i] = 0;
86         fHistPsi2Correlation[i] = 0;
87         fHistLeadingJetBackground[i] = 0;
88         fHistRhoPackage[i] = 0;
89         fHistRho[i] = 0;
90         fHistRCPhiEta[i] = 0;
91         fHistRhoVsRCPt[i] = 0;
92         fHistRCPt[i] = 0;
93         fHistDeltaPtDeltaPhi2[i] = 0;
94         fHistDeltaPtDeltaPhi2Rho0[i] = 0;
95         fHistRCPhiEtaExLJ[i] = 0;
96         fHistRhoVsRCPtExLJ[i] = 0;
97         fHistRCPtExLJ[i] = 0;
98         fHistDeltaPtDeltaPhi2ExLJ[i] = 0;
99         fHistDeltaPtDeltaPhi2ExLJRho0[i] = 0;
100         fHistJetPtRaw[i] = 0;
101         fHistJetPt[i] = 0;
102         fHistJetEtaPhi[i] = 0;
103         fHistJetPtArea[i] = 0;
104         fHistJetPtEta[i] = 0;
105         fHistJetPtConstituents[i] = 0;
106         fHistJetEtaRho[i] = 0;
107         fHistJetPsi2Pt[i] = 0;
108         fHistJetPsi2PtRho0[i] = 0;
109    }
110    for(Int_t i(0); i < 9; i++) {
111        for(Int_t j(0); j < 2; j++) {
112            for(Int_t k(0); k < 2; k++) {
113                fMeanQ[i][j][k] = 0.; 
114                fWidthQ[i][j][k] = 0.;  
115                fMeanQv3[i][j][k] = 0.; 
116                fWidthQv3[i][j][k] = 0.;
117            }
118        }
119    }
120    for(Int_t i(0); i < 4; i++) {
121        fVZEROApol[i] = 0.;
122        fVZEROCpol[i] = 0.;
123    }
124    for(Int_t i(0); i < 8; i++) fUseVZERORing[i] = kTRUE;
125    // default constructor
126 }
127 //_____________________________________________________________________________
128 AliAnalysisTaskJetV2::AliAnalysisTaskJetV2(const char* name, runModeType type) : AliAnalysisTaskEmcalJet(name, kTRUE),
129   fDebug(0), fRunToyMC(kFALSE), fLocalInit(0), fAttachToEvent(kTRUE), fFillHistograms(kTRUE), fFillQAHistograms(kTRUE), fReduceBinsXByFactor(-1.), fReduceBinsYByFactor(-1.), fNoEventWeightsForQC(kTRUE), fCentralityClasses(0), fExpectedRuns(0), fExpectedSemiGoodRuns(0), fUserSuppliedV2(0), fUserSuppliedV3(0), fUserSuppliedR2(0), fUserSuppliedR3(0), fEventPlaneWeights(0), fEventPlaneWeight(1.), fTracksCont(0), fClusterCont(0), fJetsCont(0), fLeadingJet(0), fLeadingJetAfterSub(0), fNAcceptedTracks(0), fNAcceptedTracksQCn(0), fFitModulationType(kNoFit), fFitGoodnessTest(kChi2Poisson), fQCRecovery(kTryFit), fUsePtWeight(kTRUE), fUsePtWeightErrorPropagation(kTRUE), fDetectorType(kVZEROComb), fAnalysisType(kCharged), 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), fNameSmallRho(""), fCachedRho(0), 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), fMaxCones(-1), fExcludeLeadingJetsFromFit(1.), fRebinSwapHistoOnTheFly(kTRUE), fPercentageOfFits(10.), 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), fHistPsiTPCV0M(0), fHistPsiVZEROATRK(0), fHistPsiVZEROCTRK(0), fHistPsiVZEROTRK(0), fHistPsiTPCTRK(0), fHistRhoVsMult(0), fHistRhoVsCent(0), fHistRhoAVsMult(0), fHistRhoAVsCent(0), fVZEROgainEqualization(0x0), fVZEROgainEqualizationPerRing(kFALSE), fChi2A(0x0), fChi2C(0x0), fChi3A(0x0), fChi3C(0x0), fOADB(0x0)
130 {
131     for(Int_t i(0); i < 10; i++) {
132         fProfV2Resolution[i] = 0;
133         fProfV3Resolution[i] = 0;
134         fHistPicoTrackPt[i] = 0;
135         fHistPicoTrackMult[i] = 0;
136         fHistPicoCat1[i] = 0;
137         fHistPicoCat2[i] = 0;
138         fHistPicoCat3[i] = 0;
139         fHistClusterPt[i] = 0;
140         fHistClusterEtaPhi[i] = 0;
141         fHistClusterEtaPhiWeighted[i] = 0;
142         fHistPsiTPCLeadingJet[i] = 0;
143         fHistPsiVZEROALeadingJet[i] = 0;  
144         fHistPsiVZEROCLeadingJet[i] = 0;
145         fHistPsiVZEROCombLeadingJet[i] = 0;
146         fHistPsi2Correlation[i] = 0;
147         fHistLeadingJetBackground[i] = 0;
148         fHistRhoPackage[i] = 0;
149         fHistRho[i] = 0;
150         fHistRCPhiEta[i] = 0;
151         fHistRhoVsRCPt[i] = 0;
152         fHistRCPt[i] = 0;
153         fHistDeltaPtDeltaPhi2[i] = 0;
154         fHistDeltaPtDeltaPhi2Rho0[i] = 0;
155         fHistRCPhiEtaExLJ[i] = 0;
156         fHistRhoVsRCPtExLJ[i] = 0;
157         fHistRCPtExLJ[i] = 0;
158         fHistDeltaPtDeltaPhi2ExLJ[i] = 0;
159         fHistDeltaPtDeltaPhi2ExLJRho0[i] = 0;
160         fHistJetPtRaw[i] = 0;
161         fHistJetPt[i] = 0;
162         fHistJetEtaPhi[i] = 0;
163         fHistJetPtArea[i] = 0;
164         fHistJetPtEta[i] = 0;
165         fHistJetPtConstituents[i] = 0;
166         fHistJetEtaRho[i] = 0;
167         fHistJetPsi2Pt[i] = 0;
168         fHistJetPsi2PtRho0[i] = 0;
169    }
170    for(Int_t i(0); i < 9; i++) {
171        for(Int_t j(0); j < 2; j++) {
172            for(Int_t k(0); k < 2; k++) {
173                fMeanQ[i][j][k] = 0.; 
174                fWidthQ[i][j][k] = 0.;  
175                fMeanQv3[i][j][k] = 0.; 
176                fWidthQv3[i][j][k] = 0.;
177            }
178        }
179    }
180    for(Int_t i(0); i < 4; i++) {
181        fVZEROApol[i] = 0.;
182        fVZEROCpol[i] = 0.;
183    }
184    for(Int_t i(0); i < 8; i++) fUseVZERORing[i] = kTRUE;
185
186     // constructor
187     DefineInput(0, TChain::Class());
188     DefineOutput(1, TList::Class());
189     switch (fRunModeType) {
190         case kLocal : {
191             gStyle->SetOptFit(1);
192             DefineOutput(2, TList::Class());
193             DefineOutput(3, TList::Class());
194         } break;
195         default: fDebug = -1;   // suppress debug info explicitely when not running locally
196     }
197     switch (fCollisionType) {
198         case kPythia : {
199             fFitModulationType = kNoFit;
200         } break;
201         default : break;
202     }
203     if(fLocalRhoName=="") fLocalRhoName = Form("LocalRhoFrom_%s", GetName());
204 }
205 //_____________________________________________________________________________
206 AliAnalysisTaskJetV2::~AliAnalysisTaskJetV2()
207 {
208     // destructor
209     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
210     if(fOutputList)             {delete fOutputList;            fOutputList = 0x0;}
211     if(fOutputListGood)         {delete fOutputListGood;        fOutputListGood = 0x0;}
212     if(fOutputListBad)          {delete fOutputListBad;         fOutputListBad = 0x0;}
213     if(fFitModulation)          {delete fFitModulation;         fFitModulation = 0x0;}
214     if(fHistSwap)               {delete fHistSwap;              fHistSwap = 0x0;}
215     if(fCentralityClasses)      {delete fCentralityClasses;     fCentralityClasses = 0x0;}
216     if(fExpectedRuns)           {delete fExpectedRuns;          fExpectedRuns = 0x0;}
217     if(fExpectedSemiGoodRuns)   {delete fExpectedSemiGoodRuns;  fExpectedSemiGoodRuns = 0x0;}
218     if(fFitControl)             {delete fFitControl;            fFitControl = 0x0;}
219     if(fVZEROgainEqualization)  {delete fVZEROgainEqualization; fVZEROgainEqualization = 0x0;}
220     if(fChi2A)                  {delete fChi2A;                 fChi2A = 0x0;}
221     if(fChi2C)                  {delete fChi2C;                 fChi2C = 0x0;}
222     if(fChi3A)                  {delete fChi3A;                 fChi3A = 0x0;}
223     if(fChi3C)                  {delete fChi3C;                 fChi3C = 0x0;}
224     if(fOADB && !fOADB->IsZombie()) {
225         fOADB->Close();        fOADB = 0x0;
226     } else if (fOADB) fOADB = 0x0;
227 }
228 //_____________________________________________________________________________
229 void AliAnalysisTaskJetV2::ExecOnce()
230 {
231     // Init the analysis
232     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
233     fLocalRho = new AliLocalRhoParameter(fLocalRhoName.Data(), 0); 
234     if(fAttachToEvent) {
235         if(!(InputEvent()->FindListObject(fLocalRho->GetName()))) {
236             InputEvent()->AddObject(fLocalRho);
237         } else {
238             AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), fLocalRho->GetName()));
239         }
240     }
241     AliAnalysisTaskEmcalJet::ExecOnce();        // init the base class
242     AliAnalysisTaskEmcalJet::SetVzRange(-1.*fAbsVertexZ, fAbsVertexZ);
243     if(!GetJetContainer()) AliFatal(Form("%s: Couldn't find jet container. Aborting !", GetName()));
244 }
245 //_____________________________________________________________________________
246 Bool_t AliAnalysisTaskJetV2::Notify()
247 {
248     // determine the run number to see if the track and jet cuts should be refreshed for semi-good TPC runs
249     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
250     if(fRunNumber != InputEvent()->GetRunNumber()) {
251         fRunNumber = InputEvent()->GetRunNumber();        // set the current run number
252         if(fDebug > 0) printf("__FUNC__ %s > NEW RUNNUMBER DETECTED \n ", __func__);
253         // check if this is 10h or 11h data
254         switch (fCollisionType) {
255             case kPbPb10h : {
256                 if(fDebug > 0) printf(" LHC10h data, assuming full acceptance, reading VZERO calibration DB \n ");
257                 // for 10h data the vzero event plane calibration needs to be cached
258                 ReadVZEROCalibration2010h(); 
259                 // no need to change rho or acceptance for 10h, so we're done
260                 return kTRUE;
261             } break;
262             case kJetFlowMC : {
263                 return kTRUE;
264             } break;
265             default :  {
266                 if(fDebug > 0) printf(" checking runnumber to adjust acceptance on the fly \n");           
267             } break;
268         }
269         // reset the cuts. should be a pointless operation except for the case where the run number changes
270         // from semi-good back to good on one node, which is not a likely scenario (unless trains will
271         // run as one masterjob)
272         switch (fAnalysisType) {
273             case kCharged: {
274                 AliAnalysisTaskEmcalJet::SetJetPhiLimits(-10., 10.);   
275             } break;
276             case kFull: {
277                 AliAnalysisTaskEmcalJet::SetJetPhiLimits(1.405 + GetJetRadius(), 3.135 - GetJetRadius());
278             } break;
279             default: {
280                 AliAnalysisTaskEmcal::SetTrackPhiLimits(-10., 10.);
281             } break;
282         }
283         if(fCachedRho) {                // if there's a cached rho, it's the default, so switch back
284             if(fDebug > 0) printf("__FUNC__ %s > replacing rho with cached rho \n ", __func__);
285             fRho = fCachedRho;          // reset rho back to cached value. again, should be pointless
286         }
287         Bool_t flaggedAsSemiGood(kFALSE);       // not flagged as anything
288         for(Int_t i(0); i < fExpectedSemiGoodRuns->GetSize(); i++) {
289             if(fExpectedSemiGoodRuns->At(i) == fRunNumber) { // run is semi-good
290                if(fDebug > 0) printf("__FUNC__ %s > semi-good tpc run detected, adjusting acceptance \n ", __func__);
291                 flaggedAsSemiGood = kTRUE;
292                 switch (fAnalysisType) {
293                     // for full jets the jet acceptance does not have to be changed as emcal does not
294                     // cover the tpc low voltage readout strips
295                     case kCharged: {
296                         AliAnalysisTaskEmcalJet::SetJetPhiLimits(fSemiGoodJetMinPhi, fSemiGoodJetMaxPhi);       // just an acceptance cut, jets are obtained from full azimuth, so no edge effects
297                     } break;
298                     default: break;
299                 }
300                 AliAnalysisTaskEmcal::SetTrackPhiLimits(fSemiGoodTrackMinPhi, fSemiGoodTrackMaxPhi);    // only affects vn extraction, NOT jet finding
301                 // for semi-good runs, also try to get the 'small rho' estimate, if it is available
302                 AliRhoParameter* tempRho(dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(fNameSmallRho.Data())));
303                 if(tempRho) {
304                     if(fDebug > 0) printf("__FUNC__ %s > switching to small rho, caching normal rho \n ", __func__);
305                     fHistAnalysisSummary->SetBinContent(54, 1.);        // bookkeep the fact that small rho is used
306                     fCachedRho = fRho;          // cache the original rho ...
307                     fRho = tempRho;             // ... and use the small rho
308                 }
309             }
310         }
311         if(!flaggedAsSemiGood) {
312             // in case the run is not a semi-good run, check if it is recognized as another run
313             // only done to catch unexpected runs
314             for(Int_t i(0); i < fExpectedRuns->GetSize(); i++) {
315                 if(fExpectedRuns->At(i) == fRunNumber) break; // run is known, break the loop else store the number in a random bin
316                 fHistUndeterminedRunQA->SetBinContent(TMath::Nint(10.*gRandom->Uniform(0.,.9))+1, fRunNumber);
317             }
318             fHistAnalysisSummary->SetBinContent(53, 1.);                // bookkeep which rho estimate is used 
319         }
320     }
321     return kTRUE;
322 }
323 //_____________________________________________________________________________
324 Bool_t AliAnalysisTaskJetV2::InitializeAnalysis() 
325 {
326     // initialize the anaysis
327     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
328     // if not set, estimate the number of cones that would fit into the selected acceptance
329     if(fMaxCones <= 0) fMaxCones = TMath::CeilNint((TMath::Abs(GetJetContainer()->GetJetEtaMax()-GetJetContainer()->GetJetEtaMin())*TMath::Abs(GetJetContainer()->GetJetPhiMax()-GetJetContainer()->GetJetPhiMin()))/(TMath::Pi()*GetJetRadius()*GetJetRadius()));
330     // manually 'override' the default acceptance cuts of the emcal framework (use with caution) 
331     if(fMinDisanceRCtoLJ==0) fMinDisanceRCtoLJ = GetJetRadius();
332     if(dynamic_cast<AliAODEvent*>(InputEvent())) fDataType = kAOD; // determine the datatype
333     else if(dynamic_cast<AliESDEvent*>(InputEvent())) fDataType = kESD;
334     fHistAnalysisSummary->SetBinContent(36, (int)fDataType);
335     if(!fRandom) fRandom = new TRandom3(0);  // set randomizer and random seed
336     switch (fFitModulationType)  {
337         case kNoFit : { SetModulationFit(new TF1("fix_kNoFit", "[0]", 0, TMath::TwoPi())); } break;
338         case kV2 : {
339             SetModulationFit(new TF1("fit_kV2", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
340             fFitModulation->SetParameter(0, 0.);        // normalization
341             fFitModulation->SetParameter(3, 0.2);       // v2
342             fFitModulation->FixParameter(1, 1.);        // constant
343             fFitModulation->FixParameter(2, 2.);        // constant
344         } break;
345         case kV3: {
346             SetModulationFit(new TF1("fit_kV3", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
347             fFitModulation->SetParameter(0, 0.);        // normalization
348             fFitModulation->SetParameter(3, 0.2);       // v3
349             fFitModulation->FixParameter(1, 1.);        // constant
350             fFitModulation->FixParameter(2, 3.);        // constant
351         } break;
352         default : { // for the combined fit, the 'direct fourier series' or the user supplied vn values we use v2 and v3
353              SetModulationFit(new TF1("fit_kCombined", "[0]*([1]+[2]*([3]*TMath::Cos([2]*(x-[4]))+[7]*TMath::Cos([5]*(x-[6]))))", 0, TMath::TwoPi()));
354              fFitModulation->SetParameter(0, 0.);       // normalization
355              fFitModulation->SetParameter(3, 0.2);      // v2
356              fFitModulation->FixParameter(1, 1.);       // constant
357              fFitModulation->FixParameter(2, 2.);       // constant
358              fFitModulation->FixParameter(5, 3.);       // constant
359              fFitModulation->SetParameter(7, 0.2);      // v3
360         } break;
361     }
362     switch (fRunModeType) {
363         case kGrid : { fFitModulationOptions += "N0"; } break;
364         default : break;
365     }
366     FillAnalysisSummaryHistogram();
367     return kTRUE;
368 }
369 //_____________________________________________________________________________
370 TH1F* AliAnalysisTaskJetV2::BookTH1F(const char* name, const char* x, Int_t bins, Double_t min, Double_t max, Int_t c, Bool_t append)
371 {
372     // book a TH1F and connect it to the output container
373     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
374     if(fReduceBinsXByFactor > 0 ) bins = TMath::Nint(bins/fReduceBinsXByFactor);
375     if(!fOutputList) return 0x0;
376     TString title(name);
377     if(c!=-1) { // format centrality dependent histograms accordingly
378         name = Form("%s_%i", name, c);
379         title += Form("_%i-%i", (int)(fCentralityClasses->At(c)), (int)(fCentralityClasses->At((1+c))));
380     }
381     title += Form(";%s;[counts]", x);
382     TH1F* histogram = new TH1F(name, title.Data(), bins, min, max);
383     histogram->Sumw2();
384     if(append) fOutputList->Add(histogram);
385     return histogram;   
386 }
387 //_____________________________________________________________________________
388 TH2F* AliAnalysisTaskJetV2::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)
389 {
390     // book a TH2F and connect it to the output container
391     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
392     if(fReduceBinsXByFactor > 0 ) binsx = TMath::Nint(binsx/fReduceBinsXByFactor);
393     if(fReduceBinsYByFactor > 0 ) binsy = TMath::Nint(binsy/fReduceBinsYByFactor);
394     if(!fOutputList) return 0x0;
395     TString title(name);
396     if(c!=-1) { // format centrality dependent histograms accordingly
397         name = Form("%s_%i", name, c);
398         title += Form("_%i-%i", (int)fCentralityClasses->At(c), (int)(fCentralityClasses->At((1+c))));
399     }
400     title += Form(";%s;%s", x, y);
401     TH2F* histogram = new TH2F(name, title.Data(), binsx, minx, maxx, binsy, miny, maxy);
402     histogram->Sumw2();
403     if(append) fOutputList->Add(histogram);
404     return histogram;   
405 }
406 //_____________________________________________________________________________
407 TH3F* AliAnalysisTaskJetV2::BookTH3F(const char* name, const char* x, const char* y, const char* z, Int_t binsx, Double_t minx, Double_t maxx, Int_t binsy, Double_t miny, Double_t maxy, Int_t binsz, Double_t minz, Double_t maxz, Int_t c, Bool_t append)
408 {
409     // book a TH2F and connect it to the output container
410     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
411     if(fReduceBinsXByFactor > 0 ) {
412         binsx = TMath::Nint(binsx/fReduceBinsXByFactor);
413         binsy = TMath::Nint(binsy/fReduceBinsXByFactor);
414         binsz = TMath::Nint(binsz/fReduceBinsXByFactor);
415     }
416     if(!fOutputList) return 0x0;
417     TString title(name);
418     if(c!=-1) { // format centrality dependent histograms accordingly
419         name = Form("%s_%i", name, c);
420         title += Form("_%i-%i", (int)fCentralityClasses->At(c), (int)(fCentralityClasses->At((1+c))));
421     }
422     title += Form(";%s;%s;%s", x, y, z);
423     TH3F* histogram = new TH3F(name, title.Data(), binsx, minx, maxx, binsy, miny, maxy, binsz, minz, maxz);
424     histogram->Sumw2();
425     if(append) fOutputList->Add(histogram);
426     return histogram;   
427 }
428 //_____________________________________________________________________________
429 void AliAnalysisTaskJetV2::UserCreateOutputObjects()
430 {
431     // create output objects. also initializes some default values in case they aren't 
432     // loaded via the AddTask macro
433     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
434     fOutputList = new TList();
435     fOutputList->SetOwner(kTRUE);
436     if(!fCentralityClasses) {   // classes must be defined at this point
437         Double_t c[] = {0., 20., 40., 60., 80., 100.};
438         fCentralityClasses = new TArrayD(sizeof(c)/sizeof(c[0]), c);
439     }
440     if(!fExpectedRuns) {        // expected runs must be defined at this point
441         Int_t r[] =  {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, /* up till here original good TPC list */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, /* original semi-good tpc list */169415, 169411, 169035, 168988, 168984, 168826, 168777, 168512, 168511, 168467, 168464, 168342, 168310, 168115, 168108, 168107, 167987, 167915, 167903, /*new runs, good according to RCT */ 169238, 169160, 169156, 169148, 169145, 169144 /* run swith missing OROC 8 but seem ok in QA */};
442         fExpectedRuns = new TArrayI(sizeof(r)/sizeof(r[0]), r);
443     }
444     // set default semi-good runs only for 11h data
445     switch (fCollisionType) {
446         case kPbPb10h : break;
447         default : {
448             if(!fExpectedSemiGoodRuns) {
449                 Int_t r[] = {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};
450                 fExpectedSemiGoodRuns = new TArrayI(sizeof(r)/sizeof(r[0]), r);
451             }
452         }
453     }
454
455     // global QA
456     fHistCentrality =           BookTH1F("fHistCentrality", "centrality", 102, -2, 100);
457     fHistVertexz =              BookTH1F("fHistVertexz", "vertex z (cm)", 100, -12, 12);
458
459     // for some histograms adjust the bounds according to analysis acceptance
460     Double_t etaMin(-1.), etaMax(1.), phiMin(0.), phiMax(TMath::TwoPi());
461     switch (fAnalysisType) {
462         case kFull : {
463            etaMin = -.7;       
464            etaMax = .7;
465            phiMin = 1.405;
466            phiMax = 3.135;
467         } break;
468         default : break;
469     }
470
471     // pico track and emcal cluster kinematics
472     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) { 
473         fHistPicoTrackPt[i] =           BookTH1F("fHistPicoTrackPt", "p_{t} [GeV/c]", 100, 0, 100, i);
474         fHistPicoTrackMult[i] =         BookTH1F("fHistPicoTrackMult", "multiplicity", 100, 0, 5000, i);
475         if(fFillQAHistograms) {
476             fHistPicoCat1[i] =          BookTH2F("fHistPicoCat1", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
477             fHistPicoCat2[i] =          BookTH2F("fHistPicoCat2", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
478             fHistPicoCat3[i] =          BookTH2F("fHistPicoCat3", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
479             if(fAnalysisType == AliAnalysisTaskJetV2::kFull) {
480                 fHistClusterPt[i] =     BookTH1F("fHistClusterPt", "p_{t} [GeV/c]", 100, 0, 100, i);
481                 fHistClusterEtaPhi[i] = BookTH2F("fHistClusterEtaPhi", "#eta", "#phi", 100, etaMax, etaMax, 100, phiMin, phiMax, i);
482                 fHistClusterEtaPhiWeighted[i] = BookTH2F("fHistClusterEtaPhiWeighted", "#eta", "#phi", 100, etaMin, etaMax, 100, phiMin, phiMax, i);
483             }
484             fHistPsiTPCLeadingJet[i] =          BookTH3F("fHistPsiTPCLeadingJet", "p_{t} [GeV/c]", "#Psi_{TPC}", "#varphi_{jet}", 70, 0, 210, 50, -1.*TMath::Pi()/2., TMath::Pi()/2., 50, phiMin, phiMax, i);
485             fHistPsiVZEROALeadingJet[i] =       BookTH3F("fHistPsiVZEROALeadingJet", "p_{t} [GeV/c]", "#Psi_{VZEROA}", "#varphi_{jet}", 70, 0, 210, 50, -1.*TMath::Pi()/2., TMath::Pi()/2., 50, phiMin, phiMax, i);
486             fHistPsiVZEROCLeadingJet[i] =       BookTH3F("fHistPsiVZEROCLeadingJet", "p_{t} [GeV/c]", "#Psi_{VZEROC}", "#varphi_{jet}", 70, 0, 210, 50, -1.*TMath::Pi()/2., TMath::Pi()/2., 50, phiMin, phiMax, i);
487             fHistPsiVZEROCombLeadingJet[i] =    BookTH3F("fHistPsiVZEROCombLeadingJet", "p_{t} [GeV/c]", "#Psi_{VZEROComb}", "#varphi_{jet}", 70, 0, 210, 50, -1.*TMath::Pi()/2., TMath::Pi()/2., 50, phiMin, phiMax, i);
488             fHistPsi2Correlation[i] = BookTH3F("fHistPsi2Correlation", "#Psi_{TPC}", "#Psi_{VZEROA}", "#Psi_{VZEROC}",  20, -1.*TMath::Pi()/2., TMath::Pi()/2., 20, -1.*TMath::Pi()/2., TMath::Pi()/2., 20, -1.*TMath::Pi()/2., TMath::Pi()/2., i);
489             fHistLeadingJetBackground[i] =      BookTH2F("fHistLeadingJetBackground", "#Delta #eta (leading jet with, without sub)", "Delta #varphi (leading jet with, without sub)", 50, 0., 2, 50, 0., TMath::TwoPi(), i);
490         }
491     }
492
493     if(fFillQAHistograms) {
494         // event plane estimates and quality
495         fHistPsiControl =           new TProfile("fHistPsiControl", "fHistPsiControl", 10, 0, 10);
496         fHistPsiControl->Sumw2();
497         fHistPsiSpread =            new TProfile("fHistPsiSpread", "fHistPsiSpread", 4, 0, 4);
498         fHistPsiSpread->Sumw2();
499         fHistPsiControl->GetXaxis()->SetBinLabel(1, "<#Psi_{2, VZEROA}>");
500         fHistPsiControl->GetXaxis()->SetBinLabel(2, "<#Psi_{2, VZEROC}>");
501         fHistPsiControl->GetXaxis()->SetBinLabel(3, "<#Psi_{2, TPC}>");
502         fHistPsiControl->GetXaxis()->SetBinLabel(4, "<#Psi_{2, TPC, #eta < 0}>");
503         fHistPsiControl->GetXaxis()->SetBinLabel(5, "<#Psi_{2, TPC, #eta > 0}>");
504         fHistPsiControl->GetXaxis()->SetBinLabel(6, "<#Psi_{3, VZEROA}>");
505         fHistPsiControl->GetXaxis()->SetBinLabel(7, "<#Psi_{3, VZEROC}>");
506         fHistPsiControl->GetXaxis()->SetBinLabel(8, "<#Psi_{3, TPC}>");
507         fHistPsiControl->GetXaxis()->SetBinLabel(9, "<#Psi_{3, TPC, #eta < 0}>");
508         fHistPsiControl->GetXaxis()->SetBinLabel(10, "<#Psi_{3, TPC, #eta > 0}>");
509         fHistPsiSpread->GetXaxis()->SetBinLabel(1, "<#Psi_{2, VZEROA} - #Psi_{2, VZEROC}>");
510         fHistPsiSpread->GetXaxis()->SetBinLabel(2, "<#Psi_{2, VZEROC} - #Psi_{2, TPC}>");
511         fHistPsiSpread->GetXaxis()->SetBinLabel(3, "<#Psi_{2, VZEROC} - #Psi_{2, TPC}>");
512         fHistPsiSpread->GetXaxis()->SetBinLabel(4, "<#Psi_{2, TPC, #eta < 0} - #Psi_{2, TPC, #eta > 0}>");
513         fOutputList->Add(fHistPsiControl);
514         fOutputList->Add(fHistPsiSpread);
515         fHistPsiVZEROA =            BookTH1F("fHistPsiVZEROA", "#Psi_{VZEROA}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
516         fHistPsiVZEROC =            BookTH1F("fHistPsiVZEROC", "#Psi_{VZEROC}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
517         fHistPsiVZERO =             BookTH1F("fHistPsiVZERO", "#Psi_{VZERO}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
518         fHistPsiTPC =               BookTH1F("fHistPsiTPC", "#Psi_{TPC}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
519         fHistPsiVZEROAV0M =         BookTH2F("fHistPsiVZEROAV0M", "V0M", "#Psi_{2, VZEROA}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
520         fHistPsiVZEROCV0M =         BookTH2F("fHistPsiVZEROCV0M", "V0M", "#Psi_{2, VZEROC}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
521         fHistPsiVZEROVV0M =         BookTH2F("fHistPsiVZEROV0M", "V0M", "#Psi_{2, VZERO}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
522         fHistPsiTPCV0M =            BookTH2F("fHistPsiTPCV0M", "V0M", "#Psi_{2, TRK}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
523         fHistPsiVZEROATRK =         BookTH2F("fHistPsiVZEROATRK", "TRK", "#Psi_{2, VZEROA}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
524         fHistPsiVZEROCTRK =         BookTH2F("fHistPsiVZEROCTRK", "TRK", "#Psi_{2, VZEROC}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
525         fHistPsiVZEROTRK =          BookTH2F("fHistPsiVZEROTRK", "TRK", "#Psi_{2, VZERO}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
526         fHistPsiTPCTRK =            BookTH2F("fHistPsiTPCTRK", "TRK", "#Psi_{2, TRK}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
527     }
528     // background
529     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i ++) {
530         fHistRhoPackage[i] =           BookTH1F("fHistRhoPackage",  "#rho [GeV/c]", 100, 0, 150, i);
531         fHistRho[i] =                  BookTH1F("fHistRho", "#rho [GeV/c]", 100, 0, 150, i);
532     }
533     fHistRhoVsMult =            BookTH2F("fHistRhoVsMult", "multiplicity", "#rho [GeV/c]", 100, 0, 4000, 100, 0, 250);
534     fHistRhoVsCent =            BookTH2F("fHistRhoVsCent", "centrality", "#rho [GeV/c]", 100, 0, 100, 100, 0, 250);
535     fHistRhoAVsMult =           BookTH2F("fHistRhoAVsMult", "multiplicity", "#rho * A (jet) [GeV/c]", 100, 0, 4000, 100, 0, 50);
536     fHistRhoAVsCent =           BookTH2F("fHistRhoAVsCent", "centrality", "#rho * A (jet) [GeV/c]", 100, 0, 100, 100, 0, 50);
537
538     TString detector("");
539     switch (fDetectorType) {
540         case kTPC : detector+="TPC";
541             break;
542         case kVZEROA : detector+="VZEROA";
543             break;
544         case kVZEROC : detector+="VZEROC";
545             break;
546         case kVZEROComb : detector+="VZEROComb";
547             break; 
548         case kFixedEP : detector+="FixedEP";
549             break;
550         default: break;
551     }
552     // delta pt distributions
553     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i ++) {
554         if(fFillQAHistograms)   fHistRCPhiEta[i] = BookTH2F("fHistRCPhiEta", "#phi (RC)", "#eta (RC)", 40, phiMin, phiMax, 40, etaMin, etaMax, i);
555         fHistRhoVsRCPt[i] =            BookTH2F("fHistRhoVsRCPt", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
556         fHistRCPt[i] =                 BookTH1F("fHistRCPt", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
557         if(fFillQAHistograms)   fHistRCPhiEtaExLJ[i] = BookTH2F("fHistRCPhiEtaExLJ", "#phi (RC)", "#eta (RC)", 40, phiMin, phiMax, 40, etaMin, etaMax, i);
558         fHistDeltaPtDeltaPhi2[i] =  BookTH2F("fHistDeltaPtDeltaPhi2", Form("#phi - #Psi_{2, %s}", detector.Data()), "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
559         fHistDeltaPtDeltaPhi2Rho0[i] =  BookTH2F("fHistDeltaPtDeltaPhi2Rho0", Form("#phi - #Psi_{2, %s}", detector.Data()), "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
560         fHistRhoVsRCPtExLJ[i] =        BookTH2F("fHistRhoVsRCPtExLJ", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
561         fHistRCPtExLJ[i] =             BookTH1F("fHistRCPtExLJ", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
562         fHistDeltaPtDeltaPhi2ExLJ[i] = BookTH2F("fHistDeltaPtDeltaPhi2ExLJ", Form("#phi - #Psi_{2, %s}", detector.Data()),  "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
563         fHistDeltaPtDeltaPhi2ExLJRho0[i] = BookTH2F("fHistDeltaPtDeltaPhi2ExLJRho0", Form("#phi - #Psi_{2, %s}", detector.Data()),  "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
564         // jet histograms (after kinematic cuts)
565         fHistJetPtRaw[i] =             BookTH1F("fHistJetPtRaw", "p_{t, jet} RAW [GeV/c]", 200, -50, 150, i);
566         fHistJetPt[i] =                BookTH1F("fHistJetPt", "p_{t, jet} [GeV/c]", 350, -100, 250, i);
567         if(fFillQAHistograms)   fHistJetEtaPhi[i] =            BookTH2F("fHistJetEtaPhi", "#eta", "#phi", 100, etaMin, etaMax, 100, phiMin, phiMax, i);
568         fHistJetPtArea[i] =            BookTH2F("fHistJetPtArea", "p_{t, jet} [GeV/c]", "Area", 175, -100, 250, 30, 0, 0.9, i);
569         fHistJetPtEta[i] =             BookTH2F("fHistJetPtEta", "p_{t, jet} [GeV/c]", "Eta", 175, -100, 250, 30, etaMin, etaMax, i);
570         fHistJetPtConstituents[i] =    BookTH2F("fHistJetPtConstituents", "p_{t, jet} [GeV/c]", "no. of constituents", 350, -100, 250, 60, 0, 150, i);
571         fHistJetEtaRho[i] =            BookTH2F("fHistJetEtaRho", "#eta", "#rho", 100, etaMin, etaMax, 100, 0, 300, i);
572         // in plane and out of plane spectra
573         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);
574         fHistJetPsi2PtRho0[i] =        BookTH2F("fHistJetPsi2PtRho0", Form("#phi_{jet} - #Psi_{2, %s}", detector.Data()), "p_{t, jet} [GeV/c]", 40, 0., TMath::Pi(), 350, -100, 250, i);
575         // profiles for all correlator permutations which are necessary to calculate each second and third order event plane resolution
576         fProfV2Resolution[i] = new TProfile(Form("fProfV2Resolution_%i", i), Form("fProfV2Resolution_%i", i), 11, -0.5, 10.5);
577         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(3, "<cos(2(#Psi_{VZEROA} - #Psi_{VZEROC}))>");
578         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(4, "<cos(2(#Psi_{VZEROC} - #Psi_{VZEROA}))>");
579         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(5, "<cos(2(#Psi_{VZEROA} - #Psi_{TPC}))>");
580         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(6, "<cos(2(#Psi_{TPC} - #Psi_{VZEROA}))>");
581         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(7, "<cos(2(#Psi_{VZEROC} - #Psi_{TPC}))>");
582         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(8, "<cos(2(#Psi_{TPC} - #Psi_{VZEROC}))>");
583         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(9, "<cos(2(#Psi_{VZERO} - #Psi_{TPC_A}))>");
584         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(10, "<cos(2(#Psi_{VZERO} - #Psi_{TPC_B}))>");
585         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(11, "<cos(2(#Psi_{TPC_A} - #Psi_{TPC_B}))>");
586         fOutputList->Add(fProfV2Resolution[i]); 
587         fProfV3Resolution[i] = new TProfile(Form("fProfV3Resolution_%i", i), Form("fProfV3Resolution_%i", i), 11, -0.5, 10.5);
588         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(3, "<cos(3(#Psi_{VZEROA} - #Psi_{VZEROC}))>");
589         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(4, "<cos(3(#Psi_{VZEROC} - #Psi_{VZEROA}))>");
590         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(5, "<cos(3(#Psi_{VZEROA} - #Psi_{TPC}))>");
591         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(6, "<cos(3(#Psi_{TPC} - #Psi_{VZEROA}))>");
592         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(7, "<cos(3(#Psi_{VZEROC} - #Psi_{TPC}))>");
593         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(8, "<cos(3(#Psi_{TPC} - #Psi_{VZEROC}))>");
594         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(9, "<cos(3(#Psi_{VZERO} - #Psi_{TPC_A}))>");
595         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(10, "<cos(3(#Psi_{VZERO} - #Psi_{TPC_B}))>");
596         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(11, "<cos(3(#Psi_{TPC_A} - #Psi_{TPC_B}))>");
597         fOutputList->Add(fProfV3Resolution[i]); 
598     }
599    // vn profile
600     Float_t temp[fCentralityClasses->GetSize()];
601     for(Int_t i(0); i < fCentralityClasses->GetSize(); i++) temp[i] = fCentralityClasses->At(i);
602     fProfV2 = new TProfile("fProfV2", "fProfV2", fCentralityClasses->GetSize()-1, temp);
603     fProfV3 = new TProfile("fProfV3", "fProfV3", fCentralityClasses->GetSize()-1, temp);
604     fOutputList->Add(fProfV2);
605     fOutputList->Add(fProfV3);
606     switch (fFitModulationType) {
607         case kQC2 : {
608             fProfV2Cumulant = new TProfile("fProfV2Cumulant", "fProfV2Cumulant", fCentralityClasses->GetSize()-1, temp);
609             fProfV3Cumulant = new TProfile("fProfV3Cumulant", "fProfV3Cumulant", fCentralityClasses->GetSize()-1, temp);
610             fOutputList->Add(fProfV2Cumulant);
611             fOutputList->Add(fProfV3Cumulant);
612         } break;
613         case kQC4 : {
614             fProfV2Cumulant = new TProfile("fProfV2Cumulant", "fProfV2Cumulant", fCentralityClasses->GetSize()-1, temp);
615             fProfV3Cumulant = new TProfile("fProfV3Cumulant", "fProfV3Cumulant", fCentralityClasses->GetSize()-1, temp);
616             fOutputList->Add(fProfV2Cumulant);
617             fOutputList->Add(fProfV3Cumulant);
618         } break;
619         default : break;
620     }
621     // for the histograms initialized below, binning is fixed to runnumbers or flags
622     fReduceBinsXByFactor = 1;
623     fReduceBinsYByFactor = 1;
624     if(fFillQAHistograms) {
625         fHistRunnumbersEta = new TH2F("fHistRunnumbersEta", "fHistRunnumbersEta", fExpectedRuns->GetSize()+1, -.5, fExpectedRuns->GetSize()+.5, 100, -1.1, 1.1);
626         fHistRunnumbersEta->Sumw2();
627         fOutputList->Add(fHistRunnumbersEta);
628         fHistRunnumbersPhi = new TH2F("fHistRunnumbersPhi", "fHistRunnumbersPhi", fExpectedRuns->GetSize()+1, -.5, fExpectedRuns->GetSize()+.5, 100, -0.2, TMath::TwoPi()+0.2);
629         fHistRunnumbersPhi->Sumw2();
630         fOutputList->Add(fHistRunnumbersPhi);
631         for(Int_t i(0); i < fExpectedRuns->GetSize(); i++) { 
632             fHistRunnumbersPhi->GetXaxis()->SetBinLabel(i+1, Form("%i", fExpectedRuns->At(i)));
633             fHistRunnumbersEta->GetXaxis()->SetBinLabel(i+1, Form("%i", fExpectedRuns->At(i)));
634         }
635         fHistRunnumbersPhi->GetXaxis()->SetBinLabel(fExpectedRuns->GetSize()+1, "undetermined");
636         fHistRunnumbersEta->GetXaxis()->SetBinLabel(fExpectedRuns->GetSize()+1, "undetermined");
637     }
638     fHistAnalysisSummary = BookTH1F("fHistAnalysisSummary", "flag", 54, -0.5, 54.5);
639     fHistSwap = new TH1F("fHistSwap", "fHistSwap", 20, 0, TMath::TwoPi());
640     if(fUsePtWeight) fHistSwap->Sumw2();
641
642     if(fUserSuppliedV2)         fOutputList->Add(fUserSuppliedV2);
643     if(fUserSuppliedV3)         fOutputList->Add(fUserSuppliedV3);
644     if(fUserSuppliedR2)         fOutputList->Add(fUserSuppliedR2);
645     if(fUserSuppliedR3)         fOutputList->Add(fUserSuppliedR3);
646     if(fEventPlaneWeights)      fOutputList->Add(fEventPlaneWeights);
647     // increase readability of output list
648     fOutputList->Sort();
649     // cdf and pdf of chisquare distribution
650     fHistPvalueCDF = BookTH1F("fHistPvalueCDF", "CDF #chi^{2}", 50, 0, 1);
651     fHistPvalueCDFCent = BookTH2F("fHistPvalueCDFCent", "centrality", "p-value", 40, 0, 100, 40, 0, 1);
652     fHistChi2Cent = BookTH2F("fHistChi2Cent", "centrality", "#tilde{#chi^{2}}", 100, 0, 100, 100, 0, 5);
653     fHistPChi2 = BookTH2F("fHistPChi2", "p-value", "#tilde{#chi^{2}}", 1000, 0, 1, 100, 0, 5);
654     fHistKolmogorovTest = BookTH1F("fHistKolmogorovTest", "KolmogorovTest", 50, 0, 1);
655     fHistKolmogorovTestCent = BookTH2F("fHistKolmogorovTestCent", "centrality", "Kolmogorov p", 40, 0, 100, 45, 0, 1); 
656     fHistPvalueCDFROOT = BookTH1F("fHistPvalueCDFROOT", "CDF #chi^{2} ROOT", 50, 0, 1);
657     fHistPvalueCDFROOTCent = BookTH2F("fHistPvalueCDFROOTCent", "centrality", "p-value ROOT", 40, 0, 100, 45, 0, 1);
658     fHistChi2ROOTCent = BookTH2F("fHistChi2ROOTCent", "centrality", "#tilde{#chi^{2}}", 40, 0, 100, 45, 0, 5);
659     fHistPChi2Root = BookTH2F("fHistPChi2Root", "p-value", "#tilde{#chi^{2}} ROOT", 1000, 0, 1, 100, 0, 5);
660     fHistPKolmogorov = BookTH2F("fHistPKolmogorov", "p-value", "kolmogorov p",40, 0, 1, 40, 0, 1);
661     fHistRhoStatusCent = BookTH2F("fHistRhoStatusCent", "centrality", "status [-1=lin was better, 0=ok, 1 = failed]", 101, -1, 100, 3, -1.5, 1.5);
662     fHistUndeterminedRunQA = BookTH1F("fHistUndeterminedRunQA", "runnumber", 10, 0, 10);
663  
664     PostData(1, fOutputList);
665
666     switch (fRunModeType) {
667         case kLocal : {
668             fOutputListGood = new TList();
669             fOutputListGood->SetOwner(kTRUE);
670             fOutputListBad = new TList();
671             fOutputListBad->SetOwner(kTRUE);
672             PostData(2, fOutputListGood);
673             PostData(3, fOutputListBad);
674         } break;
675         default: break;
676     }
677
678     // get the containers
679     fTracksCont = GetParticleContainer("Tracks");
680     fClusterCont = GetClusterContainer(0);      // get the default cluster container
681     fJetsCont = GetJetContainer("Jets");
682 }
683 //_____________________________________________________________________________
684 Bool_t AliAnalysisTaskJetV2::Run()
685 {
686     // called for each accepted event (call made from user exec of parent class)
687     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
688     if(!fTracks||!fJets||!fRho) {
689         if(!fTracks) printf(" > Failed to retrieve fTracks ! < \n");
690         if(!fJets) printf(" > Failed to retrieve fJets ! < \n");
691         if(!fRho) printf(" > Failed to retrieve fRho ! < \n");
692         return kFALSE;
693     }
694     if(!fLocalInit) fLocalInit = InitializeAnalysis();
695     // reject the event if expected data is missing
696     if(!PassesCuts(InputEvent())) return kFALSE;
697     // cache the leading jet within acceptance
698     fLeadingJet = GetLeadingJet();
699     // set the rho value 
700     fLocalRho->SetVal(fRho->GetVal());
701     // place holder arrays for the event planes
702     //
703     // [0][0] psi2a     [1,0]   psi2c
704     // [0][1] psi3a     [1,1]   psi3c
705     Double_t vzero[2][2];
706     /* for the combined vzero event plane
707      * [0] psi2         [1] psi3
708      * not fully implmemented yet, use with caution ! */
709     Double_t vzeroComb[2];
710     // [0] psi2         [1] psi3
711     Double_t tpc[2];
712     // evaluate the actual event planes
713     switch (fDetectorType) {
714         case kFixedEP : {
715             // for fixed, fix all ep's to default values
716             tpc[0] = 0.;         tpc[1] = 1.;
717             vzero[0][0] = 0.;    vzero[0][1] = 1.;
718             vzero[1][0] = 0.;    vzero[1][1] = 1.;
719             vzeroComb[0] = 0.;   vzeroComb[1] = 1.;
720         } break;
721         default : {
722             // else grab the actual data
723             CalculateEventPlaneVZERO(vzero);
724             CalculateEventPlaneCombinedVZERO(vzeroComb);
725             CalculateEventPlaneTPC(tpc);
726         } break;
727     }
728     Double_t psi2(-1), psi3(-1);
729     // arrays which will hold the fit parameters
730     switch (fDetectorType) {    // determine the detector type for the rho fit
731         case kTPC :     { psi2 = tpc[0];         psi3 = tpc[1]; }       break;
732         case kVZEROA :  { psi2 = vzero[0][0];    psi3 = vzero[0][1]; }  break;  
733         case kVZEROC :  { psi2 = vzero[1][0];    psi3 = vzero[1][1]; }  break;
734         case kVZEROComb : { psi2 = vzeroComb[0]; psi3 = vzeroComb[1];}  break;
735         case kFixedEP : { psi2 = 0.;             psi3 = 1.;}            break;
736         default : break;
737     }
738     // if requested extract the event plane weight
739     if(fEventPlaneWeights) {
740         fEventPlaneWeight = fEventPlaneWeights->GetBinContent(fEventPlaneWeights->FindBin(psi2));
741     }
742     switch (fFitModulationType) { // do the fits
743         case kNoFit : { 
744              switch (fCollisionType) {
745                  case kPythia : { // background is zero for pp jets
746                      fFitModulation->FixParameter(0, 0);
747                      fLocalRho->SetVal(0);
748                  } break;
749                  default :  {
750                      fFitModulation->FixParameter(0, fLocalRho->GetVal()); 
751                  } break;
752              }
753         } break;
754         case kV2 : {    // only v2
755             if(CorrectRho(psi2, psi3)) {
756                 fProfV2->Fill(fCent, fFitModulation->GetParameter(3));
757                 if(fUserSuppliedR2) {
758                     Double_t r(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
759                     if(r > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r);
760                 }
761                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
762             }
763         } break;
764         case kV3 : {    // only v3
765             if(CorrectRho(psi2, psi3)) {
766                 if(fUserSuppliedR3) {
767                     Double_t r(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
768                     if(r > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r);
769                 }
770                 fProfV3->Fill(fCent, fFitModulation->GetParameter(3));
771                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
772             }
773         } break;
774         case kQC2 : {   // qc2 analysis
775             if(CorrectRho(psi2, psi3)) {
776                 if(fUserSuppliedR2 && fUserSuppliedR3) {
777                     // note for the qc method, resolution is REVERSED to go back to v2obs
778                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
779                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
780                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)*r2);
781                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)*r3);
782                 }
783                 if (fUsePtWeight) { // use weighted weights
784                     Double_t dQCnM11 = (fNoEventWeightsForQC) ? 1. : QCnM11();
785                     fProfV2->Fill(fCent, fFitModulation->GetParameter(3), dQCnM11);
786                     fProfV3->Fill(fCent, fFitModulation->GetParameter(7), dQCnM11); 
787                 } else {
788                     Double_t dQCnM = (fNoEventWeightsForQC) ? 2. : QCnM();
789                     fProfV2->Fill(fCent, fFitModulation->GetParameter(3), dQCnM*(dQCnM-1));
790                     fProfV3->Fill(fCent, fFitModulation->GetParameter(7), dQCnM*(dQCnM-1));
791                 }
792                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
793             }
794         } break;
795         case kQC4 : {
796             if(CorrectRho(psi2, psi3)) {
797                 if(fUserSuppliedR2 && fUserSuppliedR3) {
798                     // note for the qc method, resolution is REVERSED to go back to v2obs   
799                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
800                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
801                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)*r2);
802                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)*r3);
803                 }
804                 if (fUsePtWeight) { // use weighted weights
805                     fProfV2->Fill(fCent, TMath::Power(fFitModulation->GetParameter(3),0.5)/*, QCnM1111()*/);
806                     fProfV3->Fill(fCent, TMath::Power(fFitModulation->GetParameter(7),0.5)/*, QCnM1111()*/); 
807                 } else {
808                     fProfV2->Fill(fCent, TMath::Power(fFitModulation->GetParameter(3),0.5)/*, QCnM()*(QCnM()-1)*(QCnM()-2)*(QCnM()-3)*/);
809                     fProfV3->Fill(fCent, TMath::Power(fFitModulation->GetParameter(7),0.5)/*, QCnM()*(QCnM()-1)*(QCnM()-2)*(QCnM()-3)*/);
810                 }
811             }
812             CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
813         } break;
814         default : {
815             if(CorrectRho(psi2, psi3)) {
816                 if(fUserSuppliedR2 && fUserSuppliedR3) {
817                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
818                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
819                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r2);
820                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)/r3);
821                 }
822                 fProfV2->Fill(fCent, fFitModulation->GetParameter(3));
823                 fProfV3->Fill(fCent, fFitModulation->GetParameter(7));
824                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
825             }
826         } break;
827     }
828     // if all went well, update the local rho parameter
829     fLocalRho->SetLocalRho(fFitModulation);
830     // and only at this point can the leading jet after rho subtraction be evaluated
831     if(fFillQAHistograms) fLeadingJetAfterSub = GetLeadingJet(fLocalRho);
832     // fill a number of histograms. event qa needs to be filled first as it also determines the runnumber for the track qa 
833     if(fFillQAHistograms)       {
834         if(fEventPlaneWeights) FillWeightedQAHistograms(InputEvent());
835         else FillQAHistograms(InputEvent());
836     }
837     if(fFillHistograms)         FillHistogramsAfterSubtraction(psi2, vzero, vzeroComb, tpc);
838     // send the output to the connected output container
839     PostData(1, fOutputList);
840     switch (fRunModeType) {
841         case kLocal : {
842             PostData(2, fOutputListGood);
843             PostData(3, fOutputListBad);
844         } break;
845         default: break;
846     }
847     return kTRUE;
848 }
849 //_____________________________________________________________________________
850 void AliAnalysisTaskJetV2::Exec(Option_t* c)
851 {
852     // for stand alone, avoid framework event setup
853     switch (fCollisionType) {
854         case kJetFlowMC : {
855             // need to call ExecOnce as it is not loaded otherwise
856             if(!fLocalRho) AliAnalysisTaskJetV2::ExecOnce();
857             AliAnalysisTaskJetV2::Run();
858         } break;
859         default : {
860             AliAnalysisTaskSE::Exec(c);
861         } break;
862     }
863 }  
864 //_____________________________________________________________________________
865 Double_t AliAnalysisTaskJetV2::CalculateEventPlaneChi(Double_t res)
866 {
867     // return chi for given resolution to combine event plane estimates from two subevents
868     // see Phys. Rev. C no. CS6346 (http://arxiv.org/abs/nucl-ex/9805001)
869     Double_t chi(2.), delta(1.), con((TMath::Sqrt(TMath::Pi()))/(2.*TMath::Sqrt(2)));
870     for (Int_t i(0); i < 15; i++) {
871         chi = ((con*chi*TMath::Exp(-chi*chi/4.)*(TMath::BesselI0(chi*chi/4.)+TMath::BesselI1(chi*chi/4.))) < res) ? chi + delta : chi - delta;
872         delta = delta / 2.;
873     }
874     return chi;
875 }
876 //_____________________________________________________________________________
877 void AliAnalysisTaskJetV2::CalculateEventPlaneVZERO(Double_t vzero[2][2]) const 
878 {
879     // get the vzero event plane (a and c separately)
880     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
881     switch (fCollisionType) {
882         case kPbPb10h : {
883             // for 10h data, get the calibrated q-vector from the database
884             Double_t QA2[] = {-999., -999.};
885             Double_t QA3[] = {-999., -999.};
886             Double_t QC2[] = {-999., -999.};
887             Double_t QC3[] = {-999., -999.};
888             CalculateQvectorVZERO(QA2, QA3, QC2, QC3);
889             vzero[0][0] = .5*TMath::ATan2(QA2[1], QA2[0]);
890             vzero[1][0] = .5*TMath::ATan2(QC2[1], QC2[0]);
891             vzero[0][1] = (1./3.)*TMath::ATan2(QA3[1], QA3[0]);
892             vzero[1][1] = (1./3.)*TMath::ATan2(QC3[1], QC3[0]);
893         } break;
894         default: {
895             // by default use the ep from the event header (make sure EP selection task is enabeled!)
896             Double_t a(0), b(0), c(0), d(0), e(0), f(0), g(0), h(0);
897             vzero[0][0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 2, a, b);
898             vzero[1][0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 2, c, d);
899             vzero[0][1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 3, e, f);
900             vzero[1][1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 3, g, h);
901             return;
902         }
903     }
904 }
905 //_____________________________________________________________________________
906 void AliAnalysisTaskJetV2::CalculateEventPlaneCombinedVZERO(Double_t* comb) const
907 {
908     // return the combined vzero event plane
909     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
910     switch (fCollisionType) {
911         // for 10h data call calibration info
912         case kPbPb10h : {
913             // get the calibrated q-vectors
914             Double_t Q2[] = {-999., -999.};            
915             Double_t Q3[] = {-999., -999.};
916             // return if something isn't ok from the calibration side
917             CalculateQvectorCombinedVZERO(Q2, Q3);
918             comb[0] = .5*TMath::ATan2(Q2[1], Q2[0]);
919             comb[1] = (1./3.)*TMath::ATan2(Q3[1], Q3[0]);
920         } break;
921         default : {
922             // for all other types use calibrated event plane from the event header
923             Double_t a(0), b(0), c(0), d(0);
924             comb[0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 10, 2, a, b);
925             comb[1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 10, 3, c, d);
926         } break;
927     }
928 }
929 //_____________________________________________________________________________
930 void AliAnalysisTaskJetV2::CalculateEventPlaneTPC(Double_t* tpc)
931 {
932    // grab the TPC event plane
933    if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
934    fNAcceptedTracks = 0;                // reset the track counter
935    Double_t qx2(0), qy2(0);     // for psi2
936    Double_t qx3(0), qy3(0);     // for psi3
937    if(fTracksCont) {
938        Float_t excludeInEta = -999;
939        if(fExcludeLeadingJetsFromFit > 0 ) {    // remove the leading jet from ep estimate
940            if(fLeadingJet) excludeInEta = fLeadingJet->Eta();
941        }
942        for(Int_t iTPC(0); iTPC < fTracksCont->GetNEntries(); iTPC++) {
943            AliVParticle* track = fTracksCont->GetParticle(iTPC);
944            if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
945            if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta) < GetJetContainer()->GetJetRadius()*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - GetJetContainer()->GetJetRadius() - GetJetContainer()->GetJetEtaMax() ) > 0 )) continue;
946            fNAcceptedTracks++;
947            qx2+= TMath::Cos(2.*track->Phi());
948            qy2+= TMath::Sin(2.*track->Phi());
949            qx3+= TMath::Cos(3.*track->Phi());
950            qy3+= TMath::Sin(3.*track->Phi());
951        }
952    }
953    tpc[0] = .5*TMath::ATan2(qy2, qx2);
954    tpc[1] = (1./3.)*TMath::ATan2(qy3, qx3);
955 }
956 //_____________________________________________________________________________
957 void AliAnalysisTaskJetV2::CalculateEventPlaneResolution(Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc)
958 {
959     // fill the profiles for the resolution parameters
960     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
961     fProfV2Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(2.*(vzero[0][0] - vzero[1][0])));
962     fProfV2Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(2.*(vzero[1][0] - vzero[0][0])));
963     fProfV2Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(2.*(vzero[0][0] - tpc[0])));
964     fProfV2Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(2.*(tpc[0] - vzero[0][0])));
965     fProfV2Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(2.*(vzero[1][0] - tpc[0])));
966     fProfV2Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(2.*(tpc[0] - vzero[1][0])));
967     fProfV3Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(3.*(vzero[0][0] - vzero[1][0])));
968     fProfV3Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(3.*(vzero[1][0] - vzero[0][0])));
969     fProfV3Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(3.*(vzero[0][0] - tpc[0])));
970     fProfV3Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(3.*(tpc[0] - vzero[0][0])));
971     fProfV3Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(3.*(vzero[1][0] - tpc[0])));
972     fProfV3Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(3.*(tpc[0] - vzero[1][0])));
973     // for the resolution of the combined vzero event plane, use two tpc halves as uncorrelated subdetectors
974     Double_t qx2a(0), qy2a(0);     // for psi2a, negative eta
975     Double_t qx3a(0), qy3a(0);     // for psi3a, negative eta
976     Double_t qx2b(0), qy2b(0);     // for psi2a, positive eta
977     Double_t qx3b(0), qy3b(0);     // for psi3a, positive eta
978     if(fTracks) {
979        Int_t iTracks(fTracks->GetEntriesFast());
980        for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
981            AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
982            if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
983            if(track->Eta() < 0 ) {
984                qx2a+= TMath::Cos(2.*track->Phi());
985                qy2a+= TMath::Sin(2.*track->Phi());
986                qx3a+= TMath::Cos(3.*track->Phi());
987                qy3a+= TMath::Sin(3.*track->Phi());
988            } else if (track->Eta() > 0) {
989                qx2b+= TMath::Cos(2.*track->Phi());
990                qy2b+= TMath::Sin(2.*track->Phi());
991                qx3b+= TMath::Cos(3.*track->Phi());
992                qy3b+= TMath::Sin(3.*track->Phi());
993            }
994        }
995    }
996    Double_t tpca2(.5*TMath::ATan2(qy2a, qx2a));
997    Double_t tpca3((1./3.)*TMath::ATan2(qy3a, qx3a));
998    Double_t tpcb2(.5*TMath::ATan2(qy2b, qx2b));
999    Double_t tpcb3((1./3.)*TMath::ATan2(qy3b, qx3b));
1000    fProfV2Resolution[fInCentralitySelection]->Fill(8., TMath::Cos(2.*(vzeroComb[0] - tpca2)));
1001    fProfV2Resolution[fInCentralitySelection]->Fill(9., TMath::Cos(2.*(vzeroComb[0] - tpcb2)));
1002    fProfV2Resolution[fInCentralitySelection]->Fill(10., TMath::Cos(2.*(tpca2 - tpcb2))); 
1003    fProfV3Resolution[fInCentralitySelection]->Fill(8., TMath::Cos(3.*(vzeroComb[1] - tpca3)));
1004    fProfV3Resolution[fInCentralitySelection]->Fill(9., TMath::Cos(3.*(vzeroComb[1] - tpcb3)));
1005    fProfV3Resolution[fInCentralitySelection]->Fill(10., TMath::Cos(3.*(tpca3 - tpcb3))); 
1006 }   
1007 //_____________________________________________________________________________
1008 void AliAnalysisTaskJetV2::CalculateQvectorVZERO(Double_t Qa2[2], Double_t Qc2[2], Double_t Qa3[2], Double_t Qc3[2]) const
1009 {
1010     // return the calibrated 2nd and 3rd order q-vectors for vzeroa and vzeroc
1011     // function takes arrays as arguments, which correspond to vzero info in the following way
1012     // 
1013     // Qa2[0] = Qx2 for vzero A         Qa2[1] = Qy2 for vzero A (etc)
1014     
1015     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1016     // placeholders for geometric information
1017     Double_t phi(-999.), weight(-999.); 
1018     // reset placeholders for Q-vector components
1019     Qa2[0] = 0.;    Qc2[0] = 0.;    Qa3[0] = 0.;    Qc3[0] = 0.;
1020     Qa2[1] = 0.;    Qc2[1] = 0.;    Qa3[1] = 0.;    Qc3[1] = 0.;
1021     
1022     for(Int_t i(0); i < 64; i++) {
1023         // loop over all scintillators, construct Q-vectors in the same loop
1024         phi     = TMath::PiOver4()*(0.5+i%8);
1025         weight  = 0.;
1026         // note that disabled rings have already been excluded in ReadVZEROCalibration2010h
1027         if(i<32) {    // v0c side
1028             if(i < 8) weight = InputEvent()->GetVZEROData()->GetMultiplicity(i)*fVZEROCpol[0]/fVZEROgainEqualization->GetBinContent(1+i);
1029             else if (i < 16 ) weight = InputEvent()->GetVZEROData()->GetMultiplicity(i)*fVZEROCpol[1]/fVZEROgainEqualization->GetBinContent(1+i);
1030             else if (i < 24 ) weight = InputEvent()->GetVZEROData()->GetMultiplicity(i)*fVZEROCpol[2]/fVZEROgainEqualization->GetBinContent(1+i);
1031             else if (i < 32 ) weight = InputEvent()->GetVZEROData()->GetMultiplicity(i)*fVZEROCpol[3]/fVZEROgainEqualization->GetBinContent(1+i);
1032             // fill Q-vectors for v0c side
1033             Qc2[0]+=weight*TMath::Cos(2.*phi);
1034             Qc3[0]+=weight*TMath::Cos(3.*phi);
1035             Qc2[1]+=weight*TMath::Sin(2.*phi);
1036             Qc3[1]+=weight*TMath::Sin(3.*phi);
1037         } else {       // v0a side
1038             if( i < 40) weight = InputEvent()->GetVZEROData()->GetMultiplicity(i)*fVZEROApol[0]/fVZEROgainEqualization->GetBinContent(1+i);
1039             else if ( i < 48 ) weight = InputEvent()->GetVZEROData()->GetMultiplicity(i)*fVZEROApol[1]/fVZEROgainEqualization->GetBinContent(1+i);
1040             else if ( i < 56 ) weight = InputEvent()->GetVZEROData()->GetMultiplicity(i)*fVZEROApol[2]/fVZEROgainEqualization->GetBinContent(1+i);
1041             else if ( i < 64 ) weight = InputEvent()->GetVZEROData()->GetMultiplicity(i)*fVZEROApol[3]/fVZEROgainEqualization->GetBinContent(1+i);
1042             // fill Q-vectors for v0a side
1043             Qa2[0]+=weight*TMath::Cos(2.*phi);
1044             Qa3[0]+=weight*TMath::Cos(3.*phi);
1045             Qa2[1]+=weight*TMath::Sin(2.*phi);
1046             Qa3[1]+=weight*TMath::Sin(3.*phi);
1047         }
1048     }
1049     // get the cache index and read the correction terms from the cache
1050     Int_t VZEROcentralityBin(GetVZEROCentralityBin());
1051     Double_t Qx2amean = fMeanQ[VZEROcentralityBin][1][0];
1052     Double_t Qx2arms  = fWidthQ[VZEROcentralityBin][1][0];
1053     Double_t Qy2amean = fMeanQ[VZEROcentralityBin][1][1];
1054     Double_t Qy2arms  = fWidthQ[VZEROcentralityBin][1][1];
1055
1056     Double_t Qx2cmean = fMeanQ[VZEROcentralityBin][0][0];
1057     Double_t Qx2crms  = fWidthQ[VZEROcentralityBin][0][0];
1058     Double_t Qy2cmean = fMeanQ[VZEROcentralityBin][0][1];
1059     Double_t Qy2crms  = fWidthQ[VZEROcentralityBin][0][1];      
1060
1061     Double_t Qx3amean = fMeanQv3[VZEROcentralityBin][1][0];
1062     Double_t Qx3arms  = fWidthQv3[VZEROcentralityBin][1][0];
1063     Double_t Qy3amean = fMeanQv3[VZEROcentralityBin][1][1];
1064     Double_t Qy3arms  = fWidthQv3[VZEROcentralityBin][1][1];
1065
1066     Double_t Qx3cmean = fMeanQv3[VZEROcentralityBin][0][0];
1067     Double_t Qx3crms  = fWidthQv3[VZEROcentralityBin][0][0];
1068     Double_t Qy3cmean = fMeanQv3[VZEROcentralityBin][0][1];
1069     Double_t Qy3crms  = fWidthQv3[VZEROcentralityBin][0][1];    
1070
1071     // update the weighted q-vectors with the re-centered values
1072     Qa2[0] = (Qa2[0] - Qx2amean)/Qx2arms;
1073     Qa2[1] = (Qa2[1] - Qy2amean)/Qy2arms;
1074     Qc2[0] = (Qc2[0] - Qx2cmean)/Qx2crms;
1075     Qc2[1] = (Qc2[1] - Qy2cmean)/Qy2crms;
1076
1077     Qa3[0] = (Qa3[0] - Qx3amean)/Qx3arms;
1078     Qa3[1] = (Qa3[1] - Qy3amean)/Qy3arms;
1079     Qc3[0] = (Qc3[0] - Qx3cmean)/Qx3crms;
1080     Qc3[1] = (Qc3[0] - Qy3cmean)/Qy3crms;
1081 }
1082 //_____________________________________________________________________________
1083 void AliAnalysisTaskJetV2::CalculateQvectorCombinedVZERO(Double_t Q2[2], Double_t Q3[2]) const
1084 {
1085     // calculate calibrated q-vector of the combined vzeroa, vzeroc system
1086     // this is somewhat ugly as CalculateQvectorCombinedVZERO is called more than once per event
1087     // but for now it will have to do ...
1088     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1089
1090     // first step: retrieve the q-vectors component-wise per vzero detector
1091     Double_t QA2[] = {-999., -999.};
1092     Double_t QA3[] = {-999., -999.};
1093     Double_t QC2[] = {-999., -999.};
1094     Double_t QC3[] = {-999., -999.};
1095     CalculateQvectorVZERO(QA2, QA3, QC2, QC3);
1096
1097     // get cache index and retrieve the chi weights for this centrality
1098     Int_t VZEROcentralityBin(GetVZEROCentralityBin());
1099     Double_t chi2A(fChi2A->At(VZEROcentralityBin));
1100     Double_t chi2C(fChi2C->At(VZEROcentralityBin));
1101     Double_t chi3A(fChi3A->At(VZEROcentralityBin));
1102     Double_t chi3C(fChi3C->At(VZEROcentralityBin));
1103
1104     // combine the vzera and vzeroc signal
1105     Q2[0] = chi2A*chi2A*QA2[0]+chi2C*chi2C*QC2[0];
1106     Q2[1] = chi2A*chi2A*QA2[1]+chi2C*chi2C*QC2[1];
1107     Q3[0] = chi3A*chi3A*QA3[0]+chi3C*chi3C*QC3[0];
1108     Q3[1] = chi3A*chi3A*QC3[1]+chi3C*chi3C*QC3[1];
1109 }
1110 //_____________________________________________________________________________
1111 void AliAnalysisTaskJetV2::CalculateRandomCone(Float_t &pt, Float_t &eta, Float_t &phi, 
1112         AliParticleContainer* tracksCont, AliClusterContainer* clusterCont, AliEmcalJet* jet) const
1113 {
1114     // get a random cone
1115     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1116     pt = 0; eta = 0; phi = 0;
1117     Float_t etaJet(999), phiJet(999), dJet(999);        // no jet: same as jet very far away
1118     if(jet) { // if a leading jet is given, use its kinematic properties to exclude it
1119         etaJet = jet->Eta();
1120         phiJet = jet->Phi();
1121     }
1122     // the random cone acceptance has to equal the jet acceptance
1123     // this also insures safety when runnnig on the semi-good tpc runs for 11h data,
1124     // where jet acceptance is adjusted to reduced acceptance - hence random cone acceptance as well
1125     Float_t minPhi(GetJetContainer()->GetJetPhiMin()), maxPhi(GetJetContainer()->GetJetPhiMax());
1126     if(maxPhi > TMath::TwoPi()) maxPhi = TMath::TwoPi();
1127     if(minPhi < 0 ) minPhi = 0.;
1128     // construct a random cone and see if it's far away enough from the leading jet
1129     Int_t attempts(1000);
1130     while(kTRUE) {
1131         attempts--;
1132         eta = gRandom->Uniform(GetJetContainer()->GetJetEtaMin(), GetJetContainer()->GetJetEtaMax());
1133         phi = gRandom->Uniform(minPhi, maxPhi);
1134
1135         dJet = TMath::Sqrt((etaJet-eta)*(etaJet-eta)+(phiJet-phi)*(phiJet-phi));
1136         if(dJet > fMinDisanceRCtoLJ) break;
1137         else if (attempts == 0) {
1138             printf(" > No random cone after 1000 tries, giving up ... !\n");
1139             return;
1140         }
1141     }
1142     // get the charged energy (if tracks are provided)
1143     if(tracksCont) {
1144         AliVParticle* track = tracksCont->GetNextAcceptParticle(0);
1145         while(track) {
1146             Float_t etaTrack(track->Eta()), phiTrack(track->Phi());
1147             // get distance from cone
1148             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi + TMath::TwoPi())) phiTrack+=TMath::TwoPi();
1149             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi - TMath::TwoPi())) phiTrack-=TMath::TwoPi();
1150             if(TMath::Sqrt(TMath::Abs((etaTrack-eta)*(etaTrack-eta)+(phiTrack-phi)*(phiTrack-phi))) <= GetJetRadius()) pt += track->Pt();
1151             track = tracksCont->GetNextAcceptParticle();
1152         }
1153     }
1154     // get the neutral energy (if clusters are provided)
1155     if(clusterCont) {
1156         TLorentzVector momentum;
1157         AliVCluster* cluster = clusterCont->GetNextAcceptCluster(0);
1158         while(cluster) {
1159             cluster->GetMomentum(momentum, const_cast<Double_t*>(fVertex));
1160             Float_t etaClus(momentum.Eta()), phiClus(momentum.Phi());
1161             // get distance from cone
1162             if(TMath::Abs(phiClus-phi) > TMath::Abs(phiClus - phi + TMath::TwoPi())) phiClus+=TMath::TwoPi();
1163             if(TMath::Abs(phiClus-phi) > TMath::Abs(phiClus - phi - TMath::TwoPi())) phiClus-=TMath::TwoPi();
1164             if(TMath::Sqrt(TMath::Abs((etaClus-eta)*(etaClus-eta)+(phiClus-phi)*(phiClus-phi))) <= GetJetRadius()) pt += momentum.Pt();
1165             cluster = clusterCont->GetNextAcceptCluster();
1166         }
1167     }
1168 }
1169 //_____________________________________________________________________________
1170 Double_t AliAnalysisTaskJetV2::CalculateQC2(Int_t harm) {
1171     // get the second order q-cumulant, a -999 return will be caught in the qa routine of CorrectRho
1172     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1173     Double_t reQ(0), imQ(0), modQ(0), M11(0), M(0);
1174     if(fUsePtWeight) {  // for the weighted 2-nd order q-cumulant
1175         QCnQnk(harm, 1, reQ, imQ);      // get the weighted 2-nd order q-vectors
1176         modQ = reQ*reQ+imQ*imQ;         // get abs Q-squared
1177         M11 = QCnM11();                 // equals S2,1 - S1,2
1178         return (M11 > 0) ? ((modQ - QCnS(1,2))/M11) : -999;
1179     } // else return the non-weighted 2-nd order q-cumulant
1180     QCnQnk(harm, 0, reQ, imQ);          // get the non-weighted 2-nd order q-vectors
1181     modQ = reQ*reQ+imQ*imQ;             // get abs Q-squared
1182     M = QCnM();
1183     return (M > 1) ? (modQ - M)/(M*(M-1)) : -999;
1184 }
1185 //_____________________________________________________________________________
1186 Double_t AliAnalysisTaskJetV2::CalculateQC4(Int_t harm) {
1187     // get the fourth order q-cumulant, a -999 return will be caught in the qa routine of CorrectRho
1188     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1189     Double_t reQn1(0), imQn1(0), reQ2n2(0), imQ2n2(0), reQn3(0), imQn3(0), M1111(0), M(0);
1190     Double_t a(0), b(0), c(0), d(0), e(0), f(0), g(0);  // terms of the calculation
1191     if(fUsePtWeight) {  // for the weighted 4-th order q-cumulant
1192         QCnQnk(harm, 1, reQn1, imQn1);
1193         QCnQnk(harm*2, 2, reQ2n2, imQ2n2);
1194         QCnQnk(harm, 3, reQn3, imQn3);
1195         // fill in the terms ...
1196         a = (reQn1*reQn1+imQn1*imQn1)*(reQn1*reQn1+imQn1*imQn1);
1197         b = reQ2n2*reQ2n2 + imQ2n2*imQ2n2;
1198         c = -2.*(reQ2n2*reQn1*reQn1-reQ2n2*imQn1*imQn1+2.*imQ2n2*reQn1*imQn1);
1199         d = 8.*(reQn3*reQn1+imQn3*imQn1);
1200         e = -4.*QCnS(1,2)*(reQn1*reQn1+imQn1*imQn1);
1201         f = -6.*QCnS(1,4);
1202         g = 2.*QCnS(2,2);
1203         M1111 = QCnM1111();
1204         return (M1111 > 0) ? (a+b+c+d+e+f+g)/M1111 : -999;
1205     }   // else return the unweighted case
1206     Double_t reQn(0), imQn(0), reQ2n(0), imQ2n(0);
1207     QCnQnk(harm, 0, reQn, imQn);
1208     QCnQnk(harm*2, 0, reQ2n, imQ2n);
1209     // fill in the terms ...
1210     M = QCnM();
1211     if(M < 4) return -999;
1212     a = (reQn*reQn+imQn*imQn)*(reQn*reQn+imQn*imQn);
1213     b = reQ2n*reQ2n + imQ2n*imQ2n;
1214     c = -2.*(reQ2n*reQn*reQn-reQ2n*imQn*imQn+2.*imQ2n*reQn*imQn);
1215     e = -4.*(M-2)*(reQn*reQn+imQn*imQn);
1216     f = 2.*M*(M-3);
1217     return (a+b+c+e+f)/(M*(M-1)*(M-2)*(M-3));
1218 }
1219 //_____________________________________________________________________________
1220 void AliAnalysisTaskJetV2::QCnQnk(Int_t n, Int_t k, Double_t &reQ, Double_t &imQ) {
1221     // get the weighted n-th order q-vector, pass real and imaginary part as reference
1222     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1223     if(!fTracks) return;
1224     fNAcceptedTracksQCn = 0;
1225     Int_t iTracks(fTracks->GetEntriesFast());
1226     for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
1227         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
1228         if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
1229         fNAcceptedTracksQCn++;
1230         // for the unweighted case, k equals zero and the weight doesn't contribute to the equation below
1231         reQ += TMath::Power(track->Pt(), k) * TMath::Cos(((double)n)*track->Phi());
1232         imQ += TMath::Power(track->Pt(), k) * TMath::Sin(((double)n)*track->Phi());
1233     }
1234 }
1235 //_____________________________________________________________________________
1236 void AliAnalysisTaskJetV2::QCnDiffentialFlowVectors(
1237         TClonesArray* pois, TArrayD* ptBins, Bool_t vpart, Double_t* repn, Double_t* impn, 
1238         Double_t *mp, Double_t *reqn, Double_t *imqn, Double_t* mq, Int_t n) 
1239 {
1240      if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1241    // get  unweighted differential flow vectors
1242     Int_t iPois(pois->GetEntriesFast());
1243     if(vpart) {
1244         for(Int_t i(0); i < iPois; i++) {
1245             for(Int_t ptBin(0); ptBin < ptBins->GetSize()-1; ptBin++) {
1246                 AliVTrack* poi = static_cast<AliVTrack*>(pois->At(i));
1247                 if(PassesCuts(poi)) {
1248                     if(poi->Pt() >= ptBins->At(ptBin) && poi->Pt() < ptBins->At(ptBin+1)) {
1249                             // fill the flow vectors assuming that all poi's are in the rp selection (true by design)
1250                             repn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
1251                             impn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
1252                             mp[ptBin]++;
1253                             reqn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
1254                             imqn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
1255                             mq[ptBin]++;
1256                     }
1257                 }
1258             }
1259         }
1260     } else {
1261         for(Int_t i(0); i < iPois; i++) {
1262             for(Int_t ptBin(0); ptBin < ptBins->GetSize()-1; ptBin++) {
1263                 AliEmcalJet* poi = static_cast<AliEmcalJet*>(pois->At(i));
1264                 if(PassesCuts(poi)) {    
1265                     Double_t pt(poi->Pt()-poi->Area()*fLocalRho->GetLocalVal(poi->Phi(), GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1266                     if(pt >= ptBins->At(ptBin) && pt < ptBins->At(ptBin+1)) {    
1267                             repn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
1268                             impn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
1269                             mp[ptBin]++;        // qn isn't filled, no overlap between poi's and rp's
1270                     }
1271                 }
1272             }
1273         }
1274     }
1275 }
1276 //_____________________________________________________________________________
1277 Double_t AliAnalysisTaskJetV2::QCnS(Int_t i, Int_t j) {
1278     // get the weighted ij-th order autocorrelation correction
1279     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1280     if(!fTracks || i <= 0 || j <= 0) return -999;
1281     Int_t iTracks(fTracks->GetEntriesFast());
1282     Double_t Sij(0);
1283     for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
1284         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
1285         if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
1286         Sij+=TMath::Power(track->Pt(), j);
1287     }
1288     return TMath::Power(Sij, i);
1289 }
1290 //_____________________________________________________________________________
1291 Double_t AliAnalysisTaskJetV2::QCnM() {
1292     // get multiplicity for unweighted q-cumulants. function QCnQnk should be called first
1293     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1294     return (Double_t) fNAcceptedTracksQCn;
1295 }
1296 //_____________________________________________________________________________
1297 Double_t AliAnalysisTaskJetV2::QCnM11() {
1298     // get multiplicity weights for the weighted two particle cumulant
1299     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1300     return (QCnS(2,1) - QCnS(1,2));
1301 }
1302 //_____________________________________________________________________________
1303 Double_t AliAnalysisTaskJetV2::QCnM1111() {
1304     // get multiplicity weights for the weighted four particle cumulant
1305     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1306     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));
1307 }
1308 //_____________________________________________________________________________
1309 Bool_t AliAnalysisTaskJetV2::QCnRecovery(Double_t psi2, Double_t psi3) {
1310     // decides how to deal with the situation where c2 or c3 is negative 
1311     // returns kTRUE depending on whether or not a modulated rho is used for the jet background
1312     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1313     if(TMath::AreEqualAbs(fFitModulation->GetParameter(3), .0, 1e-10) && TMath::AreEqualAbs(fFitModulation->GetParameter(7), .0,1e-10)) {
1314         fFitModulation->SetParameter(7, 0);
1315         fFitModulation->SetParameter(3, 0);
1316         fFitModulation->SetParameter(0, fLocalRho->GetVal());
1317         return kTRUE;   // v2 and v3 have physical null values
1318     }
1319     switch (fQCRecovery) {
1320         case kFixedRho : {      // roll back to the original rho
1321            fFitModulation->SetParameter(7, 0);
1322            fFitModulation->SetParameter(3, 0);
1323            fFitModulation->SetParameter(0, fLocalRho->GetVal());
1324            return kFALSE;       // rho is forced to be fixed
1325         }
1326         case kNegativeVn : {
1327            Double_t c2(fFitModulation->GetParameter(3));
1328            Double_t c3(fFitModulation->GetParameter(7));
1329            if( c2 < 0 ) c2 = -1.*TMath::Sqrt(-1.*c2);
1330            if( c3 < 0 ) c3 = -1.*TMath::Sqrt(-1.*c3);
1331            fFitModulation->SetParameter(3, c2);
1332            fFitModulation->SetParameter(7, c3);
1333            return kTRUE;        // is this a physical quantity ?
1334         }
1335         case kTryFit : {
1336            fitModulationType tempType(fFitModulationType);  // store temporarily
1337            fFitModulationType = kCombined;
1338            fFitModulation->SetParameter(7, 0);
1339            fFitModulation->SetParameter(3, 0);
1340            Bool_t pass(CorrectRho(psi2, psi3));         // do the fit and all quality checks
1341            fFitModulationType = tempType;               // roll back for next event
1342            return pass;
1343         }
1344         default : return kFALSE;
1345     }
1346     return kFALSE;
1347 }
1348 //_____________________________________________________________________________
1349 Bool_t AliAnalysisTaskJetV2::CorrectRho(Double_t psi2, Double_t psi3) 
1350 {
1351     // get rho' -> rho(phi)
1352     // two routines are available, both can be used with or without pt weights
1353     //  [1] get vn from q-cumulants or as an integrated value from a user supplied histogram
1354     //      in case of cumulants, both cumulants and vn values are stored. in both cases, v2 and v3
1355     //      are expected. a check is performed to see if rho has no negative local minimum
1356     //      for full description, see Phys. Rev. C 83, 044913
1357     //      since the cn distribution has negative values, vn = sqrt(cn) can be imaginary sometimes
1358     //      in this case one can either roll back to the 'original' rixed rho, do a fit for vn or take use
1359     //      vn = - sqrt(|cn|) 
1360     //  [2] fitting a fourier expansion to the de/dphi distribution
1361     //      the fit can be done with either v2, v3 or a combination.
1362     //      in all cases, a cut can be made on the p-value of the chi-squared value of the fit
1363     //      and a check can be performed to see if rho has no negative local minimum
1364     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1365     Int_t freeParams(2);                // free parameters of the fit (for NDF) 
1366     switch (fFitModulationType) {       // for approaches where no fitting is required
1367         case kQC2 : {
1368             fFitModulation->FixParameter(4, psi2); 
1369             fFitModulation->FixParameter(6, psi3);
1370             fFitModulation->FixParameter(3, CalculateQC2(2));   // set here with cn, vn = sqrt(cn)
1371             fFitModulation->FixParameter(7, CalculateQC2(3));
1372             // first fill the histos of the raw cumulant distribution
1373             if (fUsePtWeight) { // use weighted weights
1374                 Double_t dQCnM11 = (fNoEventWeightsForQC) ? 1. : QCnM11();
1375                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3), dQCnM11);
1376                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7), dQCnM11);
1377             } else {
1378                 Double_t dQCnM = (fNoEventWeightsForQC) ? 2. : QCnM();
1379                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3), dQCnM*(dQCnM-1));
1380                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7), dQCnM*(dQCnM-1));
1381             }
1382             // then see if one of the cn value is larger than zero and vn is readily available
1383             if(fFitModulation->GetParameter(3) > 0 && fFitModulation->GetParameter(7) > 0) {
1384                 fFitModulation->FixParameter(3, TMath::Sqrt(fFitModulation->GetParameter(3)));
1385                 fFitModulation->FixParameter(7, TMath::Sqrt(fFitModulation->GetParameter(7)));
1386             } else if (!QCnRecovery(psi2, psi3)) return kFALSE;  // try to recover the cumulant, this will set v2 and v3
1387             if(fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) {  // general check 
1388                 fFitModulation->SetParameter(7, 0);
1389                 fFitModulation->SetParameter(3, 0);
1390                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1391                 return kFALSE;
1392             }
1393             return kTRUE;
1394         } break;
1395         case kQC4 : {
1396             fFitModulation->FixParameter(4, psi2); 
1397             fFitModulation->FixParameter(6, psi3);
1398             fFitModulation->FixParameter(3, CalculateQC4(2));   // set here with cn, vn = sqrt(cn)
1399             fFitModulation->FixParameter(7, CalculateQC4(3));
1400             // first fill the histos of the raw cumulant distribution
1401             if (fUsePtWeight) { // use weighted weights
1402                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3)/*, QCnM1111()*/);
1403                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7)/*, QCnM1111()*/);
1404             } else {
1405                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3)/*, QCnM1111()*/);
1406                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7)/*, QCnM1111()*/);
1407             }
1408             // then see if one of the cn value is larger than zero and vn is readily available
1409             if(fFitModulation->GetParameter(3) > 0 && fFitModulation->GetParameter(7) > 0) {
1410                 fFitModulation->FixParameter(3, TMath::Sqrt(fFitModulation->GetParameter(3)));
1411                 fFitModulation->FixParameter(7, TMath::Sqrt(fFitModulation->GetParameter(7)));
1412             } else if (!QCnRecovery(psi2, psi3)) return kFALSE;  // try to recover the cumulant, this will set v2 and v3
1413             if(fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) {  // general check 
1414                 fFitModulation->SetParameter(7, 0);
1415                 fFitModulation->SetParameter(3, 0);
1416                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1417                 return kFALSE;
1418             }
1419         } break;
1420         case kIntegratedFlow : {
1421             // use v2 and v3 values from an earlier iteration over the data
1422             fFitModulation->FixParameter(3, fUserSuppliedV2->GetBinContent(fUserSuppliedV2->GetXaxis()->FindBin(fCent)));
1423             fFitModulation->FixParameter(4, psi2);
1424             fFitModulation->FixParameter(6, psi3);
1425             fFitModulation->FixParameter(7, fUserSuppliedV3->GetBinContent(fUserSuppliedV3->GetXaxis()->FindBin(fCent)));
1426             if(fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) { 
1427                 fFitModulation->SetParameter(7, 0);
1428                 fFitModulation->SetParameter(3, 0);
1429                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1430                 return kFALSE;
1431             }
1432             return kTRUE;
1433         }
1434         default : break;
1435     }
1436     TString detector("");
1437     switch (fDetectorType) {
1438         case kTPC : detector+="TPC";
1439             break;
1440         case kVZEROA : detector+="VZEROA";
1441             break;
1442         case kVZEROC : detector+="VZEROC";
1443             break;
1444         case kVZEROComb : detector+="VZEROComb";
1445             break; 
1446         case kFixedEP : detector+="FixedEP";
1447             break;
1448         default: break;
1449     }
1450     Int_t iTracks(fTracks->GetEntriesFast());
1451     Double_t excludeInEta = -999;
1452     Double_t excludeInPhi = -999;
1453     Double_t excludeInPt  = -999;
1454     if(iTracks <= 0 || fLocalRho->GetVal() <= 0 ) return kFALSE;   // no use fitting an empty event ...
1455     if(fExcludeLeadingJetsFromFit > 0 ) {
1456         if(fLeadingJet) {
1457             excludeInEta = fLeadingJet->Eta();
1458             excludeInPhi = fLeadingJet->Phi();
1459             excludeInPt = fLeadingJet->Pt();
1460         }
1461     }
1462     // check the acceptance of the track selection that will be used
1463     // if one uses e.g. semi-good tpc tracks, accepance in phi is reduced to 0 < phi < 4
1464     // the defaults (-10 < phi < 10) which accept all, are then overwritten
1465     Double_t lowBound(0.), upBound(TMath::TwoPi());     // bounds for fit
1466     if(GetParticleContainer()->GetParticlePhiMin() > lowBound) lowBound = GetParticleContainer()->GetParticlePhiMin();
1467     if(GetParticleContainer()->GetParticlePhiMax() < upBound) upBound = GetParticleContainer()->GetParticlePhiMax();
1468     fHistSwap->Reset(); // clear the histogram
1469     TH1F _tempSwap;     // on stack for quick access
1470     TH1F _tempSwapN;    // on stack for quick access, bookkeeping histogram
1471     if(fRebinSwapHistoOnTheFly) {
1472         if(fNAcceptedTracks < 49) fNAcceptedTracks = 49;       // avoid aliasing effects
1473         _tempSwap = TH1F("_tempSwap", "_tempSwap", TMath::CeilNint(TMath::Sqrt(fNAcceptedTracks)), lowBound, upBound);
1474         if(fUsePtWeightErrorPropagation) _tempSwapN = TH1F("_tempSwapN", "_tempSwapN", TMath::CeilNint(TMath::Sqrt(fNAcceptedTracks)), lowBound, upBound);
1475         if(fUsePtWeight) _tempSwap.Sumw2();
1476     }
1477     else _tempSwap = *fHistSwap;         // now _tempSwap holds the desired histo
1478     // non poissonian error when using pt weights
1479     Double_t totalpts(0.), totalptsquares(0.), totalns(0.);
1480     for(Int_t i(0); i < iTracks; i++) {
1481         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1482         if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta) < GetJetContainer()->GetJetRadius()*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - GetJetContainer()->GetJetRadius() - GetJetContainer()->GetJetEtaMax() ) > 0 )) continue;
1483         if(!PassesCuts(track) || track->Pt() > fSoftTrackMaxPt || track->Pt() < fSoftTrackMinPt) continue;
1484         if(fUsePtWeight) {
1485             _tempSwap.Fill(track->Phi(), track->Pt());
1486             if(fUsePtWeightErrorPropagation) {
1487                 totalpts += track->Pt();
1488                 totalptsquares += track->Pt()*track->Pt();
1489                 totalns += 1;
1490                 _tempSwapN.Fill(track->Phi());
1491             }
1492         }
1493         else _tempSwap.Fill(track->Phi());
1494     }
1495     if(fUsePtWeight && fUsePtWeightErrorPropagation) {
1496         // in the case of pt weights overwrite the poissonian error estimate which is assigned by root by a more sophisticated appraoch
1497         // 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
1498         // 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 
1499         // event, for the latter use a poissonian estimate. the two contrubitions are assumed to be uncorrelated
1500         if(totalns < 2) return kFALSE; // not one track passes the cuts > 2 avoids possible division by 0 later on
1501         for(Int_t l = 0; l < _tempSwap.GetNbinsX(); l++) {
1502             if(_tempSwapN.GetBinContent(l+1) == 0) {
1503                 _tempSwap.SetBinContent(l+1,0);
1504                 _tempSwap.SetBinError(l+1,0);
1505             }
1506             else {
1507                 Double_t vartimesnsq = totalptsquares*totalns - totalpts*totalpts;
1508                 Double_t variance = vartimesnsq/(totalns*(totalns-1.));
1509                 Double_t SDOMSq = variance / _tempSwapN.GetBinContent(l+1);
1510                 Double_t SDOMSqOverMeanSq = SDOMSq * _tempSwapN.GetBinContent(l+1) * _tempSwapN.GetBinContent(l+1) / (_tempSwapN.GetBinContent(l+1) * _tempSwapN.GetBinContent(l+1));
1511                 Double_t poissonfrac = 1./_tempSwapN.GetBinContent(l+1);
1512                 Double_t vartotalfrac = SDOMSqOverMeanSq + poissonfrac;
1513                 Double_t vartotal = vartotalfrac * _tempSwap.GetBinContent(l+1) * _tempSwap.GetBinContent(l+1);
1514                 if(vartotal > 0.0001) _tempSwap.SetBinError(l+1,TMath::Sqrt(vartotal));
1515                 else {
1516                     _tempSwap.SetBinContent(l+1,0);
1517                     _tempSwap.SetBinError(l+1,0);
1518                 }
1519             }
1520         }
1521     }
1522     fFitModulation->SetParameter(0, fLocalRho->GetVal());
1523     switch (fFitModulationType) {
1524         case kNoFit : { 
1525             fFitModulation->FixParameter(0, fLocalRho->GetVal() ); 
1526             freeParams = 0;
1527         } break;
1528         case kV2 : { 
1529             fFitModulation->FixParameter(4, psi2); 
1530             freeParams = 1;
1531         } break;
1532         case kV3 : { 
1533             fFitModulation->FixParameter(4, psi3); 
1534             freeParams = 1;
1535         } break;
1536         case kCombined : {
1537             fFitModulation->FixParameter(4, psi2); 
1538             fFitModulation->FixParameter(6, psi3);
1539             freeParams = 2;
1540         } break;
1541         case kFourierSeries : {
1542             // in this approach, an explicit calculation will be made of vn = sqrt(xn^2+yn^2)
1543             // where x[y] = Integrate[r(phi)cos[sin](n phi)dphi, 0, 2pi]
1544             Double_t cos2(0), sin2(0), cos3(0), sin3(0), sumPt(0);
1545             for(Int_t i(0); i < iTracks; i++) {
1546                 AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1547                 if(!PassesCuts(track) || track->Pt() > fSoftTrackMaxPt || track->Pt() < fSoftTrackMinPt) continue;
1548                 sumPt += track->Pt();
1549                 cos2 += track->Pt()*TMath::Cos(2*PhaseShift(track->Phi()-psi2)); 
1550                 sin2 += track->Pt()*TMath::Sin(2*PhaseShift(track->Phi()-psi2));
1551                 cos3 += track->Pt()*TMath::Cos(3*PhaseShift(track->Phi()-psi3)); 
1552                 sin3 += track->Pt()*TMath::Sin(3*PhaseShift(track->Phi()-psi3));
1553             }
1554             fFitModulation->SetParameter(3, TMath::Sqrt(cos2*cos2+sin2*sin2)/fLocalRho->GetVal());
1555             fFitModulation->SetParameter(4, psi2);
1556             fFitModulation->SetParameter(6, psi3);
1557             fFitModulation->SetParameter(7, TMath::Sqrt(cos3*cos3+sin3*sin3)/fLocalRho->GetVal());
1558         } break;
1559         default : break;
1560     }
1561     if(fRunToyMC) {
1562         // toy mc, just here to check procedure, azimuthal profile is filled from hypothesis so p-value distribution should be flat
1563         Int_t _bins = _tempSwap.GetXaxis()->GetNbins();
1564         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());
1565         _tempFit->SetParameter(0, fFitModulation->GetParameter(0));       // normalization
1566         _tempFit->SetParameter(3, 0.1);      // v2
1567         _tempFit->FixParameter(1, 1.);       // constant
1568         _tempFit->FixParameter(2, 2.);       // constant
1569         _tempFit->FixParameter(5, 3.);       // constant
1570         _tempFit->FixParameter(4, fFitModulation->GetParameter(4));
1571         _tempFit->FixParameter(6, fFitModulation->GetParameter(6));
1572         _tempFit->SetParameter(7, 0.1);      // v3
1573         _tempSwap.Reset();                   // rese bin content
1574         for(int _binsI = 0; _binsI < _bins*_bins; _binsI++)  _tempSwap.Fill(_tempFit->GetRandom());
1575     }
1576     _tempSwap.Fit(fFitModulation, fFitModulationOptions.Data(), "", lowBound, upBound);
1577     // the quality of the fit is evaluated from 1 - the cdf of the chi square distribution
1578     // three methods are available, all with their drawbacks. all are stored, one is selected to do the cut
1579     Int_t NDF(_tempSwap.GetXaxis()->GetNbins()-freeParams);
1580     if(NDF == 0 || (float)NDF <= 0.) return kFALSE;
1581     Double_t CDF(1.-ChiSquareCDF(NDF, ChiSquare(_tempSwap, fFitModulation)));
1582     Double_t CDFROOT(1.-ChiSquareCDF(NDF, fFitModulation->GetChisquare()));
1583     Double_t CDFKolmogorov(KolmogorovTest(_tempSwap, fFitModulation));
1584     // fill the values and centrality correlation (redundant but easy on the eyes)
1585     fHistPvalueCDF->Fill(CDF);
1586     fHistPvalueCDFCent->Fill(fCent, CDF);
1587     fHistPvalueCDFROOT->Fill(CDFROOT);
1588     fHistPvalueCDFROOTCent->Fill(fCent, CDFROOT);
1589     fHistKolmogorovTest->Fill(CDFKolmogorov);
1590     fHistChi2ROOTCent->Fill(fCent, fFitModulation->GetChisquare()/((float)NDF));
1591     fHistChi2Cent->Fill(fCent, ChiSquare(_tempSwap, fFitModulation)/((float)NDF));
1592     fHistKolmogorovTestCent->Fill(fCent, CDFKolmogorov);
1593     fHistPChi2Root->Fill(CDFROOT, fFitModulation->GetChisquare()/((float)NDF));
1594     fHistPChi2->Fill(CDF, ChiSquare(_tempSwap, fFitModulation)/((float)NDF));
1595     fHistPKolmogorov->Fill(CDF, CDFKolmogorov);
1596
1597     // variable CDF is used for making cuts, so we fill it with the selected p-value
1598     switch (fFitGoodnessTest) {
1599         case kChi2ROOT : {
1600             CDF = CDFROOT; 
1601         } break;
1602         case kChi2Poisson : break;      // CDF is already CDF
1603         case kKolmogorov : {
1604             CDF = CDFKolmogorov; 
1605         } break;
1606         default: break;
1607     }
1608
1609     if(fFitControl) {
1610         // as an additional quality check, see if fitting a control fit has a higher significance
1611         _tempSwap.Fit(fFitControl, fFitModulationOptions.Data(), "", lowBound, upBound);
1612         Double_t CDFControl(-1.);
1613         switch (fFitGoodnessTest) {
1614             case kChi2ROOT : {
1615                 CDFControl = 1.-ChiSquareCDF(fFitControl->GetNDF(), fFitModulation->GetChisquare());
1616             } break;
1617             case kChi2Poisson : {
1618                 CDFControl = 1.-ChiSquareCDF(fFitControl->GetNDF(), ChiSquare(_tempSwap, fFitModulation));
1619             } break;
1620             case kKolmogorov : {
1621                 CDFControl = KolmogorovTest(_tempSwap, fFitControl); 
1622             } break;
1623             default: break;
1624         }
1625         if(CDFControl > CDF) {
1626             CDF = -1.; // control fit is more significant, so throw out the 'old' fit
1627             fHistRhoStatusCent->Fill(fCent, -1);
1628         }
1629     }
1630     if(CDF >= fMinPvalue && CDF <= fMaxPvalue && ( fFitModulation->GetMinimum(0, TMath::TwoPi()) > 0)) {       
1631         // fit quality. not that although with limited acceptance the fit is performed on just
1632         // part of phase space, the requirement that energy desntiy is larger than zero is applied
1633         // to the FULL spectrum
1634         fHistRhoStatusCent->Fill(fCent, 0.);
1635         // for LOCAL didactic purposes, save the  best and the worst fits
1636         // this routine can produce a lot of output histograms (it's not memory 'safe') and will not work on GRID 
1637         // since the output will become unmergeable (i.e. different nodes may produce conflicting output)
1638         switch (fRunModeType) {
1639             case kLocal : {
1640                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
1641                 static Int_t didacticCounterBest(0);
1642                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
1643                 TF1* didacticFit = (TF1*)fFitModulation->Clone(Form("fit_%i_CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
1644                 switch(fFitModulationType) { 
1645                     case kCombined : {
1646                         // to make a nice picture also plot the separate components (v2 and v3) of the fit
1647                         // only done for cobined fit where there are actually components to split ...
1648                         TF1* v0(new TF1("dfit_kV2", "[0]", 0, TMath::TwoPi()));
1649                         v0->SetParameter(0, didacticFit->GetParameter(0));        // normalization
1650                         v0->SetLineColor(kMagenta);
1651                         v0->SetLineStyle(7);
1652                         didacticProfile->GetListOfFunctions()->Add(v0);
1653                         TF1* v2(new TF1("dfit_kV2", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
1654                         v2->SetParameter(0, didacticFit->GetParameter(0));        // normalization
1655                         v2->SetParameter(3, didacticFit->GetParameter(3));        // v2
1656                         v2->FixParameter(1, 1.);        // constant
1657                         v2->FixParameter(2, 2.);        // constant
1658                         v2->FixParameter(4, didacticFit->GetParameter(4));        // psi2
1659                         v2->SetLineColor(kGreen);
1660                         didacticProfile->GetListOfFunctions()->Add(v2);
1661                         TF1* v3(new TF1("dfit_kV3", "[0]*([1]+[2]*[3]*TMath::Cos([5]*(x-[4])))", 0, TMath::TwoPi()));
1662                         v3->SetParameter(0, didacticFit->GetParameter(0));        // normalization
1663                         v3->SetParameter(3, didacticFit->GetParameter(7));        // v3
1664                         v3->FixParameter(1, 1.);        // constant
1665                         v3->FixParameter(2, 2.);        // constant
1666                         v3->FixParameter(4, didacticFit->GetParameter(6));        // psi3
1667                         v3->FixParameter(5, 3.);        // constant
1668                         v3->SetLineColor(kCyan);
1669                         didacticProfile->GetListOfFunctions()->Add(v3);
1670                     }
1671                     default : break;
1672                 }
1673                 didacticProfile->GetListOfFunctions()->Add(didacticFit);
1674                 didacticProfile->GetYaxis()->SetTitle("#frac{d #sum #it{p}_{T}}{d #varphi} [GeV/#it{c}]");
1675                 didacticProfile->GetXaxis()->SetTitle("#varphi");
1676                 fOutputListGood->Add(didacticProfile);
1677                 didacticCounterBest++;
1678                 TH2F* didacticSurface = BookTH2F(Form("surface_%s", didacticProfile->GetName()), "#phi", "#eta", 50, 0, TMath::TwoPi(), 50, -1, 1, -1, kFALSE);
1679                 for(Int_t i(0); i < iTracks; i++) {
1680                     AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1681                     if(PassesCuts(track)) {
1682                         if(fUsePtWeight) didacticSurface->Fill(track->Phi(), track->Eta(), track->Pt());
1683                         else didacticSurface->Fill(track->Phi(), track->Eta());
1684                     }
1685                 }
1686                 if(fExcludeLeadingJetsFromFit) {       // visualize the excluded region
1687                     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);
1688                     f2->SetParameters(excludeInPt/3.,excludeInPhi,.1,excludeInEta,.1);
1689                     didacticSurface->GetListOfFunctions()->Add(f2);
1690                 }
1691                 fOutputListGood->Add(didacticSurface);
1692             } break;
1693             default : break;
1694         }
1695     } else {    // if the fit is of poor quality revert to the original rho estimate
1696         switch (fRunModeType) { // again see if we want to save the fit
1697             case kLocal : {
1698                 static Int_t didacticCounterWorst(0);
1699                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
1700                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data() ));
1701                 TF1* didacticFit = (TF1*)fFitModulation->Clone(Form("fit_%i_p_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data()));
1702                 didacticProfile->GetListOfFunctions()->Add(didacticFit);
1703                 fOutputListBad->Add(didacticProfile);
1704                 didacticCounterWorst++;
1705                 } break;
1706             default : break;
1707         }
1708         switch (fFitModulationType) {
1709             case kNoFit : break;        // nothing to do
1710             case kCombined : fFitModulation->SetParameter(7, 0);        // no break
1711             case kFourierSeries : fFitModulation->SetParameter(7, 0);   // no break
1712             default : { // needs to be done if there was a poor fit
1713                  fFitModulation->SetParameter(3, 0);
1714                  fFitModulation->SetParameter(0, fLocalRho->GetVal());
1715             } break;
1716         }
1717         if(CDF > -.5) fHistRhoStatusCent->Fill(fCent, 1.);
1718         return kFALSE;  // return false if the fit is rejected
1719     }
1720     return kTRUE;
1721 }
1722 //_____________________________________________________________________________
1723 Bool_t AliAnalysisTaskJetV2::PassesCuts(AliVEvent* event)
1724 {
1725     // event cuts
1726     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1727     switch (fCollisionType) {
1728         case kJetFlowMC : {
1729             fInCentralitySelection = 0;
1730             return kTRUE;
1731     } break;
1732         default : break;
1733     }
1734     if(!event || !AliAnalysisTaskEmcal::IsEventSelected()) return kFALSE;
1735     if(TMath::Abs(InputEvent()->GetPrimaryVertex()->GetZ()) > 10.) return kFALSE;
1736     // aod and esd specific checks
1737     switch (fDataType) {
1738        case kESD: {
1739             AliESDEvent* esdEvent = static_cast<AliESDEvent*>(InputEvent());
1740             if( (!esdEvent) || (TMath::Abs(esdEvent->GetPrimaryVertexSPD()->GetZ() - esdEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
1741        } break;
1742        case kAOD: {
1743             AliAODEvent* aodEvent = static_cast<AliAODEvent*>(InputEvent());
1744             if( (!aodEvent) || (TMath::Abs(aodEvent->GetPrimaryVertexSPD()->GetZ() - aodEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
1745        } break;
1746        default: break;
1747     }
1748     fCent = InputEvent()->GetCentrality()->GetCentralityPercentile("V0M");
1749     if(fCent <= fCentralityClasses->At(0) || fCent >= fCentralityClasses->At(fCentralityClasses->GetSize()-1) || TMath::Abs(fCent-InputEvent()->GetCentrality()->GetCentralityPercentile("TRK")) > 5.) return kFALSE;
1750     // determine centrality class
1751     fInCentralitySelection = -1;
1752     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) {
1753         if(fCent >= fCentralityClasses->At(i) && fCent <= fCentralityClasses->At(1+i)) {
1754             fInCentralitySelection = i;
1755             break;
1756         }
1757     } 
1758     if(fInCentralitySelection<0) return kFALSE;     // should be null op
1759     // see if input containers are filled
1760     if(fTracks->GetEntries() < 1) return kFALSE;
1761     if(fRho->GetVal() <= 0 ) return kFALSE;
1762     if(fAnalysisType == AliAnalysisTaskJetV2::kFull && !fClusterCont) return kFALSE;
1763     return kTRUE;
1764 }
1765 //_____________________________________________________________________________
1766 void AliAnalysisTaskJetV2::FillHistogramsAfterSubtraction(Double_t psi2, Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc)
1767 {
1768     // fill histograms 
1769     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1770     if(fEventPlaneWeights) {
1771         FillWeightedTrackHistograms();
1772         if(fAnalysisType == AliAnalysisTaskJetV2::kFull) FillWeightedClusterHistograms();
1773         FillWeightedJetHistograms(psi2); 
1774         if(fFillQAHistograms) FillWeightedEventPlaneHistograms(vzero, vzeroComb, tpc);
1775         FillWeightedRhoHistograms();
1776         FillWeightedDeltaPtHistograms(psi2);
1777     } else {
1778         FillTrackHistograms();
1779         if(fAnalysisType == AliAnalysisTaskJetV2::kFull) FillClusterHistograms();
1780         FillJetHistograms(psi2); 
1781         if(fFillQAHistograms) FillEventPlaneHistograms(vzero, vzeroComb, tpc);
1782         FillRhoHistograms();
1783         FillDeltaPtHistograms(psi2);
1784     }
1785 }
1786 //_____________________________________________________________________________
1787 void AliAnalysisTaskJetV2::FillTrackHistograms() const
1788 {
1789     // fill track histograms
1790     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1791     Int_t iTracks(fTracks->GetEntriesFast()), iAcceptedTracks(0);
1792     for(Int_t i(0); i < iTracks; i++) {
1793         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1794         if(!PassesCuts(track)) continue;
1795         iAcceptedTracks++;
1796         fHistPicoTrackPt[fInCentralitySelection]->Fill(track->Pt());
1797         if(fFillQAHistograms) FillQAHistograms(track);
1798     }
1799     fHistPicoTrackMult[fInCentralitySelection]->Fill(iAcceptedTracks);
1800 }
1801 //_____________________________________________________________________________
1802 void AliAnalysisTaskJetV2::FillClusterHistograms() const
1803 {
1804     // fill cluster histograms
1805     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1806     if(!fClusterCont) return;
1807     Int_t iClusters(fClusterCont->GetNClusters());
1808     TLorentzVector clusterLorentzVector;
1809     for(Int_t i(0); i < iClusters; i++) {
1810         AliVCluster* cluster = fClusterCont->GetCluster(i);
1811         if (!PassesCuts(cluster)) continue;
1812         cluster->GetMomentum(clusterLorentzVector, const_cast<Double_t*>(fVertex));
1813         fHistClusterPt[fInCentralitySelection]->Fill(clusterLorentzVector.Pt());
1814         fHistClusterEtaPhi[fInCentralitySelection]->Fill(clusterLorentzVector.Eta(), clusterLorentzVector.Phi());
1815         fHistClusterEtaPhiWeighted[fInCentralitySelection]->Fill(clusterLorentzVector.Eta(), clusterLorentzVector.Phi(), clusterLorentzVector.Pt());
1816     }
1817     return;
1818 }
1819 //_____________________________________________________________________________
1820 void AliAnalysisTaskJetV2::FillEventPlaneHistograms(Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc) const
1821 {
1822     // fill event plane histograms, only called in qa mode
1823     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1824     fHistPsiControl->Fill(0.5, vzero[0][0]);    // vzero a psi2
1825     fHistPsiControl->Fill(1.5, vzero[1][0]);    // vzero c psi2
1826     fHistPsiControl->Fill(2.5, tpc[0]);         // tpc psi 2
1827     fHistPsiControl->Fill(5.5, vzero[0][1]);    // vzero a psi3
1828     fHistPsiControl->Fill(6.5, vzero[1][1]);    // vzero b psi3
1829     fHistPsiControl->Fill(7.5, tpc[1]);         // tpc psi 3
1830     fHistPsiVZEROA->Fill(vzero[0][0]);
1831     fHistPsiVZEROC->Fill(vzero[1][0]);
1832     fHistPsiVZERO->Fill(vzeroComb[0]);
1833     fHistPsiTPC->Fill(tpc[0]);
1834     fHistPsiSpread->Fill(0.5, TMath::Abs(vzero[0][0]-vzero[1][0]));
1835     fHistPsiSpread->Fill(1.5, TMath::Abs(vzero[0][0]-tpc[0]));
1836     fHistPsiSpread->Fill(2.5, TMath::Abs(vzero[1][0]-tpc[0]));
1837     // event plane vs centrality QA histo's to check recentering
1838     Double_t TRK(InputEvent()->GetCentrality()->GetCentralityPercentile("TRK"));
1839     Double_t V0M(InputEvent()->GetCentrality()->GetCentralityPercentile("V0M"));
1840     fHistPsiVZEROAV0M->Fill(V0M, vzero[0][0]);
1841     fHistPsiVZEROCV0M->Fill(V0M, vzero[1][0]);
1842     fHistPsiVZEROVV0M->Fill(V0M, vzeroComb[0]);
1843     fHistPsiTPCV0M->Fill(V0M, tpc[0]);
1844     fHistPsiVZEROATRK->Fill(TRK, vzero[0][0]);
1845     fHistPsiVZEROCTRK->Fill(TRK, vzero[1][0]);
1846     fHistPsiVZEROTRK->Fill(TRK, vzeroComb[0]);
1847     fHistPsiTPCTRK->Fill(TRK, tpc[0]);
1848     // leading jet vs event plane bias
1849     if(fLeadingJet) {
1850         Double_t rho(fLocalRho->GetLocalVal(fLeadingJet->Phi(), GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1851         Double_t pt(fLeadingJet->Pt() - fLeadingJet->Area()*rho);
1852         fHistPsiTPCLeadingJet[fInCentralitySelection]->Fill(pt, tpc[0], fLeadingJet->Phi());
1853         fHistPsiVZEROALeadingJet[fInCentralitySelection]->Fill(pt, vzero[0][0], fLeadingJet->Phi());
1854         fHistPsiVZEROCLeadingJet[fInCentralitySelection]->Fill(pt, vzero[1][0], fLeadingJet->Phi());
1855         fHistPsiVZEROCombLeadingJet[fInCentralitySelection]->Fill(pt, vzeroComb[0], fLeadingJet->Phi());
1856     }
1857     // correlation of event planes
1858     fHistPsi2Correlation[fInCentralitySelection]->Fill(tpc[0], vzero[0][0], vzero[1][0]);
1859 }
1860 //_____________________________________________________________________________
1861 void AliAnalysisTaskJetV2::FillRhoHistograms()
1862 {
1863     // fill rho histograms
1864     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1865     fHistRhoPackage[fInCentralitySelection]->Fill(fLocalRho->GetVal());    // save the rho estimate from the emcal jet package
1866     // get multiplicity FIXME inefficient
1867     Int_t iJets(fJets->GetEntriesFast());
1868     Double_t rho(fLocalRho->GetLocalVal(TMath::Pi(), TMath::Pi(), fLocalRho->GetVal()));
1869     fHistRho[fInCentralitySelection]->Fill(rho);
1870     fHistRhoVsMult->Fill(fTracks->GetEntries(), rho);
1871     fHistRhoVsCent->Fill(fCent, rho);
1872     for(Int_t i(0); i < iJets; i++) {
1873         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1874         if(!PassesCuts(jet)) continue;
1875         fHistRhoAVsMult->Fill(fTracks->GetEntries(), rho * jet->Area());
1876         fHistRhoAVsCent->Fill(fCent, rho * jet->Area());
1877     }
1878 }
1879 //_____________________________________________________________________________
1880 void AliAnalysisTaskJetV2::FillDeltaPtHistograms(Double_t psi2) const
1881 {
1882     // fill delta pt histograms
1883     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1884     Int_t i(0);
1885     const Float_t areaRC = GetJetRadius()*GetJetRadius()*TMath::Pi();
1886     // we're retrieved the leading jet, now get a random cone
1887     for(i = 0; i < fMaxCones; i++) {
1888        Float_t pt(0), eta(0), phi(0);
1889        // get a random cone without constraints on leading jet position
1890        CalculateRandomCone(pt, eta, phi, fTracksCont, fClusterCont, 0x0);
1891        if(pt > 0) {
1892            if(fFillQAHistograms) fHistRCPhiEta[fInCentralitySelection]->Fill(phi, eta);
1893            fHistRhoVsRCPt[fInCentralitySelection]->Fill(pt, fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal())*areaRC);
1894            fHistRCPt[fInCentralitySelection]->Fill(pt);
1895            fHistDeltaPtDeltaPhi2[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1896            fHistDeltaPtDeltaPhi2Rho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetVal());
1897
1898        }
1899        // get a random cone excluding leading jet area
1900        CalculateRandomCone(pt, eta, phi, fTracksCont, fClusterCont, fLeadingJet);
1901        if(pt > 0) {
1902            if(fFillQAHistograms) fHistRCPhiEtaExLJ[fInCentralitySelection]->Fill(phi, eta);
1903            fHistRhoVsRCPtExLJ[fInCentralitySelection]->Fill(pt, fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal())*areaRC);
1904            fHistRCPtExLJ[fInCentralitySelection]->Fill(pt);
1905            fHistDeltaPtDeltaPhi2ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1906            fHistDeltaPtDeltaPhi2ExLJRho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetVal());
1907        }
1908     } 
1909 }
1910 //_____________________________________________________________________________
1911 void AliAnalysisTaskJetV2::FillJetHistograms(Double_t psi2)
1912 {
1913     // fill jet histograms
1914     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1915     Int_t iJets(fJets->GetEntriesFast());
1916     for(Int_t i(0); i < iJets; i++) {
1917         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1918         if(PassesCuts(jet)) {
1919             Double_t pt(jet->Pt()), area(jet->Area()), eta(jet->Eta()), phi(jet->Phi());
1920             Double_t rho(fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1921             fHistJetPtRaw[fInCentralitySelection]->Fill(pt);
1922             fHistJetPt[fInCentralitySelection]->Fill(pt-area*rho);
1923             if(fFillQAHistograms) fHistJetEtaPhi[fInCentralitySelection]->Fill(eta, phi);
1924             fHistJetPtArea[fInCentralitySelection]->Fill(pt-area*rho, area);
1925             fHistJetPtEta[fInCentralitySelection]->Fill(pt-area*rho, eta);
1926             fHistJetPsi2Pt[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt-area*rho);
1927             fHistJetPsi2PtRho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt-area*fLocalRho->GetVal());
1928             fHistJetPtConstituents[fInCentralitySelection]->Fill(pt-area*rho, jet->GetNumberOfConstituents());
1929             fHistJetEtaRho[fInCentralitySelection]->Fill(eta, pt/area);
1930         } 
1931     }
1932 }
1933 //_____________________________________________________________________________
1934 void AliAnalysisTaskJetV2::FillQAHistograms(AliVTrack* vtrack) const
1935 {
1936     // fill qa histograms for pico tracks
1937     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1938     if(!vtrack) return;
1939     AliPicoTrack* track = static_cast<AliPicoTrack*>(vtrack);
1940     fHistRunnumbersPhi->Fill(fMappedRunNumber, track->Phi());
1941     fHistRunnumbersEta->Fill(fMappedRunNumber, track->Eta());
1942     Int_t type((int)(track->GetTrackType()));
1943     switch (type) {
1944         case 0:
1945            fHistPicoCat1[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1946            break;
1947         case 1:
1948            fHistPicoCat2[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1949            break;
1950         case 2:
1951            fHistPicoCat3[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1952            break;
1953         default: break;
1954     }
1955 }
1956 //_____________________________________________________________________________
1957 void AliAnalysisTaskJetV2::FillQAHistograms(AliVEvent* vevent) 
1958 {
1959     // fill qa histograms for events
1960     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1961     if(!vevent) return;
1962     fHistVertexz->Fill(vevent->GetPrimaryVertex()->GetZ());
1963     fHistCentrality->Fill(fCent);
1964     Int_t runNumber(InputEvent()->GetRunNumber());
1965     if(fLeadingJet && fLeadingJetAfterSub) fHistLeadingJetBackground[fInCentralitySelection]->Fill(TMath::Abs(fLeadingJet->Eta()-fLeadingJetAfterSub->Eta()), PhaseShift(fLeadingJet->Phi()-fLeadingJetAfterSub->Phi()));
1966     for(fMappedRunNumber = 0; fMappedRunNumber < fExpectedRuns->GetSize(); fMappedRunNumber++) {
1967         if(fExpectedRuns->At(fMappedRunNumber) == runNumber) return;
1968     }
1969     if(fDebug > 0) printf("\n > TASK %s CANNOT IDENTIFY RUN - CONFIGURATION COULD BE INCORRECT < \n", GetName());
1970 }
1971 //_____________________________________________________________________________
1972 void AliAnalysisTaskJetV2::FillWeightedTrackHistograms() const
1973 {
1974     // fill track histograms
1975     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1976     Int_t iTracks(fTracks->GetEntriesFast()), iAcceptedTracks(0);
1977     for(Int_t i(0); i < iTracks; i++) {
1978         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1979         if(!PassesCuts(track)) continue;
1980         iAcceptedTracks++;
1981         fHistPicoTrackPt[fInCentralitySelection]->Fill(track->Pt(), fEventPlaneWeight);
1982         if(fFillQAHistograms) FillQAHistograms(track);
1983     }
1984     fHistPicoTrackMult[fInCentralitySelection]->Fill(iAcceptedTracks, fEventPlaneWeight);
1985 }
1986 //_____________________________________________________________________________
1987 void AliAnalysisTaskJetV2::FillWeightedClusterHistograms() const
1988 {
1989     // fill cluster histograms
1990     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1991     if(!fClusterCont) return;
1992     Int_t iClusters(fClusterCont->GetNClusters());
1993     TLorentzVector clusterLorentzVector;
1994     for(Int_t i(0); i < iClusters; i++) {
1995         AliVCluster* cluster = fClusterCont->GetCluster(i);
1996         if (!PassesCuts(cluster)) continue;
1997         cluster->GetMomentum(clusterLorentzVector, const_cast<Double_t*>(fVertex));
1998         fHistClusterPt[fInCentralitySelection]->Fill(clusterLorentzVector.Pt(), fEventPlaneWeight);
1999         fHistClusterEtaPhi[fInCentralitySelection]->Fill(clusterLorentzVector.Eta(), clusterLorentzVector.Phi(), fEventPlaneWeight);
2000         fHistClusterEtaPhiWeighted[fInCentralitySelection]->Fill(clusterLorentzVector.Eta(), clusterLorentzVector.Phi(), clusterLorentzVector.Pt()*fEventPlaneWeight);
2001     }
2002     return;
2003 }
2004 //_____________________________________________________________________________
2005 void AliAnalysisTaskJetV2::FillWeightedEventPlaneHistograms(Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc) const
2006 {
2007     // fill event plane histograms, only called in qa mode
2008     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2009     fHistPsiControl->Fill(0.5, vzero[0][0], fEventPlaneWeight);    // vzero a psi2
2010     fHistPsiControl->Fill(1.5, vzero[1][0], fEventPlaneWeight);    // vzero c psi2
2011     fHistPsiControl->Fill(2.5, tpc[0], fEventPlaneWeight);         // tpc psi 2
2012     fHistPsiControl->Fill(5.5, vzero[0][1], fEventPlaneWeight);    // vzero a psi3
2013     fHistPsiControl->Fill(6.5, vzero[1][1], fEventPlaneWeight);    // vzero b psi3
2014     fHistPsiControl->Fill(7.5, tpc[1], fEventPlaneWeight);         // tpc psi 3
2015     fHistPsiVZEROA->Fill(vzero[0][0], fEventPlaneWeight);
2016     fHistPsiVZEROC->Fill(vzero[1][0], fEventPlaneWeight);
2017     fHistPsiVZERO->Fill(vzeroComb[0], fEventPlaneWeight);
2018     fHistPsiTPC->Fill(tpc[0], fEventPlaneWeight);
2019     fHistPsiSpread->Fill(0.5, TMath::Abs(vzero[0][0]-vzero[1][0]), fEventPlaneWeight);
2020     fHistPsiSpread->Fill(1.5, TMath::Abs(vzero[0][0]-tpc[0]), fEventPlaneWeight);
2021     fHistPsiSpread->Fill(2.5, TMath::Abs(vzero[1][0]-tpc[0]), fEventPlaneWeight);
2022     // event plane vs centrality QA histo's to check recentering
2023     Double_t TRK(InputEvent()->GetCentrality()->GetCentralityPercentile("TRK"));
2024     Double_t V0M(InputEvent()->GetCentrality()->GetCentralityPercentile("V0M"));
2025     fHistPsiVZEROAV0M->Fill(V0M, vzero[0][0], fEventPlaneWeight);
2026     fHistPsiVZEROCV0M->Fill(V0M, vzero[1][0], fEventPlaneWeight);
2027     fHistPsiVZEROVV0M->Fill(V0M, vzeroComb[0], fEventPlaneWeight);
2028     fHistPsiTPCV0M->Fill(V0M, tpc[0], fEventPlaneWeight);
2029     fHistPsiVZEROATRK->Fill(TRK, vzero[0][0], fEventPlaneWeight);
2030     fHistPsiVZEROCTRK->Fill(TRK, vzero[1][0], fEventPlaneWeight);
2031     fHistPsiVZEROTRK->Fill(TRK, vzeroComb[0], fEventPlaneWeight);
2032     fHistPsiTPCTRK->Fill(TRK, tpc[0], fEventPlaneWeight);
2033     // leading jet vs event plane bias
2034     if(fLeadingJet) {
2035         Double_t rho(fLocalRho->GetLocalVal(fLeadingJet->Phi(), GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
2036         Double_t pt(fLeadingJet->Pt() - fLeadingJet->Area()*rho);
2037         fHistPsiTPCLeadingJet[fInCentralitySelection]->Fill(pt, tpc[0], fLeadingJet->Phi(), fEventPlaneWeight);
2038         fHistPsiVZEROALeadingJet[fInCentralitySelection]->Fill(pt, vzero[0][0], fLeadingJet->Phi(), fEventPlaneWeight);
2039         fHistPsiVZEROCLeadingJet[fInCentralitySelection]->Fill(pt, vzero[1][0], fLeadingJet->Phi(), fEventPlaneWeight);
2040         fHistPsiVZEROCombLeadingJet[fInCentralitySelection]->Fill(pt, vzeroComb[0], fLeadingJet->Phi(), fEventPlaneWeight);
2041     }
2042     // correlation of event planes
2043     fHistPsi2Correlation[fInCentralitySelection]->Fill(tpc[0], vzero[0][0], vzero[1][0], fEventPlaneWeight);
2044 }
2045 //_____________________________________________________________________________
2046 void AliAnalysisTaskJetV2::FillWeightedRhoHistograms()
2047 {
2048     // fill rho histograms
2049     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2050     fHistRhoPackage[fInCentralitySelection]->Fill(fLocalRho->GetVal(), fEventPlaneWeight);    // save the rho estimate from the emcal jet package
2051     // get multiplicity FIXME inefficient
2052     Int_t iJets(fJets->GetEntriesFast());
2053     Double_t rho(fLocalRho->GetLocalVal(TMath::Pi(), TMath::Pi(), fLocalRho->GetVal()));
2054     fHistRho[fInCentralitySelection]->Fill(rho, fEventPlaneWeight);
2055     fHistRhoVsMult->Fill(fTracks->GetEntries(), rho, fEventPlaneWeight);
2056     fHistRhoVsCent->Fill(fCent, rho, fEventPlaneWeight);
2057     for(Int_t i(0); i < iJets; i++) {
2058         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
2059         if(!PassesCuts(jet)) continue;
2060         fHistRhoAVsMult->Fill(fTracks->GetEntries(), rho * jet->Area(), fEventPlaneWeight);
2061         fHistRhoAVsCent->Fill(fCent, rho * jet->Area(), fEventPlaneWeight);
2062     }
2063 }
2064 //_____________________________________________________________________________
2065 void AliAnalysisTaskJetV2::FillWeightedDeltaPtHistograms(Double_t psi2) const
2066 {
2067     // fill delta pt histograms
2068     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2069     Int_t i(0);
2070     const Float_t areaRC = GetJetRadius()*GetJetRadius()*TMath::Pi();
2071     // we're retrieved the leading jet, now get a random cone
2072     for(i = 0; i < fMaxCones; i++) {
2073        Float_t pt(0), eta(0), phi(0);
2074        // get a random cone without constraints on leading jet position
2075        CalculateRandomCone(pt, eta, phi, fTracksCont, fClusterCont, 0x0);
2076        if(pt > 0) {
2077            if(fFillQAHistograms) fHistRCPhiEta[fInCentralitySelection]->Fill(phi, eta, fEventPlaneWeight);
2078            fHistRhoVsRCPt[fInCentralitySelection]->Fill(pt, fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal())*areaRC, fEventPlaneWeight);
2079            fHistRCPt[fInCentralitySelection]->Fill(pt, fEventPlaneWeight);
2080            fHistDeltaPtDeltaPhi2[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()), fEventPlaneWeight);
2081            fHistDeltaPtDeltaPhi2Rho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetVal(), fEventPlaneWeight);
2082
2083        }
2084        // get a random cone excluding leading jet area
2085        CalculateRandomCone(pt, eta, phi, fTracksCont, fClusterCont, fLeadingJet);
2086        if(pt > 0) {
2087            if(fFillQAHistograms) fHistRCPhiEtaExLJ[fInCentralitySelection]->Fill(phi, eta, fEventPlaneWeight);
2088            fHistRhoVsRCPtExLJ[fInCentralitySelection]->Fill(pt, fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal())*areaRC, fEventPlaneWeight);
2089            fHistRCPtExLJ[fInCentralitySelection]->Fill(pt, fEventPlaneWeight);
2090            fHistDeltaPtDeltaPhi2ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()), fEventPlaneWeight);
2091            fHistDeltaPtDeltaPhi2ExLJRho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetVal(), fEventPlaneWeight);
2092        }
2093     } 
2094 }
2095 //_____________________________________________________________________________
2096 void AliAnalysisTaskJetV2::FillWeightedJetHistograms(Double_t psi2)
2097 {
2098     // fill jet histograms
2099     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2100     Int_t iJets(fJets->GetEntriesFast());
2101     for(Int_t i(0); i < iJets; i++) {
2102         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
2103         if(PassesCuts(jet)) {
2104             Double_t pt(jet->Pt()), area(jet->Area()), eta(jet->Eta()), phi(jet->Phi());
2105             Double_t rho(fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
2106             fHistJetPtRaw[fInCentralitySelection]->Fill(pt, fEventPlaneWeight);
2107             fHistJetPt[fInCentralitySelection]->Fill(pt-area*rho, fEventPlaneWeight);
2108             if(fFillQAHistograms) fHistJetEtaPhi[fInCentralitySelection]->Fill(eta, phi, fEventPlaneWeight);
2109             fHistJetPtArea[fInCentralitySelection]->Fill(pt-area*rho, area, fEventPlaneWeight);
2110             fHistJetPtEta[fInCentralitySelection]->Fill(pt-area*rho, eta, fEventPlaneWeight);
2111             fHistJetPsi2Pt[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt-area*rho, fEventPlaneWeight);
2112             fHistJetPsi2PtRho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt-area*fLocalRho->GetVal(), fEventPlaneWeight);
2113             fHistJetPtConstituents[fInCentralitySelection]->Fill(pt-area*rho, jet->GetNumberOfConstituents(), fEventPlaneWeight);
2114             fHistJetEtaRho[fInCentralitySelection]->Fill(eta, pt/area, fEventPlaneWeight);
2115         } 
2116     }
2117 }
2118 //_____________________________________________________________________________
2119 void AliAnalysisTaskJetV2::FillWeightedQAHistograms(AliVTrack* vtrack) const
2120 {
2121     // fill qa histograms for pico tracks
2122     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2123     if(!vtrack) return;
2124     AliPicoTrack* track = static_cast<AliPicoTrack*>(vtrack);
2125     fHistRunnumbersPhi->Fill(fMappedRunNumber, track->Phi(), fEventPlaneWeight);
2126     fHistRunnumbersEta->Fill(fMappedRunNumber, track->Eta(), fEventPlaneWeight);
2127     Int_t type((int)(track->GetTrackType()));
2128     switch (type) {
2129         case 0:
2130            fHistPicoCat1[fInCentralitySelection]->Fill(track->Eta(), track->Phi(), fEventPlaneWeight); 
2131            break;
2132         case 1:
2133            fHistPicoCat2[fInCentralitySelection]->Fill(track->Eta(), track->Phi(), fEventPlaneWeight); 
2134            break;
2135         case 2:
2136            fHistPicoCat3[fInCentralitySelection]->Fill(track->Eta(), track->Phi(), fEventPlaneWeight); 
2137            break;
2138         default: break;
2139     }
2140 }
2141 //_____________________________________________________________________________
2142 void AliAnalysisTaskJetV2::FillWeightedQAHistograms(AliVEvent* vevent) 
2143 {
2144     // fill qa histograms for events
2145     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2146     if(!vevent) return;
2147     fHistVertexz->Fill(vevent->GetPrimaryVertex()->GetZ());
2148     fHistCentrality->Fill(fCent);
2149     Int_t runNumber(InputEvent()->GetRunNumber());
2150     if(fLeadingJet && fLeadingJetAfterSub) fHistLeadingJetBackground[fInCentralitySelection]->Fill(TMath::Abs(fLeadingJet->Eta()-fLeadingJetAfterSub->Eta()), PhaseShift(fLeadingJet->Phi()-fLeadingJetAfterSub->Phi()), fEventPlaneWeight);
2151     for(fMappedRunNumber = 0; fMappedRunNumber < fExpectedRuns->GetSize(); fMappedRunNumber++) {
2152         if(fExpectedRuns->At(fMappedRunNumber) == runNumber) return;
2153     }
2154     if(fDebug > 0) printf("\n > TASK %s CANNOT IDENTIFY RUN - CONFIGURATION COULD BE INCORRECT < \n", GetName());
2155 }
2156 //_____________________________________________________________________________
2157 void AliAnalysisTaskJetV2::FillAnalysisSummaryHistogram() const
2158 {
2159     // fill the analysis summary histrogram, saves all relevant analysis settigns
2160     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2161     fHistAnalysisSummary->GetXaxis()->SetBinLabel(2, "fJetRadius");
2162     fHistAnalysisSummary->SetBinContent(2, GetJetContainer()->GetJetRadius());
2163     fHistAnalysisSummary->GetXaxis()->SetBinLabel(3, "fJetEtaMin");
2164     fHistAnalysisSummary->SetBinContent(3, GetJetContainer()->GetJetEtaMin());
2165     fHistAnalysisSummary->GetXaxis()->SetBinLabel(4, "fJetEtaMax");
2166     fHistAnalysisSummary->SetBinContent(4, GetJetContainer()->GetJetEtaMax());
2167     fHistAnalysisSummary->GetXaxis()->SetBinLabel(5, "fJetPhiMin");
2168     fHistAnalysisSummary->SetBinContent(5, GetJetContainer()->GetJetPhiMin());
2169     fHistAnalysisSummary->GetXaxis()->SetBinLabel(6, "fJetPhiMax");
2170     fHistAnalysisSummary->SetBinContent(6, GetJetContainer()->GetJetPhiMin());
2171     fHistAnalysisSummary->GetXaxis()->SetBinLabel(16, "fForceBeamType");
2172     fHistAnalysisSummary->SetBinContent(16, fForceBeamType);
2173     fHistAnalysisSummary->GetXaxis()->SetBinLabel(17, "fMinCent");
2174     fHistAnalysisSummary->SetBinContent(17, fMinCent);
2175     fHistAnalysisSummary->GetXaxis()->SetBinLabel(18, "fMaxCent");
2176     fHistAnalysisSummary->SetBinContent(18, fMaxCent);
2177     fHistAnalysisSummary->GetXaxis()->SetBinLabel(19, "fMinVz");
2178     fHistAnalysisSummary->SetBinContent(19, fMinVz);
2179     fHistAnalysisSummary->GetXaxis()->SetBinLabel(20, "fMaxVz");
2180     fHistAnalysisSummary->SetBinContent(20, fMaxVz);
2181     fHistAnalysisSummary->GetXaxis()->SetBinLabel(21, "fOffTrigger");
2182     fHistAnalysisSummary->SetBinContent(21, fOffTrigger);
2183     fHistAnalysisSummary->GetXaxis()->SetBinLabel(34, "fitModulationType");
2184     fHistAnalysisSummary->SetBinContent(34, (int)fFitModulationType);
2185     fHistAnalysisSummary->GetXaxis()->SetBinLabel(35, "runModeType");
2186     fHistAnalysisSummary->SetBinContent(35, (int)fRunModeType);
2187     fHistAnalysisSummary->GetXaxis()->SetBinLabel(36, "data type");
2188     fHistAnalysisSummary->SetBinContent(36, (int)fDataType);
2189     fHistAnalysisSummary->GetXaxis()->SetBinLabel(37, "iterator");
2190     fHistAnalysisSummary->SetBinContent(37, 1.);
2191     fHistAnalysisSummary->GetXaxis()->SetBinLabel(38, "fMinPvalue");
2192     fHistAnalysisSummary->SetBinContent(38, fMinPvalue);
2193     fHistAnalysisSummary->GetXaxis()->SetBinLabel(39, "fMaxPvalue");
2194     fHistAnalysisSummary->SetBinContent(39, fMaxPvalue);
2195     fHistAnalysisSummary->GetXaxis()->SetBinLabel(40, "fExcludeLeadingJetsFromFit");
2196     fHistAnalysisSummary->SetBinContent(40, fExcludeLeadingJetsFromFit);
2197     fHistAnalysisSummary->GetXaxis()->SetBinLabel(41, "fRebinSwapHistoOnTheFly");
2198     fHistAnalysisSummary->SetBinContent(41, (int)fRebinSwapHistoOnTheFly);
2199     fHistAnalysisSummary->GetXaxis()->SetBinLabel(42, "fUsePtWeight");
2200     fHistAnalysisSummary->SetBinContent(42, (int)fUsePtWeight);
2201     fHistAnalysisSummary->GetXaxis()->SetBinLabel(44, "fSoftTrackMinPt");
2202     fHistAnalysisSummary->SetBinContent(44, fSoftTrackMinPt);
2203     fHistAnalysisSummary->GetXaxis()->SetBinLabel(45, "fSoftTrackMaxPt");
2204     fHistAnalysisSummary->SetBinContent(45, fSoftTrackMaxPt);
2205     fHistAnalysisSummary->GetXaxis()->SetBinLabel(46, "fMaxCones");
2206     fHistAnalysisSummary->SetBinContent(46, fMaxCones);
2207     fHistAnalysisSummary->GetXaxis()->SetBinLabel(47, "used rho");
2208     fHistAnalysisSummary->GetXaxis()->SetBinLabel(48, "used small rho");
2209 }
2210 //_____________________________________________________________________________
2211 void AliAnalysisTaskJetV2::Terminate(Option_t *)
2212 {
2213     // terminate
2214     switch (fRunModeType) {
2215         case kLocal : {
2216         if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2217         AliAnalysisTaskJetV2::Dump();
2218         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));
2219         } break;
2220         default : break;
2221     }
2222 }
2223 //_____________________________________________________________________________
2224 void AliAnalysisTaskJetV2::SetModulationFit(TF1* fit) 
2225 {
2226     // set modulation fit
2227     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2228     if (fFitModulation) delete fFitModulation;
2229     fFitModulation = fit; 
2230 }
2231 //_____________________________________________________________________________
2232 void AliAnalysisTaskJetV2::SetUseControlFit(Bool_t c)
2233 {
2234     // set control fit
2235     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2236     if (fFitControl) delete fFitControl;
2237     if (c) {
2238         fFitControl = new TF1("controlFit", "pol0", 0, TMath::TwoPi());
2239     } else fFitControl = 0x0;
2240 }
2241 //_____________________________________________________________________________
2242 TH1F* AliAnalysisTaskJetV2::GetResolutionFromOuptutFile(detectorType det, Int_t h, TArrayD* cen)
2243 {
2244     // INTERFACE METHOD FOR OUTPUTFILE
2245     // get the detector resolution, user has ownership of the returned histogram
2246     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2247     if(!fOutputList) {
2248         printf(" > Please add fOutputList first < \n");
2249         return 0x0;
2250     }
2251     TH1F* r(0x0);
2252     (cen) ? r = new TH1F("R", "R", cen->GetSize()-1, cen->GetArray()) : r = new TH1F("R", "R", 10, 0, 10);
2253     if(!cen) r->GetXaxis()->SetTitle("number of centrality bin");
2254     r->GetYaxis()->SetTitle(Form("Resolution #Psi_{%i}", h));
2255     for(Int_t i(0); i < 10; i++) {
2256         TProfile* temp((TProfile*)fOutputList->FindObject(Form("fProfV%iResolution_%i", h, i)));
2257         if(!temp) break;
2258         Double_t a(temp->GetBinContent(3)), b(temp->GetBinContent(5)), c(temp->GetBinContent(7));
2259         Double_t d(temp->GetBinContent(9)), e(temp->GetBinContent(10)), f(temp->GetBinContent(11));
2260         Double_t _a(temp->GetBinError(3)), _b(temp->GetBinError(5)), _c(temp->GetBinError(7));
2261         Double_t _d(temp->GetBinError(9)), _e(temp->GetBinError(10)), _f(temp->GetBinError(11));
2262         if(a <= 0 || b <= 0 || c <= 0 || d <= 0 || e <= 0 || f <= 0) continue;
2263         switch (det) {
2264             case kVZEROA : {
2265                 r->SetBinContent(1+i, TMath::Sqrt((a*b)/c));
2266                 if(i==0) r->SetNameTitle("VZEROA resolution", "VZEROA resolution");
2267                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
2268             } break;
2269             case kVZEROC : {
2270                 r->SetBinContent(1+i, TMath::Sqrt((a*c)/b));
2271                 if(i==0) r->SetNameTitle("VZEROC resolution", "VZEROC resolution");
2272                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
2273             } break;
2274             case kTPC : {
2275                 r->SetBinContent(1+i, TMath::Sqrt((b*c)/a));
2276                 if(i==0) r->SetNameTitle("TPC resolution", "TPC resolution");
2277                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
2278             } break;
2279             case kVZEROComb : {
2280                 r->SetBinContent(1+i, TMath::Sqrt((d*e)/f));
2281                 if(i==0) r->SetNameTitle("VZEROComb resolution", "VZEROComb resolution");
2282                 r->SetBinError(1+i, TMath::Sqrt(_d*_d+_e*_e+_f*_f));
2283             } break;
2284             default : break;
2285         }
2286     }
2287     return r;
2288 }
2289 //_____________________________________________________________________________
2290 TH1F* AliAnalysisTaskJetV2::CorrectForResolutionDiff(TH1F* v, detectorType det, TArrayD* cen, Int_t c, Int_t h)
2291 {
2292     // INTERFACE METHOD FOR OUTPUT FILE
2293     // correct the supplied differential vn histogram v for detector resolution
2294     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2295     TH1F* r(GetResolutionFromOuptutFile(det, h, cen));
2296     if(!r) {
2297         printf(" > Couldn't find resolution < \n");
2298         return 0x0;
2299     }
2300     Double_t res(1./r->GetBinContent(1+r->FindBin(c)));
2301     TF1* line = new TF1("line", "pol0", 0, 200);
2302     line->SetParameter(0, res);
2303     v->Multiply(line);
2304     return v;
2305 }
2306 //_____________________________________________________________________________
2307 TH1F* AliAnalysisTaskJetV2::CorrectForResolutionInt(TH1F* v, detectorType det, TArrayD* cen, Int_t h)
2308 {
2309     // INTERFACE METHOD FOR OUTPUT FILE
2310     // correct the supplied intetrated vn histogram v for detector resolution
2311     // integrated vn must have the same centrality binning as the resolotion correction
2312     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2313     TH1F* r(GetResolutionFromOuptutFile(det, h, cen));
2314     v->Divide(v, r);
2315     return v;
2316 }
2317 //_____________________________________________________________________________
2318 TH1F* AliAnalysisTaskJetV2::GetDifferentialQC(TProfile* refCumulants, TProfile* diffCumlants, TArrayD* ptBins, Int_t h)
2319 {
2320     // get differential QC
2321     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2322     Double_t r(refCumulants->GetBinContent(h-1)); // v2 reference flow
2323     if(r > 0) r = TMath::Sqrt(r);
2324     TH1F* qc = new TH1F(Form("QC2v%i", h), Form("QC2v%i", h), ptBins->GetSize()-1, ptBins->GetArray());
2325     Double_t a(0), b(0), c(0);  // dummy variables
2326     for(Int_t i(0); i < ptBins->GetSize(); i++) {
2327         if(r > 0) {
2328             a = diffCumlants->GetBinContent(1+i);
2329             b = diffCumlants->GetBinError(1+i);
2330             c = a/r;
2331             qc->SetBinContent(1+i, c);
2332             (a <= 0 || b <= 0) ? qc->SetBinError(1+i, b) : qc->SetBinError(1+i, TMath::Sqrt(c*c*b*b/(a*a)));
2333         }
2334     }
2335     return qc;
2336 }
2337 //_____________________________________________________________________________
2338 void AliAnalysisTaskJetV2::ReadVZEROCalibration2010h()
2339 {
2340     // necessary for calibration of 10h vzero event plane. code copied from flow package 
2341     // (duplicate, but i didn't want to introduce an ulgy dependency )
2342     // this function is only called when the runnumber changes 
2343     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2344
2345     // 1) check if the proper chi weights for merging vzero a and vzero c ep are present
2346     // if not, use sane defaults. centrality binning is equal to that given in the fVZEROcentralityBin snippet
2347     //
2348     // chi values can be calculated using the static helper function 
2349     // AliAnalysisTaskJetV2::CalculateEventPlaneChi(Double_t res) where res is the event plane
2350     // resolution in a given centrality bin
2351     //
2352     // the resolutions that were used for these defaults are
2353     // this might need a bit of updating as they were read 'by-eye' from a performance plot ..
2354     // Double_t R2VZEROA[] = {.35, .40, .48, .50, .48, .45, .38, .26, .16};
2355     // Double_t R2VZEROC[] = {.45, .60, .70, .73, .68, .60, .40, .36, .17};
2356     // Double_t R3VZEROA[] = {.22, .23, .22, .19, .15, .12, .08, .00, .00};
2357     // Double_t R3VZEROC[] = {.30, .30, .28, .25, .22, .17, .11, .00, .00};
2358
2359     Double_t chiC2[] = {0.771423, 1.10236, 1.38116, 1.48077, 1.31964, 1.10236, 0.674622, 0.600403, 0.273865};
2360     Double_t chiA2[] = {0.582214, 0.674622, 0.832214, 0.873962, 0.832214, 0.771423, 0.637146, 0.424255, 0.257385};
2361     Double_t chiC3[] = {0.493347, 0.493347, 0.458557, 0.407166, 0.356628, 0.273865, 0.176208, 6.10352e-05, 6.10352e-05};
2362     Double_t chiA3[] = {0.356628, 0.373474, 0.356628, 0.306702, 0.24115, 0.192322, 0.127869, 6.10352e-05, 6.10352e-05};
2363
2364     if(!fChi2A) fChi2A = new TArrayD(9, chiA2);
2365     if(!fChi2C) fChi2C = new TArrayD(9, chiC2);
2366     if(!fChi3A) fChi3A = new TArrayD(9, chiA3);
2367     if(!fChi3C) fChi3C = new TArrayD(9, chiC3);
2368
2369     // 2) open database file
2370     fOADB = TFile::Open("$ALICE_ROOT/OADB/PWGCF/VZERO/VZEROcalibEP.root");
2371     if(fOADB->IsZombie()){
2372         printf("OADB file $ALICE_ROOT/OADB/PWGCF/VZERO/VZEROcalibEP.root cannot be opened, CALIBRATION FAILED !");
2373         return;
2374     }
2375
2376     AliOADBContainer *cont = (AliOADBContainer*) fOADB->Get("hMultV0BefCorr");
2377     if(!cont){
2378         // see if database is readable
2379         printf("OADB object hMultV0BefCorr is not available in the file\n");
2380         return; 
2381     }
2382     Int_t run(fRunNumber);
2383     if(!(cont->GetObject(run))){
2384         // if the run isn't recognized fall back to a default run
2385         printf("OADB object hMultVZEROBefCorr is not available for run %i (used default run 137366)\n",run);
2386         run = 137366;
2387     }
2388     // step 3) get the proper multiplicity weights from the vzero signal
2389     fVZEROgainEqualization = ((TH2F*)cont->GetObject(run))->ProfileX();
2390     if(!fVZEROgainEqualization) {
2391         AliFatal(Form("%s: Fatal error, couldn't read fVZEROgainEqualization from OADB object < \n", GetName()));
2392         return;
2393     }
2394
2395     TF1* fpol0 = new TF1("fpol0","pol0"); 
2396     if(fVZEROgainEqualizationPerRing) {
2397         // do the calibration per ring
2398         // start with the vzero c rings (segments 0 through 31)
2399         fVZEROgainEqualization->Fit(fpol0, "", "", 0, 8);
2400         (fUseVZERORing[0]) ? SetVZEROCpol(0, fpol0->GetParameter(0)) : SetVZEROCpol(0, 0.);
2401         fVZEROgainEqualization->Fit(fpol0, "", "", 8, 16);
2402         (fUseVZERORing[1]) ? SetVZEROCpol(1, fpol0->GetParameter(0)) : SetVZEROCpol(1, 0.);
2403         fVZEROgainEqualization->Fit(fpol0, "", "", 16, 24);
2404         (fUseVZERORing[2]) ? SetVZEROCpol(2, fpol0->GetParameter(0)) : SetVZEROCpol(2, 0.);
2405         fVZEROgainEqualization->Fit(fpol0, "", "", 24, 32);
2406         (fUseVZERORing[3]) ? SetVZEROCpol(3, fpol0->GetParameter(0)) : SetVZEROCpol(3, 0.);
2407         // same thing for vero A
2408         fVZEROgainEqualization->Fit(fpol0, "", "", 32, 40);
2409         (fUseVZERORing[4]) ? SetVZEROApol(0, fpol0->GetParameter(0)) : SetVZEROApol(0, 0.);
2410         fVZEROgainEqualization->Fit(fpol0, "", "", 40, 48);
2411         (fUseVZERORing[5]) ? SetVZEROApol(1, fpol0->GetParameter(0)) : SetVZEROApol(1, 0.);
2412         fVZEROgainEqualization->Fit(fpol0, "", "", 48, 56);
2413         (fUseVZERORing[6]) ? SetVZEROApol(2, fpol0->GetParameter(0)) : SetVZEROApol(2, 0.);
2414         fVZEROgainEqualization->Fit(fpol0, "", "", 56, 64);
2415         (fUseVZERORing[7]) ? SetVZEROApol(3, fpol0->GetParameter(0)) : SetVZEROApol(3, 0.);
2416     } else {
2417         // do the calibration in one go. the calibration will still be 
2418         // stored per ring, but each ring has the same weight now
2419         // this should be the default for the analysis as the database is tuned to this configuration
2420        fVZEROgainEqualization->Fit(fpol0,"","",0,31);
2421        for(Int_t i(0); i < 4; i++) SetVZEROCpol(i, fpol0->GetParameter(0));
2422        fVZEROgainEqualization->Fit(fpol0,"","",32,64);
2423        for(Int_t i(0); i < 4; i++) SetVZEROApol(i, fpol0->GetParameter(0));
2424     }
2425
2426     // step 4) extract the information to re-weight the q-vectors 
2427     for(Int_t iside=0;iside<2;iside++){
2428         for(Int_t icoord=0;icoord<2;icoord++){
2429             for(Int_t i=0;i  < 9;i++){
2430                 char namecont[100];
2431                 if(iside==0 && icoord==0)
2432                   snprintf(namecont,100,"hQxc2_%i",i);
2433                 else if(iside==1 && icoord==0)
2434                   snprintf(namecont,100,"hQxa2_%i",i);
2435                 else if(iside==0 && icoord==1)
2436                   snprintf(namecont,100,"hQyc2_%i",i);
2437                 else if(iside==1 && icoord==1)
2438                   snprintf(namecont,100,"hQya2_%i",i);
2439
2440                 cont = (AliOADBContainer*) fOADB->Get(namecont);
2441                 if(!cont){
2442                     printf("OADB object %s is not available in the file\n",namecont);
2443                     return;     
2444                 }
2445         
2446                 if(!(cont->GetObject(run))){
2447                     printf("OADB object %s is not available for run %i (used run 137366)\n",namecont,run);
2448                     run = 137366;
2449                 }
2450
2451                 // store info for all centralities to cache
2452                 fMeanQ[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetMean();
2453                 fWidthQ[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetRMS();
2454
2455                 //for v3
2456                 if(iside==0 && icoord==0)
2457                   snprintf(namecont,100,"hQxc3_%i",i);
2458                 else if(iside==1 && icoord==0)
2459                   snprintf(namecont,100,"hQxa3_%i",i);
2460                 else if(iside==0 && icoord==1)
2461                   snprintf(namecont,100,"hQyc3_%i",i);
2462                 else if(iside==1 && icoord==1)
2463                   snprintf(namecont,100,"hQya3_%i",i);
2464
2465                 cont = (AliOADBContainer*) fOADB->Get(namecont);
2466                 if(!cont){
2467                     printf("OADB object %s is not available in the file\n",namecont);
2468                     return;     
2469                 }
2470                 
2471                 if(!(cont->GetObject(run))){
2472                     printf("OADB object %s is not available for run %i (used run 137366)\n",namecont,run);
2473                     run = 137366;
2474                 }
2475                 // store info for all centralities to cache
2476                 fMeanQv3[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetMean();
2477                 fWidthQv3[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetRMS();
2478             }
2479         }
2480     }
2481     // cleanup. the opened file is closed in the destructor, otherwise fVZEROgainEqualization is no longer available
2482     delete fpol0;
2483 }
2484 //_____________________________________________________________________________
2485 Int_t AliAnalysisTaskJetV2::GetVZEROCentralityBin() const
2486 {
2487     // return cache index number corresponding to the event centrality
2488     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
2489     Float_t v0Centr(InputEvent()->GetCentrality()->GetCentralityPercentile("V0M"));
2490     if(v0Centr < 5) return 0;
2491     else if(v0Centr < 10) return 1;
2492     else if(v0Centr < 20) return  2;
2493     else if(v0Centr < 30) return  3;
2494     else if(v0Centr < 40) return  4;
2495     else if(v0Centr < 50) return  5;
2496     else if(v0Centr < 60) return  6;
2497     else if(v0Centr < 70) return  7;
2498     else return 8;
2499 }
2500 //_____________________________________________________________________________
2501 AliEmcalJet* AliAnalysisTaskJetV2::GetLeadingJet(AliLocalRhoParameter* localRho) {
2502     // return pointer to the highest pt jet (before background subtraction) within acceptance
2503     // only rudimentary cuts are applied on this level, hence the implementation outside of
2504     // the framework
2505     Int_t iJets(fJets->GetEntriesFast());
2506     Double_t pt(0);
2507     AliEmcalJet* leadingJet(0x0);
2508     if(!localRho) {
2509         for(Int_t i(0); i < iJets; i++) {
2510             AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
2511             if(!PassesSimpleCuts(jet)) continue;
2512             if(jet->Pt() > pt) {
2513                leadingJet = jet;
2514                pt = leadingJet->Pt();
2515             }
2516         }
2517         return leadingJet;
2518     } else {
2519         // return leading jet after background subtraction
2520         Double_t rho(0);
2521         for(Int_t i(0); i < iJets; i++) {
2522             AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
2523             if(!PassesSimpleCuts(jet)) continue;
2524             rho = localRho->GetLocalVal(jet->Phi(), GetJetContainer()->GetJetRadius(), localRho->GetVal());
2525             if((jet->Pt()-jet->Area()*rho) > pt) {
2526                leadingJet = jet;
2527                pt = (leadingJet->Pt()-jet->Area()*rho);
2528             }
2529         }
2530         return leadingJet;
2531
2532     }
2533     return 0x0;
2534 }
2535 //_____________________________________________________________________________