All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
lar_content::LArHierarchyHelper::MatchInfo Class Reference

MatcheInfo class. More...

#include <LArHierarchyHelper.h>

Public Member Functions

 MatchInfo ()
 Default constructor. More...
 
 MatchInfo (const QualityCuts &qualityCuts)
 Constructor. More...
 
void Match (const MCHierarchy &mcHierarchy, const RecoHierarchy &recoHierarchy)
 Match the nodes in the MC and reco hierarchies. More...
 
const MCMatchesVectorGetMatches () const
 Retrieve the vector of matches (this will include null matches - i.e. MC nodes with no corresponding reco) More...
 
const RecoHierarchy::NodeVectorGetUnmatchedReco () const
 Retrieve the vector of unmatched reco nodes. More...
 
const pandora::MCParticle * GetMCNeutrino () const
 Retrieve the parent MC neutrino if it exists. More...
 
const pandora::ParticleFlowObject * GetRecoNeutrino () const
 Retrieve the parent reco neutrino if it exists. More...
 
unsigned int GetNMCNodes () const
 Retrieve the number of MC nodes available to match. More...
 
unsigned int GetNNeutrinoMCNodes () const
 Retrieve the number of neutrino interaction derived MC nodes available to match. More...
 
unsigned int GetNCosmicRayMCNodes () const
 Retrieve the number of cosmic ray derived MC nodes available to match. More...
 
unsigned int GetNTestBeamMCNodes () const
 Retrieve the number of test beam derived MC nodes available to match. More...
 
const QualityCutsGetQualityCuts () const
 Retrieve the quality cuts for matching. More...
 
void Print (const MCHierarchy &mcHierarchy) const
 Prints information about which reco nodes are matched to the MC nodes, information about hit sharing, purity and completeness. More...
 

Private Attributes

const pandora::MCParticle * m_pMCNeutrino
 The parent neutrino if it exists. More...
 
const pandora::ParticleFlowObject * m_pRecoNeutrino
 The parent neutrino if it exists. More...
 
MCMatchesVector m_matches
 The vector of good matches from MC to reco. More...
 
MCMatchesVector m_goodMatches
 The vector of good matches - above threshold one reco to one MC matches. More...
 
MCMatchesVector m_aboveThresholdMatches
 The vector of matches that pass quality but with multiple reco matches to the MC. More...
 
MCMatchesVector m_subThresholdMatches
 The vector of matches that don't pass quality cuts. More...
 
MCHierarchy::NodeVector m_unmatchedMC
 The vector of unmatched MC nodes. More...
 
RecoHierarchy::NodeVector m_unmatchedReco
 The vector of unmatched reco nodes. More...
 
QualityCuts m_qualityCuts
 The quality cuts to be applied to matches. More...
 

Detailed Description

MatcheInfo class.

Definition at line 722 of file LArHierarchyHelper.h.

Constructor & Destructor Documentation

lar_content::LArHierarchyHelper::MatchInfo::MatchInfo ( )

Default constructor.

Definition at line 1178 of file LArHierarchyHelper.cc.

1178  : MatchInfo(QualityCuts())
1179 {
1180 }
lar_content::LArHierarchyHelper::MatchInfo::MatchInfo ( const QualityCuts qualityCuts)

Constructor.

Parameters
qualityCutsThe quality cuts to be applied to matched nodes

Definition at line 1184 of file LArHierarchyHelper.cc.

1184  :
1185  m_pMCNeutrino{nullptr},
1186  m_pRecoNeutrino{nullptr},
1187  m_qualityCuts{qualityCuts}
1188 {
1189 }
QualityCuts m_qualityCuts
The quality cuts to be applied to matches.
const pandora::MCParticle * m_pMCNeutrino
The parent neutrino if it exists.
const pandora::ParticleFlowObject * m_pRecoNeutrino
The parent neutrino if it exists.

Member Function Documentation

const LArHierarchyHelper::MCMatchesVector & lar_content::LArHierarchyHelper::MatchInfo::GetMatches ( ) const
inline

Retrieve the vector of matches (this will include null matches - i.e. MC nodes with no corresponding reco)

Returns
The vector of matches

