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"),
61 // Default constructor
64 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
65 AliAnalysisTaskSE(name),
66 fConfigFile("ConfigJetAnalysis.C"),
77 // Default constructor
78 DefineOutput(1, TList::Class());
81 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
82 AliAnalysisTaskSE(name),
83 fConfigFile("ConfigJetAnalysis.C"),
94 // Default constructor
95 DefineOutput(1, TList::Class());
98 //----------------------------------------------------------------
99 void AliAnalysisTaskJets::UserCreateOutputObjects()
101 // Create the output container
103 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
105 if(fNonStdBranch.Length()==0)
107 // Connec default AOD to jet finder
108 // create a new branch for the background
109 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
110 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
111 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
112 AddAODBranch("AliAODJetEventBackground",&evBkg);
114 fJetFinder->ConnectAOD(AODEvent());
118 // Create a new branch for jets...
119 // how is this reset? -> cleared in the UserExec....
120 // Can this be handled by the framework?
121 // here we can also have the case that the brnaches are written to a separate file
123 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
124 tca->SetName(fNonStdBranch.Data());
125 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
126 if(!AODEvent() || !AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
127 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
128 evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
129 AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
132 if(fNonStdFile.Length()!=0){
134 // case that we have an AOD extension we need to fetch the jets from the extended output
135 // we identifay the extension aod event by looking for the branchname
136 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
137 TObjArray* extArray = aodH->GetExtensions();
139 TIter next(extArray);
140 while ((fAODExtension=(AliAODExtension*)next())){
141 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
143 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
144 fAODExtension->GetAOD()->Dump();
147 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
153 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
156 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
160 // do not add the histograms in the directory
161 // all handled by the list
162 Bool_t oldStatus = TH1::AddDirectoryStatus();
163 TH1::AddDirectory(kFALSE);
167 fListOfHistos = new TList();
168 fHistos = new AliJetHistos();
169 fHistos->AddHistosToList(fListOfHistos);
171 // Add the JetFinderInformation to the Outputlist
172 AliJetHeader *fH = fJetFinder->GetHeader();
174 // Compose a characteristic output name
175 // with the name of the output branch
177 if(fNonStdBranch.Length()==0) {
178 fH->SetName("AliJetHeader_jets");
181 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
185 TH1::AddDirectory(oldStatus);
188 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
189 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
192 //----------------------------------------------------------------
193 void AliAnalysisTaskJets::Init()
196 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
198 // Call configuration file
199 if (fConfigFile.Length()) {
200 gROOT->LoadMacro(fConfigFile);
201 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
203 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
204 fOpt = header->GetDetector();
206 // Initialise Jet Analysis
207 if(fOpt == 0) fJetFinder->Init();
208 else fJetFinder->InitTask(fChain); // V2
212 //----------------------------------------------------------------
213 void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
215 // Execute analysis for current event
217 // Fill control histos
218 TClonesArray* jarray = 0;
219 AliAODJetEventBackground* evBkg = 0;
221 if(fNonStdBranch.Length()==0) {
222 jarray = AODEvent()->GetJets();
223 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
227 if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
228 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
229 if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again
230 if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
231 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
232 if(evBkg)evBkg->Reset();
235 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
236 // AOD is input event..........................................V
237 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
239 // AOD is read from output ....................................V
240 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
245 if(fOpt==0) fJetFinder->ProcessEvent();
246 else fJetFinder->ProcessEvent2(); // V2
248 // Fill control histos
249 if(jarray)fHistos->FillHistos(jarray);
252 PostData(1, fListOfHistos);
257 //*************************************************************
259 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
261 // Terminate analysis
263 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
264 // if (fJetFinder) fJetFinder->FinishRun();