LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 bool GetTrueVertex (const pandora::MCParticleList *const pMCParticleList, pandora::CartesianVector &trueVertex)
 Retrieve the true neutrino vertex. 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 void GetMCToHitsMap (const pandora::CaloHitList *const pCaloHitList2S, const pandora::MCParticleList *const pMCParticleList, LArMCParticleHelper::MCContributionMap &mcToHitsMap)
 
static void CompleteMCHierarchy (const LArMCParticleHelper::MCContributionMap &mcToHitsMap, pandora::MCParticleList &mcHierarchy)
 
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 1039 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().

1040 {
1041  CartesianVector childDirection{pMCChild->GetEndpoint() - pMCChild->GetVertex()};
1042  if (childDirection.GetMagnitude() < std::numeric_limits<float>::epsilon())
1043  return true;
1044  childDirection = childDirection.GetUnitVector();
1045 
1046  const MCParticle *pMCUpstream{pMCParent};
1047  while (true)
1048  {
1049  CartesianVector parentDirection{pMCUpstream->GetEndpoint() - pMCUpstream->GetVertex()};
1050  if (parentDirection.GetMagnitude() > std::numeric_limits<float>::epsilon())
1051  {
1052  parentDirection = parentDirection.GetUnitVector();
1053  return parentDirection.GetDotProduct(childDirection) >= cosAngleTolerance;
1054  }
1055  else
1056  {
1057  const MCParticleList &parentList{pMCUpstream->GetParentList()};
1058  const size_t size{parentList.size()};
1059  if (size == 1)
1060  pMCUpstream = parentList.front();
1061  else if (size == 0)
1062  return true;
1063  else
1064  return false;
1065  }
1066  }
1067 
1068  return false;
1069 }
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 1162 of file LArMCParticleHelper.cc.

1164 {
1165  const CaloHitList &isolatedCaloHitList{pCluster->GetIsolatedCaloHitList()};
1166  CaloHitList caloHitList;
1167  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
1168  for (const CaloHit *pCaloHit : isolatedCaloHitList)
1169  caloHitList.push_back(pCaloHit);
1170 
1171  // Filter for only reconstructable hits
1172  for (const CaloHit *const pCaloHit : caloHitList)
1173  {
1174  bool isTargetHit{false};
1175  for (const MCContributionMap &mcParticleToHitsMap : selectedMCToHitsMaps)
1176  { // ATTN This map is unordered, but this does not impact search for specific target hit
1177  for (const MCContributionMap::value_type &mapEntry : mcParticleToHitsMap)
1178  {
1179  if (std::find(mapEntry.second.begin(), mapEntry.second.end(), pCaloHit) != mapEntry.second.end())
1180  {
1181  isTargetHit = true;
1182  break;
1183  }
1184  }
1185  if (isTargetHit)
1186  break;
1187  }
1188 
1189  if (isTargetHit)
1190  reconstructableCaloHitList2D.push_back(pCaloHit);
1191  }
1192 }
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 1096 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().

1098 {
1099 
1100  PfoList pfoList;
1101  // If foldBackHierarchy collect all 2D calo hits in pfo hierarchy
1102  // else collect hits directly belonging to pfo
1103  if (foldBackHierarchy)
1104  {
1105  // ATTN: Only collect downstream pfos for daughter test beam particles & cosmics
1106  if (pPfo->GetParentPfoList().empty() && LArPfoHelper::IsTestBeam(pPfo))
1107  {
1108  pfoList.push_back(pPfo);
1109  }
1110  else
1111  {
1112  LArPfoHelper::GetAllDownstreamPfos(pPfo, pfoList);
1113  }
1114  }
1115  else
1116  {
1117  pfoList.push_back(pPfo);
1118  }
1119 
1120  LArMCParticleHelper::CollectReconstructable2DHits(pfoList, selectedMCParticleToHitsMaps, reconstructableCaloHitList2D);
1121 }
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...
void lar_content::LArMCParticleHelper::CompleteMCHierarchy ( const LArMCParticleHelper::MCContributionMap mcToHitsMap,
pandora::MCParticleList &  mcHierarchy 
)
static

Definition at line 512 of file LArMCParticleHelper.cc.

References e, GetAllAncestorMCParticles(), hits(), and IsNeutrino().

513 {
514  try
515  {
516  for (const auto &[mc, hits] : mcToHitsMap)
517  {
518  mcHierarchy.emplace_back(mc);
520  }
521  }
522  catch (const StatusCodeException &e)
523  {
524  throw;
525  }
526 
527  // Move the neutrino to the front of the list
528  auto pivot{
529  std::find_if(mcHierarchy.begin(), mcHierarchy.end(), [](const MCParticle *mc) -> bool { return LArMCParticleHelper::IsNeutrino(mc); })};
530  if (pivot != mcHierarchy.end())
531  std::rotate(mcHierarchy.begin(), pivot, std::next(pivot));
532  else
533  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
534 }
void hits()
Definition: readHits.C:15
static void GetAllAncestorMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &ancestorMCParticleList)
Get all ancestor mc particles.
Float_t e
Definition: plot.C:35
static bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.
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 314 of file LArMCParticleHelper.cc.

