Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 07:52:21

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 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "ActsExamples/Framework/RandomNumbers.hpp"
0013 
0014 #include <numbers>
0015 #include <random>
0016 
0017 namespace ActsExamples {
0018 
0019 /// @brief Generator interface for a vertex position
0020 struct PrimaryVertexPositionGenerator {
0021   /// @brief Virtual destructor required
0022   virtual ~PrimaryVertexPositionGenerator() = default;
0023   /// @brief Generate a vertex position
0024   ///
0025   /// @param rng Shared random number generator instance
0026   /// @return Acts::Vector4 The vertex position
0027   virtual Acts::Vector4 operator()(RandomEngine& rng) const = 0;
0028 };
0029 
0030 struct FixedPrimaryVertexPositionGenerator
0031     : public PrimaryVertexPositionGenerator {
0032   /// The fixed vertex position and time.
0033   Acts::Vector4 fixed = Acts::Vector4::Zero();
0034 
0035   Acts::Vector4 operator()(RandomEngine& /*rng*/) const override {
0036     return fixed;
0037   }
0038 };
0039 
0040 struct GaussianPrimaryVertexPositionGenerator
0041     : public PrimaryVertexPositionGenerator {
0042   // standard deviation comes first, since it is more likely to be modified
0043   /// Vertex position and time standard deviation.
0044   Acts::Vector4 stddev = {0.0, 0.0, 0.0, 0.0};
0045   /// Mean vertex position and time.
0046   Acts::Vector4 mean = {0.0, 0.0, 0.0, 0.0};
0047 
0048   Acts::Vector4 operator()(RandomEngine& rng) const override {
0049     auto normal = std::normal_distribution<double>(0.0, 1.0);
0050     Acts::Vector4 rndNormal = {
0051         normal(rng),
0052         normal(rng),
0053         normal(rng),
0054         normal(rng),
0055     };
0056     return mean + rndNormal.cwiseProduct(stddev);
0057   }
0058 };
0059 
0060 //
0061 struct GaussianDisplacedVertexPositionGenerator
0062     : public PrimaryVertexPositionGenerator {
0063   double rMean = 0;
0064   double rStdDev = 1;
0065   double zMean = 0;
0066   double zStdDev = 1;
0067   double tMean = 0;
0068   double tStdDev = 1;
0069 
0070   Acts::Vector4 operator()(RandomEngine& rng) const override {
0071     double min_value = -std::numbers::pi;
0072     double max_value = std::numbers::pi;
0073 
0074     std::uniform_real_distribution uniform(min_value, max_value);
0075 
0076     std::normal_distribution rDist(rMean, rStdDev);
0077     std::normal_distribution zDist(zMean, zStdDev);
0078     std::normal_distribution tDist(tMean, tStdDev);
0079 
0080     // Generate random values from normal distributions
0081     double r = rDist(rng);
0082     double phi = uniform(rng);  // Random angle in radians
0083     double z = zDist(rng);
0084     double t = tDist(rng);
0085 
0086     // Convert cylindrical coordinates to Cartesian coordinates
0087     double x = r * std::cos(phi);
0088     double y = r * std::sin(phi);
0089 
0090     return Acts::Vector4(x, y, z, t);
0091   }
0092 };
0093 }  // namespace ActsExamples