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