CMS 3D CMS Logo

HGCalTopology.cc
Go to the documentation of this file.
7 
8 //#define EDM_ML_DEBUG
9 
11  int det) : hdcons_(hdcons) {
12 
14  layers_ = hdcons_.layers(true);
15  cells_ = hdcons_.maxCells(true);
19  waferMax_ = 2*waferOff_ + 1;
25  subdet_ = (ForwardSubdetector)(det);
27  types_ = 2;
28  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
29  det_ = (DetId::Detector)(det);
32  types_ = 2;
33  } else {
34  det_ = (DetId::Detector)(det);
37  types_ = 3;
38  }
39  kSizeForDenseIndexing = (unsigned int)(2*kHGhalf_);
40 #ifdef EDM_ML_DEBUG
41  edm::LogVerbatim("HGCalGeom") << "HGCalTopology initialized for detector "
42  << det_ << ":" << subdet_ << " having "
43  << sectors_ << " Sectors, " << layers_
44  << " Layers from " << firstLay_ << ", "
45  << cells_ << " cells and total channels "
46  << kSizeForDenseIndexing << ":"
47  << (2*kHGeomHalf_) << std::endl;
48 #endif
49 }
50 
51 unsigned int HGCalTopology::allGeomModules() const {
52  return ((mode_ == HGCalGeometryMode::Trapezoid) ?
53  (unsigned int)(2*hdcons_.numberCells(true)) :
54  (unsigned int)(2*hdcons_.wafers()));
55 }
56 
57 uint32_t HGCalTopology::detId2denseId(const DetId& idin) const {
58 
60  uint32_t idx;
63  int type = (id.iType > 0) ? 1 : 0;
64  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
65  ((((id.iCell1-1)*layers_+id.iLay-1)*sectors_+
66  id.iSec1)*types_+type));
67 #ifdef EDM_ML_DEBUG
68  edm::LogVerbatim("HGCalGeom") << "Input Hex " << id.zSide << ":" << id.iLay
69  << ":" << id.iSec1 << ":" << id.iCell1
70  << ":" << id.iType << " Constants "
71  << kHGeomHalf_ << ":" << layers_ << ":"
72  << sectors_ << ":" << types_<< " o/p "
73  << idx;
74 #endif
75  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
76  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
77  ((((id.iCell1-1)*layers_+id.iLay-firstLay_)*sectors_+
78  id.iSec1-1)*types_+id.iType));
79 #ifdef EDM_ML_DEBUG
80  edm::LogVerbatim("HGCalGeom") << "Input Trap " << id.zSide << ":" << id.iLay
81  << ":" << id.iSec1 << ":" << id.iCell1
82  << ":" << id.iType << " Constants "
83  << kHGeomHalf_ << ":" << layers_ << ":"
84  << sectors_ << ":" << types_<< " o/p "
85  << idx;
86 #endif
87  } else {
88  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
89  (((((id.iCell1*cellMax_+id.iCell2)*layers_+
90  id.iLay-1)*waferMax_+id.iSec1+waferOff_)*
91  waferMax_+id.iSec2+waferOff_)*types_+id.iType));
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << id.zSide << ":" << id.iLay
94  << ":" << id.iSec1 << ":" << id.iSec2 << ":"
95  << id.iCell1 << ":" << id.iCell2 << ":"
96  << id.iType << " Constants " << kHGeomHalf_
97  << ":" << cellMax_ << ":" << layers_ << ":"
98  << waferMax_ << ":" << waferOff_ << ":"
99  << types_<< " o/p " << idx;
100 #endif
101  }
102  return idx;
103 }
104 
106 
108  if (validHashIndex(hi)) {
109  id.zSide = ((int)(hi)<kHGhalf_ ? -1 : 1);
110  int di = ((int)(hi)%kHGhalf_);
111  if ((mode_ == HGCalGeometryMode::Hexagon) ||
113  int type = (di%types_);
114  id.iType = (type == 0 ? -1 : 1);
115  id.iSec1 = (((di-type)/types_)%sectors_);
116  id.iLay = (((((di-type)/types_)-id.iSec1+1)/sectors_)%layers_+1);
117  id.iCell1= (((((di-type)/types_)-id.iSec1+1)/sectors_-id.iLay+1)/layers_+1);
118 #ifdef EDM_ML_DEBUG
119  edm::LogVerbatim("HGCalGeom") << "Input Hex " << hi << " o/p " << id.zSide
120  << ":" << id.iLay << ":" << id.iType
121  << ":" << id.iSec1 << ":" << id.iCell1;
122 #endif
123  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
124  int type = (di%types_);
125  id.iType = type;
126  id.iSec1 = (((di-type)/types_)%sectors_)+1;
127  id.iLay = (((((di-type)/types_)-id.iSec1+1)/sectors_)%layers_+firstLay_);
128  id.iCell1= (((((di-type)/types_)-id.iSec1+1)/sectors_-id.iLay+firstLay_)/layers_+1);
129 #ifdef EDM_ML_DEBUG
130  edm::LogVerbatim("HGCalGeom") << "Input Trap " << hi << " o/p " << id.zSide
131  << ":" << id.iLay << ":" << id.iType
132  << ":" << id.iSec1 << ":" << id.iCell1;
133 #endif
134  } else {
135  int type = (di%types_);
136  id.iType = type;
137  di = (di-type)/types_;
138  id.iSec2 = (di%waferMax_)-waferOff_;
139  di = (di-id.iSec2-waferOff_)/waferMax_;
140  id.iSec1 = (di%waferMax_)-waferOff_;
141  di = (di-id.iSec1-waferOff_)/waferMax_;
142  id.iLay = (di%layers_)+1;
143  di = (di-id.iLay+1)/layers_;
144  id.iCell2 = (di%cellMax_);
145  id.iCell1 = (di-id.iCell2)/cellMax_;
146 #ifdef EDM_ML_DEBUG
147  edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << hi << " o/p " << id.zSide
148  << ":" << id.iLay << ":" << id.iType
149  << ":" << id.iSec1 << ":" << id.iSec2
150  << ":" << id.iCell1 << ":" << id.iCell2;
151 #endif
152  }
153  }
154  return encode(id);
155 }
156 
157 uint32_t HGCalTopology::detId2denseGeomId(const DetId& idin) const {
158 
160  uint32_t idx;
161  if ((mode_ == HGCalGeometryMode::Hexagon) ||
163  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
164  (id.iLay-1)*sectors_+id.iSec1);
165 #ifdef EDM_ML_DEBUG
166  edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << id.zSide << ":" << id.iLay
167  << ":" << id.iSec1 << ":" << id.iType
168  << " Constants " << kHGeomHalf_ << ":"
169  << layers_ << ":" << sectors_ << " o/p "
170  << idx;
171 #endif
172  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
173  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
174  (((id.iLay-firstLay_)*sectors_+id.iSec1-1)*cellMax_+
175  id.iCell1-1));
176 #ifdef EDM_ML_DEBUG
177  edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << id.zSide << ":"
178  << id.iLay << ":" << id.iSec1 << ":"
179  << id.iCell1 << ":" << id.iType << " Constants "
180  << kHGeomHalf_ << ":" << layers_ << ":"
181  << firstLay_ << ":" << sectors_ << ":"
182  << cellMax_ << " o/p " << idx;
183 #endif
184  } else {
185  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
186  (((id.iLay-1)*waferMax_+id.iSec1+waferOff_)*waferMax_+
187  id.iSec2+waferOff_));
188 #ifdef EDM_ML_DEBUG
189  edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << id.zSide << ":"
190  << id.iLay << ":" << id.iSec1 << ":"
191  << id.iSec2 << ":" << id.iType << " Constants "
192  << kHGeomHalf_ << ":" << layers_ << ":"
193  << waferMax_ << ":" << waferOff_ << " o/p "
194  << idx;
195 #endif
196  }
197  return idx;
198 }
199 
200 bool HGCalTopology::valid(const DetId& idin) const {
201 
203  bool flag;
204  if ((mode_ == HGCalGeometryMode::Hexagon) ||
206  flag = (idin.det() == det_ && idin.subdetId() == (int)(subdet_) &&
207  id.iCell1 >= 0 && id.iCell1 < cells_ && id.iLay > 0 &&
208  id.iLay <= layers_ && id.iSec1 >= 0 && id.iSec1 <= sectors_);
209  if (flag) flag = hdcons_.isValidHex(id.iLay,id.iSec1,id.iCell1,true);
210  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
211  flag = ((idin.det() == det_) &&
212  hdcons_.isValidTrap(id.iLay,id.iSec1,id.iCell1));
213  } else {
214  flag = ((idin.det() == det_) &&
215  hdcons_.isValidHex8(id.iLay,id.iSec1,id.iSec2,id.iCell1,id.iCell2));
216  }
217  return flag;
218 }
219 
220 DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX,
221  int nrStepsY ) const {
222 
223  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
224  DetId id = changeXY(startId,nrStepsX,nrStepsY);
225  if (valid(id)) return id;
226  }
227  return DetId(0);
228 }
229 
230 DetId HGCalTopology::switchZSide(const DetId startId) const {
231 
232  HGCalTopology::DecodedDetId id_ = decode(startId);
233  id_.zSide =-id_.zSide;
234  DetId id = encode(id_);
235  if (valid(id)) return id;
236  else return DetId(0);
237 }
238 
240 
242  if (hi < totalGeomModules()) {
243  id.zSide = ((int)(hi)<kHGeomHalf_ ? -1 : 1);
244  int di = ((int)(hi)%kHGeomHalf_);
245  if ((mode_ == HGCalGeometryMode::Hexagon) ||
247  id.iSec1 = (di%sectors_);
248  di = (di-id.iSec1)/sectors_;
249  id.iLay = (di%layers_)+1;
250  id.iType = ((di-id.iLay+1)/layers_ == 0) ? -1 : 1;
251 #ifdef EDM_ML_DEBUG
252  edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << hi << " O/P "
253  << id.zSide << ":" << id.iType << ":"
254  << id.iLay << ":" << id.iSec1;
255 #endif
256  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
257  id.iCell1 = (di%cellMax_)+1;
258  di = (di-id.iCell1+1)/cellMax_;
259  id.iSec1 = (di%sectors_)+1;
260  di = (di-id.iSec1+1)/sectors_;
261  id.iLay = (di%layers_) + firstLay_;
262  id.iType = (di-id.iLay+firstLay_)/layers_;
263 #ifdef EDM_ML_DEBUG
264  edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << hi << " O/P "
265  << id.zSide << ":" << id.iType << ":"
266  << id.iLay << ":" << id.iSec1 << ":"
267  << id.iCell1;
268 #endif
269  } else {
270  id.iSec2 = (di%waferMax_)-waferOff_;
271  di = (di-id.iSec2-waferOff_)/waferMax_;
272  id.iSec1 = (di%waferMax_)-waferOff_;
273  di = (di-id.iSec1-waferOff_)/waferMax_;
274  id.iLay = (di%layers_)+1;
275  id.iType = (di-id.iLay+1)/layers_;
276 #ifdef EDM_ML_DEBUG
277  edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << hi << " O/P "
278  << id.zSide << ":" << id.iType << ":"
279  << id.iLay << ":" << id.iSec1 << ":"
280  << id.iSec2;
281 #endif
282  }
283  }
284  return id;
285 }
286 
288 
290  if ((mode_ == HGCalGeometryMode::Hexagon) ||
292  HGCalDetId id(startId);
293  idx.iCell1 = id.cell();
294  idx.iCell2 = 0;
295  idx.iLay = id.layer();
296  idx.iSec1 = id.wafer();
297  idx.iSec2 = 0;
298  idx.iType = id.waferType();
299  idx.zSide = id.zside();
300  idx.det = id.subdetId();
301  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
302  HGCScintillatorDetId id(startId);
303  idx.iCell1 = id.iphi();
304  idx.iCell2 = 0;
305  idx.iLay = id.layer();
306  idx.iSec1 = id.ietaAbs();
307  idx.iSec2 = 0;
308  idx.iType = id.type();
309  idx.zSide = id.zside();
310  idx.det = (int)(id.subdet());
311  } else {
312  HGCSiliconDetId id(startId);
313  idx.iCell1 = id.cellU();
314  idx.iCell2 = id.cellV();
315  idx.iLay = id.layer();
316  idx.iSec1 = id.waferU();
317  idx.iSec2 = id.waferV();
318  idx.iType = id.type();
319  idx.zSide = id.zside();
320  idx.det = (int)(id.subdet());
321  }
322  return idx;
323 }
324 
326 
327  DetId id;
330  id = HGCalDetId((ForwardSubdetector)(idx.det),idx.zSide,idx.iLay,((idx.iType > 0) ? 1 : 0),idx.iSec1,idx.iCell1).rawId();
331  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
332  id = HGCScintillatorDetId(idx.iType,idx.iLay,idx.zSide*idx.iSec1,idx.iCell1).rawId();
333  } else {
334  id = HGCSiliconDetId((DetId::Detector)(idx.det),idx.zSide,idx.iType,idx.iLay,idx.iSec1,idx.iSec2,idx.iCell1,idx.iCell2).rawId();
335  }
336  return id;
337 }
338 
339 DetId HGCalTopology::changeXY(const DetId& id, int nrStepsX,
340  int nrStepsY ) const {
341 
342  return DetId();
343 }
344 
345 
346 DetId HGCalTopology::changeZ(const DetId& id, int nrStepsZ) const {
347 
348  return DetId();
349 }
350 
352 
type
Definition: HCALResponse.h:21
bool isValidTrap(int lay, int ieta, int iphi) const
bool validHashIndex(uint32_t ix) const
Definition: HGCalTopology.h:95
unsigned int allGeomModules() const
DetId changeXY(const DetId &id, int nrStepsX, int nrStepsY) const
move the nagivator along x, y
DetId changeZ(const DetId &id, int nrStepsZ) const
move the nagivator along z
HGCalGeometryMode::GeometryMode mode_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
DetId denseId2detId(uint32_t denseId) const override
ForwardSubdetector
bool isValidHex(int lay, int mod, int cell, bool reco) const
DetId::Detector det_
DetId offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const
unsigned int totalGeomModules() const
Definition: HGCalTopology.h:98
unsigned int layers(bool reco) const
bool isValidHex8(int lay, int modU, int modV, int cellU, int cellV) const
virtual uint32_t detId2denseGeomId(const DetId &id) const
DetId encode(const DecodedDetId &id_) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
uint32_t detId2denseId(const DetId &id) const override
Dense indexing.
HGCalGeometryMode::GeometryMode geomMode() const
int sectors() const
DecodedDetId geomDenseId2decId(const uint32_t &hi) const
ForwardSubdetector subdet_
int maxCellUV() const
const HGCalDDDConstants & hdcons_
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
DecodedDetId decode(const DetId &id) const
Definition: DetId.h:18
Detector
Definition: DetId.h:26
int waferUVMax() const
int numberCells(bool reco) const
DetId switchZSide(const DetId startId) const
unsigned int kSizeForDenseIndexing
int firstLayer() const
bool valid(const DetId &id) const override
Is this a valid cell id.
HGCalTopology(const HGCalDDDConstants &hdcons, int subdet)
create a new Topology
int maxCells(bool reco) const
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39