Skip to content

Commit

Permalink
Cleanup python plotting code in preparation for benchmark plots
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Jan 15, 2025
1 parent b4abb48 commit a782b98
Show file tree
Hide file tree
Showing 21 changed files with 683 additions and 623 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ struct random_track_generator_config {
// General
out << "\nRandom track generator\n"
<< "----------------------------\n"
<< " Random seed : " << cfg.seed() << "\n"
<< " No. tracks : " << cfg.n_tracks() << "\n"
<< " Charge : "
<< cfg.charge() / detray::unit<scalar_t>::e << " [e]\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ struct uniform_track_generator_config {
// General
out << "\nUnform track generator\n"
<< "----------------------------\n"
<< " Random seed : " << cfg.seed() << "\n"
<< " No. tracks : " << cfg.n_tracks() << "\n"
<< " -> phi steps : " << cfg.phi_steps() << "\n"
<< " -> theta/eta steps : " << cfg.theta_steps() << "\n"
Expand Down
3 changes: 2 additions & 1 deletion tests/tools/include/detray/options/propagation_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void add_options<detray::navigation::config>(
"mask_tolerance_scalor",
boost::program_options::value<float>()->default_value(
cfg.mask_tolerance_scalor),
"Mask tolerance scaling")(
"Mask tolerance scale factor")(
"overstep_tolerance",
boost::program_options::value<float>()->default_value(
cfg.overstep_tolerance / unit<float>::um),
Expand Down Expand Up @@ -172,6 +172,7 @@ void configure_options<detray::stepping::config>(

cfg.path_limit = path_limit * unit<float>::m;
}
cfg.do_covariance_transport = false;
if (vm.count("covariance_transport")) {
cfg.do_covariance_transport = true;
}
Expand Down
116 changes: 90 additions & 26 deletions tests/tools/include/detray/options/track_generator_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ void add_uniform_track_gen_options(
boost::program_options::value<std::size_t>()->default_value(
cfg.eta_steps()),
"No. eta steps for particle gun")(
"random_seed",
boost::program_options::value<std::size_t>()->default_value(cfg.seed()),
"Seed for the random number generator")(
"eta_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Min, Max range of eta values for particle gun")(
"randomize_charge", "Randomly flip charge sign per track")(
"origin",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Coordintates for particle gun origin position [mm]")(
"p_tot",
boost::program_options::value<scalar_t>()->default_value(
static_cast<scalar_t>(cfg.m_p_mag) / unit<scalar_t>::GeV),
"Total momentum of the test particle [GeV]")(
"p_T",
boost::program_options::value<scalar_t>()->default_value(
static_cast<scalar_t>(cfg.m_p_mag) / unit<scalar_t>::GeV),
"Transverse momentum of the test particle [GeV]");
"p_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Total momentum [range] of the test particles [GeV]")(
"pT_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Transverse momentum [range] of the test particles [GeV]");
}

/// Add options for detray event generation
Expand All @@ -66,6 +67,7 @@ void configure_uniform_track_gen_options(

cfg.phi_steps(vm["phi_steps"].as<std::size_t>());
cfg.eta_steps(vm["eta_steps"].as<std::size_t>());
cfg.seed(vm["random_seed"].as<std::size_t>());
cfg.randomize_charge(vm.count("randomize_charge"));

if (vm.count("eta_range")) {
Expand All @@ -87,15 +89,47 @@ void configure_uniform_track_gen_options(
"Particle gun origin needs three arguments");
}
}
if (!vm["p_T"].defaulted() && !vm["p_tot"].defaulted()) {
if (vm.count("pT_range") && vm.count("p_range")) {
throw std::invalid_argument(
"Transverse and total momentum cannot be specified at the same "
"time");
}
if (!vm["p_T"].defaulted()) {
cfg.p_T(vm["p_T"].as<scalar_t>() * unit<scalar_t>::GeV);
if (vm.count("pT_range")) {
const auto pt_range = vm["pT_range"].as<std::vector<scalar_t>>();

// Default
if (pt_range.empty()) {
cfg.p_T(static_cast<scalar_t>(cfg.m_p_mag) * unit<scalar_t>::GeV);
} else if (pt_range.size() == 1u) {
cfg.p_T(pt_range[0] * unit<scalar_t>::GeV);
} else if (pt_range.size() == 2u) {
std::cout << "WARNING: Momentum range not possible with uniform "
"track generator: Using first value."
<< std::endl;
cfg.p_T(pt_range[0] * unit<scalar_t>::GeV);
} else {
throw std::invalid_argument(
"Wrong number of arguments for pT range: Need one argument or "
"range");
}
} else {
cfg.p_tot(vm["p_tot"].as<scalar_t>() * unit<scalar_t>::GeV);
const auto p_range = vm["p_range"].as<std::vector<scalar_t>>();

// Default
if (p_range.empty()) {
cfg.p_tot(static_cast<scalar_t>(cfg.m_p_mag) * unit<scalar_t>::GeV);
} else if (p_range.size() == 1u) {
cfg.p_tot(p_range[0] * unit<scalar_t>::GeV);
} else if (p_range.size() == 2u) {
std::cout << "WARNING: Momentum range not possible with uniform "
"track generator: Using first value."
<< std::endl;
cfg.p_tot(p_range[0] * unit<scalar_t>::GeV);
} else {
throw std::invalid_argument(
"Wrong number of arguments for p_tot range: Need one argument "
"or range");
}
}
}

Expand All @@ -110,24 +144,25 @@ void add_rnd_track_gen_options(
boost::program_options::value<std::size_t>()->default_value(
cfg.n_tracks()),
"No. of tracks for particle gun")(
"random_seed",
boost::program_options::value<std::size_t>()->default_value(cfg.seed()),
"Seed for the random number generator")(
"theta_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Min, Max range of theta values for particle gun")(
"Min, Max range of theta values for particle gun. Interval in [0, pi)")(
"eta_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Min, Max range of eta values for particle gun")(
"randomize_charge", "Randomly flip charge sign per track")(
"origin",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Coordintates for particle gun origin position")(
"p_tot",
boost::program_options::value<scalar_t>()->default_value(
static_cast<scalar_t>(cfg.mom_range()[0]) / unit<scalar_t>::GeV),
"Total momentum of the test particle [GeV]")(
"p_T",
boost::program_options::value<scalar_t>()->default_value(
static_cast<scalar_t>(cfg.mom_range()[0]) / unit<scalar_t>::GeV),
"Transverse momentum of the test particle [GeV]");
"Coordintates for particle gun origin position [mm]")(
"p_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Total momentum [range] of the test particles [GeV]")(
"pT_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Transverse momentum [range] of the test particles [GeV]");
}

