]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/AliAnalysisTaskCumulants.cxx
added support for correction framework in cumulants
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliAnalysisTaskCumulants.cxx
CommitLineData
924fafb7 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"
aaebd73d 20#include "TList.h"
21#include "TH1.h"
22#include "TH3D.h"
23#include "TProfile.h"
24#include "TProfile2D.h"
25#include "TProfile3D.h"
924fafb7 26
aaebd73d 27#include "AliCumulantsFunctions.h"
924fafb7 28
aaebd73d 29#include "AliAnalysisTask.h"
30#include "AliAnalysisDataSlot.h"
31#include "AliAnalysisDataContainer.h"
32
33//class AliAnalysisTask;
924fafb7 34#include "AliAnalysisManager.h"
35
36#include "AliESDEvent.h"
37#include "AliESDInputHandler.h"
38
39#include "AliAODEvent.h"
40#include "AliAODInputHandler.h"
41
42#include "AliMCEventHandler.h"
43#include "AliMCEvent.h"
44
aaebd73d 45#include "../../CORRFW/AliCFManager.h"
46
924fafb7 47#include "AliAnalysisTaskCumulants.h"
48#include "AliFlowEventSimpleMaker.h"
49#include "AliFlowAnalysisWithCumulants.h"
aaebd73d 50#include "AliFlowCumuConstants.h"
51#include "AliFlowCommonConstants.h"
52#include "AliFlowCommonHistResults.h"
53
54#include "AliCumulantsFunctions.h"
924fafb7 55
56// AliAnalysisTaskCumulants:
aaebd73d 57// analysis task for
58// Cumulant method
59// with many authors (N.K. R.S. A.B.)
60// who do something
924fafb7 61
62ClassImp(AliAnalysisTaskCumulants)
63
64//________________________________________________________________________
65AliAnalysisTaskCumulants::AliAnalysisTaskCumulants(const char *name) :
66 AliAnalysisTask(name, ""),
67 fESD(NULL),
68 fAOD(NULL),
924fafb7 69 fMyCumuAnalysis(NULL),
aaebd73d 70 fEventMaker(NULL),
71 fAnalysisType("ESD"),
72 fCFManager1(NULL),
73 fCFManager2(NULL),
74 fListHistos(NULL)
924fafb7 75{
76 // Constructor
77 cout<<"AliAnalysisTaskCumulants::AliAnalysisTaskCumulants(const char *name)"<<endl;
78
79 // Define input and output slots here
80 // Input slot #0 works with a TChain
81 DefineInput(0, TChain::Class());
82
83 // Output slot #0 writes into a TList container
84 DefineOutput(0, TList::Class());
85}
aaebd73d 86//________________________________________________________________________
87AliAnalysisTaskCumulants::AliAnalysisTaskCumulants() :
88 fESD(NULL),
89 fAOD(NULL),
90 fMyCumuAnalysis(NULL),
91 fEventMaker(NULL),
92 fAnalysisType("ESD"),
93 fCFManager1(NULL),
94 fCFManager2(NULL),
95 fListHistos(NULL)
96{
97 // Constructor
98 cout<<"AliAnalysisTaskCumulants::AliAnalysisTaskCumulants(const char *name)"<<endl;
99 }
924fafb7 100
101//________________________________________________________________________
102void AliAnalysisTaskCumulants::ConnectInputData(Option_t *)
103{
104 // Connect ESD or AOD here
105 // Called once
106 cout<<"AliAnalysisTaskCumulants::ConnectInputData(Option_t *)"<<endl;
107
108 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
109 if (!tree) {
110 Printf("ERROR: Could not read chain from input slot 0");
111 }
112 else {
113 // Disable all branches and enable only the needed ones
114 if (fAnalysisType == "MC") {
115 // we want to process only MC
116 tree->SetBranchStatus("*", kFALSE);
117
118 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
119
120 if (!esdH) {
121 Printf("ERROR: Could not get ESDInputHandler");
122 } else {
123 fESD = esdH->GetEvent();
124 }
125 }
126 else if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
127 tree->SetBranchStatus("*", kFALSE);
128 tree->SetBranchStatus("Tracks.*", kTRUE);
129
130 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
131
132 if (!esdH) {
133 Printf("ERROR: Could not get ESDInputHandler");
134 } else
135 fESD = esdH->GetEvent();
136 }
137 else if (fAnalysisType == "AOD") {
138 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
139
140 if (!aodH) {
141 Printf("ERROR: Could not get AODInputHandler");
142 }
143 else {
144 fAOD = aodH->GetEvent();
145 }
146 }
147 else {
148 Printf("Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
149
150 }
151 }
152}
153
154//________________________________________________________________________
155void AliAnalysisTaskCumulants::CreateOutputObjects()
156{
aaebd73d 157 // Called at every worker node to initialize
924fafb7 158 cout<<"AliAnalysisTaskCumulants::CreateOutputObjects()"<<endl;
159
160 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) {
161 cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
162 exit(1);
163 }
aaebd73d 164
924fafb7 165 //event maker
166 fEventMaker = new AliFlowEventSimpleMaker();
aaebd73d 167 //analyser
924fafb7 168 fMyCumuAnalysis = new AliFlowAnalysisWithCumulants() ;
169
924fafb7 170 fMyCumuAnalysis->CreateOutputObjects();
171
aaebd73d 172 if (fMyCumuAnalysis->GetHistList()) {
173 // fSP->GetHistList()->Print();
174 fListHistos = fMyCumuAnalysis->GetHistList();
175 // fListHistos->Print();
176 }
177 else {Printf("ERROR: Could not retrieve histogram list"); }
178 }
924fafb7 179
180//________________________________________________________________________
181void AliAnalysisTaskCumulants::Exec(Option_t *)
182{
183 // Main loop
184 // Called for each event
185 if (fAnalysisType == "MC") {
186 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
187 // This handler can return the current MC event
188
189 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
190 if (!eventHandler) {
191 Printf("ERROR: Could not retrieve MC event handler");
192 return;
193 }
194
195 AliMCEvent* mcEvent = eventHandler->MCEvent();
196 if (!mcEvent) {
197 Printf("ERROR: Could not retrieve MC event");
198 return;
199 }
200
201 Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
aaebd73d 202 fCFManager1->SetEventInfo(mcEvent);
203 fCFManager2->SetEventInfo(mcEvent);
924fafb7 204
aaebd73d 205 //cumulant analysis
206 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
dce74562 207 fMyCumuAnalysis->Make(fEvent);
924fafb7 208 delete fEvent;
209 }
210 else if (fAnalysisType == "ESD") {
211 if (!fESD) {
212 Printf("ERROR: fESD not available");
213 return;
214 }
215 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
216
217 //Cumulant analysis
218 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD);
dce74562 219 fMyCumuAnalysis->Make(fEvent);
924fafb7 220 delete fEvent;
221 }
222 else if (fAnalysisType == "ESDMC0") {
223 if (!fESD) {
224 Printf("ERROR: fESD not available");
225 return;
226 }
227 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
228
229 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
230 if (!eventHandler) {
231 Printf("ERROR: Could not retrieve MC event handler");
232 return;
233 }
234
235 AliMCEvent* mcEvent = eventHandler->MCEvent();
236 if (!mcEvent) {
237 Printf("ERROR: Could not retrieve MC event");
238 return;
239 }
240
aaebd73d 241 fCFManager1->SetEventInfo(mcEvent);
242 fCFManager2->SetEventInfo(mcEvent);
924fafb7 243
244 //Cumulant analysis
aaebd73d 245 AliFlowEventSimple* fEvent=NULL;
246 if (fAnalysisType == "ESDMC0") {
247 fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
248 } else if (fAnalysisType == "ESDMC1") {
249 fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
250 }
dce74562 251 fMyCumuAnalysis->Make(fEvent);
924fafb7 252 delete fEvent;
253 //delete mcEvent;
254 }
aaebd73d 255
924fafb7 256 else if (fAnalysisType == "AOD") {
257 if (!fAOD) {
258 Printf("ERROR: fAOD not available");
259 return;
260 }
261 Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
262
aaebd73d 263 // analysis
264 //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
924fafb7 265 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
dce74562 266 fMyCumuAnalysis->Make(fEvent);
924fafb7 267 delete fEvent;
268 }
aaebd73d 269
270
271 PostData(0,fListHistos);
924fafb7 272}
273
274//________________________________________________________________________
275void AliAnalysisTaskCumulants::Terminate(Option_t *)
aaebd73d 276{
277 //=====================================================================================================
278 // Accessing the output file which contains the merged results from all workers;
279 fListHistos = (TList*)GetOutputData(0);
280 //fListHistos->Print();//printing the list of stored histos
281 //=====================================================================================================
282
283 if(fListHistos)
284 {
285 // Profiles with values of generating functions
286 TProfile2D *fIntFlowGenFun=dynamic_cast<TProfile2D*>(fListHistos->FindObject("fIntFlowGenFun"));
287 TProfile3D *fDiffFlowGenFunRe=dynamic_cast<TProfile3D*>(fListHistos->FindObject("fDiffFlowGenFunRe"));
288 TProfile3D *fDiffFlowGenFunIm=dynamic_cast<TProfile3D*>(fListHistos->FindObject("fDiffFlowGenFunIm"));
289
290 // Histograms to store final results
291 TH1D *fIntFlowResults=dynamic_cast<TH1D*>(fListHistos->FindObject("fIntFlowResults"));
292 TH1D *fDiffFlowResults2=dynamic_cast<TH1D*>(fListHistos->FindObject("fDiffFlowResults2"));
293 TH1D *fDiffFlowResults4=dynamic_cast<TH1D*>(fListHistos->FindObject("fDiffFlowResults4"));
294 TH1D *fDiffFlowResults6=dynamic_cast<TH1D*>(fListHistos->FindObject("fDiffFlowResults6"));
295 TH1D *fDiffFlowResults8=dynamic_cast<TH1D*>(fListHistos->FindObject("fDiffFlowResults8"));
296
297 // Avarage multiplicity
298 TProfile *AvMult=dynamic_cast<TProfile*>(fListHistos->FindObject("fHistProAvM"));
299 Double_t BvM=AvMult->GetBinContent(1);//avarage multiplicity
300
301 // Calling the function which from values of generating functions calculate integrated and differential flow and store the final results into histograms
302 AliCumulantsFunctions FinalResults(fIntFlowGenFun,fDiffFlowGenFunRe,fDiffFlowGenFunIm,fIntFlowResults,fDiffFlowResults2,fDiffFlowResults4,fDiffFlowResults6,fDiffFlowResults8,BvM);
303 FinalResults.Calculate();
304 }
305 else
306 {
307 cout<<"histogram list pointer is empty"<<endl;
308 }
309}
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
924fafb7 326
924fafb7 327
924fafb7 328
924fafb7 329
c75fdbdc 330