test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HGCalTopology.cc
Go to the documentation of this file.
3 
4 //#define EDM_ML_DEBUG
5 
7  ForwardSubdetector subdet,
8  bool half) : hdcons_(hdcons), subdet_(subdet),
9  half_(half) {
11  layers_ = hdcons_.layers(true);
12  cells_ = hdcons_.maxCells(true);
17  } else {
20  }
21  kSizeForDenseIndexing = (unsigned int)(2*kHGhalf_);
22 #ifdef EDM_ML_DEBUG
23  std::cout << "HGCalTopology initialized for subdetector " << subdet_
24  << " having half-chamber flag " << half_ << " with " << sectors_
25  << " Sectors " << layers_ << " Layers " << cells_
26  << " cells and total channels " << kSizeForDenseIndexing << ":"
27  << (2*kHGeomHalf_) << std::endl;
28 #endif
29 }
30 
31 unsigned int HGCalTopology::allGeomModules() const {
32  int n = (mode_ == HGCalGeometryMode::Square) ?
33  (2*kHGeomHalf_) : (2*hdcons_.wafers());
34  return (unsigned int)(n);
35 }
36 
37 uint32_t HGCalTopology::detId2denseId(const DetId& id) const {
38 
40  int isubsec= (id_.iSubSec > 0) ? 1 : 0;
41  uint32_t idx;
43  idx = (uint32_t)((((id_.zside > 0) ? kHGhalf_ : 0) +
44  ((((id_.iCell-1)*layers_+id_.iLay-1)*sectors_+
45  id_.iSec-1)*subSectors_+isubsec)));
46  } else {
47  idx = (uint32_t)((((id_.zside > 0) ? kHGhalf_ : 0) +
48  ((((id_.iCell-1)*layers_+id_.iLay-1)*sectors_+
49  id_.iSec)*subSectors_+isubsec)));
50  }
51  return idx;
52 }
53 
54 DetId HGCalTopology::denseId2detId(uint32_t hi) const {
55 
56  if (validHashIndex(hi)) {
58  id_.zside = ((int)(hi)<kHGhalf_ ? -1 : 1);
59  int di = ((int)(hi)%kHGhalf_);
60  int iSubSec= (di%subSectors_);
61  id_.iSubSec= (iSubSec == 0 ? -1 : 1);
63  id_.iSec = (((di-iSubSec)/subSectors_)%sectors_+1);
64  } else {
65  id_.iSec = (((di-iSubSec)/subSectors_)%sectors_);
66  }
67  id_.iLay = (((((di-iSubSec)/subSectors_)-id_.iSec+1)/sectors_)%layers_+1);
68  id_.iCell = (((((di-iSubSec)/subSectors_)-id_.iSec+1)/sectors_-id_.iLay+1)/layers_+1);
69  return encode(id_);
70  } else {
71  return DetId(0);
72  }
73 }
74 
75 uint32_t HGCalTopology::detId2denseGeomId(const DetId& id) const {
76 
78  int isubsec= (half_ && id_.iSubSec > 0) ? 1 : 0;
79  uint32_t idx;
81  idx = (uint32_t)(((id_.zside > 0) ? kHGeomHalf_ : 0) +
82  ((isubsec*layers_+id_.iLay-1)*sectors_+id_.iSec-1));
83  } else {
84  idx = (uint32_t)(((id_.zside > 0) ? kHGeomHalf_ : 0) +
85  ((isubsec*layers_+id_.iLay-1)*sectors_+id_.iSec));
86 #ifdef EDM_ML_DEBUG
87  std::cout << "I/P " << id_.zside << ":" << id_.iLay << ":" << id_.iSec
88  << ":" << isubsec << " Constants " << kHGeomHalf_ << ":"
89  << layers_ << ":" << sectors_ << " o/p " << idx << std::endl;
90 #endif
91  }
92  return idx;
93 }
94 
95 bool HGCalTopology::valid(const DetId& id) const {
96 
98  bool flag;
100  flag = (id.det() == DetId::Forward && id.subdetId() == (int)(subdet_) &&
101  id_.iCell >= 0 && id_.iCell < cells_ && id_.iLay > 0 &&
102  id_.iLay <= layers_ && id_.iSec > 0 && id_.iSec <= sectors_);
103  } else {
104  flag = (id.det() == DetId::Forward && id.subdetId() == (int)(subdet_) &&
105  id_.iCell >= 0 && id_.iCell < cells_ && id_.iLay > 0 &&
106  id_.iLay <= layers_ && id_.iSec >= 0 && id_.iSec <= sectors_);
107  if (flag) flag = hdcons_.isValid(id_.iLay,id_.iSec,id_.iCell,true);
108  }
109  return flag;
110 }
111 
112 DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX,
113  int nrStepsY ) const {
114 
115  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
116  DetId id = changeXY(startId,nrStepsX,nrStepsY);
117  if (valid(id)) return id;
118  }
119  return DetId(0);
120 }
121 
122 DetId HGCalTopology::switchZSide(const DetId startId) const {
123 
124  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
125  HGCalTopology::DecodedDetId id_ = decode(startId);
126  id_.zside =-id_.zside;
127  DetId id = encode(id_);
128  if (valid(id)) return id;
129  }
130  return DetId(0);
131 }
132 
134 
136  if (hi < totalGeomModules()) {
137  id_.zside = ((int)(hi)<kHGeomHalf_ ? -1 : 1);
138  int di = ((int)(hi)%kHGeomHalf_);
139  int iSubSec= (di%subSectors_);
140  id_.iSubSec= (iSubSec == 0 ? -1 : 1);
142  id_.iSec = (((di-iSubSec)/subSectors_)%sectors_+1);
143  } else {
144  id_.iSec = (((di-iSubSec)/subSectors_)%sectors_);
145  }
146  id_.iLay = (((((di-iSubSec)/subSectors_)-id_.iSec+1)/sectors_)%layers_+1);
147  }
148  return id_;
149 }
150 
152 
154  if ((mode_ == HGCalGeometryMode::Hexagon) ||
156  HGCalDetId id(startId);
157  id_.iCell = id.cell();
158  id_.iLay = id.layer();
159  id_.iSec = id.wafer();
160  id_.iSubSec= id.waferType();
161  id_.zside = id.zside();
162  id_.subdet = id.subdetId();
163  } else if (subdet_ == HGCEE) {
164  HGCEEDetId id(startId);
165  id_.iCell = id.cell();
166  id_.iLay = id.layer();
167  id_.iSec = id.sector();
168  id_.iSubSec= id.subsector();
169  id_.zside = id.zside();
170  id_.subdet = id.subdetId();
171  } else {
172  HGCHEDetId id(startId);
173  id_.iCell = id.cell();
174  id_.iLay = id.layer();
175  id_.iSec = id.sector();
176  id_.iSubSec= id.subsector();
177  id_.zside = id.zside();
178  id_.subdet = id.subdetId();
179  }
180  return id_;
181 }
182 
184 
185  int isubsec= (id_.iSubSec > 0) ? 1 : 0;
186  DetId id;
189  id = HGCalDetId(subdet_,id_.zside,id_.iLay,isubsec,id_.iSec,id_.iCell).rawId();
190  } else if (subdet_ == HGCEE) {
191  id = HGCEEDetId(subdet_,id_.zside,id_.iLay,id_.iSec,isubsec,id_.iCell).rawId();
192  } else {
193  id = HGCHEDetId(subdet_,id_.zside,id_.iLay,id_.iSec,isubsec,id_.iCell).rawId();
194  }
195  return id;
196 }
197 
198 DetId HGCalTopology::changeXY(const DetId& id, int nrStepsX,
199  int nrStepsY ) const {
200 
202  std::pair<int,int> kcell= hdcons_.newCell(id_.iCell,id_.iLay,id_.iSec,
203  id_.iSubSec,nrStepsX,nrStepsY,
204  half_);
205  id_.iSubSec= kcell.second;
206  id_.iSec = (kcell.second > 0) ? kcell.second : -kcell.second;
207  id_.iCell = kcell.first;
208  DetId nextPoint = encode(id_);
209  if (valid(nextPoint)) return nextPoint;
210  else return DetId(0);
211 }
212 
213 
214 DetId HGCalTopology::changeZ(const DetId& id, int nrStepsZ) const {
215 
217  std::pair<int,int> kcell = hdcons_.newCell(id_.iCell,id_.iLay,
218  id_.iSubSec,nrStepsZ,half_);
219  id_.iLay = kcell.second;
220  id_.iCell = kcell.first;
221  DetId nextPoint = encode(id_);
222  if (valid(nextPoint)) return nextPoint;
223  else return DetId(0);
224 }
225 
227 
bool isValid(int lay, int mod, int cell, bool reco) const
bool validHashIndex(uint32_t ix) const
Definition: HGCalTopology.h:97
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
ForwardSubdetector
DetId offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const
virtual uint32_t detId2denseId(const DetId &id) const
Dense indexing.
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
HGCalTopology(const HGCalDDDConstants &hdcons, ForwardSubdetector subdet, bool halfChamber)
create a new Topology
Definition: HGCalTopology.cc:6
unsigned int totalGeomModules() const
unsigned int layers(bool reco) const
virtual uint32_t detId2denseGeomId(const DetId &id) const
DetId encode(const DecodedDetId &id_) const
virtual bool valid(const DetId &id) const
Is this a valid cell id.
static const int subSectors_
Use subSector in square mode as wafer type in hexagon mode.
HGCalGeometryMode geomMode() const
int sectors() const
DecodedDetId geomDenseId2decId(const uint32_t &hi) const
ForwardSubdetector subdet_
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
const HGCalDDDConstants & hdcons_
HGCalGeometryMode
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
DecodedDetId decode(const DetId &id) const
Definition: DetId.h:18
virtual DetId denseId2detId(uint32_t denseId) const
HGCalGeometryMode mode_
DetId switchZSide(const DetId startId) const
std::pair< int, int > newCell(int cell, int layer, int sector, int subsector, int incrx, int incry, bool half) const
unsigned int kSizeForDenseIndexing
tuple cout
Definition: gather_cfg.py:145
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
int maxCells(bool reco) const