ATLAS Offline Software
SiCellId.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // SiCellId.h
8 // (c) ATLAS Detector software
10 
11 #ifndef INDETREADOUTGEOMETRY_SICELLID_H
12 #define INDETREADOUTGEOMETRY_SICELLID_H
13 
14 #include <iostream>
15 
16 namespace InDetDD {
17 
29  class SiCellId {
30 
32  // Public methods:
34  public:
35 
37  SiCellId();
39  SiCellId(int strip);
41  SiCellId(int phiIndex, int etaIndex);
42 
44  // Const methods:
46 
47  // Get the indices
48  // NB. phiIndex() and strip() are equivalent.
50  int etaIndex() const;
52  int phiIndex() const;
54  int strip() const;
55 
57  bool isValid() const;
58 
60  bool operator==(const SiCellId & other) const;
62  bool operator!=(const SiCellId & other) const;
63 
65  bool operator<(const SiCellId & other) const;
66 
67  unsigned int word() const { return m_word; }
68 
69 private:
70  unsigned int m_word;
71 
72  // Masks and shift values.
73  // bits 0 - 15 : phi_index
74  // bits 16 - 30 : eta_index
75  // bit 31 : valid flag
77  PHI_MASK = 0x0000ffff,
78  PHI_NEG = 0x00008000, // (PHI_MASK >> 1 + 1)
79  ETA_MASK = 0x00007fff,
80  ETA_SHIFT = 16,
81  ETA_NEG = 0x40000000, // ((ETA_MASK >> 1 + 1) << ETA_SHIFT)
82  VALID = 0x80000000
83  };
84 
85 };
86 
87 std::ostream & operator << (std::ostream & os, const SiCellId & cellId);
88 
90 // Inline methods:
93 {
94  // set in invalid state
95  // This sets the invalid bit plus set phi and eta index to there most negative value
96  m_word = VALID | ETA_NEG | PHI_NEG ;
97 }
98 
99 inline SiCellId::SiCellId(int phiIndex, int etaIndex)
100 {
101  // The negative check is not really necessary if negative numbers are represented as twos complement but
102  // I don't think that assumption is guaranteed to be portable.
103  if (phiIndex < 0) phiIndex = PHI_MASK + phiIndex + 1; // For negative number store as two's complement
104  if (etaIndex < 0) etaIndex = ETA_MASK + etaIndex + 1;
106 }
107 
108 inline SiCellId::SiCellId(int strip)
109 {
110  if (strip < 0) strip = PHI_MASK + strip + 1;
111  m_word = strip & PHI_MASK;
112 }
113 
114 inline int SiCellId::etaIndex() const
115 {
116  if (m_word & ETA_NEG) { // Negative index
117  return ((m_word >> ETA_SHIFT) & ETA_MASK) - ETA_MASK - 1;
118  }
119  return (m_word >> ETA_SHIFT) & ETA_MASK;
120 }
121 
122 inline int SiCellId::phiIndex() const
123 {
124  if (m_word & PHI_NEG) { // Negative index
125  return (m_word & PHI_MASK) - PHI_MASK - 1;
126  }
127  return (m_word & PHI_MASK);
128 
129 }
130 
131 inline int SiCellId::strip() const
132 {
133  return phiIndex();
134 }
135 
136 inline bool SiCellId::isValid() const
137 {
138  return !(m_word & VALID);
139 }
140 
141 inline bool SiCellId::operator==(const SiCellId & other) const
142 {
143  return (m_word == other.m_word);
144 }
145 
146 inline bool SiCellId::operator!=(const SiCellId & other) const
147 {
148  return (m_word != other.m_word);
149 }
150 
151 inline bool SiCellId::operator<(const SiCellId & other) const
152 {
153  return (m_word < other.m_word);
154 }
155 
156 
157 } // namespace InDetDD
158 
159 
160 #endif // INDETREADOUTGEOMETRY_SICELLID_H
InDetDD::SiCellId::ETA_MASK
@ ETA_MASK
Definition: SiCellId.h:79
InDetDD::SiCellId::MaskAndShiftConstants
MaskAndShiftConstants
Definition: SiCellId.h:76
InDetDD::SiCellId::isValid
bool isValid() const
Test if its in a valid state.
Definition: SiCellId.h:136
InDetDD::SiCellId::phiIndex
int phiIndex() const
Get phi index. Equivalent to strip().
Definition: SiCellId.h:122
InDetDD::SiCellId::strip
int strip() const
Get strip number. Equivalent to phiIndex().
Definition: SiCellId.h:131
InDetDD::SiCellId::operator!=
bool operator!=(const SiCellId &other) const
Test inequality.
Definition: SiCellId.h:146
InDetDD::operator<<
std::ostream & operator<<(std::ostream &os, const SiCellId &cellId)
Definition: SiCellId.cxx:8
InDetDD::SiCellId::etaIndex
int etaIndex() const
Get eta index.
Definition: SiCellId.h:114
InDetDD::SiCellId::word
unsigned int word() const
Definition: SiCellId.h:67
InDetDD::SiCellId::SiCellId
SiCellId()
Constructor. Set in invalid state.
Definition: SiCellId.h:92
InDetDD::SiCellId::operator==
bool operator==(const SiCellId &other) const
Test equality.
Definition: SiCellId.h:141
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
InDetDD::SiCellId::PHI_MASK
@ PHI_MASK
Definition: SiCellId.h:77
InDetDD::SiCellId::m_word
unsigned int m_word
Definition: SiCellId.h:70
InDetDD::SiCellId::ETA_NEG
@ ETA_NEG
Definition: SiCellId.h:81
InDetDD::SiCellId
Definition: SiCellId.h:29
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
InDetDD::SiCellId::VALID
@ VALID
Definition: SiCellId.h:82
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
InDetDD::SiCellId::ETA_SHIFT
@ ETA_SHIFT
Definition: SiCellId.h:80
InDetDD::SiCellId::operator<
bool operator<(const SiCellId &other) const
Operator for sorting.
Definition: SiCellId.h:151
InDetDD::SiCellId::PHI_NEG
@ PHI_NEG
Definition: SiCellId.h:78