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