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

Use configuration types as SSOT for defaults #833

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 2 additions & 8 deletions examples/options/include/traccc/options/clusterization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ class clusterization
std::unique_ptr<configuration_printable> as_printable() const override;

private:
/// @name Options
/// @{
/// The number of cells to merge in a partition
unsigned int threads_per_partition;
unsigned int max_cells_per_thread;
unsigned int target_cells_per_thread;
unsigned int backup_size_multiplier;
/// @}
/// Internal configuration object
clustering_config m_config;
}; // class clusterization

} // namespace traccc::opts
28 changes: 5 additions & 23 deletions examples/options/include/traccc/options/track_finding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,11 @@ class track_finding : public interface, public config_provider<finding_config> {
std::unique_ptr<configuration_printable> as_printable() const override;

private:
/// @name Options
/// @{
/// Max number of branches per seed
unsigned int max_num_branches_per_seed = 10;
/// Max number of branches per surface
unsigned int max_num_branches_per_surface = 10;
/// Number of track candidates per seed
opts::value_array<unsigned int, 2> track_candidates_range{3, 100};
/// Minimum step length that track should make to reach the next surface. It
/// should be set higher than the overstep tolerance not to make it stay on
/// the same surface
float min_step_length_for_next_surface = 0.5f * detray::unit<float>::mm;
/// Maximum step counts that track can make to reach the next surface
unsigned int max_step_counts_for_next_surface = 100;
/// Maximum chi2 for a measurement to be included in the track
float chi2_max = 10.f;
/// Maximum number of branches which each initial seed can have at a step
unsigned int nmax_per_seed = 10;
/// Maximum allowed number of skipped steps per candidate
unsigned int max_num_skipping_per_cand = 3;
/// PDG number for particle hypothesis (Default: muon)
int pdg_number = 13;
/// @}
/// The internal configuration
finding_config m_config;
/// Additional variables which we cannot simply store in the config
opts::value_array<unsigned int, 2> m_track_candidates_range{0, 0};
int m_pdg_number = 0;
}; // class track_finding

} // namespace traccc::opts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class track_propagation : public interface,
/// @name Options
/// @{
/// Propagation configuration object
detray::propagation::config config;
detray::propagation::config m_config;
/// @}

/// Search window (helper variable)
Expand Down
49 changes: 24 additions & 25 deletions examples/options/src/clusterization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,30 @@ namespace traccc::opts {

clusterization::clusterization() : interface("Clusterization Options") {

m_desc.add_options()("threads-per-partition",
boost::program_options::value(&threads_per_partition)
->default_value(256),
"The number of threads per partition");
m_desc.add_options()(
"threads-per-partition",
boost::program_options::value(&m_config.threads_per_partition)
->default_value(m_config.threads_per_partition),
"The number of threads per partition");
m_desc.add_options()(
"max-cells-per-thread",
boost::program_options::value(&max_cells_per_thread)->default_value(16),
boost::program_options::value(&m_config.max_cells_per_thread)
->default_value(m_config.max_cells_per_thread),
"The maximum number of cells per thread");
m_desc.add_options()("target-cells-per-thread",
boost::program_options::value(&target_cells_per_thread)
->default_value(8),
"The target number of cells per thread");
m_desc.add_options()("backup-size-multiplier",
boost::program_options::value(&backup_size_multiplier)
->default_value(256),
"The size multiplier of the backup scratch space");
m_desc.add_options()(
"target-cells-per-thread",
boost::program_options::value(&m_config.target_cells_per_thread)
->default_value(m_config.target_cells_per_thread),
"The target number of cells per thread");
m_desc.add_options()(
"backup-size-multiplier",
boost::program_options::value(&m_config.backup_size_multiplier)
->default_value(m_config.backup_size_multiplier),
"The size multiplier of the backup scratch space");
}

clusterization::operator clustering_config() const {
clustering_config rv;

rv.threads_per_partition = threads_per_partition;
rv.max_cells_per_thread = max_cells_per_thread;
rv.target_cells_per_thread = target_cells_per_thread;
rv.backup_size_multiplier = backup_size_multiplier;

return rv;
return m_config;
}

clusterization::operator host::clusterization_algorithm::config_type() const {
Expand All @@ -57,18 +54,20 @@ std::unique_ptr<configuration_printable> clusterization::as_printable() const {

dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Threads per partition", std::to_string(threads_per_partition)));
"Threads per partition",
std::to_string(m_config.threads_per_partition)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Target cells per thread",
std::to_string(target_cells_per_thread)));
std::to_string(m_config.target_cells_per_thread)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Max cells per thread", std::to_string(max_cells_per_thread)));
"Max cells per thread",
std::to_string(m_config.max_cells_per_thread)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Scratch space multiplier",
std::to_string(backup_size_multiplier)));
std::to_string(m_config.backup_size_multiplier)));

