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
00006 return (track.innerPosition().x()-track.vx())*track.px() +
00007 (track.innerPosition().y()-track.vy())*track.py() > 0;
00008 }
00009
00010
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
00016
00017
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());
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
00036
00037
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 }