Skip to content
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

Add theta range input #752

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/options/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ target_link_libraries( traccc_options
PUBLIC
Boost::program_options
traccc::io
PRIVATE
traccc::performance
)
6 changes: 4 additions & 2 deletions examples/options/include/traccc/options/generation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "traccc/definitions/primitives.hpp"
#include "traccc/options/details/interface.hpp"
#include "traccc/options/details/value_array.hpp"
#include "traccc/utils/ranges.hpp"

// detray include(s).
#include "detray/definitions/pdg_particle.hpp"
Expand Down Expand Up @@ -42,6 +43,9 @@ class generation : public interface {
opts::value_array<float, 2> phi_range{-180.f, 180.f};
/// Range of eta
opts::value_array<float, 2> eta_range{-2.f, 2.f};
/// Range of theta [rad] (corresponding to eta range of [-2,2])
opts::value_array<float, 2> theta_range{eta_to_theta_range(eta_range)};

/// PDG number for particle type (Default: muon)
int pdg_number = 13;

Expand All @@ -50,8 +54,6 @@ class generation : public interface {
/// @name Derived options
/// @{

/// Range of theta [rad]
opts::value_array<float, 2> theta_range{0.f, 0.f};
/// Particle type
detray::pdg_particle<traccc::scalar> ptc_type =
detray::muon<traccc::scalar>();
Expand Down
21 changes: 19 additions & 2 deletions examples/options/src/generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,35 @@ generation::generation() : interface("Particle Generation Options") {
"gen-eta",
po::value(&eta_range)->value_name("MIN:MAX")->default_value(eta_range),
"Range of eta");
m_desc.add_options()("gen-theta",
po::value(&theta_range)
->value_name("MIN:MAX")
->default_value(theta_range),
"Range of theta in degree");
m_desc.add_options()("particle-type",
po::value<int>(&pdg_number)->default_value(pdg_number),
"PDG number for the particle type");
}

void generation::read(const po::variables_map&) {
void generation::read(const po::variables_map& vm) {

vertex *= detray::unit<float>::mm;
vertex_stddev *= detray::unit<float>::mm;
mom_range *= detray::unit<float>::GeV;
phi_range *= detray::unit<float>::degree;
theta_range = eta_to_theta_range(eta_range);

// The eta and theta range can not be specified at the same time
if (vm.count("gen-eta") && !vm["gen-eta"].defaulted() &&
vm.count("gen-theta") && !vm["gen-theta"].defaulted()) {
throw std::logic_error(
std::string("Conflicting options 'gen-eta' and 'gen-theta'"));
} else if (vm.count("gen-eta") && !vm["gen-eta"].defaulted()) {
theta_range = eta_to_theta_range(eta_range);
} else if (vm.count("gen-theta") && !vm["gen-theta"].defaulted()) {
theta_range *= detray::unit<float>::degree;
eta_range = theta_to_eta_range(theta_range);
}

ptc_type = detail::particle_from_pdg_number<traccc::scalar>(pdg_number);
}

Expand Down
16 changes: 13 additions & 3 deletions performance/include/traccc/utils/ranges.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
* (c) 2023-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s).
#include "traccc/definitions/math.hpp"
#include "traccc/definitions/qualifiers.hpp"

// System include(s).
Expand All @@ -19,8 +20,17 @@ template <typename range_t>
TRACCC_HOST_DEVICE inline range_t eta_to_theta_range(const range_t& eta_range) {
// @NOTE: eta_range[0] is converted to theta_range[1] and eta_range[1]
// to theta_range[0] because theta(minEta) > theta(maxEta)
return {2 * std::atan(std::exp(-eta_range[1])),
2 * std::atan(std::exp(-eta_range[0]))};
return {2.f * math::atan(std::exp(-eta_range[1])),
2.f * math::atan(std::exp(-eta_range[0]))};
}

template <typename range_t>
TRACCC_HOST_DEVICE inline range_t theta_to_eta_range(
const range_t& theta_range) {
// @NOTE: theta_range[0] is converted to eta_range[1] and theta_range[1]
// to eta_range[0]
return {-math::log(math::tan(theta_range[1] * 0.5f)),
-math::log(math::tan(theta_range[0] * 0.5f))};
}

} // namespace traccc
15 changes: 14 additions & 1 deletion tests/cpu/test_ranges.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
* (c) 2023-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -30,3 +30,16 @@ TEST(ranges, eta_to_theta) {
ASSERT_NEAR(theta_range[1], 170.f * detray::unit<scalar>::degree,
0.1f * detray::unit<scalar>::degree);
}

// Test theta_to_eta_range function
TEST(ranges, theta_to_eta) {

std::array<scalar, 2> theta_range{45.f * detray::unit<scalar>::degree,
175.f * detray::unit<scalar>::degree};
const auto eta_range = theta_to_eta_range(theta_range);

// Comparing with the values provided by
// https://www.star.bnl.gov/~dmitry/calc2.html
ASSERT_NEAR(eta_range[0], -3.131f, 1e-3f);
ASSERT_NEAR(eta_range[1], 0.881f, 1e-3f);
}
Loading