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

Static Private Member Functions

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

Detailed Description

LArMCParticleHelper class.

Definition at line 24 of file LArMCParticleHelper.h.

Member Typedef Documentation

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

Definition at line 32 of file LArMCParticleHelper.h.

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

Definition at line 33 of file LArMCParticleHelper.h.

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

Definition at line 44 of file LArMCParticleHelper.h.

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

Definition at line 38 of file LArMCParticleHelper.h.

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

Definition at line 35 of file LArMCParticleHelper.h.

Definition at line 36 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.

Definition at line 46 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.

Definition at line 47 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 959 of file LArMCParticleHelper.cc.

960 {
961  CartesianVector childDirection{pMCChild->GetEndpoint() - pMCChild->GetVertex()};
962  if (childDirection.GetMagnitude() < std::numeric_limits<float>::epsilon())
963  return true;
964  childDirection = childDirection.GetUnitVector();
965 
966  const MCParticle *pMCUpstream{pMCParent};
967  while (true)
968  {
969  CartesianVector parentDirection{pMCUpstream->GetEndpoint() - pMCUpstream->GetVertex()};
970  if (parentDirection.GetMagnitude() > std::numeric_limits<float>::epsilon())
971  {
972  parentDirection = parentDirection.GetUnitVector();
973  return parentDirection.GetDotProduct(childDirection) >= cosAngleTolerance;
974  }
975  else
976  {
977  const MCParticleList &parentList{pMCUpstream->GetParentList()};
978  const size_t size{parentList.size()};
979  if (size == 1)
980  pMCUpstream = parentList.front();
981  else if (size == 0)
982  return true;
983  else
984  return false;
985  }
986  }
987 
988  return false;
989 }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
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
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 1082 of file LArMCParticleHelper.cc.

1084 {
1085  const CaloHitList &isolatedCaloHitList{pCluster->GetIsolatedCaloHitList()};
1086  CaloHitList caloHitList;
1087  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
1088  for (const CaloHit *pCaloHit : isolatedCaloHitList)
1089  caloHitList.push_back(pCaloHit);
1090 
1091  // Filter for only reconstructable hits
1092  for (const CaloHit *const pCaloHit : caloHitList)
1093  {
1094  bool isTargetHit{false};
1095  for (const MCContributionMap &mcParticleToHitsMap : selectedMCToHitsMaps)
1096  { // ATTN This map is unordered, but this does not impact search for specific target hit
1097  for (const MCContributionMap::value_type &mapEntry : mcParticleToHitsMap)
1098  {
1099  if (std::find(mapEntry.second.begin(), mapEntry.second.end(), pCaloHit) != mapEntry.second.end())
1100  {
1101  isTargetHit = true;
1102  break;
1103  }
1104  }
1105  if (isTargetHit)
1106  break;
1107  }
1108 
1109  if (isTargetHit)
1110  reconstructableCaloHitList2D.push_back(pCaloHit);
1111  }
1112 }
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 1016 of file LArMCParticleHelper.cc.

