]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliAnalysisTaskScalarProduct.cxx
1acf40fdc5e88f4fed8b8d9346d42012d0874771
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliAnalysisTaskScalarProduct.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 "../../CORRFW/AliCFManager.h"
36
37 #include "AliAnalysisTaskScalarProduct.h"
38 #include "AliFlowEventSimpleMaker.h"
39 #include "AliFlowAnalysisWithScalarProduct.h"
40
41 // AliAnalysisTaskScalarProduct:
42 //
43 // analysis task for Scalar Product Method
44 //
45 // Author: Naomi van der Kolk (kolk@nikhef.nl)
46
47 ClassImp(AliAnalysisTaskScalarProduct)
48
49 //________________________________________________________________________
50 AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name) : 
51   AliAnalysisTask(name, ""), 
52   fESD(NULL),
53   fAOD(NULL),
54   fSP(NULL),
55   fEventMaker(NULL),
56   fAnalysisType("ESD"),
57   fCFManager1(NULL),
58   fCFManager2(NULL),
59   fListHistos(NULL)
60 {
61   // Constructor
62   cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name)"<<endl;
63
64   // Define input and output slots here
65   // Input slot #0 works with a TChain
66   DefineInput(0, TChain::Class());
67   // Output slot #0 writes into a TList container
68   DefineOutput(0, TList::Class());  
69
70 }
71
72 //________________________________________________________________________
73 AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct() : 
74   fESD(NULL),
75   fAOD(NULL),
76   fSP(NULL),
77   fEventMaker(NULL),
78   fAnalysisType("ESD"),
79   fCFManager1(NULL),
80   fCFManager2(NULL),
81   fListHistos(NULL)
82 {
83   // Constructor
84   cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct()"<<endl;
85 }
86
87 //________________________________________________________________________
88 AliAnalysisTaskScalarProduct::~AliAnalysisTaskScalarProduct()
89 {
90   //
91   // Destructor
92   //
93
94   // histograms are in the output list and deleted when the output
95   // list is deleted by the TSelector dtor
96
97   //  if (ListHistos) {
98   //    delete fListHistos;
99   //    fListHistos = NULL;
100   //  }
101 }
102
103 //________________________________________________________________________
104 void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *) 
105 {
106   // Connect ESD or AOD here
107   // Called once
108   cout<<"AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)"<<endl;
109
110   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
111   if (!tree) {
112     Printf("ERROR: Could not read chain from input slot 0");
113   } else {
114     // Disable all branches and enable only the needed ones
115     if (fAnalysisType == "MC") {
116       cout<<"!!!!!reading MC kinematics only"<<endl;
117       // we want to process only MC
118       tree->SetBranchStatus("*", kFALSE);
119
120       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
121
122       if (!esdH) {
123         Printf("ERROR: Could not get ESDInputHandler");
124       } else {
125         fESD = esdH->GetEvent();
126       }
127     }
128     else if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1") {
129       cout<<"!!!!!reading the ESD only"<<endl;
130       tree->SetBranchStatus("*", kFALSE);
131       tree->SetBranchStatus("Tracks.*", kTRUE);
132
133       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
134
135       if (!esdH) {
136         Printf("ERROR: Could not get ESDInputHandler");
137       } else
138         fESD = esdH->GetEvent();
139     }
140     else if (fAnalysisType == "AOD") {
141       cout<<"!!!!!reading the AOD only"<<endl;
142       AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
143
144       if (!aodH) {
145         Printf("ERROR: Could not get AODInputHandler");
146       }
147       else {
148         fAOD = aodH->GetEvent();
149       }
150     }
151     else {
152       Printf("!!!!!Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
153       exit(1);
154       
155     }
156   }
157 }
158
159 //________________________________________________________________________
160 void AliAnalysisTaskScalarProduct::CreateOutputObjects() 
161 {
162   // Called at every worker node to initialize
163   cout<<"AliAnalysisTaskScalarProduct::CreateOutputObjects()"<<endl;
164
165   if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0"  || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) {
166     cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
167     exit(1);
168   }
169
170   //event maker
171   fEventMaker = new AliFlowEventSimpleMaker();
172   //Analyser
173   fSP  = new AliFlowAnalysisWithScalarProduct() ;
174   fSP-> Init();
175   
176
177   if (fSP->GetHistList()) {
178         fSP->GetHistList()->Print();
179         fListHistos = fSP->GetHistList();
180         fListHistos->Print();
181   }
182   else {Printf("ERROR: Could not retrieve histogram list"); }
183 }
184
185 //________________________________________________________________________
186 void AliAnalysisTaskScalarProduct::Exec(Option_t *) 
187 {
188   // Main loop
189   // Called for each event
190
191         
192   if (fAnalysisType == "MC") {
193
194     // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
195     // This handler can return the current MC event
196
197     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
198     if (!eventHandler) {
199       Printf("ERROR: Could not retrieve MC event handler");
200       return;
201     }
202
203     AliMCEvent* mcEvent = eventHandler->MCEvent();
204     if (!mcEvent) {
205       Printf("ERROR: Could not retrieve MC event");
206       return;
207     }
208
209     fCFManager1->SetEventInfo(mcEvent);
210     fCFManager2->SetEventInfo(mcEvent);
211
212     // analysis 
213     Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
214     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
215     fSP->Make(fEvent);
216
217     delete fEvent;
218   }
219   else if (fAnalysisType == "ESD") {
220     if (!fESD) {
221       Printf("ERROR: fESD not available");
222       return;
223     }
224     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
225     
226     // analysis 
227     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);
228     fSP->Make(fEvent);
229     delete fEvent;
230   }
231 else if (fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
232     if (!fESD) {
233       Printf("ERROR: fESD not available");
234       return;
235     }
236     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
237     
238     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
239     if (!eventHandler) {
240       Printf("ERROR: Could not retrieve MC event handler");
241       return;
242     }
243
244     AliMCEvent* mcEvent = eventHandler->MCEvent();
245     if (!mcEvent) {
246       Printf("ERROR: Could not retrieve MC event");
247       return;
248     }
249
250     fCFManager1->SetEventInfo(mcEvent);
251     fCFManager2->SetEventInfo(mcEvent);
252
253     //lee yang zeros analysis 
254     AliFlowEventSimple* fEvent=NULL;
255     if (fAnalysisType == "ESDMC0") { 
256       fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
257     } else if (fAnalysisType == "ESDMC1") {
258       fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
259     }
260     fSP->Make(fEvent);
261     delete fEvent;
262     //delete mcEvent;
263   }
264   
265   else if (fAnalysisType == "AOD") {
266     if (!fAOD) {
267       Printf("ERROR: fAOD not available");
268       return;
269     }
270     Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
271
272     // analysis 
273     //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
274     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
275     fSP->Make(fEvent);
276     delete fEvent;
277   }
278
279   //fListHistos->Print();       
280   PostData(0,fListHistos);
281
282
283 //________________________________________________________________________
284 void AliAnalysisTaskScalarProduct::Terminate(Option_t *) 
285 {
286   // Called once at the end of the query
287   //  fSP->Finish();
288   //  PostData(0,fListHistos);
289
290   fListHistos = (TList*)GetOutputData(0);
291   cout << "histgram list in Terminate" << endl;
292   if (fListHistos) 
293     {
294       fListHistos->Print();
295     }   
296   else
297     {
298       cout << "histgram list pointer is empty" << endl;
299     }
300 //  delete fSP;
301 //  delete fEventMaker;
302 }