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