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, Acts::SpacePointIndex2> spacePointMap;
37 seeds->spacePoints().reserve(spacePointsHandle->size());
38
39 // Populate the map with pixel cluster identifier (rdoID) as key.
40 // 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.
41 for (const xAOD::SpacePoint* spacePoint : *spacePointsHandle) {
42 if (!spacePoint->measurements().empty()) {
43 seeds->spacePoints().push_back(spacePoint);
44 const auto identifier = spacePoint->measurements().at(0)->identifier();
45
46 // Check for duplicates (shouldn't happen if all works as expected)
47 auto [it, inserted] = spacePointMap.emplace(identifier, seeds->spacePoints().size()-1ul);
48 if (!inserted) {
49 ATH_MSG_ERROR("Duplicate identifier 0x" << std::hex << identifier << std::dec
50 << " found for space point. Keeping first occurrence.");
51 }
52 }
53 }
54
55 seeds->reserve(tracksHandle->size());
56 // loop over the tracks and make seeds based on the hits in FPGATrackSimTracks
57 for (const auto& track : *tracksHandle) {
58 std::vector<Acts::SpacePointIndex2> spacePointsToStoreInSeed;
59 for (const FPGATrackSimHit& hit : track.getFPGATrackSimHits()) {
60 if (hit.isReal() && hit.isPixel()) {
61 ATH_MSG_DEBUG("Hit coordinates in module " << hit.getRdoIdentifier()
62 << ": (" << hit.getPhiCoord() << ", " << hit.getEtaCoord() << ")");
63
64 // map lookup
65 auto it = spacePointMap.find(hit.getRdoIdentifier());
66 if (it != spacePointMap.end()) {
67 spacePointsToStoreInSeed.push_back(it->second);
68 } else {
69 ATH_MSG_ERROR("No SP found for hit identifier 0x"
70 << std::hex << hit.getRdoIdentifier() << std::dec);
71 }
72
73 // stop in case we reach the maximum number of space points allowed
74 if (spacePointsToStoreInSeed.size() == m_maxSpacePointsPerSeed) break;
75 }
76 }
77
78 // Construct seed based on the space points stored in the vector
79 if (spacePointsToStoreInSeed.size() >= m_minSpacePointsPerSeed) { // check that seeds contains at least the minimum number of desired space points
80 auto seed = seeds->push_back(spacePointsToStoreInSeed);
81 seed.vertexZ() = track.getZ0();
82 if (track.getChi2ndof() != 0.0) {
83 seed.quality() = 1.0 / track.getChi2ndof(); // TODO: validate if this is correct. (technically the larger the value, the better the quality of the seed)
84 } else {
85 seed.quality() = 0.0; // or another default value? TODO: check if that's fine
86 }
87 }
88 }
89
90 ATH_MSG_DEBUG("Recorded " << seeds->size() << " seeds");
91 return StatusCode::SUCCESS;
92 }
93} // 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.
Acts::MutableSeedProxy2 push_back(Acts::SpacePointIndexSubset2 sp)
const SpacePointContainer & spacePoints() const noexcept