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 #include "Riostream.h" //needed as include
19 #include "TFile.h" //needed as include
23 class AliAnalysisTask;
24 #include "AliAnalysisManager.h"
26 #include "AliESDEvent.h"
27 #include "AliESDInputHandler.h"
29 #include "AliAODEvent.h"
30 #include "AliAODInputHandler.h"
32 #include "AliMCEventHandler.h"
33 #include "AliMCEvent.h"
35 #include "AliCFManager.h"
37 #include "AliAnalysisTaskFlowEvent.h"
38 #include "AliFlowEventSimpleMaker.h"
40 // AliAnalysisTaskFlowEvent:
42 // analysis task for filling the flow event
43 // from MCEvent, ESD, AOD ....
44 // and put it in an output stream so it can
45 // be used by the various flow analysis methods
46 // for cuts the correction framework is used
47 // which also outputs QA histrograms to view
48 // the effects of the cuts
51 ClassImp(AliAnalysisTaskFlowEvent)
53 //________________________________________________________________________
54 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on) :
55 AliAnalysisTask(name, ""),
68 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name)"<<endl;
70 // Define input and output slots here
71 // Input slot #0 works with a TChain
72 DefineInput(0, TChain::Class());
73 // Define here the flow event output
74 DefineOutput(0, AliFlowEventSimple::Class());
76 DefineOutput(1, TList::Class());
77 DefineOutput(2, TList::Class()); }
78 // and for testing open an output file
79 // fOutputFile = new TFile("FlowEvents.root","RECREATE");
83 //________________________________________________________________________
84 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
97 cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
100 //________________________________________________________________________
101 AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
107 // objects in the output list are deleted
108 // by the TSelector dtor (I hope)
112 //________________________________________________________________________
113 void AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *)
115 // Connect ESD or AOD here
117 cout<<"AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *)"<<endl;
119 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
121 Printf("ERROR: Could not read chain from input slot 0");
123 // Disable all branches and enable only the needed ones
124 if (fAnalysisType == "MC") {
125 // we want to process only MC
126 tree->SetBranchStatus("*", kFALSE);
128 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
131 Printf("ERROR: Could not get ESDInputHandler");
133 fESD = esdH->GetEvent();
136 else if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1") {
137 tree->SetBranchStatus("*", kFALSE);
138 tree->SetBranchStatus("Tracks.*", kTRUE);
140 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
143 Printf("ERROR: Could not get ESDInputHandler");
145 fESD = esdH->GetEvent();
147 else if (fAnalysisType == "AOD") {
148 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
151 Printf("ERROR: Could not get AODInputHandler");
154 fAOD = aodH->GetEvent();
158 Printf("!!!!!Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
165 //________________________________________________________________________
166 void AliAnalysisTaskFlowEvent::CreateOutputObjects()
168 // Called at every worker node to initialize
169 cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
171 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) {
172 cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
177 fEventMaker = new AliFlowEventSimpleMaker();
180 //________________________________________________________________________
181 void AliAnalysisTaskFlowEvent::Exec(Option_t *)
184 // Called for each event
185 AliFlowEventSimple* fEvent = NULL;
187 if (fAnalysisType == "MC") {
189 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
190 // This handler can return the current MC event
192 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
194 Printf("ERROR: Could not retrieve MC event handler");
198 AliMCEvent* mcEvent = eventHandler->MCEvent();
200 Printf("ERROR: Could not retrieve MC event");
204 fCFManager1->SetEventInfo(mcEvent);
205 fCFManager2->SetEventInfo(mcEvent);
208 Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
209 fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
210 // here we have the fEvent and want to make it available as an output stream
214 else if (fAnalysisType == "ESD") {
216 Printf("ERROR: fESD not available");
219 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
222 fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);
224 else if (fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
226 Printf("ERROR: fESD not available");
229 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
231 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
233 Printf("ERROR: Could not retrieve MC event handler");
237 AliMCEvent* mcEvent = eventHandler->MCEvent();
239 Printf("ERROR: Could not retrieve MC event");
243 fCFManager1->SetEventInfo(mcEvent);
244 fCFManager2->SetEventInfo(mcEvent);
247 if (fAnalysisType == "ESDMC0") {
248 fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
249 } else if (fAnalysisType == "ESDMC1") {
250 fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
256 else if (fAnalysisType == "AOD") {
258 Printf("ERROR: fAOD not available");
261 Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
264 //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
265 fEvent = fEventMaker->FillTracks(fAOD);
268 //fListHistos->Print();
269 // fOutputFile->WriteObject(fEvent,"myFlowEventSimple");
273 PostData(2,fQADiff); }
276 //________________________________________________________________________
277 void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
279 // Called once at the end of the query -- do not call in case of CAF