]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/AliFlowTasks/AliAnalysisTaskFlowEvent.cxx
Coverity fixies
[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
63// Interface to make the Flow Event Simple used in the flow analysis methods
940a5ed1 64#include "AliFlowEvent.h"
daf66719 65#include "AliFlowTrackCuts.h"
66#include "AliFlowEventCuts.h"
d459546b 67#include "AliFlowCommonConstants.h"
7183fe85 68#include "AliAnalysisTaskFlowEvent.h"
69
32b846cd 70#include "AliESDpid.h"
71#include "AliTOFcalib.h"
72#include "AliTOFT0maker.h"
73#include "AliCDBManager.h"
74
77111ee6 75#include "AliLog.h"
76
1c1d4332 77ClassImp(AliAnalysisTaskFlowEvent)
940a5ed1 78
1c1d4332 79//________________________________________________________________________
940a5ed1 80AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
81 AliAnalysisTaskSE(),
46bec39c 82 // fOutputFile(NULL),
12b2b8bc 83 fAnalysisType("AUTOMATIC"),
ef4799a7 84 fRPType("Global"),
1c1d4332 85 fCFManager1(NULL),
86 fCFManager2(NULL),
daf66719 87 fCutsEvent(NULL),
88 fCutsRP(NULL),
89 fCutsPOI(NULL),
1c1d4332 90 fQAInt(NULL),
91 fQADiff(NULL),
fdff44c8 92 fMinMult(0),
93 fMaxMult(10000000),
7a01f4a7 94 fMinA(-1.0),
95 fMaxA(-0.01),
96 fMinB(0.01),
97 fMaxB(1.0),
489fdf79 98 fQA(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.),
32b846cd 124 fMyTRandom3(NULL),
125 fESDpid(NULL),
126 fTOFresolution(0.0),
127 fTOFcalib(NULL),
128 ftofT0maker(NULL)
1c1d4332 129{
130 // Constructor
131 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
132}
133
489fdf79 134//________________________________________________________________________
44e060e0 135AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPtype, Bool_t on, UInt_t iseed) :
940a5ed1 136 AliAnalysisTaskSE(name),
137 // fOutputFile(NULL),
12b2b8bc 138 fAnalysisType("AUTOMATIC"),
44e060e0 139 fRPType(RPtype),
489fdf79 140 fCFManager1(NULL),
141 fCFManager2(NULL),
daf66719 142 fCutsEvent(NULL),
143 fCutsRP(NULL),
144 fCutsPOI(NULL),
489fdf79 145 fQAInt(NULL),
146 fQADiff(NULL),
fdff44c8 147 fMinMult(0),
148 fMaxMult(10000000),
7a01f4a7 149 fMinA(-1.0),
150 fMaxA(-0.01),
151 fMinB(0.01),
152 fMaxB(1.0),
489fdf79 153 fQA(on),
d459546b 154 fNbinsMult(10000),
155 fNbinsPt(100),
156 fNbinsPhi(100),
157 fNbinsEta(200),
158 fNbinsQ(500),
159 fMultMin(0.),
160 fMultMax(10000.),
161 fPtMin(0.),
162 fPtMax(10.),
163 fPhiMin(0.),
164 fPhiMax(TMath::TwoPi()),
165 fEtaMin(-5.),
166 fEtaMax(5.),
167 fQMin(0.),
168 fQMax(3.),
f6f8c3fc 169 fExcludedEtaMin(0.),
170 fExcludedEtaMax(0.),
171 fExcludedPhiMin(0.),
172 fExcludedPhiMax(0.),
54089829 173 fAfterburnerOn(kFALSE),
174 fNonFlowNumberOfTrackClones(0),
175 fV1(0.),
176 fV2(0.),
177 fV3(0.),
178 fV4(0.),
32b846cd 179 fMyTRandom3(NULL),
180 fESDpid(NULL),
181 fTOFresolution(0.0),
182 fTOFcalib(NULL),
183 ftofT0maker(NULL)
489fdf79 184{
185 // Constructor
186 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed)"<<endl;
940a5ed1 187 fMyTRandom3 = new TRandom3(iseed);
489fdf79 188 gRandom->SetSeed(fMyTRandom3->Integer(65539));
65201059 189
44e060e0 190 //FMD input slot
191 if (strcmp(RPtype,"FMD")==0) {
192 DefineInput(1, TList::Class());
193 }
65201059 194
32b846cd 195 //PID
196 fESDpid=new AliESDpid();
197 fTOFcalib = new AliTOFcalib();
198
65201059 199 // Define output slots here
489fdf79 200 // Define here the flow event output
940a5ed1 201 DefineOutput(1, AliFlowEventSimple::Class());
202 if(on)
203 {
65201059 204 DefineOutput(2, TList::Class());
940a5ed1 205 DefineOutput(3, TList::Class());
206 }
489fdf79 207 // and for testing open an output file
208 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
209
210}
211
1c1d4332 212//________________________________________________________________________
213AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
214{
215 //
216 // Destructor
217 //
32b846cd 218 delete fMyTRandom3;
219 delete fESDpid;
220 delete fTOFcalib;
221 delete ftofT0maker;
940a5ed1 222 // objects in the output list are deleted
1c1d4332 223 // by the TSelector dtor (I hope)
224
225}
226
32b846cd 227//________________________________________________________________________
228void AliAnalysisTaskFlowEvent::NotifyRun()
229{
230 //at the beginning of each new run
231 AliESDEvent* fESD = dynamic_cast<AliESDEvent*> (InputEvent());
232 Int_t run = fESD->GetRunNumber();
233 if(fTOFresolution>0.0)
234 {
235 AliCDBManager *cdb = AliCDBManager::Instance();
236 cdb->SetDefaultStorage("raw://");
237 cdb->SetRun(run);
238 fTOFcalib->Init(run);
239 fTOFcalib->CreateCalObjects();
240 delete ftofT0maker;
241 ftofT0maker= new AliTOFT0maker(fESDpid,fTOFcalib);
242 }
243 AliInfo(Form("Stariting run #%i",run));
244}
245
1c1d4332 246//________________________________________________________________________
940a5ed1 247void AliAnalysisTaskFlowEvent::UserCreateOutputObjects()
1c1d4332 248{
249 // Called at every worker node to initialize
250 cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
251
12b2b8bc 252 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" || fAnalysisType == "MC" || fAnalysisType == "AUTOMATIC"))
940a5ed1 253 {
12b2b8bc 254 AliError("WRONG ANALYSIS TYPE! only ESD, ESDMCkineESD, ESDMCkineMC, AOD, MC and AUTOMATIC are allowed.");
1c1d4332 255 exit(1);
256 }
d459546b 257
32b846cd 258 if (!(fCutsRP&&fCutsPOI))
259 {
260 AliError("cuts not set");
261 return;
262 }
32b846cd 263 //PID
264 if (fCutsRP->GetParamType()==AliFlowTrackCuts::kMC)
265 {
266 fESDpid->GetTPCResponse().SetBetheBlochParameters( 2.15898e+00/50.,
267 1.75295e+01,
268 3.40030e-09,
269 1.96178e+00,
270 3.91720e+00);
271 }
272 else
273 {
274 fESDpid->GetTPCResponse().SetBetheBlochParameters( 0.0283086,
275 2.63394e+01,
276 5.04114e-11,
277 2.12543e+00,
278 4.88663e+00 );
279 }
280
281 fCutsRP->SetESDpid(fESDpid);
282 fCutsPOI->SetESDpid(fESDpid);
283
d459546b 284 //set the common constants
285 AliFlowCommonConstants* cc = AliFlowCommonConstants::GetMaster();
286 cc->SetNbinsMult(fNbinsMult);
287 cc->SetNbinsPt(fNbinsPt);
288 cc->SetNbinsPhi(fNbinsPhi);
289 cc->SetNbinsEta(fNbinsEta);
290 cc->SetNbinsQ(fNbinsQ);
291 cc->SetMultMin(fMultMin);
292 cc->SetMultMax(fMultMax);
293 cc->SetPtMin(fPtMin);
294 cc->SetPtMax(fPtMax);
295 cc->SetPhiMin(fPhiMin);
296 cc->SetPhiMax(fPhiMax);
297 cc->SetEtaMin(fEtaMin);
298 cc->SetEtaMax(fEtaMax);
299 cc->SetQMin(fQMin);
300 cc->SetQMax(fQMax);
301
1c1d4332 302}
303
304//________________________________________________________________________
940a5ed1 305void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
1c1d4332 306{
307 // Main loop
308 // Called for each event
940a5ed1 309 AliFlowEvent* flowEvent = NULL;
310 AliMCEvent* mcEvent = MCEvent(); // from TaskSE
311 AliESDEvent* myESD = dynamic_cast<AliESDEvent*>(InputEvent()); // from TaskSE
312 AliAODEvent* myAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
ef4799a7 313 AliMultiplicity* myTracklets = NULL;
333ce021 314 AliESDPmdTrack* pmdtracks = NULL;//pmd
44e060e0 315 TH2F* histFMD = NULL;
ef4799a7 316
44e060e0 317 if(GetNinputs()==2) {
318 TList* FMDdata = dynamic_cast<TList*>(GetInputData(1));
319 if(!FMDdata) {
320 cout<<" No FMDdata "<<endl;
321 exit(2);
322 }
323 histFMD = dynamic_cast<TH2F*>(FMDdata->FindObject("dNdetadphiHistogramTrVtx"));
324 if (!histFMD) {
325 cout<< "No histFMD"<<endl;
326 exit(2);
327 }
328 }
3ca4688a 329
daf66719 330 //use the new and temporarily inclomplete way of doing things
12b2b8bc 331 if (fAnalysisType == "AUTOMATIC")
daf66719 332 {
7d9ab4fb 333 //check event cuts
334 if (fCutsEvent)
335 {
336 if (!fCutsEvent->IsSelected(InputEvent())) return;
337 }
338
32b846cd 339 //PID
340 recalibTOF(dynamic_cast<AliESDEvent*>(InputEvent()));
59dab33a 341
03d364db 342 //first attach all possible information to the cuts
441ea1cf 343 fCutsRP->SetEvent( InputEvent(), MCEvent() ); //attach event
344 fCutsPOI->SetEvent( InputEvent(), MCEvent() );
32b846cd 345 fCutsRP->SetESDpid(fESDpid);
346 fCutsPOI->SetESDpid(fESDpid);
347
03d364db 348 //then make the event
349 flowEvent = new AliFlowEvent( fCutsRP, fCutsPOI );
daf66719 350 if (myESD)
9a0783cc 351 flowEvent->SetReferenceMultiplicity(fCutsEvent->GetReferenceMultiplicity(InputEvent()));
333ce021 352 if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
daf66719 353 }
940a5ed1 354
355 // Make the FlowEvent for MC input
356 if (fAnalysisType == "MC")
357 {
1c1d4332 358 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
359 // This handler can return the current MC event
940a5ed1 360 if (!(fCFManager1&&fCFManager2))
361 {
77111ee6 362 AliError("ERROR: No pointer to correction framework cuts! ");
940a5ed1 363 return;
364 }
365 if (!mcEvent)
366 {
77111ee6 367 AliError("ERROR: Could not retrieve MC event");
940a5ed1 368 return;
369 }
1c1d4332 370
6d7734d2 371 fCFManager1->SetMCEventInfo(mcEvent);
372 fCFManager2->SetMCEventInfo(mcEvent);
940a5ed1 373
77111ee6 374 AliInfo(Form("Number of MC particles: %d", mcEvent->GetNumberOfTracks()));
375
376 //check multiplicity
377 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtGenCuts,mcEvent))
378 {
379 AliWarning("Event does not pass multiplicity cuts"); return;
380 }
381 //make event
940a5ed1 382 flowEvent = new AliFlowEvent(mcEvent,fCFManager1,fCFManager2);
1c1d4332 383 }
ef4799a7 384
940a5ed1 385 // Make the FlowEvent for ESD input
386 else if (fAnalysisType == "ESD")
387 {
388 if (!(fCFManager1&&fCFManager2))
389 {
77111ee6 390 AliError("ERROR: No pointer to correction framework cuts!");
940a5ed1 391 return;
392 }
393 if (!myESD)
394 {
77111ee6 395 AliError("ERROR: ESD not available");
940a5ed1 396 return;
397 }
77111ee6 398
b0569f96 399 //check the offline trigger (check if the event has the correct trigger)
ade93aa4 400 AliInfo(Form("ESD has %d tracks", fInputEvent->GetNumberOfTracks()));
77111ee6 401
402 //check multiplicity
403 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
404 {
405 AliWarning("Event does not pass multiplicity cuts"); return;
406 }
407
408 //make event
ef4799a7 409 if (fRPType == "Global") {
410 flowEvent = new AliFlowEvent(myESD,fCFManager1,fCFManager2);
411 }
cd755f77 412 if (fRPType == "TPCOnly") {
413 flowEvent = new AliFlowEvent(myESD,fCFManager2,kFALSE);
414 }
415 if (fRPType == "TPCHybrid") {
416 flowEvent = new AliFlowEvent(myESD,fCFManager2,kTRUE);
417 }
ef4799a7 418 else if (fRPType == "Tracklet"){
419 flowEvent = new AliFlowEvent(myESD,myTracklets,fCFManager2);
420 }
44e060e0 421 else if (fRPType == "FMD"){
422 flowEvent = new AliFlowEvent(myESD,histFMD,fCFManager2);
423 }
333ce021 424 //pmd
425 else if (fRPType == "PMD"){
426 flowEvent = new AliFlowEvent(myESD,pmdtracks,fCFManager2);
427 }
428 //pmd
44e060e0 429
ef4799a7 430 // if monte carlo event get reaction plane from monte carlo (depends on generator)
431 if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
85d2ee8d 432 //set reference multiplicity, TODO: maybe move it to the constructor?
433 flowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
1c1d4332 434 }
ef4799a7 435
940a5ed1 436 // Make the FlowEvent for ESD input combined with MC info
437 else if (fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" )
438 {
439 if (!(fCFManager1&&fCFManager2))
440 {
77111ee6 441 AliError("ERROR: No pointer to correction framework cuts! ");
940a5ed1 442 return;
443 }
444 if (!myESD)
445 {
77111ee6 446 AliError("ERROR: ESD not available");
940a5ed1 447 return;
448 }
77111ee6 449 AliInfo(Form("There are %d tracks in this event", fInputEvent->GetNumberOfTracks()));
940a5ed1 450
451 if (!mcEvent)
452 {
77111ee6 453 AliError("ERROR: Could not retrieve MC event");
940a5ed1 454 return;
455 }
1c1d4332 456
6d7734d2 457 fCFManager1->SetMCEventInfo(mcEvent);
458 fCFManager2->SetMCEventInfo(mcEvent);
1c1d4332 459
77111ee6 460 //check multiplicity
461 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
462 {
463 AliWarning("Event does not pass multiplicity cuts"); return;
464 }
465
466 //make event
940a5ed1 467 if (fAnalysisType == "ESDMCkineESD")
468 {
469 flowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kESDkine, fCFManager1, fCFManager2 );
470 }
471 else if (fAnalysisType == "ESDMCkineMC")
472 {
473 flowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kMCkine, fCFManager1, fCFManager2 );
1c1d4332 474 }
85d2ee8d 475 // if monte carlo event get reaction plane from monte carlo (depends on generator)
476 if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
477 //set reference multiplicity, TODO: maybe move it to the constructor?
478 flowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
1c1d4332 479 }
940a5ed1 480 // Make the FlowEventSimple for AOD input
481 else if (fAnalysisType == "AOD")
482 {
483 if (!myAOD)
484 {
77111ee6 485 AliError("ERROR: AOD not available");
940a5ed1 486 return;
487 }
ade93aa4 488 AliInfo(Form("AOD has %d tracks", myAOD->GetNumberOfTracks()));
940a5ed1 489 flowEvent = new AliFlowEvent(myAOD);
1c1d4332 490 }
491
77111ee6 492 //check final event cuts
940a5ed1 493 Int_t mult = flowEvent->NumberOfTracks();
ade93aa4 494 AliInfo(Form("FlowEvent has %i tracks",mult));
495 if (mult<fMinMult || mult>fMaxMult)
77111ee6 496 {
497 AliWarning("FlowEvent cut on multiplicity"); return;
498 }
940a5ed1 499
f6f8c3fc 500 //define dead zone
501 flowEvent->DefineDeadZone(fExcludedEtaMin, fExcludedEtaMax, fExcludedPhiMin, fExcludedPhiMax );
502
503
54089829 504 //////////////////////////////////////////////////////////////////////////////
505 ///////////////////////////AFTERBURNER
506 if (fAfterburnerOn)
507 {
508 //if reaction plane not set from elsewhere randomize it before adding flow
509 if (!flowEvent->IsSetMCReactionPlaneAngle())
510 flowEvent->SetMCReactionPlaneAngle(gRandom->Uniform(0.0,TMath::TwoPi()));
511
512 flowEvent->AddFlow(fV1,fV2,fV3,fV4); //add flow
513 flowEvent->CloneTracks(fNonFlowNumberOfTrackClones); //add nonflow by cloning tracks
514 }
515 //////////////////////////////////////////////////////////////////////////////
516
ef4799a7 517 //tag subEvents
940a5ed1 518 flowEvent->TagSubeventsInEta(fMinA,fMaxA,fMinB,fMaxB);
519
46bec39c 520 //fListHistos->Print();
ef4799a7 521 //fOutputFile->WriteObject(flowEvent,"myFlowEventSimple");
940a5ed1 522 PostData(1,flowEvent);
523 if (fQA)
524 {
65201059 525 PostData(2,fQAInt);
940a5ed1 526 PostData(3,fQADiff);
527 }
528}
1c1d4332 529
530//________________________________________________________________________
940a5ed1 531void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
1c1d4332 532{
533 // Called once at the end of the query -- do not call in case of CAF
1c1d4332 534}
489fdf79 535
32b846cd 536//___________________________________________________________
537void AliAnalysisTaskFlowEvent::recalibTOF(AliESDEvent *event)
538{
539 if(!(fTOFresolution>0.0))
540 return;
541 ftofT0maker->SetTimeResolution(fTOFresolution);
542 ftofT0maker->ComputeT0TOF(event);
543 ftofT0maker->WriteInESD(event);
544}