Definition at line 1022 of file LArHierarchyHelper.h.

1023 {
1024  return m_matches;
1025 }
MCMatchesVector m_matches
The vector of good matches from MC to reco.
const pandora::MCParticle * lar_content::LArHierarchyHelper::MatchInfo::GetMCNeutrino ( ) const
inline

Retrieve the parent MC neutrino if it exists.

Parameters
Theparent neutrino if it exists (nullptr otherwise)

Definition at line 1036 of file LArHierarchyHelper.h.

1037 {
1038  return m_pMCNeutrino;
1039 }
const pandora::MCParticle * m_pMCNeutrino
The parent neutrino if it exists.
unsigned int lar_content::LArHierarchyHelper::MatchInfo::GetNCosmicRayMCNodes ( ) const

Retrieve the number of cosmic ray derived MC nodes available to match.

Returns
The number of MC nodes available to match

Definition at line 1294 of file LArHierarchyHelper.cc.

1295 {
1296  unsigned int nNodes{0};
1297  for (const MCMatches &match : m_matches)
1298  {
1299  const MCHierarchy::Node *pNode{match.GetMC()};
1300  if (pNode->IsCosmicRay())
1301  ++nNodes;
1302  }
1303 
1304  return nNodes;
1305 }
MCMatchesVector m_matches
The vector of good matches from MC to reco.
unsigned int lar_content::LArHierarchyHelper::MatchInfo::GetNMCNodes ( ) const

Retrieve the number of MC nodes available to match.

Returns
The number of MC nodes available to match

Definition at line 1272 of file LArHierarchyHelper.cc.

1273 {
1274  return static_cast<unsigned int>(m_matches.size());
1275 }
MCMatchesVector m_matches
The vector of good matches from MC to reco.
unsigned int lar_content::LArHierarchyHelper::MatchInfo::GetNNeutrinoMCNodes ( ) const

Retrieve the number of neutrino interaction derived MC nodes available to match.

Returns
The number of MC nodes available to match

Definition at line 1279 of file LArHierarchyHelper.cc.

1280 {
1281  unsigned int nNodes{0};
1282  for (const MCMatches &match : m_matches)
1283  {
1284  const MCHierarchy::Node *pNode{match.GetMC()};
1285  if (!(pNode->IsCosmicRay() || pNode->IsTestBeamParticle()))
1286  ++nNodes;
1287  }
1288 
1289  return nNodes;
1290 }
MCMatchesVector m_matches
The vector of good matches from MC to reco.
unsigned int lar_content::LArHierarchyHelper::MatchInfo::GetNTestBeamMCNodes ( ) const

Retrieve the number of test beam derived MC nodes available to match.

Returns
The number of MC nodes available to match

Definition at line 1309 of file LArHierarchyHelper.cc.

1310 {
1311  unsigned int nNodes{0};
1312  for (const MCMatches &match : m_matches)
1313  {
1314  const MCHierarchy::Node *pNode{match.GetMC()};
1315  if (pNode->IsTestBeamParticle())
1316  ++nNodes;
1317  }
1318 
1319  return nNodes;
1320 }
MCMatchesVector m_matches
The vector of good matches from MC to reco.
const LArHierarchyHelper::QualityCuts & lar_content::LArHierarchyHelper::MatchInfo::GetQualityCuts ( ) const
inline

Retrieve the quality cuts for matching.

Returns
The quality cuts

Definition at line 1050 of file LArHierarchyHelper.h.

1051 {
1052  return m_qualityCuts;
1053 }
QualityCuts m_qualityCuts
The quality cuts to be applied to matches.
const pandora::ParticleFlowObject * lar_content::LArHierarchyHelper::MatchInfo::GetRecoNeutrino ( ) const
inline

Retrieve the parent reco neutrino if it exists.

Parameters
Theparent neutrino if it exists (nullptr otherwise)

Definition at line 1043 of file LArHierarchyHelper.h.

1044 {
1045  return m_pRecoNeutrino;
1046 }
const pandora::ParticleFlowObject * m_pRecoNeutrino
The parent neutrino if it exists.
const LArHierarchyHelper::RecoHierarchy::NodeVector & lar_content::LArHierarchyHelper::MatchInfo::GetUnmatchedReco ( ) const
inline

