Belle II Software development
MuidBuilderTest.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/* KLM headers. */
10#include <klm/dataobjects/bklm/BKLMElementNumbers.h>
11#include <klm/dataobjects/eklm/EKLMElementNumbers.h>
12#include <klm/dataobjects/KLMMuidLikelihood.h>
13#include <klm/muid/MuidBuilder.h>
14#include <klm/muid/MuidElementNumbers.h>
15
16/* Basf2 headers. */
17#include <framework/database/Database.h>
18#include <framework/database/DBStore.h>
19#include <framework/dataobjects/EventMetaData.h>
20#include <framework/datastore/StoreArray.h>
21#include <framework/datastore/StoreObjPtr.h>
22#include <framework/gearbox/Const.h>
23
24/* C++ headers. */
25#include <bitset>
26#include <string>
27
28/* Google Test headers. */
29#include <gtest/gtest.h>
30
31namespace Belle2 {
38 class MuidBuilderTest : public ::testing::Test {
39
40 protected:
41
43 void SetUp() override
44 {
45 /* DataStore. */
48 muids.registerInDataStore();
49 StoreObjPtr<EventMetaData> eventMetaData;
50 eventMetaData.registerInDataStore();
52 /* Database. */
53 eventMetaData.construct(1, 0, 0);
54 DBStore& dbStore = DBStore::Instance();
55 dbStore.update();
56 dbStore.updateEvent();
57 }
58
60 void TearDown() override
61 {
64 }
65
68
71
74
77 };
78
80 TEST_F(MuidBuilderTest, MuidBuilder01)
81 {
83 int pdg = Const::muon.getPDGCode();
84 std::bitset<30> bitExtPattern(std::string("11111111111111"));
85 unsigned int extPattern = static_cast<unsigned int>(bitExtPattern.to_ulong());
86 unsigned int hitPattern = static_cast<unsigned int>(bitExtPattern.to_ulong());
87 bool isForward = true;
88 bool escaped = false;
89 int lastBarrelLayer = 13;
90 int lastEndcapLayer = -1;
91 unsigned int outcome = MuidElementNumbers::calculateExtrapolationOutcome(isForward, escaped, lastBarrelLayer, lastEndcapLayer);
92 double chiSquared = 29.5;
93 int degreesOfFreedom = 28;
94 m_muid = muids.appendNew();
95 m_muid->setPDGCode(pdg);
96 m_muid->setExtLayerPattern(extPattern);
97 m_muid->setHitLayerPattern(hitPattern);
98 m_muid->setIsForward(isForward);
99 m_muid->setBarrelExtLayer(lastBarrelLayer);
100 m_muid->setEndcapExtLayer(lastBarrelLayer);
101 m_muid->setOutcome(outcome);
102 m_muid->setChiSquared(chiSquared);
103 m_muid->setDegreesOfFreedom(degreesOfFreedom);
104 std::vector<float> logLVector = { -169.215, -0.288937, -46.5124, -49.7292, -72.7715, -96.2517};
105 for (size_t i = 0; i < m_pdgVectorMinus.size(); ++i) {
106 m_muidBuilder = new MuidBuilder(m_pdgVectorMinus.at(i));
107 float logL = std::log(m_muidBuilder->getPDF(m_muid));
108 EXPECT_LT(std::abs(logL - logLVector.at(i)), 10E-4);
109 delete m_muidBuilder;
110 }
111 logLVector.clear();
112 /* Test for the positive-charged hypotheses. */
113 m_pdgVectorPlus = MuidElementNumbers::getPDGVector(1);
114 logLVector = { -169.215, -0.284881, -45.7914, -42.7717, -95.9839, -118.769};
115 for (size_t i = 0; i < m_pdgVectorPlus.size(); ++i) {
116 m_muidBuilder = new MuidBuilder(m_pdgVectorPlus.at(i));
117 float logL = std::log(m_muidBuilder->getPDF(m_muid));
118 EXPECT_LT(std::abs(logL - logLVector.at(i)), 10E-4);
119 delete m_muidBuilder;
120 }
121 }
122
124 TEST_F(MuidBuilderTest, MuidBuilder02)
125 {
127 int pdg = Const::muon.getPDGCode();
128 std::bitset<30> bitExtPattern(std::string("11111111111111"));
129 unsigned int extPattern = static_cast<unsigned int>(bitExtPattern.to_ulong());
130 std::bitset<30> bitHitPattern(std::string("11011111111101"));
131 unsigned int hitPattern = static_cast<unsigned int>(bitHitPattern.to_ulong());
132 bool isForward = true;
133 bool escaped = false;
134 int lastBarrelLayer = 13;
135 int lastEndcapLayer = -1;
136 unsigned int outcome = MuidElementNumbers::calculateExtrapolationOutcome(isForward, escaped, lastBarrelLayer, lastEndcapLayer);
137 double chiSquared = 23.5;
138 int degreesOfFreedom = 24;
139 m_muid = muids.appendNew();
140 m_muid->setPDGCode(pdg);
141 m_muid->setExtLayerPattern(extPattern);
142 m_muid->setHitLayerPattern(hitPattern);
143 m_muid->setIsForward(isForward);
144 m_muid->setBarrelExtLayer(lastBarrelLayer);
145 m_muid->setEndcapExtLayer(lastBarrelLayer);
146 m_muid->setOutcome(outcome);
147 m_muid->setChiSquared(chiSquared);
148 m_muid->setDegreesOfFreedom(degreesOfFreedom);
149 std::vector<float> logLVector = { -147.07, -6.37567, -40.9424, -43.8204, -63.8973, -84.6684};
150 for (size_t i = 0; i < m_pdgVectorMinus.size(); ++i) {
151 m_muidBuilder = new MuidBuilder(m_pdgVectorMinus.at(i));
152 float logL = std::log(m_muidBuilder->getPDF(m_muid));
153 EXPECT_LT(std::abs(logL - logLVector.at(i)), 10E-4);
154 delete m_muidBuilder;
155 }
156 }
157
159 TEST_F(MuidBuilderTest, MuidBuilder03)
160 {
162 int pdg = Const::muon.getPDGCode();
163 std::bitset<30> bitExtPattern(std::string("11111111111111"));
164 unsigned int extPattern = static_cast<unsigned int>(bitExtPattern.to_ulong());
165 std::bitset<30> bitHitPattern(std::string("11"));
166 unsigned int hitPattern = static_cast<unsigned int>(bitHitPattern.to_ulong());
167 bool isForward = true;
168 bool escaped = false;
169 int lastBarrelLayer = 1;
170 int lastEndcapLayer = -1;
171 unsigned int outcome = MuidElementNumbers::calculateExtrapolationOutcome(isForward, escaped, lastBarrelLayer, lastEndcapLayer);
172 double chiSquared = 7.5;
173 int degreesOfFreedom = 4;
174 m_muid = muids.appendNew();
175 m_muid->setPDGCode(pdg);
176 m_muid->setExtLayerPattern(extPattern);
177 m_muid->setHitLayerPattern(hitPattern);
178 m_muid->setIsForward(isForward);
179 m_muid->setBarrelExtLayer(lastBarrelLayer);
180 m_muid->setEndcapExtLayer(lastBarrelLayer);
181 m_muid->setOutcome(outcome);
182 m_muid->setChiSquared(chiSquared);
183 m_muid->setDegreesOfFreedom(degreesOfFreedom);
184 std::vector<float> logLVector = { -13.0068, -1.82853, -4.78739, -6.44048, -6.67272, -6.8342};
185 for (size_t i = 0; i < m_pdgVectorMinus.size(); ++i) {
186 m_muidBuilder = new MuidBuilder(m_pdgVectorMinus.at(i));
187 float logL = std::log(m_muidBuilder->getPDF(m_muid));
188 EXPECT_LT(std::abs(logL - logLVector.at(i)), 10E-4);
189 delete m_muidBuilder;
190 }
191 }
192
194 TEST_F(MuidBuilderTest, MuidBuilder04)
195 {
197 int pdg = Const::muon.getPDGCode();
198 std::bitset<30> bitExtPattern(std::string("1111111000000000000111"));
199 unsigned int extPattern = static_cast<unsigned int>(bitExtPattern.to_ulong());
200 unsigned int hitPattern = static_cast<unsigned int>(bitExtPattern.to_ulong());
201 /* Test the forward endcap. */
202 bool isForward = true;
203 bool escaped = false;
204 int lastBarrelLayer = 2;
205 int lastEndcapLayer = 6;
206 unsigned int outcome = MuidElementNumbers::calculateExtrapolationOutcome(isForward, escaped, lastBarrelLayer, lastEndcapLayer);
207 double chiSquared = 19.5;
208 int degreesOfFreedom = 20;
209 m_muid = muids.appendNew();
210 m_muid->setPDGCode(pdg);
211 m_muid->setExtLayerPattern(extPattern);
212 m_muid->setHitLayerPattern(hitPattern);
213 m_muid->setIsForward(isForward);
214 m_muid->setBarrelExtLayer(lastBarrelLayer);
215 m_muid->setEndcapExtLayer(lastBarrelLayer);
216 m_muid->setOutcome(outcome);
217 m_muid->setChiSquared(chiSquared);
218 m_muid->setDegreesOfFreedom(degreesOfFreedom);
219 std::vector<float> logLVector = { -44.4325, -0.746618, -17.3903, -18.7434, -25.4178, -34.7886};
220 for (size_t i = 0; i < m_pdgVectorMinus.size(); ++i) {
221 m_muidBuilder = new MuidBuilder(m_pdgVectorMinus.at(i));
222 float logL = std::log(m_muidBuilder->getPDF(m_muid));
223 EXPECT_LT(std::abs(logL - logLVector.at(i)), 10E-4);
224 delete m_muidBuilder;
225 }
226 logLVector.clear();
227 /* Test the backward endcap. */
228 isForward = false;
229 outcome = MuidElementNumbers::calculateExtrapolationOutcome(isForward, escaped, lastBarrelLayer, lastEndcapLayer);
230 m_muid->setIsForward(isForward);
231 m_muid->setOutcome(outcome);
232 logLVector = { -50.7005, -1.11268, -18.3302, -20.7392, -26.5815, -33.6206};
233 for (size_t i = 0; i < m_pdgVectorMinus.size(); ++i) {
234 m_muidBuilder = new MuidBuilder(m_pdgVectorMinus.at(i));
235 float logL = std::log(m_muidBuilder->getPDF(m_muid));
236 EXPECT_LT(std::abs(logL - logLVector.at(i)), 10E-4);
237 delete m_muidBuilder;
238 }
239 }
240
242 TEST_F(MuidBuilderTest, MuidBuilder05)
243 {
245 int pdg = Const::muon.getPDGCode();
246 std::bitset<30> bitExtPattern(std::string("1111111000000000000111"));
247 unsigned int extPattern = static_cast<unsigned int>(bitExtPattern.to_ulong());
248 std::bitset<30> bitHitPattern(std::string("1100111000000000000101"));
249 unsigned int hitPattern = static_cast<unsigned int>(bitHitPattern.to_ulong());
250 /* Test the forward endcap. */
251 bool isForward = true;
252 bool escaped = false;
253 int lastBarrelLayer = 2;
254 int lastEndcapLayer = 6;
255 unsigned int outcome = MuidElementNumbers::calculateExtrapolationOutcome(isForward, escaped, lastBarrelLayer, lastEndcapLayer);
256 double chiSquared = 15.5;
257 int degreesOfFreedom = 14;
258 float efficiency = 0.8437;
259 m_muid = muids.appendNew();
260 m_muid->setPDGCode(pdg);
261 m_muid->setExtLayerPattern(extPattern);
262 m_muid->setHitLayerPattern(hitPattern);
263 m_muid->setIsForward(isForward);
264 m_muid->setBarrelExtLayer(lastBarrelLayer);
265 m_muid->setEndcapExtLayer(lastBarrelLayer);
266 m_muid->setOutcome(outcome);
267 m_muid->setChiSquared(chiSquared);
268 m_muid->setDegreesOfFreedom(degreesOfFreedom);
269 for (int layer = 0; layer < BKLMElementNumbers::getMaximalLayerNumber(); ++layer)
270 m_muid->setExtBKLMEfficiencyValue(layer, efficiency);
271 for (int layer = 0; layer < EKLMElementNumbers::getMaximalLayerNumber(); ++layer)
272 m_muid->setExtEKLMEfficiencyValue(layer, efficiency);
273 std::vector<float> logLVector = { -38.1205, -2.43391, -16.0512, -17.094, -23.4617, -31.9516};
274 for (size_t i = 0; i < m_pdgVectorMinus.size(); ++i) {
275 m_muidBuilder = new MuidBuilder(m_pdgVectorMinus.at(i));
276 float logL = std::log(m_muidBuilder->getPDF(m_muid));
277 EXPECT_LT(std::abs(logL - logLVector.at(i)), 10E-4);
278 delete m_muidBuilder;
279 }
280 logLVector.clear();
281 /* Test the backward endcap. */
282 isForward = false;
283 outcome = MuidElementNumbers::calculateExtrapolationOutcome(isForward, escaped, lastBarrelLayer, lastEndcapLayer);
284 m_muid->setIsForward(isForward);
285 m_muid->setOutcome(outcome);
286 logLVector = { -43.7474, -2.51744, -16.6359, -18.5523, -23.8643, -29.9728};
287 for (size_t i = 0; i < m_pdgVectorMinus.size(); ++i) {
288 m_muidBuilder = new MuidBuilder(m_pdgVectorMinus.at(i));
289 float logL = std::log(m_muidBuilder->getPDF(m_muid));
290 EXPECT_LT(std::abs(logL - logLVector.at(i)), 10E-4);
291 delete m_muidBuilder;
292 }
293 }
294
296}
R E
internal precision of FFTW codelets
static constexpr int getMaximalLayerNumber()
Get maximal layer number (1-based).
int getPDGCode() const
PDG code.
Definition: Const.h:473
static const ChargedStable muon
muon particle
Definition: Const.h:660
Singleton class to cache database objects.
Definition: DBStore.h:31
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:94
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Definition: DataStore.cc:86
static constexpr int getMaximalLayerNumber()
Get maximal layer number.
Class to store the likelihoods from KLM with additional information related to the extrapolation.
Test for the MuidBuilder class, using the payloads in the default Global Tag.
KLMMuidLikelihood * m_muid
Pointer to a Muid object.
void SetUp() override
Register the necessary objects in the DataStore and setup the Database.
MuidBuilder * m_muidBuilder
Pointer to a MuidBuilder class.
std::vector< int > m_pdgVectorPlus
Vector of positive charged hypotheses.
void TearDown() override
Clear the DataStore and reset the Database.
std::vector< int > m_pdgVectorMinus
Vector of negative charged hypotheses.
Build the Muid likelihoods starting from the hit pattern and the transverse scattering in the KLM.
Definition: MuidBuilder.h:29
static unsigned int calculateExtrapolationOutcome(bool isForward, bool escaped, int lastBarrelLayer, int lastEndcapLayer)
Calculate the track extrapolation outcome.
static std::vector< int > getPDGVector()
Get a vector with all the hypothesis PDG codes used for Muid.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:119
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:28
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:142
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:79
static void reset(bool keepConfig=false)
Reset the database instance.
Definition: Database.cc:50
Abstract base class for different kinds of events.