]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/AliFlowTasks/AliAnalysisTaskFlowEvent.cxx
Go back to working dir if par compilation fails, this helps debugging (AndreaR)
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowTasks / AliAnalysisTaskFlowEvent.cxx
CommitLineData
1c1d4332 1/*************************************************************************
2* Copyright(c) 1998-2008, 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#include "Riostream.h" //needed as include
17#include "TChain.h"
18#include "TTree.h"
19#include "TFile.h" //needed as include
20#include "TList.h"
21
7183fe85 22// ALICE Analysis Framework
1c1d4332 23class AliAnalysisTask;
24#include "AliAnalysisManager.h"
25
7183fe85 26// ESD interface
1c1d4332 27#include "AliESDEvent.h"
28#include "AliESDInputHandler.h"
29
7183fe85 30// AOD interface
1c1d4332 31#include "AliAODEvent.h"
32#include "AliAODInputHandler.h"
33
7183fe85 34// Monte Carlo Event
1c1d4332 35#include "AliMCEventHandler.h"
36#include "AliMCEvent.h"
37
7183fe85 38// ALICE Correction Framework
1c1d4332 39#include "AliCFManager.h"
40
7183fe85 41// Interface to Event generators to get Reaction Plane Angle
42#include "AliGenCocktailEventHeader.h"
43#include "AliGenHijingEventHeader.h"
48ad51a1 44#include "AliGenGeVSimEventHeader.h"
7183fe85 45
46// Interface to make the Flow Event Simple used in the flow analysis methods
1c1d4332 47#include "AliFlowEventSimpleMaker.h"
48
7183fe85 49#include "AliAnalysisTaskFlowEvent.h"
50
1c1d4332 51// AliAnalysisTaskFlowEvent:
52//
53// analysis task for filling the flow event
54// from MCEvent, ESD, AOD ....
55// and put it in an output stream so it can
56// be used by the various flow analysis methods
57// for cuts the correction framework is used
58// which also outputs QA histrograms to view
59// the effects of the cuts
60
61
62ClassImp(AliAnalysisTaskFlowEvent)
c9f92d16 63 //extern void ConfigFlowAnalysis(AliAnalysisTaskFlowEvent*);
1c1d4332 64
65//________________________________________________________________________
66AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on) :
67 AliAnalysisTask(name, ""),
46bec39c 68// fOutputFile(NULL),
1c1d4332 69 fESD(NULL),
70 fAOD(NULL),
71 fEventMaker(NULL),
72 fAnalysisType("ESD"),
73 fCFManager1(NULL),
74 fCFManager2(NULL),
75 fQAInt(NULL),
76 fQADiff(NULL),
77 fQA(on)
78{
79 // Constructor
80 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name)"<<endl;
81
82 // Define input and output slots here
83 // Input slot #0 works with a TChain
84 DefineInput(0, TChain::Class());
46bec39c 85 // Define here the flow event output
86 DefineOutput(0, AliFlowEventSimple::Class());
1c1d4332 87 if(on) {
88 DefineOutput(1, TList::Class());
89 DefineOutput(2, TList::Class()); }
46bec39c 90 // and for testing open an output file
91 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
1c1d4332 92
93}
94
95//________________________________________________________________________
96AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
46bec39c 97 // fOutputFile(NULL),
1c1d4332 98 fESD(NULL),
99 fAOD(NULL),
100 fEventMaker(NULL),
101 fAnalysisType("ESD"),
102 fCFManager1(NULL),
103 fCFManager2(NULL),
104 fQAInt(NULL),
105 fQADiff(NULL),
106 fQA(kFALSE)
107{
108 // Constructor
109 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
110}
111
112//________________________________________________________________________
113AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
114{
115 //
116 // Destructor
117 //
118
119 // objects in the output list are deleted
120 // by the TSelector dtor (I hope)
121
122}
123
124//________________________________________________________________________
125void AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *)
126{
127 // Connect ESD or AOD here
128 // Called once
129 cout<<"AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *)"<<endl;
130
131 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
132 if (!tree) {
133 Printf("ERROR: Could not read chain from input slot 0");
3507ac7e 134 }
135 else {
136 if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" || fAnalysisType == "MC") {
1c1d4332 137 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
1c1d4332 138 if (!esdH) {
139 Printf("ERROR: Could not get ESDInputHandler");
3507ac7e 140 }
141 else {fESD = esdH->GetEvent();}
1c1d4332 142 }
143 else if (fAnalysisType == "AOD") {
144 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
1c1d4332 145 if (!aodH) {
146 Printf("ERROR: Could not get AODInputHandler");
147 }
3507ac7e 148 else { fAOD = aodH->GetEvent();}
1c1d4332 149 }
150 else {
151 Printf("!!!!!Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
152 exit(1);
1c1d4332 153 }
154 }
155}
156
157//________________________________________________________________________
158void AliAnalysisTaskFlowEvent::CreateOutputObjects()
159{
160 // Called at every worker node to initialize
161 cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
162
163 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) {
164 cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
165 exit(1);
166 }
167
c9f92d16 168 //ConfigFlowAnalysis(this);
169
1c1d4332 170 // Flow Event maker
171 fEventMaker = new AliFlowEventSimpleMaker();
172}
173
174//________________________________________________________________________
175void AliAnalysisTaskFlowEvent::Exec(Option_t *)
176{
177 // Main loop
178 // Called for each event
89f41a6a 179 AliFlowEventSimple* fEvent = NULL;
7183fe85 180 Double_t fRP = 0.; // the monte carlo reaction plane angle
181 AliMCEvent* mcEvent = NULL;
182 // See if we can get Monte Carlo Information and if so get the reaction plane
183
184 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
185 if (eventHandler) {
186 mcEvent = eventHandler->MCEvent();
187 if (mcEvent) {
c9f92d16 188 if (!strcmp(mcEvent-> GenEventHeader()->GetName(),"Cocktail Header")) { //returns 0 if matches
189 AliGenCocktailEventHeader *headerC = dynamic_cast<AliGenCocktailEventHeader *> (mcEvent-> GenEventHeader());
190 if (headerC) {
191 TList *lhd = headerC->GetHeaders();
192 if (lhd) {
193 AliGenHijingEventHeader *hdh = dynamic_cast<AliGenHijingEventHeader *> (lhd->At(0));
194 if (hdh) {
195 fRP = hdh->ReactionPlaneAngle();
196 //cout<<"The reactionPlane from Hijing is: "<< fRP <<endl;
197 }
7183fe85 198 }
199 }
c9f92d16 200 //else { cout<<"headerC is NULL"<<endl; }
201 }
202 else if (!strcmp(mcEvent-> GenEventHeader()->GetName(),"GeVSim header")) { //returns 0 if matches
203 AliGenGeVSimEventHeader* headerG = (AliGenGeVSimEventHeader*)(mcEvent->GenEventHeader());
204 if (headerG) {
205 fRP = headerG->GetEventPlane();
206 //cout<<"The reactionPlane from GeVSim is: "<< fRP <<endl;
207 }
208 //else { cout<<"headerG is NULL"<<endl; }
7183fe85 209 }
210 }
c9f92d16 211 //else {cout<<"No MC event!"<<endl; }
7183fe85 212 }
c9f92d16 213 //else {cout<<"No eventHandler!"<<endl; }
62726ef0 214
215 // set the value of the monte carlo event plane for the flow event
216 fEventMaker->SetMCReactionPlaneAngle(fRP);
217
218 // Fill the FlowEventSimple for MC input
1c1d4332 219 if (fAnalysisType == "MC") {
587b0a35 220 if (!fCFManager1) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
221 if (!fCFManager2) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
1c1d4332 222
223 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
224 // This handler can return the current MC event
587b0a35 225 if (!mcEvent) { Printf("ERROR: Could not retrieve MC event"); return;}
1c1d4332 226
227 fCFManager1->SetEventInfo(mcEvent);
228 fCFManager2->SetEventInfo(mcEvent);
587b0a35 229
1c1d4332 230 // analysis
7183fe85 231 Printf("Number of MC particles: %d", mcEvent->GetNumberOfTracks());
89f41a6a 232 fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
1c1d4332 233 // here we have the fEvent and want to make it available as an output stream
7183fe85 234 // so no delete fEvent;
1c1d4332 235 }
62726ef0 236 // Fill the FlowEventSimple for ESD input
1c1d4332 237 else if (fAnalysisType == "ESD") {
587b0a35 238 if (!fCFManager1) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
239 if (!fCFManager2) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
240
241 if (!fESD) { Printf("ERROR: fESD not available"); return;}
1c1d4332 242 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
243
244 // analysis
89f41a6a 245 fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);
1c1d4332 246 }
62726ef0 247 // Fill the FlowEventSimple for ESD input combined with MC info
1c1d4332 248 else if (fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
587b0a35 249 if (!fCFManager1) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
250 if (!fCFManager2) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
251 if (!fESD) { Printf("ERROR: fESD not available"); return;}
1c1d4332 252 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
253
587b0a35 254 if (!mcEvent) {Printf("ERROR: Could not retrieve MC event"); return;}
1c1d4332 255
256 fCFManager1->SetEventInfo(mcEvent);
257 fCFManager2->SetEventInfo(mcEvent);
258
89f41a6a 259
1c1d4332 260 if (fAnalysisType == "ESDMC0") {
261 fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
262 } else if (fAnalysisType == "ESDMC1") {
263 fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
264 }
1c1d4332 265 }
62726ef0 266 // Fill the FlowEventSimple for AOD input
1c1d4332 267 else if (fAnalysisType == "AOD") {
587b0a35 268 if (!fAOD) {Printf("ERROR: fAOD not available"); return;}
1c1d4332 269 Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
270
271 // analysis
272 //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
89f41a6a 273 fEvent = fEventMaker->FillTracks(fAOD);
1c1d4332 274 }
275
46bec39c 276 //fListHistos->Print();
277 // fOutputFile->WriteObject(fEvent,"myFlowEventSimple");
1c1d4332 278 PostData(0,fEvent);
279 if (fQA) {
280 PostData(1,fQAInt);
281 PostData(2,fQADiff); }
282}
283
284//________________________________________________________________________
285void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
286{
287 // Called once at the end of the query -- do not call in case of CAF
288
289}