Belle II Software light-2406-ragdoll
HitPatternCDC Class Reference

Hit pattern of CDC hits within a track. More...

#include <HitPatternCDC.h>

Collaboration diagram for HitPatternCDC:

Public Member Functions

 HitPatternCDC ()
 Create empty pattern.
 
 HitPatternCDC (ULong64_t initValue)
 Initialize the pattern with an integer.
 
ULong64_t getInteger () const
 Getter for underlying integer type.
 
unsigned short getNHits () const
 Get the total Number of CDC hits in the fit.
 
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 resetLayer (const unsigned short layer)
 Set bit corresponding to layer to false.
 
bool hasLayer (const unsigned short layer) const
 Getter for single layer.
 
short getFirstLayer () const
 Returns the index of the first layer with a hit.
 
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.
 
void resetSLayer (const unsigned short sLayer)
 Reset complete superLayer, e.g.
 
std::bitset< 64 > getSLayerPattern (const unsigned short sLayer)
 Get the bit pattern in a specific super layer.
 
unsigned short getSLayerNHits (const unsigned short sLayer) const
 Getter for the number of hits in one super-layer.
 
unsigned short getLongestContRunInSL (const unsigned short sLayer) const
 Getter for longest run of consecutive layers with hits within the given Super-layer.
 
bool hasAxialLayer () const
 True, if at least one axial layer is true.
 
bool hasStereoLayer () const
 True, if at least one axial layer is true.
 
std::string __str__ () const
 String for printing in python.
 

Private Member Functions

std::bitset< 64 > getBitSet () const
 Getter for underlying bit set.
 
void resetPattern ()
 Reset the complete hit pattern.
 

Private Attributes

std::bitset< 64 > m_pattern
 Saves the actual pattern.
 

Static Private Attributes

static const std::bitset< 64 > s_sLayerMasks [9]
 Masks to zero out all bits from other layers.
 
static const std::bitset< 64 > s_infoLayerMask = infoLayerCDC
 Mask to zero out all bits from other layers.
 
static const std::map< unsigned short, std::pair< unsigned short, unsigned short > > s_superLayerIndices
 Holds the indices for super layer access.
 

Friends

class HitPatternCDCTest_settersNGetters_Test
 
class HitPatternCDCTest_getFirstLastLayer_Test
 

Detailed Description

Hit pattern of CDC hits within a track.

The pattern is stored using a std::bitset. This allows to use the STL, which is very efficiently programmed.

For each layer there is one bit. The layer counting is from 0 to 55. Super-layer information is generated on demand. The super-layer counting goes from 0 to 8.

The numbering scheme just in this class is equivalent to the one defined in the note BELLE2-NOTE-TE-2015-022: https://docs.belle2.org/record/256

See also
HitPatternVXD

Definition at line 35 of file HitPatternCDC.h.

Constructor & Destructor Documentation

◆ HitPatternCDC() [1/2]

HitPatternCDC ( )
inline

Create empty pattern.

Definition at line 41 of file HitPatternCDC.h.

41: m_pattern(0) {}
std::bitset< 64 > m_pattern
Saves the actual pattern.

◆ HitPatternCDC() [2/2]

HitPatternCDC ( ULong64_t  initValue)
inlineexplicit

Initialize the pattern with an integer.

Definition at line 44 of file HitPatternCDC.h.

44: m_pattern(initValue) {}

Member Function Documentation

◆ __str__()

std::string __str__ ( ) const

String for printing in python.

Definition at line 169 of file HitPatternCDC.cc.

170{
171 return m_pattern.to_string();
172}

◆ getBitSet()

std::bitset< 64 > getBitSet ( ) const
inlineprivate

Getter for underlying bit set.

Just for testing.

Definition at line 166 of file HitPatternCDC.h.

166{ return m_pattern; }

◆ getFirstLayer()

short getFirstLayer ( ) const

Returns the index of the first layer with a hit.

If there is no hit in the whole pattern, -1 is returned.

Returns
Index of last layer.

Definition at line 96 of file HitPatternCDC.cc.

97{
98 for (unsigned int i = 0; i < m_pattern.size(); ++i) {
99 if ((m_pattern & ~s_infoLayerMask).test(i)) return i;
100 }
101 return -1;
102}
static const std::bitset< 64 > s_infoLayerMask
Mask to zero out all bits from other layers.

◆ getInteger()

ULong64_t getInteger ( ) const

Getter for underlying integer type.

Definition at line 69 of file HitPatternCDC.cc.

