Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix and refactor digitization parametrization in Examples #3386

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct GeometricConfig {

/// The charge smearer
ActsFatras::SingleParameterSmearFunction<ActsExamples::RandomEngine>
chargeSmearer = Digitization::Exact{};
chargeSmearer = Digitization::Exact(0);

// The threshold below a cell activation is ignored
double threshold = 0.;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ namespace ActsExamples::Digitization {
/// Exact smearing of a single parameter.
///
struct Exact {
double sigma;

/// Construct with a @param sigma standard deviation
Exact(double sigma_) : sigma{sigma_} {}
andiwand marked this conversation as resolved.
Show resolved Hide resolved

/// Call operator for the SmearFunction caller interface.
///
/// @param value parameter to be smeared
Expand All @@ -35,7 +40,7 @@ struct Exact {
/// the value and a stddev of 0.0
Acts::Result<std::pair<double, double>> operator()(
double value, RandomEngine& /*rnd*/) const {
return std::pair{value, 0.0};
return std::pair{value, sigma};
}
};

Expand All @@ -58,7 +63,7 @@ struct Gauss {
Acts::Result<std::pair<double, double>> 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};
}
};

Expand All @@ -83,12 +88,13 @@ struct GaussTrunc {
/// @return a Result that is ok() when inside range, other DigitizationError
Acts::Result<std::pair<double, double>> 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};
}
};

Expand Down Expand Up @@ -118,11 +124,12 @@ struct GaussClipped {
/// @return a Result that is ok() when inside range, other DigitizationError
Acts::Result<std::pair<double, double>> 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;
Expand Down
5 changes: 3 additions & 2 deletions Examples/Io/Json/src/JsonDigitizationConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ void to_json(nlohmann::json& j, const ActsFatras::SingleParameterSmearFunction<
return;
}
// Exact
auto exact = f.target<const Digitization::Digital>();
andiwand marked this conversation as resolved.
Show resolved Hide resolved
auto exact = f.target<const Digitization::Exact>();
if (exact != nullptr) {
j["type"] = "Exact";
j["stddev"] = exact->sigma;
return;
}

Expand Down Expand Up @@ -102,7 +103,7 @@ void from_json(
from_json(j["bindata"], bd);
f = Digitization::Digital(std::move(bd));
} else if (sType == "Exact") {
f = Digitization::Exact{};
f = Digitization::Exact(j["stddev"]);
} else {
throw std::invalid_argument("Unknown smearer type '" + sType + "'");
}
Expand Down
Loading