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