1018 {
1019 
1020  PfoList pfoList;
1021  // If foldBackHierarchy collect all 2D calo hits in pfo hierarchy
1022  // else collect hits directly belonging to pfo
1023  if (foldBackHierarchy)
1024  {
1025  // ATTN: Only collect downstream pfos for daughter test beam particles & cosmics
1026  if (pPfo->GetParentPfoList().empty() && LArPfoHelper::IsTestBeam(pPfo))
1027  {
1028  pfoList.push_back(pPfo);
1029  }
1030  else
1031  {
1032  LArPfoHelper::GetAllDownstreamPfos(pPfo, pfoList);
1033  }
1034  }
1035  else
1036  {
1037  pfoList.push_back(pPfo);
1038  }
1039 
1040  LArMCParticleHelper::CollectReconstructable2DHits(pfoList, selectedMCParticleToHitsMaps, reconstructableCaloHitList2D);
1041 }
static bool IsTestBeam(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a test beam particle.
static void CollectReconstructable2DHits(const pandora::ParticleFlowObject *const pPfo, const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D, const bool foldBackHierarchy)
For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected recon...
static void GetAllDownstreamPfos(const pandora::PfoList &inputPfoList, pandora::PfoList &outputPfoList)
Get a flat list of all pfos, recursively, of all daughters associated with those pfos in an input lis...
bool lar_content::LArMCParticleHelper::DoesLeadingMeetCriteria ( const pandora::MCParticle *const  pMCParticle,
std::function< bool(const pandora::MCParticle *const)>  fCriteria 
)
static

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

Parameters
pMCParticlethe input mc particle
fCriteriathe given criteria

Definition at line 61 of file LArMCParticleHelper.cc.

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.

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

Get all ancestor mc particles.

Parameters
pMCParticlethe input mc particle
ancestorMCParticleListthe output ancestor mc particle list

Definition at line 290 of file LArMCParticleHelper.cc.

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

Get all descendent mc particles.

Parameters
pMCParticlethe input mc particle
descendentMCParticleListthe output descendent mc particle list

Definition at line 249 of file LArMCParticleHelper.cc.

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

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

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

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

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

Definition at line 1170 of file LArMCParticleHelper.cc.

1171 {
1172  const MCParticle *const pRoot{LArMCParticleHelper::GetParentMCParticle(pMCParticle)};
1173  MCParticleList queue;
1174  mcParticleList.emplace_back(pRoot);
1175  queue.emplace_back(pRoot);
1176 
1177  while (!queue.empty())
1178  {
1179  const MCParticleList &daughters{queue.front()->GetDaughterList()};
1180  queue.pop_front();
1181  for (const MCParticle *pDaughter : daughters)
1182  {
1183  mcParticleList.emplace_back(pDaughter);
1184  queue.emplace_back(pDaughter);
1185  }
1186  }
1187 }
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 736 of file LArMCParticleHelper.cc.

738 {
739  LArMCParticleHelper::GetClusterToReconstructable2DHitsMap(clusterList, MCContributionMapVector({selectedMCToHitsMap}), clusterToReconstructable2DHitsMap);
740 }
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 744 of file LArMCParticleHelper.cc.

746 {
747  for (const Cluster *const pCluster : clusterList)
748  {
749  CaloHitList caloHitList;
750  LArMCParticleHelper::CollectReconstructable2DHits(pCluster, selectedMCToHitsMaps, caloHitList);
751 
752  if (!clusterToReconstructable2DHitsMap.insert(ClusterContributionMap::value_type(pCluster, caloHitList)).second)
753  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
754  }
755 }
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...
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.

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 369 of file LArMCParticleHelper.cc.

370 {
371  // ATTN: If not beam particle return primary particle
372  const bool isBeamParticle(LArMCParticleHelper::IsBeamParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle)));
373 
374  if (!isBeamParticle)
375  return LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle);
376 
377  // Navigate upward through MC daughter/parent links - collect this particle and all its parents
378  MCParticleVector mcVector;
379 
380  const MCParticle *pParentMCParticle = pMCParticle;
381  mcVector.push_back(pParentMCParticle);
382 
383  while (!pParentMCParticle->GetParentList().empty())
384  {
385  if (1 != pParentMCParticle->GetParentList().size())
386  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
387 
388  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
389  mcVector.push_back(pParentMCParticle);
390  }
391 
392  int hierarchyTier(0);
393  const MCParticle *pLeadingMCParticle(nullptr);
394 
395  // Navigate downward through MC parent/daughter links - return the first long-lived charged particle
396  for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(), iterEnd = mcVector.rend(); iter != iterEnd; ++iter)
397  {
398  const MCParticle *const pNextParticle = *iter;
399 
400  // ATTN: Squash any invisible particles (e.g. pizero)
401  if (!LArMCParticleHelper::IsVisible(pNextParticle))
402  continue;
403 
404  if (hierarchyTier <= hierarchyTierLimit)
405  pLeadingMCParticle = pNextParticle;
406 
407  hierarchyTier++;
408  }
409 
410  if (!pLeadingMCParticle)
411  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
412 
413  return pLeadingMCParticle;
414 }
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.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
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.
void lar_content::LArMCParticleHelper::GetLeadingMCParticleList ( const pandora::MCParticleList *const  pMCParticleList,
pandora::MCParticleVector &  mcLeadingVector 
)
static

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

