Skip to content

Commit

Permalink
feat: Smearing for straw surfaces (#3197)
Browse files Browse the repository at this point in the history
This PR introduces the smearing of the` boundParameters` of Straw Surface, that can be used for a fast digitization approach for the MDTs with a Gaussian distribution. It is configures from the json structure that can be used for the creation of a json file for a full propagation-digitization test.
Also the option for positive only values is introduced in the `SmearingConfig` as a flag because for the case of the drift radius we want to get only positive values as output.
  • Loading branch information
dimitra97 committed May 22, 2024
1 parent 1dfef95 commit fa10f5e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct ParameterSmearingConfig {
Acts::BoundIndices index = Acts::eBoundSize;
/// The smearing function for this parameter.
ActsFatras::SingleParameterSmearFunction<RandomEngine> smearFunction;
/// A flag to return only positive smeared values
bool forcePositiveValues = false;
};

// The configured indices must be unique, i.e. each one can only appear once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct BoundParametersSmearer {
/// Parameter indices that will be used to create the smeared measurements.
std::array<Acts::BoundIndices, kSize> indices{};
std::array<SingleParameterSmearFunction<generator_t>, kSize> smearFunctions{};
std::array<bool, kSize> forcePositive = {};

static constexpr std::size_t size() { return kSize; }

Expand Down Expand Up @@ -93,6 +94,9 @@ struct BoundParametersSmearer {
}
auto [value, stddev] = res.value();
par[i] = value;
if (forcePositive[i]) {
par[i] = std::abs(value);
}
cov(i, i) = stddev * stddev;
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/UnitTests/Fatras/Digitization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(unittest_extra_libraries ActsFatras)
set(unittest_extra_libraries ActsExamplesDigitization ActsExamplesIoJson ActsFatras)

add_unittest(FatrasChannelMerger ChannelMergerTests.cpp)
add_unittest(FatrasChannelizer ChannelizerTests.cpp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Surfaces/PlaneSurface.hpp"
#include "Acts/Surfaces/StrawSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Utilities/Result.hpp"
#include "ActsExamples/Digitization/DigitizationConfigurator.hpp"
#include "ActsExamples/Digitization/Smearers.hpp"
#include "ActsExamples/Io/Json/JsonDigitizationConfig.hpp"
#include "ActsFatras/Digitization/DigitizationError.hpp"
#include "ActsFatras/Digitization/UncorrelatedHitSmearer.hpp"
#include "ActsFatras/EventData/Barcode.hpp"
Expand All @@ -37,6 +41,8 @@
#include <random>
#include <utility>

#include <nlohmann/json.hpp>

namespace {

namespace bd = boost::unit_test::data;
Expand Down Expand Up @@ -69,8 +75,9 @@ struct InvalidSmearer {
}
};

template <typename generator_t>
struct Fixture {
RandomGenerator rng;
generator_t rng;
// identifiers
Acts::GeometryIdentifier gid;
ActsFatras::Barcode pid;
Expand All @@ -83,13 +90,12 @@ struct Fixture {
// hit information
ActsFatras::Hit hit;

Fixture(uint64_t rngSeed)
Fixture(uint64_t rngSeed, std::shared_ptr<Acts::Surface> surf)
: rng(rngSeed),
gid(Acts::GeometryIdentifier().setVolume(1).setLayer(2).setSensitive(
3)),
pid(ActsFatras::Barcode().setVertexPrimary(12).setParticle(23)),
surface(Acts::Surface::makeShared<Acts::PlaneSurface>(
Acts::Transform3(Acts::Translation3(3, 2, 1)))) {
surface(std::move(surf)) {
using namespace Acts::UnitLiterals;
using Acts::VectorHelpers::makeVector4;

Expand All @@ -99,6 +105,7 @@ struct Fixture {
auto [par, cov] =
Acts::detail::Test::generateBoundParametersCovariance(rng);
boundParams = par;

freeParams =
Acts::transformBoundToFreeParameters(*surface, geoCtx, boundParams);

Expand Down Expand Up @@ -135,7 +142,9 @@ constexpr auto tol = 128 * std::numeric_limits<double>::epsilon();
BOOST_AUTO_TEST_SUITE(FatrasUncorrelatedHitSmearer)

BOOST_DATA_TEST_CASE(Bound1, bd::make(boundIndices), index) {
Fixture f(123);
Fixture<RandomGenerator> f(
123, Acts::Surface::makeShared<Acts::PlaneSurface>(
Acts::Transform3(Acts::Translation3(3, 2, 1))));
ActsFatras::BoundParametersSmearer<RandomGenerator, 1u> s;
s.indices = {index};

Expand Down Expand Up @@ -165,7 +174,9 @@ BOOST_DATA_TEST_CASE(Bound1, bd::make(boundIndices), index) {
}

BOOST_AUTO_TEST_CASE(BoundAll) {
Fixture f(12356);
Fixture<RandomGenerator> f(
12356, Acts::Surface::makeShared<Acts::PlaneSurface>(
Acts::Transform3(Acts::Translation3(3, 2, 1))));
// without q/p
ActsFatras::BoundParametersSmearer<RandomGenerator, std::size(boundIndices)>
s;
Expand Down Expand Up @@ -209,7 +220,9 @@ BOOST_AUTO_TEST_CASE(BoundAll) {
}

BOOST_DATA_TEST_CASE(Free1, bd::make(freeIndices), index) {
Fixture f(1234);
Fixture<RandomGenerator> f(
1234, Acts::Surface::makeShared<Acts::PlaneSurface>(
Acts::Transform3(Acts::Translation3(3, 2, 1))));
ActsFatras::FreeParametersSmearer<RandomGenerator, 1u> s;
s.indices = {index};

Expand Down Expand Up @@ -239,7 +252,9 @@ BOOST_DATA_TEST_CASE(Free1, bd::make(freeIndices), index) {
}

BOOST_AUTO_TEST_CASE(FreeAll) {
Fixture f(123567);
Fixture<RandomGenerator> f(
123567, Acts::Surface::makeShared<Acts::PlaneSurface>(
Acts::Transform3(Acts::Translation3(3, 2, 1))));
// without q/p
ActsFatras::FreeParametersSmearer<RandomGenerator, std::size(freeIndices)> s;
std::copy(std::begin(freeIndices), std::end(freeIndices), s.indices.begin());
Expand Down Expand Up @@ -280,4 +295,62 @@ BOOST_AUTO_TEST_CASE(FreeAll) {
}
}

BOOST_AUTO_TEST_CASE(GaussianSmearing) {
nlohmann::json djson = nlohmann::json::parse(R"(
{
"acts-geometry-hierarchy-map" : {
"format-version" : 0,
"value-identifier" : "digitization-configuration"
},
"entries"
: [
{
"volume" : 1,
"value" : {
"smearing" : [
{"index" : 0, "mean" : 0.0, "stddev" : 0.05, "type" : "Gauss", "forcePositiveValues" : true}
]
}
}
]
})");
double radius = 5.;
double halfZ = 8.;
Fixture<ActsExamples::RandomEngine> f(
123567,
Acts::Surface::makeShared<Acts::StrawSurface>(
Acts::Transform3(Acts::Translation3(0., 0., 0.)), radius, halfZ));

// Get the smearing configuration from the json object
auto digiConfig =
ActsExamples::DigiConfigConverter("digitization-configuration")
.fromJson(djson);
ActsFatras::BoundParametersSmearer<ActsExamples::RandomEngine, 1u> s;

for (auto& el : digiConfig) {
for (auto& smearing : el.smearingDigiConfig) {
std::fill(std::begin(s.indices), std::end(s.indices),
static_cast<Acts::BoundIndices>(smearing.index));
std::fill(std::begin(s.smearFunctions), std::end(s.smearFunctions),
smearing.smearFunction);
std::fill(std::begin(s.forcePositive), std::end(s.forcePositive),
smearing.forcePositiveValues);
}
}

auto ret = s(f.rng, f.hit, *f.surface, f.geoCtx);

BOOST_CHECK(ret.ok());
auto [par, cov] = ret.value();
for (std::size_t i = 0; i < s.indices.size(); i++) {
BOOST_TEST_INFO("Comparing smeared measurement "
<< i << " originating from bound parameter "
<< s.indices[i]);
CHECK_CLOSE_REL(par[i], f.boundParams[s.indices[i]], 0.15);
}
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit fa10f5e

Please sign in to comment.