Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:45:49

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/HelloWorld/HelloRandomAlgorithm.hpp"
0010 
0011 #include "ActsExamples/Framework/RandomNumbers.hpp"
0012 
0013 #include <random>
0014 
0015 namespace ActsExamples {
0016 
0017 HelloRandomAlgorithm::HelloRandomAlgorithm(
0018     const HelloRandomAlgorithm::Config& cfg,
0019     std::unique_ptr<const Acts::Logger> logger)
0020     : IAlgorithm("HelloRandom", std::move(logger)), m_cfg(cfg) {
0021   if (!m_cfg.randomNumbers) {
0022     throw std::invalid_argument("Missing random number service");
0023   }
0024   if (m_cfg.output.empty()) {
0025     throw std::invalid_argument("Missing output collection");
0026   }
0027   m_writeHandle.initialize(m_cfg.output);
0028 }
0029 
0030 ProcessCode HelloRandomAlgorithm::execute(const AlgorithmContext& ctx) const {
0031   ACTS_INFO("Running random number generation");
0032 
0033   // Create the local random number generator
0034   RandomEngine rng = m_cfg.randomNumbers->spawnGenerator(ctx);
0035 
0036   // Spawn some random number distributions
0037   std::normal_distribution<> gaussDist(m_cfg.gaussParameters[0],
0038                                        m_cfg.gaussParameters[1]);
0039   std::uniform_real_distribution<> uniformDist(m_cfg.uniformParameters[0],
0040                                                m_cfg.uniformParameters[1]);
0041   std::gamma_distribution<> gammaDist(m_cfg.gammaParameters[0],
0042                                       m_cfg.gammaParameters[1]);
0043   std::poisson_distribution<> poissonDist(m_cfg.poissonParameter);
0044 
0045   ACTS_INFO(m_cfg.drawsPerEvent << " draws per event will be done");
0046 
0047   // generate collection of random numbers
0048   HelloDataCollection collection;
0049   for (std::size_t idraw = 0; idraw < m_cfg.drawsPerEvent; ++idraw) {
0050     double gauss = gaussDist(rng);
0051     double uniform = uniformDist(rng);
0052     double gamma = gammaDist(rng);
0053     int poisson = poissonDist(rng);
0054 
0055     ACTS_VERBOSE("Gauss   : " << gauss);
0056     ACTS_VERBOSE("Uniform : " << uniform);
0057     ACTS_VERBOSE("Gamma   : " << gamma);
0058     ACTS_VERBOSE("Poisson : " << poisson);
0059 
0060     HelloData x{};
0061     x.x = gauss;
0062     x.a = uniform;
0063     x.b = gamma;
0064     x.t = poisson;
0065     collection.push_back(x);
0066   }
0067 
0068   // transfer generated data to the event store.
0069   m_writeHandle(ctx, std::move(collection));
0070 
0071   return ProcessCode::SUCCESS;
0072 }
0073 
0074 }  // namespace ActsExamples