ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimSeedingAlg.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
4#include <array>
5#include <map>
7
8namespace FPGATrackSim {
9
10 FPGATrackSim::FPGATrackSimSeedingAlg::FPGATrackSimSeedingAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {
11}
16 ATH_CHECK(m_seedKey.initialize());
17
18 return StatusCode::SUCCESS;
19 }
20
21 StatusCode FPGATrackSimSeedingAlg::execute(const EventContext& ctx) const {
22
26
27 ATH_CHECK(tracksHandle.isValid());
28 ATH_CHECK(pixelClustersHandle.isValid());
29 ATH_CHECK(spacePointsHandle.isValid());
30
32 ATH_CHECK(seedHandle.record(std::make_unique<ActsTrk::SeedContainer>()));
33 ActsTrk::SeedContainer* seeds = seedHandle.ptr();
34
35 // Use a map since identifiers are unique
36 std::map<Identifier::value_type, const xAOD::SpacePoint*> spacePointMap;
37
38 // Populate the map with pixel cluster identifier (rdoID) as key.
39 // Only space points with one measurement are considered (i.e. pixels). In case strips are needed the code should not be based on the one-measurement-per-space-point assumption.
40 for (const xAOD::SpacePoint* spacePoint : *spacePointsHandle) {
41 if (!spacePoint->measurements().empty()) {
42 const auto identifier = spacePoint->measurements().at(0)->identifier();
43
44 // Check for duplicates (shouldn't happen if all works as expected)
45 auto [it, inserted] = spacePointMap.emplace(identifier, spacePoint);
46 if (!inserted) {
47 ATH_MSG_ERROR("Duplicate identifier 0x" << std::hex << identifier << std::dec
48 << " found for space point. Keeping first occurrence.");
49 }
50 }
51 }
52
53 seeds->reserve(tracksHandle->size());
54 // loop over the tracks and make seeds based on the hits in FPGATrackSimTracks
55 for (const auto& track : *tracksHandle) {
56 std::vector<const xAOD::SpacePoint*> spacePointsToStoreInSeed;
57 for (const auto& hit : track.getFPGATrackSimHitPtrs()) {
58 if (!hit) continue;
59 if (hit->isReal() && hit->isPixel()) {
60 ATH_MSG_DEBUG("Hit coordinates in module " << hit->getRdoIdentifier()
61 << ": (" << hit->getPhiCoord() << ", " << hit->getEtaCoord() << ")");
62
63 // map lookup
64 auto it = spacePointMap.find(hit->getRdoIdentifier());
65 if (it != spacePointMap.end()) {
66 spacePointsToStoreInSeed.push_back(it->second);
67 } else {
68 ATH_MSG_ERROR("No SP found for hit identifier 0x"
69 << std::hex << hit->getRdoIdentifier() << std::dec);
70 }
71
72 // stop in case we reach the maximum number of space points allowed
73 if (spacePointsToStoreInSeed.size() == m_maxSpacePointsPerSeed) break;
74 }
75 }
76
77 // Construct seed based on the space points stored in the vector
78 if (spacePointsToStoreInSeed.size() >= m_minSpacePointsPerSeed) { // check that seeds contains at least the minimum number of desired space points
79 // TODO: validate if this is correct. (technically the larger the value, the better the quality of the seed)
80 // or another default value? TODO: check if that's fine
81 const float quality = track.getChi2ndof() != 0.0 ? 1.0 / track.getChi2ndof() : 0.0;
82
83 seeds->push_back(spacePointsToStoreInSeed, quality, track.getZ0());
84 }
85 }
86
87 ATH_MSG_DEBUG("Recorded " << seeds->size() << " seeds");
88 return StatusCode::SUCCESS;
89 }
90} // namespace FPGATrackSim
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_pixelClusterContainerKey
Gaudi::Property< size_t > m_maxSpacePointsPerSeed
SG::ReadHandleKey< FPGATrackSimTrackCollection > m_FPGATrackCollectionKey
SG::ReadHandleKey< xAOD::SpacePointContainer > m_spacePointContainerKey
virtual StatusCode initialize() override final
FPGATrackSimSeedingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< size_t > m_minSpacePointsPerSeed
SG::WriteHandleKey< ActsTrk::SeedContainer > m_seedKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
Seed push_back(SpacePointRange spacePoints, float quality, float vertexZ)
void reserve(std::size_t size, float averageSpacePoints=3) noexcept
std::size_t size() const noexcept