LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::LArMCParticleHelper Class Reference

LArMCParticleHelper class. More...

#include "LArMCParticleHelper.h"

Classes

class  PrimaryParameters
 PrimaryParameters class. More...
 

Public Types

typedef std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
 
typedef std::unordered_map< const pandora::MCParticle *, int > MCParticleIntMap
 
typedef std::unordered_map< const pandora::MCParticle *, const pandora::ParticleFlowObject * > MCToPfoMap
 
typedef std::unordered_map< const pandora::CaloHit *, const pandora::MCParticle * > CaloHitToMCMap
 
typedef std::unordered_map< const pandora::CaloHit *, const pandora::ParticleFlowObject * > CaloHitToPfoMap
 
typedef std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
 
typedef std::vector< MCContributionMapMCContributionMapVector
 
typedef std::unordered_map< const pandora::Cluster *, pandora::CaloHitList > ClusterContributionMap
 
typedef std::unordered_map< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoContributionMap
 
typedef std::unordered_map< const pandora::MCParticle *, PfoContributionMapMCToPfoMatchingMap
 
typedef std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
 
typedef std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
 
typedef std::pair< const pandora::Cluster *, pandora::CaloHitList > ClusterCaloHitListPair
 
typedef std::vector< MCParticleCaloHitListPairMCParticleToSharedHitsVector
 
typedef std::vector< PfoCaloHitListPairPfoToSharedHitsVector
 
typedef std::map< const pandora::ParticleFlowObject *, MCParticleToSharedHitsVectorPfoToMCParticleHitSharingMap
 
typedef std::map< const pandora::MCParticle *, PfoToSharedHitsVectorMCParticleToPfoHitSharingMap
 

Static Public Member Functions

static bool DoesPrimaryMeetCriteria (const pandora::MCParticle *const pMCParticle, std::function< bool(const pandora::MCParticle *const)> fCriteria)
 Returns true if passed particle whose primary meets the passed criteria. More...
 
static bool DoesLeadingMeetCriteria (const pandora::MCParticle *const pMCParticle, std::function< bool(const pandora::MCParticle *const)> fCriteria)
 Returns true if passed particle whose leading meets the passed criteria. More...
 
static bool IsBeamNeutrinoFinalState (const pandora::MCParticle *const pMCParticle)
 Returns true if passed a primary neutrino final state MCParticle. More...
 
static bool IsTriggeredBeamParticle (const pandora::MCParticle *const pMCParticle)
 Returns true if passed a primary triggered beam MCParticle. More...
 
static bool IsBeamParticle (const pandora::MCParticle *const pMCParticle)
 Returns true if passed a primary beam MCParticle. More...
 
static bool IsLeadingBeamParticle (const pandora::MCParticle *const pMCParticle)
 Returns true if passed a leading beam MCParticle. More...
 
static bool IsCosmicRay (const pandora::MCParticle *const pMCParticle)
 Return true if passed a primary cosmic ray MCParticle. More...
 
static unsigned int GetNuanceCode (const pandora::MCParticle *const pMCParticle)
 Get the nuance code of an MCParticle. More...
 
static bool IsNeutrino (const pandora::MCParticle *const pMCParticle)
 Whether a mc particle is a neutrino or antineutrino. More...
 
static bool IsPrimary (const pandora::MCParticle *const pMCParticle)
 Whether a provided mc particle matches the implemented definition of being primary. More...
 
static bool IsLeading (const pandora::MCParticle *const pMCParticle)
 Whether a provided mc particle matches the implemented definition of being leading. More...
 
static int GetHierarchyTier (const pandora::MCParticle *const pMCParticle)
 Determine the position in the hierarchy for the MCParticle. More...
 
static bool IsVisible (const pandora::MCParticle *const pMCParticle)
 Whether a mc particle is visible (i.e. long-lived charged particle) More...
 
static void GetTrueNeutrinos (const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueNeutrinos)
 Get neutrino MC particles from an input MC particle list. More...
 
static void GetTrueTestBeamParticles (const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueTestBeamParticles)
 Get triggered test beam MC particles from an input MC particle list. More...
 
static void GetFirstVisibleMCParticles (const pandora::MCParticle *const pRoot, pandora::MCParticleList &visibleParticleList)
 Get the first visible MC particles given a root particle. For example, given a neutrino this would return the primaries (the visible final state particles or the first visible descendents of invisible final state particles - note photons and neutrons are considered visible for this purpose). More...
 
static const pandora::MCParticle * GetPrimaryMCParticle (const pandora::MCParticle *const pMCParticle)
 Get the primary parent mc particle. More...
 
static const pandora::MCParticle * GetLeadingMCParticle (const pandora::MCParticle *const pMCParticle, const int hierarchyTierLimit=1)
 Get the leading particle in the hierarchy, for use at ProtoDUNE. More...
 
static void GetPrimaryMCParticleList (const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcPrimaryVector)
 Get vector of primary MC particles from an input list of MC particles. More...
 
static void GetLeadingMCParticleList (const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcLeadingVector)
 Get vector of leading MC particles from an input list of MC particles. More...
 
static const pandora::MCParticle * GetParentMCParticle (const pandora::MCParticle *const pMCParticle)
 Get the parent mc particle. More...
 
static void GetAllDescendentMCParticles (const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &descendentMCParticleList)
 Get all descendent mc particles. More...
 
static void GetAllDescendentMCParticles (const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &descendentTrackParticles, pandora::MCParticleList &leadingShowerParticles, pandora::MCParticleList &leadingNeutrons)
 Get all descendent mc particles, separated into track-like, shower-like and neutron branches. This method collects together all track-like particles (i.e. not electron, photon or neutron) downstream of the root particle, stopping at a leading shower or neutron and then storing that leading shower or neutron in a separate list. More...
 
static void GetAllAncestorMCParticles (const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &ancestorMCParticleList)
 Get all ancestor mc particles. More...
 
static void GetMCPrimaryMap (const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcPrimaryMap)
 Get mapping from individual mc particles (in a provided list) and their primary parent mc particles. More...
 
static void GetMCLeadingMap (const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcLeadingMap)
 Get mapping from individual mc particles (in a provided list) and their leading parent mc particles. More...
 
static void GetMCToSelfMap (const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcToSelfMap)
 Get mapping from individual mc particles (in a provided list) to themselves (to be used when not folding particles to their primaries) More...
 
static const pandora::MCParticle * GetMainMCParticle (const pandora::ParticleFlowObject *const pPfo)
 Find the mc particle making the largest contribution to 2D clusters in a specified pfo. More...
 
static bool SortByMomentum (const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
 Sort mc particles by their momentum. More...
 
static void GetMCParticleToCaloHitMatches (const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, CaloHitToMCMap &hitToMCMap, MCContributionMap &mcToTrueHitListMap)
 Match calo hits to their parent particles. More...
 
static void SelectReconstructableMCParticles (const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters &parameters, std::function< bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap)
 Select target, reconstructable mc particles that match given criteria. More...
 
static void SelectReconstructableTestBeamHierarchyMCParticles (const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters &parameters, std::function< bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap)
 Select target, reconstructable mc particles in the relevant hierarchy that match given criteria. More...
 
static void GetPfoToReconstructable2DHitsMap (const pandora::PfoList &pfoList, const MCContributionMap &selectedMCParticleToHitsMap, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy)
 Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void GetTestBeamHierarchyPfoToReconstructable2DHitsMap (const pandora::PfoList &pfoList, const MCContributionMap &selectedMCParticleToHitsMap, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy)
 Get mapping from Pfo in reconstructed test beam hierarchy to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void GetPfoToReconstructable2DHitsMap (const pandora::PfoList &pfoList, const MCContributionMapVector &selectedMCParticleToHitsMaps, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy)
 Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void GetTestBeamHierarchyPfoToReconstructable2DHitsMap (const pandora::PfoList &pfoList, const MCContributionMapVector &selectedMCParticleToHitsMaps, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy)
 Get mapping from Pfo in reconstructed test beam hierarchy to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void GetClusterToReconstructable2DHitsMap (const pandora::ClusterList &clusterList, const MCContributionMap &selectedMCToHitsMap, ClusterContributionMap &clusterToReconstructable2DHitsMap)
 Get mapping from cluster to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void GetClusterToReconstructable2DHitsMap (const pandora::ClusterList &clusterList, const MCContributionMapVector &selectedMCToHitsMaps, ClusterContributionMap &clusterToReconstructable2DHitsMap)
 Get mapping from cluster to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void GetPfoMCParticleHitSharingMaps (const PfoContributionMap &pfoToReconstructable2DHitsMap, const MCContributionMapVector &selectedMCParticleToHitsMaps, PfoToMCParticleHitSharingMap &pfoToMCParticleHitSharingMap, MCParticleToPfoHitSharingMap &mcParticleToPfoHitSharingMap)
 Get the mappings from Pfo -> pair (reconstructable MCparticles, number of reconstructable 2D hits shared with Pfo) reconstructable MCParticle -> pair (Pfo, number of reconstructable 2D hits shared with MCParticle) More...
 
static void SelectCaloHits (const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, pandora::CaloHitList &selectedCaloHitList, const bool selectInputHits, const float maxPhotonPropagation)
 Select a subset of calo hits representing those that represent "reconstructable" regions of the event. More...
 
static bool IsDescendentOf (const pandora::MCParticle *const pMCParticle, const int pdg, const bool isChargeSensitive=false)
 Determine if the MC particle is a descendent of a particle with the given PDG code. More...
 
static void GetBreadthFirstHierarchyRepresentation (const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &mcParticleList)
 Retrieve a linearised representation of the MC particle hierarchy in breadth first order. This iterates over the MC hierarchy in a manor that sees primaries at the front of the list, with progressively deeper tiers later in the list. This is useful for some visualisation cases. More...
 
static void SelectParticlesByHitCount (const pandora::MCParticleVector &candidateTargets, const MCContributionMap &mcToTrueHitListMap, const MCRelationMap &mcToTargetMCMap, const PrimaryParameters &parameters, MCContributionMap &selectedMCParticlesToHitsMap)
 Filter an input vector of MCParticles to ensure they have sufficient good hits to be reconstructable. More...
 
static pandora::CaloHitList GetSharedHits (const pandora::CaloHitList &hitListA, const pandora::CaloHitList &hitListB)
 Get the hits in the intersection of two hit lists. More...
 
static bool IsBremsstrahlung (const pandora::MCParticle *const pMCParticle)
 
static bool IsCapture (const pandora::MCParticle *const pMCParticle)
 Check whether or not an MC particle comes from a capture process. More...
 
static bool IsDecay (const pandora::MCParticle *const pMCParticle)
 Check whether or not an MC particle comes from a decay process. More...
 
static bool IsElasticScatter (const pandora::MCParticle *const pMCParticle)
 Check whether or not an MC particle came from an elastic scattering process. More...
 
static bool IsInelasticScatter (const pandora::MCParticle *const pMCParticle)
 Check whether or not an MC particle came from an inelastic scattering process. More...
 
static bool IsIonisation (const pandora::MCParticle *const pMCParticle)
 Check whether or not an MC particle comes from an ionisation process. More...
 
static bool IsNuclear (const pandora::MCParticle *const pMCParticle)
 Check whether or not an MC particle comes from a nuclear interaction process. More...
 
static bool IsPairProduction (const pandora::MCParticle *const pMCParticle)
 Check whether or not an MC particle comes from a pair production process. More...
 
static bool AreTopologicallyContinuous (const pandora::MCParticle *const pMCParent, const pandora::MCParticle *const pMCChild, const float cosAngleTolerance)
 Determine if two MC particles are topologically continuous within a given tolerance. If the parent does not travel any distance, a travelling parent is sought and the comparison made between this and the child. If no travelling parent can be found, the particles are treated as continuous. More...
 

Static Private Member Functions

static void CollectReconstructable2DHits (const pandora::ParticleFlowObject *const pPfo, const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D, const bool foldBackHierarchy)
 For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void CollectReconstructableTestBeamHierarchy2DHits (const pandora::ParticleFlowObject *const pPfo, const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D, const bool foldBackHierarchy)
 For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle) and belong in the test beam particle interaction hierarchy. More...
 
static void CollectReconstructable2DHits (const pandora::PfoList &pfoList, const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D)
 For a given Pfo list, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void CollectReconstructable2DHits (const pandora::Cluster *const pCluster, const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D)
 For a given cluster, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle) More...
 
static void SelectGoodCaloHits (const pandora::CaloHitList *const pSelectedCaloHitList, const MCRelationMap &mcToTargetMCMap, pandora::CaloHitList &selectedGoodCaloHitList, const bool selectInputHits, const float minHitSharingFraction)
 Apply further selection criteria to end up with a collection of "good" calo hits that can be use to define whether a target mc particle is reconstructable. More...
 
static void SelectParticlesMatchingCriteria (const pandora::MCParticleVector &inputMCParticles, std::function< bool(const pandora::MCParticle *const)> fCriteria, pandora::MCParticleVector &selectedParticles, const PrimaryParameters &parameters, const bool isTestBeam)
 Select mc particles matching given criteria from an input list. More...
 
