24 srcCut_(iConfig.existsAs<
std::
string>(
"srcPreselection") ? iConfig.getParameter<
std::
string>(
"srcPreselection")
26 matchedCut_(iConfig.existsAs<
std::
string>(
"matchedPreselection")
27 ? iConfig.getParameter<
std::
string>(
"matchedPreselection")
29 requireSameCharge_(iConfig.existsAs<
bool>(
"requireSameCharge") ? iConfig.getParameter<
bool>(
"requireSameCharge")
35 if (
algo ==
"byTrackRef") {
37 }
else if (
algo ==
"byPropagatingSrc") {
39 }
else if (
algo ==
"byPropagatingMatched") {
41 }
else if (
algo ==
"byDirectComparison") {
44 throw cms::Exception(
"Configuration") <<
"Value '" <<
algo <<
"' for algorithm not yet implemented.\n";
52 throw cms::Exception(
"Configuration") <<
"Algorithm 'byTrackRef' needs tracks not to be 'none'.\n";
65 if (
sortBy ==
"deltaLocalPos")
67 else if (
sortBy ==
"deltaPtRel")
69 else if (
sortBy ==
"deltaR")
71 else if (
sortBy ==
"deltaEta")
73 else if (
sortBy ==
"deltaPhi")
79 <<
"Parameter 'sortBy' must be one of: deltaLocalPos, deltaPtRel, deltaR, chi2.\n";
97 <<
"When using 'byDirectComparison' with 'src' at vertex (or None), 'matched' must be at vertex too.\n";
101 <<
"When using 'byDirectComparison' with 'src' not at vertex, 'matched' can't be at vertex or None.\n";
103 throw cms::Exception(
"Configuration") <<
"You can't use 'byDirectComparison' with non-matching states.\n";
110 throw cms::Exception(
"Configuration") <<
"Can't compute chi2s if both tracks are set to 'none'.\n";
121 else if (choice !=
"matched")
122 throw cms::Exception(
"Configuration") <<
"chi2MomentumForDxy must be 'src' or 'matched'\n";
129 throw cms::Exception(
"Configuration") <<
"Can't sort by chi2s if 'computeChi2s' is not set to true.\n";
138 if (s_whichTrack ==
"none") {
140 }
else if (s_whichTrack ==
"tracker") {
142 }
else if (s_whichTrack ==
"muon") {
144 }
else if (s_whichTrack ==
"global") {
147 throw cms::Exception(
"Configuration") <<
"Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n";
150 if (s_whichState ==
"atVertex") {
152 }
else if (s_whichState ==
"innermost") {
154 }
else if (s_whichState ==
"outermost") {
157 throw cms::Exception(
"Configuration") <<
"Parameter 'useState' must be 'atVertex', 'innermost', 'outermost'\n";
168 float &deltaLocalPos,
179 if (
t1.isNonnull()) {
182 if (
t1.id() !=
t2.id()) {
184 <<
"Trying to match by reference tracks coming from different collections.\n";
227 float &deltaLocalPos,
258 if (
t1.isNonnull()) {
263 if (
t1.id() !=
t2.id()) {
265 <<
"Trying to match by reference tracks coming from different collections.\n";
315 throw cms::Exception(
"Invalid Data") <<
"Input object is not a RecoCandidate.\n";
316 switch (whichTrack) {
336 if (whichTrack !=
None) {
341 switch (whichState) {
368 switch (whichState) {
387 float &lastDeltaLocalPos,
388 float &lastGlobalDPtRel,
389 float &lastChi2)
const {
390 if ((
start.momentum().mag() == 0) || !
target.isValid())
401 float thisGlobalDPtRel =
412 isBest = (thisLocalPosDiff < lastDeltaLocalPos);
415 isBest = (thisGlobalMomDeltaR < lastDeltaR);
418 isBest = (thisGlobalMomDeltaEta < lastDeltaEta);
421 isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi);
424 isBest = (thisGlobalDPtRel < lastGlobalDPtRel);
427 isBest = (thisChi2 < lastChi2);
431 lastDeltaLocalPos = thisLocalPosDiff;
432 lastDeltaR = thisGlobalMomDeltaR;
433 lastDeltaEta = thisGlobalMomDeltaEta;
434 lastDeltaPhi = thisGlobalMomDeltaPhi;
435 lastGlobalDPtRel = thisGlobalDPtRel;
449 float &lastDeltaLocalPos,
450 float &lastGlobalDPtRel,
451 float &lastChi2)
const {
452 if ((
start.momentum().mag() == 0) || (
target.momentum().mag() == 0))
463 float thisGlobalMomDeltaEta = fabs(tscp.
momentum().
eta() -
target.momentum().eta());
474 isBest = (thisLocalPosDiff < lastDeltaLocalPos);
477 isBest = (thisGlobalMomDeltaR < lastDeltaR);
480 isBest = (thisGlobalMomDeltaEta < lastDeltaEta);
483 isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi);
486 isBest = (thisGlobalDPtRel < lastGlobalDPtRel);
489 isBest = (thisChi2 < lastChi2);
493 lastDeltaLocalPos = thisLocalPosDiff;
494 lastDeltaR = thisGlobalMomDeltaR;
495 lastDeltaEta = thisGlobalMomDeltaEta;
496 lastDeltaPhi = thisGlobalMomDeltaPhi;
497 lastGlobalDPtRel = thisGlobalDPtRel;
511 float &lastDeltaLocalPos,
512 float &lastGlobalDPtRel,
513 float &lastChi2)
const {
514 if ((
start.momentum().mag() == 0) ||
target.momentum().mag() == 0)
518 float thisLocalPosDiff = (
start.position() -
target.position()).
mag();
520 float thisGlobalMomDeltaPhi = fabs(
deltaPhi(
start.momentum().barePhi(),
target.momentum().barePhi()));
521 float thisGlobalMomDeltaEta = fabs(
start.momentum().eta() -
target.momentum().eta());
522 float thisGlobalDPtRel = (
start.momentum().perp() -
target.momentum().perp()) /
target.momentum().perp();
532 isBest = (thisLocalPosDiff < lastDeltaLocalPos);
535 isBest = (thisGlobalMomDeltaR < lastDeltaR);
538 isBest = (thisGlobalMomDeltaEta < lastDeltaEta);
541 isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi);
544 isBest = (thisGlobalDPtRel < lastGlobalDPtRel);
547 isBest = (thisChi2 < lastChi2);
551 lastDeltaLocalPos = thisLocalPosDiff;
552 lastDeltaR = thisGlobalMomDeltaR;
553 lastDeltaEta = thisGlobalMomDeltaEta;
554 lastDeltaPhi = thisGlobalMomDeltaPhi;
555 lastGlobalDPtRel = thisGlobalDPtRel;
567 bool useFirstMomentum) {
569 throw cms::Exception(
"LogicError") <<
"At least one of the two states must have errors to make chi2s.\n";
571 if (
start.hasError())
572 cov +=
start.curvilinearError().matrix();
573 if (
other.hasError())
574 cov +=
other.curvilinearError().matrix();
579 double pt =
p.perp(), pm =
p.mag();
581 (
x1.z() -
x2.z()) *
pt / pm - ((
x1.x() -
x2.x()) *
p.x() + (
x1.y() -
x2.y()) *
p.y()) /
pt *
p.z() / pm;
582 double dxy = (-(
x1.x() -
x2.x()) *
p.y() + (
x1.y() -
x2.y()) *
p.x()) /
pt;
584 p1.theta() -
p2.theta(),
588 return ROOT::Math::Similarity(
diff, cov);
596 throw cms::Exception(
"LogicError") <<
"At least one of the two states must have errors to make chi2s.\n";
599 if (
start.hasError())
601 if (
other.hasError())
602 cov +=
other.perigeeError().covarianceMatrix();
607 return ROOT::Math::Similarity(
diff, cov);
615 throw cms::Exception(
"LogicError") <<
"At least one of the two states must have errors to make chi2s.\n";
617 if (
start.hasError())
618 cov +=
start.localError().matrix();
619 if (
other.hasError())
620 cov +=
other.localError().matrix();
623 return ROOT::Math::Similarity(
diff, cov);
629 for (
size_t i = 0;
i < 5; ++
i) {
630 for (
size_t j =
i + 1;
j < 5; ++
j) {
647 cov.Place_at(momCov, 0, 0);
649 for (
size_t i = 3;
i < 5; ++
i) {
650 for (
size_t j =
i;
j < 5; ++
j) {
PerigeeTrajectoryParameters ftsToPerigeeParameters(const FTS &originalFTS, const GlobalPoint &referencePoint, double &pt)
T getParameter(std::string const &) const
FreeTrajectoryState startingState(const reco::Candidate &reco, WhichTrack whichTrack, WhichState whichState) const
Starting state for the propagation.
const AlgebraicSymMatrix55 & covarianceMatrix() const
edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > geometryToken_
LocalPoint localPosition() const
bool match(const reco::Candidate &c1, const reco::Candidate &c2, float &deltaR, float &deltaEta, float &deltaPhi, float &deltaLocalPos, float &deltaPtRel, float &chi2) const
TrajectoryStateOnSurface targetState(const reco::Candidate &reco, WhichTrack whichTrack, WhichState whichState) const
End state for the propagation.
ret
prodAgent to be discontinued
void getConf(const edm::ParameterSet &iConfig, const std::string &whatFor, WhichTrack &whichTrack, WhichState &whichState)
Parse some configuration.
bool matchWithPropagation(const FreeTrajectoryState &start, const FreeTrajectoryState &target, float &lastDeltaR, float &lastDeltaEta, float &lastDeltaPhi, float &lastDeltaLocalPos, float &lastGlobalDPtRel, float &lastChi2) const
Global3DPoint GlobalPoint
bool isNonnull() const
Checks for non-null.
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magfieldToken_
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
static double getChi2(const FreeTrajectoryState &start, const FreeTrajectoryState &other, bool diagonalOnly, bool useVertex, bool useFirstMomentum)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
float maxGlobalMomDeltaEta_
StringCutObjectSelector< reco::Candidate, true > matchedCut_
T const * product() const
GlobalPoint position() const
edm::ESHandle< GlobalTrackingGeometry > geometry_
edm::ESHandle< MagneticField > magfield_
ROOT::Math::SVector< double, 5 > AlgebraicVector5
StringCutObjectSelector< reco::Candidate, true > srcCut_
virtual int charge() const =0
electric charge
bool isNull() const
Checks for null.
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
float maxGlobalMomDeltaPhi_
edm::ESHandle< Propagator > propagator_
MatcherUsingTracksAlgorithm(const edm::ParameterSet &iConfig, edm::ConsumesCollector)
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...
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
float maxGlobalMomDeltaR_
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
GlobalVector globalMomentum() const
static void cropAndInvert(AlgebraicSymMatrix55 &cov, bool diagonalOnly, bool top3by3only)
Possibly crop the 3x3 part of the matrix or remove off-diagonal terms, then invert.
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorToken_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
virtual reco::TrackRef track() const
reference to a Track
void init(const edm::EventSetup &iSetup)
Call this method at the beginning of each run, to initialize geometry, magnetic field and propagators...
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
GlobalVector momentum() const
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track
PerigeeTrajectoryError ftsToPerigeeError(const FTS &originalFTS)
const_iterator begin() const
Log< level::Warning, false > LogWarning
reco::TrackRef getTrack(const reco::Candidate &reco, WhichTrack which) const
Get track reference out of a Candidate (via dynamic_cast to reco::RecoCandidate)
const_iterator end() const
Global3DVector GlobalVector
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track