Belle II Software  release-08-01-10
HitPatternVXD.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 #include <mdst/dataobjects/HitPatternVXD.h>
10 #include <framework/logging/Logger.h>
11 
12 
13 using namespace Belle2;
14 
15 const std::list<unsigned short> HitPatternVXD::s_PXDLayerNumbers = {1, 2};
16 const std::list<unsigned short> HitPatternVXD::s_SVDLayerNumbers = {3, 4, 5, 6};
17 
18 const std::bitset<32> HitPatternVXD::s_LayerMasks[6] = {
19  std::bitset<32>(static_cast<std::string>("00000000000000000000000000001111")), // layer1 PXD
20  std::bitset<32>(static_cast<std::string>("00000000000000000000000011110000")), // layer2 PXD
21  std::bitset<32>(static_cast<std::string>("00000000000000000000111100000000")), // layer3 SVD
22  std::bitset<32>(static_cast<std::string>("00000000000000001111000000000000")), // layer4 SVD
23  std::bitset<32>(static_cast<std::string>("00000000000011110000000000000000")), // layer5 SVD
24  std::bitset<32>(static_cast<std::string>("00000000111100000000000000000000")) // layer6 SVD
25 };
26 
27 const std::bitset<32> HitPatternVXD::s_PXDModeMasks[2] = {
28  std::bitset<32>(static_cast<std::string>("00000000000000000000000000110011")), // normal mode
29  std::bitset<32>(static_cast<std::string>("00000000000000000000000011001100")) // gated mode
30 };
31 
32 const std::bitset<32> HitPatternVXD::s_SVDuvMasks[2] = {
33  std::bitset<32>(static_cast<std::string>("00000000001100110011001100000000")), // u layer
34  std::bitset<32>(static_cast<std::string>("00000000110011001100110000000000")) // v layer
35 };
36 
37 const std::bitset<32> HitPatternVXD::s_V0DaughterMask(static_cast<std::string>("00000011000000000000000000000000"));
38 
39 const std::bitset<32> HitPatternVXD::s_infoLayerMask(static_cast<std::string>("11111100000000000000000000000000"));
40 
41 unsigned short HitPatternVXD::getNdf() const
42 {
43  return 2 * getNPXDHits() + getNSVDHits();
44 }
45 
46 unsigned short HitPatternVXD::getNVXDLayers(const PXDMode& pxdmode) const
47 {
48  return getNPXDLayers(pxdmode) + getNSVDLayers();
49 }
50 
51 void HitPatternVXD::setSVDLayer(const unsigned short layerId, unsigned short uHits, unsigned short vHits)
52 {
53  B2ASSERT("SVD layer is out of range.", 3 <= layerId and layerId <= 6);
54  resetSVDLayer(layerId);
55  if (uHits > 3) uHits = 3;
56  if (vHits > 3) vHits = 3;
57  const unsigned short arrayId = layerId - 3;
58  std::bitset<32> uHitPattern(uHits);
59  uHitPattern <<= s_svdUshift + 4 * arrayId;
60  std::bitset<32> vHitPattern(vHits);
61  vHitPattern <<= s_svdVshift + 4 * arrayId;
62  m_pattern |= (uHitPattern | vHitPattern);
63 }
64 
65 std::pair<const unsigned short, const unsigned short> HitPatternVXD::getSVDLayer(const unsigned short layerId) const
66 {
67  B2ASSERT("SVD layer is out of range.", 3 <= layerId and layerId <= 6);
68  std::bitset<32> uHitsPattern(m_pattern & (getLayerMask(layerId) & s_SVDuvMasks[0]));
69  std::bitset<32> vHitsPattern(m_pattern & (getLayerMask(layerId) & s_SVDuvMasks[1]));
70  const unsigned short arrayId = layerId - 3;
71  const unsigned short uHits = (uHitsPattern >> (s_svdUshift + 4 * arrayId)).to_ulong();
72  const unsigned short vHits = (vHitsPattern >> (s_svdVshift + 4 * arrayId)).to_ulong();
73  return std::make_pair(uHits, vHits);
74 }
75 
76 void HitPatternVXD::resetSVDLayer(const unsigned short layerId)
77 {
78  B2ASSERT("SVD layer is out of range.", 3 <= layerId and layerId <= 6);
79  m_pattern &= ~getLayerMask(layerId);
80  return;
81 }
82 
83 unsigned short HitPatternVXD::getNSVDHits() const
84 {
85  unsigned short svdHits = 0;
86  for (const auto layerId : s_SVDLayerNumbers) {
87  std::pair<const unsigned short, const unsigned short> svdHitPair = getSVDLayer(layerId);
88  svdHits += svdHitPair.first + svdHitPair.second;
89  }
90  return svdHits;
91 }
92 
93 unsigned short HitPatternVXD::getNSVDLayers() const
94 {
95  unsigned short nSVD = 0;
96  for (const auto layerId : s_SVDLayerNumbers) {
97  std::pair<const unsigned short, const unsigned short> hits(getSVDLayer(layerId));
98  if ((hits.first + hits.second) > 0) ++nSVD;
99  }
100  return nSVD;
101 }
102 
104 {
105  for (const auto layerId : s_SVDLayerNumbers) {
106  std::pair<const unsigned short, const unsigned short> hits(getSVDLayer(layerId));
107  if ((hits.first + hits.second) > 0) return layerId;
108  }
109  return -1;
110 }
111 
113 {
114  for (auto rit = s_SVDLayerNumbers.rbegin(); rit != s_SVDLayerNumbers.rend(); ++rit) {
115  const auto layerId = *rit;
116  std::pair<const unsigned short, const unsigned short> hits(getSVDLayer(layerId));
117  if ((hits.first + hits.second) > 0) return layerId;
118  }
119  return -1;
120 }
121 
122 void HitPatternVXD::setPXDLayer(const unsigned short layerId, unsigned short nHits, const PXDMode& mode)
123 {
124  B2ASSERT("PXD layer is out of range.", layerId == 1 or layerId == 2);
125  resetPXDLayer(layerId, mode);
126  if (nHits > 3) nHits = 3; // A Maximum of 3 can be stored in 2 bits.
127  std::bitset<32> hits(nHits);
128  const unsigned short arrayId = layerId - 1;
129  hits <<= 4 * arrayId + 2 * static_cast<unsigned short>(mode);
130  m_pattern |= hits;
131 }
132 
133 unsigned short HitPatternVXD::getPXDLayer(const unsigned short layerId, const PXDMode& mode) const
134 {
135  B2ASSERT("PXD layer is out of range.", layerId == 1 or layerId == 2);
136  const unsigned short arrayId = layerId - 1;
137  std::bitset<32> hits(m_pattern & (getLayerMask(layerId) & s_PXDModeMasks[static_cast<unsigned short>(mode)]));
138  return (hits >> (4 * arrayId + 2 * static_cast<unsigned short>(mode))).to_ulong();
139 }
140 
141 void HitPatternVXD::resetPXDLayer(const unsigned short layerId, const PXDMode& mode)
142 {
143  B2ASSERT("PXD layer is out of range.", layerId == 1 or layerId == 2);
144  m_pattern &= ~(getLayerMask(layerId) & s_PXDModeMasks[static_cast<unsigned short>(mode)]);
145 }
146 
147 unsigned short HitPatternVXD::getNPXDHits() const
148 {
149  unsigned short pxdHits = 0;
150  for (const auto layerId : s_PXDLayerNumbers) {
151  pxdHits += getPXDLayer(layerId, PXDMode::normal);
152  pxdHits += getPXDLayer(layerId, PXDMode::gated);
153  }
154  return pxdHits;
155 }
156 
157 unsigned short HitPatternVXD::getNPXDLayers(const PXDMode& mode) const
158 {
159  unsigned short nPXD = 0;
160  for (const auto layerId : s_PXDLayerNumbers) {
161  if (getPXDLayer(layerId, mode) > 0) ++nPXD;
162  }
163  return nPXD;
164 }
165 
166 short HitPatternVXD::getFirstPXDLayer(const PXDMode& mode) const
167 {
168  for (const auto layerId : s_PXDLayerNumbers) {
169  if (getPXDLayer(layerId, mode) > 0) return layerId;
170  }
171  return -1;
172 }
173 
174 short HitPatternVXD::getLastPXDLayer(const PXDMode& mode) const
175 {
176  for (auto rit = s_PXDLayerNumbers.rbegin(); rit != s_PXDLayerNumbers.rend(); ++rit) {
177  const auto layerId = *rit;
178  if (getPXDLayer(layerId, mode) > 0) return layerId;
179  }
180  return -1;
181 }
182 
183 void HitPatternVXD::setInnermostHitShareStatus(const unsigned short innermostHitShareStatus)
184 {
185  B2ASSERT("Information is out of range. Information: " << innermostHitShareStatus << ", range: " << (s_V0DaughterMask >>
186  (4 * 6)).to_ulong(),
187  innermostHitShareStatus <= (s_V0DaughterMask >> (4 * 6)).to_ulong());
189  std::bitset<32> hits(innermostHitShareStatus);
190  hits <<= 4 * 6;
191  m_pattern |= hits;
192 }
193 
195 {
196  std::bitset<32> hits(m_pattern & s_V0DaughterMask);
197  return (hits >> (4 * 6)).to_ulong();
198 }
199 
201 {
203 }
204 
205 std::string HitPatternVXD::__str__() const
206 {
207  return m_pattern.to_string();
208 }
short getLastSVDLayer() const
Get the last activated SVD layer index.
static const std::list< unsigned short > s_SVDLayerNumbers
For iterating through layers.
void resetSVDLayer(const unsigned short layerId)
Reset the number of hits in a specific layer of the SVD.
std::bitset< 32 > m_pattern
Storing of actual hit pattern.
std::string __str__() const
String for printing in python.
unsigned short getNSVDLayers() const
Returns the total number of activated layers of the SVD.
unsigned short getNPXDLayers(const PXDMode &mode=PXDMode::normal) const
Returns the total number of activated layers of the PXD.
static const std::bitset< 32 > s_PXDModeMasks[2]
Mask to zero out all bits from other layers.
static const std::bitset< 32 > s_V0DaughterMask
Mask to zero out all bits from other layers.
static const std::bitset< 32 > s_SVDuvMasks[2]
Mask to zero out all bits from other layers.
short getFirstSVDLayer() const
Get the first activated SVD layer index.
void setSVDLayer(const unsigned short layerId, unsigned short uHits, unsigned short vHits)
Set the number of hits in a specific layer of the SVD.
unsigned short getNVXDLayers(const PXDMode &pxdmode=PXDMode::normal) const
Return the total number of activated layers in the VXD depending on the mode of the PXD.
void resetPXDLayer(const unsigned short layerId, const PXDMode &mode=PXDMode::normal)
Reset the number of hits in a specific layer of the PXD.
static const std::list< unsigned short > s_PXDLayerNumbers
For iterating through layers.
unsigned short getNPXDHits() const
Get total number of hits in the PXD.
unsigned short getNSVDHits() const
Get total number of hits in the SVD.
void setInnermostHitShareStatus(const unsigned short innermostHitShareStatus)
Set the innermost hit share flags for V0 daughters.
void setPXDLayer(const unsigned short layerId, unsigned short nHits, const PXDMode &mode=PXDMode::normal)
Set the number of hits in a specific layer of the PXD.
short getLastPXDLayer(const PXDMode &mode=PXDMode::normal) const
Returns the last activated layer of the PXD depending on the mode.
void resetInnermostHitShareStatus()
Reset the innermost hit share flags for V0 daughters.
static const std::bitset< 32 > s_infoLayerMask
Mask to zero out all bits from other layers.
static const std::bitset< 32 > s_LayerMasks[6]
Masks to zero out all bits from other layers.
unsigned short getPXDLayer(const unsigned short layerId, const PXDMode &mode=PXDMode::normal) const
Get the number of hits in a specific layer of the PXD.
static const unsigned int s_svdVshift
for internal shifting to the SVD bits.
static const unsigned int s_svdUshift
for internal shifting to the SVD bits.
short getFirstPXDLayer(const PXDMode &mode=PXDMode::normal) const
Returns the first activated layer of the PXD depending on the mode.
unsigned short getNdf() const
Get degrees of freedom in PXD and SVD.
std::pair< const unsigned short, const unsigned short > getSVDLayer(const unsigned short layerId) const
Get the number of hits in a specific layer of the SVD.
std::bitset< 32 > getLayerMask(const unsigned short layerId) const
Getter for the proper layer masks.
unsigned short getInnermostHitShareStatus() const
Get the innermost hit share flags for V0 daughters.
Abstract base class for different kinds of events.