AliPhysics  6cf2591 (6cf2591)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliBaseESDTask.cxx
Go to the documentation of this file.
1 #include "AliBaseESDTask.h"
2 #include "AliFMDEventInspector.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 <TInterpreter.h>
13 #include <iostream>
14 #include <iomanip>
15 
16 //____________________________________________________________________
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 {
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;
46  // if (!manager)
47  // AliFatal("Must pass in a valid correction manager object!");
48  fBranchNames =
49  "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
50  "AliESDFMD.,SPDVertex.,TPCVertex.,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  Bool_t old)
60 {
61  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
62  if (!mgr) {
63  Error("AddTaskForwardMult", "No analysis manager to connect to.");
64  return false;
65  }
66 
67  // Add to the manager
68  mgr->AddTask(this);
69 
70  // Create and connect output containers
71  TString sumOut;
72  TString resOut;
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();
82 
83  // Always connect input
84  mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer());
85 
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(),
89  old ? "" : "Sums"));
90  AliAnalysisDataContainer* sumCon =
91  mgr->CreateContainer(sumName, TList::Class(),
92  AliAnalysisManager::kOutputContainer, sumOut);
93  mgr->ConnectOutput(this, 1, sumCon);
94  }
95  // Connect the result list unless the output 'none' is specified
96  if (!resOut.EqualTo("none", TString::kIgnoreCase)) {
97  TString resName(Form("%sResults", GetName()));
98  AliAnalysisDataContainer* resCon =
99  mgr->CreateContainer(resName, TList::Class(),
100  AliAnalysisManager::kParamContainer, resOut);
101  mgr->ConnectOutput(this, 2, resCon);
102  }
103 
104  return true;
105 }
106 
107 //____________________________________________________________________
108 TAxis*
110 {
111  static TAxis* a = new TAxis(200, -4, 6);
112  return a;
113 }
114 //____________________________________________________________________
115 TAxis*
117 {
118  static TAxis* a = AliForwardUtil::MakeFullIpZAxis(20);
119  return a;
120 }
121 //____________________________________________________________________
122 void
124 {
125  //
126  // Set debug level
127  //
128  // Parameters:
129  // dbg debug level
130  //
132 }
133 //____________________________________________________________________
134 void
136 {
138  TString s(str);
139  s.ToLower();
140  if (s.Contains("normal")) meth = AliFMDEventInspector::kNormal;
141  else if (s.Contains("pa2012")) meth = AliFMDEventInspector::kpA2012;
142  else if (s.Contains("pa2013")) meth = AliFMDEventInspector::kpA2013;
143  else if (s.Contains("ud")) meth = AliFMDEventInspector::kPWGUD;
144  else if (s.Contains("disp") || s.Contains("sat"))
146  else
147  AliWarningF("Unknown IPz method: %s, using normal", str);
149 }
150 
151 //____________________________________________________________________
152 Bool_t
153 AliBaseESDTask::Configure(const char* macro)
154 {
155  // --- Configure the task ------------------------------------------
156  TString macroPath(gROOT->GetMacroPath());
157  if (!macroPath.Contains("$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2")) {
158  macroPath.Append(":$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2");
159  gROOT->SetMacroPath(macroPath);
160  }
161  TString mac(macro);
162  if (mac.EqualTo("-default-")) mac = DefaultConfig();
163  const char* config = gSystem->Which(gROOT->GetMacroPath(), mac.Data());
164  if (!config) {
165  AliWarningF("%s not found in %s", mac.Data(), gROOT->GetMacroPath());
166  return false;
167  }
168  if (fTitle.IsNull()) fTitle = this->ClassName();
169 
170  AliInfoF("Loading configuration of '%s' from %s", ClassName(), config);
171  gROOT->Macro(Form("%s((%s*)%p)", config, GetTitle(), this));
172 
173  AliInfoF("Unloading configuration script %s", config);
174  gInterpreter->UnloadFile(config);
175 
176  delete config;
177 
178  return true;
179 }
180 
181 //____________________________________________________________________
182 void
184 {
185  fFirstEvent = true;
186  DGUARD(fDebug,1,"Doing local initialization");
187  Setup();
188 }
189 
190 //____________________________________________________________________
191 void
193 {
194  //
195  // Create output objects
196  //
197  //
198  DGUARD(fDebug,1,"Create user ouput");
199  fList = new TList;
200  fList->SetName(Form("%sSums", GetName()));
201  fList->SetOwner();
202 
203  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
204  AliAODHandler* ah =
205  dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
206  //if (!ah) AliFatal("No AOD output handler set in analysis manager");
207  if (ah) CreateBranches(ah);
208 
210 
211  if (!Book()) AliFatalF("Failed to book output objects for %s", GetName());
212 
213  // gSystem->Exec("root-config --version --prefix");
214  PostData(1, fList);
215 }
216 
217 //____________________________________________________________________
218 void
220 {
221  // Call pre-event setup
222  PreEvent();
223 
224  // Read in selected branches
225  LoadBranches();
226 
227  // Get the input data
228  AliESDEvent* esd = GetESDEvent();
229  if (!esd) return;
230 
231  // Call the user code with our event passed in
232  Event(*esd);
233  // if (!Event(*esd)) {
234  // AliWarningF("Failed to process the event for %s", GetName());
235  // return;
236  // }
237 
238  // Post data
239  PostData(1, fList);
240 
241  // Call post-event processing
242  PostEvent();
243 }
244 
245 //____________________________________________________________________
246 void
248 {
249  TList* list = dynamic_cast<TList*>(GetOutputData(1));
250  if (!list) {
251  AliError(Form("No output list defined (%p)", GetOutputData(1)));
252  if (GetOutputData(1)) GetOutputData(1)->Print();
253  return;
254  }
255 
256  // Assign to our internal variable for use by sub-classes
257  fList = list;
258 
259  // Create our output container
260  TString resName(Form("%sResults", GetName()));
261  if (fCloneList)
262  fResults = static_cast<TList*>(fList->Clone(resName));
263  else {
264  fResults = new TList;
265  fResults->SetName(resName);
266  }
267  fResults->SetOwner();
268 
269  // Now call user defined routines
270  if (!Finalize()) {
271  AliErrorF("Failed to finalize this task (%s)", GetName());
272  return;
273  }
274 
275  PostData(2, fResults);
276 }
277 
278 //____________________________________________________________________
279 Bool_t
281 {
282  return true;
283 }
284 
285 
286 //____________________________________________________________________
287 Bool_t
289 {
290  //
291  // Check if all needed corrections are there and accounted for. If not,
292  // do a Fatal exit
293  //
294  // Parameters:
295  // what Which corrections is needed
296  //
297  // Return:
298  // true if all present, false otherwise
299  //
300  DGUARD(fDebug,1,"Checking corrections 0x%x", what);
301  if (what == 0) return true;
302 
304  if (!cm) {
305  AliErrorF("Check corrections=0x%x not null, "
306  "but no correction manager defined!",
307  what);
308  return false;
309  }
310  Bool_t ret = cm->CheckCorrections(what);
311  return ret;
312 }
313 //____________________________________________________________________
314 Bool_t
316  const TAxis*& pv,
317  Bool_t mc,
318  Bool_t sat)
319 {
320  //
321  // Read corrections
322  //
323  //
325 
326  DGUARD(fDebug,1,"Read corrections 0x%x", what);
327 
329  if (!cm && fNeededCorrections) {
330  AliErrorF("Needed/extra corrections=0x%x/0x%x not null, "
331  "but no correction manager defined!",
333  return false;
334  }
335  if (!cm || !what) {
336  // In case we have no needed corrections, we can return here
337  if (!pe) pe = DefaultEtaAxis();
338  if (!pv) pv = DefaultVertexAxis();
339  return true;
340  }
341  cm->EnableCorrections(what);
343  GetEventInspector().GetCollisionSystem(),
344  GetEventInspector().GetEnergy(),
345  GetEventInspector().GetField(),
346  mc,
347  sat,
348  false)) {
349  AliWarning("Failed to read in some corrections, making task zombie");
350  return false;
351  }
352  if (!CheckCorrections(fNeededCorrections)) return false;
353 
354  // Sett our persistency pointer
355  // fCorrManager = &fcm;
356 
357  // Get the eta axis from the secondary maps - if read in
358  if (!pe) {
359  pe = cm->GetEtaAxis();
360  if (!pe) pe = DefaultEtaAxis();
361  }
362  // Get the vertex axis from the secondary maps - if read in
363  if (!pv) {
364  pv = cm->GetVertexAxis();
365  if (!pv) pv = DefaultVertexAxis();
366  }
367 
368  return true;
369 }
370 //____________________________________________________________________
373 {
374  //
375  // Get the ESD event. IF this is the first event, initialise
376  //
377  DGUARD(fDebug,1,"Get the ESD event");
378 
379  // If we're marked as a zombie, do nothing and return a null
380  if (IsZombie()) return 0;
381 
382  // Try to get the ESD event
383  AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
384  if (!esd) {
385  AliWarning("No ESD event found for input event");
386  return 0;
387  }
388 
389  // --- Load the data -----------------------------------------------
390  LoadBranches();
391 
392  if (!fFirstEvent || !esd->GetESDRun()) return esd;
393 
394  // On the first event, initialize the parameters
395  GetEventInspector().SetMC(MCEvent());
397 
398  AliInfoF("Initializing with parameters from the ESD:\n"
399  " AliESDEvent::GetBeamEnergy() ->%f\n"
400  " AliESDEvent::GetBeamType() ->%s\n"
401  " AliESDEvent::GetCurrentL3() ->%f\n"
402  " AliESDEvent::GetMagneticField()->%f\n"
403  " AliESDEvent::GetRunNumber() ->%d",
404  esd->GetBeamEnergy(),
405  esd->GetBeamType(),
406  esd->GetCurrentL3(),
407  esd->GetMagneticField(),
408  esd->GetRunNumber());
409 
410  PreCorrections(esd);
411 
412  fFirstEvent = false;
413 
414  const TAxis* pe = 0;
415  const TAxis* pv = 0;
416  Bool_t mc = IsMC();
417  Bool_t sat = false;
418  Bool_t ret = ReadCorrections(pe, pv, mc, sat);
419  if (!ret) {
420  AliError("Failed to read corrections, making this a zombie");
421  SetZombie(true);
422  return 0;
423  }
424  Printf("Vertex axis: %p Eta axis: %p", pv, pe);
425  if (!pv) AliFatal("No vertex axis defined");
426  if (!pe) AliFatal("No eta axis defined");
427 
428  // Initialize the event inspector
430 
431  // Initialize the remaining stuff
432  if (!PreData(*pv, *pe)) {
433  AliError("Failed to initialize sub-algorithms, making this a zombie");
434  SetZombie(true);
435  return 0;
436  }
437 
438  this->Print("R");
439 
440  return esd;
441 }
442 
443 //____________________________________________________________________
444 void
446 {
447  // Make sure the AOD tree is filled
448  DGUARD(fDebug,3,"Mark AOD event for storage");
449  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
450  AliAODHandler* ah =
451  dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
452  if (ah) ah->SetFillAOD(kTRUE);
453 }
454 #define PF(N,V,...) \
455  AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
456 #define PFB(N,FLAG) \
457  do { \
458  AliForwardUtil::PrintName(N); \
459  std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
460  } while(false)
461 #define PFV(N,VALUE) \
462  do { \
463  AliForwardUtil::PrintName(N); \
464  std::cout << (VALUE) << std::endl; } while(false)
465 
466 //____________________________________________________________________
467 void
469 {
470  //
471  // Print information
472  //
473  // Parameters:
474  // option Not used
475  //
476  std::cout << std::setfill('=') << std::setw(75) << "="
477  << std::setfill(' ') << std::endl;
479  gROOT->IncreaseDirLevel();
480  PF("Off-line trigger mask", "0x%0x", fOfflineTriggerMask);
481  if (GetManager()) GetManager()->Print(option);
482  else PF("No correction manager","");
483 
484  GetEventInspector().Print(option);
485  gROOT->DecreaseDirLevel();
486 }
487 //
488 // EOF
489 //
virtual Bool_t IsMC() const
return jsonbuilder str().c_str()
virtual Bool_t Setup()
virtual Bool_t ReadCorrections(const TAxis *&pe, const TAxis *&pv, Bool_t mc=false, Bool_t sat=false)
virtual Bool_t Event(AliESDEvent &esd)=0
virtual AliCorrectionManagerBase * GetManager() const
static TAxis * MakeFullIpZAxis(Int_t nCenter=20)
const char * title
Definition: MakeQAPdf.C:26
virtual void CreateBranches(AliAODHandler *)
virtual Bool_t Connect(const char *sumFile=0, const char *resFile=0)
TSystem * gSystem
virtual void Print(Option_t *option="") const
virtual void EnableCorrections(UInt_t what)
TList * list
Bool_t InitCorrections(ULong_t run, UShort_t sys, UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat, Bool_t force=false)
virtual void MarkEventForStore() const
void SetIPzMethod(const char *str)
virtual Bool_t PostEvent()
#define PF(N, V,...)
Bool_t ReadRunDetails(const AliESDEvent *esd)
void Terminate(Option_t *option)
virtual TAxis * DefaultVertexAxis() const
virtual AliFMDEventInspector & GetEventInspector()=0
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
Various utilities used in PWGLF/FORWARD.
void SetVertexMethod(EVtxType t)
virtual Bool_t Configure(const char *macro="-default-")
virtual Bool_t CheckCorrections(UInt_t what, Bool_t verbose=true) const
void SetMC(Bool_t isMC=true)
virtual Bool_t CheckCorrections(UInt_t what) const
void UserCreateOutputObjects()
virtual void SetDebug(Int_t dbg)
void CreateOutputObjects(TList *dir)
AliCorrectionManagerBase * fCorrManager
#define DGUARD(L, N, F,...)
virtual Bool_t PreData(const TAxis &vertex, const TAxis &eta)
static void PrintTask(const TObject &o)
UInt_t fExtraCorrections
virtual Bool_t Book()=0
virtual Bool_t Finalize()
virtual const TAxis * GetEtaAxis() const
virtual void Print(Option_t *option="") const
void Print(Option_t *option="") const
virtual void PreCorrections(const AliESDEvent *esd)
virtual Bool_t PreEvent()
void UserExec(Option_t *option)
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
virtual AliESDEvent * GetESDEvent()
virtual TAxis * DefaultEtaAxis() const
const char Option_t
Definition: External.C:48
UInt_t fNeededCorrections
bool Bool_t
Definition: External.C:53
virtual const char * DefaultConfig() const
void SetDebug(Int_t dbg=1)
virtual const TAxis * GetVertexAxis() const
virtual void SetupForData(const TAxis &vtxAxis)