/// Add options for detray event generation
Expand All @@ -137,6 +172,7 @@ void configure_rnd_track_gen_options(
random_track_generator_config<scalar_t> &cfg) {

cfg.n_tracks(vm["n_tracks"].as<std::size_t>());
cfg.seed(vm["random_seed"].as<std::size_t>());
cfg.randomize_charge(vm.count("randomize_charge"));

if (vm.count("eta_range") && vm.count("theta_range")) {
Expand Down Expand Up @@ -178,15 +214,43 @@ void configure_rnd_track_gen_options(
"Particle gun origin needs three coordinates");
}
}
if (!vm["p_T"].defaulted() && !vm["p_tot"].defaulted()) {
if (vm.count("pT_range") && vm.count("p_range")) {
throw std::invalid_argument(
"Transverse and total momentum cannot be specified at the same "
"time");
}
if (!vm["p_T"].defaulted()) {
cfg.p_T(vm["p_T"].as<scalar_t>() * unit<scalar_t>::GeV);
if (vm.count("pT_range")) {
const auto pt_range = vm["pT_range"].as<std::vector<scalar_t>>();

// Default
if (pt_range.empty()) {
cfg.p_T(cfg.mom_range()[0] * unit<scalar_t>::GeV);
} else if (pt_range.size() == 1u) {
cfg.p_T(pt_range[0] * unit<scalar_t>::GeV);
} else if (pt_range.size() == 2u) {
cfg.pT_range(pt_range[0] * unit<scalar_t>::GeV,
pt_range[1] * unit<scalar_t>::GeV);
} else {
throw std::invalid_argument(
"Wrong number of arguments for pT range: Need one argument or "
"range");
}
} else {
cfg.p_tot(vm["p_tot"].as<scalar_t>() * unit<scalar_t>::GeV);
const auto p_range = vm["p_range"].as<std::vector<scalar_t>>();

// Default
if (p_range.empty()) {
cfg.p_tot(cfg.mom_range()[0] * unit<scalar_t>::GeV);
} else if (p_range.size() == 1u) {
cfg.p_tot(p_range[0] * unit<scalar_t>::GeV);
} else if (p_range.size() == 2u) {
cfg.mom_range(p_range[0] * unit<scalar_t>::GeV,
p_range[1] * unit<scalar_t>::GeV);
} else {
throw std::invalid_argument(
"Wrong number of arguments for p_tot range: Need one argument "
"or range");
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/tools/python/file_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def __main__():
# ----------------------------------------------------------------arg parsing
# ---------------------------------------------------------------arg parsing

parser = argparse.ArgumentParser(description="Detray File Validation")

Expand Down Expand Up @@ -79,7 +79,7 @@ def __main__():
else:
filename_dict[grid_file] = surface_grid_schema

# ------------------------------------------------------------------------run
# -----------------------------------------------------------------------run

for filename, schema in filename_dict.items():
with open(filename) as file:
Expand All @@ -92,9 +92,9 @@ def __main__():
print(f"{filename}: OK")


# -------------------------------------------------------------------------------
# ------------------------------------------------------------------------------

if __name__ == "__main__":
__main__()

# -------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
Loading

0 comments on commit a782b98

Please sign in to comment.