1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //----------------------------------------------------------------
17 // Analysis task for interfacing the jet finders with the analysis framework
19 // Author: magali.estienne@subatech.in2p3.fr
20 // alexandre.shabetai@cern.ch
22 //----------------------------------------------------------------
24 #include <Riostream.h>
27 #include <TInterpreter.h>
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"
42 ClassImp(AliAnalysisTaskJetsFinder)
44 ////////////////////////////////////////////////////////////////////////
46 AliAnalysisTaskJetsFinder::AliAnalysisTaskJetsFinder():
48 fConfigFile("ConfigJetAnalysis.C"),
57 fUseAODBackground(kFALSE),
60 // Default constructor
63 //----------------------------------------------------------------
64 AliAnalysisTaskJetsFinder::AliAnalysisTaskJetsFinder(const char* name):
65 AliAnalysisTaskSE(name),
66 fConfigFile("ConfigJetAnalysis.C"),
75 fUseAODBackground(kFALSE),
79 DefineInput(1, TTree::Class());
80 DefineOutput(1, TList::Class());
84 //----------------------------------------------------------------
85 AliAnalysisTaskJetsFinder::~AliAnalysisTaskJetsFinder()
88 if (fHistos && ! AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fHistos;
89 if (fListOfHistos && ! AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fListOfHistos;
93 //----------------------------------------------------------------
94 void AliAnalysisTaskJetsFinder::ConnectInputData(Option_t *)
96 // Get the exchanged tree and event
97 AliAnalysisTaskSE::ConnectInputData();
99 fTreeI = (TTree*)GetInputData(1);
101 char **address =(char **)GetBranchAddress(1,"AliJetCalTrkEvent");
103 fEvent = (AliJetCalTrkEvent*) (*address);
105 else { printf("AliJetCalTrkEvent address not found, pleae check containers"); }
109 //----------------------------------------------------------------
110 void AliAnalysisTaskJetsFinder::UserCreateOutputObjects()
112 // Create the output container containt
114 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
116 AliJetHeader *fH = fJetFinder->GetJetHeader();
118 if(fNonStdBranch.Length()==0)
120 // Connect default AOD to jet finder
121 // create a new branch for the background
123 if(fUseAODBackground){
124 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
125 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
126 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
127 AddAODBranch("AliAODJetEventBackground",&evBkg);
130 fJetFinder->ConnectAOD(AODEvent());
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
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());
149 if(fNonStdFile.Length()!=0){
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());
156 TObjArray* extArray = aodH->GetExtensions();
158 TIter next(extArray);
159 while ((fAODExtension=(AliAODExtension*)next())){
160 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
162 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
163 fAODExtension->GetAOD()->Dump();
166 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
173 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
176 if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data());
177 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
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);
187 fListOfHistos = new TList();
188 fListOfHistos->SetOwner();
189 fHistos = new AliJetHistos();
190 fHistos->CreateHistos();
191 fHistos->AddHistosToList(fListOfHistos);
193 if(fJetFinder->InheritsFrom("AliCdfJetFinder")) fJetFinder->CreateOutputObjects(fListOfHistos);
195 // Add the JetFinderInformation to the Outputlist
197 // Compose a characteristic output name
198 // with the name of the output branch
200 if(fNonStdBranch.Length()==0) {
201 fH->SetName("AliJetHeader_jets");
204 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
208 TH1::AddDirectory(oldStatus);
210 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
211 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
214 PostData(1, fListOfHistos);
218 //----------------------------------------------------------------
219 void AliAnalysisTaskJetsFinder::Init()
222 if (fDebug > 1) printf("AnalysisTaskJetsFinder::Init() \n");
224 // Call configuration file
225 if (fConfigFile.Length()) {
226 gROOT->LoadMacro(fConfigFile);
227 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
230 // Initialise Jet Analysis
236 //----------------------------------------------------------------
237 Bool_t AliAnalysisTaskJetsFinder::Notify()
239 if (fDebug > 1) printf("AnalysisTaskJetsFinder::Notify() \n");
244 //----------------------------------------------------------------
245 void AliAnalysisTaskJetsFinder::UserExec(Option_t */*option*/)
248 // Execute analysis for current event
250 if (fDebug > 1) printf("AnalysisTaskJetsFinder::UserExec() \n");
252 TClonesArray* jarray = 0;
253 AliAODJetEventBackground* evBkg = 0;
255 // only need this once
256 static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
258 if(fNonStdBranch.Length()==0) {
259 jarray = AODEvent()->GetJets();
260 if(fUseAODBackground){
261 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
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();
278 fJetFinder->SetCalTrkEvent(*fEvent);
280 fJetFinder->ProcessEvent();
282 // Fill control histos
283 if(jarray)fHistos->FillHistos(jarray);
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);
296 PostData(1, fListOfHistos);
301 //----------------------------------------------------------------
302 void AliAnalysisTaskJetsFinder::Terminate(Option_t */*option*/)
304 // Terminate analysis
305 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");