CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoMuon/MuonIdentification/src/MuonCosmicsId.cc

Go to the documentation of this file.
00001 #include "RecoMuon/MuonIdentification/interface/MuonCosmicsId.h"
00002 #include "DataFormats/TrackReco/interface/Track.h"
00003 
00004 bool directionAlongMomentum(const reco::Track& track){
00005   // check is done in 2D
00006   return (track.innerPosition().x()-track.vx())*track.px() +
00007     (track.innerPosition().y()-track.vy())*track.py() > 0;
00008 }
00009 
00010 // returns angle and dPt/Pt
00011 std::pair<double, double> 
00012 muonid::matchTracks(const reco::Track& ref, const reco::Track& probe)
00013 {
00014   std::pair<double,double> result(0,0);
00015   // When both tracks are reconstructed as outside going, sign is -1
00016   // otherwise it's +1. There is also a crazy case of both are outside
00017   // going, then sign is -1 as well.
00018   int match_sign = directionAlongMomentum(ref)==directionAlongMomentum(probe) ? -1 : +1; 
00019   double sprod = ref.px()*probe.px() + ref.py()*probe.py() + ref.pz()*probe.pz();
00020   double argCos = match_sign*(sprod/ref.p()/probe.p());
00021   if (argCos < -1.0) argCos = -1.0;
00022   if (argCos > 1.0) argCos = 1.0;
00023   result.first = acos( argCos );
00024   result.second = fabs(probe.pt()-ref.pt())/sqrt(ref.pt()*probe.pt()); //SK: take a geom-mean pt
00025   return result;
00026 }
00027 
00028 reco::TrackRef 
00029 muonid::findOppositeTrack(const edm::Handle<reco::TrackCollection>& tracks, 
00030                         const reco::Track& muonTrack,
00031                         double angleMatch,
00032                         double momentumMatch)
00033 {
00034   for (unsigned int i=0; i<tracks->size(); ++i){
00035     // When both tracks are reconstructed as outside going, sign is -1
00036     // otherwise it's +1. There is also a crazy case of both are outside
00037     // going, then sign is -1 as well.
00038     const std::pair<double,double>& match = matchTracks(muonTrack,tracks->at(i));
00039     if ( match.first < angleMatch && match.second < momentumMatch )
00040       return reco::TrackRef(tracks,i);
00041   }
00042   return reco::TrackRef();
00043 
00044 }