Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:38

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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   // Prepare the I/O collections
0021   m_outputMaterialTracks.initialize(m_cfg.outputMaterialTracks);
0022   // Check the configuration - material validater
0023   if (m_cfg.materialValidater == nullptr) {
0024     throw std::invalid_argument("Missing material validater.");
0025   }
0026   // Check the configuration - random number service
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   // Create a random number generator
0034   ActsExamples::RandomEngine rng =
0035       m_cfg.randomNumberSvc->spawnGenerator(context);
0036 
0037   // Setup random number distributions for some quantities
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   // The output recorded material track collection
0044   std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
0045       recordedMaterialTracks;
0046 
0047   // Loop over the number of tracks
0048   for (std::size_t iTrack = 0; iTrack < m_cfg.ntracks; ++iTrack) {
0049     // Generate a random phi and eta
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     // Record the material
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   // Write the mapped and unmapped material tracks to the output
0066   m_outputMaterialTracks(context, std::move(recordedMaterialTracks));
0067 
0068   return ProcessCode::SUCCESS;
0069 }
0070 
0071 }  // namespace ActsExamples