Belle II Software  release-08-00-10
SVDSummaryPlots.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 #include <vxd/dataobjects/VxdID.h>
11 #include <string>
12 #include <regex>
13 #include <TH2F.h>
14 #include <TProfile.h>
15 
16 namespace Belle2 {
23  class SVDSummaryPlots: public TObject {
24 
25  public:
28  SVDSummaryPlots("", "") {};
34  SVDSummaryPlots(TString name, TString title)
35  {
36  m_defaultHistogram = new TH2F(name.Data(), title.Data(),
37  16, 0.5, 16.5,
38  19, 0, 19);
39 
40  for (int view = VIndex ; view < UIndex + 1; view++) {
41  TH2F h(*m_defaultHistogram);
42 
43  customize(h, view);
44  m_histos[view] = new TH2F(h);
45  }
46  }
47 
48 
51 
54  enum E_side { VIndex = 0, UIndex = 1 };
55 
59  TH2F* getHistogram(int view)
60  {
61  TH2F* returnValue = m_defaultHistogram;
62  try {
63  returnValue = m_histos[view];
64  } catch (...) {
65  B2WARNING("Unexpected view: " << view);
66 
67  returnValue = m_defaultHistogram;
68  }
69 
70  return returnValue;
71  }
72 
74  float getValue(const VxdID& vxdID, int view)
75  {
76  int layer = vxdID.getLayerNumber();
77  int ladder = vxdID.getLadderNumber();
78  int sensor = vxdID.getSensorNumber();
79 
80  int bin = m_histos[view]->FindBin(ladder, findBinY(layer, sensor));
81  return getHistogram(view)->GetBinContent(bin);
82  }
83 
90  float getValue(int layer, int ladder, int sensor, int view)
91  {
92  int bin = m_histos[view]->FindBin(ladder, findBinY(layer, sensor));
93  return getHistogram(view)->GetBinContent(bin);
94  }
95 
103  void fill(int layer, int ladder, int sensor, int view, float value)
104  {
105  getHistogram(view)->Fill(ladder, findBinY(layer, sensor), value);
106  }
107 
111  void fill(const VxdID& vxdID, int view, float value)
112  {
113  int layer = vxdID.getLayerNumber();
114  int ladder = vxdID.getLadderNumber();
115  int sensor = vxdID.getSensorNumber();
116 
117  getHistogram(view)->Fill(ladder, findBinY(layer, sensor), value);
118 
119  }
120 
122  void fill(const VxdID& vxdID, bool isU, float value)
123  {
124  int view = isU ? UIndex : VIndex;
125 
126  int layer = vxdID.getLayerNumber();
127  int ladder = vxdID.getLadderNumber();
128  int sensor = vxdID.getSensorNumber();
129 
130  getHistogram(view)->Fill(ladder, findBinY(layer, sensor), value);
131  }
132 
134  void customizeString(std::string& base, bool isU)
135  {
136  std::string view = isU ? "U" : "V" ;
137  base = std::regex_replace(base, std::regex("[@]view"), view);
138  std::string side = isU ? "P" : "N" ;
139  base = std::regex_replace(base, std::regex("[@]side"), side);
140  }
141 
143  void clean()
144  {
145  delete m_histos[0];
146  delete m_histos[1];
147  }
148 
149 
150 
151 
152  private:
153 
155  Int_t findBinY(Int_t layer, Int_t sensor)
156  {
157 
158  if (layer == 3)
159  return sensor; //2
160  if (layer == 4)
161  return 2 + 1 + sensor; //6
162  if (layer == 5)
163  return 6 + 1 + sensor; // 11
164  if (layer == 6)
165  return 11 + 1 + sensor; // 17
166  else
167  return -1;
168  }
169 
170  TH2F* m_histos[2];
175  void customize(TH2F& histogram, int view)
176  {
177 
178  const int nY = 19;
179  TString Ylabels[nY] = {"", "L3.x.1", "L3.x.2",
180  "", "L4.x.1", "L4.x.2", "L4.x.3",
181  "", "L5.x.1", "L5.x.2", "L5.x.3", "L5.x.4",
182  "", "L6.x.1", "L6.x.2", "L6.x.3", "L6.x.4", "L6.x.5", ""
183  };
184 
185  histogram.SetMarkerSize(1.1);
186  histogram.GetXaxis()->SetTitle("ladder number");
187  histogram.GetXaxis()->SetLabelSize(0.04);
188  for (unsigned short i = 0; i < nY; i++)
189  histogram.GetYaxis()->SetBinLabel(i + 1, Ylabels[i].Data());
190 
191  bool isU = view == UIndex;
192  std::string name = histogram.GetName();
193  customizeString(name, isU);
194  histogram.SetName(name.c_str());
195 
196  std::string title = histogram.GetTitle();
197  customizeString(title, isU);
198  histogram.SetTitle(title.c_str());
199 
200  std::string xAxis = histogram.GetXaxis()->GetTitle();
201  customizeString(xAxis, isU);
202  histogram.SetXTitle(xAxis.c_str());
203 
204  std::string yAxis = histogram.GetYaxis()->GetTitle();
205  customizeString(yAxis, isU);
206  histogram.SetYTitle(yAxis.c_str());
207 
208  std::string zAxis = histogram.GetZaxis()->GetTitle();
209  customizeString(zAxis, isU);
210  histogram.SetZTitle(zAxis.c_str());
211 
212  }
213 
214 
216  };
217 
218 
220 }
class to summarize SVD quantities per sensor and side
TH2F * m_histos[2]
vector containing the U and V histograms
void fill(const VxdID &vxdID, int view, float value)
fill the histogram for
~SVDSummaryPlots()
clean everything in the destructor
void clean()
delete pointers
Int_t findBinY(Int_t layer, Int_t sensor)
find the Y bin given the layer and sensor number
void customizeString(std::string &base, bool isU)
replaces layer ladder sensor view and apv with the current numbers
SVDSummaryPlots(TString name, TString title)
this is the default constructor
float getValue(const VxdID &vxdID, int view)
get the value contained in the corresponding bin, given VxdID and view
void fill(int layer, int ladder, int sensor, int view, float value)
fill the histogram for
void fill(const VxdID &vxdID, bool isU, float value)
fill the histogram for
TH2F * getHistogram(int view)
get a reference to the histogram for
SVDSummaryPlots()
Default constructor.
float getValue(int layer, int ladder, int sensor, int view)
get the value contained in the corresponding bin, given
void customize(TH2F &histogram, int view)
customize the histogram with the sensor, view
TH2F * m_defaultHistogram
default histograms
E_side
This enumeration assure the same semantic of the isU methods defined by Peter Kv.
ClassDef(SVDSummaryPlots, 1)
needed by root
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:100
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:98
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
Abstract base class for different kinds of events.