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 
23 #include "GaudiKernel/SystemOfUnits.h"
24 using Gaudi::Units::GeV;
25 
27 // Constructor
29 
31 (const std::string& name, ISvcLocator* pSvcLocator)
32  : AthReentrantAlgorithm(name, pSvcLocator)
33 {
34 
35  m_minNumDriftCircles = 15 ; //Minimum number of drift circles for TRT segment tracks
36  m_minPt = 1.0 * GeV ; //pt cut
37 
38  declareProperty("MinNumDriftCircles" ,m_minNumDriftCircles); //Minimum number of drift circles for TRT segment tracks
39  declareProperty("MinPt" ,m_minPt ); //Minimum Pt in preselection
40  declareProperty("OldTransitionLogic" ,m_oldLogic = true ); //use old transition logic for hits
41 }
42 
44 = default;
45 
47 // Initialisation
49 
51 {
52  m_total = {};
53 
54  ATH_CHECK(m_segToTrackTool.retrieve());
55 
56  ATH_CHECK(m_Segments.initialize());
58  ATH_CHECK(m_finalTracks.initialize());
59 
60  return StatusCode::SUCCESS;
61 }
62 
64 // Execute
67 {
68 
69  Counter_t counter {};
71 
73  //
74 
76  if(!segments.isValid()){
77  ATH_MSG_FATAL ("No segment with name " << m_Segments.key() << " found in StoreGate!");
78  return StatusCode::FAILURE;
79  }
80 
81  SG::ReadHandle<Trk::PRDtoTrackMap > prd_to_track_map;
82  const Trk::PRDtoTrackMap *prd_to_track_map_cptr = nullptr;
83  if (!m_prdToTrackMap.key().empty()) {
85  if(!prd_to_track_map.isValid()){
86  ATH_MSG_FATAL ("Failed to get " << m_prdToTrackMap.key() << ".");
87  return StatusCode::FAILURE;
88  }
89  prd_to_track_map_cptr = prd_to_track_map.cptr();
90  }
91 
92  // statistics...
93  counter[kNTrtSeg] = int(segments->size());
94  ATH_MSG_DEBUG ("TRT track container size " << counter[kNTrtSeg]);
95  ATH_MSG_DEBUG ("Begin looping over all TRT segments in the event");
96  for(const Trk::Segment *base_segment: *segments) {
97 
98  // Get the track segment
99  const Trk::TrackSegment *trackTRT = dynamic_cast<const Trk::TrackSegment*>(base_segment);
100 
101  if(!trackTRT) {
102 
103  ATH_MSG_WARNING ("No pointer to segment, should not happen !");
104  continue;
105 
106  } else {
107 
108  ATH_MSG_DEBUG ("--> start evaluating new segment");
109 
110  // start with pt preselection, get the segment parameters
111  const Amg::VectorX& p = trackTRT->localParameters();
112  if ( std::abs(sin(p(3))/p(4)) < m_minPt*0.9 ) {
113  // Statistics...
115  ATH_MSG_DEBUG ("Segment pt = " << std::abs(sin(p(3))/p(4)) << " , fails pre-cut, drop it !");
116  continue;
117  }
118 
119  // Check if segment has already been assigned to a BackTrack
120  if(m_segToTrackTool->segIsUsed(*trackTRT, prd_to_track_map_cptr)) {
121  // Statistics...
122  counter[kNUsedSeg]++;
123  ATH_MSG_DEBUG ("Segment excluded by BackTrack, drop it !");
124  continue;
125  }
126 
127  // Get the number of the TRT track segment ROTs
128  int nROTs = trackTRT->numberOfMeasurementBases();
129  ATH_MSG_DEBUG ("Number Of ROTs " << nROTs);
130 
131  bool is_toLower = false; // to handle special case
132 
133  // Cases where the min number of required TRT drift circles drops to 10
134  if(nROTs <= m_minNumDriftCircles && m_oldLogic) {
135  ATH_MSG_DEBUG ("Few DCs, can we recover ?");
136 
137  is_toLower = m_segToTrackTool->toLower(*trackTRT);
138  if (is_toLower) {
139  ATH_MSG_DEBUG ("We recovered this one, let's try...");
140  }
141  }
142 
143  if(nROTs < m_minNumDriftCircles && !is_toLower) {
144  // statistics...
146  ATH_MSG_DEBUG ("Segment fails number of DC requirements, reject it");
147  }
148  else {
149  // statistics
151  ATH_MSG_DEBUG ("Segment considered for further processing, enter into list");
152 
153  // Transform the original TRT segment into a track
154  Trk::Track* trtSeg = m_segToTrackTool->segToTrack(ctx, *trackTRT);
155  if(!trtSeg){
156  // Statistics...
157  counter[kNSegFailed]++;
158  ATH_MSG_DEBUG ("Failed to make a track out of the TRT segment!");
159  continue;
160  }
161 
162  // get all TSOS
164  if((int)ttsos->size()<10) {
165  // Statistics...
166  counter[kNSegFailed]++;
167  ATH_MSG_DEBUG ("Too few ROTs on track, reject !");
168  delete trtSeg;
169  continue;
170  }
171  // add the track to list
172  m_segToTrackTool->addNewTrack(trtSeg,event_data);
173  }
174  }
175  }
176 
177  // now resolve tracks
178  ATH_MSG_DEBUG ("Creating track container ");
179 
180  std::unique_ptr<TrackCollection> final_tracks(m_segToTrackTool->resolveTracks(prd_to_track_map.cptr(),event_data));
181  if (!final_tracks || SG::WriteHandle<TrackCollection>(m_finalTracks,ctx).record(std::move(final_tracks)).isFailure()) {
182  ATH_MSG_WARNING ("Could not save the reconstructed TRT seeded Si tracks!");
183  return StatusCode::FAILURE;
184  }
185 
186  // Update the total counters
190  {
191  std::lock_guard<std::mutex> lock(m_statMutex);
192  for (int idx=0; idx< kNCounter; ++idx) {
193  m_total[idx]+=counter[idx];
194  }
195  }
196 
197  // Print common event information
198  ATH_MSG_DEBUG( counter << std::endl );
199 
200  return StatusCode::SUCCESS;
201 }
202 
204 // Finalize
206 
208 {
209  ATH_MSG_DEBUG( m_total << std::endl );
210  return StatusCode::SUCCESS;
211 }
212 
214 // Dumps relevant information into the MsgStream
216 
217 MsgStream& InDet::TRT_StandaloneTrackFinder::dump( MsgStream& out ) const
218 {
219  // out<<std::endl;
220 
221  return dumpContainerNames(out);
222 }
223 
224 
226  out<<"| counters |" << counter << std::endl;
227  return out;
228 }
229 
230 
231 
233 // Dumps conditions information into the MsgStream
235 
237 {
238  const std::string::size_type max_width =65;
239 
240  out<<std::endl
241  <<"|----------------------------------------------------------------------"
242  <<"-------------------|"<<std::endl;
243  out<<"| Location of input tracks | "<<m_Segments.key() << std::setw( max_width-m_Segments.key().size())<< " " << "|" <<std::endl;
244  out<<"| Location of output tracks | "<<m_finalTracks.key() << std::setw( max_width-m_finalTracks.key().size()) << " " << "|" <<std::endl;
245  out<<"|----------------------------------------------------------------------"
246  <<"-------------------|";
247  return out;
248 }
249 
251 // Dumps event information into the MsgStream
253 
255 {
256 out<<std::endl
257  <<"|-------------------------------------------------------------------|" <<std::endl;
258  out<<"| Investigated |" <<std::endl;
259  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTrtSeg] <<" input TRT segments to be investigated" <<std::endl;
260  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNUsedSeg] <<" TRT segments excluded at input (by BackTracking tracks)" <<std::endl;
261  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNRejectedSeg] <<" segments rejected in selection at input" <<std::endl;
262  out<<"|-------------------------------------------------------------------|" <<std::endl;
263  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTrtSegGood] <<" input TRT segments after cuts" <<std::endl;
264  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNSegFailed] <<" segments failing to translate to a track (including refit)" <<std::endl;
265  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTrkScoreZeroTotal] <<" tracks rejected by score zero" <<std::endl;
266  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTrkSegUsedTotal] <<" excluded segments by other TRT segment" <<std::endl;
267  out<<"| "<<std::setw(7)<<counter[InDet::TRT_StandaloneTrackFinder::kNTRTTrkTotal] <<" TRT-only tracks on output" <<std::endl;
268  out<<"|-------------------------------------------------------------------|";
269  return out;
270 }
271 
272 
274 // Overload of << operator MsgStream
276 
277 MsgStream& operator<<(MsgStream& sl, const InDet::TRT_StandaloneTrackFinder& se)
278 {
279  return se.dump(sl);
280 }
281 
282 
InDet::TRT_StandaloneTrackFinder::kNTrtSegGood
@ kNTrtSegGood
Number of input TRT segments after cuts per event.
Definition: TRT_StandaloneTrackFinder.h:108
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:109
Amg::VectorX
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Definition: EventPrimitives.h:32
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
InDet::TRT_StandaloneTrackFinder::kNTrtSeg
@ kNTrtSeg
Number of input TRT segments to be investigated per event.
Definition: TRT_StandaloneTrackFinder.h:105
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_minPt
double m_minPt
Minimum pt cut for TRT only (used in preselection * 0.9)
Definition: TRT_StandaloneTrackFinder.h:87
Trk::PRDtoTrackMap
Definition: PRDtoTrackMap.h:17
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
InDet::TRT_StandaloneTrackFinder::kNUsedSeg
@ kNUsedSeg
Number of TRT segments excluded at input (by BackTracking tracks)
Definition: TRT_StandaloneTrackFinder.h:106
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
InDet::TRT_StandaloneTrackFinder::m_oldLogic
bool m_oldLogic
use old transition region hit logic
Definition: TRT_StandaloneTrackFinder.h:88
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:31
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:96
InDet::TRT_StandaloneTrackFinder::execute
StatusCode execute(const EventContext &ctx) const
Definition: TRT_StandaloneTrackFinder.cxx:66
Trk::Segment::numberOfMeasurementBases
unsigned int numberOfMeasurementBases() const
Return the number of contained Trk::MeasurementBase (s)
Definition: TrkEvent/TrkSegment/TrkSegment/Segment.h:193
TrackSegment.h
InDet::TRT_StandaloneTrackFinder::kNCounter
@ kNCounter
Definition: TRT_StandaloneTrackFinder.h:113
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:111
InDet::TRT_StandaloneTrackFinder::kNRejectedSeg
@ kNRejectedSeg
Number of segments rejected in selection at input.
Definition: TRT_StandaloneTrackFinder.h:107
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:207
InDet::TRT_StandaloneTrackFinder::m_segToTrackTool
ToolHandle< ITRT_SegmentToTrackTool > m_segToTrackTool
Segment to track tool.
Definition: TRT_StandaloneTrackFinder.h:91
Trk::Segment
Definition: TrkEvent/TrkSegment/TrkSegment/Segment.h:56
InDet::TRT_StandaloneTrackFinder::dumpContainerNames
MsgStream & dumpContainerNames(MsgStream &out) const
Definition: TRT_StandaloneTrackFinder.cxx:236
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:101
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:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TRT_StandaloneTrackFinder.h
InDet::TRT_StandaloneTrackFinder::dump
MsgStream & dump(MsgStream &out) const
Print internal tool parameters and status
Definition: TRT_StandaloneTrackFinder.cxx:217
InDet::TRT_StandaloneTrackFinder::dumpevent
static MsgStream & dumpevent(MsgStream &, const InDet::TRT_StandaloneTrackFinder::Counter_t &)
Definition: TRT_StandaloneTrackFinder.cxx:225
InDet::TRT_StandaloneTrackFinder::kNTRTTrkTotal
@ kNTRTTrkTotal
Number of TRT-only tracks on output.
Definition: TRT_StandaloneTrackFinder.h:112
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:50
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:94
InDet::TRT_StandaloneTrackFinder::Counter_t
std::array< int, kNCounter > Counter_t
Definition: TRT_StandaloneTrackFinder.h:115
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_minNumDriftCircles
int m_minNumDriftCircles
Minimum number of drift circles for TRT segment tracks.
Definition: TRT_StandaloneTrackFinder.h:86
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
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
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:110