]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/AliAODForwardHeader.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliAODForwardHeader.cxx
1 //
2 // Class that contains header information for each event.  
3 //
4 // Used by standalone PWGLF/Forward AOD productions 
5 //
6 #include "AliAODForwardHeader.h"
7 #include <TBrowser.h>
8 #include <iostream>
9 #include <TMath.h>
10 #include <TObjString.h>
11 #include <TObjArray.h>
12 #include "AliLog.h"
13 ClassImp(AliAODForwardHeader)
14 #ifdef DOXY_INPUT
15 ; // For Emacs 
16 #endif
17
18 //____________________________________________________________________
19 const Float_t AliAODForwardHeader::fgkInvalidIpZ = 1e6;
20
21 //____________________________________________________________________
22 void
23 AliAODForwardHeader::Clear(Option_t* /*option*/)
24 {
25   // Clear (or reset) internal values 
26   // 
27   // Parameters: 
28   //  option   Passed to TH1::Reset 
29   // 
30   fTriggers   = 0;
31   fIpZ        = fgkInvalidIpZ;
32   fCentrality = -1;
33   fNClusters  = 0;
34 }
35 //____________________________________________________________________
36 Bool_t
37 AliAODForwardHeader::HasIpZ() const
38 {
39   // Check if we have valid z coordinate of the interaction point 
40   // 
41   // Return:
42   //   true if the z coordinate of the interaction point is valid 
43   // 
44   return TMath::Abs(fIpZ - fgkInvalidIpZ) > 1;
45 }
46 //____________________________________________________________________
47 void
48 AliAODForwardHeader::Browse(TBrowser* b)
49 {
50   // Browse this object 
51   // 
52   // Parameters: 
53   //   b   Browser to use 
54   static TObjString ipz;
55   static TObjString trg;
56   static TObjString cnt;
57   static TObjString ncl;
58   ipz = Form("ip_z=%fcm", fIpZ);
59   trg = GetTriggerString(fTriggers);
60   cnt = Form("%+6.1f%%", fCentrality);
61   ncl = Form("%d clusters", fNClusters);
62   b->Add(&fHist);
63   b->Add(&ipz);
64   b->Add(&trg);
65   b->Add(&cnt);
66   b->Add(&ncl);
67 }
68
69 namespace { 
70   void AppendAnd(TString& trg, const TString& what)
71   {
72     if (!trg.IsNull()) trg.Append(" & ");
73     trg.Append(what);
74   }
75 }
76 //____________________________________________________________________
77 const Char_t*
78 AliAODForwardHeader::GetTriggerString(UInt_t mask)
79 {
80   // Get a string that describes the triggers 
81   // 
82   // Parameters: 
83   //   mask  Bit pattern of triggers 
84   // Return: 
85   //   Character string representation of mask 
86   static TString trg;
87   trg = "";
88   if ((mask & kInel)        != 0x0) AppendAnd(trg, "INEL");
89   if ((mask & kInelGt0)     != 0x0) AppendAnd(trg, "INEL>0");
90   if ((mask & kNSD)         != 0x0) AppendAnd(trg, "NSD");
91   if ((mask & kV0AND)       != 0x0) AppendAnd(trg, "V0AND");
92   if ((mask & kA)           != 0x0) AppendAnd(trg, "A");
93   if ((mask & kB)           != 0x0) AppendAnd(trg, "B");
94   if ((mask & kC)           != 0x0) AppendAnd(trg, "C");
95   if ((mask & kE)           != 0x0) AppendAnd(trg, "E");
96   if ((mask & kMCNSD)       != 0x0) AppendAnd(trg, "MCNSD");
97   if ((mask & kNClusterGt0) != 0x0) AppendAnd(trg, "NCluster>0");
98   if ((mask & kSatellite)   != 0x0) AppendAnd(trg, "Satellite");
99   return trg.Data();
100 }
101 //____________________________________________________________________
102 TH1I*
103 AliAODForwardHeader::MakeTriggerHistogram(const char* name, Int_t mask) 
104 {
105   // 
106   // Make a histogram to record triggers in. 
107   //
108   // The bins defined by the trigger enumeration in this class.  One
109   // can use this enumeration to retrieve the number of triggers for
110   // each class.
111   // 
112   // Parameters:
113   //    name Name of the histogram 
114   // 
115   // Return:
116   //    Newly allocated histogram 
117   //
118   TString sel("");
119   TString andSel("");
120   if (mask > 0) {
121     sel    = GetTriggerString(mask);
122     andSel = GetTriggerString(mask & ~kB);
123     andSel.Prepend(" & ");
124   }
125   TH1I* ret = new TH1I(name, "Triggers", kAccepted+1, -.5, kAccepted+.5);
126   ret->SetYTitle("Events");
127   ret->SetFillColor(kRed+1);
128   ret->SetFillStyle(3001);
129   ret->GetXaxis()->SetBinLabel(kBinAll,         "All events");
130   ret->GetXaxis()->SetBinLabel(kBinB,           Form("B (Coll.)%s", 
131                                                      andSel.Data()));
132   ret->GetXaxis()->SetBinLabel(kBinA,           Form("A%s", andSel.Data()));
133   ret->GetXaxis()->SetBinLabel(kBinC,           Form("C%s", andSel.Data()));
134   ret->GetXaxis()->SetBinLabel(kBinE,           Form("E%s", andSel.Data()));
135   ret->GetXaxis()->SetBinLabel(kBinInel,        "Coll. & INEL");
136   ret->GetXaxis()->SetBinLabel(kBinInelGt0,     "Coll. & INEL>0");
137   ret->GetXaxis()->SetBinLabel(kBinNSD,         "Coll. & NSD");
138   ret->GetXaxis()->SetBinLabel(kBinV0AND,       "Coll. & V0AND");
139   ret->GetXaxis()->SetBinLabel(kBinMCNSD,       "NSD (MC truth)");
140   ret->GetXaxis()->SetBinLabel(kBinSatellite,   "Satellite");
141   ret->GetXaxis()->SetBinLabel(kBinPileUp,      "w/Pileup");
142   ret->GetXaxis()->SetBinLabel(kBinOffline,     "w/Offline");
143   ret->GetXaxis()->SetBinLabel(kBinNClusterGt0, "w/N_{cluster}>1");
144   ret->GetXaxis()->SetBinLabel(kWithVertex,     "w/Vertex");
145   ret->GetXaxis()->SetBinLabel(kWithTrigger,    Form("w/Selected trigger (%s)",
146                                                      sel.Data()));
147   ret->GetXaxis()->SetBinLabel(kAccepted,       "Accepted by cut");
148   ret->GetXaxis()->SetNdivisions(kAccepted, false);
149   ret->SetStats(0);
150
151   return ret;
152 }
153
154 //____________________________________________________________________
155 TH1I*
156 AliAODForwardHeader::MakeStatusHistogram(const char* name) 
157 {
158   // 
159   // Make a histogram to record status in. 
160   //
161   // The bins defined by the status enumeration in this class.  
162   // 
163   // Parameters:
164   //    name Name of the histogram 
165   // 
166   // Return:
167   //    Newly allocated histogram 
168   //
169   TH1I* ret = new TH1I(name, "Event selection status", 
170                        kWrongVertex+1, -.5, kWrongVertex+.5);
171   ret->SetYTitle("Events");
172   ret->SetFillColor(kBlue+1);
173   ret->SetFillStyle(3001);
174   ret->GetXaxis()->SetBinLabel(kGoodEvent+1,       "Good");
175   ret->GetXaxis()->SetBinLabel(kWrongCentrality+1, "Out-of-range centrality");
176   ret->GetXaxis()->SetBinLabel(kWrongTrigger+1,    "Wrong trigger");
177   ret->GetXaxis()->SetBinLabel(kIsPileup+1,        "Pile-up");
178   ret->GetXaxis()->SetBinLabel(kNoVertex+1,        "No IP_{z}");
179   ret->GetXaxis()->SetBinLabel(kWrongVertex+1,     "Out-or-range IP_{z}");
180   ret->GetXaxis()->SetNdivisions(kWrongVertex, false);
181   ret->SetStats(0);
182   return ret;
183 }
184 //____________________________________________________________________
185 UInt_t 
186 AliAODForwardHeader::MakeTriggerMask(const char* what)
187 {
188   UShort_t    trgMask = 0;
189   TString     trgs(what);
190   trgs.ToUpper();
191   TObjArray*  parts = trgs.Tokenize("&");
192   TObjString* trg;
193   TIter       next(parts);
194   while ((trg = static_cast<TObjString*>(next()))) { 
195     TString s(trg->GetString());
196     s.Strip(TString::kBoth, ' ');
197     s.ToUpper();
198     if      (s.IsNull()) continue;
199     if      (s.CompareTo("INEL")       == 0) trgMask |= kInel;
200     else if (s.CompareTo("INEL>0")     == 0) trgMask |= kInelGt0;
201     else if (s.CompareTo("INELGT0")    == 0) trgMask |= kInelGt0;
202     else if (s.CompareTo("NSD")        == 0) trgMask |= kNSD;
203     else if (s.CompareTo("V0AND")      == 0) trgMask |= kV0AND;
204     else if (s.CompareTo("MCNSD")      == 0) trgMask |= kMCNSD;
205     else if (s.CompareTo("B")          == 0) trgMask |= kB;
206     else if (s.CompareTo("A")          == 0) trgMask |= kA;
207     else if (s.CompareTo("C")          == 0) trgMask |= kC;
208     else if (s.CompareTo("SAT")        == 0) trgMask |= kSatellite;
209     else if (s.CompareTo("E")          == 0) trgMask |= kE;
210     else if (s.CompareTo("NCLUSTER>0") == 0) trgMask |= kNClusterGt0;
211     else 
212       AliWarningGeneral("MakeTriggerMask", 
213                         Form("Unknown trigger %s", s.Data()));
214   }
215   delete parts;
216   return trgMask;
217 }
218 //____________________________________________________________________
219 Bool_t
220 AliAODForwardHeader::CheckEvent(Int_t    triggerMask,
221                               Double_t vzMin, Double_t vzMax,
222                               UShort_t cMin,  UShort_t cMax, 
223                               TH1*     hist,  TH1*     status) const
224 {
225   // 
226   // Check if event meets the passses requirements.   
227   //
228   // It returns true if @e all of the following is true 
229   //
230   // - The trigger is within the bit mask passed.
231   // - The vertex is within the specified limits. 
232   // - The centrality is within the specified limits, or if lower
233   //   limit is equal to or larger than the upper limit.
234   // 
235   // If a histogram is passed in the last parameter, then that
236   // histogram is filled with the trigger bits. 
237   // 
238   // Parameters:
239   //    triggerMask  Trigger mask
240   //    vzMin        Minimum @f$ v_z@f$ (in centimeters)
241   //    vzMax        Maximum @f$ v_z@f$ (in centimeters) 
242   //    cMin         Minimum centrality (in percent)
243   //    cMax         Maximum centrality (in percent)
244   //    hist         Histogram to fill 
245   // 
246   // Return:
247   //    @c true if the event meets the requirements 
248   //
249   if (cMin < cMax && (cMin > fCentrality || cMax <= fCentrality)) {
250     if (status) status->Fill(kWrongCentrality);
251     return false;
252   }
253
254   if (hist) { 
255     Int_t tmp = triggerMask & ~kB;
256     hist->AddBinContent(kBinAll);
257     if (IsTriggerBits(kB|tmp))          hist->AddBinContent(kBinB);
258     if (IsTriggerBits(kA|tmp))          hist->AddBinContent(kBinA);
259     if (IsTriggerBits(kC|tmp))          hist->AddBinContent(kBinC);
260     if (IsTriggerBits(kE|tmp))          hist->AddBinContent(kBinE);
261     if (IsTriggerBits(kB|kInel))        hist->AddBinContent(kBinInel);
262     if (IsTriggerBits(kB|kInelGt0))     hist->AddBinContent(kBinInelGt0);
263     if (IsTriggerBits(kB|kNSD))         hist->AddBinContent(kBinNSD);
264     if (IsTriggerBits(kB|kV0AND))       hist->AddBinContent(kBinV0AND);
265     if (IsTriggerBits(kPileUp))         hist->AddBinContent(kBinPileUp);
266     if (IsTriggerBits(kMCNSD))          hist->AddBinContent(kBinMCNSD);
267     if (IsTriggerBits(kOffline))        hist->AddBinContent(kBinOffline);
268     if (IsTriggerBits(kNClusterGt0))    hist->AddBinContent(kBinNClusterGt0);
269     if (IsTriggerBits(kSatellite))      hist->AddBinContent(kBinSatellite);
270     if (IsTriggerBits(triggerMask) && !IsTriggerBits(kB|tmp))
271       Warning("CheckEvent", "event: 0x%x, mask: 0x%x, tmp: 0x%x, tmp|b: 0x%x",
272              fTriggers, triggerMask, tmp, tmp|kB);
273   }
274   // Check if we have an event of interest. 
275   Int_t mask = triggerMask; //|kB
276   if (!IsTriggerBits(mask)) { 
277     if (status) status->Fill(kWrongTrigger);
278     return false;
279   }
280   
281   // Check for pileup
282   if (IsTriggerBits(kPileUp)) {
283     if (status) status->Fill(kIsPileup);
284     return false;
285   }
286   if (hist) hist->AddBinContent(kWithTrigger);
287   
288   // Check that we have a valid vertex
289   if (vzMin < vzMax && !HasIpZ()) {
290     if (status) status->Fill(kNoVertex);
291     return false;
292   }
293   if (hist) hist->AddBinContent(kWithVertex);
294
295   // Check that vertex is within cuts 
296   if (vzMin < vzMax && !InRange(vzMin, vzMax)) {
297     if (status) status->Fill(kWrongVertex);
298     return false;
299   }
300   if (hist) hist->AddBinContent(kAccepted);
301   
302   if (status) status->Fill(kGoodEvent);
303   return true;
304 }
305
306 //____________________________________________________________________
307 void
308 AliAODForwardHeader::Print(Option_t* option) const
309 {
310   // Print this object 
311   // 
312   // Parameters: 
313   //  option   Passed to TH1::Print 
314   std::cout << "Ipz:         " << fIpZ << "cm " << (HasIpZ() ? "" : "in") 
315             << "valid\n"
316             << "Triggers:    " << GetTriggerString(fTriggers)  << "\n"
317             << "Centrality:  " << fCentrality << "%" 
318             << std::endl;
319 }
320
321 //____________________________________________________________________
322 //
323 // EOF
324 //