Fixes
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliAODForwardMult.cxx
CommitLineData
f49fc45d 1//
2// Class that contains the forward multiplicity data per event
3//
4// This class contains a histogram of
5// @f[
6// \frac{d^2N_{ch}}{d\eta d\phi}\quad,
7// @f]
8// as well as a trigger mask for each analysed event.
9//
10// The eta acceptance of the event is stored in the underflow bins of
11// the histogram. So to build the final histogram, one needs to
12// correct for this acceptance (properly weighted by the events), and
13// the vertex efficiency. This simply boils down to defining a 2D
14// histogram and summing the event histograms in that histogram. One
15// should of course also do proper book-keeping of the accepted event.
16//
7e4038b5 17#include "AliAODForwardMult.h"
18#include <TBrowser.h>
19#include <iostream>
20#include <TMath.h>
21#include <TObjString.h>
9453b19e 22#include <TObjArray.h>
23#include "AliLog.h"
7e4038b5 24ClassImp(AliAODForwardMult)
ffca499d 25#ifdef DOXY_INPUT
7e4038b5 26; // For Emacs
27#endif
28
29//____________________________________________________________________
30const Float_t AliAODForwardMult::fgkInvalidIpZ = 1e6;
31
32//____________________________________________________________________
33AliAODForwardMult::AliAODForwardMult()
f49fc45d 34 : fIsMC(false),
35 fHist(),
7e4038b5 36 fTriggers(0),
e58000b7 37 fIpZ(fgkInvalidIpZ),
38 fCentrality(-1)
f49fc45d 39{
40 //
41 // Constructor
42 //
43}
7e4038b5 44
45//____________________________________________________________________
f49fc45d 46AliAODForwardMult::AliAODForwardMult(Bool_t isMC)
47 : fIsMC(isMC),
48 fHist("forwardMult", "d^{2}N_{ch}/d#etad#varphi in the forward regions",
7e4038b5 49 200, -4, 6, 20, 0, 2*TMath::Pi()),
50 fTriggers(0),
e58000b7 51 fIpZ(fgkInvalidIpZ),
52 fCentrality(-1)
7e4038b5 53{
f49fc45d 54 //
55 // Constructor
56 //
57 // Parameters:
58 // isMC If set to true this is for MC data (effects branch name)
59 //
7e4038b5 60 fHist.SetXTitle("#eta");
61 fHist.SetYTitle("#varphi [radians]");
62 fHist.SetZTitle("#frac{d^{2}N_{ch}}{d#etad#varphi}");
f49fc45d 63 fHist.SetDirectory(0);
7e4038b5 64 fHist.Sumw2();
65}
66
67//____________________________________________________________________
68void
69AliAODForwardMult::Init(const TAxis& etaAxis)
70{
f49fc45d 71 // Initialize the histogram with an eta axis
72 //
73 // Parameters:
74 // etaAxis Eta axis to use
75 //
7e4038b5 76 fHist.SetBins(etaAxis.GetNbins(), etaAxis.GetXmin(), etaAxis.GetXmax(),
77 20, 0, 2*TMath::Pi());
78}
79
80//____________________________________________________________________
81void
82AliAODForwardMult::Clear(Option_t* option)
83{
f49fc45d 84 // Clear (or reset) internal values
85 //
86 // Parameters:
87 // option Passed to TH1::Reset
88 //
7e4038b5 89 fHist.Reset(option);
90 fTriggers = 0;
91 fIpZ = fgkInvalidIpZ;
92}
b2e7f2d6 93//____________________________________________________________________
94void
95AliAODForwardMult::SetSNN(UShort_t snn)
96{
97 // set the center of mass energy per nucleon pair (GeV).
98 // This is stored in bin (0,0) of the histogram
99 //
100 // Parameters:
101 // sNN Center of mass energy per nuclean
102 fHist.SetBinContent(0,0,snn);
103}
104//____________________________________________________________________
105void
106AliAODForwardMult::SetSystem(UShort_t sys)
107{
108 // set the center of mass energy per nucleon pair (GeV).
109 // This is stored in bin (N+1,0) of the histogram
110 //
111 // Parameters:
112 // sys Collision system number
113 fHist.SetBinContent(fHist.GetNbinsX()+1,0,sys);
114}
115
7e4038b5 116//____________________________________________________________________
117Bool_t
118AliAODForwardMult::HasIpZ() const
119{
f49fc45d 120 // Check if we have valid z coordinate of the interaction point
121 //
122 // Return:
123 // true if the z coordinate of the interaction point is valid
124 //
7e4038b5 125 return TMath::Abs(fIpZ - fgkInvalidIpZ) > 1;
126}
127
b2e7f2d6 128//____________________________________________________________________
129UShort_t
130AliAODForwardMult::GetSNN() const
131{
132 // set the center of mass energy per nucleon pair (GeV).
133 // This is stored in bin (0,0) of the histogram
134 //
135 // Parameters:
136 // sNN Center of mass energy per nuclean
8e2bb72a 137 return UShort_t(fHist.GetBinContent(0,0));
b2e7f2d6 138}
139
140//____________________________________________________________________
141UShort_t
142AliAODForwardMult::GetSystem() const
143{
144 // set the center of mass energy per nucleon pair (GeV).
145 // This is stored in bin (N+1,0) of the histogram
146 //
147 // Parameters:
148 // sNN Center of mass energy per nuclean
8e2bb72a 149 return UShort_t(fHist.GetBinContent(fHist.GetNbinsX()+1,0));
b2e7f2d6 150}
151
7e4038b5 152//____________________________________________________________________
153void
154AliAODForwardMult::Browse(TBrowser* b)
155{
f49fc45d 156 // Browse this object
157 //
158 // Parameters:
159 // b Browser to use
7e4038b5 160 static TObjString ipz;
161 static TObjString trg;
e58000b7 162 static TObjString cnt;
7e4038b5 163 ipz = Form("ip_z=%fcm", fIpZ);
164 trg = GetTriggerString(fTriggers);
e58000b7 165 cnt = Form("%+6.1f%%", fCentrality);
7e4038b5 166 b->Add(&fHist);
167 b->Add(&ipz);
168 b->Add(&trg);
e58000b7 169 b->Add(&cnt);
7e4038b5 170}
171
172//____________________________________________________________________
173const Char_t*
174AliAODForwardMult::GetTriggerString(UInt_t mask)
175{
f49fc45d 176 // Get a string that describes the triggers
177 //
178 // Parameters:
179 // mask Bit pattern of triggers
180 // Return:
181 // Character string representation of mask
7e4038b5 182 static TString trg;
183 trg = "";
e58000b7 184 if ((mask & kInel) != 0x0) trg.Append("INEL ");
185 if ((mask & kInelGt0) != 0x0) trg.Append("INEL>0 ");
186 if ((mask & kNSD) != 0x0) trg.Append("NSD ");
187 if ((mask & kA) != 0x0) trg.Append("A ");
188 if ((mask & kB) != 0x0) trg.Append("B ");
189 if ((mask & kC) != 0x0) trg.Append("C ");
190 if ((mask & kE) != 0x0) trg.Append("E ");
191 if ((mask & kMCNSD) != 0x0) trg.Append("MCNSD ");
7e4038b5 192 return trg.Data();
193}
194
e938e22b 195//____________________________________________________________________
196TH1I*
197AliAODForwardMult::MakeTriggerHistogram(const char* name)
198{
ffca499d 199 //
200 // Make a histogram to record triggers in.
201 //
202 // The bins defined by the trigger enumeration in this class. One
203 // can use this enumeration to retrieve the number of triggers for
204 // each class.
205 //
206 // Parameters:
207 // name Name of the histogram
208 //
209 // Return:
210 // Newly allocated histogram
211 //
e938e22b 212 TH1I* ret = new TH1I(name, "Triggers", kAccepted+1, -.5, kAccepted+.5);
213 ret->SetYTitle("Events");
214 ret->SetFillColor(kRed+1);
215 ret->SetFillStyle(3001);
216 ret->GetXaxis()->SetBinLabel(kBinAll, "All events");
217 ret->GetXaxis()->SetBinLabel(kBinB, "w/B trigger");
218 ret->GetXaxis()->SetBinLabel(kBinA, "w/A trigger");
219 ret->GetXaxis()->SetBinLabel(kBinC, "w/C trigger");
220 ret->GetXaxis()->SetBinLabel(kBinE, "w/E trigger");
221 ret->GetXaxis()->SetBinLabel(kBinInel, "Minimum Bias");
222 ret->GetXaxis()->SetBinLabel(kBinInelGt0, "INEL>0");
223 ret->GetXaxis()->SetBinLabel(kBinNSD, "NSD");
224 ret->GetXaxis()->SetBinLabel(kBinMCNSD, "NSD (MC truth)");
225 ret->GetXaxis()->SetBinLabel(kBinPileUp, "w/Pileup");
0be6c8cd 226 ret->GetXaxis()->SetBinLabel(kBinOffline, "w/Offline");
e938e22b 227 ret->GetXaxis()->SetBinLabel(kWithVertex, "w/Vertex");
228 ret->GetXaxis()->SetBinLabel(kWithTrigger, "w/Selected trigger");
229 ret->GetXaxis()->SetBinLabel(kAccepted, "Accepted by cut");
230 ret->GetXaxis()->SetNdivisions(kAccepted, false);
231 ret->SetStats(0);
232
233 return ret;
234}
9453b19e 235//____________________________________________________________________
236UInt_t
237AliAODForwardMult::MakeTriggerMask(const char* what)
238{
239 UShort_t trgMask = 0;
240 TString trgs(what);
241 trgs.ToUpper();
242 TObjString* trg;
243 TIter next(trgs.Tokenize(" ,|"));
244 while ((trg = static_cast<TObjString*>(next()))) {
245 TString s(trg->GetString());
246 if (s.IsNull()) continue;
247 if (s.CompareTo("INEL") == 0) trgMask |= AliAODForwardMult::kInel;
248 else if (s.CompareTo("INEL>0")== 0) trgMask |= AliAODForwardMult::kInelGt0;
249 else if (s.CompareTo("NSD") == 0) trgMask |= AliAODForwardMult::kNSD;
b6b35c77 250 else if (s.CompareTo("B") == 0) trgMask |= AliAODForwardMult::kB;
251 else if (s.CompareTo("A") == 0) trgMask |= AliAODForwardMult::kA;
252 else if (s.CompareTo("C") == 0) trgMask |= AliAODForwardMult::kC;
253 else if (s.CompareTo("E") == 0) trgMask |= AliAODForwardMult::kE;
9453b19e 254 else
255 AliWarningGeneral("MakeTriggerMask",
256 Form("Unknown trigger %s", s.Data()));
257 }
258 return trgMask;
259}
e938e22b 260
261//____________________________________________________________________
262Bool_t
263AliAODForwardMult::CheckEvent(Int_t triggerMask,
264 Double_t vzMin, Double_t vzMax,
265 UShort_t cMin, UShort_t cMax,
266 TH1* hist) const
267{
ffca499d 268 //
269 // Check if event meets the passses requirements.
270 //
271 // It returns true if @e all of the following is true
272 //
273 // - The trigger is within the bit mask passed.
274 // - The vertex is within the specified limits.
275 // - The centrality is within the specified limits, or if lower
276 // limit is equal to or larger than the upper limit.
277 //
278 // If a histogram is passed in the last parameter, then that
279 // histogram is filled with the trigger bits.
280 //
281 // Parameters:
282 // triggerMask Trigger mask
283 // vzMin Minimum @f$ v_z@f$ (in centimeters)
284 // vzMax Maximum @f$ v_z@f$ (in centimeters)
285 // cMin Minimum centrality (in percent)
286 // cMax Maximum centrality (in percent)
287 // hist Histogram to fill
288 //
289 // Return:
290 // @c true if the event meets the requirements
291 //
e938e22b 292 if (cMin < cMax && (cMin > fCentrality || cMax <= fCentrality)) return false;
293
294 if (hist) {
295 hist->AddBinContent(kBinAll);
0be6c8cd 296 if (IsTriggerBits(kB|triggerMask)) hist->AddBinContent(kBinB);
297 if (IsTriggerBits(kA|triggerMask)) hist->AddBinContent(kBinA);
298 if (IsTriggerBits(kC|triggerMask)) hist->AddBinContent(kBinC);
299 if (IsTriggerBits(kE|triggerMask)) hist->AddBinContent(kBinE);
300 if (IsTriggerBits(kB|kInel)) hist->AddBinContent(kBinInel);
301 if (IsTriggerBits(kB|kInelGt0)) hist->AddBinContent(kBinInelGt0);
302 if (IsTriggerBits(kB|kNSD)) hist->AddBinContent(kBinNSD);
303 if (IsTriggerBits(kPileUp)) hist->AddBinContent(kBinPileUp);
304 if (IsTriggerBits(kMCNSD)) hist->AddBinContent(kBinMCNSD);
305 if (IsTriggerBits(kOffline)) hist->AddBinContent(kBinOffline);
e938e22b 306 }
307 // Check if we have an event of interest.
0be6c8cd 308 if (!IsTriggerBits(triggerMask|kB)) return false;
e938e22b 309
310 // Check for pileup
311 if (IsTriggerBits(kPileUp)) return false;
312 if (hist) hist->AddBinContent(kWithTrigger);
313
314 // Check that we have a valid vertex
b6b35c77 315 if (vzMin < vzMax && !HasIpZ()) return false;
e938e22b 316 if (hist) hist->AddBinContent(kWithVertex);
317
318 // Check that vertex is within cuts
b6b35c77 319 if (vzMin < vzMax && !InRange(vzMin, vzMax)) return false;
e938e22b 320 if (hist) hist->AddBinContent(kAccepted);
321
322 return true;
323}
324
7e4038b5 325//____________________________________________________________________
326void
327AliAODForwardMult::Print(Option_t* option) const
328{
f49fc45d 329 // Print this object
330 //
331 // Parameters:
332 // option Passed to TH1::Print
7e4038b5 333 fHist.Print(option);
8e2bb72a 334 UShort_t sys = GetSystem();
335 TString str = "unknown";
336 switch (sys) {
337 case 1: str = "pp"; break;
338 case 2: str = "PbPb"; break;
339 }
e58000b7 340 std::cout << "Ipz: " << fIpZ << "cm " << (HasIpZ() ? "" : "in")
7e4038b5 341 << "valid\n"
e58000b7 342 << "Triggers: " << GetTriggerString(fTriggers)
343 << "sNN: " << GetSNN() << "GeV\n"
344 << "System: " << str
345 << "Centrality: " << fCentrality << "%"
8e2bb72a 346 << std::endl;
7e4038b5 347}
348
349//____________________________________________________________________
350//
351// EOF
352//