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