Skip to content

Commit

Permalink
Merge pull request #480 from beomki-yeo/res-plots
Browse files Browse the repository at this point in the history
Resolution plot updates with truth fitting examples
  • Loading branch information
beomki-yeo authored Nov 3, 2023
2 parents d3252a6 + 47ad035 commit 4a49aad
Show file tree
Hide file tree
Showing 24 changed files with 940 additions and 53 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Demonstrator tracking chain for accelerators.
| ------------------ | ---------------------- | --- | ---- | ---- | ------- |
| **Clusterization** | CCL |||||
| | Measurement creation |||||
| | Spacepoint formation |||||
| **Track finding** | Spacepoint binning |||||
| **Seeding** | Spacepoint formation |||||
| | Spacepoint binning |||||
| | Seed finding |||||
| | Track param estimation |||||
| | Combinatorial KF ||| 🟡 ||
| **Track finding** | Combinatorial KF ||| 🟡 ||
| **Track fitting** | KF |||||

✅: exists, 🟡: work started, ⚪: work not started yet
Expand Down Expand Up @@ -255,7 +255,7 @@ cmake --build <build_directory> <options>

<build_directory>/bin/traccc_seeding_example_cuda --input_directory=detray_simulation/toy_detector/n_particles_2000/ --check_performance=true --detector_file=<detector_directory>/toy_detector_geometry.json --material_file=<detector_directory>/toy_detector_homogeneous_material.json --grid_file=<detector_directory>/toy_detector_surface_grids.json --event=1 --track_candidates_range=3:10 --constraint-step-size-mm=1000 --run_cpu=1

<build_directory>/bin/traccc_truth_finding_example_cuda --input_directory=detray_simulation/toy_detector/n_particles_2000/ --check_performance=true --detector_file=<detector_directory>/toy_detector_geometry.json --material_file=<detector_directory>/toy_detector_homogeneous_material.json --grid_file=<detector_directory>/toy_detector_surface_grids.json --event=1 --track_candidates_range=3:10 --constraint-step-size-mm=1 --run_cpu=1
<build_directory>/bin/traccc_truth_finding_example_cuda --input_directory=detray_simulation/toy_detector/n_particles_2000/ --check_performance=true --detector_file=<detector_directory>/toy_detector_geometry.json --material_file=<detector_directory>/toy_detector_homogeneous_material.json --grid_file=<detector_directory>/toy_detector_surface_grids.json --event=1 --track_candidates_range=3:30 --constraint-step-size-mm=1 --run_cpu=1
```

```sh
Expand All @@ -280,18 +280,27 @@ cmake --build <build_directory> <options>
Users can generate muon-like particle simulation data by running following example commands:

```sh
# Generate telescope geometry data
<build_directory>/bin/traccc_simulate_telescope --gen-vertex-xyz-mm=0:0:0 --gen-vertex-xyz-std-mm=0:0:0 --gen-mom-gev=100:100 --gen-phi-degree=0:0 --events=10 --gen-nparticles=2000 --output_directory=detray_simulation/telescope_detector/n_particles_2000/ --gen-eta=1:3

# Generate toy geometry data
<build_directory>/bin/traccc_simulate_toy_detector --gen-vertex-xyz-mm=0:0:0 --gen-vertex-xyz-std-mm=0:0:0 --gen-mom-gev=100:100 --gen-phi-degree=0:360 --events=10 --gen-nparticles=2000 --output_directory=detray_simulation/toy_detector/n_particles_2000/ --gen-eta=-3:3 --constraint-step-size-mm=1

# Generate drift chamber data
<build_directory>/bin/traccc_simulate_wire_chamber --gen-vertex-xyz-mm=0:0:0 --gen-vertex-xyz-std-mm=0:0:0 --gen-mom-gev=2:2 --gen-phi-degree=0:360 --events=10 --gen-nparticles=100 --output_directory=detray_simulation/wire_chamber/n_particles_100/ --gen-eta=-1:1 --constraint-step-size-mm=1
```

