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 DebugLog
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 DebugLog
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  }
87  return idx;
88 }
89 
90 bool HGCalTopology::valid(const DetId& id) const {
91 
93  bool flag;
95  flag = (id.det() == DetId::Forward && id.subdetId() == (int)(subdet_) &&
96  id_.iCell >= 0 && id_.iCell < cells_ && id_.iLay > 0 &&
97  id_.iLay <= layers_ && id_.iSec > 0 && id_.iSec <= sectors_);
98  } else {
99  flag = (id.det() == DetId::Forward && id.subdetId() == (int)(subdet_) &&
100  id_.iCell >= 0 && id_.iCell < cells_ && id_.iLay > 0 &&
101  id_.iLay <= layers_ && id_.iSec >= 0 && id_.iSec <= sectors_);
102  if (flag) flag = hdcons_.isValid(id_.iLay,id_.iSec,id_.iCell,true);
103  }
104  return flag;
105 }
106 
107 DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX,
108  int nrStepsY ) const {
109 
110  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
111  DetId id = changeXY(startId,nrStepsX,nrStepsY);
112  if (valid(id)) return id.rawId();
113  }
114  return DetId(0);
115 }
116 
117 DetId HGCalTopology::switchZSide(const DetId startId) const {
118 
119  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
120  HGCalTopology::DecodedDetId id_ = decode(startId);
121  id_.zside =-id_.zside;
122  DetId id = encode(id_);
123  if (valid(id)) return id.rawId();
124  }
125  return DetId(0);
126 }
127 
129 
131  if (hi < totalGeomModules()) {
132  id_.zside = ((int)(hi)<kHGeomHalf_ ? -1 : 1);
133  int di = ((int)(hi)%kHGeomHalf_);
134  int iSubSec= (di%subSectors_);
135  id_.iSubSec= (iSubSec == 0 ? -1 : 1);
137  id_.iSec = (((di-iSubSec)/subSectors_)%sectors_+1);
138  } else {
139  id_.iSec = (((di-iSubSec)/subSectors_)%sectors_);
140  }
141  id_.iLay = (((((di-iSubSec)/subSectors_)-id_.iSec+1)/sectors_)%layers_+1);
142  }
143  return id_;
144 }
145 
147 
150  HGCalDetId id(startId);
151  id_.iCell = id.cell();
152  id_.iLay = id.layer();
153  id_.iSec = id.wafer();
154  id_.iSubSec= id.waferType();
155  id_.zside = id.zside();
156  id_.subdet = id.subdetId();
157  } else if (subdet_ == HGCEE) {
158  HGCEEDetId id(startId);
159  id_.iCell = id.cell();
160  id_.iLay = id.layer();
161  id_.iSec = id.sector();
162  id_.iSubSec= id.subsector();
163  id_.zside = id.zside();
164  id_.subdet = id.subdetId();
165  } else {
166  HGCHEDetId id(startId);
167  id_.iCell = id.cell();
168  id_.iLay = id.layer();
169  id_.iSec = id.sector();
170  id_.iSubSec= id.subsector();
171  id_.zside = id.zside();
172  id_.subdet = id.subdetId();
173  }
174  return id_;
175 }
176 
178 
179  int isubsec= (id_.iSubSec > 0) ? 1 : 0;
180  DetId id;
182  id = HGCalDetId(subdet_,id_.zside,id_.iLay,isubsec,id_.iSec,id_.iCell).rawId();
183  } else if (subdet_ == HGCEE) {
184  id = HGCEEDetId(subdet_,id_.zside,id_.iLay,id_.iSec,isubsec,id_.iCell).rawId();
185  } else {
186  id = HGCHEDetId(subdet_,id_.zside,id_.iLay,id_.iSec,isubsec,id_.iCell).rawId();
187  }
188  return id;
189 }
190 
191 DetId HGCalTopology::changeXY(const DetId& id, int nrStepsX,
192  int nrStepsY ) const {
193 
195  std::pair<int,int> kcell= hdcons_.newCell(id_.iCell,id_.iLay,id_.iSec,
196  id_.iSubSec,nrStepsX,nrStepsY,
197  half_);
198  id_.iSubSec= kcell.second;
199  id_.iSec = (kcell.second > 0) ? kcell.second : -kcell.second;
200  id_.iCell = kcell.first;
201  DetId nextPoint = encode(id_);
202  if (valid(nextPoint)) return nextPoint;
203  else return DetId(0);
204 }
205 
206 
207 DetId HGCalTopology::changeZ(const DetId& id, int nrStepsZ) const {
208 
210  std::pair<int,int> kcell = hdcons_.newCell(id_.iCell,id_.iLay,
211  id_.iSubSec,nrStepsZ,half_);
212  id_.iLay = kcell.second;
213  id_.iCell = kcell.first;
214  DetId nextPoint = encode(id_);
215  if (valid(nextPoint)) return nextPoint;
216  else return DetId(0);
217 }
218 
220 
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_
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
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