Skip to content

Commit 4a49aad

Browse files
authored
Merge pull request #480 from beomki-yeo/res-plots
Resolution plot updates with truth fitting examples
2 parents d3252a6 + 47ad035 commit 4a49aad

24 files changed

+940
-53
lines changed

README.md

+22-8
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Demonstrator tracking chain for accelerators.
88
| ------------------ | ---------------------- | --- | ---- | ---- | ------- |
99
| **Clusterization** | CCL |||||
1010
| | Measurement creation |||||
11-
| | Spacepoint formation |||||
12-
| **Track finding** | Spacepoint binning |||||
11+
| **Seeding** | Spacepoint formation |||||
12+
| | Spacepoint binning |||||
1313
| | Seed finding |||||
1414
| | Track param estimation |||||
15-
| | Combinatorial KF ||| 🟡 ||
15+
| **Track finding** | Combinatorial KF ||| 🟡 ||
1616
| **Track fitting** | KF |||||
1717

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

256256
<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
257257

258-
<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
258+
<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
259259
```
260260

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

282282
```sh
283+
# Generate telescope geometry data
284+
<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
285+
283286
# Generate toy geometry data
284287
<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
285288

286289
# Generate drift chamber data
287290
<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
288291
```
289292

290-
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.
293+
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.
294+
295+
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.
291296

292-
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.
297+
| Category | Clusterization | Seeding | Track finding | Track fitting |
298+
| ----------------------- | -------------- | ------- | ------------- | ------------- |
299+
| `seeding_example` | ||||
300+
| `truth_finding_example` | | |||
301+
| `truth_fitting_example` | | | ||
293302

294-
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.
303+
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:
295304

296305
```sh
297306
# Run cuda seeding example for toy geometry
@@ -308,7 +317,12 @@ The dirft chamber will not produce meaningful results with seeding_examples as t
308317
<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
309318
```
310319

311-
Users can open the performance root files (with --check_performance=true) and draw the histograms.
320+
```sh
321+
# Run cpu truth fitting example for drift chamber
322+
<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
323+
```
324+
325+
Users can open the performance root files (with `--check_performance=true`) and draw the histograms.
312326

313327
```sh
314328
$ root -l performance_track_finding.root

