Skip to content

Commit

Permalink
refactor: Remove the SmearingAlgorithm (#1041)
Browse files Browse the repository at this point in the history
The SmearingAlgorithm is obsoleted by the hybrid DigitizationAlgorithm, therefore this PR removes it enterely.

in #955, the issue of documenting the new .json format was raised. I have created a WIP PR, #1040, which adds a python script that uses the old cli switches to bootstrap a .json file, if we want to to this route.

closes #955
  • Loading branch information
gagnonlg committed Oct 15, 2021
1 parent 38e1591 commit a76a3fc
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 507 deletions.
1 change: 0 additions & 1 deletion Examples/Algorithms/Digitization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ add_library(
src/DigitizationConfig.cpp
src/MeasurementCreation.cpp
src/PlanarSteppingAlgorithm.cpp
src/SmearingAlgorithm.cpp
src/DigitizationOptions.cpp
src/ModuleClusters.cpp)
target_include_directories(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ class DigitizationConfig {
std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry = nullptr;
/// Random numbers tool.
std::shared_ptr<const RandomNumbers> randomNumbers = nullptr;
/// Was the simple smearer requested
const bool isSimpleSmearer;
/// Do we merge hits or not
const bool doMerge;
/// How close do parameters have to be to consider merged
Expand All @@ -141,13 +139,5 @@ class DigitizationConfig {
std::vector<
std::pair<Acts::GeometryIdentifier, std::vector<Acts::BoundIndices>>>
getBoundIndices() const;

private:
// Private initializer for SmearingAlgorithm
void smearingConfig(const Options::Variables &vars);
};

std::shared_ptr<ActsExamples::IAlgorithm> createDigitizationAlgorithm(
DigitizationConfig &cfg, Acts::Logging::Level lvl);

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "ActsExamples/Digitization/DigitizationAlgorithm.hpp"
#include "ActsExamples/Digitization/DigitizationConfig.hpp"
#include "ActsExamples/Digitization/DigitizationOptions.hpp"
#include "ActsExamples/Digitization/SmearingAlgorithm.hpp"

#include <map>
#include <memory>
Expand Down Expand Up @@ -285,4 +284,4 @@ struct DigitizationConfigurator {
}
}
};
} // namespace ActsExamples
} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include "ActsExamples/Digitization/DigitizationAlgorithm.hpp"
#include "ActsExamples/Digitization/SmearingAlgorithm.hpp"
#include "ActsExamples/Utilities/OptionsFwd.hpp"

namespace ActsExamples {
Expand All @@ -20,10 +19,5 @@ namespace Options {
/// @param desc The options description to add options to
void addDigitizationOptions(Description &desc);

/// Read SmearingAlgorithm Config from the options.
///
/// @param variables The variables to read from
DigitizationConfig readSmearingConfig(const Variables &variables);

} // namespace Options
} // namespace ActsExamples

This file was deleted.

169 changes: 5 additions & 164 deletions Examples/Algorithms/Digitization/src/DigitizationConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/Digitization/DigitizationAlgorithm.hpp"
#include "ActsExamples/Digitization/Smearers.hpp"
#include "ActsExamples/Digitization/SmearingAlgorithm.hpp"
#include "ActsExamples/Digitization/SmearingConfig.hpp"
#include "ActsExamples/Utilities/Options.hpp"

Expand All @@ -32,175 +31,23 @@ enum SmearingTypes : int {
eDigital = 4,
};

constexpr size_t numConfigParametersForType(int type) {
// Gaussian smearing requires only a width/standard deviation parameter
// Everything else requires a width/pitch and a range
return (static_cast<SmearingTypes>(type) == eGauss) ? 1u : 3u;
}

ActsFatras::SingleParameterSmearFunction<ActsExamples::RandomEngine>
makeSmearFunctionForType(SmearingTypes smearingType, const double* parameters) {
using namespace ActsExamples::Digitization;

switch (smearingType) {
case eGauss:
return Gauss(parameters[0]);
case eGaussTruncated:
return GaussTrunc(parameters[0], {parameters[1u], parameters[2u]});
case eGaussClipped:
return GaussClipped(parameters[0], {parameters[1u], parameters[2u]});
case eUniform:
return Uniform(parameters[0], {parameters[1u], parameters[2u]});
case eDigital:
return Digital(parameters[0], {parameters[1u], parameters[2u]});
}
return nullptr;
}

} // namespace

