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