]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/AliFlowTasks/AliAnalysisTaskFlowEvent.cxx
macro made compilable + storage added as parameter and few other tiny things
[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"
489fdf79 21#include "TRandom3.h"
22#include "TTimeStamp.h"
1c1d4332 23
7183fe85 24// ALICE Analysis Framework
1c1d4332 25class AliAnalysisTask;
26#include "AliAnalysisManager.h"
27
7183fe85 28// ESD interface
1c1d4332 29#include "AliESDEvent.h"
30#include "AliESDInputHandler.h"
31
7183fe85 32// AOD interface
1c1d4332 33#include "AliAODEvent.h"
34#include "AliAODInputHandler.h"
35
7183fe85 36// Monte Carlo Event
1c1d4332 37#include "AliMCEventHandler.h"
38#include "AliMCEvent.h"
39
7183fe85 40// ALICE Correction Framework
1c1d4332 41#include "AliCFManager.h"
42
7183fe85 43// Interface to Event generators to get Reaction Plane Angle
44#include "AliGenCocktailEventHeader.h"
45#include "AliGenHijingEventHeader.h"
48ad51a1 46#include "AliGenGeVSimEventHeader.h"
7183fe85 47
48// Interface to make the Flow Event Simple used in the flow analysis methods
1c1d4332 49#include "AliFlowEventSimpleMaker.h"
50
7183fe85 51#include "AliAnalysisTaskFlowEvent.h"
52
489fdf79 53// AliAnalysisTaskFlowEvent:
54//
55// analysis task for filling the flow event
56// from MCEvent, ESD, AOD ....
57// and put it in an output stream so it can
58// be used by the various flow analysis methods
59// for cuts the correction framework is used
60// which also outputs QA histrograms to view
61// the effects of the cuts
62
1c1d4332 63
64ClassImp(AliAnalysisTaskFlowEvent)
73160af6 65
1c1d4332 66//________________________________________________________________________
67AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on) :
68 AliAnalysisTask(name, ""),
46bec39c 69// fOutputFile(NULL),
1c1d4332 70 fESD(NULL),
71 fAOD(NULL),
72 fEventMaker(NULL),
73 fAnalysisType("ESD"),
74 fCFManager1(NULL),
75 fCFManager2(NULL),
76 fQAInt(NULL),
77 fQADiff(NULL),
489fdf79 78 fQA(on),
79 fMCReactionPlaneAngle(0.),
80 fCount(0),
81 fNoOfLoops(1),
82 fEllipticFlowValue(0.),
83 fSigmaEllipticFlowValue(0.),
84 fMultiplicityOfEvent(1000000000),
85 fSigmaMultiplicityOfEvent(0),
86 fMyTRandom3(NULL)
1c1d4332 87{
88 // Constructor
89 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name)"<<endl;
90
91 // Define input and output slots here
92 // Input slot #0 works with a TChain
93 DefineInput(0, TChain::Class());
46bec39c 94 // Define here the flow event output
95 DefineOutput(0, AliFlowEventSimple::Class());
1c1d4332 96 if(on) {
97 DefineOutput(1, TList::Class());
98 DefineOutput(2, TList::Class()); }
46bec39c 99 // and for testing open an output file
489fdf79 100 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
1c1d4332 101
102}
103
104//________________________________________________________________________
105AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
46bec39c 106 // fOutputFile(NULL),
1c1d4332 107 fESD(NULL),
108 fAOD(NULL),
109 fEventMaker(NULL),
110 fAnalysisType("ESD"),
111 fCFManager1(NULL),
112 fCFManager2(NULL),
113 fQAInt(NULL),
114 fQADiff(NULL),
489fdf79 115 fQA(kFALSE),
116 fMCReactionPlaneAngle(0.),
117 fCount(0),
118 fNoOfLoops(1),
119 fEllipticFlowValue(0.),
120 fSigmaEllipticFlowValue(0.),
121 fMultiplicityOfEvent(1000000000),
122 fSigmaMultiplicityOfEvent(0),
123 fMyTRandom3(NULL)
1c1d4332 124{
125 // Constructor
126 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
127}
128
489fdf79 129//________________________________________________________________________
130AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed) :
131 AliAnalysisTask(name, ""),
132// fOutputFile(NULL),
133 fESD(NULL),
134 fAOD(NULL),
135 fEventMaker(NULL),
136 fAnalysisType("ESD"),
137 fCFManager1(NULL),
138 fCFManager2(NULL),
139 fQAInt(NULL),
140 fQADiff(NULL),
141 fQA(on),
142 fMCReactionPlaneAngle(0.),
143 fCount(0),
144 fNoOfLoops(1),
145 fEllipticFlowValue(0.),
146 fSigmaEllipticFlowValue(0.),
147 fMultiplicityOfEvent(1000000000),
148 fSigmaMultiplicityOfEvent(0),
149 fMyTRandom3(NULL)
150{
151 // Constructor
152 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed)"<<endl;
153
154 fMyTRandom3 = new TRandom3(iseed);
155 gRandom->SetSeed(fMyTRandom3->Integer(65539));
156
157 // Define input and output slots here
158 // Input slot #0 works with a TChain
159 DefineInput(0, TChain::Class());
160 // Define here the flow event output
161 DefineOutput(0, AliFlowEventSimple::Class());
162 if(on) {
163 DefineOutput(1, TList::Class());
164 DefineOutput(2, TList::Class()); }
165 // and for testing open an output file
166 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
167
168}
169
1c1d4332 170//________________________________________________________________________
171AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
172{
173 //
174 // Destructor
175 //
489fdf79 176 if (fMyTRandom3) delete fMyTRandom3;
1c1d4332 177 // objects in the output list are deleted
178 // by the TSelector dtor (I hope)
179
180}
181
182//________________________________________________________________________
183void AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *)
184{
185 // Connect ESD or AOD here
186 // Called once
187 cout<<"AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *)"<<endl;
188
189 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
190 if (!tree) {
191 Printf("ERROR: Could not read chain from input slot 0");
3507ac7e 192 }
193 else {
194 if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" || fAnalysisType == "MC") {
1c1d4332 195 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
1c1d4332 196 if (!esdH) {
197 Printf("ERROR: Could not get ESDInputHandler");
3507ac7e 198 }
199 else {fESD = esdH->GetEvent();}
1c1d4332 200 }
201 else if (fAnalysisType == "AOD") {
202 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
1c1d4332 203 if (!aodH) {
204 Printf("ERROR: Could not get AODInputHandler");
205 }
3507ac7e 206 else { fAOD = aodH->GetEvent();}
1c1d4332 207 }
208 else {
209 Printf("!!!!!Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
210 exit(1);
1c1d4332 211 }
212 }
213}
214
215//________________________________________________________________________
216void AliAnalysisTaskFlowEvent::CreateOutputObjects()
217{
218 // Called at every worker node to initialize
219 cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
220
221 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) {
222 cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
223 exit(1);
224 }
225
226 // Flow Event maker
227 fEventMaker = new AliFlowEventSimpleMaker();
228}
229
230//________________________________________________________________________
231void AliAnalysisTaskFlowEvent::Exec(Option_t *)
232{
233 // Main loop
234 // Called for each event
89f41a6a 235 AliFlowEventSimple* fEvent = NULL;
7183fe85 236 Double_t fRP = 0.; // the monte carlo reaction plane angle
237 AliMCEvent* mcEvent = NULL;
238 // See if we can get Monte Carlo Information and if so get the reaction plane
239
240 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
241 if (eventHandler) {
242 mcEvent = eventHandler->MCEvent();
243 if (mcEvent) {
d5acfb36 244 //COCKTAIL with HIJING
c9f92d16 245 if (!strcmp(mcEvent-> GenEventHeader()->GetName(),"Cocktail Header")) { //returns 0 if matches
246 AliGenCocktailEventHeader *headerC = dynamic_cast<AliGenCocktailEventHeader *> (mcEvent-> GenEventHeader());
247 if (headerC) {
248 TList *lhd = headerC->GetHeaders();
249 if (lhd) {
250 AliGenHijingEventHeader *hdh = dynamic_cast<AliGenHijingEventHeader *> (lhd->At(0));
251 if (hdh) {
252 fRP = hdh->ReactionPlaneAngle();
489fdf79 253 //cout<<"The reactionPlane from Hijing is: "<< fRP <<endl;
c9f92d16 254 }
7183fe85 255 }
256 }
c9f92d16 257 //else { cout<<"headerC is NULL"<<endl; }
258 }
d5acfb36 259 //GEVSIM
c9f92d16 260 else if (!strcmp(mcEvent-> GenEventHeader()->GetName(),"GeVSim header")) { //returns 0 if matches
261 AliGenGeVSimEventHeader* headerG = (AliGenGeVSimEventHeader*)(mcEvent->GenEventHeader());
262 if (headerG) {
263 fRP = headerG->GetEventPlane();
264 //cout<<"The reactionPlane from GeVSim is: "<< fRP <<endl;
265 }
266 //else { cout<<"headerG is NULL"<<endl; }
7183fe85 267 }
d5acfb36 268 //HIJING
269 else if (!strcmp(mcEvent-> GenEventHeader()->GetName(),"Hijing")) { //returns 0 if matches
270 AliGenHijingEventHeader* headerH = (AliGenHijingEventHeader*)(mcEvent->GenEventHeader());
271 if (headerH) {
272 fRP = headerH->ReactionPlaneAngle();
273 //cout<<"The reactionPlane from Hijing is: "<< fRP <<endl;
274 }
275 //else { cout<<"headerH is NULL"<<endl; }
276 }
7183fe85 277 }
489fdf79 278 //else {cout<<"No MC event!"<<endl; }
d5acfb36 279
7183fe85 280 }
c9f92d16 281 //else {cout<<"No eventHandler!"<<endl; }
d5acfb36 282
62726ef0 283 // set the value of the monte carlo event plane for the flow event
489fdf79 284 //RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
285 // paste setters from AliFlowEventSimpleMaker.cxx
286 //RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
287// TRandom3 random3Temp2; //init for manual settings (R.Rietkerk)
288// TTimeStamp dt2;
289// Int_t sseed2 = dt2.GetNanoSec()/1000;
290// random3Temp2.SetSeed(sseed2);
291// cout << "seed2 = " << sseed2 << endl;
292// cout << "random2 = " << random3Temp2.Rndm() << endl;
293 //RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
294 cout << "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" << endl;
295 cout << "TaskFlowEvent.cxx" << endl;
296 cout << "fCount" << fCount << endl;
297 cout << "fNoOfLoops" << fNoOfLoops << endl;
298 cout << "fEllipticFlowValue" << fEllipticFlowValue << endl;
299 cout << "fSigmaEllipticFlowValue" << fSigmaEllipticFlowValue << endl;
300 cout << "fMultiplicityOfEvent" << fMultiplicityOfEvent << endl;
301 cout << "fSigmaMultiplicityOfEvent" << fSigmaMultiplicityOfEvent << endl;
302
303 cout << "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" << endl;
304 Double_t xRPangle=TMath::TwoPi()*(fMyTRandom3->Rndm());
305 Double_t xNewFlowValue = fMyTRandom3->Gaus(fEllipticFlowValue,fSigmaEllipticFlowValue);
306 Int_t nNewMultOfEvent = fMyTRandom3->Gaus(fMultiplicityOfEvent,fSigmaMultiplicityOfEvent);
307
308 cout << "xRPangle = " << xRPangle << endl;
309 cout << "xNewFlowValue = " << xNewFlowValue << endl;
310 cout << "nNewMultOfEvent = " << nNewMultOfEvent << endl;
311 cout << "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" << endl;
312 //Int_t nNewMultOfEvent = random3Temp.Gaus(nMultiplicityOfEvent,nSigmaMult);
313 // cout << "new multiplicity: " << nNewMultOfEvent << endl;
314 //Double_t xNewFlowValue = random3Temp.Gaus(xEllipticFlowValue,xSigmaFlow);
315 // cout << "new flow value: " << xNewFlowValue << endl;
316 //fEventMaker->SetMCReactionPlaneAngle(fRP);
317 fEventMaker->SetMCReactionPlaneAngle(xRPangle);
318 fEventMaker->SetNoOfLoops(fNoOfLoops);
319 fEventMaker->SetEllipticFlowValue(xNewFlowValue);
320 fEventMaker->SetMultiplicityOfEvent(nNewMultOfEvent);
321 //RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
d5acfb36 322
62726ef0 323 // Fill the FlowEventSimple for MC input
1c1d4332 324 if (fAnalysisType == "MC") {
587b0a35 325 if (!fCFManager1) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
326 if (!fCFManager2) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
1c1d4332 327
328 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
329 // This handler can return the current MC event
587b0a35 330 if (!mcEvent) { Printf("ERROR: Could not retrieve MC event"); return;}
1c1d4332 331
332 fCFManager1->SetEventInfo(mcEvent);
333 fCFManager2->SetEventInfo(mcEvent);
587b0a35 334
1c1d4332 335 // analysis
7183fe85 336 Printf("Number of MC particles: %d", mcEvent->GetNumberOfTracks());
89f41a6a 337 fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
1c1d4332 338 // here we have the fEvent and want to make it available as an output stream
7183fe85 339 // so no delete fEvent;
1c1d4332 340 }
62726ef0 341 // Fill the FlowEventSimple for ESD input
1c1d4332 342 else if (fAnalysisType == "ESD") {
587b0a35 343 if (!fCFManager1) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
344 if (!fCFManager2) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
345
346 if (!fESD) { Printf("ERROR: fESD not available"); return;}
1c1d4332 347 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
348
349 // analysis
89f41a6a 350 fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);
1c1d4332 351 }
62726ef0 352 // Fill the FlowEventSimple for ESD input combined with MC info
1c1d4332 353 else if (fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
587b0a35 354 if (!fCFManager1) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
355 if (!fCFManager2) {cout << "ERROR: No pointer to correction framework cuts! " << endl; return; }
356 if (!fESD) { Printf("ERROR: fESD not available"); return;}
1c1d4332 357 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
358
587b0a35 359 if (!mcEvent) {Printf("ERROR: Could not retrieve MC event"); return;}
1c1d4332 360
361 fCFManager1->SetEventInfo(mcEvent);
362 fCFManager2->SetEventInfo(mcEvent);
363
489fdf79 364
1c1d4332 365 if (fAnalysisType == "ESDMC0") {
366 fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
367 } else if (fAnalysisType == "ESDMC1") {
368 fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
369 }
1c1d4332 370 }
62726ef0 371 // Fill the FlowEventSimple for AOD input
1c1d4332 372 else if (fAnalysisType == "AOD") {
587b0a35 373 if (!fAOD) {Printf("ERROR: fAOD not available"); return;}
1c1d4332 374 Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
375
376 // analysis
377 //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
89f41a6a 378 fEvent = fEventMaker->FillTracks(fAOD);
1c1d4332 379 }
380
46bec39c 381 //fListHistos->Print();
382 // fOutputFile->WriteObject(fEvent,"myFlowEventSimple");
1c1d4332 383 PostData(0,fEvent);
384 if (fQA) {
385 PostData(1,fQAInt);
386 PostData(2,fQADiff); }
387}
388
389//________________________________________________________________________
390void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
391{
392 // Called once at the end of the query -- do not call in case of CAF
393
394}
489fdf79 395
396