]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/FLOW/Tasks/AliAnalysisTaskJetFlow.cxx
8c1d7e011ea696eeefb972324eeac03943bdae78
[u/mrichter/AliRoot.git] / PWG / FLOW / Tasks / AliAnalysisTaskJetFlow.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  * AliAnaysisTaskJet
18  * author: Redmer Alexander Bertens
19  * rbertens@cern.ch, rbertens@nikhef.nl, r.a.bertens@uu.nl 
20  *
21  * jet correlation task - correlates jets to the vzero reaction plane using
22  * the scalar product method 
23  *
24  * this task expects POI's in a TClonesArray, e.g. from running it after 
25  * $ALICE_ROOT/PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskRhoVnModulation()
26  * if subtracted jet pt is stored by using jet->PtSub() run in default mode
27  * to run on unsubtracted jets - or any other class inheriting from AliVParticle - call SetDoVParticleAnalysis(kTRUE)
28  *
29  * */
30
31 #include <TChain.h>
32 #include <TH1F.h>
33 #include <AliAnalysisTask.h>
34 #include <AliAnalysisManager.h>
35 #include <AliFlowEventSimple.h>
36 #include <AliFlowTrack.h>
37 #include <AliFlowTrackCuts.h>
38 #include <AliFlowEventCuts.h>
39 #include <AliFlowCommonConstants.h>
40 #include <TString.h>
41 #include <AliAODEvent.h>
42 #include <AliESDEvent.h>
43 #include <AliEmcalJet.h>
44
45 #include "AliAnalysisTaskJetFlow.h"
46
47 class AliAnalysisTaskJetFlow;
48
49 using namespace std;
50
51 ClassImp(AliAnalysisTaskJetFlow)
52
53 AliAnalysisTaskJetFlow::AliAnalysisTaskJetFlow() : AliAnalysisTaskSE(), 
54     fDebug(-1), fJetsName(0), fOutputList(0), fDataType(kESD), fVParticleAnalysis(kFALSE), fInitialized(kFALSE), fPtBump(0), fCCMaxPt(150), fCCBinsInPt(50), fCentralityMin(-1), fCentralityMax(-1), fPOIPtMin(0.15), fPOIPtMax(150), fCutsRP(0), fCutsPOI(0), fCutsNull(0), fCutsEvent(0), fFlowEvent(0), fHistAnalysisSummary(0), fCentralitySelection(0)
55 { /* default constructor */ }
56 //_____________________________________________________________________________
57 AliAnalysisTaskJetFlow::AliAnalysisTaskJetFlow(const char* name) : AliAnalysisTaskSE(name),
58     fDebug(-1), fJetsName(0), fOutputList(0), fDataType(kESD), fVParticleAnalysis(kFALSE), fInitialized(kFALSE), fPtBump(0), fCCMaxPt(150), fCCBinsInPt(50), fCentralityMin(-1), fCentralityMax(-1), fPOIPtMin(0.15), fPOIPtMax(150), fCutsRP(0), fCutsPOI(0), fCutsNull(0), fCutsEvent(0), fFlowEvent(0), fHistAnalysisSummary(0), fCentralitySelection(0)
59 {
60     // constructor
61     DefineInput(0, TChain::Class());
62     DefineOutput(1, TList::Class());
63     DefineOutput(2, AliFlowEventSimple::Class());
64 }
65 //_____________________________________________________________________________
66 AliAnalysisTaskJetFlow::~AliAnalysisTaskJetFlow()
67 {
68     // destructor
69     if(fOutputList)     delete fOutputList;
70     if(fFlowEvent)      delete fFlowEvent;
71     if(fCutsEvent)      delete fCutsEvent;
72 }
73 //_____________________________________________________________________________
74 void AliAnalysisTaskJetFlow::LocalInit()
75 {
76     // executed once
77     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
78     fCutsEvent = new AliFlowEventCuts();
79     fCutsEvent->SetRefMultMethod(AliESDtrackCuts::kTrackletsITSTPC); 
80 }
81 //_____________________________________________________________________________
82 void AliAnalysisTaskJetFlow::UserCreateOutputObjects()
83 {
84     // create output objects
85     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
86     fOutputList = new TList();
87     fOutputList->SetOwner(kTRUE);
88     // histograms
89     fHistAnalysisSummary = new TH1F("fHistAnalysisSummary", "fHistAnalysisSummary", 4, -.5, 3.5);
90     fHistAnalysisSummary->GetXaxis()->SetBinLabel(1, "fDataType");
91     fHistAnalysisSummary->SetBinContent(1, (int)fDataType);
92     fHistAnalysisSummary->GetXaxis()->SetBinLabel(2, "fCentralityMin");
93     fHistAnalysisSummary->SetBinContent(2, fCentralityMin);
94     fHistAnalysisSummary->GetXaxis()->SetBinLabel(3, "fCentralityMax");
95     fHistAnalysisSummary->SetBinContent(3, fCentralityMax);
96     fHistAnalysisSummary->GetXaxis()->SetBinLabel(4, "pt bias");
97     fOutputList->Add(fHistAnalysisSummary);
98     // qa
99     fCentralitySelection = new TH1F("fCentralitySelection", "fCentralitySelection", 100, 0, 100);
100     fOutputList->Add(fCentralitySelection);
101
102     PostData(1, fOutputList);
103     // create the flow event and configure the static cc object
104     fFlowEvent = new AliFlowEvent(1000);
105     PostData(2, fFlowEvent);
106     AliFlowCommonConstants* cc = AliFlowCommonConstants::GetMaster();
107     cc->SetPtMax(fCCMaxPt+fPtBump);
108     cc->SetNbinsPt(fCCBinsInPt);
109 }
110 //_____________________________________________________________________________
111 void AliAnalysisTaskJetFlow::UserExec(Option_t *)
112 {
113     // user exec
114     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
115     if(!InputEvent() || !fCutsNull || !fCutsRP) return; // coverity (and sanity)
116     if(!fInitialized) { 
117         if(dynamic_cast<AliAODEvent*>(InputEvent())) fDataType = kAOD; // determine the datatype
118         else if(dynamic_cast<AliESDEvent*>(InputEvent())) fDataType = kESD;
119         fInitialized = kTRUE;
120     }
121     if(!PassesCuts(InputEvent())) return;               // check the event cuts
122     // get the jet array, which is added as an extension to the AliVEvent by the jetfinder
123     TClonesArray* jets = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fJetsName.Data()));
124     Int_t nAcceptedJets(0);
125     if(jets) {
126         Int_t iJets = jets->GetEntriesFast();
127         if(iJets <= 0) {
128             if(fDebug>0) printf(" > Retrieved empty AliVEvent extension, aborting ! < \n ");
129             return;
130         }
131         // prepare the track selection for RP's and the flow event
132         fCutsRP->SetEvent(InputEvent(), MCEvent());
133         fCutsNull->SetEvent(InputEvent(), MCEvent());
134         fFlowEvent->ClearFast();
135         fFlowEvent->Fill(fCutsRP, fCutsNull);
136         fFlowEvent->SetReferenceMultiplicity(fCutsEvent->RefMult(InputEvent(), MCEvent()));
137         // loop over jets and inject them as POI's
138         if(fVParticleAnalysis) {
139             for(Int_t i(0); i < iJets; i++) {
140                 AliVParticle* jet = static_cast<AliVParticle*>(jets->At(i));
141                 if(jet) {
142                     if(jet->Pt() + fPtBump <= fPOIPtMin || jet->Pt() > fPOIPtMax) {
143                         fHistAnalysisSummary->SetBinContent(4, 1);
144                         continue;
145                     }
146                     nAcceptedJets++;
147                     AliFlowTrack* flowTrack = new AliFlowTrack(jet);
148                     flowTrack->SetPt(jet->Pt() + fPtBump);
149                     flowTrack->SetForPOISelection(kTRUE);
150                     flowTrack->SetForRPSelection(kFALSE);
151                     fFlowEvent->InsertTrack(flowTrack);
152                 }
153             }
154         } else {
155             for(Int_t i(0); i < iJets; i++) {
156                 AliEmcalJet* jet = static_cast<AliEmcalJet*>(jets->At(i));
157                 if(jet) {
158                     if(jet->PtSub() + fPtBump <= fPOIPtMin || jet->Pt() > fPOIPtMax) {
159                         fHistAnalysisSummary->SetBinContent(4, 1);
160                         continue;
161                     }
162                     nAcceptedJets++;
163                     AliFlowTrack* flowTrack = new AliFlowTrack(jet);
164                     flowTrack->SetPt(jet->PtSub() + fPtBump);
165                     flowTrack->SetForPOISelection(kTRUE);
166                     flowTrack->SetForRPSelection(kFALSE);
167                     fFlowEvent->InsertTrack(flowTrack);
168                 }
169             }
170         }
171     }
172     else if(fDebug > 0 ) printf(" Failed to find TClones Jet array while using name %s \n ", fJetsName.Data());
173     if(nAcceptedJets < 1) {
174         if(fDebug > 0) printf(" > No accepted jets in event ! < " );
175         return;
176     }
177     fCentralitySelection->Fill(InputEvent()->GetCentrality()->GetCentralityPercentile("V0M"));
178     PostData(1, fOutputList);
179     PostData(2, fFlowEvent);
180     if(fDebug>0) {
181         printf(" Event summary \n");
182         printf(" > number of POI's (jets) %i ", fFlowEvent->NumberOfTracks() - fFlowEvent->GetNumberOfRPs());
183         printf(" > number of RP's %i \n", fFlowEvent->GetNumberOfRPs());
184     }
185 }
186 //_____________________________________________________________________________
187 Bool_t AliAnalysisTaskJetFlow::PassesCuts(AliVEvent* event)
188 {
189     // event cuts
190     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
191     if(!event) return kFALSE;
192     if(TMath::Abs(InputEvent()->GetPrimaryVertex()->GetZ()) > 10.) return kFALSE;
193     // aod and esd specific checks
194     switch (fDataType) {
195        case kESD: {
196             AliESDEvent* esdEvent = static_cast<AliESDEvent*>(InputEvent());
197             if( (!esdEvent) || (TMath::Abs(esdEvent->GetPrimaryVertexSPD()->GetZ() - esdEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
198        } break;
199        case kAOD: {
200             AliAODEvent* aodEvent = static_cast<AliAODEvent*>(InputEvent());
201             if( (!aodEvent) || (TMath::Abs(aodEvent->GetPrimaryVertexSPD()->GetZ() - aodEvent->GetPrimaryVertex()->GetZ()) > .5) ) return kFALSE; 
202        } break;
203        default: break;
204     }
205     Float_t cent(InputEvent()->GetCentrality()->GetCentralityPercentile("V0M"));
206     return (cent <= fCentralityMin || cent > fCentralityMax || TMath::Abs(cent-InputEvent()->GetCentrality()->GetCentralityPercentile("TRK")) > 5.) ? kFALSE : kTRUE;
207 }
208 //_____________________________________________________________________________
209 void AliAnalysisTaskJetFlow::Terminate(Option_t *)
210 {
211     // terminate
212     if(fDebug > 0) printf("__FILE__ = %s \n __LINE __ %i , __FUNC__ %s \n ", __FILE__, __LINE__, __func__);
213 }
214 //_____________________________________________________________________________