Belle II Software  release-06-01-15
GeoTools.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 
11 #include <vxd/dataobjects/VxdID.h>
12 #include <vector>
13 #include <algorithm>
14 
15 namespace Belle2 {
20  namespace VXD {
21 
25  class GeoTools {
26 
27  public:
32  GeoTools();
33 
34  /*********************************************************************
35  * General geometry parameters
36  ********************************************************************/
37 
41  unsigned short getNumberOfLayers() const { return m_listOfLayers.size(); }
42 
46  unsigned short getNumberOfPXDLayers() const { return m_firstSVDLayer; }
47 
51  unsigned short getNumberOfSVDLayers() const
52  { return m_listOfLayers.size() - m_firstSVDLayer; }
53 
57  std::vector<unsigned short> getLayers() const { return m_listOfLayers; }
58 
62  std::vector<unsigned short> getPXDLayers() const
63  {
64  std::vector<unsigned short> pxdLayers;
65  std::copy_if(m_listOfLayers.begin(), m_listOfLayers.end(),
66  std::back_inserter(pxdLayers),
67  [](unsigned short l)->bool {return l < 3;});
68  return pxdLayers;
69  }
70 
74  std::vector<unsigned short> getSVDLayers() const
75  {
76  std::vector<unsigned short> svdLayers;
77  std::copy_if(m_listOfLayers.begin(), m_listOfLayers.end(),
78  std::back_inserter(svdLayers),
79  [](unsigned short l)->bool {return l > 2;});
80  return svdLayers;
81  }
82 
86  unsigned short getFirstLayer() const { return *m_listOfLayers.begin(); }
87 
91  unsigned short getLastLayer() const { return *m_listOfLayers.rbegin(); }
92 
96  short getFirstPXDLayer() const
97  {
98  return (m_firstSVDLayer > 0 ? *m_listOfLayers.begin() : -1);
99  }
100 
104  short getLastPXDLayer() const
105  {
106  return (m_firstSVDLayer > 0 ? m_listOfLayers[m_firstSVDLayer - 1] : -1);
107  }
108 
112  short getFirstSVDLayer() const
113  {
115  }
116 
120  short getLastSVDLayer() const
121  {
122  return (m_firstSVDLayer < m_listOfLayers.size() ? *m_listOfLayers.rbegin() : -1);
123  }
124 
128  unsigned short getNumberOfSensors() const { return m_listOfSensors.size(); }
129 
133  unsigned short getNumberOfPXDSensors() const { return m_firstSVDIndex; }
134 
138  unsigned short getNumberOfSVDSensors() const
139  { return m_listOfSensors.size() - m_firstSVDIndex; }
140 
141  /*********************************************************************
142  * Chip-related parameters
143  *********************************************************************/
147  size_t getTotalPXDChips() const { return m_listOfPXDChips.size(); }
148 
153  unsigned short getNumberOfPXDUSideChips(unsigned short = 0) const
154  { return c_nPXDChipsU; }
155 
160  unsigned short getNumberOfPXDVSideChips(unsigned short = 0) const
161  { return c_nPXDChipsV; }
162 
167  unsigned short getNumberOfPXDReadoutGates(unsigned short = 0) const
168  { return c_nPXDReadoutGates; }
169 
173  size_t getTotalSVDChips() const { return m_listOfSVDChips.size(); }
174 
179  unsigned short getNumberOfSVDUSideChips(unsigned short = 0) const
180  { return c_nSVDChipsLu; }
181 
186  unsigned short getNumberOfSVDVSideChips(unsigned short layer) const
187  { return (layer == 3 ? c_nSVDChipsL3 : c_nSVDChipsLv); }
188 
192  unsigned short getSVDChannelsPerChip() const
193  { return c_nSVDChannelsPerChip; }
194 
195  /*********************************************************************
196  * General sensor indexing
197  *********************************************************************/
202  int getSensorIndex(VxdID sensorID) const
203  {
204  return std::distance(
205  m_listOfSensors.begin(),
206  find(m_listOfSensors.begin(), m_listOfSensors.end(), sensorID)
207  );
208  }
209 
215  VxdID getSensorIDFromIndex(int vxdIndex) const
216  {
217  return m_listOfSensors[vxdIndex];
218  }
219 
220  /*********************************************************************
221  * PXD sensor indexing
222  *********************************************************************/
228  int getPXDSensorIndex(VxdID sensorID) const
229  {
230  return getSensorIndex(sensorID);
231  }
239  int getPXDSensorIndex(int layer, int ladder, int sensor) const
240  {
241  return getSensorIndex(VxdID(layer, ladder, sensor));
242  }
243 
248  VxdID getSensorIDFromPXDIndex(int pxdIndex) const
249  {
250  return m_listOfSensors[pxdIndex];
251  }
252 
253  /*********************************************************************
254  * PXD chip indexing
255  ********************************************************************/
263  int getPXDChipIndex(VxdID sensorID, bool isU, int chip) const
264  {
265  VxdID chipID(sensorID);
266  chip = isU ? chip - 1 : chip - 1 + c_nPXDChipsU;
267  chipID.setSegmentNumber(static_cast<unsigned short>(chip));
268  return std::distance(
269  m_listOfPXDChips.begin(),
270  std::find(m_listOfPXDChips.begin(), m_listOfPXDChips.end(), chipID));
271  }
272 
281  int getPXDChipIndex(int layer, int ladder, int sensor, bool isU, int chip) const
282  {
283  return getPXDChipIndex(VxdID(layer, ladder, sensor), isU, chip);
284  }
285 
290  VxdID getChipIDFromPXDIndex(int pxdChipIndex) const
291  {
292  return m_listOfPXDChips[pxdChipIndex];
293  }
294 
299  bool isPXDSideU(VxdID chipID) const
300  {
301  return (chipID.getSegmentNumber() < c_nPXDChipsU);
302  }
303 
308  unsigned short getPXDChipNumber(VxdID chipID) const
309  {
310  unsigned short chipNo = chipID.getSegmentNumber();
311  return (chipNo < c_nPXDChipsU ? chipNo + 1 : (chipNo + 1 - c_nPXDChipsU));
312  }
313 
314  /*********************************************************************
315  * SVD sensor indexing
316  *********************************************************************/
322  int getSVDSensorIndex(VxdID sensorID) const
323  {
324  return (getSensorIndex(sensorID) - m_firstSVDIndex);
325  }
326 
334  int getSVDSensorIndex(int layer, int ladder, int sensor) const
335  {
336  return getSVDSensorIndex(VxdID(layer, ladder, sensor));
337  }
338 
343  VxdID getSensorIDFromSVDIndex(int svdIndex) const
344  {
345  return m_listOfSensors[m_firstSVDIndex + svdIndex];
346  }
347 
348  /*********************************************************************
349  * SVD chip indexing
350  ********************************************************************/
351 
358  int getSVDChipIndex(VxdID sensorID, bool isU, int chip) const
359  {
360  VxdID chipID(sensorID);
361  if (sensorID.getLayerNumber() == 3)
362  chip = isU ? chip - 1 : chip - 1 + c_nSVDChipsL3;
363  else
364  chip = isU ? chip - 1 : chip - 1 + c_nSVDChipsLu;
365  chipID.setSegmentNumber(static_cast<unsigned short>(chip));
366  return std::distance(
367  m_listOfSVDChips.begin(),
368  std::find(m_listOfSVDChips.begin(), m_listOfSVDChips.end(), chipID));
369  }
370 
379  int getSVDChipIndex(int layer, int ladder, int sensor, bool isU, int chip) const
380  {
381  return getSVDChipIndex(VxdID(layer, ladder, sensor), isU, chip);
382  }
383 
388  VxdID getChipIDFromSVDIndex(int svdChipIndex) const
389  {
390  return m_listOfSVDChips[svdChipIndex];
391  }
392 
397  bool isSVDSideU(VxdID chipID) const
398  {
399  /* cppcheck-suppress duplicateExpressionTernary */
400  return (chipID.getLayerNumber() == 3 ? chipID.getSegmentNumber() < c_nSVDChipsL3 : chipID.getSegmentNumber() < c_nSVDChipsLu);
401  }
402 
407  unsigned short getSVDChipNumber(VxdID chipID) const
408  {
409  unsigned short chipNo = chipID.getSegmentNumber();
410  if (chipID.getLayerNumber() == 3) {
411  if (chipNo < c_nSVDChipsL3)
412  return chipNo + 1;
413  else
414  return (chipNo + 1 - c_nSVDChipsL3);
415  } else {
416  if (chipNo < c_nSVDChipsLu)
417  return chipNo + 1;
418  else
419  return (chipNo + 1 - c_nSVDChipsLu);
420  }
421  }
422 
423  /*********************************************************************
424  * Layer indexing
425  ********************************************************************/
430  int getLayerIndex(unsigned short layer) const
431  {
432  return std::distance(
433  m_listOfLayers.begin(),
434  std::find(m_listOfLayers.begin(), m_listOfLayers.end(), layer)
435  );
436  }
437 
442  unsigned short getLayerNumberFromLayerIndex(int index) const
443  {
444  return m_listOfLayers[index];
445  }
446 
447 
448  private:
449 
451  void createListOfLayers();
452 
454  void createListOfPXDChips();
455 
457  void createListOfSVDChips();
458 
460  std::vector<VxdID> m_listOfSensors;
461 
464 
466  std::vector<unsigned short> m_listOfLayers;
467 
469  unsigned short m_firstSVDLayer;
470 
472  std::vector<VxdID> m_listOfPXDChips;
473 
475  std::vector<VxdID> m_listOfSVDChips;
476 
478  const unsigned short c_nPXDChipsU = 4;
480  const unsigned short c_nPXDChipsV = 6;
482  const unsigned short c_nPXDReadoutGates = 192;
484  const unsigned short c_nSVDChipsL3 = 6;
486  const unsigned short c_nSVDChipsLu = 6;
488  const unsigned short c_nSVDChipsLv = 4;
490  const unsigned short c_nSVDChannelsPerChip = 128;
491  };
492  } // VXD namespace
494 } // Belle2 namespace
The class collects utility functions for numbering layers, sensors snd chips based on current VXD geo...
Definition: GeoTools.h:25
short getLastSVDLayer() const
Get last (outermost) SVD layer number.
Definition: GeoTools.h:120
bool isPXDSideU(VxdID chipID) const
Decode sensor side from a PXD ChipID.
Definition: GeoTools.h:299
bool isSVDSideU(VxdID chipID) const
Decode sensor side from a SVD ChipID.
Definition: GeoTools.h:397
unsigned short getNumberOfSensors() const
Get total number of sensors.
Definition: GeoTools.h:128
void createListOfLayers()
Create list of VXD layers.
Definition: GeoTools.cc:34
unsigned short getLastLayer() const
Get last (outermost) layer number.
Definition: GeoTools.h:91
VxdID getSensorIDFromSVDIndex(int svdIndex) const
Return VxdID for SVD index of sensor in plots.
Definition: GeoTools.h:343
short getLastPXDLayer() const
Get last (outermost) PXD layer number.
Definition: GeoTools.h:104
VxdID getChipIDFromPXDIndex(int pxdChipIndex) const
Return chipID (VxdID + side and chipNo) for index in the list.
Definition: GeoTools.h:290
int getSVDSensorIndex(int layer, int ladder, int sensor) const
Return index of SVD sensor in plots.
Definition: GeoTools.h:334
unsigned short getNumberOfPXDLayers() const
Get number of PXD layers.
Definition: GeoTools.h:46
std::vector< VxdID > m_listOfSVDChips
List of all SVD chips.
Definition: GeoTools.h:475
unsigned short getNumberOfPXDUSideChips(unsigned short=0) const
Get number of u-side PXD chips.
Definition: GeoTools.h:153
int getPXDSensorIndex(VxdID sensorID) const
Return index of sensor in plots.
Definition: GeoTools.h:228
int getLayerIndex(unsigned short layer) const
Return index of layer in plots.
Definition: GeoTools.h:430
std::vector< unsigned short > getLayers() const
Get numbers of VXD layers.
Definition: GeoTools.h:57
size_t m_firstSVDIndex
Number of the first SVD sensor in the list.
Definition: GeoTools.h:463
VxdID getSensorIDFromIndex(int vxdIndex) const
Reverse lookup VxdID from list index.
Definition: GeoTools.h:215
unsigned short getSVDChannelsPerChip() const
Get number of strips per APV chip in SVD.
Definition: GeoTools.h:192
unsigned short getNumberOfSVDSensors() const
Get number of SVD sensors.
Definition: GeoTools.h:138
short getFirstSVDLayer() const
Get first (innermost) SVD layer number.
Definition: GeoTools.h:112
void createListOfPXDChips()
Create list of PXD chips.
Definition: GeoTools.cc:52
const unsigned short c_nPXDChipsV
Number of PXD chips per sensor in v (Switchers) (=6) on Belle II.
Definition: GeoTools.h:480
void createListOfSVDChips()
Create list of SVD chips.
Definition: GeoTools.cc:73
VxdID getChipIDFromSVDIndex(int svdChipIndex) const
Return chipID (VxdID with side and chipNo) for index in the list.
Definition: GeoTools.h:388
int getSVDChipIndex(VxdID sensorID, bool isU, int chip) const
Return SVD chip index in the list of SVD chips.
Definition: GeoTools.h:358
VxdID getSensorIDFromPXDIndex(int pxdIndex) const
Return index of a PXD sensor in plots.
Definition: GeoTools.h:248
const unsigned short c_nSVDChipsL3
Number of SVD chips per sensor in u,v in layer 3 (=6) on Belle II.
Definition: GeoTools.h:484
unsigned short getLayerNumberFromLayerIndex(int index) const
Return layer number for list index.
Definition: GeoTools.h:442
unsigned short getNumberOfLayers() const
Get number of VXD layers.
Definition: GeoTools.h:41
int getSVDChipIndex(int layer, int ladder, int sensor, bool isU, int chip) const
Return SVD chip index in the list of SVD chips.
Definition: GeoTools.h:379
unsigned short getNumberOfSVDUSideChips(unsigned short=0) const
Get number of u-side SVD chips.
Definition: GeoTools.h:179
unsigned short getPXDChipNumber(VxdID chipID) const
Decode (1-based) chip number from a PXD ChipID.
Definition: GeoTools.h:308
size_t getTotalSVDChips() const
Get total number of chips in SVD.
Definition: GeoTools.h:173
std::vector< VxdID > m_listOfPXDChips
List of all PXD chips.
Definition: GeoTools.h:472
std::vector< unsigned short > m_listOfLayers
List of all VXD layers.
Definition: GeoTools.h:466
int getSensorIndex(VxdID sensorID) const
Return index of s VXD sensor for plotting.
Definition: GeoTools.h:202
unsigned short getNumberOfPXDSensors() const
Get number of PXD sensors.
Definition: GeoTools.h:133
GeoTools()
Constructor builds lookup maps from GeoCache.
Definition: GeoTools.cc:17
size_t getTotalPXDChips() const
Get total number of chips in PXD.
Definition: GeoTools.h:147
const unsigned short c_nPXDChipsU
Number of PXD chips per sensor in u (DCD) (=4) on Belle II.
Definition: GeoTools.h:478
const unsigned short c_nSVDChannelsPerChip
Number of SVD strips per chip on Belle II.
Definition: GeoTools.h:490
int getPXDChipIndex(int layer, int ladder, int sensor, bool isU, int chip) const
Return PXD chip index in the list of PXD chips.
Definition: GeoTools.h:281
const unsigned short c_nSVDChipsLv
Number of SVD chips per sensor in v in layers 4,5,6 (=4) on Belle II.
Definition: GeoTools.h:488
std::vector< VxdID > m_listOfSensors
List of all VXD sesnros.
Definition: GeoTools.h:460
int getPXDChipIndex(VxdID sensorID, bool isU, int chip) const
Return PXD chip index in the list of PXD chips.
Definition: GeoTools.h:263
int getPXDSensorIndex(int layer, int ladder, int sensor) const
Return index of sensor in plots.
Definition: GeoTools.h:239
const unsigned short c_nSVDChipsLu
Number of SVD chips per sensor in u in layers 4,5,6 (=6) on Belle II.
Definition: GeoTools.h:486
unsigned short getNumberOfPXDReadoutGates(unsigned short=0) const
Get number of PXD readout gates.
Definition: GeoTools.h:167
unsigned short getNumberOfPXDVSideChips(unsigned short=0) const
Get number of v-side PXD chips.
Definition: GeoTools.h:160
unsigned short getNumberOfSVDVSideChips(unsigned short layer) const
Get number of v-side SVD chips.
Definition: GeoTools.h:186
short getFirstPXDLayer() const
Get first (innermost) PXD layer number.
Definition: GeoTools.h:96
unsigned short getNumberOfSVDLayers() const
Get number of SVD layers.
Definition: GeoTools.h:51
std::vector< unsigned short > getPXDLayers() const
Get numbers of PXD layers.
Definition: GeoTools.h:62
int getSVDSensorIndex(VxdID sensorID) const
Return index of SVD sensor in plots.
Definition: GeoTools.h:322
std::vector< unsigned short > getSVDLayers() const
Get numbers of SVD layers.
Definition: GeoTools.h:74
unsigned short getSVDChipNumber(VxdID chipID) const
Decode (1-based) chip number from a SVD ChipID.
Definition: GeoTools.h:407
const unsigned short c_nPXDReadoutGates
Number of PXD readout gates (or total number of Switcher channels) on Belle II.
Definition: GeoTools.h:482
unsigned short getFirstLayer() const
Get first (innermost) layer number.
Definition: GeoTools.h:86
unsigned short m_firstSVDLayer
List index of the first SVD layer.
Definition: GeoTools.h:469
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
void setSegmentNumber(baseType segment)
Set the sensor segment.
Definition: VxdID.h:113
baseType getSegmentNumber() const
Get the sensor segment.
Definition: VxdID.h:102
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
Abstract base class for different kinds of events.