coverity fixes
[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();
bc64c053 185 fListOfHistos->SetOwner();
8838ab7a 186 fHistos = new AliJetHistos();
187 fHistos->AddHistosToList(fListOfHistos);
188
189 // Add the JetFinderInformation to the Outputlist
8838ab7a 190
191 // Compose a characteristic output name
192 // with the name of the output branch
193 if(fH) {
194 if(fNonStdBranch.Length()==0) {
195 fH->SetName("AliJetHeader_jets");
4aa71b6f 196 }
8838ab7a 197 else {
198 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
99c8d2ad 199 }
8838ab7a 200 }
0f5f5d71 201
202 TH1::AddDirectory(oldStatus);
203
204
931c23a1 205 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
206 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
13ee0d77 207
208 // post
209 PostData(1, fListOfHistos);
210
e5b96aa0 211}
212
8838ab7a 213//----------------------------------------------------------------
19e6695b 214void AliAnalysisTaskJets::Init()
e5b96aa0 215{
8838ab7a 216 // Initialization
217 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
218
219 // Call configuration file
220 if (fConfigFile.Length()) {
221 gROOT->LoadMacro(fConfigFile);
222 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
223 }
224 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
225 fOpt = header->GetDetector();
226
f45e6f72 227// AODB path for Jetan Analysis... if not alread defined, use the standard one
228if ((!(((AliJetReader*) fJetFinder->GetReader())->GetJetanOADBPath()).Length())) {
229((AliJetReader*) fJetFinder->GetReader())->SetJetanOADBPath(AliAnalysisManager::GetOADBPath());
230}
231else Info( "Init"," OADBPath for Jetan was already defined (config file?) as %s",(char*)((fJetFinder->GetReader()->GetJetanOADBPath()).Data()));
232
8838ab7a 233 // Initialise Jet Analysis
234 if(fOpt == 0) fJetFinder->Init();
235 else fJetFinder->InitTask(fChain); // V2
19e6695b 236}
237
931c23a1 238
8838ab7a 239//----------------------------------------------------------------
ae24a5a1 240void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
e5b96aa0 241{
4aa71b6f 242 // Execute analysis for current event
243 //
4aa71b6f 244 // Fill control histos
245 TClonesArray* jarray = 0;
8bca421f 246 AliAODJetEventBackground* evBkg = 0;
8838ab7a 247
0b64955a 248 // only need this once
249 static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
250
8838ab7a 251 if(fNonStdBranch.Length()==0) {
4aa71b6f 252 jarray = AODEvent()->GetJets();
21ead515 253 if(fUseAODBackground){
254 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
255 evBkg->Reset();
256 }
4aa71b6f 257 }
8838ab7a 258 else {
8bca421f 259 if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
931c23a1 260 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
8bca421f 261 if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again
21ead515 262 if(fUseAODBackground){
263 if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
264 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
265 if(evBkg)evBkg->Reset();
266 }
4aa71b6f 267 }
931c23a1 268
0f4a88df 269 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
270// AOD is input event..........................................V
c98859dd 271 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
272 } else {
0f4a88df 273// AOD is read from output ....................................V
c98859dd 274 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
275 }
276
277
4aa71b6f 278
8838ab7a 279 if(fOpt==0) fJetFinder->ProcessEvent();
280 else fJetFinder->ProcessEvent2(); // V2
281
282 // Fill control histos
8bca421f 283 if(jarray)fHistos->FillHistos(jarray);
8838ab7a 284
0b64955a 285
85587ff2 286 if(jarray&&aodH&&fFilterPt>0){
0b64955a 287 if(jarray->GetEntries()>0){
288 AliAODJet *jet = (AliAODJet*)jarray->At(0);
289 if(jet->Pt()>fFilterPt){
290 // aodH->EnableFillAODforEvent();
291 aodH->SetFillAOD(kTRUE);
292 }
293 }
294 }
295
4aa71b6f 296 // Post the data
297 PostData(1, fListOfHistos);
931c23a1 298 return;
e5b96aa0 299}
300
8838ab7a 301
302//*************************************************************
303
e5b96aa0 304void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
305{
306// Terminate analysis
307//
19e6695b 308 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
9ff7671d 309// if (fJetFinder) fJetFinder->FinishRun();
e5b96aa0 310}
311