static bool PassMCParticleChecks (const pandora::MCParticle *const pOriginalPrimary, const pandora::MCParticle *const pThisMCParticle, const pandora::MCParticle *const pHitMCParticle, const float maxPhotonPropagation)
 Whether it is possible to navigate from a primary mc particle to a downstream mc particle without "passing through" a neutron. More...
 

Detailed Description

LArMCParticleHelper class.

Definition at line 24 of file LArMCParticleHelper.h.

Member Typedef Documentation

typedef std::unordered_map<const pandora::CaloHit *, const pandora::MCParticle *> lar_content::LArMCParticleHelper::CaloHitToMCMap

Definition at line 32 of file LArMCParticleHelper.h.

typedef std::unordered_map<const pandora::CaloHit *, const pandora::ParticleFlowObject *> lar_content::LArMCParticleHelper::CaloHitToPfoMap

Definition at line 33 of file LArMCParticleHelper.h.

typedef std::pair<const pandora::Cluster *, pandora::CaloHitList> lar_content::LArMCParticleHelper::ClusterCaloHitListPair

Definition at line 44 of file LArMCParticleHelper.h.

typedef std::unordered_map<const pandora::Cluster *, pandora::CaloHitList> lar_content::LArMCParticleHelper::ClusterContributionMap

Definition at line 38 of file LArMCParticleHelper.h.

typedef std::unordered_map<const pandora::MCParticle *, pandora::CaloHitList> lar_content::LArMCParticleHelper::MCContributionMap

Definition at line 35 of file LArMCParticleHelper.h.

typedef std::pair<const pandora::MCParticle *, pandora::CaloHitList> lar_content::LArMCParticleHelper::MCParticleCaloHitListPair

Definition at line 42 of file LArMCParticleHelper.h.

typedef std::unordered_map<const pandora::MCParticle *, int> lar_content::LArMCParticleHelper::MCParticleIntMap

Definition at line 28 of file LArMCParticleHelper.h.

Definition at line 50 of file LArMCParticleHelper.h.

typedef std::unordered_map<const pandora::MCParticle *, const pandora::MCParticle *> lar_content::LArMCParticleHelper::MCRelationMap

Definition at line 27 of file LArMCParticleHelper.h.

typedef std::unordered_map<const pandora::MCParticle *, const pandora::ParticleFlowObject *> lar_content::LArMCParticleHelper::MCToPfoMap

Definition at line 30 of file LArMCParticleHelper.h.

typedef std::unordered_map<const pandora::MCParticle *, PfoContributionMap> lar_content::LArMCParticleHelper::MCToPfoMatchingMap

Definition at line 40 of file LArMCParticleHelper.h.

typedef std::pair<const pandora::ParticleFlowObject *, pandora::CaloHitList> lar_content::LArMCParticleHelper::PfoCaloHitListPair

Definition at line 43 of file LArMCParticleHelper.h.

typedef std::unordered_map<const pandora::ParticleFlowObject *, pandora::CaloHitList> lar_content::LArMCParticleHelper::PfoContributionMap

Definition at line 39 of file LArMCParticleHelper.h.

Definition at line 49 of file LArMCParticleHelper.h.

Member Function Documentation

bool lar_content::LArMCParticleHelper::AreTopologicallyContinuous ( const pandora::MCParticle *const  pMCParent,
const pandora::MCParticle *const  pMCChild,
const float  cosAngleTolerance 
)
static

Determine if two MC particles are topologically continuous within a given tolerance. If the parent does not travel any distance, a travelling parent is sought and the comparison made between this and the child. If no travelling parent can be found, the particles are treated as continuous.

Parameters
pMCParentThe parent MC particle
pMCChildThe child MC particle
cosAngleToleranceThe cosine of the maximum acceptable angular deviation
Returns
True if the partiles are topologically continous, false otherwise.

Definition at line 978 of file LArMCParticleHelper.cc.

References CollectReconstructable2DHits(), lar_content::LArPfoHelper::GetAllDownstreamPfos(), and util::size().

Referenced by lar_content::LArHierarchyHelper::MCHierarchy::CollectContinuations(), and lar_content::LArHierarchyHelper::MCHierarchy::InterpretHierarchy().

979 {
980  CartesianVector childDirection{pMCChild->GetEndpoint() - pMCChild->GetVertex()};
981  if (childDirection.GetMagnitude() < std::numeric_limits<float>::epsilon())
982  return true;
983  childDirection = childDirection.GetUnitVector();
984 
985  const MCParticle *pMCUpstream{pMCParent};
986  while (true)
987  {
988  CartesianVector parentDirection{pMCUpstream->GetEndpoint() - pMCUpstream->GetVertex()};
989  if (parentDirection.GetMagnitude() > std::numeric_limits<float>::epsilon())
990  {
991  parentDirection = parentDirection.GetUnitVector();
992  return parentDirection.GetDotProduct(childDirection) >= cosAngleTolerance;
993  }
994  else
995  {
996  const MCParticleList &parentList{pMCUpstream->GetParentList()};
997  const size_t size{parentList.size()};
998  if (size == 1)
999  pMCUpstream = parentList.front();
1000  else if (size == 0)
1001  return true;
1002  else
1003  return false;
1004  }
1005  }
1006 
1007  return false;
1008 }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
static void lar_content::LArMCParticleHelper::CollectReconstructable2DHits ( const pandora::ParticleFlowObject *const  pPfo,
const MCContributionMapVector selectedMCParticleToHitsMaps,
pandora::CaloHitList &  reconstructableCaloHitList2D,
const bool  foldBackHierarchy 
)
staticprivate

For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle)

Parameters
pPfothe input pfo
selectedMCParticleToHitsMapsthe input mappings from selected reconstructable MCParticles to hits
reconstructableCaloHitList2Dthe output list of reconstructable 2D calo hits in the input pfo
foldBackHierarchywhether to fold the particle hierarchy back to primaries

Referenced by AreTopologicallyContinuous(), CollectReconstructableTestBeamHierarchy2DHits(), GetClusterToReconstructable2DHitsMap(), and SelectReconstructableTestBeamHierarchyMCParticles().

static void lar_content::LArMCParticleHelper::CollectReconstructable2DHits ( const pandora::PfoList &  pfoList,
const MCContributionMapVector selectedMCParticleToHitsMaps,
pandora::CaloHitList &  reconstructableCaloHitList2D 
)
staticprivate

For a given Pfo list, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle)

Parameters
pfoListthe input pfo list
selectedMCParticleToHitsMapsthe input mappings from selected reconstructable MCParticles to hits
reconstructableCaloHitList2Dthe output list of reconstructable 2D calo hits in the input pfo
void lar_content::LArMCParticleHelper::CollectReconstructable2DHits ( const pandora::Cluster *const  pCluster,
const MCContributionMapVector selectedMCParticleToHitsMaps,
pandora::CaloHitList &  reconstructableCaloHitList2D 
)
staticprivate

For a given cluster, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle)

Parameters
pClusterthe input cluster
selectedMCToHitsMapsthe input mappings from selected reconstructable MCParticles to hits
reconstructableCaloHitList2Dthe output list of reconstructable 2D calo hits in the input pfo

Definition at line 1101 of file LArMCParticleHelper.cc.

1103 {
1104  const CaloHitList &isolatedCaloHitList{pCluster->GetIsolatedCaloHitList()};
1105  CaloHitList caloHitList;
1106  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
1107  for (const CaloHit *pCaloHit : isolatedCaloHitList)
1108  caloHitList.push_back(pCaloHit);
1109 
1110  // Filter for only reconstructable hits
1111  for (const CaloHit *const pCaloHit : caloHitList)
1112  {
1113  bool isTargetHit{false};
1114  for (const MCContributionMap &mcParticleToHitsMap : selectedMCToHitsMaps)
1115  { // ATTN This map is unordered, but this does not impact search for specific target hit
1116  for (const MCContributionMap::value_type &mapEntry : mcParticleToHitsMap)
1117  {
1118  if (std::find(mapEntry.second.begin(), mapEntry.second.end(), pCaloHit) != mapEntry.second.end())
1119  {
1120  isTargetHit = true;
1121  break;
1122  }
1123  }
1124  if (isTargetHit)
1125  break;
1126  }
1127 
1128  if (isTargetHit)
1129  reconstructableCaloHitList2D.push_back(pCaloHit);
1130  }
1131 }
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
void lar_content::LArMCParticleHelper::CollectReconstructableTestBeamHierarchy2DHits ( const pandora::ParticleFlowObject *const  pPfo,
const MCContributionMapVector selectedMCParticleToHitsMaps,
pandora::CaloHitList &  reconstructableCaloHitList2D,
const bool  foldBackHierarchy 
)
staticprivate

For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle) and belong in the test beam particle interaction hierarchy.

Parameters
pPfothe input pfo
selectedMCParticleToHitsMapsthe input mappings from selected reconstructable MCParticles to hits
reconstructableCaloHitList2Dthe output list of reconstructable 2D calo hits in the input pfo
foldBackHierarchywhether to fold the particle hierarchy back to leading particles

Definition at line 1035 of file LArMCParticleHelper.cc.

References CollectReconstructable2DHits(), lar_content::LArPfoHelper::GetAllDownstreamPfos(), lar_content::LArPfoHelper::GetCaloHits(), lar_content::LArPfoHelper::GetIsolatedCaloHits(), and lar_content::LArPfoHelper::IsTestBeam().

Referenced by SelectReconstructableTestBeamHierarchyMCParticles().

1037 {
1038 
1039  PfoList pfoList;
1040  // If foldBackHierarchy collect all 2D calo hits in pfo hierarchy
1041  // else collect hits directly belonging to pfo
1042  if (foldBackHierarchy)
1043  {
1044  // ATTN: Only collect downstream pfos for daughter test beam particles & cosmics
1045  if (pPfo->GetParentPfoList().empty() && LArPfoHelper::IsTestBeam(pPfo))
1046  {
1047  pfoList.push_back(pPfo);
1048  }
1049  else
1050  {
1051  LArPfoHelper::GetAllDownstreamPfos(pPfo, pfoList);
1052  }
1053  }
1054  else
1055  {
1056  pfoList.push_back(pPfo);
1057  }
1058 
1059  LArMCParticleHelper::CollectReconstructable2DHits(pfoList, selectedMCParticleToHitsMaps, reconstructableCaloHitList2D);
1060 }
static bool IsTestBeam(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a test beam particle.
static void CollectReconstructable2DHits(const pandora::ParticleFlowObject *const pPfo, const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D, const bool foldBackHierarchy)
For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected recon...
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...
bool lar_content::LArMCParticleHelper::DoesLeadingMeetCriteria ( const pandora::MCParticle *const  pMCParticle,
std::function< bool(const pandora::MCParticle *const)>  fCriteria 
)
static

Returns true if passed particle whose leading meets the passed criteria.

Parameters
pMCParticlethe input mc particle
fCriteriathe given criteria

Definition at line 61 of file LArMCParticleHelper.cc.

References GetLeadingMCParticle().

Referenced by SelectParticlesMatchingCriteria().

62 {
63  try
64  {
65  const MCParticle *const pLeadingMCParticle = LArMCParticleHelper::GetLeadingMCParticle(pMCParticle);
66  return fCriteria(pLeadingMCParticle);
67  }
68  catch (const StatusCodeException &)
69  {
70  }
71 
72  return false;
73 }
static const pandora::MCParticle * GetLeadingMCParticle(const pandora::MCParticle *const pMCParticle, const int hierarchyTierLimit=1)
Get the leading particle in the hierarchy, for use at ProtoDUNE.
bool lar_content::LArMCParticleHelper::DoesPrimaryMeetCriteria ( const pandora::MCParticle *const  pMCParticle,
std::function< bool(const pandora::MCParticle *const)>  fCriteria 
)
static

Returns true if passed particle whose primary meets the passed criteria.

Parameters
pMCParticlethe input mc particle
fCriteriathe given criteria

Definition at line 45 of file LArMCParticleHelper.cc.

References GetPrimaryMCParticle().

Referenced by SelectParticlesMatchingCriteria().

46 {
47  try
48  {
49  const MCParticle *const pPrimaryMCParticle = LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle);
50  return fCriteria(pPrimaryMCParticle);
51  }
52  catch (const StatusCodeException &)
53  {
54  }
55 
56  return false;
57 }
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
void lar_content::LArMCParticleHelper::GetAllAncestorMCParticles ( const pandora::MCParticle *const  pMCParticle,
pandora::MCParticleList &  ancestorMCParticleList 
)
static

Get all ancestor mc particles.

Parameters
pMCParticlethe input mc particle
ancestorMCParticleListthe output ancestor mc particle list

Definition at line 290 of file LArMCParticleHelper.cc.

Referenced by lar_content::LArMuonLeadingHelper::RejectBremsstrahlungHits().

