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

Update event_map for detray detector #562

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion examples/io/create_binaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int create_binaries(const traccc::opts::detector& detector_opts,
traccc::io::spacepoint_reader_output spacepoints_csv(&host_mr);
traccc::io::read_spacepoints(spacepoints_csv, event,
input_opts.directory, surface_transforms,
input_opts.format);
nullptr, input_opts.format);

// Write binary file
traccc::io::write(event, output_opts.directory,
Expand Down
2 changes: 1 addition & 1 deletion examples/run/alpaka/seeding_example_alpaka.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
// Read the hits from the relevant event file
traccc::io::read_spacepoints(
sp_reader_output, event, input_opts.directory,
surface_transforms, input_opts.format);
surface_transforms, nullptr, input_opts.format);

// Read measurements
traccc::io::read_measurements(meas_reader_output, event,
Expand Down
3 changes: 2 additions & 1 deletion examples/run/cpu/seeding_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
// Read the hits from the relevant event file
traccc::io::spacepoint_reader_output readOut(&host_mr);
traccc::io::read_spacepoints(readOut, event, input_opts.directory,
surface_transforms, input_opts.format);
surface_transforms, nullptr,
input_opts.format);
traccc::spacepoint_collection_types::host& spacepoints_per_event =
readOut.spacepoints;

Expand Down
12 changes: 6 additions & 6 deletions examples/run/cpu/seq_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,25 @@ int seq_run(const traccc::opts::input_data& input_opts,

if (performance_opts.run) {

traccc::event_map2 evt_map(event, input_opts.directory,
input_opts.directory,
input_opts.directory);
traccc::event_map evt_map(
event, detector_opts.detector_file,
detector_opts.digitization_file, input_opts.directory,
input_opts.directory, input_opts.directory, host_mr);

sd_performance_writer.write(vecmem::get_data(seeds),
vecmem::get_data(spacepoints_per_event),
evt_map);
find_performance_writer.write(traccc::get_data(track_candidates),
evt_map);

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

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

fit_performance_writer.write(trk_states_per_track, fit_res,
detector, evt_map);
}

*/
if (resolution_opts.run) {
ar_performance_writer.write(
traccc::get_data(resolved_track_states), evt_map);
Expand Down
2 changes: 1 addition & 1 deletion examples/run/cuda/seeding_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
// Read the hits from the relevant event file
traccc::io::read_spacepoints(
sp_reader_output, event, input_opts.directory,
surface_transforms, input_opts.format);
surface_transforms, nullptr, input_opts.format);

// Read measurements
traccc::io::read_measurements(meas_reader_output, event,
Expand Down
6 changes: 6 additions & 0 deletions examples/run/cuda/seq_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "traccc/cuda/seeding/track_params_estimation.hpp"
#include "traccc/cuda/utils/stream.hpp"
#include "traccc/device/container_d2h_copy_alg.hpp"
#include "traccc/efficiency/finding_performance_writer.hpp"
#include "traccc/efficiency/seeding_performance_writer.hpp"
#include "traccc/finding/finding_algorithm.hpp"
#include "traccc/fitting/fitting_algorithm.hpp"
Expand Down Expand Up @@ -208,6 +209,8 @@ int seq_run(const traccc::opts::detector& detector_opts,
// performance writer
traccc::seeding_performance_writer sd_performance_writer(
traccc::seeding_performance_writer::config{});
traccc::finding_performance_writer find_performance_writer(
traccc::finding_performance_writer::config{});

traccc::performance::timing_info elapsedTimes;

Expand Down Expand Up @@ -502,11 +505,14 @@ int seq_run(const traccc::opts::detector& detector_opts,
sd_performance_writer.write(
vecmem::get_data(seeds_cuda),
vecmem::get_data(spacepoints_per_event_cuda), evt_map);
find_performance_writer.write(
traccc::get_data(track_candidates_cuda), evt_map);
}
}

if (performance_opts.run) {
sd_performance_writer.finalize();
find_performance_writer.finalize();
}

std::cout << "==> Statistics ... " << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion examples/run/kokkos/seeding_example_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
// Read the hits from the relevant event file
traccc::io::read_spacepoints(
reader_output, event, input_opts.directory,
surface_transforms, input_opts.format);
surface_transforms, nullptr, input_opts.format);
} // stop measuring hit reading timer

