1 /*************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////////////////////
17 // AliAnalysisTaskFlowEvent:
19 // analysis task for filling the flow event
20 // from MCEvent, ESD, AOD ....
21 // and put it in an output stream so it can
22 // be used by the various flow analysis methods
23 // for cuts the correction framework is used
24 // which also outputs QA histograms to view
25 // the effects of the cuts
26 ////////////////////////////////////////////////////
28 #include "Riostream.h" //needed as include
31 #include "TFile.h" //needed as include
35 #include "TTimeStamp.h"
37 // ALICE Analysis Framework
38 #include "AliAnalysisManager.h"
39 #include "AliAnalysisTaskSE.h"
40 #include "AliESDtrackCuts.h"
43 #include "AliESDEvent.h"
44 #include "AliESDInputHandler.h"
47 #include "AliAODEvent.h"
48 #include "AliAODInputHandler.h"
51 #include "AliMCEventHandler.h"
52 #include "AliMCEvent.h"
54 // ALICE Correction Framework
55 #include "AliCFManager.h"
57 // Interface to Event generators to get Reaction Plane Angle
58 #include "AliGenCocktailEventHeader.h"
59 #include "AliGenHijingEventHeader.h"
60 #include "AliGenGeVSimEventHeader.h"
61 #include "AliGenEposEventHeader.h"
63 // Interface to Load short life particles
64 #include "TObjArray.h"
65 #include "AliFlowCandidateTrack.h"
67 // Interface to make the Flow Event Simple used in the flow analysis methods
68 #include "AliFlowEvent.h"
69 #include "AliFlowTrackCuts.h"
70 #include "AliFlowEventCuts.h"
71 #include "AliFlowCommonConstants.h"
72 #include "AliAnalysisTaskFlowEvent.h"
76 ClassImp(AliAnalysisTaskFlowEvent)
78 //________________________________________________________________________
79 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
82 fAnalysisType("AUTOMATIC"),
97 fLoadCandidates(kFALSE),
108 fPhiMax(TMath::TwoPi()),
117 fAfterburnerOn(kFALSE),
118 fNonFlowNumberOfTrackClones(0),
128 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
131 //________________________________________________________________________
132 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPtype, Bool_t on, UInt_t iseed, Bool_t bCandidates) :
133 AliAnalysisTaskSE(name),
134 // fOutputFile(NULL),
135 fAnalysisType("AUTOMATIC"),
150 fLoadCandidates(bCandidates),
161 fPhiMax(TMath::TwoPi()),
170 fAfterburnerOn(kFALSE),
171 fNonFlowNumberOfTrackClones(0),
181 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed)"<<endl;
182 fMyTRandom3 = new TRandom3(iseed);
183 gRandom->SetSeed(fMyTRandom3->Integer(65539));
185 int availableINslot=1;
187 if (strcmp(RPtype,"FMD")==0) {
188 DefineInput(availableINslot++, TList::Class());
190 //Candidates input slot
191 if( fLoadCandidates )
192 DefineInput(availableINslot, TObjArray::Class());
194 // Define output slots here
195 // Define here the flow event output
196 DefineOutput(1, AliFlowEventSimple::Class());
197 DefineOutput(2, TList::Class());
199 // and for testing open an output file
200 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
204 //________________________________________________________________________
205 AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
216 // objects in the output list are deleted
217 // by the TSelector dtor (I hope)
221 //________________________________________________________________________
222 void AliAnalysisTaskFlowEvent::NotifyRun()
224 //at the beginning of each new run
225 AliESDEvent* fESD = dynamic_cast<AliESDEvent*> (InputEvent());
228 Int_t run = fESD->GetRunNumber();
229 AliInfo(Form("Stariting run #%i",run));
232 //________________________________________________________________________
233 void AliAnalysisTaskFlowEvent::UserCreateOutputObjects()
235 // Called at every worker node to initialize
236 cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
238 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" || fAnalysisType == "MC" || fAnalysisType == "AUTOMATIC"))
240 AliError("WRONG ANALYSIS TYPE! only ESD, ESDMCkineESD, ESDMCkineMC, AOD, MC and AUTOMATIC are allowed.");
244 //set the common constants
245 AliFlowCommonConstants* cc = AliFlowCommonConstants::GetMaster();
246 cc->SetNbinsMult(fNbinsMult);
247 cc->SetNbinsPt(fNbinsPt);
248 cc->SetNbinsPhi(fNbinsPhi);
249 cc->SetNbinsEta(fNbinsEta);
250 cc->SetNbinsQ(fNbinsQ);
251 cc->SetMultMin(fMultMin);
252 cc->SetMultMax(fMultMax);
253 cc->SetPtMin(fPtMin);
254 cc->SetPtMax(fPtMax);
255 cc->SetPhiMin(fPhiMin);
256 cc->SetPhiMax(fPhiMax);
257 cc->SetEtaMin(fEtaMin);
258 cc->SetEtaMax(fEtaMax);
262 fFlowEvent = new AliFlowEvent(3000);
267 fQAList->SetName(Form("%s QA",GetName()));
268 if (fCutsEvent->GetQA()) fQAList->Add(fCutsEvent->GetQA());
269 if (fCutsRP->GetQA()) fQAList->Add(fCutsRP->GetQA());
270 if (fCutsPOI->GetQA())fQAList->Add(fCutsPOI->GetQA());
275 //________________________________________________________________________
276 void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
279 // Called for each event
281 AliMCEvent* mcEvent = MCEvent(); // from TaskSE
282 AliESDEvent* myESD = dynamic_cast<AliESDEvent*>(InputEvent()); // from TaskSE
283 AliAODEvent* myAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
284 AliMultiplicity* myTracklets = NULL;
285 AliESDPmdTrack* pmdtracks = NULL;//pmd
287 int availableINslot=1;
289 if (!(fCutsRP&&fCutsPOI&&fCutsEvent))
291 AliError("cuts not set");
295 //DEFAULT - automatically takes care of everything
296 if (fAnalysisType == "AUTOMATIC")
299 if (!fCutsEvent->IsSelected(InputEvent())) return;
301 //first attach all possible information to the cuts
302 fCutsRP->SetEvent( InputEvent(), MCEvent() ); //attach event
303 fCutsPOI->SetEvent( InputEvent(), MCEvent() );
305 //then make the event
306 fFlowEvent->Fill( fCutsRP, fCutsPOI );
307 //fFlowEvent = new AliFlowEvent( fCutsRP, fCutsPOI );
310 fFlowEvent->SetReferenceMultiplicity(fCutsEvent->GetReferenceMultiplicity(InputEvent()));
311 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
314 // Make the FlowEvent for MC input
315 else if (fAnalysisType == "MC")
317 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
318 // This handler can return the current MC event
319 if (!(fCFManager1&&fCFManager2))
321 AliError("ERROR: No pointer to correction framework cuts! ");
326 AliError("ERROR: Could not retrieve MC event");
330 fCFManager1->SetMCEventInfo(mcEvent);
331 fCFManager2->SetMCEventInfo(mcEvent);
333 AliInfo(Form("Number of MC particles: %d", mcEvent->GetNumberOfTracks()));
336 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtGenCuts,mcEvent))
338 AliWarning("Event does not pass multiplicity cuts"); return;
341 fFlowEvent = new AliFlowEvent(mcEvent,fCFManager1,fCFManager2);
344 // Make the FlowEvent for ESD input
345 else if (fAnalysisType == "ESD")
347 if (!(fCFManager1&&fCFManager2))
349 AliError("ERROR: No pointer to correction framework cuts!");
354 AliError("ERROR: ESD not available");
358 //check the offline trigger (check if the event has the correct trigger)
359 AliInfo(Form("ESD has %d tracks", fInputEvent->GetNumberOfTracks()));
362 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
364 AliWarning("Event does not pass multiplicity cuts"); return;
368 if (fRPType == "Global") {
369 fFlowEvent = new AliFlowEvent(myESD,fCFManager1,fCFManager2);
371 else if (fRPType == "TPCOnly") {
372 fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kFALSE);
374 else if (fRPType == "TPCHybrid") {
375 fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kTRUE);
377 else if (fRPType == "Tracklet"){
378 fFlowEvent = new AliFlowEvent(myESD,myTracklets,fCFManager2);
380 else if (fRPType == "FMD"){
381 TList* FMDdata = dynamic_cast<TList*>(GetInputData(availableINslot++));
383 cout<<" No FMDdata "<<endl;
386 TH2F* histFMD = dynamic_cast<TH2F*>(FMDdata->FindObject("dNdetadphiHistogramTrVtx"));
388 cout<< "No histFMD"<<endl;
391 fFlowEvent = new AliFlowEvent(myESD,histFMD,fCFManager2);
393 else if (fRPType == "PMD"){
394 fFlowEvent = new AliFlowEvent(myESD,pmdtracks,fCFManager2);
398 // if monte carlo event get reaction plane from monte carlo (depends on generator)
399 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
400 //set reference multiplicity, TODO: maybe move it to the constructor?
401 fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
404 // Make the FlowEvent for ESD input combined with MC info
405 else if (fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" )
407 if (!(fCFManager1&&fCFManager2))
409 AliError("ERROR: No pointer to correction framework cuts! ");
414 AliError("ERROR: ESD not available");
417 AliInfo(Form("There are %d tracks in this event", fInputEvent->GetNumberOfTracks()));
421 AliError("ERROR: Could not retrieve MC event");
425 fCFManager1->SetMCEventInfo(mcEvent);
426 fCFManager2->SetMCEventInfo(mcEvent);
429 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
431 AliWarning("Event does not pass multiplicity cuts"); return;
435 if (fAnalysisType == "ESDMCkineESD")
437 fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kESDkine, fCFManager1, fCFManager2 );
439 else if (fAnalysisType == "ESDMCkineMC")
441 fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kMCkine, fCFManager1, fCFManager2 );
443 if (!fFlowEvent) return;
444 // if monte carlo event get reaction plane from monte carlo (depends on generator)
445 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
446 //set reference multiplicity, TODO: maybe move it to the constructor?
447 fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
449 // Make the FlowEventSimple for AOD input
450 else if (fAnalysisType == "AOD")
454 AliError("ERROR: AOD not available");
457 AliInfo(Form("AOD has %d tracks", myAOD->GetNumberOfTracks()));
458 fFlowEvent = new AliFlowEvent(myAOD);
462 if(fLoadCandidates) {
463 TObjArray* Candidates = dynamic_cast<TObjArray*>(GetInputData(availableINslot++));
464 //if(Candidates->GetEntriesFast())
465 //printf("I received %d candidates\n",Candidates->GetEntriesFast());
468 for(int iCand=0; iCand!=Candidates->GetEntriesFast(); ++iCand ) {
469 AliFlowCandidateTrack *cand = dynamic_cast<AliFlowCandidateTrack*>(Candidates->At(iCand));
471 cand->SetForPOISelection(kTRUE);
472 cand->SetForRPSelection(kFALSE);
473 //printf(" Ⱶ Checking at candidate %d with %d daughters\n",iCand,cand->GetNDaughters());
474 for(int iDau=0; iDau!=cand->GetNDaughters(); ++iDau) {
475 //printf(" Ⱶ Daughter %d with fID %d", iDau, cand->GetIDDaughter(iDau) );
476 for(int iRPs=0; iRPs!=fFlowEvent->NumberOfTracks(); ++iRPs ) {
477 AliFlowTrack *iRP = dynamic_cast<AliFlowTrack*>(fFlowEvent->GetTrack( iRPs ));
479 if( !iRP->InRPSelection() )
481 if( cand->GetIDDaughter(iDau) == iRP->GetID() ) {
482 //printf(" was in RP set");
483 cand->SetDaughter( iDau, iRP );
484 //temporarily untagging all daugters
485 iRP->SetForRPSelection(kFALSE);
490 fFlowEvent->AddTrack(cand);
495 if (!fFlowEvent) return; //shuts up coverity
497 //check final event cuts
498 Int_t mult = fFlowEvent->NumberOfTracks();
499 AliInfo(Form("FlowEvent has %i tracks",mult));
500 if (mult<fMinMult || mult>fMaxMult)
502 AliWarning("FlowEvent cut on multiplicity"); return;
506 fFlowEvent->DefineDeadZone(fExcludedEtaMin, fExcludedEtaMax, fExcludedPhiMin, fExcludedPhiMax );
509 //////////////////////////////////////////////////////////////////////////////
510 ///////////////////////////AFTERBURNER
513 //if reaction plane not set from elsewhere randomize it before adding flow
514 if (!fFlowEvent->IsSetMCReactionPlaneAngle())
515 fFlowEvent->SetMCReactionPlaneAngle(gRandom->Uniform(0.0,TMath::TwoPi()));
517 fFlowEvent->AddFlow(fV1,fV2,fV3,fV4,fV5); //add flow
518 fFlowEvent->CloneTracks(fNonFlowNumberOfTrackClones); //add nonflow by cloning tracks
520 //////////////////////////////////////////////////////////////////////////////
523 fFlowEvent->TagSubeventsInEta(fMinA,fMaxA,fMinB,fMaxB);
525 //fListHistos->Print();
526 //fOutputFile->WriteObject(fFlowEvent,"myFlowEventSimple");
527 PostData(1,fFlowEvent);
530 //________________________________________________________________________
531 void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
533 // Called once at the end of the query -- do not call in case of CAF