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 
12  ATH_CHECK(m_ClusterConverter.retrieve());
13 
19 
26 
29 
30  return StatusCode::SUCCESS;
31  }
32 
33  StatusCode FPGAConversionAlgorithm::execute(const EventContext& ctx) const {
34 
35  std::unique_ptr<InDet::PixelClusterCollection> PixelCollFromHits = std::make_unique<InDet::PixelClusterCollection>();
36  std::unique_ptr<InDet::SCT_ClusterCollection> SCTCollFromHits = std::make_unique<InDet::SCT_ClusterCollection>();
37 
38  std::unique_ptr<InDet::PixelClusterCollection> PixelCollFromClusters = std::make_unique<InDet::PixelClusterCollection>();
39  std::unique_ptr<InDet::SCT_ClusterCollection> SCTCollFromClusters = std::make_unique<InDet::SCT_ClusterCollection>();
40 
41  std::unique_ptr<xAOD::PixelClusterContainer> PixelContFromHits = std::make_unique<xAOD::PixelClusterContainer>();
42  std::unique_ptr<xAOD::PixelClusterAuxContainer> PixelAuxContFromHits = std::make_unique<xAOD::PixelClusterAuxContainer>();
43  PixelContFromHits->setStore (PixelAuxContFromHits.get());
44 
45  std::unique_ptr<xAOD::StripClusterContainer> SCTContFromHits = std::make_unique<xAOD::StripClusterContainer>();
46  std::unique_ptr<xAOD::StripClusterAuxContainer> SCTAuxContFromHits = std::make_unique<xAOD::StripClusterAuxContainer>();
47  SCTContFromHits->setStore(SCTAuxContFromHits.get() );
48 
49  std::unique_ptr<xAOD::PixelClusterContainer> PixelContFromClusters = std::make_unique<xAOD::PixelClusterContainer>();
50  std::unique_ptr<xAOD::PixelClusterAuxContainer> PixelAuxContFromClusters = std::make_unique<xAOD::PixelClusterAuxContainer>();
51  PixelContFromClusters->setStore (PixelAuxContFromClusters.get());
52 
53  std::unique_ptr<xAOD::StripClusterContainer> SCTContFromClusters = std::make_unique<xAOD::StripClusterContainer>();
54  std::unique_ptr<xAOD::StripClusterAuxContainer> SCTAuxContFromClusters = std::make_unique<xAOD::StripClusterAuxContainer>();
55  SCTContFromClusters->setStore(SCTAuxContFromClusters.get() );
56 
57  std::unique_ptr<ActsTrk::ProtoTrackCollection> ProtoTracksFromRoads = std::make_unique<ActsTrk::ProtoTrackCollection>();
58  std::unique_ptr<ActsTrk::ProtoTrackCollection> ProtoTracksFromTracks = std::make_unique<ActsTrk::ProtoTrackCollection>();
59 
60  if (m_doClusters) {
61 
63 
64  if (FPGAClustersHandle.isValid()) { // To avoid running over events that didn't pass truth tracks selections
65 
66  const FPGATrackSimClusterCollection *FPGAClusterColl = FPGAClustersHandle.cptr();
67 
68  // Convert to InDet clusters
69  ATH_MSG_DEBUG("InDet Clusters CONVERSION");
70  ATH_CHECK( m_ClusterConverter->convertClusters(*FPGAClusterColl, *PixelCollFromClusters, *SCTCollFromClusters) );
71 
72  // Convert to xAOD clusters
73  ATH_MSG_DEBUG("xAOD Clusters CONVERSION");
74  ATH_CHECK( m_ClusterConverter->convertClusters(*FPGAClusterColl, *PixelContFromClusters, *SCTContFromClusters) );
75 
76  if (m_doActsTrk) {
78  if (!FPGARoadsHandle.isValid()) {
79  ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimRoadCollection");
80  return StatusCode::FAILURE;
81  }
82 
83  const FPGATrackSimRoadCollection *FPGARoadColl = FPGARoadsHandle.cptr();
84 
86  if (!FPGAHitsInRoadsHandle.isValid()) {
87  ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimItInRoadCollection");
88  return StatusCode::FAILURE;
89  }
90  const FPGATrackSimHitContainer *FPGAHitsInRoadsCont = FPGAHitsInRoadsHandle.cptr();
91 
93  if (!FPGATracksHandle.isValid()) {
94  ATH_MSG_FATAL("Failed to retrieve 1st stage FPGATrackSimTrackCollection");
95  return StatusCode::FAILURE;
96  }
97  const FPGATrackSimTrackCollection *FPGATrackColl = FPGATracksHandle.cptr();
98 
99  if (PixelContFromClusters->size()+SCTContFromClusters->size() > 0) {
100  ATH_CHECK(m_ActsTrkConverter->findProtoTracks(ctx,*PixelContFromClusters,*SCTContFromClusters,*ProtoTracksFromRoads, *FPGAHitsInRoadsCont, *FPGARoadColl ));
101  ATH_CHECK(m_ActsTrkConverter->findProtoTracks(ctx,*PixelContFromClusters,*SCTContFromClusters,*ProtoTracksFromTracks, *FPGATrackColl ));
102  }
103  }
104  }
105 
106  else {ATH_MSG_WARNING("Failed to retrieve 1st stage FPGATrackSimClusterCollection. Will skip clusters and track conversion ");}
107 
108  SG::WriteHandle<xAOD::PixelClusterContainer> xAODPixelClusterFromFPGAClusterHandle (m_xAODPixelClusterFromFPGAClusterKey, ctx);
109  SG::WriteHandle<xAOD::StripClusterContainer> xAODStripClusterFromFPGAClusterHandle (m_xAODStripClusterFromFPGAClusterKey, ctx);
110  ATH_CHECK( xAODPixelClusterFromFPGAClusterHandle.record (std::move(PixelContFromClusters), std::move(PixelAuxContFromClusters)));
111  ATH_CHECK( xAODStripClusterFromFPGAClusterHandle.record (std::move(SCTContFromClusters), std::move(SCTAuxContFromClusters)));
112 
113  if(m_doActsTrk)
114  {
117  ATH_CHECK( ActsProtoTrackFromFPGARoadHandle.record (std::move(ProtoTracksFromRoads)));
118  ATH_CHECK( ActsProtoTrackFromFPGATrackHandle.record (std::move(ProtoTracksFromTracks)));
119  }
120  }
121 
122 
123  if (m_doHits) {
124 
126 
127  if (FPGAHitsHandle.isValid()) {
128  const FPGATrackSimHitCollection *FPGAHitColl = FPGAHitsHandle.cptr();
129 
130  // Convert to InDet clusters
131  ATH_MSG_DEBUG("InDet Hits CONVERSION");
132  ATH_CHECK( m_ClusterConverter->convertHits(*FPGAHitColl, *PixelCollFromHits, *SCTCollFromHits) );
133  ATH_MSG_DEBUG("xAOD Hits CONVERSION");
134  ATH_CHECK( m_ClusterConverter->convertHits(*FPGAHitColl, *PixelContFromHits, *SCTContFromHits) );
135 
136  }
137 
138  else {ATH_MSG_WARNING("Failed to retrieve 1st stage FPGATrackSimHitCollection. Will skip hit conversion ");}
139 
140 
143  ATH_CHECK( xAODPixelClusterFromFPGAHitHandle.record (std::move(PixelContFromHits),std::move(PixelAuxContFromHits)));
144  ATH_CHECK( xAODStripClusterFromFPGAHitHandle.record (std::move(SCTContFromHits),std::move(SCTAuxContFromHits)));
145 
146  }
147 
148  return StatusCode::SUCCESS;
149  }
150 
151 
152 template <typename T> // should be InDet::PixelCluster or InDet::SCT_Cluster
153 StatusCode FPGAConversionAlgorithm::convertCollectionToContainer(Trk::PrepRawDataCollection<T>* inputCollection, // i.e. InDet::PixelClusterCollection or InDet::SCT_ClusterCollection
155  )
156 {
158  static_assert(false, "Bad type <T>. Should be InDet::PixelCluster or InDet::SCT_Cluster");
159  return StatusCode::FAILURE;
160  }
161 
162  std::unique_ptr<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>> outputContainer = std::make_unique<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>>(SG::VIEW_ELEMENTS);
163  SG::WriteHandle<Trk::PrepRawDataContainer<Trk::PrepRawDataCollection<T>>> outputContainerHandle(outputContainerKey);
164 
165  if (!inputCollection || inputCollection->empty()){
166  outputContainerHandle.record(std::move(outputContainer));
167  return StatusCode::SUCCESS;
168  }
169 
171  newCol->setIdentifier(inputCollection->identify());
172  for (const T* clus : *inputCollection) {
173  newCol->push_back(std::make_unique<T>(*clus));
174  ATH_MSG_DEBUG("NewCol cluster identifier " << clus->identify());
175  }
176 
177  ATH_MSG_DEBUG("newCol->identifyHash() " << newCol->identifyHash());
178  ATH_CHECK(outputContainer->addCollection(newCol,newCol->identifyHash()));
179 
180  if(outputContainerHandle.record(std::move(outputContainer)).isFailure()){
181  ATH_MSG_ERROR("Could not record InDetSCTClusterContainer object with "
182  << outputContainerHandle.key()
183  << " into Event Store");
184  return StatusCode::FAILURE;
185  }
186 
187  return StatusCode::SUCCESS;
188 }
FPGAConversionAlgorithm::m_xAODPixelClusterFromFPGAClusterKey
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_xAODPixelClusterFromFPGAClusterKey
Definition: FPGAConversionAlgorithm.h:49
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
FPGAConversionAlgorithm::m_ActsTrkConverter
ToolHandle< IFPGAActsTrkConverter > m_ActsTrkConverter
Definition: FPGAConversionAlgorithm.h:41
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:153
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
FPGAConversionAlgorithm::m_xAODPixelClusterFromFPGAHitKey
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_xAODPixelClusterFromFPGAHitKey
Definition: FPGAConversionAlgorithm.h:51
FPGAConversionAlgorithm::m_ActsProtoTrackFromFPGATrackKey
SG::WriteHandleKey< ActsTrk::ProtoTrackCollection > m_ActsProtoTrackFromFPGATrackKey
Definition: FPGAConversionAlgorithm.h:54
Trk::PrepRawDataCollection
Definition: PrepRawDataCollection.h:36
FPGAConversionAlgorithm::m_outputStripClusterContainerKey
SG::WriteHandleKey< InDet::SCT_ClusterContainer > m_outputStripClusterContainerKey
Definition: FPGAConversionAlgorithm.h:60
athena.value
value
Definition: athena.py:122
FPGAConversionAlgorithm::m_FPGAHitInRoadsKey
SG::ReadHandleKey< FPGATrackSimHitContainer > m_FPGAHitInRoadsKey
Definition: FPGAConversionAlgorithm.h:47
FPGAConversionAlgorithm::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: FPGAConversionAlgorithm.cxx:33
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
PhysDESDM_SmpCaloId.inputCollection
inputCollection
Definition: PhysDESDM_SmpCaloId.py:95
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:46
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:44
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:45
FPGAConversionAlgorithm::m_ActsProtoTrackFromFPGARoadKey
SG::WriteHandleKey< ActsTrk::ProtoTrackCollection > m_ActsProtoTrackFromFPGARoadKey
Definition: FPGAConversionAlgorithm.h:53
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FPGAConversionAlgorithm::m_outputPixelClusterContainerKey
SG::WriteHandleKey< InDet::PixelClusterContainer > m_outputPixelClusterContainerKey
Definition: FPGAConversionAlgorithm.h:59
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:62
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
FPGAConversionAlgorithm::m_ClusterConverter
ToolHandle< IFPGAClusterConverter > m_ClusterConverter
Definition: FPGAConversionAlgorithm.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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:43
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.
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:52
FPGAConversionAlgorithm::m_doHits
Gaudi::Property< bool > m_doHits
Definition: FPGAConversionAlgorithm.h:63
FPGAConversionAlgorithm::FPGAConversionAlgorithm
FPGAConversionAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: FPGAConversionAlgorithm.cxx:7
ReadHandle.h
Handle class for reading from StoreGate.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
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:50
Trk::PrepRawDataCollection::setIdentifier
void setIdentifier(Identifier id)
FPGAConversionAlgorithm::m_doActsTrk
Gaudi::Property< bool > m_doActsTrk
Definition: FPGAConversionAlgorithm.h:64