Belle II Software light-2406-ragdoll
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#include <mdst/dataobjects/HitPatternVXD.h>
9#include <gtest/gtest.h>
10
11#include <bitset>
12#include <string>
13
14namespace Belle2 {
20 class HitPatternVXDTest : public ::testing::Test {
21 protected:
22 };
23
25 TEST_F(HitPatternVXDTest, NumberingScheme)
26 {
27 const std::list<unsigned short> pxdNumbering = {1, 2};
28 const std::list<unsigned short> svdNumbering = {3, 4, 5, 6};
29 EXPECT_EQ(pxdNumbering, HitPatternVXD::s_PXDLayerNumbers);
30 EXPECT_EQ(svdNumbering, HitPatternVXD::s_SVDLayerNumbers);
31 }
32
34 TEST_F(HitPatternVXDTest, General)
35 {
36 unsigned int initValue = 16776960;
37 std::bitset<32> initValueAsBitset(static_cast<std::string>("00000000111111111111111100000000"));
38
39 HitPatternVXD myHitPattern(initValue);
40 EXPECT_EQ(initValueAsBitset, myHitPattern.getBitset());
41 EXPECT_EQ(initValue, myHitPattern.getInteger());
42
43 }
44
46 TEST_F(HitPatternVXDTest, SVDSetterAndGetter)
47 {
48 HitPatternVXD myHitPattern(0);
49
50 for (const auto layerId : HitPatternVXD::s_SVDLayerNumbers) {
51 unsigned short uHits = 2;
52 unsigned short vHits = 1;
53 myHitPattern.setSVDLayer(layerId, uHits, vHits);
54 EXPECT_EQ(uHits, myHitPattern.getSVDLayer(layerId).first);
55 EXPECT_EQ(vHits, myHitPattern.getSVDLayer(layerId).second);
56 myHitPattern.resetSVDLayer(layerId);
57 EXPECT_EQ(0, myHitPattern.getSVDLayer(layerId).first);
58 EXPECT_EQ(0, myHitPattern.getSVDLayer(layerId).second);
59 uHits = 4;
60 vHits = 4;
61 myHitPattern.setSVDLayer(layerId, uHits, vHits);
62 EXPECT_EQ(3, myHitPattern.getSVDLayer(layerId).first);
63 EXPECT_EQ(3, myHitPattern.getSVDLayer(layerId).second);
64 }
65 }
66
68 TEST_F(HitPatternVXDTest, PXDSetterAndGetter)
69 {
70 HitPatternVXD myHitPattern(0);
71
72 for (const auto layerId : HitPatternVXD::s_PXDLayerNumbers) {
73 for (unsigned int nHits = 0; nHits <= 3; ++nHits) {
74 myHitPattern.setPXDLayer(layerId, nHits, HitPatternVXD::PXDMode::normal);
75 EXPECT_EQ(nHits, myHitPattern.getPXDLayer(layerId, HitPatternVXD::PXDMode::normal));
76 myHitPattern.resetPXDLayer(layerId, HitPatternVXD::PXDMode::normal);
77 EXPECT_EQ(0, myHitPattern.getPXDLayer(layerId, HitPatternVXD::PXDMode::normal));
78
79 myHitPattern.setPXDLayer(layerId, nHits, HitPatternVXD::PXDMode::gated);
80 EXPECT_EQ(nHits, myHitPattern.getPXDLayer(layerId, HitPatternVXD::PXDMode::gated));
81 myHitPattern.resetPXDLayer(layerId, HitPatternVXD::PXDMode::gated);
82 EXPECT_EQ(0, myHitPattern.getPXDLayer(layerId, HitPatternVXD::PXDMode::gated));
83 }
84 }
85
86 for (const auto layerId : HitPatternVXD::s_PXDLayerNumbers) {
87 unsigned int nHits = 4;
88 myHitPattern.setPXDLayer(layerId, nHits, HitPatternVXD::PXDMode::normal);
89 EXPECT_EQ(3, myHitPattern.getPXDLayer(layerId, HitPatternVXD::PXDMode::normal));
90 myHitPattern.resetPXDLayer(layerId, HitPatternVXD::PXDMode::normal);
91 EXPECT_EQ(0, myHitPattern.getPXDLayer(layerId, HitPatternVXD::PXDMode::normal));
92
93 myHitPattern.setPXDLayer(layerId, nHits, HitPatternVXD::PXDMode::gated);
94 EXPECT_EQ(3, myHitPattern.getPXDLayer(layerId, HitPatternVXD::PXDMode::gated));
95 myHitPattern.resetPXDLayer(layerId, HitPatternVXD::PXDMode::gated);
96 EXPECT_EQ(0, myHitPattern.getPXDLayer(layerId, HitPatternVXD::PXDMode::gated));
97 }
98 }
99
101 TEST_F(HitPatternVXDTest, NGetters)
102 {
103 HitPatternVXD myHitPattern(16777215);
104 const unsigned short svdHits = 24;
105 const unsigned short pxdHits = 12;
106 const unsigned short ndf = 2 * pxdHits + svdHits;
107 EXPECT_EQ(svdHits, myHitPattern.getNSVDHits());
108 EXPECT_EQ(pxdHits, myHitPattern.getNPXDHits());
109 EXPECT_EQ(ndf, myHitPattern.getNdf());
110
111 }
112
114 TEST_F(HitPatternVXDTest, getNLayers)
115 {
116 HitPatternVXD myHitPattern(0);
117 const unsigned short nSVD = 3;
118 const unsigned short nPXDnormal = 2;
119 const unsigned short nPXDgated = 1;
120
121 // set SVD
122 myHitPattern.setSVDLayer(3, 1, 3);
123 myHitPattern.setSVDLayer(4, 0, 0);
124 myHitPattern.setSVDLayer(5, 1, 1);
125 myHitPattern.setSVDLayer(6, 0, 1);
126 // set PXD normal
127 myHitPattern.setPXDLayer(1, 1, HitPatternVXD::PXDMode::normal);
128 myHitPattern.setPXDLayer(2, 2, HitPatternVXD::PXDMode::normal);
129 // set PXD gated
130 myHitPattern.setPXDLayer(1, 0, HitPatternVXD::PXDMode::gated);
131 myHitPattern.setPXDLayer(2, 2, HitPatternVXD::PXDMode::gated);
132
133 EXPECT_EQ(nSVD, myHitPattern.getNSVDLayers());
134 EXPECT_EQ(nPXDnormal, myHitPattern.getNPXDLayers(HitPatternVXD::PXDMode::normal));
135 EXPECT_EQ(nPXDgated, myHitPattern.getNPXDLayers(HitPatternVXD::PXDMode::gated));
136 EXPECT_EQ(nSVD + nPXDnormal, myHitPattern.getNVXDLayers(HitPatternVXD::PXDMode::normal));
137 EXPECT_EQ(nSVD + nPXDgated, myHitPattern.getNVXDLayers(HitPatternVXD::PXDMode::gated));
138
139 }
140
142 TEST_F(HitPatternVXDTest, getFirstLastLayer)
143 {
144 HitPatternVXD myHitPattern(0);
145 // random choices
146 const unsigned short firstLayerPXD = 1;
147 const unsigned short lastLayerPXD = 2;
148 const unsigned short firstLayerSVD = 4;
149 const unsigned short lastLayerSVD = 6;
150
151 // set SVD
152 myHitPattern.setSVDLayer(3, 0, 0);
153 myHitPattern.setSVDLayer(4, 3, 0);
154 myHitPattern.setSVDLayer(5, 0, 1);
155 myHitPattern.setSVDLayer(6, 1, 1);
156 // set PXD normal
157 myHitPattern.setPXDLayer(1, 1, HitPatternVXD::PXDMode::normal);
158 myHitPattern.setPXDLayer(2, 2, HitPatternVXD::PXDMode::normal);
159 // set PXD gated
160 myHitPattern.setPXDLayer(1, 1, HitPatternVXD::PXDMode::gated);
161 myHitPattern.setPXDLayer(2, 2, HitPatternVXD::PXDMode::gated);
162
163 EXPECT_EQ(firstLayerSVD, myHitPattern.getFirstSVDLayer());
164 EXPECT_EQ(lastLayerSVD, myHitPattern.getLastSVDLayer());
165 EXPECT_EQ(firstLayerPXD, myHitPattern.getFirstPXDLayer(HitPatternVXD::PXDMode::normal));
166 EXPECT_EQ(lastLayerPXD, myHitPattern.getLastPXDLayer(HitPatternVXD::PXDMode::normal));
167 EXPECT_EQ(firstLayerPXD, myHitPattern.getFirstPXDLayer(HitPatternVXD::PXDMode::gated));
168 EXPECT_EQ(lastLayerPXD, myHitPattern.getLastPXDLayer(HitPatternVXD::PXDMode::gated));
169 }
171}
Hit pattern of the VXD within a track.
Definition: HitPatternVXD.h:37
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.
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.
unsigned int getInteger() const
Getter for the underlying integer.
Definition: HitPatternVXD.h:58
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 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.
std::bitset< 32 > getBitset() const
Getter for underlying bitset.
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.
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.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24