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