core/include/traccc/fitting/kalman_filter/kalman_fitter.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class kalman_fitter {
211211
auto& last = track_states.back();
212212
last.smoothed().set_vector(last.filtered().vector());
213213
last.smoothed().set_covariance(last.filtered().covariance());
214+
last.smoothed_chi2() = last.filtered_chi2();
214215

215216
for (typename vector_type<
216217
track_state<transform3_type>>::reverse_iterator it =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2023 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
// Project include(s).
9+
#include "traccc/options/options.hpp"
10+
11+
// Detray include(s).
12+
#include "detray/definitions/units.hpp"
13+
14+
// Boost
15+
#include <boost/program_options.hpp>
16+
17+
namespace traccc {
18+
19+
namespace po = boost::program_options;
20+
21+
template <typename scalar_t>
22+
struct telescope_detector_options {
23+
bool empty_material;
24+
unsigned int n_planes;
25+
scalar_t thickness;
26+
scalar_t spacing;
27+
scalar_t smearing;
28+
scalar_t half_length;
29+
30+
telescope_detector_options(po::options_description& desc) {
31+
desc.add_options()("empty_material",
32+
po::value<bool>()->default_value(false),
33+
"Build detector without materials");
34+
desc.add_options()("n_planes",
35+
po::value<unsigned int>()->default_value(9),
36+
"Number of planes");
37+
desc.add_options()("thickness",
38+
po::value<scalar_t>()->default_value(0.5f),
39+
"Slab thickness in [mm]");
40+
desc.add_options()("spacing",
41+
po::value<scalar_t>()->default_value(20.f),
42+
"Space between planes in [mm]");
43+
desc.add_options()("smearing",
44+
po::value<scalar_t>()->default_value(50.f),
45+
"Measurement smearing in [um]");
46+
desc.add_options()("half_length",
47+
po::value<scalar_t>()->default_value(1000000.f),
48+
"Half length of plane [mm]");
49+
}
50+
51+
void read(const po::variables_map& vm) {
52+
empty_material = vm["empty_material"].as<bool>();
53+
n_planes = vm["n_planes"].as<unsigned int>();
54+
thickness = vm["thickness"].as<scalar_t>() * detray::unit<scalar_t>::mm;
55+
spacing = vm["spacing"].as<scalar_t>() * detray::unit<scalar_t>::mm;
56+
smearing = vm["smearing"].as<scalar_t>() * detray::unit<scalar_t>::um;
57+
half_length =
58+
vm["half_length"].as<scalar_t>() * detray::unit<scalar_t>::mm;
59+
}
60+
};
61+
62+
} // namespace traccc

examples/run/cpu/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ traccc_add_executable( truth_finding_example "truth_finding_example.cpp"
1616
LINK_LIBRARIES vecmem::core detray::utils traccc::core traccc::io
1717
traccc::performance traccc::options)
1818

19+
traccc_add_executable( truth_fitting_example "truth_fitting_example.cpp"
20+
LINK_LIBRARIES vecmem::core detray::io detray::utils traccc::core
21+
traccc::io traccc::performance traccc::options)
22+
1923
traccc_add_executable( ccl_example "ccl_example.cpp"
2024
LINK_LIBRARIES vecmem::core traccc::core traccc::io)
2125

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2023 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
// Project include(s).
9+
#include "traccc/definitions/common.hpp"
10+
#include "traccc/definitions/primitives.hpp"
11+
#include "traccc/fitting/fitting_algorithm.hpp"
12+
#include "traccc/fitting/kalman_filter/kalman_fitter.hpp"
13+
#include "traccc/io/read_geometry.hpp"
14+
#include "traccc/io/read_measurements.hpp"
15+
#include "traccc/io/utils.hpp"
16+
#include "traccc/options/common_options.hpp"
17+
#include "traccc/options/handle_argument_errors.hpp"
18+
#include "traccc/options/propagation_options.hpp"
19+
#include "traccc/resolution/fitting_performance_writer.hpp"
20+
#include "traccc/utils/seed_generator.hpp"
21+
22+
// Detray include(s).
23+
#include "detray/core/detector.hpp"
24+
#include "detray/core/detector_metadata.hpp"
25+
#include "detray/detectors/bfield.hpp"
26+
#include "detray/io/common/detector_reader.hpp"
27+
#include "detray/propagator/navigator.hpp"
28+
#include "detray/propagator/propagator.hpp"
29+
#include "detray/propagator/rk_stepper.hpp"
30+
31+
// VecMem include(s).
32+
#include <vecmem/memory/host_memory_resource.hpp>
33+
34+
// System include(s).
35+
#include <exception>
36+
#include <iomanip>
37+
#include <iostream>
38+
39+
using namespace traccc;
40+
namespace po = boost::program_options;
41+
42+
// The main routine
43+
//
44+
int main(int argc, char* argv[]) {
45+
// Set up the program options
46+
po::options_description desc("Allowed options");
47+
48+
// Add options
49+
desc.add_options()("help,h", "Give some help with the program's options");
50+
traccc::common_options common_opts(desc);
51+
traccc::propagation_options<scalar> propagation_opts(desc);
52+
53+
po::variables_map vm;
54+
po::store(po::parse_command_line(argc, argv, desc), vm);
55+
56+
// Check errors
57+
traccc::handle_argument_errors(vm, desc);
58+
59+
// Read options
60+
common_opts.read(vm);
61+
propagation_opts.read(vm);
62+
63+
std::cout << "Running " << argv[0] << " " << common_opts.input_directory
64+
<< " " << common_opts.events << std::endl;
65+
66+
/// Type declarations
67+
using host_detector_type = detray::detector<detray::default_metadata,
68+
detray::host_container_types>;
69+
70+
using b_field_t = covfie::field<detray::bfield::const_bknd_t>;
71+
using rk_stepper_type =
72+
detray::rk_stepper<b_field_t::view_t, traccc::transform3,
73+
detray::constrained_step<>>;
74+
75+
using host_navigator_type = detray::navigator<const host_detector_type>;
76+
using host_fitter_type =
77+
traccc::kalman_fitter<rk_stepper_type, host_navigator_type>;
78+
79+
// Memory resources used by the application.
80+
vecmem::host_memory_resource host_mr;
81+
82+
// Performance writer
83+
traccc::fitting_performance_writer fit_performance_writer(
84+
traccc::fitting_performance_writer::config{});
85+
86+
/*****************************
87+
* Build a geometry
88+
*****************************/
89+
90+
// B field value and its type
91+
// @TODO: Set B field as argument
92+
const traccc::vector3 B{0, 0, 2 * detray::unit<traccc::scalar>::T};
93+
auto field = detray::bfield::create_const_field(B);
94+
95+
// Read the detector
96+
detray::io::detector_reader_config reader_cfg{};
97+
reader_cfg
98+
.add_file(traccc::io::data_directory() + common_opts.detector_file)
99+
.add_file(traccc::io::data_directory() + common_opts.material_file)
100+
.add_file(traccc::io::data_directory() + common_opts.grid_file);
101+
102+
const auto [host_det, names] =
103+
detray::io::read_detector<host_detector_type>(host_mr, reader_cfg);
104+
105+
/*****************************
106+
* Do the reconstruction
107+
*****************************/
108+
109+
/// Standard deviations for seed track parameters
110+
static constexpr std::array<scalar, e_bound_size> stddevs = {
111+
0.03 * detray::unit<scalar>::mm,
112+
0.03 * detray::unit<scalar>::mm,
113+
0.017,
114+
0.017,
115+
0.01 / detray::unit<scalar>::GeV,
116+
1 * detray::unit<scalar>::ns};
117+
118+
// Fitting algorithm object
119+
typename traccc::fitting_algorithm<host_fitter_type>::config_type fit_cfg;
120+
fit_cfg.step_constraint = propagation_opts.step_constraint;
121+
traccc::fitting_algorithm<host_fitter_type> host_fitting(fit_cfg);
122+
123+
// Seed generator
124+
traccc::seed_generator<host_detector_type> sg(host_det, stddevs);
125+
126+
// Iterate over events
127+
for (unsigned int event = common_opts.skip;
128+
event < common_opts.events + common_opts.skip; ++event) {
129+
130+
// Truth Track Candidates
131+
traccc::event_map2 evt_map2(event, common_opts.input_directory,
132+
common_opts.input_directory,
133+
common_opts.input_directory);
134+
135+
traccc::track_candidate_container_types::host truth_track_candidates =
136+
evt_map2.generate_truth_candidates(sg, host_mr);
137+
138+
// Run fitting
139+
auto track_states =
140+
host_fitting(host_det, field, truth_track_candidates);
141+
142+
std::cout << "Number of fitted tracks: " << track_states.size()
143+
<< std::endl;
144+
145+
const unsigned int n_fitted_tracks = track_states.size();
146+
147+
if (common_opts.check_performance) {
148+
149+
for (unsigned int i = 0; i < n_fitted_tracks; i++) {
150+
const auto& trk_states_per_track = track_states.at(i).items;
151+
152+
const auto& fit_info = track_states[i].header;
153+
154+
fit_performance_writer.write(trk_states_per_track, fit_info,
155+
host_det, evt_map2);
156+
}
157+
}
158+
}
159+
160+
if (common_opts.check_performance) {
161+
fit_performance_writer.finalize();
162+
}
163+
164+
return 1;
165+
}

examples/run/cuda/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ traccc_add_executable( truth_finding_example_cuda "truth_finding_example_cuda.cp
2222
LINK_LIBRARIES vecmem::core vecmem::cuda traccc::io traccc::performance
2323
traccc::core traccc::device_common traccc::cuda
2424
traccc::options )
25+
traccc_add_executable( truth_fitting_example_cuda "truth_fitting_example_cuda.cpp"
26+
LINK_LIBRARIES vecmem::core vecmem::cuda traccc::io traccc::performance
27+
traccc::core traccc::device_common traccc::cuda
28+
traccc::options )
2529
#
2630
# Set up the "throughput applications".
2731
#

examples/run/cuda/truth_finding_example_cuda.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ int seq_run(const traccc::finding_input_config& i_cfg,
297297
std::cout << "Track candidate matching Rate: "
298298
<< float(n_matches) / track_candidates.size()
299299
<< std::endl;
300+
301+
// Compare the track parameters made on the host and on the device.
302+
traccc::collection_comparator<traccc::fitter_info<transform3>>
303+
compare_fitter_infos{"fitted tracks"};
304+
compare_fitter_infos(
305+
vecmem::get_data(track_states.get_headers()),
306+
vecmem::get_data(track_states_cuda.get_headers()));
300307
}
301308

302309
/// Statistics

0 commit comments

Comments
 (0)