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