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 {
23 
24  ATH_CHECK(m_outputTracksKey.initialize());
25 
26  ATH_CHECK(m_trackFitter.retrieve());
27  ATH_CHECK(m_seedFitter.retrieve());
28 
29  if (!m_gnnTrackFinder.empty() && !m_gnnTrackReader.empty()) {
30  ATH_MSG_ERROR("Use either track finder or track reader, not both.");
31  return StatusCode::FAILURE;
32  }
33 
34  if (!m_gnnTrackFinder.empty()) {
35  ATH_MSG_INFO("Use GNN Track Finder");
36  ATH_CHECK(m_gnnTrackFinder.retrieve());
37  }
38  if (!m_gnnTrackReader.empty()) {
39  ATH_MSG_INFO("Use GNN Track Reader");
40  ATH_CHECK(m_gnnTrackReader.retrieve());
41  }
42 
43  return StatusCode::SUCCESS;
44 }
45 
46 
47 StatusCode InDet::SiSPGNNTrackMaker::execute(const EventContext& ctx) const
48 {
50  ATH_CHECK(outputTracks.record(std::make_unique<TrackCollection>()));
51 
52  // get event info
53  uint32_t runNumber = ctx.eventID().run_number();
54  uint32_t eventNumber = ctx.eventID().event_number();
55 
56  std::vector<const Trk::SpacePoint*> spacePoints;
57 
58  auto getData = [&](const SG::ReadHandleKey<SpacePointContainer>& containerKey){
59  if (not containerKey.empty()){
60 
61  SG::ReadHandle<SpacePointContainer> container{containerKey, ctx};
62 
63  if (container.isValid()){
64  // loop over spacepoint collection
65  auto spc = container->begin();
66  auto spce = container->end();
67  for(; spc != spce; ++spc){
68  const SpacePointCollection* spCollection = (*spc);
69  auto sp = spCollection->begin();
70  auto spe = spCollection->end();
71  for(; sp != spe; ++sp) {
72  const Trk::SpacePoint* spacePoint = (*sp);
73  spacePoints.push_back(spacePoint);
74  }
75  }
76  }
77  }
78  };
79 
82 
83  std::vector<std::vector<uint32_t> > TT;
84  if (m_gnnTrackFinder.isSet()) {
85  ATH_CHECK(m_gnnTrackFinder->getTracks(spacePoints, TT));
86  } else if (m_gnnTrackReader.isSet()) {
88  } else {
89  ATH_MSG_ERROR("Both GNNTrackFinder and GNNTrackReader are not set");
90  return StatusCode::FAILURE;
91  }
92 
93 
94  ATH_MSG_DEBUG("Obtained " << TT.size() << " Tracks");
95 
96  // loop over all track candidates
97  // and perform track fitting for each.
98  int trackCounter = -1;
99  for (auto& trackIndices : TT) {
100 
101  std::vector<const Trk::PrepRawData*> clusters;
102  std::vector<const Trk::SpacePoint*> trackCandiate;
103  trackCandiate.reserve(trackIndices.size());
104 
105  trackCounter++;
106  ATH_MSG_DEBUG("Track " << trackCounter << " has " << trackIndices.size() << " spacepoints");
107 
108  std::stringstream spCoordinates;
109 
110  for (auto& id : trackIndices) {
112  if (id > spacePoints.size()) {
113  ATH_MSG_WARNING("SpacePoint index "<< id << " out of range: " << spacePoints.size());
114  continue;
115  }
116 
117  const Trk::SpacePoint* sp = spacePoints[id];
118  if (sp != nullptr) {
119  trackCandiate.push_back(sp);
120  clusters.push_back(sp->clusterList().first);
121  if (sp->clusterList().second != nullptr) {
122  clusters.push_back(sp->clusterList().second);
123  }
124  }
125  }
126  ATH_MSG_DEBUG("Track " << trackCounter << " has " << clusters.size() << " clusters");
127  ATH_MSG_DEBUG("spacepoints: " << spCoordinates.str());
128 
129  // conformal mapping for track parameters
130  auto trkParameters = m_seedFitter->fit(trackCandiate);
131  if (trkParameters == nullptr) {
132  ATH_MSG_WARNING("Conformal mapping failed");
133  continue;
134  }
135 
136  Trk::ParticleHypothesis matEffects = Trk::pion;
137  // first fit the track with local parameters and without outlier removal.
138  std::unique_ptr<Trk::Track> track = m_trackFitter->fit(ctx, clusters, *trkParameters, false, matEffects);
139  if (track != nullptr && track->perigeeParameters() != nullptr) {
140  // fit the track again with perigee parameters and without outlier removal.
141  track = m_trackFitter->fit(ctx, clusters, *track->perigeeParameters(), false, matEffects);
142  if (track != nullptr) {
143  // finally fit with outlier removal
144  track = m_trackFitter->fit(ctx, clusters, *track->perigeeParameters(), true, matEffects);
145  if (track != nullptr && track->trackSummary() != nullptr) {
146  outputTracks->push_back(track.release());
147  }
148  }
149  }
150  }
151 
152  ATH_MSG_DEBUG("Run " << runNumber << ", Event " << eventNumber << " has " << outputTracks->size() << " tracks stored");
153  return StatusCode::SUCCESS;
154 }
155 
156 
158 // Overload of << operator MsgStream
160 
161 MsgStream& InDet::operator <<
162  (MsgStream& sl,const InDet::SiSPGNNTrackMaker& se)
163 {
164  return se.dump(sl);
165 }
166 
168 // Overload of << operator std::ostream
170 
171 std::ostream& InDet::operator <<
172  (std::ostream& sl,const InDet::SiSPGNNTrackMaker& se)
173 {
174  return se.dump(sl);
175 }
176 
178 // Dumps relevant information into the MsgStream
180 
181 MsgStream& InDet::SiSPGNNTrackMaker::dump( MsgStream& out ) const
182 {
183  out<<std::endl;
184  if(msgLvl(MSG::DEBUG)) return dumpevent(out);
185  else return dumptools(out);
186 }
187 
189 // Dumps conditions information into the MsgStream
191 
192 MsgStream& InDet::SiSPGNNTrackMaker::dumptools( MsgStream& out ) const
193 {
194  out<<"| Location of output tracks | "
195  <<std::endl;
196  out<<"|----------------------------------------------------------------"
197  <<"----------------------------------------------------|"
198  <<std::endl;
199  return out;
200 }
201 
203 // Dumps event information into the ostream
205 
206 MsgStream& InDet::SiSPGNNTrackMaker::dumpevent( MsgStream& out ) const
207 {
208  return out;
209 }
210 
211 
212 std::ostream& InDet::SiSPGNNTrackMaker::dump( std::ostream& out ) const
213 {
214  return out;
215 }
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:72
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
InDet::SiSPGNNTrackMaker::m_SpacePointsPixelKey
SG::ReadHandleKey< SpacePointContainer > m_SpacePointsPixelKey
Definition: SiSPGNNTrackMaker.h:57
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:181
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:47
PrepRawData.h
InDet::SiSPGNNTrackMaker::m_outputTracksKey
SG::WriteHandleKey< TrackCollection > m_outputTracksKey
Definition: SiSPGNNTrackMaker.h:64
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:206
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:81
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:194
InDet::SiSPGNNTrackMaker::m_seedFitter
ToolHandle< ISeedFitter > m_seedFitter
Definition: SiSPGNNTrackMaker.h:76
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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:192
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:38
Analysis::TT
@ TT
Definition: JpsiFinder.h:39
InDet::SiSPGNNTrackMaker::m_SpacePointsSCTKey
SG::ReadHandleKey< SpacePointContainer > m_SpacePointsSCTKey
Definition: SiSPGNNTrackMaker.h:59
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:85