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