Belle II Software  release-08-01-10
hitPatternCDC.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 <gtest/gtest.h>
9 #include <mdst/dataobjects/HitPatternCDC.h>
10 
11 namespace Belle2 {
17  class HitPatternCDCTest : public ::testing::Test {
18  protected:
19  };
20 
22  TEST_F(HitPatternCDCTest, settersNGetters)
23  {
24  // Test proper initialization.
25  unsigned long initValue = 66560; // python >>> 2 ** 16 + 2 ** 10
26  HitPatternCDC hitPatternCDC(initValue);
27  EXPECT_EQ(initValue, hitPatternCDC.getInteger());
28 
29  HitPatternCDC hitPatternCDC2;
30  EXPECT_EQ(0, hitPatternCDC2.getNHits());
31 
32  // Test setting and getting individual bits
33  short layer = 5;
34  hitPatternCDC2.setLayer(layer);
35  EXPECT_EQ(true, hitPatternCDC2.hasLayer(5));
36 
37  // Test of SuperLayer getters; setters don't make sense.
38  // Reminder: Start counting from 0 here.
39  // Even -> Axial Layer; Odd -> Stereo Layer
40  HitPatternCDC hitPatternCDC3;
41  hitPatternCDC3.setLayer(9); // SL 1
42  hitPatternCDC3.setLayer(15); // SL 2
43  hitPatternCDC3.setLayer(21); // SL 3
44 
45  EXPECT_FALSE(hitPatternCDC3.hasSLayer(0));
46  EXPECT_TRUE(hitPatternCDC3.hasSLayer(1));
47 
48  // Test Axial and Stereo requests.
49  EXPECT_TRUE(hitPatternCDC3.hasAxialLayer());
50  EXPECT_TRUE(hitPatternCDC3.hasStereoLayer());
51  EXPECT_FALSE(hitPatternCDC2.hasStereoLayer());
52 
53  hitPatternCDC3.resetLayer(15);
54  EXPECT_FALSE(hitPatternCDC3.hasAxialLayer());
55 
56  // Test resetting of super layers.
57  hitPatternCDC3.resetSLayer(1);
58  hitPatternCDC3.resetSLayer(3);
59  EXPECT_EQ(0, hitPatternCDC3.getNHits());
60  } // settersNGetters
61 
63  TEST_F(HitPatternCDCTest, SetNGetTotalNumberOfHits)
64  {
65  unsigned long long int initValue = static_cast<unsigned long long int>(0xAAAAAAAAAAAAAAAAL); //101010...101010
66  HitPatternCDC myHitPatternCDC(initValue);
67  EXPECT_EQ(170, myHitPatternCDC.getNHits());
68  unsigned short int nHits1 = 255;
69  myHitPatternCDC.setNHits(nHits1);
70  EXPECT_EQ(nHits1, myHitPatternCDC.getNHits());
71  unsigned short int nHits2 = 0;
72  myHitPatternCDC.setNHits(nHits2);
73  EXPECT_EQ(nHits2, myHitPatternCDC.getNHits());
74  unsigned short int nHits3 = 93;
75  myHitPatternCDC.setNHits(nHits3);
76  EXPECT_EQ(nHits3, myHitPatternCDC.getNHits());
77  }
78 
80  TEST_F(HitPatternCDCTest, getLongestContRunInSL)
81  {
82  unsigned long long int initValue = static_cast<unsigned long long int>(0xEEEEEEEEEEEEEEL); // 11101110...11101110
83  HitPatternCDC myHitPatternCDC(initValue);
84  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(0));
85  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(1));
86  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(2));
87  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(3));
88  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(4));
89  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(5));
90  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(6));
91  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(7));
92  EXPECT_EQ(3, myHitPatternCDC.getLongestContRunInSL(8));
93 
94  }
95 
97  TEST_F(HitPatternCDCTest, getFirstLastLayer)
98  {
99  HitPatternCDC myHitPatternCDC(0);
100  myHitPatternCDC.setNHits(123); //arbitrary number to check if this layer is masked out correctly
101 
102  unsigned short firstLayer = 5;
103  unsigned short lastLayer = 46;
104  myHitPatternCDC.setLayer(firstLayer);
105  myHitPatternCDC.setLayer(lastLayer);
106  EXPECT_EQ(firstLayer, myHitPatternCDC.getFirstLayer());
107  EXPECT_EQ(lastLayer, myHitPatternCDC.getLastLayer());
108 
109  myHitPatternCDC.resetPattern();
110  EXPECT_EQ(-1, myHitPatternCDC.getFirstLayer());
111  EXPECT_EQ(-1, myHitPatternCDC.getLastLayer());
112  }
113 
115 } // namespace Belle2
Unit tests for the CDC hit Patterns.
Hit pattern of CDC hits within a track.
Definition: HitPatternCDC.h:35
short getLastLayer() const
Returns the index of the last layer with a hit.
bool hasSLayer(const unsigned short sLayer) const
Getter for super-layer match.
bool hasAxialLayer() const
True, if at least one axial layer is true.
void setNHits(unsigned short nHits)
Sets the 8 MSBs to the total number of hits in the CDC.
void setLayer(const unsigned short layer)
Set bit corresponding to layer to true.
void resetPattern()
Reset the complete hit pattern.
ULong64_t getInteger() const
Getter for underlying integer type.
bool hasLayer(const unsigned short layer) const
Getter for single layer.
unsigned short getNHits() const
Get the total Number of CDC hits in the fit.
short getFirstLayer() const
Returns the index of the first layer with a hit.
void resetLayer(const unsigned short layer)
Set bit corresponding to layer to false.
void resetSLayer(const unsigned short sLayer)
Reset complete superLayer, e.g.
unsigned short getLongestContRunInSL(const unsigned short sLayer) const
Getter for longest run of consecutive layers with hits within the given Super-layer.
bool hasStereoLayer() const
True, if at least one axial layer is true.
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.