LArSoft  v10_04_05
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 
80  QualityCuts(const float minPurity, const float minCompleteness, const bool selectRecoHits = false);
81 
82  const float m_minPurity;
83  const float m_minCompleteness;
84  const bool m_selectRecoHits;
85  };
86 
91  {
92  public:
97  {
98  public:
103 
108 
117  ReconstructabilityCriteria(const unsigned int minHits, const unsigned int minHitsForGoodView, const unsigned int minGoodViews,
118  const bool removeNeutrons);
119 
120  const unsigned int m_minHits;
121  const unsigned int m_minHitsForGoodView;
122  const unsigned int m_minGoodViews;
123  const bool m_removeNeutrons;
124  };
125 
126  class Node;
127  typedef std::vector<const Node *> NodeVector;
128  typedef std::list<const Node *> NodeList;
129  typedef std::map<const pandora::MCParticle *, NodeVector> MCNodeVectorMap;
130 
134  class Node
135  {
136  public:
144  Node(MCHierarchy &hierarchy, const pandora::MCParticle *pMCParticle, const int tier = 1);
145 
154  Node(MCHierarchy &hierarchy, const pandora::MCParticleList &mcParticleList, const pandora::CaloHitList &caloHitList, const int tier = 1);
155 
159  virtual ~Node();
160 
166  bool IsReconstructable() const;
167 
174  void FillHierarchy(const pandora::MCParticle *pRoot, const FoldingParameters &foldParameters);
175 
181  void FillFlat(const pandora::MCParticle *pRoot);
182 
188  const NodeVector &GetChildren() const;
189 
195  int GetId() const;
196 
202  const pandora::MCParticle *GetLeadingMCParticle() const;
203 
209  const pandora::MCParticleList &GetMCParticles() const;
210 
216  const pandora::CaloHitList &GetCaloHits() const;
217 
223  int GetParticleId() const;
224 
230  int GetHierarchyTier() const;
231 
237  bool IsNeutrinoInduced() const;
238 
244  bool IsTestBeamParticle() const;
245 
251  bool IsCosmicRay() const;
252 
258  bool IsLeadingLepton() const;
259 
265  const std::string ToString(const std::string &prefix) const;
266 
267  private:
271  void SetLeadingLepton();
272 
274  pandora::MCParticleList m_mcParticles;
275  pandora::CaloHitList m_caloHits;
276  NodeVector m_children;
277  const pandora::MCParticle *m_mainParticle;
278  int m_tier;
279  int m_pdg;
281 
282  friend class MCHierarchy;
283  };
284 
288  MCHierarchy();
289 
295  MCHierarchy(const ReconstructabilityCriteria &recoCriteria);
296 
300  virtual ~MCHierarchy();
301 
325  void FillHierarchy(const pandora::MCParticleList &mcParticleList, const pandora::CaloHitList &caloHitList, const FoldingParameters &foldParameters);
326 
336  void InterpretHierarchy(const pandora::MCParticle *const pRoot, pandora::MCParticleList &leadingParticles,
337  pandora::MCParticleList &childParticles, const float cosAngleTolerance) const;
338 
344  const pandora::MCParticle *GetNeutrino() const;
345 
353  const NodeVector &GetInteractions(const pandora::MCParticle *pRoot) const;
354 
360  void GetRootMCParticles(pandora::MCParticleList &rootMCParticles) const;
361 
368  void GetFlattenedNodes(const pandora::MCParticle *const pRoot, NodeVector &nodeVector) const;
369 
375  void RegisterNode(const Node *pNode);
376 
382  const std::string ToString() const;
383 
384  private:
393  void CollectContinuations(const pandora::MCParticle *pRoot, pandora::MCParticleList &continuingParticles,
394  pandora::MCParticleList &childParticles, const float cosAngleTolerance) const;
395 
403  bool IsReconstructable(const pandora::MCParticle *pMCParticle) const;
404 
412  bool IsReconstructable(const pandora::CaloHitList &caloHits) const;
413 
414  MCNodeVectorMap m_interactions;
416  std::map<const pandora::MCParticle *, pandora::CaloHitList> m_mcToHitsMap;
417  std::map<const Node *, int> m_nodeToIdMap;
419  };
420 
425  {
426  public:
427  class Node;
428  typedef std::vector<const Node *> NodeVector;
429  typedef std::list<const Node *> NodeList;
430  typedef std::map<const pandora::ParticleFlowObject *, NodeVector> RecoNodeVectorMap;
431 
435  class Node
436  {
437  public:
445  Node(const RecoHierarchy &hierarchy, const pandora::ParticleFlowObject *pPfo, const int tier = 1);
446 
455  Node(const RecoHierarchy &hierarchy, const pandora::PfoList &pfoList, const pandora::CaloHitList &caloHitList, const int tier = 1);
456 
460  virtual ~Node();
461 
468  void FillHierarchy(const pandora::ParticleFlowObject *pRoot, const FoldingParameters &foldParameters);
469 
475  void FillFlat(const pandora::ParticleFlowObject *pRoot);
476 
482  const NodeVector &GetChildren() const;
483 
489  const pandora::PfoList &GetRecoParticles() const;
490 
496  const pandora::ParticleFlowObject *GetLeadingPfo() const;
497 
503  const pandora::CaloHitList &GetCaloHits() const;
504 
511  int GetParticleId() const;
512 
518  int GetHierarchyTier() const;
519 
525  const std::string ToString(const std::string &prefix) const;
526 
527  private:
529  pandora::PfoList m_pfos;
530  pandora::CaloHitList m_caloHits;
531  NodeVector m_children;
532  const pandora::ParticleFlowObject *m_mainPfo;
533  int m_tier;
534  int m_pdg;
535  };
536 
540  RecoHierarchy();
541 
545  virtual ~RecoHierarchy();
546 
569  void FillHierarchy(const pandora::PfoList &pfoList, const FoldingParameters &foldParameters);
570 
578  const NodeVector &GetInteractions(const pandora::ParticleFlowObject *pRoot) const;
579 
585  void GetRootPfos(pandora::PfoList &rootPfos) const;
586 
593  void GetFlattenedNodes(const pandora::ParticleFlowObject *const pRoot, NodeVector &nodeVector) const;
594 
600  const pandora::ParticleFlowObject *GetNeutrino() const;
601 
607  const std::string ToString() const;
608 
609  private:
610  RecoNodeVectorMap m_interactions;
611  };
612 
613  typedef std::map<const RecoHierarchy::Node *, const pandora::CaloHitList> SelectedRecoHitsMap;
614 
618  class MCMatches
619  {
620  public:
626  MCMatches(const MCHierarchy::Node *pMCParticle);
627 
635  void AddRecoMatch(const RecoHierarchy::Node *pReco, const int nSharedHits, const pandora::CaloHitList &selectedRecoHits);
636 
642  const MCHierarchy::Node *GetMC() const;
643 
649  const RecoHierarchy::NodeVector &GetRecoMatches() const;
650 
658  const pandora::CaloHitList GetSelectedRecoHits(const RecoHierarchy::Node *pReco) const;
659 
667  unsigned int GetSharedHits(const RecoHierarchy::Node *pReco) const;
668 
677  float GetPurity(const RecoHierarchy::Node *pReco, const bool adcWeighted = false) const;
678 
688  float GetPurity(const RecoHierarchy::Node *pReco, const pandora::HitType view, const bool adcWeighted = false) const;
689 
698  float GetCompleteness(const RecoHierarchy::Node *pReco, const bool adcWeighted = false) const;
699 
709  float GetCompleteness(const RecoHierarchy::Node *pReco, const pandora::HitType view, const bool adcWeighted = false) const;
710 
716  size_t GetNRecoMatches() const;
717 
725  bool IsQuality(const QualityCuts &qualityCuts) const;
726 
727  private:
737  float GetPurity(const pandora::CaloHitVector &intersection, const pandora::CaloHitList &recoHits, const bool adcWeighted) const;
738 
748  float GetCompleteness(const pandora::CaloHitVector &intersection, const pandora::CaloHitList &mcHits, const bool adcWeighted) const;
749 
753  SelectedRecoHitsMap m_selectedRecoHitsMap;
754  };
755 
756  typedef std::vector<MCMatches> MCMatchesVector;
757  typedef std::map<const pandora::MCParticle *, MCMatchesVector> InteractionInfo;
758 
762  class MatchInfo
763  {
764  public:
771  MatchInfo(const MCHierarchy &mcHierarchy, const RecoHierarchy &recoHierarchy);
772 
780  MatchInfo(const MCHierarchy &mcHierarchy, const RecoHierarchy &recoHierarchy, const QualityCuts &qualityCuts);
781 
786  void Match();
787 
795  const MCMatchesVector &GetMatches(const pandora::MCParticle *const pRoot) const;
796 
800  const RecoHierarchy::NodeVector &GetUnmatchedReco() const;
801 
809  unsigned int GetNMCNodes(const pandora::MCParticle *const pRoot) const;
810 
818  unsigned int GetNNeutrinoMCNodes(const pandora::MCParticle *const pRoot) const;
819 
827  unsigned int GetNCosmicRayMCNodes(const pandora::MCParticle *const pRoot) const;
828 
836  unsigned int GetNTestBeamMCNodes(const pandora::MCParticle *const pRoot) const;
837 
843  const MCHierarchy &GetMCHierarchy() const;
844 
850  const RecoHierarchy &GetRecoHierarchy() const;
851 
857  void GetRootMCParticles(pandora::MCParticleList &rootMCParticles) const;
858 
864  const QualityCuts &GetQualityCuts() const;
865 
874  const pandora::CaloHitList GetSelectedRecoHits(const RecoHierarchy::Node *pRecoNode, const pandora::CaloHitList &allMCHits) const;
875 
882  void Print(const MCHierarchy &mcHierarchy) const;
883 
884  private:
887  InteractionInfo m_matches;
890  };
891 
900  static void FillMCHierarchy(const pandora::MCParticleList &mcParticleList, const pandora::CaloHitList &caloHitList,
901  const FoldingParameters &foldParameters, MCHierarchy &hierarchy);
902 
910  static void FillRecoHierarchy(const pandora::PfoList &pfoList, const FoldingParameters &foldParameters, RecoHierarchy &hierarchy);
911 
917  static void MatchHierarchies(MatchInfo &matchInfo);
918 
919 private:
920  typedef std::set<const pandora::MCParticle *> MCParticleSet;
921  typedef std::set<const pandora::ParticleFlowObject *> PfoSet;
922 
929  static void GetMCPrimaries(const pandora::MCParticle *pRoot, MCParticleSet &primaries);
930 
937  static void GetRecoPrimaries(const pandora::ParticleFlowObject *pRoot, PfoSet &primaries);
938 };
939 
940 //------------------------------------------------------------------------------------------------------------------------------------------
941 //------------------------------------------------------------------------------------------------------------------------------------------
942 
944 {
945  return m_children;
946 }
947 
948 //------------------------------------------------------------------------------------------------------------------------------------------
949 
950 inline const pandora::MCParticleList &LArHierarchyHelper::MCHierarchy::Node::GetMCParticles() const
951 {
952  return m_mcParticles;
953 }
954 
955 //------------------------------------------------------------------------------------------------------------------------------------------
956 
957 inline const pandora::CaloHitList &LArHierarchyHelper::MCHierarchy::Node::GetCaloHits() const
958 {
959  return m_caloHits;
960 }
961 
962 //------------------------------------------------------------------------------------------------------------------------------------------
963 
964 inline const pandora::MCParticle *LArHierarchyHelper::MCHierarchy::Node::GetLeadingMCParticle() const
965 {
966  return m_mainParticle;
967 }
968 
969 //------------------------------------------------------------------------------------------------------------------------------------------
970 
972 {
973  return m_pdg;
974 }
975 
976 //------------------------------------------------------------------------------------------------------------------------------------------
977 
979 {
980  return m_tier;
981 }
982 
983 //------------------------------------------------------------------------------------------------------------------------------------------
984 
986 {
988 }
989 
990 //------------------------------------------------------------------------------------------------------------------------------------------
991 
993 {
994  return m_isLeadingLepton;
995 }
996 
997 //------------------------------------------------------------------------------------------------------------------------------------------
998 
1000 {
1001  m_isLeadingLepton = true;
1002 }
1003 
1004 //------------------------------------------------------------------------------------------------------------------------------------------
1005 //------------------------------------------------------------------------------------------------------------------------------------------
1006 
1008 {
1009  return m_children;
1010 }
1011 
1012 //------------------------------------------------------------------------------------------------------------------------------------------
1013 
1014 inline const pandora::ParticleFlowObject *LArHierarchyHelper::RecoHierarchy::Node::GetLeadingPfo() const
1015 {
1016  return m_mainPfo;
1017 }
1018 
1019 //------------------------------------------------------------------------------------------------------------------------------------------
1020 //------------------------------------------------------------------------------------------------------------------------------------------
1021 
1023 {
1024  return m_tier;
1025 }
1026 
1027 //------------------------------------------------------------------------------------------------------------------------------------------
1028 //------------------------------------------------------------------------------------------------------------------------------------------
1029 
1031 {
1032  return m_pMCParticle;
1033 }
1034 
1035 //------------------------------------------------------------------------------------------------------------------------------------------
1036 
1038 {
1039  return m_recoNodes;
1040 }
1041 
1042 //------------------------------------------------------------------------------------------------------------------------------------------
1043 
1045 {
1046  return m_recoNodes.size();
1047 }
1048 
1049 //------------------------------------------------------------------------------------------------------------------------------------------
1050 //------------------------------------------------------------------------------------------------------------------------------------------
1051 
1052 inline const LArHierarchyHelper::MCMatchesVector &LArHierarchyHelper::MatchInfo::GetMatches(const pandora::MCParticle *const pRoot) const
1053 {
1054  if (m_matches.find(pRoot) == m_matches.end())
1055  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
1056 
1057  return m_matches.at(pRoot);
1058 }
1059 
1060 //------------------------------------------------------------------------------------------------------------------------------------------
1061 
1063 {
1064  return m_unmatchedReco;
1065 }
1066 
1067 //------------------------------------------------------------------------------------------------------------------------------------------
1068 
1070 {
1071  return m_mcHierarchy;
1072 }
1073 
1074 //------------------------------------------------------------------------------------------------------------------------------------------
1075 
1077 {
1078  return m_recoHierarchy;
1079 }
1080 
1081 //------------------------------------------------------------------------------------------------------------------------------------------
1082 
1084 {
1085  return m_qualityCuts;
1086 }
1087 
1088 } // namespace lar_content
1089 
1090 #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.
int m_tier
The hierarchy tier for this node.
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::map< const RecoHierarchy::Node *, const pandora::CaloHitList > SelectedRecoHitsMap
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...
int GetHierarchyTier() const
Retrieve the hierarchy tier of this 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.
SelectedRecoHitsMap m_selectedRecoHitsMap
Map storing the selected CaloHits for a given reco node.
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.
const bool m_selectRecoHits
Whether to only use reco hits that overlap with the MC particle hits.
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 node.
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.