]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliAnalysisTaskScalarProduct.cxx
new methods and possiility to run all methods in same run
[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 #include "AliFlowCommonHist.h"
41
42 // AliAnalysisTaskScalarProduct:
43 //
44 // analysis task for Scalar Product Method
45 //
46 // Author: Naomi van der Kolk (kolk@nikhef.nl)
47
48 ClassImp(AliAnalysisTaskScalarProduct)
49
50 //________________________________________________________________________
51 AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name, Bool_t on) : 
52   AliAnalysisTask(name, ""), 
53   fESD(NULL),
54   fAOD(NULL),
55   fSP(NULL),
56   fEventMaker(NULL),
57   fAnalysisType("ESD"),
58   fCFManager1(NULL),
59   fCFManager2(NULL),
60   fListHistos(NULL),
61   fQAInt(NULL),
62   fQADiff(NULL),
63   fQA(on)
64 {
65   // Constructor
66   cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name)"<<endl;
67
68   // Define input and output slots here
69   // Input slot #0 works with a TChain
70   DefineInput(0, TChain::Class());
71   // Output slot #0 writes into a TList container
72   DefineOutput(0, TList::Class());  
73   if(on) {
74     DefineOutput(1, TList::Class());
75     DefineOutput(2, TList::Class()); }  
76 }
77
78 //________________________________________________________________________
79 AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct() : 
80   fESD(NULL),
81   fAOD(NULL),
82   fSP(NULL),
83   fEventMaker(NULL),
84   fAnalysisType("ESD"),
85   fCFManager1(NULL),
86   fCFManager2(NULL),
87   fListHistos(NULL),
88   fQAInt(NULL),
89   fQADiff(NULL),
90   fQA(kFALSE)
91 {
92   // Constructor
93   cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct()"<<endl;
94 }
95
96 //________________________________________________________________________
97 AliAnalysisTaskScalarProduct::~AliAnalysisTaskScalarProduct()
98 {
99   //
100   // Destructor
101   //
102
103   // histograms are in the output list and deleted when the output
104   // list is deleted by the TSelector dtor
105
106   //  if (ListHistos) {
107   //    delete fListHistos;
108   //    fListHistos = NULL;
109   //  }
110 }
111
112 //________________________________________________________________________
113 void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *) 
114 {
115   // Connect ESD or AOD here
116   // Called once
117   cout<<"AliAnalysisTaskScalarProduct::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 AliAnalysisTaskScalarProduct::CreateOutputObjects() 
167 {
168   // Called at every worker node to initialize
169   cout<<"AliAnalysisTaskScalarProduct::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   //event maker
177   fEventMaker = new AliFlowEventSimpleMaker();
178   //Analyser
179   fSP  = new AliFlowAnalysisWithScalarProduct() ;
180   fSP-> Init();
181   
182
183   if (fSP->GetHistList()) {
184     //fSP->GetHistList()->Print();
185         fListHistos = fSP->GetHistList();
186         fListHistos->Print();
187   }
188   else {Printf("ERROR: Could not retrieve histogram list"); }
189 }
190
191 //________________________________________________________________________
192 void AliAnalysisTaskScalarProduct::Exec(Option_t *) 
193 {
194   // Main loop
195   // Called for each event
196
197         
198   if (fAnalysisType == "MC") {
199
200     // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
201     // This handler can return the current MC event
202
203     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
204     if (!eventHandler) {
205       Printf("ERROR: Could not retrieve MC event handler");
206       return;
207     }
208
209     AliMCEvent* mcEvent = eventHandler->MCEvent();
210     if (!mcEvent) {
211       Printf("ERROR: Could not retrieve MC event");
212       return;
213     }
214
215     fCFManager1->SetEventInfo(mcEvent);
216     fCFManager2->SetEventInfo(mcEvent);
217
218     // analysis 
219     Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
220     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
221     fSP->Make(fEvent);
222
223     delete fEvent;
224   }
225   else if (fAnalysisType == "ESD") {
226     if (!fESD) {
227       Printf("ERROR: fESD not available");
228       return;
229     }
230     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
231     
232     // analysis 
233     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);
234     fSP->Make(fEvent);
235     delete fEvent;
236   }
237 else if (fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
238     if (!fESD) {
239       Printf("ERROR: fESD not available");
240       return;
241     }
242     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
243     
244     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
245     if (!eventHandler) {
246       Printf("ERROR: Could not retrieve MC event handler");
247       return;
248     }
249
250     AliMCEvent* mcEvent = eventHandler->MCEvent();
251     if (!mcEvent) {
252       Printf("ERROR: Could not retrieve MC event");
253       return;
254     }
255
256     fCFManager1->SetEventInfo(mcEvent);
257     fCFManager2->SetEventInfo(mcEvent);
258
259     //lee yang zeros analysis 
260     AliFlowEventSimple* fEvent=NULL;
261     if (fAnalysisType == "ESDMC0") { 
262       fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
263     } else if (fAnalysisType == "ESDMC1") {
264       fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
265     }
266     fSP->Make(fEvent);
267     delete fEvent;
268     //delete mcEvent;
269   }
270   
271   else if (fAnalysisType == "AOD") {
272     if (!fAOD) {
273       Printf("ERROR: fAOD not available");
274       return;
275     }
276     Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
277
278     // analysis 
279     //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
280     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
281     fSP->Make(fEvent);
282     delete fEvent;
283   }
284
285   //fListHistos->Print();       
286   PostData(0,fListHistos);
287   if (fQA) {
288     PostData(1,fQAInt);
289     PostData(2,fQADiff); }
290
291
292 //________________________________________________________________________
293 void AliAnalysisTaskScalarProduct::Terminate(Option_t *) 
294 {
295   // Called once at the end of the query -- do not call in case of CAF
296   //  fSP->Finish();
297   //  PostData(0,fListHistos);
298
299   fListHistos = (TList*)GetOutputData(0);
300   cout << "histgram list in Terminate" << endl;
301   if (fListHistos)  {
302     fListHistos->Print();
303   }     
304   else { cout << "histgram list pointer is empty" << endl; }
305
306 }