traccc::spacepoint_collection_types::host& spacepoints_per_event =
Expand Down
2 changes: 1 addition & 1 deletion examples/run/sycl/seeding_example_sycl.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
// Read the hits from the relevant event file
traccc::io::read_spacepoints(
reader_output, event, input_opts.directory,
surface_transforms, input_opts.format);
surface_transforms, nullptr, input_opts.format);

} // stop measuring hit reading timer

Expand Down
6 changes: 3 additions & 3 deletions io/include/traccc/io/csv/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ namespace traccc::io::csv {
struct cell {

uint64_t geometry_id = 0;
uint64_t hit_id = 0;
uint64_t measurement_id = 0;
uint32_t channel0 = 0;
uint32_t channel1 = 0;
float timestamp = 0.;
float value = 0.;

// geometry_id,hit_id,channel0,channel1,timestamp,value
DFE_NAMEDTUPLE(cell, geometry_id, hit_id, channel0, channel1, timestamp,
value);
DFE_NAMEDTUPLE(cell, geometry_id, measurement_id, channel0, channel1,
timestamp, value);
};

} // namespace traccc::io::csv
3 changes: 2 additions & 1 deletion io/include/traccc/io/mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ cell_particle_map generate_cell_particle_map(
const std::string& hits_dir, const std::string& particle_dir,
const geoId_link_map& link_map = geoId_link_map());

std::tuple<measurement_cell_map, cell_module_collection_types::host>
std::pair<std::tuple<measurement_cell_map, cell_module_collection_types::host>,
std::map<uint64_t, uint64_t>>
generate_measurement_cell_map(std::size_t event,
const std::string& detector_file,
const std::string& digi_config_file,
Expand Down
16 changes: 8 additions & 8 deletions io/include/traccc/io/read_cells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void read_cells(
const digitization_config *dconfig = nullptr,
const std::map<std::uint64_t, detray::geometry::barcode> *barcode_map =
nullptr,
bool deduplicate = true);
std::map<uint64_t, uint64_t> *geo_map = nullptr, bool deduplicate = true);

