AliPhysics  f05a842 (f05a842)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliBaseAODTask.cxx
Go to the documentation of this file.
1 #include "AliBaseAODTask.h"
2 #include "AliForwardUtil.h"
3 #include "AliAODForwardMult.h"
4 #include "AliAODCentralMult.h"
5 #include "AliAODMultEventClass.h"
6 #include <AliAnalysisManager.h>
7 #include <AliLog.h>
8 #include <AliAODEvent.h>
9 #include <TROOT.h>
10 #include <TSystem.h>
11 #include <TInterpreter.h>
12 #include <TH2.h>
13 #include <iostream>
14 
15 //____________________________________________________________________
18  fTriggerMask(0xFFFFFFFF),
19  fFilterMask(AliAODForwardMult::kDefaultFilter),
20  fMinIpZ(0),
21  fMaxIpZ(-1),
22  fCentAxis(0, 0, -1),
23  fTriggers(0),
24  fEventStatus(0),
25  fVertex(0),
26  fCent(0),
27  fAccVertex(0),
28  fAccVertexXY(0),
29  fAccCent(0),
30  fFirstEvent(true),
31  fCloneList(false),
32  fSums(0),
33  fResults(0)
34 {
35 }
36 //____________________________________________________________________
38  const char* title)
39  : AliAnalysisTaskSE(name),
40  fTriggerMask(0xFFFFFFFF),
41  fFilterMask(AliAODForwardMult::kDefaultFilter),
42  fMinIpZ(0),
43  fMaxIpZ(-1),
44  fCentAxis(0, 0, -1),
45  fTriggers(0),
46  fEventStatus(0),
47  fVertex(0),
48  fCent(0),
49  fAccVertex(0),
50  fAccVertexXY(0),
51  fAccCent(0),
52  fFirstEvent(true),
53  fCloneList(false),
54  fSums(0),
55  fResults(0)
56 {
57  SetTitle(title && title[0] != '\0' ? title : this->ClassName());
58  fCentAxis.SetName("centAxis");
59  fCentAxis.SetTitle("Centrality [%]");
60  DefineOutput(1, TList::Class());
61  DefineOutput(2, TList::Class());
62 }
63 
64 //____________________________________________________________________
65 Bool_t
66 AliBaseAODTask::Configure(const char* macro)
67 {
68  // --- Configure the task ------------------------------------------
69  TString macroPath(gROOT->GetMacroPath());
70  if (!macroPath.Contains("$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2")) {
71  macroPath.Append(":$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2");
72  gROOT->SetMacroPath(macroPath);
73  }
74  TString mac(macro);
75  if (mac.EqualTo("-default-")) mac = DefaultConfig();
76  const char* config = gSystem->Which(gROOT->GetMacroPath(), mac.Data());
77  if (!config) {
78  AliWarningF("%s not found in %s", mac.Data(), gROOT->GetMacroPath());
79  return false;
80  }
81  // if (gInterpreter->IsLoaded(config))
82  // gInterpreter->UnloadFile(config);
83 
84  AliInfoF("Loading configuration of '%s' from %s", ClassName(), config);
85  gROOT->Macro(Form("%s((%s*)%p)", config, GetTitle(), this));
86 
87  Info("Configure", "Unloading configuration script");
88  gInterpreter->UnloadFile(config);
89  delete config;
90 
91  return true;
92 }
93 
94 //________________________________________________________________________
95 void
97 {
98  //
99  // Set the trigger maskl
100  //
101  // Parameters:
102  // mask Trigger mask
103  //
104  DGUARD(fDebug,3,"Set the trigger mask: %s", mask);
106 }
107 //________________________________________________________________________
108 void
110 {
111  DGUARD(fDebug,3,"Set the trigger mask: 0x%0x", mask);
112  fTriggerMask = mask;
113 }
114 //________________________________________________________________________
115 void
117 {
118  //
119  // Set the trigger maskl
120  //
121  // Parameters:
122  // mask Trigger mask
123  //
124  DGUARD(fDebug,3,"Set the filter mask: %s", mask);
126 }
127 //________________________________________________________________________
128 void
130 {
131  DGUARD(fDebug,3,"Set the filter mask: 0x%0x", mask);
132  fFilterMask = mask;
133 }
134 //________________________________________________________________________
135 void
137 {
138  DGUARD(fDebug,3,"Set centrality axis, %d bins", n);
139  TArrayD dbins(n+1);
140  for (UShort_t i = 0; i <= n; i++)
141  dbins[i] = (bins[i] == 100 ? 100.1 : bins[i]);
142  fCentAxis.Set(n, dbins.GetArray());
143 
144 }
145 //____________________________________________________________________
146 namespace {
147  Double_t GetEdge(const TString& str, Int_t start, Int_t end)
148  {
149  TString sub(str(start, end));
150  return sub.Atof();
151  }
152  Bool_t ExtractBins(const TString& spec, TArrayD& edges)
153  {
154  TArrayD tmp(200);
155  Int_t start = 0;
156  Int_t cnt = 0;
157  for (Int_t i=1; i<spec.Length(); i++) {
158  if (spec[i] == '-' || spec[i] == ':') {
159  Double_t c = GetEdge(spec, start, i);
160  if (cnt > 0 && c < tmp[cnt-1]) {
161  Warning("ExtractBins",
162  "Invalid edge @ %d: %f (< %f)", cnt, c, tmp[cnt-1]);
163  tmp.Set(0);
164  return false;
165  }
166  tmp[cnt] = c;
167  i++;
168  start = i;
169  cnt++;
170  }
171  }
172  if (start+1 != spec.Length()) {
173  Double_t c = GetEdge(spec, start, spec.Length());
174  tmp[cnt] = c;
175  cnt++;
176  }
177  edges.Set(cnt, tmp.GetArray());
178  return true;
179  }
180 }
181 
182 //________________________________________________________________________
183 void
185 {
186  DGUARD(fDebug,3,"Set centrality axis: %s", bins);
187  if (!bins || bins[0] == '\0') return;
188 
189  TString spec(bins);
190  if (spec.EqualTo("none", TString::kIgnoreCase))
191  return;
192 
193  TArrayD edges;
194  if (spec.EqualTo("default", TString::kIgnoreCase) ||
195  spec.EqualTo("pbpb", TString::kIgnoreCase)) {
196  // 1 2 3 4 5 6 7 8 9 10 11
197  Double_t tmp[] = { 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 100 };
198  edges.Set(11, tmp);
199  }
200  else if (spec.EqualTo("ppb", TString::kIgnoreCase) ||
201  spec.EqualTo("pbp", TString::kIgnoreCase)) {
202  // 1 2 3 4 5 6 7 8
203  Double_t tmp[] = { 0, 5, 10, 20, 40, 60, 80, 100 };
204  edges.Set(8, tmp);
205  }
206  else {
207  ExtractBins(spec, edges);
208  }
209  SetCentralityAxis(edges.GetSize()-1, edges.GetArray());
210 }
211 
212 //________________________________________________________________________
213 void
215 {
216  DGUARD(fDebug,3,"Set centrality axis, %d bins", n);
217  fCentAxis.Set(n, bins);
218 }
219 //________________________________________________________________________
220 void
222 {
223  Short_t a[] = { low, high };
224  SetCentralityAxis(1, a);
225 }
226 
227 //____________________________________________________________________
228 Bool_t
229 AliBaseAODTask::Connect(const char* sumFile,
230  const char* resFile)
231 {
232  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
233  if (!mgr) {
234  Error("AddTaskForwardMult", "No analysis manager to connect to.");
235  return false;
236  }
237 
238  // --- Check that we have an AOD input handler ---------------------
239  UShort_t aodInput = 0;
240  if (!(aodInput = AliForwardUtil::CheckForAOD())) {
241  AliError("Cannot proceed without and AOD handler");
242  return false;
243  }
244  if (aodInput == 2 &&
245  !AliForwardUtil::CheckForTask("AliForwardMultiplicityBase")) {
246  AliError("The relevant task wasn't added to the train");
247  return false;
248  }
249 
250  // Add to the manager
251  mgr->AddTask(this);
252 
253  // Create and connect output containers
254  TString sumOut;
255  TString resOut;
256  if (sumFile && sumFile[0] != '\0') sumOut = sumFile;
257  if (resFile && resFile[0] != '\0') resOut = resFile;
258  else if (sumFile && sumFile[0] != '\0') resOut = sumFile;
259  if (sumOut.IsNull()) sumOut = AliAnalysisManager::GetCommonFileName();
260  if (resOut.IsNull()) resOut = AliAnalysisManager::GetCommonFileName();
261 
262  AliAnalysisDataContainer* sumCon =
263  mgr->CreateContainer(Form("%sSums", GetName()), TList::Class(),
264  AliAnalysisManager::kOutputContainer, sumOut);
265  AliAnalysisDataContainer* resCon =
266  mgr->CreateContainer(Form("%sResults", GetName()), TList::Class(),
267  AliAnalysisManager::kParamContainer, resOut);
268  mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer());
269  mgr->ConnectOutput(this, 1, sumCon);
270  mgr->ConnectOutput(this, 2, resCon);
271 
272  return true;
273 }
274 //____________________________________________________________________
275 void
277 {
278  //
279  // Create output objects
280  //
281  //
282  DGUARD(fDebug,1,"Create user ouput");
283  fSums = new TList;
284  fSums->SetName(Form("%sSums", GetName()));
285  fSums->SetOwner(true);
286 
288  fTriggers->SetDirectory(0);
289 
291  fEventStatus->SetDirectory(0);
292 
293  fSums->Add(fTriggers);
294  fSums->Add(fEventStatus);
295 
297  fVertex = new TH1D("vertex", "IP_{z} of all events",
298  vA->GetNbins(), vA->GetXbins()->GetArray());
299  fVertex->SetXTitle("IP_{z} [cm]");
300  fVertex->SetYTitle("Events");
301  fVertex->SetDirectory(0);
302  fVertex->SetFillColor(kRed+2);
303  fVertex->SetFillStyle(3002);
304  fVertex->SetLineColor(kRed+2);
305  fSums->Add(fVertex);
306  fAccVertex = static_cast<TH1D*>(fVertex->Clone("vertexAcc"));
307  fAccVertex->SetTitle("IP_{z} of accepted events");
308  fAccVertex->SetDirectory(0);
309  fAccVertex->SetFillColor(kGreen+2);
310  fAccVertex->SetLineColor(kGreen+2);
311  fSums->Add(fAccVertex);
312 
313  fAccVertexXY = new TH2D("vertexAccXY", "IP_{x,y} of accepted events",
314  1000,-2,2,1000,-2,2);
315  fAccVertexXY->SetXTitle("IP_{x} [cm]");
316  fAccVertexXY->SetYTitle("IP_{y} [cm]");
317  fAccVertexXY->SetDirectory(0);
318  fSums->Add(fAccVertexXY);
319 
320  fCent = new TH1D("cent","Centrality of all events",102, -1, 101);
321  fCent->SetXTitle("Centrality [%]");
322  fCent->SetYTitle("Events");
323  fCent->SetFillColor(kRed+2);
324  fCent->SetFillStyle(3002);
325  fCent->SetLineColor(kRed+2);
326  fCent->SetDirectory(0);
327  fSums->Add(fCent);
328  fAccCent = static_cast<TH1D*>(fCent->Clone("centAcc"));
329  fAccCent->SetTitle("Centrality of accepted events");
330  fAccCent->SetDirectory(0);
331  fAccCent->SetFillColor(kGreen+2);
332  fAccCent->SetLineColor(kGreen+2);
333  fSums->Add(fAccCent);
334 
335  // Store centrality axis as a histogram - which can be merged
336  TH1* cH = 0;
337  if (fCentAxis.GetXbins() && fCentAxis.GetXbins()->GetSize() > 0)
338  cH = new TH1I(fCentAxis.GetName(), fCentAxis.GetTitle(),
339  fCentAxis.GetNbins(), fCentAxis.GetXbins()->GetArray());
340  else
341  cH = new TH1I(fCentAxis.GetName(), fCentAxis.GetTitle(),
342  fCentAxis.GetNbins(), fCentAxis.GetXmin(),
343  fCentAxis.GetXmax());
344  cH->SetBinContent(1,1);
345  cH->GetXaxis()->SetTitle(fCentAxis.GetTitle());
346  cH->GetXaxis()->SetName(fCentAxis.GetName());
347 
348  fSums->Add(cH);
349 
352  fSums->Add(AliForwardUtil::MakeParameter("count", 1));
353  fSums->Add(AliForwardUtil::MakeParameter("alirootRev",
355  fSums->Add(AliForwardUtil::MakeParameter("alirootBranch",
357 
358 
359 
360  if (!Book()) AliFatalF("Failed to book output objects for %s", GetName());
361 
362  Print();
363 
364  PostData(1, fSums);
365 }
366 
367 //____________________________________________________________________
370 {
371  // Get the forward object that contains our event selection stuff
372  TObject* obj = 0;
373  if (mc) obj = aod.FindListObject("ForwardMC");
374  else obj = aod.FindListObject("Forward");
375  if (!obj) {
376  if (verb) AliWarning("No forward object found");
377  return 0;
378  }
379  AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
380  return forward;
381 }
382 //____________________________________________________________________
385 {
386  // Get the forward object that contains our event selection stuff
387  TObject* obj = aod.FindListObject("MultClass");
388  if (!obj) {
389  if (verb) AliWarning("No multiplicity event class object found");
390  return 0;
391  }
392  AliAODMultEventClass* multClass = static_cast<AliAODMultEventClass*>(obj);
393  return multClass;
394 }
395 //____________________________________________________________________
396 Double_t
398  AliAODForwardMult* forward,
399  Int_t& qual)
400 {
401  qual = 0;
402  Double_t cent = forward->GetCentrality();
403  Double_t max = (HasCentrality() ? fCentAxis.GetXmax() : 100);
404  if (cent < 0) { cent = -.5; qual = 0xFFFF; }
405  if (cent > max) { cent = TMath::Max(max+.1,100.5); qual = 198; }
406  return cent;
407 }
408 //____________________________________________________________________
409 Double_t
411  AliAODForwardMult* forward)
412 {
413  Int_t qual = 0;
414  Double_t cent = GetCentrality(event, forward, qual);
415  if (qual > 0) forward->SetTriggerBits(AliAODForwardMult::kCentNoCalib);
416  return cent;
417 }
418 
419 //____________________________________________________________________
420 Double_t
422  AliAODForwardMult* forward)
423 {
424  return forward->GetIpZ();
425 }
426 //____________________________________________________________________
427 Bool_t
429 
430 {
431  x = -10000;
432  y = -10000;
433  AliVVertex* gen = aod.GetPrimaryVertex();
434  AliVVertex* vtx[] = { aod.GetPrimaryVertexSPD(),
435  aod.GetPrimaryVertexTPC(),
436  gen };
437  Bool_t ret = false;
438  for (Int_t i = 0; i < 3; i++) {
439  if (!vtx[i] || (vtx[i] != gen && !vtx[i]->IsFromVertexer3D()))
440  continue;
441 
442  x = vtx[i]->GetX();
443  y = vtx[i]->GetY();
444  ret = true;
445  break;
446  }
447  return ret;
448 }
449 
450 //____________________________________________________________________
453 {
454  // Get the central object that contains our event selection stuff
455  TObject* obj = 0;
456  if (mc) obj = aod.FindListObject("CentralClustersMC");
457  else obj = aod.FindListObject("CentralClusters");
458  if (!obj) {
459  if (verb) AliWarning("No central object found");
460  return 0;
461  }
462  AliAODCentralMult* central = static_cast<AliAODCentralMult*>(obj);
463  return central;
464 }
465 //____________________________________________________________________
466 TH2D*
468 {
469  TObject* obj = aod.FindListObject("primary");
470  if (!obj) return 0;
471  TH2D* ret = static_cast<TH2D*>(obj);
472  return ret;
473 }
474 
475 //____________________________________________________________________
476 void
478 {
479  //
480  // Process a single event
481  //
482  // Parameters:
483  // option Not used
484  //
485  // Main loop
486  DGUARD(fDebug,1,"Analyse the AOD event in UserExec");
487  if (!PreEvent()) return;
488 
490  if (!aod) return;
491 
492  // Get the forward object that contains our event selection stuff
493  AliAODForwardMult* forward = GetForward(*aod);
494  if (!forward) return;
495 
496  if (fFirstEvent) {
497  if (!PreData()) return;
498  StoreInformation(*forward);
499  fFirstEvent = false;
500  }
501 
502  // Get our ip_z and centrality
503  Double_t vtx = GetIpZ(*aod, forward);
504  Float_t cent = GetCentrality(*aod, forward);
505  fVertex->Fill(vtx);
506  fCent->Fill(cent);
507 
508  // Now check our event selectio up front
509  if (!CheckEvent(*forward)) return;
510 
511  // Let user defined code do the job
512  Bool_t taken = Event(*aod);
513 
514  // Fill our histograms
515  if (taken) {
516  fAccVertex->Fill(vtx);
517  fAccCent->Fill(cent);
518 
519  Double_t ipX, ipY;
520  GetIpXY(*aod, ipX, ipY);
521  fAccVertexXY->Fill(ipX, ipY);
522  }
523 
524  PostData(1, fSums);
525 
526  PostEvent();
527 }
528 
529 //____________________________________________________________________
530 Bool_t
532 {
533  if (HasCentrality()) {
534  return forward.CheckEvent(fTriggerMask, fMinIpZ, fMaxIpZ,
535  fCentAxis.GetXmin(),
536  fCentAxis.GetXmax(),
538  fFilterMask);
539 }
540  return forward.CheckEvent(fTriggerMask, fMinIpZ, fMaxIpZ,
541  0, 0, fTriggers, fEventStatus,
542  fFilterMask);
543 }
544 
545 //____________________________________________________________________
546 void
548 {
549  fSums->Add(AliForwardUtil::MakeParameter("sNN", forward.GetSNN()));
550  fSums->Add(AliForwardUtil::MakeParameter("sys", forward.GetSystem()));
551 }
552 
553 //____________________________________________________________________
554 void
556 {
557  TList* list = dynamic_cast<TList*>(GetOutputData(1));
558  if (!list) {
559  AliError(Form("No output list defined (%p)", GetOutputData(1)));
560  if (GetOutputData(1)) GetOutputData(1)->Print();
561  return;
562  }
563 
564  // Assign to our internal variable for use by sub-classes
565  fSums = list;
566 
567  // Create our output container
568  TString resName(Form("%sResults", GetName()));
569  if (fCloneList)
570  fResults = static_cast<TList*>(fSums->Clone(resName.Data()));
571  else {
572  fResults = new TList;
573  fResults->SetName(resName.Data());
574  }
575  fResults->SetOwner(true);
576 
577  // Now call user defined routines
578  if (!Finalize()) {
579  AliErrorF("Failed to finalize this task (%s)", GetName());
580  return;
581  }
582 
583  PostData(2, fResults);
584 }
585 
586 #define PF(N,V,...) \
587  AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
588 #define PFB(N,FLAG) \
589  do { \
590  AliForwardUtil::PrintName(N); \
591  std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
592  } while(false)
593 #define PFV(N,VALUE) \
594  do { \
595  AliForwardUtil::PrintName(N); \
596  std::cout << (VALUE) << std::endl; } while(false)
597 
598 //____________________________________________________________________
599 void
600 AliBaseAODTask::Print(Option_t* /*option=""*/) const
601 {
608  gROOT->IncreaseDirLevel();
611  PF("IP z range", "%++6.1f - %+6.1f", fMinIpZ, fMaxIpZ);
612  PFV("Centrality bins", (HasCentrality() ? "" : "none"));
613  gROOT->IndentLevel();
614  if (HasCentrality()) {
615  Int_t nBins = fCentAxis.GetNbins();
616  const Double_t* bins = fCentAxis.GetXbins()->GetArray();
617  for (Int_t i = 0; i <= nBins; i++)
618  std::cout << (i==0 ? " " : "-") << bins[i];
619  std::cout << std::endl;
620  }
621  gROOT->DecreaseDirLevel();
622 }
623 //
624 // EOF
625 //
virtual Bool_t CheckEvent(const AliAODForwardMult &forward)
virtual void Terminate(Option_t *option)
return jsonbuilder str().c_str()
UShort_t GetSystem() const
static UInt_t MakeTriggerMask(const char *what, const char *sep="&")
double Double_t
Definition: External.C:58
static TAxis * MakeFullIpZAxis(Int_t nCenter=20)
void SetTriggerBits(UInt_t bits)
virtual Bool_t PreEvent()
const char * title
Definition: MakeQAPdf.C:26
void SetTriggerMask(UInt_t mask)
TSystem * gSystem
virtual Bool_t PreData()
TList * list
static TH1I * MakeTriggerHistogram(const char *name="triggers", UInt_t mask=0)
virtual void UserCreateOutputObjects()
TCanvas * c
Definition: TestFitELoss.C:172
#define PF(N, V,...)
static AliAODEvent * GetAODEvent(AliAnalysisTaskSE *task)
Float_t GetIpZ() const
virtual Bool_t GetIpXY(AliAODEvent &aod, Double_t &x, Double_t &y)
UShort_t GetSNN() const
void SetFilterMask(UInt_t mask)
Int_t cH
Definition: Combine.C:26
Per-event per bin.
int Int_t
Definition: External.C:63
Definition: External.C:204
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
virtual Bool_t PostEvent()
Various utilities used in PWGLF/FORWARD.
virtual Bool_t Configure(const char *macro="-default-")
Definition: External.C:228
Definition: External.C:212
#define PFV(N, VALUE)
void Print(Option_t *option="") const
unsigned long ULong_t
Definition: External.C:38
static const Char_t * GetTriggerString(UInt_t mask, const char *sep="&")
#define DGUARD(L, N, F,...)
static void PrintTask(const TObject &o)
virtual Bool_t Event(AliAODEvent &aod)=0
short Short_t
Definition: External.C:23
static TObject * MakeParameter(const char *name, UShort_t value)
static TH1I * MakeStatusHistogram(const char *name="status")
virtual Bool_t Connect(const char *sumFile=0, const char *resFile=0)
static UShort_t CheckForAOD()
AliAODMultEventClass * GetMultClass(const AliAODEvent &aod, Bool_t verb=true)
AliAODForwardMult * GetForward(const AliAODEvent &aod, Bool_t mc=false, Bool_t verb=true)
static ULong_t AliROOTBranch()
virtual Bool_t Finalize()=0
unsigned short UShort_t
Definition: External.C:28
virtual void StoreInformation(AliAODForwardMult &forward)
void SetCentralityAxis(UShort_t n, Short_t *bins)
Float_t GetCentrality() const
const char Option_t
Definition: External.C:48
virtual Bool_t Book()=0
TH2D * GetPrimary(const AliAODEvent &aod)
virtual const char * DefaultConfig() const
AliAODCentralMult * GetCentral(const AliAODEvent &aod, Bool_t mc=false, Bool_t verb=true)
bool Bool_t
Definition: External.C:53
static Bool_t CheckForTask(const char *clsOrName, Bool_t cls=true)
static ULong_t AliROOTRevision()
virtual Double_t GetCentrality(AliAODEvent &event, AliAODForwardMult *forward, Int_t &qual)
Bool_t CheckEvent(UInt_t triggerMask=kInel, Double_t vzMin=-10, Double_t vzMax=10, Double_t cMin=0, Double_t cMax=100, TH1 *hist=0, TH1 *status=0, UInt_t filterMask=kDefaultFilter) const
Definition: External.C:196
virtual void UserExec(Option_t *option)
Bool_t HasCentrality() const
virtual Double_t GetIpZ(AliAODEvent &event, AliAODForwardMult *forward)