Retrieve the vector of unmatched reco nodes.

Definition at line 1029 of file LArHierarchyHelper.h.

1030 {
1031  return m_unmatchedReco;
1032 }
RecoHierarchy::NodeVector m_unmatchedReco
The vector of unmatched reco nodes.
void lar_content::LArHierarchyHelper::MatchInfo::Match ( const MCHierarchy mcHierarchy,
const RecoHierarchy recoHierarchy 
)

Match the nodes in the MC and reco hierarchies.

Parameters
mcHierarchyThe MC hierarchy
recoHierarchyThe reco hierarchy

Definition at line 1193 of file LArHierarchyHelper.cc.

1194 {
1195  m_pMCNeutrino = mcHierarchy.GetNeutrino();
1196  m_pRecoNeutrino = recoHierarchy.GetNeutrino();
1197  MCHierarchy::NodeVector mcNodes;
1198  mcHierarchy.GetFlattenedNodes(mcNodes);
1199  RecoHierarchy::NodeVector recoNodes;
1200  recoHierarchy.GetFlattenedNodes(recoNodes);
1201 
1202  std::sort(mcNodes.begin(), mcNodes.end(),
1203  [](const MCHierarchy::Node *lhs, const MCHierarchy::Node *rhs) { return lhs->GetCaloHits().size() > rhs->GetCaloHits().size(); });
1204  std::sort(recoNodes.begin(), recoNodes.end(),
1205  [](const RecoHierarchy::Node *lhs, const RecoHierarchy::Node *rhs) { return lhs->GetCaloHits().size() > rhs->GetCaloHits().size(); });
1206 
1207  std::map<const MCHierarchy::Node *, MCMatches> mcToMatchMap;
1208  for (const RecoHierarchy::Node *pRecoNode : recoNodes)
1209  {
1210  const CaloHitList &recoHits{pRecoNode->GetCaloHits()};
1211  const MCHierarchy::Node *pBestNode{nullptr};
1212  size_t bestSharedHits{0};
1213  for (const MCHierarchy::Node *pMCNode : mcNodes)
1214  {
1215  if (!pMCNode->IsReconstructable())
1216  continue;
1217  const CaloHitList &mcHits{pMCNode->GetCaloHits()};
1218  CaloHitVector intersection;
1219  std::set_intersection(mcHits.begin(), mcHits.end(), recoHits.begin(), recoHits.end(), std::back_inserter(intersection));
1220 
1221  if (!intersection.empty())
1222  {
1223  const size_t sharedHits{intersection.size()};
1224  if (sharedHits > bestSharedHits)
1225  {
1226  bestSharedHits = sharedHits;
1227  pBestNode = pMCNode;
1228  }
1229  }
1230  }
1231  if (pBestNode)
1232  {
1233  auto iter{mcToMatchMap.find(pBestNode)};
1234  if (iter != mcToMatchMap.end())
1235  {
1236  MCMatches &match(iter->second);
1237  match.AddRecoMatch(pRecoNode, static_cast<int>(bestSharedHits));
1238  }
1239  else
1240  {
1241  MCMatches match(pBestNode);
1242  match.AddRecoMatch(pRecoNode, static_cast<int>(bestSharedHits));
1243  mcToMatchMap.insert(std::make_pair(pBestNode, match));
1244  }
1245  }
1246  else
1247  {
1248  m_unmatchedReco.emplace_back(pRecoNode);
1249  }
1250  }
1251 
1252  for (auto [pMCNode, matches] : mcToMatchMap)
1253  m_matches.emplace_back(matches);
1254 
1255  const auto predicate = [](const MCMatches &lhs, const MCMatches &rhs) {
1256  return lhs.GetMC()->GetCaloHits().size() > rhs.GetMC()->GetCaloHits().size();
1257  };
1258  std::sort(m_matches.begin(), m_matches.end(), predicate);
1259 
1260  for (const MCHierarchy::Node *pMCNode : mcNodes)
1261  {
1262  if (pMCNode->IsReconstructable() && mcToMatchMap.find(pMCNode) == mcToMatchMap.end())
1263  {
1264  MCMatches match(pMCNode);
1265  m_matches.emplace_back(match);
1266  }
1267  }
1268 }
MCMatchesVector m_matches
The vector of good matches from MC to reco.
RecoHierarchy::NodeVector m_unmatchedReco
The vector of unmatched reco nodes.
const pandora::MCParticle * m_pMCNeutrino
The parent neutrino if it exists.
const pandora::ParticleFlowObject * m_pRecoNeutrino
The parent neutrino if it exists.
void lar_content::LArHierarchyHelper::MatchInfo::Print ( const MCHierarchy mcHierarchy) const

