ATLAS Offline Software
TrackTruthSimilaritySelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <memory>
6 
7 
8 
11 
12 TrackTruthSimilaritySelector::TrackTruthSimilaritySelector(const std::string &name,ISvcLocator *pSvcLocator)
13  : AthAlgorithm(name,pSvcLocator)
14 {
15 }
16 
17 // -----------------------------------------------------------------------------------------------------
19 {
20  ATH_MSG_INFO ("TrackTruthSimilaritySelector::initialize(), output " << m_out.key());
21  ATH_CHECK( m_matchTool.retrieve() );
24  return StatusCode::SUCCESS;
25 }
26 
27 // -----------------------------------------------------------------------------------------------------
29  ATH_MSG_INFO ("TrackTruthSimilaritySelector finalized");
30  return StatusCode::SUCCESS;
31 }
32 
33 // -----------------------------------------------------------------------------------------------------
35 
36  ATH_MSG_DEBUG ("TrackTruthSimilaritySelector::execute()");
37 
38  //----------------------------------------------------------------
39  // Retrieve the input
40 
41  auto detailedHandle = SG::makeHandle( m_detailed );
42  if (!detailedHandle.isValid()){
43  ATH_MSG_ERROR ("DetailedTrackTruthCollection "<<m_detailed.key()<<" NOT found");
44  return StatusCode::FAILURE;
45  } else {
46  ATH_MSG_DEBUG ("Got DetailedTrackTruthCollection "<<m_detailed.key());
47  }
48 
49  //----------------------------------------------------------------
50  // Produce and store the output.
51 
52  auto outHandle = SG::makeHandle( m_out );
53  outHandle = std::make_unique<TrackTruthCollection>
54  (detailedHandle->trackCollectionLink());
55 
56  fillOutput(outHandle.ptr(), detailedHandle.cptr());
57 
58  ATH_MSG_DEBUG ("TrackTruthCollection '"<<m_out.key()<<"' is registered in StoreGate, size="<<outHandle->size());
59 
60 
61  return StatusCode::SUCCESS;
62 }
63 
64 //================================================================
67 {
68 
69  using Iter = DetailedTrackTruthCollection::const_iterator;
70  Iter itrackData=in->begin();
71  while(itrackData!=in->end()) {
72  std::pair<Iter,Iter> range = in->equal_range(itrackData->first);
73 
74  // We KNOW that the range is not empty - no need to check that.
75  Iter selected = range.first;
76  double bestProb = m_matchTool->trackTruthSimilarity(selected->second);
77  ATH_MSG_VERBOSE ("track="<<selected->first.index()<<" prob="<<bestProb
78  <<" link: "<<*(selected->second.trajectory().rbegin()));
79 
80  for(Iter imatch = ++range.first; imatch != range.second; ++imatch) {
81  double prob = m_matchTool->trackTruthSimilarity(imatch->second);
82  ATH_MSG_VERBOSE ("track="<<imatch->first.index()<<" prob="<<prob
83  <<" link: "<<*(imatch->second.trajectory().rbegin()));
84  if(prob>bestProb) {
85  bestProb = prob;
86  selected = imatch;
87  }
88  }
89 
90  // trajectory[0] is the LAST particle on the trajectory. The first is at trajectory.rbegin().
91  const HepMcParticleLink& particleLink = *(selected->second.trajectory().rbegin());
92 
93  ATH_MSG_VERBOSE ("Truth selected for track="<<selected->first.index()<<" prob="<<bestProb<<" link: "<<particleLink);
94  out->insert(std::make_pair(selected->first, TrackTruth(particleLink, bestProb, 0) ));
95  itrackData=range.second;
96  }
97 
98 }
99 
100 //================================================================
IDetailedTrackTruthSimilarity.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrackTruthSimilaritySelector::m_out
SG::WriteHandleKey< TrackTruthCollection > m_out
Definition: TrackTruthSimilaritySelector.h:30
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
TrackTruthSimilaritySelector::finalize
virtual StatusCode finalize() override
Definition: TrackTruthSimilaritySelector.cxx:28
TrackTruthSimilaritySelector.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
covarianceTool.prob
prob
Definition: covarianceTool.py:678
TrackTruthSimilaritySelector::m_detailed
SG::ReadHandleKey< DetailedTrackTruthCollection > m_detailed
Definition: TrackTruthSimilaritySelector.h:27
TrackTruthSimilaritySelector::execute
virtual StatusCode execute() override
Definition: TrackTruthSimilaritySelector.cxx:34
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrackTruthCollection
Definition: TrackTruthCollection.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackTruthSimilaritySelector::fillOutput
void fillOutput(TrackTruthCollection *out, const DetailedTrackTruthCollection *in)
Definition: TrackTruthSimilaritySelector.cxx:65
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
TrackTruthSimilaritySelector::m_matchTool
ToolHandle< Trk::IDetailedTrackTruthSimilarity > m_matchTool
Definition: TrackTruthSimilaritySelector.h:34
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
AthAlgorithm
Definition: AthAlgorithm.h:47
TrackTruthSimilaritySelector::TrackTruthSimilaritySelector
TrackTruthSimilaritySelector(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackTruthSimilaritySelector.cxx:12
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TrackTruth
MC particle associated with a reco track + the quality of match.
Definition: TrackTruth.h:14
DetailedTrackTruthCollection
Definition: DetailedTrackTruthCollection.h:20
TrackTruthSimilaritySelector::initialize
virtual StatusCode initialize() override
Definition: TrackTruthSimilaritySelector.cxx:18