ATLAS Offline Software
TRT_StandaloneTrackFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // Implementation file for class InDet::TRT_StandaloneTrackFinder
8 // (c) ATLAS Detector software
11 // Version 1.0 09/28/2007 Thomas Koffas
12 // update by Markus Elsing
14 
19 
22 
24 // Constructor
26 
28 (const std::string& name, ISvcLocator* pSvcLocator)
29  : AthReentrantAlgorithm(name, pSvcLocator)
30 { }
31 
33 = default;
34 
36 // Initialisation
38 
40 {
41  m_total = {};
42 
43  ATH_CHECK(m_segToTrackTool.retrieve());
44 
45  ATH_CHECK(m_Segments.initialize());
47  ATH_CHECK(m_finalTracks.initialize());
48 
49  return StatusCode::SUCCESS;
50 }
51 
53 // Execute
56 {
57 
58  Counter_t counter {};
60 
62  //
63 
65  if(!segments.isValid()){
66  ATH_MSG_FATAL ("No segment with name " << m_Segments.key() << " found in StoreGate!");
67  return StatusCode::FAILURE;
68  }
69 
70  SG::ReadHandle<Trk::PRDtoTrackMap > prd_to_track_map;
71  const Trk::PRDtoTrackMap *prd_to_track_map_cptr = nullptr;
72  if (!m_prdToTrackMap.key().empty()) {
74  if(!prd_to_track_map.isValid()){
75  ATH_MSG_FATAL ("Failed to get " << m_prdToTrackMap.key() << ".");
76  return StatusCode::FAILURE;
77  }
78  prd_to_track_map_cptr = prd_to_track_map.cptr();
79  }
80 
81  // statistics...
82  counter[kNTrtSeg] = int(segments->size());
83  ATH_MSG_DEBUG ("TRT track container size " << counter[kNTrtSeg]);
84  ATH_MSG_DEBUG ("Begin looping over all TRT segments in the event");
85  for(const Trk::Segment *base_segment: *segments) {
86 
87  // Get the track segment
88  const Trk::TrackSegment *trackTRT = dynamic_cast<const Trk::TrackSegment*>(base_segment);
89 
90  if(!trackTRT) {
91 
92  ATH_MSG_WARNING ("No pointer to segment, should not happen !");
93  continue;
94 
95  } else {
96 
97  ATH_MSG_DEBUG ("--> start evaluating new segment");
98 
99  // start with pt preselection, get the segment parameters
100  const Amg::VectorX& p = trackTRT->localParameters();
101  if ( std::abs(sin(p(3))/p(4)) < m_minPt*0.9 ) {
102  // Statistics...
104  ATH_MSG_DEBUG ("Segment pt = " << std::abs(sin(p(3))/p(4)) << " , fails pre-cut, drop it !");
105  continue;
106  }
107 
108  // Check if segment has already been assigned to a BackTrack
109  if(m_segToTrackTool->segIsUsed(*trackTRT, prd_to_track_map_cptr)) {
110  // Statistics...
111  counter[kNUsedSeg]++;
112  ATH_MSG_DEBUG ("Segment excluded by BackTrack, drop it !");
113  continue;
114  }
115 
116  // Get the number of the TRT track segment ROTs
117  int nROTs = trackTRT->numberOfMeasurementBases();
118  ATH_MSG_DEBUG ("Number Of ROTs " << nROTs);
119 
120  bool is_toLower = false; // to handle special case
121 
122  // Cases where the min number of required TRT drift circles drops to 10
123  if(nROTs <= m_minNumDriftCircles && m_oldLogic) {
124  ATH_MSG_DEBUG ("Few DCs, can we recover ?");
125 
126  is_toLower = m_segToTrackTool->toLower(*trackTRT);
127  if (is_toLower) {
128  ATH_MSG_DEBUG ("We recovered this one, let's try...");
129  }
130  }
131 
132  if(nROTs < m_minNumDriftCircles && !is_toLower) {
133  // statistics...
135  ATH_MSG_DEBUG ("Segment fails number of DC requirements, reject it");
136  }
137  else {
138  // statistics
140  ATH_MSG_DEBUG ("Segment considered for further processing, enter into list");
141 
142  // Transform the original TRT segment into a track
143  Trk::Track* trtSeg = m_segToTrackTool->segToTrack(ctx, *trackTRT);
144  if(!trtSeg){
145  // Statistics...
146  counter[kNSegFailed]++;
147  ATH_MSG_DEBUG ("Failed to make a track out of the TRT segment!");
148  continue;
149  }
150 
151  // get all TSOS
153  if((int)ttsos->size()<10) {
154  // Statistics...
155  counter[kNSegFailed]++;
156  ATH_MSG_DEBUG ("Too few ROTs on track, reject !");
157  delete trtSeg;
158  continue;
159  }
160  // add the track to list
161  m_segToTrackTool->addNewTrack(trtSeg,event_data);
162  }
163  }
164  }
165 
166  // now resolve tracks
167  ATH_MSG_DEBUG ("Creating track container ");
168 
169  std::unique_ptr<TrackCollection> final_tracks(m_segToTrackTool->resolveTracks(prd_to_track_map.cptr(),event_data));
170  if (!final_tracks || SG::WriteHandle<TrackCollection>(m_finalTracks,ctx).record(std::move(final_tracks)).isFailure()) {
171  ATH_MSG_WARNING ("Could not save the reconstructed TRT seeded Si tracks!");
172  return StatusCode::FAILURE;
173  }
174 
175  // Update the total counters
179  {
180  std::lock_guard<std::mutex> lock(m_statMutex);
181  for (int idx=0; idx< kNCounter; ++idx) {
182  m_total[idx]+=counter[idx];
183  }
184  }
185 
186  // Print common event information
187  ATH_MSG_DEBUG( counter << std::endl );
188 
189  return StatusCode::SUCCESS;
190 }
191 
193 // Finalize
195 
197 {
198  ATH_MSG_DEBUG( m_total << std::endl );
199  return StatusCode::SUCCESS;
200 }
201 
203 // Dumps relevant information into the MsgStream
205 
206 MsgStream& InDet::TRT_StandaloneTrackFinder::dump( MsgStream& out ) const
207 {
208  // out<<std::endl;
209 
210  return dumpContainerNames(out);
211 }
212 
213 
215  out<<"| counters |" << counter << std::endl;
216  return out;
217 }
218 
219 
220 
222 // Dumps conditions information into the MsgStream
224 
226 {
227  const std::string::size_type max_width =65;
228 
229  out<<std::endl
230  <<"|----------------------------------------------------------------------"
231  <<"-------------------|"<<std::endl;
232  out<<"| Location of input tracks | "<<m_Segments.key() << std::setw( max_width-m_Segments.key().size())<< " " << "|" <<std::endl;
233  out<<"| Location of output tracks | "<<m_finalTracks.key() << std::setw( max_width-m_finalTracks.key().size()) << " " << "|" <<std::endl;
234  out<<"|----------------------------------------------------------------------"
235  <<"-------------------|";
236  return out;
237 }
238 
240 // Dumps event information into the MsgStream
242 
244 {
245 out<<std::endl
246  <<"|-------------------------------------------------------------------|" <<std::endl;
247  out<<"| Investigated |" <<std::endl;
248  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTrtSeg] <<" input TRT segments to be investigated" <<std::endl;
249  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNUsedSeg] <<" TRT segments excluded at input (by BackTracking tracks)" <<std::endl;
250  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNRejectedSeg] <<" segments rejected in selection at input" <<std::endl;
251  out<<"|-------------------------------------------------------------------|" <<std::endl;
252  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTrtSegGood] <<" input TRT segments after cuts" <<std::endl;
253  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNSegFailed] <<" segments failing to translate to a track (including refit)" <<std::endl;
254  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTrkScoreZeroTotal] <<" tracks rejected by score zero" <<std::endl;
255  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTrkSegUsedTotal] <<" excluded segments by other TRT segment" <<std::endl;
256  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTRTTrkTotal] <<" TRT-only tracks on output" <<std::endl;
257  out<<"|-------------------------------------------------------------------|";
258  return out;
259 }
260 
261 
263 // Overload of << operator MsgStream
265 
266 MsgStream& operator<<(MsgStream& sl, const InDet::TRT_StandaloneTrackFinder& se)
267 {
268  return se.dump(sl);
269 }
270 
271 
InDet::TRT_StandaloneTrackFinder::kNTrtSegGood
@ kNTrtSegGood
Number of input TRT segments after cuts per event.
Definition: TRT_StandaloneTrackFinder.h:115
InDet::operator<<
MsgStream & operator<<(MsgStream &, const GNNTrackReaderTool &)
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
InDet::TRT_StandaloneTrackFinder::kNSegFailed
@ kNSegFailed
Number of segments failing to translate to a track (inclusing refit)
Definition: TRT_StandaloneTrackFinder.h:116
Amg::VectorX
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Definition: EventPrimitives.h:30
InDet::TRT_StandaloneTrackFinder::kNTrtSeg
@ kNTrtSeg
Number of input TRT segments to be investigated per event.
Definition: TRT_StandaloneTrackFinder.h:112
TrackParameters.h
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
InDet::ITRT_SegmentToTrackTool::EventData::knTrkScoreZero
@ knTrkScoreZero
Number of tracks rejected by score zero.
Definition: ITRT_SegmentToTrackTool.h:52
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
InDet::TRT_StandaloneTrackFinder::m_minNumDriftCircles
IntegerProperty m_minNumDriftCircles
Definition: TRT_StandaloneTrackFinder.h:88
Trk::PRDtoTrackMap
Definition: PRDtoTrackMap.h:17
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet::TRT_StandaloneTrackFinder::kNUsedSeg
@ kNUsedSeg
Number of TRT segments excluded at input (by BackTracking tracks)
Definition: TRT_StandaloneTrackFinder.h:113
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
FitQualityOnSurface.h
Trk::TrackSegment
Definition: TrackSegment.h:56
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
InDet::TRT_StandaloneTrackFinder::TRT_StandaloneTrackFinder
TRT_StandaloneTrackFinder(const std::string &name, ISvcLocator *pSvcLocator)
Standard Algotithm methods
Definition: TRT_StandaloneTrackFinder.cxx:28
keylayer_zslicemap.se
se
Definition: keylayer_zslicemap.py:194
InDet::TRT_StandaloneTrackFinder::m_prdToTrackMap
SG::ReadHandleKey< Trk::PRDtoTrackMap > m_prdToTrackMap
map between PRDs and tracks to identify shared hits.
Definition: TRT_StandaloneTrackFinder.h:103
InDet::TRT_StandaloneTrackFinder::execute
StatusCode execute(const EventContext &ctx) const
Definition: TRT_StandaloneTrackFinder.cxx:55
Trk::Segment::numberOfMeasurementBases
unsigned int numberOfMeasurementBases() const
Return the number of contained Trk::MeasurementBase (s)
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:193
TrackSegment.h
InDet::TRT_StandaloneTrackFinder::kNCounter
@ kNCounter
Definition: TRT_StandaloneTrackFinder.h:120
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
InDet::TRT_StandaloneTrackFinder::kNTrkSegUsedTotal
@ kNTrkSegUsedTotal
Number of excluded segments by other TRT segments.
Definition: TRT_StandaloneTrackFinder.h:118
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
InDet::TRT_StandaloneTrackFinder::kNRejectedSeg
@ kNRejectedSeg
Number of segments rejected in selection at input.
Definition: TRT_StandaloneTrackFinder.h:114
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
InDet::TRT_StandaloneTrackFinder::finalize
StatusCode finalize()
Definition: TRT_StandaloneTrackFinder.cxx:196
InDet::TRT_StandaloneTrackFinder::m_segToTrackTool
ToolHandle< ITRT_SegmentToTrackTool > m_segToTrackTool
Segment to track tool.
Definition: TRT_StandaloneTrackFinder.h:98
Trk::Segment
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:56
InDet::TRT_StandaloneTrackFinder::dumpContainerNames
MsgStream & dumpContainerNames(MsgStream &out) const
Definition: TRT_StandaloneTrackFinder.cxx:225
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDet::TRT_StandaloneTrackFinder::m_finalTracks
SG::WriteHandleKey< TrackCollection > m_finalTracks
Tracks that will be passed out of AmbiProcessor.
Definition: TRT_StandaloneTrackFinder.h:108
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
DataVector< const Trk::MeasurementBase >
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InDet::TRT_StandaloneTrackFinder
Definition: TRT_StandaloneTrackFinder.h:56
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TRT_StandaloneTrackFinder.h
InDet::TRT_StandaloneTrackFinder::dump
MsgStream & dump(MsgStream &out) const
Print internal tool parameters and status
Definition: TRT_StandaloneTrackFinder.cxx:206
InDet::TRT_StandaloneTrackFinder::dumpevent
static MsgStream & dumpevent(MsgStream &, const InDet::TRT_StandaloneTrackFinder::Counter_t &)
Definition: TRT_StandaloneTrackFinder.cxx:214
InDet::TRT_StandaloneTrackFinder::kNTRTTrkTotal
@ kNTRTTrkTotal
Number of TRT-only tracks on output.
Definition: TRT_StandaloneTrackFinder.h:119
Trk::MeasurementBase::localParameters
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
Definition: MeasurementBase.h:132
Trk::Track::measurementsOnTrack
const DataVector< const MeasurementBase > * measurementsOnTrack() const
return a pointer to a vector of MeasurementBase (NOT including any that come from outliers).
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:178
InDet::TRT_StandaloneTrackFinder::initialize
StatusCode initialize()
Definition: TRT_StandaloneTrackFinder.cxx:39
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
InDet::TRT_StandaloneTrackFinder::m_Segments
SG::ReadHandleKey< Trk::SegmentCollection > m_Segments
TRT segments to use.
Definition: TRT_StandaloneTrackFinder.h:101
InDet::TRT_StandaloneTrackFinder::Counter_t
std::array< int, kNCounter > Counter_t
Definition: TRT_StandaloneTrackFinder.h:122
InDet::TRT_StandaloneTrackFinder::m_oldLogic
BooleanProperty m_oldLogic
Definition: TRT_StandaloneTrackFinder.h:94
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
InDet::ITRT_SegmentToTrackTool::EventData::knTRTTrk
@ knTRTTrk
Number of TRT-only tracks on output.
Definition: ITRT_SegmentToTrackTool.h:54
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
InDet::TRT_StandaloneTrackFinder::m_minPt
DoubleProperty m_minPt
Definition: TRT_StandaloneTrackFinder.h:91
InDet::TRT_StandaloneTrackFinder::~TRT_StandaloneTrackFinder
virtual ~TRT_StandaloneTrackFinder()
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
InDet::ITRT_SegmentToTrackTool::EventData::knTrkSegUsed
@ knTrkSegUsed
Number of excluded segments by other TRT segments.
Definition: ITRT_SegmentToTrackTool.h:53
FitQuality.h
test_pyathena.counter
counter
Definition: test_pyathena.py:15
InDet::ITRT_SegmentToTrackTool::EventData
Definition: ITRT_SegmentToTrackTool.h:50
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDet::ITRT_SegmentToTrackTool::EventData::m_counter
std::array< int, kNCounter > m_counter
Definition: ITRT_SegmentToTrackTool.h:56
InDet::TRT_StandaloneTrackFinder::kNTrkScoreZeroTotal
@ kNTrkScoreZeroTotal
Number of tracks rejected by score zero.
Definition: TRT_StandaloneTrackFinder.h:117