Referenced by CompleteMCHierarchy(), and lar_content::LArMuonLeadingHelper::RejectBremsstrahlungHits().

315 {
316  const MCParticleList &parentMCParticleList = pMCParticle->GetParentList();
317  if (parentMCParticleList.empty())
318  return;
319  if (parentMCParticleList.size() != 1)
320  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
321 
322  const MCParticle *pParentMCParticle = *parentMCParticleList.begin();
323  if (std::find(ancestorMCParticleList.begin(), ancestorMCParticleList.end(), pParentMCParticle) == ancestorMCParticleList.end())
324  {
325  ancestorMCParticleList.push_back(pParentMCParticle);
326  LArMCParticleHelper::GetAllAncestorMCParticles(pParentMCParticle, ancestorMCParticleList);
327  }
328 }
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 273 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().

274 {
275  for (const MCParticle *pDaughterMCParticle : pMCParticle->GetDaughterList())
276  {
277  if (std::find(descendentMCParticleList.begin(), descendentMCParticleList.end(), pDaughterMCParticle) == descendentMCParticleList.end())
278  {
279  descendentMCParticleList.emplace_back(pDaughterMCParticle);
280  LArMCParticleHelper::GetAllDescendentMCParticles(pDaughterMCParticle, descendentMCParticleList);
281  }
282  }
283 }
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 1250 of file LArMCParticleHelper.cc.

References GetParentMCParticle().

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

1251 {
1252  const MCParticle *const pRoot{LArMCParticleHelper::GetParentMCParticle(pMCParticle)};
1253  MCParticleList queue;
1254  mcParticleList.emplace_back(pRoot);
1255  queue.emplace_back(pRoot);
1256 
1257  while (!queue.empty())
1258  {
1259  const MCParticleList &daughters{queue.front()->GetDaughterList()};
1260  queue.pop_front();
1261  for (const MCParticle *pDaughter : daughters)
1262  {
1263  mcParticleList.emplace_back(pDaughter);
1264  queue.emplace_back(pDaughter);
1265  }
1266  }
1267 }
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 816 of file LArMCParticleHelper.cc.

818 {
819  LArMCParticleHelper::GetClusterToReconstructable2DHitsMap(clusterList, MCContributionMapVector({selectedMCToHitsMap}), clusterToReconstructable2DHitsMap);
820 }
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 824 of file LArMCParticleHelper.cc.

References CollectReconstructable2DHits().

826 {
827  for (const Cluster *const pCluster : clusterList)
828  {
829  CaloHitList caloHitList;
830  LArMCParticleHelper::CollectReconstructable2DHits(pCluster, selectedMCToHitsMaps, caloHitList);
831 
832  if (!clusterToReconstructable2DHitsMap.insert(ClusterContributionMap::value_type(pCluster, caloHitList)).second)
833  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
834  }
835 }
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 362 of file LArMCParticleHelper.cc.

References IsVisible().

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

363 {
365  {
366  visibleParticleList.emplace_back(pRoot);
367  }
368  else
369  {
370  for (const MCParticle *const pMCParticle : pRoot->GetDaughterList())
371  LArMCParticleHelper::GetFirstVisibleMCParticles(pMCParticle, visibleParticleList);
372  }
373 }
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 408 of file LArMCParticleHelper.cc.

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

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

409 {
410  // ATTN: If not beam particle return primary particle
411  const bool isBeamParticle(LArMCParticleHelper::IsBeamParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle)));
412 
413  if (!isBeamParticle)
414  return LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle);
415 
416  // Navigate upward through MC daughter/parent links - collect this particle and all its parents
417  MCParticleVector mcVector;
418 
419  const MCParticle *pParentMCParticle = pMCParticle;
420  mcVector.push_back(pParentMCParticle);
421 
422  while (!pParentMCParticle->GetParentList().empty())
423  {
424  if (1 != pParentMCParticle->GetParentList().size())
425  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
426 
427  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
428  mcVector.push_back(pParentMCParticle);
429  }
430 
431  int hierarchyTier(0);
432  const MCParticle *pLeadingMCParticle(nullptr);
433 
434  // Navigate downward through MC parent/daughter links - return the first long-lived charged particle
435  for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(), iterEnd = mcVector.rend(); iter != iterEnd; ++iter)
436  {
437  const MCParticle *const pNextParticle = *iter;
438 
439  // ATTN: Squash any invisible particles (e.g. pizero)
440  if (!LArMCParticleHelper::IsVisible(pNextParticle))
441  continue;
442 
443  if (hierarchyTier <= hierarchyTierLimit)
444  pLeadingMCParticle = pNextParticle;
445 
446  hierarchyTier++;
447  }
448 
449  if (!pLeadingMCParticle)
450  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
451 
452  return pLeadingMCParticle;
453 }
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 345 of file LArMCParticleHelper.cc.

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

