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"),
98 fLoadCandidates(kFALSE),
110 fPhiMax(TMath::TwoPi()),
117 fHistWeightvsPhiMin(0.),
118 fHistWeightvsPhiMax(3.),
123 fAfterburnerOn(kFALSE),
124 fNonFlowNumberOfTrackClones(0),
134 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
137 //________________________________________________________________________
138 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPtype, Bool_t on, UInt_t iseed, Bool_t bCandidates) :
139 AliAnalysisTaskSE(name),
140 // fOutputFile(NULL),
141 fAnalysisType("AUTOMATIC"),
148 fCutContainer(new TList()),
157 fLoadCandidates(bCandidates),
169 fPhiMax(TMath::TwoPi()),
176 fHistWeightvsPhiMin(0.),
177 fHistWeightvsPhiMax(3.),
182 fAfterburnerOn(kFALSE),
183 fNonFlowNumberOfTrackClones(0),
193 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed)"<<endl;
194 fMyTRandom3 = new TRandom3(iseed);
195 gRandom->SetSeed(fMyTRandom3->Integer(65539));
197 int availableINslot=1;
199 if (strcmp(RPtype,"FMD")==0) {
200 DefineInput(availableINslot++, TList::Class());
202 //Candidates input slot
203 if( fLoadCandidates )
204 DefineInput(availableINslot, TObjArray::Class());
206 // Define output slots here
207 // Define here the flow event output
208 DefineOutput(1, AliFlowEventSimple::Class());
209 DefineOutput(2, TList::Class());
211 // and for testing open an output file
212 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
216 //________________________________________________________________________
217 AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
226 if (fCutContainer) fCutContainer->Delete(); delete fCutContainer;
227 // objects in the output list are deleted
228 // by the TSelector dtor (I hope)
232 //________________________________________________________________________
233 void AliAnalysisTaskFlowEvent::NotifyRun()
235 //at the beginning of each new run
236 AliESDEvent* fESD = dynamic_cast<AliESDEvent*> (InputEvent());
239 Int_t run = fESD->GetRunNumber();
240 AliInfo(Form("Stariting run #%i",run));
243 //________________________________________________________________________
244 void AliAnalysisTaskFlowEvent::UserCreateOutputObjects()
246 // Called at every worker node to initialize
247 cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
249 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" || fAnalysisType == "MC" || fAnalysisType == "AUTOMATIC"))
251 AliError("WRONG ANALYSIS TYPE! only ESD, ESDMCkineESD, ESDMCkineMC, AOD, MC and AUTOMATIC are allowed.");
255 //set the common constants
256 AliFlowCommonConstants* cc = AliFlowCommonConstants::GetMaster();
257 cc->SetNbinsMult(fNbinsMult);
258 cc->SetNbinsPt(fNbinsPt);
259 cc->SetNbinsPhi(fNbinsPhi);
260 cc->SetNbinsEta(fNbinsEta);
261 cc->SetNbinsQ(fNbinsQ);
262 cc->SetNbinsMass(fNbinsMass);
263 cc->SetMultMin(fMultMin);
264 cc->SetMultMax(fMultMax);
265 cc->SetPtMin(fPtMin);
266 cc->SetPtMax(fPtMax);
267 cc->SetPhiMin(fPhiMin);
268 cc->SetPhiMax(fPhiMax);
269 cc->SetEtaMin(fEtaMin);
270 cc->SetEtaMax(fEtaMax);
273 cc->SetMassMin(fMassMin);
274 cc->SetMassMax(fMassMax);
275 cc->SetHistWeightvsPhiMax(fHistWeightvsPhiMax);
276 cc->SetHistWeightvsPhiMin(fHistWeightvsPhiMin);
278 fFlowEvent = new AliFlowEvent(3000);
284 fQAList->SetName(Form("%s QA",GetName()));
285 if (fCutsEvent->GetQA()) fQAList->Add(fCutsEvent->GetQA()); //0
286 if (fCutsRP->GetQA()) fQAList->Add(fCutsRP->GetQA()); //1
287 if (fCutsPOI->GetQA())fQAList->Add(fCutsPOI->GetQA()); //2
288 fQAList->Add(new TH1F("event plane angle","event plane angle;angle [rad];",100,0.,TMath::TwoPi())); //3
293 //________________________________________________________________________
294 void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
297 // Called for each event
299 AliMCEvent* mcEvent = MCEvent(); // from TaskSE
300 AliESDEvent* myESD = dynamic_cast<AliESDEvent*>(InputEvent()); // from TaskSE
301 AliAODEvent* myAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
302 AliMultiplicity* myTracklets = NULL;
303 AliESDPmdTrack* pmdtracks = NULL;//pmd
305 int availableINslot=1;
307 if (!(fCutsRP&&fCutsPOI&&fCutsEvent))
309 AliError("cuts not set");
313 //DEFAULT - automatically takes care of everything
314 if (fAnalysisType == "AUTOMATIC")
317 if (InputEvent() && !fCutsEvent->IsSelected(InputEvent())) return;
319 //first attach all possible information to the cuts
320 fCutsRP->SetEvent( InputEvent(), MCEvent() ); //attach event
321 fCutsPOI->SetEvent( InputEvent(), MCEvent() );
323 //then make the event
324 fFlowEvent->Fill( fCutsRP, fCutsPOI );
325 //fFlowEvent = new AliFlowEvent( fCutsRP, fCutsPOI );
328 fFlowEvent->SetReferenceMultiplicity(fCutsEvent->GetReferenceMultiplicity(InputEvent()));
329 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
332 // Make the FlowEvent for MC input
333 else if (fAnalysisType == "MC")
335 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
336 // This handler can return the current MC event
337 if (!(fCFManager1&&fCFManager2))
339 AliError("ERROR: No pointer to correction framework cuts! ");
344 AliError("ERROR: Could not retrieve MC event");
348 fCFManager1->SetMCEventInfo(mcEvent);
349 fCFManager2->SetMCEventInfo(mcEvent);
351 AliInfo(Form("Number of MC particles: %d", mcEvent->GetNumberOfTracks()));
354 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtGenCuts,mcEvent))
356 AliWarning("Event does not pass multiplicity cuts"); return;
359 fFlowEvent = new AliFlowEvent(mcEvent,fCFManager1,fCFManager2);
362 // Make the FlowEvent for ESD input
363 else if (fAnalysisType == "ESD")
365 if (!(fCFManager1&&fCFManager2))
367 AliError("ERROR: No pointer to correction framework cuts!");
372 AliError("ERROR: ESD not available");
376 //check the offline trigger (check if the event has the correct trigger)
377 AliInfo(Form("ESD has %d tracks", fInputEvent->GetNumberOfTracks()));
380 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
382 AliWarning("Event does not pass multiplicity cuts"); return;
386 if (fRPType == "Global") {
387 fFlowEvent = new AliFlowEvent(myESD,fCFManager1,fCFManager2);
389 else if (fRPType == "TPCOnly") {
390 fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kFALSE);
392 else if (fRPType == "TPCHybrid") {
393 fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kTRUE);
395 else if (fRPType == "Tracklet"){
396 fFlowEvent = new AliFlowEvent(myESD,myTracklets,fCFManager2);
398 else if (fRPType == "FMD"){
399 TList* dataFMD = dynamic_cast<TList*>(GetInputData(availableINslot++));
401 cout<<" No dataFMD "<<endl;
404 TH2F* histFMD = dynamic_cast<TH2F*>(dataFMD->FindObject("dNdetadphiHistogramTrVtx"));
406 cout<< "No histFMD"<<endl;
409 fFlowEvent = new AliFlowEvent(myESD,histFMD,fCFManager2);
411 else if (fRPType == "PMD"){
412 fFlowEvent = new AliFlowEvent(myESD,pmdtracks,fCFManager2);
416 // if monte carlo event get reaction plane from monte carlo (depends on generator)
417 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
418 //set reference multiplicity, TODO: maybe move it to the constructor?
419 fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
422 // Make the FlowEvent for ESD input combined with MC info
423 else if (fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" )
425 if (!(fCFManager1&&fCFManager2))
427 AliError("ERROR: No pointer to correction framework cuts! ");
432 AliError("ERROR: ESD not available");
435 AliInfo(Form("There are %d tracks in this event", fInputEvent->GetNumberOfTracks()));
439 AliError("ERROR: Could not retrieve MC event");
443 fCFManager1->SetMCEventInfo(mcEvent);
444 fCFManager2->SetMCEventInfo(mcEvent);
447 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
449 AliWarning("Event does not pass multiplicity cuts"); return;
453 if (fAnalysisType == "ESDMCkineESD")
455 fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kESDkine, fCFManager1, fCFManager2 );
457 else if (fAnalysisType == "ESDMCkineMC")
459 fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kMCkine, fCFManager1, fCFManager2 );
461 if (!fFlowEvent) return;
462 // if monte carlo event get reaction plane from monte carlo (depends on generator)
463 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
464 //set reference multiplicity, TODO: maybe move it to the constructor?
465 fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
467 // Make the FlowEventSimple for AOD input
468 else if (fAnalysisType == "AOD")
472 AliError("ERROR: AOD not available");
475 AliInfo(Form("AOD has %d tracks", myAOD->GetNumberOfTracks()));
476 fFlowEvent = new AliFlowEvent(myAOD);
480 if(fLoadCandidates) {
481 TObjArray* candidates = dynamic_cast<TObjArray*>(GetInputData(availableINslot++));
482 //if(candidates->GetEntriesFast())
483 // printf("I received %d candidates\n",candidates->GetEntriesFast());
486 for(int iCand=0; iCand!=candidates->GetEntriesFast(); ++iCand ) {
487 AliFlowCandidateTrack *cand = dynamic_cast<AliFlowCandidateTrack*>(candidates->At(iCand));
489 //printf(" Ⱶ Checking at candidate %d with %d daughters: mass %f\n",iCand,cand->GetNDaughters(),cand->Mass());
490 for(int iDau=0; iDau!=cand->GetNDaughters(); ++iDau) {
491 //printf(" Ⱶ Daughter %d with fID %d", iDau, cand->GetIDDaughter(iDau) );
492 for(int iRPs=0; iRPs!=fFlowEvent->NumberOfTracks(); ++iRPs ) {
493 AliFlowTrack *iRP = dynamic_cast<AliFlowTrack*>(fFlowEvent->GetTrack( iRPs ));
495 if( !iRP->InRPSelection() )
497 if( cand->GetIDDaughter(iDau) == iRP->GetID() ) {
498 //printf(" was in RP set");
499 //cand->SetDaughter( iDau, iRP );
500 //temporarily untagging all daugters
501 iRP->SetForRPSelection(kFALSE);
502 fFlowEvent->SetNumberOfRPs( fFlowEvent->GetNumberOfRPs() -1 );
507 cand->SetForPOISelection(kTRUE);
508 fFlowEvent->InsertTrack( ((AliFlowTrack*) cand) );
513 if (!fFlowEvent) return; //shuts up coverity
515 //check final event cuts
516 Int_t mult = fFlowEvent->NumberOfTracks();
517 AliInfo(Form("FlowEvent has %i tracks",mult));
518 if (mult<fMinMult || mult>fMaxMult)
520 AliWarning("FlowEvent cut on multiplicity"); return;
524 fFlowEvent->DefineDeadZone(fExcludedEtaMin, fExcludedEtaMax, fExcludedPhiMin, fExcludedPhiMax );
527 //////////////////////////////////////////////////////////////////////////////
528 ///////////////////////////AFTERBURNER
531 //if reaction plane not set from elsewhere randomize it before adding flow
532 if (!fFlowEvent->IsSetMCReactionPlaneAngle())
533 fFlowEvent->SetMCReactionPlaneAngle(gRandom->Uniform(0.0,TMath::TwoPi()));
535 fFlowEvent->AddFlow(fV1,fV2,fV3,fV4,fV5); //add flow
536 fFlowEvent->CloneTracks(fNonFlowNumberOfTrackClones); //add nonflow by cloning tracks
538 //////////////////////////////////////////////////////////////////////////////
541 fFlowEvent->TagSubeventsInEta(fMinA,fMaxA,fMinB,fMaxB);
546 TH1* h1 = static_cast<TH1*>(fQAList->FindObject("event plane angle"));
547 h1->Fill(fFlowEvent->GetMCReactionPlaneAngle());
550 //fListHistos->Print();
551 //fOutputFile->WriteObject(fFlowEvent,"myFlowEventSimple");
552 PostData(1,fFlowEvent);
555 //________________________________________________________________________
556 void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
558 // Called once at the end of the query -- do not call in case of CAF