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());
16  ATH_CHECK(m_seedKey.initialize());
17 
18  return StatusCode::SUCCESS;
19  }
20 
21  StatusCode FPGATrackSimSeedingAlg::execute(const EventContext& ctx) const {
25 
26  ATH_CHECK(tracksHandle.isValid());
27  ATH_CHECK(pixelClustersHandle.isValid());
28  ATH_CHECK(spacePointsHandle.isValid());
29 
31  ATH_CHECK(seedHandle.record(std::make_unique<ActsTrk::SeedContainer>()));
32  ActsTrk::SeedContainer* seeds = seedHandle.ptr();
33 
34 
35  std::multimap<xAOD::DetectorIDHashType, const xAOD::SpacePoint*> spacePointMap;
36  // Populate the multimap with Pixel cluster hashID as key.
37  // Only space points with one measurement are considered (i.e. pixels)
38  for (const xAOD::SpacePoint* spacePoint : *spacePointsHandle) {
39  if (!spacePoint->measurements().empty()) {
40  spacePointMap.emplace(spacePoint->measurements().at(0)->identifierHash(), spacePoint);
41  }
42  }
43 
44  // loop over the tracks and make seeds based on the hits in FPGATrackSimTracks
45  for (const auto& track : *tracksHandle) {
46  std::vector<const FPGATrackSimHit*> hitsToStoreInSeed;
47  std::vector<const xAOD::SpacePoint*> spacePointsToStoreInSeed;
48  for (const FPGATrackSimHit& hit : track.getFPGATrackSimHits()) {
49  if (hit.isReal() && hit.isPixel()) {
50  ATH_MSG_DEBUG("Hit coordinates in module " << hit.getIdentifierHash() << ": (" << hit.getPhiCoord() << ", " << hit.getEtaCoord() << ")");
51  // find in the multimap the SP that matches this globalPosition
52  auto range = spacePointMap.equal_range(hit.getIdentifierHash());
53  for (auto it = range.first; it != range.second; ++it) {
54  constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
55  if (std::abs(hit.getPhiCoord() - it->second->measurements().at(0)->localPosition<2>()[0]) < kEpsilon &&
56  std::abs(hit.getEtaCoord() - it->second->measurements().at(0)->localPosition<2>()[1]) < kEpsilon) {
57  spacePointsToStoreInSeed.push_back(it->second);
58  if (spacePointsToStoreInSeed.size() == m_maxSpacePointsPerSeed) break; // stop if max reached
59  }
60  else
61  {
62  // printout SP coordinates to see why the above check fails
63  ATH_MSG_DEBUG("SpacePoint coordinates: (" << it->second->measurements().at(0)->localPosition<2>()[0] << ", " << it->second->measurements().at(0)->localPosition<2>()[1] << ")");
64  }
65  }
66  if (spacePointsToStoreInSeed.size() == m_maxSpacePointsPerSeed) break; // stop in case we reach the maximum number of space points allowed
67  }
68  }
69  // construct seed based on the space points stored in the vector
70  if (spacePointsToStoreInSeed.size() >= m_minSpacePointsPerSeed) { // check that seeds contains at least the minimum number of desired space points
71  std::unique_ptr<ActsTrk::ActsSeed<xAOD::SpacePoint>> seed = std::make_unique<ActsTrk::ActsSeed<xAOD::SpacePoint>>(spacePointsToStoreInSeed);
72  seed->setVertexZ(track.getZ0());
73  if (track.getChi2ndof() != 0.0) {
74  seed->setQuality(1.0 / track.getChi2ndof()); // TODO: validate if this is correct. (technically the larger the value, the better the quality of the seed)
75  } else {
76  seed->setQuality(0.0); // or another default value? TODO: check if that's fine
77  }
78  seeds->push_back(std::move(seed));
79  }
80  }
81 
82  ATH_MSG_DEBUG("Recorded " << seeds->size() << " seeds");
83  return StatusCode::SUCCESS;
84  }
85 } // namespace FPGATrackSim
FPGATrackSim::FPGATrackSimSeedingAlg::initialize
virtual StatusCode initialize() override final
Definition: FPGATrackSimSeedingAlg.cxx:12
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
skel.it
it
Definition: skel.GENtoEVGEN.py:407
FPGATrackSim::FPGATrackSimSeedingAlg::m_maxSpacePointsPerSeed
Gaudi::Property< size_t > m_maxSpacePointsPerSeed
Definition: FPGATrackSimSeedingAlg.h:38
FPGATrackSim::FPGATrackSimSeedingAlg::m_seedKey
SG::WriteHandleKey< ActsTrk::SeedContainer > m_seedKey
Definition: FPGATrackSimSeedingAlg.h:46
xAOD::SpacePoint_v1
Definition: SpacePoint_v1.h:29
FPGATrackSim::FPGATrackSimSeedingAlg::m_spacePointContainerKey
SG::ReadHandleKey< xAOD::SpacePointContainer > m_spacePointContainerKey
Definition: FPGATrackSimSeedingAlg.h:43
FPGATrackSim::FPGATrackSimSeedingAlg::m_minSpacePointsPerSeed
Gaudi::Property< size_t > m_minSpacePointsPerSeed
Definition: FPGATrackSimSeedingAlg.h:37
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
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
FPGATrackSim
Definition: FPGATrackSimRegionMergingAlg.h:25
SpacePoint.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
FPGATrackSim::FPGATrackSimSeedingAlg::m_FPGATrackCollectionKey
SG::ReadHandleKey< FPGATrackSimTrackCollection > m_FPGATrackCollectionKey
Definition: FPGATrackSimSeedingAlg.h:41
FPGATrackSim::FPGATrackSimSeedingAlg::m_pixelClusterContainerKey
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_pixelClusterContainerKey
Definition: FPGATrackSimSeedingAlg.h:42
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.