CORSIKA8  0.0.0
The framework to simulate particle cascades for astroparticle physics
UniformRealDistribution.hpp
1 /*
2  * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
3  *
4  * This software is distributed under the terms of the GNU General Public
5  * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
6  * the license.
7  */
8 
9 #pragma once
10 
12 #include <random>
13 
14 namespace corsika {
15 
16  template <typename Quantity>
18 
19  typedef typename Quantity::value_type real_type;
20  typedef std::uniform_real_distribution<real_type> distribution_type;
21 
22  public:
23  typedef Quantity value_type;
24 
25  UniformRealDistribution() = delete;
26 
27  UniformRealDistribution(Quantity const& b)
28  : min_{value_type(phys::units::detail::magnitude_tag, 0)}
29  , max_(b) {}
30 
31  UniformRealDistribution(value_type const& pmin, value_type const& pmax)
32  : min_(pmin)
33  , max_(pmax) {}
34 
36  : min_(other.getMin())
37  , max_(other.getMax()) {}
38 
41  if (this == &other) return *this;
42  min_ = other.getMin();
43  max_ = other.getMax();
44  return *this;
45  }
46 
55  value_type getMax() const { return max_; }
56 
65  void setMax(value_type const& pmax) { max_ = pmax; }
66 
75  value_type getMin() const { return min_; }
76 
85  void setMin(value_type const& pmin) { min_ = pmin; }
86 
97  template <class Generator>
98  value_type operator()(Generator& g) {
99  return min_ + dist_(g) * (max_ - min_);
100  }
101 
102  private:
103  distribution_type dist_{real_type(0.), real_type(1.)};
104 
105  value_type min_;
106  value_type max_;
107  };
108 
109 } // namespace corsika
Import and extend the phys::units package.
value_type getMax() const
Get the upper limit.
void setMax(value_type const &pmax)
Set the upper limit.
void setMin(value_type const &pmin)
Set the lower limit.
The cascade namespace assembles all objects needed to simulate full particles cascades.
value_type operator()(Generator &g)
Generate a random numberin the range [min, max].
value_type getMin() const
Get the lower limit.