ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkAlgorithms
TrkTruthAlgs
src
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
9
#include "
TrkTruthAlgs/TrackTruthSimilaritySelector.h
"
10
#include "
TrkToolInterfaces/IDetailedTrackTruthSimilarity.h
"
11
12
TrackTruthSimilaritySelector::TrackTruthSimilaritySelector
(
const
std::string &name,ISvcLocator *pSvcLocator)
13
:
AthAlgorithm
(name,pSvcLocator)
14
{
15
}
16
17
// -----------------------------------------------------------------------------------------------------
18
StatusCode
TrackTruthSimilaritySelector::initialize
()
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
// -----------------------------------------------------------------------------------------------------
28
StatusCode
TrackTruthSimilaritySelector::finalize
() {
29
ATH_MSG_INFO
(
"TrackTruthSimilaritySelector finalized"
);
30
return
StatusCode::SUCCESS;
31
}
32
33
// -----------------------------------------------------------------------------------------------------
34
StatusCode
TrackTruthSimilaritySelector::execute
(
const
EventContext& ctx) {
35
36
ATH_MSG_DEBUG
(
"TrackTruthSimilaritySelector::execute()"
);
37
38
//----------------------------------------------------------------
39
// Retrieve the input
40
41
auto
detailedHandle =
SG::makeHandle
(
m_detailed
, ctx);
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
, ctx);
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
//================================================================
65
void
TrackTruthSimilaritySelector::fillOutput
(
TrackTruthCollection
*out,
66
const
DetailedTrackTruthCollection
*in)
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
//================================================================
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
IDetailedTrackTruthSimilarity.h
TrackTruthSimilaritySelector.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
DetailedTrackTruthCollection
Definition
DetailedTrackTruthCollection.h:20
HepMcParticleLink
a link optimized in size for a GenParticle in a McEventCollection
Definition
HepMcParticleLink.h:72
TrackTruthCollection
Definition
TrackTruthCollection.h:21
TrackTruthSimilaritySelector::finalize
virtual StatusCode finalize() override
Definition
TrackTruthSimilaritySelector.cxx:28
TrackTruthSimilaritySelector::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
TrackTruthSimilaritySelector.cxx:34
TrackTruthSimilaritySelector::fillOutput
void fillOutput(TrackTruthCollection *out, const DetailedTrackTruthCollection *in)
Definition
TrackTruthSimilaritySelector.cxx:65
TrackTruthSimilaritySelector::m_detailed
SG::ReadHandleKey< DetailedTrackTruthCollection > m_detailed
Definition
TrackTruthSimilaritySelector.h:27
TrackTruthSimilaritySelector::TrackTruthSimilaritySelector
TrackTruthSimilaritySelector(const std::string &name, ISvcLocator *pSvcLocator)
Definition
TrackTruthSimilaritySelector.cxx:12
TrackTruthSimilaritySelector::m_matchTool
ToolHandle< Trk::IDetailedTrackTruthSimilarity > m_matchTool
Definition
TrackTruthSimilaritySelector.h:34
TrackTruthSimilaritySelector::initialize
virtual StatusCode initialize() override
Definition
TrackTruthSimilaritySelector.cxx:18
TrackTruthSimilaritySelector::m_out
SG::WriteHandleKey< TrackTruthCollection > m_out
Definition
TrackTruthSimilaritySelector.h:30
TrackTruth
MC particle associated with a reco track + the quality of match.
Definition
TrackTruth.h:14
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition
ReadCondHandle.h:269
Generated on
for ATLAS Offline Software by
1.17.0