/// Read cell data into memory
///
Expand All @@ -60,12 +60,12 @@ void read_cells(
/// (For Acts->Detray identifier re-mapping, if necessary)
/// @param deduplicate Whether to deduplicate the cells
///
void read_cells(cell_reader_output &out, std::string_view filename,
data_format format = data_format::csv,
const geometry *geom = nullptr,
const digitization_config *dconfig = nullptr,
const std::map<std::uint64_t, detray::geometry::barcode>
*barcode_map = nullptr,
bool deduplicate = true);
void read_cells(
cell_reader_output &out, std::string_view filename,
data_format format = data_format::csv, const geometry *geom = nullptr,
const digitization_config *dconfig = nullptr,
const std::map<std::uint64_t, detray::geometry::barcode> *barcode_map =
nullptr,
std::map<uint64_t, uint64_t> *geo_map = nullptr, bool deduplicate = true);

} // namespace traccc::io
19 changes: 11 additions & 8 deletions io/include/traccc/io/read_spacepoints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ namespace traccc::io {
/// @param geom The description of the detector geometry
/// @param format The format of the cell data files (to read)
///
void read_spacepoints(spacepoint_reader_output& out, std::size_t event,
std::string_view directory, const geometry& geom,
data_format format = data_format::csv);
void read_spacepoints(
spacepoint_reader_output& out, std::size_t event,
std::string_view directory, const geometry& geom,
std::map<std::uint64_t, detray::geometry::barcode>* barcode_map = nullptr,
data_format format = data_format::csv);

/// Read spacepoint data into memory
///
Expand All @@ -45,10 +47,11 @@ void read_spacepoints(spacepoint_reader_output& out, std::size_t event,
/// @param geom The description of the detector geometry
/// @param format The format of the cell data files (to read)
///
void read_spacepoints(spacepoint_reader_output& out, std::string_view filename,
std::string_view meas_filename,
std::string_view meas_hit_map_filename,
const geometry& geom,
data_format format = data_format::csv);
void read_spacepoints(
spacepoint_reader_output& out, std::string_view filename,
std::string_view meas_filename, std::string_view meas_hit_map_filename,
const geometry& geom,
std::map<std::uint64_t, detray::geometry::barcode>* barcode_map = nullptr,
data_format format = data_format::csv);

} // namespace traccc::io
7 changes: 6 additions & 1 deletion io/src/csv/read_cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void read_cells(
cell_reader_output& out, std::string_view filename, const geometry* geom,
const digitization_config* dconfig,
const std::map<std::uint64_t, detray::geometry::barcode>* barcode_map,
const bool deduplicate) {
std::map<uint64_t, uint64_t>* geo_map, const bool deduplicate) {

// Get the cells and modules into an intermediate format.
auto cellsMap = (deduplicate ? read_deduplicated_cells(filename)
Expand All @@ -191,11 +191,16 @@ void read_cells(
// Add the module and its cells to the output.
out.modules.push_back(
get_module(geometry_id, geom, dconfig, original_geometry_id));

for (auto& cell : cells) {
out.cells.push_back(cell);
// Set the module link.
out.cells.back().module_link = out.modules.size() - 1;
}

if (geo_map != nullptr) {
(*geo_map)[geometry_id] = original_geometry_id;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions io/src/csv/read_cells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void read_cells(cell_reader_output& out, std::string_view filename,
const digitization_config* dconfig = nullptr,
const std::map<std::uint64_t, detray::geometry::barcode>*
barcode_map = nullptr,
std::map<uint64_t, uint64_t>* geo_map = nullptr,
bool deduplicate = true);

} // namespace traccc::io::csv
15 changes: 10 additions & 5 deletions io/src/csv/read_spacepoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

namespace traccc::io::csv {

void read_spacepoints(spacepoint_reader_output& out, std::string_view filename,
std::string_view meas_filename,
std::string_view meas_hit_map_filename,
const geometry& geom) {
void read_spacepoints(
spacepoint_reader_output& out, std::string_view filename,
std::string_view meas_filename, std::string_view meas_hit_map_filename,
const geometry& geom,
std::map<std::uint64_t, detray::geometry::barcode>* barcode_map) {
// Read measurements
measurement_reader_output meas_reader_out;
read_measurements(meas_reader_out, meas_filename, false);
Expand Down Expand Up @@ -59,7 +60,11 @@ void read_spacepoints(spacepoint_reader_output& out, std::string_view filename,
m[iohit.geometry_id] = link;
cell_module mod;
mod.surface_link = detray::geometry::barcode{iohit.geometry_id};
mod.placement = geom[iohit.geometry_id];
if (barcode_map == nullptr) {
mod.placement = geom[iohit.geometry_id];
} else {
mod.placement = geom[(*barcode_map)[iohit.geometry_id].value()];
}
result_modules.push_back(mod);
}

Expand Down
9 changes: 5 additions & 4 deletions io/src/csv/read_spacepoints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ namespace traccc::io::csv {
/// @param filename The file to read the spacepoint data from
/// @param geom The description of the detector geometry
///
void read_spacepoints(spacepoint_reader_output& out, std::string_view filename,
std::string_view meas_filename,
std::string_view meas_hit_map_filename,
const geometry& geom);
void read_spacepoints(
spacepoint_reader_output& out, std::string_view filename,
std::string_view meas_filename, std::string_view meas_hit_map_filename,
const geometry& geom,
std::map<std::uint64_t, detray::geometry::barcode>* barcode_map = nullptr);

} // namespace traccc::io::csv
27 changes: 17 additions & 10 deletions io/src/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ hit_cell_map generate_hit_cell_map(std::size_t event,

while (creader.read(iocell)) {
unsigned int link = 0;
auto it = link_map.find(iocell.geometry_id);
auto it = link_map.find(
detray::geometry::barcode{iocell.geometry_id}.value());

if (it != link_map.end()) {
link = (*it).second;
}
result[hmap[iocell.hit_id]].push_back(

result[hmap[iocell.measurement_id]].push_back(
cell{iocell.channel0, iocell.channel1, iocell.value,
iocell.timestamp, link});
}
Expand Down Expand Up @@ -185,29 +188,32 @@ cell_particle_map generate_cell_particle_map(std::size_t event,
return result;
}

std::tuple<measurement_cell_map, cell_module_collection_types::host>
std::pair<std::tuple<measurement_cell_map, cell_module_collection_types::host>,
std::map<uint64_t, uint64_t>>
generate_measurement_cell_map(std::size_t event,
const std::string& detector_file,
const std::string& digi_config_file,
const std::string& cells_dir,
vecmem::memory_resource& resource) {

measurement_cell_map result;
std::map<uint64_t, uint64_t> geo_map;

// CCA algorithms
host::sparse_ccl_algorithm cc(resource);
host::measurement_creation_algorithm mc(resource);

// Read the surface transforms
auto [surface_transforms, _] = io::read_geometry(detector_file);
auto [surface_transforms, barcode_map] =
io::read_geometry(detector_file, traccc::data_format::json);

// Read the digitization configuration file
auto digi_cfg = io::read_digitization_config(digi_config_file);

// Read the cells from the relevant event file
traccc::io::cell_reader_output readOut(&resource);
io::read_cells(readOut, event, cells_dir, traccc::data_format::csv,
&surface_transforms, &digi_cfg, nullptr, false);
&surface_transforms, &digi_cfg, barcode_map.get(), &geo_map);
cell_collection_types::host& cells_per_event = readOut.cells;
cell_module_collection_types::host& modules_per_event = readOut.modules;

Expand All @@ -223,7 +229,7 @@ generate_measurement_cell_map(std::size_t event,
result[measurements_per_event[i]] = clus;
}

return {result, modules_per_event};
return {{result, modules_per_event}, geo_map};
}

measurement_particle_map generate_measurement_particle_map(
Expand All @@ -235,7 +241,7 @@ measurement_particle_map generate_measurement_particle_map(
measurement_particle_map result;

// generate measurement cell map
auto gen_m_c_map = generate_measurement_cell_map(
auto [gen_m_c_map, geo_map] = generate_measurement_cell_map(
event, detector_file, digi_config_file, cells_dir, resource);
auto& m_c_map = std::get<0>(gen_m_c_map);
auto& modules = std::get<1>(gen_m_c_map);
Expand All @@ -244,7 +250,7 @@ measurement_particle_map generate_measurement_particle_map(
geoId_link_map link_map;

for (unsigned int i = 0; i < modules.size(); ++i) {
link_map[modules[i].surface_link.value()] = i;
link_map[geo_map[modules[i].surface_link.value()]] = i;
}

// generate cell particle map
Expand All @@ -268,12 +274,13 @@ measurement_particle_map generate_measurement_particle_map(
measurement_particle_map result;

// Read the surface transforms
auto [surface_transforms, _] = io::read_geometry(detector_file);
auto [surface_transforms, barcode_map] =
io::read_geometry(detector_file, traccc::data_format::json);

// Read the spacepoints from the relevant event file
traccc::io::spacepoint_reader_output readOut(&resource);
io::read_spacepoints(readOut, event, hits_dir, surface_transforms,
traccc::data_format::csv);
barcode_map.get(), traccc::data_format::csv);
spacepoint_collection_types::host& spacepoints_per_event =
readOut.spacepoints;
cell_module_collection_types::host& modules = readOut.modules;
Expand Down
Loading
Loading