Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-29 23:13:04

0001 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0002 
0003 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0004 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0005 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0007 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0008 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0009 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0011 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0012 
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 
0018 using namespace hgcal;
0019 
0020 namespace {
0021   template <typename DDD>
0022   inline void check_ddd(const DDD* ddd) {
0023     if (nullptr == ddd) {
0024       throw cms::Exception("hgcal::RecHitTools") << "DDDConstants not accessibl to hgcal::RecHitTools!";
0025     }
0026   }
0027 
0028   template <typename GEOM>
0029   inline void check_geom(const GEOM* geom) {
0030     if (nullptr == geom) {
0031       throw cms::Exception("hgcal::RecHitTools") << "Geometry not provided yet to hgcal::RecHitTools!";
0032     }
0033   }
0034 
0035   inline const HGCalDDDConstants* get_ddd(const CaloSubdetectorGeometry* geom, const HGCalDetId& detid) {
0036     const HGCalGeometry* hg = static_cast<const HGCalGeometry*>(geom);
0037     const HGCalDDDConstants* ddd = &(hg->topology().dddConstants());
0038     check_ddd(ddd);
0039     return ddd;
0040   }
0041 
0042   inline const HGCalDDDConstants* get_ddd(const CaloSubdetectorGeometry* geom, const HGCSiliconDetId& detid) {
0043     const HGCalGeometry* hg = static_cast<const HGCalGeometry*>(geom);
0044     const HGCalDDDConstants* ddd = &(hg->topology().dddConstants());
0045     check_ddd(ddd);
0046     return ddd;
0047   }
0048 
0049   inline const HGCalDDDConstants* get_ddd(const CaloSubdetectorGeometry* geom, const HFNoseDetId& detid) {
0050     const HGCalGeometry* hg = static_cast<const HGCalGeometry*>(geom);
0051     const HGCalDDDConstants* ddd = &(hg->topology().dddConstants());
0052     check_ddd(ddd);
0053     return ddd;
0054   }
0055 
0056   inline const HGCalDDDConstants* get_ddd(const CaloGeometry* geom, int type, int maxLayerEE, int layer) {
0057     DetId::Detector det = ((type == 0) ? DetId::Forward : ((layer > maxLayerEE) ? DetId::HGCalHSi : DetId::HGCalEE));
0058     int subdet = ((type != 0) ? ForwardSubdetector::ForwardEmpty
0059                               : ((layer > maxLayerEE) ? ForwardSubdetector::HGCEE : ForwardSubdetector::HGCHEF));
0060     const HGCalGeometry* hg = static_cast<const HGCalGeometry*>(geom->getSubdetectorGeometry(det, subdet));
0061     const HGCalDDDConstants* ddd = &(hg->topology().dddConstants());
0062     check_ddd(ddd);
0063     return ddd;
0064   }
0065 
0066   enum CellType {
0067     CE_E_120 = 0,
0068     CE_E_200 = 1,
0069     CE_E_300 = 2,
0070     CE_H_120 = 3,
0071     CE_H_200 = 4,
0072     CE_H_300 = 5,
0073     CE_H_SCINT = 6,
0074     EnumSize = 7
0075   };
0076 
0077 }  // namespace
0078 
0079 void RecHitTools::setGeometry(const CaloGeometry& geom) {
0080   geom_ = &geom;
0081   unsigned int wmaxEE(0), wmaxFH(0);
0082   auto geomEE = static_cast<const HGCalGeometry*>(
0083       geom_->getSubdetectorGeometry(DetId::HGCalEE, ForwardSubdetector::ForwardEmpty));
0084   //check if it's the new geometry
0085   if (geomEE) {
0086     geometryType_ = 1;
0087     eeOffset_ = (geomEE->topology().dddConstants()).getLayerOffset();
0088     wmaxEE = (geomEE->topology().dddConstants()).waferCount(0);
0089     auto geomFH = static_cast<const HGCalGeometry*>(
0090         geom_->getSubdetectorGeometry(DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty));
0091     fhOffset_ = (geomFH->topology().dddConstants()).getLayerOffset();
0092     wmaxFH = (geomFH->topology().dddConstants()).waferCount(0);
0093     fhLastLayer_ = fhOffset_ + (geomFH->topology().dddConstants()).lastLayer(true);
0094     auto geomBH = static_cast<const HGCalGeometry*>(
0095         geom_->getSubdetectorGeometry(DetId::HGCalHSc, ForwardSubdetector::ForwardEmpty));
0096     bhOffset_ = (geomBH->topology().dddConstants()).getLayerOffset();
0097     bhFirstLayer_ = bhOffset_ + (geomBH->topology().dddConstants()).firstLayer();
0098     bhLastLayer_ = bhOffset_ + (geomBH->topology().dddConstants()).lastLayer(true);
0099     bhMaxIphi_ = geomBH->topology().dddConstants().maxCells(true);
0100   } else {
0101     geometryType_ = 0;
0102     geomEE =
0103         static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HGCEE));
0104     eeOffset_ = (geomEE->topology().dddConstants()).getLayerOffset();
0105     wmaxEE = 1 + (geomEE->topology().dddConstants()).waferMax();
0106     auto geomFH =
0107         static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HGCHEF));
0108     fhOffset_ = (geomFH->topology().dddConstants()).getLayerOffset();
0109     fhLastLayer_ = fhOffset_ + (geomFH->topology().dddConstants()).layers(true);
0110     bhOffset_ = fhLastLayer_;
0111     bhFirstLayer_ = bhOffset_ + 1;
0112     wmaxFH = 1 + (geomFH->topology().dddConstants()).waferMax();
0113     auto geomBH =
0114         static_cast<const HcalGeometry*>(geom_->getSubdetectorGeometry(DetId::Hcal, HcalSubdetector::HcalEndcap));
0115     bhLastLayer_ = bhOffset_ + (geomBH->topology().dddConstants())->getMaxDepth(1);
0116   }
0117   maxNumberOfWafersPerLayer_ = std::max(wmaxEE, wmaxFH);
0118   // For nose geometry
0119   auto geomNose =
0120       static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HFNose));
0121   if (geomNose) {
0122     maxNumberOfWafersNose_ = (geomNose->topology().dddConstants()).waferCount(0);
0123     noseLastLayer_ = (geomNose->topology().dddConstants()).layers(true);
0124   } else {
0125     maxNumberOfWafersNose_ = 0;
0126     noseLastLayer_ = 0;
0127   }
0128 }
0129 
0130 const CaloSubdetectorGeometry* RecHitTools::getSubdetectorGeometry(const DetId& id) const {
0131   DetId::Detector det = id.det();
0132   int subdet = (det == DetId::HGCalEE || det == DetId::HGCalHSi || det == DetId::HGCalHSc)
0133                    ? ForwardSubdetector::ForwardEmpty
0134                    : id.subdetId();
0135   auto geom = geom_->getSubdetectorGeometry(det, subdet);
0136   check_geom(geom);
0137   return geom;
0138 }
0139 
0140 GlobalPoint RecHitTools::getPosition(const DetId& id) const {
0141   auto geom = getSubdetectorGeometry(id);
0142   GlobalPoint position;
0143   if (id.det() == DetId::Hcal || id.det() == DetId::Ecal) {
0144     position = geom->getGeometry(id)->getPosition();
0145   } else {
0146     auto hg = static_cast<const HGCalGeometry*>(geom);
0147     position = hg->getPosition(id);
0148   }
0149   return position;
0150 }
0151 
0152 GlobalPoint RecHitTools::getPositionLayer(int layer, bool nose) const {
0153   unsigned int lay = std::abs(layer);
0154   double z(0);
0155   if (nose) {
0156     auto geomNose =
0157         static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HFNose));
0158     if (geomNose) {
0159       const HGCalDDDConstants* ddd = &(geomNose->topology().dddConstants());
0160       if (ddd)
0161         z = (layer > 0) ? ddd->waferZ(lay, true) : -ddd->waferZ(lay, true);
0162     }
0163   } else {
0164     const HGCalDDDConstants* ddd = get_ddd(geom_, geometryType_, fhOffset_, lay);
0165     if (geometryType_ == 1) {
0166       if (lay > fhOffset_)
0167         lay -= fhOffset_;
0168     }
0169     z = (layer > 0) ? ddd->waferZ(lay, true) : -ddd->waferZ(lay, true);
0170   }
0171   return GlobalPoint(0, 0, z);
0172 }
0173 
0174 int RecHitTools::zside(const DetId& id) const {
0175   int zside = 0;
0176   if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
0177     zside = HGCSiliconDetId(id).zside();
0178   } else if (id.det() == DetId::HGCalHSc) {
0179     zside = HGCScintillatorDetId(id).zside();
0180   } else if (id.det() == DetId::Forward && id.subdetId() == static_cast<int>(HFNose)) {
0181     zside = HFNoseDetId(id).zside();
0182   } else if (id.det() == DetId::Forward) {
0183     zside = HGCalDetId(id).zside();
0184   } else if (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap) {
0185     zside = HcalDetId(id).zside();
0186   }
0187   return zside;
0188 }
0189 
0190 std::float_t RecHitTools::getSiThickness(const DetId& id) const {
0191   auto geom = getSubdetectorGeometry(id);
0192   std::float_t thick(0.37);
0193   if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
0194     const HGCSiliconDetId hid(id);
0195     auto ddd = get_ddd(geom, hid);
0196     thick = ddd->cellThickness(hid.layer(), hid.waferU(), hid.waferV());
0197   } else if (id.det() == DetId::Forward && id.subdetId() == static_cast<int>(HFNose)) {
0198     const HFNoseDetId hid(id);
0199     auto ddd = get_ddd(geom, hid);
0200     thick = ddd->cellThickness(hid.layer(), hid.waferU(), hid.waferV());
0201   } else if (id.det() == DetId::Forward) {
0202     const HGCalDetId hid(id);
0203     auto ddd = get_ddd(geom, hid);
0204     thick = ddd->cellThickness(hid.layer(), hid.wafer(), 0);
0205   } else {
0206     LogDebug("getSiThickness::InvalidSiliconDetid")
0207         << "det id: " << std::hex << id.rawId() << std::dec << ":" << id.det() << " is not HGCal silicon!";
0208     // It does not make any sense to return 0.37 as thickness for a detector
0209     // that is not Silicon(does it?). Mark it as 0. to be able to distinguish
0210     // the case.
0211     thick = 0.f;
0212   }
0213   return thick;
0214 }
0215 
0216 int RecHitTools::getSiThickIndex(const DetId& id) const {
0217   int thickIndex = -1;
0218   if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
0219     thickIndex = HGCSiliconDetId(id).type();
0220   } else if (id.det() == DetId::Forward && id.subdetId() == static_cast<int>(HFNose)) {
0221     thickIndex = HFNoseDetId(id).type();
0222   } else if (id.det() == DetId::Forward) {
0223     float thickness = getSiThickness(id);
0224     if (thickness > 99. && thickness < 121.)
0225       thickIndex = 0;
0226     else if (thickness > 199. && thickness < 201.)
0227       thickIndex = 1;
0228     else if (thickness > 299. && thickness < 301.)
0229       thickIndex = 2;
0230     else
0231       assert(thickIndex > 0 && "ERROR - silicon thickness has a nonsensical value");
0232   }
0233   return thickIndex;
0234 }
0235 
0236 std::pair<float, float> RecHitTools::getScintDEtaDPhi(const DetId& id) const {
0237   if (!isScintillator(id)) {
0238     LogDebug("getScintDEtaDPhi::InvalidScintDetid")
0239         << "det id: " << std::hex << id.rawId() << std::dec << ":" << id.det() << " is not HGCal scintillator!";
0240     return {0.f, 0.f};
0241   }
0242   auto cellGeom = getSubdetectorGeometry(id)->getGeometry(id);
0243   return {cellGeom->etaSpan(), cellGeom->phiSpan()};
0244 }
0245 
0246 std::float_t RecHitTools::getRadiusToSide(const DetId& id) const {
0247   auto geom = getSubdetectorGeometry(id);
0248   std::float_t size(std::numeric_limits<std::float_t>::max());
0249   if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
0250     const HGCSiliconDetId hid(id);
0251     auto ddd = get_ddd(geom, hid);
0252     size = ddd->cellSizeHex(hid.type());
0253   } else if (id.det() == DetId::Forward && id.subdetId() == static_cast<int>(HFNose)) {
0254     const HFNoseDetId hid(id);
0255     auto ddd = get_ddd(geom, hid);
0256     size = ddd->cellSizeHex(hid.type());
0257   } else if (id.det() == DetId::Forward) {
0258     const HGCalDetId hid(id);
0259     auto ddd = get_ddd(geom, hid);
0260     size = ddd->cellSizeHex(hid.waferType());
0261   } else {
0262     edm::LogError("getRadiusToSide::InvalidSiliconDetid")
0263         << "det id: " << std::hex << id.rawId() << std::dec << ":" << id.det() << " is not HGCal silicon!";
0264   }
0265   return size;
0266 }
0267 
0268 unsigned int RecHitTools::getLayer(const ForwardSubdetector type) const {
0269   int layer(0);
0270   switch (type) {
0271     case (ForwardSubdetector::HGCEE): {
0272       auto geomEE =
0273           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HGCEE));
0274       layer = (geomEE->topology().dddConstants()).layers(true);
0275       break;
0276     }
0277     case (ForwardSubdetector::HGCHEF): {
0278       auto geomFH =
0279           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HGCHEF));
0280       layer = (geomFH->topology().dddConstants()).layers(true);
0281       break;
0282     }
0283     case (ForwardSubdetector::HGCHEB): {
0284       auto geomBH =
0285           static_cast<const HcalGeometry*>(geom_->getSubdetectorGeometry(DetId::Hcal, HcalSubdetector::HcalEndcap));
0286       layer = (geomBH->topology().dddConstants())->getMaxDepth(1);
0287       break;
0288     }
0289     case (ForwardSubdetector::ForwardEmpty): {
0290       auto geomEE =
0291           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HGCEE));
0292       layer = (geomEE->topology().dddConstants()).layers(true);
0293       auto geomFH =
0294           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HGCHEF));
0295       layer += (geomFH->topology().dddConstants()).layers(true);
0296       auto geomBH =
0297           static_cast<const HcalGeometry*>(geom_->getSubdetectorGeometry(DetId::Hcal, HcalSubdetector::HcalEndcap));
0298       if (geomBH)
0299         layer += (geomBH->topology().dddConstants())->getMaxDepth(1);
0300       auto geomBH2 =
0301           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HGCHEB));
0302       if (geomBH2)
0303         layer += (geomBH2->topology().dddConstants()).layers(true);
0304       break;
0305     }
0306     case (ForwardSubdetector::HFNose): {
0307       auto geomHFN =
0308           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HFNose));
0309       layer = (geomHFN->topology().dddConstants()).layers(true);
0310       break;
0311     }
0312     default:
0313       layer = 0;
0314   }
0315   return (unsigned int)(layer);
0316 }
0317 
0318 unsigned int RecHitTools::getLayer(const DetId::Detector type, bool nose) const {
0319   int layer;
0320   switch (type) {
0321     case (DetId::HGCalEE): {
0322       auto geomEE =
0323           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(type, ForwardSubdetector::ForwardEmpty));
0324       layer = (geomEE->topology().dddConstants()).layers(true);
0325       break;
0326     }
0327     case (DetId::HGCalHSi): {
0328       auto geomFH =
0329           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(type, ForwardSubdetector::ForwardEmpty));
0330       layer = (geomFH->topology().dddConstants()).layers(true);
0331       break;
0332     }
0333     case (DetId::HGCalHSc): {
0334       auto geomBH =
0335           static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(type, ForwardSubdetector::ForwardEmpty));
0336       layer = (geomBH->topology().dddConstants()).layers(true);
0337       break;
0338     }
0339     case (DetId::Forward): {
0340       if (nose) {
0341         auto geomHFN = static_cast<const HGCalGeometry*>(
0342             geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HFNose));
0343         layer = (geomHFN->topology().dddConstants()).layers(true);
0344       } else {
0345         auto geomEE = static_cast<const HGCalGeometry*>(
0346             geom_->getSubdetectorGeometry(DetId::HGCalEE, ForwardSubdetector::ForwardEmpty));
0347         layer = (geomEE->topology().dddConstants()).layers(true);
0348         auto geomFH = static_cast<const HGCalGeometry*>(
0349             geom_->getSubdetectorGeometry(DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty));
0350         layer += (geomFH->topology().dddConstants()).layers(true);
0351       }
0352       break;
0353     }
0354     default:
0355       layer = 0;
0356   }
0357   return (unsigned int)(layer);
0358 }
0359 
0360 unsigned int RecHitTools::getLayer(const DetId& id) const {
0361   unsigned int layer = std::numeric_limits<unsigned int>::max();
0362   if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
0363     layer = HGCSiliconDetId(id).layer();
0364   } else if (id.det() == DetId::HGCalHSc) {
0365     layer = HGCScintillatorDetId(id).layer();
0366   } else if (id.det() == DetId::Forward && id.subdetId() == static_cast<int>(HFNose)) {
0367     layer = HFNoseDetId(id).layer();
0368   } else if (id.det() == DetId::Forward) {
0369     layer = HGCalDetId(id).layer();
0370   } else if (id.det() == DetId::Hcal && id.subdetId() != HcalEmpty) {
0371     if (id.subdetId() == HcalBarrel)
0372       layer = HcalDetId(id).depth();
0373     else if (id.subdetId() == HcalOuter)
0374       layer = HcalDetId(id).depth() + 1;
0375   } else if (id.det() == DetId::Ecal) {
0376     layer = 0;
0377   }
0378   return layer;
0379 }
0380 
0381 unsigned int RecHitTools::getLayerWithOffset(const DetId& id) const {
0382   unsigned int layer = getLayer(id);
0383   if (id.det() == DetId::Forward && id.subdetId() == HGCHEF) {
0384     layer += fhOffset_;
0385   } else if (id.det() == DetId::HGCalHSi || id.det() == DetId::HGCalHSc) {
0386     // DetId::HGCalHSc hits include the offset w.r.t. EE already
0387     layer += fhOffset_;
0388   } else if (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap) {
0389     layer += bhOffset_;
0390   }
0391   // no need to add offset for HFnose
0392   return layer;
0393 }
0394 
0395 std::pair<int, int> RecHitTools::getWafer(const DetId& id) const {
0396   int waferU = std::numeric_limits<int>::max();
0397   int waferV = 0;
0398   if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
0399     waferU = HGCSiliconDetId(id).waferU();
0400     waferV = HGCSiliconDetId(id).waferV();
0401   } else if (id.det() == DetId::Forward && id.subdetId() == static_cast<int>(HFNose)) {
0402     waferU = HFNoseDetId(id).waferU();
0403     waferV = HFNoseDetId(id).waferV();
0404   } else if (id.det() == DetId::Forward) {
0405     waferU = HGCalDetId(id).wafer();
0406   } else {
0407     edm::LogError("getWafer::InvalidSiliconDetid")
0408         << "det id: " << std::hex << id.rawId() << std::dec << ":" << id.det() << " is not HGCal silicon!";
0409   }
0410   return std::pair<int, int>(waferU, waferV);
0411 }
0412 
0413 std::pair<int, int> RecHitTools::getCell(const DetId& id) const {
0414   int cellU = std::numeric_limits<int>::max();
0415   int cellV = 0;
0416   if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
0417     cellU = HGCSiliconDetId(id).cellU();
0418     cellV = HGCSiliconDetId(id).cellV();
0419   } else if (id.det() == DetId::Forward && id.subdetId() == static_cast<int>(HFNose)) {
0420     cellU = HFNoseDetId(id).cellU();
0421     cellV = HFNoseDetId(id).cellV();
0422   } else if (id.det() == DetId::Forward) {
0423     cellU = HGCalDetId(id).cell();
0424   } else {
0425     edm::LogError("getCell::InvalidSiliconDetid")
0426         << "det id: " << std::hex << id.rawId() << std::dec << ":" << id.det() << " is not HGCal silicon!";
0427   }
0428   return std::pair<int, int>(cellU, cellV);
0429 }
0430 
0431 bool RecHitTools::isHalfCell(const DetId& id) const {
0432   bool ishalf = false;
0433   if (id.det() == DetId::Forward) {
0434     HGCalDetId hid(id);
0435     auto geom = getSubdetectorGeometry(hid);
0436     auto ddd = get_ddd(geom, hid);
0437     const int waferType = ddd->waferTypeT(hid.waferType());
0438     return ddd->isHalfCell(waferType, hid.cell());
0439   }
0440   //new geometry is always false
0441   return ishalf;
0442 }
0443 
0444 int RecHitTools::getCellType(const DetId& id) const {
0445   auto layer_number = getLayerWithOffset(id);
0446   auto thickness = getSiThickIndex(id);
0447   auto geomNose =
0448       static_cast<const HGCalGeometry*>(geom_->getSubdetectorGeometry(DetId::Forward, ForwardSubdetector::HFNose));
0449   auto isNose = geomNose ? true : false;
0450   auto isEELayer = (layer_number <= lastLayerEE(isNose));
0451   auto isScint = isScintillator(id);
0452   int layerType = -1;
0453 
0454   if (isScint) {
0455     layerType = CE_H_SCINT;
0456   }
0457   if (isEELayer) {
0458     if (thickness == 0) {
0459       layerType = CE_E_120;
0460     } else if (thickness == 1) {
0461       layerType = CE_E_200;
0462     } else if (thickness == 2) {
0463       layerType = CE_E_300;
0464     }
0465   } else {
0466     if (thickness == 0) {
0467       layerType = CE_H_120;
0468     } else if (thickness == 1) {
0469       layerType = CE_H_200;
0470     } else if (thickness == 2) {
0471       layerType = CE_H_300;
0472     }
0473   }
0474   assert(layerType != -1);
0475   return layerType;
0476 }
0477 
0478 bool RecHitTools::isSilicon(const DetId& id) const {
0479   return (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi ||
0480           (id.det() == DetId::Forward && id.subdetId() == static_cast<int>(HFNose)));
0481 }
0482 
0483 bool RecHitTools::isScintillator(const DetId& id) const { return id.det() == DetId::HGCalHSc; }
0484 
0485 bool RecHitTools::isOnlySilicon(const unsigned int layer) const {
0486   // HFnose TODO
0487   bool isonlysilicon = (layer % bhLastLayer_) < bhOffset_;
0488   return isonlysilicon;
0489 }
0490 
0491 float RecHitTools::getEta(const GlobalPoint& position, const float& vertex_z) const {
0492   GlobalPoint corrected_position = GlobalPoint(position.x(), position.y(), position.z() - vertex_z);
0493   return corrected_position.eta();
0494 }
0495 
0496 float RecHitTools::getEta(const DetId& id, const float& vertex_z) const {
0497   GlobalPoint position = getPosition(id);
0498   float eta = getEta(position, vertex_z);
0499   return eta;
0500 }
0501 
0502 float RecHitTools::getPhi(const GlobalPoint& position) const {
0503   float phi = atan2(position.y(), position.x());
0504   return phi;
0505 }
0506 
0507 float RecHitTools::getPhi(const DetId& id) const {
0508   GlobalPoint position = getPosition(id);
0509   float phi = atan2(position.y(), position.x());
0510   return phi;
0511 }
0512 
0513 float RecHitTools::getPt(const GlobalPoint& position, const float& hitEnergy, const float& vertex_z) const {
0514   float eta = getEta(position, vertex_z);
0515   float pt = hitEnergy / cosh(eta);
0516   return pt;
0517 }
0518 
0519 float RecHitTools::getPt(const DetId& id, const float& hitEnergy, const float& vertex_z) const {
0520   GlobalPoint position = getPosition(id);
0521   float eta = getEta(position, vertex_z);
0522   float pt = hitEnergy / cosh(eta);
0523   return pt;
0524 }
0525 
0526 std::pair<uint32_t, uint32_t> RecHitTools::firstAndLastLayer(DetId::Detector det, int subdet) const {
0527   if ((det == DetId::HGCalEE) || ((det == DetId::Forward) && (subdet == HGCEE))) {
0528     return std::make_pair(eeOffset_ + 1, fhOffset_);
0529   } else if ((det == DetId::HGCalHSi) || ((det == DetId::Forward) && (subdet == HGCHEF))) {
0530     return std::make_pair(fhOffset_ + 1, fhLastLayer_);
0531   } else if ((det == DetId::Forward) && (subdet == HFNose)) {
0532     return std::make_pair(1, noseLastLayer_);
0533   } else {
0534     return std::make_pair(bhFirstLayer_, bhLastLayer_);
0535   }
0536 }
0537 
0538 bool RecHitTools::maskCell(const DetId& id, int corners) const {
0539   if (id.det() == DetId::Hcal) {
0540     return false;
0541   } else {
0542     auto hg = static_cast<const HGCalGeometry*>(getSubdetectorGeometry(id));
0543     return hg->topology().dddConstants().maskCell(id, corners);
0544   }
0545 }