ATLAS Offline Software
Loading...
Searching...
No Matches
GenericSeedingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// ACTS
8#include "Acts/Definitions/Units.hpp"
9#include "Acts/EventData/SeedContainer2.hpp"
10#include "Acts/EventData/SpacePointContainer2.hpp"
11#include "Acts/MagneticField/MagneticFieldContext.hpp"
12#include "Acts/Seeding/BinnedGroup.hpp"
14
15// Other
23
24namespace ActsTrk {
25
27 ISvcLocator* pSvcLocator)
28 : AthReentrantAlgorithm(name, pSvcLocator) {}
29
31 ATH_MSG_INFO("Initializing " << name() << " ... ");
33 ATH_MSG_INFO(" using fast tracking configuration.");
34
35 // Retrieve seed tool
36 ATH_CHECK(m_seedsTool.retrieve());
37
38 // Cond
39 ATH_CHECK(m_beamSpotKey.initialize());
41
42 // Read and Write handles
43 ATH_CHECK(m_spacePointKey.initialize());
44 ATH_CHECK(m_seedKey.initialize());
45
46 ATH_CHECK(m_monTool.retrieve(EnableTool{not m_monTool.empty()}));
47
48 return StatusCode::SUCCESS;
49}
50
52 ATH_MSG_INFO("Seed statistics" << std::endl
53 << makeTable(m_stat,
54 std::array<std::string, kNStat>{
55 "Spacepoints", "Seeds"})
56 .columnWidth(10));
57 return StatusCode::SUCCESS;
58}
59
60StatusCode GenericSeedingAlg::execute(const EventContext& ctx) const {
61 ATH_MSG_DEBUG("Executing " << name() << " ... ");
62
63 auto timer = Monitored::Timer<std::chrono::milliseconds>("TIME_execute");
64 auto time_seedCreation =
66 auto mon_nSeeds = Monitored::Scalar<int>("nSeeds");
67 auto mon = Monitored::Group(m_monTool, timer, time_seedCreation, mon_nSeeds);
68
69 // ================================================== //
70 // ===================== OUTPUTS ==================== //
71 // ================================================== //
72
75 ATH_MSG_DEBUG(" \\__ Seed Container `" << m_seedKey.key()
76 << "` created ...");
77 ATH_CHECK(seedHandle.record(std::make_unique<ActsTrk::SeedContainer>()));
78 ActsTrk::SeedContainer* seedPtrs = seedHandle.ptr();
79
80 // ================================================== //
81 // ===================== INPUTS ===================== //
82 // ================================================== //
83
84 // Read the Beam Spot information
85 const InDet::BeamSpotData* beamSpotData{nullptr};
86 ATH_CHECK(SG::get(beamSpotData, m_beamSpotKey, ctx));
87 // Beam Spot Position
88 Acts::Vector3 beamPos(beamSpotData->beamPos().x() * Acts::UnitConstants::mm,
89 beamSpotData->beamPos().y() * Acts::UnitConstants::mm,
90 beamSpotData->beamPos().z() * Acts::UnitConstants::mm);
91
92 ATH_MSG_DEBUG("Retrieving elements from " << m_spacePointKey.size()
93 << " input collections...");
94 std::vector<const xAOD::SpacePointContainer*> allInputCollections;
95 allInputCollections.reserve(m_spacePointKey.size());
96
97 for (const auto& spacePointKey : m_spacePointKey) {
98 ATH_MSG_DEBUG("Retrieving from Input Collection '" << spacePointKey.key()
99 << "' ...");
100 const xAOD::SpacePointContainer* spCont{nullptr};
101 ATH_CHECK(SG::get(spCont, spacePointKey, ctx));
102 allInputCollections.push_back(spCont);
103 ATH_MSG_DEBUG(" \\__ " << spCont->size() << " elements!");
104 }
105
106 std::size_t totalSpacePoints = 0;
107 for (const xAOD::SpacePointContainer* collection : allInputCollections) {
108 totalSpacePoints += collection->size();
109 }
110
111 ATH_MSG_DEBUG(" \\__ Total input space points: " << totalSpacePoints);
112 m_stat[kNSpacepoints] += totalSpacePoints;
113
114 // Early Exit in case no space points at this stage
115 if (totalSpacePoints == 0) {
116 ATH_MSG_DEBUG("No input space points found, we stop seeding");
117 return StatusCode::SUCCESS;
118 }
119
120 // ================================================== //
121 // ===================== CONDS ====================== //
122 // ================================================== //
123
124 // Read the b-field information
125 const AtlasFieldCacheCondObj* fieldCondObj{nullptr};
126 ATH_CHECK(SG::get(fieldCondObj, m_fieldCondObjInputKey, ctx));
127
128 // Get the magnetic field
129 // Using ACTS classes in order to be sure we are consistent
130 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
131 ATLASMagneticFieldWrapper magneticField;
132 Acts::MagneticFieldProvider::Cache magFieldCache =
133 magneticField.makeCache(magFieldContext);
134 Acts::Vector3 bField = *magneticField.getField(
135 Acts::Vector3(beamPos.x(), beamPos.y(), 0), magFieldCache);
136
137 // ================================================== //
138 // ===================== COMPUTATION ================ //
139 // ================================================== //
140
141 ATH_MSG_DEBUG("Running Grid Triplet Seed Finding ...");
142 time_seedCreation.start();
143 try {
144 ATH_CHECK(m_seedsTool->createSeeds(ctx, allInputCollections,
145 beamPos.cast<float>(), bField.z(),
146 *seedPtrs));
147 } catch (const std::exception& e) {
148 ATH_MSG_ERROR("Exception caught during seed creation: " << e.what());
149 return StatusCode::FAILURE;
150 }
151 time_seedCreation.stop();
152
153 ATH_MSG_DEBUG(" \\__ Created " << seedPtrs->size() << " seeds");
154 m_stat[kNSeeds] += seedPtrs->size();
155
156 mon_nSeeds = seedPtrs->size();
157
158 return StatusCode::SUCCESS;
159}
160
161} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Header file to be included by clients of the Monitored infrastructure.
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition TableUtils.h:543
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Acts::MagneticFieldProvider::Cache &gcache) const override
MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
GenericSeedingAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
virtual StatusCode finalize() override
SG::ReadHandleKeyArray< xAOD::SpacePointContainer > m_spacePointKey
SG::WriteHandleKey< ActsTrk::SeedContainer > m_seedKey
ToolHandle< GenericMonitoringTool > m_monTool
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< bool > m_fastTracking
ToolHandle< ActsTrk::ISeedingTool > m_seedsTool
An algorithm that can be simultaneously executed in multiple threads.
size_type size() const noexcept
Returns the number of elements in the collection.
const Amg::Vector3D & beamPos() const noexcept
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
A monitored timer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
SpacePointContainer_v1 SpacePointContainer
Define the version of the space point container.
std::size_t size() const noexcept