Parameters
pMCParticleListthe input mc particle list
mcLeadingVectorthe output mc particle vector

Definition at line 321 of file LArMCParticleHelper.cc.

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

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

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

Definition at line 462 of file LArMCParticleHelper.cc.

463 {
464  ClusterList clusterList;
465  LArPfoHelper::GetTwoDClusterList(pPfo, clusterList);
466  return MCParticleHelper::GetMainMCParticle(&clusterList);
467 }
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 435 of file LArMCParticleHelper.cc.

436 {
437  for (const MCParticle *const pMCParticle : *pMCParticleList)
438  {
439  try
440  {
441  const MCParticle *const pLeadingMCParticle = LArMCParticleHelper::GetLeadingMCParticle(pMCParticle);
442  mcLeadingMap[pMCParticle] = pLeadingMCParticle;
443  }
444  catch (const StatusCodeException &)
445  {
446  }
447  }
448 }
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 497 of file LArMCParticleHelper.cc.

499 {
500  for (const CaloHit *const pCaloHit : *pCaloHitList)
501  {
502  try
503  {
504  const MCParticle *const pHitParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
505  const MCParticle *pTargetParticle(pHitParticle);
506 
507  // ATTN Do not map back to target if mc to primary mc map or mc to self map not provided
508  if (!mcToTargetMCMap.empty())
509  {
510  MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pHitParticle);
511 
512  if (mcToTargetMCMap.end() == mcIter)
513  continue;
514 
515  pTargetParticle = mcIter->second;
516  }
517 
518  mcToTrueHitListMap[pTargetParticle].push_back(pCaloHit);
519  hitToMCMap[pCaloHit] = pTargetParticle;
520  }
521  catch (StatusCodeException &statusCodeException)
522  {
523  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
524  throw statusCodeException;
525  }
526  }
527 }
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 418 of file LArMCParticleHelper.cc.

419 {
420  for (const MCParticle *const pMCParticle : *pMCParticleList)
421  {
422  try
423  {
424  const MCParticle *const pPrimaryMCParticle = LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle);
425  mcPrimaryMap[pMCParticle] = pPrimaryMCParticle;
426  }
427  catch (const StatusCodeException &)
428  {
429  }
430  }
431 }
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
void lar_content::LArMCParticleHelper::GetMCToSelfMap ( const pandora::MCParticleList *const  pMCParticleList,
MCRelationMap mcToSelfMap 
)
static

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

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

Definition at line 452 of file LArMCParticleHelper.cc.

453 {
454  for (const MCParticle *const pMCParticle : *pMCParticleList)
455  {
456  mcToSelfMap[pMCParticle] = pMCParticle;
457  }
458 }
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.

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 }
QTextStream & endl(QTextStream &s)
const MCParticle * lar_content::LArMCParticleHelper::GetParentMCParticle ( const pandora::MCParticle *const  pMCParticle)
static

Get the parent mc particle.

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

Definition at line 232 of file LArMCParticleHelper.cc.

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

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

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

Definition at line 671 of file LArMCParticleHelper.cc.