Referenced by SelectReconstructableTestBeamHierarchyMCParticles().

346 {
347  for (const MCParticle *const pMCParticle : *pMCParticleList)
348  {
349  const bool isBeamParticle(LArMCParticleHelper::IsBeamParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle)));
350 
351  if ((isBeamParticle && LArMCParticleHelper::IsLeading(pMCParticle)) || (!isBeamParticle && LArMCParticleHelper::IsPrimary(pMCParticle)))
352  {
353  mcLeadingVector.push_back(pMCParticle);
354  }
355  }
356 
357  std::sort(mcLeadingVector.begin(), mcLeadingVector.end(), LArMCParticleHelper::SortByMomentum);
358 }
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 538 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().

539 {
540  ClusterList clusterList;
541  LArPfoHelper::GetTwoDClusterList(pPfo, clusterList);
542  return MCParticleHelper::GetMainMCParticle(&clusterList);
543 }
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 474 of file LArMCParticleHelper.cc.

References GetLeadingMCParticle().

Referenced by SelectReconstructableTestBeamHierarchyMCParticles().

475 {
476  for (const MCParticle *const pMCParticle : *pMCParticleList)
477  {
478  try
479  {
480  const MCParticle *const pLeadingMCParticle = LArMCParticleHelper::GetLeadingMCParticle(pMCParticle);
481  mcLeadingMap[pMCParticle] = pLeadingMCParticle;
482  }
483  catch (const StatusCodeException &)
484  {
485  }
486  }
487 }
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 573 of file LArMCParticleHelper.cc.

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

575 {
576  for (const CaloHit *const pCaloHit : *pCaloHitList)
577  {
578  try
579  {
580  const MCParticle *const pHitParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
581  const MCParticle *pTargetParticle(pHitParticle);
582 
583  // ATTN Do not map back to target if mc to primary mc map or mc to self map not provided
584  if (!mcToTargetMCMap.empty())
585  {
586  MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pHitParticle);
587 
588  if (mcToTargetMCMap.end() == mcIter)
589  continue;
590 
591  pTargetParticle = mcIter->second;
592  }
593 
594  mcToTrueHitListMap[pTargetParticle].push_back(pCaloHit);
595  hitToMCMap[pCaloHit] = pTargetParticle;
596  }
597  catch (StatusCodeException &statusCodeException)
598  {
599  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
600  throw statusCodeException;
601  }
602  }
603 }
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 457 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().

458 {
459  for (const MCParticle *const pMCParticle : *pMCParticleList)
460  {
461  try
462  {
463  const MCParticle *const pPrimaryMCParticle = LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle);
464  mcPrimaryMap[pMCParticle] = pPrimaryMCParticle;
465  }
466  catch (const StatusCodeException &)
467  {
468  }
469  }
470 }
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
void lar_content::LArMCParticleHelper::GetMCToHitsMap ( const pandora::CaloHitList *const  pCaloHitList2S,
const pandora::MCParticleList *const  pMCParticleList,
LArMCParticleHelper::MCContributionMap mcToHitsMap 
)
static

Definition at line 501 of file LArMCParticleHelper.cc.

References IsBeamNeutrinoFinalState(), lar_content::LArMCParticleHelper::PrimaryParameters::m_maxPhotonPropagation, and SelectReconstructableMCParticles().

503 {
504  PrimaryParameters parameters;
505  parameters.m_maxPhotonPropagation = std::numeric_limits<float>::max();
507  pMCParticleList, pCaloHitList2D, parameters, LArMCParticleHelper::IsBeamNeutrinoFinalState, mcToHitsMap);
508 }
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.
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
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 491 of file LArMCParticleHelper.cc.

Referenced by SelectReconstructableMCParticles(), and SelectReconstructableTestBeamHierarchyMCParticles().

492 {
493  for (const MCParticle *const pMCParticle : *pMCParticleList)
494  {
495  mcToSelfMap[pMCParticle] = pMCParticle;
496  }
497 }
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 256 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::VisualParticleMonitoringAlgorithm::Run(), lar_content::HierarchyValidationAlgorithm::Run(), lar_content::LArMuonLeadingHelper::SelectLeadingMCParticles(), SelectReconstructableTestBeamHierarchyMCParticles(), and lar_content::CheatingSliceSelectionTool::SelectSlices().

257 {
258  const MCParticle *pParentMCParticle = pMCParticle;
259 
260  while (pParentMCParticle->GetParentList().empty() == false)
261  {
262  if (1 != pParentMCParticle->GetParentList().size())
263  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
264 
265  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
266  }
267 
268  return pParentMCParticle;
269 }
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 747 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().