291 {
292  const MCParticleList &parentMCParticleList = pMCParticle->GetParentList();
293  if (parentMCParticleList.empty())
294  return;
295  if (parentMCParticleList.size() != 1)
296  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
297 
298  const MCParticle *pParentMCParticle = *parentMCParticleList.begin();
299  if (std::find(ancestorMCParticleList.begin(), ancestorMCParticleList.end(), pParentMCParticle) == ancestorMCParticleList.end())
300  {
301  ancestorMCParticleList.push_back(pParentMCParticle);
302  LArMCParticleHelper::GetAllAncestorMCParticles(pParentMCParticle, ancestorMCParticleList);
303  }
304 }
static void GetAllAncestorMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &ancestorMCParticleList)
Get all ancestor mc particles.
void lar_content::LArMCParticleHelper::GetAllDescendentMCParticles ( const pandora::MCParticle *const  pMCParticle,
pandora::MCParticleList &  descendentMCParticleList 
)
static

Get all descendent mc particles.

Parameters
pMCParticlethe input mc particle
descendentMCParticleListthe output descendent mc particle list

Definition at line 249 of file LArMCParticleHelper.cc.

References util::abs().

Referenced by lar_content::LArHierarchyHelper::MCHierarchy::Node::FillFlat(), lar_content::LArHierarchyHelper::MCHierarchy::Node::FillHierarchy(), lar_content::LArHierarchyHelper::MCHierarchy::FillHierarchy(), and lar_content::LArHierarchyHelper::MCHierarchy::InterpretHierarchy().

250 {
251  for (const MCParticle *pDaughterMCParticle : pMCParticle->GetDaughterList())
252  {
253  if (std::find(descendentMCParticleList.begin(), descendentMCParticleList.end(), pDaughterMCParticle) == descendentMCParticleList.end())
254  {
255  descendentMCParticleList.emplace_back(pDaughterMCParticle);
256  LArMCParticleHelper::GetAllDescendentMCParticles(pDaughterMCParticle, descendentMCParticleList);
257  }
258  }
259 }
static void GetAllDescendentMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &descendentMCParticleList)
Get all descendent mc particles.
static void lar_content::LArMCParticleHelper::GetAllDescendentMCParticles ( const pandora::MCParticle *const  pMCParticle,
pandora::MCParticleList &  descendentTrackParticles,
pandora::MCParticleList &  leadingShowerParticles,
pandora::MCParticleList &  leadingNeutrons 
)
static

Get all descendent mc particles, separated into track-like, shower-like and neutron branches. This method collects together all track-like particles (i.e. not electron, photon or neutron) downstream of the root particle, stopping at a leading shower or neutron and then storing that leading shower or neutron in a separate list.

Parameters
pMCParticlethe input mc particle
descendentTrackParticlesthe output list of descendent track-like particles
leadingShowerParticlesthe output list of leading shower particles
leadingNeutronsthe output list of leading neutrons
void lar_content::LArMCParticleHelper::GetBreadthFirstHierarchyRepresentation ( const pandora::MCParticle *const  pMCParticle,
pandora::MCParticleList &  mcParticleList 
)
static

Retrieve a linearised representation of the MC particle hierarchy in breadth first order. This iterates over the MC hierarchy in a manor that sees primaries at the front of the list, with progressively deeper tiers later in the list. This is useful for some visualisation cases.

Parameters
pMCParticlean MC particle in the hierarchy - can be any particle
mcParticleListthe output MC particle list

Definition at line 1189 of file LArMCParticleHelper.cc.

References GetParentMCParticle().

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

1190 {
1191  const MCParticle *const pRoot{LArMCParticleHelper::GetParentMCParticle(pMCParticle)};
1192  MCParticleList queue;
1193  mcParticleList.emplace_back(pRoot);
1194  queue.emplace_back(pRoot);
1195 
1196  while (!queue.empty())
1197  {
1198  const MCParticleList &daughters{queue.front()->GetDaughterList()};
1199  queue.pop_front();
1200  for (const MCParticle *pDaughter : daughters)
1201  {
1202  mcParticleList.emplace_back(pDaughter);
1203  queue.emplace_back(pDaughter);
1204  }
1205  }
1206 }
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
void lar_content::LArMCParticleHelper::GetClusterToReconstructable2DHitsMap ( const pandora::ClusterList &  clusterList,
const MCContributionMap selectedMCToHitsMap,
ClusterContributionMap clusterToReconstructable2DHitsMap 
)
static

Get mapping from cluster to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)

Parameters
clusterListthe input list of clusters
selectedMCToHitsMapthe input mapping from selected reconstructable MCParticles to their hits
clusterToReconstructable2DHitsMapthe output mapping from clusters to their reconstructable 2D hits

Definition at line 755 of file LArMCParticleHelper.cc.

757 {
758  LArMCParticleHelper::GetClusterToReconstructable2DHitsMap(clusterList, MCContributionMapVector({selectedMCToHitsMap}), clusterToReconstructable2DHitsMap);
759 }
std::vector< MCContributionMap > MCContributionMapVector
static void GetClusterToReconstructable2DHitsMap(const pandora::ClusterList &clusterList, const MCContributionMap &selectedMCToHitsMap, ClusterContributionMap &clusterToReconstructable2DHitsMap)
Get mapping from cluster to reconstructable 2D hits (=good hits belonging to a selected reconstructab...
void lar_content::LArMCParticleHelper::GetClusterToReconstructable2DHitsMap ( const pandora::ClusterList &  clusterList,
const MCContributionMapVector selectedMCToHitsMaps,
ClusterContributionMap clusterToReconstructable2DHitsMap 
)
static

Get mapping from cluster to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)

Parameters
clusterListthe input list of clusters
selectedMCToHitsMapsthe input vector of mappings from selected reconstructable MCParticles to their hits
clusterToReconstructable2DHitsMapthe output mapping from cluster to their reconstructable 2D hits

Definition at line 763 of file LArMCParticleHelper.cc.

References CollectReconstructable2DHits().

765 {
766  for (const Cluster *const pCluster : clusterList)
767  {
768  CaloHitList caloHitList;
769  LArMCParticleHelper::CollectReconstructable2DHits(pCluster, selectedMCToHitsMaps, caloHitList);
770 
771  if (!clusterToReconstructable2DHitsMap.insert(ClusterContributionMap::value_type(pCluster, caloHitList)).second)
772  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
773  }
774 }
static void CollectReconstructable2DHits(const pandora::ParticleFlowObject *const pPfo, const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D, const bool foldBackHierarchy)
For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected recon...
void lar_content::LArMCParticleHelper::GetFirstVisibleMCParticles ( const pandora::MCParticle *const  pRoot,
pandora::MCParticleList &  visibleParticleList 
)
static

Get the first visible MC particles given a root particle. For example, given a neutrino this would return the primaries (the visible final state particles or the first visible descendents of invisible final state particles - note photons and neutrons are considered visible for this purpose).

Parameters
pRootthe input mc particle
visibleParticleListthe output list of visible particles (if pRoot is visible this will contain only pRoot)

Definition at line 338 of file LArMCParticleHelper.cc.

References IsVisible().

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

339 {
341  {
342  visibleParticleList.emplace_back(pRoot);
343  }
344  else
345  {
346  for (const MCParticle *const pMCParticle : pRoot->GetDaughterList())
347  LArMCParticleHelper::GetFirstVisibleMCParticles(pMCParticle, visibleParticleList);
348  }
349 }
static bool IsVisible(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is visible (i.e. long-lived charged particle)
static void GetFirstVisibleMCParticles(const pandora::MCParticle *const pRoot, pandora::MCParticleList &visibleParticleList)
Get the first visible MC particles given a root particle. For example, given a neutrino this would re...
int lar_content::LArMCParticleHelper::GetHierarchyTier ( const pandora::MCParticle *const  pMCParticle)
static

Determine the position in the hierarchy for the MCParticle.

Parameters
pMCParticlethe address of the mc particle
Returns
integer

Definition at line 173 of file LArMCParticleHelper.cc.

Referenced by lar_content::LArHierarchyHelper::MCHierarchy::Node::FillHierarchy(), lar_content::LArMuonLeadingHelper::GetLeadingParticle(), lar_content::LArMuonLeadingHelper::GetLeadingProcess(), lar_content::LArMuonLeadingHelper::IsMuonLeading(), lar_content::LArMuonLeadingHelper::RejectBremsstrahlungHits(), and lar_content::HierarchyMonitoringAlgorithm::Run().

174 {
175  const MCParticle *pParentMCParticle = pMCParticle;
176  int tier(0);
177 
178  while (pParentMCParticle->GetParentList().empty() == false)
179  {
180  if (1 != pParentMCParticle->GetParentList().size())
181  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
182 
183  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
184  ++tier;
185  }
186 
187  return tier;
188 }
const MCParticle * lar_content::LArMCParticleHelper::GetLeadingMCParticle ( const pandora::MCParticle *const  pMCParticle,
const int  hierarchyTierLimit = 1 
)
static

Get the leading particle in the hierarchy, for use at ProtoDUNE.

Parameters
pMCParticlethe input mc particle
Returns
address of the primary parent mc particle

Definition at line 384 of file LArMCParticleHelper.cc.

References GetParentMCParticle(), GetPrimaryMCParticle(), IsBeamParticle(), and IsVisible().

Referenced by DoesLeadingMeetCriteria(), GetMCLeadingMap(), and IsLeading().

385 {
386  // ATTN: If not beam particle return primary particle
387  const bool isBeamParticle(LArMCParticleHelper::IsBeamParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle)));
388 
389  if (!isBeamParticle)
390  return LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle);
391 
392  // Navigate upward through MC daughter/parent links - collect this particle and all its parents
393  MCParticleVector mcVector;
394 
395  const MCParticle *pParentMCParticle = pMCParticle;
396  mcVector.push_back(pParentMCParticle);
397 
398  while (!pParentMCParticle->GetParentList().empty())
399  {
400  if (1 != pParentMCParticle->GetParentList().size())
401  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
402 
403  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
404  mcVector.push_back(pParentMCParticle);
405  }
406 
407  int hierarchyTier(0);
408  const MCParticle *pLeadingMCParticle(nullptr);
409 
410  // Navigate downward through MC parent/daughter links - return the first long-lived charged particle
411  for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(), iterEnd = mcVector.rend(); iter != iterEnd; ++iter)
412  {
413  const MCParticle *const pNextParticle = *iter;
414 
415  // ATTN: Squash any invisible particles (e.g. pizero)
416  if (!LArMCParticleHelper::IsVisible(pNextParticle))
417  continue;
418 
419  if (hierarchyTier <= hierarchyTierLimit)
420  pLeadingMCParticle = pNextParticle;
421 
422  hierarchyTier++;
423  }
424 
425  if (!pLeadingMCParticle)
426  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
427 
428  return pLeadingMCParticle;
429 }
static bool IsVisible(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is visible (i.e. long-lived charged particle)
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
void lar_content::LArMCParticleHelper::GetLeadingMCParticleList ( const pandora::MCParticleList *const  pMCParticleList,
pandora::MCParticleVector &  mcLeadingVector 
)
static

Get vector of leading MC particles from an input list of MC particles.

Parameters
pMCParticleListthe input mc particle list
mcLeadingVectorthe output mc particle vector

Definition at line 321 of file LArMCParticleHelper.cc.

References GetParentMCParticle(), IsBeamParticle(), IsLeading(), IsPrimary(), and SortByMomentum().

Referenced by SelectReconstructableTestBeamHierarchyMCParticles().

322 {
323  for (const MCParticle *const pMCParticle : *pMCParticleList)
324  {
325  const bool isBeamParticle(LArMCParticleHelper::IsBeamParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle)));
326 
327  if ((isBeamParticle && LArMCParticleHelper::IsLeading(pMCParticle)) || (!isBeamParticle && LArMCParticleHelper::IsPrimary(pMCParticle)))
328  {
329  mcLeadingVector.push_back(pMCParticle);
330  }
331  }
332 
333  std::sort(mcLeadingVector.begin(), mcLeadingVector.end(), LArMCParticleHelper::SortByMomentum);
334 }
static bool IsPrimary(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being primary.
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
static bool IsLeading(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being leading.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
const MCParticle * lar_content::LArMCParticleHelper::GetMainMCParticle ( const pandora::ParticleFlowObject *const  pPfo)
static

Find the mc particle making the largest contribution to 2D clusters in a specified pfo.

Parameters
pPfoaddress of the pfo to examine
Returns
address of the main mc particle

Definition at line 477 of file LArMCParticleHelper.cc.

References lar_content::LArPfoHelper::GetTwoDClusterList().

Referenced by lar_content::CheatingNeutrinoCreationAlgorithm::GetMCParticleToDaughterPfoMap(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), lar_content::CheatingNeutrinoDaughterVerticesAlgorithm::ProcessDaughterPfo(), and lar_content::VisualParticleMonitoringAlgorithm::Run().

478 {
479  ClusterList clusterList;
480  LArPfoHelper::GetTwoDClusterList(pPfo, clusterList);
481  return MCParticleHelper::GetMainMCParticle(&clusterList);
482 }
static void GetTwoDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 2D clusters from an input pfo.
void lar_content::LArMCParticleHelper::GetMCLeadingMap ( const pandora::MCParticleList *const  pMCParticleList,
MCRelationMap mcLeadingMap 
)
static

Get mapping from individual mc particles (in a provided list) and their leading parent mc particles.

Parameters
pMCParticleListthe input mc particle list
mcLeadingMapthe output mapping between mc particles and their leading parent

Definition at line 450 of file LArMCParticleHelper.cc.

References GetLeadingMCParticle().

Referenced by SelectReconstructableTestBeamHierarchyMCParticles().

451 {
452  for (const MCParticle *const pMCParticle : *pMCParticleList)
453  {
454  try
455  {
456  const MCParticle *const pLeadingMCParticle = LArMCParticleHelper::GetLeadingMCParticle(pMCParticle);
457  mcLeadingMap[pMCParticle] = pLeadingMCParticle;
458  }
459  catch (const StatusCodeException &)
460  {
461  }
462  }
463 }
static const pandora::MCParticle * GetLeadingMCParticle(const pandora::MCParticle *const pMCParticle, const int hierarchyTierLimit=1)
Get the leading particle in the hierarchy, for use at ProtoDUNE.
void lar_content::LArMCParticleHelper::GetMCParticleToCaloHitMatches ( const pandora::CaloHitList *const  pCaloHitList,
const MCRelationMap mcToTargetMCMap,
CaloHitToMCMap hitToMCMap,
MCContributionMap mcToTrueHitListMap 
)
static

Match calo hits to their parent particles.

Parameters
pCaloHitListthe input list of calo hits
mcToTargetMCMapthe mc particle to target (primary or self) mc particle map
hitToMCMapoutput mapping between calo hits and their main MC particle
mcToTrueHitListMapoutput mapping between MC particles and their associated hits

Definition at line 512 of file LArMCParticleHelper.cc.

Referenced by lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), lar_content::MCParticleMonitoringAlgorithm::PrintPrimaryMCParticles(), lar_content::LArMuonLeadingHelper::SelectReconstructableLeadingParticles(), SelectReconstructableMCParticles(), and SelectReconstructableTestBeamHierarchyMCParticles().

514 {
515  for (const CaloHit *const pCaloHit : *pCaloHitList)
516  {
517  try
518  {
519  const MCParticle *const pHitParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
520  const MCParticle *pTargetParticle(pHitParticle);
521 
522  // ATTN Do not map back to target if mc to primary mc map or mc to self map not provided
523  if (!mcToTargetMCMap.empty())
524  {
525  MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pHitParticle);
526 
527  if (mcToTargetMCMap.end() == mcIter)
528  continue;
529 
530  pTargetParticle = mcIter->second;
531  }
532 
533  mcToTrueHitListMap[pTargetParticle].push_back(pCaloHit);
534  hitToMCMap[pCaloHit] = pTargetParticle;
535  }
536  catch (StatusCodeException &statusCodeException)
537  {
538  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
539  throw statusCodeException;
540  }
541  }
542 }
intermediate_table::const_iterator const_iterator
void lar_content::LArMCParticleHelper::GetMCPrimaryMap ( const pandora::MCParticleList *const  pMCParticleList,
MCRelationMap mcPrimaryMap 
)
static