70{
71 if constexpr(sizeof(unsigned long) >= 8) {
72 return m_pattern.to_ulong();
73 } else {
74 return m_pattern.to_ullong();
75 }
76}

◆ getLastLayer()

short getLastLayer ( ) const

Returns the index of the last layer with a hit.

If there is no hit in the whole pattern, -1 is returned.

Returns
Index of last layer.

Definition at line 104 of file HitPatternCDC.cc.

105{
106 // m_pattern.size()-8 because the first 8 bits are not pattern
107 for (unsigned int i = m_pattern.size() - 8; i > 0; --i) {
108 // -1 because of the index couting...
109 if ((m_pattern & ~s_infoLayerMask).test(i - 1)) return i - 1;
110 }
111 return -1;
112}

◆ getLongestContRunInSL()

unsigned short getLongestContRunInSL ( const unsigned short  sLayer) const

Getter for longest run of consecutive layers with hits within the given Super-layer.

Parameters
sLayerSuper-layer index.
Returns
Length of longest run.

Definition at line 139 of file HitPatternCDC.cc.

140{
141 B2ASSERT("Super layer outof range.", sLayer <= 8);
142 unsigned short max = 0;
143 unsigned short counter = 0;
144 std::pair<unsigned short, unsigned short> indices = s_superLayerIndices.at(sLayer);
145 for (unsigned short i = indices.first; i <= indices.second; ++i) {
146 counter += m_pattern[i];
147 if (m_pattern[i] == 0) {
148 if (counter > max) {
149 max = counter;
150 }
151 counter = 0;
152 }
153 }
154 return std::max(max, counter);
155}
static const std::map< unsigned short, std::pair< unsigned short, unsigned short > > s_superLayerIndices
Holds the indices for super layer access.

◆ getNHits()

unsigned short getNHits ( ) const

Get the total Number of CDC hits in the fit.

Nota Bene: The maximum value returned here is 255. This is because only 8 bits are available to store the information. If the track had more than 255 hits, e.g. because it was a curler, the returned value may be to small.

Returns
Number of hits in the CDC.

Definition at line 47 of file HitPatternCDC.cc.

48{
49 // Shift the 8 MSBs to the right and return their value as integer.
50 return static_cast<unsigned short int>((m_pattern >> 56).to_ulong());
51}

◆ getSLayerNHits()

unsigned short getSLayerNHits ( const unsigned short  sLayer) const

Getter for the number of hits in one super-layer.

Nota Bene: As only a bitwise information is available if a layer is hit, under-counting is possible if in at least one layer more than one wire is hit.

Parameters
sLayerSuper-layer index.
Returns
Number of hits in super-layer.

Definition at line 133 of file HitPatternCDC.cc.

134{
135 B2ASSERT("Super layer outof range.", sLayer <= 8);
136 return static_cast<unsigned short>((m_pattern & s_sLayerMasks[sLayer]).count());
137}
static const std::bitset< 64 > s_sLayerMasks[9]
Masks to zero out all bits from other layers.

◆ getSLayerPattern()

std::bitset< 64 > getSLayerPattern ( const unsigned short  sLayer)

Get the bit pattern in a specific super layer.

Parameters
sLayerSuper-layer index.
Returns
Super-layer bit pattern.

Definition at line 128 of file HitPatternCDC.cc.

129{
130 return m_pattern & s_sLayerMasks[sLayer];
131}

◆ hasAxialLayer()

bool hasAxialLayer ( ) const

True, if at least one axial layer is true.

Definition at line 157 of file HitPatternCDC.cc.

158{
160 & m_pattern).any();
161}

◆ hasLayer()

bool hasLayer ( const unsigned short  layer) const

Getter for single layer.

Parameters
layerLayer index.
Returns
Boolean if layer is hit or not.

Definition at line 90 of file HitPatternCDC.cc.

91{
92 B2ASSERT("Layer is out of range.", layer <= 55);
93 return m_pattern[layer];
94}

◆ hasSLayer()

bool hasSLayer ( const unsigned short  sLayer) const

Getter for super-layer match.

Parameters
sLayersuper-layer index.

Definition at line 114 of file HitPatternCDC.cc.

115{
116 B2ASSERT("Super layer outof range.", sLayer <= 8);
117 return ((m_pattern & s_sLayerMasks[sLayer]).any());
118}

◆ hasStereoLayer()

bool hasStereoLayer ( ) const

True, if at least one axial layer is true.

Definition at line 163 of file HitPatternCDC.cc.

