CMS 3D CMS Logo

HGCScintillatorDetId.h
Go to the documentation of this file.
1 #ifndef DataFormats_ForwardDetId_HGCScintillatorDetId_H
2 #define DataFormats_ForwardDetId_HGCScintillatorDetId_H 1
3 
4 #include <iosfwd>
5 #include <vector>
9 
10 /* \brief description of the bit assigment
11  [0:8] iphi index wrt x-axis on +z side
12  [9:16] |ring| index (starting from a minimum radius depending on type)
13  [17:21] Layer #
14  [22] Trigger(1)/Detector(0) cell
15  [23] SiPM type (0 for 2mm: 1 for 4mm)
16  [24] Free
17  [25:25] z-side (0 for +z; 1 for -z)
18  [26:27] Tile granularity and type (0 fine divisions of scintillators;
19  1 coarse divisions of type "c";
20  2 coarse divisions of type "m")
21  [28:31] Detector type (HGCalHSc)
22 */
23 
24 class HGCScintillatorDetId : public DetId {
25 public:
29  constexpr HGCScintillatorDetId(uint32_t rawid) : DetId(rawid) {}
31  constexpr HGCScintillatorDetId(int type, int layer, int ring, int phi, bool trigger = false, int sipm = 0)
33  int zside = (ring < 0) ? 1 : 0;
34  int itrig = trigger ? 1 : 0;
35  int ringAbs = std::abs(ring);
40  }
41 
44  if (!gen.null()) {
45  if (gen.det() != HGCalHSc) {
46  throw cms::Exception("Invalid DetId")
47  << "Cannot initialize HGCScintillatorDetId from " << std::hex << gen.rawId() << std::dec;
48  }
49  }
50  id_ = gen.rawId();
51  }
52 
55  if (!gen.null()) {
56  if (gen.det() != HGCalHSc) {
57  throw cms::Exception("Invalid DetId")
58  << "Cannot assign HGCScintillatorDetId from " << std::hex << gen.rawId() << std::dec;
59  }
60  }
61  id_ = gen.rawId();
62  return (*this);
63  }
64 
67  if (trigger()) {
68  return HGCScintillatorDetId(type(), layer(), iradiusTrigger(), iphiTrigger(), false);
69  } else {
70  return HGCScintillatorDetId(type(), layer(), iradius(), iphi(), false);
71  }
72  }
73 
75  constexpr DetId::Detector subdet() const { return det(); }
76 
78  constexpr int type() const { return (id_ >> kHGCalTypeOffset) & kHGCalTypeMask; }
79  constexpr void setType(int type) {
82  }
83 
85  constexpr int zside() const { return (((id_ >> kHGCalZsideOffset) & kHGCalZsideMask) ? -1 : 1); }
86 
88  constexpr int layer() const { return (id_ >> kHGCalLayerOffset) & kHGCalLayerMask; }
89 
91  constexpr int ring() const {
92  if (trigger())
93  return (2 * ((id_ >> kHGCalRadiusOffset) & kHGCalRadiusMask));
94  else
95  return ((id_ >> kHGCalRadiusOffset) & kHGCalRadiusMask);
96  }
97  constexpr int iradiusAbs() const { return ring(); }
98  constexpr int iradius() const { return zside() * ring(); }
99  constexpr int ietaAbs() const { return ring(); }
100  constexpr int ieta() const { return zside() * ring(); }
101 
103  constexpr int iphi() const {
104  if (trigger())
105  return (2 * ((id_ >> kHGCalPhiOffset) & kHGCalPhiMask));
106  else
107  return ((id_ >> kHGCalPhiOffset) & kHGCalPhiMask);
108  }
109  constexpr std::pair<int, int> ietaphi() const { return std::pair<int, int>(ieta(), iphi()); }
110  constexpr std::pair<int, int> ringphi() const { return std::pair<int, int>(iradius(), iphi()); }
111 
113  constexpr int sipm() const { return (id_ >> kHGCalSiPMOffset) & kHGCalSiPMMask; }
114  constexpr void setSiPM(int sipm) {
115  id_ &= kHGCalSiPMMask0;
117  }
118 
120  std::vector<HGCScintillatorDetId> detectorCells() const;
121 
122  constexpr bool trigger() const { return (((id_ >> kHGCalTriggerOffset) & kHGCalTriggerMask) == 1); }
124  if (trigger())
125  return HGCScintillatorDetId(type(), layer(), iradius(), iphi(), true);
126  else
127  return HGCScintillatorDetId(type(), layer(), iradiusTrigger(), iphiTrigger(), true);
128  }
129 
131  constexpr bool isEE() const { return false; }
132  constexpr bool isHE() const { return true; }
133  constexpr bool isForward() const { return true; }
134 
136 
137 public:
138  static constexpr int kHGCalPhiOffset = 0;
139  static constexpr int kHGCalPhiMask = 0x1FF;
141  static constexpr int kHGCalRadiusMask = 0xFF;
142  static constexpr int kHGCalLayerOffset = 17;
143  static constexpr int kHGCalLayerMask = 0x1F;
145  static constexpr int kHGCalTriggerMask = 0x1;
146  static constexpr int kHGCalSiPMOffset = 23;
147  static constexpr int kHGCalSiPMMask = 0x1;
148  static constexpr int kHGCalSiPMMask0 = 0xFF7FFFFF;
149  static constexpr int kHGCalZsideOffset = 25;
150  static constexpr int kHGCalZsideMask = 0x1;
151  static constexpr int kHGCalTypeOffset = 26;
152  static constexpr int kHGCalTypeMask = 0x3;
153  static constexpr int kHGCalTypeMask0 = 0xF3FFFFFF;
154 
156  if (trigger())
157  return ((ring() + 1) / 2);
158  else
159  return ring();
160  }
161  constexpr int iradiusTrigger() const { return zside() * iradiusTriggerAbs(); }
162  constexpr int iphiTrigger() const {
163  if (trigger())
164  return ((iphi() + 1) / 2);
165  else
166  return iphi();
167  }
168 };
169 
170 std::ostream& operator<<(std::ostream&, const HGCScintillatorDetId& id);
171 
172 #endif
constexpr int iradiusTrigger() const
constexpr int ieta() const
constexpr HGCScintillatorDetId(uint32_t rawid)
constexpr int iphi() const
get the phi index
constexpr DetId::Detector subdet() const
get the subdetector
static constexpr int kHGCalTypeMask
constexpr int iradiusTriggerAbs() const
constexpr int ietaAbs() const
constexpr int iphiTrigger() const
static constexpr int kHGCalPhiMask
static constexpr int kHGCalZsideOffset
constexpr std::pair< int, int > ringphi() const
constexpr bool isEE() const
consistency check : no bits left => no overhead
static constexpr int kHGCalRadiusOffset
constexpr int zside() const
get the z-side of the cell (1/-1)
constexpr int sipm() const
get/set the sipm size
static constexpr int kHGCalLayerOffset
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
static constexpr int kHGCalRadiusMask
constexpr bool isForward() const
constexpr HGCScintillatorDetId geometryCell() const
constexpr std::pair< int, int > ietaphi() const
static constexpr int kHGCalLayerMask
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr bool trigger() const
static constexpr int kHGCalSiPMMask
static constexpr int kHGCalPhiOffset
constexpr int type() const
get/set the type
static const HGCScintillatorDetId Undefined
Definition: DetId.h:17
std::vector< HGCScintillatorDetId > detectorCells() const
trigger or detector cell
std::ostream & operator<<(std::ostream &, const HGCScintillatorDetId &id)
static constexpr int kHGCalZsideMask
constexpr HGCScintillatorDetId(const DetId &gen)
Detector
Definition: DetId.h:24
uint32_t id_
Definition: DetId.h:69
constexpr HGCScintillatorDetId(int type, int layer, int ring, int phi, bool trigger=false, int sipm=0)
static constexpr int kHGCalSiPMOffset
static constexpr int kHGCalTypeMask0
static constexpr int kHGCalTypeOffset
constexpr void setType(int type)
constexpr int layer() const
get the layer #
constexpr int iradius() const
static constexpr int kHGCalTriggerOffset
constexpr void setSiPM(int sipm)
constexpr int ring() const
get the eta index
constexpr bool isHE() const
constexpr HGCScintillatorDetId triggerCell() const
constexpr HGCScintillatorDetId & operator=(const DetId &gen)
constexpr int iradiusAbs() const
static constexpr int kHGCalSiPMMask0
static constexpr int kHGCalTriggerMask