ATLAS Offline Software
SiSPGNNTrackMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <memory>
6 #include <fstream>
7 
8 #include "SiSPGNNTrackMaker.h"
9 
11 
13  const std::string& name, ISvcLocator* pSvcLocator)
14  : AthReentrantAlgorithm(name, pSvcLocator)
15 {
16 
17 }
18 
20 {
24 
25  ATH_CHECK(m_outputTracksKey.initialize());
26 
27  ATH_CHECK(m_trackFitter.retrieve());
28  ATH_CHECK(m_seedFitter.retrieve());
29 
30  if (!m_gnnTrackFinder.empty() && !m_gnnTrackReader.empty()) {
31  ATH_MSG_ERROR("Use either track finder or track reader, not both.");
32  return StatusCode::FAILURE;
33  }
34 
35  if (!m_gnnTrackFinder.empty()) {
36  ATH_MSG_INFO("Use GNN Track Finder");
37  ATH_CHECK(m_gnnTrackFinder.retrieve());
38  }
39  if (!m_gnnTrackReader.empty()) {
40  ATH_MSG_INFO("Use GNN Track Reader");
41  ATH_CHECK(m_gnnTrackReader.retrieve());
42  }
43 
44  return StatusCode::SUCCESS;
45 }
46 
47 
48 StatusCode InDet::SiSPGNNTrackMaker::execute(const EventContext& ctx) const
49 {
51  ATH_CHECK(outputTracks.record(std::make_unique<TrackCollection>()));
52 
53  // get event info
54  uint32_t runNumber = ctx.eventID().run_number();
55  uint32_t eventNumber = ctx.eventID().event_number();
56 
57  std::vector<const Trk::SpacePoint*> spacePoints;
58 
59  auto getData = [&](const SG::ReadHandleKey<SpacePointContainer>& containerKey){
60  if (not containerKey.empty()){
61 
62  SG::ReadHandle<SpacePointContainer> container{containerKey, ctx};
63 
64  if (container.isValid()){
65  // loop over spacepoint collection
66  auto spc = container->begin();
67  auto spce = container->end();
68  for(; spc != spce; ++spc){
69  const SpacePointCollection* spCollection = (*spc);
70  auto sp = spCollection->begin();
71  auto spe = spCollection->end();
72  for(; sp != spe; ++sp) {
73  const Trk::SpacePoint* spacePoint = (*sp);
74  spacePoints.push_back(spacePoint);
75  }
76  }
77  }
78  }
79  };
80 
81  auto getOverlapData = [&](const SG::ReadHandleKey<SpacePointOverlapCollection>& containerKey){
82  if (not containerKey.empty()){
83 
84  SG::ReadHandle<SpacePointOverlapCollection> collection{containerKey, ctx};
85 
86  if (collection.isValid()){
87  ATH_MSG_DEBUG("Number of overlapping space points: " << collection->size());
88  for (const Trk::SpacePoint *sp : *collection) {
89  spacePoints.push_back(sp);
90  }
91  }
92  }
93  };
94 
97  int nNonOverlap = spacePoints.size();
98  ATH_MSG_DEBUG("Number of non-overlapping spacepoints: " << nNonOverlap );
99  getOverlapData(m_SpacePointsOverlapKey);
100  ATH_MSG_DEBUG("Number of spacepoints: " << spacePoints.size() );
101 
102  std::vector<std::vector<uint32_t> > TT;
103  if (m_gnnTrackFinder.isSet()) {
104  ATH_CHECK(m_gnnTrackFinder->getTracks(spacePoints, TT));
105  } else if (m_gnnTrackReader.isSet()) {
107  } else {
108  ATH_MSG_ERROR("Both GNNTrackFinder and GNNTrackReader are not set");
109  return StatusCode::FAILURE;
110  }
111 
112 
113  ATH_MSG_DEBUG("Obtained " << TT.size() << " Tracks");
114 
115  // loop over all track candidates
116  // and perform track fitting for each.
117  int trackCounter = -1;
118  for (auto& trackIndices : TT) {
119 
120  std::vector<const Trk::PrepRawData*> clusters;
121  std::vector<const Trk::SpacePoint*> trackCandiate;
122  trackCandiate.reserve(trackIndices.size());
123 
124  trackCounter++;
125  ATH_MSG_DEBUG("Track " << trackCounter << " has " << trackIndices.size() << " spacepoints");
126 
127  std::stringstream spCoordinates;
128 
129  for (auto& id : trackIndices) {
131  if (id > spacePoints.size()) {
132  ATH_MSG_WARNING("SpacePoint index "<< id << " out of range: " << spacePoints.size());
133  continue;
134  }
135 
136  const Trk::SpacePoint* sp = spacePoints[id];
137  if (static_cast<int>(id) > nNonOverlap) {
138  ATH_MSG_DEBUG("Track " << trackCounter << " Overlapping Hit " << id << ": (" << sp->globalPosition().x() << ", " << sp->globalPosition().y() << ", " << sp->globalPosition().z() << ")");
139  }
140  if (sp != nullptr) {
141  trackCandiate.push_back(sp);
142  clusters.push_back(sp->clusterList().first);
143  if (sp->clusterList().second != nullptr) {
144  clusters.push_back(sp->clusterList().second);
145  }
146  }
147  }
148  ATH_MSG_DEBUG("Track " << trackCounter << " has " << clusters.size() << " clusters");
149  ATH_MSG_DEBUG("spacepoints: " << spCoordinates.str());
150 
151  // conformal mapping for track parameters
152  auto trkParameters = m_seedFitter->fit(trackCandiate);
153  if (trkParameters == nullptr) {
154  ATH_MSG_WARNING("Conformal mapping failed");
155  continue;
156  }
157 
158  Trk::ParticleHypothesis matEffects = Trk::pion;
159  // first fit the track with local parameters and without outlier removal.
160  std::unique_ptr<Trk::Track> track = m_trackFitter->fit(ctx, clusters, *trkParameters, false, matEffects);
161  if (track != nullptr && track->perigeeParameters() != nullptr) {
162  // fit the track again with perigee parameters and without outlier removal.
163  track = m_trackFitter->fit(ctx, clusters, *track->perigeeParameters(), false, matEffects);
164  if (track != nullptr) {
165  // finally fit with outlier removal
166  track = m_trackFitter->fit(ctx, clusters, *track->perigeeParameters(), true, matEffects);
167  if (track != nullptr && track->trackSummary() != nullptr) {
168  outputTracks->push_back(track.release());
169  }
170  }
171  }
172  }
173 
174  ATH_MSG_DEBUG("Run " << runNumber << ", Event " << eventNumber << " has " << outputTracks->size() << " tracks stored");
175  return StatusCode::SUCCESS;
176 }
177 
178 
180 // Overload of << operator MsgStream
182 
183 MsgStream& InDet::operator <<
184  (MsgStream& sl,const InDet::SiSPGNNTrackMaker& se)
185 {
186  return se.dump(sl);
187 }
188 
190 // Overload of << operator std::ostream
192 
193 std::ostream& InDet::operator <<
194  (std::ostream& sl,const InDet::SiSPGNNTrackMaker& se)
195 {
196  return se.dump(sl);
197 }
198 
200 // Dumps relevant information into the MsgStream
202 
203 MsgStream& InDet::SiSPGNNTrackMaker::dump( MsgStream& out ) const
204 {
205  out<<std::endl;
206  if(msgLvl(MSG::DEBUG)) return dumpevent(out);
207  else return dumptools(out);
208 }
209 
211 // Dumps conditions information into the MsgStream
213 
214 MsgStream& InDet::SiSPGNNTrackMaker::dumptools( MsgStream& out ) const
215 {
216  out<<"| Location of output tracks | "
217  <<std::endl;
218  out<<"|----------------------------------------------------------------"
219  <<"----------------------------------------------------|"
220  <<std::endl;
221  return out;
222 }
223 
225 // Dumps event information into the ostream
227 
228 MsgStream& InDet::SiSPGNNTrackMaker::dumpevent( MsgStream& out ) const
229 {
230  return out;
231 }
232 
233 
234 std::ostream& InDet::SiSPGNNTrackMaker::dump( std::ostream& out ) const
235 {
236  return out;
237 }
Trk::SpacePoint::clusterList
const std::pair< const PrepRawData *, const PrepRawData * > & clusterList() const
return the pair of cluster pointers by reference
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePoint.h:127
Trk::SpacePoint
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePoint.h:35
InDetSimDataHelpers::getData
const InDetSimData * getData(const InDetSimDataCollection &coll, const Identifier &id)
Definition: InDetSimDataDict.h:24
InDet::SiSPGNNTrackMaker::m_gnnTrackFinder
ToolHandle< IGNNTrackFinder > m_gnnTrackFinder
GNN-based track finding tool that produces track candidates.
Definition: SiSPGNNTrackMaker.h:74
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
InDet::SiSPGNNTrackMaker::m_SpacePointsPixelKey
SG::ReadHandleKey< SpacePointContainer > m_SpacePointsPixelKey
Definition: SiSPGNNTrackMaker.h:58
Trk::SpacePoint::globalPosition
virtual const Amg::Vector3D & globalPosition() const override final
Interface method to get the global Position.
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePoint.h:146
SiSPGNNTrackMaker.h
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle< SpacePointContainer >
InDet::SiSPGNNTrackMaker::initialize
virtual StatusCode initialize() override
Definition: SiSPGNNTrackMaker.cxx:19
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
InDet::SiSPGNNTrackMaker::dump
MsgStream & dump(MsgStream &out) const
Definition: SiSPGNNTrackMaker.cxx:203
InDet::SiSPGNNTrackMaker::m_SpacePointsOverlapKey
SG::ReadHandleKey< SpacePointOverlapCollection > m_SpacePointsOverlapKey
Definition: SiSPGNNTrackMaker.h:62
SG::ReadHandleKey< SpacePointContainer >
keylayer_zslicemap.se
se
Definition: keylayer_zslicemap.py:194
InDet::SiSPGNNTrackMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: SiSPGNNTrackMaker.cxx:48
PrepRawData.h
InDet::SiSPGNNTrackMaker::m_outputTracksKey
SG::WriteHandleKey< TrackCollection > m_outputTracksKey
Definition: SiSPGNNTrackMaker.h:66
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InDet::SiSPGNNTrackMaker::dumpevent
MsgStream & dumpevent(MsgStream &out) const
Definition: SiSPGNNTrackMaker.cxx:228
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::pion
@ pion
Definition: ParticleHypothesis.h:29
InDet::SiSPGNNTrackMaker::m_trackFitter
ToolHandle< Trk::ITrackFitter > m_trackFitter
Track Fitter.
Definition: SiSPGNNTrackMaker.h:83
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:236
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
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
InDet::SiSPGNNTrackMaker::m_seedFitter
ToolHandle< ISeedFitter > m_seedFitter
Definition: SiSPGNNTrackMaker.h:78
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
InDet::SiSPGNNTrackMaker::SiSPGNNTrackMaker
SiSPGNNTrackMaker(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SiSPGNNTrackMaker.cxx:12
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SpacePointCollection
Definition: SpacePointCollection.h:40
DEBUG
#define DEBUG
Definition: page_access.h:11
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
InDet::SiSPGNNTrackMaker::dumptools
MsgStream & dumptools(MsgStream &out) const
Definition: SiSPGNNTrackMaker.cxx:214
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
InDet::SiSPGNNTrackMaker
InDet::SiSPGNNTrackMaker is an algorithm that uses the GNN-based track finding tool to reconstruct tr...
Definition: SiSPGNNTrackMaker.h:39
Analysis::TT
@ TT
Definition: JpsiFinder.h:36
InDet::SiSPGNNTrackMaker::m_SpacePointsSCTKey
SG::ReadHandleKey< SpacePointContainer > m_SpacePointsSCTKey
Definition: SiSPGNNTrackMaker.h:60
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
InDet::SiSPGNNTrackMaker::m_gnnTrackReader
ToolHandle< IGNNTrackReaderTool > m_gnnTrackReader
Definition: SiSPGNNTrackMaker.h:87