750 {
751  PfoVector sortedPfos;
752  for (const auto &mapEntry : pfoToReconstructable2DHitsMap)
753  sortedPfos.push_back(mapEntry.first);
754  std::sort(sortedPfos.begin(), sortedPfos.end(), LArPfoHelper::SortByNHits);
755 
756  for (const ParticleFlowObject *const pPfo : sortedPfos)
757  {
758  for (const MCContributionMap &mcParticleToHitsMap : selectedMCParticleToHitsMaps)
759  {
760  MCParticleVector sortedMCParticles;
761  for (const auto &mapEntry : mcParticleToHitsMap)
762  sortedMCParticles.push_back(mapEntry.first);
763  std::sort(sortedMCParticles.begin(), sortedMCParticles.end(), PointerLessThan<MCParticle>());
764 
765  for (const MCParticle *const pMCParticle : sortedMCParticles)
766  {
767  // Add map entries for this Pfo & MCParticle if required
768  if (pfoToMCParticleHitSharingMap.find(pPfo) == pfoToMCParticleHitSharingMap.end())
769  if (!pfoToMCParticleHitSharingMap.insert(PfoToMCParticleHitSharingMap::value_type(pPfo, MCParticleToSharedHitsVector())).second)
770  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT); // ATTN maybe overkill
771 
772  if (mcParticleToPfoHitSharingMap.find(pMCParticle) == mcParticleToPfoHitSharingMap.end())
773  if (!mcParticleToPfoHitSharingMap.insert(MCParticleToPfoHitSharingMap::value_type(pMCParticle, PfoToSharedHitsVector())).second)
774  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
775 
776  // Check this Pfo & MCParticle pairing hasn't already been checked
777  MCParticleToSharedHitsVector &mcHitPairs(pfoToMCParticleHitSharingMap.at(pPfo));
778  PfoToSharedHitsVector &pfoHitPairs(mcParticleToPfoHitSharingMap.at(pMCParticle));
779 
780  if (std::any_of(mcHitPairs.begin(), mcHitPairs.end(),
781  [&](const MCParticleCaloHitListPair &pair) { return (pair.first == pMCParticle); }))
782  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
783 
784  if (std::any_of(pfoHitPairs.begin(), pfoHitPairs.end(), [&](const PfoCaloHitListPair &pair) { return (pair.first == pPfo); }))
785  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
786 
787  // Add records to maps if there are any shared hits
788  const CaloHitList sharedHits(
789  LArMCParticleHelper::GetSharedHits(pfoToReconstructable2DHitsMap.at(pPfo), mcParticleToHitsMap.at(pMCParticle)));
790 
791  if (!sharedHits.empty())
792  {
793  mcHitPairs.push_back(MCParticleCaloHitListPair(pMCParticle, sharedHits));
794  pfoHitPairs.push_back(PfoCaloHitListPair(pPfo, sharedHits));
795 
796  std::sort(mcHitPairs.begin(), mcHitPairs.end(),
797  [](const MCParticleCaloHitListPair &a, const MCParticleCaloHitListPair &b) -> bool
798  {
799  return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size()
800  : LArMCParticleHelper::SortByMomentum(a.first, b.first));
801  });
802 
803  std::sort(pfoHitPairs.begin(), pfoHitPairs.end(),
804  [](const PfoCaloHitListPair &a, const PfoCaloHitListPair &b) -> bool {
805  return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size()
806  : LArPfoHelper::SortByNHits(a.first, b.first));
807  });
808  }
809  }
810  }
811  }
812 }
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 377 of file LArMCParticleHelper.cc.

References IsVisible().

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

378 {
379  // Navigate upward through MC daughter/parent links - collect this particle and all its parents
380  MCParticleVector mcVector;
381 
382  const MCParticle *pParentMCParticle = pMCParticle;
383  mcVector.push_back(pParentMCParticle);
384 
385  while (!pParentMCParticle->GetParentList().empty())
386  {
387  if (1 != pParentMCParticle->GetParentList().size())
388  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
389 
390  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
391  mcVector.push_back(pParentMCParticle);
392  }
393 
394  // Navigate downward through MC parent/daughter links - return the first long-lived charged particle
395  for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(), iterEnd = mcVector.rend(); iter != iterEnd; ++iter)
396  {
397  const MCParticle *const pNextParticle = *iter;
398 
399  if (LArMCParticleHelper::IsVisible(pNextParticle))
400  return pNextParticle;
401  }
402 
403  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
404 }
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 332 of file LArMCParticleHelper.cc.

References IsPrimary(), and SortByMomentum().

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

333 {
334  for (const MCParticle *const pMCParticle : *pMCParticleList)
335  {
336  if (LArMCParticleHelper::IsPrimary(pMCParticle))
337  mcPrimaryVector.push_back(pMCParticle);
338  }
339 
340  std::sort(mcPrimaryVector.begin(), mcPrimaryVector.end(), LArMCParticleHelper::SortByMomentum);
341 }
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 1024 of file LArMCParticleHelper.cc.

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

1025 {
1026  CaloHitList sharedHits;
1027 
1028  for (const CaloHit *const pCaloHit : hitListA)
1029  {
1030  if (std::find(hitListB.begin(), hitListB.end(), pCaloHit) != hitListB.end())
1031  sharedHits.push_back(pCaloHit);
1032  }
1033 
1034  return sharedHits;
1035 }
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::GetTrueVertex ( const pandora::MCParticleList *const  pMCParticleList,
pandora::CartesianVector &  trueVertex 
)
static

