]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliAnalysisTaskScalarProduct.cxx
New line missing.
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliAnalysisTaskScalarProduct.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" //needed as include
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
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
45 ClassImp(AliAnalysisTaskScalarProduct)
46
47 //________________________________________________________________________
48 AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name) : 
49   AliAnalysisTask(name, ""), 
50   fESD(0),
51   fAOD(0),
52   fSP(0),
53   fEventMaker(0),
54   fAnalysisType("ESD")
55 {
56   // Constructor
57   cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name)"<<endl;
58
59   // Define input and output slots here
60   // Input slot #0 works with a TChain
61   DefineInput(0, TChain::Class());
62   // Output slot #0 writes into a TList container
63   DefineOutput(0, TList::Class());  
64 }
65
66 //________________________________________________________________________
67 void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *) 
68 {
69   // Connect ESD or AOD here
70   // Called once
71   cout<<"AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)"<<endl;
72
73   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
74   if (!tree) {
75     Printf("ERROR: Could not read chain from input slot 0");
76   } else {
77     // Disable all branches and enable only the needed ones
78     if (fAnalysisType == "MC") {
79       cout<<"!!!!!reading MC kinematics only"<<endl;
80       // we want to process only MC
81       tree->SetBranchStatus("*", kFALSE);
82
83       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
84
85       if (!esdH) {
86         Printf("ERROR: Could not get ESDInputHandler");
87       } else {
88         fESD = esdH->GetEvent();
89       }
90     }
91     else if (fAnalysisType == "ESD") {
92       cout<<"!!!!!reading the ESD only"<<endl;
93       tree->SetBranchStatus("*", kFALSE);
94       tree->SetBranchStatus("Tracks.*", kTRUE);
95
96       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
97
98       if (!esdH) {
99         Printf("ERROR: Could not get ESDInputHandler");
100       } else
101         fESD = esdH->GetEvent();
102     }
103     else if (fAnalysisType == "AOD") {
104       cout<<"!!!!!reading the AOD only"<<endl;
105       AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
106
107       if (!aodH) {
108         Printf("ERROR: Could not get AODInputHandler");
109       }
110       else {
111         fAOD = aodH->GetEvent();
112       }
113     }
114     else {
115       Printf("!!!!!Wrong analysis type: Only ESD, AOD and MC types are allowed!");
116       exit(1);
117       
118     }
119   }
120 }
121
122 //________________________________________________________________________
123 void AliAnalysisTaskScalarProduct::CreateOutputObjects() 
124 {
125   // Called once
126   cout<<"AliAnalysisTaskScalarProduct::CreateOutputObjects()"<<endl;
127
128   if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "MC")) {
129     cout<<"WRONG ANALYSIS TYPE! only ESD, AOD and MC are allowed."<<endl;
130     exit(1);
131   }
132
133   //event maker
134   fEventMaker = new AliFlowEventSimpleMaker();
135   //Analyser
136   fSP  = new AliFlowAnalysisWithScalarProduct() ;
137
138   //output file
139   TString fName = "outputFromScalarProductAnalysis" ;
140   fName += fAnalysisType.Data() ;
141   fName += ".root" ;
142   fSP->SetHistFileName( fName.Data() );
143     
144   fSP-> Init();
145
146
147 }
148
149 //________________________________________________________________________
150 void AliAnalysisTaskScalarProduct::Exec(Option_t *) 
151 {
152   // Main loop
153   // Called for each event
154
155   
156   // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
157   // This handler can return the current MC event
158
159   AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
160   if (!eventHandler) {
161     Printf("ERROR: Could not retrieve MC event handler");
162     return;
163   }
164
165   AliMCEvent* mcEvent = eventHandler->MCEvent();
166   if (!mcEvent) {
167     Printf("ERROR: Could not retrieve MC event");
168     return;
169   }
170
171   Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
172       
173   if (fAnalysisType == "MC") {
174     // analysis 
175     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent);
176     fSP->Make(fEvent);
177
178     delete fEvent;
179   }
180   else if (fAnalysisType == "ESD") {
181     if (!fESD) {
182       Printf("ERROR: fESD not available");
183       return;
184     }
185     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
186     
187     // analysis 
188     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD);
189     fSP->Make(fEvent);
190     delete fEvent;
191   }
192   else if (fAnalysisType == "AOD") {
193     if (!fAOD) {
194       Printf("ERROR: fAOD not available");
195       return;
196     }
197     Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
198
199     // analysis 
200     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
201     fSP->Make(fEvent);
202     delete fEvent;
203   }
204
205 }      
206
207 //________________________________________________________________________
208 void AliAnalysisTaskScalarProduct::Terminate(Option_t *) 
209 {
210   // Called once at the end of the query
211   fSP->Finish();
212   PostData(0,fSP->GetHistFile());
213
214   delete fSP;
215   delete fEventMaker;
216 }