Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:05:41

0001 // -*- C++ -*-
0002 //
0003 // Package:    TrackAssociator
0004 // Class:      MuonDetIdAssociator
0005 //
0006 /*
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Dmytro Kovalskyi
0015 //         Created:  Fri Apr 21 10:59:41 PDT 2006
0016 //
0017 //
0018 
0019 #include "MuonDetIdAssociator.h"
0020 // #include "Utilities/Timing/interface/TimerStack.h"
0021 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
0022 #include "DataFormats/GeometrySurface/interface/Plane.h"
0023 #include "Geometry/DTGeometry/interface/DTChamber.h"
0024 #include "Geometry/CSCGeometry/interface/CSCChamber.h"
0025 #include "Geometry/RPCGeometry/interface/RPCChamber.h"
0026 #include <deque>
0027 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0028 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0029 #include "Geometry/GEMGeometry/interface/ME0Geometry.h"
0030 
0031 void MuonDetIdAssociator::check_setup() const {
0032   if (geometry_ == nullptr)
0033     throw cms::Exception("ConfigurationProblem") << "GlobalTrackingGeomtry is not set\n";
0034   if (cscbadchambers_ == nullptr)
0035     throw cms::Exception("ConfigurationProblem") << "CSCBadChambers is not set\n";
0036   DetIdAssociator::check_setup();
0037 }
0038 
0039 const GeomDet* MuonDetIdAssociator::getGeomDet(const DetId& id) const {
0040   if (geometry_ == nullptr)
0041     throw cms::Exception("ConfigurationProblem") << "GlobalTrackingGeomtry is not set\n";
0042   const GeomDet* gd = geometry_->idToDet(id);
0043   if (gd == nullptr)
0044     throw cms::Exception("NoGeometry") << "Cannot find GeomDet for DetID: " << id.rawId() << "\n";
0045   return gd;
0046 }
0047 
0048 GlobalPoint MuonDetIdAssociator::getPosition(const DetId& id) const {
0049   Surface::PositionType point(getGeomDet(id)->surface().position());
0050   return GlobalPoint(point.x(), point.y(), point.z());
0051 }
0052 
0053 void MuonDetIdAssociator::getValidDetIds(unsigned int subDectorIndex, std::vector<DetId>& validIds) const {
0054   validIds.clear();
0055   if (geometry_ == nullptr)
0056     throw cms::Exception("ConfigurationProblem") << "GlobalTrackingGeomtry is not set\n";
0057   if (subDectorIndex != 0)
0058     throw cms::Exception("FatalError")
0059         << "Muon sub-dectors are all handle as one sub-system, but subDetectorIndex is not zero.\n";
0060 
0061   // CSC
0062   if (!geometry_->slaveGeometry(CSCDetId()))
0063     throw cms::Exception("FatalError") << "Cannnot CSCGeometry\n";
0064   auto const& geomDetsCSC = geometry_->slaveGeometry(CSCDetId())->dets();
0065   for (auto it = geomDetsCSC.begin(); it != geomDetsCSC.end(); ++it)
0066     if (auto csc = dynamic_cast<const CSCChamber*>(*it)) {
0067       if ((!includeBadChambers_) && (cscbadchambers_->isInBadChamber(CSCDetId(csc->id()))))
0068         continue;
0069       validIds.push_back(csc->id());
0070     }
0071 
0072   // DT
0073   if (!geometry_->slaveGeometry(DTChamberId()))
0074     throw cms::Exception("FatalError") << "Cannnot DTGeometry\n";
0075   auto const& geomDetsDT = geometry_->slaveGeometry(DTChamberId())->dets();
0076   for (auto it = geomDetsDT.begin(); it != geomDetsDT.end(); ++it)
0077     if (auto dt = dynamic_cast<const DTChamber*>(*it))
0078       validIds.push_back(dt->id());
0079 
0080   // RPC
0081   if (!geometry_->slaveGeometry(RPCDetId()))
0082     throw cms::Exception("FatalError") << "Cannnot RPCGeometry\n";
0083   auto const& geomDetsRPC = geometry_->slaveGeometry(RPCDetId())->dets();
0084   for (auto it = geomDetsRPC.begin(); it != geomDetsRPC.end(); ++it)
0085     if (auto rpc = dynamic_cast<const RPCChamber*>(*it)) {
0086       std::vector<const RPCRoll*> rolls = (rpc->rolls());
0087       for (std::vector<const RPCRoll*>::iterator r = rolls.begin(); r != rolls.end(); ++r)
0088         validIds.push_back((*r)->id().rawId());
0089     }
0090 
0091   // GEM
0092   if (includeGEM_) {
0093     if (!geometry_->slaveGeometry(GEMDetId()))
0094       throw cms::Exception("FatalError") << "Cannnot GEMGeometry\n";
0095     auto const& geomDetsGEM = geometry_->slaveGeometry(GEMDetId())->dets();
0096     for (auto it = geomDetsGEM.begin(); it != geomDetsGEM.end(); ++it) {
0097       if (auto gem = dynamic_cast<const GEMSuperChamber*>(*it)) {
0098         if (gem->id().station() == 0)
0099           validIds.push_back(gem->id());
0100         else
0101           for (auto ch : gem->chambers())
0102             validIds.push_back(ch->id());
0103       }
0104     }
0105   }
0106   // ME0
0107   if (includeME0_) {
0108     if (!geometry_->slaveGeometry(ME0DetId()))
0109       throw cms::Exception("FatalError") << "Cannnot ME0Geometry\n";
0110     auto const& geomDetsME0 = geometry_->slaveGeometry(ME0DetId())->dets();
0111     for (auto it = geomDetsME0.begin(); it != geomDetsME0.end(); ++it) {
0112       if (auto me0 = dynamic_cast<const ME0Chamber*>(*it)) {
0113         validIds.push_back(me0->id());
0114       }
0115     }
0116   }
0117 }
0118 
0119 bool MuonDetIdAssociator::insideElement(const GlobalPoint& point, const DetId& id) const {
0120   if (geometry_ == nullptr)
0121     throw cms::Exception("ConfigurationProblem") << "GlobalTrackingGeomtry is not set\n";
0122   LocalPoint lp = geometry_->idToDet(id)->toLocal(point);
0123   return geometry_->idToDet(id)->surface().bounds().inside(lp);
0124 }
0125 
0126 std::pair<DetIdAssociator::const_iterator, DetIdAssociator::const_iterator> MuonDetIdAssociator::getDetIdPoints(
0127     const DetId& id, std::vector<GlobalPoint>& points) const {
0128   points.clear();
0129   points.reserve(8);
0130   const GeomDet* geomDet = getGeomDet(id);
0131 
0132   // the coners of muon detector elements are not stored and can be only calculated
0133   // based on methods defined in the interface class Bounds:
0134   //   width() - x
0135   //   length() - y
0136   //   thinkness() - z
0137   // NOTE: this convention is implementation specific and can fail. Both
0138   //       RectangularPlaneBounds and TrapezoidalPlaneBounds use it.
0139   // Even though the CSC geomtry is more complicated (trapezoid),  it's enough
0140   // to estimate which bins should contain this element. For the distance
0141   // calculation from the edge, we will use exact geometry to get it right.
0142 
0143   const Bounds* bounds = &(geometry_->idToDet(id)->surface().bounds());
0144   points.push_back(
0145       geomDet->toGlobal(LocalPoint(+bounds->width() / 2, +bounds->length() / 2, +bounds->thickness() / 2)));
0146   points.push_back(
0147       geomDet->toGlobal(LocalPoint(-bounds->width() / 2, +bounds->length() / 2, +bounds->thickness() / 2)));
0148   points.push_back(
0149       geomDet->toGlobal(LocalPoint(+bounds->width() / 2, -bounds->length() / 2, +bounds->thickness() / 2)));
0150   points.push_back(
0151       geomDet->toGlobal(LocalPoint(-bounds->width() / 2, -bounds->length() / 2, +bounds->thickness() / 2)));
0152   points.push_back(
0153       geomDet->toGlobal(LocalPoint(+bounds->width() / 2, +bounds->length() / 2, -bounds->thickness() / 2)));
0154   points.push_back(
0155       geomDet->toGlobal(LocalPoint(-bounds->width() / 2, +bounds->length() / 2, -bounds->thickness() / 2)));
0156   points.push_back(
0157       geomDet->toGlobal(LocalPoint(+bounds->width() / 2, -bounds->length() / 2, -bounds->thickness() / 2)));
0158   points.push_back(
0159       geomDet->toGlobal(LocalPoint(-bounds->width() / 2, -bounds->length() / 2, -bounds->thickness() / 2)));
0160 
0161   return std::pair<const_iterator, const_iterator>(points.begin(), points.end());
0162 }