Retrieve the true neutrino vertex.

Parameters
pMCParticleListThe list of MC particles to search for the true vertex
trueVertexThe output true vertex position
Returns
true if a vertex is found, false otherwise

Definition at line 232 of file LArMCParticleHelper.cc.

References GetPrimaryMCParticleList(), and IsNeutrino().

233 {
234  MCParticleVector primaries;
235  LArMCParticleHelper::GetPrimaryMCParticleList(pMCParticleList, primaries);
236  if (!primaries.empty())
237  {
238  const MCParticle *primary{primaries.front()};
239  const MCParticleList &parents{primary->GetParentList()};
240  if (parents.size() == 1)
241  {
242  const MCParticle *trueNeutrino{parents.front()};
243  if (LArMCParticleHelper::IsNeutrino(trueNeutrino))
244  {
245  trueVertex = primaries.front()->GetVertex();
246  return true;
247  }
248  }
249  }
250 
251  return false;
252 }
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 bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.
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(), GetMCToHitsMap(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), IsCosmicRay(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::NeutrinoEventValidationAlgorithm::ProcessOutput(), lar_content::PfoValidationAlgorithm::Run(), and lar_content::MCParticleMonitoringAlgorithm::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

Returns true if passed a primary beam MCParticle.

Definition at line 93 of file LArMCParticleHelper.cc.

References GetNuanceCode(), and IsPrimary().

Referenced by lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), GetLeadingMCParticle(), GetLeadingMCParticleList(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), lar_content::LArHierarchyHelper::MCHierarchy::Node::IsTestBeamParticle(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::LArHierarchyHelper::MatchInfo::Print(), lar_content::PfoValidationAlgorithm::Run(), lar_content::MCParticleMonitoringAlgorithm::Run(), lar_content::CheatingBeamParticleIdTool::SelectOutputPfos(), and SelectReconstructableTestBeamHierarchyMCParticles().

94 {
95  const int nuance(LArMCParticleHelper::GetNuanceCode(pMCParticle));
96  return (LArMCParticleHelper::IsPrimary(pMCParticle) && ((nuance == 2000) || (nuance == 2001)));
97 }
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::IsBremsstrahlung ( const pandora::MCParticle *const  pMCParticle)
static

Definition at line 839 of file LArMCParticleHelper.cc.

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

840 {
841  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
842  if (!pLArMCParticle)
843  return false;
844 
845  switch (pLArMCParticle->GetProcess())
846  {
847  case MC_PROC_E_BREM:
848  case MC_PROC_MU_BREM:
849  case MC_PROC_HAD_BREM:
850  return true;
851  default:
852  return false;
853  }
854 
855  return false;
856 }
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 860 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.

861 {
862  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
863  if (!pLArMCParticle)
864  return false;
865 
866  switch (pLArMCParticle->GetProcess())
867  {
869  case MC_PROC_N_CAPTURE:
873  return true;
874  default:
875  return false;
876  }
877 
878  return false;
879 }
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::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 883 of file LArMCParticleHelper.cc.

References lar_content::MC_PROC_DECAY.

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

884 {
885  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
886  if (!pLArMCParticle)
887  return false;
888 
889  switch (pLArMCParticle->GetProcess())
890  {
891  case MC_PROC_DECAY:
892  return true;
893  default:
894  return false;
895  }
896 
897  return false;
898 }
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 1230 of file LArMCParticleHelper.cc.

References util::abs().

1231 {
1232  const MCParticle *pCurrentParticle = pMCParticle;
1233  while (!pCurrentParticle->GetParentList().empty())
1234  {
1235  if (pCurrentParticle->GetParentList().size() > 1)
1236  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
1237 
1238  const MCParticle *pParent = *(pCurrentParticle->GetParentList().begin());
1239  const bool found{isChargeSensitive ? pParent->GetParticleId() == pdg : std::abs(pParent->GetParticleId()) == std::abs(pdg)};
1240  if (found)
1241  return true;
1242  pCurrentParticle = pParent;
1243  }
1244 
1245  return false;
1246 }
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 902 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().

903 {
904  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
905  if (!pLArMCParticle)
906  return false;
907 
908  switch (pLArMCParticle->GetProcess())
909  {
912  case MC_PROC_HAD_ELASTIC:
913  case MC_PROC_RAYLEIGH:
914  return true;
915  default:
916  return false;
917  }
918 
919  return false;
920 }
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 924 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().

925 {
926  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
927  if (!pLArMCParticle)
928  return false;
929 
930  switch (pLArMCParticle->GetProcess())
931  {
932  case MC_PROC_COMPT:
951  return true;
952  default:
953  return false;
954  }
955 
956  return false;
957 }
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 961 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.

962 {
963  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
964  if (!pLArMCParticle)
965  return false;
966 
967  switch (pLArMCParticle->GetProcess())
968  {
969  case MC_PROC_E_IONI:
970  case MC_PROC_MU_IONI:
971  case MC_PROC_HAD_IONI:
972  case MC_PROC_ION_IONI:
973  return true;
974  default:
975  return false;
976  }
977 
978  return false;
979 }
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(), CompleteMCHierarchy(), lar_content::NeutrinoIdTool< T >::CountNeutrinoInducedHits(), lar_content::CheatingNeutrinoCreationAlgorithm::GetMCNeutrinoVector(), GetTrueNeutrinos(), GetTrueVertex(), lar_content::LArEventTopology::Particle::GetVertices(), IsBeamNeutrinoFinalState(), lar_content::LArEventTopology::LArEventTopology(), lar_content::LArHierarchyHelper::MatchInfo::Print(), lar_content::CheatingCosmicRayIdentificationAlg::Run(), lar_content::CheatingVertexCreationAlgorithm::Run(), lar_content::VisualParticleMonitoringAlgorithm::Run(), and lar_content::HierarchyValidationAlgorithm::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 983 of file LArMCParticleHelper.cc.

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

984 {
985  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
986  if (!pLArMCParticle)
987  return false;
988 
989  switch (pLArMCParticle->GetProcess())
990  {
993  case MC_PROC_MU_NUCLEAR:
994  return true;
995  default:
996  return false;
997  }
998 
999  return false;
1000 }
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 1004 of file LArMCParticleHelper.cc.

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

1005 {
1006  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
1007  if (!pLArMCParticle)
1008  return false;
1009 
1010  switch (pLArMCParticle->GetProcess())
1011  {
1012  case MC_PROC_MU_PAIR_PROD:
1013  case MC_PROC_HAD_PAIR_PROD:
1014  return true;
1015  default:
1016  return false;
1017  }
1018 
1019  return false;
1020 }
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 1396 of file LArMCParticleHelper.cc.

References util::abs().

Referenced by SelectCaloHits().

1398 {
1399  if (NEUTRON == std::abs(pThisMCParticle->GetParticleId()))
1400  return false;
1401 
1402  if ((PHOTON == pThisMCParticle->GetParticleId()) && (PHOTON != pOriginalPrimary->GetParticleId()) &&
1403  (E_MINUS != std::abs(pOriginalPrimary->GetParticleId())))
1404  {
1405  if ((pThisMCParticle->GetEndpoint() - pThisMCParticle->GetVertex()).GetMagnitude() > maxPhotonPropagation)
1406  return false;
1407  }
1408 
1409  if (pThisMCParticle == pHitMCParticle)
1410  return true;
1411 
1412  for (const MCParticle *const pDaughterMCParticle : pThisMCParticle->GetDaughterList())
1413  {
1414  if (PassMCParticleChecks(pOriginalPrimary, pDaughterMCParticle, pHitMCParticle, maxPhotonPropagation))
1415  return true;
1416  }
1417 
1418  return false;
1419 }
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 1196 of file LArMCParticleHelper.cc.

References GetPrimaryMCParticle(), and PassMCParticleChecks().

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

1198 {
1199  if (!selectInputHits)
1200  {
1201  selectedCaloHitList.insert(selectedCaloHitList.end(), pCaloHitList->begin(), pCaloHitList->end());
1202  return;
1203  }
1204 
1205  for (const CaloHit *const pCaloHit : *pCaloHitList)
1206  {
1207  try
1208  {
1209  const MCParticle *const pHitParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
1210 
1211  LArMCParticleHelper::MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pHitParticle);
1212 
1213  if (mcToTargetMCMap.end() == mcIter)
1214  continue;
1215 
1216  // ATTN With folding on or off, still require primary particle to review hierarchy details
1217  const MCParticle *const pPrimaryParticle = LArMCParticleHelper::GetPrimaryMCParticle(pHitParticle);
1218 
1219  if (PassMCParticleChecks(pPrimaryParticle, pPrimaryParticle, pHitParticle, maxPhotonPropagation))
1220  selectedCaloHitList.push_back(pCaloHit);
1221  }
1222  catch (const StatusCodeException &)
1223  {
1224  }
1225  }
1226 }
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 1311 of file LArMCParticleHelper.cc.

