AliPhysics  d3bfcb9 (d3bfcb9)
AliBaseMCCorrectionsTask.cxx
Go to the documentation of this file.
1 //
2 // Calculate the corrections in the base regions
3 //
4 // Inputs:
5 // - AliESDEvent
6 //
7 // Outputs:
8 // - AliAODBaseMult
9 //
10 // Histograms
11 //
12 // Corrections used
13 //
15 #include "AliBaseMCTrackDensity.h"
17 #include "AliLog.h"
18 #include "AliESDEvent.h"
19 #include "AliMCEvent.h"
20 #include "AliAODForwardMult.h"
21 #include "AliForwardUtil.h"
22 #include <TH1.h>
23 #include <TH2D.h>
24 #include <TH2F.h>
25 #include <TDirectory.h>
26 #include <TTree.h>
27 #include <TList.h>
28 #include <TROOT.h>
29 #include <iostream>
30 
31 //====================================================================
32 namespace {
33  const char* GetEventName(Bool_t tr, Bool_t vtx)
34  {
35  return Form("nEvents%s%s", (tr ? "Tr" : ""), (vtx ? "Vtx" : ""));
36  }
37 }
38 
39 //====================================================================
41  : AliBaseESDTask(),
42  fInspector(),
43  fVtxBins(0),
44  fHEvents(0),
45  fHEventsTr(0),
46  fHEventsTrVtx(0),
47  fVtxAxis(),
48  fEtaAxis(),
49  fUseESDVertex(false),
50  fAfterEventSel(false)
51 {
52  //
53  // Constructor
54  //
55  // Parameters:
56  // name Name of task
57  //
58 }
59 
60 //____________________________________________________________________
63  : AliBaseESDTask(name, "", m),
64  fInspector("eventInspector"),
65  fVtxBins(0),
66  fHEvents(0),
67  fHEventsTr(0),
68  fHEventsTrVtx(0),
69  fVtxAxis(10,-10,10),
70  fEtaAxis(200,-4,6),
71  fUseESDVertex(false),
72  fAfterEventSel(false)
73 {
74  //
75  // Constructor
76  //
77  // Parameters:
78  // name Name of task
79  fBranchNames =
80  "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
81  "AliESDFMD.,SPDVertex.,PrimaryVertex.";
82 }
83 
84 //____________________________________________________________________
85 void
87 {
88  if (!sat) return;
90  SetEtaAxis(240, -6, 6);
91  SetIPzMethod("displaced");
92 }
93 //____________________________________________________________________
94 void
96  Double_t max)
97 {
98  //
99  // Set the vertex axis to use
100  //
101  // Parameters:
102  // nBins Number of bins
103  // vzMin Least @f$z@f$ coordinate of interation point
104  // vzMax Largest @f$z@f$ coordinate of interation point
105  //
106  if (max < min) {
107  Double_t tmp = min;
108  min = max;
109  max = tmp;
110  }
111  /*
112  if (min < -10)
113  AliWarning(Form("Minimum vertex %f < -10, make sure you want this",min));
114  if (max > +10)
115  AliWarning(Form("Minimum vertex %f > +10, make sure you want this",max));
116  */
117  fVtxAxis.Set(nBin, min, max);
118 }
119 //____________________________________________________________________
120 void
122 {
123  //
124  // Set the vertex axis to use
125  //
126  // Parameters:
127  // axis Axis
128  //
129  if (axis.GetXbins() && axis.GetXbins()->GetArray())
130  fVtxAxis.Set(axis.GetNbins(),axis.GetXbins()->GetArray());
131  else
132  SetVertexAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
133 }
134 
135 //____________________________________________________________________
136 void
138 {
139  //
140  // Set the eta axis to use
141  //
142  // Parameters:
143  // nBins Number of bins
144  // vzMin Least @f$\eta@f$
145  // vzMax Largest @f$\eta@f$
146  //
147  if (max < min) {
148  Double_t tmp = min;
149  min = max;
150  max = tmp;
151  }
152  if (min < -4)
153  AliWarning(Form("Minimum eta %f < -4, make sure you want this",min));
154  if (max > +6)
155  AliWarning(Form("Minimum eta %f > +6, make sure you want this",max));
156  fEtaAxis.Set(nBin, min, max);
157 }
158 //____________________________________________________________________
159 void
161 {
162  //
163  // Set the eta axis to use
164  //
165  // Parameters:
166  // axis Axis
167  //
168  SetEtaAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
169 }
170 
171 //____________________________________________________________________
172 void
174 {
175  if (!fVtxBins) fVtxBins = new TObjArray(fVtxAxis.GetNbins(), 1);
176  if (fVtxBins->GetEntries() > 0) return;
177 
178  fVtxBins->SetOwner();
179  for (Int_t i = 1; i <= fVtxAxis.GetNbins(); i++) {
180  Double_t low = fVtxAxis.GetBinLowEdge(i);
181  Double_t high = fVtxAxis.GetBinUpEdge(i);
182  VtxBin* bin = CreateVtxBin(low, high);
183  fVtxBins->AddAt(bin, i);
184  bin->CreateOutputObjects(l);
185  }
186 }
187 
188 //____________________________________________________________________
189 Bool_t
191 {
192  //
193  // Create output objects
194  //
195  //
196  DefineBins(fList);
197  fNeededCorrections = 0;
198  fExtraCorrections = 0;
199 
200  fHEvents = 0;
201  TH1* vtxAxis = 0;
202  if (fVtxAxis.GetXbins() && fVtxAxis.GetXbins()->GetArray()) {
203  vtxAxis = new TH1D("vtxAxis", "Vertex axis",
204  fVtxAxis.GetNbins(), fVtxAxis.GetXbins()->GetArray());
205  fHEvents = new TH1I(GetEventName(false,false),
206  "Number of all events",
207  fVtxAxis.GetNbins(), fVtxAxis.GetXbins()->GetArray());
208  }
209  else {
210  vtxAxis = new TH1D("vtxAxis", "Vertex axis",
211  fVtxAxis.GetNbins(),
212  fVtxAxis.GetXmin(),
213  fVtxAxis.GetXmax());
214  fHEvents = new TH1I(GetEventName(false,false),
215  "Number of all events",
216  fVtxAxis.GetNbins(),
217  fVtxAxis.GetXmin(),
218  fVtxAxis.GetXmax());
219  }
220  fHEvents->SetXTitle("v_{z} [cm]");
221  fHEvents->SetYTitle("# of events");
222  fHEvents->SetFillColor(kBlue+1);
223  fHEvents->SetFillStyle(3001);
224  fHEvents->SetDirectory(0);
225  fList->Add(fHEvents);
226 
227  fHEventsTr = static_cast<TH1I*>(fHEvents->Clone(GetEventName(true, false)));
228  fHEventsTr->SetTitle("Number of triggered events");
229  fHEventsTr->SetFillColor(kRed+1);
230  fHEventsTr->SetDirectory(0);
231  fList->Add(fHEventsTr);
232 
233  fHEventsTrVtx = static_cast<TH1I*>(fHEvents->Clone(GetEventName(true,true)));
234  fHEventsTrVtx->SetTitle("Number of events w/trigger and vertex");
235  fHEventsTrVtx->SetFillColor(kMagenta+1);
236  fHEventsTrVtx->SetDirectory(0);
237  fList->Add(fHEventsTrVtx);
238 
239  // Copy axis objects to output
240  TH1* etaAxis = new TH1D("etaAxis", "Eta axis",
241  fEtaAxis.GetNbins(),
242  fEtaAxis.GetXmin(),
243  fEtaAxis.GetXmax());
244  vtxAxis->SetXTitle("IP_{#it{z}}");
245  vtxAxis->SetYTitle("dummy");
246  etaAxis->SetXTitle("#eta");
247  etaAxis->SetYTitle("dummy");
248 
249  fList->Add(vtxAxis);
250  fList->Add(etaAxis);
251 
252  AliInfo(Form("Initialising sub-routines: %p, %p",
255 
256  return true;
257 }
258 
259 //____________________________________________________________________
260 Bool_t
262 {
263  //
264  // Process each event
265  //
266  // Parameters:
267  // option Not used
268  //
269 
270  // Get the input data - MC event
271  AliMCEvent* mcEvent = MCEvent();
272  if (!mcEvent) {
273  AliWarning("No MC event found");
274  return false;
275  }
276 
277  // Some variables
278  UInt_t triggers = 0; // Trigger bits
279  Bool_t lowFlux = true; // Low flux flag
280  UShort_t iVz = 0; // Vertex bin from ESD
281  TVector3 ip(1024,1024,1000);
282  Double_t cent = -1; // Centrality
283  UShort_t iVzMc = 0; // Vertex bin from MC
284  TVector3 ipMc(1024,1024,1000);
285  Double_t b = -1; // Impact parameter
286  Double_t cMC = -1; // Centrality estimate from b
287  Int_t nPart = -1; // Number of participants
288  Int_t nBin = -1; // Number of binary collisions
289  Double_t phiR = 100; // Reaction plane from MC
290  UShort_t nClusters = 0; // Number of SPD clusters
291  // Process the data
292  UInt_t retESD = fInspector.Process(&esd, triggers, lowFlux, iVz, ip,
293  cent, nClusters);
294 
295  Bool_t isAccepted = true;
296  if(fAfterEventSel) {
297  if (retESD & AliFMDEventInspector::kNoEvent) isAccepted = false;
298  if (retESD & AliFMDEventInspector::kNoTriggers) isAccepted = false;
299  if (retESD & AliFMDEventInspector::kNoVertex) isAccepted = false;
300  if (retESD & AliFMDEventInspector::kNoFMD) isAccepted = false;
301  if (!isAccepted) return false;
302  // returns if there is not event , does not pass phys selection ,
303  // has no veretx and lack of FMD data.
304  // with good veretx outside z range it will continue
305  }
306 
307 
308  fInspector.ProcessMC(mcEvent, triggers, iVzMc, ipMc,
309  b, cMC, nPart, nBin, phiR);
310 
311  fInspector.CompareResults(ip.Z(), ipMc.Z(),
312  cent, cMC,
313  b, nPart, nBin);
314  // Only allow NSD events to contribute
315  // if (!(triggers & AliAODForwardMult::kMCNSD)) return false;
316  Bool_t isInel = triggers & AliAODForwardMult::kInel;
317  Bool_t hasVtx = retESD == AliFMDMCEventInspector::kOk;
318 
319 
320  // Fill the event count histograms
321  if (isInel) fHEventsTr->Fill(ipMc.Z());
322  if (isInel && hasVtx) fHEventsTrVtx->Fill(ipMc.Z());
323  fHEvents->Fill(ipMc.Z());
324 
325  // Now find our vertex bin object
326  VtxBin* bin = 0;
327  UShort_t usedZbin = iVzMc;
328  if (fUseESDVertex) usedZbin = iVz;
329  // if (!hasVtx) usedZbin = 0;
330 
331 
332  if (usedZbin > 0 && usedZbin <= fVtxAxis.GetNbins())
333  bin = static_cast<VtxBin*>(fVtxBins->At(usedZbin));
334  if (!bin) {
335  AliErrorF("No vertex bin object @ %d (%f)", iVzMc, ipMc.Z());
336  return false;
337  }
338 
339  return ProcessESD(esd, *mcEvent, *bin, ipMc);
340 }
341 
342 //____________________________________________________________________
343 Bool_t
345 {
346  //
347  // End of job
348  //
349  // Parameters:
350  // option Not used
351  //
352  DefineBins(fList);
354 
355  TIter next(fVtxBins);
356  VtxBin* bin = 0;
357  UShort_t iVz = 1;
358  while ((bin = static_cast<VtxBin*>(next())))
359  FinalizeVtxBin(bin, iVz++);
360 
361  return true;
362 }
363 
364 //____________________________________________________________________
365 void
367 {
368  AliBaseESDTask::Print(option);
369  std::cout << " Vertex bins: " << fVtxAxis.GetNbins() << '\n'
370  << " Vertex range: [" << fVtxAxis.GetXmin()
371  << "," << fVtxAxis.GetXmax() << "]\n"
372  << " Eta bins: " << fEtaAxis.GetNbins() << '\n'
373  << " Eta range: [" << fEtaAxis.GetXmin()
374  << "," << fEtaAxis.GetXmax() << "]"
375  << std::endl;
376 }
377 
378 //====================================================================
379 const char*
381  Double_t high)
382 {
383  static TString buf;
384  buf = Form("vtx%+05.1f_%+05.1f", low, high);
385  buf.ReplaceAll("+", "p");
386  buf.ReplaceAll("-", "m");
387  buf.ReplaceAll(".", "d");
388  return buf.Data();
389 }
390 
391 
392 //____________________________________________________________________
394  : TNamed(),
395  fPrimary(0),
396  fCounts(0)
397 {
398 }
399 //____________________________________________________________________
401  Double_t high,
402  const TAxis& axis,
403  UShort_t nPhi)
404  : TNamed(BinName(low, high),
405  Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
406  fPrimary(0),
407  fCounts(0)
408 {
409  fPrimary = new TH2D("primary", "Primaries",
410  axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
411  nPhi, 0, 2*TMath::Pi());
412  fPrimary->SetXTitle("#eta");
413  fPrimary->SetYTitle("#varphi [radians]");
414  fPrimary->Sumw2();
415  fPrimary->SetDirectory(0);
416 
417  fCounts = new TH1D("counts", "Counts", 1, 0, 1);
418  fCounts->SetXTitle("Events");
419  fCounts->SetYTitle("# of Events");
420  fCounts->SetDirectory(0);
421 }
422 
423 
424 //____________________________________________________________________
425 TList*
427 {
428  TList* d = new TList;
429  d->SetName(GetName());
430  d->SetOwner();
431  l->Add(d);
432 
433  d->Add(fPrimary);
434  d->Add(fCounts);
435 
436  return d;
437 }
438 
439 
440 //
441 // EOF
442 //
Base class for correction managers.
virtual AliBaseMCTrackDensity & GetTrackDensity()=0
virtual Bool_t FinalizeVtxBin(VtxBin *bin, UShort_t iVz)=0
double Double_t
Definition: External.C:58
static TAxis * MakeFullIpZAxis(Int_t nCenter=20)
virtual Bool_t ProcessESD(const AliESDEvent &esd, const AliMCEvent &mc, VtxBin &bin, const TVector3 &ip)=0
virtual Bool_t Event(AliESDEvent &esd)
void SetEtaAxis(Int_t nBins, Double_t etaMin, Double_t etaMax=-1000000)
virtual Bool_t CompareResults(Double_t vz, Double_t trueVz, Double_t cent, Double_t mcC, Double_t b, Int_t npart, Int_t nbin)
virtual void CreateOutputObjects(TList *list)
virtual void Print(Option_t *option="") const
void SetIPzMethod(const char *str)
virtual void CreateCorrections(TList *results)=0
UInt_t Process(const AliESDEvent *event, UInt_t &triggers, Bool_t &lowFlux, UShort_t &ivz, TVector3 &ip, Double_t &cent, UShort_t &nClusters)
Per-event per bin.
int Int_t
Definition: External.C:63
Definition: External.C:204
unsigned int UInt_t
Definition: External.C:33
static const char * BinName(Double_t low, Double_t high)
Various utilities used in PWGLF/FORWARD.
AliFMDMCEventInspector fInspector
Definition: External.C:228
Definition: External.C:212
virtual TList * CreateOutputObjects(TList *list)
UInt_t fExtraCorrections
virtual VtxBin * CreateVtxBin(Double_t low, Double_t high)=0
UInt_t ProcessMC(AliMCEvent *event, UInt_t &triggers, UShort_t &ivz, TVector3 &ip, Double_t &b, Double_t &c, Int_t &npart, Int_t &nbin, Double_t &phiR)
void SetVertexAxis(Int_t nBins, Double_t vzMin, Double_t vzMax=-1000000)
void Print(Option_t *option="") const
unsigned short UShort_t
Definition: External.C:28
const char Option_t
Definition: External.C:48
UInt_t fNeededCorrections
bool Bool_t
Definition: External.C:53
Definition: External.C:196