Skip to content

Commit

Permalink
Add constructor from initializer lists for cov matrix components
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Apr 30, 2024
1 parent 171a14e commit 0a07c65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions edm4hep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ components:
includes: "#include <edm4hep/utils/cov_matrix_utils.h>"
declaration: "
constexpr CovMatrix2f() = default;\n
template<typename... Vs>\n
constexpr CovMatrix2f(Vs... v) : values{v...} {}\n
constexpr CovMatrix2f(const std::array<float, 3>& v) : values(v) {}\n
constexpr CovMatrix2f& operator=(std::array<float, 3>& v) { values = v; return *this; }\n
bool operator==(const CovMatrix2f& v) const { return v.values == values; }\n
Expand All @@ -143,6 +145,8 @@ components:
declaration: "
constexpr CovMatrix3f() = default;\n
constexpr CovMatrix3f(const std::array<float, 6>& v) : values(v) {}\n
template<typename... Vs>\n
constexpr CovMatrix3f(Vs... v) : values{v...} {}\n
constexpr CovMatrix3f& operator=(std::array<float, 6>& v) { values = v; return *this; }\n
bool operator==(const CovMatrix3f& v) const { return v.values == values; }\n
bool operator!=(const CovMatrix3f& v) const { return v.values != values; }\n
Expand All @@ -157,6 +161,8 @@ components:
includes: "#include <edm4hep/utils/cov_matrix_utils.h>"
declaration: "
constexpr CovMatrix4f() = default;\n
template<typename... Vs>\n
constexpr CovMatrix4f(Vs... v) : values{v...} {}\n
constexpr CovMatrix4f(const std::array<float, 10>& v) : values(v) {}\n
constexpr CovMatrix4f& operator=(std::array<float, 10>& v) { values = v; return *this; }\n
bool operator==(const CovMatrix4f& v) const { return v.values == values; }\n
Expand All @@ -172,6 +178,8 @@ components:
includes: "#include <edm4hep/utils/cov_matrix_utils.h>"
declaration: "
constexpr CovMatrix6f() = default;\n
template<typename... Vs>\n
constexpr CovMatrix6f(Vs... v) : values{v...} {}\n
constexpr CovMatrix6f(const std::array<float, 21>& v) : values(v) {}\n
constexpr CovMatrix6f& operator=(std::array<float, 21>& v) { values = v; return *this; }\n
bool operator==(const CovMatrix6f& v) const { return v.values == values; }\n
Expand Down Expand Up @@ -471,7 +479,6 @@ datatypes:
declaration: "
/// Set the position covariance matrix value for the two passed dimensions\n
void setCovMatrix(float value, edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) { getCovMatrix().setValue(value, dimI, dimJ); }\n
void setCovMatrix(const std::array<float, 6>& values) { getCovMatrix() = values; }
"

#------------- TrackerHitPlane
Expand Down Expand Up @@ -502,7 +509,6 @@ datatypes:
declaration: "
/// Set the position covariance matrix value for the two passed dimensions\n
void setCovMatrix(float value, edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) { getCovMatrix().setValue(value, dimI, dimJ); }\n
void setCovMatrix(const std::array<float, 6>& values) { getCovMatrix() = values; }
"

#---------- RawTimeSeries
Expand Down Expand Up @@ -563,7 +569,6 @@ datatypes:
declaration: "
/// Set the position covariance matrix value for the two passed dimensions\n
void setCovMatrix(float value, edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) { getCovMatrix().setValue(value, dimI, dimJ); }\n
void setCovMatrix(const std::array<float, 6>& values) { getCovMatrix() = values; }
"

#------- ReconstructedParticle
Expand Down Expand Up @@ -605,7 +610,6 @@ datatypes:
void setType(int32_t pdg) { setPDG(pdg); }\n
/// Set the four momentum covariance matrix value for the two passed dimensions\n
void setCovMatrix(float value, edm4hep::FourMomCoords dimI, edm4hep::FourMomCoords dimJ) { getCovMatrix().setValue(value, dimI, dimJ); }\n
void setCovMatrix(const std::array<float, 10>& values) { getCovMatrix() = values; }
"

edm4hep::MCRecoParticleAssociation:
Expand Down
7 changes: 7 additions & 0 deletions test/utils/test_covmatrix_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,11 @@ TEST_CASE("TrackerHit3D covariance", "[cov_matrix_utils]") {

auto hit = edm4hep::TrackerHit3D(trackerHit);
REQUIRE(hit.getCovMatrix(edm4hep::Cartesian::x, edm4hep::Cartesian::z) == 3.14f);

trackerHit.setCovMatrix({1.f, 2.f, 3.f, 4.f, 5.f, 6.f});
REQUIRE(trackerHit.getCovMatrix() == std::array{1.f, 2.f, 3.f, 4.f, 5.f, 6.f});

const std::array arrValues = {6.f, 5.f, 4.f, 3.f, 2.f, 1.f};
trackerHit.setCovMatrix(arrValues);
REQUIRE(trackerHit.getCovMatrix() == std::array{6.f, 5.f, 4.f, 3.f, 2.f, 1.f});
}

0 comments on commit 0a07c65

Please sign in to comment.