Belle II Software development
BKLMElementNumbers.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/bklm/BKLMElementNumbers.h>
11
12/* Basf2 headers. */
13#include <rawdata/dataobjects/RawCOPPERFormat.h>
14
15using namespace Belle2;
16
18{
19}
20
22{
23}
24
26 int section, int sector, int layer, int plane, int strip)
27{
28 checkChannelNumber(section, sector, layer, plane, strip);
29 return (section << BKLM_SECTION_BIT)
30 | ((sector - 1) << BKLM_SECTOR_BIT)
31 | ((layer - 1) << BKLM_LAYER_BIT)
32 | ((plane) << BKLM_PLANE_BIT)
33 | ((strip - 1) << BKLM_STRIP_BIT);
34}
35
37 KLMChannelNumber channel, int* section, int* sector, int* layer, int* plane,
38 int* strip)
39{
40 *section = ((channel & BKLM_SECTION_MASK) >> BKLM_SECTION_BIT);
41 *sector = ((channel & BKLM_SECTOR_MASK) >> BKLM_SECTOR_BIT) + 1;
42 *layer = ((channel & BKLM_LAYER_MASK) >> BKLM_LAYER_BIT) + 1;
43 *plane = ((channel & BKLM_PLANE_MASK) >> BKLM_PLANE_BIT);
44 *strip = ((channel & BKLM_STRIP_MASK) >> BKLM_STRIP_BIT) + 1;
45}
46
48 int section, int sector, int layer, int plane)
49{
50 checkSection(section);
51 checkSector(sector);
52 checkLayer(layer);
53 checkPlane(plane);
54 return (section << BKLM_SECTION_BIT)
55 | ((sector - 1) << BKLM_SECTOR_BIT)
56 | ((layer - 1) << BKLM_LAYER_BIT)
57 | ((plane) << BKLM_PLANE_BIT);
58}
59
61 KLMPlaneNumber planeGlobal, int* section, int* sector, int* layer, int* plane)
62{
63 *section = ((planeGlobal & BKLM_SECTION_MASK) >> BKLM_SECTION_BIT);
64 *sector = ((planeGlobal & BKLM_SECTOR_MASK) >> BKLM_SECTOR_BIT) + 1;
65 *layer = ((planeGlobal & BKLM_LAYER_MASK) >> BKLM_LAYER_BIT) + 1;
66 *plane = ((planeGlobal & BKLM_PLANE_MASK) >> BKLM_PLANE_BIT);
67}
68
70 int section, int sector, int layer, bool fatalError)
71{
72 checkSection(section);
73 checkSector(sector, fatalError);
74 checkLayer(layer, fatalError);
75 return (section << BKLM_SECTION_BIT)
76 | ((sector - 1) << BKLM_SECTOR_BIT)
77 | ((layer - 1) << BKLM_LAYER_BIT);
78}
79
81 KLMModuleNumber module, int* section, int* sector, int* layer)
82{
83 *section = ((module & BKLM_SECTION_MASK) >> BKLM_SECTION_BIT);
84 *sector = ((module & BKLM_SECTOR_MASK) >> BKLM_SECTOR_BIT) + 1;
85 *layer = ((module & BKLM_LAYER_MASK) >> BKLM_LAYER_BIT) + 1;
86}
87
89{
90 checkSection(section);
91 checkSector(sector);
92 return (section ? BKLM_SECTION_MASK : 0)
93 | ((sector - 1) << BKLM_SECTOR_BIT);
94}
95
96int BKLMElementNumbers::layerGlobalNumber(int section, int sector, int layer)
97{
98 checkSection(section);
99 checkSector(sector);
100 checkLayer(layer);
101 int layerGlobal = layer;
102 layerGlobal += (sector - 1) * m_MaximalLayerNumber;
103 layerGlobal += section * m_MaximalSectorNumber * m_MaximalLayerNumber;
104 return layerGlobal;
105}
106
108 int section, int sector, int layer, int plane)
109{
110 checkSection(section);
111 checkSector(sector);
112 checkLayer(layer);
113 checkPlane(plane);
114 int strips = 0;
118 /* Chimney sector. */
119 if (layer < 3)
120 strips = 38;
121 if (layer > 2)
122 strips = 34;
123 } else {
124 /* Other sectors. */
125 if (layer == 1 && plane == BKLMElementNumbers::c_PhiPlane)
126 strips = 37;
127 if (layer == 2 && plane == BKLMElementNumbers::c_PhiPlane)
128 strips = 42;
129 if (layer > 2 && layer < 7 && plane == BKLMElementNumbers::c_PhiPlane)
130 strips = 36;
131 if (layer > 6 && plane == BKLMElementNumbers::c_PhiPlane)
132 strips = 48;
133 if (layer == 1 && plane == BKLMElementNumbers::c_ZPlane)
134 strips = 54;
135 if (layer == 2 && plane == BKLMElementNumbers::c_ZPlane)
136 strips = 54;
137 if (layer > 2 && plane == BKLMElementNumbers::c_ZPlane)
138 strips = 48;
139 }
140 return strips;
141}
142
143bool BKLMElementNumbers::checkSection(int section, bool fatalError)
144{
145 if (section < BKLMElementNumbers::c_BackwardSection || section > BKLMElementNumbers::c_ForwardSection) {
146 if (fatalError)
147 B2FATAL("Invalid BKLM section number: " << section << ".");
148 return false;
149 }
150 return true;
151}
152
153bool BKLMElementNumbers::checkSector(int sector, bool fatalError)
154{
155 if (sector < 1 || sector > m_MaximalSectorNumber) {
156 if (fatalError)
157 B2FATAL("Invalid BKLM sector number: " << sector << ".");
158 return false;
159 }
160 return true;
161}
162
163bool BKLMElementNumbers::checkLayer(int layer, bool fatalError)
164{
165 if (layer < 1 || layer > m_MaximalLayerNumber) {
166 if (fatalError)
167 B2FATAL("Invalid BKLM layer number: " << layer << ".");
168 return false;
169 }
170 return true;
171}
172
173bool BKLMElementNumbers::checkPlane(int plane, bool fatalError)
174{
175 if (plane < 0 || plane > m_MaximalPlaneNumber) {
176 if (fatalError)
177 B2FATAL("Invalid BKLM plane number: " << plane << ".");
178 return false;
179 }
180 return true;
181}
182
184 int section, int sector, int layer, int plane, int strip, bool fatalError)
185{
186 if (strip < 1 || strip > getNStrips(section, sector, layer, plane)) {
187 if (fatalError)
188 B2FATAL("Invalid BKLM channel number: section = " << section << ", sector = " << sector << ", layer = " << layer << ", plane = " <<
189 plane << ", strip = " << strip << ".");
190 return false;
191 }
192 return true;
193}
194
195void BKLMElementNumbers::layerGlobalNumberToElementNumbers(int layerGlobal, int* section, int* sector, int* layer)
196{
197 *section = ((layerGlobal / m_MaximalLayerNumber) / m_MaximalSectorNumber) % (m_MaximalLayerNumber + 1);
198 *sector = ((layerGlobal / m_MaximalLayerNumber) % m_MaximalSectorNumber) + 1;
199 *layer = (layerGlobal % m_MaximalLayerNumber) + 1;
200}
201
202std::string BKLMElementNumbers::getHSLBName(int copper, int slot)
203{
204 char hslb = 'a' + slot - 1;
205 return "700" + std::to_string(copper - BKLM_ID) + hslb;
206}
static void planeNumberToElementNumbers(KLMPlaneNumber planeGlobal, int *section, int *sector, int *layer, int *plane)
Get element numbers by plane number.
static constexpr int BKLM_STRIP_BIT
Bit position for strip-1 [0..47].
static void channelNumberToElementNumbers(KLMChannelNumber channel, int *section, int *sector, int *layer, int *plane, int *strip)
Get element numbers by channel number.
@ c_ChimneySector
Chimney sector: BB3 in 1-based notation; BB2 in 0-based notation.
static constexpr int m_MaximalPlaneNumber
Maximal plane number (0-based).
static KLMPlaneNumber planeNumber(int section, int sector, int layer, int plane)
Get plane number.
static constexpr int BKLM_PLANE_BIT
Bit position for plane-1 [0..1].
static bool checkSector(int sector, bool fatalError=true)
Check if sector number is correct.
static bool checkSection(int section, bool fatalError=true)
Check if section number is correct.
static bool checkChannelNumber(int section, int sector, int layer, int plane, int strip, bool fatalError=true)
Check channel number.
static constexpr int BKLM_SECTOR_MASK
Bit mask for sector-1 [0..7].
static KLMChannelNumber channelNumber(int section, int sector, int layer, int plane, int strip)
Get channel number.
static bool checkLayer(int layer, bool fatalError=true)
Check if layer number is correct.
static void layerGlobalNumberToElementNumbers(int layerGlobal, int *section, int *sector, int *layer)
Get element numbers by layer global number (0-based).
static bool checkPlane(int plane, bool fatalError=true)
Check if plane number is correct.
static constexpr int BKLM_LAYER_MASK
Bit mask for layer-1 [0..15]; 0 is innermost and 14 is outermost.
static KLMSectorNumber sectorNumber(int section, int sector)
Get sector number.
static constexpr int BKLM_PLANE_MASK
Bit mask for plane-1 [0..1]; 0 is inner-plane and phiReadout plane,.
static std::string getHSLBName(int copper, int slot)
Get HSLB name.
static constexpr int BKLM_SECTOR_BIT
Bit position for sector-1 [0..7].
static constexpr int BKLM_SECTION_BIT
Bit position for detector end [0..1]; forward is 0.
static constexpr int BKLM_SECTION_MASK
Bit mask for detector end [0..1]; forward is 0.
static constexpr int m_MaximalSectorNumber
Maximal sector number (1-based).
static KLMModuleNumber moduleNumber(int section, int sector, int layer, bool fatalError=true)
Get module number.
static constexpr int m_MaximalLayerNumber
Maximal layer number (1-based).
static void moduleNumberToElementNumbers(KLMModuleNumber module, int *section, int *sector, int *layer)
Get element numbers by module number.
static int layerGlobalNumber(int section, int sector, int layer)
Get layer global number.
static constexpr int BKLM_LAYER_BIT
Bit position for layer-1 [0..14]; 0 is innermost.
static constexpr int BKLM_STRIP_MASK
Bit mask for strip-1 [0..47].
static int getNStrips(int section, int sector, int layer, int plane)
Get number of strips.
uint16_t KLMSectorNumber
Sector number.
uint16_t KLMChannelNumber
Channel number.
uint16_t KLMModuleNumber
Module number.
uint16_t KLMPlaneNumber
Plane number.
Abstract base class for different kinds of events.