Prints information about which reco nodes are matched to the MC nodes, information about hit sharing, purity and completeness.

Parameters
mcHierarchyThe MC hierarchy

Definition at line 1324 of file LArHierarchyHelper.cc.

1325 {
1326  unsigned int nNeutrinoMCParticles{this->GetNNeutrinoMCNodes()}, nNeutrinoRecoParticles{0};
1327  unsigned int nCosmicMCParticles{this->GetNCosmicRayMCNodes()}, nCosmicRecoParticles{0}, nCosmicRecoBTParticles{0};
1328  unsigned int nTestBeamMCParticles{this->GetNTestBeamMCNodes()}, nTestBeamRecoParticles{0}, nTestBeamRecoBTParticles{0};
1329  std::cout << "=== Matches ===" << std::endl;
1330  for (const MCMatches &match : m_matches)
1331  {
1332  const MCHierarchy::Node *pMCNode{match.GetMC()};
1333  const int pdg{pMCNode->GetParticleId()};
1334  const size_t mcHits{pMCNode->GetCaloHits().size()};
1335  const std::string tag{pMCNode->IsTestBeamParticle() ? "(Beam) " : pMCNode->IsCosmicRay() ? "(Cosmic) " : ""};
1336  std::cout << "MC " << tag << pdg << " hits " << mcHits << std::endl;
1337  const RecoHierarchy::NodeVector &nodeVector{match.GetRecoMatches()};
1338 
1339  for (const RecoHierarchy::Node *pRecoNode : nodeVector)
1340  {
1341  const unsigned int recoHits{static_cast<unsigned int>(pRecoNode->GetCaloHits().size())};
1342  const unsigned int sharedHits{match.GetSharedHits(pRecoNode)};
1343  const float purity{match.GetPurity(pRecoNode)};
1344  const float completeness{match.GetCompleteness(pRecoNode)};
1345  std::cout << " Matched " << sharedHits << " out of " << recoHits << " with purity " << purity << " and completeness "
1346  << completeness << std::endl;
1347  }
1348  if (nodeVector.empty())
1349  std::cout << " Unmatched" << std::endl;
1350 
1351  if (pMCNode->IsTestBeamParticle())
1352  ++nTestBeamRecoParticles;
1353  else if (pMCNode->IsCosmicRay())
1354  ++nCosmicRecoParticles;
1355  else
1356  ++nNeutrinoRecoParticles;
1357  }
1358 
1359  if (mcHierarchy.IsNeutrinoHierarchy())
1360  {
1361  std::cout << "Neutrino Interaction Summary:" << std::endl;
1362  std::cout << std::fixed << std::setprecision(1);
1363  if (nNeutrinoMCParticles)
1364  {
1365  std::cout << "Matched final state particles: " << nNeutrinoRecoParticles << " of " << nNeutrinoMCParticles << " : "
1366  << (100 * nNeutrinoRecoParticles / static_cast<float>(nNeutrinoMCParticles)) << "%" << std::endl;
1367  }
1368  if (nCosmicMCParticles)
1369  {
1370  std::cout << "Matched cosmics: " << nCosmicRecoParticles << " of " << nCosmicMCParticles << " : "
1371  << (100 * nCosmicRecoParticles / static_cast<float>(nCosmicMCParticles)) << "%" << std::endl;
1372  }
1373  }
1374  else if (mcHierarchy.IsTestBeamHierarchy())
1375  {
1376  std::cout << "Test Beam Interaction Summary:" << std::endl;
1377  std::cout << std::fixed << std::setprecision(1);
1378  if (nTestBeamMCParticles)
1379  {
1380  std::cout << "Matched test beam particles: " << nTestBeamRecoParticles << " of " << nTestBeamMCParticles << " : "
1381  << (100 * nTestBeamRecoParticles / static_cast<float>(nTestBeamMCParticles)) << "%" << std::endl;
1382  std::cout << "Loosely matched test beam particles: " << (nTestBeamRecoParticles + nTestBeamRecoBTParticles) << " of " << nTestBeamMCParticles
1383  << " : " << (100 * (nTestBeamRecoParticles + nTestBeamRecoBTParticles) / static_cast<float>(nTestBeamMCParticles))
1384  << "%" << std::endl;
1385  }
1386  if (nCosmicMCParticles)
1387  {
1388  std::cout << "Matched cosmics: " << nCosmicRecoParticles << " of " << nCosmicMCParticles << " : "
1389  << (100 * nCosmicRecoParticles / static_cast<float>(nCosmicMCParticles)) << "%" << std::endl;
1390  std::cout << "Loosely matched cosmics: " << (nCosmicRecoParticles + nCosmicRecoBTParticles) << " of " << nCosmicMCParticles << " : "
1391  << (100 * (nCosmicRecoParticles + nCosmicRecoBTParticles) / static_cast<float>(nCosmicMCParticles)) << "%" << std::endl;
1392  }
1393  }
1394  if (!this->GetUnmatchedReco().empty())
1395  std::cout << "Unmatched reco: " << this->GetUnmatchedReco().size() << std::endl;
1396 }
MCMatchesVector m_matches
The vector of good matches from MC to reco.
var pdg
Definition: selectors.fcl:14
unsigned int GetNTestBeamMCNodes() const
Retrieve the number of test beam derived MC nodes available to match.
unsigned int GetNNeutrinoMCNodes() const
Retrieve the number of neutrino interaction derived MC nodes available to match.
const RecoHierarchy::NodeVector & GetUnmatchedReco() const
Retrieve the vector of unmatched reco nodes.
BEGIN_PROLOG could also be cout
unsigned int GetNCosmicRayMCNodes() const
Retrieve the number of cosmic ray derived MC nodes available to match.

