ATLAS Offline Software
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 
8 namespace FPGATrackSim {
9 
10  FPGATrackSim::FPGATrackSimSeedingAlg::FPGATrackSimSeedingAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {
11 }
15  ATH_CHECK(m_spacePointContainerKey.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 
36  std::multimap<xAOD::DetectorIDHashType, Acts::SpacePointIndex2> spacePointMap;
37  seeds->spacePoints().reserve(spacePointsHandle->size());
38  // Populate the multimap with Pixel cluster hashID as key.
39  // Only space points with one measurement are considered (i.e. pixels)
40  for (const xAOD::SpacePoint* spacePoint : *spacePointsHandle) {
41  if (!spacePoint->measurements().empty()) {
42  seeds->spacePoints().push_back(spacePoint);
43  spacePointMap.emplace(spacePoint->measurements().at(0)->identifierHash(), seeds->spacePoints().size()-1ul);
44  }
45  }
46 
47  seeds->reserve(tracksHandle->size());
48  // loop over the tracks and make seeds based on the hits in FPGATrackSimTracks
49  for (const auto& track : *tracksHandle) {
50  std::vector<const FPGATrackSimHit*> hitsToStoreInSeed;
51  std::vector<Acts::SpacePointIndex2> spacePointsToStoreInSeed;
52  for (const FPGATrackSimHit& hit : track.getFPGATrackSimHits()) {
53  if (hit.isReal() && hit.isPixel()) {
54  ATH_MSG_DEBUG("Hit coordinates in module " << hit.getIdentifierHash() << ": (" << hit.getPhiCoord() << ", " << hit.getEtaCoord() << ")");
55  // find in the multimap the SP that matches this globalPosition
56  auto range = spacePointMap.equal_range(hit.getIdentifierHash());
57  for (auto it = range.first; it != range.second; ++it) {
58  const xAOD::SpacePoint* spacePoint = seeds->spacePoints().at(it->second);
59  constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
60  if (std::abs(hit.getPhiCoord() - spacePoint->measurements().at(0)->localPosition<2>()[0]) < kEpsilon &&
61  std::abs(hit.getEtaCoord() - spacePoint->measurements().at(0)->localPosition<2>()[1]) < kEpsilon) {
62  spacePointsToStoreInSeed.push_back(it->second);
63  if (spacePointsToStoreInSeed.size() == m_maxSpacePointsPerSeed) break; // stop if max reached
64  }
65  else
66  {
67  // printout SP coordinates to see why the above check fails
68  ATH_MSG_DEBUG("SpacePoint coordinates: (" << spacePoint->measurements().at(0)->localPosition<2>()[0] << ", " << spacePoint->measurements().at(0)->localPosition<2>()[1] << ")");
69  }
70  }
71  if (spacePointsToStoreInSeed.size() == m_maxSpacePointsPerSeed) break; // stop in case we reach the maximum number of space points allowed
72  }
73  }
74  // construct seed based on the space points stored in the vector
75  if (spacePointsToStoreInSeed.size() >= m_minSpacePointsPerSeed) { // check that seeds contains at least the minimum number of desired space points
76  auto seed = seeds->push_back(spacePointsToStoreInSeed);
77  seed.vertexZ() = track.getZ0();
78  if (track.getChi2ndof() != 0.0) {
79  seed.quality() = 1.0 / track.getChi2ndof(); // TODO: validate if this is correct. (technically the larger the value, the better the quality of the seed)
80  } else {
81  seed.quality() = 0.0; // or another default value? TODO: check if that's fine
82  }
83  }
84  }
85 
86  ATH_MSG_DEBUG("Recorded " << seeds->size() << " seeds");
87  return StatusCode::SUCCESS;
88  }
89 } // namespace FPGATrackSim
ActsTrk::SeedContainer
Definition: SeedContainer.h:19
FPGATrackSim::FPGATrackSimSeedingAlg::initialize
virtual StatusCode initialize() override final
Definition: FPGATrackSimSeedingAlg.cxx:12
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CaloClusterMLCalib::epsilon
constexpr float epsilon
Definition: CaloClusterMLGaussianMixture.h:16
skel.it
it
Definition: skel.GENtoEVGEN.py:407
FPGATrackSim::FPGATrackSimSeedingAlg::m_maxSpacePointsPerSeed
Gaudi::Property< size_t > m_maxSpacePointsPerSeed
Definition: FPGATrackSimSeedingAlg.h:37
FPGATrackSim::FPGATrackSimSeedingAlg::m_seedKey
SG::WriteHandleKey< ActsTrk::SeedContainer > m_seedKey
Definition: FPGATrackSimSeedingAlg.h:45
xAOD::SpacePoint_v1
Definition: SpacePoint_v1.h:29
FPGATrackSim::FPGATrackSimSeedingAlg::m_spacePointContainerKey
SG::ReadHandleKey< xAOD::SpacePointContainer > m_spacePointContainerKey
Definition: FPGATrackSimSeedingAlg.h:42
FPGATrackSim::FPGATrackSimSeedingAlg::m_minSpacePointsPerSeed
Gaudi::Property< size_t > m_minSpacePointsPerSeed
Definition: FPGATrackSimSeedingAlg.h:36
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FPGATrackSim::FPGATrackSimSeedingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: FPGATrackSimSeedingAlg.cxx:21
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
FPGATrackSimSeedingAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:46
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::SpacePoint_v1::measurements
const std::vector< const xAOD::UncalibratedMeasurement * > & measurements() const
Returns the index of the measurements.
FPGATrackSim
Definition: FPGATrackSimRegionMergingAlg.h:25
ActsTrk::SeedContainer::spacePoints
const SpacePointContainer & spacePoints() const noexcept
Definition: SeedContainer.h:41
SpacePoint.h
ActsTrk::SeedContainer::push_back
Acts::MutableSeedProxy2 push_back(Acts::MutableSeedProxy2 seed)
Definition: SeedContainer.h:89
FPGATrackSim::FPGATrackSimSeedingAlg::m_FPGATrackCollectionKey
SG::ReadHandleKey< FPGATrackSimTrackCollection > m_FPGATrackCollectionKey
Definition: FPGATrackSimSeedingAlg.h:40
FPGATrackSim::FPGATrackSimSeedingAlg::m_pixelClusterContainerKey
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_pixelClusterContainerKey
Definition: FPGATrackSimSeedingAlg.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
FPGATrackSim::FPGATrackSimSeedingAlg::FPGATrackSimSeedingAlg
FPGATrackSimSeedingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: FPGATrackSimSeedingAlg.cxx:10
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
xAOD::track
@ track
Definition: TrackingPrimitives.h:513