Get mapping from individual mc particles (in a provided list) and their primary parent mc particles.

Parameters
pMCParticleListthe input mc particle list
mcPrimaryMapthe output mapping between mc particles and their parents

Definition at line 433 of file LArMCParticleHelper.cc.

References GetPrimaryMCParticle().

Referenced by lar_content::NeutrinoIdTool< T >::GetBestMCSliceIndex(), lar_content::BdtBeamParticleIdTool::GetBestMCSliceIndices(), lar_content::CheatingNeutrinoCreationAlgorithm::GetMCParticleToDaughterPfoMap(), lar_content::CheatingClusterCreationAlgorithm::GetMCParticleToHitListMap(), lar_content::CheatingNeutrinoDaughterVerticesAlgorithm::GetMCPrimaryMap(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), lar_content::CheatingPfoCreationAlgorithm::Run(), and SelectReconstructableMCParticles().

434 {
435  for (const MCParticle *const pMCParticle : *pMCParticleList)
436  {
437  try
438  {
439  const MCParticle *const pPrimaryMCParticle = LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle);
440  mcPrimaryMap[pMCParticle] = pPrimaryMCParticle;
441  }
442  catch (const StatusCodeException &)
443  {
444  }
445  }
446 }
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
void lar_content::LArMCParticleHelper::GetMCToSelfMap ( const pandora::MCParticleList *const  pMCParticleList,
MCRelationMap mcToSelfMap 
)
static

Get mapping from individual mc particles (in a provided list) to themselves (to be used when not folding particles to their primaries)

Parameters
pMCParticleListthe input mc particle list
mcToSelfMapthe output mapping between mc particles and themselves

Definition at line 467 of file LArMCParticleHelper.cc.

Referenced by SelectReconstructableMCParticles(), and SelectReconstructableTestBeamHierarchyMCParticles().

468 {
469  for (const MCParticle *const pMCParticle : *pMCParticleList)
470  {
471  mcToSelfMap[pMCParticle] = pMCParticle;
472  }
473 }
unsigned int lar_content::LArMCParticleHelper::GetNuanceCode ( const pandora::MCParticle *const  pMCParticle)
static

Get the nuance code of an MCParticle.

Definition at line 119 of file LArMCParticleHelper.cc.

References lar_content::LArMCParticle::GetNuanceCode().

Referenced by lar_content::BdtBeamParticleIdTool::GetBestMCSliceIndices(), lar_content::NeutrinoIdTool< T >::GetNuanceCode(), IsBeamParticle(), IsCosmicRay(), IsLeadingBeamParticle(), IsNeutrino(), IsTriggeredBeamParticle(), and lar_content::NeutrinoEventValidationAlgorithm::ProcessOutput().

120 {
121  const LArMCParticle *const pLArMCParticle(dynamic_cast<const LArMCParticle *>(pMCParticle));
122  if (pLArMCParticle)
123  return pLArMCParticle->GetNuanceCode();
124 
125  std::cout << "LArMCParticleHelper::GetNuanceCode - Error: Can't cast to LArMCParticle" << std::endl;
126  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
127 }
const MCParticle * lar_content::LArMCParticleHelper::GetParentMCParticle ( const pandora::MCParticle *const  pMCParticle)
static

Get the parent mc particle.

Parameters
pMCParticlethe input mc particle
Returns
address of the parent mc particle

Definition at line 232 of file LArMCParticleHelper.cc.

Referenced by lar_content::NeutrinoIdTool< T >::CountNeutrinoInducedHits(), GetBreadthFirstHierarchyRepresentation(), GetLeadingMCParticle(), GetLeadingMCParticleList(), lar_content::LArMuonLeadingHelper::GetMCToLeadingMap(), lar_content::LArMuonLeadingHelper::GetPfoMatchContamination(), IsBeamNeutrinoFinalState(), IsLeadingBeamParticle(), lar_content::LArMuonLeadingHelper::IsMuonLeading(), lar_content::BdtBeamParticleIdTool::PopulateMCParticleToHitsMap(), lar_content::NeutrinoEventValidationAlgorithm::ProcessOutput(), lar_content::LArMuonLeadingHelper::SelectLeadingMCParticles(), SelectReconstructableTestBeamHierarchyMCParticles(), and lar_content::CheatingSliceSelectionTool::SelectSlices().

233 {
234  const MCParticle *pParentMCParticle = pMCParticle;
235 
236  while (pParentMCParticle->GetParentList().empty() == false)
237  {
238  if (1 != pParentMCParticle->GetParentList().size())
239  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
240 
241  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
242  }
243 
244  return pParentMCParticle;
245 }
void lar_content::LArMCParticleHelper::GetPfoMCParticleHitSharingMaps ( const PfoContributionMap pfoToReconstructable2DHitsMap,
const MCContributionMapVector selectedMCParticleToHitsMaps,
PfoToMCParticleHitSharingMap pfoToMCParticleHitSharingMap,
MCParticleToPfoHitSharingMap mcParticleToPfoHitSharingMap 
)
static

Get the mappings from Pfo -> pair (reconstructable MCparticles, number of reconstructable 2D hits shared with Pfo) reconstructable MCParticle -> pair (Pfo, number of reconstructable 2D hits shared with MCParticle)

Parameters
pfoToReconstructable2DHitsMapthe input mapping from Pfos to reconstructable 2D hits
selectedMCParticleToHitsMapsthe input mappings from selected reconstructable MCParticles to hits
pfoToMCParticleHitSharingMapthe output mapping from Pfos to selected reconstructable MCParticles and the number hits shared
mcParticleToPfoHitSharingMapthe output mapping from selected reconstructable MCParticles to Pfos and the number hits shared

Definition at line 686 of file LArMCParticleHelper.cc.

References GetSharedHits(), SortByMomentum(), and lar_content::LArPfoHelper::SortByNHits().

Referenced by lar_content::NeutrinoEventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), lar_content::MuonLeadingEventValidationAlgorithm::PerformUnfoldedMatching(), and lar_content::PfoValidationAlgorithm::Run().

689 {
690  PfoVector sortedPfos;
691  for (const auto &mapEntry : pfoToReconstructable2DHitsMap)
692  sortedPfos.push_back(mapEntry.first);
693  std::sort(sortedPfos.begin(), sortedPfos.end(), LArPfoHelper::SortByNHits);
694 
695  for (const ParticleFlowObject *const pPfo : sortedPfos)
696  {
697  for (const MCContributionMap &mcParticleToHitsMap : selectedMCParticleToHitsMaps)
698  {
699  MCParticleVector sortedMCParticles;
700  for (const auto &mapEntry : mcParticleToHitsMap)
701  sortedMCParticles.push_back(mapEntry.first);
702  std::sort(sortedMCParticles.begin(), sortedMCParticles.end(), PointerLessThan<MCParticle>());
703 
704  for (const MCParticle *const pMCParticle : sortedMCParticles)
705  {
706  // Add map entries for this Pfo & MCParticle if required
707  if (pfoToMCParticleHitSharingMap.find(pPfo) == pfoToMCParticleHitSharingMap.end())
708  if (!pfoToMCParticleHitSharingMap.insert(PfoToMCParticleHitSharingMap::value_type(pPfo, MCParticleToSharedHitsVector())).second)
709  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT); // ATTN maybe overkill
710 
711  if (mcParticleToPfoHitSharingMap.find(pMCParticle) == mcParticleToPfoHitSharingMap.end())
712  if (!mcParticleToPfoHitSharingMap.insert(MCParticleToPfoHitSharingMap::value_type(pMCParticle, PfoToSharedHitsVector())).second)
713  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
714 
715  // Check this Pfo & MCParticle pairing hasn't already been checked
716  MCParticleToSharedHitsVector &mcHitPairs(pfoToMCParticleHitSharingMap.at(pPfo));
717  PfoToSharedHitsVector &pfoHitPairs(mcParticleToPfoHitSharingMap.at(pMCParticle));
718 
719  if (std::any_of(mcHitPairs.begin(), mcHitPairs.end(),
720  [&](const MCParticleCaloHitListPair &pair) { return (pair.first == pMCParticle); }))
721  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
722 
723  if (std::any_of(pfoHitPairs.begin(), pfoHitPairs.end(), [&](const PfoCaloHitListPair &pair) { return (pair.first == pPfo); }))
724  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
725 
726  // Add records to maps if there are any shared hits
727  const CaloHitList sharedHits(
728  LArMCParticleHelper::GetSharedHits(pfoToReconstructable2DHitsMap.at(pPfo), mcParticleToHitsMap.at(pMCParticle)));
729 
730  if (!sharedHits.empty())
731  {
732  mcHitPairs.push_back(MCParticleCaloHitListPair(pMCParticle, sharedHits));
733  pfoHitPairs.push_back(PfoCaloHitListPair(pPfo, sharedHits));
734 
735  std::sort(mcHitPairs.begin(), mcHitPairs.end(),
736  [](const MCParticleCaloHitListPair &a, const MCParticleCaloHitListPair &b) -> bool
737  {
738  return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size()
739  : LArMCParticleHelper::SortByMomentum(a.first, b.first));
740  });
741 
742  std::sort(pfoHitPairs.begin(), pfoHitPairs.end(),
743  [](const PfoCaloHitListPair &a, const PfoCaloHitListPair &b) -> bool {
744  return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size()
745  : LArPfoHelper::SortByNHits(a.first, b.first));
746  });
747  }
748  }
749  }
750  }
751 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
std::vector< PfoCaloHitListPair > PfoToSharedHitsVector
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
std::vector< MCParticleCaloHitListPair > MCParticleToSharedHitsVector
static pandora::CaloHitList GetSharedHits(const pandora::CaloHitList &hitListA, const pandora::CaloHitList &hitListB)
Get the hits in the intersection of two hit lists.
static void lar_content::LArMCParticleHelper::GetPfoToReconstructable2DHitsMap ( const pandora::PfoList &  pfoList,
const MCContributionMap selectedMCParticleToHitsMap,
PfoContributionMap pfoToReconstructable2DHitsMap,
const bool  foldBackHierarchy 
)
static

Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)

