ATLAS Offline Software
FPGAConversionAlgorithm.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
4 #include "StoreGate/ReadHandle.h"
5 #include <type_traits>
6 
7 FPGAConversionAlgorithm::FPGAConversionAlgorithm(const std::string& name, ISvcLocator* pSvcLocator ):
8  AthReentrantAlgorithm( name, pSvcLocator ){}
9 
11  ATH_CHECK(m_ClusterConverter.retrieve());
12 
29  return StatusCode::SUCCESS;
30  }
31 
32  StatusCode FPGAConversionAlgorithm::execute(const EventContext& ctx) const {
33  std::unique_ptr<InDet::PixelClusterCollection> PixelCollFromHits = std::make_unique<InDet::PixelClusterCollection>();
34  std::unique_ptr<InDet::SCT_ClusterCollection> SCTCollFromHits = std::make_unique<InDet::SCT_ClusterCollection>();
35 
36  std::unique_ptr<InDet::PixelClusterCollection> PixelCollFromClusters = std::make_unique<InDet::PixelClusterCollection>();
37  std::unique_ptr<InDet::SCT_ClusterCollection> SCTCollFromClusters = std::make_unique<InDet::SCT_ClusterCollection>();
38 
39  std::unique_ptr<InDet::SCT_ClusterCollection> SCTCollFromSP = std::make_unique<InDet::SCT_ClusterCollection>();
40  std::unique_ptr<xAOD::PixelClusterContainer> PixelContFromHits = std::make_unique<xAOD::PixelClusterContainer>();
41  std::unique_ptr<xAOD::PixelClusterAuxContainer> PixelAuxContFromHits = std::make_unique<xAOD::PixelClusterAuxContainer>();
42  PixelContFromHits->setStore (PixelAuxContFromHits.get());
43 
44  std::unique_ptr<xAOD::StripClusterContainer> SCTContFromHits = std::make_unique<xAOD::StripClusterContainer>();
45  std::unique_ptr<xAOD::StripClusterAuxContainer> SCTAuxContFromHits = std::make_unique<xAOD::StripClusterAuxContainer>();
46  SCTContFromHits->setStore(SCTAuxContFromHits.get() );
47 
48  std::unique_ptr<xAOD::PixelClusterContainer> PixelContFromClusters = std::make_unique<xAOD::PixelClusterContainer>();
49  std::unique_ptr<xAOD::PixelClusterAuxContainer> PixelAuxContFromClusters = std::make_unique<xAOD::PixelClusterAuxContainer>();
50  PixelContFromClusters->setStore (PixelAuxContFromClusters.get());
51 
52  std::unique_ptr<xAOD::StripClusterContainer> SCTContFromClusters = std::make_unique<xAOD::StripClusterContainer>();
53  std::unique_ptr<xAOD::StripClusterAuxContainer> SCTAuxContFromClusters = std::make_unique<xAOD::StripClusterAuxContainer>();
54  SCTContFromClusters->setStore(SCTAuxContFromClusters.get() );
55 
56  std::unique_ptr<xAOD::SpacePointContainer> StripSPCont = std::make_unique<xAOD::SpacePointContainer>();
57  std::unique_ptr<xAOD::SpacePointAuxContainer> StripSPAuxCont = std::make_unique<xAOD::SpacePointAuxContainer>();
58  StripSPCont->setStore(StripSPAuxCont.get() );
59 
60  std::unique_ptr<xAOD::SpacePointContainer> PixelSPCont = std::make_unique<xAOD::SpacePointContainer>();
61  std::unique_ptr<xAOD::SpacePointAuxContainer> PixelSPAuxCont = std::make_unique<xAOD::SpacePointAuxContainer>();
62  PixelSPCont->setStore(PixelSPAuxCont.get() );
63 
64  std::unique_ptr<ActsTrk::ProtoTrackCollection> ProtoTracksFromRoads = std::make_unique<ActsTrk::ProtoTrackCollection>();
65  std::unique_ptr<ActsTrk::ProtoTrackCollection> ProtoTracksFromTracks = std::make_unique<ActsTrk::ProtoTrackCollection>();
66 
67 
68  if (m_doClusters) {
69 
71  if (FPGAClustersHandle.isValid()) { // To avoid running over events that didn't pass truth tracks selections
72  const FPGATrackSimClusterCollection *FPGAClusterColl = FPGAClustersHandle.cptr();
73 
74  // Convert to InDet clusters
75  ATH_MSG_DEBUG("InDet Clusters CONVERSION");
76  ATH_CHECK( m_ClusterConverter->convertClusters(*FPGAClusterColl, *PixelCollFromClusters, *SCTCollFromClusters) );
77 
78  // Convert to xAOD clusters
79  ATH_MSG_DEBUG("xAOD Clusters CONVERSION");
80  ATH_CHECK( m_ClusterConverter->convertClusters(*FPGAClusterColl, *PixelContFromClusters, *SCTContFromClusters) );
81  if (m_doActsTrk) {
83  if (!FPGARoadsHandle.isValid()) {
84  ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimRoadCollection");
85  return StatusCode::FAILURE;
86  }
87 
88  const FPGATrackSimRoadCollection *FPGARoadColl = FPGARoadsHandle.cptr();
89 
91  if (!FPGAHitsInRoadsHandle.isValid()) {
92  ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimItInRoadCollection");
93  return StatusCode::FAILURE;
94  }
95  const FPGATrackSimHitContainer *FPGAHitsInRoadsCont = FPGAHitsInRoadsHandle.cptr();
96 
98  if (!FPGATracksHandle.isValid()) {
99  ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimTrackCollection");
100  return StatusCode::FAILURE;
101  }
102  const FPGATrackSimTrackCollection *FPGATrackColl = FPGATracksHandle.cptr();
103 
104  if (PixelContFromClusters->size()+SCTContFromClusters->size() > 0) {
105  ATH_CHECK(m_ActsTrkConverter->findProtoTracks(ctx,*PixelContFromClusters,*SCTContFromClusters,*ProtoTracksFromRoads, *FPGAHitsInRoadsCont, *FPGARoadColl ));
106  ATH_CHECK(m_ActsTrkConverter->findProtoTracks(ctx,*PixelContFromClusters,*SCTContFromClusters,*ProtoTracksFromTracks, *FPGATrackColl ));
107  }
108  }
109 
110  if (m_doSP) {
113 
114  if (FPGASPHandle.isValid()) { // To avoid running over events that didn't pass truth tracks selections
115  const FPGATrackSimClusterCollection *FPGASPColl = FPGASPHandle.cptr();
116  const FPGATrackSimClusterCollection *FPGAClustersColl = FPGAClustersHandle.cptr();
117  ATH_CHECK( m_ClusterConverter->convertSpacePoints(*FPGASPColl, *FPGAClustersColl, *StripSPCont, *PixelSPCont, *SCTContFromClusters, *PixelContFromClusters) );
118  }
119  else {{ATH_MSG_WARNING("Failed to retrieve 1st stage FPGATrackSimSpacePointCollection. Will skip SP conversion ");}}
120  }
121  }
122 
123  else {ATH_MSG_WARNING("Failed to retrieve 1st stage FPGATrackSimClusterCollection. Will skip clusters and track conversion ");}
124  SG::WriteHandle<xAOD::PixelClusterContainer> xAODPixelClusterFromFPGAClusterHandle (m_xAODPixelClusterFromFPGAClusterKey, ctx);
125  SG::WriteHandle<xAOD::StripClusterContainer> xAODStripClusterFromFPGAClusterHandle (m_xAODStripClusterFromFPGAClusterKey, ctx);
126 
127  ATH_CHECK( xAODPixelClusterFromFPGAClusterHandle.record (std::move(PixelContFromClusters), std::move(PixelAuxContFromClusters)));
128  ATH_CHECK( xAODStripClusterFromFPGAClusterHandle.record (std::move(SCTContFromClusters), std::move(SCTAuxContFromClusters)));
129  if(m_doActsTrk)
130  {
133  ATH_CHECK( ActsProtoTrackFromFPGARoadHandle.record (std::move(ProtoTracksFromRoads)));
134  ATH_CHECK( ActsProtoTrackFromFPGATrackHandle.record (std::move(ProtoTracksFromTracks)));
135  }
136  if (m_doSP)
137  {
138  SG::WriteHandle<xAOD::SpacePointContainer> xAODStripSpacePointFromFPGAHandle (m_xAODStripSpacePointFromFPGAKey, ctx);
139  SG::WriteHandle<xAOD::SpacePointContainer> xAODPixelSpacePointFromFPGAHandle (m_xAODPixelSpacePointFromFPGAKey, ctx);
140  ATH_CHECK( xAODStripSpacePointFromFPGAHandle.record (std::move(StripSPCont), std::move(StripSPAuxCont)));
141  ATH_CHECK( xAODPixelSpacePointFromFPGAHandle.record (std::move(PixelSPCont), std::move(PixelSPAuxCont)));
142  }
143  }
144 
145 
146 
147 
148  if (m_doHits) {
149 
151 
152  if (FPGAHitsHandle.isValid()) {
153  const FPGATrackSimHitCollection *FPGAHitColl = FPGAHitsHandle.cptr();
154 
155  // Convert to InDet clusters
156  ATH_MSG_DEBUG("InDet Hits CONVERSION");
157  ATH_CHECK( m_ClusterConverter->convertHits(*FPGAHitColl, *PixelCollFromHits, *SCTCollFromHits) );
158  ATH_MSG_DEBUG("xAOD Hits CONVERSION");
159  ATH_CHECK( m_ClusterConverter->convertHits(*FPGAHitColl, *PixelContFromHits, *SCTContFromHits) );
160  }
161 
162  else {ATH_MSG_WARNING("Failed to retrieve 1st stage FPGATrackSimHitCollection. Will skip hit conversion ");}
163 
164 
167  ATH_CHECK( xAODPixelClusterFromFPGAHitHandle.record (std::move(PixelContFromHits),std::move(PixelAuxContFromHits)));
168  ATH_CHECK( xAODStripClusterFromFPGAHitHandle.record (std::move(SCTContFromHits),std::move(SCTAuxContFromHits)));
169  }
170 
171  return StatusCode::SUCCESS;
172  }
173 
174 
175 template <typename T> // should be InDet::PixelCluster or InDet::SCT_Cluster
176 StatusCode FPGAConversionAlgorithm::convertCollectionToContainer(Trk::PrepRawDataCollection<T>* inputCollection, // i.e. InDet::PixelClusterCollection or InDet::SCT_ClusterCollection
178  )
179 {
181  static_assert(false, "Bad type <T>. Should be InDet::PixelCluster or InDet::SCT_Cluster");
182  return StatusCode::FAILURE;
183  }
184 
185  std::unique_ptr<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>> outputContainer = std::make_unique<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>>(SG::VIEW_ELEMENTS);
186  SG::WriteHandle<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>> outputContainerHandle(outputContainerKey);
187 
188  if (!inputCollection || inputCollection->empty()){
189  outputContainerHandle.record(std::move(outputContainer));
190  return StatusCode::SUCCESS;
191  }
192 
194  newCol->setIdentifier(inputCollection->identify());
195  for (const T* clus : *inputCollection) {
196  newCol->push_back(std::make_unique<T>(*clus));
197  ATH_MSG_DEBUG("NewCol cluster identifier " << clus->identify());
198  }
199 
200  ATH_MSG_DEBUG("newCol->identifyHash() " << newCol->identifyHash());
201  ATH_CHECK(outputContainer->addCollection(newCol,newCol->identifyHash()));
202 
203  if(outputContainerHandle.record(std::move(outputContainer)).isFailure()){
204  ATH_MSG_ERROR("Could not record InDetSCTClusterContainer object with "
205  << outputContainerHandle.key()
206  << " into Event Store");
207  return StatusCode::FAILURE;
208  }
209 
210  return StatusCode::SUCCESS;
211 }
FPGAConversionAlgorithm::m_xAODPixelClusterFromFPGAClusterKey
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_xAODPixelClusterFromFPGAClusterKey
Definition: FPGAConversionAlgorithm.h:55
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
FPGAConversionAlgorithm::m_ActsTrkConverter
ToolHandle< IFPGAActsTrkConverter > m_ActsTrkConverter
Definition: FPGAConversionAlgorithm.h:46
FPGATrackSimHitContainer
std::vector< std::vector< FPGATrackSimHit > > FPGATrackSimHitContainer
Definition: FPGATrackSimHitContainer.h:13
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
FPGAConversionAlgorithm::convertCollectionToContainer
StatusCode convertCollectionToContainer(Trk::PrepRawDataCollection< T > *inputCollection, SG::WriteHandleKey< Trk::PrepRawDataContainer< Trk::PrepRawDataCollection< T >>> &outputContainerKey)
Definition: FPGAConversionAlgorithm.cxx:176
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
FPGAConversionAlgorithm::m_doSP
Gaudi::Property< bool > m_doSP
Definition: FPGAConversionAlgorithm.h:73
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
FPGAConversionAlgorithm::m_xAODPixelClusterFromFPGAHitKey
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_xAODPixelClusterFromFPGAHitKey
Definition: FPGAConversionAlgorithm.h:59
FPGAConversionAlgorithm::m_ActsProtoTrackFromFPGATrackKey
SG::WriteHandleKey< ActsTrk::ProtoTrackCollection > m_ActsProtoTrackFromFPGATrackKey
Definition: FPGAConversionAlgorithm.h:62
Trk::PrepRawDataCollection
Definition: PrepRawDataCollection.h:36
FPGAConversionAlgorithm::m_outputStripClusterContainerKey
SG::WriteHandleKey< InDet::SCT_ClusterContainer > m_outputStripClusterContainerKey
Definition: FPGAConversionAlgorithm.h:68
athena.value
value
Definition: athena.py:124
FPGAConversionAlgorithm::m_FPGAHitInRoadsKey
SG::ReadHandleKey< FPGATrackSimHitContainer > m_FPGAHitInRoadsKey
Definition: FPGAConversionAlgorithm.h:53
FPGAConversionAlgorithm::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: FPGAConversionAlgorithm.cxx:32
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
FPGATrackSimClusterCollection
std::vector< FPGATrackSimCluster > FPGATrackSimClusterCollection
Definition: FPGATrackSimClusterCollection.h:13
FPGATrackSimHitCollection
std::vector< FPGATrackSimHit > FPGATrackSimHitCollection
Definition: FPGATrackSimHitCollection.h:13
FPGAConversionAlgorithm::m_FPGATrackKey
SG::ReadHandleKey< FPGATrackSimTrackCollection > m_FPGATrackKey
Definition: FPGAConversionAlgorithm.h:52
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition: StoreGate/StoreGate/WriteHandleKey.h:40
FPGAConversionAlgorithm::m_FPGAHitKey
SG::ReadHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey
Definition: FPGAConversionAlgorithm.h:50
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
Trk::PrepRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
FPGAConversionAlgorithm::m_FPGARoadKey
SG::ReadHandleKey< FPGATrackSimRoadCollection > m_FPGARoadKey
Definition: FPGAConversionAlgorithm.h:51
FPGAConversionAlgorithm::m_ActsProtoTrackFromFPGARoadKey
SG::WriteHandleKey< ActsTrk::ProtoTrackCollection > m_ActsProtoTrackFromFPGARoadKey
Definition: FPGAConversionAlgorithm.h:61
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FPGAConversionAlgorithm::m_FPGASPKey
SG::ReadHandleKey< FPGATrackSimClusterCollection > m_FPGASPKey
Definition: FPGAConversionAlgorithm.h:49
FPGAConversionAlgorithm::m_outputPixelClusterContainerKey
SG::WriteHandleKey< InDet::PixelClusterContainer > m_outputPixelClusterContainerKey
Definition: FPGAConversionAlgorithm.h:67
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
FPGAConversionAlgorithm.h
FPGAConversionAlgorithm::m_doClusters
Gaudi::Property< bool > m_doClusters
Definition: FPGAConversionAlgorithm.h:70
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
FPGAConversionAlgorithm::m_ClusterConverter
ToolHandle< IFPGAClusterConverter > m_ClusterConverter
Definition: FPGAConversionAlgorithm.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DataVector< PrepRawDataT >::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
FPGATrackSimRoadCollection
std::vector< FPGATrackSimRoad > FPGATrackSimRoadCollection
Definition: FPGATrackSimRoadCollection.h:12
FPGAConversionAlgorithm::m_FPGAClusterKey
SG::ReadHandleKey< FPGATrackSimClusterCollection > m_FPGAClusterKey
Definition: FPGAConversionAlgorithm.h:48
FPGATrackSimTrackCollection
std::vector< FPGATrackSimTrack > FPGATrackSimTrackCollection
Definition: FPGATrackSimTrackCollection.h:13
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Trk::PrepRawDataCollection::identify
virtual Identifier identify() const override final
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::PrepRawDataContainer
Definition: PrepRawDataContainer.h:26
FPGAConversionAlgorithm::m_xAODStripClusterFromFPGAHitKey
SG::WriteHandleKey< xAOD::StripClusterContainer > m_xAODStripClusterFromFPGAHitKey
Definition: FPGAConversionAlgorithm.h:60
FPGAConversionAlgorithm::m_doHits
Gaudi::Property< bool > m_doHits
Definition: FPGAConversionAlgorithm.h:71
FPGAConversionAlgorithm::FPGAConversionAlgorithm
FPGAConversionAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: FPGAConversionAlgorithm.cxx:7
ReadHandle.h
Handle class for reading from StoreGate.
FPGAConversionAlgorithm::m_xAODPixelSpacePointFromFPGAKey
SG::WriteHandleKey< xAOD::SpacePointContainer > m_xAODPixelSpacePointFromFPGAKey
Definition: FPGAConversionAlgorithm.h:58
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector< PrepRawDataT >::empty
bool empty() const noexcept
Returns true if the collection is empty.
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
FPGAConversionAlgorithm::initialize
virtual StatusCode initialize() override
Athena algorithm's Hooks.
Definition: FPGAConversionAlgorithm.cxx:10
FPGAConversionAlgorithm::m_xAODStripClusterFromFPGAClusterKey
SG::WriteHandleKey< xAOD::StripClusterContainer > m_xAODStripClusterFromFPGAClusterKey
Definition: FPGAConversionAlgorithm.h:56
Trk::PrepRawDataCollection::setIdentifier
void setIdentifier(Identifier id)
FPGAConversionAlgorithm::m_doActsTrk
Gaudi::Property< bool > m_doActsTrk
Definition: FPGAConversionAlgorithm.h:72
FPGAConversionAlgorithm::m_xAODStripSpacePointFromFPGAKey
SG::WriteHandleKey< xAOD::SpacePointContainer > m_xAODStripSpacePointFromFPGAKey
Definition: FPGAConversionAlgorithm.h:57