Back to home page

Project CMSSW displayed by LXR

 
 

    


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   // check is done in 2D
0006   return (track.innerPosition().x() - track.vx()) * track.px() + (track.innerPosition().y() - track.vy()) * track.py() >
0007          0;
0008 }
0009 
0010 // returns angle and dPt/Pt
0011 std::pair<double, double> muonid::matchTracks(const reco::Track& ref, const reco::Track& probe) {
0012   std::pair<double, double> result(0, 0);
0013   // When both tracks are reconstructed as outside going, sign is -1
0014   // otherwise it's +1. There is also a crazy case of both are outside
0015   // going, then sign is -1 as well.
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());  //SK: take a geom-mean 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     // When both tracks are reconstructed as outside going, sign is -1
0034     // otherwise it's +1. There is also a crazy case of both are outside
0035     // going, then sign is -1 as well.
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 }