ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkAlgorithms
TrkTruthAlgs
src
TrackTruthSelector.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
TrkTruthAlgs/TrackTruthSelector.h
"
6
7
TrackTruthSelector::TrackTruthSelector
(
const
std::string &name,ISvcLocator *pSvcLocator) :
AthAlgorithm
(name,pSvcLocator) {}
8
9
// -----------------------------------------------------------------------------------------------------
10
StatusCode
TrackTruthSelector::initialize
()
11
{
12
m_subDetWeights
[
SubDetHitStatistics::Pixel
] =
m_weightPixel
;
13
m_subDetWeights
[
SubDetHitStatistics::SCT
] =
m_weightSCT
;
14
m_subDetWeights
[
SubDetHitStatistics::TRT
] =
m_weightTRT
;
15
m_subDetWeights
[
SubDetHitStatistics::MDT
] =
m_weightMDT
;
16
m_subDetWeights
[
SubDetHitStatistics::RPC
] =
m_weightRPC
;
17
m_subDetWeights
[
SubDetHitStatistics::TGC
] =
m_weightTGC
;
18
m_subDetWeights
[
SubDetHitStatistics::CSC
] =
m_weightCSC
;
19
m_subDetWeights
[
SubDetHitStatistics::STGC
] =
m_weightsTGC
;
20
m_subDetWeights
[
SubDetHitStatistics::MM
] =
m_weightMM
;
21
22
ATH_CHECK
(
m_detailedTrackTruthName
.initialize() );
23
ATH_CHECK
(
m_outputName
.initialize() );
24
return
StatusCode::SUCCESS;
25
}
26
27
// -----------------------------------------------------------------------------------------------------
28
StatusCode
TrackTruthSelector::execute
(
const
EventContext& ctx) {
29
ATH_MSG_DEBUG
(
"TrackTruthSelector::execute()"
);
30
31
//----------------------------------------------------------------
32
// Retrieve the input
33
const
DetailedTrackTruthCollection
*detailed =
nullptr
;
34
SG::ReadHandle<DetailedTrackTruthCollection>
rh_detailed(
m_detailedTrackTruthName
, ctx);
35
SG::WriteHandle<TrackTruthCollection>
wh_output(
m_outputName
, ctx);
36
if
(!rh_detailed.
isValid
()){
37
ATH_MSG_WARNING
(
"DetailedTrackTruthCollection "
<<
m_detailedTrackTruthName
.key()<<
" NOT found"
);
38
return
StatusCode::SUCCESS;
39
}
else
{
40
detailed = rh_detailed.
cptr
();
41
ATH_MSG_DEBUG
(
"Got DetailedTrackTruthCollection "
<<
m_detailedTrackTruthName
.key());
42
}
43
44
45
//----------------------------------------------------------------
46
// Produce and store the output.
47
48
TrackTruthCollection
*out =
new
TrackTruthCollection
(detailed->
trackCollectionLink
());
49
50
fillOutput
(out,detailed);
51
52
ATH_CHECK
(wh_output.
record
(std::unique_ptr<TrackTruthCollection>(out)));
53
54
return
StatusCode::SUCCESS;
55
56
}
57
//================================================================
58
59
void
TrackTruthSelector::fillOutput
(
TrackTruthCollection
*out,
60
const
DetailedTrackTruthCollection
*in)
61
{
62
using
Iter = DetailedTrackTruthCollection::const_iterator;
63
Iter itrackData=in->begin();
64
while
(itrackData!=in->end()) {
65
std::pair<Iter,Iter> range = in->equal_range(itrackData->first);
66
67
// We KNOW that the range is not empty - no need to check that.
68
Iter selected = range.first;
69
double
bestProb =
getProbability
(selected->second);
70
ATH_MSG_VERBOSE
(
"track="
<< selected->first.index() <<
" prob="
<< bestProb <<
" link: "
<< *(selected->second.trajectory().rbegin()));
71
for
(Iter imatch = ++range.first; imatch != range.second; ++imatch) {
72
double
prob =
getProbability
(imatch->second);
73
ATH_MSG_VERBOSE
(
"track="
<< imatch->first.index() <<
" prob="
<< prob <<
" link: "
<< *(imatch->second.trajectory().rbegin()));
74
if
(prob>bestProb) {
75
bestProb = prob;
76
selected = imatch;
77
}
78
}
79
80
// trajectory[0] is the LAST particle on the trajectory. The first
81
// is at trajectory.rbegin(), but different trajectories can have
82
// the same first particle.
83
// const HepMcParticleLink& particleLink = selected->second.trajectory()[0];
84
const
HepMcParticleLink
& particleLink = *(selected->second.trajectory().rbegin());
85
86
ATH_MSG_DEBUG
(
"Truth selected for track="
<< selected->first.index() <<
" prob="
<< bestProb <<
" link: "
<< particleLink);
87
out->insert(std::make_pair(selected->first,
TrackTruth
(particleLink, bestProb, 0) ));
88
itrackData=range.second;
89
}
90
91
}
92
93
//================================================================
94
double
TrackTruthSelector::getProbability
(
const
DetailedTrackTruth
& dt)
const
95
{
96
double
prd_track=0, prd_common=0;
97
for
(
unsigned
i=0; i<
SubDetHitStatistics::NUM_SUBDETECTORS
; i++) {
98
prd_common +=
m_subDetWeights
[i] * dt.statsCommon()[
SubDetHitStatistics::SubDetType
(i)];
99
prd_track +=
m_subDetWeights
[i] * dt.statsTrack()[
SubDetHitStatistics::SubDetType
(i)];
100
}
101
return
(prd_track>0)? prd_common/prd_track : -1.;
102
}
103
104
//================================================================
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
TrackTruthSelector.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
DetailedTrackTruthCollection
Definition
DetailedTrackTruthCollection.h:20
DetailedTrackTruthCollection::trackCollectionLink
DataLink< TrackCollection > trackCollectionLink() const
Definition
DetailedTrackTruthCollection.h:25
DetailedTrackTruth
Definition
DetailedTrackTruth.h:16
HepMcParticleLink
a link optimized in size for a GenParticle in a McEventCollection
Definition
HepMcParticleLink.h:72
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SubDetHitStatistics::SubDetType
SubDetType
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::RPC
@ RPC
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::MDT
@ MDT
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::TRT
@ TRT
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::MM
@ MM
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::NUM_SUBDETECTORS
@ NUM_SUBDETECTORS
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::STGC
@ STGC
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::SCT
@ SCT
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::CSC
@ CSC
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::TGC
@ TGC
Definition
SubDetHitStatistics.h:74
SubDetHitStatistics::Pixel
@ Pixel
Definition
SubDetHitStatistics.h:74
TrackTruthCollection
Definition
TrackTruthCollection.h:21
TrackTruthSelector::getProbability
double getProbability(const DetailedTrackTruth &dt) const
Definition
TrackTruthSelector.cxx:94
TrackTruthSelector::m_weightCSC
DoubleProperty m_weightCSC
Definition
TrackTruthSelector.h:42
TrackTruthSelector::m_outputName
SG::WriteHandleKey< TrackTruthCollection > m_outputName
Definition
TrackTruthSelector.h:31
TrackTruthSelector::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
TrackTruthSelector.cxx:28
TrackTruthSelector::m_subDetWeights
std::vector< double > m_subDetWeights
Definition
TrackTruthSelector.h:34
TrackTruthSelector::fillOutput
void fillOutput(TrackTruthCollection *out, const DetailedTrackTruthCollection *in)
Definition
TrackTruthSelector.cxx:59
TrackTruthSelector::m_detailedTrackTruthName
SG::ReadHandleKey< DetailedTrackTruthCollection > m_detailedTrackTruthName
Definition
TrackTruthSelector.h:27
TrackTruthSelector::initialize
virtual StatusCode initialize() override
Definition
TrackTruthSelector.cxx:10
TrackTruthSelector::m_weightTGC
DoubleProperty m_weightTGC
Definition
TrackTruthSelector.h:41
TrackTruthSelector::m_weightTRT
DoubleProperty m_weightTRT
Definition
TrackTruthSelector.h:38
TrackTruthSelector::TrackTruthSelector
TrackTruthSelector(const std::string &name, ISvcLocator *pSvcLocator)
Definition
TrackTruthSelector.cxx:7
TrackTruthSelector::m_weightMM
DoubleProperty m_weightMM
Definition
TrackTruthSelector.h:44
TrackTruthSelector::m_weightPixel
DoubleProperty m_weightPixel
Definition
TrackTruthSelector.h:36
TrackTruthSelector::m_weightRPC
DoubleProperty m_weightRPC
Definition
TrackTruthSelector.h:40
TrackTruthSelector::m_weightsTGC
DoubleProperty m_weightsTGC
Definition
TrackTruthSelector.h:43
TrackTruthSelector::m_weightSCT
DoubleProperty m_weightSCT
Definition
TrackTruthSelector.h:37
TrackTruthSelector::m_weightMDT
DoubleProperty m_weightMDT
Definition
TrackTruthSelector.h:39
TrackTruth
MC particle associated with a reco track + the quality of match.
Definition
TrackTruth.h:14
Generated on
for ATLAS Offline Software by
1.17.0