File indexing completed on 2024-04-06 12:27:02
0001 #include "RecoMuon/MuonIdentification/interface/MuonCosmicsId.h"
0002 #include "DataFormats/TrackReco/interface/Track.h"
0003
0004 bool directionAlongMomentum(const reco::Track& track) {
0005
0006 return (track.innerPosition().x() - track.vx()) * track.px() + (track.innerPosition().y() - track.vy()) * track.py() >
0007 0;
0008 }
0009
0010
0011 std::pair<double, double> muonid::matchTracks(const reco::Track& ref, const reco::Track& probe) {
0012 std::pair<double, double> result(0, 0);
0013
0014
0015
0016 int match_sign = directionAlongMomentum(ref) == directionAlongMomentum(probe) ? -1 : +1;
0017 double sprod = ref.px() * probe.px() + ref.py() * probe.py() + ref.pz() * probe.pz();
0018 double argCos = match_sign * (sprod / ref.p() / probe.p());
0019 if (argCos < -1.0)
0020 argCos = -1.0;
0021 if (argCos > 1.0)
0022 argCos = 1.0;
0023 result.first = acos(argCos);
0024 result.second = fabs(probe.pt() - ref.pt()) / sqrt(ref.pt() * probe.pt());
0025 return result;
0026 }
0027
0028 reco::TrackRef muonid::findOppositeTrack(const edm::Handle<reco::TrackCollection>& tracks,
0029 const reco::Track& muonTrack,
0030 double angleMatch,
0031 double momentumMatch) {
0032 for (unsigned int i = 0; i < tracks->size(); ++i) {
0033
0034
0035
0036 const std::pair<double, double>& match = matchTracks(muonTrack, tracks->at(i));
0037 if (match.first < angleMatch && match.second < momentumMatch)
0038 return reco::TrackRef(tracks, i);
0039 }
0040 return reco::TrackRef();
0041 }