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()),
113 fHistWeightvsPhiMin(0.),
114 fHistWeightvsPhiMax(3.),
119 fAfterburnerOn(kFALSE),
120 fNonFlowNumberOfTrackClones(0),
130 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
133 //________________________________________________________________________
134 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPtype, Bool_t on, UInt_t iseed, Bool_t bCandidates) :
135 AliAnalysisTaskSE(name),
136 // fOutputFile(NULL),
137 fAnalysisType("AUTOMATIC"),
152 fLoadCandidates(bCandidates),
163 fPhiMax(TMath::TwoPi()),
168 fHistWeightvsPhiMin(0.),
169 fHistWeightvsPhiMax(3.),
174 fAfterburnerOn(kFALSE),
175 fNonFlowNumberOfTrackClones(0),
185 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed)"<<endl;
186 fMyTRandom3 = new TRandom3(iseed);
187 gRandom->SetSeed(fMyTRandom3->Integer(65539));
189 int availableINslot=1;
191 if (strcmp(RPtype,"FMD")==0) {
192 DefineInput(availableINslot++, TList::Class());
194 //Candidates input slot
195 if( fLoadCandidates )
196 DefineInput(availableINslot, TObjArray::Class());
198 // Define output slots here
199 // Define here the flow event output
200 DefineOutput(1, AliFlowEventSimple::Class());
201 DefineOutput(2, TList::Class());
203 // and for testing open an output file
204 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
208 //________________________________________________________________________
209 AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
220 // objects in the output list are deleted
221 // by the TSelector dtor (I hope)
225 //________________________________________________________________________
226 void AliAnalysisTaskFlowEvent::NotifyRun()
228 //at the beginning of each new run
229 AliESDEvent* fESD = dynamic_cast<AliESDEvent*> (InputEvent());
232 Int_t run = fESD->GetRunNumber();
233 AliInfo(Form("Stariting run #%i",run));
236 //________________________________________________________________________
237 void AliAnalysisTaskFlowEvent::UserCreateOutputObjects()
239 // Called at every worker node to initialize
240 cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
242 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" || fAnalysisType == "MC" || fAnalysisType == "AUTOMATIC"))
244 AliError("WRONG ANALYSIS TYPE! only ESD, ESDMCkineESD, ESDMCkineMC, AOD, MC and AUTOMATIC are allowed.");
248 //set the common constants
249 AliFlowCommonConstants* cc = AliFlowCommonConstants::GetMaster();
250 cc->SetNbinsMult(fNbinsMult);
251 cc->SetNbinsPt(fNbinsPt);
252 cc->SetNbinsPhi(fNbinsPhi);
253 cc->SetNbinsEta(fNbinsEta);
254 cc->SetNbinsQ(fNbinsQ);
255 cc->SetMultMin(fMultMin);
256 cc->SetMultMax(fMultMax);
257 cc->SetPtMin(fPtMin);
258 cc->SetPtMax(fPtMax);
259 cc->SetPhiMin(fPhiMin);
260 cc->SetPhiMax(fPhiMax);
261 cc->SetEtaMin(fEtaMin);
262 cc->SetEtaMax(fEtaMax);
265 cc->SetHistWeightvsPhiMax(fHistWeightvsPhiMax);
266 cc->SetHistWeightvsPhiMin(fHistWeightvsPhiMin);
268 fFlowEvent = new AliFlowEvent(3000);
274 fQAList->SetName(Form("%s QA",GetName()));
275 if (fCutsEvent->GetQA()) fQAList->Add(fCutsEvent->GetQA()); //0
276 if (fCutsRP->GetQA()) fQAList->Add(fCutsRP->GetQA()); //1
277 if (fCutsPOI->GetQA())fQAList->Add(fCutsPOI->GetQA()); //2
278 fQAList->Add(new TH1F("event plane angle","event plane angle;angle [rad];",100,0.,TMath::TwoPi())); //3
283 //________________________________________________________________________
284 void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
287 // Called for each event
289 AliMCEvent* mcEvent = MCEvent(); // from TaskSE
290 AliESDEvent* myESD = dynamic_cast<AliESDEvent*>(InputEvent()); // from TaskSE
291 AliAODEvent* myAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
292 AliMultiplicity* myTracklets = NULL;
293 AliESDPmdTrack* pmdtracks = NULL;//pmd
295 int availableINslot=1;
297 if (!(fCutsRP&&fCutsPOI&&fCutsEvent))
299 AliError("cuts not set");
303 //DEFAULT - automatically takes care of everything
304 if (fAnalysisType == "AUTOMATIC")
307 if (!fCutsEvent->IsSelected(InputEvent())) return;
309 //first attach all possible information to the cuts
310 fCutsRP->SetEvent( InputEvent(), MCEvent() ); //attach event
311 fCutsPOI->SetEvent( InputEvent(), MCEvent() );
313 //then make the event
314 fFlowEvent->Fill( fCutsRP, fCutsPOI );
315 //fFlowEvent = new AliFlowEvent( fCutsRP, fCutsPOI );
318 fFlowEvent->SetReferenceMultiplicity(fCutsEvent->GetReferenceMultiplicity(InputEvent()));
319 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
322 // Make the FlowEvent for MC input
323 else if (fAnalysisType == "MC")
325 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
326 // This handler can return the current MC event
327 if (!(fCFManager1&&fCFManager2))
329 AliError("ERROR: No pointer to correction framework cuts! ");
334 AliError("ERROR: Could not retrieve MC event");
338 fCFManager1->SetMCEventInfo(mcEvent);
339 fCFManager2->SetMCEventInfo(mcEvent);
341 AliInfo(Form("Number of MC particles: %d", mcEvent->GetNumberOfTracks()));
344 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtGenCuts,mcEvent))
346 AliWarning("Event does not pass multiplicity cuts"); return;
349 fFlowEvent = new AliFlowEvent(mcEvent,fCFManager1,fCFManager2);
352 // Make the FlowEvent for ESD input
353 else if (fAnalysisType == "ESD")
355 if (!(fCFManager1&&fCFManager2))
357 AliError("ERROR: No pointer to correction framework cuts!");
362 AliError("ERROR: ESD not available");
366 //check the offline trigger (check if the event has the correct trigger)
367 AliInfo(Form("ESD has %d tracks", fInputEvent->GetNumberOfTracks()));
370 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
372 AliWarning("Event does not pass multiplicity cuts"); return;
376 if (fRPType == "Global") {
377 fFlowEvent = new AliFlowEvent(myESD,fCFManager1,fCFManager2);
379 else if (fRPType == "TPCOnly") {
380 fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kFALSE);
382 else if (fRPType == "TPCHybrid") {
383 fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kTRUE);
385 else if (fRPType == "Tracklet"){
386 fFlowEvent = new AliFlowEvent(myESD,myTracklets,fCFManager2);
388 else if (fRPType == "FMD"){
389 TList* FMDdata = dynamic_cast<TList*>(GetInputData(availableINslot++));
391 cout<<" No FMDdata "<<endl;
394 TH2F* histFMD = dynamic_cast<TH2F*>(FMDdata->FindObject("dNdetadphiHistogramTrVtx"));
396 cout<< "No histFMD"<<endl;
399 fFlowEvent = new AliFlowEvent(myESD,histFMD,fCFManager2);
401 else if (fRPType == "PMD"){
402 fFlowEvent = new AliFlowEvent(myESD,pmdtracks,fCFManager2);
406 // if monte carlo event get reaction plane from monte carlo (depends on generator)
407 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
408 //set reference multiplicity, TODO: maybe move it to the constructor?
409 fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
412 // Make the FlowEvent for ESD input combined with MC info
413 else if (fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" )
415 if (!(fCFManager1&&fCFManager2))
417 AliError("ERROR: No pointer to correction framework cuts! ");
422 AliError("ERROR: ESD not available");
425 AliInfo(Form("There are %d tracks in this event", fInputEvent->GetNumberOfTracks()));
429 AliError("ERROR: Could not retrieve MC event");
433 fCFManager1->SetMCEventInfo(mcEvent);
434 fCFManager2->SetMCEventInfo(mcEvent);
437 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
439 AliWarning("Event does not pass multiplicity cuts"); return;
443 if (fAnalysisType == "ESDMCkineESD")
445 fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kESDkine, fCFManager1, fCFManager2 );
447 else if (fAnalysisType == "ESDMCkineMC")
449 fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kMCkine, fCFManager1, fCFManager2 );
451 if (!fFlowEvent) return;
452 // if monte carlo event get reaction plane from monte carlo (depends on generator)
453 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
454 //set reference multiplicity, TODO: maybe move it to the constructor?
455 fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
457 // Make the FlowEventSimple for AOD input
458 else if (fAnalysisType == "AOD")
462 AliError("ERROR: AOD not available");
465 AliInfo(Form("AOD has %d tracks", myAOD->GetNumberOfTracks()));
466 fFlowEvent = new AliFlowEvent(myAOD);
470 if(fLoadCandidates) {
471 TObjArray* Candidates = dynamic_cast<TObjArray*>(GetInputData(availableINslot++));
472 //if(Candidates->GetEntriesFast())
473 //printf("I received %d candidates\n",Candidates->GetEntriesFast());
476 for(int iCand=0; iCand!=Candidates->GetEntriesFast(); ++iCand ) {
477 AliFlowCandidateTrack *cand = dynamic_cast<AliFlowCandidateTrack*>(Candidates->At(iCand));
479 cand->SetForPOISelection(kTRUE);
480 cand->SetForRPSelection(kFALSE);
481 //printf(" Ⱶ Checking at candidate %d with %d daughters\n",iCand,cand->GetNDaughters());
482 for(int iDau=0; iDau!=cand->GetNDaughters(); ++iDau) {
483 //printf(" Ⱶ Daughter %d with fID %d", iDau, cand->GetIDDaughter(iDau) );
484 for(int iRPs=0; iRPs!=fFlowEvent->NumberOfTracks(); ++iRPs ) {
485 AliFlowTrack *iRP = dynamic_cast<AliFlowTrack*>(fFlowEvent->GetTrack( iRPs ));
487 if( !iRP->InRPSelection() )
489 if( cand->GetIDDaughter(iDau) == iRP->GetID() ) {
490 //printf(" was in RP set");
491 cand->SetDaughter( iDau, iRP );
492 //temporarily untagging all daugters
493 iRP->SetForRPSelection(kFALSE);
498 fFlowEvent->AddTrack(cand);
503 if (!fFlowEvent) return; //shuts up coverity
505 //check final event cuts
506 Int_t mult = fFlowEvent->NumberOfTracks();
507 AliInfo(Form("FlowEvent has %i tracks",mult));
508 if (mult<fMinMult || mult>fMaxMult)
510 AliWarning("FlowEvent cut on multiplicity"); return;
514 fFlowEvent->DefineDeadZone(fExcludedEtaMin, fExcludedEtaMax, fExcludedPhiMin, fExcludedPhiMax );
517 //////////////////////////////////////////////////////////////////////////////
518 ///////////////////////////AFTERBURNER
521 //if reaction plane not set from elsewhere randomize it before adding flow
522 if (!fFlowEvent->IsSetMCReactionPlaneAngle())
523 fFlowEvent->SetMCReactionPlaneAngle(gRandom->Uniform(0.0,TMath::TwoPi()));
525 fFlowEvent->AddFlow(fV1,fV2,fV3,fV4,fV5); //add flow
526 fFlowEvent->CloneTracks(fNonFlowNumberOfTrackClones); //add nonflow by cloning tracks
528 //////////////////////////////////////////////////////////////////////////////
531 fFlowEvent->TagSubeventsInEta(fMinA,fMaxA,fMinB,fMaxB);
536 TH1* h1 = static_cast<TH1*>(fQAList->At(3));
537 h1->Fill(fFlowEvent->GetMCReactionPlaneAngle());
540 //fListHistos->Print();
541 //fOutputFile->WriteObject(fFlowEvent,"myFlowEventSimple");
542 PostData(1,fFlowEvent);
545 //________________________________________________________________________
546 void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
548 // Called once at the end of the query -- do not call in case of CAF