ATLAS Offline Software
Loading...
Searching...
No Matches
GridTripletSeedingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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"
13#include "Acts/Seeding/SeedFilter.hpp"
14#include "Acts/Seeding/SeedFinder.hpp"
16
17// Other
25
26namespace ActsTrk {
27
29 ISvcLocator* pSvcLocator)
30 : AthReentrantAlgorithm(name, pSvcLocator) {}
31
33 ATH_MSG_INFO("Initializing " << name() << " ... ");
35 ATH_MSG_INFO(" using fast tracking configuration.");
36
37 // Retrieve seed tool
38 ATH_CHECK(m_seedsTool.retrieve());
39
40 // Cond
41 ATH_CHECK(m_beamSpotKey.initialize());
43
44 // Read and Write handles
45 ATH_CHECK(m_spacePointKey.initialize());
46 ATH_CHECK(m_seedKey.initialize());
47
48 ATH_CHECK(m_monTool.retrieve(EnableTool{not m_monTool.empty()}));
49
50 return StatusCode::SUCCESS;
51}
52
54 ATH_MSG_INFO("Seed statistics" << std::endl
55 << makeTable(m_stat,
56 std::array<std::string, kNStat>{
57 "Spacepoints", "Seeds"})
58 .columnWidth(10));
59 return StatusCode::SUCCESS;
60}
61
62StatusCode GridTripletSeedingAlg::execute(const EventContext& ctx) const {
63 ATH_MSG_DEBUG("Executing " << name() << " ... ");
64
65 auto timer = Monitored::Timer<std::chrono::milliseconds>("TIME_execute");
66 auto time_seedCreation =
68 auto mon_nSeeds = Monitored::Scalar<int>("nSeeds");
69 auto mon = Monitored::Group(m_monTool, timer, time_seedCreation, mon_nSeeds);
70
71 // ================================================== //
72 // ===================== OUTPUTS ==================== //
73 // ================================================== //
74
77 ATH_MSG_DEBUG(" \\__ Seed Container `" << m_seedKey.key()
78 << "` created ...");
79 ATH_CHECK(seedHandle.record(std::make_unique<ActsTrk::SeedContainer>()));
80 ActsTrk::SeedContainer* seedPtrs = seedHandle.ptr();
81
82 // ================================================== //
83 // ===================== INPUTS ===================== //
84 // ================================================== //
85
86 // Read the Beam Spot information
87 const InDet::BeamSpotData* beamSpotData{nullptr};
88 ATH_CHECK(SG::get(beamSpotData, m_beamSpotKey, ctx));
89 // Beam Spot Position
90 Acts::Vector3 beamPos(beamSpotData->beamPos().x() * Acts::UnitConstants::mm,
91 beamSpotData->beamPos().y() * Acts::UnitConstants::mm,
92 beamSpotData->beamPos().z() * Acts::UnitConstants::mm);
93
94 ATH_MSG_DEBUG("Retrieving elements from " << m_spacePointKey.size()
95 << " input collections...");
96 std::vector<const xAOD::SpacePointContainer*> allInputCollections;
97 allInputCollections.reserve(m_spacePointKey.size());
98
99 for (const auto& spacePointKey : m_spacePointKey) {
100 ATH_MSG_DEBUG("Retrieving from Input Collection '" << spacePointKey.key()
101 << "' ...");
102 const xAOD::SpacePointContainer* spCont{nullptr};
103 ATH_CHECK(SG::get(spCont, spacePointKey, ctx));
104 allInputCollections.push_back(spCont);
105 ATH_MSG_DEBUG(" \\__ " << spCont->size() << " elements!");
106 }
107
108 std::size_t totalSpacePoints = 0;
109 for (const xAOD::SpacePointContainer* collection : allInputCollections) {
110 totalSpacePoints += collection->size();
111 }
112
113 ATH_MSG_DEBUG(" \\__ Total input space points: " << totalSpacePoints);
114 m_stat[kNSpacepoints] += totalSpacePoints;
115
116 // Early Exit in case no space points at this stage
117 if (totalSpacePoints == 0) {
118 ATH_MSG_DEBUG("No input space points found, we stop seeding");
119 return StatusCode::SUCCESS;
120 }
121
122 // ================================================== //
123 // ===================== CONDS ====================== //
124 // ================================================== //
125
126 // Read the b-field information
127 const AtlasFieldCacheCondObj* fieldCondObj{nullptr};
128 ATH_CHECK(SG::get(fieldCondObj, m_fieldCondObjInputKey, ctx));
129
130 // Get the magnetic field
131 // Using ACTS classes in order to be sure we are consistent
132 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
133 ATLASMagneticFieldWrapper magneticField;
134 Acts::MagneticFieldProvider::Cache magFieldCache =
135 magneticField.makeCache(magFieldContext);
136 Acts::Vector3 bField = *magneticField.getField(
137 Acts::Vector3(beamPos.x(), beamPos.y(), 0), magFieldCache);
138
139 // ================================================== //
140 // ===================== COMPUTATION ================ //
141 // ================================================== //
142
143 ATH_MSG_DEBUG("Running Grid Triplet Seed Finding ...");
144 time_seedCreation.start();
145 try {
146 ATH_CHECK(m_seedsTool->createSeeds2(ctx, allInputCollections,
147 beamPos.cast<float>(), bField.z(),
148 *seedPtrs));
149 } catch (const std::exception& e) {
150 ATH_MSG_ERROR("Exception caught during seed creation: " << e.what());
151 return StatusCode::FAILURE;
152 }
153 time_seedCreation.stop();
154
155 ATH_MSG_DEBUG(" \\__ Created " << seedPtrs->size() << " seeds");
156 m_stat[kNSeeds] += seedPtrs->size();
157
158 mon_nSeeds = seedPtrs->size();
159
160 return StatusCode::SUCCESS;
161}
162
163} // 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:523
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Acts::MagneticFieldProvider::Cache &gcache) const override
MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
SG::ReadHandleKeyArray< xAOD::SpacePointContainer > m_spacePointKey
GridTripletSeedingAlg(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< ActsTrk::ISeedingTool > m_seedsTool
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Gaudi::Property< bool > m_fastTracking
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
virtual StatusCode finalize() override
SG::WriteHandleKey< ActsTrk::SeedContainer > m_seedKey
ToolHandle< GenericMonitoringTool > m_monTool
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.