52 #include "GaudiKernel/IToolSvc.h"
63 declareInterface< ITrkObserverTool >(
this);
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()));
82 return StatusCode::SUCCESS;
87 return StatusCode::SUCCESS;
106 const EventContext& ctx{Gaudi::Hive::currentContext()};
107 std::lock_guard<std::mutex> lock{m_mutex};
110 if ( trk_map->find(uid) == trk_map->end() ) {
112 ATH_MSG_WARNING(
"updateTrackMap: track << " << uid <<
" not found in observedTrkMap");
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;
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);
130 const EventContext& ctx{Gaudi::Hive::currentContext()};
131 std::lock_guard<std::mutex> lock{m_mutex};
134 if ( trk_map->find(uid) == trk_map->end() ) {
136 ATH_MSG_WARNING(
"updateScore: track " << uid <<
" not found in observedTrkMap");
140 std::get<xAOD::ObserverToolIndex::score>(trk_map->at(uid)) =
score;
149 const EventContext& ctx{Gaudi::Hive::currentContext()};
150 std::lock_guard<std::mutex> lock{m_mutex};
153 if ( trk_map->find(uid) == trk_map->end() ) {
155 ATH_MSG_WARNING(
"rejectTrack: track "<<uid<<
" not found in observedTrkMap");
159 std::get<xAOD::ObserverToolIndex::rejectStep>(trk_map->at(uid)) =
rejectStep;
160 std::get<xAOD::ObserverToolIndex::rejectReason>(trk_map->at(uid)) =
rejectReason;
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);
172 const EventContext& ctx{Gaudi::Hive::currentContext()};
173 std::lock_guard<std::mutex> lock{m_mutex};
175 if (ent->m_evt!=ctx.evt()) {
178 ent->m_evt = ctx.evt();
181 std::unique_ptr<Trk::Track> copiedTrack = std::make_unique<Trk::Track>(
track);
184 ent->m_observedTrkMap->insert( std::make_pair(uid, std::make_tuple(copiedTrack.release(),
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)));
198 const EventContext& ctx{Gaudi::Hive::currentContext()};
199 std::lock_guard<std::mutex> lock{m_mutex};
203 std::unique_ptr<Trk::Track> copiedTrack = std::make_unique<Trk::Track>(
track);
207 if ( trk_map->find(parent_uid) == trk_map->end() ) {
209 ATH_MSG_WARNING(
"addSubTrack: parent " << parent_uid <<
" not found in observedTrkMap");
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);
218 std::vector<xAOD::RejectionStep> v_rejectStep = {
rejectStep};
220 trk_map->insert( std::make_pair(track_uid, std::make_tuple(copiedTrack.release(),
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)));
236 if (ent->m_evt!=ctx.evt()) {
239 return ent->m_observedTrkMap;
244 std::lock_guard<std::mutex> lock{m_mutex};
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());
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());
259 ATH_MSG_INFO(
"saveTracksToStore: Recorded empty container for input tracks to: "<<m_savedTracksWriteKey.key());
261 if (!wh_tracks.isValid()) {
262 ATH_MSG_DEBUG (
"saveTracksToStore: Invalid key: "<<m_savedTracksWriteKey.key());
265 ATH_MSG_DEBUG (
"saveTracksToStore: Valid key: "<<m_savedTracksWriteKey.key());
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());
274 ATH_MSG_INFO(
"saveTracksToStore: Recorded empty container for tracks map to: "<<m_savedTracksMapWriteKey.key());
276 if (!wh_tracksMap.isValid()) {
277 ATH_MSG_DEBUG (
"saveTracksToStore: Invalid key: "<<m_savedTracksMapWriteKey.key());
280 ATH_MSG_DEBUG (
"saveTracksToStore: Valid key: "<<m_savedTracksMapWriteKey.key());
286 ATH_MSG_INFO (
"saveTracksToStore: Recording "<<trk_map->size() <<
" observed track candidates to event store");
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));
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");
297 int nFinalTracks = getNFinalTracks(trk_map);
298 ATH_MSG_DEBUG (
"saveTracksToStore: Number of RejectionReason = acceptedTrack (should equal final tracks): " << nFinalTracks);
309 const EventContext& ctx{Gaudi::Hive::currentContext()};
310 std::lock_guard<std::mutex> lock{m_mutex};
314 if ( trk_map->find(uid) == trk_map->end() ) {
316 ATH_MSG_WARNING(
"updateHolesSharedHits: track "<<uid<<
" not found in observedTrkMap");
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;
323 std::get<xAOD::ObserverToolIndex::numSplitSharedSCT>(trk_map->at(uid)) =
numSplitSharedSCT;
324 std::get<xAOD::ObserverToolIndex::numSharedOrSplit>(trk_map->at(uid)) =
numSharedOrSplit;
326 std::get<xAOD::ObserverToolIndex::numShared>(trk_map->at(uid)) =
numShared;
327 std::get<xAOD::ObserverToolIndex::isPatternTrack>(trk_map->at(uid)) =
isPatternTrack;
328 std::get<xAOD::ObserverToolIndex::totalSiHits>(trk_map->at(uid)) =
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;
353 std::lock_guard<std::mutex> lock{m_mutex};
355 ATH_MSG_INFO (
"Dump observedTrkMap (size = " << getNObservedTracks(trk_map) <<
")");
356 for (
const auto& itrMap : *trk_map) {
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));
388 ATH_MSG_DEBUG(
"Number of RejectionReason = acceptedTrack (should equal final tracks): " << getNFinalTracks(trk_map));
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() ) {
403 rejection_step = istep->second;
405 const auto ireason = m_rejectReason_descriptions.find(
rejectReason);
406 if ( ireason == m_rejectReason_descriptions.end() ) {
412 rejection_reason = ireason->second;
414 rejection_description = rejection_step +
" (" + rejection_reason +
")";
415 return rejection_description;
420 int nFinalTracks = 0;
421 for (
const auto& itrMap : *trk_map) {
429 return trk_map->size();