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

RecoHierarchy class. More...

#include "LArHierarchyHelper.h"

Classes

class  Node
 Node class. More...
 

Public Types

typedef std::vector< const Node * > NodeVector
 
typedef std::list< const Node * > NodeList
 
typedef std::map< const pandora::ParticleFlowObject *, NodeVectorRecoNodeVectorMap
 

Public Member Functions

 RecoHierarchy ()
 Default constructor. More...
 
virtual ~RecoHierarchy ()
 Destructor. More...
 
void FillHierarchy (const pandora::PfoList &pfoList, const FoldingParameters &foldParameters)
 Creates a reconstructed hierarchy representation. Without folding this will be a mirror image of the standard ParticleFlowObject (PFO) relationships. However, with folding options selected the hierarchy structure will group together PFOs into nodes based on the folding requirements. More...
 
const NodeVectorGetInteractions (const pandora::ParticleFlowObject *pRoot) const
 Retrieve the root nodes in the hierarchy for a given interaction. More...
 
void GetRootPfos (pandora::PfoList &rootPfos) const
 Retrieve the root particle flow objects of the interaction hierarchies. More...
 
void GetFlattenedNodes (const pandora::ParticleFlowObject *const pRoot, NodeVector &nodeVector) const
 Retrieve a flat vector of the nodes in the hierarchy. More...
 
const pandora::ParticleFlowObject * GetNeutrino () const
 Retrieve the neutrino at the root of the hierarchy if it exists. More...
 
const std::string ToString () const
 Produce a string representation of the hierarchy. More...
 

Private Attributes

RecoNodeVectorMap m_interactions
 Map from the root PFO (e.g. neutrino) to primaries. More...
 

Detailed Description

RecoHierarchy class.

Definition at line 424 of file LArHierarchyHelper.h.

Member Typedef Documentation

Definition at line 429 of file LArHierarchyHelper.h.

Definition at line 427 of file LArHierarchyHelper.h.

typedef std::map<const pandora::ParticleFlowObject *, NodeVector> lar_content::LArHierarchyHelper::RecoHierarchy::RecoNodeVectorMap

Definition at line 430 of file LArHierarchyHelper.h.

Constructor & Destructor Documentation

lar_content::LArHierarchyHelper::RecoHierarchy::RecoHierarchy ( )

Default constructor.

Definition at line 813 of file LArHierarchyHelper.cc.

814 {
815 }
lar_content::LArHierarchyHelper::RecoHierarchy::~RecoHierarchy ( )
virtual

Destructor.

Definition at line 819 of file LArHierarchyHelper.cc.

References lar_content::LArHierarchyHelper::MCHierarchy::m_interactions.

820 {
821  for (const auto &[pRoot, nodeVector] : m_interactions)
822  {
823  for (const Node *pNode : nodeVector)
824  delete pNode;
825  }
826  m_interactions.clear();
827 }
RecoNodeVectorMap m_interactions
Map from the root PFO (e.g. neutrino) to primaries.

Member Function Documentation

void lar_content::LArHierarchyHelper::RecoHierarchy::FillHierarchy ( const pandora::PfoList &  pfoList,
const FoldingParameters foldParameters 
)

Creates a reconstructed hierarchy representation. Without folding this will be a mirror image of the standard ParticleFlowObject (PFO) relationships. However, with folding options selected the hierarchy structure will group together PFOs into nodes based on the folding requirements.

If only folding back to primaries, the hierarchy will be relatively flat, with a top-level neutrino or test beam particle, if appropriate, and then a set of leaf nodes, one for each primary particles also containing the PFOs (and corresponding hits) from daughter particles.

If only folding back to leading shower particles, the hierarchy will largely mirror the standard PFO hierarchy, but, when a shower particle is reached (based on the track/shower characterisation), this particle and all daughter particles will be represented by a single leaf node.

If folding back to both primary and leading shower particles the hierarchy will again be rather flat, but in this case, if a primary track-like particle has a downstream shower particle then all downstream particles above the shower-like particle will be folded into the primary node, but a new, daughter leaf node will be created for the shower-like particle and all of its daughters, and a parent-child relationship will be formed between the primary node and shower node.

Parameters
pfoListThe list of PFOs with which to fill the hierarchy
foldParametersThe folding parameters to use for the hierarchy

Definition at line 831 of file LArHierarchyHelper.cc.

References util::abs(), lar_content::LArPfoHelper::GetAllCaloHits(), lar_content::LArPfoHelper::GetAllDownstreamPfos(), lar_content::LArHierarchyHelper::GetRecoPrimaries(), lar_content::LArHierarchyHelper::FoldingParameters::m_foldToLeadingShowers, lar_content::LArHierarchyHelper::FoldingParameters::m_foldToTier, lar_content::LArHierarchyHelper::MCHierarchy::m_interactions, lar_content::LArHierarchyHelper::FoldingParameters::m_tier, and lar_content::LArPfoHelper::SortByNHits().

Referenced by lar_content::LArHierarchyHelper::FillRecoHierarchy().

832 {
833  PfoList rootNodes;
834  for (const ParticleFlowObject *pPfo : pfoList)
835  {
836  const PfoList &parentList{pPfo->GetParentPfoList()};
837  if (parentList.empty())
838  {
839  rootNodes.emplace_back(pPfo);
840  }
841  }
842 
843  for (const ParticleFlowObject *const pRoot : rootNodes)
844  {
845  PfoSet primarySet;
846  LArHierarchyHelper::GetRecoPrimaries(pRoot, primarySet);
847  PfoList primaries(primarySet.begin(), primarySet.end());
848  primaries.sort(LArPfoHelper::SortByNHits);
849  if (foldParameters.m_foldToTier && foldParameters.m_tier == 1)
850  {
851  for (const ParticleFlowObject *pPrimary : primaries)
852  {
853  PfoList allParticles;
854  // ATTN - pPrimary gets added to the list of downstream PFOs, not just the child PFOs
855  LArPfoHelper::GetAllDownstreamPfos(pPrimary, allParticles);
856  CaloHitList allHits;
857  for (const ParticleFlowObject *pPfo : allParticles)
858  LArPfoHelper::GetAllCaloHits(pPfo, allHits);
859  m_interactions[pRoot].emplace_back(new Node(*this, allParticles, allHits));
860  }
861  }
862  else if (foldParameters.m_foldToLeadingShowers)
863  {
864  for (const ParticleFlowObject *pPrimary : primaries)
865  {
866  PfoList allParticles;
867  int pdg{std::abs(pPrimary->GetParticleId())};
868  const bool isShower{pdg == E_MINUS};
869  // ATTN - pPrimary gets added to the list of downstream PFOs, not just the child PFOs
870  if (isShower)
871  LArPfoHelper::GetAllDownstreamPfos(pPrimary, allParticles);
872  else
873  allParticles.emplace_back(pPrimary);
874 
875  CaloHitList allHits;
876  for (const ParticleFlowObject *pPfo : allParticles)
877  LArPfoHelper::GetAllCaloHits(pPfo, allHits);
878  Node *pNode{new Node(*this, allParticles, allHits)};
879  m_interactions[pRoot].emplace_back(pNode);
880  if (!isShower)
881  {
882  // Find the children of this particle and recursively add them to the hierarchy
883  const PfoList &children{pPrimary->GetDaughterPfoList()};
884  for (const ParticleFlowObject *pChild : children)
885  pNode->FillHierarchy(pChild, foldParameters);
886  }
887  }
888  }
889  else
890  {
891  // Dynamic fold, Unfolded and fold to tier > 1 have the same behaviour for primaries
892  for (const ParticleFlowObject *pPrimary : primaries)
893  {
894  PfoList allParticles{pPrimary};
895  CaloHitList allHits;
896  for (const ParticleFlowObject *pPfo : allParticles)
897  LArPfoHelper::GetAllCaloHits(pPfo, allHits);
898  Node *pNode{new Node(*this, allParticles, allHits)};
899  m_interactions[pRoot].emplace_back(pNode);
900  // Find the children of this particle and recursively add them to the hierarchy
901  const PfoList &children{pPrimary->GetDaughterPfoList()};
902  for (const ParticleFlowObject *pChild : children)
903  pNode->FillHierarchy(pChild, foldParameters.m_foldToLeadingShowers);
904  }
905  }
906  }
907 }
static void GetRecoPrimaries(const pandora::ParticleFlowObject *pRoot, PfoSet &primaries)
Retrieves the primary PFOs from a list and returns the root (neutrino) for hierarchy, if it exists.
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
constexpr auto abs(T v)
Returns the absolute value of the argument.
static void GetAllCaloHits(const pandora::ParticleFlowObject *pPfo, pandora::CaloHitList &caloHitList)
Get a list of all calo hits (including isolated) of all types from a given pfo.
Definition: LArPfoHelper.cc:76
RecoNodeVectorMap m_interactions
Map from the root PFO (e.g. neutrino) to primaries.
static void GetAllDownstreamPfos(const pandora::PfoList &inputPfoList, pandora::PfoList &outputPfoList)
Get a flat list of all pfos, recursively, of all daughters associated with those pfos in an input lis...
std::set< const pandora::ParticleFlowObject * > PfoSet
void lar_content::LArHierarchyHelper::RecoHierarchy::GetFlattenedNodes ( const pandora::ParticleFlowObject *const  pRoot,
NodeVector nodeVector 
) const

Retrieve a flat vector of the nodes in the hierarchy.

Parameters
pRootThe root particle flow object for an interaction
nodeVectorThe output vector for the nodes in the hierarchy in breadth first order

Definition at line 929 of file LArHierarchyHelper.cc.

References lar_content::LArHierarchyHelper::MCHierarchy::m_interactions.

Referenced by lar_content::LArHierarchyHelper::MatchInfo::Match(), and lar_content::HierarchyMonitoringAlgorithm::Run().

930 {
931  NodeList queue;
932  for (const Node *pNode : m_interactions.at(pRoot))
933  {
934  nodeVector.emplace_back(pNode);
935  queue.emplace_back(pNode);
936  }
937  while (!queue.empty())
938  {
939  const NodeVector &children{queue.front()->GetChildren()};
940  queue.pop_front();
941  for (const Node *pChild : children)
942  {
943  nodeVector.emplace_back(pChild);
944  queue.emplace_back(pChild);
945  }
946  }
947 }
RecoNodeVectorMap m_interactions
Map from the root PFO (e.g. neutrino) to primaries.
const LArHierarchyHelper::RecoHierarchy::NodeVector & lar_content::LArHierarchyHelper::RecoHierarchy::GetInteractions ( const pandora::ParticleFlowObject *  pRoot) const

Retrieve the root nodes in the hierarchy for a given interaction.

Parameters
pRootThe root of the interaction hierarchy
Returns
The root nodes in this hierarchy

Definition at line 911 of file LArHierarchyHelper.cc.

References lar_content::LArHierarchyHelper::MCHierarchy::m_interactions.

912 {
913  if (m_interactions.find(pRoot) == m_interactions.end())
914  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
915 
916  return m_interactions.at(pRoot);
917 }
RecoNodeVectorMap m_interactions
Map from the root PFO (e.g. neutrino) to primaries.
const pandora::ParticleFlowObject* lar_content::LArHierarchyHelper::RecoHierarchy::GetNeutrino ( ) const

Retrieve the neutrino at the root of the hierarchy if it exists.

Returns
The address of the incident neutrino (nullptr if it doesn't exist)
void lar_content::LArHierarchyHelper::RecoHierarchy::GetRootPfos ( pandora::PfoList &  rootPfos) const

Retrieve the root particle flow objects of the interaction hierarchies.

Parameters
rootPfosThe output list of root particle flow objects

Definition at line 921 of file LArHierarchyHelper.cc.

References lar_content::LArHierarchyHelper::MCHierarchy::m_interactions.

Referenced by lar_content::LArHierarchyHelper::MatchInfo::Match(), lar_content::HierarchyValidationAlgorithm::Run(), and lar_content::HierarchyMonitoringAlgorithm::Run().

922 {
923  for (auto iter = m_interactions.begin(); iter != m_interactions.end(); ++iter)
924  rootPfos.emplace_back(iter->first);
925 }
RecoNodeVectorMap m_interactions
Map from the root PFO (e.g. neutrino) to primaries.
const std::string lar_content::LArHierarchyHelper::RecoHierarchy::ToString ( ) const

Produce a string representation of the hierarchy.

Returns
The string representation of the hierarchy

Definition at line 951 of file LArHierarchyHelper.cc.

References lar_content::LArHierarchyHelper::MCHierarchy::m_interactions, and util::to_string().

Referenced by lar_content::HierarchyMonitoringAlgorithm::Run().

952 {
953  std::string str;
954  for (const auto &[pRoot, nodeVector] : m_interactions)
955  {
956  str += "=== Reco Interaction : PDG " + std::to_string(pRoot->GetParticleId()) + "\n";
957  for (const Node *pNode : nodeVector)
958  str += " " + pNode->ToString("") + "\n";
959  }
960 
961  return str;
962 }
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
RecoNodeVectorMap m_interactions
Map from the root PFO (e.g. neutrino) to primaries.

Member Data Documentation

RecoNodeVectorMap lar_content::LArHierarchyHelper::RecoHierarchy::m_interactions
private

Map from the root PFO (e.g. neutrino) to primaries.

Definition at line 610 of file LArHierarchyHelper.h.


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