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>
15 //____________________________________________________________________
16 AliBaseESDTask::AliBaseESDTask()
17 : AliAnalysisTaskSE(),
21 fNeededCorrections(0),
27 //____________________________________________________________________
28 AliBaseESDTask::AliBaseESDTask(const char* name, const char* title,
29 AliCorrectionManagerBase* manager)
30 : AliAnalysisTaskSE(name),
34 fNeededCorrections(0),
39 SetTitle(title && title[0] != '\0' ? title : this->ClassName());
40 fCorrManager = manager;
42 // AliFatal("Must pass in a valid correction manager object!");
44 "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
45 "AliESDFMD.,SPDVertex.,PrimaryVertex.";
47 DefineOutput(1, TList::Class());
48 DefineOutput(2, TList::Class());
50 //____________________________________________________________________
52 AliBaseESDTask::Connect(const char* sumFile,
55 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
57 Error("AddTaskForwardMult", "No analysis manager to connect to.");
64 // Create and connect output containers
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;
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();
77 // Always connect input
78 mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer());
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);
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);
98 //____________________________________________________________________
100 AliBaseESDTask::DefaultEtaAxis() const
102 static TAxis* a = new TAxis(200, -4, 6);
105 //____________________________________________________________________
107 AliBaseESDTask::DefaultVertexAxis() const
109 static TAxis* a = AliForwardUtil::MakeFullIpZAxis(20);
112 //____________________________________________________________________
114 AliBaseESDTask::SetDebug(Int_t dbg)
122 GetEventInspector().SetDebug(dbg);
126 //____________________________________________________________________
128 AliBaseESDTask::Configure(const char* macro)
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);
137 if (mac.EqualTo("-default-"))
138 mac = "$(ALICE_ROOT)/PWGLF/FORWARD/analysis2/ForwardAODConfig.C";
139 const char* config = gSystem->Which(gROOT->GetMacroPath(), mac.Data());
141 AliWarningF("%s not found in %s", mac.Data(), gROOT->GetMacroPath());
145 AliInfoF("Loading configuration of '%s' from %s", ClassName(), config);
146 gROOT->Macro(Form("%s((%s*)%p)", config, GetTitle(), this));
152 //____________________________________________________________________
154 AliBaseESDTask::LocalInit()
160 //____________________________________________________________________
162 AliBaseESDTask::UserCreateOutputObjects()
165 // Create output objects
168 DGUARD(fDebug,1,"Create user ouput");
170 fList->SetName(Form("%sSums", GetName()));
173 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
175 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
176 //if (!ah) AliFatal("No AOD output handler set in analysis manager");
177 if (ah) CreateBranches(ah);
179 GetEventInspector().CreateOutputObjects(fList);
181 if (!Book()) AliFatalF("Failed to book output objects for %s", GetName());
183 // gSystem->Exec("root-config --version --prefix");
187 //____________________________________________________________________
189 AliBaseESDTask::UserExec(Option_t*)
191 // Call pre-event setup
194 // Read in selected branches
197 // Get the input data
198 AliESDEvent* esd = GetESDEvent();
201 // Call the user code with our event passed in
203 // if (!Event(*esd)) {
204 // AliWarningF("Failed to process the event for %s", GetName());
211 // Call post-event processing
215 //____________________________________________________________________
217 AliBaseESDTask::Terminate(Option_t*)
219 TList* list = dynamic_cast<TList*>(GetOutputData(1));
221 AliError(Form("No output list defined (%p)", GetOutputData(1)));
222 if (GetOutputData(1)) GetOutputData(1)->Print();
226 // Assign to our internal variable for use by sub-classes
229 // Create our output container
230 TString resName(Form("%sResults", GetName()));
232 fResults = static_cast<TList*>(fList->Clone(resName));
234 fResults = new TList;
235 fResults->SetName(resName);
237 fResults->SetOwner();
239 // Now call user defined routines
241 AliErrorF("Failed to finalize this task (%s)", GetName());
245 PostData(2, fResults);
248 //____________________________________________________________________
250 AliBaseESDTask::PreData(const TAxis&, const TAxis&)
256 //____________________________________________________________________
258 AliBaseESDTask::CheckCorrections(UInt_t what) const
261 // Check if all needed corrections are there and accounted for. If not,
265 // what Which corrections is needed
268 // true if all present, false otherwise
270 DGUARD(fDebug,1,"Checking corrections 0x%x", what);
271 if (what == 0) return true;
273 AliCorrectionManagerBase* cm = GetManager();
275 AliErrorF("Check corrections=0x%x not null, "
276 "but no correction manager defined!",
280 Bool_t ret = cm->CheckCorrections(what);
283 //____________________________________________________________________
285 AliBaseESDTask::ReadCorrections(const TAxis*& pe,
294 UInt_t what = fNeededCorrections|fExtraCorrections;
296 DGUARD(fDebug,1,"Read corrections 0x%x", what);
298 AliCorrectionManagerBase* cm = GetManager();
299 if (!cm && fNeededCorrections) {
300 AliErrorF("Needed/extra corrections=0x%x/0x%x not null, "
301 "but no correction manager defined!",
302 fNeededCorrections, fExtraCorrections);
306 // In case we have no needed corrections, we can return here
307 if (!pe) pe = DefaultEtaAxis();
308 if (!pv) pv = DefaultVertexAxis();
311 cm->EnableCorrections(what);
312 if (!cm->InitCorrections(GetEventInspector().GetRunNumber(),
313 GetEventInspector().GetCollisionSystem(),
314 GetEventInspector().GetEnergy(),
315 GetEventInspector().GetField(),
319 AliWarning("Failed to read in some corrections, making task zombie");
322 if (!CheckCorrections(fNeededCorrections)) return false;
324 // Sett our persistency pointer
325 // fCorrManager = &fcm;
327 // Get the eta axis from the secondary maps - if read in
329 pe = cm->GetEtaAxis();
330 if (!pe) pe = DefaultEtaAxis();
332 // Get the vertex axis from the secondary maps - if read in
334 pv = cm->GetVertexAxis();
335 if (!pv) pv = DefaultVertexAxis();
340 //____________________________________________________________________
342 AliBaseESDTask::GetESDEvent()
345 // Get the ESD event. IF this is the first event, initialise
347 DGUARD(fDebug,1,"Get the ESD event");
349 // If we're marked as a zombie, do nothing and return a null
350 if (IsZombie()) return 0;
352 // Try to get the ESD event
353 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
355 AliWarning("No ESD event found for input event");
359 // --- Load the data -----------------------------------------------
362 if (!fFirstEvent || !esd->GetESDRun()) return esd;
364 // On the first event, initialize the parameters
365 GetEventInspector().SetMC(MCEvent());
366 GetEventInspector().ReadRunDetails(esd);
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(),
377 esd->GetMagneticField(),
378 esd->GetRunNumber());
386 Bool_t ret = ReadCorrections(pe, pv, mc, sat);
388 AliError("Failed to read corrections, making this a zombie");
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");
396 // Initialize the event inspector
397 GetEventInspector().SetupForData(*pv);
399 // Initialize the remaining stuff
400 if (!PreData(*pv, *pe)) {
401 AliError("Failed to initialize sub-algorithms, making this a zombie");
411 //____________________________________________________________________
413 AliBaseESDTask::MarkEventForStore() const
415 // Make sure the AOD tree is filled
416 DGUARD(fDebug,3,"Mark AOD event for storage");
417 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
419 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
420 if (ah) ah->SetFillAOD(kTRUE);
422 #define PF(N,V,...) \
423 AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
424 #define PFB(N,FLAG) \
426 AliForwardUtil::PrintName(N); \
427 std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
429 #define PFV(N,VALUE) \
431 AliForwardUtil::PrintName(N); \
432 std::cout << (VALUE) << std::endl; } while(false)
434 //____________________________________________________________________
436 AliBaseESDTask::Print(Option_t* option) const
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);
449 if (GetManager()) GetManager()->Print(option);
450 else PF("No correction manager","");
452 GetEventInspector().Print(option);
453 gROOT->DecreaseDirLevel();