]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | #include <Riostream.h> | |
18 | #include <TROOT.h> | |
19 | #include <TSystem.h> | |
20 | #include <TInterpreter.h> | |
21 | #include <TChain.h> | |
22 | #include <TFile.h> | |
23 | #include <TList.h> | |
24 | #include <TH1.h> | |
25 | ||
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" | |
34 | #include "AliESD.h" | |
35 | #include "AliAODEvent.h" | |
36 | #include "AliAODJetEventBackground.h" | |
37 | #include "AliAODHandler.h" | |
38 | #include "AliAODExtension.h" | |
39 | #include "AliMCEventHandler.h" | |
40 | #include "AliESDInputHandler.h" | |
41 | #include "AliMCEvent.h" | |
42 | #include "AliStack.h" | |
43 | ||
44 | ||
45 | ClassImp(AliAnalysisTaskJets) | |
46 | ||
47 | //////////////////////////////////////////////////////////////////////// | |
48 | ||
49 | AliAnalysisTaskJets::AliAnalysisTaskJets(): | |
50 | AliAnalysisTaskSE(), | |
51 | fConfigFile("ConfigJetAnalysis.C"), | |
52 | fNonStdBranch(""), | |
53 | fNonStdFile(""), | |
54 | fJetFinder(0x0), | |
55 | fHistos(0x0), | |
56 | fAODExtension(0x0), | |
57 | fListOfHistos(0x0), | |
58 | fChain(0x0), | |
59 | fOpt(0), | |
60 | fReadAODFromOutput(0), | |
61 | fUseAODBackground(kFALSE), | |
62 | fFilterPt(0.) | |
63 | { | |
64 | // Default constructor | |
65 | } | |
66 | ||
67 | AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name): | |
68 | AliAnalysisTaskSE(name), | |
69 | fConfigFile("ConfigJetAnalysis.C"), | |
70 | fNonStdBranch(""), | |
71 | fNonStdFile(""), | |
72 | fJetFinder(0x0), | |
73 | fHistos(0x0), | |
74 | fAODExtension(0x0), | |
75 | fListOfHistos(0x0), | |
76 | fChain(0x0), | |
77 | fOpt(0), | |
78 | fReadAODFromOutput(0), | |
79 | fUseAODBackground(kFALSE), | |
80 | fFilterPt(0.) | |
81 | { | |
82 | // Default constructor | |
83 | DefineOutput(1, TList::Class()); | |
84 | } | |
85 | ||
86 | AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain): | |
87 | AliAnalysisTaskSE(name), | |
88 | fConfigFile("ConfigJetAnalysis.C"), | |
89 | fNonStdBranch(""), | |
90 | fNonStdFile(""), | |
91 | fJetFinder(0x0), | |
92 | fHistos(0x0), | |
93 | fAODExtension(0x0), | |
94 | fListOfHistos(0x0), | |
95 | fChain(chain), | |
96 | fOpt(0), | |
97 | fReadAODFromOutput(0), | |
98 | fUseAODBackground(kFALSE), | |
99 | fFilterPt(0.) | |
100 | { | |
101 | // Default constructor | |
102 | DefineOutput(1, TList::Class()); | |
103 | } | |
104 | ||
105 | //---------------------------------------------------------------- | |
106 | void AliAnalysisTaskJets::UserCreateOutputObjects() | |
107 | { | |
108 | // Create the output container | |
109 | // | |
110 | if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n"); | |
111 | ||
112 | AliJetHeader *fH = fJetFinder->GetHeader(); | |
113 | ||
114 | if(fNonStdBranch.Length()==0) | |
115 | { | |
116 | // Connec default AOD to jet finder | |
117 | // create a new branch for the background | |
118 | ||
119 | if(fUseAODBackground){ | |
120 | if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){ | |
121 | AliAODJetEventBackground* evBkg = new AliAODJetEventBackground(); | |
122 | evBkg->SetName(AliAODJetEventBackground::StdBranchName()); | |
123 | AddAODBranch("AliAODJetEventBackground",&evBkg); | |
124 | } | |
125 | } | |
126 | fJetFinder->ConnectAOD(AODEvent()); | |
127 | } | |
128 | else | |
129 | { | |
130 | // Create a new branch for jets... | |
131 | // how is this reset? -> cleared in the UserExec.... | |
132 | // Can this be handled by the framework? | |
133 | // here we can also have the case that the brnaches are written to a separate file | |
134 | ||
135 | TClonesArray *tca = new TClonesArray("AliAODJet", 0); | |
136 | tca->SetName(fNonStdBranch.Data()); | |
137 | AddAODBranch("TClonesArray",&tca,fNonStdFile.Data()); | |
138 | if(fUseAODBackground){ | |
139 | if(!AODEvent() || !AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){ | |
140 | AliAODJetEventBackground* evBkg = new AliAODJetEventBackground(); | |
141 | evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())); | |
142 | AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data()); | |
143 | } | |
144 | } | |
145 | if(fNonStdFile.Length()!=0){ | |
146 | // | |
147 | // case that we have an AOD extension we need to fetch the jets from the extended output | |
148 | // we identifay the extension aod event by looking for the branchname | |
149 | AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()); | |
150 | fAODExtension = 0; | |
151 | if(aodH){ | |
152 | TObjArray* extArray = aodH->GetExtensions(); | |
153 | if (extArray) { | |
154 | TIter next(extArray); | |
155 | while ((fAODExtension=(AliAODExtension*)next())){ | |
156 | TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()); | |
157 | if(fDebug>10){ | |
158 | Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__); | |
159 | fAODExtension->GetAOD()->Dump(); | |
160 | } | |
161 | if(obj){ | |
162 | if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data()); | |
163 | break; | |
164 | } | |
165 | fAODExtension = 0; | |
166 | } | |
167 | } | |
168 | } | |
169 | if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data()); | |
170 | } | |
171 | else{ | |
172 | if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data()); | |
173 | fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data()); | |
174 | } | |
175 | } | |
176 | ||
177 | // do not add the histograms in the directory | |
178 | // all handled by the list | |
179 | Bool_t oldStatus = TH1::AddDirectoryStatus(); | |
180 | TH1::AddDirectory(kFALSE); | |
181 | ||
182 | ||
183 | // Histograms | |
184 | fListOfHistos = new TList(); | |
185 | fListOfHistos->SetOwner(); | |
186 | fHistos = new AliJetHistos(); | |
187 | fHistos->AddHistosToList(fListOfHistos); | |
188 | ||
189 | // Add the JetFinderInformation to the Outputlist | |
190 | ||
191 | // Compose a characteristic output name | |
192 | // with the name of the output branch | |
193 | if(fH) { | |
194 | if(fNonStdBranch.Length()==0) { | |
195 | fH->SetName("AliJetHeader_jets"); | |
196 | } | |
197 | else { | |
198 | fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data())); | |
199 | } | |
200 | } | |
201 | ||
202 | TH1::AddDirectory(oldStatus); | |
203 | ||
204 | ||
205 | if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH); | |
206 | else fAODExtension->GetTree()->GetUserInfo()->Add(fH); | |
207 | ||
208 | // post | |
209 | PostData(1, fListOfHistos); | |
210 | ||
211 | } | |
212 | ||
213 | //---------------------------------------------------------------- | |
214 | void AliAnalysisTaskJets::Init() | |
215 | { | |
216 | // Initialization | |
217 | if (fDebug > 1) printf("AnalysisTaskJets::Init() \n"); | |
218 | ||
219 | // Call configuration file | |
220 | if (fConfigFile.Length()) { | |
221 | gROOT->LoadMacro(fConfigFile); | |
222 | fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()"); | |
223 | } | |
224 | AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader(); | |
225 | fOpt = header->GetDetector(); | |
226 | ||
227 | // AODB path for Jetan Analysis... if not alread defined, use the standard one | |
228 | if ((!(((AliJetReader*) fJetFinder->GetReader())->GetJetanOADBPath()).Length())) { | |
229 | ((AliJetReader*) fJetFinder->GetReader())->SetJetanOADBPath(AliAnalysisManager::GetOADBPath()); | |
230 | } | |
231 | else Info( "Init"," OADBPath for Jetan was already defined (config file?) as %s",(char*)((fJetFinder->GetReader()->GetJetanOADBPath()).Data())); | |
232 | ||
233 | // Initialise Jet Analysis | |
234 | if(fOpt == 0) fJetFinder->Init(); | |
235 | else fJetFinder->InitTask(fChain); // V2 | |
236 | } | |
237 | ||
238 | ||
239 | //---------------------------------------------------------------- | |
240 | void AliAnalysisTaskJets::UserExec(Option_t */*option*/) | |
241 | { | |
242 | // Execute analysis for current event | |
243 | // | |
244 | // Fill control histos | |
245 | TClonesArray* jarray = 0; | |
246 | AliAODJetEventBackground* evBkg = 0; | |
247 | ||
248 | // only need this once | |
249 | static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()); | |
250 | ||
251 | if(fNonStdBranch.Length()==0) { | |
252 | jarray = AODEvent()->GetJets(); | |
253 | if(fUseAODBackground){ | |
254 | evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())); | |
255 | evBkg->Reset(); | |
256 | } | |
257 | } | |
258 | else { | |
259 | if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data())); | |
260 | if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data())); | |
261 | if(jarray)jarray->Delete(); // this is our responsibility, clear before filling again | |
262 | if(fUseAODBackground){ | |
263 | if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))); | |
264 | if(!evBkg) evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))); | |
265 | if(evBkg)evBkg->Reset(); | |
266 | } | |
267 | } | |
268 | ||
269 | if (dynamic_cast<AliAODEvent*>(InputEvent()) != 0 && !fReadAODFromOutput) { | |
270 | // AOD is input event..........................................V | |
271 | fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent()); | |
272 | } else { | |
273 | // AOD is read from output ....................................V | |
274 | fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent()); | |
275 | } | |
276 | ||
277 | ||
278 | ||
279 | if(fOpt==0) fJetFinder->ProcessEvent(); | |
280 | else fJetFinder->ProcessEvent2(); // V2 | |
281 | ||
282 | // Fill control histos | |
283 | if(jarray)fHistos->FillHistos(jarray); | |
284 | ||
285 | ||
286 | if(jarray&&aodH&&fFilterPt>0){ | |
287 | if(jarray->GetEntries()>0){ | |
288 | AliAODJet *jet = (AliAODJet*)jarray->At(0); | |
289 | if(jet->Pt()>fFilterPt){ | |
290 | // aodH->EnableFillAODforEvent(); | |
291 | aodH->SetFillAOD(kTRUE); | |
292 | } | |
293 | } | |
294 | } | |
295 | ||
296 | // Post the data | |
297 | PostData(1, fListOfHistos); | |
298 | return; | |
299 | } | |
300 | ||
301 | ||
302 | //************************************************************* | |
303 | ||
304 | void AliAnalysisTaskJets::Terminate(Option_t */*option*/) | |
305 | { | |
306 | // Terminate analysis | |
307 | // | |
308 | if (fDebug > 1) printf("AnalysisJets: Terminate() \n"); | |
309 | // if (fJetFinder) fJetFinder->FinishRun(); | |
310 | } | |
311 |