Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
24 #include "ActsInterop/TableUtils.h"
25 
26 namespace ActsTrk {
27  SeedingAlg::SeedingAlg( const std::string &name,
28  ISvcLocator *pSvcLocator )
29  : AthReentrantAlgorithm( name,pSvcLocator )
30  {}
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 << 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
ActsTrk::SpacePointCollector
Definition: SpacePointCollector.h:20
ActsTrk::SeedingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: SeedingAlg.cxx:62
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:97
ActsTrk::SeedingAlg::finalize
virtual StatusCode finalize() override
Definition: SeedingAlg.cxx:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
AtlasFieldCacheCondObj
Definition: AtlasFieldCacheCondObj.h:19
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
ITkSiSpacePointForSeed.h
ATLASMagneticFieldWrapper.h
ActsTrk::SeedingAlg::m_seedKey
SG::WriteHandleKey< ActsTrk::SeedContainer > m_seedKey
Definition: SeedingAlg.h:61
ActsTrk::SeedingAlg::m_usePixel
Gaudi::Property< bool > m_usePixel
Definition: SeedingAlg.h:64
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
ATLASMagneticFieldWrapper::makeCache
MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
Definition: ATLASMagneticFieldWrapper.h:34
ActsTrk::SeedingAlg::m_seedsTool
ToolHandle< ActsTrk::ISeedingTool > m_seedsTool
Definition: SeedingAlg.h:52
SeedingAlg.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
ActsTrk::SeedingAlg::m_fastTracking
Gaudi::Property< bool > m_fastTracking
Definition: SeedingAlg.h:63
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:521
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::SeedingAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: SeedingAlg.h:53
SiSpacePointForSeed.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsTrk::SeedingAlg::initialize
virtual StatusCode initialize() override
Definition: SeedingAlg.cxx:32
ActsTrk::SeedingAlg::kNSpacepoints
@ kNSpacepoints
Definition: SeedingAlg.h:68
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::SeedingAlg::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: SeedingAlg.h:56
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SiDetectorElementCollection.h
ActsTrk::SeedingAlg::SeedingAlg
SeedingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SeedingAlg.cxx:27
SiDetectorElement.h
ActsTrk::SeedingAlg::m_fieldCondObjInputKey
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
Definition: SeedingAlg.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
ActsTrk::SeedingAlg::kNSeeds
@ kNSeeds
Definition: SeedingAlg.h:69
ActsTrk::SeedingAlg::m_spacePointKey
SG::ReadHandleKeyArray< xAOD::SpacePointContainer > m_spacePointKey
Definition: SeedingAlg.h:60
xAOD::SpacePointContainer
SpacePointContainer_v1 SpacePointContainer
Define the version of the space point container.
Definition: Event/xAOD/xAODInDetMeasurement/xAODInDetMeasurement/SpacePointContainer.h:14
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:67
Trig::FeatureAccessImpl::collect
void collect(const HLT::TriggerElement *te, std::vector< Trig::Feature< T > > &data, const std::string &label, unsigned int condition, const std::string &teName, const HLT::TrigNavStructure *navstructure)
actual feature acceess implementation It has (thanks to the ClassTraits) functionality to flatten con...
Definition: FeatureCollectAthena.h:299
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx: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.
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32