LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::LArHierarchyHelper::MCHierarchy::Node Class Reference

Node class. More...

#include "LArHierarchyHelper.h"

Public Member Functions

 Node (MCHierarchy &hierarchy, const pandora::MCParticle *pMCParticle, const int tier=1)
 Create a node with a primary MC particle. More...
 
 Node (MCHierarchy &hierarchy, const pandora::MCParticleList &mcParticleList, const pandora::CaloHitList &caloHitList, const int tier=1)
 Create a node from a list of MC particles. More...
 
virtual ~Node ()
 Destructor. More...
 
bool IsReconstructable () const
 Return whether or not this node should be considered reconstructable. More...
 
void FillHierarchy (const pandora::MCParticle *pRoot, const FoldingParameters &foldParameters)
 Recursively fill the hierarchy based on the criteria established for this MCHierarchy. More...
 
void FillFlat (const pandora::MCParticle *pRoot)
 Fill this node by folding all descendent particles to this node. More...
 
const NodeVectorGetChildren () const
 Return the vector of children for this node. More...
 
int GetId () const
 Retrieve the unique ID of this node. More...
 
const pandora::MCParticle * GetLeadingMCParticle () const
 Retrieve the leading MC particle associated with this node. More...
 
const pandora::MCParticleList & GetMCParticles () const
 Retrieve the MC particles associated with this node. More...
 
const pandora::CaloHitList & GetCaloHits () const
 Retrieve the CaloHits associated with this node. More...
 
int GetParticleId () const
 Retrieve the PDG code for the leading particle in this node. More...
 
int GetHierarchyTier () const
 Retrieve the hierarchy tier of this node. More...
 
bool IsNeutrinoInduced () const
 Check if this is a particle induced by a neutrino interaction. More...
 
bool IsTestBeamParticle () const
 Check if this is a test beam particle. More...
 
bool IsCosmicRay () const
 Check if this is a cosmic ray particle. More...
 
bool IsLeadingLepton () const
 Returns whether or not this particle is the leading lepton in the event. More...
 
const std::string ToString (const std::string &prefix) const
 Produce a string representation of the hierarchy. More...
 

Private Member Functions

void SetLeadingLepton ()
 Tags the particle as the leading lepton. More...
 

Private Attributes

MCHierarchym_hierarchy
 The parent MC hierarchy. More...
 
pandora::MCParticleList m_mcParticles
 The list of MC particles of which this node is composed. More...
 
pandora::CaloHitList m_caloHits
 The list of calo hits of which this node is composed. More...
 
NodeVector m_children
 The child nodes of this node. More...
 
const pandora::MCParticle * m_mainParticle
 The leading MC particle for this node. More...
 
int m_tier
 The hierarchy tier for this node. More...
 
int m_pdg
 The PDG code of the leading MC particle for this node. More...
 
bool m_isLeadingLepton
 Whether or not this node is the leading lepton. More...
 

Friends

class MCHierarchy
 

Detailed Description

Node class.

Definition at line 134 of file LArHierarchyHelper.h.

Constructor & Destructor Documentation

lar_content::LArHierarchyHelper::MCHierarchy::Node::Node ( MCHierarchy hierarchy,
const pandora::MCParticle *  pMCParticle,
const int  tier = 1 
)

Create a node with a primary MC particle.

Parameters
hierarchyThe parent hierarchy of this node
pMCParticleThe primary MC particle with which this node should be created
tierThe tier that should be assigned to this node

Referenced by lar_content::LArHierarchyHelper::MCHierarchy::IsReconstructable().

lar_content::LArHierarchyHelper::MCHierarchy::Node::Node ( MCHierarchy hierarchy,
const pandora::MCParticleList &  mcParticleList,
const pandora::CaloHitList &  caloHitList,
const int  tier = 1 
)

Create a node from a list of MC particles.

Parameters
hierarchyThe parent hierarchy of this node
mcParticleListThe MC particle list with which this node should be created
caloHitListThe CaloHit list with which this node should be created
tierThe tier that should be assigned to this node
lar_content::LArHierarchyHelper::MCHierarchy::Node::~Node ( )
virtual

Destructor.

Definition at line 586 of file LArHierarchyHelper.cc.

587 {
588  m_mcParticles.clear();
589  m_caloHits.clear();
590  for (const Node *node : m_children)
591  delete node;
592  m_children.clear();
593 }
pandora::CaloHitList m_caloHits
The list of calo hits of which this node is composed.
NodeVector m_children
The child nodes of this node.
Node(MCHierarchy &hierarchy, const pandora::MCParticle *pMCParticle, const int tier=1)
Create a node with a primary MC particle.
pandora::MCParticleList m_mcParticles
The list of MC particles of which this node is composed.