References f, and weight.

Referenced by SelectParticlesByHitCount().

1313 {
1314  if (!selectInputHits)
1315  {
1316  selectedGoodCaloHitList.insert(selectedGoodCaloHitList.end(), pSelectedCaloHitList->begin(), pSelectedCaloHitList->end());
1317  return;
1318  }
1319 
1320  for (const CaloHit *const pCaloHit : *pSelectedCaloHitList)
1321  {
1322  MCParticleVector mcParticleVector;
1323  for (const auto &mapEntry : pCaloHit->GetMCParticleWeightMap())
1324  mcParticleVector.push_back(mapEntry.first);
1325  std::sort(mcParticleVector.begin(), mcParticleVector.end(), PointerLessThan<MCParticle>());
1326 
1327  MCParticleWeightMap targetWeightMap;
1328 
1329  for (const MCParticle *const pMCParticle : mcParticleVector)
1330  {
1331  const float weight(pCaloHit->GetMCParticleWeightMap().at(pMCParticle));
1332  LArMCParticleHelper::MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pMCParticle);
1333 
1334  if (mcToTargetMCMap.end() != mcIter)
1335  targetWeightMap[mcIter->second] += weight;
1336  }
1337 
1338  MCParticleVector mcTargetVector;
1339  for (const auto &mapEntry : targetWeightMap)
1340  mcTargetVector.push_back(mapEntry.first);
1341  std::sort(mcTargetVector.begin(), mcTargetVector.end(), PointerLessThan<MCParticle>());
1342 
1343  const MCParticle *pBestTargetParticle(nullptr);
1344  float bestTargetWeight(0.f), targetWeightSum(0.f);
1345 
1346  for (const MCParticle *const pTargetMCParticle : mcTargetVector)
1347  {
1348  const float targetWeight(targetWeightMap.at(pTargetMCParticle));
1349  targetWeightSum += targetWeight;
1350 
1351  if (targetWeight > bestTargetWeight)
1352  {
1353  bestTargetWeight = targetWeight;
1354  pBestTargetParticle = pTargetMCParticle;
1355  }
1356  }
1357 
1358  if (!pBestTargetParticle || (targetWeightSum < std::numeric_limits<float>::epsilon()) || ((bestTargetWeight / targetWeightSum) < minHitSharingFraction))
1359  continue;
1360 
1361  selectedGoodCaloHitList.push_back(pCaloHit);
1362  }
1363 }
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 1271 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().

