47 dtRadius_(matchParameters.getParameter<double>(
"DTradius")),
72 vector<const DTRecSegment4D*> pointerTo4DSegments;
74 std::vector<TrackingRecHit const *> dtHits;
76 bool segments =
false;
80 if (!(*hit)->isValid())
continue;
81 if ( (*hit)->geographicalId().det() !=
DetId::Muon )
continue;
83 if (!(*hit)->recHits().empty())
84 if ((*(*hit)->recHits().begin())->recHits().size()>1) segments =
true;
85 dtHits.push_back(*
hit);
93 double matchRatioPhi=0;
97 LocalPoint pointLocal = rechit->localPosition();
101 for(
auto hit = dtHits.begin();
hit != dtHits.end(); ++
hit) {
104 DetId idT = (*hit)->geographicalId();
105 if(!(rechit->geographicalId().rawId()==idT.
rawId()))
continue;
108 LocalPoint segLocal = (*hit)->localPosition();
109 if ((fabs(pointLocal.
x()-segLocal.
x())<ZCutParameter) &&
110 (fabs(pointLocal.
y()-segLocal.
y())<ZCutParameter))
111 pointerTo4DSegments.push_back(&(*rechit));
119 if(rechit->hasZed()) {
120 double countMuonDTHits = 0;
121 double countAgreeingHits=0;
125 nhitsZ = segmZ->
recHits().size();
131 for(
auto hit = dtHits.begin();
hit != dtHits.end(); ++
hit) {
133 if ( !(*hit)->isValid())
continue;
135 DetId idT = (*hit)->geographicalId();
139 LocalPoint pointLocal = (*hit)->localPosition();
141 if ((chamberSegIdT==dtDetIdHitT) && (dtDetLayerIdHitT.superlayer()==2)) countMuonDTHits++;
143 for (vector<DTRecHit1D>::const_iterator hiti=hits1d.begin(); hiti!=hits1d.end(); hiti++) {
145 if ( !hiti->isValid())
continue;
148 if(!(hiti->geographicalId().rawId()==idT.
rawId()))
continue;
154 if ((fabs(pointLocal.x()-segLocal.
x())<ZCutParameter) &&
155 (fabs(pointLocal.y()-segLocal.
y())<ZCutParameter))
160 matchRatioZ = countMuonDTHits == 0 ? 0 : countAgreeingHits/countMuonDTHits;
162 if (countAgreeingHits/nhitsZ>matchRatioZ) matchRatioZ=countAgreeingHits/nhitsZ;
165 if(rechit->hasPhi()) {
166 double countMuonDTHits = 0;
167 double countAgreeingHits=0;
171 segmPhi =
dynamic_cast<const DTRecSegment2D*
>(rechit->phiSegment());
172 nhitsPhi = segmPhi->
recHits().size();
178 for(
auto hit = dtHits.begin();
hit != dtHits.end(); ++
hit) {
180 if ( !(*hit)->isValid())
continue;
182 DetId idT = (*hit)->geographicalId();
186 LocalPoint pointLocal = (*hit)->localPosition();
188 if ((chamberSegIdT==dtDetIdHitT)&&((dtDetLayerIdHitT.superlayer()==1)||(dtDetLayerIdHitT.superlayer()==3)))
191 for (vector<DTRecHit1D>::const_iterator hiti=hits1d.begin(); hiti!=hits1d.end(); hiti++) {
193 if ( !hiti->isValid())
continue;
196 if(!(hiti->geographicalId().rawId()==idT.
rawId()))
continue;
203 if ((fabs(pointLocal.x()-segLocal.
x())<PhiCutParameter) &&
204 (fabs(pointLocal.y()-segLocal.
y())<PhiCutParameter))
209 matchRatioPhi = countMuonDTHits != 0 ? countAgreeingHits/countMuonDTHits : 0;
211 if (countAgreeingHits/nhitsPhi>matchRatioPhi) matchRatioPhi=countAgreeingHits/nhitsPhi;
215 if((matchRatioPhi>0.9)&&(matchRatioZ>0.9)) {
217 pointerTo4DSegments.push_back(&(*rechit));
220 if((matchRatioPhi>0.9 && nhitsPhi)||(matchRatioZ>0.9 && nhitsZ)) {
222 pointerTo4DSegments.push_back(&(*rechit));
228 return pointerTo4DSegments;
241 vector<const CSCSegment*> pointerToCSCSegments;
243 double matchRatioCSC=0;
245 double CSCXCut = 0.001;
246 double CSCYCut = 0.001;
247 double countMuonCSCHits = 0;
250 double CSCcountAgreeingHits=0;
252 if ( !segmentCSC->isValid())
continue;
255 const vector<CSCRecHit2D>& CSCRechits2D = segmentCSC->specificRecHits();
256 countMuonCSCHits = 0;
257 CSCDetId myChamber((*segmentCSC).geographicalId().rawId());
259 bool segments =
false;
262 if (!(*hitC)->isValid())
continue;
263 if ( (*hitC)->geographicalId().det() !=
DetId::Muon )
continue;
265 if (!(*hitC)->isValid())
continue;
266 if ( (*hitC)->recHits().size()>1) segments =
true;
269 DetId id = (*hitC)->geographicalId();
273 if(!(myChamber.rawId()==cscDetIdHit.
rawId()))
continue;
276 LocalPoint positionLocalCSC = (*hitC)->localPosition();
277 LocalPoint segLocalCSC = segmentCSC->localPosition();
278 if ((fabs(positionLocalCSC.
x()-segLocalCSC.
x())<CSCXCut) &&
279 (fabs(positionLocalCSC.
y()-segLocalCSC.
y())<CSCYCut))
280 pointerToCSCSegments.push_back(&(*segmentCSC));
284 if(!(cscDetIdHit.
ring()==myChamber.ring()))
continue;
285 if(!(cscDetIdHit.
station()==myChamber.station()))
continue;
286 if(!(cscDetIdHit.
endcap()==myChamber.endcap()))
continue;
287 if(!(cscDetIdHit.
chamber()==myChamber.chamber()))
continue;
291 LocalPoint positionLocalCSC = (*hitC)->localPosition();
293 for (vector<CSCRecHit2D>::const_iterator hiti=CSCRechits2D.begin(); hiti!=CSCRechits2D.end(); hiti++) {
295 if ( !hiti->isValid())
continue;
296 CSCDetId cscDetId((hiti->geographicalId()).rawId());
298 if ((*hitC)->geographicalId().rawId()!=(hiti->geographicalId()).rawId())
continue;
300 LocalPoint segLocalCSC = hiti->localPosition();
303 if((fabs(positionLocalCSC.
x()-segLocalCSC.
x())<CSCXCut) &&
304 (fabs(positionLocalCSC.
y()-segLocalCSC.
y())<CSCYCut)) {
305 CSCcountAgreeingHits++;
311 matchRatioCSC = countMuonCSCHits == 0 ? 0 : CSCcountAgreeingHits/countMuonCSCHits;
313 if ((matchRatioCSC>0.9) && ((countMuonCSCHits>1) || !
cscTightMatch)) pointerToCSCSegments.push_back(&(*segmentCSC));
317 return pointerToCSCSegments;
330 vector<const RPCRecHit*> pointerToRPCRecHits;
331 double RPCCut = 0.001;
335 if ( !hitRPC->isValid())
continue;
337 RPCDetId myChamber((*hitRPC).geographicalId().rawId());
338 LocalPoint posLocalRPC = hitRPC->localPosition();
342 if (!(*hitC)->isValid())
continue;
343 if ( (*hitC)->geographicalId().det() !=
DetId::Muon )
continue;
345 if (!(*hitC)->isValid())
continue;
348 DetId id = (*hitC)->geographicalId();
351 if (rpcDetIdHit!=myChamber)
continue;
352 LocalPoint posLocalMuon = (*hitC)->localPosition();
356 if((fabs(posLocalMuon.
x()-posLocalRPC.x())<RPCCut)) {
363 if (matched) pointerToRPCRecHits.push_back(&(*hitRPC));
366 return pointerToRPCRecHits;
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
edm::EDGetTokenT< RPCRecHitCollection > rpcRecHitsToken
MuonSegmentMatcher(const edm::ParameterSet &, edm::ConsumesCollector &iC)
constructor with Parameter Set and MuonServiceProxy
std::vector< const CSCSegment * > matchCSC(const reco::Track &muon, const edm::Event &event)
edm::InputTag RPCHitTags_
uint32_t rawId() const
get the raw id
edm::EDGetTokenT< CSCSegmentCollection > allSegmentsCSCToken
edm::InputTag DTSegmentTags_
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
edm::InputTag CSCSegmentTags_
std::vector< const RPCRecHit * > matchRPC(const reco::Track &muon, const edm::Event &event)
virtual ~MuonSegmentMatcher()
destructor
edm::EDGetTokenT< DTRecSegment4DCollection > dtRecHitsToken
std::vector< const DTRecSegment4D * > matchDT(const reco::Track &muon, const edm::Event &event)
perform the matching
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
DetId geographicalId() const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.