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

build: Exclude Examples tests from Core tests, phony target #3279

Merged
merged 10 commits into from
Jun 13, 2024
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ option(ACTS_BUILD_ANALYSIS_APPS "Build Analysis applications in the examples" OF
option(ACTS_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(ACTS_BUILD_INTEGRATIONTESTS "Build integration tests" OFF)
option(ACTS_BUILD_UNITTESTS "Build unit tests" OFF)
if(ACTS_BUILD_UNITTESTS AND ACTS_BUILD_EXAMPLES)
set(_default_examples_unit_tests ON)
else()
set(_default_examples_unit_tests OFF)
endif()
option(ACTS_BUILD_EXAMPLES_UNITTESTS "Build unit tests" "${_default_examples_unit_tests}")
option(ACTS_BUILD_NONCOMPILE_TESTS "Build tests that check build failure invariants" OFF)
option(ACTS_RUN_CLANG_TIDY "Run clang-tidy static analysis" OFF)
# other options
Expand Down Expand Up @@ -166,7 +172,7 @@ function(check_root_compatibility)
get_target_property(ROOT_INCLUDE_DIR ROOT::Core INTERFACE_INCLUDE_DIRECTORIES)
set(CMAKE_REQUIRED_INCLUDES ${ROOT_INCLUDE_DIR})
#yolo
#check_cxx_source_compiles("#include <string>\n#include <TString.h>\nint main(){}" ROOT_COMPATIBILITY_CHECK)
#check_cxx_source_compiles(" #include <string>\n #include <TString.h>\nint main(){}" ROOT_COMPATIBILITY_CHECK)
#if(NOT ROOT_COMPATIBILITY_CHECK)
# message(FATAL_ERROR "Root installation is misconfigured. Ensure that your Root installation was compiled.")
#endif()
Expand Down
12 changes: 6 additions & 6 deletions Tests/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ macro(add_unittest _name _source)
target_compile_definitions(
${_target}
PRIVATE "-DBOOST_TEST_DYN_LINK")
set_source_files_properties(${_source} PROPERTIES
set_source_files_properties(${_source} PROPERTIES
COMPILE_DEFINITIONS "BOOST_TEST_MODULE=${_target}")
target_include_directories(
${_target}
Expand All @@ -32,7 +32,7 @@ macro(add_unittest _name _source)
endmacro()

# This function adds a non compile test. To this end it
# - Adds a target to process the file at `src`, and converts begin/end macros
# - Adds a target to process the file at `src`, and converts begin/end macros
# to `#if defined` in an extra file
# - Adds an executable target for that source file, excludes it from the default build
# Set a preprocessor define to enable ONE critical section.
Expand All @@ -52,7 +52,7 @@ function(add_non_compile_test name src)
get_filename_component(_filename ${src} NAME)
set(_processed_source "${CMAKE_CURRENT_BINARY_DIR}/${_filename}")

# Add a build step to generate the source file by invoking a CMake script
# Add a build step to generate the source file by invoking a CMake script
add_custom_command(
OUTPUT ${_processed_source}
DEPENDS ${src}
Expand All @@ -67,7 +67,7 @@ function(add_non_compile_test name src)
DEPENDS ${_processed_source}
)

# Create the executable target, add the generated source code as a
# Create the executable target, add the generated source code as a
# dependencies, so that it's generated when required.
set(test "ActsNonCompileTest${name}Closure")
set(target "${test}_Executable")
Expand All @@ -77,7 +77,7 @@ function(add_non_compile_test name src)

# Don't build this target by default
set_target_properties(${target} PROPERTIES
EXCLUDE_FROM_ALL ON
EXCLUDE_FROM_ALL ON
EXCLUDE_FROM_DEFAULT_BUILD ON)

# Add the test that calls into CMake to build the target. This one we expect to succeed
Expand All @@ -100,7 +100,7 @@ function(add_non_compile_test name src)
add_dependencies(${target} "${name}_generated_source")

set_target_properties(${target} PROPERTIES
EXCLUDE_FROM_ALL ON
EXCLUDE_FROM_ALL ON
EXCLUDE_FROM_DEFAULT_BUILD ON)

add_test(NAME ${test}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
set(unittest_extra_libraries ActsExamplesDigitization)
set(unittest_extra_libraries ActsExamplesDigitization ActsExamplesIoJson)

add_unittest(ModuleClusters ModuleClustersTests.cpp)
118 changes: 118 additions & 0 deletions Tests/UnitTests/Examples/Io/Json/JsonDigitizationConfigTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/detail/GenerateParameters.hpp"
#include "Acts/Surfaces/StrawSurface.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Utilities/BinUtility.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "ActsExamples/Digitization/DigitizationConfig.hpp"
Expand All @@ -25,8 +28,123 @@

using namespace Acts;

namespace {
template <typename generator_t>
struct Fixture {
generator_t rng;
// identifiers
Acts::GeometryIdentifier gid;
ActsFatras::Barcode pid;
// geometry information
std::shared_ptr<Acts::Surface> surface;
Acts::GeometryContext geoCtx;
// local and global track parameters
Acts::BoundVector boundParams;
Acts::FreeVector freeParams;
// hit information
ActsFatras::Hit hit;

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(std::move(surf)) {
using namespace Acts::UnitLiterals;
using Acts::VectorHelpers::makeVector4;

surface->assignGeometryId(gid);

// generate random track parameters
auto [par, cov] =
Acts::detail::Test::generateBoundParametersCovariance(rng);
boundParams = par;

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

// construct hit from free parameters
Acts::Vector4 r4;
r4.segment<3>(Acts::ePos0) = freeParams.segment<3>(Acts::eFreePos0);
r4[Acts::eTime] = freeParams[Acts::eFreeTime];
// construct 4-momentum vector assuming m=0
Acts::Vector4 p4;
p4.segment<3>(Acts::eMom0) =
freeParams.segment<3>(Acts::eFreeDir0).normalized();
p4[Acts::eEnergy] = 1;
p4 *= std::abs(1_e / freeParams[Acts::eFreeQOverP]);
// same 4-momentum before/after hit
hit = ActsFatras::Hit(gid, pid, r4, p4, p4, 13);
}
};
} // namespace

BOOST_AUTO_TEST_SUITE(JsonDigitizationConfig)

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) {
// check if the forcePositiveValue parameter is successfully parsed
BOOST_CHECK(smearing.forcePositiveValues);
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]);
double ref = f.boundParams[s.indices[i]];
if (s.forcePositive[i]) {
ref = std::abs(ref);
}
CHECK_CLOSE_REL(par[i], ref, 0.15);
}
}

BOOST_AUTO_TEST_CASE(DigitizationConfigRoundTrip) {
std::ofstream out;

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 ActsExamplesDigitization ActsExamplesIoJson ActsFatras)
set(unittest_extra_libraries 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,13 +18,9 @@
#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,12 +33,9 @@
#include <iterator>
#include <limits>
#include <memory>
#include <ostream>
#include <random>
#include <utility>

#include <nlohmann/json.hpp>

namespace {

namespace bd = boost::unit_test::data;
Expand Down Expand Up @@ -295,68 +288,4 @@ 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) {
// check if the forcePositiveValue parameter is successfully parsed
BOOST_CHECK(smearing.forcePositiveValues);
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]);
double ref = f.boundParams[s.indices[i]];
if (s.forcePositive[i]) {
ref = std::abs(ref);
}
CHECK_CLOSE_REL(par[i], ref, 0.15);
}
}

BOOST_AUTO_TEST_SUITE_END()
1 change: 1 addition & 0 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ components.
| ACTS_BUILD_BENCHMARKS | Build benchmarks<br> type: `bool`, default: `OFF` |
| ACTS_BUILD_INTEGRATIONTESTS | Build integration tests<br> type: `bool`, default: `OFF` |
| ACTS_BUILD_UNITTESTS | Build unit tests<br> type: `bool`, default: `OFF` |
| ACTS_BUILD_EXAMPLES_UNITTESTS | Build unit testsfor examples<br> type: `bool`, default: `ACTS_BUILD_UNITTESTS AND ACTS_BUILD_EXAMPLES` |
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
| ACTS_BUILD_NONCOMPILE_TESTS | Build tests that check build failure<br>invariants<br> type: `bool`, default: `OFF` |
| ACTS_RUN_CLANG_TIDY | Run clang-tidy static analysis<br> type: `bool`, default: `OFF` |
| ACTS_BUILD_DOCS | Build documentation<br> type: `bool`, default: `OFF` |
Expand Down
Loading