Skip to content

Commit

Permalink
test: Use deterministic RNG for tests (acts-project#2694)
Browse files Browse the repository at this point in the history
apparently otherwise the random engine can be different on different platforms which I observed in acts-project#2625 with macos

at the same time I hardcoded the type for the `std::uniform_int_distribution`. apparently this can also make a difference for the random value
  • Loading branch information
LaraCalic committed Dec 11, 2023
1 parent c37c59f commit 0aa19a9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Examples/Run/Alignment/Common/DetectorAlignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ int runDetectorAlignment(
if (vm.empty()) {
return EXIT_FAILURE;
}

// feed the alignment group to config
cfg.alignmentGroups = alignmentAlgorithm.getAlignmentGroups();

Sequencer sequencer(Options::readSequencerConfig(vm));

Expand Down
66 changes: 66 additions & 0 deletions Tests/UnitTests/Alignment/Kernel/AlignmentTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,72 @@ BOOST_AUTO_TEST_CASE(ZeroFieldKalmanAlignment) {
BOOST_CHECK_EQUAL(alignState.alignmentToChi2Derivative.size(), 30);
BOOST_CHECK_EQUAL(alignState.alignmentToChi2SecondDerivative.rows(), 30);

// Unit tests that test makeAlignmentGroup functionality

struct DetectorAlignment::Config {
std::string alignmentGroupsFile;
};

int DetectorAlignment::runDetectorAlignment(
int argc, char* argv[],
const std::shared_ptr<ActsExamples::IBaseDetector>& detector,
ActsAlignment::AlignedTransformUpdater alignedTransformUpdater,
const AlignedDetElementGetter& alignedDetElementsGetter) {


// separate function for reading and parsing JSON
std::vector<AlignmentAlgorithm::AlignmentParameters> readJsonFile(const std::string& filePath) {
std::vector<AlignmentAlgorithm::AlignmentParameters> alignmentParameters;

if (!filePath.empty()) {
std::ifstream jsonFile(filePath);
if (!jsonFile.is_open()) {
std::cerr << " Unable to open an alignment group file" << std::endl;
return alignmentParameters; // Return an empty vector in case of failure
}

// parsing the json file
nlohmann::json jsonData;
try {
jsonFile >> jsonData;
} catch (const nlohmann::json::parse_error& e) {
std::cerr << "Error parsing JSON: " << e.what() << std::endl;
return EXIT_FAILURE;
}

// populate the alignmentParameters vector
for (const auto& alignmentData : jsonData) {
// create AlignmentParameters
AlignmentAlgorithm::AlignmentParameters alignmentPar;

alignmentParameters.push_back(alignmentPar);
}

jsonFile.close();

int DetectorAlignment::runDetectorAlignment(
int argc, char* argv[],
const std::shared_ptr<ActsExamples::IBaseDetector>& detector,
ActsAlignment::AlignedTransformUpdater alignedTransformUpdater,
const AlignedDetElementGetter& alignedDetElementsGetter) {

std::string alignmentGroupsFile = vm["name-alignment-groups-file"].as<std::string>();

// Unit test: Check if the alignmentGroupsFile is empty
if (alignmentGroupsFile.empty()) {
std::cout << "Unit Test: Alignment groups file is empty." << std::endl;
return EXIT_SUCCESS;
}

// Separate function for reading and parsing JSON
//std::vector<AlignmentAlgorithm::AlignmentParameters> alignmentParameters =
// readJsonFile(alignmentGroupsFile);

// makeAlignmentGroup creates alignment groups
alignmentAlgorithm.makeAlignmentGroup(alignmentParameters);
}


// Test the align method
std::vector<std::vector<TestSourceLink>> trajCollection;
trajCollection.reserve(10);
Expand Down
1 change: 1 addition & 0 deletions acts
Submodule acts added at 825db4

0 comments on commit 0aa19a9

Please sign in to comment.