164{
165 return ((s_sLayerMasks[1] | s_sLayerMasks[3] | s_sLayerMasks[5] | s_sLayerMasks[7])
166 & m_pattern).any();
167}

◆ resetLayer()

void resetLayer ( const unsigned short  layer)

Set bit corresponding to layer to false.

This function may throw an out-of-range exception.

Parameters
layerLayer index.

Definition at line 84 of file HitPatternCDC.cc.

85{
86 B2ASSERT("Layer is out of range.", layer <= 55);
87 m_pattern.reset(layer);
88}

◆ resetPattern()

void resetPattern ( )
inlineprivate

Reset the complete hit pattern.

Just for testing.

Definition at line 169 of file HitPatternCDC.h.

169{ m_pattern.reset(); }

◆ resetSLayer()

void resetSLayer ( const unsigned short  sLayer)

Reset complete superLayer, e.g.

because segment shouldn't belong to that track.

Parameters
sLayerSuper-layer index.

Definition at line 120 of file HitPatternCDC.cc.

121{
122 B2ASSERT("Super layer outof range.", sLayer <= 8);
123 for (unsigned short int ii = 0; ii < m_pattern.size(); ++ii) {
124 if ((s_sLayerMasks[sLayer])[ii]) {resetLayer(ii);}
125 }
126}
void resetLayer(const unsigned short layer)
Set bit corresponding to layer to false.

◆ setLayer()

void setLayer ( const unsigned short  layer)

Set bit corresponding to layer to true.

This function may throw an out-of-range exception.

Parameters
layerLayer index.

Definition at line 78 of file HitPatternCDC.cc.

79{
80 B2ASSERT("Layer is out of range.", layer <= 55);
81 m_pattern.set(layer);
82}

◆ setNHits()

void setNHits ( unsigned short  nHits)

Sets the 8 MSBs to the total number of hits in the CDC.

Nota Bene: If the whole track has more than 255 hits, e.g. because it is a curler, the value is set to 255.

Parameters
nHitsNumber of hits in the CDC.

Definition at line 53 of file HitPatternCDC.cc.

54{
55 if (nHits > 256) {
56 // Maximum with 8 available bits
57 nHits = 255;
58 }
59 // Reset the 8 MSBs to zero.
60 m_pattern = m_pattern & ~s_infoLayerMask;
61 // Set the total number of hits as the 8 MSBs
62 std::bitset<64> numberOfHits(nHits);
63 numberOfHits <<= 56;
64 // Set the 8 MSBs to the total number of hits.
65 // The 8 MSBs have to be zero, otherwise this breaks.
66 m_pattern = numberOfHits | m_pattern;
67}

Friends And Related Function Documentation

◆ HitPatternCDCTest_getFirstLastLayer_Test

friend class HitPatternCDCTest_getFirstLastLayer_Test
friend

Definition at line 37 of file HitPatternCDC.h.

◆ HitPatternCDCTest_settersNGetters_Test

friend class HitPatternCDCTest_settersNGetters_Test
friend

Definition at line 36 of file HitPatternCDC.h.

Member Data Documentation

◆ m_pattern

std::bitset<64> m_pattern
private

Saves the actual pattern.

Definition at line 158 of file HitPatternCDC.h.

◆ s_infoLayerMask

const std::bitset< 64 > s_infoLayerMask = infoLayerCDC
staticprivate

Mask to zero out all bits from other layers.

Definition at line 160 of file HitPatternCDC.h.

◆ s_sLayerMasks

const std::bitset< 64 > s_sLayerMasks
staticprivate
Initial value:
= {sLayerZer, sLayerOne, sLayerTwo, sLayerThr, sLayerFou,
sLayerFiv, sLayerSix, sLayerSev, sLayerEig
}

Masks to zero out all bits from other layers.

Definition at line 159 of file HitPatternCDC.h.

◆ s_superLayerIndices

const std::map< unsigned short, std::pair< unsigned short, unsigned short > > s_superLayerIndices
staticprivate
Initial value:
= {
{0, std::make_pair(0, 7)},
{1, std::make_pair(8, 13)},
{2, std::make_pair(14, 19)},
{3, std::make_pair(20, 25)},
{4, std::make_pair(26, 31)},
{5, std::make_pair(32, 37)},
{6, std::make_pair(38, 43)},
{7, std::make_pair(44, 49)},
{8, std::make_pair(50, 55)}
}

Holds the indices for super layer access.

Definition at line 163 of file HitPatternCDC.h.


The documentation for this class was generated from the following files: