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::SetDebug(Int_t dbg)
108 GetEventInspector().SetDebug(dbg);
112 //____________________________________________________________________
114 AliBaseESDTask::Configure(const char* macro)
116 // --- Configure the task ------------------------------------------
117 TString macroPath(gROOT->GetMacroPath());
118 if (!macroPath.Contains("$(ALICE_ROOT)/PWGLF/FORWARD/analysis2")) {
119 macroPath.Append(":$(ALICE_ROOT)/PWGLF/FORWARD/analysis2");
120 gROOT->SetMacroPath(macroPath);
123 if (mac.EqualTo("-default-"))
124 mac = "$(ALICE_ROOT)/PWGLF/FORWARD/analysis2/ForwardAODConfig.C";
125 const char* config = gSystem->Which(gROOT->GetMacroPath(), mac.Data());
127 AliWarningF("%s not found in %s", mac.Data(), gROOT->GetMacroPath());
131 AliInfoF("Loading configuration of '%s' from %s", ClassName(), config);
132 gROOT->Macro(Form("%s((%s*)%p)", config, GetTitle(), this));
138 //____________________________________________________________________
140 AliBaseESDTask::LocalInit()
146 //____________________________________________________________________
148 AliBaseESDTask::UserCreateOutputObjects()
151 // Create output objects
154 DGUARD(fDebug,1,"Create user ouput");
156 fList->SetName(Form("%sSums", GetName()));
159 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
161 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
162 //if (!ah) AliFatal("No AOD output handler set in analysis manager");
163 if (ah) CreateBranches(ah);
165 GetEventInspector().CreateOutputObjects(fList);
167 if (!Book()) AliFatalF("Failed to book output objects for %s", GetName());
169 // gSystem->Exec("root-config --version --prefix");
173 //____________________________________________________________________
175 AliBaseESDTask::UserExec(Option_t*)
177 // Call pre-event setup
180 // Get the input data
181 AliESDEvent* esd = GetESDEvent();
184 // Call the user code with our event passed in
186 // if (!Event(*esd)) {
187 // AliWarningF("Failed to process the event for %s", GetName());
194 // Call post-event processing
198 //____________________________________________________________________
200 AliBaseESDTask::Terminate(Option_t*)
202 TList* list = dynamic_cast<TList*>(GetOutputData(1));
204 AliError(Form("No output list defined (%p)", GetOutputData(1)));
205 if (GetOutputData(1)) GetOutputData(1)->Print();
209 // Assign to our internal variable for use by sub-classes
212 // Create our output container
213 TString resName(Form("%sResults", GetName()));
215 fResults = static_cast<TList*>(fList->Clone(resName));
217 fResults = new TList;
218 fResults->SetName(resName);
220 fResults->SetOwner();
222 // Now call user defined routines
224 AliErrorF("Failed to finalize this task (%s)", GetName());
228 PostData(2, fResults);
231 //____________________________________________________________________
233 AliBaseESDTask::PreData(const TAxis&, const TAxis&)
239 //____________________________________________________________________
241 AliBaseESDTask::CheckCorrections(UInt_t what) const
244 // Check if all needed corrections are there and accounted for. If not,
248 // what Which corrections is needed
251 // true if all present, false otherwise
253 DGUARD(fDebug,1,"Checking corrections 0x%x", what);
255 AliCorrectionManagerBase* cm = GetManager();
256 Bool_t ret = cm->CheckCorrections(what);
259 //____________________________________________________________________
261 AliBaseESDTask::ReadCorrections(const TAxis*& pe,
270 UInt_t what = fNeededCorrections|fExtraCorrections;
271 DGUARD(fDebug,1,"Read corrections 0x%x", what);
272 AliCorrectionManagerBase* cm = GetManager();
273 cm->EnableCorrections(what);
274 if (!cm->InitCorrections(GetEventInspector().GetRunNumber(),
275 GetEventInspector().GetCollisionSystem(),
276 GetEventInspector().GetEnergy(),
277 GetEventInspector().GetField(),
281 AliWarning("Failed to read in some corrections, making task zombie");
284 if (!CheckCorrections(fNeededCorrections)) return false;
286 // Sett our persistency pointer
287 // fCorrManager = &fcm;
289 // Get the eta axis from the secondary maps - if read in
291 pe = cm->GetEtaAxis();
292 if (!pe) pe = DefaultEtaAxis();
293 if (!pe) AliFatal("No eta axis defined");
295 // Get the vertex axis from the secondary maps - if read in
297 pv = cm->GetVertexAxis();
298 if (!pv) pv = DefaultVertexAxis();
299 if (!pv) AliFatal("No vertex axis defined");
304 //____________________________________________________________________
306 AliBaseESDTask::GetESDEvent()
309 // Get the ESD event. IF this is the first event, initialise
311 DGUARD(fDebug,1,"Get the ESD event");
313 // If we're marked as a zombie, do nothing and return a null
314 if (IsZombie()) return 0;
316 // Try to get the ESD event
317 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
319 AliWarning("No ESD event found for input event");
323 // --- Load the data -----------------------------------------------
326 if (!fFirstEvent || !esd->GetESDRun()) return esd;
328 // On the first event, initialize the parameters
329 GetEventInspector().SetMC(MCEvent());
330 GetEventInspector().ReadRunDetails(esd);
332 AliInfoF("Initializing with parameters from the ESD:\n"
333 " AliESDEvent::GetBeamEnergy() ->%f\n"
334 " AliESDEvent::GetBeamType() ->%s\n"
335 " AliESDEvent::GetCurrentL3() ->%f\n"
336 " AliESDEvent::GetMagneticField()->%f\n"
337 " AliESDEvent::GetRunNumber() ->%d",
338 esd->GetBeamEnergy(),
341 esd->GetMagneticField(),
342 esd->GetRunNumber());
350 Bool_t ret = ReadCorrections(pe, pv, mc, sat);
352 AliError("Failed to read corrections, making this a zombie");
357 // Initialize the event inspector
358 GetEventInspector().SetupForData(*pv);
360 // Initialize the remaining stuff
361 if (!PreData(*pv, *pe)) {
362 AliError("Failed to initialize sub-algorithms, making this a zombie");
372 //____________________________________________________________________
374 AliBaseESDTask::MarkEventForStore() const
376 // Make sure the AOD tree is filled
377 DGUARD(fDebug,3,"Mark AOD event for storage");
378 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
380 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
381 if (ah) ah->SetFillAOD(kTRUE);
383 #define PF(N,V,...) \
384 AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
385 #define PFB(N,FLAG) \
387 AliForwardUtil::PrintName(N); \
388 std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
390 #define PFV(N,VALUE) \
392 AliForwardUtil::PrintName(N); \
393 std::cout << (VALUE) << std::endl; } while(false)
395 //____________________________________________________________________
397 AliBaseESDTask::Print(Option_t* option) const
405 std::cout << std::setfill('=') << std::setw(75) << "="
406 << std::setfill(' ') << std::endl;
407 AliForwardUtil::PrintTask(*this);
408 gROOT->IncreaseDirLevel();
409 PF("Off-line trigger mask", "0x%0x", fOfflineTriggerMask);
410 if (fCorrManager) fCorrManager->Print(option);
411 else PF("Correction manager not set yet","");
413 GetEventInspector().Print(option);
414 gROOT->DecreaseDirLevel();