Member Function Documentation

void lar_content::LArHierarchyHelper::MCHierarchy::Node::FillFlat ( const pandora::MCParticle *  pRoot)

Fill this node by folding all descendent particles to this node.

Parameters
pRootThe MC particle acting as the root of the current branch of the hierarchy

Definition at line 668 of file LArHierarchyHelper.cc.

References lar_content::LArMCParticleHelper::GetAllDescendentMCParticles(), and lcvn::neutrons.

669 {
670  MCParticleList allParticles{pRoot};
672  {
674  }
675  else
676  {
677  MCParticleList neutrons;
678  LArMCParticleHelper::GetAllDescendentMCParticles(pRoot, allParticles, allParticles, neutrons);
679  }
680  CaloHitList allHits;
681  for (const MCParticle *pMCParticle : allParticles)
682  {
683  // ATTN - Not all MC particles will have hits
684  if (m_hierarchy.m_mcToHitsMap.find(pMCParticle) != m_hierarchy.m_mcToHitsMap.end())
685  {
686  const CaloHitList &caloHits(m_hierarchy.m_mcToHitsMap.at(pMCParticle));
687  allHits.insert(allHits.begin(), caloHits.begin(), caloHits.end());
688  }
689  }
690  if (!allParticles.empty())
691  {
692  Node *pNode{new Node(m_hierarchy, allParticles, allHits, this->m_tier + 1)};
693  m_children.emplace_back(pNode);
694  }
695 }
std::map< const pandora::MCParticle *, pandora::CaloHitList > m_mcToHitsMap
The map between MC particles and calo hits.
NodeVector m_children
The child nodes of this node.
ReconstructabilityCriteria m_recoCriteria
The criteria used to determine if the node is reconstructable.
MCHierarchy & m_hierarchy
The parent MC hierarchy.
const bool m_removeNeutrons
whether to remove neutrons and their downstream particles
Node(MCHierarchy &hierarchy, const pandora::MCParticle *pMCParticle, const int tier=1)
Create a node with a primary MC particle.
int m_tier
The hierarchy tier for this node.
static void GetAllDescendentMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &descendentMCParticleList)
Get all descendent mc particles.
void lar_content::LArHierarchyHelper::MCHierarchy::Node::FillHierarchy ( const pandora::MCParticle *  pRoot,
const FoldingParameters foldParameters 
)

Recursively fill the hierarchy based on the criteria established for this MCHierarchy.

Parameters
pRootThe MC particle acting as the root of the current branch of the hierarchy
foldParametersThe folding parameters

Definition at line 597 of file LArHierarchyHelper.cc.

References util::abs(), FillHierarchy(), lar_content::LArMCParticleHelper::GetAllDescendentMCParticles(), lar_content::LArMCParticleHelper::GetHierarchyTier(), lar_content::LArHierarchyHelper::FoldingParameters::m_cosAngleTolerance, lar_content::LArHierarchyHelper::FoldingParameters::m_foldDynamic, lar_content::LArHierarchyHelper::FoldingParameters::m_foldToLeadingShowers, lar_content::LArHierarchyHelper::FoldingParameters::m_foldToTier, and lar_content::LArHierarchyHelper::FoldingParameters::m_tier.

Referenced by FillHierarchy().

