CMS 3D CMS Logo

HGCalTriggerTools.cc
Go to the documentation of this file.
2 
4 
12 
14 
16 
17 namespace {
18  template <typename DDD>
19  inline void check_ddd(const DDD* ddd) {
20  if (nullptr == ddd) {
21  throw cms::Exception("hgcal::HGCalTriggerTools") << "DDDConstants not accessible to hgcal::HGCalTriggerTools!";
22  }
23  }
24 
25  template <typename GEOM>
26  inline void check_geom(const GEOM* geom) {
27  if (nullptr == geom) {
28  throw cms::Exception("hgcal::HGCalTriggerTools") << "Geometry not provided yet to hgcal::HGCalTriggerTools!";
29  }
30  }
31 } // namespace
32 
35  es.get<CaloGeometryRecord>().get(triggerGeometry_);
36  geom_ = triggerGeometry_.product();
37 
40  if (geom_->isV9Geometry()) {
43  } else {
46  }
47 }
48 
50  if (id.det() == DetId::Hcal || id.det() == DetId::HGCalEE) {
51  throw cms::Exception("hgcal::HGCalTriggerTools") << "method getTCPosition called for DetId not belonging to a TC";
52  // FIXME: this would actually need a better test...but at the moment I can not think to anything better
53  // to distinguish a TC detId
54  }
55 
57  return position;
58 }
59 
61  unsigned layers = 0;
62  switch (type) {
64  layers = eeLayers_;
65  break;
67  layers = fhLayers_;
68  break;
70  layers = bhLayers_;
71  break;
73  layers = totalLayers_;
74  break;
75  default:
76  break;
77  };
78  return layers;
79 }
80 
82  unsigned layers = 0;
83  switch (type) {
84  case DetId::HGCalEE:
85  layers = eeLayers_;
86  break;
87  case DetId::HGCalHSi:
88  layers = fhLayers_;
89  break;
90  case DetId::HGCalHSc:
91  layers = bhLayers_;
92  break;
93  case DetId::Forward:
94  layers = totalLayers_;
95  break;
96  default:
97  break;
98  }
99  return layers;
100 }
101 
102 unsigned HGCalTriggerTools::layer(const DetId& id) const {
104  if (id.det() == DetId::Forward) {
105  layer = HGCalDetId(id).layer();
106  } else if (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap) {
107  layer = HcalDetId(id).depth();
108  } else if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
109  layer = HGCSiliconDetId(id).layer();
110  } else if (id.det() == DetId::HGCalTrigger) {
111  layer = HGCalTriggerDetId(id).layer();
112  } else if (id.det() == DetId::HGCalHSc) {
113  layer = HGCScintillatorDetId(id).layer();
114  }
115  return layer;
116 }
117 
118 unsigned HGCalTriggerTools::layerWithOffset(const DetId& id) const {
119  unsigned int l = layer(id);
120  if (isHad(id) && isSilicon(id)) {
121  l += eeLayers_;
122  } else if (isHad(id) && isScintillator(id)) {
123  if (geom_->isV9Geometry())
124  l += eeLayers_; // mixed silicon and scintillator layers
125  else
126  l += eeLayers_ + fhLayers_;
127  }
128  return l;
129 }
130 
131 bool HGCalTriggerTools::isEm(const DetId& id) const {
132  bool em = false;
133  if (id.det() == DetId::Forward) {
134  em = (id.subdetId() == HGCEE);
135  } else if (id.det() == DetId::HGCalEE) {
136  em = true;
137  } else if (id.det() == DetId::HGCalTrigger) {
139  }
140  return em;
141 }
142 
143 bool HGCalTriggerTools::isSilicon(const DetId& id) const {
144  bool silicon = false;
145  if (id.det() == DetId::Forward) {
146  silicon = (id.subdetId() != HGCHEB);
147  } else if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
148  silicon = true;
149  } else if (id.det() == DetId::HGCalTrigger) {
151  }
152  return silicon;
153 }
154 
155 int HGCalTriggerTools::zside(const DetId& id) const {
156  int zside = 0;
157  if (id.det() == DetId::Forward) {
158  zside = HGCalDetId(id).zside();
159  } else if (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap) {
160  zside = HcalDetId(id).zside();
161  } else if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
162  zside = HGCSiliconDetId(id).zside();
163  } else if (id.det() == DetId::HGCalTrigger) {
164  zside = HGCalTriggerDetId(id).zside();
165  } else if (id.det() == DetId::HGCalHSc) {
166  zside = HGCScintillatorDetId(id).zside();
167  }
168  return zside;
169 }
170 
171 int HGCalTriggerTools::thicknessIndex(const DetId& id, bool tc) const {
172  unsigned det = id.det();
173  int thickness = 0;
174  // For the v8 geometry
175  if (det == DetId::Forward) {
176  if (!tc)
177  thickness = sensorCellThicknessV8(id);
178  else {
179  // For the old geometry, TCs can contain sensor cells
180  // with different thicknesses.
181  // Use a majority logic to find the TC thickness
182  std::array<unsigned, 3> occurences = {{0, 0, 0}};
183  for (const auto& c_id : geom_->getCellsFromTriggerCell(id)) {
184  int c_thickness = sensorCellThicknessV8(c_id);
185  occurences[c_thickness]++;
186  }
187  thickness = std::max_element(occurences.begin(), occurences.end()) - occurences.begin();
188  }
189  }
190  // For the v9 geometry
191  else if (det == DetId::HGCalEE || det == DetId::HGCalHSi) {
192  thickness = HGCSiliconDetId(id).type();
193  } else if (det == DetId::HGCalTrigger) {
194  thickness = HGCalTriggerDetId(id).type();
195  }
196  return thickness;
197 }
198 
199 float HGCalTriggerTools::getEta(const GlobalPoint& position, const float& vertex_z) const {
200  GlobalPoint corrected_position = GlobalPoint(position.x(), position.y(), position.z() - vertex_z);
201  return corrected_position.eta();
202 }
203 
204 float HGCalTriggerTools::getTCEta(const DetId& id, const float& vertex_z) const {
206  return getEta(position, vertex_z);
207 }
208 
210  float phi = atan2(position.y(), position.x());
211  return phi;
212 }
213 
214 float HGCalTriggerTools::getTCPhi(const DetId& id) const {
216  return getPhi(position);
217 }
218 
219 float HGCalTriggerTools::getPt(const GlobalPoint& position, const float& hitEnergy, const float& vertex_z) const {
220  float eta = getEta(position, vertex_z);
221  float pt = hitEnergy / cosh(eta);
222  return pt;
223 }
224 
225 float HGCalTriggerTools::getTCPt(const DetId& id, const float& hitEnergy, const float& vertex_z) const {
227  return getPt(position, hitEnergy, vertex_z);
228 }
229 
230 float HGCalTriggerTools::getLayerZ(const unsigned& layerWithOffset) const {
231  int subdet = ForwardSubdetector::HGCEE;
232  unsigned offset = 0;
233  if (layerWithOffset > lastLayerEE() && layerWithOffset <= lastLayerFH()) {
235  offset = lastLayerEE();
236  } else if (layerWithOffset > lastLayerFH()) {
238  offset = lastLayerFH();
239  }
240  return getLayerZ(subdet, layerWithOffset - offset);
241 }
242 
243 float HGCalTriggerTools::getLayerZ(const int& subdet, const unsigned& layer) const {
244  float layerGlobalZ = 0.;
245  if ((subdet == ForwardSubdetector::HGCEE) || (subdet == DetId::HGCalEE)) {
246  layerGlobalZ = geom_->eeTopology().dddConstants().waferZ(layer, true);
247  } else if ((subdet == ForwardSubdetector::HGCHEF) || (subdet == DetId::HGCalHSi)) {
248  layerGlobalZ = geom_->fhTopology().dddConstants().waferZ(layer, true);
249  } else if ((subdet == HcalSubdetector::HcalEndcap) || (subdet == ForwardSubdetector::HGCHEB) ||
250  (subdet == DetId::HGCalHSc)) {
251  if (geom_->isV9Geometry()) {
252  layerGlobalZ = geom_->hscTopology().dddConstants().waferZ(layer, true);
253  } else {
254  layerGlobalZ = geom_->bhTopology().dddConstants()->getRZ(
256  }
257  }
258  return layerGlobalZ;
259 }
260 
261 DetId HGCalTriggerTools::simToReco(const DetId& simid, const HGCalTopology& topo) const {
262  DetId recoid(0);
263  const auto& dddConst = topo.dddConstants();
264  // V9
265  if (dddConst.geomMode() == HGCalGeometryMode::Hexagon8 || dddConst.geomMode() == HGCalGeometryMode::Hexagon8Full ||
266  dddConst.geomMode() == HGCalGeometryMode::Trapezoid) {
267  recoid = simid;
268  }
269  // V8
270  else {
271  int subdet(simid.subdetId());
272  int layer = 0, cell = 0, sec = 0, subsec = 0, zp = 0;
273  HGCalTestNumbering::unpackHexagonIndex(simid, subdet, zp, layer, sec, subsec, cell);
274  //sec is wafer and subsec is celltype
275  //skip this hit if after ganging it is not valid
276  auto recoLayerCell = dddConst.simToReco(cell, layer, sec, topo.detectorType());
277  cell = recoLayerCell.first;
278  layer = recoLayerCell.second;
279  if (layer >= 0 && cell >= 0) {
280  recoid = HGCalDetId((ForwardSubdetector)subdet, zp, layer, subsec, sec, cell);
281  }
282  }
283  return recoid;
284 }
285 
286 DetId HGCalTriggerTools::simToReco(const DetId& simid, const HcalTopology& topo) const {
287  DetId recoid(0);
288  const auto& dddConst = topo.dddConstants();
289  HcalDetId id = HcalHitRelabeller::relabel(simid, dddConst);
290  if (id.subdet() == int(HcalEndcap))
291  recoid = id;
292  return recoid;
293 }
294 
296  int thickness = 0;
297  switch (id.subdetId()) {
299  thickness = geom_->eeTopology().dddConstants().waferTypeL(HGCalDetId(id).wafer()) - 1;
300  break;
302  thickness = geom_->fhTopology().dddConstants().waferTypeL(HGCalDetId(id).wafer()) - 1;
303  break;
304  default:
305  break;
306  };
307  return thickness;
308 }
type
Definition: HCALResponse.h:21
bool isScintillator(const DetId &id) const
float getTCEta(const DetId &id, const float &vertex_z=0.) const
unsigned layer(const DetId &) const
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:168
virtual geom_set getCellsFromTriggerCell(const unsigned cell_det_id) const =0
void eventSetup(const edm::EventSetup &)
HGCalTriggerSubdetector subdet() const
get the subdetector
unsigned lastLayerEE() const
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:149
const HGCalTopology & eeTopology() const
const HGCalTriggerGeometryBase * geom_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
int zside() const
get the z-side of the cell (1/-1)
bool detectorType() const
int zside() const
get the z-side of the cell (1/-1)
float getLayerZ(const unsigned &layerWithOffset) const
unsigned layerWithOffset(const DetId &) const
ForwardSubdetector
int type() const
get the type
std::pair< int, int > getEtaRange(const int &i) const
int layer() const
get the layer #
int depth() const
get the tower depth
Definition: HcalDetId.h:166
bool isHad(const DetId &id) const
unsigned int layers(bool reco) const
float getEta(const GlobalPoint &position, const float &vertex_z=0.) const
int zside() const
get the z-side of the cell (1/-1)
Definition: HGCalDetId.h:51
int zside(const DetId &) const
const HcalTopology & bhTopology() const
int type() const
get the type
int layer() const
get the layer #
T z() const
Definition: PV3DBase.h:64
double getRZ(const int &subdet, const int &ieta, const int &depth) 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
int waferTypeL(int wafer) const
float getTCPhi(const DetId &id) const
float getTCPt(const DetId &id, const float &hitEnergy, const float &vertex_z=0.) const
double waferZ(int layer, bool reco) const
float getPhi(const GlobalPoint &position) const
Definition: DetId.h:18
unsigned layers(ForwardSubdetector type) const
int thicknessIndex(const DetId &, bool tc=false) const
int sensorCellThicknessV8(const DetId &id) const
bool isSilicon(const DetId &) const
const HGCalDDDConstants & dddConstants() const
const HGCalTopology & hscTopology() const
Detector
Definition: DetId.h:26
int getMaxDepth(const int &type) const
int layer() const
get the layer #
T eta() const
Definition: PV3DBase.h:76
bool isEm(const DetId &) const
int zside() const
get the z-side of the cell (1/-1)
float getPt(const GlobalPoint &position, const float &hitEnergy, const float &vertex_z=0.) const
static int position[264][3]
Definition: ReadPGInfo.cc:509
T get() const
Definition: EventSetup.h:71
GlobalPoint getTCPosition(const DetId &id) const
DetId simToReco(const DetId &, const HGCalTopology &) const
DetId relabel(const uint32_t testId) const
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
Definition: HGCalDetId.h:48
virtual GlobalPoint getTriggerCellPosition(const unsigned trigger_cell_det_id) const =0
unsigned lastLayerFH() const