@@ -166,6 +166,7 @@ MuonIdProducer::MuonIdProducer(const edm::ParameterSet& iConfig)
166166 // create mesh holder
167167 meshAlgo_ = std::make_unique<MuonMesh>(iConfig.getParameter <edm::ParameterSet>(" arbitrationCleanerOptions" ));
168168
169+ gemgeomToken_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
169170 edm::InputTag rpcHitTag (" rpcRecHits" );
170171 rpcHitToken_ = consumes<RPCRecHitCollection>(rpcHitTag);
171172
@@ -274,6 +275,7 @@ void MuonIdProducer::init(edm::Event& iEvent, const edm::EventSetup& iSetup) {
274275 iEvent.getByToken (glbQualToken_, glbQualHandle_);
275276 if (selectHighPurity_)
276277 iEvent.getByToken (pvToken_, pvHandle_);
278+ gemgeom = &iSetup.getData (gemgeomToken_);
277279}
278280
279281reco::Muon MuonIdProducer::makeMuon (edm::Event& iEvent,
@@ -296,6 +298,24 @@ reco::Muon MuonIdProducer::makeMuon(edm::Event& iEvent,
296298 return aMuon;
297299}
298300
301+ bool MuonIdProducer::checkBounds (const GeomDet* geomDet,
302+ const GlobalPoint& global_position,
303+ const float bordercut) {
304+ const TrapezoidalPlaneBounds* bounds = dynamic_cast <const TrapezoidalPlaneBounds*>(&geomDet->surface ().bounds ());
305+ LocalPoint localPoint = geomDet->surface ().toLocal (global_position);
306+ float wideWidth = bounds->width ();
307+ float narrowWidth = 2 .f * bounds->widthAtHalfLength () - wideWidth;
308+ float length = bounds->length ();
309+ float tangent = (wideWidth - narrowWidth) / (2 .f * length);
310+ float halfWidthAtY = tangent * localPoint.y () + 0 .25f * (narrowWidth + wideWidth);
311+ float distanceY = std::abs (localPoint.y ()) - 0 .5f * length;
312+ float distanceX = std::abs (localPoint.x ()) - halfWidthAtY;
313+ if (distanceX < bordercut && distanceY < bordercut) {
314+ return true ;
315+ }
316+ return false ;
317+ }
318+
299319reco::CaloMuon MuonIdProducer::makeCaloMuon (const reco::Muon& muon) {
300320 LogTrace (" MuonIdentification" ) << " Creating a CaloMuon from a Muon" ;
301321
@@ -1121,9 +1141,23 @@ void MuonIdProducer::fillMuonId(edm::Event& iEvent,
11211141 gemHitMatch.x = gemRecHit.localPosition ().x ();
11221142 gemHitMatch.mask = 0 ;
11231143 gemHitMatch.bx = gemRecHit.BunchX ();
1124-
1144+
1145+ const GeomDet* geomDet = gemgeom->idToDetUnit (chamber.id );
1146+ const GlobalPoint& global_position = geomDet->toGlobal (lPos);
1147+ bool GEMmatched = false ;
1148+ int ieta = 0 ;
1149+ if (const GEMChamber* gemChamber = dynamic_cast <const GEMChamber*>(geomDet)) {
1150+ for (const GEMEtaPartition* eta_partition : gemChamber->etaPartitions ()) {
1151+ ieta = eta_partition->id ().ieta ();
1152+ if (ieta == gemRecHit.gemId ().ieta ()) {
1153+ if (checkBounds (eta_partition, global_position, 2 )) {
1154+ GEMmatched = true ;
1155+ }
1156+ }
1157+ }
1158+ }
11251159 const double absDx = std::abs (gemRecHit.localPosition ().x () - chamber.tState .localPosition ().x ());
1126- if (absDx <= 5 or absDx * absDx <= 16 * localError.xx ())
1160+ if (( absDx <= 5 or absDx * absDx <= 16 * localError.xx ()) && GEMmatched )
11271161 matchedChamber.gemHitMatches .push_back (gemHitMatch);
11281162 }
11291163
0 commit comments