598 {
599  if (foldParameters.m_foldDynamic)
600  {
601  MCParticleList leadingParticles, childParticles;
602  m_hierarchy.InterpretHierarchy(pRoot, leadingParticles, childParticles, foldParameters.m_cosAngleTolerance);
603  CaloHitList allHits;
604  for (const MCParticle *pMCParticle : leadingParticles)
605  {
606  // ATTN - Not all MC particles will have hits
607  if (m_hierarchy.m_mcToHitsMap.find(pMCParticle) != m_hierarchy.m_mcToHitsMap.end())
608  {
609  const CaloHitList &caloHits(m_hierarchy.m_mcToHitsMap.at(pMCParticle));
610  allHits.insert(allHits.begin(), caloHits.begin(), caloHits.end());
611  }
612  }
613 
614  Node *pNode{new Node(m_hierarchy, leadingParticles, allHits, this->m_tier + 1)};
615  m_children.emplace_back(pNode);
616  for (const MCParticle *pChild : childParticles)
617  pNode->FillHierarchy(pChild, foldParameters);
618  }
619  else
620  {
621  MCParticleList allParticles{pRoot};
622  const int pdg{std::abs(pRoot->GetParticleId())};
623  const bool isShower{pdg == E_MINUS || pdg == PHOTON};
624  const bool isNeutron{pdg == NEUTRON};
625 
626  if (foldParameters.m_foldToTier && LArMCParticleHelper::GetHierarchyTier(pRoot) >= foldParameters.m_tier)
628  else if (foldParameters.m_foldToLeadingShowers && (isShower || (isNeutron && !m_hierarchy.m_recoCriteria.m_removeNeutrons)))
630  else if (m_hierarchy.m_recoCriteria.m_removeNeutrons && isNeutron)
631  return;
632 
633  CaloHitList allHits;
634  for (const MCParticle *pMCParticle : allParticles)
635  {
636  // ATTN - Not all MC particles will have hits
637  if (m_hierarchy.m_mcToHitsMap.find(pMCParticle) != m_hierarchy.m_mcToHitsMap.end())
638  {
639  const CaloHitList &caloHits(m_hierarchy.m_mcToHitsMap.at(pMCParticle));
640  allHits.insert(allHits.begin(), caloHits.begin(), caloHits.end());
641  }
642  }
643 
644  if (!allParticles.empty())
645  {
646  const bool hasChildren{(foldParameters.m_foldToTier && LArMCParticleHelper::GetHierarchyTier(pRoot) < foldParameters.m_tier) ||
647  (!foldParameters.m_foldToTier && !foldParameters.m_foldToLeadingShowers) ||
648  (foldParameters.m_foldToLeadingShowers && !(isShower || isNeutron))};
649  // Only add the node if it either has children, or is a leaf node with hits
650  if (hasChildren || (!hasChildren && !allHits.empty()))
651  {
652  Node *pNode{new Node(m_hierarchy, allParticles, allHits, this->m_tier + 1)};
653  m_children.emplace_back(pNode);
654  if (hasChildren)
655  {
656  // Find the children of this particle and recursively add them to the hierarchy
657  const MCParticleList &children{pRoot->GetDaughterList()};
658  for (const MCParticle *pChild : children)
659  pNode->FillHierarchy(pChild, foldParameters);
660  }
661  }
662  }
663  }
664 }
std::map< const pandora::MCParticle *, pandora::CaloHitList > m_mcToHitsMap
The map between MC particles and calo hits.
constexpr auto abs(T v)
Returns the absolute value of the argument.
static int GetHierarchyTier(const pandora::MCParticle *const pMCParticle)
Determine the position in the hierarchy for the MCParticle.
void InterpretHierarchy(const pandora::MCParticle *const pRoot, pandora::MCParticleList &leadingParticles, pandora::MCParticleList &childParticles, const float cosAngleTolerance) const
Interpret the hierarchy below a particular particle to determine if and how it should be folded...
NodeVector m_children
The child nodes of this node.
ReconstructabilityCriteria m_recoCriteria
The criteria used to determine if the node is reconstructable.
MCHierarchy & m_hierarchy
The parent MC hierarchy.
const bool m_removeNeutrons
whether to remove neutrons and their downstream particles
Node(MCHierarchy &hierarchy, const pandora::MCParticle *pMCParticle, const int tier=1)
Create a node with a primary MC particle.
int m_tier
The hierarchy tier for this node.
static void GetAllDescendentMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &descendentMCParticleList)
Get all descendent mc particles.
const pandora::CaloHitList & lar_content::LArHierarchyHelper::MCHierarchy::Node::GetCaloHits ( ) const
inline

Retrieve the CaloHits associated with this node.

Returns
The list of CaloHits associated with this node

Definition at line 957 of file LArHierarchyHelper.h.

Referenced by lar_content::LArHierarchyHelper::MCMatches::GetCompleteness(), lar_content::LArHierarchyHelper::MCMatches::GetPurity(), and lar_content::LArHierarchyHelper::MatchInfo::Match().

958 {
959  return m_caloHits;
960 }
pandora::CaloHitList m_caloHits
The list of calo hits of which this node is composed.
const LArHierarchyHelper::MCHierarchy::NodeVector & lar_content::LArHierarchyHelper::MCHierarchy::Node::GetChildren ( ) const
inline

Return the vector of children for this node.

Returns
The vector of children

Definition at line 943 of file LArHierarchyHelper.h.

944 {
945  return m_children;
946 }
NodeVector m_children
The child nodes of this node.
int lar_content::LArHierarchyHelper::MCHierarchy::Node::GetHierarchyTier ( ) const
inline

Retrieve the hierarchy tier of this node.

Returns
The hierarchy tier of this node

Definition at line 978 of file LArHierarchyHelper.h.

References lar_content::LArHierarchyHelper::FoldingParameters::m_tier.

