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),
62 // Default constructor
65 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
66 AliAnalysisTaskSE(name),
67 fConfigFile("ConfigJetAnalysis.C"),
76 fReadAODFromOutput(0),
79 // Default constructor
80 DefineOutput(1, TList::Class());
83 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
84 AliAnalysisTaskSE(name),
85 fConfigFile("ConfigJetAnalysis.C"),
94 fReadAODFromOutput(0),
97 // Default constructor
98 DefineOutput(1, TList::Class());
101 //----------------------------------------------------------------
102 void AliAnalysisTaskJets::UserCreateOutputObjects()
104 // Create the output container
106 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
108 if(fNonStdBranch.Length()==0)
110 // Connec default AOD to jet finder
111 // create a new branch for the background
112 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
113 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
114 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
115 AddAODBranch("AliAODJetEventBackground",&evBkg);
117 fJetFinder->ConnectAOD(AODEvent());
121 // Create a new branch for jets...
122 // how is this reset? -> cleared in the UserExec....
123 // Can this be handled by the framework?
124 // here we can also have the case that the brnaches are written to a separate file
126 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
127 tca->SetName(fNonStdBranch.Data());
128 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
129 if(!AODEvent() || !AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
130 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
131 evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
132 AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
135 if(fNonStdFile.Length()!=0){
137 // case that we have an AOD extension we need to fetch the jets from the extended output
138 // we identifay the extension aod event by looking for the branchname
139 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
142 TObjArray* extArray = aodH->GetExtensions();
144 TIter next(extArray);
145 while ((fAODExtension=(AliAODExtension*)next())){
146 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
148 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
149 fAODExtension->GetAOD()->Dump();
152 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
159 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
162 if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data());
163 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
167 // do not add the histograms in the directory
168 // all handled by the list
169 Bool_t oldStatus = TH1::AddDirectoryStatus();
170 TH1::AddDirectory(kFALSE);
174 fListOfHistos = new TList();
175 fHistos = new AliJetHistos();
176 fHistos->AddHistosToList(fListOfHistos);
178 // Add the JetFinderInformation to the Outputlist
179 AliJetHeader *fH = fJetFinder->GetHeader();
181 // Compose a characteristic output name
182 // with the name of the output branch
184 if(fNonStdBranch.Length()==0) {
185 fH->SetName("AliJetHeader_jets");
188 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
192 TH1::AddDirectory(oldStatus);
195 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
196 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
199 //----------------------------------------------------------------
200 void AliAnalysisTaskJets::Init()
203 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
205 // Call configuration file
206 if (fConfigFile.Length()) {
207 gROOT->LoadMacro(fConfigFile);
208 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
210 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
211 fOpt = header->GetDetector();
213 // Initialise Jet Analysis
214 if(fOpt == 0) fJetFinder->Init();
215 else fJetFinder->InitTask(fChain); // V2
219 //----------------------------------------------------------------
220 void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
222 // Execute analysis for current event
224 // Fill control histos
225 TClonesArray* jarray = 0;
226 AliAODJetEventBackground* evBkg = 0;
228 // only need this once
229 static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
231 if(fNonStdBranch.Length()==0) {
232 jarray = AODEvent()->GetJets();
233 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
237 if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
238 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
239 if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again
240 if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
241 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
242 if(evBkg)evBkg->Reset();
245 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
246 // AOD is input event..........................................V
247 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
249 // AOD is read from output ....................................V
250 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
255 if(fOpt==0) fJetFinder->ProcessEvent();
256 else fJetFinder->ProcessEvent2(); // V2
258 // Fill control histos
259 if(jarray)fHistos->FillHistos(jarray);
262 if(aodH&&fFilterPt>0){
263 if(jarray->GetEntries()>0){
264 AliAODJet *jet = (AliAODJet*)jarray->At(0);
265 if(jet->Pt()>fFilterPt){
266 // aodH->EnableFillAODforEvent();
267 aodH->SetFillAOD(kTRUE);
273 PostData(1, fListOfHistos);
278 //*************************************************************
280 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
282 // Terminate analysis
284 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
285 // if (fJetFinder) fJetFinder->FinishRun();