diff --git a/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/DigitizationConfig.hpp b/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/DigitizationConfig.hpp index bea13649440..5f1088d4c58 100644 --- a/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/DigitizationConfig.hpp +++ b/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/DigitizationConfig.hpp @@ -60,7 +60,7 @@ struct GeometricConfig { /// The charge smearer ActsFatras::SingleParameterSmearFunction - chargeSmearer = Digitization::Exact{}; + chargeSmearer = Digitization::Exact(0); // The threshold below a cell activation is ignored double threshold = 0.; diff --git a/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/Smearers.hpp b/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/Smearers.hpp index 1305ea657b8..416a9a85abe 100644 --- a/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/Smearers.hpp +++ b/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/Smearers.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2020 CERN for the benefit of the Acts project +// Copyright (C) 2020-2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -26,6 +26,11 @@ namespace ActsExamples::Digitization { /// Exact smearing of a single parameter. /// struct Exact { + double sigma; + + /// Construct with a @param sigma standard deviation + explicit Exact(double sigma_) : sigma{sigma_} {} + /// Call operator for the SmearFunction caller interface. /// /// @param value parameter to be smeared @@ -35,7 +40,7 @@ struct Exact { /// the value and a stddev of 0.0 Acts::Result> operator()( double value, RandomEngine& /*rnd*/) const { - return std::pair{value, 0.0}; + return std::pair{value, sigma}; } }; @@ -47,7 +52,7 @@ struct Gauss { double sigma; /// Construct with a @param sigma standard deviation - Gauss(double sigma_) : sigma{sigma_} {} + explicit Gauss(double sigma_) : sigma{sigma_} {} /// Call operator for the SmearFunction caller interface. /// @@ -58,7 +63,7 @@ struct Gauss { Acts::Result> operator()(double value, RandomEngine& rnd) const { std::normal_distribution<> dist{0, sigma}; - return std::pair{value + dist(rnd), dist.stddev()}; + return std::pair{value + dist(rnd), sigma}; } }; @@ -83,12 +88,13 @@ struct GaussTrunc { /// @return a Result that is ok() when inside range, other DigitizationError Acts::Result> operator()(double value, RandomEngine& rnd) const { - std::normal_distribution<> dist{0., sigma}; - double svalue = value + dist(rnd); - if (svalue >= range.first && svalue <= range.second) { - return std::pair{svalue, dist.stddev()}; + std::normal_distribution<> dist{0., 1}; + double x = dist(rnd); + if (x < range.first || x > range.second) { + return ActsFatras::DigitizationError::SmearingOutOfRange; } - return ActsFatras::DigitizationError::SmearingOutOfRange; + double svalue = value + sigma * x; + return std::pair{svalue, sigma}; } }; @@ -118,11 +124,12 @@ struct GaussClipped { /// @return a Result that is ok() when inside range, other DigitizationError Acts::Result> operator()(double value, RandomEngine& rnd) const { - std::normal_distribution<> dist{0., sigma}; + std::normal_distribution<> dist{0., 1}; for (std::size_t attempt = 0; attempt < maxAttemps; ++attempt) { - double svalue = value + dist(rnd); - if (svalue >= range.first && svalue <= range.second) { - return std::pair{svalue, dist.stddev()}; + double x = dist(rnd); + if (x >= range.first && x <= range.second) { + double svalue = value + sigma * x; + return std::pair{svalue, sigma}; } } return ActsFatras::DigitizationError::SmearingError; @@ -145,7 +152,7 @@ struct Uniform { /// Constructor with a binning data in order to get the bin borders. /// /// @param bu the binning data - Uniform(Acts::BinningData&& bd) : binningData(bd) {} + explicit Uniform(const Acts::BinningData& bd) : binningData(bd) {} /// Call operator for the SmearFunction caller interface. /// @@ -183,7 +190,7 @@ struct Digital { /// Constructor with a bin utility in order to get the bin borders. /// /// @param bu the bin utility within hich the parameter is allowed - Digital(Acts::BinningData&& bd) : binningData(bd) {} + explicit Digital(const Acts::BinningData& bd) : binningData(bd) {} /// Call operator for the SmearFunction caller interface. /// diff --git a/Examples/Io/Json/src/JsonDigitizationConfig.cpp b/Examples/Io/Json/src/JsonDigitizationConfig.cpp index 6d633463277..5e1d6b684ff 100644 --- a/Examples/Io/Json/src/JsonDigitizationConfig.cpp +++ b/Examples/Io/Json/src/JsonDigitizationConfig.cpp @@ -69,9 +69,10 @@ void to_json(nlohmann::json& j, const ActsFatras::SingleParameterSmearFunction< return; } // Exact - auto exact = f.target(); + auto exact = f.target(); if (exact != nullptr) { j["type"] = "Exact"; + j["stddev"] = exact->sigma; return; } @@ -96,13 +97,13 @@ void from_json( } else if (sType == "Uniform") { Acts::BinningData bd; from_json(j["bindata"], bd); - f = Digitization::Uniform(std::move(bd)); + f = Digitization::Uniform(bd); } else if (sType == "Digitial") { Acts::BinningData bd; from_json(j["bindata"], bd); - f = Digitization::Digital(std::move(bd)); + f = Digitization::Digital(bd); } else if (sType == "Exact") { - f = Digitization::Exact{}; + f = Digitization::Exact(j["stddev"]); } else { throw std::invalid_argument("Unknown smearer type '" + sType + "'"); }