return cat;
}
Expand Down
95 changes: 47 additions & 48 deletions examples/options/src/track_finding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,69 +20,67 @@ namespace traccc::opts {
namespace po = boost::program_options;

track_finding::track_finding() : interface("Track Finding Options") {
m_pdg_number = m_config.ptc_hypothesis.pdg_num();
m_track_candidates_range[0] = m_config.min_track_candidates_per_track;
m_track_candidates_range[1] = m_config.max_track_candidates_per_track;

m_desc.add_options()("max-num-branches-per-seed",
po::value(&max_num_branches_per_seed)
->default_value(max_num_branches_per_seed),
"Max number of branches per seed");
m_desc.add_options()("max-num-branches-per-surface",
po::value(&max_num_branches_per_surface)
->default_value(max_num_branches_per_surface),
"Max number of branches per surface");
m_desc.add_options()(
"max-num-branches-per-seed",
po::value(&m_config.max_num_branches_per_seed)
->default_value(m_config.max_num_branches_per_seed),
"Max number of branches per seed");
m_desc.add_options()(
"max-num-branches-per-surface",
po::value(&m_config.max_num_branches_per_surface)
->default_value(m_config.max_num_branches_per_surface),
"Max number of branches per surface");
m_desc.add_options()("track-candidates-range",
po::value(&track_candidates_range)
po::value(&m_track_candidates_range)
->value_name("MIN:MAX")
->default_value(track_candidates_range),
->default_value(m_track_candidates_range),
"Range of track candidates number");
m_desc.add_options()(
"min-step-length-for-next-surface",
po::value(&min_step_length_for_next_surface)
->default_value(min_step_length_for_next_surface),
po::value(&m_config.min_step_length_for_next_surface)
->default_value(m_config.min_step_length_for_next_surface),
"Minimum step length that track should make to reach the next surface. "
"This should be set higher than the overstep tolerance not to make it "
"stay on the same surface");
m_desc.add_options()(
"max-step-counts-for-next-surface",
po::value<unsigned int>(&max_step_counts_for_next_surface)
->default_value(max_step_counts_for_next_surface),
po::value<unsigned int>(&m_config.max_step_counts_for_next_surface)
->default_value(m_config.max_step_counts_for_next_surface),
"Maximum step counts that track can make to reach the next surface");
m_desc.add_options()(
"chi2-max", po::value(&chi2_max)->default_value(chi2_max),
"chi2-max",
po::value(&m_config.chi2_max)->default_value(m_config.chi2_max),
"Maximum Chi suqare that measurements can be included in the track");
m_desc.add_options()(
"nmax-per-seed",
po::value<unsigned int>(&nmax_per_seed)->default_value(nmax_per_seed),
po::value<unsigned int>(&m_config.max_num_branches_per_seed)
->default_value(m_config.max_num_branches_per_seed),
"Maximum number of branches which each initial seed can have at a "
"step.");
m_desc.add_options()(
"max-num-skipping-per-cand",
po::value<unsigned int>(&max_num_skipping_per_cand)
->default_value(max_num_skipping_per_cand),
po::value<unsigned int>(&m_config.max_num_skipping_per_cand)
->default_value(m_config.max_num_skipping_per_cand),
"Maximum allowed number of skipped steps per candidate");
m_desc.add_options()(
"max-num-skipping-per-cand",
po::value<unsigned int>(&max_num_skipping_per_cand)
->default_value(max_num_skipping_per_cand),
"Maximum allowed number of skipped steps per candidate");
m_desc.add_options()("particle-hypothesis",
po::value<int>(&pdg_number)->default_value(pdg_number),
"PDG number for the particle hypothesis");
"particle-hypothesis",
po::value<int>(&m_pdg_number)->default_value(m_pdg_number),
"PDG number for the particle hypothesis");
}

track_finding::operator finding_config() const {
finding_config out;
out.max_num_branches_per_seed = max_num_branches_per_seed;
out.max_num_branches_per_surface = max_num_branches_per_surface;
out.min_track_candidates_per_track = track_candidates_range[0];
out.max_track_candidates_per_track = track_candidates_range[1];
out.min_step_length_for_next_surface = min_step_length_for_next_surface;
out.max_step_counts_for_next_surface = max_step_counts_for_next_surface;
out.chi2_max = chi2_max;
out.max_num_branches_per_seed = nmax_per_seed;
out.max_num_skipping_per_cand = max_num_skipping_per_cand;
finding_config out = m_config;

out.min_track_candidates_per_track = m_track_candidates_range[0];
out.max_track_candidates_per_track = m_track_candidates_range[1];
out.ptc_hypothesis =
detail::particle_from_pdg_number<traccc::scalar>(pdg_number);
return out;
detail::particle_from_pdg_number<traccc::scalar>(m_pdg_number);

return m_config;
}

std::unique_ptr<configuration_printable> track_finding::as_printable() const {
Expand All @@ -92,37 +90,38 @@ std::unique_ptr<configuration_printable> track_finding::as_printable() const {
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Max branches per seed",
std::to_string(max_num_branches_per_seed)));
std::to_string(m_config.max_num_branches_per_seed)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Max branches at surface",
std::to_string(max_num_branches_per_surface)));
std::to_string(m_config.max_num_branches_per_surface)));
std::stringstream candidate_ss;
candidate_ss << track_candidates_range;
candidate_ss << m_track_candidates_range;
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>("Track candidate range",
candidate_ss.str()));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Min step length to next surface",
std::to_string(min_step_length_for_next_surface) + " mm"));
std::to_string(m_config.min_step_length_for_next_surface) + " mm"));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Max step count to next surface",
std::to_string(max_step_counts_for_next_surface)));
std::to_string(m_config.max_step_counts_for_next_surface)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>("Max Chi2",
std::to_string(chi2_max)));
std::make_unique<configuration_kv_pair>(
"Max Chi2", std::to_string(m_config.chi2_max)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>("Max branches per step",
std::to_string(nmax_per_seed)));
std::make_unique<configuration_kv_pair>(
"Max branches per step",
std::to_string(m_config.max_num_branches_per_seed)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Max holes per candidate",
std::to_string(max_num_skipping_per_cand)));
std::to_string(m_config.max_num_skipping_per_cand)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>("PDG number",
std::to_string(pdg_number)));
std::to_string(m_pdg_number)));

return cat;
}
Expand Down
Loading
Loading