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>
9 #include <AliESDEvent.h>
12 #include <TInterpreter.h>
16 //____________________________________________________________________
17 AliBaseESDTask::AliBaseESDTask()
18 : AliAnalysisTaskSE(),
22 fNeededCorrections(0),
28 //____________________________________________________________________
29 AliBaseESDTask::AliBaseESDTask(const char* name, const char* title,
30 AliCorrectionManagerBase* manager)
31 : AliAnalysisTaskSE(name),
35 fNeededCorrections(0),
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 : "");
45 fCorrManager = manager;
47 // AliFatal("Must pass in a valid correction manager object!");
49 "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
50 "AliESDFMD.,SPDVertex.,PrimaryVertex.";
52 DefineOutput(1, TList::Class());
53 DefineOutput(2, TList::Class());
55 //____________________________________________________________________
57 AliBaseESDTask::Connect(const char* sumFile,
61 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
63 Error("AddTaskForwardMult", "No analysis manager to connect to.");
70 // Create and connect output containers
73 if (sumFile && sumFile[0] != '\0') sumOut = sumFile;
74 if (resFile && resFile[0] != '\0') resOut = resFile;
75 else if (sumFile && sumFile[0] != '\0') resOut = sumFile;
76 // If the string is null or 'default' connect to standard output file
77 if (sumOut.IsNull() || sumOut.EqualTo("default", TString::kIgnoreCase))
78 sumOut = AliAnalysisManager::GetCommonFileName();
79 // If the string is null or 'default' connect to standard output file
80 if (resOut.IsNull() || resOut.EqualTo("default", TString::kIgnoreCase))
81 resOut = AliAnalysisManager::GetCommonFileName();
83 // Always connect input
84 mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer());
86 // Connect sum list unless the output 'none' is specified
87 if (!sumOut.EqualTo("none", TString::kIgnoreCase)) {
88 TString sumName(Form("%s%s", old ? "Forward" : GetName(), old ? "" : "Sums"));
89 AliAnalysisDataContainer* sumCon =
90 mgr->CreateContainer(sumName, TList::Class(),
91 AliAnalysisManager::kOutputContainer, sumOut);
92 mgr->ConnectOutput(this, 1, sumCon);
94 // Connect the result list unless the output 'none' is specified
95 if (!resOut.EqualTo("none", TString::kIgnoreCase)) {
96 TString resName(Form("%sResults", GetName()));
97 AliAnalysisDataContainer* resCon =
98 mgr->CreateContainer(resName, TList::Class(),
99 AliAnalysisManager::kParamContainer, resOut);
100 mgr->ConnectOutput(this, 2, resCon);
106 //____________________________________________________________________
108 AliBaseESDTask::DefaultEtaAxis() const
110 static TAxis* a = new TAxis(200, -4, 6);
113 //____________________________________________________________________
115 AliBaseESDTask::DefaultVertexAxis() const
117 static TAxis* a = AliForwardUtil::MakeFullIpZAxis(20);
120 //____________________________________________________________________
122 AliBaseESDTask::SetDebug(Int_t dbg)
130 GetEventInspector().SetDebug(dbg);
134 //____________________________________________________________________
136 AliBaseESDTask::Configure(const char* macro)
138 // --- Configure the task ------------------------------------------
139 TString macroPath(gROOT->GetMacroPath());
140 if (!macroPath.Contains("$(ALICE_ROOT)/PWGLF/FORWARD/analysis2")) {
141 macroPath.Append(":$(ALICE_ROOT)/PWGLF/FORWARD/analysis2");
142 gROOT->SetMacroPath(macroPath);
145 if (mac.EqualTo("-default-")) mac = DefaultConfig();
146 const char* config = gSystem->Which(gROOT->GetMacroPath(), mac.Data());
148 AliWarningF("%s not found in %s", mac.Data(), gROOT->GetMacroPath());
151 if (fTitle.IsNull()) fTitle = this->ClassName();
153 AliInfoF("Loading configuration of '%s' from %s", ClassName(), config);
154 gROOT->Macro(Form("%s((%s*)%p)", config, GetTitle(), this));
156 Info("Configure", "Unloading configuration script");
157 gInterpreter->UnloadFile(config);
164 //____________________________________________________________________
166 AliBaseESDTask::LocalInit()
169 DGUARD(fDebug,1,"Doing local initialization");
173 //____________________________________________________________________
175 AliBaseESDTask::UserCreateOutputObjects()
178 // Create output objects
181 DGUARD(fDebug,1,"Create user ouput");
183 fList->SetName(Form("%sSums", GetName()));
186 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
188 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
189 //if (!ah) AliFatal("No AOD output handler set in analysis manager");
190 if (ah) CreateBranches(ah);
192 GetEventInspector().CreateOutputObjects(fList);
194 if (!Book()) AliFatalF("Failed to book output objects for %s", GetName());
196 // gSystem->Exec("root-config --version --prefix");
200 //____________________________________________________________________
202 AliBaseESDTask::UserExec(Option_t*)
204 // Call pre-event setup
207 // Read in selected branches
210 // Get the input data
211 AliESDEvent* esd = GetESDEvent();
214 // Call the user code with our event passed in
216 // if (!Event(*esd)) {
217 // AliWarningF("Failed to process the event for %s", GetName());
224 // Call post-event processing
228 //____________________________________________________________________
230 AliBaseESDTask::Terminate(Option_t*)
232 TList* list = dynamic_cast<TList*>(GetOutputData(1));
234 AliError(Form("No output list defined (%p)", GetOutputData(1)));
235 if (GetOutputData(1)) GetOutputData(1)->Print();
239 // Assign to our internal variable for use by sub-classes
242 // Create our output container
243 TString resName(Form("%sResults", GetName()));
245 fResults = static_cast<TList*>(fList->Clone(resName));
247 fResults = new TList;
248 fResults->SetName(resName);
250 fResults->SetOwner();
252 // Now call user defined routines
254 AliErrorF("Failed to finalize this task (%s)", GetName());
258 PostData(2, fResults);
261 //____________________________________________________________________
263 AliBaseESDTask::PreData(const TAxis&, const TAxis&)
269 //____________________________________________________________________
271 AliBaseESDTask::CheckCorrections(UInt_t what) const
274 // Check if all needed corrections are there and accounted for. If not,
278 // what Which corrections is needed
281 // true if all present, false otherwise
283 DGUARD(fDebug,1,"Checking corrections 0x%x", what);
284 if (what == 0) return true;
286 AliCorrectionManagerBase* cm = GetManager();
288 AliErrorF("Check corrections=0x%x not null, "
289 "but no correction manager defined!",
293 Bool_t ret = cm->CheckCorrections(what);
296 //____________________________________________________________________
298 AliBaseESDTask::ReadCorrections(const TAxis*& pe,
307 UInt_t what = fNeededCorrections|fExtraCorrections;
309 DGUARD(fDebug,1,"Read corrections 0x%x", what);
311 AliCorrectionManagerBase* cm = GetManager();
312 if (!cm && fNeededCorrections) {
313 AliErrorF("Needed/extra corrections=0x%x/0x%x not null, "
314 "but no correction manager defined!",
315 fNeededCorrections, fExtraCorrections);
319 // In case we have no needed corrections, we can return here
320 if (!pe) pe = DefaultEtaAxis();
321 if (!pv) pv = DefaultVertexAxis();
324 cm->EnableCorrections(what);
325 if (!cm->InitCorrections(GetEventInspector().GetRunNumber(),
326 GetEventInspector().GetCollisionSystem(),
327 GetEventInspector().GetEnergy(),
328 GetEventInspector().GetField(),
332 AliWarning("Failed to read in some corrections, making task zombie");
335 if (!CheckCorrections(fNeededCorrections)) return false;
337 // Sett our persistency pointer
338 // fCorrManager = &fcm;
340 // Get the eta axis from the secondary maps - if read in
342 pe = cm->GetEtaAxis();
343 if (!pe) pe = DefaultEtaAxis();
345 // Get the vertex axis from the secondary maps - if read in
347 pv = cm->GetVertexAxis();
348 if (!pv) pv = DefaultVertexAxis();
353 //____________________________________________________________________
355 AliBaseESDTask::GetESDEvent()
358 // Get the ESD event. IF this is the first event, initialise
360 DGUARD(fDebug,1,"Get the ESD event");
362 // If we're marked as a zombie, do nothing and return a null
363 if (IsZombie()) return 0;
365 // Try to get the ESD event
366 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
368 AliWarning("No ESD event found for input event");
372 // --- Load the data -----------------------------------------------
375 if (!fFirstEvent || !esd->GetESDRun()) return esd;
377 // On the first event, initialize the parameters
378 GetEventInspector().SetMC(MCEvent());
379 GetEventInspector().ReadRunDetails(esd);
381 AliInfoF("Initializing with parameters from the ESD:\n"
382 " AliESDEvent::GetBeamEnergy() ->%f\n"
383 " AliESDEvent::GetBeamType() ->%s\n"
384 " AliESDEvent::GetCurrentL3() ->%f\n"
385 " AliESDEvent::GetMagneticField()->%f\n"
386 " AliESDEvent::GetRunNumber() ->%d",
387 esd->GetBeamEnergy(),
390 esd->GetMagneticField(),
391 esd->GetRunNumber());
401 Bool_t ret = ReadCorrections(pe, pv, mc, sat);
403 AliError("Failed to read corrections, making this a zombie");
407 Printf("Vertex axis: %p Eta axis: %p", pv, pe);
408 if (!pv) AliFatal("No vertex axis defined");
409 if (!pe) AliFatal("No eta axis defined");
411 // Initialize the event inspector
412 GetEventInspector().SetupForData(*pv);
414 // Initialize the remaining stuff
415 if (!PreData(*pv, *pe)) {
416 AliError("Failed to initialize sub-algorithms, making this a zombie");
426 //____________________________________________________________________
428 AliBaseESDTask::MarkEventForStore() const
430 // Make sure the AOD tree is filled
431 DGUARD(fDebug,3,"Mark AOD event for storage");
432 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
434 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
435 if (ah) ah->SetFillAOD(kTRUE);
437 #define PF(N,V,...) \
438 AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
439 #define PFB(N,FLAG) \
441 AliForwardUtil::PrintName(N); \
442 std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
444 #define PFV(N,VALUE) \
446 AliForwardUtil::PrintName(N); \
447 std::cout << (VALUE) << std::endl; } while(false)
449 //____________________________________________________________________
451 AliBaseESDTask::Print(Option_t* option) const
459 std::cout << std::setfill('=') << std::setw(75) << "="
460 << std::setfill(' ') << std::endl;
461 AliForwardUtil::PrintTask(*this);
462 gROOT->IncreaseDirLevel();
463 PF("Off-line trigger mask", "0x%0x", fOfflineTriggerMask);
464 if (GetManager()) GetManager()->Print(option);
465 else PF("No correction manager","");
467 GetEventInspector().Print(option);
468 gROOT->DecreaseDirLevel();