Parameters
pfoListthe input list of Pfos
selectedMCParticleToHitsMapthe input mapping from selected reconstructable MCParticles to their hits
pfoToReconstructable2DHitsMapthe output mapping from Pfos to their reconstructable 2D hits
foldBackHierarchywhether to fold the particle hierarchy back to the primaries

Referenced by lar_content::NeutrinoEventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), lar_content::MuonLeadingEventValidationAlgorithm::PerformUnfoldedMatching(), lar_content::PfoValidationAlgorithm::Run(), and SelectReconstructableTestBeamHierarchyMCParticles().

static void lar_content::LArMCParticleHelper::GetPfoToReconstructable2DHitsMap ( const pandora::PfoList &  pfoList,
const MCContributionMapVector selectedMCParticleToHitsMaps,
PfoContributionMap pfoToReconstructable2DHitsMap,
const bool  foldBackHierarchy 
)
static

Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)

Parameters
pfoListthe input list of Pfos
selectedMCParticleToHitsMapsthe input vector of mappings from selected reconstructable MCParticles to their hits
pfoToReconstructable2DHitsMapthe output mapping from Pfos to their reconstructable 2D hits
foldToHierarchywhether to fold the particle hierarchy back to the primaries
const MCParticle * lar_content::LArMCParticleHelper::GetPrimaryMCParticle ( const pandora::MCParticle *const  pMCParticle)
static

Get the primary parent mc particle.

Parameters
pMCParticlethe input mc particle
Returns
address of the primary parent mc particle

Definition at line 353 of file LArMCParticleHelper.cc.

References IsVisible().

Referenced by DoesPrimaryMeetCriteria(), lar_content::ElectronInitialRegionRefinementAlgorithm::FillElectronHitMap(), GetLeadingMCParticle(), GetMCPrimaryMap(), IsPrimary(), and SelectCaloHits().

354 {
355  // Navigate upward through MC daughter/parent links - collect this particle and all its parents
356  MCParticleVector mcVector;
357 
358  const MCParticle *pParentMCParticle = pMCParticle;
359  mcVector.push_back(pParentMCParticle);
360 
361  while (!pParentMCParticle->GetParentList().empty())
362  {
363  if (1 != pParentMCParticle->GetParentList().size())
364  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
365 
366  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
367  mcVector.push_back(pParentMCParticle);
368  }
369 
370  // Navigate downward through MC parent/daughter links - return the first long-lived charged particle
371  for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(), iterEnd = mcVector.rend(); iter != iterEnd; ++iter)
372  {
373  const MCParticle *const pNextParticle = *iter;
374 
375  if (LArMCParticleHelper::IsVisible(pNextParticle))
376  return pNextParticle;
377  }
378 
379  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
380 }
static bool IsVisible(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is visible (i.e. long-lived charged particle)
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
void lar_content::LArMCParticleHelper::GetPrimaryMCParticleList ( const pandora::MCParticleList *const  pMCParticleList,
pandora::MCParticleVector &  mcPrimaryVector 
)
static

Get vector of primary MC particles from an input list of MC particles.

Parameters
pMCParticleListthe input mc particle list
mcPrimaryVectorthe output mc particle vector

Definition at line 308 of file LArMCParticleHelper.cc.

References IsPrimary(), and SortByMomentum().

Referenced by lar_content::VertexMonitoringAlgorithm::AssessVertices(), and SelectReconstructableMCParticles().

309 {
310  for (const MCParticle *const pMCParticle : *pMCParticleList)
311  {
312  if (LArMCParticleHelper::IsPrimary(pMCParticle))
313  mcPrimaryVector.push_back(pMCParticle);
314  }
315 
316  std::sort(mcPrimaryVector.begin(), mcPrimaryVector.end(), LArMCParticleHelper::SortByMomentum);
317 }
static bool IsPrimary(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being primary.
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
CaloHitList lar_content::LArMCParticleHelper::GetSharedHits ( const pandora::CaloHitList &  hitListA,
const pandora::CaloHitList &  hitListB 
)
static

Get the hits in the intersection of two hit lists.

Parameters
hitListAan input hit list
hitListBanother input hit list
Returns
The hits that are found in both hitListA and hitListB

Definition at line 963 of file LArMCParticleHelper.cc.

Referenced by GetPfoMCParticleHitSharingMaps(), lar_content::ElectronInitialRegionRefinementAlgorithm::IsElectron(), and lar_content::ElectronInitialRegionRefinementAlgorithm::IsSpineCoincident().

964 {
965  CaloHitList sharedHits;
966 
967  for (const CaloHit *const pCaloHit : hitListA)
968  {
969  if (std::find(hitListB.begin(), hitListB.end(), pCaloHit) != hitListB.end())
970  sharedHits.push_back(pCaloHit);
971  }
972 
973  return sharedHits;
974 }
static void lar_content::LArMCParticleHelper::GetTestBeamHierarchyPfoToReconstructable2DHitsMap ( const pandora::PfoList &  pfoList,
const MCContributionMap selectedMCParticleToHitsMap,
PfoContributionMap pfoToReconstructable2DHitsMap,
const bool  foldBackHierarchy 
)
static

Get mapping from Pfo in reconstructed test beam hierarchy to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)

Parameters
pfoListthe input list of Pfos
selectedMCParticleToHitsMapthe input mapping from selected reconstructable MCParticles to their hits
pfoToReconstructable2DHitsMapthe output mapping from Pfos to their reconstructable 2D hits
foldBackHierarchywhether to fold the particle hierarchy back to the leading particles

Referenced by SelectReconstructableTestBeamHierarchyMCParticles().

static void lar_content::LArMCParticleHelper::GetTestBeamHierarchyPfoToReconstructable2DHitsMap ( const pandora::PfoList &  pfoList,
const MCContributionMapVector selectedMCParticleToHitsMaps,
PfoContributionMap pfoToReconstructable2DHitsMap,
const bool  foldBackHierarchy 
)
static

Get mapping from Pfo in reconstructed test beam hierarchy to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)

Parameters
pfoListthe input list of Pfos
selectedMCParticleToHitsMapsthe input vector of mappings from selected reconstructable MCParticles to their hits
pfoToReconstructable2DHitsMapthe output mapping from Pfos to their reconstructable 2D hits
foldBackHierarchywhether to fold the particle hierarchy back to the leading particles
void lar_content::LArMCParticleHelper::GetTrueNeutrinos ( const pandora::MCParticleList *const  pMCParticleList,
pandora::MCParticleVector &  trueNeutrinos 
)
static

Get neutrino MC particles from an input MC particle list.

Parameters
pMCParticleListthe input MC particle list
trueNeutrinosto receive the vector of neutrino MC particles

Definition at line 206 of file LArMCParticleHelper.cc.

References IsNeutrino(), and SortByMomentum().

Referenced by lar_content::TrainedVertexSelectionAlgorithm::GetBestVertex(), lar_content::CheatingNeutrinoCreationAlgorithm::GetMCNeutrinoVector(), lar_content::NeutrinoIdTool< T >::GetNuanceCode(), lar_content::EventWritingAlgorithm::PassNeutrinoVertexFilter(), and lar_content::EventWritingAlgorithm::PassNuanceCodeFilter().

207 {
208  for (const MCParticle *const pMCParticle : *pMCParticleList)
209  {
210  if (LArMCParticleHelper::IsNeutrino(pMCParticle))
211  trueNeutrinos.push_back(pMCParticle);
212  }
213 
214  std::sort(trueNeutrinos.begin(), trueNeutrinos.end(), LArMCParticleHelper::SortByMomentum);
215 }
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
static bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.
void lar_content::LArMCParticleHelper::GetTrueTestBeamParticles ( const pandora::MCParticleList *const  pMCParticleList,
pandora::MCParticleVector &  trueTestBeamParticles 
)
static

Get triggered test beam MC particles from an input MC particle list.

Parameters
pMCParticleListthe input MC particle list
trueTestBeamParticlesto receive the vector of neutrino MC particles

Definition at line 219 of file LArMCParticleHelper.cc.

References IsTriggeredBeamParticle(), and SortByMomentum().

Referenced by lar_content::TrainedVertexSelectionAlgorithm::GetBestVertex().

220 {
221  for (const MCParticle *const pMCParticle : *pMCParticleList)
222  {
224  trueTestBeamParticles.push_back(pMCParticle);
225  }
226 
227  std::sort(trueTestBeamParticles.begin(), trueTestBeamParticles.end(), LArMCParticleHelper::SortByMomentum);
228 }
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
static bool IsTriggeredBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary triggered beam MCParticle.
bool lar_content::LArMCParticleHelper::IsBeamNeutrinoFinalState ( const pandora::MCParticle *const  pMCParticle)
static

Returns true if passed a primary neutrino final state MCParticle.

Definition at line 77 of file LArMCParticleHelper.cc.

References GetParentMCParticle(), IsNeutrino(), and IsPrimary().

