22 whichState1_(AtVertex),
23 whichState2_(AtVertex),
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")
32 if (
algo ==
"byTrackRef") {
34 }
else if (
algo ==
"byPropagatingSrc") {
36 }
else if (
algo ==
"byPropagatingMatched") {
38 }
else if (
algo ==
"byDirectComparison") {
41 throw cms::Exception(
"Configuration") <<
"Value '" <<
algo <<
"' for algorithm not yet implemented.\n";
49 throw cms::Exception(
"Configuration") <<
"Algorithm 'byTrackRef' needs tracks not to be 'none'.\n";
62 if (
sortBy ==
"deltaLocalPos")
64 else if (
sortBy ==
"deltaPtRel")
66 else if (
sortBy ==
"deltaR")
68 else if (
sortBy ==
"deltaEta")
70 else if (
sortBy ==
"deltaPhi")
76 <<
"Parameter 'sortBy' must be one of: deltaLocalPos, deltaPtRel, deltaR, chi2.\n";
94 <<
"When using 'byDirectComparison' with 'src' at vertex (or None), 'matched' must be at vertex too.\n";
98 <<
"When using 'byDirectComparison' with 'src' not at vertex, 'matched' can't be at vertex or None.\n";
100 throw cms::Exception(
"Configuration") <<
"You can't use 'byDirectComparison' with non-matching states.\n";
107 throw cms::Exception(
"Configuration") <<
"Can't compute chi2s if both tracks are set to 'none'.\n";
118 else if (choice !=
"matched")
119 throw cms::Exception(
"Configuration") <<
"chi2MomentumForDxy must be 'src' or 'matched'\n";
126 throw cms::Exception(
"Configuration") <<
"Can't sort by chi2s if 'computeChi2s' is not set to true.\n";
135 if (s_whichTrack ==
"none") {
137 }
else if (s_whichTrack ==
"tracker") {
139 }
else if (s_whichTrack ==
"muon") {
141 }
else if (s_whichTrack ==
"global") {
144 throw cms::Exception(
"Configuration") <<
"Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n";
147 if (s_whichState ==
"atVertex") {
149 }
else if (s_whichState ==
"innermost") {
151 }
else if (s_whichState ==
"outermost") {
154 throw cms::Exception(
"Configuration") <<
"Parameter 'useState' must be 'atVertex', 'innermost', 'outermost'\n";
165 float &deltaLocalPos,
176 if (
t1.isNonnull()) {
179 if (
t1.id() !=
t2.id()) {
181 <<
"Trying to match by reference tracks coming from different collections.\n";
224 float &deltaLocalPos,
245 for (it = c2s.
begin(), ed = c2s.
end(),
i = 0; it != ed; ++it, ++
i) {
255 if (
t1.isNonnull()) {
260 if (
t1.id() !=
t2.id()) {
262 <<
"Trying to match by reference tracks coming from different collections.\n";
312 throw cms::Exception(
"Invalid Data") <<
"Input object is not a RecoCandidate.\n";
313 switch (whichTrack) {
333 if (whichTrack !=
None) {
338 switch (whichState) {
365 switch (whichState) {
384 float &lastDeltaLocalPos,
385 float &lastGlobalDPtRel,
386 float &lastChi2)
const {
387 if ((
start.momentum().mag() == 0) || !
target.isValid())
398 float thisGlobalDPtRel =
409 isBest = (thisLocalPosDiff < lastDeltaLocalPos);
412 isBest = (thisGlobalMomDeltaR < lastDeltaR);
415 isBest = (thisGlobalMomDeltaEta < lastDeltaEta);
418 isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi);
421 isBest = (thisGlobalDPtRel < lastGlobalDPtRel);
424 isBest = (thisChi2 < lastChi2);
428 lastDeltaLocalPos = thisLocalPosDiff;
429 lastDeltaR = thisGlobalMomDeltaR;
430 lastDeltaEta = thisGlobalMomDeltaEta;
431 lastDeltaPhi = thisGlobalMomDeltaPhi;
432 lastGlobalDPtRel = thisGlobalDPtRel;
446 float &lastDeltaLocalPos,
447 float &lastGlobalDPtRel,
448 float &lastChi2)
const {
449 if ((
start.momentum().mag() == 0) || (
target.momentum().mag() == 0))
460 float thisGlobalMomDeltaEta = fabs(tscp.
momentum().
eta() -
target.momentum().eta());
471 isBest = (thisLocalPosDiff < lastDeltaLocalPos);
474 isBest = (thisGlobalMomDeltaR < lastDeltaR);
477 isBest = (thisGlobalMomDeltaEta < lastDeltaEta);
480 isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi);
483 isBest = (thisGlobalDPtRel < lastGlobalDPtRel);
486 isBest = (thisChi2 < lastChi2);
490 lastDeltaLocalPos = thisLocalPosDiff;
491 lastDeltaR = thisGlobalMomDeltaR;
492 lastDeltaEta = thisGlobalMomDeltaEta;
493 lastDeltaPhi = thisGlobalMomDeltaPhi;
494 lastGlobalDPtRel = thisGlobalDPtRel;
508 float &lastDeltaLocalPos,
509 float &lastGlobalDPtRel,
510 float &lastChi2)
const {
511 if ((
start.momentum().mag() == 0) ||
target.momentum().mag() == 0)
515 float thisLocalPosDiff = (
start.position() -
target.position()).
mag();
517 float thisGlobalMomDeltaPhi = fabs(
deltaPhi(
start.momentum().barePhi(),
target.momentum().barePhi()));
518 float thisGlobalMomDeltaEta = fabs(
start.momentum().eta() -
target.momentum().eta());
519 float thisGlobalDPtRel = (
start.momentum().perp() -
target.momentum().perp()) /
target.momentum().perp();
529 isBest = (thisLocalPosDiff < lastDeltaLocalPos);
532 isBest = (thisGlobalMomDeltaR < lastDeltaR);
535 isBest = (thisGlobalMomDeltaEta < lastDeltaEta);
538 isBest = (thisGlobalMomDeltaPhi < lastDeltaPhi);
541 isBest = (thisGlobalDPtRel < lastGlobalDPtRel);
544 isBest = (thisChi2 < lastChi2);
548 lastDeltaLocalPos = thisLocalPosDiff;
549 lastDeltaR = thisGlobalMomDeltaR;
550 lastDeltaEta = thisGlobalMomDeltaEta;
551 lastDeltaPhi = thisGlobalMomDeltaPhi;
552 lastGlobalDPtRel = thisGlobalDPtRel;
564 bool useFirstMomentum) {
566 throw cms::Exception(
"LogicError") <<
"At least one of the two states must have errors to make chi2s.\n";
568 if (
start.hasError())
569 cov +=
start.curvilinearError().matrix();
570 if (
other.hasError())
571 cov +=
other.curvilinearError().matrix();
576 double pt =
p.perp(), pm =
p.mag();
577 double dsz = (
x1.z() -
x2.z()) *
pt / pm - ((
x1.x() -
x2.x()) *
p.x() + (
x1.y() -
x2.y()) *
p.y()) /
pt *
p.z() / pm;
578 double dxy = (-(
x1.x() -
x2.x()) *
p.y() + (
x1.y() -
x2.y()) *
p.x()) /
pt;
580 p1.theta() -
p2.theta(),
584 return ROOT::Math::Similarity(
diff, cov);
592 throw cms::Exception(
"LogicError") <<
"At least one of the two states must have errors to make chi2s.\n";
595 if (
start.hasError())
597 if (
other.hasError())
598 cov +=
other.perigeeError().covarianceMatrix();
603 return ROOT::Math::Similarity(
diff, cov);
611 throw cms::Exception(
"LogicError") <<
"At least one of the two states must have errors to make chi2s.\n";
613 if (
start.hasError())
614 cov +=
start.localError().matrix();
615 if (
other.hasError())
616 cov +=
other.localError().matrix();
619 return ROOT::Math::Similarity(
diff, cov);
625 for (
size_t i = 0;
i < 5; ++
i) {
626 for (
size_t j =
i + 1;
j < 5; ++
j) {
643 cov.Place_at(momCov, 0, 0);
645 for (
size_t i = 3;
i < 5; ++
i) {
646 for (
size_t j =
i;
j < 5; ++
j) {