Skip to content
Snippets Groups Projects

MuonRecoChainTester - Pointer based truth matching

Merged Johannes Junggeburth requested to merge jojungge/athena:SegmentFitVolVII into main
7 files
+ 195
72
Compare changes
  • Side-by-side
  • Inline
Files
7
@@ -4,7 +4,7 @@
// Framework includes
#include "MuonRecoChainTester.h"
#include "MuonTesterTree/EventInfoBranch.h"
#include "MuonTesterTree/MuonTesterTreeDict.h"
#include "MuonTesterTree/TrackChi2Branch.h"
#include "MuonPRDTest/SegmentVariables.h"
#include "MuonPRDTest/ParticleVariables.h"
@@ -41,15 +41,12 @@ namespace MuonValR4{
m_legacyTrks = std::make_shared<IParticleFourMomBranch>(m_tree, "LegacyMSTrks");
m_legacyTrks->addVariable(std::make_shared<TrackChi2Branch>(*m_legacyTrks));
m_legacyTrks->addVariable<int>("truthMatched");
m_TrksHoughR4 = std::make_shared<IParticleFourMomBranch>(m_tree, "HoughMSTrks");
m_TrksHoughR4->addVariable(std::make_shared<TrackChi2Branch>(*m_TrksHoughR4));
m_TrksHoughR4->addVariable<int>("truthMatched");
m_TrksSegmentR4 = std::make_shared<IParticleFourMomBranch>(m_tree, "MSTrksR4");
m_TrksSegmentR4->addVariable(std::make_shared<TrackChi2Branch>(*m_TrksSegmentR4));
m_TrksSegmentR4->addVariable<int>("truthMatched");
m_tree.addBranch(m_legacyTrks);
m_tree.addBranch(m_TrksSegmentR4);
@@ -60,36 +57,20 @@ namespace MuonValR4{
m_trkTruthLinks.emplace_back(m_TrackKeyHoughR4, "truthParticleLink");
m_trkTruthLinks.emplace_back(m_TrackKeyR4, "truthParticleLink");
m_truthTrks = std::make_shared<IParticleFourMomBranch>(m_tree, "TruthMuons");
m_truthTrks->addVariable<int>("legacyMatched");
m_truthTrks->addVariable<int>("houghMatched");
m_truthTrks->addVariable<int>("r4Matched");
/// m_legacyTrks->addVariable(std::make_shared<LinkerBranch>(*m_legacyTrks, m_truthTrks, [](const xAOD::IParticle* trk){
/// return xAOD::TruthHelpers::getTruthParticle(*trk);
/// }, "truthMatched"));
/// m_TrksHoughR4->addBranch(std::make_shared<LinkerBranch>(*m_TrksHoughR4, m_truthTrks, [](const xAOD::IParticle* trk){
/// return xAOD::TruthHelpers::getTruthParticle(*trk);
/// }, "truthMatched"));
m_tree.addBranch(m_truthTrks);
}
ATH_CHECK(m_trkTruthLinks.initialize());
ATH_CHECK(m_tree.init(this));
return StatusCode::SUCCESS;
}
void MuonRecoChainTester::matchTrackToTruth(const xAOD::TruthParticle* truth,
const xAOD::TrackParticleContainer& tracks,
const SG::Decorator<int>& decRecoMatch,
const std::shared_ptr<MuonVal::IParticleFourMomBranch>& trkBranch) const {
decRecoMatch(*truth) = -1;
const auto match_itr = std::find_if(tracks.begin(), tracks.end(),[truth](const xAOD::TrackParticle* track){
return truth == xAOD::TruthHelpers::getTruthParticle(*track);
});
if (match_itr == tracks.end()) {
return;
}
const xAOD::TrackParticle* closest{*match_itr};
// Decorate the truth particle index to the reco particle
acc_truthMatched(*closest) = static_cast<int>(m_truthTrks->size());
trkBranch->push_back(closest);
/// Decorate the reco particle index to the truth particle
decRecoMatch(*truth) = trkBranch->find(closest);
}
void MuonRecoChainTester::fillBucketsPerStation(const MuonR4::SpacePointContainer& spContainer,
const StIdx station,
MuonVal::ScalarBranch<uint16_t>& outBranch) const{
@@ -101,11 +82,6 @@ namespace MuonValR4{
StatusCode MuonRecoChainTester::execute() {
const SG::Decorator<int> acc_legacyMatched{"legacyMatched"};
const SG::Decorator<int> acc_houghMatched{"houghMatched"};
const SG::Decorator<int> acc_r4Matched{"r4Matched"};
const EventContext& ctx{Gaudi::Hive::currentContext()};
SG::ReadHandle legacyTrks{m_legacyTrackKey, ctx};
ATH_CHECK(legacyTrks.isPresent());
@@ -115,15 +91,15 @@ namespace MuonValR4{
ATH_CHECK(trksR4.isPresent());
for (const xAOD::TrackParticle* trk : *legacyTrks) {
acc_truthMatched(*trk) = -1;
m_legacyTrks->push_back(trk);
}
for (const xAOD::TrackParticle* trk : *trksR4) {
acc_truthMatched(*trk) = -1;
m_TrksSegmentR4->push_back(trk);
}
for (const xAOD::TrackParticle* trk : *trksFromHoughR4) {
acc_truthMatched(*trk) = -1;
}
m_TrksHoughR4->push_back(trk);
}
ConstDataVector<xAOD::TruthParticleContainer> truthParts{SG::VIEW_ELEMENTS};
if (!m_truthKey.empty()) {
SG::ReadHandle readHandle{m_truthKey, ctx};
@@ -135,27 +111,8 @@ namespace MuonValR4{
}
}
for (const xAOD::TruthParticle* truth : truthParts) {
matchTrackToTruth(truth, *legacyTrks, acc_legacyMatched, m_legacyTrks);
matchTrackToTruth(truth, *trksFromHoughR4, acc_houghMatched, m_TrksHoughR4);
matchTrackToTruth(truth, *trksR4, acc_r4Matched, m_TrksSegmentR4);
if (truth->eta() > 2. && acc_legacyMatched(*truth) != -1
&& acc_r4Matched(*truth) == -1 ) {
ATH_MSG_VERBOSE("In event "<<ctx.eventID()<<" the new chain is inefficient. eta: "
<<truth->eta()<<", pT: "<<truth->pt()
<<" legacy: "<<acc_legacyMatched(*truth)<<", r4-hough: "<<
acc_houghMatched(*truth)<<", r4 seg: "<<acc_r4Matched(*truth));
}
m_truthTrks->push_back(truth);
}
for (const xAOD::TrackParticle* trk : *legacyTrks) {
m_legacyTrks->push_back(trk);
}
for (const xAOD::TrackParticle* trk : *trksR4) {
m_TrksSegmentR4->push_back(trk);
}
for (const xAOD::TrackParticle* trk : *trksFromHoughR4) {
m_TrksHoughR4->push_back(trk);
}
/** Fill the bucket summary counts */
SG::ReadHandle spContainer{m_spacePointKey, ctx};
ATH_CHECK(spContainer.isPresent());
Loading