674 {
675  PfoVector sortedPfos;
676  for (const auto &mapEntry : pfoToReconstructable2DHitsMap)
677  sortedPfos.push_back(mapEntry.first);
678  std::sort(sortedPfos.begin(), sortedPfos.end(), LArPfoHelper::SortByNHits);
679 
680  for (const ParticleFlowObject *const pPfo : sortedPfos)
681  {
682  for (const MCContributionMap &mcParticleToHitsMap : selectedMCParticleToHitsMaps)
683  {
684  MCParticleVector sortedMCParticles;
685  for (const auto &mapEntry : mcParticleToHitsMap)
686  sortedMCParticles.push_back(mapEntry.first);
687  std::sort(sortedMCParticles.begin(), sortedMCParticles.end(), PointerLessThan<MCParticle>());
688 
689  for (const MCParticle *const pMCParticle : sortedMCParticles)
690  {
691  // Add map entries for this Pfo & MCParticle if required
692  if (pfoToMCParticleHitSharingMap.find(pPfo) == pfoToMCParticleHitSharingMap.end())
693  if (!pfoToMCParticleHitSharingMap.insert(PfoToMCParticleHitSharingMap::value_type(pPfo, MCParticleToSharedHitsVector())).second)
694  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT); // ATTN maybe overkill
695 
696  if (mcParticleToPfoHitSharingMap.find(pMCParticle) == mcParticleToPfoHitSharingMap.end())
697  if (!mcParticleToPfoHitSharingMap.insert(MCParticleToPfoHitSharingMap::value_type(pMCParticle, PfoToSharedHitsVector())).second)
698  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
699 
700  // Check this Pfo & MCParticle pairing hasn't already been checked
701  MCParticleToSharedHitsVector &mcHitPairs(pfoToMCParticleHitSharingMap.at(pPfo));
702  PfoToSharedHitsVector &pfoHitPairs(mcParticleToPfoHitSharingMap.at(pMCParticle));
703 
704  if (std::any_of(mcHitPairs.begin(), mcHitPairs.end(),
705  [&](const MCParticleCaloHitListPair &pair) { return (pair.first == pMCParticle); }))
706  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
707 
708  if (std::any_of(pfoHitPairs.begin(), pfoHitPairs.end(), [&](const PfoCaloHitListPair &pair) { return (pair.first == pPfo); }))
709  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
710 
711  // Add records to maps if there are any shared hits
712  const CaloHitList sharedHits(
713  LArMCParticleHelper::GetSharedHits(pfoToReconstructable2DHitsMap.at(pPfo), mcParticleToHitsMap.at(pMCParticle)));
714 
715  if (!sharedHits.empty())
716  {
717  mcHitPairs.push_back(MCParticleCaloHitListPair(pMCParticle, sharedHits));
718  pfoHitPairs.push_back(PfoCaloHitListPair(pPfo, sharedHits));
719 
720  std::sort(mcHitPairs.begin(), mcHitPairs.end(), [](const MCParticleCaloHitListPair &a, const MCParticleCaloHitListPair &b) -> bool {
721  return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size()
722  : LArMCParticleHelper::SortByMomentum(a.first, b.first));
723  });
724 
725  std::sort(pfoHitPairs.begin(), pfoHitPairs.end(), [](const PfoCaloHitListPair &a, const PfoCaloHitListPair &b) -> bool {
726  return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size() : LArPfoHelper::SortByNHits(a.first, b.first));
727  });
728  }
729  }
730  }
731  }
732 }
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
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
const double a
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
static bool * b
Definition: config.cpp:1043
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
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 338 of file LArMCParticleHelper.cc.

