File indexing completed on 2025-01-18 09:11:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/MaterialMapping/MaterialValidation.hpp"
0010
0011 #include "ActsExamples/MaterialMapping/IMaterialWriter.hpp"
0012
0013 #include <stdexcept>
0014
0015 namespace ActsExamples {
0016
0017 MaterialValidation::MaterialValidation(const MaterialValidation::Config& cfg,
0018 Acts::Logging::Level level)
0019 : IAlgorithm("MaterialValidation", level), m_cfg(cfg) {
0020
0021 m_outputMaterialTracks.initialize(m_cfg.outputMaterialTracks);
0022
0023 if (m_cfg.materialValidater == nullptr) {
0024 throw std::invalid_argument("Missing material validater.");
0025 }
0026
0027 if (m_cfg.randomNumberSvc == nullptr) {
0028 throw std::invalid_argument("Missing random number service.");
0029 }
0030 }
0031
0032 ProcessCode MaterialValidation::execute(const AlgorithmContext& context) const {
0033
0034 ActsExamples::RandomEngine rng =
0035 m_cfg.randomNumberSvc->spawnGenerator(context);
0036
0037
0038 std::uniform_real_distribution<double> phiDist(m_cfg.phiRange.first,
0039 m_cfg.phiRange.second);
0040 std::uniform_real_distribution<double> etaDist(m_cfg.etaRange.first,
0041 m_cfg.etaRange.second);
0042
0043
0044 std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
0045 recordedMaterialTracks;
0046
0047
0048 for (std::size_t iTrack = 0; iTrack < m_cfg.ntracks; ++iTrack) {
0049
0050 double phi = phiDist(rng);
0051 double eta = etaDist(rng);
0052 double theta = 2 * std::atan(std::exp(-eta));
0053 Acts::Vector3 direction(std::cos(phi) * std::sin(theta),
0054 std::sin(phi) * std::sin(theta), std::cos(theta));
0055
0056
0057 auto rMaterial = m_cfg.materialValidater->recordMaterial(
0058 context.geoContext, context.magFieldContext, m_cfg.startPosition,
0059 direction);
0060
0061 recordedMaterialTracks.emplace_hint(recordedMaterialTracks.end(), iTrack,
0062 rMaterial);
0063 }
0064
0065
0066 m_outputMaterialTracks(context, std::move(recordedMaterialTracks));
0067
0068 return ProcessCode::SUCCESS;
0069 }
0070
0071 }