Referenced by lar_content::NeutrinoEventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::TrainedVertexSelectionAlgorithm::GetInteractionType(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), IsCosmicRay(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::NeutrinoEventValidationAlgorithm::ProcessOutput(), lar_content::PfoValidationAlgorithm::Run(), lar_content::MCParticleMonitoringAlgorithm::Run(), and lar_content::VisualParticleMonitoringAlgorithm::Run().

78 {
79  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle));
80  return (LArMCParticleHelper::IsPrimary(pMCParticle) && LArMCParticleHelper::IsNeutrino(pParentMCParticle));
81 }
static bool IsPrimary(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being primary.
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
static bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.
bool lar_content::LArMCParticleHelper::IsBeamParticle ( const pandora::MCParticle *const  pMCParticle)
static
bool lar_content::LArMCParticleHelper::IsBremsstrahlung ( const pandora::MCParticle *const  pMCParticle)
static

Definition at line 778 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_E_BREM, lar_content::MC_PROC_HAD_BREM, and lar_content::MC_PROC_MU_BREM.

779 {
780  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
781  if (!pLArMCParticle)
782  return false;
783 
784  switch (pLArMCParticle->GetProcess())
785  {
786  case MC_PROC_E_BREM:
787  case MC_PROC_MU_BREM:
788  case MC_PROC_HAD_BREM:
789  return true;
790  default:
791  return false;
792  }
793 
794  return false;
795 }
bool lar_content::LArMCParticleHelper::IsCapture ( const pandora::MCParticle *const  pMCParticle)
static

Check whether or not an MC particle comes from a capture process.

Parameters
pMCParticleThe MC particle to consider
Returns
Whether or not the MC particle came from capture

Definition at line 799 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_CHIPS_NUCLEAR_CAPTURE_AT_REST, lar_content::MC_PROC_HAD_BERTINI_CAPTURE_AT_REST, lar_content::MC_PROC_HAD_FRITIOF_CAPTURE_AT_REST, lar_content::MC_PROC_MU_MINUS_CAPTURE_AT_REST, and lar_content::MC_PROC_N_CAPTURE.

800 {
801  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
802  if (!pLArMCParticle)
803  return false;
804 
805  switch (pLArMCParticle->GetProcess())
806  {
808  case MC_PROC_N_CAPTURE:
812  return true;
813  default:
814  return false;
815  }
816 
817  return false;
818 }
bool lar_content::LArMCParticleHelper::IsCosmicRay ( const pandora::MCParticle *const  pMCParticle)
static

Return true if passed a primary cosmic ray MCParticle.

Definition at line 110 of file LArMCParticleHelper.cc.

References GetNuanceCode(), IsBeamNeutrinoFinalState(), and IsPrimary().

Referenced by lar_content::MuonLeadingEventValidationAlgorithm::DetermineIncorrectlyReconstructedCosmicRays(), lar_content::NeutrinoEventValidationAlgorithm::FillValidationInfo(), lar_content::CheatingCosmicRayTaggingTool::FindAmbiguousPfos(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::LArMuonLeadingHelper::GetMCToLeadingMap(), lar_content::LArMuonLeadingHelper::GetPfoMatchContamination(), lar_content::MuonLeadingEventValidationAlgorithm::GetRecoCosmicRayHits(), lar_content::LArHierarchyHelper::MCHierarchy::Node::IsCosmicRay(), lar_content::LArMuonLeadingHelper::IsMuonLeading(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::LArHierarchyHelper::MatchInfo::Print(), lar_content::NeutrinoEventValidationAlgorithm::ProcessOutput(), lar_content::MuonLeadingEventValidationAlgorithm::ProcessOutput(), lar_content::PfoValidationAlgorithm::Run(), lar_content::MCParticleMonitoringAlgorithm::Run(), lar_content::VisualParticleMonitoringAlgorithm::Run(), lar_content::LArMuonLeadingHelper::SelectCaloHits(), and lar_content::LArMuonLeadingHelper::SelectLeadingMCParticles().

111 {
112  const int nuance(LArMCParticleHelper::GetNuanceCode(pMCParticle));
113  return (LArMCParticleHelper::IsPrimary(pMCParticle) &&
114  ((nuance == 3000) || ((nuance == 0) && !LArMCParticleHelper::IsBeamNeutrinoFinalState(pMCParticle))));
115 }
static bool IsPrimary(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being primary.
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
bool lar_content::LArMCParticleHelper::IsDecay ( const pandora::MCParticle *const  pMCParticle)
static

Check whether or not an MC particle comes from a decay process.

Parameters
pMCParticleThe MC particle to consider
Returns
Whether or not the MC particle came from decay

Definition at line 822 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_DECAY.

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

823 {
824  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
825  if (!pLArMCParticle)
826  return false;
827 
828  switch (pLArMCParticle->GetProcess())
829  {
830  case MC_PROC_DECAY:
831  return true;
832  default:
833  return false;
834  }
835 
836  return false;
837 }
bool lar_content::LArMCParticleHelper::IsDescendentOf ( const pandora::MCParticle *const  pMCParticle,
const int  pdg,
const bool  isChargeSensitive = false 
)
static

Determine if the MC particle is a descendent of a particle with the given PDG code.

Parameters
pMCParticlethe descendent particle
pdgthe PDG code of the ancestor particle
isChargeSensitivewhether or not to consider the sign of the PDG code when looking for the ancestor (default: false)
Returns
true if the MC particle has an ancestor with the matching PDG code, false otherwise

Definition at line 1169 of file LArMCParticleHelper.cc.

References util::abs().

1170 {
1171  const MCParticle *pCurrentParticle = pMCParticle;
1172  while (!pCurrentParticle->GetParentList().empty())
1173  {
1174  if (pCurrentParticle->GetParentList().size() > 1)
1175  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
1176 
1177  const MCParticle *pParent = *(pCurrentParticle->GetParentList().begin());
1178  const bool found{isChargeSensitive ? pParent->GetParticleId() == pdg : std::abs(pParent->GetParticleId()) == std::abs(pdg)};
1179  if (found)
1180  return true;
1181  pCurrentParticle = pParent;
1182  }
1183 
1184  return false;
1185 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
bool lar_content::LArMCParticleHelper::IsElasticScatter ( const pandora::MCParticle *const  pMCParticle)
static

Check whether or not an MC particle came from an elastic scattering process.

Parameters
pMCParticleThe MC particle to consider
Returns
Whether or not the MC particle came from an elastic scatter

Definition at line 841 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_COULOMB_SCAT, lar_content::MC_PROC_HAD_ELASTIC, lar_content::MC_PROC_NEUTRON_INELASTIC, and lar_content::MC_PROC_RAYLEIGH.

Referenced by lar_content::LArHierarchyHelper::MCHierarchy::CollectContinuations(), and lar_content::LArHierarchyHelper::MCHierarchy::InterpretHierarchy().

842 {
843  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
844  if (!pLArMCParticle)
845  return false;
846 
847  switch (pLArMCParticle->GetProcess())
848  {
851  case MC_PROC_HAD_ELASTIC:
852  case MC_PROC_RAYLEIGH:
853  return true;
854  default:
855  return false;
856  }
857 
858  return false;
859 }
bool lar_content::LArMCParticleHelper::IsInelasticScatter ( const pandora::MCParticle *const  pMCParticle)
static

Check whether or not an MC particle came from an inelastic scattering process.

Parameters
pMCParticleThe MC particle to consider
Returns
Whether or not the MC particle came from an inelastic scatter

Definition at line 863 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_ALPHA_INELASTIC, lar_content::MC_PROC_ANTI_ALPHA_INELASTIC, lar_content::MC_PROC_ANTI_DEUTERON_INELASTIC, lar_content::MC_PROC_ANTI_HE3_INELASTIC, lar_content::MC_PROC_ANTI_NEUTRON_INELASTIC, lar_content::MC_PROC_ANTI_PROTON_INELASTIC, lar_content::MC_PROC_ANTI_TRITON_INELASTIC, lar_content::MC_PROC_COMPT, lar_content::MC_PROC_DEUTERON_INELASTIC, lar_content::MC_PROC_HE3_INELASTIC, lar_content::MC_PROC_ION_INELASTIC, lar_content::MC_PROC_KAON_MINUS_INELASTIC, lar_content::MC_PROC_KAON_PLUS_INELASTIC, lar_content::MC_PROC_LAMBDA_INELASTIC, lar_content::MC_PROC_PHOTON_INELASTIC, lar_content::MC_PROC_PI_MINUS_INELASTIC, lar_content::MC_PROC_PI_PLUS_INELASTIC, lar_content::MC_PROC_PROTON_INELASTIC, and lar_content::MC_PROC_TRITON_INELASTIC.

Referenced by lar_content::LArHierarchyHelper::MCHierarchy::CollectContinuations(), and lar_content::LArHierarchyHelper::MCHierarchy::InterpretHierarchy().

864 {
865  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
866  if (!pLArMCParticle)
867  return false;
868 
869  switch (pLArMCParticle->GetProcess())
870  {
871  case MC_PROC_COMPT:
890  return true;
891  default:
892  return false;
893  }
894 
895  return false;
896 }
bool lar_content::LArMCParticleHelper::IsIonisation ( const pandora::MCParticle *const  pMCParticle)
static

Check whether or not an MC particle comes from an ionisation process.

Parameters
pMCParticleThe MC particle to consider
Returns
Whether or not the MC particle came from ionisation

Definition at line 900 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_E_IONI, lar_content::MC_PROC_HAD_IONI, lar_content::MC_PROC_ION_IONI, and lar_content::MC_PROC_MU_IONI.

901 {
902  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
903  if (!pLArMCParticle)
904  return false;
905 
906  switch (pLArMCParticle->GetProcess())
907  {
908  case MC_PROC_E_IONI:
909  case MC_PROC_MU_IONI:
910  case MC_PROC_HAD_IONI:
911  case MC_PROC_ION_IONI:
912  return true;
913  default:
914  return false;
915  }
916 
917  return false;
918 }
bool lar_content::LArMCParticleHelper::IsLeading ( const pandora::MCParticle *const  pMCParticle)
static

Whether a provided mc particle matches the implemented definition of being leading.

Parameters
pMCParticlethe address of the mc particle
Returns
boolean

Definition at line 158 of file LArMCParticleHelper.cc.

References GetLeadingMCParticle().

Referenced by GetLeadingMCParticleList(), and IsLeadingBeamParticle().

159 {
160  try
161  {
162  return (LArMCParticleHelper::GetLeadingMCParticle(pMCParticle) == pMCParticle);
163  }
164  catch (const StatusCodeException &)
165  {
166  }
167 
168  return false;
169 }
static const pandora::MCParticle * GetLeadingMCParticle(const pandora::MCParticle *const pMCParticle, const int hierarchyTierLimit=1)
Get the leading particle in the hierarchy, for use at ProtoDUNE.
bool lar_content::LArMCParticleHelper::IsLeadingBeamParticle ( const pandora::MCParticle *const  pMCParticle)
static

Returns true if passed a leading beam MCParticle.

Definition at line 101 of file LArMCParticleHelper.cc.

References GetNuanceCode(), GetParentMCParticle(), and IsLeading().

102 {
103  // ATTN: Only the parent triggered beam particle has nuance code 2001
105  return (LArMCParticleHelper::IsLeading(pMCParticle) && (parentNuance == 2001 || parentNuance == 2000));
106 }
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
static bool IsLeading(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being leading.
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
bool lar_content::LArMCParticleHelper::IsNeutrino ( const pandora::MCParticle *const  pMCParticle)
static

Whether a mc particle is a neutrino or antineutrino.

Parameters
pMCParticlethe input mc particle
Returns
boolean

Definition at line 131 of file LArMCParticleHelper.cc.

References util::abs(), and GetNuanceCode().

Referenced by lar_content::VertexMonitoringAlgorithm::AssessVertices(), lar_content::NeutrinoIdTool< T >::CountNeutrinoInducedHits(), lar_content::CheatingNeutrinoCreationAlgorithm::GetMCNeutrinoVector(), GetTrueNeutrinos(), IsBeamNeutrinoFinalState(), lar_content::LArHierarchyHelper::MatchInfo::Print(), lar_content::CheatingVertexCreationAlgorithm::Run(), and lar_content::CheatingCosmicRayIdentificationAlg::Run().

132 {
133  const int nuance(LArMCParticleHelper::GetNuanceCode(pMCParticle));
134  if ((nuance == 0) || (nuance == 2000) || (nuance == 2001) || (nuance == 3000))
135  return false;
136 
137  const int absoluteParticleId(std::abs(pMCParticle->GetParticleId()));
138  return ((NU_E == absoluteParticleId) || (NU_MU == absoluteParticleId) || (NU_TAU == absoluteParticleId));
139 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
bool lar_content::LArMCParticleHelper::IsNuclear ( const pandora::MCParticle *const  pMCParticle)
static

Check whether or not an MC particle comes from a nuclear interaction process.

Parameters
pMCParticleThe MC particle to consider
Returns
Whether or not the MC particle came from nuclear interaction

Definition at line 922 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_ELECTRON_NUCLEAR, lar_content::MC_PROC_MU_NUCLEAR, and lar_content::MC_PROC_PHOTON_NUCLEAR.

923 {
924  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
925  if (!pLArMCParticle)
926  return false;
927 
928  switch (pLArMCParticle->GetProcess())
929  {
932  case MC_PROC_MU_NUCLEAR:
933  return true;
934  default:
935  return false;
936  }
937 
938  return false;
939 }
bool lar_content::LArMCParticleHelper::IsPairProduction ( const pandora::MCParticle *const  pMCParticle)
static

Check whether or not an MC particle comes from a pair production process.

Parameters
pMCParticleThe MC particle to consider
Returns
Whether or not the MC particle came from pair production

Definition at line 943 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_HAD_PAIR_PROD, and lar_content::MC_PROC_MU_PAIR_PROD.

944 {
945  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
946  if (!pLArMCParticle)
947  return false;
948 
949  switch (pLArMCParticle->GetProcess())
950  {
953  return true;
954  default:
955  return false;
956  }
957 
958  return false;
959 }
bool lar_content::LArMCParticleHelper::IsPrimary ( const pandora::MCParticle *const  pMCParticle)
static

Whether a provided mc particle matches the implemented definition of being primary.

Parameters
pMCParticlethe address of the mc particle
Returns
boolean

Definition at line 143 of file LArMCParticleHelper.cc.

References GetPrimaryMCParticle().

Referenced by GetLeadingMCParticleList(), GetPrimaryMCParticleList(), IsBeamNeutrinoFinalState(), IsBeamParticle(), IsCosmicRay(), and IsTriggeredBeamParticle().

144 {
145  try
146  {
147  return (LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle) == pMCParticle);
148  }
149  catch (const StatusCodeException &)
150  {
151  }
152 
153  return false;
154 }
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
bool lar_content::LArMCParticleHelper::IsTriggeredBeamParticle ( const pandora::MCParticle *const  pMCParticle)
static

Returns true if passed a primary triggered beam MCParticle.

Definition at line 85 of file LArMCParticleHelper.cc.

References GetNuanceCode(), and IsPrimary().

Referenced by lar_content::TrainedVertexSelectionAlgorithm::GetInteractionType(), and GetTrueTestBeamParticles().

86 {
87  const int nuance(LArMCParticleHelper::GetNuanceCode(pMCParticle));
88  return (LArMCParticleHelper::IsPrimary(pMCParticle) && (nuance == 2001));
89 }
static bool IsPrimary(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being primary.
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
bool lar_content::LArMCParticleHelper::IsVisible ( const pandora::MCParticle *const  pMCParticle)
static

Whether a mc particle is visible (i.e. long-lived charged particle)

Parameters
pMCParticlethe input mc particle
Returns
boolean

Definition at line 192 of file LArMCParticleHelper.cc.

References util::abs().

Referenced by GetFirstVisibleMCParticles(), GetLeadingMCParticle(), and GetPrimaryMCParticle().

193 {
194  const int absoluteParticleId(std::abs(pMCParticle->GetParticleId()));
195 
196  if ((E_MINUS == absoluteParticleId) || (MU_MINUS == absoluteParticleId) || (PI_PLUS == absoluteParticleId) || (K_PLUS == absoluteParticleId) ||
197  (SIGMA_MINUS == absoluteParticleId) || (SIGMA_PLUS == absoluteParticleId) || (HYPERON_MINUS == absoluteParticleId) ||
198  (PROTON == absoluteParticleId) || (PHOTON == absoluteParticleId) || (NEUTRON == absoluteParticleId))
199  return true;
200 
201  return false;
202 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
bool lar_content::LArMCParticleHelper::PassMCParticleChecks ( const pandora::MCParticle *const  pOriginalPrimary,
const pandora::MCParticle *const  pThisMCParticle,
const pandora::MCParticle *const  pHitMCParticle,
const float  maxPhotonPropagation 
)
staticprivate

Whether it is possible to navigate from a primary mc particle to a downstream mc particle without "passing through" a neutron.

Parameters
pOriginalPrimarythe address of the original primary mc particle
pThisMCParticlethe address of the current mc particle in the primary decay chain
pHitMCParticlethe address of the mc particle associated to a calo hit
maxPhotonPropagationthe maximum photon propagation length
Returns
boolean

Definition at line 1335 of file LArMCParticleHelper.cc.

References util::abs().

Referenced by SelectCaloHits().

1337 {
1338  if (NEUTRON == std::abs(pThisMCParticle->GetParticleId()))
1339  return false;
1340 
1341  if ((PHOTON == pThisMCParticle->GetParticleId()) && (PHOTON != pOriginalPrimary->GetParticleId()) &&
1342  (E_MINUS != std::abs(pOriginalPrimary->GetParticleId())))
1343  {
1344  if ((pThisMCParticle->GetEndpoint() - pThisMCParticle->GetVertex()).GetMagnitude() > maxPhotonPropagation)
1345  return false;
1346  }
1347 
1348  if (pThisMCParticle == pHitMCParticle)
1349  return true;
1350 
1351  for (const MCParticle *const pDaughterMCParticle : pThisMCParticle->GetDaughterList())
1352  {
1353  if (PassMCParticleChecks(pOriginalPrimary, pDaughterMCParticle, pHitMCParticle, maxPhotonPropagation))
1354  return true;
1355  }
1356 
1357  return false;
1358 }
static bool PassMCParticleChecks(const pandora::MCParticle *const pOriginalPrimary, const pandora::MCParticle *const pThisMCParticle, const pandora::MCParticle *const pHitMCParticle, const float maxPhotonPropagation)
Whether it is possible to navigate from a primary mc particle to a downstream mc particle without "pa...
constexpr auto abs(T v)
Returns the absolute value of the argument.
void lar_content::LArMCParticleHelper::SelectCaloHits ( const pandora::CaloHitList *const  pCaloHitList,
const MCRelationMap mcToTargetMCMap,
pandora::CaloHitList &  selectedCaloHitList,
const bool  selectInputHits,
const float  maxPhotonPropagation 
)
static

Select a subset of calo hits representing those that represent "reconstructable" regions of the event.

Parameters
pCaloHitListthe address of the input calo hit list
mcToTargetMCMapthe mc particle to target (primary or self) mc particle map
selectedCaloHitListto receive the populated selected calo hit list
selectInputHitswhether to select input hits
maxPhotonPropagationthe maximum photon propagation length

Definition at line 1135 of file LArMCParticleHelper.cc.

References GetPrimaryMCParticle(), and PassMCParticleChecks().

Referenced by lar_content::NeutrinoIdTool< T >::GetBestMCSliceIndex(), lar_content::BdtBeamParticleIdTool::GetBestMCSliceIndices(), SelectReconstructableMCParticles(), and SelectReconstructableTestBeamHierarchyMCParticles().

1137 {
1138  if (!selectInputHits)
1139  {
1140  selectedCaloHitList.insert(selectedCaloHitList.end(), pCaloHitList->begin(), pCaloHitList->end());
1141  return;
1142  }
1143 
1144  for (const CaloHit *const pCaloHit : *pCaloHitList)
1145  {
1146  try
1147  {
1148  const MCParticle *const pHitParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
1149 
1150  LArMCParticleHelper::MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pHitParticle);
1151 
1152  if (mcToTargetMCMap.end() == mcIter)
1153  continue;
1154 
1155  // ATTN With folding on or off, still require primary particle to review hierarchy details
1156  const MCParticle *const pPrimaryParticle = LArMCParticleHelper::GetPrimaryMCParticle(pHitParticle);
1157 
1158  if (PassMCParticleChecks(pPrimaryParticle, pPrimaryParticle, pHitParticle, maxPhotonPropagation))
1159  selectedCaloHitList.push_back(pCaloHit);
1160  }
1161  catch (const StatusCodeException &)
1162  {
1163  }
1164  }
1165 }
static bool PassMCParticleChecks(const pandora::MCParticle *const pOriginalPrimary, const pandora::MCParticle *const pThisMCParticle, const pandora::MCParticle *const pHitMCParticle, const float maxPhotonPropagation)
Whether it is possible to navigate from a primary mc particle to a downstream mc particle without "pa...
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
intermediate_table::const_iterator const_iterator
void lar_content::LArMCParticleHelper::SelectGoodCaloHits ( const pandora::CaloHitList *const  pSelectedCaloHitList,
const MCRelationMap mcToTargetMCMap,
pandora::CaloHitList &  selectedGoodCaloHitList,
const bool  selectInputHits,
const float  minHitSharingFraction 
)
staticprivate

Apply further selection criteria to end up with a collection of "good" calo hits that can be use to define whether a target mc particle is reconstructable.

Parameters
pSelectedCaloHitListthe address of the calo hit list (typically already been through some selection procedure)
mcToTargetMCMapthe mc particle to target (primary or self) mc particle map
selectedGoodCaloHitListto receive the populated good selected calo hit list
selectInputHitswhether to select input hits
minHitSharingFractionthe minimum Hit sharing fraction

Definition at line 1250 of file LArMCParticleHelper.cc.

References f, and weight.

Referenced by SelectParticlesByHitCount().

1252 {
1253  if (!selectInputHits)
1254  {
1255  selectedGoodCaloHitList.insert(selectedGoodCaloHitList.end(), pSelectedCaloHitList->begin(), pSelectedCaloHitList->end());
1256  return;
1257  }
1258 
1259  for (const CaloHit *const pCaloHit : *pSelectedCaloHitList)
1260  {
1261  MCParticleVector mcParticleVector;
1262  for (const auto &mapEntry : pCaloHit->GetMCParticleWeightMap())
1263  mcParticleVector.push_back(mapEntry.first);
1264  std::sort(mcParticleVector.begin(), mcParticleVector.end(), PointerLessThan<MCParticle>());
1265 
1266  MCParticleWeightMap targetWeightMap;
1267 
1268  for (const MCParticle *const pMCParticle : mcParticleVector)
1269  {
1270  const float weight(pCaloHit->GetMCParticleWeightMap().at(pMCParticle));
1271  LArMCParticleHelper::MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pMCParticle);
1272 
1273  if (mcToTargetMCMap.end() != mcIter)
1274  targetWeightMap[mcIter->second] += weight;
1275  }
1276 
1277  MCParticleVector mcTargetVector;
1278  for (const auto &mapEntry : targetWeightMap)
1279  mcTargetVector.push_back(mapEntry.first);
1280  std::sort(mcTargetVector.begin(), mcTargetVector.end(), PointerLessThan<MCParticle>());
1281 
1282  const MCParticle *pBestTargetParticle(nullptr);
1283  float bestTargetWeight(0.f), targetWeightSum(0.f);
1284 
1285  for (const MCParticle *const pTargetMCParticle : mcTargetVector)
1286  {
1287  const float targetWeight(targetWeightMap.at(pTargetMCParticle));
1288  targetWeightSum += targetWeight;
1289 
1290  if (targetWeight > bestTargetWeight)
1291  {
1292  bestTargetWeight = targetWeight;
1293  pBestTargetParticle = pTargetMCParticle;
1294  }
1295  }
1296 
1297  if (!pBestTargetParticle || (targetWeightSum < std::numeric_limits<float>::epsilon()) || ((bestTargetWeight / targetWeightSum) < minHitSharingFraction))
1298  continue;
1299 
1300  selectedGoodCaloHitList.push_back(pCaloHit);
1301  }
1302 }
intermediate_table::const_iterator const_iterator
TFile f
Definition: plotHisto.C:6
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
double weight
Definition: plottest35.C:25
void lar_content::LArMCParticleHelper::SelectParticlesByHitCount ( const pandora::MCParticleVector &  candidateTargets,
const MCContributionMap mcToTrueHitListMap,
const MCRelationMap mcToTargetMCMap,
const PrimaryParameters parameters,
MCContributionMap selectedMCParticlesToHitsMap 
)
static

Filter an input vector of MCParticles to ensure they have sufficient good hits to be reconstructable.

Parameters
candidateTargetscandidate reconstructable MCParticles
mcToTrueHitListMapmapping from candidates reconstructable MCParticles to their true hits
mcToTargetMCMapthe mc particle to target (primary or self) mc particle map
parametersvalidation parameters to decide when an MCParticle is considered reconstructable
selectedMCParticlesToHitsMapthe output mapping from selected mcparticles to their hits

Definition at line 1210 of file LArMCParticleHelper.cc.

References lar_content::LArMonitoringHelper::CountHitsByType(), lar_content::LArMCParticleHelper::PrimaryParameters::m_minHitsForGoodView, lar_content::LArMCParticleHelper::PrimaryParameters::m_minHitSharingFraction, lar_content::LArMCParticleHelper::PrimaryParameters::m_minPrimaryGoodHits, lar_content::LArMCParticleHelper::PrimaryParameters::m_minPrimaryGoodViews, lar_content::LArMCParticleHelper::PrimaryParameters::m_selectInputHits, and SelectGoodCaloHits().

Referenced by lar_content::LArMuonLeadingHelper::SelectReconstructableLeadingParticles(), SelectReconstructableMCParticles(), and SelectReconstructableTestBeamHierarchyMCParticles().

1212 {
1213  // Apply restrictions on the number of good hits associated with the MCParticles
1214  for (const MCParticle *const pMCTarget : candidateTargets)
1215  {
1216  MCContributionMap::const_iterator trueHitsIter = mcToTrueHitListMap.find(pMCTarget);
1217  if (mcToTrueHitListMap.end() == trueHitsIter)
1218  continue;
1219 
1220  const CaloHitList &caloHitList(trueHitsIter->second);
1221 
1222  // Remove shared hits where target particle deposits below threshold energy fraction
1223  CaloHitList goodCaloHitList;
1225  &caloHitList, mcToTargetMCMap, goodCaloHitList, parameters.m_selectInputHits, parameters.m_minHitSharingFraction);
1226 
1227  if (goodCaloHitList.size() < parameters.m_minPrimaryGoodHits)
1228  continue;
1229 
1230  unsigned int nGoodViews(0);
1231  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1232  ++nGoodViews;
1233 
1234  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1235  ++nGoodViews;
1236 
1237  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1238  ++nGoodViews;
1239 
1240  if (nGoodViews < parameters.m_minPrimaryGoodViews)
1241  continue;
1242 
1243  if (!selectedMCParticlesToHitsMap.insert(MCContributionMap::value_type(pMCTarget, caloHitList)).second)
1244  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
1245  }
1246 }
intermediate_table::const_iterator const_iterator
static void SelectGoodCaloHits(const pandora::CaloHitList *const pSelectedCaloHitList, const MCRelationMap &mcToTargetMCMap, pandora::CaloHitList &selectedGoodCaloHitList, const bool selectInputHits, const float minHitSharingFraction)
Apply further selection criteria to end up with a collection of "good" calo hits that can be use to d...
static unsigned int CountHitsByType(const pandora::HitType hitType, const pandora::CaloHitList &caloHitList)
Count the number of calo hits, in a provided list, of a specified type.
void lar_content::LArMCParticleHelper::SelectParticlesMatchingCriteria ( const pandora::MCParticleVector &  inputMCParticles,
std::function< bool(const pandora::MCParticle *const)>  fCriteria,
pandora::MCParticleVector &  selectedParticles,
const PrimaryParameters parameters,
const bool  isTestBeam 
)
staticprivate

Select mc particles matching given criteria from an input list.

Parameters
inputMCParticlesinput vector of MCParticles
fCriteriaa function which returns a bool (= shouldSelect) for a given input MCParticle
selectedParticlesthe output vector of particles selected
parametersvalidation parameters to decide when an MCParticle is considered reconstructable
isTestBeamwhether the mc particles correspond to the test beam case or the neutrino case

Definition at line 1306 of file LArMCParticleHelper.cc.

References DoesLeadingMeetCriteria(), DoesPrimaryMeetCriteria(), and lar_content::LArMCParticleHelper::PrimaryParameters::m_foldBackHierarchy.

Referenced by SelectReconstructableMCParticles(), and SelectReconstructableTestBeamHierarchyMCParticles().

1308 {
1309  for (const MCParticle *const pMCParticle : inputMCParticles)
1310  {
1311  if (parameters.m_foldBackHierarchy)
1312  {
1313  if (!fCriteria(pMCParticle))
1314  continue;
1315  }
1316  else
1317  {
1318  if (isTestBeam)
1319  {
1320  if (!LArMCParticleHelper::DoesLeadingMeetCriteria(pMCParticle, fCriteria))
1321  continue;
1322  }
1323  else
1324  {
1325  if (!LArMCParticleHelper::DoesPrimaryMeetCriteria(pMCParticle, fCriteria))
1326  continue;
1327  }
1328  }
1329  selectedParticles.push_back(pMCParticle);
1330  }
1331 }
static bool DoesPrimaryMeetCriteria(const pandora::MCParticle *const pMCParticle, std::function< bool(const pandora::MCParticle *const)> fCriteria)
Returns true if passed particle whose primary meets the passed criteria.
static bool DoesLeadingMeetCriteria(const pandora::MCParticle *const pMCParticle, std::function< bool(const pandora::MCParticle *const)> fCriteria)
Returns true if passed particle whose leading meets the passed criteria.
void lar_content::LArMCParticleHelper::SelectReconstructableMCParticles ( const pandora::MCParticleList *  pMCParticleList,
const pandora::CaloHitList *  pCaloHitList,
const PrimaryParameters parameters,
std::function< bool(const pandora::MCParticle *const)>  fCriteria,
MCContributionMap selectedMCParticlesToHitsMap 
)
static

Select target, reconstructable mc particles that match given criteria.

Parameters
pMCParticleListthe address of the list of MCParticles
pCaloHitListthe address of the list of CaloHits
parametersvalidation parameters to decide when an MCParticle is considered reconstructable
fCriteriaa function which returns a bool (= shouldSelect) for a given input MCParticle
selectedMCParticlesToHitsMapthe output mapping from selected mcparticles to their hits

Definition at line 546 of file LArMCParticleHelper.cc.

References GetMCParticleToCaloHitMatches(), GetMCPrimaryMap(), GetMCToSelfMap(), GetPrimaryMCParticleList(), lar_content::LArMCParticleHelper::PrimaryParameters::m_foldBackHierarchy, lar_content::LArMCParticleHelper::PrimaryParameters::m_maxPhotonPropagation, lar_content::LArMCParticleHelper::PrimaryParameters::m_selectInputHits, SelectCaloHits(), SelectParticlesByHitCount(), and SelectParticlesMatchingCriteria().

Referenced by lar_content::NeutrinoEventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::TrainedVertexSelectionAlgorithm::GetInteractionType(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::PfoValidationAlgorithm::Run(), lar_content::MCParticleMonitoringAlgorithm::Run(), and lar_content::VisualParticleMonitoringAlgorithm::Run().

548 {
549  // Obtain map: [mc particle -> target mc particle]
550  LArMCParticleHelper::MCRelationMap mcToTargetMCMap;
551  parameters.m_foldBackHierarchy ? LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToTargetMCMap)
552  : LArMCParticleHelper::GetMCToSelfMap(pMCParticleList, mcToTargetMCMap);
553 
554  // Remove non-reconstructable hits, e.g. those downstream of a neutron
555  // Unless selectInputHits == false
556  CaloHitList selectedCaloHitList;
557  LArMCParticleHelper::SelectCaloHits(pCaloHitList, mcToTargetMCMap, selectedCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
558 
559  // Obtain maps: [hit -> target mc particle], [target mc particle -> list of hits]
560  CaloHitToMCMap trueHitToTargetMCMap;
561  MCContributionMap targetMCToTrueHitListMap;
562  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&selectedCaloHitList, mcToTargetMCMap, trueHitToTargetMCMap, targetMCToTrueHitListMap);
563 
564  // Obtain vector: target mc particles
565  MCParticleVector targetMCVector;
566  if (parameters.m_foldBackHierarchy)
567  {
568  LArMCParticleHelper::GetPrimaryMCParticleList(pMCParticleList, targetMCVector);
569  }
570  else
571  {
572  std::copy(pMCParticleList->begin(), pMCParticleList->end(), std::back_inserter(targetMCVector));
573  }
574 
575  // Select MCParticles matching criteria
576  MCParticleVector candidateTargets;
577  LArMCParticleHelper::SelectParticlesMatchingCriteria(targetMCVector, fCriteria, candidateTargets, parameters, false);
578 
579  // Ensure the MCParticles have enough "good" hits to be reconstructed
580  LArMCParticleHelper::SelectParticlesByHitCount(candidateTargets, targetMCToTrueHitListMap, mcToTargetMCMap, parameters, selectedMCParticlesToHitsMap);
581 }
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::unordered_map< const pandora::CaloHit *, const pandora::MCParticle * > CaloHitToMCMap
static void GetMCPrimaryMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcPrimaryMap)
Get mapping from individual mc particles (in a provided list) and their primary parent mc particles...
static void SelectParticlesByHitCount(const pandora::MCParticleVector &candidateTargets, const MCContributionMap &mcToTrueHitListMap, const MCRelationMap &mcToTargetMCMap, const PrimaryParameters &parameters, MCContributionMap &selectedMCParticlesToHitsMap)
Filter an input vector of MCParticles to ensure they have sufficient good hits to be reconstructable...
static void GetMCToSelfMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcToSelfMap)
Get mapping from individual mc particles (in a provided list) to themselves (to be used when not fold...
static void GetMCParticleToCaloHitMatches(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, CaloHitToMCMap &hitToMCMap, MCContributionMap &mcToTrueHitListMap)
Match calo hits to their parent particles.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static void GetPrimaryMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcPrimaryVector)
Get vector of primary MC particles from an input list of MC particles.
static void SelectParticlesMatchingCriteria(const pandora::MCParticleVector &inputMCParticles, std::function< bool(const pandora::MCParticle *const)> fCriteria, pandora::MCParticleVector &selectedParticles, const PrimaryParameters &parameters, const bool isTestBeam)
Select mc particles matching given criteria from an input list.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
static void SelectCaloHits(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, pandora::CaloHitList &selectedCaloHitList, const bool selectInputHits, const float maxPhotonPropagation)
Select a subset of calo hits representing those that represent "reconstructable" regions of the event...
void lar_content::LArMCParticleHelper::SelectReconstructableTestBeamHierarchyMCParticles ( const pandora::MCParticleList *  pMCParticleList,
const pandora::CaloHitList *  pCaloHitList,
const PrimaryParameters parameters,
std::function< bool(const pandora::MCParticle *const)>  fCriteria,
MCContributionMap selectedMCParticlesToHitsMap 
)
static

Select target, reconstructable mc particles in the relevant hierarchy that match given criteria.

Parameters
pMCParticleListthe address of the list of MCParticles
pCaloHitListthe address of the list of CaloHits
parametersvalidation parameters to decide when an MCParticle is considered reconstructable
fCriteriaa function which returns a bool (= shouldSelect) for a given input MCParticle
selectedMCParticlesToHitsMapthe output mapping from selected mcparticles to their hits

Definition at line 585 of file LArMCParticleHelper.cc.

References CollectReconstructable2DHits(), CollectReconstructableTestBeamHierarchy2DHits(), GetLeadingMCParticleList(), GetMCLeadingMap(), GetMCParticleToCaloHitMatches(), GetMCToSelfMap(), GetParentMCParticle(), GetPfoToReconstructable2DHitsMap(), GetTestBeamHierarchyPfoToReconstructable2DHitsMap(), IsBeamParticle(), lar_content::LArMCParticleHelper::PrimaryParameters::m_foldBackHierarchy, lar_content::LArMCParticleHelper::PrimaryParameters::m_maxPhotonPropagation, lar_content::LArMCParticleHelper::PrimaryParameters::m_selectInputHits, SelectCaloHits(), SelectParticlesByHitCount(), and SelectParticlesMatchingCriteria().

587 {
588  // Obtain map: [mc particle -> target mc particle]
589  LArMCParticleHelper::MCRelationMap mcToTargetMCMap;
590  parameters.m_foldBackHierarchy ? LArMCParticleHelper::GetMCLeadingMap(pMCParticleList, mcToTargetMCMap)
591  : LArMCParticleHelper::GetMCToSelfMap(pMCParticleList, mcToTargetMCMap);
592 
593  // Remove non-reconstructable hits, e.g. those downstream of a neutron
594  // Unless selectInputHits == false
595  CaloHitList selectedCaloHitList;
596  LArMCParticleHelper::SelectCaloHits(pCaloHitList, mcToTargetMCMap, selectedCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
597 
598  // Obtain maps: [hit -> target mc particle], [target mc particle -> list of hits]
599  CaloHitToMCMap trueHitToTargetMCMap;
600  MCContributionMap targetMCToTrueHitListMap;
601  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&selectedCaloHitList, mcToTargetMCMap, trueHitToTargetMCMap, targetMCToTrueHitListMap);
602 
603  // Obtain vector: target mc particles
604  MCParticleVector targetMCVector;
605  if (parameters.m_foldBackHierarchy)
606  {
607  LArMCParticleHelper::GetLeadingMCParticleList(pMCParticleList, targetMCVector);
608  }
609  else
610  {
611  std::copy(pMCParticleList->begin(), pMCParticleList->end(), std::back_inserter(targetMCVector));
612  }
613 
614  // Select MCParticles matching criteria
615  MCParticleVector candidateTargets;
616  LArMCParticleHelper::SelectParticlesMatchingCriteria(targetMCVector, fCriteria, candidateTargets, parameters, true);
617 
618  // Ensure the MCParticles have enough "good" hits to be reconstructed
619  LArMCParticleHelper::SelectParticlesByHitCount(candidateTargets, targetMCToTrueHitListMap, mcToTargetMCMap, parameters, selectedMCParticlesToHitsMap);
620 
621  // ATTN: The parent particle must be in the hierarchy map, event if not reconstructable
622  for (const MCParticle *const pMCParticle : candidateTargets)
623  {
624  if (!LArMCParticleHelper::IsBeamParticle(pMCParticle))
625  continue;
626 
627  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle));
628  if (selectedMCParticlesToHitsMap.find(pParentMCParticle) == selectedMCParticlesToHitsMap.end())
629  {
630  CaloHitList caloHitList;
631  selectedMCParticlesToHitsMap.insert(MCContributionMap::value_type(pParentMCParticle, caloHitList));
632  }
633  }
634 }
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
static void GetLeadingMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcLeadingVector)
Get vector of leading MC particles from an input list of MC particles.
std::unordered_map< const pandora::CaloHit *, const pandora::MCParticle * > CaloHitToMCMap
static void SelectParticlesByHitCount(const pandora::MCParticleVector &candidateTargets, const MCContributionMap &mcToTrueHitListMap, const MCRelationMap &mcToTargetMCMap, const PrimaryParameters &parameters, MCContributionMap &selectedMCParticlesToHitsMap)
Filter an input vector of MCParticles to ensure they have sufficient good hits to be reconstructable...
static void GetMCToSelfMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcToSelfMap)
Get mapping from individual mc particles (in a provided list) to themselves (to be used when not fold...
static void GetMCParticleToCaloHitMatches(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, CaloHitToMCMap &hitToMCMap, MCContributionMap &mcToTrueHitListMap)
Match calo hits to their parent particles.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
static void GetMCLeadingMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcLeadingMap)
Get mapping from individual mc particles (in a provided list) and their leading parent mc particles...
static void SelectParticlesMatchingCriteria(const pandora::MCParticleVector &inputMCParticles, std::function< bool(const pandora::MCParticle *const)> fCriteria, pandora::MCParticleVector &selectedParticles, const PrimaryParameters &parameters, const bool isTestBeam)
Select mc particles matching given criteria from an input list.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
static void SelectCaloHits(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, pandora::CaloHitList &selectedCaloHitList, const bool selectInputHits, const float maxPhotonPropagation)
Select a subset of calo hits representing those that represent "reconstructable" regions of the event...
bool lar_content::LArMCParticleHelper::SortByMomentum ( const pandora::MCParticle *const  pLhs,
const pandora::MCParticle *const  pRhs 
)
static

