LArSoft  v09_90_00
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 132 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 584 of file LArHierarchyHelper.cc.

585 {
586  m_mcParticles.clear();
587  m_caloHits.clear();
588  for (const Node *node : m_children)
589  delete node;
590  m_children.clear();
591 }
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 666 of file LArHierarchyHelper.cc.

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

667 {
668  MCParticleList allParticles{pRoot};
670  {
672  }
673  else
674  {
675  MCParticleList neutrons;
676  LArMCParticleHelper::GetAllDescendentMCParticles(pRoot, allParticles, allParticles, neutrons);
677  }
678  CaloHitList allHits;
679  for (const MCParticle *pMCParticle : allParticles)
680  {
681  // ATTN - Not all MC particles will have hits
682  if (m_hierarchy.m_mcToHitsMap.find(pMCParticle) != m_hierarchy.m_mcToHitsMap.end())
683  {
684  const CaloHitList &caloHits(m_hierarchy.m_mcToHitsMap.at(pMCParticle));
685  allHits.insert(allHits.begin(), caloHits.begin(), caloHits.end());
686  }
687  }
688  if (!allParticles.empty())
689  {
690  Node *pNode{new Node(m_hierarchy, allParticles, allHits, this->m_tier + 1)};
691  m_children.emplace_back(pNode);
692  }
693 }
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 595 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().

596 {
597  if (foldParameters.m_foldDynamic)
598  {
599  MCParticleList leadingParticles, childParticles;
600  m_hierarchy.InterpretHierarchy(pRoot, leadingParticles, childParticles, foldParameters.m_cosAngleTolerance);
601  CaloHitList allHits;
602  for (const MCParticle *pMCParticle : leadingParticles)
603  {
604  // ATTN - Not all MC particles will have hits
605  if (m_hierarchy.m_mcToHitsMap.find(pMCParticle) != m_hierarchy.m_mcToHitsMap.end())
606  {
607  const CaloHitList &caloHits(m_hierarchy.m_mcToHitsMap.at(pMCParticle));
608  allHits.insert(allHits.begin(), caloHits.begin(), caloHits.end());
609  }
610  }
611 
612  Node *pNode{new Node(m_hierarchy, leadingParticles, allHits, this->m_tier + 1)};
613  m_children.emplace_back(pNode);
614  for (const MCParticle *pChild : childParticles)
615  pNode->FillHierarchy(pChild, foldParameters);
616  }
617  else
618  {
619  MCParticleList allParticles{pRoot};
620  const int pdg{std::abs(pRoot->GetParticleId())};
621  const bool isShower{pdg == E_MINUS || pdg == PHOTON};
622  const bool isNeutron{pdg == NEUTRON};
623 
624  if (foldParameters.m_foldToTier && LArMCParticleHelper::GetHierarchyTier(pRoot) >= foldParameters.m_tier)
626  else if (foldParameters.m_foldToLeadingShowers && (isShower || (isNeutron && !m_hierarchy.m_recoCriteria.m_removeNeutrons)))
628  else if (m_hierarchy.m_recoCriteria.m_removeNeutrons && isNeutron)
629  return;
630 
631  CaloHitList allHits;
632  for (const MCParticle *pMCParticle : allParticles)
633  {
634  // ATTN - Not all MC particles will have hits
635  if (m_hierarchy.m_mcToHitsMap.find(pMCParticle) != m_hierarchy.m_mcToHitsMap.end())
636  {
637  const CaloHitList &caloHits(m_hierarchy.m_mcToHitsMap.at(pMCParticle));
638  allHits.insert(allHits.begin(), caloHits.begin(), caloHits.end());
639  }
640  }
641 
642  if (!allParticles.empty())
643  {
644  const bool hasChildren{(foldParameters.m_foldToTier && LArMCParticleHelper::GetHierarchyTier(pRoot) < foldParameters.m_tier) ||
645  (!foldParameters.m_foldToTier && !foldParameters.m_foldToLeadingShowers) ||
646  (foldParameters.m_foldToLeadingShowers && !(isShower || isNeutron))};
647  // Only add the node if it either has children, or is a leaf node with hits
648  if (hasChildren || (!hasChildren && !allHits.empty()))
649  {
650  Node *pNode{new Node(m_hierarchy, allParticles, allHits, this->m_tier + 1)};
651  m_children.emplace_back(pNode);
652  if (hasChildren)
653  {
654  // Find the children of this particle and recursively add them to the hierarchy
655  const MCParticleList &children{pRoot->GetDaughterList()};
656  for (const MCParticle *pChild : children)
657  pNode->FillHierarchy(pChild, foldParameters);
658  }
659  }
660  }
661  }
662 }
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 922 of file LArHierarchyHelper.h.

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

