EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LandauDistribution.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LandauDistribution.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <random>
12 
13 namespace ActsFatras {
14 
19  public:
21  struct param_type {
24 
28  double location = 0.0;
30  double scale = 1.0;
31 
33  param_type(double location_, double scale_)
34  : location(location_), scale(scale_) {}
35  // Explicitlely defaulted construction and assignment
36  param_type() = default;
37  param_type(const param_type &) = default;
38  param_type(param_type &&) = default;
39  param_type &operator=(const param_type &) = default;
40  param_type &operator=(param_type &&) = default;
41 
43  friend bool operator==(const param_type &lhs, const param_type &rhs) {
44  return (lhs.location == rhs.location) and (lhs.scale == rhs.scale);
45  }
46  friend bool operator!=(const param_type &lhs, const param_type &rhs) {
47  return not(lhs == rhs);
48  }
49  };
51  using result_type = double;
52 
54  LandauDistribution(double location, double scale) : m_cfg(location, scale) {}
56  LandauDistribution(const param_type &cfg) : m_cfg(cfg) {}
57  // Explicitlely defaulted construction and assignment
58  LandauDistribution() = default;
59  LandauDistribution(const LandauDistribution &) = default;
63 
65  void reset() {}
67  param_type param() const { return m_cfg; }
69  void param(const param_type &cfg) { m_cfg = cfg; }
70 
72  result_type min() const { return -std::numeric_limits<double>::infinity(); }
74  result_type max() const { return std::numeric_limits<double>::infinity(); }
75 
77  template <typename Generator>
79  return (*this)(generator, m_cfg);
80  }
82  template <typename Generator>
84  const auto z = std::uniform_real_distribution<double>()(generator);
85  return params.location + params.scale * quantile(z);
86  }
87 
89  friend bool operator==(const LandauDistribution &lhs,
90  const LandauDistribution &rhs) {
91  return lhs.m_cfg == rhs.m_cfg;
92  }
93  friend bool operator!=(const LandauDistribution &lhs,
94  const LandauDistribution &rhs) {
95  return !(lhs == rhs);
96  }
97 
98  private:
100 
101  static double quantile(double z);
102 };
103 
104 } // namespace ActsFatras