Sort mc particles by their momentum.

Parameters
pLhsaddress of first mc particle
pRhsaddress of second mc particle

Definition at line 486 of file LArMCParticleHelper.cc.

Referenced by lar_content::CheatingClusterCreationAlgorithm::CreateClusters(), lar_content::CheatingPfoCreationAlgorithm::CreatePfos(), lar_content::LArHierarchyHelper::MCHierarchy::FillHierarchy(), lar_content::TrainedVertexSelectionAlgorithm::GetInteractionType(), GetLeadingMCParticleList(), GetPfoMCParticleHitSharingMaps(), GetPrimaryMCParticleList(), GetTrueNeutrinos(), GetTrueTestBeamParticles(), lar_content::LArHierarchyHelper::MCHierarchy::IsReconstructable(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::LArHierarchyHelper::MatchInfo::Print(), lar_content::MuonLeadingEventValidationAlgorithm::ProcessOutput(), lar_content::MasterAlgorithm::Reset(), lar_content::HierarchyValidationAlgorithm::Run(), lar_content::LArMuonLeadingHelper::SelectLeadingMCParticles(), and lar_content::CheatingSliceSelectionTool::SelectSlices().

487 {
488  // Sort by momentum (prefer higher momentum)
489  const float momentumLhs(pLhs->GetMomentum().GetMagnitudeSquared());
490  const float momentumRhs(pRhs->GetMomentum().GetMagnitudeSquared());
491 
492  if (std::fabs(momentumLhs - momentumRhs) > std::numeric_limits<float>::epsilon())
493  return (momentumLhs > momentumRhs);
494 
495  // Sort by energy (prefer lighter particles)
496  if (std::fabs(pLhs->GetEnergy() - pRhs->GetEnergy()) > std::numeric_limits<float>::epsilon())
497  return (pLhs->GetEnergy() < pRhs->GetEnergy());
498 
499  // Sort by PDG code (prefer smaller numbers)
500  if (pLhs->GetParticleId() != pRhs->GetParticleId())
501  return (pLhs->GetParticleId() < pRhs->GetParticleId());
502 
503  // Sort by vertex position (tie-breaker)
504  const float positionLhs(pLhs->GetVertex().GetMagnitudeSquared());
505  const float positionRhs(pRhs->GetVertex().GetMagnitudeSquared());
506 
507  return (positionLhs < positionRhs);
508 }

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