Skip to content

Commit 05279ac

Browse files
authored
Add a theta range input (#752)
1 parent c88c85f commit 05279ac

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

examples/options/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,5 @@ target_link_libraries( traccc_options
4949
PUBLIC
5050
Boost::program_options
5151
traccc::io
52-
PRIVATE
5352
traccc::performance
5453
)

examples/options/include/traccc/options/generation.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "traccc/definitions/primitives.hpp"
1212
#include "traccc/options/details/interface.hpp"
1313
#include "traccc/options/details/value_array.hpp"
14+
#include "traccc/utils/ranges.hpp"
1415

1516
// detray include(s).
1617
#include "detray/definitions/pdg_particle.hpp"
@@ -42,6 +43,9 @@ class generation : public interface {
4243
opts::value_array<float, 2> phi_range{-180.f, 180.f};
4344
/// Range of eta
4445
opts::value_array<float, 2> eta_range{-2.f, 2.f};
46+
/// Range of theta [rad] (corresponding to eta range of [-2,2])
47+
opts::value_array<float, 2> theta_range{eta_to_theta_range(eta_range)};
48+
4549
/// PDG number for particle type (Default: muon)
4650
int pdg_number = 13;
4751

@@ -50,8 +54,6 @@ class generation : public interface {
5054
/// @name Derived options
5155
/// @{
5256

53-
/// Range of theta [rad]
54-
opts::value_array<float, 2> theta_range{0.f, 0.f};
5557
/// Particle type
5658
detray::pdg_particle<traccc::scalar> ptc_type =
5759
detray::muon<traccc::scalar>();

examples/options/src/generation.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,35 @@ generation::generation() : interface("Particle Generation Options") {
4949
"gen-eta",
5050
po::value(&eta_range)->value_name("MIN:MAX")->default_value(eta_range),
5151
"Range of eta");
52+
m_desc.add_options()("gen-theta",
53+
po::value(&theta_range)
54+
->value_name("MIN:MAX")
55+
->default_value(theta_range),
56+
"Range of theta in degree");
5257
m_desc.add_options()("particle-type",
5358
po::value<int>(&pdg_number)->default_value(pdg_number),
5459
"PDG number for the particle type");
5560
}
5661

57-
void generation::read(const po::variables_map&) {
62+
void generation::read(const po::variables_map& vm) {
5863

5964
vertex *= detray::unit<float>::mm;
6065
vertex_stddev *= detray::unit<float>::mm;
6166
mom_range *= detray::unit<float>::GeV;
6267
phi_range *= detray::unit<float>::degree;
63-
theta_range = eta_to_theta_range(eta_range);
68+
69+
// The eta and theta range can not be specified at the same time
70+
if (vm.count("gen-eta") && !vm["gen-eta"].defaulted() &&
71+
vm.count("gen-theta") && !vm["gen-theta"].defaulted()) {
72+
throw std::logic_error(
73+
std::string("Conflicting options 'gen-eta' and 'gen-theta'"));
74+
} else if (vm.count("gen-eta") && !vm["gen-eta"].defaulted()) {
75+
theta_range = eta_to_theta_range(eta_range);
76+
} else if (vm.count("gen-theta") && !vm["gen-theta"].defaulted()) {
77+
theta_range *= detray::unit<float>::degree;
78+
eta_range = theta_to_eta_range(theta_range);
79+
}
80+
6481
ptc_type = detail::particle_from_pdg_number<traccc::scalar>(pdg_number);
6582
}
6683

performance/include/traccc/utils/ranges.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2023 CERN for the benefit of the ACTS project
3+
* (c) 2023-2024 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
77

88
#pragma once
99

1010
// Project include(s).
11+
#include "traccc/definitions/math.hpp"
1112
#include "traccc/definitions/qualifiers.hpp"
1213

1314
// System include(s).
@@ -19,8 +20,17 @@ template <typename range_t>
1920
TRACCC_HOST_DEVICE inline range_t eta_to_theta_range(const range_t& eta_range) {
2021
// @NOTE: eta_range[0] is converted to theta_range[1] and eta_range[1]
2122
// to theta_range[0] because theta(minEta) > theta(maxEta)
22-
return {2 * std::atan(std::exp(-eta_range[1])),
23-
2 * std::atan(std::exp(-eta_range[0]))};
23+
return {2.f * math::atan(std::exp(-eta_range[1])),
24+
2.f * math::atan(std::exp(-eta_range[0]))};
25+
}
26+
27+
template <typename range_t>
28+
TRACCC_HOST_DEVICE inline range_t theta_to_eta_range(
29+
const range_t& theta_range) {
30+
// @NOTE: theta_range[0] is converted to eta_range[1] and theta_range[1]
31+
// to eta_range[0]
32+
return {-math::log(math::tan(theta_range[1] * 0.5f)),
33+
-math::log(math::tan(theta_range[0] * 0.5f))};
2434
}
2535

2636
} // namespace traccc

tests/cpu/test_ranges.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2023 CERN for the benefit of the ACTS project
3+
* (c) 2023-2024 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -30,3 +30,16 @@ TEST(ranges, eta_to_theta) {
3030
ASSERT_NEAR(theta_range[1], 170.f * detray::unit<scalar>::degree,
3131
0.1f * detray::unit<scalar>::degree);
3232
}
33+
34+
// Test theta_to_eta_range function
35+
TEST(ranges, theta_to_eta) {
36+
37+
std::array<scalar, 2> theta_range{45.f * detray::unit<scalar>::degree,
38+
175.f * detray::unit<scalar>::degree};
39+
const auto eta_range = theta_to_eta_range(theta_range);
40+
41+
// Comparing with the values provided by
42+
// https://www.star.bnl.gov/~dmitry/calc2.html
43+
ASSERT_NEAR(eta_range[0], -3.131f, 1e-3f);
44+
ASSERT_NEAR(eta_range[1], 0.881f, 1e-3f);
45+
}

0 commit comments

Comments
 (0)