Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Nov 14, 2024
1 parent 25d184c commit 1e7f661
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute(
DigitizedParameters dParameters;

if (simHit.depositedEnergy() < m_cfg.minEnergyDeposit) {
ACTS_VERBOSE("Skip hit because energy deposit to small");
ACTS_VERBOSE("Skip hit because energy deposit too small");
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,24 @@ using RandomEngine = std::mt19937_64; ///< Mersenne Twister
/// The seed type used in the framework.
using RandomSeed = std::uint64_t;

/// Provide event and algorithm specific random number generator.s
class RandomNumbers;

class RandomNumberChannel {
public:
RandomNumberChannel(const RandomNumbers& randomNumbers, RandomSeed seed);

RandomSeed seed() const;

RandomEngine createEngine() const;

RandomNumberChannel createSubChannel(RandomSeed seed) const;

private:
const RandomNumbers* m_randomNumbers = nullptr;
RandomSeed m_seed = 0;
};

/// Provide an event and algorithm specific random number generator.
///
/// This provides local random number generators, allowing for
/// thread-safe, lock-free, and reproducible random number generation across
Expand All @@ -39,6 +56,11 @@ class RandomNumbers {

explicit RandomNumbers(const Config& cfg);

RandomNumberChannel createChannel() const;

RandomNumberChannel createAlgorithmEventChannel(
const AlgorithmContext& context) const;

/// Spawn an algorithm-local random number generator. To avoid inefficiencies
/// and multiple uses of a given RNG seed, this should only be done once per
/// Algorithm invocation, after what the generator object should be reused.
Expand All @@ -48,7 +70,7 @@ class RandomNumbers {
/// @param context is the AlgorithmContext of the host algorithm
RandomEngine spawnGenerator(const AlgorithmContext& context) const;

/// Generate a event and algorithm specific seed value.
/// Generate an event and algorithm specific seed value.
///
/// This should only be used in special cases e.g. where a custom
/// random engine is used and `spawnGenerator` can not be used.
Expand Down
26 changes: 26 additions & 0 deletions Examples/Framework/src/Framework/RandomNumbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,34 @@

namespace ActsExamples {

RandomNumberChannel::RandomNumberChannel(const RandomNumbers& randomNumbers,
RandomSeed seed)
: m_randomNumbers(&randomNumbers), m_seed(seed) {}

RandomSeed RandomNumberChannel::seed() const {
return m_seed;
}

RandomEngine RandomNumberChannel::createEngine() const {
return RandomEngine(m_seed);
}

RandomNumberChannel RandomNumberChannel::createSubChannel(
RandomSeed seed) const {
return RandomNumberChannel(*m_randomNumbers, m_seed + seed);
}

RandomNumbers::RandomNumbers(const Config& cfg) : m_cfg(cfg) {}

RandomNumberChannel RandomNumbers::createChannel() const {
return RandomNumberChannel(*this, m_cfg.seed);
}

RandomNumberChannel RandomNumbers::createAlgorithmEventChannel(
const AlgorithmContext& context) const {
return RandomNumberChannel(*this, generateSeed(context));
}

RandomEngine RandomNumbers::spawnGenerator(
const AlgorithmContext& context) const {
return RandomEngine(generateSeed(context));
Expand Down

0 comments on commit 1e7f661

Please sign in to comment.