]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowTasks/AliAnalysisTaskFlowEvent.cxx
small mods for separate task
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowTasks / AliAnalysisTaskFlowEvent.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
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 **************************************************************************/
15
16 #include "Riostream.h" //needed as include
17 #include "TChain.h"
18 #include "TTree.h"
19 #include "TFile.h" //needed as include
20 #include "TList.h"
21
22
23 class AliAnalysisTask;
24 #include "AliAnalysisManager.h"
25
26 #include "AliESDEvent.h"
27 #include "AliESDInputHandler.h"
28
29 #include "AliAODEvent.h"
30 #include "AliAODInputHandler.h"
31
32 #include "AliMCEventHandler.h"
33 #include "AliMCEvent.h"
34
35 #include "AliCFManager.h"
36
37 #include "AliAnalysisTaskFlowEvent.h"
38 #include "AliFlowEventSimpleMaker.h"
39
40 // AliAnalysisTaskFlowEvent:
41 //
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
49
50
51 ClassImp(AliAnalysisTaskFlowEvent)
52
53 //________________________________________________________________________
54 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on) : 
55   AliAnalysisTask(name, ""), 
56 //  fOutputFile(NULL),
57   fESD(NULL),
58   fAOD(NULL),
59   fEventMaker(NULL),
60   fAnalysisType("ESD"),
61   fCFManager1(NULL),
62   fCFManager2(NULL),
63   fQAInt(NULL),
64   fQADiff(NULL),
65   fQA(on)
66 {
67   // Constructor
68   cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name)"<<endl;
69
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());  
75   if(on) {
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");
80
81 }
82
83 //________________________________________________________________________
84 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() : 
85   //  fOutputFile(NULL),
86   fESD(NULL),
87   fAOD(NULL),
88   fEventMaker(NULL),
89   fAnalysisType("ESD"),
90   fCFManager1(NULL),
91   fCFManager2(NULL),
92   fQAInt(NULL),
93   fQADiff(NULL),
94   fQA(kFALSE)
95 {
96   // Constructor
97   cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
98 }
99
100 //________________________________________________________________________
101 AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
102 {
103   //
104   // Destructor
105   //
106
107   // objects in the output list are deleted 
108   // by the TSelector dtor (I hope)
109
110 }
111
112 //________________________________________________________________________
113 void AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *) 
114 {
115   // Connect ESD or AOD here
116   // Called once
117   cout<<"AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *)"<<endl;
118
119   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
120   if (!tree) {
121     Printf("ERROR: Could not read chain from input slot 0");
122   } else {
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);
127
128       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
129
130       if (!esdH) {
131         Printf("ERROR: Could not get ESDInputHandler");
132       } else {
133         fESD = esdH->GetEvent();
134       }
135     }
136     else if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1") {
137       tree->SetBranchStatus("*", kFALSE);
138       tree->SetBranchStatus("Tracks.*", kTRUE);
139
140       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
141
142       if (!esdH) {
143         Printf("ERROR: Could not get ESDInputHandler");
144       } else
145         fESD = esdH->GetEvent();
146     }
147     else if (fAnalysisType == "AOD") {
148       AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
149
150       if (!aodH) {
151         Printf("ERROR: Could not get AODInputHandler");
152       }
153       else {
154         fAOD = aodH->GetEvent();
155       }
156     }
157     else {
158       Printf("!!!!!Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
159       exit(1);
160       
161     }
162   }
163 }
164
165 //________________________________________________________________________
166 void AliAnalysisTaskFlowEvent::CreateOutputObjects() 
167 {
168   // Called at every worker node to initialize
169   cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
170
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;
173     exit(1);
174   }
175
176   // Flow Event maker
177   fEventMaker = new AliFlowEventSimpleMaker();
178 }
179
180 //________________________________________________________________________
181 void AliAnalysisTaskFlowEvent::Exec(Option_t *) 
182 {
183   // Main loop
184   // Called for each event
185   AliFlowEventSimple* fEvent = NULL;
186         
187   if (fAnalysisType == "MC") {
188
189     // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
190     // This handler can return the current MC event
191
192     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
193     if (!eventHandler) {
194       Printf("ERROR: Could not retrieve MC event handler");
195       return;
196     }
197
198     AliMCEvent* mcEvent = eventHandler->MCEvent();
199     if (!mcEvent) {
200       Printf("ERROR: Could not retrieve MC event");
201       return;
202     }
203
204     fCFManager1->SetEventInfo(mcEvent);
205     fCFManager2->SetEventInfo(mcEvent);
206
207     // analysis 
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
211     // so no
212     //   delete fEvent;
213   }
214   else if (fAnalysisType == "ESD") {
215     if (!fESD) {
216       Printf("ERROR: fESD not available");
217       return;
218     }
219     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
220     
221     // analysis 
222     fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);
223   }
224   else if (fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
225     if (!fESD) {
226       Printf("ERROR: fESD not available");
227       return;
228     }
229     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
230     
231     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
232     if (!eventHandler) {
233       Printf("ERROR: Could not retrieve MC event handler");
234       return;
235     }
236
237     AliMCEvent* mcEvent = eventHandler->MCEvent();
238     if (!mcEvent) {
239       Printf("ERROR: Could not retrieve MC event");
240       return;
241     }
242
243     fCFManager1->SetEventInfo(mcEvent);
244     fCFManager2->SetEventInfo(mcEvent);
245
246
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
251     }
252     //delete fEvent;
253     //delete mcEvent;
254   }
255   
256   else if (fAnalysisType == "AOD") {
257     if (!fAOD) {
258       Printf("ERROR: fAOD not available");
259       return;
260     }
261     Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
262
263     // analysis 
264     //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
265     fEvent = fEventMaker->FillTracks(fAOD);
266   }
267
268   //fListHistos->Print();
269   //  fOutputFile->WriteObject(fEvent,"myFlowEventSimple");     
270   PostData(0,fEvent);
271   if (fQA) {
272     PostData(1,fQAInt);
273     PostData(2,fQADiff); }
274
275
276 //________________________________________________________________________
277 void AliAnalysisTaskFlowEvent::Terminate(Option_t *) 
278 {
279   // Called once at the end of the query -- do not call in case of CAF
280
281 }