From cbacd7189a7d9851c86650f0d292ed4026f43edd Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Thu, 14 Dec 2023 13:13:25 -0500 Subject: [PATCH 01/11] add 4 vector object --- edm4hep.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/edm4hep.yaml b/edm4hep.yaml index 8cd26e84a..6c4a458ca 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -6,6 +6,22 @@ options: includeSubfolder: True components: + + #Vector4f with floats + edm4eic::Vector4f: + Members: + - float x + - float y + - float z + - float t + ExtraCode: + declaration: " + constexpr Vector4f() : x(0),y(0),z(0),t(0) {}\n + constexpr Vector4f(float xx, float yy, float zz, float tt) : x(xx),y(yy),z(zz),t(tt) {}\n + constexpr Vector4f(const float* v) : x(v[0]),y(v[1]),z(v[2]),t(v[3]) {}\n + constexpr bool operator==(const Vector4f& v) const { return (x==v.x&&y==v.y&&z==v.z&&t==v.t) ; }\n + constexpr float operator[](unsigned i) const { return *( &x + i ) ; }\n + " # Vector3D with floats edm4hep::Vector3f: From 5fb224cbcd5cbabb73b078c39ea789d09568bd34 Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Tue, 19 Dec 2023 11:29:50 -0500 Subject: [PATCH 02/11] add description, fix eic namespace --- edm4hep.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index 6c4a458ca..c17fab129 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -8,7 +8,8 @@ options: components: #Vector4f with floats - edm4eic::Vector4f: + edm4hep::Vector4f: + Description: "Generic 4 vector for storing classical 4D coordinates in memory. 4 vector helper functions are in edm4hep::utils" Members: - float x - float y From 8bb56ca26afb634f4d8b3f53400c2ed594622b48 Mon Sep 17 00:00:00 2001 From: Joe Osborn <53052717+osbornjd@users.noreply.github.com> Date: Wed, 20 Dec 2023 08:08:13 -0500 Subject: [PATCH 03/11] Update edm4hep.yaml Co-authored-by: Thomas Madlener --- edm4hep.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index c17fab129..601e599b1 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -9,7 +9,7 @@ components: #Vector4f with floats edm4hep::Vector4f: - Description: "Generic 4 vector for storing classical 4D coordinates in memory. 4 vector helper functions are in edm4hep::utils" + Description: "Generic vector for storing classical 4D coordinates in memory. Four momentum helper functions are in edm4hep::utils" Members: - float x - float y From 289434a65f5724939e08d6a7b99407a747326ea3 Mon Sep 17 00:00:00 2001 From: Joe Osborn <53052717+osbornjd@users.noreply.github.com> Date: Wed, 20 Dec 2023 08:08:21 -0500 Subject: [PATCH 04/11] Update edm4hep.yaml Co-authored-by: Thomas Madlener --- edm4hep.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index 601e599b1..cd48a3ba1 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -7,7 +7,6 @@ options: components: - #Vector4f with floats edm4hep::Vector4f: Description: "Generic vector for storing classical 4D coordinates in memory. Four momentum helper functions are in edm4hep::utils" Members: From 5540d858cedfa98c9dea62f0577c16a8493f4534 Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Wed, 20 Dec 2023 08:32:36 -0500 Subject: [PATCH 05/11] update readme to new links --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 14d4145c4..78fa879fd 100644 --- a/README.md +++ b/README.md @@ -12,30 +12,30 @@ A generic event data model for future HEP collider experiments. | | | | |-|-|-| -| [Vector3f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L11) | [Vector3d](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L26) | [Vector2i](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L42) | -| [Vector2f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L56) | [TrackState](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L70) | [ObjectID](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L93) | -| [Quantity](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L105) | [Hypothesis](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L113) | [HitLevelData](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L120) | +| [Vector4f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L10) | [Vector3f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L27) | [Vector3d](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L42) | [Vector2i](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L58) | +| [Vector2f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L72) | [TrackState](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L86) | [ObjectID](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L109) | +| [Quantity](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L121) | [Hypothesis](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L129) | [HitLevelData](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L136) | **Datatypes** | | | | |-|-|-| -| [EventHeader](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L130) | [MCParticle](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L140) | [SimTrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L209) | -| [CaloHitContribution](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L243) | [SimCalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L255) | [RawCalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L267) | -| [CalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L276) | [ParticleID](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L288) | [Cluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L301) | -| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L322) | [TrackerHitPlane](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L339) | [RawTimeSeries](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L360) | -| [Track](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L373) | [Vertex](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L392) | [ReconstructedParticle](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L409) | -| [SimPrimaryIonizationCluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L513) | [TrackerPulse](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L531) | [RecIonizationCluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L544) | -| [TimeSeries](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L555) | [RecDqdx](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L567) | | +| [EventHeader](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L146) | [MCParticle](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L156) | [SimTrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L225) | +| [CaloHitContribution](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L259) | [SimCalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L271) | [RawCalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L283) | +| [CalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L292) | [ParticleID](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L304) | [Cluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L317) | +| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L338) | [TrackerHitPlane](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L355) | [RawTimeSeries](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L376) | +| [Track](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L389) | [Vertex](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L408) | [ReconstructedParticle](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L425) | +| [SimPrimaryIonizationCluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L529) | [TrackerPulse](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L547) | [RecIonizationCluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L560) | +| [TimeSeries](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L571) | [RecDqdx](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L583) | | **Associations** | | | | |-|-|-| -| [MCRecoParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L439) | [MCRecoCaloAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L448) | [MCRecoTrackerAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L457) | -| [MCRecoTrackerHitPlaneAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L466) | [MCRecoCaloParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L475) | [MCRecoClusterParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L484) | -| [MCRecoTrackParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L493) | [RecoParticleVertexAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L502) | | +| [MCRecoParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L455) | [MCRecoCaloAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L464) | [MCRecoTrackerAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L473) | +| [MCRecoTrackerHitPlaneAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L482) | [MCRecoCaloParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L491) | [MCRecoClusterParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L500) | +| [MCRecoTrackParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L509) | [RecoParticleVertexAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L518) | | The tests and examples in the `tests` directory show how to read, write, and use these types in your code. From e3338b6e0c6e51379e5fc2253ff084adadea976e Mon Sep 17 00:00:00 2001 From: Joe Osborn <53052717+osbornjd@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:54:47 -0500 Subject: [PATCH 06/11] Update edm4hep.yaml Co-authored-by: Thomas Madlener --- edm4hep.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index cd48a3ba1..14cd2983f 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -6,7 +6,6 @@ options: includeSubfolder: True components: - edm4hep::Vector4f: Description: "Generic vector for storing classical 4D coordinates in memory. Four momentum helper functions are in edm4hep::utils" Members: From 92a1d116ef670c0f65cab0aa6dfc2cca7a86c8f3 Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Wed, 20 Dec 2023 12:44:17 -0500 Subject: [PATCH 07/11] Tests pass --- test/utils/test_vector_utils.cpp | 19 ++++-- utils/include/edm4hep/utils/vector_utils.h | 76 ++++++++++++++++++++-- 2 files changed, 84 insertions(+), 11 deletions(-) diff --git a/test/utils/test_vector_utils.cpp b/test/utils/test_vector_utils.cpp index 7cdeb9621..43770d150 100644 --- a/test/utils/test_vector_utils.cpp +++ b/test/utils/test_vector_utils.cpp @@ -8,15 +8,21 @@ #include "edm4hep/Vector2i.h" #include "edm4hep/Vector3d.h" #include "edm4hep/Vector3f.h" +#include "edm4hep/Vector4f.h" #include #include - -using AllVectorTypes = std::tuple; +using Vector2And3Types = std::tuple; +using AllVectorTypes = std::tuple; template constexpr V create(); +template <> +constexpr edm4hep::Vector4f create() { + return edm4hep::Vector4f{1.0f, 2.0f, 3.0f, 4.0f}; +} + template <> constexpr edm4hep::Vector3f create() { return edm4hep::Vector3f{1.0f, 2.0f, 3.0f}; @@ -47,6 +53,8 @@ TEMPLATE_LIST_TEST_CASE("Vector uniform getters", "[vector_utils]", AllVectorTyp // 2D vectors fill z component with 0 if constexpr (std::is_same_v || std::is_same_v) { STATIC_REQUIRE(utils::vector_z(vector) == utils::ValueType(0.0)); + } else if constexpr (std::is_same_v) { + STATIC_REQUIRE(utils::vector_t(vector) == utils::ValueType(4.0)); } else { STATIC_REQUIRE(utils::vector_z(vector) == utils::ValueType(3.0)); } @@ -58,6 +66,7 @@ TEST_CASE("Vector ValueType", "[vector_utils]") { STATIC_REQUIRE(std::is_same_v>); STATIC_REQUIRE(std::is_same_v>); STATIC_REQUIRE(std::is_same_v>); + STATIC_REQUIRE(std::is_same_v>); } TEMPLATE_LIST_TEST_CASE("Vector operators", "[vector_utils]", AllVectorTypes) { @@ -78,12 +87,14 @@ TEMPLATE_LIST_TEST_CASE("Vector operators", "[vector_utils]", AllVectorTypes) { // Vector product (depends again on whether it is 2D or 3D) if constexpr (std::is_same_v || std::is_same_v) { STATIC_REQUIRE(vector1 * vector2 == utils::ValueType(5)); - } else { + } else if constexpr (std::is_same_v || std::is_same_v) { STATIC_REQUIRE(vector1 * vector2 == utils::ValueType(14)); + } else { + STATIC_REQUIRE(vector1 * vector2 == utils::ValueType(-2)); } } -TEMPLATE_LIST_TEST_CASE("Vector utility functionality", "[vector_utils]", AllVectorTypes) { +TEMPLATE_LIST_TEST_CASE("Vector utility functionality", "[vector_utils]", Vector2And3Types) { const auto vector = create(); using namespace edm4hep; diff --git a/utils/include/edm4hep/utils/vector_utils.h b/utils/include/edm4hep/utils/vector_utils.h index e959ae038..942d38603 100644 --- a/utils/include/edm4hep/utils/vector_utils.h +++ b/utils/include/edm4hep/utils/vector_utils.h @@ -28,6 +28,11 @@ concept VectorHasZ = requires(V v) { v.z; }; +template +concept VectorHasT = requires(V v) { + v.t; +}; + template concept VectorHasA = requires(V v) { v.a; @@ -44,22 +49,28 @@ concept ClassVector = requires(V v) { }; template -concept Vector2D_XY = VectorHasX && VectorHasY && !VectorHasZ && !ClassVector; +concept Vector2D_XY = VectorHasX && VectorHasY && !VectorHasZ && !VectorHasT && !ClassVector; template -concept Vector2D_AB = VectorHasA && VectorHasB && !VectorHasZ && !ClassVector; +concept Vector2D_AB = VectorHasA && VectorHasB && !VectorHasZ && !VectorHasT && !ClassVector; template concept Vector2D = Vector2D_XY || Vector2D_AB; template -concept Vector3D = VectorHasX && VectorHasY && VectorHasZ && !ClassVector; +concept Vector3D = VectorHasX && VectorHasY && VectorHasZ && !VectorHasT && !ClassVector; + +template +concept Vector4D = VectorHasX && VectorHasY && VectorHasZ && VectorHasT && !ClassVector; template concept VectorND = Vector2D || Vector3D; template -concept VectorND_XYZ = Vector2D_XY || Vector3D; +concept VectorAD = Vector2D || Vector3D || Vector4D; + +template +concept VectorND_XYZ = Vector2D_XY || Vector3D || Vector4D; namespace utils { // Utility getters to accomodate different vector types @@ -78,6 +89,16 @@ namespace utils { return v.z; } + template + constexpr auto vector_z(const V& v) { + return v.z; + } + + template + constexpr auto vector_t(const V& v) { + return v.t; + } + template constexpr auto vector_x(const V& v) { return v.a; @@ -93,6 +114,16 @@ namespace utils { return 0; } + template + constexpr auto vector_t(const V&) { + return 0; + } + + template + constexpr auto vector_t(const V&) { + return 0; + } + namespace detail { /// Helper struct to determine the underlying type of edm4hep vector types template @@ -158,6 +189,11 @@ namespace utils { return std::hypot(vector_x(v), vector_y(v), vector_z(v)); } + template + double magnitude(const V& v) { + return std::hypot(vector_x(v), vector_y(v), vector_z(v)) - vector_t(v) * vector_t(v); + } + template double magnitudeTransverse(const V& v) { return std::hypot(vector_x(v), vector_y(v)); @@ -222,6 +258,14 @@ inline constexpr V operator+(const V& v1, const V& v2) { edm4hep::utils::vector_z(v1) + edm4hep::utils::vector_z(v2)}; } +template +inline constexpr V operator+(const V& v1, const V& v2) { + return {edm4hep::utils::vector_x(v1) + edm4hep::utils::vector_x(v2), + edm4hep::utils::vector_y(v1) + edm4hep::utils::vector_y(v2), + edm4hep::utils::vector_z(v1) + edm4hep::utils::vector_z(v2), + edm4hep::utils::vector_t(v1) + edm4hep::utils::vector_t(v2)}; +} + template inline constexpr auto operator*(const V& v1, const V& v2) { return edm4hep::utils::vector_x(v1) * edm4hep::utils::vector_x(v2) + @@ -235,6 +279,14 @@ inline constexpr auto operator*(const V& v1, const V& v2) { edm4hep::utils::vector_z(v1) * edm4hep::utils::vector_z(v2); } +template +inline constexpr auto operator*(const V& v1, const V& v2) { + return (edm4hep::utils::vector_x(v1) * edm4hep::utils::vector_x(v2) + + edm4hep::utils::vector_y(v1) * edm4hep::utils::vector_y(v2) + + edm4hep::utils::vector_z(v1) * edm4hep::utils::vector_z(v2)) - + edm4hep::utils::vector_t(v1) * edm4hep::utils::vector_t(v2); +} + template inline constexpr V operator*(const double d, const V& v) { using VT = edm4hep::utils::ValueType; @@ -252,17 +304,27 @@ inline constexpr V operator*(const double d, const V& v) { return {x, y, z}; } -template +template +inline constexpr V operator*(const double d, const V& v) { + using VT = edm4hep::utils::ValueType; + const VT x = d * edm4hep::utils::vector_x(v); + const VT y = d * edm4hep::utils::vector_y(v); + const VT z = d * edm4hep::utils::vector_z(v); + const VT t = d * edm4hep::utils::vector_t(v); + return {x, y, z, t}; +} + +template inline constexpr V operator*(const V& v, const double d) { return d * v; } -template +template inline constexpr V operator-(const V& v1, const V& v2) { return v1 + (-1. * v2); } -template +template inline constexpr V operator/(const V& v, const double d) { return (1. / d) * v; } From f86e384010a77598aebd9559f24e44fdbe62c4e3 Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Wed, 20 Dec 2023 12:55:58 -0500 Subject: [PATCH 08/11] Consolidate some types --- utils/include/edm4hep/utils/vector_utils.h | 41 ++++++++++------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/utils/include/edm4hep/utils/vector_utils.h b/utils/include/edm4hep/utils/vector_utils.h index 942d38603..1a31e3698 100644 --- a/utils/include/edm4hep/utils/vector_utils.h +++ b/utils/include/edm4hep/utils/vector_utils.h @@ -64,10 +64,10 @@ template concept Vector4D = VectorHasX && VectorHasY && VectorHasZ && VectorHasT && !ClassVector; template -concept VectorND = Vector2D || Vector3D; +concept Vector2or3D = Vector2D || Vector3D; template -concept VectorAD = Vector2D || Vector3D || Vector4D; +concept VectorND = Vector2D || Vector3D || Vector4D; template concept VectorND_XYZ = Vector2D_XY || Vector3D || Vector4D; @@ -83,6 +83,11 @@ namespace utils { constexpr auto vector_y(const V& v) { return v.y; } + + template + constexpr auto vector_z(const V&) { + return 0; + } template constexpr auto vector_z(const V& v) { @@ -99,6 +104,11 @@ namespace utils { return v.t; } + template + constexpr auto vector_t(const V&) { + return 0; + } + template constexpr auto vector_x(const V& v) { return v.a; @@ -109,21 +119,6 @@ namespace utils { return v.b; } - template - constexpr auto vector_z(const V&) { - return 0; - } - - template - constexpr auto vector_t(const V&) { - return 0; - } - - template - constexpr auto vector_t(const V&) { - return 0; - } - namespace detail { /// Helper struct to determine the underlying type of edm4hep vector types template @@ -184,7 +179,7 @@ namespace utils { return angleToEta(anglePolar(v)); } - template + template double magnitude(const V& v) { return std::hypot(vector_x(v), vector_y(v), vector_z(v)); } @@ -224,7 +219,7 @@ namespace utils { } // Two vector functions - template + template double angleBetween(const V& v1, const V& v2) { const double dot = v1 * v2; if (dot == 0) { @@ -234,7 +229,7 @@ namespace utils { } // Project v onto v1 - template + template double projection(const V& v, const V& v1) { const double norm = magnitude(v1); if (norm == 0) { @@ -314,17 +309,17 @@ inline constexpr V operator*(const double d, const V& v) { return {x, y, z, t}; } -template +template inline constexpr V operator*(const V& v, const double d) { return d * v; } -template +template inline constexpr V operator-(const V& v1, const V& v2) { return v1 + (-1. * v2); } -template +template inline constexpr V operator/(const V& v, const double d) { return (1. / d) * v; } From 8cb3cfa81e3e93616876dad52889c7da4aa3b246 Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Wed, 20 Dec 2023 15:26:58 -0500 Subject: [PATCH 09/11] fix readme --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 78fa879fd..529b4fe42 100644 --- a/README.md +++ b/README.md @@ -12,30 +12,30 @@ A generic event data model for future HEP collider experiments. | | | | |-|-|-| -| [Vector4f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L10) | [Vector3f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L27) | [Vector3d](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L42) | [Vector2i](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L58) | -| [Vector2f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L72) | [TrackState](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L86) | [ObjectID](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L109) | -| [Quantity](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L121) | [Hypothesis](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L129) | [HitLevelData](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L136) | +| [Vector4f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L9) | [Vector3f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L26) | [Vector3d](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L41) | [Vector2i](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L57) | +| [Vector2f](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L71) | [TrackState](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L85) | [ObjectID](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L108) | +| [Quantity](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L120) | [Hypothesis](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L128) | [HitLevelData](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L135) | **Datatypes** | | | | |-|-|-| -| [EventHeader](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L146) | [MCParticle](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L156) | [SimTrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L225) | -| [CaloHitContribution](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L259) | [SimCalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L271) | [RawCalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L283) | -| [CalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L292) | [ParticleID](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L304) | [Cluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L317) | -| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L338) | [TrackerHitPlane](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L355) | [RawTimeSeries](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L376) | -| [Track](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L389) | [Vertex](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L408) | [ReconstructedParticle](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L425) | -| [SimPrimaryIonizationCluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L529) | [TrackerPulse](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L547) | [RecIonizationCluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L560) | -| [TimeSeries](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L571) | [RecDqdx](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L583) | | +| [EventHeader](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L145) | [MCParticle](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L155) | [SimTrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L224) | +| [CaloHitContribution](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L258) | [SimCalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L270) | [RawCalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L282) | +| [CalorimeterHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L291) | [ParticleID](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L303) | [Cluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L316) | +| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L337) | [TrackerHitPlane](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L354) | [RawTimeSeries](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L375) | +| [Track](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L388) | [Vertex](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L407) | [ReconstructedParticle](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L424) | +| [SimPrimaryIonizationCluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L528) | [TrackerPulse](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L546) | [RecIonizationCluster](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L559) | +| [TimeSeries](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L570) | [RecDqdx](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L582) | | **Associations** | | | | |-|-|-| -| [MCRecoParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L455) | [MCRecoCaloAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L464) | [MCRecoTrackerAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L473) | -| [MCRecoTrackerHitPlaneAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L482) | [MCRecoCaloParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L491) | [MCRecoClusterParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L500) | -| [MCRecoTrackParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L509) | [RecoParticleVertexAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L518) | | +| [MCRecoParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L454) | [MCRecoCaloAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L463) | [MCRecoTrackerAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L472) | +| [MCRecoTrackerHitPlaneAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L481) | [MCRecoCaloParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L490) | [MCRecoClusterParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L499) | +| [MCRecoTrackParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L508) | [RecoParticleVertexAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L517) | | The tests and examples in the `tests` directory show how to read, write, and use these types in your code. From cf59c55f28c56c6d76255837ce8a94eb8734516a Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Wed, 20 Dec 2023 15:57:33 -0500 Subject: [PATCH 10/11] clang-format --- test/utils/test_vector_utils.cpp | 3 ++- utils/include/edm4hep/utils/vector_utils.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/utils/test_vector_utils.cpp b/test/utils/test_vector_utils.cpp index 43770d150..c01975c17 100644 --- a/test/utils/test_vector_utils.cpp +++ b/test/utils/test_vector_utils.cpp @@ -13,7 +13,8 @@ #include #include using Vector2And3Types = std::tuple; -using AllVectorTypes = std::tuple; +using AllVectorTypes = + std::tuple; template constexpr V create(); diff --git a/utils/include/edm4hep/utils/vector_utils.h b/utils/include/edm4hep/utils/vector_utils.h index 1a31e3698..48b5b6cf8 100644 --- a/utils/include/edm4hep/utils/vector_utils.h +++ b/utils/include/edm4hep/utils/vector_utils.h @@ -83,7 +83,7 @@ namespace utils { constexpr auto vector_y(const V& v) { return v.y; } - + template constexpr auto vector_z(const V&) { return 0; From 33d9b6db9b82b6cdd770aba1e1339e5ff6be216e Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Thu, 21 Dec 2023 09:56:06 -0500 Subject: [PATCH 11/11] update c++17 vector util operators --- .../edm4hep/utils/vector_utils_legacy.h | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/utils/include/edm4hep/utils/vector_utils_legacy.h b/utils/include/edm4hep/utils/vector_utils_legacy.h index 8f6225035..3bb68fa1a 100644 --- a/utils/include/edm4hep/utils/vector_utils_legacy.h +++ b/utils/include/edm4hep/utils/vector_utils_legacy.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,11 @@ namespace utils { return v.z; } + template + constexpr auto vector_t(const V& v) { + return v.t; + } + // 2D vector uses a,b instead of x,y template <> inline constexpr auto vector_x(const edm4hep::Vector2i& v) { @@ -98,6 +104,7 @@ namespace utils { using ValueType = typename detail::ValueTypeHelper::type; using EDM4hepVectorTypes = std::tuple; + using EDM4hepVector4DTypes = std::tuple; using EDM4hepVector3DTypes = std::tuple; using EDM4hepVector2DTypes = std::tuple; using EDM4hepFloatVectorTypes = std::tuple; @@ -111,6 +118,8 @@ namespace utils { template using EnableIfEDM4hepVector3DType = std::enable_if_t, bool>; + template + using EnableIfEdm4hepVector4DType = std::enable_if_t, bool>; template using EnableIfEDM4hepFloatVectorType = std::enable_if_t, bool>; @@ -218,6 +227,15 @@ inline constexpr V operator+(const V& v1, const V& v2) { return {x, y, z}; } +template = false> +inline constexpr V operator+(const V& v1, const V& v2) { + const auto x = edm4hep::utils::vector_x(v1) + edm4hep::utils::vector_x(v2); + const auto y = edm4hep::utils::vector_y(v1) + edm4hep::utils::vector_y(v2); + const auto z = edm4hep::utils::vector_z(v1) + edm4hep::utils::vector_z(v2); + const auto t = edm4hep::utils::vector_t(v1) + edm4hep::utils::vector_t(v2); + return {x, y, z, t}; +} + template = false> inline constexpr double operator*(const V& v1, const V& v2) { return edm4hep::utils::vector_x(v1) * edm4hep::utils::vector_x(v2) + @@ -231,6 +249,14 @@ inline constexpr double operator*(const V& v1, const V& v2) { edm4hep::utils::vector_z(v1) * edm4hep::utils::vector_z(v2); } +template = false> +inline constexpr double operator*(const V& v1, const V& v2) { + return (edm4hep::utils::vector_x(v1) * edm4hep::utils::vector_x(v2) + + edm4hep::utils::vector_y(v1) * edm4hep::utils::vector_y(v2) + + edm4hep::utils::vector_z(v1) * edm4hep::utils::vector_z(v2)) - + edm4hep::utils::vector_t(v1) * edm4hep::utils::vector_t(v2); +} + template = false> inline constexpr V operator*(const double d, const V& v) { using VT = edm4hep::utils::ValueType; @@ -248,6 +274,16 @@ inline constexpr V operator*(const double d, const V& v) { return {x, y, z}; } +template = false> +inline constexpr V operator*(const double d, const V& v) { + using VT = edm4hep::utils::ValueType; + const VT x = d * edm4hep::utils::vector_x(v); + const VT y = d * edm4hep::utils::vector_y(v); + const VT z = d * edm4hep::utils::vector_z(v); + const VT t = d * edm4hep::utils::vector_t(v); + return {x, y, z, t}; +} + template inline constexpr V operator*(const V& v, const double d) { return d * v;