]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/AliFlowTasks/AliAnalysisTaskFlowEvent.cxx
some coverty fixes
[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 *
940a5ed1 13* provided "as is" without express or implied warranty. *
1c1d4332 14**************************************************************************/
15
fdff44c8 16////////////////////////////////////////////////////
17// AliAnalysisTaskFlowEvent:
18//
19// analysis task for filling the flow event
20// from MCEvent, ESD, AOD ....
940a5ed1 21// and put it in an output stream so it can
22// be used by the various flow analysis methods
fdff44c8 23// for cuts the correction framework is used
24// which also outputs QA histograms to view
25// the effects of the cuts
26////////////////////////////////////////////////////
27
1c1d4332 28#include "Riostream.h" //needed as include
29#include "TChain.h"
30#include "TTree.h"
31#include "TFile.h" //needed as include
32#include "TList.h"
44e060e0 33#include "TH2F.h"
489fdf79 34#include "TRandom3.h"
35#include "TTimeStamp.h"
1c1d4332 36
7183fe85 37// ALICE Analysis Framework
1c1d4332 38#include "AliAnalysisManager.h"
fbdb53fa 39#include "AliAnalysisTaskSE.h"
85d2ee8d 40#include "AliESDtrackCuts.h"
1c1d4332 41
7183fe85 42// ESD interface
1c1d4332 43#include "AliESDEvent.h"
44#include "AliESDInputHandler.h"
45
7183fe85 46// AOD interface
1c1d4332 47#include "AliAODEvent.h"
48#include "AliAODInputHandler.h"
49
7183fe85 50// Monte Carlo Event
1c1d4332 51#include "AliMCEventHandler.h"
52#include "AliMCEvent.h"
53
7183fe85 54// ALICE Correction Framework
1c1d4332 55#include "AliCFManager.h"
56
7183fe85 57// Interface to Event generators to get Reaction Plane Angle
58#include "AliGenCocktailEventHeader.h"
59#include "AliGenHijingEventHeader.h"
48ad51a1 60#include "AliGenGeVSimEventHeader.h"
26f120fa 61#include "AliGenEposEventHeader.h"
7183fe85 62
6e214c87 63// Interface to Load short life particles
64#include "TObjArray.h"
65#include "AliFlowCandidateTrack.h"
66
7183fe85 67// Interface to make the Flow Event Simple used in the flow analysis methods
940a5ed1 68#include "AliFlowEvent.h"
daf66719 69#include "AliFlowTrackCuts.h"
70#include "AliFlowEventCuts.h"
d459546b 71#include "AliFlowCommonConstants.h"
7183fe85 72#include "AliAnalysisTaskFlowEvent.h"
73
77111ee6 74#include "AliLog.h"
75
1c1d4332 76ClassImp(AliAnalysisTaskFlowEvent)
940a5ed1 77
1c1d4332 78//________________________________________________________________________
940a5ed1 79AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
80 AliAnalysisTaskSE(),
46bec39c 81 // fOutputFile(NULL),
12b2b8bc 82 fAnalysisType("AUTOMATIC"),
ef4799a7 83 fRPType("Global"),
1c1d4332 84 fCFManager1(NULL),
85 fCFManager2(NULL),
daf66719 86 fCutsEvent(NULL),
87 fCutsRP(NULL),
88 fCutsPOI(NULL),
1c1d4332 89 fQAInt(NULL),
90 fQADiff(NULL),
fdff44c8 91 fMinMult(0),
92 fMaxMult(10000000),
7a01f4a7 93 fMinA(-1.0),
94 fMaxA(-0.01),
95 fMinB(0.01),
96 fMaxB(1.0),
489fdf79 97 fQA(kFALSE),
6e214c87 98 fLoadCandidates(kFALSE),
d459546b 99 fNbinsMult(10000),
100 fNbinsPt(100),
101 fNbinsPhi(100),
102 fNbinsEta(200),
103 fNbinsQ(500),
104 fMultMin(0.),
105 fMultMax(10000.),
106 fPtMin(0.),
107 fPtMax(10.),
108 fPhiMin(0.),
109 fPhiMax(TMath::TwoPi()),
110 fEtaMin(-5.),
111 fEtaMax(5.),
112 fQMin(0.),
113 fQMax(3.),
f6f8c3fc 114 fExcludedEtaMin(0.),
115 fExcludedEtaMax(0.),
116 fExcludedPhiMin(0.),
117 fExcludedPhiMax(0.),
54089829 118 fAfterburnerOn(kFALSE),
119 fNonFlowNumberOfTrackClones(0),
120 fV1(0.),
121 fV2(0.),
122 fV3(0.),
123 fV4(0.),
aab6527a 124 fMyTRandom3(NULL)
1c1d4332 125{
126 // Constructor
127 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
128}
129
489fdf79 130//________________________________________________________________________
6e214c87 131AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPtype, Bool_t on, UInt_t iseed, Bool_t bCandidates) :
940a5ed1 132 AliAnalysisTaskSE(name),
133 // fOutputFile(NULL),
12b2b8bc 134 fAnalysisType("AUTOMATIC"),
44e060e0 135 fRPType(RPtype),
489fdf79 136 fCFManager1(NULL),
137 fCFManager2(NULL),
daf66719 138 fCutsEvent(NULL),
139 fCutsRP(NULL),
140 fCutsPOI(NULL),
489fdf79 141 fQAInt(NULL),
142 fQADiff(NULL),
fdff44c8 143 fMinMult(0),
144 fMaxMult(10000000),
7a01f4a7 145 fMinA(-1.0),
146 fMaxA(-0.01),
147 fMinB(0.01),
148 fMaxB(1.0),
489fdf79 149 fQA(on),
6e214c87 150 fLoadCandidates(bCandidates),
d459546b 151 fNbinsMult(10000),
152 fNbinsPt(100),
153 fNbinsPhi(100),
154 fNbinsEta(200),
155 fNbinsQ(500),
156 fMultMin(0.),
157 fMultMax(10000.),
158 fPtMin(0.),
159 fPtMax(10.),
160 fPhiMin(0.),
161 fPhiMax(TMath::TwoPi()),
162 fEtaMin(-5.),
163 fEtaMax(5.),
164 fQMin(0.),
165 fQMax(3.),
f6f8c3fc 166 fExcludedEtaMin(0.),
167 fExcludedEtaMax(0.),
168 fExcludedPhiMin(0.),
169 fExcludedPhiMax(0.),
54089829 170 fAfterburnerOn(kFALSE),
171 fNonFlowNumberOfTrackClones(0),
172 fV1(0.),
173 fV2(0.),
174 fV3(0.),
175 fV4(0.),
aab6527a 176 fMyTRandom3(NULL)
489fdf79 177{
178 // Constructor
179 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed)"<<endl;
940a5ed1 180 fMyTRandom3 = new TRandom3(iseed);
489fdf79 181 gRandom->SetSeed(fMyTRandom3->Integer(65539));
65201059 182
6e214c87 183 int availableINslot=1;
44e060e0 184 //FMD input slot
185 if (strcmp(RPtype,"FMD")==0) {
6e214c87 186 DefineInput(availableINslot++, TList::Class());
44e060e0 187 }
6e214c87 188 //Candidates input slot
189 if( fLoadCandidates )
190 DefineInput(availableINslot, TObjArray::Class());
65201059 191
192 // Define output slots here
489fdf79 193 // Define here the flow event output
940a5ed1 194 DefineOutput(1, AliFlowEventSimple::Class());
195 if(on)
196 {
65201059 197 DefineOutput(2, TList::Class());
940a5ed1 198 DefineOutput(3, TList::Class());
199 }
6e214c87 200
489fdf79 201 // and for testing open an output file
202 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
203
204}
205
1c1d4332 206//________________________________________________________________________
207AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
208{
209 //
210 // Destructor
211 //
32b846cd 212 delete fMyTRandom3;
940a5ed1 213 // objects in the output list are deleted
1c1d4332 214 // by the TSelector dtor (I hope)
215
216}
217
32b846cd 218//________________________________________________________________________
219void AliAnalysisTaskFlowEvent::NotifyRun()
220{
221 //at the beginning of each new run
222 AliESDEvent* fESD = dynamic_cast<AliESDEvent*> (InputEvent());
2a745a5f 223 if (!fESD) return;
3abf7ecc 224
225 Int_t run = fESD->GetRunNumber();
226 AliInfo(Form("Stariting run #%i",run));
32b846cd 227}
228
1c1d4332 229//________________________________________________________________________
940a5ed1 230void AliAnalysisTaskFlowEvent::UserCreateOutputObjects()
1c1d4332 231{
232 // Called at every worker node to initialize
233 cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
234
12b2b8bc 235 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" || fAnalysisType == "MC" || fAnalysisType == "AUTOMATIC"))
940a5ed1 236 {
12b2b8bc 237 AliError("WRONG ANALYSIS TYPE! only ESD, ESDMCkineESD, ESDMCkineMC, AOD, MC and AUTOMATIC are allowed.");
1c1d4332 238 exit(1);
239 }
d459546b 240
241 //set the common constants
242 AliFlowCommonConstants* cc = AliFlowCommonConstants::GetMaster();
243 cc->SetNbinsMult(fNbinsMult);
244 cc->SetNbinsPt(fNbinsPt);
245 cc->SetNbinsPhi(fNbinsPhi);
246 cc->SetNbinsEta(fNbinsEta);
247 cc->SetNbinsQ(fNbinsQ);
248 cc->SetMultMin(fMultMin);
249 cc->SetMultMax(fMultMax);
250 cc->SetPtMin(fPtMin);
251 cc->SetPtMax(fPtMax);
252 cc->SetPhiMin(fPhiMin);
253 cc->SetPhiMax(fPhiMax);
254 cc->SetEtaMin(fEtaMin);
255 cc->SetEtaMax(fEtaMax);
256 cc->SetQMin(fQMin);
257 cc->SetQMax(fQMax);
258
1c1d4332 259}
260
261//________________________________________________________________________
940a5ed1 262void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
1c1d4332 263{
264 // Main loop
265 // Called for each event
940a5ed1 266 AliFlowEvent* flowEvent = NULL;
267 AliMCEvent* mcEvent = MCEvent(); // from TaskSE
268 AliESDEvent* myESD = dynamic_cast<AliESDEvent*>(InputEvent()); // from TaskSE
269 AliAODEvent* myAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
ef4799a7 270 AliMultiplicity* myTracklets = NULL;
333ce021 271 AliESDPmdTrack* pmdtracks = NULL;//pmd
44e060e0 272 TH2F* histFMD = NULL;
ef4799a7 273
6e214c87 274 int availableINslot=1;
275 if(strcmp(fRPType,"FMD")==0) {
276 TList* FMDdata = dynamic_cast<TList*>(GetInputData(availableINslot++));
44e060e0 277 if(!FMDdata) {
278 cout<<" No FMDdata "<<endl;
279 exit(2);
280 }
281 histFMD = dynamic_cast<TH2F*>(FMDdata->FindObject("dNdetadphiHistogramTrVtx"));
282 if (!histFMD) {
283 cout<< "No histFMD"<<endl;
284 exit(2);
285 }
286 }
3ca4688a 287
2a745a5f 288 if (!(fCutsRP&&fCutsPOI&&fCutsEvent))
289 {
290 AliError("cuts not set");
291 return;
292 }
293
3abf7ecc 294 //use the new and temporarily incomplete way of doing things
12b2b8bc 295 if (fAnalysisType == "AUTOMATIC")
daf66719 296 {
7d9ab4fb 297 //check event cuts
2a745a5f 298 if (!fCutsEvent->IsSelected(InputEvent())) return;
7d9ab4fb 299
03d364db 300 //first attach all possible information to the cuts
441ea1cf 301 fCutsRP->SetEvent( InputEvent(), MCEvent() ); //attach event
302 fCutsPOI->SetEvent( InputEvent(), MCEvent() );
32b846cd 303
03d364db 304 //then make the event
305 flowEvent = new AliFlowEvent( fCutsRP, fCutsPOI );
daf66719 306 if (myESD)
9a0783cc 307 flowEvent->SetReferenceMultiplicity(fCutsEvent->GetReferenceMultiplicity(InputEvent()));
333ce021 308 if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
daf66719 309 }
940a5ed1 310
311 // Make the FlowEvent for MC input
312 if (fAnalysisType == "MC")
313 {
1c1d4332 314 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
315 // This handler can return the current MC event
940a5ed1 316 if (!(fCFManager1&&fCFManager2))
317 {
77111ee6 318 AliError("ERROR: No pointer to correction framework cuts! ");
940a5ed1 319 return;
320 }
321 if (!mcEvent)
322 {
77111ee6 323 AliError("ERROR: Could not retrieve MC event");
940a5ed1 324 return;
325 }
1c1d4332 326
6d7734d2 327 fCFManager1->SetMCEventInfo(mcEvent);
328 fCFManager2->SetMCEventInfo(mcEvent);
940a5ed1 329
77111ee6 330 AliInfo(Form("Number of MC particles: %d", mcEvent->GetNumberOfTracks()));
331
332 //check multiplicity
333 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtGenCuts,mcEvent))
334 {
335 AliWarning("Event does not pass multiplicity cuts"); return;
336 }
337 //make event
940a5ed1 338 flowEvent = new AliFlowEvent(mcEvent,fCFManager1,fCFManager2);
1c1d4332 339 }
ef4799a7 340
940a5ed1 341 // Make the FlowEvent for ESD input
342 else if (fAnalysisType == "ESD")
343 {
344 if (!(fCFManager1&&fCFManager2))
345 {
77111ee6 346 AliError("ERROR: No pointer to correction framework cuts!");
940a5ed1 347 return;
348 }
349 if (!myESD)
350 {
77111ee6 351 AliError("ERROR: ESD not available");
940a5ed1 352 return;
353 }
77111ee6 354
b0569f96 355 //check the offline trigger (check if the event has the correct trigger)
ade93aa4 356 AliInfo(Form("ESD has %d tracks", fInputEvent->GetNumberOfTracks()));
77111ee6 357
358 //check multiplicity
359 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
360 {
361 AliWarning("Event does not pass multiplicity cuts"); return;
362 }
363
364 //make event
ef4799a7 365 if (fRPType == "Global") {
366 flowEvent = new AliFlowEvent(myESD,fCFManager1,fCFManager2);
367 }
cd755f77 368 if (fRPType == "TPCOnly") {
369 flowEvent = new AliFlowEvent(myESD,fCFManager2,kFALSE);
370 }
371 if (fRPType == "TPCHybrid") {
372 flowEvent = new AliFlowEvent(myESD,fCFManager2,kTRUE);
373 }
ef4799a7 374 else if (fRPType == "Tracklet"){
375 flowEvent = new AliFlowEvent(myESD,myTracklets,fCFManager2);
376 }
44e060e0 377 else if (fRPType == "FMD"){
378 flowEvent = new AliFlowEvent(myESD,histFMD,fCFManager2);
379 }
333ce021 380 //pmd
381 else if (fRPType == "PMD"){
382 flowEvent = new AliFlowEvent(myESD,pmdtracks,fCFManager2);
383 }
384 //pmd
44e060e0 385
ef4799a7 386 // if monte carlo event get reaction plane from monte carlo (depends on generator)
422c61c7 387 if (flowEvent)
388 {
389 if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
390 //set reference multiplicity, TODO: maybe move it to the constructor?
391 flowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
392 }
1c1d4332 393 }
ef4799a7 394
940a5ed1 395 // Make the FlowEvent for ESD input combined with MC info
396 else if (fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" )
397 {
398 if (!(fCFManager1&&fCFManager2))
399 {
77111ee6 400 AliError("ERROR: No pointer to correction framework cuts! ");
940a5ed1 401 return;
402 }
403 if (!myESD)
404 {
77111ee6 405 AliError("ERROR: ESD not available");
940a5ed1 406 return;
407 }
77111ee6 408 AliInfo(Form("There are %d tracks in this event", fInputEvent->GetNumberOfTracks()));
940a5ed1 409
410 if (!mcEvent)
411 {
77111ee6 412 AliError("ERROR: Could not retrieve MC event");
940a5ed1 413 return;
414 }
1c1d4332 415
6d7734d2 416 fCFManager1->SetMCEventInfo(mcEvent);
417 fCFManager2->SetMCEventInfo(mcEvent);
1c1d4332 418
77111ee6 419 //check multiplicity
420 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
421 {
422 AliWarning("Event does not pass multiplicity cuts"); return;
423 }
424
425 //make event
940a5ed1 426 if (fAnalysisType == "ESDMCkineESD")
427 {
428 flowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kESDkine, fCFManager1, fCFManager2 );
429 }
430 else if (fAnalysisType == "ESDMCkineMC")
431 {
432 flowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kMCkine, fCFManager1, fCFManager2 );
1c1d4332 433 }
85d2ee8d 434 // if monte carlo event get reaction plane from monte carlo (depends on generator)
435 if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
436 //set reference multiplicity, TODO: maybe move it to the constructor?
437 flowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
1c1d4332 438 }
940a5ed1 439 // Make the FlowEventSimple for AOD input
440 else if (fAnalysisType == "AOD")
441 {
442 if (!myAOD)
443 {
77111ee6 444 AliError("ERROR: AOD not available");
940a5ed1 445 return;
446 }
ade93aa4 447 AliInfo(Form("AOD has %d tracks", myAOD->GetNumberOfTracks()));
940a5ed1 448 flowEvent = new AliFlowEvent(myAOD);
1c1d4332 449 }
450
6e214c87 451 //inject candidates
452 if(fLoadCandidates) {
453 TObjArray* Candidates = dynamic_cast<TObjArray*>(GetInputData(availableINslot++));
422c61c7 454 AliFlowCandidateTrack *cand = NULL;
455 if (Candidates)
456 {
457 for(int iCand=0; iCand!=Candidates->GetEntriesFast(); ++iCand )
458 {
459 cand = dynamic_cast<AliFlowCandidateTrack*>(Candidates->At(iCand));
460 if (!cand) continue;
461 cand->SetForPOISelection();
462 flowEvent->AddTrack(cand);
463 }
6e214c87 464 }
465 }
466
77111ee6 467 //check final event cuts
940a5ed1 468 Int_t mult = flowEvent->NumberOfTracks();
ade93aa4 469 AliInfo(Form("FlowEvent has %i tracks",mult));
470 if (mult<fMinMult || mult>fMaxMult)
77111ee6 471 {
472 AliWarning("FlowEvent cut on multiplicity"); return;
473 }
940a5ed1 474
f6f8c3fc 475 //define dead zone
476 flowEvent->DefineDeadZone(fExcludedEtaMin, fExcludedEtaMax, fExcludedPhiMin, fExcludedPhiMax );
477
478
54089829 479 //////////////////////////////////////////////////////////////////////////////
480 ///////////////////////////AFTERBURNER
481 if (fAfterburnerOn)
482 {
483 //if reaction plane not set from elsewhere randomize it before adding flow
484 if (!flowEvent->IsSetMCReactionPlaneAngle())
485 flowEvent->SetMCReactionPlaneAngle(gRandom->Uniform(0.0,TMath::TwoPi()));
486
487 flowEvent->AddFlow(fV1,fV2,fV3,fV4); //add flow
488 flowEvent->CloneTracks(fNonFlowNumberOfTrackClones); //add nonflow by cloning tracks
489 }
490 //////////////////////////////////////////////////////////////////////////////
491
ef4799a7 492 //tag subEvents
940a5ed1 493 flowEvent->TagSubeventsInEta(fMinA,fMaxA,fMinB,fMaxB);
494
46bec39c 495 //fListHistos->Print();
ef4799a7 496 //fOutputFile->WriteObject(flowEvent,"myFlowEventSimple");
940a5ed1 497 PostData(1,flowEvent);
498 if (fQA)
499 {
65201059 500 PostData(2,fQAInt);
940a5ed1 501 PostData(3,fQADiff);
502 }
503}
1c1d4332 504
505//________________________________________________________________________
940a5ed1 506void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
1c1d4332 507{
508 // Called once at the end of the query -- do not call in case of CAF
1c1d4332 509}
489fdf79 510