339 {
340  // Navigate upward through MC daughter/parent links - collect this particle and all its parents
341  MCParticleVector mcVector;
342 
343  const MCParticle *pParentMCParticle = pMCParticle;
344  mcVector.push_back(pParentMCParticle);
345 
346  while (!pParentMCParticle->GetParentList().empty())
347  {
348  if (1 != pParentMCParticle->GetParentList().size())
349  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
350 
351  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
352  mcVector.push_back(pParentMCParticle);
353  }
354 
355  // Navigate downward through MC parent/daughter links - return the first long-lived charged particle
356  for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(), iterEnd = mcVector.rend(); iter != iterEnd; ++iter)
357  {
358  const MCParticle *const pNextParticle = *iter;
359 
360  if (LArMCParticleHelper::IsVisible(pNextParticle))
361  return pNextParticle;
362  }
363 
364  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
365 }
static bool IsVisible(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is visible (i.e. long-lived charged particle)
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
void lar_content::LArMCParticleHelper::GetPrimaryMCParticleList ( const pandora::MCParticleList *const  pMCParticleList,
pandora::MCParticleVector &  mcPrimaryVector 
)
static

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

Parameters
pMCParticleListthe input mc particle list
mcPrimaryVectorthe output mc particle vector

Definition at line 308 of file LArMCParticleHelper.cc.

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

Get the hits in the intersection of two hit lists.

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

Definition at line 944 of file LArMCParticleHelper.cc.

945 {
946  CaloHitList sharedHits;
947 
948  for (const CaloHit *const pCaloHit : hitListA)
949  {
950  if (std::find(hitListB.begin(), hitListB.end(), pCaloHit) != hitListB.end())
951  sharedHits.push_back(pCaloHit);
952  }
953 
954  return sharedHits;
955 }
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
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.

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.

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

Returns true if passed a primary neutrino final state MCParticle.

Definition at line 77 of file LArMCParticleHelper.cc.

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.

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 759 of file LArMCParticleHelper.cc.

760 {
761  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
762  if (!pLArMCParticle)
763  return false;
764 
765  switch (pLArMCParticle->GetProcess())
766  {
767  case MC_PROC_E_BREM:
768  case MC_PROC_MU_BREM:
769  case MC_PROC_HAD_BREM:
770  return true;
771  default:
772  return false;
773  }
774 
775  return false;
776 }
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 780 of file LArMCParticleHelper.cc.

781 {
782  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
783  if (!pLArMCParticle)
784  return false;
785 
786  switch (pLArMCParticle->GetProcess())
787  {
789  case MC_PROC_N_CAPTURE:
793  return true;
794  default:
795  return false;
796  }
797 
798  return false;
799 }
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.

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 803 of file LArMCParticleHelper.cc.

804 {
805  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
806  if (!pLArMCParticle)
807  return false;
808 
809  switch (pLArMCParticle->GetProcess())
810  {
811  case MC_PROC_DECAY:
812  return true;
813  default:
814  return false;
815  }
816 
817  return false;
818 }
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 1150 of file LArMCParticleHelper.cc.

1151 {
1152  const MCParticle *pCurrentParticle = pMCParticle;
1153  while (!pCurrentParticle->GetParentList().empty())
1154  {
1155  if (pCurrentParticle->GetParentList().size() > 1)
1156  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
1157 
1158  const MCParticle *pParent = *(pCurrentParticle->GetParentList().begin());
1159  const bool found{isChargeSensitive ? pParent->GetParticleId() == pdg : std::abs(pParent->GetParticleId()) == std::abs(pdg)};
1160  if (found)
1161  return true;
1162  pCurrentParticle = pParent;
1163  }
1164 
1165  return false;
1166 }
T abs(T value)
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 822 of file LArMCParticleHelper.cc.

823 {
824  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
825  if (!pLArMCParticle)
826  return false;
827 
828  switch (pLArMCParticle->GetProcess())
829  {
832  case MC_PROC_HAD_ELASTIC:
833  case MC_PROC_RAYLEIGH:
834  return true;
835  default:
836  return false;
837  }
838 
839  return false;
840 }
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 844 of file LArMCParticleHelper.cc.

845 {
846  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
847  if (!pLArMCParticle)
848  return false;
849 
850  switch (pLArMCParticle->GetProcess())
851  {
852  case MC_PROC_COMPT:
871  return true;
872  default:
873  return false;
874  }
875 
876  return false;
877 }
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 881 of file LArMCParticleHelper.cc.

882 {
883  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
884  if (!pLArMCParticle)
885  return false;
886 
887  switch (pLArMCParticle->GetProcess())
888  {
889  case MC_PROC_E_IONI:
890  case MC_PROC_MU_IONI:
891  case MC_PROC_HAD_IONI:
892  case MC_PROC_ION_IONI:
893  return true;
894  default:
895  return false;
896  }
897 
898  return false;
899 }
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.

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.

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.

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 }
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
T abs(T value)
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 903 of file LArMCParticleHelper.cc.

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

925 {
926  const LArMCParticle *pLArMCParticle{dynamic_cast<const LArMCParticle *>(pMCParticle)};
927  if (!pLArMCParticle)
928  return false;
929 
930  switch (pLArMCParticle->GetProcess())
931  {
934  return true;
935  default:
936  return false;
937  }
938 
939  return false;
940 }
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.

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.

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.

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 }
T abs(T value)
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 1316 of file LArMCParticleHelper.cc.

