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