Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:14

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s).
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/definitions/units.hpp"
0015 #include "detray/utils/axis_rotation.hpp"
0016 #include "detray/utils/unit_vectors.hpp"
0017 
0018 // System include(s).
0019 #include <random>
0020 
0021 namespace detray {
0022 
0023 template <concepts::algebra algebra_t>
0024 struct scattering_helper {
0025  public:
0026   using scalar_type = dscalar<algebra_t>;
0027   using vector3_type = dvector3D<algebra_t>;
0028 
0029   /// @brief Operator to scatter the direction with scattering angle
0030   ///
0031   /// @param dir  input direction
0032   /// @param angle  scattering angle
0033   /// @param generator random generator
0034   /// @returns the new direction from random scattering
0035   template <typename generator_t>
0036   DETRAY_HOST inline vector3_type operator()(const vector3_type& dir,
0037                                              const scalar_type angle,
0038                                              generator_t& generator) const {
0039     // Generate theta and phi for random scattering
0040     const scalar_type r_theta{
0041         angle == 0.f
0042             ? 0.f
0043             : std::normal_distribution<scalar_type>(0.f, angle)(generator)};
0044 
0045     const scalar_type r_phi{std::uniform_real_distribution<scalar_type>(
0046         -constant<scalar_type>::pi, constant<scalar_type>::pi)(generator)};
0047 
0048     // xaxis of curvilinear plane
0049     const vector3_type u =
0050         unit_vectors<vector3_type>().make_curvilinear_unit_u(dir);
0051 
0052     vector3_type new_dir = axis_rotation<algebra_t>(u, r_theta)(dir);
0053     return axis_rotation<algebra_t>(dir, r_phi)(new_dir);
0054   }
0055 };
0056 
0057 }  // namespace detray