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 **************************************************************************/
17 #include <Riostream.h>
20 #include <TInterpreter.h>
26 #include "AliAnalysisTaskJets.h"
27 #include "AliAnalysisManager.h"
28 #include "AliJetFinder.h"
29 #include "AliJetHeader.h"
30 #include "AliJetReader.h"
31 #include "AliJetReaderHeader.h"
32 #include "AliJetHistos.h"
33 #include "AliESDEvent.h"
35 #include "AliAODEvent.h"
36 #include "AliAODJetEventBackground.h"
37 #include "AliAODHandler.h"
38 #include "AliAODExtension.h"
39 #include "AliMCEventHandler.h"
40 #include "AliESDInputHandler.h"
41 #include "AliMCEvent.h"
45 ClassImp(AliAnalysisTaskJets)
47 ////////////////////////////////////////////////////////////////////////
49 AliAnalysisTaskJets::AliAnalysisTaskJets():
51 fConfigFile("ConfigJetAnalysis.C"),
60 fReadAODFromOutput(0),
61 fUseAODBackground(kFALSE),
64 // Default constructor
67 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
68 AliAnalysisTaskSE(name),
69 fConfigFile("ConfigJetAnalysis.C"),
78 fReadAODFromOutput(0),
79 fUseAODBackground(kFALSE),
82 // Default constructor
83 DefineOutput(1, TList::Class());
86 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
87 AliAnalysisTaskSE(name),
88 fConfigFile("ConfigJetAnalysis.C"),
97 fReadAODFromOutput(0),
98 fUseAODBackground(kFALSE),
101 // Default constructor
102 DefineOutput(1, TList::Class());
105 //----------------------------------------------------------------
106 void AliAnalysisTaskJets::UserCreateOutputObjects()
108 // Create the output container
110 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
112 AliJetHeader *fH = fJetFinder->GetHeader();
114 if(fNonStdBranch.Length()==0)
116 // Connec default AOD to jet finder
117 // create a new branch for the background
119 if(fUseAODBackground){
120 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
121 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
122 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
123 AddAODBranch("AliAODJetEventBackground",&evBkg);
126 fJetFinder->ConnectAOD(AODEvent());
130 // Create a new branch for jets...
131 // how is this reset? -> cleared in the UserExec....
132 // Can this be handled by the framework?
133 // here we can also have the case that the brnaches are written to a separate file
135 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
136 tca->SetName(fNonStdBranch.Data());
137 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
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());
145 if(fNonStdFile.Length()!=0){
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());
152 TObjArray* extArray = aodH->GetExtensions();
154 TIter next(extArray);
155 while ((fAODExtension=(AliAODExtension*)next())){
156 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
158 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
159 fAODExtension->GetAOD()->Dump();
162 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
169 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
172 if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data());
173 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
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);
184 fListOfHistos = new TList();
185 fListOfHistos->SetOwner();
186 fHistos = new AliJetHistos();
187 fHistos->AddHistosToList(fListOfHistos);
189 // Add the JetFinderInformation to the Outputlist
191 // Compose a characteristic output name
192 // with the name of the output branch
194 if(fNonStdBranch.Length()==0) {
195 fH->SetName("AliJetHeader_jets");
198 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
202 TH1::AddDirectory(oldStatus);
205 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
206 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
209 PostData(1, fListOfHistos);
213 //----------------------------------------------------------------
214 void AliAnalysisTaskJets::Init()
217 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
219 // Call configuration file
220 if (fConfigFile.Length()) {
221 gROOT->LoadMacro(fConfigFile);
222 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
224 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
225 fOpt = header->GetDetector();
227 // AODB path for Jetan Analysis... if not alread defined, use the standard one
228 if ((!(((AliJetReader*) fJetFinder->GetReader())->GetJetanOADBPath()).Length())) {
229 ((AliJetReader*) fJetFinder->GetReader())->SetJetanOADBPath(AliAnalysisManager::GetOADBPath());
231 else Info( "Init"," OADBPath for Jetan was already defined (config file?) as %s",(char*)((fJetFinder->GetReader()->GetJetanOADBPath()).Data()));
233 // Initialise Jet Analysis
234 if(fOpt == 0) fJetFinder->Init();
235 else fJetFinder->InitTask(fChain); // V2
239 //----------------------------------------------------------------
240 void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
242 // Execute analysis for current event
244 // Fill control histos
245 TClonesArray* jarray = 0;
246 AliAODJetEventBackground* evBkg = 0;
248 // only need this once
249 static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
251 if(fNonStdBranch.Length()==0) {
252 jarray = AODEvent()->GetJets();
253 if(fUseAODBackground){
254 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
259 if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
260 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
261 if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again
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();
269 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
270 // AOD is input event..........................................V
271 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
273 // AOD is read from output ....................................V
274 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
279 if(fOpt==0) fJetFinder->ProcessEvent();
280 else fJetFinder->ProcessEvent2(); // V2
282 // Fill control histos
283 if(jarray)fHistos->FillHistos(jarray);
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->EnableFillAODforEvent();
291 aodH->SetFillAOD(kTRUE);
297 PostData(1, fListOfHistos);
302 //*************************************************************
304 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
306 // Terminate analysis
308 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
309 // if (fJetFinder) fJetFinder->FinishRun();