]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowTasks/AliAnalysisTaskFlowEvent.cxx
Added the new class
[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   fESD(NULL),
57   fAOD(NULL),
58   fEventMaker(NULL),
59   fAnalysisType("ESD"),
60   fCFManager1(NULL),
61   fCFManager2(NULL),
62   fQAInt(NULL),
63   fQADiff(NULL),
64   fQA(on)
65 {
66   // Constructor
67   cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name)"<<endl;
68
69   // Define input and output slots here
70   // Input slot #0 works with a TChain
71   DefineInput(0, TChain::Class());
72   // Output slot #0 writes into a TList container
73   DefineOutput(0, TObject::Class());  
74   if(on) {
75     DefineOutput(1, TList::Class());
76     DefineOutput(2, TList::Class()); }  
77   // Define here the flow event output
78
79 }
80
81 //________________________________________________________________________
82 AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() : 
83   fESD(NULL),
84   fAOD(NULL),
85   fEventMaker(NULL),
86   fAnalysisType("ESD"),
87   fCFManager1(NULL),
88   fCFManager2(NULL),
89   fQAInt(NULL),
90   fQADiff(NULL),
91   fQA(kFALSE)
92 {
93   // Constructor
94   cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
95 }
96
97 //________________________________________________________________________
98 AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
99 {
100   //
101   // Destructor
102   //
103
104   // objects in the output list are deleted 
105   // by the TSelector dtor (I hope)
106
107 }
108
109 //________________________________________________________________________
110 void AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *) 
111 {
112   // Connect ESD or AOD here
113   // Called once
114   cout<<"AliAnalysisTaskFlowEvent::ConnectInputData(Option_t *)"<<endl;
115
116   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
117   if (!tree) {
118     Printf("ERROR: Could not read chain from input slot 0");
119   } else {
120     // Disable all branches and enable only the needed ones
121     if (fAnalysisType == "MC") {
122       // we want to process only MC
123       tree->SetBranchStatus("*", kFALSE);
124
125       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
126
127       if (!esdH) {
128         Printf("ERROR: Could not get ESDInputHandler");
129       } else {
130         fESD = esdH->GetEvent();
131       }
132     }
133     else if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1") {
134       tree->SetBranchStatus("*", kFALSE);
135       tree->SetBranchStatus("Tracks.*", kTRUE);
136
137       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
138
139       if (!esdH) {
140         Printf("ERROR: Could not get ESDInputHandler");
141       } else
142         fESD = esdH->GetEvent();
143     }
144     else if (fAnalysisType == "AOD") {
145       AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
146
147       if (!aodH) {
148         Printf("ERROR: Could not get AODInputHandler");
149       }
150       else {
151         fAOD = aodH->GetEvent();
152       }
153     }
154     else {
155       Printf("!!!!!Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
156       exit(1);
157       
158     }
159   }
160 }
161
162 //________________________________________________________________________
163 void AliAnalysisTaskFlowEvent::CreateOutputObjects() 
164 {
165   // Called at every worker node to initialize
166   cout<<"AliAnalysisTaskFlowEvent::CreateOutputObjects()"<<endl;
167
168   if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0"  || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) {
169     cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
170     exit(1);
171   }
172
173   // Flow Event maker
174   fEventMaker = new AliFlowEventSimpleMaker();
175 }
176
177 //________________________________________________________________________
178 void AliAnalysisTaskFlowEvent::Exec(Option_t *) 
179 {
180   // Main loop
181   // Called for each event
182   AliFlowEventSimple* fEvent = NULL;
183         
184   if (fAnalysisType == "MC") {
185
186     // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
187     // This handler can return the current MC event
188
189     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
190     if (!eventHandler) {
191       Printf("ERROR: Could not retrieve MC event handler");
192       return;
193     }
194
195     AliMCEvent* mcEvent = eventHandler->MCEvent();
196     if (!mcEvent) {
197       Printf("ERROR: Could not retrieve MC event");
198       return;
199     }
200
201     fCFManager1->SetEventInfo(mcEvent);
202     fCFManager2->SetEventInfo(mcEvent);
203
204     // analysis 
205     Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
206     fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
207     // here we have the fEvent and want to make it available as an output stream
208     // so no
209     //   delete fEvent;
210   }
211   else if (fAnalysisType == "ESD") {
212     if (!fESD) {
213       Printf("ERROR: fESD not available");
214       return;
215     }
216     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
217     
218     // analysis 
219     fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);
220   }
221   else if (fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
222     if (!fESD) {
223       Printf("ERROR: fESD not available");
224       return;
225     }
226     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
227     
228     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
229     if (!eventHandler) {
230       Printf("ERROR: Could not retrieve MC event handler");
231       return;
232     }
233
234     AliMCEvent* mcEvent = eventHandler->MCEvent();
235     if (!mcEvent) {
236       Printf("ERROR: Could not retrieve MC event");
237       return;
238     }
239
240     fCFManager1->SetEventInfo(mcEvent);
241     fCFManager2->SetEventInfo(mcEvent);
242
243
244     if (fAnalysisType == "ESDMC0") { 
245       fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
246     } else if (fAnalysisType == "ESDMC1") {
247       fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
248     }
249     //delete fEvent;
250     //delete mcEvent;
251   }
252   
253   else if (fAnalysisType == "AOD") {
254     if (!fAOD) {
255       Printf("ERROR: fAOD not available");
256       return;
257     }
258     Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
259
260     // analysis 
261     //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
262     fEvent = fEventMaker->FillTracks(fAOD);
263   }
264
265   //fListHistos->Print();       
266   PostData(0,fEvent);
267   if (fQA) {
268     PostData(1,fQAInt);
269     PostData(2,fQADiff); }
270
271
272 //________________________________________________________________________
273 void AliAnalysisTaskFlowEvent::Terminate(Option_t *) 
274 {
275   // Called once at the end of the query -- do not call in case of CAF
276
277 }