All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
energy.h
Go to the documentation of this file.
1 /**
2  * @file lardataalg/Utilities/quantities/energy.h
3  * @brief Dimensioned variables representing energy.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 20, 2020
6  * @see lardataalg/Utilities/quantities.h
7  *
8  * Set of basic quantities related to energy. Currently, quantities
9  * are defined based on the following units:
10  * * electronvolt (meV, eV, keV, MeV, GeV, TeV)
11  *
12  * This is a header-only library.
13  *
14  * @todo Also belong here: joule, watt, eV/c, eV/c^2
15  *
16  */
17 
18 #ifndef LARDATAALG_UTILITIES_QUANTITIES_ENERGY_H
19 #define LARDATAALG_UTILITIES_QUANTITIES_ENERGY_H
20 
21 // LArSoft libraries
23 
24 // C/C++ standard libraries
25 #include <string_view>
26 #include <ratio>
27 
28 
29 //------------------------------------------------------------------------------
30 namespace util::quantities {
31 
32  namespace units {
33 
34  using namespace std::string_view_literals; // for operator""sv()
35 
37  static constexpr auto symbol = "eV"sv;
38  static constexpr auto name = "electronvolt"sv;
39  };
40 
41 
42  } // namespace units
43 
44 
45  // -- BEGIN Particle energy --------------------------------------------------
46  /**
47  * @name Particle energy quantities
48  *
49  * These energy quantities are tied to
50  * `util::quantities::units::ElectronVolt`.
51  * A few options are provided:
52  *
53  * * most general template, `scaled_electronvolt`, allowing to choose both the
54  * scale of the unit (e.g. `std::exa` for exaelectronvolt) and the type of
55  * the numerical representation
56  * * generic templates (e.g. `electronvolt_as`), allowing to choose which
57  * numerical representation to use
58  * * double precision (e.g. `electronvolt`), ready for use
59  *
60  */
61  /// @{
62 
63 
64  /// The most generic `units::ElectronVolt`-based quantity.
65  template <typename R, typename T = double>
68 
69  //
70  // electronvolt
71  //
72  /// Type of energy stored in electronvolt.
73  template <typename T = double>
75 
76  /// Type of energy stored in electronvolts, in double precision.
78 
79  //
80  // microelectronvolt
81  //
82  /// Type of energy stored in microelectronvolt.
83  template <typename T = double>
86 
87  /// Type of energy stored in microelectronvolt, in double precision.
89 
90  //
91  // millielectronvolt
92  //
93  /// Type of energy stored in millielectronvolt.
94  template <typename T = double>
97 
98  /// Type of energy stored in millielectronvolt, in double precision.
100 
101  //
102  // kiloelectronvolt
103  //
104  /// Type of energy stored in kiloelectronvolt.
105  template <typename T = double>
107 
108  /// Type of energy stored in kiloelectronvolt, in double precision.
110 
111  //
112  // megaelectronvolt
113  //
114  /// Type of energy stored in megaelectronvolt.
115  template <typename T = double>
117 
118  /// Type of energy stored in megaelectronvolt, in double precision.
120 
121  //
122  // gigaelectronvolt
123  //
124  /// Type of energy stored in gigaelectronvolt.
125  template <typename T = double>
127 
128  /// Type of energy stored in gigaelectronvolt, in double precision.
130 
131  //
132  // teraelectronvolt
133  //
134  /// Type of energy stored in teraelectronvolt.
135  template <typename T = double>
137 
138  /// Type of energy stored in teraelectronvolt, in double precision.
140 
141  /// @}
142  // -- END Particle energy ----------------------------------------------------
143 
144 
145  /**
146  * @brief Literal constants for energy quantities.
147  *
148  * These functions allow a simplified syntax for specifying a energy quantity.
149  * In order to use these, their namespace must be used:
150  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
151  * using namespace util::quantities::energy_literals;
152  *
153  * // definition of `util::quantities::megaelectronvolt` constant:
154  * constexpr auto muon_MeV = 105.6583745_MeV;
155  *
156  * // assignment (likely to a quantity) of
157  * // `util::quantities::gigaelectronvolt{1.5}`
158  * E = 1.5_GeV;
159  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160  *
161  */
162  namespace energy_literals {
163 
164  // @{
165  /// Literal electronvolt value.
166  constexpr electronvolt operator""_eV (long double v)
167  { return electronvolt{ static_cast<double>(v) }; }
168  constexpr electronvolt operator""_eV (unsigned long long int v)
169  { return electronvolt{ static_cast<double>(v) }; }
170  // @}
171 
172  // @{
173  /// Literal microelectronvolt value.
174  constexpr microelectronvolt operator""_ueV (long double v)
175  { return microelectronvolt{ static_cast<double>(v) }; }
176  constexpr microelectronvolt operator""_ueV (unsigned long long int v)
177  { return microelectronvolt{ static_cast<double>(v) }; }
178  // @}
179 
180  // @{
181  /// Literal millielectronvolt value.
182  constexpr millielectronvolt operator""_meV (long double v)
183  { return millielectronvolt{ static_cast<double>(v) }; }
184  constexpr millielectronvolt operator""_meV (unsigned long long int v)
185  { return millielectronvolt{ static_cast<double>(v) }; }
186  // @}
187 
188  // @{
189  /// Literal kilovolt value.
190  constexpr kiloelectronvolt operator""_keV (long double v)
191  { return kiloelectronvolt{ static_cast<double>(v) }; }
192  constexpr kiloelectronvolt operator""_keV (unsigned long long int v)
193  { return kiloelectronvolt{ static_cast<double>(v) }; }
194  // @}
195 
196  // @{
197  /// Literal megaelectronvolt value.
198  constexpr megaelectronvolt operator""_MeV (long double v)
199  { return megaelectronvolt{ static_cast<double>(v) }; }
200  constexpr megaelectronvolt operator""_MeV (unsigned long long int v)
201  { return megaelectronvolt{ static_cast<double>(v) }; }
202  // @}
203 
204  // @{
205  /// Literal gigaelectronvolt value.
206  constexpr gigaelectronvolt operator""_GeV (long double v)
207  { return gigaelectronvolt{ static_cast<double>(v) }; }
208  constexpr gigaelectronvolt operator""_GeV (unsigned long long int v)
209  { return gigaelectronvolt{ static_cast<double>(v) }; }
210  // @}
211 
212  // @{
213  /// Literal teraelectronvolt value.
214  constexpr teraelectronvolt operator""_TeV (long double v)
215  { return teraelectronvolt{ static_cast<double>(v) }; }
216  constexpr teraelectronvolt operator""_TeV (unsigned long long int v)
217  { return teraelectronvolt{ static_cast<double>(v) }; }
218  // @}
219 
220  } // energy_literals
221 
222 
223 } // namespace util::quantities
224 
225 //------------------------------------------------------------------------------
226 
227 
228 #endif // LARDATAALG_UTILITIES_QUANTITIES_ENERGY_H
BEGIN_PROLOG units
A value measured in the specified unit.
Definition: quantities.h:566
Numeric variable proxies with embedded unit of measurement.
then echo fcl name