ATLAS Offline Software
Loading...
Searching...
No Matches
Acts/ActsMaterial/src/MaterialValidation.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "CLHEP/Random/RandomEngine.h"
8#include "GaudiKernel/IInterface.h"
10#include "Acts/Geometry/TrackingGeometry.hpp"
11#include "Acts/Material/IntersectionMaterialAssigner.hpp"
12
13ActsTrk::MaterialValidation::MaterialValidation(const std::string& name, ISvcLocator* pSvcLocator) :
14 AthReentrantAlgorithm(name, pSvcLocator)
15{}
16
19
21{
23 ATH_CHECK(m_rndmGenSvc.retrieve());
25
26 // Retrieve the material surfaces
27 std::vector<const Acts::Surface*> materialSurfaces = {};
28
29 auto surfaceSelector = [&](const Acts::Surface* surface) {
30 if (surface->surfaceMaterial() != nullptr &&
31 std::ranges::find(materialSurfaces, surface) == materialSurfaces.end()) {
32 materialSurfaces.push_back(surface);
33 }
34 };
35
36 // Visit all surfaces (second argument = if true only sensitive surfaces are visited)
37 m_trackingGeometrySvc->trackingGeometry()->visitSurfaces(surfaceSelector, false);
38
39 // The material intersection assigner
40 Acts::IntersectionMaterialAssigner::Config assingerConfig;
41 assingerConfig.surfaces = materialSurfaces;
42 auto materialAssigner = std::make_shared<Acts::IntersectionMaterialAssigner>(assingerConfig,
43 makeActsAthenaLogger(this, "MaterialAssigner"));
44
46 Acts::MaterialValidator::Config validatorConfig;
47 validatorConfig.materialAssigner = materialAssigner;
48 m_materialValidator = std::make_shared<Acts::MaterialValidator> (validatorConfig,
49 makeActsAthenaLogger(this, "MaterialValidator"));
50
51 return StatusCode::SUCCESS;
52}
53
54StatusCode
55ActsTrk::MaterialValidation::execute (const EventContext& ctx) const
56{
57 // Write to the collection to the EventStore
59
60 // Record the collection once per event if not already there
61 if (!materialTracks.isPresent()) {
62 auto coll = std::make_unique<ActsTrk::RecordedMaterialTrackCollection>();
63 ATH_CHECK(materialTracks.record(std::move(coll)));
64 }
65
66 // Add the track to the recorded collection
67 auto* coll = materialTracks.ptr();
68 if (!coll) {
69 ATH_MSG_ERROR("RecordedMaterialTrackCollection ptr() is null for key "
71 return StatusCode::FAILURE;
72 }
73
74 // Some useful parameters to be used later
75 Acts::Vector3 startPosition(0., 0., 0.);
76 const ActsTrk::GeometryContext& geoContext{m_trackingGeometrySvc->getNominalContext()};
77 Acts::MagneticFieldContext magFieldContext;
78
79 ATHRNG::RNGWrapper *wrapper = m_rndmGenSvc->getEngine(this);
80 wrapper->setSeed(name(), ctx);
81 CLHEP::HepRandomEngine *rndmEngine = wrapper->getEngine(ctx);
82
83 // Loop over the number of tracks
84 for (std::size_t iTrack = 0; iTrack < m_nTracks; ++iTrack) {
85 // Generate a random phi and eta
86 double phi = rndmEngine->flat() * 2 * M_PI - M_PI;
87 double eta = rndmEngine->flat() * std::abs(m_etaRange.value().second - m_etaRange.value().first) + m_etaRange.value().first;
88 double theta = 2 * std::atan(std::exp(-eta));
89 Acts::Vector3 direction(std::cos(phi) * std::sin(theta),
90 std::sin(phi) * std::sin(theta), std::cos(theta));
91
92 // Record the material
93 auto rmTrack = m_materialValidator->recordMaterial(geoContext.context(),
94 magFieldContext,
95 startPosition,
96 direction);
97
98 // filling the collection
99 coll->push_back(std::move(rmTrack));
100
101 }
102
103 return StatusCode::SUCCESS;
104
105}
106
107
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
Acts::GeometryContext context() const
virtual StatusCode execute(const EventContext &ctx) const override
ServiceHandle< IAthRNGSvc > m_rndmGenSvc
The random number service.
SG::WriteHandleKey< RecordedMaterialTrackCollection > m_materialTrackCollectionKey
The RecordedMaterialTrackCollection to write.
MaterialValidation(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::pair< double, double > > m_etaRange
The eta range for track generation.
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
The tracking geometry service to retrive the geometry context and material surfaces.
std::shared_ptr< Acts::MaterialValidator > m_materialValidator
The material validator from the ACTS core components.
Gaudi::Property< size_t > m_nTracks
The number of tracks to use per event.
An algorithm that can be simultaneously executed in multiple threads.
bool isPresent() const
Is the referenced object present in SG?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.