979 {
980  return m_tier;
981 }
int m_tier
The hierarchy tier for this node.
int lar_content::LArHierarchyHelper::MCHierarchy::Node::GetId ( ) const

Retrieve the unique ID of this node.

Returns
The unique ID of this node

Definition at line 699 of file LArHierarchyHelper.cc.

700 {
701  return m_hierarchy.m_nodeToIdMap.at(this);
702 }
MCHierarchy & m_hierarchy
The parent MC hierarchy.
std::map< const Node *, int > m_nodeToIdMap
A map from nodes to unique ids.
const pandora::MCParticle * lar_content::LArHierarchyHelper::MCHierarchy::Node::GetLeadingMCParticle ( ) const
inline

Retrieve the leading MC particle associated with this node.

Returns
The main MC particle associated with this node

Definition at line 964 of file LArHierarchyHelper.h.

Referenced by lar_content::LArHierarchyHelper::MCHierarchy::FillHierarchy(), lar_content::LArHierarchyHelper::MatchInfo::Print(), and lar_content::HierarchyValidationAlgorithm::Run().

965 {
966  return m_mainParticle;
967 }
const pandora::MCParticle * m_mainParticle
The leading MC particle for this node.
const pandora::MCParticleList & lar_content::LArHierarchyHelper::MCHierarchy::Node::GetMCParticles ( ) const
inline

Retrieve the MC particles associated with this node.

Returns
The MC particles associated with this node

Definition at line 950 of file LArHierarchyHelper.h.

951 {
952  return m_mcParticles;
953 }
pandora::MCParticleList m_mcParticles
The list of MC particles of which this node is composed.
int lar_content::LArHierarchyHelper::MCHierarchy::Node::GetParticleId ( ) const
inline

Retrieve the PDG code for the leading particle in this node.

Returns
The PDG code for the leading particle in this node

Definition at line 971 of file LArHierarchyHelper.h.

Referenced by lar_content::LArHierarchyHelper::MatchInfo::Print().

972 {
973  return m_pdg;
974 }
int m_pdg
The PDG code of the leading MC particle for this node.
bool lar_content::LArHierarchyHelper::MCHierarchy::Node::IsCosmicRay ( ) const

Check if this is a cosmic ray particle.

Returns
Whether or not this is a cosmic ray

Definition at line 758 of file LArHierarchyHelper.cc.

References lar_content::LArMCParticleHelper::IsCosmicRay().

Referenced by IsNeutrinoInduced().

759 {
760  if (m_mainParticle)
762  else
763  return false;
764 }
static bool IsCosmicRay(const pandora::MCParticle *const pMCParticle)
Return true if passed a primary cosmic ray MCParticle.
const pandora::MCParticle * m_mainParticle
The leading MC particle for this node.
bool lar_content::LArHierarchyHelper::MCHierarchy::Node::IsLeadingLepton ( ) const
inline

Returns whether or not this particle is the leading lepton in the event.

Returns
Whether or not this is the leading lepton

Definition at line 992 of file LArHierarchyHelper.h.

993 {
994  return m_isLeadingLepton;
995 }
bool m_isLeadingLepton
Whether or not this node is the leading lepton.
bool lar_content::LArHierarchyHelper::MCHierarchy::Node::IsNeutrinoInduced ( ) const
inline

Check if this is a particle induced by a neutrino interaction.

Returns
Whether or not this is neutrino induced

Definition at line 985 of file LArHierarchyHelper.h.

References IsCosmicRay(), and IsTestBeamParticle().

986 {
988 }
bool IsCosmicRay() const
Check if this is a cosmic ray particle.
bool IsTestBeamParticle() const
Check if this is a test beam particle.
bool lar_content::LArHierarchyHelper::MCHierarchy::Node::IsReconstructable ( ) const

Return whether or not this node should be considered reconstructable.

Returns
true if reconstructable, false otherwise

Definition at line 706 of file LArHierarchyHelper.cc.

