Adding include path to allow compilation of CleanGeom task
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskJetsFinder.cxx
CommitLineData
d89b8229 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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//----------------------------------------------------------------
17// Analysis task for interfacing the jet finders with the analysis framework
18//
19// Author: magali.estienne@subatech.in2p3.fr
20// alexandre.shabetai@cern.ch
21//
22//----------------------------------------------------------------
23
24#include <Riostream.h>
25#include <TROOT.h>
26#include <TSystem.h>
27#include <TInterpreter.h>
28#include <TFile.h>
29#include <TList.h>
30#include <TH1.h>
31
32#include "AliAnalysisTaskJetsFinder.h"
33#include "AliAnalysisManager.h"
34#include "AliJetFinder.h"
35#include "AliJetHeader.h"
36#include "AliJetHistos.h"
37#include "AliAODEvent.h"
38#include "AliAODJetEventBackground.h"
39#include "AliAODHandler.h"
40#include "AliAODExtension.h"
41
42ClassImp(AliAnalysisTaskJetsFinder)
43
44////////////////////////////////////////////////////////////////////////
45
46AliAnalysisTaskJetsFinder::AliAnalysisTaskJetsFinder():
47 AliAnalysisTaskSE(),
48 fConfigFile("ConfigJetAnalysis.C"),
49 fNonStdBranch(""),
50 fNonStdFile(""),
51 fJetFinder(0x0),
52 fHistos(0x0),
53 fAODExtension(0x0),
54 fListOfHistos(0x0),
55 fTreeI(0x0),
56 fEvent(0x0),
57 fUseAODBackground(kFALSE),
58 fFilterPt(0.)
59{
60 // Default constructor
61}
62
63//----------------------------------------------------------------
64AliAnalysisTaskJetsFinder::AliAnalysisTaskJetsFinder(const char* name):
65 AliAnalysisTaskSE(name),
66 fConfigFile("ConfigJetAnalysis.C"),
67 fNonStdBranch(""),
68 fNonStdFile(""),
69 fJetFinder(0x0),
70 fHistos(0x0),
71 fAODExtension(0x0),
72 fListOfHistos(0x0),
73 fTreeI(0x0),
74 fEvent(0x0),
75 fUseAODBackground(kFALSE),
76 fFilterPt(0.)
77{
78 // Constructor 2
79 DefineInput(1, TTree::Class());
80 DefineOutput(1, TList::Class());
81
82}
83
84//----------------------------------------------------------------
85AliAnalysisTaskJetsFinder::~AliAnalysisTaskJetsFinder()
86{
87 // destructor
88 if (fHistos && ! AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fHistos;
89 if (fListOfHistos && ! AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fListOfHistos;
90
91}
92
93//----------------------------------------------------------------
94void AliAnalysisTaskJetsFinder::ConnectInputData(Option_t *)
95{
96 // Get the exchanged tree and event
97 AliAnalysisTaskSE::ConnectInputData();
98
99 fTreeI = (TTree*)GetInputData(1);
100
101 char **address =(char **)GetBranchAddress(1,"AliJetCalTrkEvent");
102 if (address) {
103 fEvent = (AliJetCalTrkEvent*) (*address);
104 }
105 else { printf("AliJetCalTrkEvent address not found, pleae check containers"); }
106
107}
108
109//----------------------------------------------------------------
110void AliAnalysisTaskJetsFinder::UserCreateOutputObjects()
111{
112 // Create the output container containt
113 //
114 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
115
116 AliJetHeader *fH = fJetFinder->GetJetHeader();
117
118 if(fNonStdBranch.Length()==0)
119 {
120 // Connect default AOD to jet finder
121 // create a new branch for the background
122
123 if(fUseAODBackground){
124 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
125 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
126 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
127 AddAODBranch("AliAODJetEventBackground",&evBkg);
128 }
129 }
130 fJetFinder->ConnectAOD(AODEvent());
131 }
132 else
133 {
134 // Create a new branch for jets...
135 // how is this reset? -> cleared in the UserExec....
136 // Can this be handled by the framework?
137 // here we can also have the case that the brnaches are written to a separate file
138
139 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
140 tca->SetName(fNonStdBranch.Data());
141 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
142 if(fUseAODBackground){
143 if(!AODEvent() || !AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
144 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
145 evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
146 AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
147 }
148 }
149 if(fNonStdFile.Length()!=0){
150 //
151 // case that we have an AOD extension we need to fetch the jets from the extended output
152 // we identifay the extension aod event by looking for the branchname
153 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
154 fAODExtension = 0;
155 if(aodH){
156 TObjArray* extArray = aodH->GetExtensions();
157 if (extArray) {
158 TIter next(extArray);
159 while ((fAODExtension=(AliAODExtension*)next())){
160 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
161 if(fDebug>10){
162 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
163 fAODExtension->GetAOD()->Dump();
164 }
165 if(obj){
166 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
167 break;
168 }
169 fAODExtension = 0;
170 }
171 }
172 }
173 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
174 }
175 else{
176 if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data());
177 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
178 }
179 }
180
181 // do not add the histograms in the directory
182 // all handled by the list
183 Bool_t oldStatus = TH1::AddDirectoryStatus();
184 TH1::AddDirectory(kFALSE);
185
186 // Histograms
187 fListOfHistos = new TList();
188 fListOfHistos->SetOwner();
189 fHistos = new AliJetHistos();
190 fHistos->CreateHistos();
191 fHistos->AddHistosToList(fListOfHistos);
192 // CDF case
193 if(fJetFinder->InheritsFrom("AliCdfJetFinder")) fJetFinder->CreateOutputObjects(fListOfHistos);
194
195 // Add the JetFinderInformation to the Outputlist
196
197 // Compose a characteristic output name
198 // with the name of the output branch
199 if(fH) {
200 if(fNonStdBranch.Length()==0) {
201 fH->SetName("AliJetHeader_jets");
202 }
203 else {
204 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
205 }
206 }
207
208 TH1::AddDirectory(oldStatus);
209
210 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
211 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
212
213 // post
214 PostData(1, fListOfHistos);
215
216}
217
218//----------------------------------------------------------------
219void AliAnalysisTaskJetsFinder::Init()
220{
221 // Initialization
222 if (fDebug > 1) printf("AnalysisTaskJetsFinder::Init() \n");
223
224 // Call configuration file
225 if (fConfigFile.Length()) {
226 gROOT->LoadMacro(fConfigFile);
227 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
228 }
229
230 // Initialise Jet Analysis
231 fJetFinder->Init();
232
233}
234
235
236//----------------------------------------------------------------
237Bool_t AliAnalysisTaskJetsFinder::Notify()
238{
239 if (fDebug > 1) printf("AnalysisTaskJetsFinder::Notify() \n");
240 return kTRUE;
241
242}
243
244//----------------------------------------------------------------
245void AliAnalysisTaskJetsFinder::UserExec(Option_t */*option*/)
246{
247
248 // Execute analysis for current event
249
250 if (fDebug > 1) printf("AnalysisTaskJetsFinder::UserExec() \n");
251
252 TClonesArray* jarray = 0;
253 AliAODJetEventBackground* evBkg = 0;
254
255 // only need this once
256 static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
257
258 if(fNonStdBranch.Length()==0) {
259 jarray = AODEvent()->GetJets();
260 if(fUseAODBackground){
261 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
262 evBkg->Reset();
263 }
264 }
265 else {
266 if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
267 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
268 if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again
269 if(fUseAODBackground){
270 if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
271 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
272 if(evBkg)evBkg->Reset();
273 }
274 }
275
276 fTreeI->GetEntry(0);
277
278 fJetFinder->SetCalTrkEvent(*fEvent);
279
280 fJetFinder->ProcessEvent();
281
282 // Fill control histos
283 if(jarray)fHistos->FillHistos(jarray);
284
285 // Store the jet branch in the AOD
286 if(jarray&&aodH&&fFilterPt>0){
287 if(jarray->GetEntries()>0){
288 AliAODJet *jet = (AliAODJet*)jarray->At(0);
289 if(jet->Pt()>fFilterPt){
290 aodH->SetFillAOD(kTRUE);
291 }
292 }
293 }
294
295 // Post the data
296 PostData(1, fListOfHistos);
297 return;
298
299}
300
301//----------------------------------------------------------------
302void AliAnalysisTaskJetsFinder::Terminate(Option_t */*option*/)
303{
304 // Terminate analysis
305 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
306
307}
308