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"),
59 // Default constructor
62 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
63 AliAnalysisTaskSE(name),
64 fConfigFile("ConfigJetAnalysis.C"),
75 // Default constructor
76 DefineOutput(1, TList::Class());
79 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
80 AliAnalysisTaskSE(name),
81 fConfigFile("ConfigJetAnalysis.C"),
92 // Default constructor
93 DefineOutput(1, TList::Class());
96 //----------------------------------------------------------------
97 void AliAnalysisTaskJets::UserCreateOutputObjects()
99 // Create the output container
101 if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
103 // we already have a non standard output, need not to book a new file...
104 if (!IsStandardAOD())fNonStdFile = "";
106 if(fNonStdBranch.Length()==0)
108 // Connec default AOD to jet finder
109 // create a new branch for the background
110 if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
111 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
112 evBkg->SetName(AliAODJetEventBackground::StdBranchName());
113 AddAODBranch("AliAODJetEventBackground",&evBkg);
115 fJetFinder->ConnectAOD(AODEvent());
119 // Create a new branch for jets...
120 // how is this reset? -> cleared in the UserExec....
121 // Can this be handled by the framework?
122 // here we can also have the case that the brnaches are written to a separate file
124 TClonesArray *tca = new TClonesArray("AliAODJet", 0);
125 tca->SetName(fNonStdBranch.Data());
126 AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
127 if(!AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
128 AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
129 evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
130 AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
133 if(fNonStdFile.Length()!=0){
135 // case that we have an AOD extension we need to fetch the jets from the extended output
136 // we identifay the extension aod event by looking for the branchname
137 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
138 TObjArray* extArray = aodH->GetExtensions();
140 TIter next(extArray);
141 while ((fAODExtension=(AliAODExtension*)next())){
142 TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
144 Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
145 fAODExtension->GetAOD()->Dump();
148 if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
154 if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data());
157 fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data());
164 fListOfHistos = new TList();
165 fHistos = new AliJetHistos();
166 fHistos->AddHistosToList(fListOfHistos);
168 // Add the JetFinderInformation to the Outputlist
169 AliJetHeader *fH = fJetFinder->GetHeader();
171 // Compose a characteristic output name
172 // with the name of the output branch
174 if(fNonStdBranch.Length()==0) {
175 fH->SetName("AliJetHeader_jets");
178 fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
181 if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
182 else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
185 //----------------------------------------------------------------
186 void AliAnalysisTaskJets::Init()
189 if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
191 // Call configuration file
192 if (fConfigFile.Length()) {
193 gROOT->LoadMacro(fConfigFile);
194 fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
196 AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
197 fOpt = header->GetDetector();
199 // Initialise Jet Analysis
200 if(fOpt == 0) fJetFinder->Init();
201 else fJetFinder->InitTask(fChain); // V2
205 //----------------------------------------------------------------
206 void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
208 // Execute analysis for current event
210 // Fill control histos
211 TClonesArray* jarray = 0;
212 AliAODJetEventBackground* evBkg;
214 if(fNonStdBranch.Length()==0) {
215 jarray = AODEvent()->GetJets();
216 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
220 jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
221 if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
222 jarray->Delete(); // this is our responsibility, clear before filling again
223 evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
224 if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
228 if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) {
229 // AOD is input event..........................................V
230 fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
232 // AOD is read from output ....................................V
233 fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
238 if(fOpt==0) fJetFinder->ProcessEvent();
239 else fJetFinder->ProcessEvent2(); // V2
241 // Fill control histos
242 fHistos->FillHistos(jarray);
245 PostData(1, fListOfHistos);
250 //*************************************************************
252 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
254 // Terminate analysis
256 if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
257 // if (fJetFinder) fJetFinder->FinishRun();