CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
NuclearComposition.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 
13 
14 #include <cassert>
15 #include <functional>
16 #include <numeric>
17 #include <random>
18 #include <stdexcept>
19 #include <vector>
20 
21 namespace corsika {
22 
29  public:
40  NuclearComposition(std::vector<Code> const& pComponents,
41  std::vector<double> const& pFractions);
42 
53  template <typename TFunction>
54  auto getWeighted(TFunction func) const;
55 
67  template <typename TFunction>
68  auto getWeightedSum(TFunction func) const -> decltype(func(std::declval<Code>()));
69 
74  size_t getSize() const;
75 
77  std::vector<double> const& getFractions() const;
79  std::vector<Code> const& getComponents() const;
80  double const getAverageMassNumber() const;
81 
82  template <class TRNG>
83  Code sampleTarget(std::vector<CrossSectionType> const& sigma,
84  TRNG&& randomStream) const;
85 
86  // Note: when this class ever modifies its internal data, the hash
87  // must be updated, too!
88  size_t getHash() const;
89 
91  bool operator==(NuclearComposition const& v) const;
92 
93  private:
94  void updateHash();
95 
96  std::vector<double> const numberFractions_;
97  std::vector<Code> const components_;
98 
99  double const avgMassNumber_;
100 
101  std::size_t hash_;
102  };
103 
104 } // namespace corsika
105 
106 #include <corsika/detail/media/NuclearComposition.inl>
std::vector< double > const & getFractions() const
Returns a const reference to the fraction.
Import and extend the phys::units package.
NuclearComposition(std::vector< Code > const &pComponents, std::vector< double > const &pFractions)
Constructor The constructore takes a list of elements and a list which describe the relative amount...
auto getWeightedSum(TFunction func) const -> decltype(func(std::declval< Code >()))
Sum all all relative composition weighted by func(element) This function sums all relative compositio...
`, since they are used everywhere as integral part of the framework.
std::vector< Code > const & getComponents() const
Returns a const reference to the fraction.
size_t getSize() const
Number of elements in the composition array.
bool operator==(NuclearComposition const &v) const
based on hash value
auto getWeighted(TFunction func) const
Returns a vector of the same length as elements in the material with the weighted return of "func"...
Describes the composition of matter Allowes and handles the creation of custom matter compositions...
Interface to particle properties.