]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskJetV2.cxx
0175f05de1c655e32e6b9297dd191e7700575988
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskJetV2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* 
17  * Jet V2 task
18  *
19  * this task is part of the emcal jet framework and should be run in the emcaljet train
20  * the following extensions to an accepted AliVEvent are expected:
21  *      - (anti-kt) jets
22  *      - background estimate rho
23  *      - pico tracks
24  *      aod's and esd's are handled transparently
25  * the task will attempt to estimate a phi-dependent background density rho 
26  * by fitting vn harmonics to the dpt/dphi distribution
27  *
28  * author: Redmer Alexander Bertens, Utrecht Univeristy, Utrecht, Netherlands
29  * rbertens@cern.ch, rbertens@nikhef.nl, r.a.bertens@uu.nl 
30  */
31
32 // root includes
33 #include <TStyle.h>
34 #include <TRandom3.h>
35 #include <TChain.h>
36 #include <TMath.h>
37 #include <TF1.h>
38 #include <TF2.h>
39 #include <TH1F.h>
40 #include <TH2F.h>
41 #include <TProfile.h>
42 // aliroot includes
43 #include <AliAnalysisTask.h>
44 #include <AliAnalysisManager.h>
45 #include <AliCentrality.h>
46 #include <AliVVertex.h>
47 #include <AliVTrack.h>
48 #include <AliESDEvent.h>
49 #include <AliAODEvent.h>
50 #include <AliAODTrack.h>
51 // emcal jet framework includes
52 #include <AliPicoTrack.h>
53 #include <AliEmcalJet.h>
54 #include <AliRhoParameter.h>
55 #include <AliLocalRhoParameter.h>
56 #include <AliAnalysisTaskJetV2.h>
57 #include <AliClusterContainer.h>
58
59 class AliAnalysisTaskJetV2;
60 using namespace std;
61
62 ClassImp(AliAnalysisTaskJetV2)
63
64 AliAnalysisTaskJetV2::AliAnalysisTaskJetV2() : AliAnalysisTaskEmcalJet("AliAnalysisTaskJetV2", kTRUE), 
65     fDebug(0), fRunToyMC(kFALSE), fLocalInit(0), fAttachToEvent(kTRUE), fFillHistograms(kTRUE), fFillQAHistograms(kTRUE), fReduceBinsXByFactor(-1.), fReduceBinsYByFactor(-1.), fNoEventWeightsForQC(kTRUE), fCentralityClasses(0), fExpectedRuns(0), fExpectedSemiGoodRuns(0), fUserSuppliedV2(0), fUserSuppliedV3(0), fUserSuppliedR2(0), fUserSuppliedR3(0), fTracksCont(0), fClusterCont(0), fJetsCont(0), fLeadingJet(0), fNAcceptedTracks(0), fNAcceptedTracksQCn(0), fFitModulationType(kNoFit), fFitGoodnessTest(kChi2Poisson), fQCRecovery(kTryFit), fUsePtWeight(kTRUE), fUsePtWeightErrorPropagation(kTRUE), fDetectorType(kTPC), fAnalysisType( kCharged), fFitModulationOptions("QWLI"), fRunModeType(kGrid), fDataType(kESD), fCollisionType(kPbPb), fRandom(0), fRunNumber(-1), fMappedRunNumber(0), fInCentralitySelection(-1), fFitModulation(0), fFitControl(0), fMinPvalue(0.01), fMaxPvalue(1), fNameSmallRho(""), fCachedRho(0), fSoftTrackMinPt(0.15), fSoftTrackMaxPt(5.), fSemiGoodJetMinPhi(0.), fSemiGoodJetMaxPhi(4.), fSemiGoodTrackMinPhi(0.), fSemiGoodTrackMaxPhi(4.), fAbsVertexZ(10), fHistCentrality(0), fHistVertexz(0), fHistRunnumbersPhi(0), fHistRunnumbersEta(0), fHistPvalueCDFROOT(0), fHistPvalueCDFROOTCent(0), fHistChi2ROOTCent(0), fHistPChi2Root(0),  fHistPvalueCDF(0), fHistPvalueCDFCent(0), fHistChi2Cent(0), fHistPChi2(0), fHistKolmogorovTest(0), fHistKolmogorovTestCent(0), fHistPKolmogorov(0), fHistRhoStatusCent(0), fHistUndeterminedRunQA(0), fMinDisanceRCtoLJ(0), fMaxCones(-1), fExcludeLeadingJetsFromFit(1.), fRebinSwapHistoOnTheFly(kTRUE), fPercentageOfFits(10.), fUseV0EventPlaneFromHeader(kTRUE), /*fExplicitOutlierCut(-1),*/ 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), fHistPsiTPCiV0M(0), fHistPsiVZEROATRK(0), fHistPsiVZEROCTRK(0), fHistPsiVZEROTRK(0), fHistPsiTPCTRK(0), fHistRhoVsMult(0), fHistRhoVsCent(0), fHistRhoAVsMult(0), fHistRhoAVsCent(0) {
66     for(Int_t i(0); i < 10; i++) {
67         fProfV2Resolution[i] = 0;
68         fProfV3Resolution[i] = 0;
69         fHistPicoTrackPt[i] = 0;
70         fHistPicoTrackMult[i] = 0;
71         fHistPicoCat1[i] = 0;
72         fHistPicoCat2[i] = 0;
73         fHistPicoCat3[i] = 0;
74         fHistClusterPt[i] = 0;
75         fHistClusterEtaPhi[i] = 0;
76         fHistClusterEtaPhiWeighted[i] = 0;
77         fHistRhoPackage[i] = 0;
78         fHistRho[i] = 0;
79         fHistRCPhiEta[i] = 0;
80         fHistRhoVsRCPt[i] = 0;
81         fHistRCPt[i] = 0;
82         fHistDeltaPtDeltaPhi2[i] = 0;
83         fHistDeltaPtDeltaPhi2Rho0[i] = 0;
84         fHistRCPhiEtaExLJ[i] = 0;
85         fHistRhoVsRCPtExLJ[i] = 0;
86         fHistRCPtExLJ[i] = 0;
87         fHistDeltaPtDeltaPhi2ExLJ[i] = 0;
88         fHistDeltaPtDeltaPhi2ExLJRho0[i] = 0;
89         fHistJetPtRaw[i] = 0;
90         fHistJetPt[i] = 0;
91         fHistJetEtaPhi[i] = 0;
92         fHistJetPtArea[i] = 0;
93         fHistJetPtEta[i] = 0;
94         fHistJetPtConstituents[i] = 0;
95         fHistJetEtaRho[i] = 0;
96         fHistJetPsi2Pt[i] = 0;
97         fHistJetPsi2PtRho0[i] = 0;
98    }
99     // default constructor
100 }
101 //_____________________________________________________________________________
102 AliAnalysisTaskJetV2::AliAnalysisTaskJetV2(const char* name, runModeType type) : AliAnalysisTaskEmcalJet(name, kTRUE),
103   fDebug(0), fRunToyMC(kFALSE), fLocalInit(0), fAttachToEvent(kTRUE), fFillHistograms(kTRUE), fFillQAHistograms(kTRUE), fReduceBinsXByFactor(-1.), fReduceBinsYByFactor(-1.), fNoEventWeightsForQC(kTRUE), fCentralityClasses(0), fExpectedRuns(0), fExpectedSemiGoodRuns(0), fUserSuppliedV2(0), fUserSuppliedV3(0), fUserSuppliedR2(0), fUserSuppliedR3(0), fTracksCont(0), fClusterCont(0), fJetsCont(0), fLeadingJet(0), fNAcceptedTracks(0), fNAcceptedTracksQCn(0), fFitModulationType(kNoFit), fFitGoodnessTest(kChi2Poisson), fQCRecovery(kTryFit), fUsePtWeight(kTRUE), fUsePtWeightErrorPropagation(kTRUE), fDetectorType(kTPC), fAnalysisType(kCharged), fFitModulationOptions("QWLI"), fRunModeType(type), fDataType(kESD), fCollisionType(kPbPb), fRandom(0), fRunNumber(-1), fMappedRunNumber(0), fInCentralitySelection(-1), fFitModulation(0), fFitControl(0), fMinPvalue(0.01), fMaxPvalue(1), fNameSmallRho(""), fCachedRho(0), fSoftTrackMinPt(0.15), fSoftTrackMaxPt(5.), fSemiGoodJetMinPhi(0.), fSemiGoodJetMaxPhi(4.), fSemiGoodTrackMinPhi(0.), fSemiGoodTrackMaxPhi(4.), fAbsVertexZ(10), fHistCentrality(0), fHistVertexz(0), fHistRunnumbersPhi(0), fHistRunnumbersEta(0), fHistPvalueCDFROOT(0), fHistPvalueCDFROOTCent(0), fHistChi2ROOTCent(0), fHistPChi2Root(0),  fHistPvalueCDF(0), fHistPvalueCDFCent(0), fHistChi2Cent(0), fHistPChi2(0), fHistKolmogorovTest(0), fHistKolmogorovTestCent(0), fHistPKolmogorov(0), fHistRhoStatusCent(0), fHistUndeterminedRunQA(0), fMinDisanceRCtoLJ(0), fMaxCones(-1), fExcludeLeadingJetsFromFit(1.), fRebinSwapHistoOnTheFly(kTRUE), fPercentageOfFits(10.), fUseV0EventPlaneFromHeader(kTRUE), /*fExplicitOutlierCut(-1),*/ 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), fHistPsiTPCiV0M(0), fHistPsiVZEROATRK(0), fHistPsiVZEROCTRK(0), fHistPsiVZEROTRK(0), fHistPsiTPCTRK(0), fHistRhoVsMult(0), fHistRhoVsCent(0), fHistRhoAVsMult(0), fHistRhoAVsCent(0) {
104     for(Int_t i(0); i < 10; i++) {
105         fProfV2Resolution[i] = 0;
106         fProfV3Resolution[i] = 0;
107         fHistPicoTrackPt[i] = 0;
108         fHistPicoTrackMult[i] = 0;
109         fHistPicoCat1[i] = 0;
110         fHistPicoCat2[i] = 0;
111         fHistPicoCat3[i] = 0;
112         fHistClusterPt[i] = 0;
113         fHistClusterEtaPhi[i] = 0;
114         fHistClusterEtaPhiWeighted[i] = 0;
115         fHistRhoPackage[i] = 0;
116         fHistRho[i] = 0;
117         fHistRCPhiEta[i] = 0;
118         fHistRhoVsRCPt[i] = 0;
119         fHistRCPt[i] = 0;
120         fHistDeltaPtDeltaPhi2[i] = 0;
121         fHistDeltaPtDeltaPhi2Rho0[i] = 0;
122         fHistRCPhiEtaExLJ[i] = 0;
123         fHistRhoVsRCPtExLJ[i] = 0;
124         fHistRCPtExLJ[i] = 0;
125         fHistDeltaPtDeltaPhi2ExLJ[i] = 0;
126         fHistDeltaPtDeltaPhi2ExLJRho0[i] = 0;
127         fHistJetPtRaw[i] = 0;
128         fHistJetPt[i] = 0;
129         fHistJetEtaPhi[i] = 0;
130         fHistJetPtArea[i] = 0;
131         fHistJetPtEta[i] = 0;
132         fHistJetPtConstituents[i] = 0;
133         fHistJetEtaRho[i] = 0;
134         fHistJetPsi2Pt[i] = 0;
135         fHistJetPsi2PtRho0[i] = 0;
136     }
137     // constructor
138     DefineInput(0, TChain::Class());
139     DefineOutput(1, TList::Class());
140     switch (fRunModeType) {
141         case kLocal : {
142             gStyle->SetOptFit(1);
143             DefineOutput(2, TList::Class());
144             DefineOutput(3, TList::Class());
145         } break;
146         default: fDebug = -1;   // suppress debug info explicitely when not running locally
147     }
148     switch (fCollisionType) {
149         case kPythia : {
150             fFitModulationType = kNoFit;
151         } break;
152         default : break;
153     }
154     if(fLocalRhoName=="") fLocalRhoName = Form("LocalRhoFrom_%s", GetName());
155 }
156 //_____________________________________________________________________________
157 AliAnalysisTaskJetV2::~AliAnalysisTaskJetV2()
158 {
159     // destructor
160     if(fOutputList)             {delete fOutputList;            fOutputList = 0x0;}
161     if(fOutputListGood)         {delete fOutputListGood;        fOutputListGood = 0x0;}
162     if(fOutputListBad)          {delete fOutputListBad;         fOutputListBad = 0x0;}
163     if(fFitModulation)          {delete fFitModulation;         fFitModulation = 0x0;}
164     if(fHistSwap)               {delete fHistSwap;              fHistSwap = 0x0;}
165     if(fCentralityClasses)      {delete fCentralityClasses;     fCentralityClasses = 0x0;}
166     if(fExpectedRuns)           {delete fExpectedRuns;          fExpectedRuns = 0x0;}
167     if(fExpectedSemiGoodRuns)   {delete fExpectedSemiGoodRuns;  fExpectedSemiGoodRuns = 0x0;}
168     if(fFitControl)             {delete fFitControl;            fFitControl = 0x0;}
169 }
170 //_____________________________________________________________________________
171 void AliAnalysisTaskJetV2::ExecOnce()
172 {
173     // Init the analysis
174     fLocalRho = new AliLocalRhoParameter(fLocalRhoName.Data(), 0); 
175     if(fAttachToEvent) {
176         if(!(InputEvent()->FindListObject(fLocalRho->GetName()))) {
177             InputEvent()->AddObject(fLocalRho);
178         } else {
179             AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), fLocalRho->GetName()));
180         }
181     }
182     AliAnalysisTaskEmcalJet::ExecOnce();        // init the base class
183     AliAnalysisTaskEmcalJet::SetVzRange(-1.*fAbsVertexZ, fAbsVertexZ);
184     if(!GetJetContainer()) AliFatal(Form("%s: Couldn't find jet container. Aborting !", GetName()));
185 }
186 //_____________________________________________________________________________
187 Bool_t AliAnalysisTaskJetV2::Notify()
188 {
189     // determine the run number to see if the track and jet cuts should be refreshed for semi-good TPC runs
190     if(fRunNumber != InputEvent()->GetRunNumber()) {
191         fRunNumber = InputEvent()->GetRunNumber();        // set the current run number
192         if(fDebug > 0) printf("__FUNC__ %s > NEW RUNNUMBER DETECTED \n ", __func__);
193         // check if this is 10h or 11h data. for 10h we don't want to change the acceptance
194         switch (fCollisionType) {
195             case kPbPb10h : {
196                 return kTRUE;
197             } break;
198             default : break;
199         }
200         // reset the cuts. should be a pointless operation except for the case where the run number changes
201         // from semi-good back to good on one node, which is not a likely scenario (unless trains will
202         // run as one masterjob)
203         AliAnalysisTaskEmcal::SetTrackPhiLimits(-10., 10.);
204         switch (fAnalysisType) {
205             case kCharged: {
206                 AliAnalysisTaskEmcalJet::SetJetPhiLimits(-10., 10.);   
207             } break;
208             case kFull: {
209                 AliAnalysisTaskEmcalJet::SetJetPhiLimits(1.405 + GetJetRadius(), 3.135 - GetJetRadius());
210             } break;
211             default: break;
212         }
213         if(fCachedRho) {                // if there's a cached rho, it's the default, so switch back
214             if(fDebug > 0) printf("__FUNC__ %s > replacing rho with cached rho \n ", __func__);
215             fRho = fCachedRho;          // reset rho back to cached value. again, should be pointless
216         }
217         Bool_t flaggedAsSemiGood(kFALSE);       // not flagged as anything
218         for(Int_t i(0); i < fExpectedSemiGoodRuns->GetSize(); i++) {
219             if(fExpectedSemiGoodRuns->At(i) == fRunNumber) { // run is semi-good
220                if(fDebug > 0) printf("__FUNC__ %s > semi-good tpc run detected, adjusting acceptance \n ", __func__);
221                 flaggedAsSemiGood = kTRUE;
222                 switch (fAnalysisType) {
223                     // for full jets the jet acceptance does not have to be changed as emcal does not
224                     // cover the tpc low voltage readout strips
225                     case kCharged: {
226                         AliAnalysisTaskEmcalJet::SetJetPhiLimits(fSemiGoodJetMinPhi, fSemiGoodJetMaxPhi);       // just an acceptance cut, jets are obtained from full azimuth, so no edge effects
227                     } break;
228                     default: break;
229                 }
230                 AliAnalysisTaskEmcal::SetTrackPhiLimits(fSemiGoodTrackMinPhi, fSemiGoodTrackMaxPhi);    // only affects vn extraction, NOT jet finding
231                 // for semi-good runs, also try to get the 'small rho' estimate, if it is available
232                 AliRhoParameter* tempRho(dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(fNameSmallRho.Data())));
233                 if(tempRho) {
234                     if(fDebug > 0) printf("__FUNC__ %s > switching to small rho, caching normal rho \n ", __func__);
235                     fHistAnalysisSummary->SetBinContent(54, 1.);        // bookkeep the fact that small rho is used
236                     fCachedRho = fRho;          // cache the original rho ...
237                     fRho = tempRho;             // ... and use the small rho
238                 }
239             }
240         }
241         if(!flaggedAsSemiGood) {
242             // in case the run is not a semi-good run, check if it is recognized as another run
243             // only done to catch unexpected runs
244             for(Int_t i(0); i < fExpectedRuns->GetSize(); i++) {
245                 if(fExpectedRuns->At(i) == fRunNumber) break; // run is known, break the loop else store the number in a random bin
246                 fHistUndeterminedRunQA->SetBinContent(TMath::Nint(10.*gRandom->Uniform(0.,.9))+1, fRunNumber);
247             }
248             fHistAnalysisSummary->SetBinContent(53, 1.);                // bookkeep which rho estimate is used 
249         }
250     }
251     return kTRUE;
252 }
253 //_____________________________________________________________________________
254 Bool_t AliAnalysisTaskJetV2::InitializeAnalysis() 
255 {
256     // initialize the anaysis
257     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
258     // if not set, estimate the number of cones that would fit into the selected acceptance
259     if(fMaxCones <= 0) fMaxCones = TMath::CeilNint((TMath::Abs(GetJetContainer()->GetJetEtaMax()-GetJetContainer()->GetJetEtaMin())*TMath::Abs(GetJetContainer()->GetJetPhiMax()-GetJetContainer()->GetJetPhiMin()))/(TMath::Pi()*GetJetRadius()*GetJetRadius()));
260     // manually 'override' the default acceptance cuts of the emcal framework (use with caution) 
261     if(fMinDisanceRCtoLJ==0) fMinDisanceRCtoLJ = GetJetRadius();
262     if(dynamic_cast<AliAODEvent*>(InputEvent())) fDataType = kAOD; // determine the datatype
263     else if(dynamic_cast<AliESDEvent*>(InputEvent())) fDataType = kESD;
264     fHistAnalysisSummary->SetBinContent(36, (int)fDataType);
265     if(!fRandom) fRandom = new TRandom3(0);  // set randomizer and random seed
266     switch (fFitModulationType)  {
267         case kNoFit : { SetModulationFit(new TF1("fix_kNoFit", "[0]", 0, TMath::TwoPi())); } break;
268         case kV2 : {
269             SetModulationFit(new TF1("fit_kV2", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
270             fFitModulation->SetParameter(0, 0.);        // normalization
271             fFitModulation->SetParameter(3, 0.2);       // v2
272             fFitModulation->FixParameter(1, 1.);        // constant
273             fFitModulation->FixParameter(2, 2.);        // constant
274         } break;
275         case kV3: {
276             SetModulationFit(new TF1("fit_kV3", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
277             fFitModulation->SetParameter(0, 0.);        // normalization
278             fFitModulation->SetParameter(3, 0.2);       // v3
279             fFitModulation->FixParameter(1, 1.);        // constant
280             fFitModulation->FixParameter(2, 3.);        // constant
281         } break;
282         default : { // for the combined fit, the 'direct fourier series' or the user supplied vn values we use v2 and v3
283              SetModulationFit(new TF1("fit_kCombined", "[0]*([1]+[2]*([3]*TMath::Cos([2]*(x-[4]))+[7]*TMath::Cos([5]*(x-[6]))))", 0, TMath::TwoPi()));
284              fFitModulation->SetParameter(0, 0.);       // normalization
285              fFitModulation->SetParameter(3, 0.2);      // v2
286              fFitModulation->FixParameter(1, 1.);       // constant
287              fFitModulation->FixParameter(2, 2.);       // constant
288              fFitModulation->FixParameter(5, 3.);       // constant
289              fFitModulation->SetParameter(7, 0.2);      // v3
290         } break;
291     }
292     switch (fRunModeType) {
293         case kGrid : { fFitModulationOptions += "N0"; } break;
294         default : break;
295     }
296     FillAnalysisSummaryHistogram();
297     return kTRUE;
298 }
299 //_____________________________________________________________________________
300 TH1F* AliAnalysisTaskJetV2::BookTH1F(const char* name, const char* x, Int_t bins, Double_t min, Double_t max, Int_t c, Bool_t append)
301 {
302     // book a TH1F and connect it to the output container
303     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
304     if(fReduceBinsXByFactor > 0 ) bins = TMath::Nint(bins/fReduceBinsXByFactor);
305     if(!fOutputList) return 0x0;
306     TString title(name);
307     if(c!=-1) { // format centrality dependent histograms accordingly
308         name = Form("%s_%i", name, c);
309         title += Form("_%i-%i", (int)(fCentralityClasses->At(c)), (int)(fCentralityClasses->At((1+c))));
310     }
311     title += Form(";%s;[counts]", x);
312     TH1F* histogram = new TH1F(name, title.Data(), bins, min, max);
313     histogram->Sumw2();
314     if(append) fOutputList->Add(histogram);
315     return histogram;   
316 }
317 //_____________________________________________________________________________
318 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)
319 {
320     // book a TH2F and connect it to the output container
321     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
322     if(fReduceBinsXByFactor > 0 ) binsx = TMath::Nint(binsx/fReduceBinsXByFactor);
323     if(fReduceBinsYByFactor > 0 ) binsy = TMath::Nint(binsy/fReduceBinsYByFactor);
324     if(!fOutputList) return 0x0;
325     TString title(name);
326     if(c!=-1) { // format centrality dependent histograms accordingly
327         name = Form("%s_%i", name, c);
328         title += Form("_%i-%i", (int)fCentralityClasses->At(c), (int)(fCentralityClasses->At((1+c))));
329     }
330     title += Form(";%s;%s", x, y);
331     TH2F* histogram = new TH2F(name, title.Data(), binsx, minx, maxx, binsy, miny, maxy);
332     histogram->Sumw2();
333     if(append) fOutputList->Add(histogram);
334     return histogram;   
335 }
336 //_____________________________________________________________________________
337 void AliAnalysisTaskJetV2::UserCreateOutputObjects()
338 {
339     // create output objects. also initializes some default values in case they aren't 
340     // loaded via the AddTask macro
341     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
342     fOutputList = new TList();
343     fOutputList->SetOwner(kTRUE);
344     if(!fCentralityClasses) {   // classes must be defined at this point
345         Double_t c[] = {0., 20., 40., 60., 80., 100.};
346         fCentralityClasses = new TArrayD(sizeof(c)/sizeof(c[0]), c);
347     }
348     if(!fExpectedRuns) {        // expected runs must be defined at this point
349         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 */};
350         fExpectedRuns = new TArrayI(sizeof(r)/sizeof(r[0]), r);
351     }
352     // set default semi-good runs only for 11h data
353     switch (fCollisionType) {
354         case kPbPb10h : break;
355         default : {
356             if(!fExpectedSemiGoodRuns) {
357                 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};
358                 fExpectedSemiGoodRuns = new TArrayI(sizeof(r)/sizeof(r[0]), r);
359             }
360         }
361     }
362
363     // global QA
364     fHistCentrality =           BookTH1F("fHistCentrality", "centrality", 102, -2, 100);
365     fHistVertexz =              BookTH1F("fHistVertexz", "vertex z (cm)", 100, -12, 12);
366
367     // pico track and emcal cluster kinematics
368     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) { 
369         fHistPicoTrackPt[i] =           BookTH1F("fHistPicoTrackPt", "p_{t} [GeV/c]", 100, 0, 100, i);
370         fHistPicoTrackMult[i] =         BookTH1F("fHistPicoTrackMult", "multiplicity", 100, 0, 5000, i);
371         if(fFillQAHistograms) {
372             fHistPicoCat1[i] =          BookTH2F("fHistPicoCat1", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
373             fHistPicoCat2[i] =          BookTH2F("fHistPicoCat2", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
374             fHistPicoCat3[i] =          BookTH2F("fHistPicoCat3", "#eta", "#phi", 50, -1, 1, 50, 0, TMath::TwoPi(), i);
375             if(fAnalysisType == AliAnalysisTaskJetV2::kFull) {
376                 fHistClusterPt[i] =     BookTH1F("fHistClusterPt", "p_{t} [GeV/c]", 100, 0, 100, i);
377                 fHistClusterEtaPhi[i] = BookTH2F("fHistClusterEtaPhi", "#eta", "#phi", 100, -1., 1., 100, 0, TMath::TwoPi(), i);
378                 fHistClusterEtaPhiWeighted[i] =    BookTH2F("fHistClusterEtaPhiWeighted", "#eta", "#phi", 100, -1., 1., 100, 0, TMath::TwoPi(), i);
379             }
380         }
381     }
382
383     if(fFillQAHistograms) {
384         // event plane estimates and quality
385         fHistPsiControl =           new TProfile("fHistPsiControl", "fHistPsiControl", 10, 0, 10);
386         fHistPsiControl->Sumw2();
387         fHistPsiSpread =            new TProfile("fHistPsiSpread", "fHistPsiSpread", 4, 0, 4);
388         fHistPsiSpread->Sumw2();
389         fHistPsiControl->GetXaxis()->SetBinLabel(1, "<#Psi_{2, VZEROA}>");
390         fHistPsiControl->GetXaxis()->SetBinLabel(2, "<#Psi_{2, VZEROC}>");
391         fHistPsiControl->GetXaxis()->SetBinLabel(3, "<#Psi_{2, TPC}>");
392         fHistPsiControl->GetXaxis()->SetBinLabel(4, "<#Psi_{2, TPC, #eta < 0}>");
393         fHistPsiControl->GetXaxis()->SetBinLabel(5, "<#Psi_{2, TPC, #eta > 0}>");
394         fHistPsiControl->GetXaxis()->SetBinLabel(6, "<#Psi_{3, VZEROA}>");
395         fHistPsiControl->GetXaxis()->SetBinLabel(7, "<#Psi_{3, VZEROC}>");
396         fHistPsiControl->GetXaxis()->SetBinLabel(8, "<#Psi_{3, TPC}>");
397         fHistPsiControl->GetXaxis()->SetBinLabel(9, "<#Psi_{3, TPC, #eta < 0}>");
398         fHistPsiControl->GetXaxis()->SetBinLabel(10, "<#Psi_{3, TPC, #eta > 0}>");
399         fHistPsiSpread->GetXaxis()->SetBinLabel(1, "<#Psi_{2, VZEROA} - #Psi_{2, VZEROC}>");
400         fHistPsiSpread->GetXaxis()->SetBinLabel(2, "<#Psi_{2, VZEROC} - #Psi_{2, TPC}>");
401         fHistPsiSpread->GetXaxis()->SetBinLabel(3, "<#Psi_{2, VZEROC} - #Psi_{2, TPC}>");
402         fHistPsiSpread->GetXaxis()->SetBinLabel(4, "<#Psi_{2, TPC, #eta < 0} - #Psi_{2, TPC, #eta > 0}>");
403         fOutputList->Add(fHistPsiControl);
404         fOutputList->Add(fHistPsiSpread);
405         fHistPsiVZEROA =            BookTH1F("fHistPsiVZEROA", "#Psi_{VZEROA}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
406         fHistPsiVZEROC =            BookTH1F("fHistPsiVZEROC", "#Psi_{VZEROC}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
407         fHistPsiVZERO =             BookTH1F("fHistPsiVZERO", "#Psi_{VZERO}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
408         fHistPsiTPC =               BookTH1F("fHistPsiTPC", "#Psi_{TPC}", 40, -.5*TMath::Pi(), .5*TMath::Pi());
409         fHistPsiVZEROAV0M =         BookTH2F("fHistPsiVZEROAV0M", "V0M", "#Psi_{2, VZEROA}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
410         fHistPsiVZEROCV0M =         BookTH2F("fHistPsiVZEROCV0M", "V0M", "#Psi_{2, VZEROC}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
411         fHistPsiVZEROVV0M =         BookTH2F("fHistPsiVZEROV0M", "V0M", "#Psi_{2, VZERO}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
412         fHistPsiTPCiV0M =           BookTH2F("fHistPsiTPCV0M", "V0M", "#Psi_{2, TRK}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
413         fHistPsiVZEROATRK =         BookTH2F("fHistPsiVZEROATRK", "TRK", "#Psi_{2, VZEROA}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
414         fHistPsiVZEROCTRK =         BookTH2F("fHistPsiVZEROCTRK", "TRK", "#Psi_{2, VZEROC}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
415         fHistPsiVZEROTRK =          BookTH2F("fHistPsiVZEROTRK", "TRK", "#Psi_{2, VZERO}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
416         fHistPsiTPCTRK =            BookTH2F("fHistPsiTPCTRK", "TRK", "#Psi_{2, TRK}", 60, 0, 60, 40, -.5*TMath::Pi(), .5*TMath::Pi());
417     }
418     // background
419     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i ++) {
420         fHistRhoPackage[i] =           BookTH1F("fHistRhoPackage",  "#rho [GeV/c]", 100, 0, 150, i);
421         fHistRho[i] =                  BookTH1F("fHistRho", "#rho [GeV/c]", 100, 0, 150, i);
422     }
423     fHistRhoVsMult =            BookTH2F("fHistRhoVsMult", "multiplicity", "#rho [GeV/c]", 100, 0, 4000, 100, 0, 250);
424     fHistRhoVsCent =            BookTH2F("fHistRhoVsCent", "centrality", "#rho [GeV/c]", 100, 0, 100, 100, 0, 250);
425     fHistRhoAVsMult =           BookTH2F("fHistRhoAVsMult", "multiplicity", "#rho * A (jet) [GeV/c]", 100, 0, 4000, 100, 0, 50);
426     fHistRhoAVsCent =           BookTH2F("fHistRhoAVsCent", "centrality", "#rho * A (jet) [GeV/c]", 100, 0, 100, 100, 0, 50);
427
428     TString detector("");
429     switch (fDetectorType) {
430         case kTPC : detector+="TPC";
431             break;
432         case kVZEROA : detector+="VZEROA";
433             break;
434         case kVZEROC : detector+="VZEROC";
435             break;
436         case kVZEROComb : detector+="VZEROComb";
437             break; 
438         default: break;
439     }
440     // delta pt distributions
441     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i ++) {
442         if(fFillQAHistograms)   fHistRCPhiEta[i] = BookTH2F("fHistRCPhiEta", "#phi (RC)", "#eta (RC)", 40, 0, TMath::TwoPi(), 40, -1, 1, i);
443         fHistRhoVsRCPt[i] =            BookTH2F("fHistRhoVsRCPt", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
444         fHistRCPt[i] =                 BookTH1F("fHistRCPt", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
445         if(fFillQAHistograms)   fHistRCPhiEtaExLJ[i] = BookTH2F("fHistRCPhiEtaExLJ", "#phi (RC)", "#eta (RC)", 40, 0, TMath::TwoPi(), 40, -1, 1, i);
446         fHistDeltaPtDeltaPhi2[i] =  BookTH2F("fHistDeltaPtDeltaPhi2", Form("#phi - #Psi_{2, %s}", detector.Data()), "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
447         fHistDeltaPtDeltaPhi2Rho0[i] =  BookTH2F("fHistDeltaPtDeltaPhi2Rho0", Form("#phi - #Psi_{2, %s}", detector.Data()), "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
448         fHistRhoVsRCPtExLJ[i] =        BookTH2F("fHistRhoVsRCPtExLJ", "p_{t} (RC) [GeV/c]", "#rho * A (RC) [GeV/c]", 100, 0, 300, 100, 0, 350, i);
449         fHistRCPtExLJ[i] =             BookTH1F("fHistRCPtExLJ", "p_{t} (RC) [GeV/c]", 130, -20, 150, i);
450         fHistDeltaPtDeltaPhi2ExLJ[i] = BookTH2F("fHistDeltaPtDeltaPhi2ExLJ", Form("#phi - #Psi_{2, %s}", detector.Data()),  "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
451         fHistDeltaPtDeltaPhi2ExLJRho0[i] = BookTH2F("fHistDeltaPtDeltaPhi2ExLJRho0", Form("#phi - #Psi_{2, %s}", detector.Data()),  "#delta p_{t} [GeV/c]", 40, 0, TMath::Pi(), 400, -70, 130, i);
452         // jet histograms (after kinematic cuts)
453         fHistJetPtRaw[i] =             BookTH1F("fHistJetPtRaw", "p_{t, jet} RAW [GeV/c]", 200, -50, 150, i);
454         fHistJetPt[i] =                BookTH1F("fHistJetPt", "p_{t, jet} [GeV/c]", 350, -100, 250, i);
455         if(fFillQAHistograms)   fHistJetEtaPhi[i] =            BookTH2F("fHistJetEtaPhi", "#eta", "#phi", 100, -1, 1, 100, 0, TMath::TwoPi(), i);
456         fHistJetPtArea[i] =            BookTH2F("fHistJetPtArea", "p_{t, jet} [GeV/c]", "Area", 175, -100, 250, 30, 0, 0.9, i);
457         fHistJetPtEta[i] =             BookTH2F("fHistJetPtEta", "p_{t, jet} [GeV/c]", "Eta", 175, -100, 250, 30, -0.9, 0.9, i);
458         fHistJetPtConstituents[i] =    BookTH2F("fHistJetPtConstituents", "p_{t, jet} [GeV/c]", "Area", 350, -100, 250, 60, 0, 150, i);
459         fHistJetEtaRho[i] =            BookTH2F("fHistJetEtaRho", "#eta", "#rho", 100, -1, 1, 100, 0, 300, i);
460         // in plane and out of plane spectra
461         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);
462         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);
463         // profiles for all correlator permutations which are necessary to calculate each second and third order event plane resolution
464         fProfV2Resolution[i] = new TProfile(Form("fProfV2Resolution_%i", i), Form("fProfV2Resolution_%i", i), 11, -0.5, 10.5);
465         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(3, "<cos(2(#Psi_{VZEROA} - #Psi_{VZEROC}))>");
466         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(4, "<cos(2(#Psi_{VZEROC} - #Psi_{VZEROA}))>");
467         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(5, "<cos(2(#Psi_{VZEROA} - #Psi_{TPC}))>");
468         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(6, "<cos(2(#Psi_{TPC} - #Psi_{VZEROA}))>");
469         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(7, "<cos(2(#Psi_{VZEROC} - #Psi_{TPC}))>");
470         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(8, "<cos(2(#Psi_{TPC} - #Psi_{VZEROC}))>");
471         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(9, "<cos(2(#Psi_{VZERO} - #Psi_{TPC_A}))>");
472         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(10, "<cos(2(#Psi_{VZERO} - #Psi_{TPC_B}))>");
473         fProfV2Resolution[i]->GetXaxis()->SetBinLabel(11, "<cos(2(#Psi_{TPC_A} - #Psi_{TPC_B}))>");
474         fOutputList->Add(fProfV2Resolution[i]); 
475         fProfV3Resolution[i] = new TProfile(Form("fProfV3Resolution_%i", i), Form("fProfV3Resolution_%i", i), 11, -0.5, 10.5);
476         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(3, "<cos(3(#Psi_{VZEROA} - #Psi_{VZEROC}))>");
477         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(4, "<cos(3(#Psi_{VZEROC} - #Psi_{VZEROA}))>");
478         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(5, "<cos(3(#Psi_{VZEROA} - #Psi_{TPC}))>");
479         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(6, "<cos(3(#Psi_{TPC} - #Psi_{VZEROA}))>");
480         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(7, "<cos(3(#Psi_{VZEROC} - #Psi_{TPC}))>");
481         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(8, "<cos(3(#Psi_{TPC} - #Psi_{VZEROC}))>");
482         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(9, "<cos(3(#Psi_{VZERO} - #Psi_{TPC_A}))>");
483         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(10, "<cos(3(#Psi_{VZERO} - #Psi_{TPC_B}))>");
484         fProfV3Resolution[i]->GetXaxis()->SetBinLabel(11, "<cos(3(#Psi_{TPC_A} - #Psi_{TPC_B}))>");
485         fOutputList->Add(fProfV3Resolution[i]); 
486     }
487    // vn profile
488     Float_t temp[fCentralityClasses->GetSize()];
489     for(Int_t i(0); i < fCentralityClasses->GetSize(); i++) temp[i] = fCentralityClasses->At(i);
490     fProfV2 = new TProfile("fProfV2", "fProfV2", fCentralityClasses->GetSize()-1, temp);
491     fProfV3 = new TProfile("fProfV3", "fProfV3", fCentralityClasses->GetSize()-1, temp);
492     fOutputList->Add(fProfV2);
493     fOutputList->Add(fProfV3);
494     switch (fFitModulationType) {
495         case kQC2 : {
496             fProfV2Cumulant = new TProfile("fProfV2Cumulant", "fProfV2Cumulant", fCentralityClasses->GetSize()-1, temp);
497             fProfV3Cumulant = new TProfile("fProfV3Cumulant", "fProfV3Cumulant", fCentralityClasses->GetSize()-1, temp);
498             fOutputList->Add(fProfV2Cumulant);
499             fOutputList->Add(fProfV3Cumulant);
500         } break;
501         case kQC4 : {
502             fProfV2Cumulant = new TProfile("fProfV2Cumulant", "fProfV2Cumulant", fCentralityClasses->GetSize()-1, temp);
503             fProfV3Cumulant = new TProfile("fProfV3Cumulant", "fProfV3Cumulant", fCentralityClasses->GetSize()-1, temp);
504             fOutputList->Add(fProfV2Cumulant);
505             fOutputList->Add(fProfV3Cumulant);
506         } break;
507         default : break;
508     }
509     // for the histograms initialized below, binning is fixed to runnumbers or flags
510     fReduceBinsXByFactor = 1;
511     fReduceBinsYByFactor = 1;
512     if(fFillQAHistograms) {
513         fHistRunnumbersEta = new TH2F("fHistRunnumbersEta", "fHistRunnumbersEta", fExpectedRuns->GetSize()+1, -.5, fExpectedRuns->GetSize()+.5, 100, -1.1, 1.1);
514         fHistRunnumbersEta->Sumw2();
515         fOutputList->Add(fHistRunnumbersEta);
516         fHistRunnumbersPhi = new TH2F("fHistRunnumbersPhi", "fHistRunnumbersPhi", fExpectedRuns->GetSize()+1, -.5, fExpectedRuns->GetSize()+.5, 100, -0.2, TMath::TwoPi()+0.2);
517         fHistRunnumbersPhi->Sumw2();
518         fOutputList->Add(fHistRunnumbersPhi);
519         for(Int_t i(0); i < fExpectedRuns->GetSize(); i++) { 
520             fHistRunnumbersPhi->GetXaxis()->SetBinLabel(i+1, Form("%i", fExpectedRuns->At(i)));
521             fHistRunnumbersEta->GetXaxis()->SetBinLabel(i+1, Form("%i", fExpectedRuns->At(i)));
522         }
523         fHistRunnumbersPhi->GetXaxis()->SetBinLabel(fExpectedRuns->GetSize()+1, "undetermined");
524         fHistRunnumbersEta->GetXaxis()->SetBinLabel(fExpectedRuns->GetSize()+1, "undetermined");
525     }
526     fHistAnalysisSummary = BookTH1F("fHistAnalysisSummary", "flag", 54, -0.5, 54.5);
527     fHistSwap = new TH1F("fHistSwap", "fHistSwap", 20, 0, TMath::TwoPi());
528     if(fUsePtWeight) fHistSwap->Sumw2();
529
530     if(fUserSuppliedV2) fOutputList->Add(fUserSuppliedV2);
531     if(fUserSuppliedV3) fOutputList->Add(fUserSuppliedV3);
532     if(fUserSuppliedR2) fOutputList->Add(fUserSuppliedR2);
533     if(fUserSuppliedR3) fOutputList->Add(fUserSuppliedR3);
534     // increase readability of output list
535     fOutputList->Sort();
536     // cdf and pdf of chisquare distribution
537     fHistPvalueCDF = BookTH1F("fHistPvalueCDF", "CDF #chi^{2}", 50, 0, 1);
538     fHistPvalueCDFCent = BookTH2F("fHistPvalueCDFCent", "centrality", "p-value", 40, 0, 100, 40, 0, 1);
539     fHistChi2Cent = BookTH2F("fHistChi2Cent", "centrality", "#tilde{#chi^{2}}", 100, 0, 100, 100, 0, 5);
540     fHistPChi2 = BookTH2F("fHistPChi2", "p-value", "#tilde{#chi^{2}}", 1000, 0, 1, 100, 0, 5);
541     fHistKolmogorovTest = BookTH1F("fHistKolmogorovTest", "KolmogorovTest", 50, 0, 1);
542     fHistKolmogorovTestCent = BookTH2F("fHistKolmogorovTestCent", "centrality", "Kolmogorov p", 40, 0, 100, 45, 0, 1); 
543     fHistPvalueCDFROOT = BookTH1F("fHistPvalueCDFROOT", "CDF #chi^{2} ROOT", 50, 0, 1);
544     fHistPvalueCDFROOTCent = BookTH2F("fHistPvalueCDFROOTCent", "centrality", "p-value ROOT", 40, 0, 100, 45, 0, 1);
545     fHistChi2ROOTCent = BookTH2F("fHistChi2ROOTCent", "centrality", "#tilde{#chi^{2}}", 40, 0, 100, 45, 0, 5);
546     fHistPChi2Root = BookTH2F("fHistPChi2Root", "p-value", "#tilde{#chi^{2}} ROOT", 1000, 0, 1, 100, 0, 5);
547     fHistPKolmogorov = BookTH2F("fHistPKolmogorov", "p-value", "kolmogorov p",40, 0, 1, 40, 0, 1);
548     fHistRhoStatusCent = BookTH2F("fHistRhoStatusCent", "centrality", "status [-1=lin was better, 0=ok, 1 = failed]", 101, -1, 100, 3, -1.5, 1.5);
549     fHistUndeterminedRunQA = BookTH1F("fHistUndeterminedRunQA", "runnumber", 10, 0, 10);
550  
551     PostData(1, fOutputList);
552
553     switch (fRunModeType) {
554         case kLocal : {
555             fOutputListGood = new TList();
556             fOutputListGood->SetOwner(kTRUE);
557             fOutputListBad = new TList();
558             fOutputListBad->SetOwner(kTRUE);
559             PostData(2, fOutputListGood);
560             PostData(3, fOutputListBad);
561         } break;
562         default: break;
563     }
564
565     // get the containers
566     fTracksCont = GetParticleContainer("Tracks");
567     fClusterCont = GetClusterContainer(0);      // get the default cluster container
568     fJetsCont = GetJetContainer("Jets");
569 }
570 //_____________________________________________________________________________
571 Bool_t AliAnalysisTaskJetV2::Run()
572 {
573     // user exec: execute once for each event
574     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
575     if(!fTracks||!fJets||!fRho) return kFALSE;
576     if(!fLocalInit) fLocalInit = InitializeAnalysis();
577     // reject the event if expected data is missing
578     if(!PassesCuts(InputEvent())) return kFALSE;
579     fLeadingJet = GetLeadingJet();      // store the leading jet
580     // set the rho value 
581     fLocalRho->SetVal(fRho->GetVal());
582     // [0][0] psi2a     [1,0]   psi2c
583     // [0][1] psi3a     [1,1]   psi3c
584     Double_t vzero[2][2];
585     CalculateEventPlaneVZERO(vzero);
586     /* for the combined vzero event plane
587      * [0] psi2         [1] psi3
588      * not fully implmemented yet, use with caution ! */
589     Double_t vzeroComb[2];
590     CalculateEventPlaneCombinedVZERO(vzeroComb);
591     // [0] psi2         [1] psi3
592     Double_t tpc[2];
593     CalculateEventPlaneTPC(tpc);
594     Double_t psi2(-1), psi3(-1);
595     // arrays which will hold the fit parameters
596     switch (fDetectorType) {    // determine the detector type for the rho fit
597         case kTPC :     { psi2 = tpc[0];         psi3 = tpc[1]; }        break;
598         case kVZEROA :  { psi2 = vzero[0][0];    psi3 = vzero[0][1]; }   break;  
599         case kVZEROC :  { psi2 = vzero[1][0];    psi3 = vzero[1][1]; }   break;
600         case kVZEROComb : { psi2 = vzeroComb[0]; psi3 = vzeroComb[1];} break;
601         default : break;
602     }
603     switch (fFitModulationType) { // do the fits
604         case kNoFit : { 
605              switch (fCollisionType) {
606                  case kPythia : { // background is zero for pp jets
607                      fFitModulation->FixParameter(0, 0);
608                      fLocalRho->SetVal(0);
609                  } break;
610                  default :  {
611                      fFitModulation->FixParameter(0, fLocalRho->GetVal()); 
612                  } break;
613              }
614         } break;
615         case kV2 : {    // only v2
616             if(CorrectRho(psi2, psi3)) {
617                 fProfV2->Fill(fCent, fFitModulation->GetParameter(3));
618                 if(fUserSuppliedR2) {
619                     Double_t r(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
620                     if(r > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r);
621                 }
622                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
623             }
624         } break;
625         case kV3 : {    // only v3
626             if(CorrectRho(psi2, psi3)) {
627                 if(fUserSuppliedR3) {
628                     Double_t r(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
629                     if(r > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r);
630                 }
631                 fProfV3->Fill(fCent, fFitModulation->GetParameter(3));
632                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
633             }
634         } break;
635         case kQC2 : {   // qc2 analysis
636             if(CorrectRho(psi2, psi3)) {
637                 if(fUserSuppliedR2 && fUserSuppliedR3) {
638                     // note for the qc method, resolution is REVERSED to go back to v2obs
639                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
640                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
641                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)*r2);
642                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)*r3);
643                 }
644                 if (fUsePtWeight) { // use weighted weights
645                     Double_t dQCnM11 = (fNoEventWeightsForQC) ? 1. : QCnM11();
646                     fProfV2->Fill(fCent, fFitModulation->GetParameter(3), dQCnM11);
647                     fProfV3->Fill(fCent, fFitModulation->GetParameter(7), dQCnM11); 
648                 } else {
649                     Double_t dQCnM = (fNoEventWeightsForQC) ? 2. : QCnM();
650                     fProfV2->Fill(fCent, fFitModulation->GetParameter(3), dQCnM*(dQCnM-1));
651                     fProfV3->Fill(fCent, fFitModulation->GetParameter(7), dQCnM*(dQCnM-1));
652                 }
653                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
654             }
655         } break;
656         case kQC4 : {
657             if(CorrectRho(psi2, psi3)) {
658                 if(fUserSuppliedR2 && fUserSuppliedR3) {
659                     // note for the qc method, resolution is REVERSED to go back to v2obs   
660                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
661                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
662                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)*r2);
663                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)*r3);
664                 }
665                 if (fUsePtWeight) { // use weighted weights
666                     fProfV2->Fill(fCent, TMath::Power(fFitModulation->GetParameter(3),0.5)/*, QCnM1111()*/);
667                     fProfV3->Fill(fCent, TMath::Power(fFitModulation->GetParameter(7),0.5)/*, QCnM1111()*/); 
668                 } else {
669                     fProfV2->Fill(fCent, TMath::Power(fFitModulation->GetParameter(3),0.5)/*, QCnM()*(QCnM()-1)*(QCnM()-2)*(QCnM()-3)*/);
670                     fProfV3->Fill(fCent, TMath::Power(fFitModulation->GetParameter(7),0.5)/*, QCnM()*(QCnM()-1)*(QCnM()-2)*(QCnM()-3)*/);
671                 }
672             }
673             CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
674         } break;
675         default : {
676             if(CorrectRho(psi2, psi3)) {
677                 if(fUserSuppliedR2 && fUserSuppliedR3) {
678                     Double_t r2(fUserSuppliedR2->GetBinContent(fUserSuppliedR2->GetXaxis()->FindBin(fCent)));
679                     Double_t r3(fUserSuppliedR3->GetBinContent(fUserSuppliedR3->GetXaxis()->FindBin(fCent)));
680                     if(r2 > 0) fFitModulation->SetParameter(3, fFitModulation->GetParameter(3)/r2);
681                     if(r3 > 0) fFitModulation->SetParameter(7, fFitModulation->GetParameter(7)/r3);
682                 }
683                 fProfV2->Fill(fCent, fFitModulation->GetParameter(3));
684                 fProfV3->Fill(fCent, fFitModulation->GetParameter(7));
685                 CalculateEventPlaneResolution(vzero, vzeroComb, tpc);
686             }
687         } break;
688     }
689     // if all went well, update the local rho parameter
690     fLocalRho->SetLocalRho(fFitModulation);
691     // fill a number of histograms. event qa needs to be filled first as it also determines the runnumber for the track qa 
692     if(fFillQAHistograms)       FillQAHistograms(InputEvent());
693     if(fFillHistograms)         FillHistogramsAfterSubtraction(psi2, vzero, vzeroComb, tpc);
694     // send the output to the connected output container
695     PostData(1, fOutputList);
696     switch (fRunModeType) {
697         case kLocal : {
698             PostData(2, fOutputListGood);
699             PostData(3, fOutputListBad);
700         } break;
701         default: break;
702     }
703
704     return kTRUE;
705 }
706 //_____________________________________________________________________________
707 void AliAnalysisTaskJetV2::CalculateEventPlaneVZERO(Double_t vzero[2][2]) const 
708 {
709     // get the vzero event plane
710     if(fUseV0EventPlaneFromHeader) {    // use the vzero from the header
711         Double_t a(0), b(0), c(0), d(0), e(0), f(0), g(0), h(0);
712         vzero[0][0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 2, a, b);
713         vzero[1][0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 2, c, d);
714         vzero[0][1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 8, 3, e, f);
715         vzero[1][1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 9, 3, g, h);
716         return;
717     }
718     // grab the vzero event plane without recentering
719     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
720     Double_t qxa2(0), qya2(0), qxc2(0), qyc2(0);    // for psi2
721     Double_t qxa3(0), qya3(0), qxc3(0), qyc3(0);    // for psi3
722     for(Int_t iVZERO(0); iVZERO < 64; iVZERO++) {
723         Double_t phi(TMath::PiOver4()*(.5+iVZERO%8)), /* eta(0), */ weight(InputEvent()->GetVZEROEqMultiplicity(iVZERO));
724         if(iVZERO<32) {
725             qxa2 += weight*TMath::Cos(2.*phi);
726             qya2 += weight*TMath::Sin(2.*phi);
727             qxa3 += weight*TMath::Cos(3.*phi);
728             qya3 += weight*TMath::Sin(3.*phi);
729         }
730         else {
731             qxc2 += weight*TMath::Cos(2.*phi);
732             qyc2 += weight*TMath::Sin(2.*phi);
733             qxc3 += weight*TMath::Cos(3.*phi);
734             qyc3 += weight*TMath::Sin(3.*phi);
735        }
736     }
737     vzero[0][0] = .5*TMath::ATan2(qya2, qxa2);
738     vzero[1][0] = .5*TMath::ATan2(qyc2, qxc2);
739     vzero[0][1] = (1./3.)*TMath::ATan2(qya3, qxa3);
740     vzero[1][1] = (1./3.)*TMath::ATan2(qyc3, qxc3);
741 }
742 //_____________________________________________________________________________
743 void AliAnalysisTaskJetV2::CalculateEventPlaneTPC(Double_t* tpc)
744 {
745    // grab the TPC event plane
746    if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
747    fNAcceptedTracks = 0;                // reset the track counter
748    Double_t qx2(0), qy2(0);     // for psi2
749    Double_t qx3(0), qy3(0);     // for psi3
750    if(fTracksCont) {
751        Float_t excludeInEta = -999;
752        if(fExcludeLeadingJetsFromFit > 0 ) {    // remove the leading jet from ep estimate
753            if(fLeadingJet) excludeInEta = fLeadingJet->Eta();
754        }
755        for(Int_t iTPC(0); iTPC < fTracksCont->GetNEntries(); iTPC++) {
756            AliVParticle* track = fTracksCont->GetParticle(iTPC);
757            if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
758            if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta) < GetJetContainer()->GetJetRadius()*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - GetJetContainer()->GetJetRadius() - GetJetContainer()->GetJetEtaMax() ) > 0 )) continue;
759            fNAcceptedTracks++;
760            qx2+= TMath::Cos(2.*track->Phi());
761            qy2+= TMath::Sin(2.*track->Phi());
762            qx3+= TMath::Cos(3.*track->Phi());
763            qy3+= TMath::Sin(3.*track->Phi());
764        }
765    }
766    tpc[0] = .5*TMath::ATan2(qy2, qx2);
767    tpc[1] = (1./3.)*TMath::ATan2(qy3, qx3);
768
769 //_____________________________________________________________________________
770 void AliAnalysisTaskJetV2::CalculateEventPlaneCombinedVZERO(Double_t* comb) const
771 {
772     // grab the combined vzero event plane
773     Double_t a(0), b(0), c(0), d(0);
774     comb[0] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 10, 2, a, b);
775     comb[1] = InputEvent()->GetEventplane()->CalculateVZEROEventPlane(InputEvent(), 10, 3, c, d);
776 }
777 //_____________________________________________________________________________
778 void AliAnalysisTaskJetV2::CalculateEventPlaneResolution(Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc)
779 {
780     // fill the profiles for the resolution parameters
781     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
782     fProfV2Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(2.*(vzero[0][0] - vzero[1][0])));
783     fProfV2Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(2.*(vzero[1][0] - vzero[0][0])));
784     fProfV2Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(2.*(vzero[0][0] - tpc[0])));
785     fProfV2Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(2.*(tpc[0] - vzero[0][0])));
786     fProfV2Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(2.*(vzero[1][0] - tpc[0])));
787     fProfV2Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(2.*(tpc[0] - vzero[1][0])));
788     fProfV3Resolution[fInCentralitySelection]->Fill(2., TMath::Cos(3.*(vzero[0][0] - vzero[1][0])));
789     fProfV3Resolution[fInCentralitySelection]->Fill(3., TMath::Cos(3.*(vzero[1][0] - vzero[0][0])));
790     fProfV3Resolution[fInCentralitySelection]->Fill(4., TMath::Cos(3.*(vzero[0][0] - tpc[0])));
791     fProfV3Resolution[fInCentralitySelection]->Fill(5., TMath::Cos(3.*(tpc[0] - vzero[0][0])));
792     fProfV3Resolution[fInCentralitySelection]->Fill(6., TMath::Cos(3.*(vzero[1][0] - tpc[0])));
793     fProfV3Resolution[fInCentralitySelection]->Fill(7., TMath::Cos(3.*(tpc[0] - vzero[1][0])));
794     // for the resolution of the combined vzero event plane, use two tpc halves as uncorrelated subdetectors
795     Double_t qx2a(0), qy2a(0);     // for psi2a, negative eta
796     Double_t qx3a(0), qy3a(0);     // for psi3a, negative eta
797     Double_t qx2b(0), qy2b(0);     // for psi2a, positive eta
798     Double_t qx3b(0), qy3b(0);     // for psi3a, positive eta
799     if(fTracks) {
800        Int_t iTracks(fTracks->GetEntriesFast());
801        for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
802            AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
803            if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
804            if(track->Eta() < 0 ) {
805                qx2a+= TMath::Cos(2.*track->Phi());
806                qy2a+= TMath::Sin(2.*track->Phi());
807                qx3a+= TMath::Cos(3.*track->Phi());
808                qy3a+= TMath::Sin(3.*track->Phi());
809            } else if (track->Eta() > 0) {
810                qx2b+= TMath::Cos(2.*track->Phi());
811                qy2b+= TMath::Sin(2.*track->Phi());
812                qx3b+= TMath::Cos(3.*track->Phi());
813                qy3b+= TMath::Sin(3.*track->Phi());
814            }
815        }
816    }
817    Double_t tpca2(.5*TMath::ATan2(qy2a, qx2a));
818    Double_t tpca3((1./3.)*TMath::ATan2(qy3a, qx3a));
819    Double_t tpcb2(.5*TMath::ATan2(qy2b, qx2b));
820    Double_t tpcb3((1./3.)*TMath::ATan2(qy3b, qx3b));
821    fProfV2Resolution[fInCentralitySelection]->Fill(8., TMath::Cos(2.*(vzeroComb[0] - tpca2)));
822    fProfV2Resolution[fInCentralitySelection]->Fill(9., TMath::Cos(2.*(vzeroComb[0] - tpcb2)));
823    fProfV2Resolution[fInCentralitySelection]->Fill(10., TMath::Cos(2.*(tpca2 - tpcb2))); 
824    fProfV3Resolution[fInCentralitySelection]->Fill(8., TMath::Cos(3.*(vzeroComb[1] - tpca3)));
825    fProfV3Resolution[fInCentralitySelection]->Fill(9., TMath::Cos(3.*(vzeroComb[1] - tpcb3)));
826    fProfV3Resolution[fInCentralitySelection]->Fill(10., TMath::Cos(3.*(tpca3 - tpcb3))); 
827 }   
828 //_____________________________________________________________________________
829 void AliAnalysisTaskJetV2::CalculateRandomCone(Float_t &pt, Float_t &eta, Float_t &phi, 
830         AliParticleContainer* tracksCont, AliClusterContainer* clusterCont, AliEmcalJet* jet) const
831 {
832     // get a random cone
833     if(fDebug > 1) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
834     pt = 0; eta = 0; phi = 0;
835     Float_t etaJet(999), phiJet(999), dJet(999);        // no jet: same as jet very far away
836     if(jet) { // if a leading jet is given, use its kinematic properties to exclude it
837         etaJet = jet->Eta();
838         phiJet = jet->Phi();
839     }
840     // the random cone acceptance has to equal the jet acceptance
841     // this also insures safety when runnnig on the semi-good tpc runs for 11h data,
842     // where jet acceptance is adjusted to reduced acceptance - hence random cone acceptance as well
843     Float_t minPhi(GetJetContainer()->GetJetPhiMin()), maxPhi(GetJetContainer()->GetJetPhiMax());
844     if(maxPhi > TMath::TwoPi()) maxPhi = TMath::TwoPi();
845     if(minPhi < 0 ) minPhi = 0.;
846     // construct a random cone and see if it's far away enough from the leading jet
847     Int_t attempts(1000);
848     while(kTRUE) {
849         attempts--;
850         eta = gRandom->Uniform(GetJetContainer()->GetJetEtaMin(), GetJetContainer()->GetJetEtaMax());
851         phi = gRandom->Uniform(minPhi, maxPhi);
852
853         dJet = TMath::Sqrt((etaJet-eta)*(etaJet-eta)+(phiJet-phi)*(phiJet-phi));
854         if(dJet > fMinDisanceRCtoLJ) break;
855         else if (attempts == 0) {
856             printf(" > No random cone after 1000 tries, giving up ... !\n");
857             return;
858         }
859     }
860     // get the charged energy (if tracks are provided)
861     if(tracksCont) {
862         AliVParticle* track = tracksCont->GetNextAcceptParticle(0);
863         while(track) {
864             Float_t etaTrack(track->Eta()), phiTrack(track->Phi());
865             // get distance from cone
866             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi + TMath::TwoPi())) phiTrack+=TMath::TwoPi();
867             if(TMath::Abs(phiTrack-phi) > TMath::Abs(phiTrack - phi - TMath::TwoPi())) phiTrack-=TMath::TwoPi();
868             if(TMath::Sqrt(TMath::Abs((etaTrack-eta)*(etaTrack-eta)+(phiTrack-phi)*(phiTrack-phi))) <= GetJetRadius()) pt += track->Pt();
869             track = tracksCont->GetNextAcceptParticle();
870         }
871     }
872     // get the neutral energy (if clusters are provided)
873     if(clusterCont) {
874         AliVCluster* cluster = clusterCont->GetNextAcceptCluster(0);
875         while(cluster) {
876             TLorentzVector momentum;
877             cluster->GetMomentum(momentum, const_cast<Double_t*>(fVertex));
878             Float_t etaClus(momentum.Eta()), phiClus(momentum.Phi());
879             // get distance from cone
880             if(TMath::Abs(phiClus-phi) > TMath::Abs(phiClus - phi + TMath::TwoPi())) phiClus+=TMath::TwoPi();
881             if(TMath::Abs(phiClus-phi) > TMath::Abs(phiClus - phi - TMath::TwoPi())) phiClus-=TMath::TwoPi();
882             if(TMath::Sqrt(TMath::Abs((etaClus-eta)*(etaClus-eta)+(phiClus-phi)*(phiClus-phi))) <= GetJetRadius()) pt += momentum.Pt();
883             cluster = clusterCont->GetNextAcceptCluster();
884         }
885     }
886 }
887 //_____________________________________________________________________________
888 Double_t AliAnalysisTaskJetV2::CalculateQC2(Int_t harm) {
889     // get the second order q-cumulant, a -999 return will be caught in the qa routine of CorrectRho
890     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
891     Double_t reQ(0), imQ(0), modQ(0), M11(0), M(0);
892     if(fUsePtWeight) {  // for the weighted 2-nd order q-cumulant
893         QCnQnk(harm, 1, reQ, imQ);      // get the weighted 2-nd order q-vectors
894         modQ = reQ*reQ+imQ*imQ;         // get abs Q-squared
895         M11 = QCnM11();                 // equals S2,1 - S1,2
896         return (M11 > 0) ? ((modQ - QCnS(1,2))/M11) : -999;
897     } // else return the non-weighted 2-nd order q-cumulant
898     QCnQnk(harm, 0, reQ, imQ);          // get the non-weighted 2-nd order q-vectors
899     modQ = reQ*reQ+imQ*imQ;             // get abs Q-squared
900     M = QCnM();
901     return (M > 1) ? (modQ - M)/(M*(M-1)) : -999;
902 }
903 //_____________________________________________________________________________
904 Double_t AliAnalysisTaskJetV2::CalculateQC4(Int_t harm) {
905     // get the fourth order q-cumulant, a -999 return will be caught in the qa routine of CorrectRho
906     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
907     Double_t reQn1(0), imQn1(0), reQ2n2(0), imQ2n2(0), reQn3(0), imQn3(0), M1111(0), M(0);
908     Double_t a(0), b(0), c(0), d(0), e(0), f(0), g(0);  // terms of the calculation
909     if(fUsePtWeight) {  // for the weighted 4-th order q-cumulant
910         QCnQnk(harm, 1, reQn1, imQn1);
911         QCnQnk(harm*2, 2, reQ2n2, imQ2n2);
912         QCnQnk(harm, 3, reQn3, imQn3);
913         // fill in the terms ...
914         a = (reQn1*reQn1+imQn1*imQn1)*(reQn1*reQn1+imQn1*imQn1);
915         b = reQ2n2*reQ2n2 + imQ2n2*imQ2n2;
916         c = -2.*(reQ2n2*reQn1*reQn1-reQ2n2*imQn1*imQn1+2.*imQ2n2*reQn1*imQn1);
917         d = 8.*(reQn3*reQn1+imQn3*imQn1);
918         e = -4.*QCnS(1,2)*(reQn1*reQn1+imQn1*imQn1);
919         f = -6.*QCnS(1,4);
920         g = 2.*QCnS(2,2);
921         M1111 = QCnM1111();
922         return (M1111 > 0) ? (a+b+c+d+e+f+g)/M1111 : -999;
923     }   // else return the unweighted case
924     Double_t reQn(0), imQn(0), reQ2n(0), imQ2n(0);
925     QCnQnk(harm, 0, reQn, imQn);
926     QCnQnk(harm*2, 0, reQ2n, imQ2n);
927     // fill in the terms ...
928     M = QCnM();
929     if(M < 4) return -999;
930     a = (reQn*reQn+imQn*imQn)*(reQn*reQn+imQn*imQn);
931     b = reQ2n*reQ2n + imQ2n*imQ2n;
932     c = -2.*(reQ2n*reQn*reQn-reQ2n*imQn*imQn+2.*imQ2n*reQn*imQn);
933     e = -4.*(M-2)*(reQn*reQn+imQn*imQn);
934     f = 2.*M*(M-3);
935     return (a+b+c+e+f)/(M*(M-1)*(M-2)*(M-3));
936 }
937 //_____________________________________________________________________________
938 void AliAnalysisTaskJetV2::QCnQnk(Int_t n, Int_t k, Double_t &reQ, Double_t &imQ) {
939     // get the weighted n-th order q-vector, pass real and imaginary part as reference
940     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
941     if(!fTracks) return;
942     fNAcceptedTracksQCn = 0;
943     Int_t iTracks(fTracks->GetEntriesFast());
944     for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
945         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
946         if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
947         fNAcceptedTracksQCn++;
948         // for the unweighted case, k equals zero and the weight doesn't contribute to the equation below
949         reQ += TMath::Power(track->Pt(), k) * TMath::Cos(((double)n)*track->Phi());
950         imQ += TMath::Power(track->Pt(), k) * TMath::Sin(((double)n)*track->Phi());
951     }
952 }
953 //_____________________________________________________________________________
954 void AliAnalysisTaskJetV2::QCnDiffentialFlowVectors(
955         TClonesArray* pois, TArrayD* ptBins, Bool_t vpart, Double_t* repn, Double_t* impn, 
956         Double_t *mp, Double_t *reqn, Double_t *imqn, Double_t* mq, Int_t n) 
957 {
958     // get  unweighted differential flow vectors
959     Int_t iPois(pois->GetEntriesFast());
960     if(vpart) {
961         for(Int_t i(0); i < iPois; i++) {
962             for(Int_t ptBin(0); ptBin < ptBins->GetSize()-1; ptBin++) {
963                 AliVTrack* poi = static_cast<AliVTrack*>(pois->At(i));
964                 if(PassesCuts(poi)) {
965                     if(poi->Pt() >= ptBins->At(ptBin) && poi->Pt() < ptBins->At(ptBin+1)) {
966                             // fill the flow vectors assuming that all poi's are in the rp selection (true by design)
967                             repn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
968                             impn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
969                             mp[ptBin]++;
970                             reqn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
971                             imqn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
972                             mq[ptBin]++;
973                     }
974                 }
975             }
976         }
977     } else {
978         for(Int_t i(0); i < iPois; i++) {
979             for(Int_t ptBin(0); ptBin < ptBins->GetSize()-1; ptBin++) {
980                 AliEmcalJet* poi = static_cast<AliEmcalJet*>(pois->At(i));
981                 if(PassesCuts(poi)) {    
982                     Double_t pt(poi->Pt()-poi->Area()*fLocalRho->GetLocalVal(poi->Phi(), GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
983                     if(pt >= ptBins->At(ptBin) && pt < ptBins->At(ptBin+1)) {    
984                             repn[ptBin]+=TMath::Cos(((double)n)*poi->Phi());
985                             impn[ptBin]+=TMath::Sin(((double)n)*poi->Phi());
986                             mp[ptBin]++;        // qn isn't filled, no overlap between poi's and rp's
987                     }
988                 }
989             }
990         }
991     }
992 }
993 //_____________________________________________________________________________
994 Double_t AliAnalysisTaskJetV2::QCnS(Int_t i, Int_t j) {
995     // get the weighted ij-th order autocorrelation correction
996     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
997     if(!fTracks || i <= 0 || j <= 0) return -999;
998     Int_t iTracks(fTracks->GetEntriesFast());
999     Double_t Sij(0);
1000     for(Int_t iTPC(0); iTPC < iTracks; iTPC++) {
1001         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(iTPC));
1002         if(!PassesCuts(track) || track->Pt() < fSoftTrackMinPt || track->Pt() > fSoftTrackMaxPt) continue;
1003         Sij+=TMath::Power(track->Pt(), j);
1004     }
1005     return TMath::Power(Sij, i);
1006 }
1007 //_____________________________________________________________________________
1008 Double_t AliAnalysisTaskJetV2::QCnM() {
1009     // get multiplicity for unweighted q-cumulants. function QCnQnk should be called first
1010     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1011     return (Double_t) fNAcceptedTracksQCn;
1012 }
1013 //_____________________________________________________________________________
1014 Double_t AliAnalysisTaskJetV2::QCnM11() {
1015     // get multiplicity weights for the weighted two particle cumulant
1016     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1017     return (QCnS(2,1) - QCnS(1,2));
1018 }
1019 //_____________________________________________________________________________
1020 Double_t AliAnalysisTaskJetV2::QCnM1111() {
1021     // get multiplicity weights for the weighted four particle cumulant
1022     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1023     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));
1024 }
1025 //_____________________________________________________________________________
1026 Bool_t AliAnalysisTaskJetV2::QCnRecovery(Double_t psi2, Double_t psi3) {
1027     // decides how to deal with the situation where c2 or c3 is negative 
1028     // returns kTRUE depending on whether or not a modulated rho is used for the jet background
1029     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1030     if(TMath::AreEqualAbs(fFitModulation->GetParameter(3), .0, 1e-10) && TMath::AreEqualAbs(fFitModulation->GetParameter(7), .0,1e-10)) {
1031         fFitModulation->SetParameter(7, 0);
1032         fFitModulation->SetParameter(3, 0);
1033         fFitModulation->SetParameter(0, fLocalRho->GetVal());
1034         return kTRUE;   // v2 and v3 have physical null values
1035     }
1036     switch (fQCRecovery) {
1037         case kFixedRho : {      // roll back to the original rho
1038            fFitModulation->SetParameter(7, 0);
1039            fFitModulation->SetParameter(3, 0);
1040            fFitModulation->SetParameter(0, fLocalRho->GetVal());
1041            return kFALSE;       // rho is forced to be fixed
1042         }
1043         case kNegativeVn : {
1044            Double_t c2(fFitModulation->GetParameter(3));
1045            Double_t c3(fFitModulation->GetParameter(7));
1046            if( c2 < 0 ) c2 = -1.*TMath::Sqrt(-1.*c2);
1047            if( c3 < 0 ) c3 = -1.*TMath::Sqrt(-1.*c3);
1048            fFitModulation->SetParameter(3, c2);
1049            fFitModulation->SetParameter(7, c3);
1050            return kTRUE;        // is this a physical quantity ?
1051         }
1052         case kTryFit : {
1053            fitModulationType tempType(fFitModulationType);  // store temporarily
1054            fFitModulationType = kCombined;
1055            fFitModulation->SetParameter(7, 0);
1056            fFitModulation->SetParameter(3, 0);
1057            Bool_t pass(CorrectRho(psi2, psi3));         // do the fit and all quality checks
1058            fFitModulationType = tempType;               // roll back for next event
1059            return pass;
1060         }
1061         default : return kFALSE;
1062     }
1063     return kFALSE;
1064 }
1065 //_____________________________________________________________________________
1066 Bool_t AliAnalysisTaskJetV2::CorrectRho(Double_t psi2, Double_t psi3) 
1067 {
1068     // get rho' -> rho(phi)
1069     // two routines are available, both can be used with or without pt weights
1070     //  [1] get vn from q-cumulants or as an integrated value from a user supplied histogram
1071     //      in case of cumulants, both cumulants and vn values are stored. in both cases, v2 and v3
1072     //      are expected. a check is performed to see if rho has no negative local minimum
1073     //      for full description, see Phys. Rev. C 83, 044913
1074     //      since the cn distribution has negative values, vn = sqrt(cn) can be imaginary sometimes
1075     //      in this case one can either roll back to the 'original' rixed rho, do a fit for vn or take use
1076     //      vn = - sqrt(|cn|) 
1077     //  [2] fitting a fourier expansion to the de/dphi distribution
1078     //      the fit can be done with either v2, v3 or a combination.
1079     //      in all cases, a cut can be made on the p-value of the chi-squared value of the fit
1080     //      and a check can be performed to see if rho has no negative local minimum
1081     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1082     Int_t freeParams(2);                // free parameters of the fit (for NDF) 
1083     switch (fFitModulationType) {       // for approaches where no fitting is required
1084         case kQC2 : {
1085             fFitModulation->FixParameter(4, psi2); 
1086             fFitModulation->FixParameter(6, psi3);
1087             fFitModulation->FixParameter(3, CalculateQC2(2));   // set here with cn, vn = sqrt(cn)
1088             fFitModulation->FixParameter(7, CalculateQC2(3));
1089             // first fill the histos of the raw cumulant distribution
1090             if (fUsePtWeight) { // use weighted weights
1091                 Double_t dQCnM11 = (fNoEventWeightsForQC) ? 1. : QCnM11();
1092                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3), dQCnM11);
1093                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7), dQCnM11);
1094             } else {
1095                 Double_t dQCnM = (fNoEventWeightsForQC) ? 2. : QCnM();
1096                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3), dQCnM*(dQCnM-1));
1097                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7), dQCnM*(dQCnM-1));
1098             }
1099             // then see if one of the cn value is larger than zero and vn is readily available
1100             if(fFitModulation->GetParameter(3) > 0 && fFitModulation->GetParameter(7) > 0) {
1101                 fFitModulation->FixParameter(3, TMath::Sqrt(fFitModulation->GetParameter(3)));
1102                 fFitModulation->FixParameter(7, TMath::Sqrt(fFitModulation->GetParameter(7)));
1103             } else if (!QCnRecovery(psi2, psi3)) return kFALSE;  // try to recover the cumulant, this will set v2 and v3
1104             if(fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) {  // general check 
1105                 fFitModulation->SetParameter(7, 0);
1106                 fFitModulation->SetParameter(3, 0);
1107                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1108                 return kFALSE;
1109             }
1110             return kTRUE;
1111         } break;
1112         case kQC4 : {
1113             fFitModulation->FixParameter(4, psi2); 
1114             fFitModulation->FixParameter(6, psi3);
1115             fFitModulation->FixParameter(3, CalculateQC4(2));   // set here with cn, vn = sqrt(cn)
1116             fFitModulation->FixParameter(7, CalculateQC4(3));
1117             // first fill the histos of the raw cumulant distribution
1118             if (fUsePtWeight) { // use weighted weights
1119                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3)/*, QCnM1111()*/);
1120                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7)/*, QCnM1111()*/);
1121             } else {
1122                 fProfV2Cumulant->Fill(fCent, fFitModulation->GetParameter(3)/*, QCnM1111()*/);
1123                 fProfV3Cumulant->Fill(fCent, fFitModulation->GetParameter(7)/*, QCnM1111()*/);
1124             }
1125             // then see if one of the cn value is larger than zero and vn is readily available
1126             if(fFitModulation->GetParameter(3) > 0 && fFitModulation->GetParameter(7) > 0) {
1127                 fFitModulation->FixParameter(3, TMath::Sqrt(fFitModulation->GetParameter(3)));
1128                 fFitModulation->FixParameter(7, TMath::Sqrt(fFitModulation->GetParameter(7)));
1129             } else if (!QCnRecovery(psi2, psi3)) return kFALSE;  // try to recover the cumulant, this will set v2 and v3
1130             if(fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) {  // general check 
1131                 fFitModulation->SetParameter(7, 0);
1132                 fFitModulation->SetParameter(3, 0);
1133                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1134                 return kFALSE;
1135             }
1136         } break;
1137         case kIntegratedFlow : {
1138             // use v2 and v3 values from an earlier iteration over the data
1139             fFitModulation->FixParameter(3, fUserSuppliedV2->GetBinContent(fUserSuppliedV2->GetXaxis()->FindBin(fCent)));
1140             fFitModulation->FixParameter(4, psi2);
1141             fFitModulation->FixParameter(6, psi3);
1142             fFitModulation->FixParameter(7, fUserSuppliedV3->GetBinContent(fUserSuppliedV3->GetXaxis()->FindBin(fCent)));
1143             if(fFitModulation->GetMinimum(0, TMath::TwoPi()) < 0) { 
1144                 fFitModulation->SetParameter(7, 0);
1145                 fFitModulation->SetParameter(3, 0);
1146                 fFitModulation->SetParameter(0, fLocalRho->GetVal());
1147                 return kFALSE;
1148             }
1149             return kTRUE;
1150         }
1151         default : break;
1152     }
1153     TString detector("");
1154     switch (fDetectorType) {
1155         case kTPC : detector+="TPC";
1156             break;
1157         case kVZEROA : detector+="VZEROA";
1158             break;
1159         case kVZEROC : detector+="VZEROC";
1160             break;
1161         case kVZEROComb : detector+="VZEROComb";
1162             break; 
1163         default: break;
1164     }
1165     Int_t iTracks(fTracks->GetEntriesFast());
1166     Double_t excludeInEta = -999;
1167     Double_t excludeInPhi = -999;
1168     Double_t excludeInPt  = -999;
1169     if(iTracks <= 0 || fLocalRho->GetVal() <= 0 ) return kFALSE;   // no use fitting an empty event ...
1170     if(fExcludeLeadingJetsFromFit > 0 ) {
1171         if(fLeadingJet) {
1172             excludeInEta = fLeadingJet->Eta();
1173             excludeInPhi = fLeadingJet->Phi();
1174             excludeInPt = fLeadingJet->Pt();
1175         }
1176     }
1177     // check the acceptance of the track selection that will be used
1178     // if one uses e.g. semi-good tpc tracks, accepance in phi is reduced to 0 < phi < 4
1179     // the defaults (-10 < phi < 10) which accept all, are then overwritten
1180     Double_t lowBound(0.), upBound(TMath::TwoPi());     // bounds for fit
1181     if(GetParticleContainer()->GetParticlePhiMin() > lowBound) lowBound = GetParticleContainer()->GetParticlePhiMin();
1182     if(GetParticleContainer()->GetParticlePhiMax() < upBound) upBound = GetParticleContainer()->GetParticlePhiMax();
1183
1184     fHistSwap->Reset();                 // clear the histogram
1185     TH1F _tempSwap;     // on stack for quick access
1186     TH1F _tempSwapN;    // on stack for quick access, bookkeeping histogram
1187     if(fRebinSwapHistoOnTheFly) {
1188         if(fNAcceptedTracks < 49) fNAcceptedTracks = 49;       // avoid aliasing effects
1189         _tempSwap = TH1F("_tempSwap", "_tempSwap", TMath::CeilNint(TMath::Sqrt(fNAcceptedTracks)), lowBound, upBound);
1190         if(fUsePtWeightErrorPropagation) _tempSwapN = TH1F("_tempSwapN", "_tempSwapN", TMath::CeilNint(TMath::Sqrt(fNAcceptedTracks)), lowBound, upBound);
1191         if(fUsePtWeight) _tempSwap.Sumw2();
1192     }
1193     else _tempSwap = *fHistSwap;         // now _tempSwap holds the desired histo
1194     // non poissonian error when using pt weights
1195     Double_t totalpts(0.), totalptsquares(0.), totalns(0.);
1196     for(Int_t i(0); i < iTracks; i++) {
1197             AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1198             if(fExcludeLeadingJetsFromFit > 0 &&( (TMath::Abs(track->Eta() - excludeInEta) < GetJetContainer()->GetJetRadius()*fExcludeLeadingJetsFromFit ) || (TMath::Abs(track->Eta()) - GetJetContainer()->GetJetRadius() - GetJetContainer()->GetJetEtaMax() ) > 0 )) continue;
1199             if(!PassesCuts(track) || track->Pt() > fSoftTrackMaxPt || track->Pt() < fSoftTrackMinPt) continue;
1200             if(fUsePtWeight) {
1201                 _tempSwap.Fill(track->Phi(), track->Pt());
1202                 if(fUsePtWeightErrorPropagation) {
1203                     totalpts += track->Pt();
1204                     totalptsquares += track->Pt()*track->Pt();
1205                     totalns += 1;
1206                     _tempSwapN.Fill(track->Phi());
1207                 }
1208             }
1209             else _tempSwap.Fill(track->Phi());
1210     }
1211     if(fUsePtWeight && fUsePtWeightErrorPropagation) {
1212         // in the case of pt weights overwrite the poissonian error estimate which is assigned by root by a more sophisticated appraoch
1213         // 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
1214         // 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 
1215         // event, for the latter use a poissonian estimate. the two contrubitions are assumed to be uncorrelated
1216         if(totalns < 1) return kFALSE; // not one track passes the cuts
1217         for(Int_t l = 0; l < _tempSwap.GetNbinsX(); l++) {
1218             if(_tempSwapN.GetBinContent(l+1) == 0) {
1219                 _tempSwap.SetBinContent(l+1,0);
1220                 _tempSwap.SetBinError(l+1,0);
1221             }
1222             else {
1223                 Double_t vartimesnsq = totalptsquares*totalns - totalpts*totalpts;
1224                 Double_t variance = vartimesnsq/(totalns*(totalns-1.));
1225                 Double_t SDOMSq = variance / _tempSwapN.GetBinContent(l+1);
1226                 Double_t SDOMSqOverMeanSq = SDOMSq * _tempSwapN.GetBinContent(l+1) * _tempSwapN.GetBinContent(l+1) / (_tempSwapN.GetBinContent(l+1) * _tempSwapN.GetBinContent(l+1));
1227                 Double_t poissonfrac = 1./_tempSwapN.GetBinContent(l+1);
1228                 Double_t vartotalfrac = SDOMSqOverMeanSq + poissonfrac;
1229                 Double_t vartotal = vartotalfrac * _tempSwap.GetBinContent(l+1) * _tempSwap.GetBinContent(l+1);
1230                 if(vartotal > 0.0001) _tempSwap.SetBinError(l+1,TMath::Sqrt(vartotal));
1231                 else {
1232                     _tempSwap.SetBinContent(l+1,0);
1233                     _tempSwap.SetBinError(l+1,0);
1234                 }
1235             }
1236         }
1237     }
1238
1239     fFitModulation->SetParameter(0, fLocalRho->GetVal());
1240     switch (fFitModulationType) {
1241         case kNoFit : { 
1242             fFitModulation->FixParameter(0, fLocalRho->GetVal() ); 
1243             freeParams = 0;
1244         } break;
1245         case kV2 : { 
1246             fFitModulation->FixParameter(4, psi2); 
1247             freeParams = 1;
1248         } break;
1249         case kV3 : { 
1250             fFitModulation->FixParameter(4, psi3); 
1251             freeParams = 1;
1252         } break;
1253         case kCombined : {
1254             fFitModulation->FixParameter(4, psi2); 
1255             fFitModulation->FixParameter(6, psi3);
1256             freeParams = 2;
1257         } break;
1258         case kFourierSeries : {
1259             // in this approach, an explicit calculation will be made of vn = sqrt(xn^2+yn^2)
1260             // where x[y] = Integrate[r(phi)cos[sin](n phi)dphi, 0, 2pi]
1261             Double_t cos2(0), sin2(0), cos3(0), sin3(0), sumPt(0);
1262             for(Int_t i(0); i < iTracks; i++) {
1263                 AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1264                 if(!PassesCuts(track) || track->Pt() > fSoftTrackMaxPt || track->Pt() < fSoftTrackMinPt) continue;
1265                 sumPt += track->Pt();
1266                 cos2 += track->Pt()*TMath::Cos(2*PhaseShift(track->Phi()-psi2)); 
1267                 sin2 += track->Pt()*TMath::Sin(2*PhaseShift(track->Phi()-psi2));
1268                 cos3 += track->Pt()*TMath::Cos(3*PhaseShift(track->Phi()-psi3)); 
1269                 sin3 += track->Pt()*TMath::Sin(3*PhaseShift(track->Phi()-psi3));
1270             }
1271             fFitModulation->SetParameter(3, TMath::Sqrt(cos2*cos2+sin2*sin2)/fLocalRho->GetVal());
1272             fFitModulation->SetParameter(4, psi2);
1273             fFitModulation->SetParameter(6, psi3);
1274             fFitModulation->SetParameter(7, TMath::Sqrt(cos3*cos3+sin3*sin3)/fLocalRho->GetVal());
1275         } break;
1276         default : break;
1277     }
1278     if(fRunToyMC) {
1279         // toy mc, just here to check procedure, azimuthal profile is filled from hypothesis so p-value distribution should be flat
1280         Int_t _bins = _tempSwap.GetXaxis()->GetNbins();
1281         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());
1282         _tempFit->SetParameter(0, fFitModulation->GetParameter(0));       // normalization
1283         _tempFit->SetParameter(3, 0.1);      // v2
1284         _tempFit->FixParameter(1, 1.);       // constant
1285         _tempFit->FixParameter(2, 2.);       // constant
1286         _tempFit->FixParameter(5, 3.);       // constant
1287         _tempFit->FixParameter(4, fFitModulation->GetParameter(4));
1288         _tempFit->FixParameter(6, fFitModulation->GetParameter(6));
1289         _tempFit->SetParameter(7, 0.1);      // v3
1290         _tempSwap.Reset();                   // rese bin content
1291         for(int _binsI = 0; _binsI < _bins*_bins; _binsI++)  _tempSwap.Fill(_tempFit->GetRandom());
1292     }
1293     _tempSwap.Fit(fFitModulation, fFitModulationOptions.Data(), "", lowBound, upBound);
1294     // the quality of the fit is evaluated from 1 - the cdf of the chi square distribution
1295     // three methods are available, all with their drawbacks. all are stored, one is selected to do the cut
1296     Int_t NDF(_tempSwap.GetXaxis()->GetNbins()-freeParams);
1297     if(NDF == 0) return kFALSE;
1298     Double_t CDF(1.-ChiSquareCDF(NDF, ChiSquare(_tempSwap, fFitModulation)));
1299     Double_t CDFROOT(1.-ChiSquareCDF(NDF, fFitModulation->GetChisquare()));
1300     Double_t CDFKolmogorov(KolmogorovTest(_tempSwap, fFitModulation));
1301     // fill the values and centrality correlation (redundant but easy on the eyes)
1302     fHistPvalueCDF->Fill(CDF);
1303     fHistPvalueCDFCent->Fill(fCent, CDF);
1304     fHistPvalueCDFROOT->Fill(CDFROOT);
1305     fHistPvalueCDFROOTCent->Fill(fCent, CDFROOT);
1306     fHistKolmogorovTest->Fill(CDFKolmogorov);
1307     fHistChi2ROOTCent->Fill(fCent, fFitModulation->GetChisquare()/((float)NDF));
1308     fHistChi2Cent->Fill(fCent, ChiSquare(_tempSwap, fFitModulation)/((float)NDF));
1309     fHistKolmogorovTestCent->Fill(fCent, CDFKolmogorov);
1310     fHistPChi2Root->Fill(CDFROOT, fFitModulation->GetChisquare()/((float)NDF));
1311     fHistPChi2->Fill(CDF, ChiSquare(_tempSwap, fFitModulation)/((float)NDF));
1312     fHistPKolmogorov->Fill(CDF, CDFKolmogorov);
1313
1314     // variable CDF is used for making cuts, so we fill it with the selected p-value
1315     switch (fFitGoodnessTest) {
1316         case kChi2ROOT : {
1317             CDF = CDFROOT; 
1318         } break;
1319         case kChi2Poisson : break;      // CDF is already CDF
1320         case kKolmogorov : {
1321             CDF = CDFKolmogorov; 
1322         } break;
1323         default: break;
1324     }
1325
1326     if(fFitControl) {
1327         // as an additional quality check, see if fitting a control fit has a higher significance
1328         _tempSwap.Fit(fFitControl, fFitModulationOptions.Data(), "", lowBound, upBound);
1329         Double_t CDFControl(-1.);
1330         switch (fFitGoodnessTest) {
1331             case kChi2ROOT : {
1332                 CDFControl = 1.-ChiSquareCDF(fFitControl->GetNDF(), fFitModulation->GetChisquare());
1333             } break;
1334             case kChi2Poisson : {
1335                 CDFControl = 1.-ChiSquareCDF(fFitControl->GetNDF(), ChiSquare(_tempSwap, fFitModulation));
1336             } break;
1337             case kKolmogorov : {
1338                 CDFControl = KolmogorovTest(_tempSwap, fFitControl); 
1339             } break;
1340             default: break;
1341         }
1342         if(CDFControl > CDF) {
1343             CDF = -1.; // control fit is more significant, so throw out the 'old' fit
1344             fHistRhoStatusCent->Fill(fCent, -1);
1345         }
1346     }
1347     if(CDF >= fMinPvalue && CDF <= fMaxPvalue && ( fFitModulation->GetMinimum(0, TMath::TwoPi()) > 0)) {       // fit quality. not that although with limited acceptance the fit is performed on just
1348                        // part of phase space, the requirement that energy desntiy is larger than zero is applied
1349                        // to the FULL spectrum
1350         fHistRhoStatusCent->Fill(fCent, 0.);
1351         // for LOCAL didactic purposes, save the  best and the worst fits
1352         // this routine can produce a lot of output histograms (it's not memory 'safe') and will not work on GRID 
1353         // since the output will become unmergeable (i.e. different nodes may produce conflicting output)
1354         switch (fRunModeType) {
1355             case kLocal : {
1356                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
1357                 static Int_t didacticCounterBest(0);
1358                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
1359                 TF1* didacticFit = (TF1*)fFitModulation->Clone(Form("fit_%i_CDF_%.3f_cen_%i_%s", didacticCounterBest, CDF, fInCentralitySelection, detector.Data()));
1360                 switch(fFitModulationType) { 
1361                     case kCombined : {
1362                         // to make a nice picture also plot the separate components (v2 and v3) of the fit
1363                         // only done for cobined fit where there are actually components to split ...
1364                         TF1* v0(new TF1("dfit_kV2", "[0]", 0, TMath::TwoPi()));
1365                         v0->SetParameter(0, didacticFit->GetParameter(0));        // normalization
1366                         v0->SetLineColor(kMagenta);
1367                         v0->SetLineStyle(7);
1368                         didacticProfile->GetListOfFunctions()->Add(v0);
1369                         TF1* v2(new TF1("dfit_kV2", "[0]*([1]+[2]*[3]*TMath::Cos([2]*(x-[4])))", 0, TMath::TwoPi()));
1370                         v2->SetParameter(0, didacticFit->GetParameter(0));        // normalization
1371                         v2->SetParameter(3, didacticFit->GetParameter(3));        // v2
1372                         v2->FixParameter(1, 1.);        // constant
1373                         v2->FixParameter(2, 2.);        // constant
1374                         v2->FixParameter(4, didacticFit->GetParameter(4));        // psi2
1375                         v2->SetLineColor(kGreen);
1376                         didacticProfile->GetListOfFunctions()->Add(v2);
1377                         TF1* v3(new TF1("dfit_kV3", "[0]*([1]+[2]*[3]*TMath::Cos([5]*(x-[4])))", 0, TMath::TwoPi()));
1378                         v3->SetParameter(0, didacticFit->GetParameter(0));        // normalization
1379                         v3->SetParameter(3, didacticFit->GetParameter(7));        // v3
1380                         v3->FixParameter(1, 1.);        // constant
1381                         v3->FixParameter(2, 2.);        // constant
1382                         v3->FixParameter(4, didacticFit->GetParameter(6));        // psi3
1383                         v3->FixParameter(5, 3.);        // constant
1384                         v3->SetLineColor(kCyan);
1385                         didacticProfile->GetListOfFunctions()->Add(v3);
1386                     }
1387                     default : break;
1388                 }
1389                 didacticProfile->GetListOfFunctions()->Add(didacticFit);
1390                 didacticProfile->GetYaxis()->SetTitle("#frac{d #sum #it{p}_{T}}{d #varphi} [GeV/#it{c}]");
1391                 didacticProfile->GetXaxis()->SetTitle("#varphi");
1392                 fOutputListGood->Add(didacticProfile);
1393                 didacticCounterBest++;
1394                 TH2F* didacticSurface = BookTH2F(Form("surface_%s", didacticProfile->GetName()), "#phi", "#eta", 50, 0, TMath::TwoPi(), 50, -1, 1, -1, kFALSE);
1395                 for(Int_t i(0); i < iTracks; i++) {
1396                     AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1397                     if(PassesCuts(track)) {
1398                         if(fUsePtWeight) didacticSurface->Fill(track->Phi(), track->Eta(), track->Pt());
1399                         else didacticSurface->Fill(track->Phi(), track->Eta());
1400                     }
1401                 }
1402                 if(fExcludeLeadingJetsFromFit) {       // visualize the excluded region
1403                     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);
1404                     f2->SetParameters(excludeInPt/3.,excludeInPhi,.1,excludeInEta,.1);
1405                     didacticSurface->GetListOfFunctions()->Add(f2);
1406                 }
1407                 fOutputListGood->Add(didacticSurface);
1408             } break;
1409             default : break;
1410         }
1411     } else {    // if the fit is of poor quality revert to the original rho estimate
1412         switch (fRunModeType) { // again see if we want to save the fit
1413             case kLocal : {
1414                 static Int_t didacticCounterWorst(0);
1415                 if(fRandom->Uniform(0, 100) > fPercentageOfFits) break;
1416                 TProfile* didacticProfile = (TProfile*)_tempSwap.Clone(Form("Fit_%i_1-CDF_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data() ));
1417                 TF1* didacticFit = (TF1*)fFitModulation->Clone(Form("fit_%i_p_%.3f_cen_%i_%s", didacticCounterWorst, CDF, fInCentralitySelection, detector.Data()));
1418                 didacticProfile->GetListOfFunctions()->Add(didacticFit);
1419                 fOutputListBad->Add(didacticProfile);
1420                 didacticCounterWorst++;
1421                 } break;
1422             default : break;
1423         }
1424         switch (fFitModulationType) {
1425             case kNoFit : break;        // nothing to do
1426             case kCombined : fFitModulation->SetParameter(7, 0);        // no break
1427             case kFourierSeries : fFitModulation->SetParameter(7, 0);   // no break
1428             default : { // needs to be done if there was a poor fit
1429                  fFitModulation->SetParameter(3, 0);
1430                  fFitModulation->SetParameter(0, fLocalRho->GetVal());
1431             } break;
1432         }
1433         if(CDF > -.5) fHistRhoStatusCent->Fill(fCent, 1.);
1434         return kFALSE;  // return false if the fit is rejected
1435     }
1436     return kTRUE;
1437 }
1438 //_____________________________________________________________________________
1439 Bool_t AliAnalysisTaskJetV2::PassesCuts(AliVEvent* event)
1440 {
1441     // event cuts
1442     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1443     if(!event || !AliAnalysisTaskEmcal::IsEventSelected()) return kFALSE;
1444     if(TMath::Abs(InputEvent()->GetPrimaryVertex()->GetZ()) > 10.) return kFALSE;
1445     // aod and esd specific checks
1446     switch (fDataType) {
1447        case kESD: {
1448             AliESDEvent* esdEvent = static_cast<AliESDEvent*>(InputEvent());
1449             if( (!esdEvent) || (TMath::Abs(esdEvent->GetPrimaryVertexSPD()->GetZ() - esdEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
1450        } break;
1451        case kAOD: {
1452             AliAODEvent* aodEvent = static_cast<AliAODEvent*>(InputEvent());
1453             if( (!aodEvent) || (TMath::Abs(aodEvent->GetPrimaryVertexSPD()->GetZ() - aodEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
1454        } break;
1455        default: break;
1456     }
1457     fCent = InputEvent()->GetCentrality()->GetCentralityPercentile("V0M");
1458     if(fCent <= fCentralityClasses->At(0) || fCent >= fCentralityClasses->At(fCentralityClasses->GetSize()-1) || TMath::Abs(fCent-InputEvent()->GetCentrality()->GetCentralityPercentile("TRK")) > 5.) return kFALSE;
1459     // determine centrality class
1460     fInCentralitySelection = -1;
1461     for(Int_t i(0); i < fCentralityClasses->GetSize()-1; i++) {
1462         if(fCent >= fCentralityClasses->At(i) && fCent <= fCentralityClasses->At(1+i)) {
1463             fInCentralitySelection = i;
1464             break; }
1465     } 
1466     if(fInCentralitySelection<0) return kFALSE;     // should be null op
1467 /*    if(fExplicitOutlierCut == 2010 || fExplicitOutlierCut == 2011) {
1468        if(!PassesCuts(fExplicitOutlierCut)) return kFALSE;
1469     }*/
1470     // see if input containers are filled
1471     if(fTracks->GetEntries() < 1) return kFALSE;
1472     if(fRho->GetVal() <= 0 ) return kFALSE;
1473     if(fAnalysisType == AliAnalysisTaskJetV2::kFull && !fClusterCont) return kFALSE;
1474     return kTRUE;
1475 }
1476 //_____________________________________________________________________________
1477 /*Bool_t AliAnalysisTaskJetV2::PassesCuts(Int_t year) 
1478 {
1479     // additional centrality cut based on relation between tpc and global multiplicity
1480     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1481     AliAODEvent* event(dynamic_cast<AliAODEvent*>(InputEvent()));
1482     if(!event) return kFALSE;
1483     Int_t multTPC(0), multGlob(0), nTracks(InputEvent()->GetNumberOfTracks());
1484     for(Int_t iTracks = 0; iTracks < nTracks; iTracks++) { 
1485         AliAODTrack* track = event->GetTrack(iTracks);
1486         if(!track) continue;
1487         if (!track || track->Pt() < .2 || track->Pt() > 5.0 || TMath::Abs(track->Eta()) > .8 || track->GetTPCNcls() < 70 || !track->GetDetPid() || track->GetDetPid()->GetTPCsignal() < 10.0)  continue;  // general quality cut
1488         if (track->TestFilterBit(1) && track->Chi2perNDF() > 0.2) multTPC++;
1489         if (!track->TestFilterBit(16) || track->Chi2perNDF() < 0.1) continue;
1490         Double_t b[2] = {-99., -99.};
1491         Double_t bCov[3] = {-99., -99., -99.};
1492         AliAODTrack copy(*track);
1493         if (copy.PropagateToDCA(event->GetPrimaryVertex(), event->GetMagneticField(), 100., b, bCov) && TMath::Abs(b[0]) < 0.3 && TMath::Abs(b[1]) < 0.3) multGlob++;
1494     }
1495     if(year == 2010 && multTPC > (-40.3+1.22*multGlob) && multTPC < (32.1+1.59*multGlob)) return kTRUE;
1496     if(year == 2011  && multTPC > (-36.73 + 1.48*multGlob) && multTPC < (62.87 + 1.78*multGlob)) return kTRUE;
1497     return kFALSE;
1498 }*/
1499 //_____________________________________________________________________________
1500 void AliAnalysisTaskJetV2::FillHistogramsAfterSubtraction(Double_t psi2, Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc)
1501 {
1502     // fill histograms 
1503     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1504     FillTrackHistograms();
1505     if(fAnalysisType == AliAnalysisTaskJetV2::kFull) FillClusterHistograms();
1506     FillJetHistograms(psi2); 
1507     if(fFillQAHistograms) FillEventPlaneHistograms(vzero, vzeroComb, tpc);
1508     FillRhoHistograms();
1509     FillDeltaPtHistograms(psi2);
1510 }
1511 //_____________________________________________________________________________
1512 void AliAnalysisTaskJetV2::FillTrackHistograms() const
1513 {
1514     // fill track histograms
1515     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1516     Int_t iTracks(fTracks->GetEntriesFast()), iAcceptedTracks(0);
1517     for(Int_t i(0); i < iTracks; i++) {
1518         AliVTrack* track = static_cast<AliVTrack*>(fTracks->At(i));
1519         if(!PassesCuts(track)) continue;
1520         iAcceptedTracks++;
1521         fHistPicoTrackPt[fInCentralitySelection]->Fill(track->Pt());
1522         if(fFillQAHistograms) FillQAHistograms(track);
1523     }
1524     fHistPicoTrackMult[fInCentralitySelection]->Fill(iAcceptedTracks);
1525 }
1526 //_____________________________________________________________________________
1527 void AliAnalysisTaskJetV2::FillClusterHistograms() const
1528 {
1529     // fill cluster histograms
1530     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1531     if(!fClusterCont) return;
1532     Int_t iClusters(fClusterCont->GetNClusters());
1533     for(Int_t i(0); i < iClusters; i++) {
1534         AliVCluster* cluster = fClusterCont->GetCluster(i);
1535         if (!PassesCuts(cluster)) continue;
1536         TLorentzVector clusterLorentzVector;
1537         cluster->GetMomentum(clusterLorentzVector, const_cast<Double_t*>(fVertex));
1538         fHistClusterPt[fInCentralitySelection]->Fill(clusterLorentzVector.Pt());
1539         fHistClusterEtaPhi[fInCentralitySelection]->Fill(clusterLorentzVector.Eta(), clusterLorentzVector.Phi());
1540         fHistClusterEtaPhiWeighted[fInCentralitySelection]->Fill(clusterLorentzVector.Eta(), clusterLorentzVector.Phi(), clusterLorentzVector.Pt());
1541     }
1542     return;
1543 }
1544 //_____________________________________________________________________________
1545 void AliAnalysisTaskJetV2::FillEventPlaneHistograms(Double_t vzero[2][2], Double_t* vzeroComb, Double_t* tpc) const
1546 {
1547     // fill event plane histograms
1548     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1549     fHistPsiControl->Fill(0.5, vzero[0][0]);    // vzero a psi2
1550     fHistPsiControl->Fill(1.5, vzero[1][0]);    // vzero c psi2
1551     fHistPsiControl->Fill(2.5, tpc[0]);         // tpc psi 2
1552     fHistPsiControl->Fill(5.5, vzero[0][1]);    // vzero a psi3
1553     fHistPsiControl->Fill(6.5, vzero[1][1]);    // vzero b psi3
1554     fHistPsiControl->Fill(7.5, tpc[1]);         // tpc psi 3
1555     fHistPsiVZEROA->Fill(vzero[0][0]);
1556     fHistPsiVZEROC->Fill(vzero[1][0]);
1557     fHistPsiVZERO->Fill(vzeroComb[0]);
1558     fHistPsiTPC->Fill(tpc[0]);
1559     fHistPsiSpread->Fill(0.5, TMath::Abs(vzero[0][0]-vzero[1][0]));
1560     fHistPsiSpread->Fill(1.5, TMath::Abs(vzero[0][0]-tpc[0]));
1561     fHistPsiSpread->Fill(2.5, TMath::Abs(vzero[1][0]-tpc[0]));
1562     // event plane vs centrality QA histo's to check recentering
1563     Double_t TRK(InputEvent()->GetCentrality()->GetCentralityPercentile("TRK"));
1564     Double_t V0M(InputEvent()->GetCentrality()->GetCentralityPercentile("V0M"));
1565     fHistPsiVZEROAV0M->Fill(V0M, vzero[0][0]);
1566     fHistPsiVZEROCV0M->Fill(V0M, vzero[1][0]);
1567     fHistPsiVZEROVV0M->Fill(V0M, vzeroComb[0]);
1568     fHistPsiTPCiV0M->Fill(V0M, tpc[0]);
1569     fHistPsiVZEROATRK->Fill(TRK, vzero[0][0]);
1570     fHistPsiVZEROCTRK->Fill(TRK, vzero[1][0]);
1571     fHistPsiVZEROTRK->Fill(TRK, vzeroComb[0]);
1572     fHistPsiTPCTRK->Fill(TRK, tpc[0]);
1573 }
1574 //_____________________________________________________________________________
1575 void AliAnalysisTaskJetV2::FillRhoHistograms()
1576 {
1577     // fill rho histograms
1578     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1579     fHistRhoPackage[fInCentralitySelection]->Fill(fLocalRho->GetVal());    // save the rho estimate from the emcal jet package
1580     // get multiplicity FIXME inefficient
1581     Int_t iJets(fJets->GetEntriesFast());
1582     Double_t rho(fLocalRho->GetLocalVal(TMath::Pi(), TMath::Pi(), fLocalRho->GetVal()));
1583     fHistRho[fInCentralitySelection]->Fill(rho);
1584     fHistRhoVsMult->Fill(fTracks->GetEntries(), rho);
1585     fHistRhoVsCent->Fill(fCent, rho);
1586     for(Int_t i(0); i < iJets; i++) {
1587         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1588         if(!PassesCuts(jet)) continue;
1589         fHistRhoAVsMult->Fill(fTracks->GetEntries(), rho * jet->Area());
1590         fHistRhoAVsCent->Fill(fCent, rho * jet->Area());
1591     }
1592 }
1593 //_____________________________________________________________________________
1594 void AliAnalysisTaskJetV2::FillDeltaPtHistograms(Double_t psi2) const
1595 {
1596     // fill delta pt histograms
1597     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1598     Int_t i(0);
1599     const Float_t areaRC = GetJetRadius()*GetJetRadius()*TMath::Pi();
1600     // we're retrieved the leading jet, now get a random cone
1601     for(i = 0; i < fMaxCones; i++) {
1602        Float_t pt(0), eta(0), phi(0);
1603        // get a random cone without constraints on leading jet position
1604        CalculateRandomCone(pt, eta, phi, fTracksCont, fClusterCont, 0x0);
1605        if(pt > 0) {
1606            if(fFillQAHistograms) fHistRCPhiEta[fInCentralitySelection]->Fill(phi, eta);
1607            fHistRhoVsRCPt[fInCentralitySelection]->Fill(pt, fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal())*areaRC);
1608            fHistRCPt[fInCentralitySelection]->Fill(pt);
1609            fHistDeltaPtDeltaPhi2[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1610            fHistDeltaPtDeltaPhi2Rho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetVal());
1611
1612        }
1613        // get a random cone excluding leading jet area
1614        CalculateRandomCone(pt, eta, phi, fTracksCont, fClusterCont, fLeadingJet);
1615        if(pt > 0) {
1616            if(fFillQAHistograms) fHistRCPhiEtaExLJ[fInCentralitySelection]->Fill(phi, eta);
1617            fHistRhoVsRCPtExLJ[fInCentralitySelection]->Fill(pt, fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal())*areaRC);
1618            fHistRCPtExLJ[fInCentralitySelection]->Fill(pt);
1619            fHistDeltaPtDeltaPhi2ExLJ[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1620            fHistDeltaPtDeltaPhi2ExLJRho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt - areaRC*fLocalRho->GetVal());
1621        }
1622     } 
1623 }
1624 //_____________________________________________________________________________
1625 void AliAnalysisTaskJetV2::FillJetHistograms(Double_t psi2)
1626 {
1627     // fill jet histograms
1628     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1629     Int_t iJets(fJets->GetEntriesFast());
1630     for(Int_t i(0); i < iJets; i++) {
1631         AliEmcalJet* jet = static_cast<AliEmcalJet*>(fJets->At(i));
1632         if(PassesCuts(jet)) {
1633             Double_t pt(jet->Pt()), area(jet->Area()), eta(jet->Eta()), phi(jet->Phi());
1634             Double_t rho(fLocalRho->GetLocalVal(phi, GetJetContainer()->GetJetRadius(), fLocalRho->GetVal()));
1635             fHistJetPtRaw[fInCentralitySelection]->Fill(pt);
1636             fHistJetPt[fInCentralitySelection]->Fill(pt-area*rho);
1637             if(fFillQAHistograms) fHistJetEtaPhi[fInCentralitySelection]->Fill(eta, phi);
1638             fHistJetPtArea[fInCentralitySelection]->Fill(pt-area*rho, area);
1639             fHistJetPtEta[fInCentralitySelection]->Fill(pt-area*rho, eta);
1640             fHistJetPsi2Pt[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt-area*rho);
1641             fHistJetPsi2PtRho0[fInCentralitySelection]->Fill(PhaseShift(phi-psi2, 2.), pt-area*fLocalRho->GetVal());
1642             fHistJetPtConstituents[fInCentralitySelection]->Fill(pt-area*rho, jet->Nch());
1643             fHistJetEtaRho[fInCentralitySelection]->Fill(eta, pt/area);
1644         } 
1645     }
1646 }
1647 //_____________________________________________________________________________
1648 void AliAnalysisTaskJetV2::FillQAHistograms(AliVTrack* vtrack) const
1649 {
1650     // fill qa histograms for pico tracks
1651     if(!vtrack) return;
1652     AliPicoTrack* track = static_cast<AliPicoTrack*>(vtrack);
1653     fHistRunnumbersPhi->Fill(fMappedRunNumber, track->Phi());
1654     fHistRunnumbersEta->Fill(fMappedRunNumber, track->Eta());
1655     Int_t type((int)(track->GetTrackType()));
1656     switch (type) {
1657         case 0:
1658            fHistPicoCat1[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1659            break;
1660         case 1:
1661            fHistPicoCat2[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1662            break;
1663         case 2:
1664            fHistPicoCat3[fInCentralitySelection]->Fill(track->Eta(), track->Phi()); 
1665            break;
1666         default: break;
1667     }
1668 }
1669 //_____________________________________________________________________________
1670 void AliAnalysisTaskJetV2::FillQAHistograms(AliVEvent* vevent) 
1671 {
1672     // fill qa histograms for events
1673     if(!vevent) return;
1674     fHistVertexz->Fill(vevent->GetPrimaryVertex()->GetZ());
1675     fHistCentrality->Fill(fCent);
1676     Int_t runNumber(InputEvent()->GetRunNumber());
1677     for(fMappedRunNumber = 0; fExpectedRuns->GetSize()+1; fMappedRunNumber++) {
1678         if(fExpectedRuns->At(fMappedRunNumber) == runNumber) break;
1679     }
1680 }
1681 //_____________________________________________________________________________
1682 void AliAnalysisTaskJetV2::FillAnalysisSummaryHistogram() const
1683 {
1684     // fill the analysis summary histrogram, saves all relevant analysis settigns
1685     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1686     fHistAnalysisSummary->GetXaxis()->SetBinLabel(2, "fJetRadius");
1687     fHistAnalysisSummary->SetBinContent(2, GetJetContainer()->GetJetRadius());
1688     fHistAnalysisSummary->GetXaxis()->SetBinLabel(3, "fJetEtaMin");
1689     fHistAnalysisSummary->SetBinContent(3, GetJetContainer()->GetJetEtaMin());
1690     fHistAnalysisSummary->GetXaxis()->SetBinLabel(4, "fJetEtaMax");
1691     fHistAnalysisSummary->SetBinContent(4, GetJetContainer()->GetJetEtaMax());
1692     fHistAnalysisSummary->GetXaxis()->SetBinLabel(5, "fJetPhiMin");
1693     fHistAnalysisSummary->SetBinContent(5, GetJetContainer()->GetJetPhiMin());
1694     fHistAnalysisSummary->GetXaxis()->SetBinLabel(6, "fJetPhiMax");
1695     fHistAnalysisSummary->SetBinContent(6, GetJetContainer()->GetJetPhiMin());
1696     fHistAnalysisSummary->GetXaxis()->SetBinLabel(16, "fForceBeamType");
1697     fHistAnalysisSummary->SetBinContent(16, fForceBeamType);
1698     fHistAnalysisSummary->GetXaxis()->SetBinLabel(17, "fMinCent");
1699     fHistAnalysisSummary->SetBinContent(17, fMinCent);
1700     fHistAnalysisSummary->GetXaxis()->SetBinLabel(18, "fMaxCent");
1701     fHistAnalysisSummary->SetBinContent(18, fMaxCent);
1702     fHistAnalysisSummary->GetXaxis()->SetBinLabel(19, "fMinVz");
1703     fHistAnalysisSummary->SetBinContent(19, fMinVz);
1704     fHistAnalysisSummary->GetXaxis()->SetBinLabel(20, "fMaxVz");
1705     fHistAnalysisSummary->SetBinContent(20, fMaxVz);
1706     fHistAnalysisSummary->GetXaxis()->SetBinLabel(21, "fOffTrigger");
1707     fHistAnalysisSummary->SetBinContent(21, fOffTrigger);
1708     fHistAnalysisSummary->GetXaxis()->SetBinLabel(34, "fitModulationType");
1709     fHistAnalysisSummary->SetBinContent(34, (int)fFitModulationType);
1710     fHistAnalysisSummary->GetXaxis()->SetBinLabel(35, "runModeType");
1711     fHistAnalysisSummary->SetBinContent(35, (int)fRunModeType);
1712     fHistAnalysisSummary->GetXaxis()->SetBinLabel(36, "data type");
1713     fHistAnalysisSummary->SetBinContent(36, (int)fDataType);
1714     fHistAnalysisSummary->GetXaxis()->SetBinLabel(37, "iterator");
1715     fHistAnalysisSummary->SetBinContent(37, 1.);
1716     fHistAnalysisSummary->GetXaxis()->SetBinLabel(38, "fMinPvalue");
1717     fHistAnalysisSummary->SetBinContent(38, fMinPvalue);
1718     fHistAnalysisSummary->GetXaxis()->SetBinLabel(39, "fMaxPvalue");
1719     fHistAnalysisSummary->SetBinContent(39, fMaxPvalue);
1720     fHistAnalysisSummary->GetXaxis()->SetBinLabel(40, "fExcludeLeadingJetsFromFit");
1721     fHistAnalysisSummary->SetBinContent(40, fExcludeLeadingJetsFromFit);
1722     fHistAnalysisSummary->GetXaxis()->SetBinLabel(41, "fRebinSwapHistoOnTheFly");
1723     fHistAnalysisSummary->SetBinContent(41, (int)fRebinSwapHistoOnTheFly);
1724     fHistAnalysisSummary->GetXaxis()->SetBinLabel(42, "fUsePtWeight");
1725     fHistAnalysisSummary->SetBinContent(42, (int)fUsePtWeight);
1726 //    fHistAnalysisSummary->GetXaxis()->SetBinLabel(43, "fExplicitOutlierCut");
1727 //    fHistAnalysisSummary->SetBinContent(43, fExplicitOutlierCut);
1728     fHistAnalysisSummary->GetXaxis()->SetBinLabel(44, "fSoftTrackMinPt");
1729     fHistAnalysisSummary->SetBinContent(44, fSoftTrackMinPt);
1730     fHistAnalysisSummary->GetXaxis()->SetBinLabel(45, "fSoftTrackMaxPt");
1731     fHistAnalysisSummary->SetBinContent(45, fSoftTrackMaxPt);
1732     fHistAnalysisSummary->GetXaxis()->SetBinLabel(46, "fMaxCones");
1733     fHistAnalysisSummary->SetBinContent(46, fMaxCones);
1734     fHistAnalysisSummary->GetXaxis()->SetBinLabel(47, "used rho");
1735     fHistAnalysisSummary->GetXaxis()->SetBinLabel(48, "used small rho");
1736 }
1737 //_____________________________________________________________________________
1738 void AliAnalysisTaskJetV2::Terminate(Option_t *)
1739 {
1740     // terminate
1741     switch (fRunModeType) {
1742         case kLocal : {
1743         printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
1744         AliAnalysisTaskJetV2::Dump();
1745         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));
1746         } break;
1747         default : break;
1748     }
1749 }
1750 //_____________________________________________________________________________
1751 void AliAnalysisTaskJetV2::SetModulationFit(TF1* fit) 
1752 {
1753     // set modulation fit
1754     if (fFitModulation) delete fFitModulation;
1755     fFitModulation = fit; 
1756 }
1757 //_____________________________________________________________________________
1758 void AliAnalysisTaskJetV2::SetUseControlFit(Bool_t c)
1759 {
1760     // set control fit
1761     if (fFitControl) delete fFitControl;
1762     if (c) {
1763         fFitControl = new TF1("controlFit", "pol0", 0, TMath::TwoPi());
1764     } else fFitControl = 0x0;
1765 }
1766 //_____________________________________________________________________________
1767 TH1F* AliAnalysisTaskJetV2::GetResolutionFromOuptutFile(detectorType det, Int_t h, TArrayD* cen)
1768 {
1769     // INTERFACE METHOD FOR OUTPUTFILE
1770     // get the detector resolution, user has ownership of the returned histogram
1771     if(!fOutputList) {
1772         printf(" > Please add fOutputList first < \n");
1773         return 0x0;
1774     }
1775     TH1F* r(0x0);
1776     (cen) ? r = new TH1F("R", "R", cen->GetSize()-1, cen->GetArray()) : r = new TH1F("R", "R", 10, 0, 10);
1777     if(!cen) r->GetXaxis()->SetTitle("number of centrality bin");
1778     r->GetYaxis()->SetTitle(Form("Resolution #Psi_{%i}", h));
1779     for(Int_t i(0); i < 10; i++) {
1780         TProfile* temp((TProfile*)fOutputList->FindObject(Form("fProfV%iResolution_%i", h, i)));
1781         if(!temp) break;
1782         Double_t a(temp->GetBinContent(3)), b(temp->GetBinContent(5)), c(temp->GetBinContent(7));
1783         Double_t d(temp->GetBinContent(9)), e(temp->GetBinContent(10)), f(temp->GetBinContent(11));
1784         Double_t _a(temp->GetBinError(3)), _b(temp->GetBinError(5)), _c(temp->GetBinError(7));
1785         Double_t _d(temp->GetBinError(9)), _e(temp->GetBinError(10)), _f(temp->GetBinError(11));
1786         if(a <= 0 || b <= 0 || c <= 0 || d <= 0 || e <= 0 || f <= 0) continue;
1787         switch (det) {
1788             case kVZEROA : {
1789                 r->SetBinContent(1+i, TMath::Sqrt((a*b)/c));
1790                 if(i==0) r->SetNameTitle("VZEROA resolution", "VZEROA resolution");
1791                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
1792             } break;
1793             case kVZEROC : {
1794                 r->SetBinContent(1+i, TMath::Sqrt((a*c)/b));
1795                 if(i==0) r->SetNameTitle("VZEROC resolution", "VZEROC resolution");
1796                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
1797             } break;
1798             case kTPC : {
1799                 r->SetBinContent(1+i, TMath::Sqrt((b*c)/a));
1800                 if(i==0) r->SetNameTitle("TPC resolution", "TPC resolution");
1801                 r->SetBinError(1+i, TMath::Sqrt(_a*_a+_b*_b+_c*_c));
1802             } break;
1803             case kVZEROComb : {
1804                 r->SetBinContent(1+i, TMath::Sqrt((d*e)/f));
1805                 if(i==0) r->SetNameTitle("VZEROComb resolution", "VZEROComb resolution");
1806                 r->SetBinError(1+i, TMath::Sqrt(_d*_d+_e*_e+_f*_f));
1807             } break;
1808             default : break;
1809         }
1810     }
1811     return r;
1812 }
1813 //_____________________________________________________________________________
1814 TH1F* AliAnalysisTaskJetV2::CorrectForResolutionDiff(TH1F* v, detectorType det, TArrayD* cen, Int_t c, Int_t h)
1815 {
1816     // INTERFACE METHOD FOR OUTPUT FILE
1817     // correct the supplied differential vn histogram v for detector resolution
1818     TH1F* r(GetResolutionFromOuptutFile(det, h, cen));
1819     if(!r) {
1820         printf(" > Couldn't find resolution < \n");
1821         return 0x0;
1822     }
1823     Double_t res(1./r->GetBinContent(1+r->FindBin(c)));
1824     TF1* line = new TF1("line", "pol0", 0, 200);
1825     line->SetParameter(0, res);
1826     v->Multiply(line);
1827     return v;
1828 }
1829 //_____________________________________________________________________________
1830 TH1F* AliAnalysisTaskJetV2::CorrectForResolutionInt(TH1F* v, detectorType det, TArrayD* cen, Int_t h)
1831 {
1832     // INTERFACE METHOD FOR OUTPUT FILE
1833     // correct the supplied intetrated vn histogram v for detector resolution
1834     // integrated vn must have the same centrality binning as the resolotion correction
1835     TH1F* r(GetResolutionFromOuptutFile(det, h, cen));
1836     v->Divide(v, r);
1837     return v;
1838 }
1839 //_____________________________________________________________________________
1840 TH1F* AliAnalysisTaskJetV2::GetDifferentialQC(TProfile* refCumulants, TProfile* diffCumlants, TArrayD* ptBins, Int_t h)
1841 {
1842     // get differential QC
1843     Double_t r(refCumulants->GetBinContent(h-1)); // v2 reference flow
1844     if(r > 0) r = TMath::Sqrt(r);
1845     TH1F* qc = new TH1F(Form("QC2v%i", h), Form("QC2v%i", h), ptBins->GetSize()-1, ptBins->GetArray());
1846     Double_t a(0), b(0), c(0);  // dummy variables
1847     for(Int_t i(0); i < ptBins->GetSize(); i++) {
1848         if(r > 0) {
1849             a = diffCumlants->GetBinContent(1+i);
1850             b = diffCumlants->GetBinError(1+i);
1851             c = a/r;
1852             qc->SetBinContent(1+i, c);
1853             (a <= 0 || b <= 0) ? qc->SetBinError(1+i, b) : qc->SetBinError(1+i, TMath::Sqrt(c*c*b*b/(a*a)));
1854         }
1855     }
1856     return qc;
1857 }
1858
1859 //_____________________________________________________________________________