ATLAS Offline Software
Loading...
Searching...
No Matches
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
12TrackTruthSimilaritySelector::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() );
22 ATH_CHECK( m_detailed.initialize() );
23 ATH_CHECK( m_out.initialize() );
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//================================================================
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual StatusCode finalize() override
virtual StatusCode execute() override
void fillOutput(TrackTruthCollection *out, const DetailedTrackTruthCollection *in)
SG::ReadHandleKey< DetailedTrackTruthCollection > m_detailed
TrackTruthSimilaritySelector(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< Trk::IDetailedTrackTruthSimilarity > m_matchTool
virtual StatusCode initialize() override
SG::WriteHandleKey< TrackTruthCollection > m_out
MC particle associated with a reco track + the quality of match.
Definition TrackTruth.h:14
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())