ATLAS Offline Software
TrkObserverTool.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // TrkObserverTool.cxx
8 // Implementation file for class TrkObserverTool
9 // Authors: C.Rauchegger<christoph.rauchegger@cern.ch> and
10 // S.Rettie<sebastien.rettie@cern.ch>
11 
12 // Description:
13 // This tool monitors a track candidate through the whole
14 // ambiguity solving process
15 // (AmbiguityProcessorBase.cxx,
16 // DenseEnvironmentsAmbiguityProcessorTool.cxx,
17 // DenseEnvironmentsAmbiguityScoreProcessorTool.cxx,
18 // InDetDenseEnvAmbiTrackSelectionTool.cxx).
19 // Every change (score, subtrack created, track rejected) is
20 // recorded and in the end an xAOD output file is created.
21 
22 // The output file contains all the tracks which occur during
23 // the ambiguity solving (input tracks, final tracks, and only
24 // temporary tracks as well). The tracks in the file contain
25 // all information the ambiguity solver has (pixel hits, SCT
26 // hits, split hits, etc.) and additional information by the
27 // TrkObserverTool (uniqueId, parentId, score, rejection location).
28 
29 // Every track has ONLY one "direct subtrack". But this subtrack
30 // can have another subtrack, ...
31 
32 // Each track is uniquely identified using a thread-safe
33 // std::atomic<std::uint32_t> (defined in AmbiguityProcessorUtility.cxx),
34 // which serves as Id for the tool. If a track has a parent, the unique
35 // Id of the parent is also saved by the tool. As the ambiguity processor
36 // tools delete tracks, all tracks (including temporary tracks) are
37 // saved to the tool's cache entry, i.e. an ObservedTrackMap object.
38 
39 // Two instances of the TrkObserverTool must be instantiated in order
40 // to avoid data handle conflicts:
41 // - Instance that does not initialize the data handles and
42 // is used throughout the ambiguity solving
43 // - Instance that initializes the data handles and is only used
44 // to write out the observed tracks after the ambiguity solving
45 // is done
46 
47 // Package includes
49 #include <sstream>
50 
51 // FrameWork includes
52 #include "GaudiKernel/IToolSvc.h"
54 
56 // Public methods:
58 
59 // Constructor
61 Trk::TrkObserverTool::TrkObserverTool(const std::string& type, const std::string& name, const IInterface* parent)
63  declareInterface< ITrkObserverTool >(this);
64  declareProperty("ObsTrackCollection", m_savedTracksWriteKey);
65  declareProperty("ObsTrackCollectionMap", m_savedTracksMapWriteKey);
66 }
67 
68 // Destructor
71 
72 // Athena algtool's Hooks
75  ATH_MSG_INFO("Initializing TrkObserverTool with name: " << name());
76  ATH_MSG_INFO("\tm_savedTracksWriteKey: " << m_savedTracksWriteKey.key());
77  ATH_MSG_INFO("\tm_savedTracksMapWriteKey: " << m_savedTracksMapWriteKey.key());
79  ATH_CHECK(m_savedTracksWriteKey.initialize(!m_savedTracksWriteKey.key().empty()));
80  ATH_CHECK(m_savedTracksMapWriteKey.initialize(!m_savedTracksMapWriteKey.key().empty()));
81  ATH_MSG_INFO("Initialized TrkObserverTool");
82  return StatusCode::SUCCESS;
83 }
84 
86  ATH_MSG_INFO("Finalizing " << name() << "...");
87  return StatusCode::SUCCESS;
88 }
89 
91 // Const methods:
94  ATH_MSG_DEBUG("Starting new event");
95  if (ent->m_observedTrkMap) {
96  ent->m_observedTrkMap->clear();
97  delete ent->m_observedTrkMap;
98  }
100 }
101 
103 
104  ATH_MSG_DEBUG("updateTrackMap: track "<<uid);
105  // get event context and map from cache
106  const EventContext& ctx{Gaudi::Hive::currentContext()};
107  std::lock_guard<std::mutex> lock{m_mutex};
108  ObservedTrackMap* trk_map = getTrackMap(ctx);
109  // find track and update score
110  if ( trk_map->find(uid) == trk_map->end() ) {
111  // not found
112  ATH_MSG_WARNING("updateTrackMap: track << " << uid << " not found in observedTrkMap");
113  }
114  else {
115  // found
116  std::get<xAOD::ObserverToolIndex::score>(trk_map->at(uid)) = score;
117  std::get<xAOD::ObserverToolIndex::rejectStep>(trk_map->at(uid)) = rejectStep;
118  std::get<xAOD::ObserverToolIndex::rejectReason>(trk_map->at(uid)) = rejectReason;
119  // Keep track of cumulative rejection steps/reasons
120  std::get<xAOD::ObserverToolIndex::rejectStep_full>(trk_map->at(uid)).push_back(rejectStep);
121  std::get<xAOD::ObserverToolIndex::rejectReason_full>(trk_map->at(uid)).push_back(rejectReason);
122  ATH_MSG_DEBUG("updateTrackMap: track "<<uid<<" with score, rejectStep, rejectReason: "<<score<<", "<<rejectStep<<", "<<rejectReason);
123  }
124 }
125 
126 void Trk::TrkObserverTool::updateScore(int uid, double score) const {
127 
128  ATH_MSG_DEBUG("updateScore: track "<<uid);
129  // get event context and map from cache
130  const EventContext& ctx{Gaudi::Hive::currentContext()};
131  std::lock_guard<std::mutex> lock{m_mutex};
132  ObservedTrackMap* trk_map = getTrackMap(ctx);
133  // find track and update score
134  if ( trk_map->find(uid) == trk_map->end() ) {
135  // not found
136  ATH_MSG_WARNING("updateScore: track " << uid << " not found in observedTrkMap");
137  }
138  else {
139  // found
140  std::get<xAOD::ObserverToolIndex::score>(trk_map->at(uid)) = score;
141  ATH_MSG_DEBUG("updateScore: track "<<uid<<" with score "<<score);
142  }
143 }
144 
146 
147  ATH_MSG_DEBUG("rejectTrack: track "<<uid);
148  // get event context and map from cache
149  const EventContext& ctx{Gaudi::Hive::currentContext()};
150  std::lock_guard<std::mutex> lock{m_mutex};
151  ObservedTrackMap* trk_map = getTrackMap(ctx);
152  // find track and update rejection location
153  if ( trk_map->find(uid) == trk_map->end() ) {
154  // not found
155  ATH_MSG_WARNING("rejectTrack: track "<<uid<<" not found in observedTrkMap");
156  }
157  else {
158  // found
159  std::get<xAOD::ObserverToolIndex::rejectStep>(trk_map->at(uid)) = rejectStep;
160  std::get<xAOD::ObserverToolIndex::rejectReason>(trk_map->at(uid)) = rejectReason;
161  // Keep track of cumulative rejection steps/reasons
162  std::get<xAOD::ObserverToolIndex::rejectStep_full>(trk_map->at(uid)).push_back(rejectStep);
163  std::get<xAOD::ObserverToolIndex::rejectReason_full>(trk_map->at(uid)).push_back(rejectReason);
164  ATH_MSG_DEBUG("rejectTrack: track "<<uid<<" with rejection in "<<dumpRejection(rejectStep, rejectReason));
165  }
166 }
167 
169 
170  ATH_MSG_DEBUG("addInputTrack: track "<<uid);
171  // test to see if we have a new event
172  const EventContext& ctx{Gaudi::Hive::currentContext()};
173  std::lock_guard<std::mutex> lock{m_mutex};
174  CacheEntry* ent{m_cache.get(ctx)};
175  if (ent->m_evt!=ctx.evt()) {
176  // New event in this slot
177  newEvent(ent);
178  ent->m_evt = ctx.evt();
179  }
180  // add input track to cache map
181  std::unique_ptr<Trk::Track> copiedTrack = std::make_unique<Trk::Track>(track);
182  std::vector<xAOD::RejectionStep> v_rejectStep = {xAOD::RejectionStep::solveTracks};
183  std::vector<xAOD::RejectionReason> v_rejectReason = {xAOD::RejectionReason::acceptedTrack};
184  ent->m_observedTrkMap->insert( std::make_pair(uid, std::make_tuple(copiedTrack.release(), // Id, track
185  -1, // score
186  xAOD::RejectionStep::solveTracks, // rejection step
187  xAOD::RejectionReason::acceptedTrack, // rejection reason
188  0, // unique parentId
189  // holes/shared/split hits information (-2 means not filled yet)
190  -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2.0f, -2.0f, -2,
191  v_rejectStep, v_rejectReason)));
192 }
193 
194 void Trk::TrkObserverTool::addSubTrack(int track_uid, int parent_uid, const Trk::Track& track) const {
195 
196  ATH_MSG_DEBUG("addSubTrack: subtrack "<<track_uid);
197  // get event context and map from cache
198  const EventContext& ctx{Gaudi::Hive::currentContext()};
199  std::lock_guard<std::mutex> lock{m_mutex};
200  ObservedTrackMap* trk_map = getTrackMap(ctx);
201 
202  // deep copy of the track (because some subtracks get deleted), information has to be available later
203  std::unique_ptr<Trk::Track> copiedTrack = std::make_unique<Trk::Track>(track);
204  // get score and rejection step from parent element
205  double score = -1;
207  if ( trk_map->find(parent_uid) == trk_map->end() ) {
208  // not found
209  ATH_MSG_WARNING("addSubTrack: parent " << parent_uid << " not found in observedTrkMap");
210  }
211  else {
212  // found
213  score = std::get<xAOD::ObserverToolIndex::score>(trk_map->at(parent_uid));
214  rejectStep = std::get<xAOD::ObserverToolIndex::rejectStep>(trk_map->at(parent_uid));
215  ATH_MSG_DEBUG("addSubTrack: track "<<track_uid<<" with parent "<<parent_uid<<", score "<<score);
216  }
217  // add subtrack to cache map
218  std::vector<xAOD::RejectionStep> v_rejectStep = {rejectStep};
219  std::vector<xAOD::RejectionReason> v_rejectReason = {xAOD::RejectionReason::acceptedTrack};
220  trk_map->insert( std::make_pair(track_uid, std::make_tuple(copiedTrack.release(), // Id, track
221  score, // score
222  rejectStep, // rejection step
223  xAOD::RejectionReason::acceptedTrack, // rejection reason
224  parent_uid, // unique parentId
225  // holes/shared/split hits information (-2 means not filled yet)
226  -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2.0f, -2.0f, -2,
227  v_rejectStep, v_rejectReason)));
228 }
229 
230 ObservedTrackMap* Trk::TrkObserverTool::getTrackMap(const EventContext& ctx) const {
231 
232  ATH_MSG_DEBUG("Get track map from cache");
233  // get cache
234  CacheEntry* ent{m_cache.get(ctx)};
235  // sanity check
236  if (ent->m_evt!=ctx.evt()) {
237  ATH_MSG_ERROR("Different event context in getTrackMap!!");
238  }
239  return ent->m_observedTrkMap;
240 }
241 
242 int Trk::TrkObserverTool::saveTracksToStore(const EventContext& ctx, const ObservedTrackMap* trk_map) const {
243 
244  std::lock_guard<std::mutex> lock{m_mutex};
245  // Save tracks and map to store
246  ATH_MSG_INFO ("saveTracksToStore: Recording empty observed track containers to event store");
247  ATH_MSG_DEBUG("\tm_savedTracksWriteKey: "<<m_savedTracksWriteKey.key());
248  ATH_MSG_DEBUG("\tm_savedTracksMapWriteKey: "<<m_savedTracksMapWriteKey.key());
249 
250  SG::WriteHandle<TrackCollection> wh_tracks{m_savedTracksWriteKey, ctx};
251  SG::WriteHandle<ObservedTrackMap> wh_tracksMap{m_savedTracksMapWriteKey, ctx};
252 
253  // Tracks write handle
254  StatusCode sc = wh_tracks.record(std::make_unique<TrackCollection>());
255  if (sc.isFailure()) {
256  ATH_MSG_ERROR("saveTracksToStore: Could not record input tracks: "<<m_savedTracksWriteKey.key());
257  }
258  else {
259  ATH_MSG_INFO("saveTracksToStore: Recorded empty container for input tracks to: "<<m_savedTracksWriteKey.key());
260  }
261  if (!wh_tracks.isValid()) {
262  ATH_MSG_DEBUG ("saveTracksToStore: Invalid key: "<<m_savedTracksWriteKey.key());
263  }
264  else {
265  ATH_MSG_DEBUG ("saveTracksToStore: Valid key: "<<m_savedTracksWriteKey.key());
266  }
267 
268  // Tracks map write handle
269  sc = wh_tracksMap.record(std::make_unique<ObservedTrackMap>());
270  if (sc.isFailure()) {
271  ATH_MSG_ERROR("saveTracksToStore: Could not record tracks map: "<<m_savedTracksMapWriteKey.key());
272  }
273  else {
274  ATH_MSG_INFO("saveTracksToStore: Recorded empty container for tracks map to: "<<m_savedTracksMapWriteKey.key());
275  }
276  if (!wh_tracksMap.isValid()) {
277  ATH_MSG_DEBUG ("saveTracksToStore: Invalid key: "<<m_savedTracksMapWriteKey.key());
278  }
279  else {
280  ATH_MSG_DEBUG ("saveTracksToStore: Valid key: "<<m_savedTracksMapWriteKey.key());
281  }
282  if (!trk_map){
283  return 0;
284  }
285  else {
286  ATH_MSG_INFO ("saveTracksToStore: Recording "<<trk_map->size() << " observed track candidates to event store");
287  }
288  for (const auto& itrMap : *trk_map) {
289  ATH_MSG_DEBUG("saveTracksToStore: Writing track with id "<<itrMap.first<<", rejection step "<<std::get<xAOD::ObserverToolIndex::rejectStep>(itrMap.second)<<", rejection reason "<<std::get<xAOD::ObserverToolIndex::rejectReason>(itrMap.second));
290  wh_tracks->push_back(std::get<xAOD::ObserverToolIndex::track>(itrMap.second));
291  wh_tracksMap->insert(std::make_pair(itrMap.first, itrMap.second));
292  }
293 
294  ATH_MSG_DEBUG("saveTracksToStore: Pushed "<<wh_tracks->size()<<" observed tracks to store");
295  ATH_MSG_DEBUG("saveTracksToStore: Pushed "<<wh_tracksMap->size()<<" pairs to track map in store");
296  // Keep track of "good" tracks as a sanity check
297  int nFinalTracks = getNFinalTracks(trk_map);
298  ATH_MSG_DEBUG ("saveTracksToStore: Number of RejectionReason = acceptedTrack (should equal final tracks): " << nFinalTracks);
299  return nFinalTracks;
300 }
301 
305  int numSCTHits, int numUnused, int numTRT_Unused, int numSCT_Unused, int numPseudo, float averageSplit1, float averageSplit2, int numWeightedShared) const {
306 
307  ATH_MSG_DEBUG("updateHolesSharedHits: track "<<uid);
308  // get event context and map from cache
309  const EventContext& ctx{Gaudi::Hive::currentContext()};
310  std::lock_guard<std::mutex> lock{m_mutex};
311  ObservedTrackMap* trk_map = getTrackMap(ctx);
312 
313  // find track and update rejection location
314  if ( trk_map->find(uid) == trk_map->end() ) {
315  // not found
316  ATH_MSG_WARNING("updateHolesSharedHits: track "<<uid<<" not found in observedTrkMap");
317  }
318  else {
319  // found
320  std::get<xAOD::ObserverToolIndex::numPixelHoles>(trk_map->at(uid)) = numPixelHoles;
321  std::get<xAOD::ObserverToolIndex::numSCTHoles>(trk_map->at(uid)) = numSCTHoles;
322  std::get<xAOD::ObserverToolIndex::numSplitSharedPixel>(trk_map->at(uid)) = numSplitSharedPixel; // Number of Pixel clusters comptaible with being split that are also shared
323  std::get<xAOD::ObserverToolIndex::numSplitSharedSCT>(trk_map->at(uid)) = numSplitSharedSCT; // Number of SCT clusters comptaible with being split that are also shared
324  std::get<xAOD::ObserverToolIndex::numSharedOrSplit>(trk_map->at(uid)) = numSharedOrSplit; // Number of split + shared clusters
325  std::get<xAOD::ObserverToolIndex::numSharedOrSplitPixels>(trk_map->at(uid)) = numSharedOrSplitPixels; // Number of pixel clusters that are either split or shared
326  std::get<xAOD::ObserverToolIndex::numShared>(trk_map->at(uid)) = numShared; // Number of shared hits on track
327  std::get<xAOD::ObserverToolIndex::isPatternTrack>(trk_map->at(uid)) = isPatternTrack; // Pattern Track or Fitted track
328  std::get<xAOD::ObserverToolIndex::totalSiHits>(trk_map->at(uid)) = totalSiHits; // totalSiHits
329  std::get<xAOD::ObserverToolIndex::inROI>(trk_map->at(uid)) = inROI;
330  std::get<xAOD::ObserverToolIndex::hasIBLHit>(trk_map->at(uid)) = hasIBLHit;
331  std::get<xAOD::ObserverToolIndex::hasSharedIBLHit>(trk_map->at(uid)) = hasSharedIBLHit;
332  std::get<xAOD::ObserverToolIndex::hasSharedPixel>(trk_map->at(uid)) = hasSharedPixel;
333  std::get<xAOD::ObserverToolIndex::firstPixIsShared>(trk_map->at(uid)) = firstPixIsShared;
334  std::get<xAOD::ObserverToolIndex::numPixelDeadSensor>(trk_map->at(uid)) = numPixelDeadSensor;
335  std::get<xAOD::ObserverToolIndex::numSCTDeadSensor>(trk_map->at(uid)) = numSCTDeadSensor;
336  std::get<xAOD::ObserverToolIndex::numPixelHits>(trk_map->at(uid)) = numPixelHits;
337  std::get<xAOD::ObserverToolIndex::numSCTHits>(trk_map->at(uid)) = numSCTHits;
338  std::get<xAOD::ObserverToolIndex::numUnused>(trk_map->at(uid)) = numUnused;
339  std::get<xAOD::ObserverToolIndex::numTRT_Unused>(trk_map->at(uid)) = numTRT_Unused;
340  std::get<xAOD::ObserverToolIndex::numSCT_Unused>(trk_map->at(uid)) = numSCT_Unused;
341  std::get<xAOD::ObserverToolIndex::numPseudo>(trk_map->at(uid)) = numPseudo;
342  std::get<xAOD::ObserverToolIndex::averageSplit1>(trk_map->at(uid)) = averageSplit1;
343  std::get<xAOD::ObserverToolIndex::averageSplit2>(trk_map->at(uid)) = averageSplit2;
344  std::get<xAOD::ObserverToolIndex::numWeightedShared>(trk_map->at(uid)) = numWeightedShared;
345  ATH_MSG_DEBUG("updateHolesSharedHits: track "<<uid<<" with totalSiHits "<<totalSiHits);
346  }
347 }
348 
350 
351  // prints out/dumps all entries in m_observedTrkMap
352 
353  std::lock_guard<std::mutex> lock{m_mutex};
354 
355  ATH_MSG_INFO ("Dump observedTrkMap (size = " << getNObservedTracks(trk_map) << ")");
356  for (const auto& itrMap : *trk_map) {
357  ATH_MSG_DEBUG("Id: " << itrMap.first);
358  ATH_MSG_DEBUG("\tscore: " << std::get<xAOD::ObserverToolIndex::score>(itrMap.second));
359  ATH_MSG_DEBUG("\trejectStep: " << std::get<xAOD::ObserverToolIndex::rejectStep>(itrMap.second));
360  ATH_MSG_DEBUG("\trejectReason: " << std::get<xAOD::ObserverToolIndex::rejectReason>(itrMap.second));
361  ATH_MSG_DEBUG("\tparentId: " << std::get<xAOD::ObserverToolIndex::parentId>(itrMap.second));
362  ATH_MSG_DEBUG("\tnumPixelHoles: " << std::get<xAOD::ObserverToolIndex::numPixelHoles>(itrMap.second));
363  ATH_MSG_DEBUG("\tnumSCTHoles: " << std::get<xAOD::ObserverToolIndex::numSCTHoles>(itrMap.second));
364  ATH_MSG_DEBUG("\tnumSplitSharedPixel: " << std::get<xAOD::ObserverToolIndex::numSplitSharedPixel>(itrMap.second));
365  ATH_MSG_DEBUG("\tnumSplitSharedSCT: " << std::get<xAOD::ObserverToolIndex::numSplitSharedSCT>(itrMap.second));
366  ATH_MSG_DEBUG("\tnumSharedOrSplit: " << std::get<xAOD::ObserverToolIndex::numSharedOrSplit>(itrMap.second));
367  ATH_MSG_DEBUG("\tnumSharedOrSplitPixels: " << std::get<xAOD::ObserverToolIndex::numSharedOrSplitPixels>(itrMap.second));
368  ATH_MSG_DEBUG("\tnumShared: " << std::get<xAOD::ObserverToolIndex::numShared>(itrMap.second));
369  ATH_MSG_DEBUG("\tisPatternTrack: " << std::get<xAOD::ObserverToolIndex::isPatternTrack>(itrMap.second));
370  ATH_MSG_DEBUG("\ttotalSiHits: " << std::get<xAOD::ObserverToolIndex::totalSiHits>(itrMap.second));
371  ATH_MSG_DEBUG("\tinROI: " << std::get<xAOD::ObserverToolIndex::inROI>(itrMap.second));
372  ATH_MSG_DEBUG("\thasIBLHit: " << std::get<xAOD::ObserverToolIndex::hasIBLHit>(itrMap.second));
373  ATH_MSG_DEBUG("\thasSharedIBLHit: " << std::get<xAOD::ObserverToolIndex::hasSharedIBLHit>(itrMap.second));
374  ATH_MSG_DEBUG("\thasSharedPixel: " << std::get<xAOD::ObserverToolIndex::hasSharedPixel>(itrMap.second));
375  ATH_MSG_DEBUG("\tfirstPixIsShared: " << std::get<xAOD::ObserverToolIndex::firstPixIsShared>(itrMap.second));
376  ATH_MSG_DEBUG("\tnumPixelDeadSensor: " << std::get<xAOD::ObserverToolIndex::numPixelDeadSensor>(itrMap.second));
377  ATH_MSG_DEBUG("\tnumSCTDeadSensor: " << std::get<xAOD::ObserverToolIndex::numSCTDeadSensor>(itrMap.second));
378  ATH_MSG_DEBUG("\tnumPixelHits: " << std::get<xAOD::ObserverToolIndex::numPixelHits>(itrMap.second));
379  ATH_MSG_DEBUG("\tnumSCTHits: " << std::get<xAOD::ObserverToolIndex::numSCTHits>(itrMap.second));
380  ATH_MSG_DEBUG("\tnumUnused: " << std::get<xAOD::ObserverToolIndex::numUnused>(itrMap.second));
381  ATH_MSG_DEBUG("\tnumTRT_Unused: " << std::get<xAOD::ObserverToolIndex::numTRT_Unused>(itrMap.second));
382  ATH_MSG_DEBUG("\tnumSCT_Unused: " << std::get<xAOD::ObserverToolIndex::numSCT_Unused>(itrMap.second));
383  ATH_MSG_DEBUG("\tnumPseudo: " << std::get<xAOD::ObserverToolIndex::numPseudo>(itrMap.second));
384  ATH_MSG_DEBUG("\taverageSplit1: " << std::get<xAOD::ObserverToolIndex::averageSplit1>(itrMap.second));
385  ATH_MSG_DEBUG("\taverageSplit2: " << std::get<xAOD::ObserverToolIndex::averageSplit2>(itrMap.second));
386  ATH_MSG_DEBUG("\tnumWeightedShared: " << std::get<xAOD::ObserverToolIndex::numWeightedShared>(itrMap.second));
387  }
388  ATH_MSG_DEBUG("Number of RejectionReason = acceptedTrack (should equal final tracks): " << getNFinalTracks(trk_map));
389 }
390 
392  // Generate rejection description
393  std::string rejection_step = "";
394  std::string rejection_reason = "";
395  std::string rejection_description = "";
396  const auto istep = m_rejectStep_descriptions.find(rejectStep);
397  if ( istep == m_rejectStep_descriptions.end() ) {
398  // not found
399  rejection_step = "REJECTION STEP DESCRIPTION NOT FOUND: " + std::to_string(rejectStep);
400  }
401  else {
402  // found
403  rejection_step = istep->second;
404  }
405  const auto ireason = m_rejectReason_descriptions.find(rejectReason);
406  if ( ireason == m_rejectReason_descriptions.end() ) {
407  // not found
408  rejection_reason = "REJECTION REASON DESCRIPTION NOT FOUND: " + std::to_string(rejectReason);
409  }
410  else {
411  // found
412  rejection_reason = ireason->second;
413  }
414  rejection_description = rejection_step + " (" + rejection_reason + ")";
415  return rejection_description;
416 }
417 
419  // counts the tracks which did not get rejected (this number should equal finalTracks)
420  int nFinalTracks = 0;
421  for (const auto& itrMap : *trk_map) {
422  if (std::get<xAOD::ObserverToolIndex::rejectReason>(itrMap.second) == xAOD::RejectionReason::acceptedTrack) nFinalTracks++;
423  }
424  return nFinalTracks;
425 }
426 
428  // check the number of tracks in the observer tool map
429  return trk_map->size();
430 }
431 
432 const std::map<xAOD::RejectionStep, std::string> Trk::TrkObserverTool::m_rejectStep_descriptions = {
433  {xAOD::RejectionStep::addNewTracks, "DenseEnvironmentsAmbiguityScoreProcessorTool::addNewTracks"},
434  {xAOD::RejectionStep::refitTrack, "AmbiguityProcessorBase::refitTrack"},
435  {xAOD::RejectionStep::addTrack, "AmbiguityProcessorBase::addTrack"},
436  {xAOD::RejectionStep::decideWhichHitsToKeep, "InDetDenseEnvAmbiTrackSelectionTool::decideWhichHitsToKeep"},
437  {xAOD::RejectionStep::getCleanedOutTrack, "InDetDenseEnvAmbiTrackSelectionTool::getCleanedOutTrack"}
438 };
439 
440 const std::map<xAOD::RejectionReason, std::string> Trk::TrkObserverTool::m_rejectReason_descriptions = {
441  {xAOD::RejectionReason::acceptedTrack, "not actually a rejection; accepted track"},
442  // Reason for rejection within DenseEnvironmentsAmbiguityProcessorTool::solveTracks
443  {xAOD::RejectionReason::stillBeingProcessed, "not actually a rejection; track still being processed"},
444  // Reason for rejection within DenseEnvironmentsAmbiguityScoreProcessorTool::addNewTracks
445  {xAOD::RejectionReason::trackScoreZero, "track score is zero"},
446  {xAOD::RejectionReason::duplicateTrack, "duplicate track"},
447  // Reason for rejection within AmbiguityProcessorBase::refitTrack
448  {xAOD::RejectionReason::subtrackCreated, "not actually a rejection; refit successful, new subtrack created"},
449  {xAOD::RejectionReason::refitFailed, "refit failed"},
450  // Reason for rejection within AmbiguityProcessorBase::addTrack
451  {xAOD::RejectionReason::bremRefitFailed, "brem refit failed"},
452  {xAOD::RejectionReason::bremRefitSubtrackCreated, "not actually a rejection; brem refit successful, new subtrack created"},
453  {xAOD::RejectionReason::bremRefitTrackScoreZero, "brem refit still gave track score zero"},
454  {xAOD::RejectionReason::refitTrackScoreZero, "refit track score 0"},
455  // Reason for rejection within decideWhichHitsToKeep
456  {xAOD::RejectionReason::TSOSRejectedHit, "TSOS of type RejectedHit"},
457  {xAOD::RejectionReason::TSOSOutlierShared, "TSOS of type Outlier and shared"},
458  {xAOD::RejectionReason::pixelSplitButTooManyShared2Ptc, "pixel split but shared between too many tracks (2 particle cluster)"},
459  {xAOD::RejectionReason::pixelSplitButTooManyShared3Ptc, "pixel split but shared between too many tracks (3+ particle cluster)"},
460  {xAOD::RejectionReason::tooManySharedRecoverable, "too many shared hits (recoverable shared hits)"},
461  {xAOD::RejectionReason::tooManySharedNonRecoverable, "too many shared hits (all other non-recoverable shared hits)"},
462  {xAOD::RejectionReason::sharedSCT, "shared SCT hits when we don't really have enough to share"},
463  {xAOD::RejectionReason::sharedHitsBadChi2, "shared hits cause a bad chi2 track"},
464  {xAOD::RejectionReason::sharedHitsNotEnoughUniqueHits, "shared hits does not leave enough unique hits on accepted track"},
465  {xAOD::RejectionReason::firstHitSharedAndPixIBL, "first hit is shared and either IBL or pixel"},
466  {xAOD::RejectionReason::firstHitSharedAndExtraShared, "track with first hit shared had additional shared hit"},
467  {xAOD::RejectionReason::sharedHitsNotEnoughUniqueSiHits, "shared hits does not leave enough Si hits on accepted track"},
468  {xAOD::RejectionReason::sharedIBLSharedWithNoIBLTrack, "shared IBL hit is shared with accepted track that does not have an IBL hit"},
469  {xAOD::RejectionReason::sharedPixelSharedWithDifferentIBLTrack, "shared pixel hit is shared with accepted track that has different IBL hit content"},
470  {xAOD::RejectionReason::tooManySharedAfterIncreasingShared, "too many shared hits after increasing shared hits"},
471  // Reason for rejection within getCleanedOutTrack
472  {xAOD::RejectionReason::notEnoughSiHits, "not enough Si hits"},
473  {xAOD::RejectionReason::notEnoughTRTHits, "not enough TRT hits"},
474  {xAOD::RejectionReason::notEnoughUniqueSiHits, "not enough unique Si hits"},
475  {xAOD::RejectionReason::tooFewHits, "too few hits, reject track with shared hits"},
476  {xAOD::RejectionReason::failedSubtrackCreation, "failed to create subtrack"},
477  {xAOD::RejectionReason::subtrackCreatedWithRecoveredShared, "created subtrack with recovered shared hits"},
479 };
xAOD::numSharedOrSplit
@ numSharedOrSplit
Definition: TrackingPrimitives.h:521
xAOD::hasIBLHit
@ hasIBLHit
Definition: TrackingPrimitives.h:527
xAOD::numWeightedShared
@ numWeightedShared
Definition: TrackingPrimitives.h:541
xAOD::numUnused
@ numUnused
Definition: TrackingPrimitives.h:535
Trk::TrkObserverTool::m_savedTracksMapWriteKey
SG::WriteHandleKey< ObservedTrackMap > m_savedTracksMapWriteKey
Definition: TrkObserverTool.h:63
xAOD::acceptedTrack
@ acceptedTrack
Definition: TrackingPrimitives.h:472
xAOD::subtrackCreatedWithRecoveredShared
@ subtrackCreatedWithRecoveredShared
Definition: TrackingPrimitives.h:508
Trk::TrkObserverTool::updateHolesSharedHits
void updateHolesSharedHits(int uid, int numPixelHoles, int numSCTHoles, int numSplitSharedPixel, int numSplitSharedSCT, int numSharedOrSplit, int numSharedOrSplitPixels, int numShared, int isPatternTrack, int totalSiHits, int inROI, int hasIBLHit, int hasSharedIBLHit, int hasSharedPixel, int firstPixIsShared, int numPixelDeadSensor, int numSCTDeadSensor, int numPixelHits, int numSCTHits, int numUnused, int numTRT_Unused, int numSCT_Unused, int numPseudo, float averageSplit1, float averageSplit2, int numWeightedShared) const
Definition: TrkObserverTool.cxx:302
xAOD::isPatternTrack
@ isPatternTrack
Definition: TrackingPrimitives.h:524
xAOD::averageSplit2
@ averageSplit2
Definition: TrackingPrimitives.h:540
xAOD::refitTrackScoreZero
@ refitTrackScoreZero
Definition: TrackingPrimitives.h:485
xAOD::addNewTracks
@ addNewTracks
Definition: TrackingPrimitives.h:461
xAOD::hasSharedIBLHit
@ hasSharedIBLHit
Definition: TrackingPrimitives.h:528
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::TSOSOutlierShared
@ TSOSOutlierShared
Definition: TrackingPrimitives.h:488
xAOD::sharedPixelSharedWithDifferentIBLTrack
@ sharedPixelSharedWithDifferentIBLTrack
Definition: TrackingPrimitives.h:500
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
xAOD::tooManySharedNonRecoverable
@ tooManySharedNonRecoverable
Definition: TrackingPrimitives.h:492
xAOD::trackScoreZero
@ trackScoreZero
Definition: TrackingPrimitives.h:476
xAOD::bremRefitTrackScoreZero
@ bremRefitTrackScoreZero
Definition: TrackingPrimitives.h:484
Trk::TrkObserverTool::finalize
virtual StatusCode finalize()
Definition: TrkObserverTool.cxx:85
Trk::TrkObserverTool::addInputTrack
void addInputTrack(int uid, const Trk::Track &track) const
Definition: TrkObserverTool.cxx:168
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::TrkObserverTool::rejectTrack
void rejectTrack(int uid, xAOD::RejectionStep rejectStep, xAOD::RejectionReason rejectReason) const
Definition: TrkObserverTool.cxx:145
initialize
void initialize()
Definition: run_EoverP.cxx:894
xAOD::numSplitSharedPixel
@ numSplitSharedPixel
Definition: TrackingPrimitives.h:519
xAOD::tooFewHits
@ tooFewHits
Definition: TrackingPrimitives.h:506
xAOD::numPseudo
@ numPseudo
Definition: TrackingPrimitives.h:538
xAOD::sharedHitsNotEnoughUniqueHits
@ sharedHitsNotEnoughUniqueHits
Definition: TrackingPrimitives.h:495
xAOD::firstPixIsShared
@ firstPixIsShared
Definition: TrackingPrimitives.h:530
xAOD::pixelSplitButTooManyShared3Ptc
@ pixelSplitButTooManyShared3Ptc
Definition: TrackingPrimitives.h:490
xAOD::tooManySharedRecoverable
@ tooManySharedRecoverable
Definition: TrackingPrimitives.h:491
xAOD::notEnoughUniqueSiHits
@ notEnoughUniqueSiHits
Definition: TrackingPrimitives.h:505
Trk::TrkObserverTool::m_rejectReason_descriptions
static const std::map< xAOD::RejectionReason, std::string > m_rejectReason_descriptions
Definition: TrkObserverTool.h:79
xAOD::hasSharedPixel
@ hasSharedPixel
Definition: TrackingPrimitives.h:529
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trk::TrkObserverTool::updateTrackMap
void updateTrackMap(int uid, double score, xAOD::RejectionStep rejectStep, xAOD::RejectionReason rejectReason) const
Definition: TrkObserverTool.cxx:102
Trk::TrkObserverTool::dumpRejection
static std::string dumpRejection(xAOD::RejectionStep rejectStep, xAOD::RejectionReason rejectReason)
Definition: TrkObserverTool.cxx:391
ObservedTrackMap
std::map< int, std::tuple< Trk::Track *, double, xAOD::RejectionStep, xAOD::RejectionReason, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, float, float, int, std::vector< xAOD::RejectionStep >, std::vector< xAOD::RejectionReason > > > ObservedTrackMap
Definition: ObservedTrackMap.h:50
xAOD::notEnoughTRTHits
@ notEnoughTRTHits
Definition: TrackingPrimitives.h:504
xAOD::numSCTDeadSensor
@ numSCTDeadSensor
Definition: TrackingPrimitives.h:532
xAOD::firstHitSharedAndExtraShared
@ firstHitSharedAndExtraShared
Definition: TrackingPrimitives.h:497
xAOD::addTrack
@ addTrack
Definition: TrackingPrimitives.h:465
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::pixelSplitButTooManyShared2Ptc
@ pixelSplitButTooManyShared2Ptc
Definition: TrackingPrimitives.h:489
xAOD::totalSiHits
@ totalSiHits
Definition: TrackingPrimitives.h:525
xAOD::tooManySharedAfterIncreasingShared
@ tooManySharedAfterIncreasingShared
Definition: TrackingPrimitives.h:501
xAOD::numPixelHits
@ numPixelHits
Definition: TrackingPrimitives.h:533
Trk::TrkObserverTool::saveTracksToStore
int saveTracksToStore(const EventContext &ctx, const ObservedTrackMap *trk_map) const
Definition: TrkObserverTool.cxx:242
Trk::TrkObserverTool::initialize
virtual StatusCode initialize()
Definition: TrkObserverTool.cxx:74
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
xAOD::bremRefitFailed
@ bremRefitFailed
Definition: TrackingPrimitives.h:482
TrackCollection.h
Trk::TrkObserverTool::getTrackMap
ObservedTrackMap * getTrackMap(const EventContext &ctx) const
Definition: TrkObserverTool.cxx:230
xAOD::numSharedOrSplitPixels
@ numSharedOrSplitPixels
Definition: TrackingPrimitives.h:522
xAOD::numSCTHits
@ numSCTHits
Definition: TrackingPrimitives.h:534
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::rejectStep
@ rejectStep
Definition: TrackingPrimitives.h:514
xAOD::failedSubtrackCreation
@ failedSubtrackCreation
Definition: TrackingPrimitives.h:507
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::TrkObserverTool::CacheEntry
Definition: TrkObserverTool.h:66
xAOD::RejectionReason
RejectionReason
Definition: TrackingPrimitives.h:471
xAOD::stillBeingProcessed
@ stillBeingProcessed
Definition: TrackingPrimitives.h:474
xAOD::numSCT_Unused
@ numSCT_Unused
Definition: TrackingPrimitives.h:537
xAOD::refitFailed
@ refitFailed
Definition: TrackingPrimitives.h:480
Trk::TrkObserverTool::newEvent
void newEvent(CacheEntry *ent) const
Definition: TrkObserverTool.cxx:93
xAOD::bremRefitSubtrackCreated
@ bremRefitSubtrackCreated
Definition: TrackingPrimitives.h:483
xAOD::inROI
@ inROI
Definition: TrackingPrimitives.h:526
Trk::TrkObserverTool::getNFinalTracks
static int getNFinalTracks(const ObservedTrackMap *trk_map)
Definition: TrkObserverTool.cxx:418
Trk::TrkObserverTool::addSubTrack
void addSubTrack(int track_uid, int parent_uid, const Trk::Track &track) const
Definition: TrkObserverTool.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
xAOD::decideWhichHitsToKeep
@ decideWhichHitsToKeep
Definition: TrackingPrimitives.h:467
xAOD::sharedHitsNotEnoughUniqueSiHits
@ sharedHitsNotEnoughUniqueSiHits
Definition: TrackingPrimitives.h:498
xAOD::firstHitSharedAndPixIBL
@ firstHitSharedAndPixIBL
Definition: TrackingPrimitives.h:496
xAOD::averageSplit1
@ averageSplit1
Definition: TrackingPrimitives.h:539
xAOD::score
@ score
Definition: TrackingPrimitives.h:513
Trk::TrkObserverTool::CacheEntry::m_observedTrkMap
ObservedTrackMap * m_observedTrkMap
Definition: TrkObserverTool.h:69
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
Trk::TrkObserverTool::~TrkObserverTool
virtual ~TrkObserverTool()
xAOD::duplicateTrack
@ duplicateTrack
Definition: TrackingPrimitives.h:477
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Trk::TrkObserverTool::getNObservedTracks
static int getNObservedTracks(const ObservedTrackMap *trk_map)
Definition: TrkObserverTool.cxx:427
xAOD::notEnoughSiHits
@ notEnoughSiHits
Definition: TrackingPrimitives.h:503
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::rejectReason
@ rejectReason
Definition: TrackingPrimitives.h:515
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrkObserverTool.h
Trk::TrkObserverTool::dumpTrackMap
void dumpTrackMap(const ObservedTrackMap *trk_map) const
Definition: TrkObserverTool.cxx:349
xAOD::numPixelHoles
@ numPixelHoles
Definition: TrackingPrimitives.h:517
xAOD::numTRT_Unused
@ numTRT_Unused
Definition: TrackingPrimitives.h:536
xAOD::numSCTHoles
@ numSCTHoles
Definition: TrackingPrimitives.h:518
xAOD::numSplitSharedSCT
@ numSplitSharedSCT
Definition: TrackingPrimitives.h:520
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::sharedSCT
@ sharedSCT
Definition: TrackingPrimitives.h:493
xAOD::TSOSRejectedHit
@ TSOSRejectedHit
Definition: TrackingPrimitives.h:487
xAOD::getCleanedOutTrack
@ getCleanedOutTrack
Definition: TrackingPrimitives.h:469
AthAlgTool
Definition: AthAlgTool.h:26
xAOD::numShared
@ numShared
Definition: TrackingPrimitives.h:523
Trk::TrkObserverTool::TrkObserverTool
TrkObserverTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TrkObserverTool.cxx:61
xAOD::refitTrack
@ refitTrack
Definition: TrackingPrimitives.h:463
Trk::TrkObserverTool::m_savedTracksWriteKey
SG::WriteHandleKey< TrackCollection > m_savedTracksWriteKey
Definition: TrkObserverTool.h:62
xAOD::subtrackCreated
@ subtrackCreated
Definition: TrackingPrimitives.h:479
xAOD::RejectionStep
RejectionStep
Definition: TrackingPrimitives.h:457
xAOD::numPixelDeadSensor
@ numPixelDeadSensor
Definition: TrackingPrimitives.h:531
xAOD::sharedIBLSharedWithNoIBLTrack
@ sharedIBLSharedWithNoIBLTrack
Definition: TrackingPrimitives.h:499
Trk::TrkObserverTool::m_rejectStep_descriptions
static const std::map< xAOD::RejectionStep, std::string > m_rejectStep_descriptions
Definition: TrkObserverTool.h:78
xAOD::sharedHitsBadChi2
@ sharedHitsBadChi2
Definition: TrackingPrimitives.h:494
Trk::TrkObserverTool::updateScore
void updateScore(int uid, double score) const
Definition: TrkObserverTool.cxx:126
xAOD::solveTracks
@ solveTracks
Definition: TrackingPrimitives.h:459