Belle II Software  release-06-02-00
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 /* Belle 2 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 section, int sector, int layer, int plane) const
128 {
129  KLMPlaneNumber planeGlobal;
130  planeGlobal = BKLMElementNumbers::planeNumber(section, sector, layer, plane);
131  return planeGlobal + m_BKLMOffset;
132 }
133 
135  int section, int sector, int layer, int plane) const
136 {
137  KLMPlaneNumber planeGlobal;
138  /*
139  * Note that the default order of elements is different
140  * for EKLM-specific code!
141  */
142  planeGlobal = m_eklmElementNumbers->planeNumber(
143  section, layer, sector, plane);
144  return planeGlobal;
145 }
146 
148  int subdetector, int section, int sector, int layer) const
149 {
150  if (subdetector == c_BKLM)
151  return moduleNumberBKLM(section, sector, layer);
152  else
153  return moduleNumberEKLM(section, sector, layer);
154 }
155 
157  int section, int sector, int layer) const
158 {
159  KLMModuleNumber module;
160  module = BKLMElementNumbers::moduleNumber(section, sector, layer);
161  return module + m_BKLMOffset;
162 }
163 
165  int section, int sector, int layer) const
166 {
167  KLMModuleNumber module;
168  /*
169  * Note that the default order of elements is different
170  * for EKLM-specific code!
171  */
172  module = m_eklmElementNumbers->sectorNumber(section, layer, sector);
173  return module;
174 }
175 
177  KLMChannelNumber channel) const
178 {
179  int subdetector, section, sector, layer, plane, strip;
180  channelNumberToElementNumbers(channel, &subdetector, &section, &sector,
181  &layer, &plane, &strip);
182  return moduleNumber(subdetector, section, sector, layer);
183 }
184 
186  KLMModuleNumber module, int* subdetector, int* section, int* sector,
187  int* layer) const
188 {
189  int localModule;
190  if (isBKLMChannel(module)) {
191  *subdetector = c_BKLM;
192  localModule = localChannelNumberBKLM(module);
194  localModule, section, sector, layer);
195  } else {
196  *subdetector = c_EKLM;
197  localModule = localChannelNumberEKLM(module);
198  /*
199  * Note that the default order of elements is different
200  * for EKLM-specific code!
201  */
203  localModule, section, layer, sector);
204  }
205 }
206 
208 {
209  if (isBKLMChannel(module)) {
210  int localModule = localChannelNumberBKLM(module);
211  int section, sector, layer;
213  localModule, &section, &sector, &layer);
214  return BKLMElementNumbers::getNStrips(section, sector, layer, 0) +
215  BKLMElementNumbers::getNStrips(section, sector, layer, 1);
216  } else {
218  }
219 }
220 
222  int section, int sector) const
223 {
224  KLMSectorNumber sect;
225  sect = BKLMElementNumbers::sectorNumber(section, sector);
226  return sect + m_BKLMOffset;
227 }
228 
230  int section, int sector) const
231 {
232  KLMSectorNumber sect;
233  sect = m_eklmElementNumbers->sectorNumberKLMOrder(section, sector);
234  return sect;
235 }
236 
237 int KLMElementNumbers::getExtrapolationLayer(int subdetector, int layer) const
238 {
239  if (subdetector == c_BKLM)
240  return layer;
241  else
243 }
244 
246 {
247  if (subdetector == c_BKLM)
248  return 0;
249  else
250  return 1;
251 }
252 
253 std::string KLMElementNumbers::getSectorDAQName(int subdetector, int section, int sector) const
254 {
255  std::string name;
256  if (subdetector == c_BKLM) {
259  name = "BB" + std::to_string(sector - 1);
261  name = "BF" + std::to_string(sector - 1);
262  }
263  if (subdetector == c_EKLM) {
266  name = "EB" + std::to_string(sector - 1);
268  name = "EF" + std::to_string(sector - 1);
269  }
270  if (name.empty())
271  B2FATAL("Invalid KLM sector."
272  << LogVar("Subdetector", subdetector)
273  << LogVar("Section", section)
274  << LogVar("Sector", sector));
275  return name;
276 }
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 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.