]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/AliAODForwardMult.cxx
Some fixes
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliAODForwardMult.cxx
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 //
17 #include "AliAODForwardMult.h"
18 #include <TBrowser.h>
19 #include <iostream>
20 #include <TMath.h>
21 #include <TObjString.h>
22 #include <TObjArray.h>
23 #include "AliLog.h"
24 ClassImp(AliAODForwardMult)
25 #ifdef DOXY_INPUT
26 ; // For Emacs 
27 #endif
28
29 //____________________________________________________________________
30 const Float_t AliAODForwardMult::fgkInvalidIpZ = 1e6;
31
32 //____________________________________________________________________
33 AliAODForwardMult::AliAODForwardMult()
34   : fIsMC(false),
35     fHist(),
36     fTriggers(0),
37     fIpZ(fgkInvalidIpZ), 
38     fCentrality(-1)
39 {
40   // 
41   // Constructor 
42   // 
43 }
44
45 //____________________________________________________________________
46 AliAODForwardMult::AliAODForwardMult(Bool_t isMC) 
47   : fIsMC(isMC),
48     fHist("forwardMult", "d^{2}N_{ch}/d#etad#varphi in the forward regions", 
49           200, -4, 6, 20, 0, 2*TMath::Pi()),
50     fTriggers(0),
51     fIpZ(fgkInvalidIpZ), 
52     fCentrality(-1)
53 {
54   // 
55   // Constructor 
56   // 
57   // Parameters: 
58   //  isMC   If set to true this is for MC data (effects branch name)
59   // 
60   fHist.SetXTitle("#eta");
61   fHist.SetYTitle("#varphi [radians]");
62   fHist.SetZTitle("#frac{d^{2}N_{ch}}{d#etad#varphi}");
63   fHist.SetDirectory(0);
64   fHist.Sumw2();
65 }
66
67 //____________________________________________________________________
68 void
69 AliAODForwardMult::Init(const TAxis& etaAxis)
70 {
71   // Initialize the histogram with an eta axis 
72   // 
73   // Parameters: 
74   //   etaAxis       Eta axis to use 
75   // 
76   fHist.SetBins(etaAxis.GetNbins(), etaAxis.GetXmin(), etaAxis.GetXmax(), 
77                 20, 0, 2*TMath::Pi());
78 }
79
80 //____________________________________________________________________
81 void
82 AliAODForwardMult::Clear(Option_t* option)
83 {
84   // Clear (or reset) internal values 
85   // 
86   // Parameters: 
87   //  option   Passed to TH1::Reset 
88   // 
89   fHist.Reset(option);
90   fTriggers = 0;
91   fIpZ      = fgkInvalidIpZ;
92 }
93 //____________________________________________________________________
94 void
95 AliAODForwardMult::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 //____________________________________________________________________
105 void
106 AliAODForwardMult::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
116 //____________________________________________________________________
117 Bool_t
118 AliAODForwardMult::HasIpZ() const
119 {
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   // 
125   return TMath::Abs(fIpZ - fgkInvalidIpZ) > 1;
126 }
127
128 //____________________________________________________________________
129 UShort_t
130 AliAODForwardMult::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 
137   return UShort_t(fHist.GetBinContent(0,0));
138 }
139
140 //____________________________________________________________________
141 UShort_t
142 AliAODForwardMult::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 
149   return UShort_t(fHist.GetBinContent(fHist.GetNbinsX()+1,0));
150 }
151
152 //____________________________________________________________________
153 void
154 AliAODForwardMult::Browse(TBrowser* b)
155 {
156   // Browse this object 
157   // 
158   // Parameters: 
159   //   b   Browser to use 
160   static TObjString ipz;
161   static TObjString trg;
162   static TObjString cnt;
163   ipz = Form("ip_z=%fcm", fIpZ);
164   trg = GetTriggerString(fTriggers);
165   cnt = Form("%+6.1f%%", fCentrality);
166   b->Add(&fHist);
167   b->Add(&ipz);
168   b->Add(&trg);
169   b->Add(&cnt);
170 }
171
172 //____________________________________________________________________
173 const Char_t*
174 AliAODForwardMult::GetTriggerString(UInt_t mask)
175 {
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 
182   static TString trg;
183   trg = "";
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 ");
192   return trg.Data();
193 }
194   
195 //____________________________________________________________________
196 TH1I*
197 AliAODForwardMult::MakeTriggerHistogram(const char* name) 
198 {
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   //
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");
226   ret->GetXaxis()->SetBinLabel(kBinOffline,     "w/Offline");
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 }
235 //____________________________________________________________________
236 UInt_t 
237 AliAODForwardMult::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;
250     else 
251       AliWarningGeneral("MakeTriggerMask", 
252                         Form("Unknown trigger %s", s.Data()));
253   }
254   return trgMask;
255 }
256
257 //____________________________________________________________________
258 Bool_t
259 AliAODForwardMult::CheckEvent(Int_t    triggerMask,
260                               Double_t vzMin, Double_t vzMax,
261                               UShort_t cMin,  UShort_t cMax, 
262                               TH1*     hist) const
263 {
264   // 
265   // Check if event meets the passses requirements.   
266   //
267   // It returns true if @e all of the following is true 
268   //
269   // - The trigger is within the bit mask passed.
270   // - The vertex is within the specified limits. 
271   // - The centrality is within the specified limits, or if lower
272   //   limit is equal to or larger than the upper limit.
273   // 
274   // If a histogram is passed in the last parameter, then that
275   // histogram is filled with the trigger bits. 
276   // 
277   // Parameters:
278   //    triggerMask  Trigger mask
279   //    vzMin        Minimum @f$ v_z@f$ (in centimeters)
280   //    vzMax        Maximum @f$ v_z@f$ (in centimeters) 
281   //    cMin         Minimum centrality (in percent)
282   //    cMax         Maximum centrality (in percent)
283   //    hist         Histogram to fill 
284   // 
285   // Return:
286   //    @c true if the event meets the requirements 
287   //
288   if (cMin < cMax && (cMin > fCentrality || cMax <= fCentrality)) return false;
289
290   if (hist) { 
291     hist->AddBinContent(kBinAll);
292     if (IsTriggerBits(kB|triggerMask))  hist->AddBinContent(kBinB);
293     if (IsTriggerBits(kA|triggerMask))  hist->AddBinContent(kBinA);
294     if (IsTriggerBits(kC|triggerMask))  hist->AddBinContent(kBinC);
295     if (IsTriggerBits(kE|triggerMask))  hist->AddBinContent(kBinE);
296     if (IsTriggerBits(kB|kInel))        hist->AddBinContent(kBinInel);
297     if (IsTriggerBits(kB|kInelGt0))     hist->AddBinContent(kBinInelGt0);
298     if (IsTriggerBits(kB|kNSD))         hist->AddBinContent(kBinNSD);
299     if (IsTriggerBits(kPileUp))         hist->AddBinContent(kBinPileUp);
300     if (IsTriggerBits(kMCNSD))          hist->AddBinContent(kBinMCNSD);
301     if (IsTriggerBits(kOffline))        hist->AddBinContent(kBinOffline);
302   }
303   // Check if we have an event of interest. 
304   if (!IsTriggerBits(triggerMask|kB)) return false;
305   
306   // Check for pileup
307   if (IsTriggerBits(kPileUp)) return false;
308   if (hist) hist->AddBinContent(kWithTrigger);
309   
310   // Check that we have a valid vertex
311   if (!HasIpZ()) return false;
312   if (hist) hist->AddBinContent(kWithVertex);
313
314   // Check that vertex is within cuts 
315   if (!InRange(vzMin, vzMax)) return false;
316   if (hist) hist->AddBinContent(kAccepted);
317   
318   return true;
319 }
320
321 //____________________________________________________________________
322 void
323 AliAODForwardMult::Print(Option_t* option) const
324 {
325   // Print this object 
326   // 
327   // Parameters: 
328   //  option   Passed to TH1::Print 
329   fHist.Print(option);
330   UShort_t sys = GetSystem();
331   TString  str = "unknown";
332   switch (sys) { 
333   case 1:  str = "pp"; break;
334   case 2:  str = "PbPb"; break;
335   }
336   std::cout << "Ipz:         " << fIpZ << "cm " << (HasIpZ() ? "" : "in") 
337             << "valid\n"
338             << "Triggers:    " << GetTriggerString(fTriggers) 
339             << "sNN:         " << GetSNN() << "GeV\n" 
340             << "System:      " << str 
341             << "Centrality:  " << fCentrality << "%" 
342             << std::endl;
343 }
344
345 //____________________________________________________________________
346 //
347 // EOF
348 //