1318 {
1319  if (NEUTRON == std::abs(pThisMCParticle->GetParticleId()))
1320  return false;
1321 
1322  if ((PHOTON == pThisMCParticle->GetParticleId()) && (PHOTON != pOriginalPrimary->GetParticleId()) &&
1323  (E_MINUS != std::abs(pOriginalPrimary->GetParticleId())))
1324  {
1325  if ((pThisMCParticle->GetEndpoint() - pThisMCParticle->GetVertex()).GetMagnitude() > maxPhotonPropagation)
1326  return false;
1327  }
1328 
1329  if (pThisMCParticle == pHitMCParticle)
1330  return true;
1331 
1332  for (const MCParticle *const pDaughterMCParticle : pThisMCParticle->GetDaughterList())
1333  {
1334  if (PassMCParticleChecks(pOriginalPrimary, pDaughterMCParticle, pHitMCParticle, maxPhotonPropagation))
1335  return true;
1336  }
1337 
1338  return false;
1339 }
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...
T abs(T value)
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 1116 of file LArMCParticleHelper.cc.

1118 {
1119  if (!selectInputHits)
1120  {
1121  selectedCaloHitList.insert(selectedCaloHitList.end(), pCaloHitList->begin(), pCaloHitList->end());
1122  return;
1123  }
1124 
1125  for (const CaloHit *const pCaloHit : *pCaloHitList)
1126  {
1127  try
1128  {
1129  const MCParticle *const pHitParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
1130 
1131  LArMCParticleHelper::MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pHitParticle);
1132 
1133  if (mcToTargetMCMap.end() == mcIter)
1134  continue;
1135 
1136  // ATTN With folding on or off, still require primary particle to review hierarchy details
1137  const MCParticle *const pPrimaryParticle = LArMCParticleHelper::GetPrimaryMCParticle(pHitParticle);
1138 
1139  if (PassMCParticleChecks(pPrimaryParticle, pPrimaryParticle, pHitParticle, maxPhotonPropagation))
1140  selectedCaloHitList.push_back(pCaloHit);
1141  }
1142  catch (const StatusCodeException &)
1143  {
1144  }
1145  }
1146 }
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 1231 of file LArMCParticleHelper.cc.

1233 {
1234  if (!selectInputHits)
1235  {
1236  selectedGoodCaloHitList.insert(selectedGoodCaloHitList.end(), pSelectedCaloHitList->begin(), pSelectedCaloHitList->end());
1237  return;
1238  }
1239 
1240  for (const CaloHit *const pCaloHit : *pSelectedCaloHitList)
1241  {
1242  MCParticleVector mcParticleVector;
1243  for (const auto &mapEntry : pCaloHit->GetMCParticleWeightMap())
1244  mcParticleVector.push_back(mapEntry.first);
1245  std::sort(mcParticleVector.begin(), mcParticleVector.end(), PointerLessThan<MCParticle>());
1246 
1247  MCParticleWeightMap targetWeightMap;
1248 
1249  for (const MCParticle *const pMCParticle : mcParticleVector)
1250  {
1251  const float weight(pCaloHit->GetMCParticleWeightMap().at(pMCParticle));
1252  LArMCParticleHelper::MCRelationMap::const_iterator mcIter = mcToTargetMCMap.find(pMCParticle);
1253 
1254  if (mcToTargetMCMap.end() != mcIter)
1255  targetWeightMap[mcIter->second] += weight;
1256  }
1257 
1258  MCParticleVector mcTargetVector;
1259  for (const auto &mapEntry : targetWeightMap)
1260  mcTargetVector.push_back(mapEntry.first);
1261  std::sort(mcTargetVector.begin(), mcTargetVector.end(), PointerLessThan<MCParticle>());
1262 
1263  const MCParticle *pBestTargetParticle(nullptr);
1264  float bestTargetWeight(0.f), targetWeightSum(0.f);
1265 
1266  for (const MCParticle *const pTargetMCParticle : mcTargetVector)
1267  {
1268  const float targetWeight(targetWeightMap.at(pTargetMCParticle));
1269  targetWeightSum += targetWeight;
1270 
1271  if (targetWeight > bestTargetWeight)
1272  {
1273  bestTargetWeight = targetWeight;
1274  pBestTargetParticle = pTargetMCParticle;
1275  }
1276  }
1277 
1278  if (!pBestTargetParticle || (targetWeightSum < std::numeric_limits<float>::epsilon()) || ((bestTargetWeight / targetWeightSum) < minHitSharingFraction))
1279  continue;
1280 
1281  selectedGoodCaloHitList.push_back(pCaloHit);
1282  }
1283 }
intermediate_table::const_iterator const_iterator
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
weight
Definition: test.py:257
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 1191 of file LArMCParticleHelper.cc.