707 {
708  const bool enoughHits{m_caloHits.size() >= m_hierarchy.m_recoCriteria.m_minHits};
709  if (!enoughHits)
710  return false;
711  bool enoughGoodViews{false};
712  unsigned int nHitsU{0}, nHitsV{0}, nHitsW{0};
713  for (const CaloHit *pCaloHit : m_caloHits)
714  {
715  switch (pCaloHit->GetHitType())
716  {
717  case TPC_VIEW_U:
718  ++nHitsU;
719  break;
720  case TPC_VIEW_V:
721  ++nHitsV;
722  break;
723  case TPC_VIEW_W:
724  ++nHitsW;
725  break;
726  default:
727  break;
728  }
729  unsigned int nGoodViews{0};
731  ++nGoodViews;
733  ++nGoodViews;
735  ++nGoodViews;
736  if (nGoodViews >= m_hierarchy.m_recoCriteria.m_minGoodViews)
737  {
738  enoughGoodViews = true;
739  break;
740  }
741  }
742 
743  return enoughGoodViews;
744 }
const unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
pandora::CaloHitList m_caloHits
The list of calo hits of which this node is composed.
ReconstructabilityCriteria m_recoCriteria
The criteria used to determine if the node is reconstructable.
MCHierarchy & m_hierarchy
The parent MC hierarchy.
const unsigned int m_minHits
the minimum number of primary good Hits
const unsigned int m_minGoodViews
the minimum number of primary good views
bool lar_content::LArHierarchyHelper::MCHierarchy::Node::IsTestBeamParticle ( ) const

Check if this is a test beam particle.

Returns
Whether or not this is a test beam particle

Definition at line 748 of file LArHierarchyHelper.cc.

References lar_content::LArMCParticleHelper::IsBeamParticle().

Referenced by IsNeutrinoInduced().

749 {
750  if (m_mainParticle)
752  else
753  return false;
754 }
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
const pandora::MCParticle * m_mainParticle
The leading MC particle for this node.
void lar_content::LArHierarchyHelper::MCHierarchy::Node::SetLeadingLepton ( )
inlineprivate

Tags the particle as the leading lepton.

Definition at line 999 of file LArHierarchyHelper.h.

Referenced by lar_content::LArHierarchyHelper::MCHierarchy::FillHierarchy().

1000 {
1001  m_isLeadingLepton = true;
1002 }
bool m_isLeadingLepton
Whether or not this node is the leading lepton.
const std::string lar_content::LArHierarchyHelper::MCHierarchy::Node::ToString ( const std::string &  prefix) const

Produce a string representation of the hierarchy.

Returns
The string representation of the hierarchy

Definition at line 768 of file LArHierarchyHelper.cc.

References util::to_string().

769 {
770  std::string str(prefix + "PDG: " + std::to_string(m_pdg) + " Energy: " + std::to_string(m_mainParticle ? m_mainParticle->GetEnergy() : 0) +
771  " Hits: " + std::to_string(m_caloHits.size()) + "\n");
772  for (const Node *pChild : m_children)
773  str += pChild->ToString(prefix + " ");
774 
775  return str;
776 }
int m_pdg
The PDG code of the leading MC particle for this node.
pandora::CaloHitList m_caloHits
The list of calo hits of which this node is composed.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
NodeVector m_children
The child nodes of this node.
const pandora::MCParticle * m_mainParticle
The leading MC particle for this node.
Node(MCHierarchy &hierarchy, const pandora::MCParticle *pMCParticle, const int tier=1)
Create a node with a primary MC particle.

Friends And Related Function Documentation

friend class MCHierarchy
friend

Definition at line 282 of file LArHierarchyHelper.h.

Member Data Documentation

pandora::CaloHitList lar_content::LArHierarchyHelper::MCHierarchy::Node::m_caloHits
private

The list of calo hits of which this node is composed.

Definition at line 275 of file LArHierarchyHelper.h.

NodeVector lar_content::LArHierarchyHelper::MCHierarchy::Node::m_children
private

The child nodes of this node.

Definition at line 276 of file LArHierarchyHelper.h.

MCHierarchy& lar_content::LArHierarchyHelper::MCHierarchy::Node::m_hierarchy
private

The parent MC hierarchy.

Definition at line 273 of file LArHierarchyHelper.h.

bool lar_content::LArHierarchyHelper::MCHierarchy::Node::m_isLeadingLepton
private

Whether or not this node is the leading lepton.

Definition at line 280 of file LArHierarchyHelper.h.

const pandora::MCParticle* lar_content::LArHierarchyHelper::MCHierarchy::Node::m_mainParticle
private

The leading MC particle for this node.

Definition at line 277 of file LArHierarchyHelper.h.

pandora::MCParticleList lar_content::LArHierarchyHelper::MCHierarchy::Node::m_mcParticles
private

The list of MC particles of which this node is composed.

Definition at line 274 of file LArHierarchyHelper.h.

int lar_content::LArHierarchyHelper::MCHierarchy::Node::m_pdg
private

The PDG code of the leading MC particle for this node.

Definition at line 279 of file LArHierarchyHelper.h.

int lar_content::LArHierarchyHelper::MCHierarchy::Node::m_tier
private

The hierarchy tier for this node.

Definition at line 278 of file LArHierarchyHelper.h.


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