The simulation will also generate the detector json files (geometry, material and surface_grid) in the current directory. It is user's responsibility to move them to an appropriate place (say, <detector_directory>) and match it to the input file arguments of the reconstruction examples.
The simulation will also generate the detector json files (geometry, material and surface_grid) in the current directory. It is user's responsibility to move them to an appropriate place (e.g. `<detector_directory>`) and match them to the input file arguments of reconstruction chains.

There are three types of partial reconstruction chain users can operate: `seeding_example`, `truth_finding_example`, and `truth_fitting_example` where their algorithm coverages are shown in the table below. Each of them starts from truth measurements, truth seeds, and truth tracks, respectively.

Currently, there are two types of partial reconstruction chain users can operate: seeding_example and truth_finding_example. seeding_example takes the truth measurement input w/o clusterization and it goes through seeding, finding and fitting, which generate performance root files, respectively. On the other hand, truth_finding_examples starts from the truth initial parameter of particles (no duplicate seeds; i.e. the number of seeds for CKF = the number of truth particles) and run track finding and track fitting.
| Category | Clusterization | Seeding | Track finding | Track fitting |
| ----------------------- | -------------- | ------- | ------------- | ------------- |
| `seeding_example` | ||||
| `truth_finding_example` | | |||
| `truth_fitting_example` | | | ||

The dirft chamber will not produce meaningful results with seeding_examples as the current seeding algorithm is only designed for 2D measurement objects. Truth finding works OK in general but the combinatoric explosion can occur for a few unlucky events, leading to poor pull value distributions.
The dirft chamber will not produce meaningful results with `seeding_example` as the current seeding algorithm is only designed for 2D measurement objects. Truth finding works OK in general but the combinatoric explosion can occur for a few unlucky events, leading to poor pull value distributions. The followings are example commands:

```sh
# Run cuda seeding example for toy geometry
Expand All @@ -308,7 +317,12 @@ The dirft chamber will not produce meaningful results with seeding_examples as t
<build_directory>/bin/traccc_truth_finding_example_cuda --input_directory=detray_simulation/wire_chamber/n_particles_100/ --check_performance=true --detector_file=<detector_directory>/wire_chamber_geometry.json --material_file=<detector_directory>/wire_chamber_homogeneous_material.json --grid_file=<detector_directory>/wire_chamber_surface_grids.json --event=10 --track_candidates_range=6:30 --constraint-step-size-mm=1 --run_cpu=1
```

Users can open the performance root files (with --check_performance=true) and draw the histograms.
```sh
# Run cpu truth fitting example for drift chamber
<build_directory>/bin/traccc_truth_fitting_example --input_directory=detray_simulation/wire_chamber/n_particles_2000_100GeV/ --check_performance=true --detector_file=<detector_directory>/wire_chamber_geometry.json --material_file=<detector_directory>/wire_chamber_homogeneous_material.json --grid_file=<detector_directory>/wire_chamber_surface_grids.json --event=10 --constraint-step-size-mm=1
```

Users can open the performance root files (with `--check_performance=true`) and draw the histograms.