1193 {
1194  // Apply restrictions on the number of good hits associated with the MCParticles
1195  for (const MCParticle *const pMCTarget : candidateTargets)
1196  {
1197  MCContributionMap::const_iterator trueHitsIter = mcToTrueHitListMap.find(pMCTarget);
1198  if (mcToTrueHitListMap.end() == trueHitsIter)
1199  continue;
1200 
1201  const CaloHitList &caloHitList(trueHitsIter->second);
1202 
1203  // Remove shared hits where target particle deposits below threshold energy fraction
1204  CaloHitList goodCaloHitList;
1206  &caloHitList, mcToTargetMCMap, goodCaloHitList, parameters.m_selectInputHits, parameters.m_minHitSharingFraction);
1207 
1208  if (goodCaloHitList.size() < parameters.m_minPrimaryGoodHits)
1209  continue;
1210 
1211  unsigned int nGoodViews(0);
1212  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1213  ++nGoodViews;
1214 
1215  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1216  ++nGoodViews;
1217 
1218  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, goodCaloHitList) >= parameters.m_minHitsForGoodView)
1219  ++nGoodViews;
1220 
1221  if (nGoodViews < parameters.m_minPrimaryGoodViews)
1222  continue;
1223 
1224  if (!selectedMCParticlesToHitsMap.insert(MCContributionMap::value_type(pMCTarget, caloHitList)).second)
1225  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
1226  }
1227 }
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 1287 of file LArMCParticleHelper.cc.

1289 {
1290  for (const MCParticle *const pMCParticle : inputMCParticles)
1291  {
1292  if (parameters.m_foldBackHierarchy)
1293  {
1294  if (!fCriteria(pMCParticle))
1295  continue;
1296  }
1297  else
1298  {
1299  if (isTestBeam)
1300  {
1301  if (!LArMCParticleHelper::DoesLeadingMeetCriteria(pMCParticle, fCriteria))
1302  continue;
1303  }
1304  else
1305  {
1306  if (!LArMCParticleHelper::DoesPrimaryMeetCriteria(pMCParticle, fCriteria))
1307  continue;
1308  }
1309  }
1310  selectedParticles.push_back(pMCParticle);
1311  }
1312 }
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 531 of file LArMCParticleHelper.cc.

533 {
534  // Obtain map: [mc particle -> target mc particle]
535  LArMCParticleHelper::MCRelationMap mcToTargetMCMap;
536  parameters.m_foldBackHierarchy ? LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToTargetMCMap)
537  : LArMCParticleHelper::GetMCToSelfMap(pMCParticleList, mcToTargetMCMap);
538 
539  // Remove non-reconstructable hits, e.g. those downstream of a neutron
540  // Unless selectInputHits == false
541  CaloHitList selectedCaloHitList;
542  LArMCParticleHelper::SelectCaloHits(pCaloHitList, mcToTargetMCMap, selectedCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
543 
544  // Obtain maps: [hit -> target mc particle], [target mc particle -> list of hits]
545  CaloHitToMCMap trueHitToTargetMCMap;
546  MCContributionMap targetMCToTrueHitListMap;
547  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&selectedCaloHitList, mcToTargetMCMap, trueHitToTargetMCMap, targetMCToTrueHitListMap);
548 
549  // Obtain vector: target mc particles
550  MCParticleVector targetMCVector;
551  if (parameters.m_foldBackHierarchy)
552  {
553  LArMCParticleHelper::GetPrimaryMCParticleList(pMCParticleList, targetMCVector);
554  }
555  else
556  {
557  std::copy(pMCParticleList->begin(), pMCParticleList->end(), std::back_inserter(targetMCVector));
558  }
559 
560  // Select MCParticles matching criteria
561  MCParticleVector candidateTargets;
562  LArMCParticleHelper::SelectParticlesMatchingCriteria(targetMCVector, fCriteria, candidateTargets, parameters, false);
563 
564  // Ensure the MCParticles have enough "good" hits to be reconstructed
565  LArMCParticleHelper::SelectParticlesByHitCount(candidateTargets, targetMCToTrueHitListMap, mcToTargetMCMap, parameters, selectedMCParticlesToHitsMap);
566 }
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::unordered_map< const pandora::CaloHit *, const pandora::MCParticle * > CaloHitToMCMap
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
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.
static void GetPrimaryMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcPrimaryVector)
Get vector of primary MC particles from an input list of MC particles.
T copy(T const &v)
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 570 of file LArMCParticleHelper.cc.

