cleanup
[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
68//________________________________________________________________________
69AliAnalysisTaskScalarProduct::~AliAnalysisTaskScalarProduct()
70{
71 //
72 // Destructor
73 //
74
75 // histograms are in the output list and deleted when the output
76 // list is deleted by the TSelector dtor
77
78 // if (ListHistos) {
79 // delete fListHistos;
80 // fListHistos = NULL;
81 // }
8d312f00 82}
83
84//________________________________________________________________________
85void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)
86{
87 // Connect ESD or AOD here
88 // Called once
89 cout<<"AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)"<<endl;
90
91 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
92 if (!tree) {
93 Printf("ERROR: Could not read chain from input slot 0");
94 } else {
95 // Disable all branches and enable only the needed ones
96 if (fAnalysisType == "MC") {
97 cout<<"!!!!!reading MC kinematics only"<<endl;
98 // we want to process only MC
99 tree->SetBranchStatus("*", kFALSE);
100
101 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
102
103 if (!esdH) {
104 Printf("ERROR: Could not get ESDInputHandler");
105 } else {
106 fESD = esdH->GetEvent();
107 }
108 }
109 else if (fAnalysisType == "ESD") {
110 cout<<"!!!!!reading the ESD only"<<endl;
111 tree->SetBranchStatus("*", kFALSE);
112 tree->SetBranchStatus("Tracks.*", kTRUE);
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 else if (fAnalysisType == "AOD") {
122 cout<<"!!!!!reading the AOD only"<<endl;
123 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
124
125 if (!aodH) {
126 Printf("ERROR: Could not get AODInputHandler");
127 }
128 else {
129 fAOD = aodH->GetEvent();
130 }
131 }
132 else {
133 Printf("!!!!!Wrong analysis type: Only ESD, AOD and MC types are allowed!");
134 exit(1);
135
136 }
137 }
138}
139
140//________________________________________________________________________
141void AliAnalysisTaskScalarProduct::CreateOutputObjects()
142{
e2d51347 143 // Called at every worker node to initialize
8d312f00 144 cout<<"AliAnalysisTaskScalarProduct::CreateOutputObjects()"<<endl;
e2d51347 145 //event maker
146 fEventMaker = new AliFlowEventSimpleMaker();
147 //Analyser
148 fSP = new AliFlowAnalysisWithScalarProduct() ;
149 fSP-> Init();
d7eb18ec 150
8d312f00 151
d7eb18ec 152 if (fSP->GetHistList()) {
153 fSP->GetHistList()->Print();
e2d51347 154// fListHistos = new TList(fSP->GetHistList());
d7eb18ec 155 fListHistos = fSP->GetHistList();
e2d51347 156 fListHistos->Print();
8d312f00 157 }
d7eb18ec 158 else {Printf("ERROR: Could not retrieve histogram list"); }
8d312f00 159}
160
161//________________________________________________________________________
162void AliAnalysisTaskScalarProduct::Exec(Option_t *)
163{
164 // Main loop
165 // Called for each event
166
167
168 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
169 // This handler can return the current MC event
170
171 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
172 if (!eventHandler) {
173 Printf("ERROR: Could not retrieve MC event handler");
174 return;
175 }
176
177 AliMCEvent* mcEvent = eventHandler->MCEvent();
178 if (!mcEvent) {
179 Printf("ERROR: Could not retrieve MC event");
180 return;
181 }
182
183 Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
184
185 if (fAnalysisType == "MC") {
186 // analysis
187 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent);
188 fSP->Make(fEvent);
189
190 delete fEvent;
191 }
192 else if (fAnalysisType == "ESD") {
193 if (!fESD) {
194 Printf("ERROR: fESD not available");
195 return;
196 }
197 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
198
199 // analysis
200 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD);
201 fSP->Make(fEvent);
202 delete fEvent;
203 }
204 else if (fAnalysisType == "AOD") {
205 if (!fAOD) {
206 Printf("ERROR: fAOD not available");
207 return;
208 }
209 Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
210
211 // analysis
212 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
213 fSP->Make(fEvent);
214 delete fEvent;
215 }
216
d7eb18ec 217 PostData(0,fListHistos);
8d312f00 218}
219
220//________________________________________________________________________
221void AliAnalysisTaskScalarProduct::Terminate(Option_t *)
222{
223 // Called once at the end of the query
224 fSP->Finish();
e2d51347 225 // PostData(0,fListHistos);
8d312f00 226
227 delete fSP;
228 delete fEventMaker;
df802279 229}