CMS 3D CMS Logo

HGCalTopology.cc
Go to the documentation of this file.
8 
9 //#define EDM_ML_DEBUG
10 
12  int det) : hdcons_(hdcons) {
13 
15  layers_ = hdcons_.layers(true);
16  cells_ = hdcons_.maxCells(true);
20  waferMax_ = 2*waferOff_ + 1;
26  subdet_ = (ForwardSubdetector)(det);
28  types_ = 2;
29  } else if (det == (int)(DetId::Forward)) {
31  subdet_ = HFNose;
33  types_ = 3;
34  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
35  det_ = (DetId::Detector)(det);
38  types_ = 2;
39  } else {
40  det_ = (DetId::Detector)(det);
43  types_ = 3;
44  }
45  kSizeForDenseIndexing = (unsigned int)(2*kHGhalf_);
46 #ifdef EDM_ML_DEBUG
47  edm::LogVerbatim("HGCalGeom") << "HGCalTopology initialized for detector "
48  << det_ << ":" << subdet_ << " having "
49  << sectors_ << " Sectors, " << layers_
50  << " Layers from " << firstLay_ << ", "
51  << cells_ << " cells and total channels "
52  << kSizeForDenseIndexing << ":"
53  << (2*kHGeomHalf_) << std::endl;
54 #endif
55 }
56 
57 unsigned int HGCalTopology::allGeomModules() const {
58  return ((mode_ == HGCalGeometryMode::Trapezoid) ?
59  (unsigned int)(2*hdcons_.numberCells(true)) :
60  (unsigned int)(2*hdcons_.wafers()));
61 }
62 
63 uint32_t HGCalTopology::detId2denseId(const DetId& idin) const {
64 
66  uint32_t idx;
69  int type = (id.iType > 0) ? 1 : 0;
70  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
71  ((((id.iCell1-1)*layers_+id.iLay-1)*sectors_+
72  id.iSec1)*types_+type));
73 #ifdef EDM_ML_DEBUG
74  edm::LogVerbatim("HGCalGeom") << "Input Hex " << id.zSide << ":" << id.iLay
75  << ":" << id.iSec1 << ":" << id.iCell1
76  << ":" << id.iType << " Constants "
77  << kHGeomHalf_ << ":" << layers_ << ":"
78  << sectors_ << ":" << types_<< " o/p "
79  << idx;
80 #endif
81  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
82  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
83  ((((id.iCell1-1)*layers_+id.iLay-firstLay_)*sectors_+
84  id.iSec1-1)*types_+id.iType));
85 #ifdef EDM_ML_DEBUG
86  edm::LogVerbatim("HGCalGeom") << "Input Trap " << id.zSide << ":" << id.iLay
87  << ":" << id.iSec1 << ":" << id.iCell1
88  << ":" << id.iType << " Constants "
89  << kHGeomHalf_ << ":" << layers_ << ":"
90  << sectors_ << ":" << types_<< " o/p "
91  << idx;
92 #endif
93  } else {
94  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
95  (((((id.iCell1*cellMax_+id.iCell2)*layers_+
96  id.iLay-1)*waferMax_+id.iSec1+waferOff_)*
97  waferMax_+id.iSec2+waferOff_)*types_+id.iType));
98 #ifdef EDM_ML_DEBUG
99  edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << id.zSide << ":" << id.iLay
100  << ":" << id.iSec1 << ":" << id.iSec2 << ":"
101  << id.iCell1 << ":" << id.iCell2 << ":"
102  << id.iType << " Constants " << kHGeomHalf_
103  << ":" << cellMax_ << ":" << layers_ << ":"
104  << waferMax_ << ":" << waferOff_ << ":"
105  << types_<< " o/p " << idx;
106 #endif
107  }
108  return idx;
109 }
110 
112 
114  if (validHashIndex(hi)) {
115  id.zSide = ((int)(hi)<kHGhalf_ ? -1 : 1);
116  int di = ((int)(hi)%kHGhalf_);
117  if ((mode_ == HGCalGeometryMode::Hexagon) ||
119  int type = (di%types_);
120  id.iType = (type == 0 ? -1 : 1);
121  id.iSec1 = (((di-type)/types_)%sectors_);
122  id.iLay = (((((di-type)/types_)-id.iSec1+1)/sectors_)%layers_+1);
123  id.iCell1= (((((di-type)/types_)-id.iSec1+1)/sectors_-id.iLay+1)/layers_+1);
124 #ifdef EDM_ML_DEBUG
125  edm::LogVerbatim("HGCalGeom") << "Input Hex " << hi << " o/p " << id.zSide
126  << ":" << id.iLay << ":" << id.iType
127  << ":" << id.iSec1 << ":" << id.iCell1;
128 #endif
129  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
130  int type = (di%types_);
131  id.iType = type;
132  id.iSec1 = (((di-type)/types_)%sectors_)+1;
133  id.iLay = (((((di-type)/types_)-id.iSec1+1)/sectors_)%layers_+firstLay_);
134  id.iCell1= (((((di-type)/types_)-id.iSec1+1)/sectors_-id.iLay+firstLay_)/layers_+1);
135 #ifdef EDM_ML_DEBUG
136  edm::LogVerbatim("HGCalGeom") << "Input Trap " << hi << " o/p " << id.zSide
137  << ":" << id.iLay << ":" << id.iType
138  << ":" << id.iSec1 << ":" << id.iCell1;
139 #endif
140  } else {
141  int type = (di%types_);
142  id.iType = type;
143  di = (di-type)/types_;
144  id.iSec2 = (di%waferMax_)-waferOff_;
145  di = (di-id.iSec2-waferOff_)/waferMax_;
146  id.iSec1 = (di%waferMax_)-waferOff_;
147  di = (di-id.iSec1-waferOff_)/waferMax_;
148  id.iLay = (di%layers_)+1;
149  di = (di-id.iLay+1)/layers_;
150  id.iCell2 = (di%cellMax_);
151  id.iCell1 = (di-id.iCell2)/cellMax_;
152 #ifdef EDM_ML_DEBUG
153  edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << hi << " o/p " << id.zSide
154  << ":" << id.iLay << ":" << id.iType
155  << ":" << id.iSec1 << ":" << id.iSec2
156  << ":" << id.iCell1 << ":" << id.iCell2;
157 #endif
158  }
159  }
160  return encode(id);
161 }
162 
163 uint32_t HGCalTopology::detId2denseGeomId(const DetId& idin) const {
164 
166  uint32_t idx;
167  if ((mode_ == HGCalGeometryMode::Hexagon) ||
169  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
170  (id.iLay-1)*sectors_+id.iSec1);
171 #ifdef EDM_ML_DEBUG
172  edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << id.zSide << ":"
173  << id.iLay << ":" << id.iSec1 << ":"
174  << id.iType << " Constants " << kHGeomHalf_
175  << ":" << layers_ << ":" << sectors_
176  << " o/p " << idx;
177 #endif
178  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
179  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
180  (((id.iLay-firstLay_)*sectors_+id.iSec1-1)*cellMax_+
181  id.iCell1-1));
182 #ifdef EDM_ML_DEBUG
183  edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << id.zSide << ":"
184  << id.iLay << ":" << id.iSec1 << ":"
185  << id.iCell1 << ":" << id.iType
186  << " Constants " << kHGeomHalf_ << ":"
187  << layers_ << ":" << firstLay_ << ":"
188  << sectors_ << ":" << cellMax_
189  << " o/p " << idx;
190 #endif
191  } else {
192  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
193  (((id.iLay-1)*waferMax_+id.iSec1+waferOff_)*waferMax_+
194  id.iSec2+waferOff_));
195 #ifdef EDM_ML_DEBUG
196  edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << id.zSide << ":"
197  << id.iLay << ":" << id.iSec1 << ":"
198  << id.iSec2 << ":" << id.iType
199  << " Constants " << kHGeomHalf_ << ":"
200  << layers_ << ":" << waferMax_ << ":"
201  << waferOff_ << " o/p " << idx;
202 #endif
203  }
204  return idx;
205 }
206 
207 bool HGCalTopology::valid(const DetId& idin) const {
208 
210  bool flag;
211  if ((mode_ == HGCalGeometryMode::Hexagon) ||
213  flag = (idin.det() == det_ && idin.subdetId() == (int)(subdet_) &&
214  id.iCell1 >= 0 && id.iCell1 < cells_ && id.iLay > 0 &&
215  id.iLay <= layers_ && id.iSec1 >= 0 && id.iSec1 <= sectors_);
216  if (flag) flag = hdcons_.isValidHex(id.iLay,id.iSec1,id.iCell1,true);
217  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
218  flag = ((idin.det() == det_) &&
219  hdcons_.isValidTrap(id.iLay,id.iSec1,id.iCell1));
220  } else {
221  flag = ((idin.det() == det_) &&
222  hdcons_.isValidHex8(id.iLay,id.iSec1,id.iSec2,id.iCell1,id.iCell2));
223  }
224  return flag;
225 }
226 
227 DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX,
228  int nrStepsY ) const {
229 
230  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
231  DetId id = changeXY(startId,nrStepsX,nrStepsY);
232  if (valid(id)) return id;
233  }
234  return DetId(0);
235 }
236 
237 DetId HGCalTopology::switchZSide(const DetId startId) const {
238 
239  HGCalTopology::DecodedDetId id_ = decode(startId);
240  id_.zSide =-id_.zSide;
241  DetId id = encode(id_);
242  if (valid(id)) return id;
243  else return DetId(0);
244 }
245 
247 
249  if (hi < totalGeomModules()) {
250  id.zSide = ((int)(hi)<kHGeomHalf_ ? -1 : 1);
251  int di = ((int)(hi)%kHGeomHalf_);
252  if ((mode_ == HGCalGeometryMode::Hexagon) ||
254  id.iSec1 = (di%sectors_);
255  di = (di-id.iSec1)/sectors_;
256  id.iLay = (di%layers_)+1;
257  id.iType = ((di-id.iLay+1)/layers_ == 0) ? -1 : 1;
258 #ifdef EDM_ML_DEBUG
259  edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << hi << " O/P "
260  << id.zSide << ":" << id.iType << ":"
261  << id.iLay << ":" << id.iSec1;
262 #endif
263  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
264  id.iCell1 = (di%cellMax_)+1;
265  di = (di-id.iCell1+1)/cellMax_;
266  id.iSec1 = (di%sectors_)+1;
267  di = (di-id.iSec1+1)/sectors_;
268  id.iLay = (di%layers_) + firstLay_;
269  id.iType = (di-id.iLay+firstLay_)/layers_;
270 #ifdef EDM_ML_DEBUG
271  edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << hi << " O/P "
272  << id.zSide << ":" << id.iType << ":"
273  << id.iLay << ":" << id.iSec1 << ":"
274  << id.iCell1;
275 #endif
276  } else {
277  id.iSec2 = (di%waferMax_)-waferOff_;
278  di = (di-id.iSec2-waferOff_)/waferMax_;
279  id.iSec1 = (di%waferMax_)-waferOff_;
280  di = (di-id.iSec1-waferOff_)/waferMax_;
281  id.iLay = (di%layers_)+1;
282  id.iType = (di-id.iLay+1)/layers_;
283 #ifdef EDM_ML_DEBUG
284  edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << hi << " O/P "
285  << id.zSide << ":" << id.iType << ":"
286  << id.iLay << ":" << id.iSec1 << ":"
287  << id.iSec2;
288 #endif
289  }
290  }
291  return id;
292 }
293 
295 
297  if ((mode_ == HGCalGeometryMode::Hexagon) ||
299  HGCalDetId id(startId);
300  idx.iCell1 = id.cell();
301  idx.iCell2 = 0;
302  idx.iLay = id.layer();
303  idx.iSec1 = id.wafer();
304  idx.iSec2 = 0;
305  idx.iType = id.waferType();
306  idx.zSide = id.zside();
307  idx.det = id.subdetId();
308  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
309  HGCScintillatorDetId id(startId);
310  idx.iCell1 = id.iphi();
311  idx.iCell2 = 0;
312  idx.iLay = id.layer();
313  idx.iSec1 = id.ietaAbs();
314  idx.iSec2 = 0;
315  idx.iType = id.type();
316  idx.zSide = id.zside();
317  idx.det = (int)(id.subdet());
319  HFNoseDetId id(startId);
320  idx.iCell1 = id.cellU();
321  idx.iCell2 = id.cellV();
322  idx.iLay = id.layer();
323  idx.iSec1 = id.waferU();
324  idx.iSec2 = id.waferV();
325  idx.iType = id.type();
326  idx.zSide = id.zside();
327  idx.det = (int)(id.subdet());
328  } else {
329  HGCSiliconDetId id(startId);
330  idx.iCell1 = id.cellU();
331  idx.iCell2 = id.cellV();
332  idx.iLay = id.layer();
333  idx.iSec1 = id.waferU();
334  idx.iSec2 = id.waferV();
335  idx.iType = id.type();
336  idx.zSide = id.zside();
337  idx.det = (int)(id.subdet());
338  }
339  return idx;
340 }
341 
343 
344  DetId id;
347  id = HGCalDetId((ForwardSubdetector)(idx.det),idx.zSide,idx.iLay,((idx.iType > 0) ? 1 : 0),idx.iSec1,idx.iCell1).rawId();
348  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
349  id = HGCScintillatorDetId(idx.iType,idx.iLay,idx.zSide*idx.iSec1,idx.iCell1).rawId();
351  id = HFNoseDetId(idx.zSide,idx.iType,idx.iLay,idx.iSec1,idx.iSec2,idx.iCell1,idx.iCell2).rawId();
352  } else {
353  id = HGCSiliconDetId((DetId::Detector)(idx.det),idx.zSide,idx.iType,idx.iLay,idx.iSec1,idx.iSec2,idx.iCell1,idx.iCell2).rawId();
354  }
355  return id;
356 }
357 
358 DetId HGCalTopology::changeXY(const DetId& id, int nrStepsX,
359  int nrStepsY ) const {
360 
361  return DetId();
362 }
363 
364 
365 DetId HGCalTopology::changeZ(const DetId& id, int nrStepsZ) const {
366 
367  return DetId();
368 }
369 
371 
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