-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement digitization configurator for detray geometries
- Loading branch information
1 parent
7a4aca5
commit f67290c
Showing
9 changed files
with
517 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** 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/io/digitization_configurator.hpp" | ||
#include "traccc/io/read_digitization_config.hpp" | ||
#include "traccc/io/write_digitization_config.hpp" | ||
#include "traccc/options/handle_argument_errors.hpp" | ||
|
||
// Detray include(s) | ||
#include "detray/core/detector.hpp" | ||
#include "detray/geometry/surface.hpp" | ||
#include "detray/io/common/detector_reader.hpp" | ||
|
||
// VecMem include(s). | ||
#include <vecmem/memory/host_memory_resource.hpp> | ||
|
||
// Boost | ||
#include <boost/program_options.hpp> | ||
|
||
// System include(s) | ||
#include <sstream> | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
namespace po = boost::program_options; | ||
|
||
/// @brief create a detailed digitization file for the given detector | ||
/// | ||
/// Takes a human editable digitization "meta"-configuration file and assigns | ||
/// the given configuration to the specified surfaces by visitng the geometry. | ||
/// For every discovered surface in a digitization domain, the respective | ||
/// digitization configuration is written into the output json file. | ||
/// | ||
/// @param digi_meta_config_file file that contains the editable "meta"-config | ||
/// @param reader_cfg detray detector reader config, specifying the geometry | ||
int create_digitization_config( | ||
const std::string& digi_meta_config_file, | ||
const detray::io::detector_reader_config& reader_cfg) { | ||
|
||
vecmem::host_memory_resource host_mr; | ||
|
||
const auto [det, names] = | ||
detray::io::read_detector<detray::detector<>>(host_mr, reader_cfg); | ||
|
||
std::cout << "Running digitization configurator for \"" << names.at(0) | ||
<< "\"..." << std::endl; | ||
|
||
const traccc::digitization_config digi_meta_cfg = | ||
traccc::io::read_digitization_config(digi_meta_config_file); | ||
|
||
traccc::io::digitization_configurator digi_configurator{digi_meta_cfg}; | ||
|
||
// Visit all detector surfaces to generate their digitization configuration | ||
for (const auto& sf_desc : det.surface_lookup()) { | ||
digi_configurator(detray::surface{det, sf_desc}); | ||
} | ||
|
||
std::string outfile_name = names.at(0) + "-geometric-config.json"; | ||
traccc::io::write_digitization_config(outfile_name, | ||
digi_configurator.output_digi_cfg); | ||
|
||
std::cout << "Done. Written config to: " << outfile_name << std::endl; | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
// The main routine | ||
// | ||
int main(int argc, char* argv[]) { | ||
// Options parsing | ||
po::options_description desc("\ntraccc digitization configurator"); | ||
|
||
desc.add_options()("help", "produce help message")( | ||
"geometry_file", po::value<std::string>(), | ||
"detray geometry input file")("digi_meta_config_file", | ||
po::value<std::string>(), | ||
"digitization meta-configuration file"); | ||
|
||
po::variables_map vm; | ||
po::store(po::parse_command_line(argc, argv, desc), vm); | ||
|
||
traccc::handle_argument_errors(vm, desc); | ||
|
||
// Configs to be filled | ||
detray::io::detector_reader_config reader_cfg{}; | ||
|
||
// Input files | ||
if (vm.count("geometry_file")) { | ||
reader_cfg.add_file(vm["geometry_file"].as<std::string>()); | ||
} else { | ||
std::stringstream err_stream{}; | ||
err_stream << "Please specify a geometry input file!\n\n" << desc; | ||
|
||
throw std::invalid_argument(err_stream.str()); | ||
} | ||
std::string digi_meta_config_file; | ||
if (vm.count("geometry_file")) { | ||
digi_meta_config_file = vm["digi_meta_config_file"].as<std::string>(); | ||
} else { | ||
std::stringstream err_stream{}; | ||
err_stream << "Please specify a digitization meta-configuration input" | ||
<< " file!\n\n" | ||
<< desc; | ||
|
||
throw std::invalid_argument(err_stream.str()); | ||
} | ||
|
||
return create_digitization_config(digi_meta_config_file, reader_cfg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** 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 | ||
*/ | ||
|
||
#pragma once | ||
|
||
// Local include(s). | ||
#include "traccc/io/data_format.hpp" | ||
|
||
// Project include(s). | ||
#include "traccc/io/digitization_config.hpp" | ||
|
||
// Detray include(s). | ||
#include "detray/geometry/barcode.hpp" | ||
#include "detray/geometry/surface.hpp" | ||
|
||
// System include(s). | ||
#include <string_view> | ||
|
||
namespace Acts { | ||
class BinUtility; | ||
} | ||
|
||
namespace traccc::io { | ||
|
||
/// Helper configurator that takes a simplified (per volume, per extra bit) | ||
/// input digitization file and creates a full fletched per module | ||
/// digitization configuration file. | ||
/// | ||
/// It acts as a visitor and then builds a fully developed digitization file | ||
/// for the geometric digitization, filling in the correct dimensions and | ||
/// number of bins. | ||
/// | ||
/// The simplified file is assumed to have just one bin for the geometric | ||
/// digitization, which is then used to calculate the number of bins with | ||
/// respect to the bounds range. | ||
struct digitization_configurator { | ||
/// Simplified input components for digitization (meta-configuration) | ||
digitization_config input_digi_cfg; | ||
|
||
/// Final collection of output components | ||
std::vector< | ||
std::pair<detray::geometry::barcode, module_digitization_config>> | ||
output_digi_cfg; | ||
|
||
/// Needs an input configuration | ||
digitization_configurator() = delete; | ||
|
||
/// Construct from an input configuration @param cfg and initializes an | ||
/// empty output configuration | ||
digitization_configurator(digitization_config cfg) | ||
: input_digi_cfg{cfg}, output_digi_cfg{} {} | ||
|
||
/// The visitor call for the geometry | ||
/// | ||
/// @param surface is the surfaces that is visited | ||
/// | ||
/// Takes the @c input_digi_cfg and adds an appropriate entry into the | ||
/// @c output_digi_cfg for the given surface | ||
template <class detector_t> | ||
void operator()(const detray::surface<detector_t> &surface); | ||
|
||
struct segmentation_configurator { | ||
|
||
/// Create the segmentation for a specific surface from the | ||
/// given configuration in @param input_segmentation. | ||
template <typename mask_t> | ||
void fill_output_segmentation( | ||
const mask_t &mask, const Acts::BinUtility &input_segmentation, | ||
Acts::BinUtility &output_segmentation) const; | ||
|
||
/// Visitor for the surface mask | ||
template <typename mask_group_t, typename index_t> | ||
inline void operator()(const mask_group_t &mask_group, | ||
const index_t &index, | ||
const Acts::BinUtility &input_segmentation, | ||
Acts::BinUtility &output_segmentation) const { | ||
|
||
fill_output_segmentation(mask_group[index], input_segmentation, | ||
output_segmentation); | ||
} | ||
}; | ||
}; | ||
|
||
} // namespace traccc::io | ||
|
||
#include "traccc/io/digitization_configurator.ipp" |
Oops, something went wrong.