1273 {
1274  // Apply restrictions on the number of good hits associated with the MCParticles
1275  for (const MCParticle *const pMCTarget : candidateTargets)
1276  {
1277  MCContributionMap::const_iterator trueHitsIter = mcToTrueHitListMap.find(pMCTarget);
1278  if (mcToTrueHitListMap.end() == trueHitsIter)
1279  continue;
1280 
1281  const CaloHitList &caloHitList(trueHitsIter->second);
1282 
1283  // Remove shared hits where target particle deposits below threshold energy fraction
1284  CaloHitList goodCaloHitList;
1286  &caloHitList, mcToTargetMCMap, goodCaloHitList, parameters.m_selectInputHits, parameters.m_minHitSharingFraction);
1287 
1288  if (goodCaloHitList.size() < parameters.m_minPrimaryGoodHits)
1289  continue;
1290 
1291  unsigned int nGoodViews(0);
1292  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1293  ++nGoodViews;
1294 
1295  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1296  ++nGoodViews;
1297 
1298  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1299  ++nGoodViews;
1300 
1301  if (nGoodViews < parameters.m_minPrimaryGoodViews)
1302  continue;
1303 
1304  if (!selectedMCParticlesToHitsMap.insert(MCContributionMap::value_type(pMCTarget, caloHitList)).second)
1305  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
1306  }
1307 }
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 1367 of file LArMCParticleHelper.cc.

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

Referenced by SelectReconstructableMCParticles(), and SelectReconstructableTestBeamHierarchyMCParticles().

1369 {
1370  for (const MCParticle *const pMCParticle : inputMCParticles)
1371  {
1372  if (parameters.m_foldBackHierarchy)
1373  {
1374  if (!fCriteria(pMCParticle))
1375  continue;
1376  }
1377  else
1378  {
1379  if (isTestBeam)
1380  {
1381  if (!LArMCParticleHelper::DoesLeadingMeetCriteria(pMCParticle, fCriteria))
1382  continue;
1383  }
1384  else
1385  {
1386  if (!LArMCParticleHelper::DoesPrimaryMeetCriteria(pMCParticle, fCriteria))
1387  continue;
1388  }
1389  }
1390  selectedParticles.push_back(pMCParticle);
1391  }
1392 }
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 607 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(), GetMCToHitsMap(), lar_content::MvaPfoCharacterisationAlgorithm< T >::IsClearTrack(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::PfoValidationAlgorithm::Run(), and lar_content::MCParticleMonitoringAlgorithm::Run().

609 {
610  // Obtain map: [mc particle -> target mc particle]
611  LArMCParticleHelper::MCRelationMap mcToTargetMCMap;
612  parameters.m_foldBackHierarchy ? LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToTargetMCMap)
613  : LArMCParticleHelper::GetMCToSelfMap(pMCParticleList, mcToTargetMCMap);
614 
615  // Remove non-reconstructable hits, e.g. those downstream of a neutron
616  // Unless selectInputHits == false
617  CaloHitList selectedCaloHitList;
618  LArMCParticleHelper::SelectCaloHits(pCaloHitList, mcToTargetMCMap, selectedCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
619 
620  // Obtain maps: [hit -> target mc particle], [target mc particle -> list of hits]
621  CaloHitToMCMap trueHitToTargetMCMap;
622  MCContributionMap targetMCToTrueHitListMap;
623  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&selectedCaloHitList, mcToTargetMCMap, trueHitToTargetMCMap, targetMCToTrueHitListMap);
624 
625  // Obtain vector: target mc particles
626  MCParticleVector targetMCVector;
627  if (parameters.m_foldBackHierarchy)
628  {
629  LArMCParticleHelper::GetPrimaryMCParticleList(pMCParticleList, targetMCVector);
630  }
631  else
632  {
633  std::copy(pMCParticleList->begin(), pMCParticleList->end(), std::back_inserter(targetMCVector));
634  }
635 
636  // Select MCParticles matching criteria
637  MCParticleVector candidateTargets;
638  LArMCParticleHelper::SelectParticlesMatchingCriteria(targetMCVector, fCriteria, candidateTargets, parameters, false);
639 
640  // Ensure the MCParticles have enough "good" hits to be reconstructed
641  LArMCParticleHelper::SelectParticlesByHitCount(candidateTargets, targetMCToTrueHitListMap, mcToTargetMCMap, parameters, selectedMCParticlesToHitsMap);
642 }
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 646 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().

