ATLAS Offline Software
Loading...
Searching...
No Matches
FPGAConversionAlgorithm.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
5#include <type_traits>
6#include <format>
7
8constexpr bool enableBenchmark =
9#ifdef BENCHMARK_FPGATRACKSIM
10 true;
11#else
12 false;
13#endif
14
15FPGAConversionAlgorithm::FPGAConversionAlgorithm(const std::string& name, ISvcLocator* pSvcLocator ):
16 AthReentrantAlgorithm( name, pSvcLocator ){}
17
40
41 StatusCode FPGAConversionAlgorithm::execute(const EventContext& ctx) const {
42 std::unique_ptr<InDet::PixelClusterCollection> PixelCollFromHits = std::make_unique<InDet::PixelClusterCollection>();
43 std::unique_ptr<InDet::SCT_ClusterCollection> SCTCollFromHits = std::make_unique<InDet::SCT_ClusterCollection>();
44
45 std::unique_ptr<InDet::PixelClusterCollection> PixelCollFromClusters = std::make_unique<InDet::PixelClusterCollection>();
46 std::unique_ptr<InDet::SCT_ClusterCollection> SCTCollFromClusters = std::make_unique<InDet::SCT_ClusterCollection>();
47
48 std::unique_ptr<InDet::SCT_ClusterCollection> SCTCollFromSP = std::make_unique<InDet::SCT_ClusterCollection>();
49 std::unique_ptr<xAOD::PixelClusterContainer> PixelContFromHits = std::make_unique<xAOD::PixelClusterContainer>();
50 std::unique_ptr<xAOD::PixelClusterAuxContainer> PixelAuxContFromHits = std::make_unique<xAOD::PixelClusterAuxContainer>();
51 PixelContFromHits->setStore (PixelAuxContFromHits.get());
52
53 std::unique_ptr<xAOD::StripClusterContainer> SCTContFromHits = std::make_unique<xAOD::StripClusterContainer>();
54 std::unique_ptr<xAOD::StripClusterAuxContainer> SCTAuxContFromHits = std::make_unique<xAOD::StripClusterAuxContainer>();
55 SCTContFromHits->setStore(SCTAuxContFromHits.get() );
56
57 std::unique_ptr<xAOD::PixelClusterContainer> PixelContFromClusters = std::make_unique<xAOD::PixelClusterContainer>();
58 std::unique_ptr<xAOD::PixelClusterAuxContainer> PixelAuxContFromClusters = std::make_unique<xAOD::PixelClusterAuxContainer>();
59 PixelContFromClusters->setStore (PixelAuxContFromClusters.get());
60
61 std::unique_ptr<xAOD::StripClusterContainer> SCTContFromClusters = std::make_unique<xAOD::StripClusterContainer>();
62 std::unique_ptr<xAOD::StripClusterAuxContainer> SCTAuxContFromClusters = std::make_unique<xAOD::StripClusterAuxContainer>();
63 SCTContFromClusters->setStore(SCTAuxContFromClusters.get() );
64
65 std::unique_ptr<xAOD::SpacePointContainer> StripSPCont = std::make_unique<xAOD::SpacePointContainer>();
66 std::unique_ptr<xAOD::SpacePointAuxContainer> StripSPAuxCont = std::make_unique<xAOD::SpacePointAuxContainer>();
67 StripSPCont->setStore(StripSPAuxCont.get() );
68
69 std::unique_ptr<xAOD::SpacePointContainer> PixelSPCont = std::make_unique<xAOD::SpacePointContainer>();
70 std::unique_ptr<xAOD::SpacePointAuxContainer> PixelSPAuxCont = std::make_unique<xAOD::SpacePointAuxContainer>();
71 PixelSPCont->setStore(PixelSPAuxCont.get() );
72
73 std::unique_ptr<ActsTrk::ProtoTrackCollection> ProtoTracksFromRoads = std::make_unique<ActsTrk::ProtoTrackCollection>();
74 std::unique_ptr<ActsTrk::ProtoTrackCollection> ProtoTracksFromTracks = std::make_unique<ActsTrk::ProtoTrackCollection>();
75
76 if (m_doClusters) {
77
79 if (FPGAClustersHandle.isValid()) { // To avoid running over events that didn't pass truth tracks selections
80 const FPGATrackSimClusterCollection *FPGAClusterColl = FPGAClustersHandle.cptr();
81
82 // Convert to InDet clusters
83 if (m_doIndet) {
84 ATH_MSG_DEBUG("InDet Clusters CONVERSION");
85 ATH_CHECK(m_ClusterConverter->convertClusters(*FPGAClusterColl, *PixelCollFromClusters, *SCTCollFromClusters));
86 }
87
88 // Convert to xAOD clusters
89 ATH_MSG_INFO("xAOD Clusters CONVERSION");
90 if constexpr (enableBenchmark) m_chrono->chronoStart("FPGAConversion: cluster conversion");
91 ATH_CHECK( m_ClusterConverter->convertClusters(*FPGAClusterColl, *PixelContFromClusters, *SCTContFromClusters) );
92 if constexpr (enableBenchmark) m_chrono->chronoStop("FPGAConversion: cluster conversion");
93
94 if (m_doActsTrk) {
95 if (m_useRoads) {
97 if (!FPGARoadsHandle.isValid()) {
98 ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimRoadCollection");
99 return StatusCode::FAILURE;
100 }
101 const FPGATrackSimRoadCollection* FPGARoadColl = FPGARoadsHandle.cptr();
102 if constexpr (enableBenchmark) m_chrono->chronoStart("FPGAConversion: Prototrack formation (from roads)");
103 ATH_CHECK(m_ActsTrkConverter->findProtoTracks(ctx, *PixelContFromClusters, *SCTContFromClusters, *ProtoTracksFromRoads, *FPGARoadColl));
104 if constexpr (enableBenchmark) m_chrono->chronoStop("FPGAConversion: Prototrack formation (from roads)");
105 }
106 else{
108 if (!FPGATracksHandle.isValid()) {
109 ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimTrackCollection");
110 return StatusCode::FAILURE;
111 }
112 const FPGATrackSimTrackCollection* FPGATrackColl = FPGATracksHandle.cptr();
113
114 if constexpr (enableBenchmark) m_chrono->chronoStart("FPGAConversion: Prototrack formation (from tracks)");
115 ATH_CHECK(m_ActsTrkConverter->findProtoTracks(ctx, *PixelContFromClusters, *SCTContFromClusters, *ProtoTracksFromTracks, *FPGATrackColl));
116 if constexpr (enableBenchmark) m_chrono->chronoStop("FPGAConversion: Prototrack formation (from tracks)");
117 }
118 }
119
120 if (m_doSP) {
121 ATH_MSG_INFO("Starting xAOD SpacePoint Conversion");
123
124 if (FPGASPHandle.isValid()) { // To avoid running over events that didn't pass truth tracks selections
125 const FPGATrackSimClusterCollection *FPGASPColl = FPGASPHandle.cptr();
126 ATH_CHECK( m_ClusterConverter->convertSpacePoints(*FPGASPColl, *StripSPCont, *PixelSPCont, *SCTContFromClusters, *PixelContFromClusters) );
127 }
128 else {{ATH_MSG_WARNING("Failed to retrieve 1st stage FPGATrackSimSpacePointCollection. Will skip SP conversion ");}}
129 }
130 }
131
132 else {ATH_MSG_WARNING("Failed to retrieve 1st stage FPGATrackSimClusterCollection. Will skip clusters and track conversion ");}
135
136 ATH_CHECK( xAODPixelClusterFromFPGAClusterHandle.record (std::move(PixelContFromClusters), std::move(PixelAuxContFromClusters)));
137 ATH_CHECK( xAODStripClusterFromFPGAClusterHandle.record (std::move(SCTContFromClusters), std::move(SCTAuxContFromClusters)));
138 if(m_doActsTrk)
139 {
141 ATH_CHECK( ActsProtoTrackFromFPGATrackHandle.record (std::move(ProtoTracksFromTracks)));
142 if(m_useRoads) {
144 ATH_CHECK( ActsProtoTrackFromFPGARoadHandle.record (std::move(ProtoTracksFromRoads)));
145 }
146 }
147 if (m_doSP)
148 {
151 ATH_CHECK( xAODStripSpacePointFromFPGAHandle.record (std::move(StripSPCont), std::move(StripSPAuxCont)));
152 ATH_CHECK( xAODPixelSpacePointFromFPGAHandle.record (std::move(PixelSPCont), std::move(PixelSPAuxCont)));
153 }
154 }
155
156 if (m_doHits) {
158
159 if (FPGAHitsHandle.isValid()) {
160 const FPGATrackSimHitCollection *FPGAHitColl = FPGAHitsHandle.cptr();
161
162 // Convert to InDet clusters
163 if (m_doIndet) {
164 ATH_MSG_DEBUG("InDet Hits CONVERSION");
165 ATH_CHECK(m_ClusterConverter->convertHits(*FPGAHitColl, *PixelCollFromHits, *SCTCollFromHits));
166 }
167 ATH_MSG_DEBUG("xAOD Hits CONVERSION");
168 ATH_CHECK( m_ClusterConverter->convertHits(*FPGAHitColl, *PixelContFromHits, *SCTContFromHits) );
169 }
170
171 else {ATH_MSG_WARNING("Failed to retrieve 1st stage FPGATrackSimHitCollection. Will skip hit conversion ");}
172
173
176 ATH_CHECK( xAODPixelClusterFromFPGAHitHandle.record (std::move(PixelContFromHits),std::move(PixelAuxContFromHits)));
177 ATH_CHECK( xAODStripClusterFromFPGAHitHandle.record (std::move(SCTContFromHits),std::move(SCTAuxContFromHits)));
178
179 // Also do the tracks
180 if (m_doActsTrk && !m_useRoads) {
182 if (!FPGATracksHandle.isValid()) {
183 ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimTrackCollection");
184 return StatusCode::FAILURE;
185 }
186 const FPGATrackSimTrackCollection* FPGATrackColl = FPGATracksHandle.cptr();
187
188 if constexpr (enableBenchmark) m_chrono->chronoStart("FPGAConversion: Prototrack formation (from tracks)");
189 ATH_CHECK(m_ActsTrkConverter->findProtoTracks(ctx, *PixelContFromClusters, *SCTContFromClusters, *ProtoTracksFromTracks, *FPGATrackColl));
190 if constexpr (enableBenchmark) m_chrono->chronoStop("FPGAConversion: Prototrack formation (from tracks)");
191 }
192 }
193
194 return StatusCode::SUCCESS;
195 }
196
197
198template <typename T> // should be InDet::PixelCluster or InDet::SCT_Cluster
199StatusCode FPGAConversionAlgorithm::convertCollectionToContainer(Trk::PrepRawDataCollection<T>* inputCollection, // i.e. InDet::PixelClusterCollection or InDet::SCT_ClusterCollection
201 )
202{
203 if constexpr (!std::is_same<T, InDet::PixelCluster>::value && !std::is_same<T, InDet::SCT_Cluster>::value) {
204 static_assert(false, "Bad type <T>. Should be InDet::PixelCluster or InDet::SCT_Cluster");
205 return StatusCode::FAILURE;
206 }
207
208 std::unique_ptr<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>> outputContainer = std::make_unique<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>>(SG::VIEW_ELEMENTS);
209 SG::WriteHandle<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>> outputContainerHandle(outputContainerKey);
210
211 if (!inputCollection || inputCollection->empty()){
212 outputContainerHandle.record(std::move(outputContainer));
213 return StatusCode::SUCCESS;
214 }
215
217 newCol->setIdentifier(inputCollection->identify());
218 for (const T* clus : *inputCollection) {
219 newCol->push_back(std::make_unique<T>(*clus));
220 ATH_MSG_DEBUG("NewCol cluster identifier " << clus->identify());
221 }
222
223 ATH_MSG_DEBUG("newCol->identifyHash() " << newCol->identifyHash());
224 ATH_CHECK(outputContainer->addCollection(newCol,newCol->identifyHash()));
225
226 if(outputContainerHandle.record(std::move(outputContainer)).isFailure()){
227 ATH_MSG_ERROR("Could not record InDetSCTClusterContainer object with "
228 << outputContainerHandle.key()
229 << " into Event Store");
230 return StatusCode::FAILURE;
231 }
232
233 return StatusCode::SUCCESS;
234}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< FPGATrackSimCluster > FPGATrackSimClusterCollection
DataVector< FPGATrackSimHit > FPGATrackSimHitCollection
std::vector< FPGATrackSimRoad > FPGATrackSimRoadCollection
std::vector< FPGATrackSimTrack > FPGATrackSimTrackCollection
Handle class for reading from StoreGate.
An algorithm that can be simultaneously executed in multiple threads.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
bool empty() const noexcept
Returns true if the collection is empty.
SG::WriteHandleKey< ActsTrk::ProtoTrackCollection > m_ActsProtoTrackFromFPGARoadKey
FPGAConversionAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_xAODPixelClusterFromFPGAHitKey
SG::WriteHandleKey< xAOD::SpacePointContainer > m_xAODStripSpacePointFromFPGAKey
ServiceHandle< IChronoStatSvc > m_chrono
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_xAODPixelClusterFromFPGAClusterKey
ToolHandle< IFPGAActsTrkConverter > m_ActsTrkConverter
ToolHandle< IFPGAClusterConverter > m_ClusterConverter
SG::ReadHandleKey< FPGATrackSimTrackCollection > m_FPGATrackKey
SG::ReadHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey
Gaudi::Property< bool > m_doSP
Gaudi::Property< bool > m_doActsTrk
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< FPGATrackSimClusterCollection > m_FPGASPKey
SG::WriteHandleKey< xAOD::StripClusterContainer > m_xAODStripClusterFromFPGAHitKey
SG::WriteHandleKey< InDet::PixelClusterContainer > m_outputPixelClusterContainerKey
SG::WriteHandleKey< InDet::SCT_ClusterContainer > m_outputStripClusterContainerKey
SG::WriteHandleKey< ActsTrk::ProtoTrackCollection > m_ActsProtoTrackFromFPGATrackKey
Gaudi::Property< bool > m_doIndet
SG::WriteHandleKey< xAOD::StripClusterContainer > m_xAODStripClusterFromFPGAClusterKey
StatusCode convertCollectionToContainer(Trk::PrepRawDataCollection< T > *inputCollection, SG::WriteHandleKey< Trk::PrepRawDataContainer< Trk::PrepRawDataCollection< T > > > &outputContainerKey)
Gaudi::Property< bool > m_doClusters
SG::WriteHandleKey< xAOD::SpacePointContainer > m_xAODPixelSpacePointFromFPGAKey
virtual StatusCode initialize() override
Athena algorithm's Hooks.
SG::ReadHandleKey< FPGATrackSimClusterCollection > m_FPGAClusterKey
Gaudi::Property< bool > m_doHits
Gaudi::Property< bool > m_useRoads
SG::ReadHandleKey< FPGATrackSimRoadCollection > m_FPGARoadKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual Identifier identify() const override final
virtual IdentifierHash identifyHash() const override final
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
constexpr bool enableBenchmark