Adding includes for EMCAL_Utils and OADB PATH (A. Shabetai)
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskJets.cxx
CommitLineData
e5b96aa0 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 **************************************************************************/
f1a3e20a 15
16/* $Id$ */
8838ab7a 17#include <Riostream.h>
e5b96aa0 18#include <TROOT.h>
19#include <TSystem.h>
20#include <TInterpreter.h>
21#include <TChain.h>
76c48857 22#include <TFile.h>
22003a60 23#include <TList.h>
0f5f5d71 24#include <TH1.h>
e5b96aa0 25
26#include "AliAnalysisTaskJets.h"
1d27ecd2 27#include "AliAnalysisManager.h"
e5b96aa0 28#include "AliJetFinder.h"
99c8d2ad 29#include "AliJetHeader.h"
8838ab7a 30#include "AliJetReader.h"
31#include "AliJetReaderHeader.h"
22003a60 32#include "AliJetHistos.h"
1b307662 33#include "AliESDEvent.h"
7f7091b8 34#include "AliESD.h"
1d27ecd2 35#include "AliAODEvent.h"
bcec7a80 36#include "AliAODJetEventBackground.h"
1d27ecd2 37#include "AliAODHandler.h"
1240edf5 38#include "AliAODExtension.h"
691685d6 39#include "AliMCEventHandler.h"
9ff7671d 40#include "AliESDInputHandler.h"
7f7091b8 41#include "AliMCEvent.h"
691685d6 42#include "AliStack.h"
1d27ecd2 43
e5b96aa0 44
45ClassImp(AliAnalysisTaskJets)
46
47////////////////////////////////////////////////////////////////////////
48
19e6695b 49AliAnalysisTaskJets::AliAnalysisTaskJets():
8838ab7a 50 AliAnalysisTaskSE(),
51 fConfigFile("ConfigJetAnalysis.C"),
52 fNonStdBranch(""),
931c23a1 53 fNonStdFile(""),
4aa71b6f 54 fJetFinder(0x0),
55 fHistos(0x0),
931c23a1 56 fAODExtension(0x0),
8838ab7a 57 fListOfHistos(0x0),
58 fChain(0x0),
08c28025 59 fOpt(0),
0b64955a 60 fReadAODFromOutput(0),
21ead515 61 fUseAODBackground(kFALSE),
0b64955a 62 fFilterPt(0.)
19e6695b 63{
64 // Default constructor
65}
66
e5b96aa0 67AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
8838ab7a 68 AliAnalysisTaskSE(name),
69 fConfigFile("ConfigJetAnalysis.C"),
70 fNonStdBranch(""),
931c23a1 71 fNonStdFile(""),
8838ab7a 72 fJetFinder(0x0),
73 fHistos(0x0),
931c23a1 74 fAODExtension(0x0),
8838ab7a 75 fListOfHistos(0x0),
76 fChain(0x0),
0f4a88df 77 fOpt(0),
0b64955a 78 fReadAODFromOutput(0),
21ead515 79 fUseAODBackground(kFALSE),
0b64955a 80 fFilterPt(0.)
e5b96aa0 81{
82 // Default constructor
8838ab7a 83 DefineOutput(1, TList::Class());
eaabc21f 84}
85
8838ab7a 86AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
87 AliAnalysisTaskSE(name),
88 fConfigFile("ConfigJetAnalysis.C"),
89 fNonStdBranch(""),
931c23a1 90 fNonStdFile(""),
8838ab7a 91 fJetFinder(0x0),
92 fHistos(0x0),
931c23a1 93 fAODExtension(0x0),
8838ab7a 94 fListOfHistos(0x0),
95 fChain(chain),
0f4a88df 96 fOpt(0),
0b64955a 97 fReadAODFromOutput(0),
21ead515 98 fUseAODBackground(kFALSE),
0b64955a 99 fFilterPt(0.)
eaabc21f 100{
8838ab7a 101 // Default constructor
102 DefineOutput(1, TList::Class());
103}
4aa71b6f 104
8838ab7a 105//----------------------------------------------------------------
106void AliAnalysisTaskJets::UserCreateOutputObjects()
107{
108 // Create the output container
109 //
110 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
931c23a1 111
21ead515 112 AliJetHeader *fH = fJetFinder->GetHeader();
113
8838ab7a 114 if(fNonStdBranch.Length()==0)
115 {
4aa71b6f 116 // Connec default AOD to jet finder
bcec7a80 117 // create a new branch for the background
21ead515 118
119 if(fUseAODBackground){
120 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
121 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
122 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
123 AddAODBranch("AliAODJetEventBackground",&evBkg);
124 }
bcec7a80 125 }
4aa71b6f 126 fJetFinder->ConnectAOD(AODEvent());
127 }
8838ab7a 128 else
129 {
4aa71b6f 130 // Create a new branch for jets...
8838ab7a 131 // how is this reset? -> cleared in the UserExec....
4aa71b6f 132 // Can this be handled by the framework?
931c23a1 133 // here we can also have the case that the brnaches are written to a separate file
134
4aa71b6f 135 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
931c23a1 136 tca->SetName(fNonStdBranch.Data());
137 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
21ead515 138 if(fUseAODBackground){
139 if(!AODEvent() || !AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
140 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
141 evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
142 AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
143 }
931c23a1 144 }
931c23a1 145 if(fNonStdFile.Length()!=0){
146 //
147 // case that we have an AOD extension we need to fetch the jets from the extended output
148 // we identifay the extension aod event by looking for the branchname
149 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
225f0094 150 fAODExtension = 0;
151 if(aodH){
152 TObjArray* extArray = aodH->GetExtensions();
153 if (extArray) {
154 TIter next(extArray);
155 while ((fAODExtension=(AliAODExtension*)next())){
156 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
157 if(fDebug>10){
158 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
159 fAODExtension->GetAOD()->Dump();
160 }
161 if(obj){
931c23a1 162 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
163 break;
225f0094 164 }
165 fAODExtension = 0;
931c23a1 166 }
931c23a1 167 }
168 }
169 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
170 }
171 else{
294056ab 172 if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data());
931c23a1 173 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
bcec7a80 174 }
8838ab7a 175 }
bcec7a80 176
0f5f5d71 177 // do not add the histograms in the directory
178 // all handled by the list
179 Bool_t oldStatus = TH1::AddDirectoryStatus();
180 TH1::AddDirectory(kFALSE);
181
952b368c 182
8838ab7a 183 // Histograms
8838ab7a 184 fListOfHistos = new TList();
185 fHistos = new AliJetHistos();
186 fHistos->AddHistosToList(fListOfHistos);
187
188 // Add the JetFinderInformation to the Outputlist
8838ab7a 189
190 // Compose a characteristic output name
191 // with the name of the output branch
192 if(fH) {
193 if(fNonStdBranch.Length()==0) {
194 fH->SetName("AliJetHeader_jets");
4aa71b6f 195 }
8838ab7a 196 else {
197 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
99c8d2ad 198 }
8838ab7a 199 }
0f5f5d71 200
201 TH1::AddDirectory(oldStatus);
202
203
931c23a1 204 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
205 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
e5b96aa0 206}
207
8838ab7a 208//----------------------------------------------------------------
19e6695b 209void AliAnalysisTaskJets::Init()
e5b96aa0 210{
8838ab7a 211 // Initialization
212 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
213
214 // Call configuration file
215 if (fConfigFile.Length()) {
216 gROOT->LoadMacro(fConfigFile);
217 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
218 }
219 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
220 fOpt = header->GetDetector();
221
f45e6f72 222// AODB path for Jetan Analysis... if not alread defined, use the standard one
223if ((!(((AliJetReader*) fJetFinder->GetReader())->GetJetanOADBPath()).Length())) {
224((AliJetReader*) fJetFinder->GetReader())->SetJetanOADBPath(AliAnalysisManager::GetOADBPath());
225}
226else Info( "Init"," OADBPath for Jetan was already defined (config file?) as %s",(char*)((fJetFinder->GetReader()->GetJetanOADBPath()).Data()));
227
8838ab7a 228 // Initialise Jet Analysis
229 if(fOpt == 0) fJetFinder->Init();
230 else fJetFinder->InitTask(fChain); // V2
19e6695b 231}
232
931c23a1 233
8838ab7a 234//----------------------------------------------------------------
ae24a5a1 235void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
e5b96aa0 236{
4aa71b6f 237 // Execute analysis for current event
238 //
4aa71b6f 239 // Fill control histos
240 TClonesArray* jarray = 0;
8bca421f 241 AliAODJetEventBackground* evBkg = 0;
8838ab7a 242
0b64955a 243 // only need this once
244 static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
245
8838ab7a 246 if(fNonStdBranch.Length()==0) {
4aa71b6f 247 jarray = AODEvent()->GetJets();
21ead515 248 if(fUseAODBackground){
249 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
250 evBkg->Reset();
251 }
4aa71b6f 252 }
8838ab7a 253 else {
8bca421f 254 if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
931c23a1 255 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
8bca421f 256 if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again
21ead515 257 if(fUseAODBackground){
258 if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
259 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
260 if(evBkg)evBkg->Reset();
261 }
4aa71b6f 262 }
931c23a1 263
0f4a88df 264 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
265// AOD is input event..........................................V
c98859dd 266 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
267 } else {
0f4a88df 268// AOD is read from output ....................................V
c98859dd 269 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
270 }
271
272
4aa71b6f 273
8838ab7a 274 if(fOpt==0) fJetFinder->ProcessEvent();
275 else fJetFinder->ProcessEvent2(); // V2
276
277 // Fill control histos
8bca421f 278 if(jarray)fHistos->FillHistos(jarray);
8838ab7a 279
0b64955a 280
85587ff2 281 if(jarray&&aodH&&fFilterPt>0){
0b64955a 282 if(jarray->GetEntries()>0){
283 AliAODJet *jet = (AliAODJet*)jarray->At(0);
284 if(jet->Pt()>fFilterPt){
285 // aodH->EnableFillAODforEvent();
286 aodH->SetFillAOD(kTRUE);
287 }
288 }
289 }
290
4aa71b6f 291 // Post the data
292 PostData(1, fListOfHistos);
931c23a1 293 return;
e5b96aa0 294}
295
8838ab7a 296
297//*************************************************************
298
e5b96aa0 299void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
300{
301// Terminate analysis
302//
19e6695b 303 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
9ff7671d 304// if (fJetFinder) fJetFinder->FinishRun();
e5b96aa0 305}
306