ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
7TrackTruthSelector::TrackTruthSelector(const std::string &name,ISvcLocator *pSvcLocator) : AthAlgorithm(name,pSvcLocator) {}
8
9// -----------------------------------------------------------------------------------------------------
26
27// -----------------------------------------------------------------------------------------------------
29 ATH_MSG_DEBUG ("TrackTruthSelector::execute()");
30
31 //----------------------------------------------------------------
32 // Retrieve the input
33 const DetailedTrackTruthCollection *detailed = nullptr;
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
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
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//================================================================
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//================================================================
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
DataLink< TrackCollection > trackCollectionLink() const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
double getProbability(const DetailedTrackTruth &dt) const
DoubleProperty m_weightCSC
SG::WriteHandleKey< TrackTruthCollection > m_outputName
std::vector< double > m_subDetWeights
void fillOutput(TrackTruthCollection *out, const DetailedTrackTruthCollection *in)
SG::ReadHandleKey< DetailedTrackTruthCollection > m_detailedTrackTruthName
virtual StatusCode initialize() override
DoubleProperty m_weightTGC
DoubleProperty m_weightTRT
virtual StatusCode execute() override
TrackTruthSelector(const std::string &name, ISvcLocator *pSvcLocator)
DoubleProperty m_weightMM
DoubleProperty m_weightPixel
DoubleProperty m_weightRPC
DoubleProperty m_weightsTGC
DoubleProperty m_weightSCT
DoubleProperty m_weightMDT
MC particle associated with a reco track + the quality of match.
Definition TrackTruth.h:14