648 {
649  // Obtain map: [mc particle -> target mc particle]
650  LArMCParticleHelper::MCRelationMap mcToTargetMCMap;
651  parameters.m_foldBackHierarchy ? LArMCParticleHelper::GetMCLeadingMap(pMCParticleList, mcToTargetMCMap)
652  : LArMCParticleHelper::GetMCToSelfMap(pMCParticleList, mcToTargetMCMap);
653 
654  // Remove non-reconstructable hits, e.g. those downstream of a neutron
655  // Unless selectInputHits == false
656  CaloHitList selectedCaloHitList;
657  LArMCParticleHelper::SelectCaloHits(pCaloHitList, mcToTargetMCMap, selectedCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
658 
659  // Obtain maps: [hit -> target mc particle], [target mc particle -> list of hits]
660  CaloHitToMCMap trueHitToTargetMCMap;
661  MCContributionMap targetMCToTrueHitListMap;
662  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&selectedCaloHitList, mcToTargetMCMap, trueHitToTargetMCMap, targetMCToTrueHitListMap);
663 
664  // Obtain vector: target mc particles
665  MCParticleVector targetMCVector;
666  if (parameters.m_foldBackHierarchy)
667  {
668  LArMCParticleHelper::GetLeadingMCParticleList(pMCParticleList, targetMCVector);
669  }
670  else
671  {
672  std::copy(pMCParticleList->begin(), pMCParticleList->end(), std::back_inserter(targetMCVector));
673  }
674 
675  // Select MCParticles matching criteria
676  MCParticleVector candidateTargets;
677  LArMCParticleHelper::SelectParticlesMatchingCriteria(targetMCVector, fCriteria, candidateTargets, parameters, true);
678 
679  // Ensure the MCParticles have enough "good" hits to be reconstructed
680  LArMCParticleHelper::SelectParticlesByHitCount(candidateTargets, targetMCToTrueHitListMap, mcToTargetMCMap, parameters, selectedMCParticlesToHitsMap);
681 
682  // ATTN: The parent particle must be in the hierarchy map, event if not reconstructable
683  for (const MCParticle *const pMCParticle : candidateTargets)
684  {
685  if (!LArMCParticleHelper::IsBeamParticle(pMCParticle))
686  continue;
687 
688  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle));
689  if (selectedMCParticlesToHitsMap.find(pParentMCParticle) == selectedMCParticlesToHitsMap.end())
690  {
691  CaloHitList caloHitList;
692  selectedMCParticlesToHitsMap.insert(MCContributionMap::value_type(pParentMCParticle, caloHitList));
693  }
694  }
695 }
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 547 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().

548 {
549  // Sort by momentum (prefer higher momentum)
550  const float momentumLhs(pLhs->GetMomentum().GetMagnitudeSquared());
551  const float momentumRhs(pRhs->GetMomentum().GetMagnitudeSquared());
552 
553  if (std::fabs(momentumLhs - momentumRhs) > std::numeric_limits<float>::epsilon())
554  return (momentumLhs > momentumRhs);
555 
556  // Sort by energy (prefer lighter particles)
557  if (std::fabs(pLhs->GetEnergy() - pRhs->GetEnergy()) > std::numeric_limits<float>::epsilon())
558  return (pLhs->GetEnergy() < pRhs->GetEnergy());
559 
560  // Sort by PDG code (prefer smaller numbers)
561  if (pLhs->GetParticleId() != pRhs->GetParticleId())
562  return (pLhs->GetParticleId() < pRhs->GetParticleId());
563 
564  // Sort by vertex position (tie-breaker)
565  const float positionLhs(pLhs->GetVertex().GetMagnitudeSquared());
566  const float positionRhs(pRhs->GetVertex().GetMagnitudeSquared());
567 
568  return (positionLhs < positionRhs);
569 }

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