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  if (isScintillator(id)) {
174  }
175  unsigned det = id.det();
176  int thickness = 0;
177  // For the v8 detid scheme
178  if (det == DetId::Forward) {
179  if (!tc)
180  thickness = sensorCellThicknessV8(id);
181  else {
182  // For the old geometry, TCs can contain sensor cells
183  // with different thicknesses.
184  // Use a majority logic to find the TC thickness
185  std::array<unsigned, 3> occurences = {{0, 0, 0}};
186  for (const auto& c_id : geom_->getCellsFromTriggerCell(id)) {
187  unsigned c_det = DetId(c_id).det();
188  int c_thickness = -1;
189  // For the v8 detid scheme
190  if (c_det == DetId::Forward) {
191  c_thickness = sensorCellThicknessV8(c_id);
192  } else {
193  c_thickness = HGCSiliconDetId(c_id).type();
194  }
195  if (c_thickness < 0 || unsigned(c_thickness) >= occurences.size()) {
196  throw cms::Exception("OutOfBound") << "Found thickness index = " << c_thickness;
197  }
198  occurences[c_thickness]++;
199  }
200  thickness = std::max_element(occurences.begin(), occurences.end()) - occurences.begin();
201  }
202  }
203  // For the v9 detid scheme
204  else if (det == DetId::HGCalEE || det == DetId::HGCalHSi) {
205  thickness = HGCSiliconDetId(id).type();
206  } else if (det == DetId::HGCalTrigger) {
207  thickness = HGCalTriggerDetId(id).type();
208  }
209  return thickness;
210 }
211 
212 float HGCalTriggerTools::getEta(const GlobalPoint& position, const float& vertex_z) const {
213  GlobalPoint corrected_position = GlobalPoint(position.x(), position.y(), position.z() - vertex_z);
214  return corrected_position.eta();
215 }
216 
217 float HGCalTriggerTools::getTCEta(const DetId& id, const float& vertex_z) const {
219  return getEta(position, vertex_z);
220 }
221 
223  float phi = atan2(position.y(), position.x());
224  return phi;
225 }
226 
227 float HGCalTriggerTools::getTCPhi(const DetId& id) const {
229  return getPhi(position);
230 }
231 
232 float HGCalTriggerTools::getPt(const GlobalPoint& position, const float& hitEnergy, const float& vertex_z) const {
233  float eta = getEta(position, vertex_z);
234  float pt = hitEnergy / cosh(eta);
235  return pt;
236 }
237 
238 float HGCalTriggerTools::getTCPt(const DetId& id, const float& hitEnergy, const float& vertex_z) const {
240  return getPt(position, hitEnergy, vertex_z);
241 }
242 
243 float HGCalTriggerTools::getLayerZ(const unsigned& layerWithOffset) const {
244  int subdet = ForwardSubdetector::HGCEE;
245  unsigned offset = 0;
246  if (layerWithOffset > lastLayerEE() && layerWithOffset <= lastLayerFH()) {
248  offset = lastLayerEE();
249  } else if (layerWithOffset > lastLayerFH()) {
251  offset = lastLayerFH();
252  }
253  return getLayerZ(subdet, layerWithOffset - offset);
254 }
255 
256 float HGCalTriggerTools::getLayerZ(const int& subdet, const unsigned& layer) const {
257  float layerGlobalZ = 0.;
258  if ((subdet == ForwardSubdetector::HGCEE) || (subdet == DetId::HGCalEE)) {
259  layerGlobalZ = geom_->eeTopology().dddConstants().waferZ(layer, true);
260  } else if ((subdet == ForwardSubdetector::HGCHEF) || (subdet == DetId::HGCalHSi)) {
261  layerGlobalZ = geom_->fhTopology().dddConstants().waferZ(layer, true);
262  } else if ((subdet == HcalSubdetector::HcalEndcap) || (subdet == ForwardSubdetector::HGCHEB) ||
263  (subdet == DetId::HGCalHSc)) {
264  if (geom_->isV9Geometry()) {
265  layerGlobalZ = geom_->hscTopology().dddConstants().waferZ(layer, true);
266  } else {
267  layerGlobalZ = geom_->bhTopology().dddConstants()->getRZ(
269  }
270  }
271  return layerGlobalZ;
272 }
273 
274 DetId HGCalTriggerTools::simToReco(const DetId& simid, const HGCalTopology& topo) const {
275  DetId recoid(0);
276  const auto& dddConst = topo.dddConstants();
277  // V9
278  if (dddConst.geomMode() == HGCalGeometryMode::Hexagon8 || dddConst.geomMode() == HGCalGeometryMode::Hexagon8Full ||
279  dddConst.geomMode() == HGCalGeometryMode::Trapezoid) {
280  recoid = simid;
281  }
282  // V8
283  else {
284  int subdet(simid.subdetId());
285  int layer = 0, cell = 0, sec = 0, subsec = 0, zp = 0;
286  HGCalTestNumbering::unpackHexagonIndex(simid, subdet, zp, layer, sec, subsec, cell);
287  //sec is wafer and subsec is celltype
288  //skip this hit if after ganging it is not valid
289  auto recoLayerCell = dddConst.simToReco(cell, layer, sec, topo.detectorType());
290  cell = recoLayerCell.first;
291  layer = recoLayerCell.second;
292  if (layer >= 0 && cell >= 0) {
293  recoid = HGCalDetId((ForwardSubdetector)subdet, zp, layer, subsec, sec, cell);
294  }
295  }
296  return recoid;
297 }
298 
299 DetId HGCalTriggerTools::simToReco(const DetId& simid, const HcalTopology& topo) const {
300  DetId recoid(0);
301  const auto& dddConst = topo.dddConstants();
302  HcalDetId id = HcalHitRelabeller::relabel(simid, dddConst);
303  if (id.subdet() == int(HcalEndcap))
304  recoid = id;
305  return recoid;
306 }
307 
309  int thickness = 0;
310  switch (id.subdetId()) {
312  thickness = geom_->eeTopology().dddConstants().waferTypeL(HGCalDetId(id).wafer()) - 1;
313  break;
315  thickness = geom_->fhTopology().dddConstants().waferTypeL(HGCalDetId(id).wafer()) - 1;
316  break;
317  default:
318  break;
319  };
320  return thickness;
321 }
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:164
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:141
const HGCalTopology & eeTopology() const
const HGCalTriggerGeometryBase * geom_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:60
static unsigned kScintillatorPseudoThicknessIndex_
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
int layer() const
get the layer #
int depth() const
get the tower depth
Definition: HcalDetId.h:164
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:49
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:61
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:48
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:17
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
Definition: HGCalTopology.h:96
const HGCalTopology & hscTopology() const
Detector
Definition: DetId.h:24
int getMaxDepth(const int &type) const
int layer() const
get the layer #
T eta() const
Definition: PV3DBase.h:73
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:289
T get() const
Definition: EventSetup.h:73
GlobalPoint getTCPosition(const DetId &id) const
DetId simToReco(const DetId &, const HGCalTopology &) const
DetId relabel(const uint32_t testId) const
std::pair< int, int > getEtaRange(const int &i) const
T x() const
Definition: PV3DBase.h:59
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:46
virtual GlobalPoint getTriggerCellPosition(const unsigned trigger_cell_det_id) const =0
unsigned lastLayerFH() const
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46