Belle II Software  release-08-01-10
KLMElementNumbers.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/KLMElementNumbers.h>
11 
12 /* KLM headers. */
13 #include <klm/dataobjects/bklm/BKLMElementNumbers.h>
14 
15 /* Basf2 headers. */
16 #include <framework/logging/Logger.h>
17 
18 using namespace Belle2;
19 
21  m_eklmElementNumbers(&(EKLMElementNumbers::Instance()))
22 {
23 }
24 
26 {
27 }
28 
30 {
31  static KLMElementNumbers klmElementNumbers;
32  return klmElementNumbers;
33 }
34 
36  int subdetector, int section, int sector, int layer, int plane,
37  int strip) const
38 {
39  switch (subdetector) {
40  case c_BKLM:
41  return channelNumberBKLM(section, sector, layer, plane, strip);
42  case c_EKLM:
43  return channelNumberEKLM(section, sector, layer, plane, strip);
44  }
45  B2FATAL("Incorrect subdetector number: " << subdetector);
46 }
47 
49  int section, int sector, int layer, int plane, int strip) const
50 {
51  KLMChannelNumber channel;
53  section, sector, layer, plane, strip);
54  return channel + m_BKLMOffset;
55 }
56 
58 {
59  return bklmChannel + m_BKLMOffset;
60 }
61 
63  int section, int sector, int layer, int plane, int strip) const
64 {
65  KLMChannelNumber channel;
66  /*
67  * Note that the default order of elements is different
68  * for EKLM-specific code!
69  */
71  section, layer, sector, plane, strip);
72  return channel;
73 }
74 
76 {
77  return eklmStrip;
78 }
79 
81 {
82  return (channel >= m_BKLMOffset);
83 }
84 
86 {
87  return (channel < m_BKLMOffset);
88 }
89 
91 {
92  if (!isBKLMChannel(channel))
93  B2FATAL("Cannot get BKLM local channel number for non-BKLM channel.");
94  return channel - m_BKLMOffset;
95 }
96 
98 {
99  if (!isEKLMChannel(channel))
100  B2FATAL("Cannot get EKLM local channel number for non-EKLM channel.");
101  return channel;
102 }
103 
105  KLMChannelNumber channel, int* subdetector, int* section, int* sector, int* layer,
106  int* plane, int* strip) const
107 {
108  int localChannel;
109  if (isBKLMChannel(channel)) {
110  *subdetector = c_BKLM;
111  localChannel = localChannelNumberBKLM(channel);
113  localChannel, section, sector, layer, plane, strip);
114  } else {
115  *subdetector = c_EKLM;
116  localChannel = localChannelNumberEKLM(channel);
117  /*
118  * Note that the default order of elements is different
119  * for EKLM-specific code!
120  */
122  localChannel, section, layer, sector, plane, strip);
123  }
124 }
125 
127  int subdetector, int section, int sector, int layer, int plane) const
128 {
129  if (subdetector == c_BKLM)
130  return planeNumberBKLM(section, sector, layer, plane);
131  else
132  return planeNumberEKLM(section, sector, layer, plane);
133 }
134 
136  int section, int sector, int layer, int plane) const
137 {
138  KLMPlaneNumber planeGlobal;
139  planeGlobal = BKLMElementNumbers::planeNumber(section, sector, layer, plane);
140  return planeGlobal + m_BKLMOffset;
141 }
142 
144  int section, int sector, int layer, int plane) const
145 {
146  KLMPlaneNumber planeGlobal;
147  /*
148  * Note that the default order of elements is different
149  * for EKLM-specific code!
150  */
151  planeGlobal = m_eklmElementNumbers->planeNumber(
152  section, layer, sector, plane);
153  return planeGlobal;
154 }
155 
157  int subdetector, int section, int sector, int layer) const
158 {
159  if (subdetector == c_BKLM)
160  return moduleNumberBKLM(section, sector, layer);
161  else
162  return moduleNumberEKLM(section, sector, layer);
163 }
164 
166  int section, int sector, int layer) const
167 {
168  KLMModuleNumber module;
169  module = BKLMElementNumbers::moduleNumber(section, sector, layer);
170  return module + m_BKLMOffset;
171 }
172 
174  int section, int sector, int layer) const
175 {
176  KLMModuleNumber module;
177  /*
178  * Note that the default order of elements is different
179  * for EKLM-specific code!
180  */
181  module = m_eklmElementNumbers->sectorNumber(section, layer, sector);
182  return module;
183 }
184 
186  KLMChannelNumber channel) const
187 {
188  int subdetector, section, sector, layer, plane, strip;
189  channelNumberToElementNumbers(channel, &subdetector, &section, &sector,
190  &layer, &plane, &strip);
191  return moduleNumber(subdetector, section, sector, layer);
192 }
193 
195  KLMModuleNumber module, int* subdetector, int* section, int* sector,
196  int* layer) const
197 {
198  int localModule;
199  if (isBKLMChannel(module)) {
200  *subdetector = c_BKLM;
201  localModule = localChannelNumberBKLM(module);
203  localModule, section, sector, layer);
204  } else {
205  *subdetector = c_EKLM;
206  localModule = localChannelNumberEKLM(module);
207  /*
208  * Note that the default order of elements is different
209  * for EKLM-specific code!
210  */
212  localModule, section, layer, sector);
213  }
214 }
215 
217 {
218  if (isBKLMChannel(module)) {
219  int localModule = localChannelNumberBKLM(module);
220  int section, sector, layer;
222  localModule, &section, &sector, &layer);
223  return BKLMElementNumbers::getNStrips(section, sector, layer, 0) +
224  BKLMElementNumbers::getNStrips(section, sector, layer, 1);
225  } else {
227  }
228 }
229 
231  int section, int sector) const
232 {
233  KLMSectorNumber sect;
234  sect = BKLMElementNumbers::sectorNumber(section, sector);
235  return sect + m_BKLMOffset;
236 }
237 
239  int section, int sector) const
240 {
241  KLMSectorNumber sect;
242  sect = m_eklmElementNumbers->sectorNumberKLMOrder(section, sector);
243  return sect;
244 }
245 
246 int KLMElementNumbers::getExtrapolationLayer(int subdetector, int layer) const
247 {
248  if (subdetector == c_BKLM)
249  return layer;
250  else
252 }
253 
255 {
256  if (subdetector == c_BKLM)
257  return 0;
258  else
259  return 1;
260 }
261 
262 std::string KLMElementNumbers::getSectorDAQName(int subdetector, int section, int sector) const
263 {
264  std::string name;
265  if (subdetector == c_BKLM) {
268  name = "BB" + std::to_string(sector - 1);
270  name = "BF" + std::to_string(sector - 1);
271  }
272  if (subdetector == c_EKLM) {
275  name = "EB" + std::to_string(sector - 1);
277  name = "EF" + std::to_string(sector - 1);
278  }
279  if (name.empty())
280  B2FATAL("Invalid KLM sector."
281  << LogVar("Subdetector", subdetector)
282  << LogVar("Section", section)
283  << LogVar("Sector", sector));
284  return name;
285 }
static void channelNumberToElementNumbers(KLMChannelNumber channel, int *section, int *sector, int *layer, int *plane, int *strip)
Get element numbers by channel number.
static KLMPlaneNumber planeNumber(int section, int sector, int layer, int plane)
Get plane number.
static bool checkSector(int sector, bool fatalError=true)
Check if sector number is correct.
static KLMChannelNumber channelNumber(int section, int sector, int layer, int plane, int strip)
Get channel number.
static KLMSectorNumber sectorNumber(int section, int sector)
Get sector number.
static constexpr int getMaximalLayerNumber()
Get maximal layer number (1-based).
static KLMModuleNumber moduleNumber(int section, int sector, int layer, bool fatalError=true)
Get module number.
static void moduleNumberToElementNumbers(KLMModuleNumber module, int *section, int *sector, int *layer)
Get element numbers by module number.
static int getNStrips(int section, int sector, int layer, int plane)
Get number of strips.
EKLM element numbers.
static constexpr int getNStripsSector()
Get number of strips in a sector.
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.
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.
bool checkSector(int sector, bool fatalError=true) const
Check if sector number is correct (fatal error if not).
int planeNumber(int section, int layer, int sector, int plane) const
Get plane number.
KLM element numbers.
KLMSectorNumber sectorNumberEKLM(int section, int sector) const
Get sector number for EKLM.
KLMModuleNumber moduleNumberByChannel(KLMChannelNumber channel) const
Get module number by channel number.
KLMChannelNumber channelNumberBKLM(int section, int sector, int layer, int plane, int strip) const
Get channel number for BKLM.
static constexpr uint16_t m_BKLMOffset
BKLM offset.
KLMChannelNumber channelNumber(int subdetector, int section, int sector, int layer, int plane, int strip) const
Get channel number.
const EKLMElementNumbers * m_eklmElementNumbers
EKLM element numbers.
int getMinimalPlaneNumber(int subdetector) const
Get minimal plane number.
static const KLMElementNumbers & Instance()
Instantiation.
int localChannelNumberEKLM(KLMChannelNumber channel) const
Get local EKLM channel number.
KLMPlaneNumber planeNumber(int subdetector, int section, int sector, int layer, int plane) const
Get plane number.
KLMPlaneNumber planeNumberEKLM(int section, int sector, int layer, int plane) const
Get channel number for EKLM.
bool isEKLMChannel(KLMChannelNumber channel) const
Determine whether a given channel is in EKLM.
void channelNumberToElementNumbers(KLMChannelNumber channel, int *subdetector, int *section, int *sector, int *layer, int *plane, int *strip) const
Get element numbers by channel number.
unsigned int getNChannelsModule(KLMModuleNumber module) const
Get number of channels in module.
int getExtrapolationLayer(int subdetector, int layer) const
Get extrapolation layer number (BKLM - from 1 to 15, EKLM - from 16 to 29).
void moduleNumberToElementNumbers(KLMModuleNumber module, int *subdetector, int *section, int *sector, int *layer) const
Get element numbers by module number.
KLMPlaneNumber planeNumberBKLM(int section, int sector, int layer, int plane) const
Get plane number for BKLM.
KLMModuleNumber moduleNumberBKLM(int section, int sector, int layer) const
Get module number for BKLM.
KLMModuleNumber moduleNumber(int subdetector, int section, int sector, int layer) const
Get module number.
KLMSectorNumber sectorNumberBKLM(int section, int sector) const
Get sector number for BKLM.
std::string getSectorDAQName(int subdetector, int section, int sector) const
Get DAQ name for a given sector.
KLMModuleNumber moduleNumberEKLM(int section, int sector, int layer) const
Get module number for EKLM.
bool isBKLMChannel(KLMChannelNumber channel) const
Determine whether a given channel is in BKLM.
int localChannelNumberBKLM(KLMChannelNumber channel) const
Get local BKLM channel number.
KLMChannelNumber channelNumberEKLM(int section, int sector, int layer, int plane, int strip) const
Get channel number for EKLM.
Class to store variables with their name which were sent to the logging service.
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.