Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-20 11:33:58

0001 #include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h"
0002 
0003 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0004 
0005 #include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
0006 #include "DataFormats/ForwardDetId/interface/HFNoseTriggerDetId.h"
0007 #include "DataFormats/ForwardDetId/interface/HGCalTriggerDetId.h"
0008 #include "DataFormats/ForwardDetId/interface/HGCalTriggerModuleDetId.h"
0009 #include "Geometry/HcalCommonData/interface/HcalHitRelabeller.h"
0010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0011 #include "SimDataFormats/CaloTest/interface/HGCalTestNumbering.h"
0012 
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 
0017 namespace {
0018   template <typename DDD>
0019   inline void check_ddd(const DDD* ddd) {
0020     if (nullptr == ddd) {
0021       throw cms::Exception("hgcal::HGCalTriggerTools") << "DDDConstants not accessible to hgcal::HGCalTriggerTools!";
0022     }
0023   }
0024 
0025   template <typename GEOM>
0026   inline void check_geom(const GEOM* geom) {
0027     if (nullptr == geom) {
0028       throw cms::Exception("hgcal::HGCalTriggerTools") << "Geometry not provided yet to hgcal::HGCalTriggerTools!";
0029     }
0030   }
0031 }  // namespace
0032 
0033 // Kept for backward compatibility: used in L1Trigger/L1CaloTrigger/test
0034 void HGCalTriggerTools::eventSetup(const edm::EventSetup& es,
0035                                    const edm::ESGetToken<HGCalTriggerGeometryBase, CaloGeometryRecord>& token) {
0036   const edm::ESHandle<HGCalTriggerGeometryBase>& triggerGeometry = es.getHandle(token);
0037   setGeometry(triggerGeometry.product());
0038 }
0039 
0040 void HGCalTriggerTools::setGeometry(const HGCalTriggerGeometryBase* const geom) {
0041   geom_ = geom;
0042   eeLayers_ = geom_->eeTopology().dddConstants().layers(true);
0043   fhLayers_ = geom_->fhTopology().dddConstants().layers(true);
0044   if (geom_->isWithNoseGeometry())
0045     noseLayers_ = geom_->noseTopology().dddConstants().layers(true);
0046 
0047   bhLayers_ = geom_->hscTopology().dddConstants().layers(true);
0048   totalLayers_ = eeLayers_ + fhLayers_;
0049 }
0050 
0051 GlobalPoint HGCalTriggerTools::getTCPosition(const DetId& id) const {
0052   if (id.det() == DetId::HGCalEE) {
0053     throw cms::Exception("hgcal::HGCalTriggerTools") << "method getTCPosition called for DetId not belonging to a TC";
0054     // FIXME: this would actually need a better test...but at the moment I can not think to anything better
0055     // to distinguish a TC detId
0056   }
0057 
0058   GlobalPoint position = geom_->getTriggerCellPosition(id);
0059   return position;
0060 }
0061 
0062 unsigned HGCalTriggerTools::layers(ForwardSubdetector type) const {
0063   unsigned layers = 0;
0064   switch (type) {
0065     case ForwardSubdetector::HGCEE:
0066       layers = eeLayers_;
0067       break;
0068     case ForwardSubdetector::HGCHEF:
0069       layers = fhLayers_;
0070       break;
0071     case ForwardSubdetector::HGCHEB:
0072       layers = bhLayers_;
0073       break;
0074     case ForwardSubdetector::HFNose:
0075       layers = noseLayers_;
0076       break;
0077     case ForwardSubdetector::ForwardEmpty:
0078       layers = totalLayers_;
0079       break;
0080     default:
0081       break;
0082   };
0083   return layers;
0084 }
0085 
0086 unsigned HGCalTriggerTools::layers(DetId::Detector type) const {
0087   unsigned layers = 0;
0088   switch (type) {
0089     case DetId::HGCalEE:
0090       layers = eeLayers_;
0091       break;
0092     case DetId::HGCalHSi:
0093       layers = fhLayers_;
0094       break;
0095     case DetId::HGCalHSc:
0096       layers = bhLayers_;
0097       break;
0098     // FIXME: to do HFNose
0099     case DetId::Forward:
0100       layers = totalLayers_;
0101       break;
0102     default:
0103       break;
0104   }
0105   return layers;
0106 }
0107 
0108 unsigned HGCalTriggerTools::layer(const DetId& id) const {
0109   unsigned int layer = std::numeric_limits<unsigned int>::max();
0110   if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
0111     layer = HFNoseDetId(id).layer();
0112   } else if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HGCTrigger) {
0113     layer = HGCalTriggerModuleDetId(id).layer();
0114   } else if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
0115     layer = HGCSiliconDetId(id).layer();
0116   } else if (id.det() == DetId::HGCalTrigger &&
0117              (HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalEETrigger ||
0118               HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalHSiTrigger)) {
0119     layer = HGCalTriggerDetId(id).layer();
0120   } else if (id.det() == DetId::HGCalTrigger &&
0121              HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
0122     layer = HFNoseTriggerDetId(id).layer();
0123   } else if (id.det() == DetId::HGCalHSc) {
0124     layer = HGCScintillatorDetId(id).layer();
0125   }
0126   return layer;
0127 }
0128 
0129 unsigned HGCalTriggerTools::layerWithOffset(const DetId& id) const {
0130   unsigned int l = layer(id);
0131 
0132   if (isNose(id)) {
0133     l = layer(id);  // no offset for HFnose
0134   } else if (isHad(id)) {
0135     l += eeLayers_;
0136   }
0137 
0138   return l;
0139 }
0140 
0141 bool HGCalTriggerTools::isEm(const DetId& id) const {
0142   bool em = false;
0143 
0144   if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
0145     em = HFNoseDetId(id).isEE();
0146   } else if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HGCTrigger) {
0147     em = HGCalTriggerModuleDetId(id).isEE();
0148   } else if (id.det() == DetId::HGCalEE) {
0149     em = true;
0150   } else if (id.det() == DetId::HGCalTrigger &&
0151              HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalEETrigger) {
0152     em = true;
0153   } else if (id.det() == DetId::HGCalTrigger &&
0154              HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
0155     em = HFNoseTriggerDetId(id).isEE();
0156   }
0157   return em;
0158 }
0159 
0160 bool HGCalTriggerTools::isNose(const DetId& id) const {
0161   bool nose = false;
0162   if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
0163     nose = true;
0164   } else if (id.det() == DetId::HGCalTrigger &&
0165              HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
0166     nose = true;
0167   }
0168   return nose;
0169 }
0170 
0171 bool HGCalTriggerTools::isSilicon(const DetId& id) const {
0172   bool silicon = false;
0173   if (id.det() == DetId::Forward && id.subdetId() == HGCTrigger) {
0174     silicon = (HGCalTriggerModuleDetId(id).triggerSubdetId() != HGCalHScTrigger);
0175   } else if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
0176     silicon = true;
0177   } else if (id.det() == DetId::HGCalTrigger &&
0178              HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
0179     silicon = true;
0180   } else if (id.det() == DetId::HGCalTrigger &&
0181              (HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalEETrigger ||
0182               HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalHSiTrigger)) {
0183     silicon = true;
0184   }
0185   return silicon;
0186 }
0187 
0188 HGCalTriggerTools::SubDetectorType HGCalTriggerTools::getSubDetectorType(const DetId& id) const {
0189   SubDetectorType subdet;
0190   if (!isScintillator(id)) {
0191     if (isEm(id))
0192       subdet = HGCalTriggerTools::hgcal_silicon_CEE;
0193     else
0194       subdet = HGCalTriggerTools::hgcal_silicon_CEH;
0195   } else
0196     subdet = HGCalTriggerTools::hgcal_scintillator;
0197   return subdet;
0198 }
0199 
0200 int HGCalTriggerTools::zside(const DetId& id) const {
0201   int zside = 0;
0202   if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
0203     zside = HFNoseDetId(id).zside();
0204   } else if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HGCTrigger) {
0205     zside = HGCalTriggerModuleDetId(id).zside();
0206   } else if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
0207     zside = HGCSiliconDetId(id).zside();
0208   } else if (id.det() == DetId::HGCalTrigger &&
0209              (HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalEETrigger ||
0210               HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalHSiTrigger)) {
0211     zside = HGCalTriggerDetId(id).zside();
0212   } else if (id.det() == DetId::HGCalTrigger &&
0213              HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
0214     zside = HFNoseTriggerDetId(id).zside();
0215   } else if (id.det() == DetId::HGCalHSc) {
0216     zside = HGCScintillatorDetId(id).zside();
0217   }
0218   return zside;
0219 }
0220 
0221 int HGCalTriggerTools::thicknessIndex(const DetId& id) const {
0222   if (isScintillator(id)) {
0223     return kScintillatorPseudoThicknessIndex_;
0224   }
0225   unsigned det = id.det();
0226   int thickness = 0;
0227   if (det == DetId::HGCalEE || det == DetId::HGCalHSi) {
0228     thickness = HGCSiliconDetId(id).type();
0229   } else if (det == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
0230     thickness = HFNoseDetId(id).type();
0231   } else if (det == DetId::Forward && id.subdetId() == ForwardSubdetector::HGCTrigger) {
0232     thickness = HGCalTriggerModuleDetId(id).type();
0233   } else if (id.det() == DetId::HGCalTrigger &&
0234              (HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalEETrigger ||
0235               HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalHSiTrigger)) {
0236     thickness = HGCalTriggerDetId(id).type();
0237   } else if (id.det() == DetId::HGCalTrigger &&
0238              HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
0239     thickness = HFNoseTriggerDetId(id).type();
0240   }
0241   return thickness;
0242 }
0243 
0244 float HGCalTriggerTools::getEta(const GlobalPoint& position, const float& vertex_z) const {
0245   GlobalPoint corrected_position = GlobalPoint(position.x(), position.y(), position.z() - vertex_z);
0246   return corrected_position.eta();
0247 }
0248 
0249 float HGCalTriggerTools::getTCEta(const DetId& id, const float& vertex_z) const {
0250   GlobalPoint position = getTCPosition(id);
0251   return getEta(position, vertex_z);
0252 }
0253 
0254 float HGCalTriggerTools::getPhi(const GlobalPoint& position) const {
0255   float phi = atan2(position.y(), position.x());
0256   return phi;
0257 }
0258 
0259 float HGCalTriggerTools::getTCPhi(const DetId& id) const {
0260   GlobalPoint position = getTCPosition(id);
0261   return getPhi(position);
0262 }
0263 
0264 float HGCalTriggerTools::getPt(const GlobalPoint& position, const float& hitEnergy, const float& vertex_z) const {
0265   float eta = getEta(position, vertex_z);
0266   float pt = hitEnergy / cosh(eta);
0267   return pt;
0268 }
0269 
0270 float HGCalTriggerTools::getTCPt(const DetId& id, const float& hitEnergy, const float& vertex_z) const {
0271   GlobalPoint position = getTCPosition(id);
0272   return getPt(position, hitEnergy, vertex_z);
0273 }
0274 
0275 float HGCalTriggerTools::getLayerZ(const unsigned& layerWithOffset) const {
0276   int subdet = ForwardSubdetector::HGCEE;
0277   unsigned offset = 0;
0278   if (layerWithOffset > lastLayerEE() && layerWithOffset <= lastLayerFH()) {
0279     subdet = ForwardSubdetector::HGCHEF;
0280     offset = lastLayerEE();
0281   } else if (layerWithOffset > lastLayerFH()) {
0282     subdet = HcalSubdetector::HcalEndcap;
0283     offset = lastLayerFH();
0284   }
0285   // note for HFnose offset is always zero since we have less layers than HGCEE
0286   return getLayerZ(subdet, layerWithOffset - offset);
0287 }
0288 
0289 float HGCalTriggerTools::getLayerZ(const int& subdet, const unsigned& layer) const {
0290   float layerGlobalZ = 0.;
0291   if ((subdet == ForwardSubdetector::HGCEE) || (subdet == DetId::HGCalEE)) {
0292     layerGlobalZ = geom_->eeTopology().dddConstants().waferZ(layer, true);
0293   } else if ((subdet == ForwardSubdetector::HGCHEF) || (subdet == DetId::HGCalHSi)) {
0294     layerGlobalZ = geom_->fhTopology().dddConstants().waferZ(layer, true);
0295   } else if (subdet == ForwardSubdetector::HFNose) {
0296     layerGlobalZ = geom_->noseTopology().dddConstants().waferZ(layer, true);
0297   } else if ((subdet == ForwardSubdetector::HGCHEB) || (subdet == DetId::HGCalHSc)) {
0298     layerGlobalZ = geom_->hscTopology().dddConstants().waferZ(layer, true);
0299   }
0300   return layerGlobalZ;
0301 }
0302 
0303 DetId HGCalTriggerTools::simToReco(const DetId& simid, const HGCalTopology& topo) const {
0304   DetId recoid(0);
0305   const auto& dddConst = topo.dddConstants();
0306   if (dddConst.waferHexagon8() || dddConst.tileTrapezoid()) {
0307     recoid = simid;
0308   }
0309   return recoid;
0310 }