Belle II Software development
SVDHistograms.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 <vxd/geometry/GeoCache.h>
12#include <vxd/geometry/SensorInfoBase.h>
13#include <string>
14#include <regex>
15
16namespace Belle2 {
23 template < class H > // H is an histogram
24 class SVDHistograms: public TObject {
25
26 public:
29 SVDHistograms(H(), H(), H(), H()) {};
32 explicit SVDHistograms(const H& templateHisto):
33 SVDHistograms(templateHisto, templateHisto,
34 templateHisto, templateHisto)
35 {};
36
43 SVDHistograms(const H& templateU3, const H& templateV3,
44 const H& templateU456, const H& templateV456);
45
48
51 enum E_side { VIndex = 0, UIndex = 1 };
52
56 H* getHistogram(const VxdID& vxdID, int view)
57 {
58 H* returnValue = m_defaultHistogram;
59 try {
60 auto& layer = m_histograms.at(vxdID.getLayerNumber());
61 auto& ladder = layer.at(vxdID.getLadderNumber());
62 auto& sensor = ladder.at(vxdID.getSensorNumber());
63 returnValue = sensor.at(view);
64 } catch (...) {
65 B2WARNING("Unexpected VxdID /view. VxdID: " << (std::string)(vxdID)
66 << " view : " << view);
67
68 returnValue = m_defaultHistogram;
69 }
70
71 return returnValue;
72 }
73
74 // variable number of arguments for TH1 TH2...
76 template< class ... Types>
77 void fill(const VxdID& vxdID, int view, Types ... args)
78 {
79 getHistogram(vxdID, view)->Fill(args...);
80 }
81
82 // variable number of arguments for TH1 TH2...
84 template< class ... Types>
85 void fill(const VxdID& vxdID, bool isU, Types ... args)
86 {
87 int view = isU ? UIndex : VIndex;
88 getHistogram(vxdID, view)->Fill(args...);
89 }
90
92 void customizeString(std::string& base, const VxdID& vxdID, bool isU)
93 {
94 std::string layer = std::to_string(vxdID.getLayerNumber());
95 std::string ladder = std::to_string(vxdID.getLadderNumber());
96 std::string sensor = std::to_string(vxdID.getSensorNumber());
97 std::string view = isU ? "U" : "V" ;
98 base = std::regex_replace(base, std::regex("[@]layer"), layer);
99 base = std::regex_replace(base, std::regex("[@]ladder"), ladder);
100 base = std::regex_replace(base, std::regex("[@]sensor"), sensor);
101 base = std::regex_replace(base, std::regex("[@]view"), view);
102 std::string side = isU ? "P" : "N" ;
103 base = std::regex_replace(base, std::regex("[@]side"), side);
104 }
105
107 void clean()
108 {
109
110 for (auto& layer : m_histograms)
111 for (auto& ladder : layer)
112 for (auto& sensor : ladder)
113 for (auto& view : sensor)
114 delete view;
115 }
116
118 void reset()
119 {
120 for (auto& layer : m_histograms)
121 for (auto& ladder : layer)
122 for (auto& sensor : ladder)
123 for (auto& view : sensor)
124 view->Reset();
125 }
126
127
128 private:
129 // A t_SVDSensor is a vector of H that will have length 2.
130 // Index 0 for the V side, index 1 for the U side
131 // Please, please, pleaseeeee use SVDHistograms<...>::UIndex
132 // and SVDHistograms<...>::VIndex instead of 1 and 0 for better
133 // code readibility
134 typedef std::vector< H* > t_SVDSensor;
136 // A t_SVDLadder is a vector of t_SVDSensors
137 typedef std::vector< t_SVDSensor > t_SVDLadder;
139 // A t_SVDLayer is a vector of t_SVDLAdders
140 typedef std::vector< t_SVDLadder > t_SVDLayer;
142 // The t_SVD is a vector of t_SVDLayers
143 typedef std::vector< t_SVDLayer > t_SVD;
149 void customize(H& histogram, VxdID vxdID, int view);
152 };
153
155 template <class H>
156 SVDHistograms<H>::SVDHistograms(const H& templateU3, const H& templateV3,
157 const H& templateU456, const H& templateV456)
158 {
159 m_defaultHistogram = new H(templateU3);
160
162 for (auto layer : geoCache.getLayers(VXD::SensorInfoBase::SVD)) {
163 unsigned int layerNumber = layer.getLayerNumber();
164 if (m_histograms.size() <= layerNumber)
165 m_histograms.resize(layerNumber + 1);
166
167 for (auto ladder : geoCache.getLadders(layer)) {
168 unsigned int ladderNumber = ladder.getLadderNumber();
169 if (m_histograms[layerNumber].size() <= ladderNumber)
170 m_histograms[layerNumber].resize(ladderNumber + 1);
171
172 for (Belle2::VxdID sensor : geoCache.getSensors(ladder)) {
173 unsigned int sensorNumber = sensor.getSensorNumber();
174 if (m_histograms[layerNumber][ladderNumber].size() <= sensorNumber)
175 m_histograms[layerNumber][ladderNumber].resize(sensorNumber + 1);
176 m_histograms[layerNumber][ladderNumber][sensorNumber].resize(2);
177
178 for (int view = VIndex ; view < UIndex + 1; view++) {
179 H h = layerNumber == 3 && view == UIndex ? templateU3 :
180 layerNumber == 3 && view == VIndex ? templateV3 :
181 view == UIndex ? templateU456 : templateV456 ;
182 customize(h, sensor, view);
183 m_histograms[layerNumber][ladderNumber][sensorNumber][view] = new H(h);
184 }
185 }
186 }
187 }
188 }
189
191 template < class H >
192 void SVDHistograms<H>::customize(H& histogram, VxdID vxdID, int view)
193 {
194 bool isU = view == UIndex;
195 std::string name = histogram.GetName();
196 customizeString(name, vxdID, isU);
197 histogram.SetName(name.c_str());
198
199 std::string title = histogram.GetTitle();
200 customizeString(title, vxdID, isU);
201 histogram.SetTitle(title.c_str());
202
203 std::string xAxis = histogram.GetXaxis()->GetTitle();
204 customizeString(xAxis, vxdID, isU);
205 histogram.SetXTitle(xAxis.c_str());
206
207 std::string yAxis = histogram.GetYaxis()->GetTitle();
208 customizeString(yAxis, vxdID, isU);
209 histogram.SetYTitle(yAxis.c_str());
210
211 std::string zAxis = histogram.GetZaxis()->GetTitle();
212 customizeString(zAxis, vxdID, isU);
213 histogram.SetZTitle(zAxis.c_str());
214
215 }
217}
template class for SVd histograms
Definition: SVDHistograms.h:24
t_SVD m_histograms
the vector of vector ... that contains all histograms
~SVDHistograms()
clean everything in the destructor
Definition: SVDHistograms.h:47
void fill(const VxdID &vxdID, bool isU, Types ... args)
fill the histogram for
Definition: SVDHistograms.h:85
void clean()
delete pointers
std::vector< t_SVDLadder > t_SVDLayer
a vector of vector of vector of H, length = # ladders
SVDHistograms(const H &templateHisto)
the class is built with a default histogram for L3 and L456, U and V sides
Definition: SVDHistograms.h:32
void fill(const VxdID &vxdID, int view, Types ... args)
fill the histogram for
Definition: SVDHistograms.h:77
H * getHistogram(const VxdID &vxdID, int view)
get a reference to the histogram for
Definition: SVDHistograms.h:56
SVDHistograms()
Default constructor.
Definition: SVDHistograms.h:28
void customizeString(std::string &base, const VxdID &vxdID, bool isU)
replaces layer ladder sensor view and apv with the current numbers
Definition: SVDHistograms.h:92
std::vector< t_SVDLayer > t_SVD
a vector of vector of vector of vector of H, length = # layers
H * m_defaultHistogram
the default histogram
std::vector< H * > t_SVDSensor
a vector of H, length = 2
std::vector< t_SVDSensor > t_SVDLadder
a vector of vector of H, length = # svd sensors
ClassDef(SVDHistograms, 1)
needed by root
void reset()
Call Reset() on all histograms.
E_side
This enumeration assure the same semantic of the isU methods defined by Peter Kv.
Definition: SVDHistograms.h:51
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
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
SVDHistograms(const H &templateU3, const H &templateV3, const H &templateU456, const H &templateV456)
Use templates to initialize all the histograms.
void customize(H &histogram, VxdID vxdID, int view)
customize the histogram with the sensor, view
Abstract base class for different kinds of events.