#include <MatcherUsingTracksAlgorithm.h>
Public Member Functions | |
bool | hasChi2 () const |
Return 'true' if the matcher will produce also chi2. | |
bool | hasMetrics () const |
Return 'true' if the matcher will produce meaningful deltaR, deltaLocalPos, deltaPtRel values. | |
void | init (const edm::EventSetup &iSetup) |
Call this method at the beginning of each run, to initialize geometry, magnetic field and propagators. | |
int | match (const reco::Candidate &tk, const edm::View< reco::Candidate > &c2s, float &deltaR, float &deltaEta, float &deltaPhi, float &deltaLocalPos, float &deltaPtRel, float &chi2) const |
bool | match (const reco::Candidate &c1, const reco::Candidate &c2, float &deltaR, float &deltaEta, float &deltaPhi, float &deltaLocalPos, float &deltaPtRel, float &chi2) const |
MatcherUsingTracksAlgorithm (const edm::ParameterSet &iConfig) | |
virtual | ~MatcherUsingTracksAlgorithm () |
Static Public Member Functions | |
static void | cropAndInvert (AlgebraicSymMatrix55 &cov, bool diagonalOnly, bool top3by3only) |
Possibly crop the 3x3 part of the matrix or remove off-diagonal terms, then invert. | |
static double | getChi2 (const FreeTrajectoryState &start, const TrajectoryStateClosestToPoint &other, bool diagonalOnly, bool useVertex) |
static double | getChi2 (const TrajectoryStateOnSurface &start, const TrajectoryStateOnSurface &other, bool diagonalOnly, bool usePosition) |
static double | getChi2 (const FreeTrajectoryState &start, const FreeTrajectoryState &other, bool diagonalOnly, bool useVertex, bool useFirstMomentum) |
Private Types | |
enum | AlgoType { ByTrackRef, ByDirectComparison, ByPropagatingSrc, ByPropagatingMatched, ByPropagatingSrcTSCP, ByPropagatingMatchedTSCP } |
enum | SortBy { LocalPosDiff, GlobalMomDeltaR, GlobalMomDeltaEta, GlobalMomDeltaPhi, GlobalDPtRel, Chi2 } |
enum | WhichState { AtVertex, Innermost, Outermost } |
enum | WhichTrack { None, TrackerTk, MuonTk, GlobalTk } |
Private Member Functions | |
void | getConf (const edm::ParameterSet &iConfig, const std::string &whatFor, WhichTrack &whichTrack, WhichState &whichState) |
Parse some configuration. | |
reco::TrackRef | getTrack (const reco::Candidate &reco, WhichTrack which) const |
Get track reference out of a Candidate (via dynamic_cast to reco::RecoCandidate) | |
bool | matchByDirectComparison (const FreeTrajectoryState &start, const FreeTrajectoryState &other, float &lastDeltaR, float &lastDeltaEta, float &lastDeltaPhi, float &lastDeltaLocalPos, float &lastGlobalDPtRel, float &lastChi2) const |
Compare directly two states. return true if current pair is the new best match (in that case, update also deltaR and deltaLocalPos) | |
bool | matchWithPropagation (const FreeTrajectoryState &start, const TrajectoryStateOnSurface &target, float &lastDeltaR, float &lastDeltaEta, float &lastDeltaPhi, float &lastDeltaLocalPos, float &lastGlobalDPtRel, float &lastChi2) const |
bool | matchWithPropagation (const FreeTrajectoryState &start, const FreeTrajectoryState &target, float &lastDeltaR, float &lastDeltaEta, float &lastDeltaPhi, float &lastDeltaLocalPos, float &lastGlobalDPtRel, float &lastChi2) const |
FreeTrajectoryState | startingState (const reco::Candidate &reco, WhichTrack whichTrack, WhichState whichState) const |
Starting state for the propagation. | |
TrajectoryStateOnSurface | targetState (const reco::Candidate &reco, WhichTrack whichTrack, WhichState whichState) const |
End state for the propagation. | |
Private Attributes | |
AlgoType | algo_ |
bool | chi2DiagonalOnly_ |
bool | chi2FirstMomentum_ |
bool | chi2UseVertex_ |
edm::ESHandle < GlobalTrackingGeometry > | geometry_ |
edm::ESHandle< MagneticField > | magfield_ |
StringCutObjectSelector < reco::Candidate, true > | matchedCut_ |
float | maxChi2_ |
float | maxGlobalDPtRel_ |
float | maxGlobalMomDeltaEta_ |
float | maxGlobalMomDeltaPhi_ |
float | maxGlobalMomDeltaR_ |
float | maxLocalPosDiff_ |
edm::ESHandle< Propagator > | propagator_ |
bool | requireSameCharge_ |
SortBy | sortBy_ |
StringCutObjectSelector < reco::Candidate, true > | srcCut_ |
bool | useChi2_ |
WhichState | whichState1_ |
WhichState | whichState2_ |
WhichTrack | whichTrack1_ |
WhichTrack | whichTrack2_ |
Definition at line 31 of file MatcherUsingTracksAlgorithm.h.
enum MatcherUsingTracksAlgorithm::AlgoType [private] |
ByTrackRef | |
ByDirectComparison | |
ByPropagatingSrc | |
ByPropagatingMatched | |
ByPropagatingSrcTSCP | |
ByPropagatingMatchedTSCP |
Definition at line 76 of file MatcherUsingTracksAlgorithm.h.
{ ByTrackRef, ByDirectComparison, ByPropagatingSrc, ByPropagatingMatched, ByPropagatingSrcTSCP, ByPropagatingMatchedTSCP }; // propagate closest to point
enum MatcherUsingTracksAlgorithm::SortBy [private] |
Definition at line 98 of file MatcherUsingTracksAlgorithm.h.
enum MatcherUsingTracksAlgorithm::WhichState [private] |
Definition at line 80 of file MatcherUsingTracksAlgorithm.h.
enum MatcherUsingTracksAlgorithm::WhichTrack [private] |
MatcherUsingTracksAlgorithm::MatcherUsingTracksAlgorithm | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 31 of file MatcherUsingTracksAlgorithm.cc.
References algo, algo_, AtVertex, ByDirectComparison, ByPropagatingMatched, ByPropagatingMatchedTSCP, ByPropagatingSrc, ByPropagatingSrcTSCP, ByTrackRef, Chi2, chi2DiagonalOnly_, chi2FirstMomentum_, chi2UseVertex_, Exception, edm::ParameterSet::existsAs(), getConf(), edm::ParameterSet::getParameter(), GlobalDPtRel, GlobalMomDeltaEta, GlobalMomDeltaPhi, GlobalMomDeltaR, LocalPosDiff, maxChi2_, maxGlobalDPtRel_, maxGlobalMomDeltaEta_, maxGlobalMomDeltaPhi_, maxGlobalMomDeltaR_, maxLocalPosDiff_, None, sortBy_, useChi2_, whichState1_, whichState2_, whichTrack1_, and whichTrack2_.
: whichTrack1_(None), whichTrack2_(None), whichState1_(AtVertex), whichState2_(AtVertex), srcCut_(iConfig.existsAs<std::string>("srcPreselection") ? iConfig.getParameter<std::string>("srcPreselection") : ""), matchedCut_(iConfig.existsAs<std::string>("matchedPreselection") ? iConfig.getParameter<std::string>("matchedPreselection") : ""), requireSameCharge_(iConfig.existsAs<bool>("requireSameCharge") ? iConfig.getParameter<bool>("requireSameCharge") : false) { std::string algo = iConfig.getParameter<std::string>("algorithm"); if (algo == "byTrackRef") { algo_ = ByTrackRef; } else if (algo == "byPropagatingSrc") { algo_ = ByPropagatingSrc; } else if (algo == "byPropagatingMatched") { algo_ = ByPropagatingMatched; } else if (algo == "byDirectComparison") { algo_ = ByDirectComparison; } else throw cms::Exception("Configuration") << "Value '" << algo << "' for algorithm not yet implemented.\n"; getConf(iConfig, "src", whichTrack1_, whichState1_); getConf(iConfig, "matched", whichTrack2_, whichState2_); if (algo_ == ByTrackRef) { // validate the config if (whichTrack1_ == None || whichTrack2_ == None) throw cms::Exception("Configuration") << "Algorithm 'byTrackRef' needs tracks not to be 'none'.\n"; } else if (algo_ == ByPropagatingSrc || algo_ == ByPropagatingMatched || algo_ == ByDirectComparison) { // read matching cuts maxLocalPosDiff_ = iConfig.getParameter<double>("maxDeltaLocalPos"); maxGlobalMomDeltaR_ = iConfig.getParameter<double>("maxDeltaR"); maxGlobalMomDeltaEta_ = iConfig.existsAs<double>("maxDeltaEta") ? iConfig.getParameter<double>("maxDeltaEta") : maxGlobalMomDeltaR_; maxGlobalMomDeltaPhi_ = iConfig.existsAs<double>("maxDeltaPhi") ? iConfig.getParameter<double>("maxDeltaPhi") : maxGlobalMomDeltaR_; maxGlobalDPtRel_ = iConfig.getParameter<double>("maxDeltaPtRel"); // choice of sorting variable std::string sortBy = iConfig.getParameter<std::string>("sortBy"); if (sortBy == "deltaLocalPos") sortBy_ = LocalPosDiff; else if (sortBy == "deltaPtRel") sortBy_ = GlobalDPtRel; else if (sortBy == "deltaR") sortBy_ = GlobalMomDeltaR; else if (sortBy == "deltaEta") sortBy_ = GlobalMomDeltaEta; else if (sortBy == "deltaPhi") sortBy_ = GlobalMomDeltaPhi; else if (sortBy == "chi2") sortBy_ = Chi2; else throw cms::Exception("Configuration") << "Parameter 'sortBy' must be one of: deltaLocalPos, deltaPtRel, deltaR, chi2.\n"; // validate the config if (algo_ == ByPropagatingSrc) { if (whichTrack2_ == None || whichState2_ == AtVertex) { algo_ = ByPropagatingSrcTSCP; //throw cms::Exception("Configuration") << "Destination track must be non-null, and state must not be 'AtVertex' (not yet).\n"; } } else if (algo_ == ByPropagatingMatched) { if (whichTrack1_ == None || whichState1_ == AtVertex) { algo_ = ByPropagatingMatchedTSCP; //throw cms::Exception("Configuration") << "Destination track must be non-null, and state must not be 'AtVertex' (not yet).\n"; } } else if (algo_ == ByDirectComparison) { bool firstAtVertex = (whichTrack1_ == None || whichState1_ == AtVertex); bool secAtVertex = (whichTrack2_ == None || whichState2_ == AtVertex); if (firstAtVertex) { if (!secAtVertex) throw cms::Exception("Configuration") << "When using 'byDirectComparison' with 'src' at vertex (or None), 'matched' must be at vertex too.\n"; } else { if (secAtVertex) throw cms::Exception("Configuration") << "When using 'byDirectComparison' with 'src' not at vertex, 'matched' can't be at vertex or None.\n"; if (whichState1_ != whichState2_) throw cms::Exception("Configuration") << "You can't use 'byDirectComparison' with non-matching states.\n"; } } useChi2_ = iConfig.existsAs<bool>("computeChi2") ? iConfig.getParameter<bool>("computeChi2") : false; if (useChi2_) { if (whichTrack1_ == None && whichTrack2_ == None) throw cms::Exception("Configuration") << "Can't compute chi2s if both tracks are set to 'none'.\n"; maxChi2_ = iConfig.getParameter<double>("maxChi2"); chi2DiagonalOnly_ = iConfig.getParameter<bool>("chi2DiagonalOnly"); if (algo_ == ByPropagatingSrc || algo_ == ByPropagatingMatched) { chi2UseVertex_ = iConfig.getParameter<bool>("chi2UsePosition"); } else { chi2UseVertex_ = iConfig.getParameter<bool>("chi2UseVertex"); if (algo_ == ByDirectComparison) { std::string choice = iConfig.getParameter<std::string>("chi2MomentumForDxy"); if (choice == "src") chi2FirstMomentum_ = true; else if (choice != "matched") throw cms::Exception("Configuration") << "chi2MomentumForDxy must be 'src' or 'matched'\n"; } } } else maxChi2_ = 1; if (sortBy_ == Chi2 && !useChi2_) throw cms::Exception("Configuration") << "Can't sort by chi2s if 'computeChi2s' is not set to true.\n"; } }
virtual MatcherUsingTracksAlgorithm::~MatcherUsingTracksAlgorithm | ( | ) | [inline, virtual] |
Definition at line 34 of file MatcherUsingTracksAlgorithm.h.
{ }
void MatcherUsingTracksAlgorithm::cropAndInvert | ( | AlgebraicSymMatrix55 & | cov, |
bool | diagonalOnly, | ||
bool | top3by3only | ||
) | [static] |
Possibly crop the 3x3 part of the matrix or remove off-diagonal terms, then invert.
Definition at line 493 of file MatcherUsingTracksAlgorithm.cc.
Referenced by getChi2().
{ if (!top3by3only) { if (diagonalOnly) { for (size_t i = 0; i < 5; ++i) { for (size_t j = i+1; j < 5; ++j) { cov(i,j) = 0; } } } cov.Invert(); } else { // get 3x3 covariance AlgebraicSymMatrix33 momCov = cov.Sub<AlgebraicSymMatrix33>(0,0); // get 3x3 matrix if (diagonalOnly) { momCov(0,1) = 0; momCov(0,2) = 0; momCov(1,2) = 0; } // invert momCov.Invert(); // place it cov.Place_at(momCov,0,0); // zero the rest for (size_t i = 3; i < 5; ++i) { for (size_t j = i; j < 5; ++j) { cov(i,j) = 0; } } } }
double MatcherUsingTracksAlgorithm::getChi2 | ( | const FreeTrajectoryState & | start, |
const FreeTrajectoryState & | other, | ||
bool | diagonalOnly, | ||
bool | useVertex, | ||
bool | useFirstMomentum | ||
) | [static] |
Compute the chi2 of two free trajectory states, in the curvilinear frame (q/p, theta, phi, dxy, dsz) At least one must have errors diagonalOnly: don't use off-diagonal terms of covariance matrix useVertex : use dxy, dsz in the chi2 (if false, use only q/p, theta, phi) useFirstMomentum : use the 'start' state momentum to compute dxy, dsx (if false, use 'other')
Definition at line 448 of file MatcherUsingTracksAlgorithm.cc.
References FreeTrajectoryState::charge(), cropAndInvert(), FreeTrajectoryState::curvilinearError(), diffTreeTool::diff, FreeTrajectoryState::hasError(), PV3DBase< T, PVType, FrameType >::mag(), CurvilinearTrajectoryError::matrix(), FreeTrajectoryState::momentum(), AlCaHLTBitMon_ParallelJobs::p, p1, p2, PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::phi(), FreeTrajectoryState::position(), PV3DBase< T, PVType, FrameType >::theta(), relativeConstraints::value, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by matchByDirectComparison(), and matchWithPropagation().
{ if (!start.hasError() && !other.hasError()) throw cms::Exception("LogicError") << "At least one of the two states must have errors to make chi2s.\n"; AlgebraicSymMatrix55 cov; if (start.hasError()) cov += start.curvilinearError().matrix(); if (other.hasError()) cov += other.curvilinearError().matrix(); cropAndInvert(cov, diagonalOnly, !useVertex); GlobalVector p1 = start.momentum(), p2 = other.momentum(); GlobalPoint x1 = start.position(), x2 = other.position(); GlobalVector p = useFirstMomentum ? p1 : p2; double pt = p.perp(), pm = p.mag(); double dsz = (x1.z()-x2.z())*pt/pm - ( (x1.x()-x2.x())*p.x() + (x1.y()-x2.y())*p.y() ) / pt * p.z()/pm; double dxy = ( -(x1.x()-x2.x())*p.y() + (x1.y()-x2.y())*p.x() )/pt; AlgebraicVector5 diff(start.charge()/p1.mag()-other.charge()/p2.mag(), p1.theta()-p2.theta(), (p1.phi()-p2.phi()).value(), dxy, dsz); return ROOT::Math::Similarity(diff, cov); }
double MatcherUsingTracksAlgorithm::getChi2 | ( | const TrajectoryStateOnSurface & | start, |
const TrajectoryStateOnSurface & | other, | ||
bool | diagonalOnly, | ||
bool | usePosition | ||
) | [static] |
Compute the chi2 of two free trajectory states, in the local frame (q/p, dx, dy, dxdz, dydz) At least one must have errors diagonalOnly: don't use off-diagonal terms of covariance matrix useVertex : use dx, dy in the chi2 (if false, use only direction and q/p)
Definition at line 482 of file MatcherUsingTracksAlgorithm.cc.
References cropAndInvert(), diffTreeTool::diff, TrajectoryStateOnSurface::hasError(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localParameters(), LocalTrajectoryError::matrix(), and LocalTrajectoryParameters::mixedFormatVector().
{ if (!start.hasError() && !other.hasError()) throw cms::Exception("LogicError") << "At least one of the two states must have errors to make chi2s.\n"; AlgebraicSymMatrix55 cov; if (start.hasError()) cov += start.localError().matrix(); if (other.hasError()) cov += other.localError().matrix(); cropAndInvert(cov, diagonalOnly, !usePosition); AlgebraicVector5 diff(start.localParameters().mixedFormatVector() - other.localParameters().mixedFormatVector()); return ROOT::Math::Similarity(diff, cov); }
double MatcherUsingTracksAlgorithm::getChi2 | ( | const FreeTrajectoryState & | start, |
const TrajectoryStateClosestToPoint & | other, | ||
bool | diagonalOnly, | ||
bool | useVertex | ||
) | [static] |
Compute the chi2 of one free trajectory state and a TrajectoryStateClosestToPoint closest to it, in the perigee frame At least one must have errors diagonalOnly: don't use off-diagonal terms of covariance matrix useVertex : use dxy, dsz in the chi2 (if false, use only q/p, theta, phi)
Definition at line 468 of file MatcherUsingTracksAlgorithm.cc.
References PerigeeTrajectoryError::covarianceMatrix(), cropAndInvert(), diffTreeTool::diff, PerigeeConversions::ftsToPerigeeError(), PerigeeConversions::ftsToPerigeeParameters(), FreeTrajectoryState::hasError(), TrajectoryStateClosestToPoint::hasError(), TrajectoryStateClosestToPoint::perigeeError(), TrajectoryStateClosestToPoint::perigeeParameters(), TrajectoryStateClosestToPoint::referencePoint(), and PerigeeTrajectoryParameters::vector().
{ if (!start.hasError() && !other.hasError()) throw cms::Exception("LogicError") << "At least one of the two states must have errors to make chi2s.\n"; PerigeeConversions pgconvert; double pt; // needed by pgconvert AlgebraicSymMatrix55 cov; if (start.hasError()) cov += pgconvert.ftsToPerigeeError(start).covarianceMatrix(); if (other.hasError()) cov += other.perigeeError().covarianceMatrix(); cropAndInvert(cov, diagonalOnly, !useVertex); AlgebraicVector5 pgpar1 = pgconvert.ftsToPerigeeParameters(start,other.referencePoint(),pt).vector(); AlgebraicVector5 pgpar2 = other.perigeeParameters().vector(); AlgebraicVector5 diff(pgpar1-pgpar2); return ROOT::Math::Similarity(diff, cov); }
void MatcherUsingTracksAlgorithm::getConf | ( | const edm::ParameterSet & | iConfig, |
const std::string & | whatFor, | ||
WhichTrack & | whichTrack, | ||
WhichState & | whichState | ||
) | [private] |
Parse some configuration.
Definition at line 112 of file MatcherUsingTracksAlgorithm.cc.
References algo_, AtVertex, ByTrackRef, Exception, edm::ParameterSet::getParameter(), GlobalTk, Innermost, MuonTk, None, Outermost, and TrackerTk.
Referenced by MatcherUsingTracksAlgorithm().
{ std::string s_whichTrack = iConfig.getParameter<std::string>(whatFor+"Track"); if (s_whichTrack == "none") { whichTrack = None; } else if (s_whichTrack == "tracker") { whichTrack = TrackerTk; } else if (s_whichTrack == "muon") { whichTrack = MuonTk; } else if (s_whichTrack == "global") { whichTrack = GlobalTk; } else throw cms::Exception("Configuration") << "Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n"; if ((whichTrack != None) && (algo_ != ByTrackRef)) { std::string s_whichState = iConfig.getParameter<std::string>(whatFor+"State"); if (s_whichState == "atVertex") { whichState = AtVertex; } else if (s_whichState == "innermost") { whichState = Innermost; } else if (s_whichState == "outermost") { whichState = Outermost; } else throw cms::Exception("Configuration") << "Parameter 'useState' must be 'atVertex', 'innermost', 'outermost'\n"; } }
reco::TrackRef MatcherUsingTracksAlgorithm::getTrack | ( | const reco::Candidate & | reco, |
WhichTrack | which | ||
) | const [private] |
Get track reference out of a Candidate (via dynamic_cast to reco::RecoCandidate)
Definition at line 246 of file MatcherUsingTracksAlgorithm.cc.
References reco::RecoCandidate::combinedMuon(), Exception, GlobalTk, MuonTk, dt_dqm_sourceclient_common_cff::reco, reco::RecoCandidate::standAloneMuon(), reco::RecoCandidate::track(), and TrackerTk.
Referenced by match(), startingState(), and targetState().
{ reco::TrackRef tk; const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&reco); if (rc == 0) throw cms::Exception("Invalid Data") << "Input object is not a RecoCandidate.\n"; switch (whichTrack) { case TrackerTk: tk = rc->track(); break; case MuonTk : tk = rc->standAloneMuon(); break; case GlobalTk : tk = rc->combinedMuon(); break; default: break; // just to make gcc happy } return tk; }
bool MatcherUsingTracksAlgorithm::hasChi2 | ( | ) | const [inline] |
Return 'true' if the matcher will produce also chi2.
Definition at line 52 of file MatcherUsingTracksAlgorithm.h.
References useChi2_.
{ return useChi2_; }
bool MatcherUsingTracksAlgorithm::hasMetrics | ( | ) | const [inline] |
Return 'true' if the matcher will produce meaningful deltaR, deltaLocalPos, deltaPtRel values.
Definition at line 49 of file MatcherUsingTracksAlgorithm.h.
References algo_, and ByTrackRef.
{ return algo_ != ByTrackRef; }
void MatcherUsingTracksAlgorithm::init | ( | const edm::EventSetup & | iSetup | ) |
Call this method at the beginning of each run, to initialize geometry, magnetic field and propagators.
Definition at line 238 of file MatcherUsingTracksAlgorithm.cc.
References geometry_, edm::EventSetup::get(), magfield_, and propagator_.
{ iSetup.get<IdealMagneticFieldRecord>().get(magfield_); iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator_); iSetup.get<GlobalTrackingGeometryRecord>().get(geometry_); }
bool MatcherUsingTracksAlgorithm::match | ( | const reco::Candidate & | c1, |
const reco::Candidate & | c2, | ||
float & | deltR, | ||
float & | deltEta, | ||
float & | deltPhi, | ||
float & | deltaLocalPos, | ||
float & | deltaPtRel, | ||
float & | chi2 | ||
) | const |
Try to match one track to another one. Return true if succeeded. For matches not by ref, it will update deltaR, deltaLocalPos and deltaPtRel if the match suceeded
Definition at line 131 of file MatcherUsingTracksAlgorithm.cc.
References algo_, ByDirectComparison, ByPropagatingMatched, ByPropagatingMatchedTSCP, ByPropagatingSrc, ByPropagatingSrcTSCP, ByTrackRef, reco::Candidate::charge(), getTrack(), edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::isNonnull(), matchByDirectComparison(), matchedCut_, matchWithPropagation(), requireSameCharge_, srcCut_, errorMatrix2Lands_multiChannel::start, startingState(), filterCSVwithJSON::target, targetState(), whichState1_, whichState2_, whichTrack1_, and whichTrack2_.
Referenced by match().
{ if (!(srcCut_(c1) && matchedCut_(c2))) return false; if (requireSameCharge_ && (c1.charge() != c2.charge())) return false; switch (algo_) { case ByTrackRef: { reco::TrackRef t1 = getTrack(c1, whichTrack1_); reco::TrackRef t2 = getTrack(c2, whichTrack2_); if (t1.isNonnull()) { if (t1 == t2) return true; if (t1.id() != t2.id()) { edm::LogWarning("MatcherUsingTracksAlgorithm") << "Trying to match by reference tracks coming from different collections.\n"; } } } case ByPropagatingSrc: { FreeTrajectoryState start = startingState(c1, whichTrack1_, whichState1_); TrajectoryStateOnSurface target = targetState(c2, whichTrack2_, whichState2_); return matchWithPropagation(start, target, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2); } case ByPropagatingMatched: { FreeTrajectoryState start = startingState(c2, whichTrack2_, whichState2_); TrajectoryStateOnSurface target = targetState(c1, whichTrack1_, whichState1_); return matchWithPropagation(start, target, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2); } case ByPropagatingSrcTSCP: { FreeTrajectoryState start = startingState(c1, whichTrack1_, whichState1_); FreeTrajectoryState target = startingState(c2, whichTrack2_, whichState2_); return matchWithPropagation(start, target, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2); } case ByPropagatingMatchedTSCP: { FreeTrajectoryState start = startingState(c2, whichTrack2_, whichState2_); FreeTrajectoryState target = startingState(c1, whichTrack1_, whichState1_); return matchWithPropagation(start, target, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2); } case ByDirectComparison: { FreeTrajectoryState start = startingState(c1, whichTrack1_, whichState1_); FreeTrajectoryState otherstart = startingState(c2, whichTrack2_, whichState2_); return matchByDirectComparison(start, otherstart, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2); } } return false; }
int MatcherUsingTracksAlgorithm::match | ( | const reco::Candidate & | c1, |
const edm::View< reco::Candidate > & | c2s, | ||
float & | deltR, | ||
float & | deltEta, | ||
float & | deltPhi, | ||
float & | deltaLocalPos, | ||
float & | deltaPtRel, | ||
float & | chi2 | ||
) | const |
Find the best match to another candidate, and return its index in the vector For matches not by ref, it will update deltaR, deltaLocalPos and deltaPtRel if the match suceeded Returns -1 if the match fails
Definition at line 177 of file MatcherUsingTracksAlgorithm.cc.
References algo_, edm::View< T >::begin(), ByDirectComparison, ByPropagatingMatched, ByPropagatingMatchedTSCP, ByPropagatingSrc, ByPropagatingSrcTSCP, ByTrackRef, reco::Candidate::charge(), edm::View< T >::end(), cmsRelvalreport::exit, getTrack(), i, edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::isNonnull(), match(), matchByDirectComparison(), matchedCut_, matchWithPropagation(), requireSameCharge_, srcCut_, errorMatrix2Lands_multiChannel::start, startingState(), filterCSVwithJSON::target, targetState(), whichState1_, whichState2_, whichTrack1_, and whichTrack2_.
{ if (!srcCut_(c1)) return -1; // working and output variables FreeTrajectoryState start; TrajectoryStateOnSurface target; int match = -1; // pre-fetch some states if needed if (algo_ == ByPropagatingSrc || algo_ == ByPropagatingSrcTSCP || algo_ == ByPropagatingMatchedTSCP || algo_ == ByDirectComparison) { start = startingState(c1, whichTrack1_, whichState1_); } else if (algo_ == ByPropagatingMatched) target = targetState(c1, whichTrack1_, whichState1_); // loop on the collection edm::View<reco::Candidate>::const_iterator it, ed; int i; for (it = c2s.begin(), ed = c2s.end(), i = 0; it != ed; ++it, ++i) { if (!matchedCut_(*it)) continue; if (requireSameCharge_ && (c1.charge() != it->charge()) ) continue; bool exit = false; switch (algo_) { case ByTrackRef: { reco::TrackRef t1 = getTrack(c1, whichTrack1_); reco::TrackRef t2 = getTrack(*it, whichTrack2_); if (t1.isNonnull()) { if (t1 == t2) { match = i; exit = true; } if (t1.id() != t2.id()) { edm::LogWarning("MatcherUsingTracksAlgorithm") << "Trying to match by reference tracks coming from different collections.\n"; } } } break; case ByPropagatingSrc: case ByPropagatingMatched: { if (algo_ == ByPropagatingMatched) start = startingState(*it, whichTrack2_, whichState2_); else if (algo_ == ByPropagatingSrc) target = targetState(*it, whichTrack2_, whichState2_); if (matchWithPropagation(start, target, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2)) { match = i; } } break; case ByDirectComparison: { FreeTrajectoryState otherstart = startingState(*it, whichTrack2_, whichState2_); if (matchByDirectComparison(start, otherstart, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2)) { match = i; } } break; case ByPropagatingSrcTSCP: { FreeTrajectoryState otherstart = startingState(*it, whichTrack2_, whichState2_); if (matchWithPropagation(start, otherstart, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2)) { match = i; } } break; case ByPropagatingMatchedTSCP: { FreeTrajectoryState otherstart = startingState(*it, whichTrack2_, whichState2_); if (matchWithPropagation(otherstart, start, deltR, deltEta, deltPhi, deltaLocalPos, deltaPtRel, chi2)) { match = i; } } break; } if (exit) break; } return match; }
bool MatcherUsingTracksAlgorithm::matchByDirectComparison | ( | const FreeTrajectoryState & | start, |
const FreeTrajectoryState & | other, | ||
float & | lastDeltaR, | ||
float & | lastDeltaEta, | ||
float & | lastDeltaPhi, | ||
float & | lastDeltaLocalPos, | ||
float & | lastGlobalDPtRel, | ||
float & | lastChi2 | ||
) | const [private] |
Compare directly two states. return true if current pair is the new best match (in that case, update also deltaR and deltaLocalPos)
Definition at line 401 of file MatcherUsingTracksAlgorithm.cc.
References chi2DiagonalOnly_, chi2FirstMomentum_, chi2UseVertex_, SiPixelRawToDigiRegional_cfi::deltaPhi, deltaR(), PV3DBase< T, PVType, FrameType >::eta(), getChi2(), GlobalDPtRel, GlobalMomDeltaEta, GlobalMomDeltaPhi, GlobalMomDeltaR, LocalPosDiff, PV3DBase< T, PVType, FrameType >::mag(), mag(), maxChi2_, maxGlobalDPtRel_, maxGlobalMomDeltaEta_, maxGlobalMomDeltaPhi_, maxGlobalMomDeltaR_, maxLocalPosDiff_, FreeTrajectoryState::momentum(), PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::phi(), FreeTrajectoryState::position(), sortBy_, and useChi2_.
Referenced by match().
{ if ((start.momentum().mag() == 0) || target.momentum().mag() == 0) return false; bool isBest = false; float thisLocalPosDiff = (start.position()-target.position()).mag(); float thisGlobalMomDeltaR = deltaR(start.momentum(), target.momentum()); float thisGlobalMomDeltaPhi = fabs(deltaPhi(start.momentum().phi(), target.momentum().phi())); float thisGlobalMomDeltaEta = fabs(start.momentum().eta() - target.momentum().eta()); float thisGlobalDPtRel = (start.momentum().perp() - target.momentum().perp())/target.momentum().perp(); if ((thisLocalPosDiff < maxLocalPosDiff_) && (thisGlobalMomDeltaR < maxGlobalMomDeltaR_) && (thisGlobalMomDeltaEta < maxGlobalMomDeltaEta_) && (thisGlobalMomDeltaPhi < maxGlobalMomDeltaPhi_) && (fabs(thisGlobalDPtRel) < maxGlobalDPtRel_)) { float thisChi2 = useChi2_ ? getChi2(start, target, chi2DiagonalOnly_, chi2UseVertex_, chi2FirstMomentum_) : 0; if (thisChi2 >= maxChi2_) return false; switch (sortBy_) { case LocalPosDiff: isBest = (thisLocalPosDiff < lastDeltaLocalPos); break; case GlobalMomDeltaR: isBest = (thisGlobalMomDeltaR < lastDeltaR); break; case GlobalMomDeltaEta: isBest = (thisGlobalMomDeltaEta < lastDeltaEta); break; case GlobalMomDeltaPhi: isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi); break; case GlobalDPtRel: isBest = (thisGlobalDPtRel < lastGlobalDPtRel); break; case Chi2: isBest = (thisChi2 < lastChi2); break; } if (isBest) { lastDeltaLocalPos = thisLocalPosDiff; lastDeltaR = thisGlobalMomDeltaR; lastDeltaEta = thisGlobalMomDeltaEta; lastDeltaPhi = thisGlobalMomDeltaPhi; lastGlobalDPtRel = thisGlobalDPtRel; lastChi2 = thisChi2; } } // if match return isBest; }
bool MatcherUsingTracksAlgorithm::matchWithPropagation | ( | const FreeTrajectoryState & | start, |
const FreeTrajectoryState & | target, | ||
float & | lastDeltaR, | ||
float & | lastDeltaEta, | ||
float & | lastDeltaPhi, | ||
float & | lastDeltaLocalPos, | ||
float & | lastGlobalDPtRel, | ||
float & | lastChi2 | ||
) | const [private] |
Propagate and match. return true if current pair is the new best match (in that case, update also deltaR and deltaLocalPos) Uses TrajectoryStateClosestToPointBuilder
Definition at line 348 of file MatcherUsingTracksAlgorithm.cc.
References chi2DiagonalOnly_, chi2UseVertex_, SiPixelRawToDigiRegional_cfi::deltaPhi, deltaR(), PV3DBase< T, PVType, FrameType >::eta(), getChi2(), GlobalDPtRel, GlobalMomDeltaEta, GlobalMomDeltaPhi, GlobalMomDeltaR, LocalPosDiff, PV3DBase< T, PVType, FrameType >::mag(), mag(), maxChi2_, maxGlobalDPtRel_, maxGlobalMomDeltaEta_, maxGlobalMomDeltaPhi_, maxGlobalMomDeltaR_, maxLocalPosDiff_, TrajectoryStateClosestToPoint::momentum(), FreeTrajectoryState::momentum(), PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::phi(), TrajectoryStateClosestToPoint::position(), FreeTrajectoryState::position(), LargeD0_PixelPairStep_cff::propagator, sortBy_, and useChi2_.
Referenced by match().
{ if ((start.momentum().mag() == 0) || (target.momentum().mag() == 0)) return false; TSCPBuilderNoMaterial propagator; /*2.2.X*/ try { TrajectoryStateClosestToPoint tscp = propagator(start, target.position()); // if (!tscp.isValid()) return false; // in 3.1.X bool isBest = false; float thisLocalPosDiff = (tscp.position()-target.position()).mag(); float thisGlobalMomDeltaR = deltaR(tscp.momentum(), target.momentum()); float thisGlobalMomDeltaPhi = fabs(deltaPhi(tscp.momentum().phi(), target.momentum().phi())); float thisGlobalMomDeltaEta = fabs(tscp.momentum().eta() - target.momentum().eta()); float thisGlobalDPtRel = (tscp.momentum().perp() - target.momentum().perp())/target.momentum().perp(); if ((thisLocalPosDiff < maxLocalPosDiff_) && (thisGlobalMomDeltaR < maxGlobalMomDeltaR_) && (thisGlobalMomDeltaEta < maxGlobalMomDeltaEta_) && (thisGlobalMomDeltaPhi < maxGlobalMomDeltaPhi_) && (fabs(thisGlobalDPtRel) < maxGlobalDPtRel_)) { float thisChi2 = useChi2_ ? getChi2(target, tscp, chi2DiagonalOnly_, chi2UseVertex_) : 0; if (thisChi2 >= maxChi2_) return false; switch (sortBy_) { case LocalPosDiff: isBest = (thisLocalPosDiff < lastDeltaLocalPos); break; case GlobalMomDeltaR: isBest = (thisGlobalMomDeltaR < lastDeltaR); break; case GlobalMomDeltaEta: isBest = (thisGlobalMomDeltaEta < lastDeltaEta); break; case GlobalMomDeltaPhi: isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi); break; case GlobalDPtRel: isBest = (thisGlobalDPtRel < lastGlobalDPtRel); break; case Chi2: isBest = (thisChi2 < lastChi2); break; } if (isBest) { lastDeltaLocalPos = thisLocalPosDiff; lastDeltaR = thisGlobalMomDeltaR; lastDeltaEta = thisGlobalMomDeltaEta; lastDeltaPhi = thisGlobalMomDeltaPhi; lastGlobalDPtRel = thisGlobalDPtRel; lastChi2 = thisChi2; } } // if match return isBest; /*2.2.X*/ } catch (const TrajectoryStateException &err) { return false; } }
bool MatcherUsingTracksAlgorithm::matchWithPropagation | ( | const FreeTrajectoryState & | start, |
const TrajectoryStateOnSurface & | target, | ||
float & | lastDeltaR, | ||
float & | lastDeltaEta, | ||
float & | lastDeltaPhi, | ||
float & | lastDeltaLocalPos, | ||
float & | lastGlobalDPtRel, | ||
float & | lastChi2 | ||
) | const [private] |
Propagate and match. return true if current pair is the new best match (in that case, update also deltaR and deltaLocalPos) Uses standard propagator to reach target's surface
Definition at line 297 of file MatcherUsingTracksAlgorithm.cc.
References chi2DiagonalOnly_, chi2UseVertex_, SiPixelRawToDigiRegional_cfi::deltaPhi, deltaR(), PV3DBase< T, PVType, FrameType >::eta(), getChi2(), GlobalDPtRel, GlobalMomDeltaEta, GlobalMomDeltaPhi, GlobalMomDeltaR, TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::isValid(), LocalPosDiff, TrajectoryStateOnSurface::localPosition(), PV3DBase< T, PVType, FrameType >::mag(), mag(), maxChi2_, maxGlobalDPtRel_, maxGlobalMomDeltaEta_, maxGlobalMomDeltaPhi_, maxGlobalMomDeltaR_, maxLocalPosDiff_, FreeTrajectoryState::momentum(), PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::phi(), propagator_, sortBy_, TrajectoryStateOnSurface::surface(), and useChi2_.
{ if ((start.momentum().mag() == 0) || !target.isValid()) return false; TrajectoryStateOnSurface tsos = propagator_->propagate(start, target.surface()); bool isBest = false; if (tsos.isValid()) { float thisLocalPosDiff = (tsos.localPosition()-target.localPosition()).mag(); float thisGlobalMomDeltaR = deltaR(tsos.globalMomentum(), target.globalMomentum()); float thisGlobalMomDeltaPhi = fabs(deltaPhi(tsos.globalMomentum().phi(), target.globalMomentum().phi())); float thisGlobalMomDeltaEta = fabs(tsos.globalMomentum().eta() - target.globalMomentum().eta()); float thisGlobalDPtRel = (tsos.globalMomentum().perp() - target.globalMomentum().perp())/target.globalMomentum().perp(); if ((thisLocalPosDiff < maxLocalPosDiff_) && (thisGlobalMomDeltaR < maxGlobalMomDeltaR_) && (thisGlobalMomDeltaEta < maxGlobalMomDeltaEta_) && (thisGlobalMomDeltaPhi < maxGlobalMomDeltaPhi_) && (fabs(thisGlobalDPtRel) < maxGlobalDPtRel_)) { float thisChi2 = useChi2_ ? getChi2(target, tsos, chi2DiagonalOnly_, chi2UseVertex_) : 0; if (thisChi2 >= maxChi2_) return false; switch (sortBy_) { case LocalPosDiff: isBest = (thisLocalPosDiff < lastDeltaLocalPos); break; case GlobalMomDeltaR: isBest = (thisGlobalMomDeltaR < lastDeltaR); break; case GlobalMomDeltaEta: isBest = (thisGlobalMomDeltaEta < lastDeltaEta); break; case GlobalMomDeltaPhi: isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi); break; case GlobalDPtRel: isBest = (thisGlobalDPtRel < lastGlobalDPtRel); break; case Chi2: isBest = (thisChi2 < lastChi2); break; } if (isBest) { lastDeltaLocalPos = thisLocalPosDiff; lastDeltaR = thisGlobalMomDeltaR; lastDeltaEta = thisGlobalMomDeltaEta; lastDeltaPhi = thisGlobalMomDeltaPhi; lastGlobalDPtRel = thisGlobalDPtRel; lastChi2 = thisChi2; } } // if match } return isBest; }
FreeTrajectoryState MatcherUsingTracksAlgorithm::startingState | ( | const reco::Candidate & | reco, |
WhichTrack | whichTrack, | ||
WhichState | whichState | ||
) | const [private] |
Starting state for the propagation.
Definition at line 260 of file MatcherUsingTracksAlgorithm.cc.
References AtVertex, reco::Candidate::charge(), getTrack(), trajectoryStateTransform::initialFreeState(), trajectoryStateTransform::innerFreeState(), Innermost, edm::Ref< C, T, F >::isNull(), magfield_, None, trajectoryStateTransform::outerFreeState(), Outermost, edm::ESHandle< T >::product(), reco::Candidate::px(), reco::Candidate::py(), reco::Candidate::pz(), run_regression::ret, reco::Candidate::vx(), reco::Candidate::vy(), and reco::Candidate::vz().
Referenced by match().
{ FreeTrajectoryState ret; if (whichTrack != None) { reco::TrackRef tk = getTrack(reco, whichTrack); if (tk.isNull()) { ret = FreeTrajectoryState(); } else { switch (whichState) { case AtVertex: ret = trajectoryStateTransform::initialFreeState(*tk, magfield_.product()); break; case Innermost: ret = trajectoryStateTransform::innerFreeState( *tk, magfield_.product()); break; case Outermost: ret = trajectoryStateTransform::outerFreeState( *tk, magfield_.product()); break; } } } else { ret = FreeTrajectoryState( GlobalPoint( reco.vx(), reco.vy(), reco.vz()), GlobalVector(reco.px(), reco.py(), reco.pz()), reco.charge(), magfield_.product()); } return ret; }
TrajectoryStateOnSurface MatcherUsingTracksAlgorithm::targetState | ( | const reco::Candidate & | reco, |
WhichTrack | whichTrack, | ||
WhichState | whichState | ||
) | const [private] |
End state for the propagation.
Definition at line 283 of file MatcherUsingTracksAlgorithm.cc.
References geometry_, getTrack(), Innermost, trajectoryStateTransform::innerStateOnSurface(), edm::Ref< C, T, F >::isNonnull(), magfield_, Outermost, trajectoryStateTransform::outerStateOnSurface(), edm::ESHandle< T >::product(), and run_regression::ret.
Referenced by match().
{ TrajectoryStateOnSurface ret; reco::TrackRef tk = getTrack(reco, whichTrack); if (tk.isNonnull()) { switch (whichState) { case Innermost: ret = trajectoryStateTransform::innerStateOnSurface( *tk, *geometry_, magfield_.product()); break; case Outermost: ret = trajectoryStateTransform::outerStateOnSurface( *tk, *geometry_, magfield_.product()); break; default: break; // just to make gcc happy } } return ret; }
AlgoType MatcherUsingTracksAlgorithm::algo_ [private] |
Definition at line 82 of file MatcherUsingTracksAlgorithm.h.
Referenced by getConf(), hasMetrics(), match(), and MatcherUsingTracksAlgorithm().
bool MatcherUsingTracksAlgorithm::chi2DiagonalOnly_ [private] |
Definition at line 97 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
bool MatcherUsingTracksAlgorithm::chi2FirstMomentum_ [private] |
Definition at line 97 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), and MatcherUsingTracksAlgorithm().
bool MatcherUsingTracksAlgorithm::chi2UseVertex_ [private] |
Definition at line 97 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
Definition at line 105 of file MatcherUsingTracksAlgorithm.h.
Referenced by init(), and targetState().
Definition at line 103 of file MatcherUsingTracksAlgorithm.h.
Referenced by init(), startingState(), and targetState().
Definition at line 87 of file MatcherUsingTracksAlgorithm.h.
Referenced by match().
float MatcherUsingTracksAlgorithm::maxChi2_ [private] |
Definition at line 95 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
float MatcherUsingTracksAlgorithm::maxGlobalDPtRel_ [private] |
Definition at line 94 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
float MatcherUsingTracksAlgorithm::maxGlobalMomDeltaEta_ [private] |
Definition at line 92 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
float MatcherUsingTracksAlgorithm::maxGlobalMomDeltaPhi_ [private] |
Definition at line 93 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
float MatcherUsingTracksAlgorithm::maxGlobalMomDeltaR_ [private] |
Definition at line 91 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
float MatcherUsingTracksAlgorithm::maxLocalPosDiff_ [private] |
Definition at line 90 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
Definition at line 104 of file MatcherUsingTracksAlgorithm.h.
Referenced by init(), and matchWithPropagation().
bool MatcherUsingTracksAlgorithm::requireSameCharge_ [private] |
Definition at line 96 of file MatcherUsingTracksAlgorithm.h.
Referenced by match().
SortBy MatcherUsingTracksAlgorithm::sortBy_ [private] |
Definition at line 99 of file MatcherUsingTracksAlgorithm.h.
Referenced by matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
Definition at line 87 of file MatcherUsingTracksAlgorithm.h.
Referenced by match().
bool MatcherUsingTracksAlgorithm::useChi2_ [private] |
Definition at line 97 of file MatcherUsingTracksAlgorithm.h.
Referenced by hasChi2(), matchByDirectComparison(), MatcherUsingTracksAlgorithm(), and matchWithPropagation().
Definition at line 84 of file MatcherUsingTracksAlgorithm.h.
Referenced by match(), and MatcherUsingTracksAlgorithm().
Definition at line 84 of file MatcherUsingTracksAlgorithm.h.
Referenced by match(), and MatcherUsingTracksAlgorithm().
Definition at line 83 of file MatcherUsingTracksAlgorithm.h.
Referenced by match(), and MatcherUsingTracksAlgorithm().
Definition at line 83 of file MatcherUsingTracksAlgorithm.h.
Referenced by match(), and MatcherUsingTracksAlgorithm().