Belle II Software development
EKLMElementNumbers.cc
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/* Own header. */
10#include <klm/dataobjects/eklm/EKLMElementNumbers.h>
11
12/* Basf2 headers. */
13#include <framework/logging/Logger.h>
14#include <rawdata/dataobjects/RawCOPPERFormat.h>
15
16using namespace Belle2;
17
19{
20 static EKLMElementNumbers ens;
21 return ens;
22}
23
25{
26}
27
29{
30}
31
32bool EKLMElementNumbers::checkSection(int section, bool fatalError) const
33{
34 if (section <= 0 || section > m_MaximalSectionNumber) {
35 if (fatalError) {
36 B2FATAL("Number of section must be 1 (backward) or 2 (forward).");
37 }
38 return false;
39 }
40 return true;
41}
42
43bool EKLMElementNumbers::checkLayer(int layer, bool fatalError) const
44{
45 if (layer <= 0 || layer > m_MaximalLayerNumber) {
46 if (fatalError) {
47 B2FATAL("Number of layer must be from 1 to " << m_MaximalLayerNumber <<
48 ".");
49 }
50 return false;
51 }
52 return true;
53}
54
55bool EKLMElementNumbers::checkDetectorLayer(int section, int layer,
56 bool fatalError) const
57{
58 /* cppcheck-suppress variableScope */
59 const char* sectionName[2] = {"backward", "forward"};
60 if (layer < 0 || layer > m_MaximalDetectorLayerNumber[section - 1]) {
61 if (fatalError) {
62 B2FATAL("Number of layer must be from 1 to the maximal number of "
63 "detector layers in the " << sectionName[section - 1] << " section ("
64 << m_MaximalDetectorLayerNumber[section - 1] << ").");
65 }
66 return false;
67 }
68 return true;
69}
70
71bool EKLMElementNumbers::checkSector(int sector, bool fatalError) const
72{
73 if (sector <= 0 || sector > m_MaximalSectorNumber) {
74 if (fatalError) {
75 B2FATAL("Number of sector must be from 1 to " << m_MaximalSectorNumber <<
76 ".");
77 }
78 return false;
79 }
80 return true;
81}
82
83bool EKLMElementNumbers::checkPlane(int plane, bool fatalError) const
84{
85 if (plane <= 0 || plane > m_MaximalPlaneNumber) {
86 if (fatalError) {
87 B2FATAL("Number of plane must be from 1 to " << m_MaximalPlaneNumber <<
88 ".");
89 }
90 return false;
91 }
92 return true;
93}
94
95bool EKLMElementNumbers::checkSegment(int segment, bool fatalError) const
96{
97 if (segment <= 0 || segment > m_MaximalSegmentNumber) {
98 if (fatalError) {
99 B2FATAL("Number of segment must be from 1 to " <<
101 }
102 return false;
103 }
104 return true;
105}
106
107bool EKLMElementNumbers::checkStrip(int strip, bool fatalError) const
108{
109 if (strip <= 0 || strip > m_MaximalStripNumber) {
110 if (fatalError) {
111 B2FATAL("Number of strip must be from 1 to " << m_MaximalStripNumber <<
112 ".");
113 }
114 return false;
115 }
116 return true;
117}
118
119int EKLMElementNumbers::detectorLayerNumber(int section, int layer) const
120{
121 checkSection(section);
122 checkDetectorLayer(section, layer);
123 if (section == 1)
124 return layer;
125 return m_MaximalDetectorLayerNumber[0] + layer;
126}
127
129 int layerGlobal, int* section, int* layer) const
130{
131 static int maxLayer = getMaximalLayerGlobalNumber();
132 if (layerGlobal <= 0 || layerGlobal > maxLayer)
133 B2FATAL("Number of segment must be from 1 to " << maxLayer << ".");
134 if (layerGlobal <= m_MaximalDetectorLayerNumber[0]) {
135 *section = 1;
136 *layer = layerGlobal;
137 } else {
138 *section = 2;
139 *layer = layerGlobal - m_MaximalDetectorLayerNumber[0];
140 }
141}
142
143int EKLMElementNumbers::sectorNumber(int section, int layer, int sector) const
144{
145 checkSector(sector);
146 return m_MaximalSectorNumber * (detectorLayerNumber(section, layer) - 1) +
147 sector;
148}
149
150int EKLMElementNumbers::sectorNumberKLMOrder(int section, int sector) const
151{
152 checkSection(section);
153 checkSector(sector);
154 return m_MaximalSectorNumber * (section - 1) + sector;
155}
156
158 int sectorGlobal, int* section, int* layer, int* sector) const
159{
160 static int maxSector = getMaximalSectorGlobalNumber();
161 int layerGlobal;
162 if (sectorGlobal <= 0 || sectorGlobal > maxSector)
163 B2FATAL("Number of segment must be from 1 to " << maxSector << ".");
164 *sector = (sectorGlobal - 1) % m_MaximalSectorNumber + 1;
165 layerGlobal = (sectorGlobal - 1) / m_MaximalSectorNumber + 1;
166 layerNumberToElementNumbers(layerGlobal, section, layer);
167}
168
169int EKLMElementNumbers::planeNumber(int section, int layer, int sector,
170 int plane) const
171{
172 checkPlane(plane);
173 return m_MaximalPlaneNumber * (sectorNumber(section, layer, sector) - 1) +
174 plane;
175}
176
178 int planeGlobal, int* section, int* layer, int* sector, int* plane) const
179{
180 static int maxPlane = getMaximalPlaneGlobalNumber();
181 int sectorGlobal;
182 if (planeGlobal <= 0 || planeGlobal > maxPlane)
183 B2FATAL("Number of segment must be from 1 to " << maxPlane << ".");
184 *plane = (planeGlobal - 1) % m_MaximalPlaneNumber + 1;
185 sectorGlobal = (planeGlobal - 1) / m_MaximalPlaneNumber + 1;
186 sectorNumberToElementNumbers(sectorGlobal, section, layer, sector);
187}
188
189int EKLMElementNumbers::segmentNumber(int section, int layer, int sector,
190 int plane, int segment) const
191{
192 checkSegment(segment);
193 return m_MaximalSegmentNumber * (planeNumber(section, layer, sector, plane) -
194 1) + segment;
195}
196
198 int segmentGlobal, int* section, int* layer, int* sector, int* plane,
199 int* segment) const
200{
201 static int maxSegment = getMaximalSegmentGlobalNumber();
202 int planeGlobal;
203 if (segmentGlobal <= 0 || segmentGlobal > maxSegment)
204 B2FATAL("Number of segment must be from 1 to " << maxSegment << ".");
205 *segment = (segmentGlobal - 1) % m_MaximalSegmentNumber + 1;
206 planeGlobal = (segmentGlobal - 1) / m_MaximalSegmentNumber + 1;
207 planeNumberToElementNumbers(planeGlobal, section, layer, sector, plane);
208}
209
210int EKLMElementNumbers::stripNumber(int section, int layer, int sector,
211 int plane, int strip) const
212{
213 checkStrip(strip);
214 return m_MaximalStripNumber * (planeNumber(section, layer, sector, plane) - 1)
215 + strip;
216}
217
219 int stripGlobal, int* section, int* layer, int* sector, int* plane,
220 int* strip) const
221{
222 static int maxStrip = getMaximalStripGlobalNumber();
223 int planeGlobal;
224 if (stripGlobal <= 0 || stripGlobal > maxStrip)
225 B2FATAL("Number of strip must be from 1 to " << maxStrip << ".");
226 *strip = (stripGlobal - 1) % m_MaximalStripNumber + 1;
227 planeGlobal = (stripGlobal - 1) / m_MaximalStripNumber + 1;
228 planeNumberToElementNumbers(planeGlobal, section, layer, sector, plane);
229}
230
232{
233 int section, layer, sector, plane, strip;
234 stripNumberToElementNumbers(stripGlobal,
235 &section, &layer, &sector, &plane, &strip);
236 return section;
237}
238
240{
241 int section, layer, sector, plane, strip;
242 stripNumberToElementNumbers(stripGlobal,
243 &section, &layer, &sector, &plane, &strip);
244 return layer;
245}
246
248{
249 int section, layer, sector, plane, strip;
250 stripNumberToElementNumbers(stripGlobal,
251 &section, &layer, &sector, &plane, &strip);
252 return sector;
253}
254
256{
257 int section, layer, sector, plane, strip;
258 stripNumberToElementNumbers(stripGlobal,
259 &section, &layer, &sector, &plane, &strip);
260 return plane;
261}
262
264{
265 static int maxStrip = getMaximalStripGlobalNumber();
266 if (stripGlobal <= 0 || stripGlobal > maxStrip)
267 B2FATAL("Number of strip must be from 1 to " << maxStrip << ".");
268 return (stripGlobal - 1) % m_MaximalStripNumber + 1;
269}
270
271std::string EKLMElementNumbers::getHSLBName(int copper, int slot)
272{
273 char hslb = 'a' + slot - 1;
274 return "800" + std::to_string(copper - EKLM_ID) + hslb;
275}
276
278{
279 checkSection(section);
280 return m_MaximalDetectorLayerNumber[section - 1];
281}
EKLM element numbers.
static constexpr int m_MaximalStripNumber
Maximal strip number.
bool checkLayer(int layer, bool fatalError=true) const
Check if layer number is correct.
static constexpr int getMaximalLayerGlobalNumber()
Get maximal detector layer global number.
void planeNumberToElementNumbers(int planeGlobal, int *section, int *layer, int *sector, int *plane) const
Get element numbers by plane global number.
int getMaximalDetectorLayerNumber(int section) const
Get maximal detector layer number.
static const EKLMElementNumbers & Instance()
Instantiation.
int sectorNumber(int section, int layer, int sector) const
Get sector number.
void sectorNumberToElementNumbers(int sectorGlobal, int *section, int *layer, int *sector) const
Get element numbers by sector global number.
static constexpr int m_MaximalPlaneNumber
Maximal plane number.
static constexpr int m_MaximalSectionNumber
Maximal section number.
static constexpr int m_MaximalDetectorLayerNumber[2]
Maximal detector layer number.
int getPlaneByGlobalStrip(int stripGlobal)
Get plane number by global strip number.
bool checkPlane(int plane, bool fatalError=true) const
Check if plane number is correct (fatal error if not).
bool checkDetectorLayer(int section, int layer, bool fatalError=true) const
Check if detector layer number is correct (fatal error if not).
int getStripByGlobalStrip(int stripGlobal)
Get strip number by global strip number.
int getSectorByGlobalStrip(int stripGlobal)
Get sector number by global strip number.
bool checkStrip(int strip, bool fatalError=true) const
Check if strip number is correct (fatal error if not).
void layerNumberToElementNumbers(int layerGlobal, int *section, int *layer) const
Get element numbers by detector layer global number.
int detectorLayerNumber(int section, int layer) const
Get detector layer number.
bool checkSegment(int segment, bool fatalError=true) const
Check if segment number is correct (fatal error if not).
int stripNumber(int section, int layer, int sector, int plane, int strip) const
Get strip number.
int sectorNumberKLMOrder(int section, int sector) const
Get sector number (KLM order of elements: section, sector, layer).
void stripNumberToElementNumbers(int stripGlobal, int *section, int *layer, int *sector, int *plane, int *strip) const
Get element numbers by strip global number.
static constexpr int getMaximalPlaneGlobalNumber()
Get maximal plane global number.
bool checkSector(int sector, bool fatalError=true) const
Check if sector number is correct (fatal error if not).
static constexpr int getMaximalStripGlobalNumber()
Get maximal strip global number.
static std::string getHSLBName(int copper, int slot)
Get HSLB name.
static constexpr int m_MaximalSectorNumber
Maximal sector number.
static constexpr int getMaximalSegmentGlobalNumber()
Get maximal segment global number.
int getSectionByGlobalStrip(int stripGlobal)
Get section number by global strip number.
int segmentNumber(int section, int layer, int sector, int plane, int segment) const
Get segment number.
static constexpr int m_MaximalLayerNumber
Maximal layer number.
int getLayerByGlobalStrip(int stripGlobal)
Get layer number by global strip number.
static constexpr int getMaximalSectorGlobalNumber()
Get maximal sector global number.
bool checkSection(int section, bool fatalError=true) const
Check if section number is correct.
int planeNumber(int section, int layer, int sector, int plane) const
Get plane number.
static constexpr int m_MaximalSegmentNumber
Maximal segment number.
void segmentNumberToElementNumbers(int segmentGlobal, int *section, int *layer, int *sector, int *plane, int *segment) const
Get element numbers by segment global number.
Abstract base class for different kinds of events.