572 {
573  // Obtain map: [mc particle -> target mc particle]
574  LArMCParticleHelper::MCRelationMap mcToTargetMCMap;
575  parameters.m_foldBackHierarchy ? LArMCParticleHelper::GetMCLeadingMap(pMCParticleList, mcToTargetMCMap)
576  : LArMCParticleHelper::GetMCToSelfMap(pMCParticleList, mcToTargetMCMap);
577 
578  // Remove non-reconstructable hits, e.g. those downstream of a neutron
579  // Unless selectInputHits == false
580  CaloHitList selectedCaloHitList;
581  LArMCParticleHelper::SelectCaloHits(pCaloHitList, mcToTargetMCMap, selectedCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
582 
583  // Obtain maps: [hit -> target mc particle], [target mc particle -> list of hits]
584  CaloHitToMCMap trueHitToTargetMCMap;
585  MCContributionMap targetMCToTrueHitListMap;
586  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&selectedCaloHitList, mcToTargetMCMap, trueHitToTargetMCMap, targetMCToTrueHitListMap);
587 
588  // Obtain vector: target mc particles
589  MCParticleVector targetMCVector;
590  if (parameters.m_foldBackHierarchy)
591  {
592  LArMCParticleHelper::GetLeadingMCParticleList(pMCParticleList, targetMCVector);
593  }
594  else
595  {
596  std::copy(pMCParticleList->begin(), pMCParticleList->end(), std::back_inserter(targetMCVector));
597  }
598 
599  // Select MCParticles matching criteria
600  MCParticleVector candidateTargets;
601  LArMCParticleHelper::SelectParticlesMatchingCriteria(targetMCVector, fCriteria, candidateTargets, parameters, true);
602 
603  // Ensure the MCParticles have enough "good" hits to be reconstructed
604  LArMCParticleHelper::SelectParticlesByHitCount(candidateTargets, targetMCToTrueHitListMap, mcToTargetMCMap, parameters, selectedMCParticlesToHitsMap);
605 
606  // ATTN: The parent particle must be in the hierarchy map, event if not reconstructable
607  for (const MCParticle *const pMCParticle : candidateTargets)
608  {
609  if (!LArMCParticleHelper::IsBeamParticle(pMCParticle))
610  continue;
611 
612  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle));
613  if (selectedMCParticlesToHitsMap.find(pParentMCParticle) == selectedMCParticlesToHitsMap.end())
614  {
615  CaloHitList caloHitList;
616  selectedMCParticlesToHitsMap.insert(MCContributionMap::value_type(pParentMCParticle, caloHitList));
617  }
618  }
619 }
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
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
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.
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...
T copy(T const &v)
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 471 of file LArMCParticleHelper.cc.

472 {
473  // Sort by momentum (prefer higher momentum)
474  const float momentumLhs(pLhs->GetMomentum().GetMagnitudeSquared());
475  const float momentumRhs(pRhs->GetMomentum().GetMagnitudeSquared());
476 
477  if (std::fabs(momentumLhs - momentumRhs) > std::numeric_limits<float>::epsilon())
478  return (momentumLhs > momentumRhs);
479 
480  // Sort by energy (prefer lighter particles)
481  if (std::fabs(pLhs->GetEnergy() - pRhs->GetEnergy()) > std::numeric_limits<float>::epsilon())
482  return (pLhs->GetEnergy() < pRhs->GetEnergy());
483 
484  // Sort by PDG code (prefer smaller numbers)
485  if (pLhs->GetParticleId() != pRhs->GetParticleId())
486  return (pLhs->GetParticleId() < pRhs->GetParticleId());
487 
488  // Sort by vertex position (tie-breaker)
489  const float positionLhs(pLhs->GetVertex().GetMagnitudeSquared());
490  const float positionRhs(pRhs->GetVertex().GetMagnitudeSquared());
491 
492  return (positionLhs < positionRhs);
493 }

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