ATLAS Offline Software
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
18 #include "ActsInterop/TableUtils.h"
25 
26 namespace ActsTrk {
27 
29  ISvcLocator* pSvcLocator)
30  : AthReentrantAlgorithm(name, pSvcLocator) {}
31 
33  ATH_MSG_INFO("Initializing " << name() << " ... ");
34  if (m_fastTracking)
35  ATH_MSG_INFO(" using fast tracking configuration.");
36 
37  // Retrieve seed tool
38  ATH_CHECK(m_seedsTool.retrieve());
39 
40  // Cond
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 
62 StatusCode GridTripletSeedingAlg::execute(const EventContext& ctx) const {
63  ATH_MSG_DEBUG("Executing " << name() << " ... ");
64 
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
ActsTrk::GridTripletSeedingAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: GridTripletSeedingAlg.h:49
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
ATLASMagneticFieldWrapper
Definition: ATLASMagneticFieldWrapper.h:15
python.SystemOfUnits.mm
float mm
Definition: SystemOfUnits.py:98
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AtlasFieldCacheCondObj
Definition: AtlasFieldCacheCondObj.h:19
ActsTrk::GridTripletSeedingAlg::GridTripletSeedingAlg
GridTripletSeedingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GridTripletSeedingAlg.cxx:28
ITkSiSpacePointForSeed.h
ATLASMagneticFieldWrapper.h
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:85
ATLASMagneticFieldWrapper::makeCache
MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
Definition: ATLASMagneticFieldWrapper.h:34
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
ActsTrk::GridTripletSeedingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: GridTripletSeedingAlg.cxx:62
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
ActsTrk::GridTripletSeedingAlg::kNSpacepoints
@ kNSpacepoints
Definition: GridTripletSeedingAlg.h:68
GridTripletSeedingAlg.h
SpacePointCollection.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
makeTable
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition: TableUtils.h:523
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
ActsTrk::GridTripletSeedingAlg::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: GridTripletSeedingAlg.h:53
ActsTrk::GridTripletSeedingAlg::finalize
virtual StatusCode finalize() override
Definition: GridTripletSeedingAlg.cxx:53
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ActsTrk::GridTripletSeedingAlg::m_seedKey
SG::WriteHandleKey< ActsTrk::SeedContainer > m_seedKey
Definition: GridTripletSeedingAlg.h:61
SiSpacePointForSeed.h
calibdata.exception
exception
Definition: calibdata.py:495
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
ActsTrk::GridTripletSeedingAlg::m_seedsTool
ToolHandle< ActsTrk::ISeedingTool > m_seedsTool
Definition: GridTripletSeedingAlg.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::GridTripletSeedingAlg::m_fastTracking
Gaudi::Property< bool > m_fastTracking
Definition: GridTripletSeedingAlg.h:64
ActsTrk::GridTripletSeedingAlg::initialize
virtual StatusCode initialize() override
Definition: GridTripletSeedingAlg.cxx:32
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SiDetectorElementCollection.h
SiDetectorElement.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
InDet::BeamSpotData
Definition: BeamSpotData.h:21
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATLASMagneticFieldWrapper::getField
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Acts::MagneticFieldProvider::Cache &gcache) const override
Definition: ATLASMagneticFieldWrapper.h:39
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:66
ActsTrk::GridTripletSeedingAlg::kNSeeds
@ kNSeeds
Definition: GridTripletSeedingAlg.h:68
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MSTrackingVolumeBuilder.cxx:24
ActsTrk::GridTripletSeedingAlg::m_fieldCondObjInputKey
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
Definition: GridTripletSeedingAlg.h:55
TableUtils.h
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ActsTrk::GridTripletSeedingAlg::m_spacePointKey
SG::ReadHandleKeyArray< xAOD::SpacePointContainer > m_spacePointKey
Definition: GridTripletSeedingAlg.h:59
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32