]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliAnalysisTaskCumulants.cxx
bfbf8765e4d625442b77850ac4de57029eb16d07
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliAnalysisTaskCumulants.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"
20
21
22 class AliAnalysisTask;
23 #include "AliAnalysisManager.h"
24
25 #include "AliESDEvent.h"
26 #include "AliESDInputHandler.h"
27
28 #include "AliAODEvent.h"
29 #include "AliAODInputHandler.h"
30
31 #include "AliMCEventHandler.h"
32 #include "AliMCEvent.h"
33
34 #include "AliAnalysisTaskCumulants.h"
35 #include "AliFlowEventSimpleMaker.h"
36 #include "AliFlowAnalysisWithCumulants.h"
37
38 // AliAnalysisTaskCumulants:
39 // analysis task for Lee Yang Zeros method
40 // Author: Naomi van der Kolk (kolk@nikhef.nl)
41
42 ClassImp(AliAnalysisTaskCumulants)
43
44 //________________________________________________________________________
45 AliAnalysisTaskCumulants::AliAnalysisTaskCumulants(const char *name) : 
46   AliAnalysisTask(name, ""), 
47   fESD(NULL),
48   fAOD(NULL),
49   fAnalysisType("ESD"), 
50   fMyCumuAnalysis(NULL),
51   fEventMaker(NULL)
52 {
53   // Constructor
54   cout<<"AliAnalysisTaskCumulants::AliAnalysisTaskCumulants(const char *name)"<<endl;
55
56   // Define input and output slots here
57   // Input slot #0 works with a TChain
58   DefineInput(0, TChain::Class());
59
60   // Output slot #0 writes into a TList container
61   DefineOutput(0, TList::Class());  
62 }
63
64 //________________________________________________________________________
65 void AliAnalysisTaskCumulants::ConnectInputData(Option_t *) 
66 {
67   // Connect ESD or AOD here
68   // Called once
69   cout<<"AliAnalysisTaskCumulants::ConnectInputData(Option_t *)"<<endl;
70
71   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
72   if (!tree) {
73     Printf("ERROR: Could not read chain from input slot 0");
74   } 
75   else {
76     // Disable all branches and enable only the needed ones
77     if (fAnalysisType == "MC") {
78       // we want to process only MC
79       tree->SetBranchStatus("*", kFALSE);
80
81       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
82
83       if (!esdH) {
84         Printf("ERROR: Could not get ESDInputHandler");
85       } else {
86         fESD = esdH->GetEvent();
87       }
88     }
89     else if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1"  ) {
90       tree->SetBranchStatus("*", kFALSE);
91       tree->SetBranchStatus("Tracks.*", kTRUE);
92
93       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
94
95       if (!esdH) {
96         Printf("ERROR: Could not get ESDInputHandler");
97       } else
98         fESD = esdH->GetEvent();
99     }
100     else if (fAnalysisType == "AOD") {
101       AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
102
103       if (!aodH) {
104         Printf("ERROR: Could not get AODInputHandler");
105       }
106       else {
107         fAOD = aodH->GetEvent();
108       }
109     }
110     else {
111       Printf("Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
112
113     }
114   }
115 }
116
117 //________________________________________________________________________
118 void AliAnalysisTaskCumulants::CreateOutputObjects() 
119 {
120   // Called once
121   cout<<"AliAnalysisTaskCumulants::CreateOutputObjects()"<<endl;
122
123   if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0"  || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) {
124     cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
125     exit(1);
126   }
127
128   //event maker
129   fEventMaker = new AliFlowEventSimpleMaker();
130   //Analyser
131   fMyCumuAnalysis = new AliFlowAnalysisWithCumulants() ;
132    
133
134   //output file
135   TString outputName = "outputFromCumulantsAnalysis" ;
136   outputName += fAnalysisType.Data();
137   outputName += ".root";
138   fMyCumuAnalysis->SetHistFileName( outputName.Data() ); //Ante please implement
139   
140   
141   fMyCumuAnalysis->CreateOutputObjects();
142
143 }
144
145 //________________________________________________________________________
146 void AliAnalysisTaskCumulants::Exec(Option_t *) 
147 {
148   // Main loop
149   // Called for each event
150   if (fAnalysisType == "MC") {
151     // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
152     // This handler can return the current MC event
153
154     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
155     if (!eventHandler) {
156       Printf("ERROR: Could not retrieve MC event handler");
157       return;
158     }
159
160     AliMCEvent* mcEvent = eventHandler->MCEvent();
161     if (!mcEvent) {
162       Printf("ERROR: Could not retrieve MC event");
163       return;
164     }
165
166     Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
167
168     //Cumulants analysis 
169     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent);
170     fMyCumuAnalysis->Make(fEvent);
171     delete fEvent;
172   }
173   else if (fAnalysisType == "ESD") {
174     if (!fESD) {
175       Printf("ERROR: fESD not available");
176       return;
177     }
178     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
179     
180     //Cumulant analysis 
181     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD);
182     fMyCumuAnalysis->Make(fEvent);
183     delete fEvent;
184   }
185   else if (fAnalysisType == "ESDMC0") {
186     if (!fESD) {
187       Printf("ERROR: fESD not available");
188       return;
189     }
190     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
191     
192     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
193     if (!eventHandler) {
194       Printf("ERROR: Could not retrieve MC event handler");
195       return;
196     }
197
198     AliMCEvent* mcEvent = eventHandler->MCEvent();
199     if (!mcEvent) {
200       Printf("ERROR: Could not retrieve MC event");
201       return;
202     }
203
204     //Cumulant analysis 
205     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD,mcEvent,0); //0 = kine from ESD, 1 = kine from MC
206     fMyCumuAnalysis->Make(fEvent);
207     delete fEvent;
208     //delete mcEvent;
209   }
210   else if (fAnalysisType == "ESDMC1") {
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     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
218     if (!eventHandler) {
219       Printf("ERROR: Could not retrieve MC event handler");
220       return;
221     }
222
223     AliMCEvent* mcEvent = eventHandler->MCEvent();
224     if (!mcEvent) {
225       Printf("ERROR: Could not retrieve MC event");
226       return;
227     }
228
229     //Cumulant analysis 
230     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD,mcEvent,1); //0 = kine from ESD, 1 = kine from MC
231     fMyCumuAnalysis->Make(fEvent);
232     delete fEvent;
233     //delete mcEvent;
234   }
235   else if (fAnalysisType == "AOD") {
236     if (!fAOD) {
237       Printf("ERROR: fAOD not available");
238       return;
239     }
240     Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
241
242     //Cumulant analysis 
243     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
244     fMyCumuAnalysis->Make(fEvent);
245     delete fEvent;
246   }
247   
248 }
249
250 //________________________________________________________________________
251 void AliAnalysisTaskCumulants::Terminate(Option_t *) 
252 {
253   // Called once at the end of the query
254   cerr<<"fMyCumuAnalysis->GetHistFile() -> IsOpen() = "<<fMyCumuAnalysis->GetHistFile() -> IsOpen()<<endl;
255
256   fMyCumuAnalysis->Finish(); 
257
258   PostData(0,fMyCumuAnalysis->GetHistFile());
259
260   delete fMyCumuAnalysis;
261   delete fEventMaker;
262
263   cout<<".....finished"<<endl;
264 }