Skip to content

Commit

Permalink
use 32 bit for seed
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Nov 13, 2024
1 parent 72aa801 commit 3185410
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute(
measurementParticlesMap.reserve(simHits.size());
measurementSimHitsMap.reserve(simHits.size());

auto eventSeed = m_cfg.randomNumbers->generateSeed(ctx);
RandomSeed eventSeed = m_cfg.randomNumbers->generateSeed(ctx);

// Some statistics
std::size_t skippedHits = 0;
Expand Down Expand Up @@ -216,8 +216,8 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute(
<< " - still forwarding it to the digitizer");
}

auto hitSeed = eventSeed + moduleGeoId.value() +
simHit.particleId().value() + hitIndex;
RandomSeed hitSeed = eventSeed + moduleGeoId.value() +
simHit.particleId().value() + hitIndex;
RandomEngine rng(hitSeed);

DigitizedParameters dParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//
// RandomNumbers.hpp
// ActsExamples
//
// Created by Andreas Salzburger on 17/05/16.
//
//

#pragma once

#include "ActsExamples/Framework/AlgorithmContext.hpp"

#include <cstdint>
#include <random>

Expand All @@ -27,6 +17,9 @@ struct AlgorithmContext;
/// The random number generator used in the framework.
using RandomEngine = std::mt19937; ///< Mersenne Twister

/// The seed type used in the framework.
using RandomSeed = std::uint32_t;

/// Provide event and algorithm specific random number generator.s
///
/// This provides local random number generators, allowing for
Expand All @@ -41,7 +34,7 @@ using RandomEngine = std::mt19937; ///< Mersenne Twister
class RandomNumbers {
public:
struct Config {
std::uint64_t seed = 1234567890u; ///< random seed
RandomSeed seed = 1234567890u; ///< random seed
};

explicit RandomNumbers(const Config& cfg);
Expand All @@ -59,7 +52,7 @@ class RandomNumbers {
///
/// This should only be used in special cases e.g. where a custom
/// random engine is used and `spawnGenerator` can not be used.
std::uint64_t generateSeed(const AlgorithmContext& context) const;
RandomSeed generateSeed(const AlgorithmContext& context) const;

private:
Config m_cfg;
Expand Down
21 changes: 9 additions & 12 deletions Examples/Framework/src/Framework/RandomNumbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//
// RandomNumbers.cpp
// ActsExamples
//
// Created by Andreas Salzburger on 17/05/16.
//
//

#include "ActsExamples/Framework/RandomNumbers.hpp"

#include "ActsExamples/Framework/AlgorithmContext.hpp"

ActsExamples::RandomNumbers::RandomNumbers(const Config& cfg) : m_cfg(cfg) {}
#include <boost/functional/hash.hpp>

ActsExamples::RandomEngine ActsExamples::RandomNumbers::spawnGenerator(
namespace ActsExamples {

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

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

std::uint64_t ActsExamples::RandomNumbers::generateSeed(
const AlgorithmContext& context) const {
RandomSeed RandomNumbers::generateSeed(const AlgorithmContext& context) const {
return m_cfg.seed + context.eventNumber;
}

} // namespace ActsExamples

0 comments on commit 3185410

Please sign in to comment.