CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTriggerOffline/Muon/interface/L1MuonMatcherAlgo.h

Go to the documentation of this file.
00001 #ifndef MuonAnalysis_MuonAssociators_interface_L1MuonMatcherAlgo_h
00002 #define MuonAnalysis_MuonAssociators_interface_L1MuonMatcherAlgo_h
00003 //
00004 // $Id: L1MuonMatcherAlgo.h,v 1.1 2010/04/15 18:37:17 klukas Exp $
00005 //
00006 
00016 #include <cmath>
00017 #include "DataFormats/Math/interface/deltaR.h"
00018 #include "DataFormats/Math/interface/deltaPhi.h"
00019 #include "DataFormats/Candidate/interface/Candidate.h"
00020 #include "DataFormats/TrackReco/interface/Track.h"
00021 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00022 #include "FWCore/Framework/interface/EventSetup.h"
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00025 #include "CommonTools/Utils/interface/AnySelector.h"
00026 #include "HLTriggerOffline/Muon/interface/PropagateToMuon.h"
00027 
00028 class L1MuonMatcherAlgo {
00029     public:
00030         explicit L1MuonMatcherAlgo(const edm::ParameterSet & iConfig) ;
00031         ~L1MuonMatcherAlgo() ;
00032 
00034         void init(const edm::EventSetup &iSetup) ;
00035 
00037         TrajectoryStateOnSurface extrapolate(const reco::Track &tk)     const { return prop_.extrapolate(tk); }
00038 
00040         TrajectoryStateOnSurface extrapolate(const reco::Candidate &tk) const { return prop_.extrapolate(tk); }
00041 
00043         TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &state) const { return prop_.extrapolate(state); }
00044 
00046         PropagateToMuon & propagatorToMuon() { return prop_; }
00048         const PropagateToMuon & propagatorToMuon() const { return prop_; }
00049 
00052         bool match(const reco::Track &tk, const l1extra::L1MuonParticle &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const {
00053             propagated = extrapolate(tk);
00054             return propagated.isValid() ? match(propagated, l1, deltaR, deltaPhi) : false;
00055         }
00056 
00059         bool match(const reco::Candidate &c, const l1extra::L1MuonParticle &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const {
00060             propagated = extrapolate(c);
00061             return propagated.isValid() ? match(propagated, l1, deltaR, deltaPhi) : false;
00062         }
00063 
00066         bool match(TrajectoryStateOnSurface & propagated, const l1extra::L1MuonParticle &l1, float &deltaR, float &deltaPhi) const ;
00067 
00071         int match(const reco::Track &tk, const std::vector<l1extra::L1MuonParticle> &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const {
00072             propagated = extrapolate(tk);
00073             return propagated.isValid() ? match(propagated, l1, deltaR, deltaPhi) : -1;
00074         }
00075 
00079         int match(const reco::Candidate &c, const std::vector<l1extra::L1MuonParticle> &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const {
00080             propagated = extrapolate(c);
00081             return propagated.isValid() ? match(propagated, l1, deltaR, deltaPhi) : -1;
00082         }
00083 
00087         int match(TrajectoryStateOnSurface &propagated, const std::vector<l1extra::L1MuonParticle> &l1, float &deltaR, float &deltaPhi) const ;
00088 
00089 
00094         template<typename Collection, typename Selector>
00095         int matchGeneric(const reco::Track &tk, const Collection &l1, const Selector &sel, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const {
00096             propagated = extrapolate(tk);
00097             return propagated.isValid() ? matchGeneric(propagated, l1, sel, deltaR, deltaPhi) : -1;
00098         }
00099 
00104         template<typename Collection, typename Selector>
00105         int matchGeneric(const reco::Candidate &c, const Collection &l1, const Selector &sel, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const {
00106             propagated = extrapolate(c);
00107             return propagated.isValid() ? matchGeneric(propagated, l1, sel, deltaR, deltaPhi) : -1;
00108         }
00109 
00114         template<typename Collection, typename Selector>
00115         int matchGeneric(TrajectoryStateOnSurface &propagated, const Collection &l1, const Selector &sel, float &deltaR, float &deltaPhi) const ;
00116 
00117 
00118     private:
00119         PropagateToMuon prop_;
00120 
00121         typedef StringCutObjectSelector<l1extra::L1MuonParticle> L1Selector;
00123         L1Selector preselectionCut_;
00124 
00126         double deltaR2_, deltaPhi_;
00127 
00129         bool sortByDeltaPhi_;
00130 };
00131 
00132 template<typename Collection, typename Selector>
00133 int 
00134 L1MuonMatcherAlgo::matchGeneric(TrajectoryStateOnSurface &propagated, const Collection &l1s, const Selector &sel, float &deltaR, float &deltaPhi) const {
00135     typedef typename Collection::value_type obj;
00136     int match = -1;
00137     double minDeltaPhi = deltaPhi_;
00138     double minDeltaR2  = deltaR2_;
00139     GlobalPoint pos = propagated.globalPosition();
00140     for (int i = 0, n = l1s.size(); i < n; ++i) {
00141         const obj &l1 = l1s[i];
00142         if (sel(l1)) {
00143             double thisDeltaPhi = ::deltaPhi(double(pos.phi()),  l1.phi());
00144             double thisDeltaR2  = ::deltaR2(double(pos.eta()), double(pos.phi()), l1.eta(), l1.phi());
00145             if ((fabs(thisDeltaPhi) < deltaPhi_) && (thisDeltaR2 < deltaR2_)) { // check both
00146                 if (sortByDeltaPhi_ ? (fabs(thisDeltaPhi) < fabs(minDeltaPhi)) : (thisDeltaR2 < minDeltaR2)) { // sort on one
00147                     match = i;
00148                     deltaR   = std::sqrt(thisDeltaR2);
00149                     deltaPhi = thisDeltaPhi;
00150                     if (sortByDeltaPhi_) minDeltaPhi = thisDeltaPhi; else minDeltaR2 = thisDeltaR2;
00151                 }
00152             }
00153         }
00154     }
00155     return match;
00156 }
00157 
00158 #endif