ATLAS Offline Software
Loading...
Searching...
No Matches
SeedingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "src/SeedingAlg.h"
6
7// ACTS
8#include "Acts/Definitions/Units.hpp"
9#include "Acts/MagneticField/MagneticFieldContext.hpp"
11#include "Acts/Seeding/BinnedGroup.hpp"
12#include "Acts/Seeding/SeedFilter.hpp"
13#include "Acts/Seeding/SeedFinder.hpp"
14
20
21
23
25
26namespace ActsTrk {
27 SeedingAlg::SeedingAlg( const std::string &name,
28 ISvcLocator *pSvcLocator )
29 : AthReentrantAlgorithm( name,pSvcLocator )
30 {}
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() );
42 ATH_CHECK( m_fieldCondObjInputKey.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
53 StatusCode SeedingAlg::finalize() {
54 ATH_MSG_INFO("Seed statistics" << std::endl << makeTable(m_stat,
55 std::array<std::string, kNStat>{
56 "Spacepoints",
57 "Seeds"
58 }).columnWidth(10));
59 return StatusCode::SUCCESS;
60 }
61
62 StatusCode SeedingAlg::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 = Monitored::Timer<std::chrono::milliseconds>( "TIME_seedCreation" );
67 auto mon_nSeeds = Monitored::Scalar<int>("nSeeds");
68 auto mon = Monitored::Group( m_monTool, timer, time_seedCreation, mon_nSeeds );
69
70 // ================================================== //
71 // ===================== OUTPUTS ==================== //
72 // ================================================== //
73
75 ATH_MSG_DEBUG( " \\__ Seed Container `" << m_seedKey.key() << "` created ..." );
76 ATH_CHECK( seedHandle.record( std::make_unique< ActsTrk::SeedContainer >() ) );
77 ActsTrk::SeedContainer *seedPtrs = seedHandle.ptr();
78
79 // ================================================== //
80 // ===================== INPUTS ===================== //
81 // ================================================== //
82
83 // Read the Beam Spot information
85 ATH_CHECK( beamSpotHandle.isValid() );
86 if (beamSpotHandle.cptr() == nullptr) {
87 ATH_MSG_ERROR("Retrieved Beam Spot Handle contains a nullptr");
88 return StatusCode::FAILURE;
89 }
90 auto beamSpotData = beamSpotHandle.cptr();
91 // Beam Spot Position
92 Acts::Vector3 beamPos( beamSpotData->beamPos().x() * Acts::UnitConstants::mm,
93 beamSpotData->beamPos().y() * Acts::UnitConstants::mm,
94 beamSpotData->beamPos().z() * Acts::UnitConstants::mm);
95
96
97 ATH_MSG_DEBUG( "Retrieving elements from " << m_spacePointKey.size() << " input collections...");
98 std::vector<const xAOD::SpacePointContainer *> all_input_collections;
99 all_input_collections.reserve(m_spacePointKey.size());
100
101 std::size_t number_input_space_points = 0;
102 for (const auto& spacePointKey : m_spacePointKey) {
103 ATH_MSG_DEBUG( "Retrieving from Input Collection '" << spacePointKey.key() << "' ..." );
104 SG::ReadHandle< xAOD::SpacePointContainer > handle = SG::makeHandle( spacePointKey, ctx );
105 ATH_CHECK( handle.isValid() );
106 all_input_collections.push_back(handle.cptr());
107 ATH_MSG_DEBUG( " \\__ " << handle->size() << " elements!");
108 number_input_space_points += handle->size();
109 }
110
111 // Apply selection on which SPs you want to use from the input container
112 std::vector<const xAOD::SpacePoint*> selectedSpacePoints;
113 selectedSpacePoints.reserve(number_input_space_points);
114
115 for (const auto* collection : all_input_collections) {
116 selectedSpacePoints.insert(selectedSpacePoints.end(), collection->begin(), collection->end());
117 }
118
119 ATH_MSG_DEBUG( " \\__ Total input space points: " << selectedSpacePoints.size());
120 m_stat[kNSpacepoints] += selectedSpacePoints.size();
121
122 // Early Exit in case no space points at this stage
123 if (selectedSpacePoints.empty()) {
124 ATH_MSG_DEBUG("No input space points found, we stop seeding");
125 return StatusCode::SUCCESS;
126 }
127
128 // ================================================== //
129 // ===================== CONDS ====================== //
130 // ================================================== //
131
132 // Read the b-field information
134 ATH_CHECK( readHandle.isValid() );
135
136 const AtlasFieldCacheCondObj* fieldCondObj{ *readHandle };
137 if (fieldCondObj == nullptr) {
138 ATH_MSG_ERROR("Failed to retrieve AtlasFieldCacheCondObj with key " << m_fieldCondObjInputKey.key());
139 return StatusCode::FAILURE;
140 }
141
142 // Get the magnetic field
143 // Using ACTS classes in order to be sure we are consistent
144 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
145 ATLASMagneticFieldWrapper magneticField;
146 Acts::MagneticFieldProvider::Cache magFieldCache = magneticField.makeCache( magFieldContext );
147 Acts::Vector3 bField = *magneticField.getField( Acts::Vector3(beamPos.x(), beamPos.y(), 0),
148 magFieldCache );
149
150 // ================================================== //
151 // ===================== COMPUTATION ================ //
152 // ================================================== //
153
154 ActsTrk::SpacePointCollector backEnd(selectedSpacePoints);
155
156 Acts::SpacePointContainerConfig spConfig;
157 spConfig.useDetailedDoubleMeasurementInfo = not m_usePixel;
158 // Options
159 Acts::SpacePointContainerOptions spOptions;
160 spOptions.beamPos = Acts::Vector2(beamPos.x(), beamPos.y());
161
162 Acts::SpacePointContainer<decltype(backEnd), Acts::detail::RefHolder> collect(spConfig, spOptions, backEnd);
163
164 ATH_MSG_DEBUG("Running Seed Finding ...");
165 time_seedCreation.start();
166 ATH_CHECK( m_seedsTool->createSeeds( ctx,
167 collect,
168 beamPos,
169 bField,
170 *seedPtrs ) );
171 time_seedCreation.stop();
172 ATH_MSG_DEBUG(" \\__ Created " << seedPtrs->size() << " seeds");
173 m_stat[kNSeeds] += seedPtrs->size();
174
175 mon_nSeeds = seedPtrs->size();
176
177 return StatusCode::SUCCESS;
178 }
179
180} // namespace
#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::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition SeedingAlg.h:56
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
ToolHandle< GenericMonitoringTool > m_monTool
Definition SeedingAlg.h:53
SeedingAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode finalize() override
Gaudi::Property< bool > m_fastTracking
Definition SeedingAlg.h:63
SG::WriteHandleKey< ActsTrk::SeedContainer > m_seedKey
Definition SeedingAlg.h:61
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
Definition SeedingAlg.h:57
SG::ReadHandleKeyArray< xAOD::SpacePointContainer > m_spacePointKey
Definition SeedingAlg.h:60
ToolHandle< ActsTrk::ISeedingTool > m_seedsTool
Definition SeedingAlg.h:52
Gaudi::Property< bool > m_usePixel
Definition SeedingAlg.h:64
An algorithm that can be simultaneously executed in multiple threads.
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
A monitored timer.
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
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...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())