Member Data Documentation

MCMatchesVector lar_content::LArHierarchyHelper::MatchInfo::m_aboveThresholdMatches
private

The vector of matches that pass quality but with multiple reco matches to the MC.

Definition at line 820 of file LArHierarchyHelper.h.

MCMatchesVector lar_content::LArHierarchyHelper::MatchInfo::m_goodMatches
private

The vector of good matches - above threshold one reco to one MC matches.

Definition at line 819 of file LArHierarchyHelper.h.

MCMatchesVector lar_content::LArHierarchyHelper::MatchInfo::m_matches
private

The vector of good matches from MC to reco.

Definition at line 818 of file LArHierarchyHelper.h.

const pandora::MCParticle* lar_content::LArHierarchyHelper::MatchInfo::m_pMCNeutrino
private

The parent neutrino if it exists.

Definition at line 815 of file LArHierarchyHelper.h.

const pandora::ParticleFlowObject* lar_content::LArHierarchyHelper::MatchInfo::m_pRecoNeutrino
private

The parent neutrino if it exists.

Definition at line 816 of file LArHierarchyHelper.h.

QualityCuts lar_content::LArHierarchyHelper::MatchInfo::m_qualityCuts
private

The quality cuts to be applied to matches.

Definition at line 824 of file LArHierarchyHelper.h.

MCMatchesVector lar_content::LArHierarchyHelper::MatchInfo::m_subThresholdMatches
private

The vector of matches that don't pass quality cuts.

Definition at line 821 of file LArHierarchyHelper.h.

MCHierarchy::NodeVector lar_content::LArHierarchyHelper::MatchInfo::m_unmatchedMC
private

The vector of unmatched MC nodes.

Definition at line 822 of file LArHierarchyHelper.h.

RecoHierarchy::NodeVector lar_content::LArHierarchyHelper::MatchInfo::m_unmatchedReco
private

The vector of unmatched reco nodes.

Definition at line 823 of file LArHierarchyHelper.h.


The documentation for this class was generated from the following files: