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 "AliMCEventHandler.h"
39 #include "AliESDInputHandler.h"
40 #include "AliMCEvent.h"
44 ClassImp(AliAnalysisTaskJets)
46 ////////////////////////////////////////////////////////////////////////
48 AliAnalysisTaskJets::AliAnalysisTaskJets():
50 fConfigFile("ConfigJetAnalysis.C"),
59 fReadAODFromOutput(0),
60 fUseAODBackground(kFALSE),
63 // Default constructor
66 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
67 AliAnalysisTaskSE(name),
68 fConfigFile("ConfigJetAnalysis.C"),
77 fReadAODFromOutput(0),
78 fUseAODBackground(kFALSE),
81 // Default constructor
82 DefineOutput(1, TList::Class());
85 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
86 AliAnalysisTaskSE(name),
87 fConfigFile("ConfigJetAnalysis.C"),
96 fReadAODFromOutput(0),
97 fUseAODBackground(kFALSE),
100 // Default constructor
101 DefineOutput(1, TList::Class());
104 //----------------------------------------------------------------
105 void AliAnalysisTaskJets::UserCreateOutputObjects()
107 // Create the output container
109 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
111 AliJetHeader *fH = fJetFinder->GetHeader();
113 if(fNonStdBranch.Length()==0)
115 // Connec default AOD to jet finder
116 // create a new branch for the background
118 if(fUseAODBackground){
119 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
120 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
121 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
122 AddAODBranch("AliAODJetEventBackground",&evBkg);
125 fJetFinder->ConnectAOD(AODEvent());
129 // Create a new branch for jets...
130 // how is this reset? -> cleared in the UserExec....
131 // Can this be handled by the framework?
132 // here we can also have the case that the brnaches are written to a separate file
134 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
135 tca->SetName(fNonStdBranch.Data());
136 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
137 if(fUseAODBackground){
138 if(!AODEvent() || !AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
139 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
140 evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
141 AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
144 if(fNonStdFile.Length()!=0){
146 // case that we have an AOD extension we need to fetch the jets from the extended output
147 // we identifay the extension aod event by looking for the branchname
148 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
151 TObjArray* extArray = aodH->GetExtensions();
153 TIter next(extArray);
154 while ((fAODExtension=(AliAODExtension*)next())){
155 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
157 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
158 fAODExtension->GetAOD()->Dump();
161 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
168 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
171 if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data());
172 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
176 // do not add the histograms in the directory
177 // all handled by the list
178 Bool_t oldStatus = TH1::AddDirectoryStatus();
179 TH1::AddDirectory(kFALSE);
183 fListOfHistos = new TList();
184 fHistos = new AliJetHistos();
185 fHistos->AddHistosToList(fListOfHistos);
187 // Add the JetFinderInformation to the Outputlist
189 // Compose a characteristic output name
190 // with the name of the output branch
192 if(fNonStdBranch.Length()==0) {
193 fH->SetName("AliJetHeader_jets");
196 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
200 TH1::AddDirectory(oldStatus);
203 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
204 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
207 //----------------------------------------------------------------
208 void AliAnalysisTaskJets::Init()
211 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
213 // Call configuration file
214 if (fConfigFile.Length()) {
215 gROOT->LoadMacro(fConfigFile);
216 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
218 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
219 fOpt = header->GetDetector();
221 // Initialise Jet Analysis
222 if(fOpt == 0) fJetFinder->Init();
223 else fJetFinder->InitTask(fChain); // V2
227 //----------------------------------------------------------------
228 void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
230 // Execute analysis for current event
232 // Fill control histos
233 TClonesArray* jarray = 0;
234 AliAODJetEventBackground* evBkg = 0;
236 // only need this once
237 static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
239 if(fNonStdBranch.Length()==0) {
240 jarray = AODEvent()->GetJets();
241 if(fUseAODBackground){
242 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
247 if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
248 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
249 if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again
250 if(fUseAODBackground){
251 if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
252 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
253 if(evBkg)evBkg->Reset();
257 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
258 // AOD is input event..........................................V
259 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
261 // AOD is read from output ....................................V
262 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
267 if(fOpt==0) fJetFinder->ProcessEvent();
268 else fJetFinder->ProcessEvent2(); // V2
270 // Fill control histos
271 if(jarray)fHistos->FillHistos(jarray);
274 if(jarray&&aodH&&fFilterPt>0){
275 if(jarray->GetEntries()>0){
276 AliAODJet *jet = (AliAODJet*)jarray->At(0);
277 if(jet->Pt()>fFilterPt){
278 // aodH->EnableFillAODforEvent();
279 aodH->SetFillAOD(kTRUE);
285 PostData(1, fListOfHistos);
290 //*************************************************************
292 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
294 // Terminate analysis
296 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
297 // if (fJetFinder) fJetFinder->FinishRun();