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>
25 #include "AliAnalysisTaskJets.h"
26 #include "AliAnalysisManager.h"
27 #include "AliJetFinder.h"
28 #include "AliJetHeader.h"
29 #include "AliJetReader.h"
30 #include "AliJetReaderHeader.h"
31 #include "AliJetHistos.h"
32 #include "AliESDEvent.h"
34 #include "AliAODEvent.h"
35 #include "AliAODJetEventBackground.h"
36 #include "AliAODHandler.h"
37 #include "AliMCEventHandler.h"
38 #include "AliESDInputHandler.h"
39 #include "AliMCEvent.h"
43 ClassImp(AliAnalysisTaskJets)
45 ////////////////////////////////////////////////////////////////////////
47 AliAnalysisTaskJets::AliAnalysisTaskJets():
49 fConfigFile("ConfigJetAnalysis.C"),
60 // Default constructor
63 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
64 AliAnalysisTaskSE(name),
65 fConfigFile("ConfigJetAnalysis.C"),
76 // Default constructor
77 DefineOutput(1, TList::Class());
80 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
81 AliAnalysisTaskSE(name),
82 fConfigFile("ConfigJetAnalysis.C"),
93 // Default constructor
94 DefineOutput(1, TList::Class());
97 //----------------------------------------------------------------
98 void AliAnalysisTaskJets::UserCreateOutputObjects()
100 // Create the output container
102 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
104 // we already have a non standard output, need not to book a new file...
105 if (!IsStandardAOD())fNonStdFile = "";
107 if(fNonStdBranch.Length()==0)
109 // Connec default AOD to jet finder
110 // create a new branch for the background
111 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
112 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
113 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
114 AddAODBranch("AliAODJetEventBackground",&evBkg);
116 fJetFinder->ConnectAOD(AODEvent());
120 // Create a new branch for jets...
121 // how is this reset? -> cleared in the UserExec....
122 // Can this be handled by the framework?
123 // here we can also have the case that the brnaches are written to a separate file
125 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
126 tca->SetName(fNonStdBranch.Data());
127 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
128 if(!AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
129 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
130 evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
131 AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
134 if(fNonStdFile.Length()!=0){
136 // case that we have an AOD extension we need to fetch the jets from the extended output
137 // we identifay the extension aod event by looking for the branchname
138 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
139 TObjArray* extArray = aodH->GetExtensions();
141 TIter next(extArray);
142 while ((fAODExtension=(AliAODExtension*)next())){
143 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
145 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
146 fAODExtension->GetAOD()->Dump();
149 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
155 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
158 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
165 fListOfHistos = new TList();
166 fHistos = new AliJetHistos();
167 fHistos->AddHistosToList(fListOfHistos);
169 // Add the JetFinderInformation to the Outputlist
170 AliJetHeader *fH = fJetFinder->GetHeader();
172 // Compose a characteristic output name
173 // with the name of the output branch
175 if(fNonStdBranch.Length()==0) {
176 fH->SetName("AliJetHeader_jets");
179 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
182 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
183 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
186 //----------------------------------------------------------------
187 void AliAnalysisTaskJets::Init()
190 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
192 // Call configuration file
193 if (fConfigFile.Length()) {
194 gROOT->LoadMacro(fConfigFile);
195 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
197 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
198 fOpt = header->GetDetector();
200 // Initialise Jet Analysis
201 if(fOpt == 0) fJetFinder->Init();
202 else fJetFinder->InitTask(fChain); // V2
206 //----------------------------------------------------------------
207 void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
209 // Execute analysis for current event
211 // Fill control histos
212 TClonesArray* jarray = 0;
213 AliAODJetEventBackground* evBkg;
215 if(fNonStdBranch.Length()==0) {
216 jarray = AODEvent()->GetJets();
217 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
221 jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
222 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
223 jarray->Delete(); // this is our responsibility, clear before filling again
224 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
225 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
229 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
230 // AOD is input event..........................................V
231 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
233 // AOD is read from output ....................................V
234 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
239 if(fOpt==0) fJetFinder->ProcessEvent();
240 else fJetFinder->ProcessEvent2(); // V2
242 // Fill control histos
243 fHistos->FillHistos(jarray);
246 PostData(1, fListOfHistos);
251 //*************************************************************
253 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
255 // Terminate analysis
257 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
258 // if (fJetFinder) fJetFinder->FinishRun();