```sh
$ root -l performance_track_finding.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class kalman_fitter {
auto& last = track_states.back();
last.smoothed().set_vector(last.filtered().vector());
last.smoothed().set_covariance(last.filtered().covariance());
last.smoothed_chi2() = last.filtered_chi2();

for (typename vector_type<
track_state<transform3_type>>::reverse_iterator it =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

// Project include(s).
#include "traccc/options/options.hpp"

// Detray include(s).
#include "detray/definitions/units.hpp"

// Boost
#include <boost/program_options.hpp>

namespace traccc {

namespace po = boost::program_options;

template <typename scalar_t>
struct telescope_detector_options {
bool empty_material;
unsigned int n_planes;
scalar_t thickness;
scalar_t spacing;
scalar_t smearing;
scalar_t half_length;

telescope_detector_options(po::options_description& desc) {
desc.add_options()("empty_material",
po::value<bool>()->default_value(false),
"Build detector without materials");
desc.add_options()("n_planes",
po::value<unsigned int>()->default_value(9),
"Number of planes");
desc.add_options()("thickness",
po::value<scalar_t>()->default_value(0.5f),
"Slab thickness in [mm]");
desc.add_options()("spacing",
po::value<scalar_t>()->default_value(20.f),
"Space between planes in [mm]");
desc.add_options()("smearing",
po::value<scalar_t>()->default_value(50.f),
"Measurement smearing in [um]");
desc.add_options()("half_length",
po::value<scalar_t>()->default_value(1000000.f),
"Half length of plane [mm]");
}

void read(const po::variables_map& vm) {
empty_material = vm["empty_material"].as<bool>();
n_planes = vm["n_planes"].as<unsigned int>();
thickness = vm["thickness"].as<scalar_t>() * detray::unit<scalar_t>::mm;
spacing = vm["spacing"].as<scalar_t>() * detray::unit<scalar_t>::mm;
smearing = vm["smearing"].as<scalar_t>() * detray::unit<scalar_t>::um;
half_length =
vm["half_length"].as<scalar_t>() * detray::unit<scalar_t>::mm;
}
};

} // namespace traccc
4 changes: 4 additions & 0 deletions examples/run/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ traccc_add_executable( truth_finding_example "truth_finding_example.cpp"
LINK_LIBRARIES vecmem::core detray::utils traccc::core traccc::io
traccc::performance traccc::options)

traccc_add_executable( truth_fitting_example "truth_fitting_example.cpp"
LINK_LIBRARIES vecmem::core detray::io detray::utils traccc::core
traccc::io traccc::performance traccc::options)

traccc_add_executable( ccl_example "ccl_example.cpp"
LINK_LIBRARIES vecmem::core traccc::core traccc::io)

Expand Down
165 changes: 165 additions & 0 deletions examples/run/cpu/truth_fitting_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

// Project include(s).
#include "traccc/definitions/common.hpp"
#include "traccc/definitions/primitives.hpp"
#include "traccc/fitting/fitting_algorithm.hpp"
#include "traccc/fitting/kalman_filter/kalman_fitter.hpp"
#include "traccc/io/read_geometry.hpp"
#include "traccc/io/read_measurements.hpp"
#include "traccc/io/utils.hpp"
#include "traccc/options/common_options.hpp"
#include "traccc/options/handle_argument_errors.hpp"
#include "traccc/options/propagation_options.hpp"
#include "traccc/resolution/fitting_performance_writer.hpp"
#include "traccc/utils/seed_generator.hpp"

// Detray include(s).
#include "detray/core/detector.hpp"
#include "detray/core/detector_metadata.hpp"
#include "detray/detectors/bfield.hpp"
#include "detray/io/common/detector_reader.hpp"
#include "detray/propagator/navigator.hpp"
#include "detray/propagator/propagator.hpp"
#include "detray/propagator/rk_stepper.hpp"

// VecMem include(s).
#include <vecmem/memory/host_memory_resource.hpp>

// System include(s).
#include <exception>
#include <iomanip>
#include <iostream>

using namespace traccc;
namespace po = boost::program_options;

// The main routine
//
int main(int argc, char* argv[]) {
// Set up the program options
po::options_description desc("Allowed options");

// Add options
desc.add_options()("help,h", "Give some help with the program's options");
traccc::common_options common_opts(desc);
traccc::propagation_options<scalar> propagation_opts(desc);

po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);

// Check errors
traccc::handle_argument_errors(vm, desc);

// Read options
common_opts.read(vm);
propagation_opts.read(vm);

std::cout << "Running " << argv[0] << " " << common_opts.input_directory
<< " " << common_opts.events << std::endl;

/// Type declarations
using host_detector_type = detray::detector<detray::default_metadata,
detray::host_container_types>;

using b_field_t = covfie::field<detray::bfield::const_bknd_t>;
using rk_stepper_type =
detray::rk_stepper<b_field_t::view_t, traccc::transform3,
detray::constrained_step<>>;

using host_navigator_type = detray::navigator<const host_detector_type>;
using host_fitter_type =
traccc::kalman_fitter<rk_stepper_type, host_navigator_type>;

// Memory resources used by the application.
vecmem::host_memory_resource host_mr;

// Performance writer
traccc::fitting_performance_writer fit_performance_writer(
traccc::fitting_performance_writer::config{});

/*****************************
* Build a geometry
*****************************/

// B field value and its type
// @TODO: Set B field as argument
const traccc::vector3 B{0, 0, 2 * detray::unit<traccc::scalar>::T};
auto field = detray::bfield::create_const_field(B);

// Read the detector
detray::io::detector_reader_config reader_cfg{};
reader_cfg
.add_file(traccc::io::data_directory() + common_opts.detector_file)
.add_file(traccc::io::data_directory() + common_opts.material_file)
.add_file(traccc::io::data_directory() + common_opts.grid_file);

const auto [host_det, names] =
detray::io::read_detector<host_detector_type>(host_mr, reader_cfg);

/*****************************
* Do the reconstruction
*****************************/

/// Standard deviations for seed track parameters
static constexpr std::array<scalar, e_bound_size> stddevs = {
0.03 * detray::unit<scalar>::mm,
0.03 * detray::unit<scalar>::mm,
0.017,
0.017,
0.01 / detray::unit<scalar>::GeV,
1 * detray::unit<scalar>::ns};

// Fitting algorithm object
typename traccc::fitting_algorithm<host_fitter_type>::config_type fit_cfg;
fit_cfg.step_constraint = propagation_opts.step_constraint;
traccc::fitting_algorithm<host_fitter_type> host_fitting(fit_cfg);

// Seed generator
traccc::seed_generator<host_detector_type> sg(host_det, stddevs);

// Iterate over events
for (unsigned int event = common_opts.skip;
event < common_opts.events + common_opts.skip; ++event) {

// Truth Track Candidates
traccc::event_map2 evt_map2(event, common_opts.input_directory,
common_opts.input_directory,
common_opts.input_directory);

traccc::track_candidate_container_types::host truth_track_candidates =
evt_map2.generate_truth_candidates(sg, host_mr);

// Run fitting
auto track_states =
host_fitting(host_det, field, truth_track_candidates);

std::cout << "Number of fitted tracks: " << track_states.size()
<< std::endl;

const unsigned int n_fitted_tracks = track_states.size();

if (common_opts.check_performance) {

for (unsigned int i = 0; i < n_fitted_tracks; i++) {
const auto& trk_states_per_track = track_states.at(i).items;

const auto& fit_info = track_states[i].header;

fit_performance_writer.write(trk_states_per_track, fit_info,
host_det, evt_map2);
}
}
}

if (common_opts.check_performance) {
fit_performance_writer.finalize();
}

return 1;
}
4 changes: 4 additions & 0 deletions examples/run/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ traccc_add_executable( truth_finding_example_cuda "truth_finding_example_cuda.cp
LINK_LIBRARIES vecmem::core vecmem::cuda traccc::io traccc::performance
traccc::core traccc::device_common traccc::cuda
traccc::options )
traccc_add_executable( truth_fitting_example_cuda "truth_fitting_example_cuda.cpp"
LINK_LIBRARIES vecmem::core vecmem::cuda traccc::io traccc::performance
traccc::core traccc::device_common traccc::cuda
traccc::options )
#
# Set up the "throughput applications".
#
Expand Down
7 changes: 7 additions & 0 deletions examples/run/cuda/truth_finding_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ int seq_run(const traccc::finding_input_config& i_cfg,
std::cout << "Track candidate matching Rate: "
<< float(n_matches) / track_candidates.size()
<< std::endl;

// Compare the track parameters made on the host and on the device.
traccc::collection_comparator<traccc::fitter_info<transform3>>
compare_fitter_infos{"fitted tracks"};
compare_fitter_infos(
vecmem::get_data(track_states.get_headers()),
vecmem::get_data(track_states_cuda.get_headers()));
}

/// Statistics
Expand Down
Loading

0 comments on commit 4a49aad

Please sign in to comment.