Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:07

0001 // TRENTO: Reduced Thickness Event-by-event Nuclear Topology
0002 // Copyright 2015 Jonah E. Bernhard, J. Scott Moreland
0003 // TRENTO3D: Three-dimensional extension of TRENTO by Weiyao Ke
0004 // MIT License
0005 
0006 #ifndef RANDOM_H
0007 #define RANDOM_H
0008 
0009 #include <limits>
0010 #include <random>
0011 
0012 #include <boost/math/constants/constants.hpp>
0013 
0014 #include "fwd_decl.h"
0015 
0016 namespace trento { namespace random {
0017 
0018 /// Mersenne Twister engine, 64-bit preset.
0019 using Engine = std::mt19937_64;
0020 
0021 /// Global variable defined in \c random.cxx.
0022 extern Engine engine;
0023 
0024 /// Helper function to easily generate random numbers in [0, 1).
0025 template <typename RealType = double>
0026 inline RealType canonical() {
0027   return std::generate_canonical
0028            <RealType, std::numeric_limits<RealType>::digits>
0029            (engine);
0030 }
0031 
0032 /// Sample a spherical polar angle cos(theta).
0033 template <typename RealType = double>
0034 inline double cos_theta() {
0035   return 2 * canonical<RealType>() - 1;
0036 }
0037 
0038 /// Sample a spherical azimuthal angle phi.
0039 template <typename RealType = double>
0040 inline double phi() {
0041   return math::constants::two_pi<RealType>() * canonical<RealType>();
0042 }
0043 
0044 }}  // namespace trento::random
0045 
0046 #endif  // RANDOM_H