diff --git a/Environment/NuclearComposition.h b/Environment/NuclearComposition.h index 491f25a251ed7f6c9d5c1ccbde06ea225e88f47e..d97ba380880ddf018e685d010e688a9f639bd0ac 100644 --- a/Environment/NuclearComposition.h +++ b/Environment/NuclearComposition.h @@ -64,9 +64,13 @@ namespace corsika::environment { , fComponents(pComponents) , fAvgMassNumber(std::inner_product( pComponents.cbegin(), pComponents.cend(), pFractions.cbegin(), 0., - [](double x, double y) { return x + y; }, - [](auto const& compID, auto const& fraction) { - return corsika::particles::GetNucleusA(compID) * fraction; + std::plus<double>(), [](auto const compID, auto const fraction) -> double { + if (particles::IsNucleus(compID)) { + return particles::GetNucleusA(compID) * fraction; + } else { + return particles::GetMass(compID) / + units::si::ConvertSIToHEP(units::constants::u) * fraction; + } })) { assert(pComponents.size() == pFractions.size()); auto const sumFractions = diff --git a/Framework/Particles/ParticleProperties.h b/Framework/Particles/ParticleProperties.h index ba38e7383e06bd5e7b8d4d9e2f56de269d038182..ed0e919b5acce89a7b0573489695a635a0abb104 100644 --- a/Framework/Particles/ParticleProperties.h +++ b/Framework/Particles/ParticleProperties.h @@ -93,7 +93,7 @@ namespace corsika::particles { corsika::units::si::ElectricChargeType constexpr GetCharge(Code const p) { if (p == Code::Nucleus) 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) { @@ -119,10 +119,6 @@ namespace corsika::particles { 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) { return detail::nucleusA[static_cast<CodeIntType>(p)]; } @@ -131,11 +127,13 @@ namespace corsika::particles { 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); diff --git a/Framework/Particles/pdxml_reader.py b/Framework/Particles/pdxml_reader.py index 5c6732475ae0a54048aad7e3328b3a47c0d45e3a..ccb7dfc2378ae201c9f22af7ae5de6aa5e43d88b 100755 --- a/Framework/Particles/pdxml_reader.py +++ b/Framework/Particles/pdxml_reader.py @@ -369,38 +369,23 @@ def gen_properties(particle_db): ### 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 string += "static constexpr std::array<int16_t, size> nucleusA = {\n" for p in particle_db.values(): - A = 0 - if p['isNucleus']: - A = p['A'] + A = p.get('A', 0) string += " {val},\n".format(val = A) string += "};\n" # nucleus charge number Z string += "static constexpr std::array<int16_t, size> nucleusZ = {\n" for p in particle_db.values(): - Z = 0 - if p['isNucleus']: - Z = p['Z'] + Z = p.get('Z', 0) string += " {val},\n".format(val = Z) string += "};\n" return string - - ############################################################### # # return string with a list of classes for all particles diff --git a/Framework/Random/RNGManager.cc b/Framework/Random/RNGManager.cc index ddcccae37171c36c93158af286f85de91a75b6d4..1291dfd44f02300e06bccdcc9f9fc0c376ab2d56 100644 --- a/Framework/Random/RNGManager.cc +++ b/Framework/Random/RNGManager.cc @@ -33,6 +33,20 @@ std::stringstream corsika::random::RNGManager::dumpState() const { 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, std::seed_seq const& pSeedSeq) { diff --git a/Framework/Random/RNGManager.h b/Framework/Random/RNGManager.h index da630c2531a2cb0dc5702dee9b837ba3aa13b99d..5d17a930483f003a8d92397ee055401d8739ac16 100644 --- a/Framework/Random/RNGManager.h +++ b/Framework/Random/RNGManager.h @@ -61,6 +61,14 @@ namespace corsika::random { * set seed_seq of \a pStreamName to \a 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