ActsExamples::DigitizationConfig::DigitizationConfig(
const Options::Variables& vars,
Acts::GeometryHierarchyMap<DigiComponentsConfig>&& digiCfgs)
: isSimpleSmearer(vars["digi-smear"].as<bool>()),
doMerge(vars["digi-merge"].as<bool>()),
: doMerge(vars["digi-merge"].as<bool>()),
mergeNsigma(vars["digi-merge-nsigma"].as<double>()),
mergeCommonCorner(vars["digi-merge-common-corner"].as<bool>()) {
digitizationConfigs = std::move(digiCfgs);
if (isSimpleSmearer)
smearingConfig(vars);
}

ActsExamples::DigitizationConfig::DigitizationConfig(
Acts::GeometryHierarchyMap<DigiComponentsConfig>&& digiCfgs)
: isSimpleSmearer(false),
doMerge(false),
mergeNsigma(1.0),
mergeCommonCorner(false) {
: doMerge(false), mergeNsigma(1.0), mergeCommonCorner(false) {
digitizationConfigs = std::move(digiCfgs);
}

void ActsExamples::DigitizationConfig::smearingConfig(
const Options::Variables& variables) {
ACTS_LOCAL_LOGGER(
Acts::getDefaultLogger("SmearingOptions", Acts::Logging::INFO));

using namespace Acts::UnitLiterals;
using namespace ActsExamples::Options;

// Smear configuration with command line input
// only limited smearing configuration possible:
// complex smearing option configuration has to be done with a
// digitization config file

// in case of an error, we always return a configuration struct with empty
// smearers configuration. this will be caught later on during the algorithm
// construction.

// no configured volumes are not considered an error at this stage
if (not variables.count("digi-smear-volume"))
return;
auto volumes = variables["digi-smear-volume"].as<std::vector<int>>();
if (volumes.empty())
return;

if (not variables["digi-config-file"].as<std::string>().empty()) {
ACTS_WARNING(
"Smearing configuration on command-line will override .json "
"configuration!");
}

auto indices =
variables["digi-smear-indices"].as<std::vector<VariableIntegers>>();
auto types =
variables["digi-smear-types"].as<std::vector<VariableIntegers>>();
auto parameters =
variables["digi-smear-parameters"].as<std::vector<VariableReals>>();
if (indices.size() != volumes.size()) {
ACTS_ERROR("Inconsistent digi-smear-indices options. Expected "
<< volumes.size() << ", but received " << indices.size());
return;
}
if (types.size() != volumes.size()) {
ACTS_ERROR("Inconsistent digi-smear-types options. Expected "
<< volumes.size() << ", but received " << types.size());
return;
}
if (parameters.size() != volumes.size()) {
ACTS_ERROR("Inconsistent digi-smear-parameters options. Expected "
<< volumes.size() << ", but received " << parameters.size());
return;
}

// construct the input for the smearer configuation
std::vector<std::pair<Acts::GeometryIdentifier, DigiComponentsConfig>>
smearersInput;
for (size_t ivol = 0; ivol < volumes.size(); ++ivol) {
Acts::GeometryIdentifier geoId =
Acts::GeometryIdentifier(0).setVolume(volumes[ivol]);
const auto& volIndices = indices[ivol].values;
const auto& volTypes = types[ivol].values;
const auto& volParameters = parameters[ivol].values;

if (volTypes.size() != volIndices.size()) {
ACTS_ERROR("Inconsistent number of digi-smear-types values for volume "
<< volumes[ivol] << ". Expected " << indices.size()
<< ", but received " << types.size());
return;
}
// count the expected number of smearing configuration parameters
size_t expectedNumParameters = 0;
for (auto smearingType : volTypes) {
expectedNumParameters += numConfigParametersForType(smearingType);
}
if (volParameters.size() != expectedNumParameters) {
ACTS_ERROR(
"Inconsistent number of digi-smear-parameters values for volume "
<< volumes[ivol] << ". Expected " << expectedNumParameters
<< ", but received " << types.size());
return;
}

// create the smearing configuration for this geometry identifier
SmearingConfig geoCfg;
geoCfg.reserve(volIndices.size());

for (size_t iidx = 0, ipar = 0; iidx < volIndices.size(); ++iidx) {
const auto paramIndex = static_cast<Acts::BoundIndices>(volIndices[iidx]);
const auto smearingType = static_cast<SmearingTypes>(volTypes[iidx]);
const double* smearingParameters = &volParameters[ipar];
ipar += numConfigParametersForType(smearingType);

ParameterSmearingConfig parCfg;
parCfg.index = paramIndex;
parCfg.smearFunction =
makeSmearFunctionForType(smearingType, smearingParameters);
if (not parCfg.smearFunction) {
ACTS_ERROR("Invalid smearing type for entry "
<< iidx << " for volume " << volumes[ivol] << ". Type "
<< volTypes[iidx] << " is not valid");
return;
}
geoCfg.emplace_back(std::move(parCfg));
}
DigiComponentsConfig dcfg;
dcfg.smearingDigiConfig = geoCfg;
smearersInput.emplace_back(geoId, std::move(dcfg));
}
// set the smearer configuration from the prepared input
digitizationConfigs = Acts::GeometryHierarchyMap<DigiComponentsConfig>(
std::move(smearersInput));
}

std::shared_ptr<ActsExamples::IAlgorithm>
ActsExamples::createDigitizationAlgorithm(ActsExamples::DigitizationConfig& cfg,
Acts::Logging::Level lvl) {
if (cfg.isSimpleSmearer)
return std::make_shared<SmearingAlgorithm>(cfg, lvl);
else
return std::make_shared<DigitizationAlgorithm>(cfg, lvl);
}

std::vector<
std::pair<Acts::GeometryIdentifier, std::vector<Acts::BoundIndices>>>
ActsExamples::DigitizationConfig::getBoundIndices() const {
Expand All @@ -212,15 +59,9 @@ ActsExamples::DigitizationConfig::getBoundIndices() const {
Acts::GeometryIdentifier geoID = digitizationConfigs.idAt(ibi);
const auto dCfg = digitizationConfigs.valueAt(ibi);
std::vector<Acts::BoundIndices> boundIndices;
if (isSimpleSmearer) {
for (const auto& sConfig : dCfg.smearingDigiConfig) {
boundIndices.push_back(sConfig.index);
}
} else {
boundIndices.insert(boundIndices.end(),
dCfg.geometricDigiConfig.indices.begin(),
dCfg.geometricDigiConfig.indices.end());
}
boundIndices.insert(boundIndices.end(),
dCfg.geometricDigiConfig.indices.begin(),
dCfg.geometricDigiConfig.indices.end());
bIndexInput.push_back({geoID, boundIndices});
}
return bIndexInput;
Expand Down
29 changes: 0 additions & 29 deletions Examples/Algorithms/Digitization/src/DigitizationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,12 @@ void ActsExamples::Options::addDigitizationOptions(Description& desc) {
using boost::program_options::bool_switch;
using boost::program_options::value;

// each volume configuration is one logical block
//
// --digi-smear-volume-id=8
// --digi-smear-indices=0:1:5 # loc0, loc1, and time
// --digi-smear-types=0:0:3 # loc{0,1} uses gaussian, time uses uniform
// # parameter 0: loc0 gaussian width
// # parameter 1: loc1 gaussian width
// # parameter 2-4: time pitch,min,max
// --digi-smear-parameters=10:20:2.5:-25:25
//
// which can be repeated as often as needed
//
// --digi-smear-volume-id=11
// --digi-smear-indices=1 # loc1
// --digi-smear-types=0 # loc1 uses gaussian
// --digi-smear-parameters=12.5 # loc1 gaussian width
//
auto opt = desc.add_options();
opt("digi-config-file", value<std::string>()->default_value(""),
"Configuration (.json) file for digitization description, overwrites "
"smearing options input on command line.");
opt("dump-digi-config", value<std::string>()->default_value(""),
"Path to .json file in which to dump digitization configuration.");
opt("digi-smear", bool_switch(), "Smearing: Switching hit smearing on");
opt("digi-smear-volume", value<std::vector<int>>(),
"Smearing Input: sensitive volume identifiers.");
opt("digi-smear-indices", value<std::vector<VariableIntegers>>(),
"Smearing Input: smear parameter indices for this volume.");
opt("digi-smear-types", value<std::vector<VariableIntegers>>(),
"Smearing Input: smear function types as 0 (gauss), 1 (truncated gauss), "
"2 (clipped gauss), 3 (uniform), 4 (digital).");
opt("digi-smear-parameters", value<std::vector<VariableReals>>(),
"Smearing Input: smear parameters depending on the smearing type, 1 "
"parameter for simple gauss, 3 for all others (1 parameter, 2 range "
"values.");
opt("digi-merge", bool_switch(), "Turn on hit merging");
opt("digi-merge-nsigma", value<double>()->default_value(1.0),
"Defines how close smeared parameters have to be when merging");
Expand Down

0 comments on commit a76a3fc

Please sign in to comment.