Belle II Software  release-05-02-19
SVDSummaryPlots.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Giulia Casarosa *
7  * *
8  * This software is provided "as is" without any warranty. *
9  * WARNING! Have the potential to cause addiction, but not always... *
10  **************************************************************************/
11 
12 #pragma once
13 #include <vxd/dataobjects/VxdID.h>
14 #include <string>
15 #include <regex>
16 #include <TH2F.h>
17 #include <TProfile.h>
18 
19 namespace Belle2 {
26  class SVDSummaryPlots: public TObject {
27 
28  public:
31  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 
50  ~SVDSummaryPlots() { clean(); };
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 
85  float getValue(int layer, int ladder, int sensor, int view)
86  {
87  int bin = m_histos[view]->FindBin(ladder, findBinY(layer, sensor));
88  return getHistogram(view)->GetBinContent(bin);
89  }
90 
92  void fill(int layer, int ladder, int sensor, int view, float value)
93  {
94  getHistogram(view)->Fill(ladder, findBinY(layer, sensor), value);
95  }
96 
98  void fill(const VxdID& vxdID, int view, float value)
99  {
100  int layer = vxdID.getLayerNumber();
101  int ladder = vxdID.getLadderNumber();
102  int sensor = vxdID.getSensorNumber();
103 
104  getHistogram(view)->Fill(ladder, findBinY(layer, sensor), value);
105 
106  }
107 
109  void fill(const VxdID& vxdID, bool isU, float value)
110  {
111  int view = isU ? UIndex : VIndex;
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 
121  void customizeString(std::string& base, bool isU)
122  {
123  std::string view = isU ? "U" : "V" ;
124  base = std::regex_replace(base, std::regex("[@]view") , view);
125  std::string side = isU ? "P" : "N" ;
126  base = std::regex_replace(base, std::regex("[@]side") , side);
127  }
128 
130  void clean()
131  {
132  delete m_histos[0];
133  delete m_histos[1];
134  }
135 
136 
137 
138 
139  private:
140 
142  Int_t findBinY(Int_t layer, Int_t sensor)
143  {
144 
145  if (layer == 3)
146  return sensor; //2
147  if (layer == 4)
148  return 2 + 1 + sensor; //6
149  if (layer == 5)
150  return 6 + 1 + sensor; // 11
151  if (layer == 6)
152  return 11 + 1 + sensor; // 17
153  else
154  return -1;
155  }
156 
157  TH2F* m_histos[2];
159  TH2F* m_defaultHistogram;
162  void customize(TH2F& histogram, int view)
163  {
164 
165  const int nY = 19;
166  TString Ylabels[nY] = {"", "L3.x.1", "L3.x.2",
167  "", "L4.x.1", "L4.x.2", "L4.x.3",
168  "", "L5.x.1", "L5.x.2", "L5.x.3", "L5.x.4",
169  "", "L6.x.1", "L6.x.2", "L6.x.3", "L6.x.4", "L6.x.5", ""
170  };
171 
172  histogram.SetMarkerSize(1.1);
173  histogram.GetXaxis()->SetTitle("ladder number");
174  histogram.GetXaxis()->SetLabelSize(0.04);
175  for (unsigned short i = 0; i < nY; i++)
176  histogram.GetYaxis()->SetBinLabel(i + 1, Ylabels[i].Data());
177 
178  bool isU = view == UIndex;
179  std::string name = histogram.GetName();
180  customizeString(name, isU);
181  histogram.SetName(name.c_str());
182 
183  std::string title = histogram.GetTitle();
184  customizeString(title, isU);
185  histogram.SetTitle(title.c_str());
186 
187  std::string xAxis = histogram.GetXaxis()->GetTitle();
188  customizeString(xAxis, isU);
189  histogram.SetXTitle(xAxis.c_str());
190 
191  std::string yAxis = histogram.GetYaxis()->GetTitle();
192  customizeString(yAxis, isU);
193  histogram.SetYTitle(yAxis.c_str());
194 
195  std::string zAxis = histogram.GetZaxis()->GetTitle();
196  customizeString(zAxis, isU);
197  histogram.SetZTitle(zAxis.c_str());
198 
199  }
200 
201 
203  };
204 
205 
207 }
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::SVDSummaryPlots::m_defaultHistogram
TH2F * m_defaultHistogram
default histograms
Definition: SVDSummaryPlots.h:168
Belle2::SVDSummaryPlots::getHistogram
TH2F * getHistogram(int view)
get a reference to the histogram for
Definition: SVDSummaryPlots.h:68
Belle2::VxdID::getLadderNumber
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:108
Belle2::SVDSummaryPlots::fill
void fill(int layer, int ladder, int sensor, int view, float value)
fill the histogram for
Definition: SVDSummaryPlots.h:101
Belle2::SVDSummaryPlots::customizeString
void customizeString(std::string &base, bool isU)
replaces layer ladder sensor view and apv with the current numbers
Definition: SVDSummaryPlots.h:130
Belle2::SVDSummaryPlots::ClassDef
ClassDef(SVDSummaryPlots, 1)
needed by root
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVDSummaryPlots::customize
void customize(TH2F &histogram, int view)
customize the histogram with the sensor, view
Definition: SVDSummaryPlots.h:171
Belle2::SVDSummaryPlots
class to summarize SVD quantities per sensor and side
Definition: SVDSummaryPlots.h:35
Belle2::VxdID::getSensorNumber
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:110
Belle2::SVDSummaryPlots::SVDSummaryPlots
SVDSummaryPlots()
Default constructor.
Definition: SVDSummaryPlots.h:39
Belle2::SVDSummaryPlots::findBinY
Int_t findBinY(Int_t layer, Int_t sensor)
find the Y bin given the layer and sensor number
Definition: SVDSummaryPlots.h:151
Belle2::SVDSummaryPlots::m_histos
TH2F * m_histos[2]
vector containing the U and V histograms
Definition: SVDSummaryPlots.h:166
Belle2::SVDSummaryPlots::~SVDSummaryPlots
~SVDSummaryPlots()
clean everything in the destructor
Definition: SVDSummaryPlots.h:59
Belle2::SVDSummaryPlots::clean
void clean()
delete pointers
Definition: SVDSummaryPlots.h:139
Belle2::VxdID::getLayerNumber
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:106
Belle2::SVDSummaryPlots::E_side
E_side
This enumeration assure the same semantic of the isU methods defined by Peter Kv.
Definition: SVDSummaryPlots.h:63
Belle2::SVDSummaryPlots::getValue
float getValue(const VxdID &vxdID, int view)
get the value contained in the corresponding bin, given VxdID and view
Definition: SVDSummaryPlots.h:83