923 {
924  return m_caloHits;
925 }
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 908 of file LArHierarchyHelper.h.

909 {
910  return m_children;
911 }
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 943 of file LArHierarchyHelper.h.

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

944 {
945  return m_tier;
946 }
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 697 of file LArHierarchyHelper.cc.

698 {
699  return m_hierarchy.m_nodeToIdMap.at(this);
700 }
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 929 of file LArHierarchyHelper.h.

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

930 {
931  return m_mainParticle;
932 }
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 915 of file LArHierarchyHelper.h.

916 {
917  return m_mcParticles;
918 }
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 936 of file LArHierarchyHelper.h.

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

937 {
938  return m_pdg;
939 }
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 756 of file LArHierarchyHelper.cc.

References lar_content::LArMCParticleHelper::IsCosmicRay().

Referenced by IsNeutrinoInduced().

757 {
758  if (m_mainParticle)
760  else
761  return false;
762 }
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 957 of file LArHierarchyHelper.h.

958 {
959  return m_isLeadingLepton;
960 }
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 950 of file LArHierarchyHelper.h.

References IsCosmicRay(), and IsTestBeamParticle().

951 {
953 }
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 704 of file LArHierarchyHelper.cc.

705 {
706  const bool enoughHits{m_caloHits.size() >= m_hierarchy.m_recoCriteria.m_minHits};
707  if (!enoughHits)
708  return false;
709  bool enoughGoodViews{false};
710  unsigned int nHitsU{0}, nHitsV{0}, nHitsW{0};
711  for (const CaloHit *pCaloHit : m_caloHits)
712  {
713  switch (pCaloHit->GetHitType())
714  {
715  case TPC_VIEW_U:
716  ++nHitsU;
717  break;
718  case TPC_VIEW_V:
719  ++nHitsV;
720  break;
721  case TPC_VIEW_W:
722  ++nHitsW;
723  break;
724  default:
725  break;
726  }
727  unsigned int nGoodViews{0};
729  ++nGoodViews;
731  ++nGoodViews;
733  ++nGoodViews;
734  if (nGoodViews >= m_hierarchy.m_recoCriteria.m_minGoodViews)
735  {
736  enoughGoodViews = true;
737  break;
738  }
739  }
740 
741  return enoughGoodViews;
742 }
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 746 of file LArHierarchyHelper.cc.

References lar_content::LArMCParticleHelper::IsBeamParticle().

Referenced by IsNeutrinoInduced(), and lar_content::HierarchyValidationAlgorithm::Run().

747 {
748  if (m_mainParticle)
750  else
751  return false;
752 }
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 964 of file LArHierarchyHelper.h.

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

965 {
966  m_isLeadingLepton = true;
967 }
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 766 of file LArHierarchyHelper.cc.

References util::to_string().

767 {
768  std::string str(prefix + "PDG: " + std::to_string(m_pdg) + " Energy: " + std::to_string(m_mainParticle ? m_mainParticle->GetEnergy() : 0) +
769  " Hits: " + std::to_string(m_caloHits.size()) + "\n");
770  for (const Node *pChild : m_children)
771  str += pChild->ToString(prefix + " ");
772 
773  return str;
774 }
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 280 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 273 of file LArHierarchyHelper.h.

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

The child nodes of this node.

Definition at line 274 of file LArHierarchyHelper.h.

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

The parent MC hierarchy.

Definition at line 271 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 278 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 275 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 272 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 277 of file LArHierarchyHelper.h.

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

The hierarchy tier for this node.

Definition at line 276 of file LArHierarchyHelper.h.


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