From 7fe5c99069bfa02f85ce8d5201e59a7683a194d2 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 30 Oct 2023 01:34:48 +0100 Subject: [PATCH] Add pT related functions --- .../detray/tracks/bound_track_parameters.hpp | 8 ++++++++ .../detray/tracks/detail/track_helper.hpp | 16 ++++++++++++++++ .../detray/tracks/free_track_parameters.hpp | 3 +++ tests/unit_tests/cpu/tools_track.cpp | 7 +++++++ 4 files changed, 34 insertions(+) diff --git a/core/include/detray/tracks/bound_track_parameters.hpp b/core/include/detray/tracks/bound_track_parameters.hpp index bcfeb8e42..870b65dc7 100644 --- a/core/include/detray/tracks/bound_track_parameters.hpp +++ b/core/include/detray/tracks/bound_track_parameters.hpp @@ -142,12 +142,20 @@ struct bound_track_parameters { matrix_operator().element(m_vector, e_bound_qoverp, 0u) = qop; } + DETRAY_HOST_DEVICE + scalar_type qopT() const { return track_helper().qopT(m_vector); } + DETRAY_HOST_DEVICE scalar_type p() const { return track_helper().p(m_vector); } DETRAY_HOST_DEVICE vector3 mom() const { return track_helper().mom(m_vector); } + DETRAY_HOST_DEVICE + scalar_type pT() const { + return std::abs(1.f / this->qop() * getter::perp(this->dir())); + } + private: geometry::barcode m_barcode; vector_type m_vector; diff --git a/core/include/detray/tracks/detail/track_helper.hpp b/core/include/detray/tracks/detail/track_helper.hpp index e6a6ba836..9ec5d711f 100644 --- a/core/include/detray/tracks/detail/track_helper.hpp +++ b/core/include/detray/tracks/detail/track_helper.hpp @@ -121,6 +121,22 @@ struct track_helper { return matrix_operator().element(bound_vec, e_bound_qoverp, 0u); } + DETRAY_HOST_DEVICE + inline scalar_type qopT(const free_vector& free_vec) const { + const auto dir = this->dir(free_vec); + return matrix_operator().element(free_vec, e_free_qoverp, 0u) / + getter::perp(dir); + } + + DETRAY_HOST_DEVICE + inline scalar_type qopT(const bound_vector& bound_vec) const { + const scalar_type theta{ + matrix_operator().element(bound_vec, e_bound_theta, 0u)}; + const scalar_type sinTheta{math_ns::sin(theta)}; + return matrix_operator().element(bound_vec, e_bound_qoverp, 0u) / + sinTheta; + } + DETRAY_HOST_DEVICE inline scalar_type time(const free_vector& free_vec) const { return matrix_operator().element(free_vec, e_free_time, 0u); diff --git a/core/include/detray/tracks/free_track_parameters.hpp b/core/include/detray/tracks/free_track_parameters.hpp index 84df5cc78..8bfbab145 100644 --- a/core/include/detray/tracks/free_track_parameters.hpp +++ b/core/include/detray/tracks/free_track_parameters.hpp @@ -144,6 +144,9 @@ struct free_track_parameters { matrix_operator().element(m_vector, e_free_qoverp, 0u) = qop; } + DETRAY_HOST_DEVICE + scalar_type qopT() const { return track_helper().qopT(m_vector); } + DETRAY_HOST_DEVICE scalar_type p() const { return track_helper().p(m_vector); } diff --git a/tests/unit_tests/cpu/tools_track.cpp b/tests/unit_tests/cpu/tools_track.cpp index d20f2c667..9420d4278 100644 --- a/tests/unit_tests/cpu/tools_track.cpp +++ b/tests/unit_tests/cpu/tools_track.cpp @@ -53,6 +53,12 @@ GTEST_TEST(detray_tracks, bound_track_parameters) { bound_track_parameters bound_param1( geometry::barcode{}.set_index(sf_idx1), bound_vec1, bound_cov1); + EXPECT_NEAR(bound_param1.pT(), + 1.f / + std::abs(getter::element(bound_vec1, e_bound_qoverp, 0u)) * + std::sin(getter::element(bound_vec1, e_bound_theta, 0u)), + tol); + EXPECT_NEAR(bound_param1.qopT(), -1.f / bound_param1.pT(), tol); // second track dindex sf_idx2 = 1u; @@ -171,6 +177,7 @@ GTEST_TEST(detray_tracks, free_track_parameters) { tol); EXPECT_NEAR(free_param1.pT(), std::sqrt(std::pow(mom[0], 2.f) + std::pow(mom[1], 2.f)), tol); + EXPECT_NEAR(free_param1.qopT(), charge / free_param1.pT(), tol); EXPECT_NEAR(free_param1.mom()[0], free_param1.p() * free_param1.dir()[0], tol); EXPECT_NEAR(free_param1.mom()[1], free_param1.p() * free_param1.dir()[1],