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