Belle II Software  release-08-01-10
KLMMuidLikelihoodTest.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/KLMMuidLikelihood.h>
11 
12 /* Basf2 headers. */
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/gearbox/Const.h>
15 
16 /* C++ headers. */
17 #include <bitset>
18 #include <string>
19 
20 /* Google Test headers. */
21 #include <gtest/gtest.h>
22 
23 namespace Belle2 {
30  class KLMMuidLikelihoodTest : public ::testing::Test {
31 
32  protected:
34  void SetUp() override
35  {
38  muids.registerInDataStore();
40  }
41 
43  void TearDown() override
44  {
46  }
47 
50  };
51 
54  {
56 
57  // Test the non-default constructor
58  int pdg = Const::muon.getPDGCode();
59  m_muid = muids.appendNew();
60  m_muid->setPDGCode(pdg);
61  EXPECT_EQ(m_muid->getPDGCode(), pdg);
62  EXPECT_EQ(m_muid->getOutcome(), 0);
63  EXPECT_EQ(m_muid->getHitLayer(), -1);
64  EXPECT_FLOAT_EQ(m_muid->getLogL_mu(), -1.0E20);
65 
66  // Test the efficiency methods
67  int layer = 4;
68  float efficiency = 0.2;
69  m_muid->setExtBKLMEfficiencyValue(layer, efficiency);
70  EXPECT_FLOAT_EQ(m_muid->getExtBKLMEfficiencyValue(layer), efficiency);
71  m_muid->setExtEKLMEfficiencyValue(layer, efficiency);
72  EXPECT_FLOAT_EQ(m_muid->getExtEKLMEfficiencyValue(layer), efficiency);
73 
74  // Test the methods to count the hits and to check the crossed layer
75  // 111111
76  // it means 6 hits in BKLM and 0 in EKLM
77  std::bitset<30> bitPattern(std::string("111111"));
78  unsigned int pattern = static_cast<unsigned int>(bitPattern.to_ulong());
79  m_muid->setHitLayerPattern(pattern);
80  EXPECT_EQ(m_muid->getHitLayerPattern(), pattern);
81  EXPECT_EQ(m_muid->getTotalBarrelHits(), 6);
82  EXPECT_EQ(m_muid->getTotalEndcapHits(), 0);
83  m_muid->setExtLayerPattern(pattern);
84  EXPECT_TRUE(m_muid->isExtrapolatedBarrelLayerCrossed(5));
85  EXPECT_FALSE(m_muid->isExtrapolatedBarrelLayerCrossed(6));
86  EXPECT_FALSE(m_muid->isExtrapolatedEndcapLayerCrossed(0));
87  // 1000000000000000
88  // it means 0 hits in BKLM and 1 in EKLM
89  bitPattern = std::bitset<30>(std::string("1000000000000000"));
90  pattern = static_cast<unsigned int>(bitPattern.to_ulong());
91  m_muid->setHitLayerPattern(pattern);
92  EXPECT_EQ(m_muid->getHitLayerPattern(), pattern);
93  EXPECT_EQ(m_muid->getTotalBarrelHits(), 0);
94  EXPECT_EQ(m_muid->getTotalEndcapHits(), 1);
95  m_muid->setExtLayerPattern(pattern);
96  EXPECT_FALSE(m_muid->isExtrapolatedBarrelLayerCrossed(0));
97  EXPECT_TRUE(m_muid->isExtrapolatedEndcapLayerCrossed(0));
98  EXPECT_FALSE(m_muid->isExtrapolatedEndcapLayerCrossed(1));
99  // 10101000000000111000
100  // it means 3 hits in BKLM and 3 in EKLM
101  bitPattern = std::bitset<30>(std::string("10101000000000111000"));
102  pattern = static_cast<unsigned int>(bitPattern.to_ulong());
103  m_muid->setHitLayerPattern(pattern);
104  EXPECT_EQ(m_muid->getHitLayerPattern(), pattern);
105  EXPECT_EQ(m_muid->getTotalBarrelHits(), 3);
106  EXPECT_EQ(m_muid->getTotalEndcapHits(), 3);
107  m_muid->setExtLayerPattern(pattern);
108  EXPECT_TRUE(m_muid->isExtrapolatedBarrelLayerCrossed(4));
109  EXPECT_TRUE(m_muid->isExtrapolatedEndcapLayerCrossed(0));
110  EXPECT_FALSE(m_muid->isExtrapolatedEndcapLayerCrossed(10));
111  // 11111111111111111111111111111
112  // it means 15 hits in BKLM, 14 in EKLM and 1 "fake" hit
113  bitPattern = std::bitset<30>(std::string("11111111111111111111111111111"));
114  pattern = static_cast<unsigned int>(bitPattern.to_ulong());
115  m_muid->setHitLayerPattern(pattern);
116  EXPECT_EQ(m_muid->getHitLayerPattern(), pattern);
117  EXPECT_EQ(m_muid->getTotalBarrelHits(), 15);
118  EXPECT_EQ(m_muid->getTotalEndcapHits(), 14);
119  m_muid->setExtLayerPattern(pattern);
120  EXPECT_TRUE(m_muid->isExtrapolatedBarrelLayerCrossed(14));
121  EXPECT_FALSE(m_muid->isExtrapolatedBarrelLayerCrossed(15));
122  EXPECT_TRUE(m_muid->isExtrapolatedEndcapLayerCrossed(13));
123  }
124 
126 }
int getPDGCode() const
PDG code.
Definition: Const.h:464
static const ChargedStable muon
muon particle
Definition: Const.h:651
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
Test class for the KLMMuidLikelihood object.
KLMMuidLikelihood * m_muid
Pointer to a Muid object.
void SetUp() override
Register KLMMuidLikelihood in the DataStore.
void TearDown() override
Clear the DataStore.
Class to store the likelihoods from KLM with additional informations related to the extrapolation.
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
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Definition: globalLabel.cc:72
Abstract base class for different kinds of events.