]>
Commit | Line | Data |
---|---|---|
c8b1a7db | 1 | #include "AliBaseESDTask.h" |
2 | #include "AliFMDEventInspector.h" | |
3 | #include "AliForwardCorrectionManager.h" | |
4 | #include "AliForwardUtil.h" | |
5 | #include "AliFMDCorrELossFit.h" | |
6 | #include <AliAnalysisManager.h> | |
7 | #include <AliAODHandler.h> | |
8 | #include <AliLog.h> | |
9 | #include <AliESDEvent.h> | |
10 | #include <TROOT.h> | |
11 | #include <TSystem.h> | |
0e5c1634 | 12 | #include <TInterpreter.h> |
c8b1a7db | 13 | #include <iostream> |
14 | #include <iomanip> | |
15 | ||
16 | //____________________________________________________________________ | |
17 | AliBaseESDTask::AliBaseESDTask() | |
18 | : AliAnalysisTaskSE(), | |
19 | fFirstEvent(true), | |
20 | fList(0), | |
21 | fResults(0), | |
22 | fNeededCorrections(0), | |
23 | fExtraCorrections(0), | |
24 | fCloneList(false), | |
25 | fCorrManager(0) | |
26 | {} | |
27 | ||
28 | //____________________________________________________________________ | |
29 | AliBaseESDTask::AliBaseESDTask(const char* name, const char* title, | |
30 | AliCorrectionManagerBase* manager) | |
31 | : AliAnalysisTaskSE(name), | |
32 | fFirstEvent(true), | |
33 | fList(0), | |
34 | fResults(0), | |
35 | fNeededCorrections(0), | |
36 | fExtraCorrections(0), | |
37 | fCloneList(false), | |
38 | fCorrManager(0) | |
39 | { | |
7c0b3e50 | 40 | // The line below doesn't actually do the job - when we're |
41 | // constructing, the derived class ins't set yet and this explicitly | |
42 | // points to an object of _this_ class. | |
43 | // SetTitle(title && title[0] != '\0' ? title : this->ClassName()); | |
44 | SetTitle(title && title[0] != '\0' ? title : ""); | |
c8b1a7db | 45 | fCorrManager = manager; |
77f97e3f CHC |
46 | // if (!manager) |
47 | // AliFatal("Must pass in a valid correction manager object!"); | |
c8b1a7db | 48 | fBranchNames = |
49 | "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.," | |
50 | "AliESDFMD.,SPDVertex.,PrimaryVertex."; | |
51 | ||
52 | DefineOutput(1, TList::Class()); | |
53 | DefineOutput(2, TList::Class()); | |
54 | } | |
55 | //____________________________________________________________________ | |
56 | Bool_t | |
57 | AliBaseESDTask::Connect(const char* sumFile, | |
58 | const char* resFile) | |
59 | { | |
60 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
61 | if (!mgr) { | |
62 | Error("AddTaskForwardMult", "No analysis manager to connect to."); | |
63 | return false; | |
64 | } | |
65 | ||
66 | // Add to the manager | |
67 | mgr->AddTask(this); | |
68 | ||
69 | // Create and connect output containers | |
70 | TString sumOut; | |
71 | TString resOut; | |
72 | if (sumFile && sumFile[0] != '\0') sumOut = sumFile; | |
73 | if (resFile && resFile[0] != '\0') resOut = resFile; | |
74 | else if (sumFile && sumFile[0] != '\0') resOut = sumFile; | |
0b7de667 | 75 | // If the string is null or 'default' connect to standard output file |
76 | if (sumOut.IsNull() || sumOut.EqualTo("default", TString::kIgnoreCase)) | |
77 | sumOut = AliAnalysisManager::GetCommonFileName(); | |
78 | // If the string is null or 'default' connect to standard output file | |
79 | if (resOut.IsNull() || resOut.EqualTo("default", TString::kIgnoreCase)) | |
80 | resOut = AliAnalysisManager::GetCommonFileName(); | |
81 | ||
82 | // Always connect input | |
c8b1a7db | 83 | mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer()); |
0b7de667 | 84 | |
85 | // Connect sum list unless the output 'none' is specified | |
86 | if (!sumOut.EqualTo("none", TString::kIgnoreCase)) { | |
87 | AliAnalysisDataContainer* sumCon = | |
88 | mgr->CreateContainer(Form("%sSums", GetName()), TList::Class(), | |
89 | AliAnalysisManager::kOutputContainer, sumOut); | |
90 | mgr->ConnectOutput(this, 1, sumCon); | |
91 | } | |
92 | // Connect the result list unless the output 'none' is specified | |
93 | if (!resOut.EqualTo("none", TString::kIgnoreCase)) { | |
94 | AliAnalysisDataContainer* resCon = | |
95 | mgr->CreateContainer(Form("%sResults", GetName()), TList::Class(), | |
96 | AliAnalysisManager::kParamContainer, resOut); | |
97 | mgr->ConnectOutput(this, 2, resCon); | |
98 | } | |
c8b1a7db | 99 | |
100 | return true; | |
101 | } | |
102 | ||
77f97e3f CHC |
103 | //____________________________________________________________________ |
104 | TAxis* | |
105 | AliBaseESDTask::DefaultEtaAxis() const | |
106 | { | |
107 | static TAxis* a = new TAxis(200, -4, 6); | |
108 | return a; | |
109 | } | |
110 | //____________________________________________________________________ | |
111 | TAxis* | |
112 | AliBaseESDTask::DefaultVertexAxis() const | |
113 | { | |
114 | static TAxis* a = AliForwardUtil::MakeFullIpZAxis(20); | |
115 | return a; | |
116 | } | |
c8b1a7db | 117 | //____________________________________________________________________ |
118 | void | |
119 | AliBaseESDTask::SetDebug(Int_t dbg) | |
120 | { | |
121 | // | |
122 | // Set debug level | |
123 | // | |
124 | // Parameters: | |
125 | // dbg debug level | |
126 | // | |
127 | GetEventInspector().SetDebug(dbg); | |
128 | } | |
129 | ||
130 | ||
131 | //____________________________________________________________________ | |
132 | Bool_t | |
133 | AliBaseESDTask::Configure(const char* macro) | |
134 | { | |
135 | // --- Configure the task ------------------------------------------ | |
136 | TString macroPath(gROOT->GetMacroPath()); | |
137 | if (!macroPath.Contains("$(ALICE_ROOT)/PWGLF/FORWARD/analysis2")) { | |
138 | macroPath.Append(":$(ALICE_ROOT)/PWGLF/FORWARD/analysis2"); | |
139 | gROOT->SetMacroPath(macroPath); | |
140 | } | |
141 | TString mac(macro); | |
7c0b3e50 | 142 | if (mac.EqualTo("-default-")) mac = DefaultConfig(); |
c8b1a7db | 143 | const char* config = gSystem->Which(gROOT->GetMacroPath(), mac.Data()); |
144 | if (!config) { | |
145 | AliWarningF("%s not found in %s", mac.Data(), gROOT->GetMacroPath()); | |
146 | return false; | |
147 | } | |
7c0b3e50 | 148 | if (fTitle.IsNull()) fTitle = this->ClassName(); |
c8b1a7db | 149 | |
150 | AliInfoF("Loading configuration of '%s' from %s", ClassName(), config); | |
151 | gROOT->Macro(Form("%s((%s*)%p)", config, GetTitle(), this)); | |
0e5c1634 | 152 | |
153 | Info("Configure", "Unloading configuration script"); | |
154 | gInterpreter->UnloadFile(config); | |
155 | ||
c8b1a7db | 156 | delete config; |
157 | ||
158 | return true; | |
159 | } | |
0b7de667 | 160 | |
161 | //____________________________________________________________________ | |
162 | void | |
163 | AliBaseESDTask::LocalInit() | |
164 | { | |
165 | fFirstEvent = true; | |
166 | Setup(); | |
167 | } | |
168 | ||
c8b1a7db | 169 | //____________________________________________________________________ |
170 | void | |
171 | AliBaseESDTask::UserCreateOutputObjects() | |
172 | { | |
173 | // | |
174 | // Create output objects | |
175 | // | |
176 | // | |
177 | DGUARD(fDebug,1,"Create user ouput"); | |
178 | fList = new TList; | |
179 | fList->SetName(Form("%sSums", GetName())); | |
180 | fList->SetOwner(); | |
181 | ||
182 | AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager(); | |
183 | AliAODHandler* ah = | |
184 | dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler()); | |
185 | //if (!ah) AliFatal("No AOD output handler set in analysis manager"); | |
186 | if (ah) CreateBranches(ah); | |
187 | ||
188 | GetEventInspector().CreateOutputObjects(fList); | |
189 | ||
190 | if (!Book()) AliFatalF("Failed to book output objects for %s", GetName()); | |
0b7de667 | 191 | |
192 | // gSystem->Exec("root-config --version --prefix"); | |
c8b1a7db | 193 | PostData(1, fList); |
194 | } | |
195 | ||
196 | //____________________________________________________________________ | |
197 | void | |
198 | AliBaseESDTask::UserExec(Option_t*) | |
199 | { | |
200 | // Call pre-event setup | |
201 | PreEvent(); | |
202 | ||
77f97e3f CHC |
203 | // Read in selected branches |
204 | LoadBranches(); | |
205 | ||
c8b1a7db | 206 | // Get the input data |
207 | AliESDEvent* esd = GetESDEvent(); | |
208 | if (!esd) return; | |
209 | ||
210 | // Call the user code with our event passed in | |
211 | Event(*esd); | |
212 | // if (!Event(*esd)) { | |
213 | // AliWarningF("Failed to process the event for %s", GetName()); | |
214 | // return; | |
215 | // } | |
216 | ||
217 | // Post data | |
218 | PostData(1, fList); | |
219 | ||
220 | // Call post-event processing | |
221 | PostEvent(); | |
222 | } | |
223 | ||
224 | //____________________________________________________________________ | |
225 | void | |
226 | AliBaseESDTask::Terminate(Option_t*) | |
227 | { | |
228 | TList* list = dynamic_cast<TList*>(GetOutputData(1)); | |
229 | if (!list) { | |
230 | AliError(Form("No output list defined (%p)", GetOutputData(1))); | |
231 | if (GetOutputData(1)) GetOutputData(1)->Print(); | |
232 | return; | |
233 | } | |
234 | ||
235 | // Assign to our internal variable for use by sub-classes | |
236 | fList = list; | |
237 | ||
238 | // Create our output container | |
239 | TString resName(Form("%sResults", GetName())); | |
240 | if (fCloneList) | |
241 | fResults = static_cast<TList*>(fList->Clone(resName)); | |
242 | else { | |
243 | fResults = new TList; | |
244 | fResults->SetName(resName); | |
245 | } | |
246 | fResults->SetOwner(); | |
247 | ||
248 | // Now call user defined routines | |
249 | if (!Finalize()) { | |
250 | AliErrorF("Failed to finalize this task (%s)", GetName()); | |
251 | return; | |
252 | } | |
253 | ||
254 | PostData(2, fResults); | |
255 | } | |
256 | ||
257 | //____________________________________________________________________ | |
258 | Bool_t | |
259 | AliBaseESDTask::PreData(const TAxis&, const TAxis&) | |
260 | { | |
261 | return true; | |
262 | } | |
263 | ||
264 | ||
265 | //____________________________________________________________________ | |
266 | Bool_t | |
267 | AliBaseESDTask::CheckCorrections(UInt_t what) const | |
268 | { | |
269 | // | |
270 | // Check if all needed corrections are there and accounted for. If not, | |
271 | // do a Fatal exit | |
272 | // | |
273 | // Parameters: | |
274 | // what Which corrections is needed | |
275 | // | |
276 | // Return: | |
277 | // true if all present, false otherwise | |
278 | // | |
279 | DGUARD(fDebug,1,"Checking corrections 0x%x", what); | |
77f97e3f | 280 | if (what == 0) return true; |
c8b1a7db | 281 | |
282 | AliCorrectionManagerBase* cm = GetManager(); | |
77f97e3f CHC |
283 | if (!cm) { |
284 | AliErrorF("Check corrections=0x%x not null, " | |
285 | "but no correction manager defined!", | |
286 | what); | |
287 | return false; | |
288 | } | |
c8b1a7db | 289 | Bool_t ret = cm->CheckCorrections(what); |
290 | return ret; | |
291 | } | |
292 | //____________________________________________________________________ | |
293 | Bool_t | |
294 | AliBaseESDTask::ReadCorrections(const TAxis*& pe, | |
295 | const TAxis*& pv, | |
296 | Bool_t mc, | |
297 | Bool_t sat) | |
298 | { | |
299 | // | |
300 | // Read corrections | |
301 | // | |
302 | // | |
303 | UInt_t what = fNeededCorrections|fExtraCorrections; | |
77f97e3f | 304 | |
c8b1a7db | 305 | DGUARD(fDebug,1,"Read corrections 0x%x", what); |
77f97e3f | 306 | |
c8b1a7db | 307 | AliCorrectionManagerBase* cm = GetManager(); |
77f97e3f CHC |
308 | if (!cm && fNeededCorrections) { |
309 | AliErrorF("Needed/extra corrections=0x%x/0x%x not null, " | |
310 | "but no correction manager defined!", | |
311 | fNeededCorrections, fExtraCorrections); | |
312 | return false; | |
313 | } | |
314 | if (!cm || !what) { | |
315 | // In case we have no needed corrections, we can return here | |
316 | if (!pe) pe = DefaultEtaAxis(); | |
317 | if (!pv) pv = DefaultVertexAxis(); | |
318 | return true; | |
319 | } | |
c8b1a7db | 320 | cm->EnableCorrections(what); |
321 | if (!cm->InitCorrections(GetEventInspector().GetRunNumber(), | |
322 | GetEventInspector().GetCollisionSystem(), | |
323 | GetEventInspector().GetEnergy(), | |
324 | GetEventInspector().GetField(), | |
325 | mc, | |
326 | sat, | |
327 | false)) { | |
328 | AliWarning("Failed to read in some corrections, making task zombie"); | |
329 | return false; | |
330 | } | |
331 | if (!CheckCorrections(fNeededCorrections)) return false; | |
332 | ||
333 | // Sett our persistency pointer | |
334 | // fCorrManager = &fcm; | |
335 | ||
336 | // Get the eta axis from the secondary maps - if read in | |
337 | if (!pe) { | |
338 | pe = cm->GetEtaAxis(); | |
339 | if (!pe) pe = DefaultEtaAxis(); | |
c8b1a7db | 340 | } |
341 | // Get the vertex axis from the secondary maps - if read in | |
342 | if (!pv) { | |
343 | pv = cm->GetVertexAxis(); | |
344 | if (!pv) pv = DefaultVertexAxis(); | |
c8b1a7db | 345 | } |
346 | ||
347 | return true; | |
348 | } | |
349 | //____________________________________________________________________ | |
350 | AliESDEvent* | |
351 | AliBaseESDTask::GetESDEvent() | |
352 | { | |
353 | // | |
354 | // Get the ESD event. IF this is the first event, initialise | |
355 | // | |
356 | DGUARD(fDebug,1,"Get the ESD event"); | |
357 | ||
358 | // If we're marked as a zombie, do nothing and return a null | |
359 | if (IsZombie()) return 0; | |
360 | ||
361 | // Try to get the ESD event | |
362 | AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent()); | |
363 | if (!esd) { | |
364 | AliWarning("No ESD event found for input event"); | |
365 | return 0; | |
366 | } | |
367 | ||
368 | // --- Load the data ----------------------------------------------- | |
369 | LoadBranches(); | |
370 | ||
371 | if (!fFirstEvent || !esd->GetESDRun()) return esd; | |
372 | ||
373 | // On the first event, initialize the parameters | |
374 | GetEventInspector().SetMC(MCEvent()); | |
375 | GetEventInspector().ReadRunDetails(esd); | |
376 | ||
377 | AliInfoF("Initializing with parameters from the ESD:\n" | |
378 | " AliESDEvent::GetBeamEnergy() ->%f\n" | |
379 | " AliESDEvent::GetBeamType() ->%s\n" | |
380 | " AliESDEvent::GetCurrentL3() ->%f\n" | |
381 | " AliESDEvent::GetMagneticField()->%f\n" | |
382 | " AliESDEvent::GetRunNumber() ->%d", | |
383 | esd->GetBeamEnergy(), | |
384 | esd->GetBeamType(), | |
385 | esd->GetCurrentL3(), | |
386 | esd->GetMagneticField(), | |
387 | esd->GetRunNumber()); | |
0ccdab7b | 388 | |
389 | PreCorrections(esd); | |
390 | ||
c8b1a7db | 391 | fFirstEvent = false; |
392 | ||
393 | const TAxis* pe = 0; | |
394 | const TAxis* pv = 0; | |
395 | Bool_t mc = IsMC(); | |
396 | Bool_t sat = false; | |
397 | Bool_t ret = ReadCorrections(pe, pv, mc, sat); | |
398 | if (!ret) { | |
399 | AliError("Failed to read corrections, making this a zombie"); | |
400 | SetZombie(true); | |
401 | return 0; | |
402 | } | |
77f97e3f CHC |
403 | Printf("Vertex axis: %p Eta axis: %p", pv, pe); |
404 | if (!pv) AliFatal("No vertex axis defined"); | |
405 | if (!pe) AliFatal("No eta axis defined"); | |
c8b1a7db | 406 | |
407 | // Initialize the event inspector | |
408 | GetEventInspector().SetupForData(*pv); | |
409 | ||
410 | // Initialize the remaining stuff | |
411 | if (!PreData(*pv, *pe)) { | |
412 | AliError("Failed to initialize sub-algorithms, making this a zombie"); | |
413 | SetZombie(true); | |
414 | return 0; | |
415 | } | |
416 | ||
417 | this->Print("R"); | |
418 | ||
419 | return esd; | |
420 | } | |
421 | ||
422 | //____________________________________________________________________ | |
423 | void | |
424 | AliBaseESDTask::MarkEventForStore() const | |
425 | { | |
426 | // Make sure the AOD tree is filled | |
427 | DGUARD(fDebug,3,"Mark AOD event for storage"); | |
428 | AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager(); | |
429 | AliAODHandler* ah = | |
430 | dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler()); | |
431 | if (ah) ah->SetFillAOD(kTRUE); | |
432 | } | |
433 | #define PF(N,V,...) \ | |
434 | AliForwardUtil::PrintField(N,V, ## __VA_ARGS__) | |
435 | #define PFB(N,FLAG) \ | |
436 | do { \ | |
437 | AliForwardUtil::PrintName(N); \ | |
438 | std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \ | |
439 | } while(false) | |
440 | #define PFV(N,VALUE) \ | |
441 | do { \ | |
442 | AliForwardUtil::PrintName(N); \ | |
443 | std::cout << (VALUE) << std::endl; } while(false) | |
444 | ||
445 | //____________________________________________________________________ | |
446 | void | |
447 | AliBaseESDTask::Print(Option_t* option) const | |
448 | { | |
449 | // | |
450 | // Print information | |
451 | // | |
452 | // Parameters: | |
453 | // option Not used | |
454 | // | |
455 | std::cout << std::setfill('=') << std::setw(75) << "=" | |
456 | << std::setfill(' ') << std::endl; | |
457 | AliForwardUtil::PrintTask(*this); | |
458 | gROOT->IncreaseDirLevel(); | |
459 | PF("Off-line trigger mask", "0x%0x", fOfflineTriggerMask); | |
77f97e3f CHC |
460 | if (GetManager()) GetManager()->Print(option); |
461 | else PF("No correction manager",""); | |
c8b1a7db | 462 | |
463 | GetEventInspector().Print(option); | |
464 | gROOT->DecreaseDirLevel(); | |
465 | } | |
77f97e3f CHC |
466 | // |
467 | // EOF | |
468 | // |