-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to make track covariance Pos-def in packedcandidate #39599
Changes from 7 commits
71827f6
a4a3ccc
8a17e7c
299b70d
e53f24c
8de7474
192287b
2e6d7ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h" | ||
|
||
#include "DataFormats/Math/interface/liblogintpack.h" | ||
|
||
#include "TMatrixDSym.h" | ||
#include "TVectorD.h" | ||
using namespace logintpack; | ||
|
||
CovarianceParameterization pat::PackedCandidate::covarianceParameterization_; | ||
|
@@ -105,6 +108,7 @@ void pat::PackedCandidate::unpackCovariance() const { | |
unpackCovarianceElement(*m, packedCovariance_.dxydz, 3, 4); | ||
unpackCovarianceElement(*m, packedCovariance_.dlambdadz, 1, 4); | ||
unpackCovarianceElement(*m, packedCovariance_.dphidxy, 2, 3); | ||
|
||
reco::TrackBase::CovarianceMatrix *expected = nullptr; | ||
if (m_.compare_exchange_strong(expected, m.get())) { | ||
m.release(); | ||
|
@@ -161,6 +165,60 @@ float pat::PackedCandidate::dz(const Point &p) const { | |
((vertex_.load()->X() - p.X()) * std::cos(phi) + (vertex_.load()->Y() - p.Y()) * std::sin(phi)) * pzpt; | ||
} | ||
|
||
const reco::Track pat::PackedCandidate::pseudoPosDefTrack() const { | ||
//if (posdeftrack_) return *posdeftrack_; | ||
// perform the regular unpacking of the track | ||
if (!track_) | ||
unpackTrk(); | ||
|
||
// std::cout<<"unpacking enforcing positive-definite cov matrix"<<std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove or add a |
||
//calculate the determinant and verify positivity | ||
double det = 0; | ||
bool notPosDef = (!(*m_).Sub<AlgebraicSymMatrix22>(0, 0).Det(det) || det < 0) || | ||
(!(*m_).Sub<AlgebraicSymMatrix33>(0, 0).Det(det) || det < 0) || | ||
(!(*m_).Sub<AlgebraicSymMatrix44>(0, 0).Det(det) || det < 0) || (!(*m_).Det(det) || det < 0); | ||
|
||
if (notPosDef) { | ||
// std::cout << "during unpacking, the determinant is: " << det << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove or add a |
||
reco::TrackBase::CovarianceMatrix m(*m_); | ||
//if not positive-definite, alter values to allow for pos-def | ||
TMatrixDSym eigenCov(5); | ||
for (int i = 0; i < 5; i++) { | ||
for (int j = 0; j < 5; j++) { | ||
if (std::isnan((m)(i, j)) || std::isinf((m)(i, j))) | ||
eigenCov(i, j) = 1e-6; | ||
else | ||
eigenCov(i, j) = (m)(i, j); | ||
} | ||
} | ||
TVectorD eigenValues(5); | ||
eigenCov.EigenVectors(eigenValues); | ||
double minEigenValue = eigenValues.Min(); | ||
double delta = 1e-6; | ||
if (minEigenValue < 0) { | ||
for (int i = 0; i < 5; i++) | ||
m(i, i) += delta - minEigenValue; | ||
} | ||
|
||
// bool notPosDef = (!m.Sub<AlgebraicSymMatrix22>(0, 0).Det(det) || det < 0) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this line plus the 3 after |
||
// (!m.Sub<AlgebraicSymMatrix33>(0, 0).Det(det) || det < 0) || | ||
// (!m.Sub<AlgebraicSymMatrix44>(0, 0).Det(det) || det < 0) || (!m.Det(det) || det < 0); | ||
// std::cout << " the determinant of the corrected covariance matrix is: " << det << std::endl; | ||
// make a track object with pos def covariance matrix | ||
return reco::Track(normalizedChi2_ * (*track_).ndof(), | ||
(*track_).ndof(), | ||
*vertex_, | ||
(*track_).momentum(), | ||
(*track_).charge(), | ||
m, | ||
reco::TrackBase::undefAlgorithm, | ||
reco::TrackBase::loose); | ||
} else { | ||
// just return a copy of the unpacked track | ||
return reco::Track(*track_); | ||
} | ||
} | ||
|
||
void pat::PackedCandidate::unpackTrk() const { | ||
maybeUnpackBoth(); | ||
math::RhoEtaPhiVector p3(ptTrk(), etaAtVtx(), phiAtVtx()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this line be removed?