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 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);
15  kSizeForDenseIndexing = (unsigned int)(2*kHGhalf_);
16 #ifdef DebugLog
17  std::cout << "HGCalTopology initialized for subdetector " << subdet_
18  << " having half-chamber flag " << half_ << " with " << sectors_
19  << " Sectors " << layers_ << " Layers " << cells_
20  << " cells and total channels " << kSizeForDenseIndexing << ":"
21  << (2*kHGeomHalf_) << std::endl;
22 #endif
23 }
24 
25 uint32_t HGCalTopology::detId2denseId(const DetId& id) const {
26 
28  int isubsec= (id_.iSubSec > 0) ? 1 : 0;
29  uint32_t idx = (uint32_t)((((id_.zside > 0) ? kHGhalf_ : 0) +
30  ((((id_.iCell-1)*layers_+id_.iLay-1)*sectors_+
31  id_.iSec-1)*subSectors_+isubsec)));
32  return idx;
33 }
34 
35 DetId HGCalTopology::denseId2detId(uint32_t hi) const {
36 
37  if (validHashIndex(hi)) {
39  id_.zside = ((int)(hi)<kHGhalf_ ? -1 : 1);
40  int di = ((int)(hi)%kHGhalf_);
41  int iSubSec= (di%subSectors_);
42  id_.iSubSec= (iSubSec == 0 ? -1 : 1);
43  id_.iSec = (((di-iSubSec)/subSectors_)%sectors_+1);
44  id_.iLay = (((((di-iSubSec)/subSectors_)-id_.iSec+1)/sectors_)%layers_+1);
45  id_.iCell = (((((di-iSubSec)/subSectors_)-id_.iSec+1)/sectors_-id_.iLay+1)/layers_+1);
46  return encode(id_);
47  } else {
48  return DetId(0);
49  }
50 }
51 
52 uint32_t HGCalTopology::detId2denseGeomId(const DetId& id) const {
53 
55  int isubsec= (half_ && id_.iSubSec > 0) ? 1 : 0;
56  uint32_t idx = (uint32_t)(((id_.zside > 0) ? kHGeomHalf_ : 0) +
57  ((isubsec*layers_+id_.iLay-1)*sectors_+
58  id_.iSec-1));
59  return idx;
60 }
61 
62 bool HGCalTopology::valid(const DetId& id) const {
63 
65  bool flag = (id.det() == DetId::Forward && id.subdetId() == (int)(subdet_) &&
66  id_.iCell >= 0 && id_.iCell < cells_ && id_.iLay > 0 &&
67  id_.iLay <= layers_ && id_.iSec > 0 && id_.iSec <= sectors_);
68  return flag;
69 }
70 
71 DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX,
72  int nrStepsY ) const {
73 
74  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
75  DetId id = changeXY(startId,nrStepsX,nrStepsY);
76  if (valid(id)) return id.rawId();
77  }
78  return DetId(0);
79 }
80 
81 DetId HGCalTopology::switchZSide(const DetId startId) const {
82 
83  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
84  HGCalTopology::DecodedDetId id_ = decode(startId);
85  id_.zside =-id_.zside;
86  DetId id = encode(id_);
87  if (valid(id)) return id.rawId();
88  }
89  return DetId(0);
90 }
91 
93 
95  if (hi < totalGeomModules()) {
96  id_.zside = ((int)(hi)<kHGeomHalf_ ? -1 : 1);
97  int di = ((int)(hi)%kHGeomHalf_);
98  int iSubSec= (di%subSectors_);
99  id_.iSubSec= (iSubSec == 0 ? -1 : 1);
100  id_.iSec = (((di-iSubSec)/subSectors_)%sectors_+1);
101  id_.iLay = (((((di-iSubSec)/subSectors_)-id_.iSec+1)/sectors_)%layers_+1);
102  }
103  return id_;
104 }
105 
107 
109  if (subdet_ == HGCEE) {
110  HGCEEDetId id(startId);
111  id_.iCell = id.cell();
112  id_.iLay = id.layer();
113  id_.iSec = id.sector();
114  id_.iSubSec= id.subsector();
115  id_.zside = id.zside();
116  id_.subdet = id.subdetId();
117  } else {
118  HGCHEDetId id(startId);
119  id_.iCell = id.cell();
120  id_.iLay = id.layer();
121  id_.iSec = id.sector();
122  id_.iSubSec= id.subsector();
123  id_.zside = id.zside();
124  id_.subdet = id.subdetId();
125  }
126  return id_;
127 }
128 
130 
131  int isubsec= (id_.iSubSec > 0) ? 1 : 0;
132  DetId id;
133  if (subdet_ == HGCEE) {
134  id = HGCEEDetId(subdet_,id_.zside,id_.iLay,id_.iSec,isubsec,id_.iCell).rawId();
135  } else {
136  id = HGCHEDetId(subdet_,id_.zside,id_.iLay,id_.iSec,isubsec,id_.iCell).rawId();
137  }
138  return id;
139 }
140 
141 DetId HGCalTopology::changeXY(const DetId& id, int nrStepsX,
142  int nrStepsY ) const {
143 
145  std::pair<int,int> kcell= hdcons_.newCell(id_.iCell,id_.iLay,id_.iSec,
146  id_.iSubSec,nrStepsX,nrStepsY,
147  half_);
148  id_.iSubSec= kcell.second;
149  id_.iSec = (kcell.second > 0) ? kcell.second : -kcell.second;
150  id_.iCell = kcell.first;
151  DetId nextPoint = encode(id_);
152  if (valid(nextPoint)) return nextPoint;
153  else return DetId(0);
154 }
155 
156 
157 DetId HGCalTopology::changeZ(const DetId& id, int nrStepsZ) const {
158 
160  std::pair<int,int> kcell = hdcons_.newCell(id_.iCell,id_.iLay,
161  id_.iSubSec,nrStepsZ,half_);
162  id_.iLay = kcell.second;
163  id_.iCell = kcell.first;
164  DetId nextPoint = encode(id_);
165  if (valid(nextPoint)) return nextPoint;
166  else return DetId(0);
167 }
168 
170 
bool validHashIndex(uint32_t ix) const
Definition: HGCalTopology.h:92
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
Definition: HGCalTopology.h:95
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_
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_
#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
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:121
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
int maxCells(bool reco) const