IAP GITLAB

Skip to content
Snippets Groups Projects
Commit ef16c7ac authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan:
Browse files

Merge branch 'improvements' into 'master'

Improvements

See merge request !134
parents 8176e9d0 0f88736c
No related branches found
No related tags found
1 merge request!134Improvements
Pipeline #803 passed with warnings
...@@ -64,9 +64,13 @@ namespace corsika::environment { ...@@ -64,9 +64,13 @@ namespace corsika::environment {
, fComponents(pComponents) , fComponents(pComponents)
, fAvgMassNumber(std::inner_product( , fAvgMassNumber(std::inner_product(
pComponents.cbegin(), pComponents.cend(), pFractions.cbegin(), 0., pComponents.cbegin(), pComponents.cend(), pFractions.cbegin(), 0.,
[](double x, double y) { return x + y; }, std::plus<double>(), [](auto const compID, auto const fraction) -> double {
[](auto const& compID, auto const& fraction) { if (particles::IsNucleus(compID)) {
return corsika::particles::GetNucleusA(compID) * fraction; return particles::GetNucleusA(compID) * fraction;
} else {
return particles::GetMass(compID) /
units::si::ConvertSIToHEP(units::constants::u) * fraction;
}
})) { })) {
assert(pComponents.size() == pFractions.size()); assert(pComponents.size() == pFractions.size());
auto const sumFractions = auto const sumFractions =
......
...@@ -93,7 +93,7 @@ namespace corsika::particles { ...@@ -93,7 +93,7 @@ namespace corsika::particles {
corsika::units::si::ElectricChargeType constexpr GetCharge(Code const p) { corsika::units::si::ElectricChargeType constexpr GetCharge(Code const p) {
if (p == Code::Nucleus) if (p == Code::Nucleus)
throw std::runtime_error("Cannot GetCharge() of particle::Nucleus -> unspecified"); throw std::runtime_error("Cannot GetCharge() of particle::Nucleus -> unspecified");
return GetChargeNumber(p) * (corsika::units::constants::e); return GetChargeNumber(p) * corsika::units::constants::e;
} }
constexpr std::string const& GetName(Code const p) { constexpr std::string const& GetName(Code const p) {
...@@ -119,10 +119,6 @@ namespace corsika::particles { ...@@ -119,10 +119,6 @@ namespace corsika::particles {
c == Code::NuMuBar || c == Code::NuTauBar; c == Code::NuMuBar || c == Code::NuTauBar;
} }
bool constexpr IsNucleus(Code const p) {
return detail::isNucleus[static_cast<CodeIntType>(p)];
}
int constexpr GetNucleusA(Code const p) { int constexpr GetNucleusA(Code const p) {
return detail::nucleusA[static_cast<CodeIntType>(p)]; return detail::nucleusA[static_cast<CodeIntType>(p)];
} }
...@@ -131,11 +127,13 @@ namespace corsika::particles { ...@@ -131,11 +127,13 @@ namespace corsika::particles {
return detail::nucleusZ[static_cast<CodeIntType>(p)]; return detail::nucleusZ[static_cast<CodeIntType>(p)];
} }
bool constexpr IsNucleus(Code const p) { return GetNucleusA(p) != 0; }
/** /**
* the output operator for particles * the output operator for humand-readable particle codes
**/ **/
std::ostream& operator<<(std::ostream& stream, corsika::particles::Code const p); std::ostream& operator<<(std::ostream&, corsika::particles::Code);
Code ConvertFromPDG(PDGCode); Code ConvertFromPDG(PDGCode);
......
...@@ -369,38 +369,23 @@ def gen_properties(particle_db): ...@@ -369,38 +369,23 @@ def gen_properties(particle_db):
### nuclear data ### ### nuclear data ###
# is nucleus flag
string += "static constexpr std::array<bool, size> isNucleus = {\n"
for p in particle_db.values():
value = 'false'
if p['isNucleus']:
value = 'true'
string += " {val},\n".format(val = value)
string += "};\n"
# nucleus mass number A # nucleus mass number A
string += "static constexpr std::array<int16_t, size> nucleusA = {\n" string += "static constexpr std::array<int16_t, size> nucleusA = {\n"
for p in particle_db.values(): for p in particle_db.values():
A = 0 A = p.get('A', 0)
if p['isNucleus']:
A = p['A']
string += " {val},\n".format(val = A) string += " {val},\n".format(val = A)
string += "};\n" string += "};\n"
# nucleus charge number Z # nucleus charge number Z
string += "static constexpr std::array<int16_t, size> nucleusZ = {\n" string += "static constexpr std::array<int16_t, size> nucleusZ = {\n"
for p in particle_db.values(): for p in particle_db.values():
Z = 0 Z = p.get('Z', 0)
if p['isNucleus']:
Z = p['Z']
string += " {val},\n".format(val = Z) string += " {val},\n".format(val = Z)
string += "};\n" string += "};\n"
return string return string
############################################################### ###############################################################
# #
# return string with a list of classes for all particles # return string with a list of classes for all particles
......
...@@ -33,6 +33,20 @@ std::stringstream corsika::random::RNGManager::dumpState() const { ...@@ -33,6 +33,20 @@ std::stringstream corsika::random::RNGManager::dumpState() const {
return buffer; return buffer;
} }
void corsika::random::RNGManager::SeedAll(uint64_t vSeed) {
for (auto& entry : rngs) { entry.second.seed(vSeed++); }
}
void corsika::random::RNGManager::SeedAll() {
std::random_device rd;
for (auto& entry : rngs) {
std::seed_seq sseq{rd(), rd(), rd(), rd(), rd(), rd()};
entry.second.seed(sseq);
}
}
/* /*
void corsika::random::RNGManager::SetSeedSeq(std::string const& pStreamName, void corsika::random::RNGManager::SetSeedSeq(std::string const& pStreamName,
std::seed_seq const& pSeedSeq) { std::seed_seq const& pSeedSeq) {
......
...@@ -61,6 +61,14 @@ namespace corsika::random { ...@@ -61,6 +61,14 @@ namespace corsika::random {
* set seed_seq of \a pStreamName to \a pSeedSeq * set seed_seq of \a pStreamName to \a pSeedSeq
*/ */
// void SetSeedSeq(std::string const& pStreamName, std::seed_seq& const pSeedSeq); // void SetSeedSeq(std::string const& pStreamName, std::seed_seq& const pSeedSeq);
/**
* Set explicit seeds for all currently registered streams. The actual seed values
* are incremented from \a vSeed.
*/
void SeedAll(uint64_t vSeed);
void SeedAll(); //!< seed all currently registered streams with "real" randomness
}; };
} // namespace corsika::random } // namespace corsika::random
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment