LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArHierarchyHelper.h
Go to the documentation of this file.
1 
8 #ifndef LAR_HIERARCHY_HELPER_H
9 #define LAR_HIERARCHY_HELPER_H 1
10 
11 #include "Pandora/PandoraInternal.h"
12 
13 #include "Helpers/MCParticleHelper.h"
14 
17 
18 namespace lar_content
19 {
20 
25 {
26 public:
31  {
32  public:
37 
43  FoldingParameters(const bool foldDynamic, const float cosAngleTolerance = 0.9962f);
44 
53  FoldingParameters(const int foldingTier);
54 
56  bool m_foldToTier;
59  int m_tier;
60  };
61 
66  {
67  public:
71  QualityCuts();
72 
79  QualityCuts(const float minPurity, const float minCompleteness);
80 
81  const float m_minPurity;
82  const float m_minCompleteness;
83  };
84 
89  {
90  public:
95  {
96  public:
101 
106 
115  ReconstructabilityCriteria(const unsigned int minHits, const unsigned int minHitsForGoodView, const unsigned int minGoodViews,
116  const bool removeNeutrons);
117 
118  const unsigned int m_minHits;
119  const unsigned int m_minHitsForGoodView;
120  const unsigned int m_minGoodViews;
121  const bool m_removeNeutrons;
122  };
123 
124  class Node;
125  typedef std::vector<const Node *> NodeVector;
126  typedef std::list<const Node *> NodeList;
127  typedef std::map<const pandora::MCParticle *, NodeVector> MCNodeVectorMap;
128 
132  class Node
133  {
134  public:
142  Node(MCHierarchy &hierarchy, const pandora::MCParticle *pMCParticle, const int tier = 1);
143 
152  Node(MCHierarchy &hierarchy, const pandora::MCParticleList &mcParticleList, const pandora::CaloHitList &caloHitList, const int tier = 1);
153 
157  virtual ~Node();
158 
164  bool IsReconstructable() const;
165 
172  void FillHierarchy(const pandora::MCParticle *pRoot, const FoldingParameters &foldParameters);
173 
179  void FillFlat(const pandora::MCParticle *pRoot);
180 
186  const NodeVector &GetChildren() const;
187 
193  int GetId() const;
194 
200  const pandora::MCParticle *GetLeadingMCParticle() const;
201 
207  const pandora::MCParticleList &GetMCParticles() const;
208 
214  const pandora::CaloHitList &GetCaloHits() const;
215 
221  int GetParticleId() const;
222 
228  int GetHierarchyTier() const;
229 
235  bool IsNeutrinoInduced() const;
236 
242  bool IsTestBeamParticle() const;
243 
249  bool IsCosmicRay() const;
250 
256  bool IsLeadingLepton() const;
257 
263  const std::string ToString(const std::string &prefix) const;
264 
265  private:
269  void SetLeadingLepton();
270 
272  pandora::MCParticleList m_mcParticles;
273  pandora::CaloHitList m_caloHits;
274  NodeVector m_children;
275  const pandora::MCParticle *m_mainParticle;
276  int m_tier;
277  int m_pdg;
279 
280  friend class MCHierarchy;
281  };
282 
286  MCHierarchy();
287 
293  MCHierarchy(const ReconstructabilityCriteria &recoCriteria);
294 
298  virtual ~MCHierarchy();
299 
323  void FillHierarchy(const pandora::MCParticleList &mcParticleList, const pandora::CaloHitList &caloHitList, const FoldingParameters &foldParameters);
324 
334  void InterpretHierarchy(const pandora::MCParticle *const pRoot, pandora::MCParticleList &leadingParticles,
335  pandora::MCParticleList &childParticles, const float cosAngleTolerance) const;
336 
342  const pandora::MCParticle *GetNeutrino() const;
343 
351  const NodeVector &GetInteractions(const pandora::MCParticle *pRoot) const;
352 
358  void GetRootMCParticles(pandora::MCParticleList &rootMCParticles) const;
359 
366  void GetFlattenedNodes(const pandora::MCParticle *const pRoot, NodeVector &nodeVector) const;
367 
373  void RegisterNode(const Node *pNode);
374 
380  const std::string ToString() const;
381 
382  private:
391  void CollectContinuations(const pandora::MCParticle *pRoot, pandora::MCParticleList &continuingParticles,
392  pandora::MCParticleList &childParticles, const float cosAngleTolerance) const;
393 
401  bool IsReconstructable(const pandora::MCParticle *pMCParticle) const;
402 
410  bool IsReconstructable(const pandora::CaloHitList &caloHits) const;
411 
412  MCNodeVectorMap m_interactions;
414  std::map<const pandora::MCParticle *, pandora::CaloHitList> m_mcToHitsMap;
415  std::map<const Node *, int> m_nodeToIdMap;
417  };
418 
423  {
424  public:
425  class Node;
426  typedef std::vector<const Node *> NodeVector;
427  typedef std::list<const Node *> NodeList;
428  typedef std::map<const pandora::ParticleFlowObject *, NodeVector> RecoNodeVectorMap;
429 
433  class Node
434  {
435  public:
442  Node(const RecoHierarchy &hierarchy, const pandora::ParticleFlowObject *pPfo);
443 
451  Node(const RecoHierarchy &hierarchy, const pandora::PfoList &pfoList, const pandora::CaloHitList &caloHitList);
452 
456  virtual ~Node();
457 
464  void FillHierarchy(const pandora::ParticleFlowObject *pRoot, const FoldingParameters &foldParameters);
465 
471  void FillFlat(const pandora::ParticleFlowObject *pRoot);
472 
478  const NodeVector &GetChildren() const;
479 
485  const pandora::PfoList &GetRecoParticles() const;
486 
492  const pandora::ParticleFlowObject *GetLeadingPfo() const;
493 
499  const pandora::CaloHitList &GetCaloHits() const;
500 
507  int GetParticleId() const;
508 
514  const std::string ToString(const std::string &prefix) const;
515 
516  private:
518  pandora::PfoList m_pfos;
519  pandora::CaloHitList m_caloHits;
520  NodeVector m_children;
521  const pandora::ParticleFlowObject *m_mainPfo;
522  int m_pdg;
523  };
524 
528  RecoHierarchy();
529 
533  virtual ~RecoHierarchy();
534 
557  void FillHierarchy(const pandora::PfoList &pfoList, const FoldingParameters &foldParameters);
558 
566  const NodeVector &GetInteractions(const pandora::ParticleFlowObject *pRoot) const;
567 
573  void GetRootPfos(pandora::PfoList &rootPfos) const;
574 
581  void GetFlattenedNodes(const pandora::ParticleFlowObject *const pRoot, NodeVector &nodeVector) const;
582 
588  const pandora::ParticleFlowObject *GetNeutrino() const;
589 
595  const std::string ToString() const;
596 
597  private:
598  RecoNodeVectorMap m_interactions;
599  };
600 
604  class MCMatches
605  {
606  public:
612  MCMatches(const MCHierarchy::Node *pMCParticle);
613 
620  void AddRecoMatch(const RecoHierarchy::Node *pReco, const int nSharedHits);
621 
627  const MCHierarchy::Node *GetMC() const;
628 
634  const RecoHierarchy::NodeVector &GetRecoMatches() const;
635 
643  unsigned int GetSharedHits(const RecoHierarchy::Node *pReco) const;
644 
653  float GetPurity(const RecoHierarchy::Node *pReco, const bool adcWeighted = false) const;
654 
664  float GetPurity(const RecoHierarchy::Node *pReco, const pandora::HitType view, const bool adcWeighted = false) const;
665 
674  float GetCompleteness(const RecoHierarchy::Node *pReco, const bool adcWeighted = false) const;
675 
685  float GetCompleteness(const RecoHierarchy::Node *pReco, const pandora::HitType view, const bool adcWeighted = false) const;
686 
692  size_t GetNRecoMatches() const;
693 
701  bool IsQuality(const QualityCuts &qualityCuts) const;
702 
703  private:
713  float GetPurity(const pandora::CaloHitVector &intersection, const pandora::CaloHitList &recoHits, const bool adcWeighted) const;
714 
724  float GetCompleteness(const pandora::CaloHitVector &intersection, const pandora::CaloHitList &mcHits, const bool adcWeighted) const;
725 
729  };
730 
731  typedef std::vector<MCMatches> MCMatchesVector;
732  typedef std::map<const pandora::MCParticle *, MCMatchesVector> InteractionInfo;
733 
737  class MatchInfo
738  {
739  public:
746  MatchInfo(const MCHierarchy &mcHierarchy, const RecoHierarchy &recoHierarchy);
747 
755  MatchInfo(const MCHierarchy &mcHierarchy, const RecoHierarchy &recoHierarchy, const QualityCuts &qualityCuts);
756 
761  void Match();
762 
770  const MCMatchesVector &GetMatches(const pandora::MCParticle *const pRoot) const;
771 
775  const RecoHierarchy::NodeVector &GetUnmatchedReco() const;
776 
784  unsigned int GetNMCNodes(const pandora::MCParticle *const pRoot) const;
785 
793  unsigned int GetNNeutrinoMCNodes(const pandora::MCParticle *const pRoot) const;
794 
802  unsigned int GetNCosmicRayMCNodes(const pandora::MCParticle *const pRoot) const;
803 
811  unsigned int GetNTestBeamMCNodes(const pandora::MCParticle *const pRoot) const;
812 
818  const MCHierarchy &GetMCHierarchy() const;
819 
825  const RecoHierarchy &GetRecoHierarchy() const;
826 
832  void GetRootMCParticles(pandora::MCParticleList &rootMCParticles) const;
833 
839  const QualityCuts &GetQualityCuts() const;
840 
847  void Print(const MCHierarchy &mcHierarchy) const;
848 
849  private:
852  InteractionInfo m_matches;
855  };
856 
865  static void FillMCHierarchy(const pandora::MCParticleList &mcParticleList, const pandora::CaloHitList &caloHitList,
866  const FoldingParameters &foldParameters, MCHierarchy &hierarchy);
867 
875  static void FillRecoHierarchy(const pandora::PfoList &pfoList, const FoldingParameters &foldParameters, RecoHierarchy &hierarchy);
876 
882  static void MatchHierarchies(MatchInfo &matchInfo);
883 
884 private:
885  typedef std::set<const pandora::MCParticle *> MCParticleSet;
886  typedef std::set<const pandora::ParticleFlowObject *> PfoSet;
887 
894  static void GetMCPrimaries(const pandora::MCParticle *pRoot, MCParticleSet &primaries);
895 
902  static void GetRecoPrimaries(const pandora::ParticleFlowObject *pRoot, PfoSet &primaries);
903 };
904 
905 //------------------------------------------------------------------------------------------------------------------------------------------
906 //------------------------------------------------------------------------------------------------------------------------------------------
907 
909 {
910  return m_children;
911 }
912 
913 //------------------------------------------------------------------------------------------------------------------------------------------
914 
915 inline const pandora::MCParticleList &LArHierarchyHelper::MCHierarchy::Node::GetMCParticles() const
916 {
917  return m_mcParticles;
918 }
919 
920 //------------------------------------------------------------------------------------------------------------------------------------------
921 
922 inline const pandora::CaloHitList &LArHierarchyHelper::MCHierarchy::Node::GetCaloHits() const
923 {
924  return m_caloHits;
925 }
926 
927 //------------------------------------------------------------------------------------------------------------------------------------------
928 
929 inline const pandora::MCParticle *LArHierarchyHelper::MCHierarchy::Node::GetLeadingMCParticle() const
930 {
931  return m_mainParticle;
932 }
933 
934 //------------------------------------------------------------------------------------------------------------------------------------------
935 
937 {
938  return m_pdg;
939 }
940 
941 //------------------------------------------------------------------------------------------------------------------------------------------
942 
944 {
945  return m_tier;
946 }
947 
948 //------------------------------------------------------------------------------------------------------------------------------------------
949 
951 {
953 }
954 
955 //------------------------------------------------------------------------------------------------------------------------------------------
956 
958 {
959  return m_isLeadingLepton;
960 }
961 
962 //------------------------------------------------------------------------------------------------------------------------------------------
963 
965 {
966  m_isLeadingLepton = true;
967 }
968 
969 //------------------------------------------------------------------------------------------------------------------------------------------
970 //------------------------------------------------------------------------------------------------------------------------------------------
971 
973 {
974  return m_children;
975 }
976 
977 //------------------------------------------------------------------------------------------------------------------------------------------
978 
979 inline const pandora::ParticleFlowObject *LArHierarchyHelper::RecoHierarchy::Node::GetLeadingPfo() const
980 {
981  return m_mainPfo;
982 }
983 
984 //------------------------------------------------------------------------------------------------------------------------------------------
985 //------------------------------------------------------------------------------------------------------------------------------------------
986 
988 {
989  return m_pMCParticle;
990 }
991 
992 //------------------------------------------------------------------------------------------------------------------------------------------
993 
995 {
996  return m_recoNodes;
997 }
998 
999 //------------------------------------------------------------------------------------------------------------------------------------------
1000 
1002 {
1003  return m_recoNodes.size();
1004 }
1005 
1006 //------------------------------------------------------------------------------------------------------------------------------------------
1007 //------------------------------------------------------------------------------------------------------------------------------------------
1008 
1009 inline const LArHierarchyHelper::MCMatchesVector &LArHierarchyHelper::MatchInfo::GetMatches(const pandora::MCParticle *const pRoot) const
1010 {
1011  if (m_matches.find(pRoot) == m_matches.end())
1012  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
1013 
1014  return m_matches.at(pRoot);
1015 }
1016 
1017 //------------------------------------------------------------------------------------------------------------------------------------------
1018 
1020 {
1021  return m_unmatchedReco;
1022 }
1023 
1024 //------------------------------------------------------------------------------------------------------------------------------------------
1025 
1027 {
1028  return m_mcHierarchy;
1029 }
1030 
1031 //------------------------------------------------------------------------------------------------------------------------------------------
1032 
1034 {
1035  return m_recoHierarchy;
1036 }
1037 
1038 //------------------------------------------------------------------------------------------------------------------------------------------
1039 
1041 {
1042  return m_qualityCuts;
1043 }
1044 
1045 } // namespace lar_content
1046 
1047 #endif // #ifndef LAR_HIERARCHY_HELPER_H
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.
const unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
std::set< const pandora::MCParticle * > MCParticleSet
Header file for the pfo helper class.
const MCMatchesVector & GetMatches(const pandora::MCParticle *const pRoot) const
Retrieve the vector of matches (this will include null matches - i.e. MC nodes with no corresponding ...
const RecoHierarchy & GetRecoHierarchy() const
Retrieve the reco hierarchy used for the matching.
const MCHierarchy::Node * m_pMCParticle
MC node associated with any matches.
const NodeVector & GetChildren() const
Return the vector of children for this node.
bool m_foldToTier
Whether or not to apply folding based on particle tier.
int m_tier
If folding to a tier, the tier to be combined with its child particles.
RecoHierarchy::NodeVector m_recoNodes
Matched reco nodes.
const pandora::ParticleFlowObject * GetLeadingPfo() const
Retrieve the leading reco particle for this node.
pandora::IntVector m_sharedHits
Number of shared hits for each match.
int m_pdg
The PDG code of the leading MC particle for this node.
std::map< const pandora::MCParticle *, pandora::CaloHitList > m_mcToHitsMap
The map between MC particles and calo hits.
static void GetMCPrimaries(const pandora::MCParticle *pRoot, MCParticleSet &primaries)
Retrieves the primary MC particles from a list and returns the root (neutrino) for hierarchy...
const RecoHierarchy & m_hierarchy
The parent reco hierarchy.
const RecoHierarchy::NodeVector & GetRecoMatches() const
Retrieve the vector of matched reco nodes.
int m_pdg
The particle ID (track = muon, shower = electron)
std::map< const pandora::ParticleFlowObject *, NodeVector > RecoNodeVectorMap
QualityCuts m_qualityCuts
The quality cuts to be applied to matches.
std::vector< int > IntVector
size_t GetNRecoMatches() const
Get the number of reco nodes matched (both above and below quality cut thresholds) to the MC node...
const pandora::CaloHitList & GetCaloHits() const
Retrieve the CaloHits associated with this node.
bool m_isLeadingLepton
Whether or not this node is the leading lepton.
static void MatchHierarchies(MatchInfo &matchInfo)
Finds the matches between reconstructed and MC hierarchies.
pandora::CaloHitList m_caloHits
The list of calo hits of which this node is composed.
const MCHierarchy::Node * GetMC() const
Retrieve the MC node.
TFile f
Definition: plotHisto.C:6
static void FillRecoHierarchy(const pandora::PfoList &pfoList, const FoldingParameters &foldParameters, RecoHierarchy &hierarchy)
Fill a reconstructed hierarchy based on the specified folding criteria (see RecoHierarchy::FillHierar...
const pandora::MCParticle * GetLeadingMCParticle() const
Retrieve the leading MC particle associated with this node.
Header file for the lar monte carlo particle helper helper class.
RecoNodeVectorMap m_interactions
Map from the root PFO (e.g. neutrino) to primaries.
const float m_minPurity
The minimum purity for a match to be considered good.
NodeVector m_children
The child nodes of this node.
bool IsCosmicRay() const
Check if this is a cosmic ray particle.
int GetParticleId() const
Retrieve the PDG code for the leading particle in this node.
pandora::PfoList m_pfos
The list of PFOs of which this node is composed.
float m_cosAngleTolerance
Cosine of the maximum angle at which topologies can be considered continuous.
void Print(G4Element &ele)
Definition: pyG4Element.cc:55
NodeVector m_children
The child nodes of this nodea.
LArHierarchyHelper class.
const QualityCuts & GetQualityCuts() const
Retrieve the quality cuts for matching.
bool IsLeadingLepton() const
Returns whether or not this particle is the leading lepton in the event.
bool m_foldDynamic
Whether or not to use process and topological information to make folding decisions.
const RecoHierarchy::NodeVector & GetUnmatchedReco() const
Retrieve the vector of unmatched reco nodes.
ReconstructabilityCriteria m_recoCriteria
The criteria used to determine if the node is reconstructable.
const NodeVector & GetChildren() const
Return the vector of children for this node.
bool m_foldToLeadingShowers
Whether or not to fold shower children to the leading shower particle.
MCHierarchy & m_hierarchy
The parent MC hierarchy.
const bool m_removeNeutrons
whether to remove neutrons and their downstream particles
int GetHierarchyTier() const
Retrieve the hierarchy tier of this node.
const pandora::MCParticle * m_mainParticle
The leading MC particle for this node.
const pandora::ParticleFlowObject * m_mainPfo
The leading particle flow object for this node.
std::vector< MCMatches > MCMatchesVector
pandora::CaloHitList m_caloHits
The list of calo hits of which this node is composed.
HitType
Definition: HitType.h:12
const MCHierarchy & GetMCHierarchy() const
Retrieve the MC hierarchy used for the matching.
const MCHierarchy & m_mcHierarchy
The MC hierarchy for the matching procedure.
void SetLeadingLepton()
Tags the particle as the leading lepton.
const RecoHierarchy & m_recoHierarchy
The Reco hierarchy for the matching procedure.
static void FillMCHierarchy(const pandora::MCParticleList &mcParticleList, const pandora::CaloHitList &caloHitList, const FoldingParameters &foldParameters, MCHierarchy &hierarchy)
Fill an MC hierarchy based on the specified folding criteria (see MCHierarchy::FillHierarchy for deta...
pandora::MCParticleList m_mcParticles
The list of MC particles of which this node is composed.
int m_nextNodeId
The ID to use for the next node.
const unsigned int m_minHits
the minimum number of primary good Hits
RecoHierarchy::NodeVector m_unmatchedReco
The vector of unmatched reco nodes.
int m_tier
The hierarchy tier for this node.
const unsigned int m_minGoodViews
the minimum number of primary good views
const pandora::MCParticleList & GetMCParticles() const
Retrieve the MC particles associated with this node.
MCNodeVectorMap m_interactions
Map from incident particles (e.g. neutrino) to primaries.
bool IsNeutrinoInduced() const
Check if this is a particle induced by a neutrino interaction.
std::map< const pandora::MCParticle *, MCMatchesVector > InteractionInfo
std::map< const pandora::MCParticle *, NodeVector > MCNodeVectorMap
bool IsTestBeamParticle() const
Check if this is a test beam particle.
std::set< const pandora::ParticleFlowObject * > PfoSet
const float m_minCompleteness
The minimum completeness for a match to be considered good.
std::map< const Node *, int > m_nodeToIdMap
A map from nodes to unique ids.
InteractionInfo m_matches
The map between an interaction and the vector of good matches from MC to reco.