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
36 #include "TTimeStamp.h"
38 // ALICE Analysis Framework
39 #include "AliAnalysisManager.h"
40 #include "AliAnalysisTaskSE.h"
41 #include "AliESDtrackCuts.h"
44 #include "AliESDEvent.h"
45 #include "AliESDInputHandler.h"
48 #include "AliAODEvent.h"
49 #include "AliAODInputHandler.h"
52 #include "AliMCEventHandler.h"
53 #include "AliMCEvent.h"
55 // ALICE Correction Framework
56 #include "AliCFManager.h"
58 // Interface to Event generators to get Reaction Plane Angle
59 #include "AliGenCocktailEventHeader.h"
60 #include "AliGenHijingEventHeader.h"
61 #include "AliGenGeVSimEventHeader.h"
62 #include "AliGenEposEventHeader.h"
64 // Interface to Load short life particles
65 #include "TObjArray.h"
66 #include "AliFlowCandidateTrack.h"
68 // Interface to make the Flow Event Simple used in the flow analysis methods
69 #include "AliFlowEvent.h"
70 #include "AliFlowTrackCuts.h"
71 #include "AliFlowEventCuts.h"
72 #include "AliFlowCommonConstants.h"
73 #include "AliAnalysisTaskFlowEvent.h"
79 ClassImp(AliAnalysisTaskFlowEvent)
81 //________________________________________________________________________
82 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
85 fAnalysisType("AUTOMATIC"),
101 fLoadCandidates(kFALSE),
113 fPhiMax(TMath::TwoPi()),
120 fHistWeightvsPhiMin(0.),
121 fHistWeightvsPhiMax(3.),
126 fAfterburnerOn(kFALSE),
127 fNonFlowNumberOfTrackClones(0),
135 fShuffleTracks(kFALSE),
139 AliDebug(2,"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()");
142 //________________________________________________________________________
143 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPtype, Bool_t on, UInt_t iseed, Bool_t bCandidates) :
144 AliAnalysisTaskSE(name),
145 // fOutputFile(NULL),
146 fAnalysisType("AUTOMATIC"),
153 fCutContainer(new TList()),
162 fLoadCandidates(bCandidates),
174 fPhiMax(TMath::TwoPi()),
181 fHistWeightvsPhiMin(0.),
182 fHistWeightvsPhiMax(3.),
187 fAfterburnerOn(kFALSE),
188 fNonFlowNumberOfTrackClones(0),
196 fShuffleTracks(kFALSE),
200 AliDebug(2,"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed)");
201 fMyTRandom3 = new TRandom3(iseed);
202 gRandom->SetSeed(fMyTRandom3->Integer(65539));
204 int availableINslot=1;
206 if (strcmp(RPtype,"FMD")==0) {
207 DefineInput(availableINslot++, TList::Class());
209 //Candidates input slot
210 if( fLoadCandidates )
211 DefineInput(availableINslot, TObjArray::Class());
213 // Define output slots here
214 // Define here the flow event output
215 DefineOutput(1, AliFlowEventSimple::Class());
216 DefineOutput(2, TList::Class());
218 // and for testing open an output file
219 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
223 //________________________________________________________________________
224 AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
233 if (fCutContainer) fCutContainer->Delete(); delete fCutContainer;
234 // objects in the output list are deleted
235 // by the TSelector dtor (I hope)
239 //________________________________________________________________________
240 void AliAnalysisTaskFlowEvent::NotifyRun()
242 //at the beginning of each new run
243 if (fCutsRP) fCutsRP->SetRunsMuon(fInputHandler); // XZhang 20120604
244 if (fCutsPOI) fCutsPOI->SetRunsMuon(fInputHandler); // XZhang 20120604
245 AliESDEvent* fESD = dynamic_cast<AliESDEvent*> (InputEvent());
248 Int_t run = fESD->GetRunNumber();
249 AliInfo(Form("Stariting run #%i",run));
252 //________________________________________________________________________
253 void AliAnalysisTaskFlowEvent::UserCreateOutputObjects()
255 // Called at every worker node to initialize
256 AliDebug(2,"AliAnalysisTaskFlowEvent::CreateOutputObjects()");
258 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" || fAnalysisType == "MC" || fAnalysisType == "AUTOMATIC"))
260 AliError("WRONG ANALYSIS TYPE! only ESD, ESDMCkineESD, ESDMCkineMC, AOD, MC and AUTOMATIC are allowed.");
264 //set the common constants
265 AliFlowCommonConstants* cc = AliFlowCommonConstants::GetMaster();
266 cc->SetNbinsMult(fNbinsMult);
267 cc->SetNbinsPt(fNbinsPt);
268 cc->SetNbinsPhi(fNbinsPhi);
269 cc->SetNbinsEta(fNbinsEta);
270 cc->SetNbinsQ(fNbinsQ);
271 cc->SetNbinsMass(fNbinsMass);
272 cc->SetMultMin(fMultMin);
273 cc->SetMultMax(fMultMax);
274 cc->SetPtMin(fPtMin);
275 cc->SetPtMax(fPtMax);
276 cc->SetPhiMin(fPhiMin);
277 cc->SetPhiMax(fPhiMax);
278 cc->SetEtaMin(fEtaMin);
279 cc->SetEtaMax(fEtaMax);
282 cc->SetMassMin(fMassMin);
283 cc->SetMassMax(fMassMax);
284 cc->SetHistWeightvsPhiMax(fHistWeightvsPhiMax);
285 cc->SetHistWeightvsPhiMin(fHistWeightvsPhiMin);
287 fFlowEvent = new AliFlowEvent(10000);
293 fQAList->SetName(Form("%s QA",GetName()));
294 if (fCutsEvent->GetQA()) fQAList->Add(fCutsEvent->GetQA()); //0
295 if (fCutsRP->GetQA()) fQAList->Add(fCutsRP->GetQA()); //1
296 if (fCutsPOI->GetQA())fQAList->Add(fCutsPOI->GetQA()); //2
297 fQAList->Add(new TH1F("event plane angle","event plane angle;angle [rad];",100,0.,TMath::TwoPi())); //3
302 //________________________________________________________________________
303 void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
306 // Called for each event
308 AliMCEvent* mcEvent = MCEvent(); // from TaskSE
309 AliESDEvent* myESD = dynamic_cast<AliESDEvent*>(InputEvent()); // from TaskSE
310 AliAODEvent* myAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
311 AliMultiplicity* myTracklets = NULL;
312 AliESDPmdTrack* pmdtracks = NULL;//pmd
314 int availableINslot=1;
316 if (!(fCutsRP&&fCutsPOI&&fCutsEvent))
318 AliError("cuts not set");
322 //DEFAULT - automatically takes care of everything
323 if (fAnalysisType == "AUTOMATIC")
326 if (InputEvent() && !fCutsEvent->IsSelected(InputEvent(),MCEvent()))
329 //first attach all possible information to the cuts
330 fCutsRP->SetEvent( InputEvent(), MCEvent() ); //attach event
331 fCutsPOI->SetEvent( InputEvent(), MCEvent() );
333 //then make the event
334 fFlowEvent->Fill( fCutsRP, fCutsPOI );
335 //fFlowEvent = new AliFlowEvent( fCutsRP, fCutsPOI );
338 fFlowEvent->SetReferenceMultiplicity(fCutsEvent->GetReferenceMultiplicity(InputEvent(),mcEvent));
339 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
342 // Make the FlowEvent for MC input
343 else if (fAnalysisType == "MC")
345 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
346 // This handler can return the current MC event
347 if (!(fCFManager1&&fCFManager2))
349 AliError("ERROR: No pointer to correction framework cuts! ");
354 AliError("ERROR: Could not retrieve MC event");
358 fCFManager1->SetMCEventInfo(mcEvent);
359 fCFManager2->SetMCEventInfo(mcEvent);
361 AliInfo(Form("Number of MC particles: %d", mcEvent->GetNumberOfTracks()));
364 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtGenCuts,mcEvent))
366 AliWarning("Event does not pass multiplicity cuts"); return;
369 fFlowEvent = new AliFlowEvent(mcEvent,fCFManager1,fCFManager2);
372 // Make the FlowEvent for ESD input
373 else if (fAnalysisType == "ESD")
375 if (!(fCFManager1&&fCFManager2))
377 AliError("ERROR: No pointer to correction framework cuts!");
382 AliError("ERROR: ESD not available");
386 //check the offline trigger (check if the event has the correct trigger)
387 AliInfo(Form("ESD has %d tracks", fInputEvent->GetNumberOfTracks()));
390 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
392 AliWarning("Event does not pass multiplicity cuts"); return;
396 if (fRPType == "Global") {
397 fFlowEvent = new AliFlowEvent(myESD,fCFManager1,fCFManager2);
399 else if (fRPType == "TPCOnly") {
400 fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kFALSE);
402 else if (fRPType == "TPCHybrid") {
403 fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kTRUE);
405 else if (fRPType == "Tracklet"){
406 fFlowEvent = new AliFlowEvent(myESD,myTracklets,fCFManager2);
408 else if (fRPType == "FMD"){
409 TList* dataFMD = dynamic_cast<TList*>(GetInputData(availableINslot++));
411 cout<<" No dataFMD "<<endl;
414 TH2F* histFMD = dynamic_cast<TH2F*>(dataFMD->FindObject("dNdetadphiHistogramTrVtx"));
416 cout<< "No histFMD"<<endl;
419 fFlowEvent = new AliFlowEvent(myESD,histFMD,fCFManager2);
421 else if (fRPType == "PMD"){
422 fFlowEvent = new AliFlowEvent(myESD,pmdtracks,fCFManager2);
426 // if monte carlo event get reaction plane from monte carlo (depends on generator)
427 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
428 //set reference multiplicity, TODO: maybe move it to the constructor?
429 fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
432 // Make the FlowEvent for ESD input combined with MC info
433 else if (fAnalysisType == "ESDMCkineESD" || fAnalysisType == "ESDMCkineMC" )
435 if (!(fCFManager1&&fCFManager2))
437 AliError("ERROR: No pointer to correction framework cuts! ");
442 AliError("ERROR: ESD not available");
445 AliInfo(Form("There are %d tracks in this event", fInputEvent->GetNumberOfTracks()));
449 AliError("ERROR: Could not retrieve MC event");
453 fCFManager1->SetMCEventInfo(mcEvent);
454 fCFManager2->SetMCEventInfo(mcEvent);
457 if (!fCFManager1->CheckEventCuts(AliCFManager::kEvtRecCuts,myESD))
459 AliWarning("Event does not pass multiplicity cuts"); return;
463 if (fAnalysisType == "ESDMCkineESD")
465 fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kESDkine, fCFManager1, fCFManager2 );
467 else if (fAnalysisType == "ESDMCkineMC")
469 fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kMCkine, fCFManager1, fCFManager2 );
471 if (!fFlowEvent) return;
472 // if monte carlo event get reaction plane from monte carlo (depends on generator)
473 if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
474 //set reference multiplicity, TODO: maybe move it to the constructor?
475 fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
477 // Make the FlowEventSimple for AOD input
478 else if (fAnalysisType == "AOD")
482 AliError("ERROR: AOD not available");
485 AliInfo(Form("AOD has %d tracks", myAOD->GetNumberOfTracks()));
486 fFlowEvent = new AliFlowEvent(myAOD);
490 if(fLoadCandidates) {
491 TObjArray* candidates = dynamic_cast<TObjArray*>(GetInputData(availableINslot++));
492 //if(candidates->GetEntriesFast())
493 // printf("I received %d candidates\n",candidates->GetEntriesFast());
496 for(int iCand=0; iCand!=candidates->GetEntriesFast(); ++iCand ) {
497 AliFlowCandidateTrack *cand = dynamic_cast<AliFlowCandidateTrack*>(candidates->At(iCand));
499 //printf(" - Checking at candidate %d with %d daughters: mass %f\n",iCand,cand->GetNDaughters(),cand->Mass());
500 for(int iDau=0; iDau!=cand->GetNDaughters(); ++iDau) {
501 //printf(" - Daughter %d with fID %d", iDau, cand->GetIDDaughter(iDau) );
502 for(int iRPs=0; iRPs!=fFlowEvent->NumberOfTracks(); ++iRPs ) {
503 AliFlowTrack *iRP = dynamic_cast<AliFlowTrack*>(fFlowEvent->GetTrack( iRPs ));
505 if( !iRP->InRPSelection() )
507 if( cand->GetIDDaughter(iDau) == iRP->GetID() ) {
508 //printf(" was in RP set");
509 //cand->SetDaughter( iDau, iRP );
510 //temporarily untagging all daugters
511 iRP->SetForRPSelection(kFALSE);
512 fFlowEvent->SetNumberOfRPs( fFlowEvent->GetNumberOfRPs() -1 );
517 cand->SetForPOISelection(kTRUE);
518 fFlowEvent->InsertTrack( ((AliFlowTrack*) cand) );
523 if (!fFlowEvent) return; //shuts up coverity
525 //check final event cuts
526 Int_t mult = fFlowEvent->NumberOfTracks();
527 // AliInfo(Form("FlowEvent has %i tracks",mult));
528 if (mult<fMinMult || mult>fMaxMult)
530 AliWarning("FlowEvent cut on multiplicity"); return;
534 fFlowEvent->DefineDeadZone(fExcludedEtaMin, fExcludedEtaMax, fExcludedPhiMin, fExcludedPhiMax );
537 //////////////////////////////////////////////////////////////////////////////
538 ///////////////////////////AFTERBURNER
541 //if reaction plane not set from elsewhere randomize it before adding flow
542 if (!fFlowEvent->IsSetMCReactionPlaneAngle())
543 fFlowEvent->SetMCReactionPlaneAngle(gRandom->Uniform(0.0,TMath::TwoPi()));
546 fFlowEvent->AddV2(fDifferentialV2);
548 fFlowEvent->AddFlow(fV1,fV2,fV3,fV4,fV5); //add flow
549 fFlowEvent->CloneTracks(fNonFlowNumberOfTrackClones); //add nonflow by cloning tracks
551 //////////////////////////////////////////////////////////////////////////////
554 fFlowEvent->TagSubeventsInEta(fMinA,fMaxA,fMinB,fMaxB);
559 TH1* h1 = static_cast<TH1*>(fQAList->FindObject("event plane angle"));
560 h1->Fill(fFlowEvent->GetMCReactionPlaneAngle());
563 //do we want to serve shullfed tracks to everybody?
564 fFlowEvent->SetShuffleTracks(fShuffleTracks);
566 //fListHistos->Print();
567 //fOutputFile->WriteObject(fFlowEvent,"myFlowEventSimple");
568 PostData(1,fFlowEvent);
571 //________________________________________________________________________
572 void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
574 // Called once at the end of the query -- do not call in case of CAF