LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::LArMCParticleHelper Class Reference

LArMCParticleHelper class. More...

#include "LArMCParticleHelper.h"

Classes

class  PrimaryParameters
 PrimaryParameters class. More...
 

Public Types

typedef std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
 
typedef std::unordered_map< const pandora::MCParticle *, 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::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::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 IsBeamNeutrinoFinalState (const pandora::MCParticle *const pMCParticle)
 Returns true if passed a primary neutrino final state MCParticle. More...
 
static bool IsBeamParticle (const pandora::MCParticle *const pMCParticle)
 Returns true if passed a primary 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 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 const pandora::MCParticle * GetPrimaryMCParticle (const pandora::MCParticle *const pMCParticle)
 Get the primary parent mc particle. 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 const pandora::MCParticle * GetParentMCParticle (const pandora::MCParticle *const pMCParticle)
 Get the parent mc particle. 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 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 &mcToPrimaryMCMap, 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 primary, reconstructable mc particles that match given criteria. More...
 
static void GetPfoToReconstructable2DHitsMap (const pandora::PfoList &pfoList, const MCContributionMap &selectedMCParticleToHitsMap, PfoContributionMap &pfoToReconstructable2DHitsMap)
 Get mapping from Pfo 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)
 Get mapping from Pfo 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 &mcToPrimaryMCMap, 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 Private Member Functions

static void CollectReconstructable2DHits (const pandora::ParticleFlowObject *const pPfo, const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D)
 For a given Pfo, 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 &mcToPrimaryMCMap, 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)
 Select mc particles matching given criteria from an input list. More...
 
static void SelectParticlesByHitCount (const pandora::MCParticleVector &candidateTargets, const MCContributionMap &mcToTrueHitListMap, const MCRelationMap &mcToPrimaryMCMap, const PrimaryParameters &parameters, MCContributionMap &selectedMCParticlesToHitsMap)
 Filter an input vector of MCParticles to ensure they have sufficient good hits to be reconstructable. 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...
 
static pandora::CaloHitList GetSharedHits (const pandora::CaloHitList &hitListA, const pandora::CaloHitList &hitListB)
 Get the hits in the intersection of two hit lists. 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 31 of file LArMCParticleHelper.h.

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

Definition at line 32 of file LArMCParticleHelper.h.

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

Definition at line 34 of file LArMCParticleHelper.h.

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

Definition at line 40 of file LArMCParticleHelper.h.

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

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

Definition at line 38 of file LArMCParticleHelper.h.

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

Definition at line 41 of file LArMCParticleHelper.h.

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

Definition at line 37 of file LArMCParticleHelper.h.

Definition at line 46 of file LArMCParticleHelper.h.

Member Function Documentation

void lar_content::LArMCParticleHelper::CollectReconstructable2DHits ( const pandora::ParticleFlowObject *const  pPfo,
const MCContributionMapVector selectedMCParticleToHitsMaps,
pandora::CaloHitList &  reconstructableCaloHitList2D 
)
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

Definition at line 390 of file LArMCParticleHelper.cc.

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

Referenced by SelectReconstructableMCParticles().

392 {
393  // Collect all 2D calo hits in pfo hierarchy
394  PfoList pfoList;
395  LArPfoHelper::GetAllDownstreamPfos(pPfo, pfoList);
396 
397  CaloHitList caloHitList2D;
398  LArPfoHelper::GetCaloHits(pfoList, TPC_VIEW_U, caloHitList2D);
399  LArPfoHelper::GetCaloHits(pfoList, TPC_VIEW_V, caloHitList2D);
400  LArPfoHelper::GetCaloHits(pfoList, TPC_VIEW_W, caloHitList2D);
401  LArPfoHelper::GetIsolatedCaloHits(pfoList, TPC_VIEW_U, caloHitList2D); // TODO check isolated usage throughout
402  LArPfoHelper::GetIsolatedCaloHits(pfoList, TPC_VIEW_V, caloHitList2D);
403  LArPfoHelper::GetIsolatedCaloHits(pfoList, TPC_VIEW_W, caloHitList2D);
404 
405  // Filter for only reconstructable hits
406  for (const CaloHit *const pCaloHit : caloHitList2D)
407  {
408  bool isTargetHit(false);
409  for (const MCContributionMap &mcParticleToHitsMap : selectedMCParticleToHitsMaps)
410  {
411  // ATTN This map is unordered, but this does not impact search for specific target hit
412  for (const MCContributionMap::value_type &mapEntry : mcParticleToHitsMap)
413  {
414  if (std::find(mapEntry.second.begin(), mapEntry.second.end(), pCaloHit) != mapEntry.second.end())
415  {
416  isTargetHit = true;
417  break;
418  }
419  }
420  if (isTargetHit) break;
421  }
422 
423  if (isTargetHit)
424  reconstructableCaloHitList2D.push_back(pCaloHit);
425  }
426 }
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
static void GetIsolatedCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of isolated calo hits of a particular hit type from a list of pfos.
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...
static void GetCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of calo hits of a particular hit type from a list of pfos.
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 210 of file LArMCParticleHelper.cc.

References lar_content::LArPfoHelper::GetTwoDClusterList().

Referenced by lar_content::CheatingNeutrinoCreationAlgorithm::GetMCParticleToDaughterPfoMap(), lar_content::SvmPfoCharacterisationAlgorithm::IsClearTrack(), and lar_content::CheatingNeutrinoDaughterVerticesAlgorithm::ProcessDaughterPfo().

211 {
212  ClusterList clusterList;
213  LArPfoHelper::GetTwoDClusterList(pPfo, clusterList);
214  return MCParticleHelper::GetMainMCParticle(&clusterList);
215 }
static void GetTwoDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 2D clusters from an input pfo.
Definition: LArPfoHelper.cc:97
void lar_content::LArMCParticleHelper::GetMCParticleToCaloHitMatches ( const pandora::CaloHitList *const  pCaloHitList,
const MCRelationMap mcToPrimaryMCMap,
CaloHitToMCMap hitToMCMap,
MCContributionMap mcToTrueHitListMap 
)
static

Match calo hits to their parent particles.

Parameters
pCaloHitListthe input list of calo hits
mcToPrimaryMCMapinput mapping between mc particles and their primaries
hitToPrimaryMCMapoutput mapping between calo hits and their main MC particle (primary MC particle if mcToPrimaryMCMap provided)
mcToTrueHitListMapoutput mapping between MC particles and their associated hits

Definition at line 245 of file LArMCParticleHelper.cc.

Referenced by lar_content::MCParticleMonitoringAlgorithm::PrintPrimaryMCParticles(), and SelectReconstructableMCParticles().

247 {
248  for (const CaloHit *const pCaloHit : *pCaloHitList)
249  {
250  try
251  {
252  const MCParticle *const pHitParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
253  const MCParticle *pPrimaryParticle(pHitParticle);
254 
255  // ATTN Do not map back to mc primaries if mc to primary mc map not provided
256  if (!mcToPrimaryMCMap.empty())
257  {
258  MCRelationMap::const_iterator mcIter = mcToPrimaryMCMap.find(pHitParticle);
259 
260  if (mcToPrimaryMCMap.end() == mcIter)
261  continue;
262 
263  pPrimaryParticle = mcIter->second;
264  }
265 
266  mcToTrueHitListMap[pPrimaryParticle].push_back(pCaloHit);
267  hitToMCMap[pCaloHit] = pPrimaryParticle;
268  }
269  catch (StatusCodeException &statusCodeException)
270  {
271  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
272  throw statusCodeException;
273  }
274  }
275 }
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 195 of file LArMCParticleHelper.cc.

References GetPrimaryMCParticle().

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

196 {
197  for (const MCParticle *const pMCParticle : *pMCParticleList)
198  {
199  try
200  {
201  const MCParticle *const pPrimaryMCParticle = LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle);
202  mcPrimaryMap[pMCParticle] = pPrimaryMCParticle;
203  }
204  catch (const StatusCodeException &) {}
205  }
206 }
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
unsigned int lar_content::LArMCParticleHelper::GetNuanceCode ( const pandora::MCParticle *const  pMCParticle)
static

Get the nuance code of an MCParticle.

Definition at line 68 of file LArMCParticleHelper.cc.

References lar_content::LArMCParticle::GetNuanceCode().

Referenced by lar_content::BdtBeamParticleIdTool::GetBestMCSliceIndices(), lar_content::NeutrinoIdTool::GetNuanceCode(), IsBeamParticle(), IsCosmicRay(), IsNeutrino(), and lar_content::EventValidationAlgorithm::ProcessOutput().

69 {
70  const LArMCParticle *const pLArMCParticle(dynamic_cast<const LArMCParticle*>(pMCParticle));
71  if (pLArMCParticle)
72  return pLArMCParticle->GetNuanceCode();
73 
74  std::cout << "LArMCParticleHelper::GetNuanceCode - Error: Can't cast to LArMCParticle" << std::endl;
75  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
76 }
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 134 of file LArMCParticleHelper.cc.

Referenced by lar_content::NeutrinoIdTool::CountNeutrinoInducedHits(), IsBeamNeutrinoFinalState(), lar_content::BdtBeamParticleIdTool::PopulateMCParticleToHitsMap(), and lar_content::EventValidationAlgorithm::ProcessOutput().

135 {
136  const MCParticle *pParentMCParticle = pMCParticle;
137 
138  while (pParentMCParticle->GetParentList().empty() == false)
139  {
140  if (1 != pParentMCParticle->GetParentList().size())
141  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
142 
143  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
144  }
145 
146  return pParentMCParticle;
147 }
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 332 of file LArMCParticleHelper.cc.

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

Referenced by lar_content::EventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), and lar_content::PfoValidationAlgorithm::Run().

334 {
335  PfoVector sortedPfos;
336  for (const auto &mapEntry : pfoToReconstructable2DHitsMap) sortedPfos.push_back(mapEntry.first);
337  std::sort(sortedPfos.begin(), sortedPfos.end(), LArPfoHelper::SortByNHits);
338 
339  for (const ParticleFlowObject *const pPfo : sortedPfos)
340  {
341  for (const MCContributionMap &mcParticleToHitsMap : selectedMCParticleToHitsMaps)
342  {
343  MCParticleVector sortedMCParticles;
344  for (const auto &mapEntry : mcParticleToHitsMap) sortedMCParticles.push_back(mapEntry.first);
345  std::sort(sortedMCParticles.begin(), sortedMCParticles.end(), PointerLessThan<MCParticle>());
346 
347  for (const MCParticle *const pMCParticle : sortedMCParticles)
348  {
349  // Add map entries for this Pfo & MCParticle if required
350  if (pfoToMCParticleHitSharingMap.find(pPfo) == pfoToMCParticleHitSharingMap.end())
351  if (!pfoToMCParticleHitSharingMap.insert(PfoToMCParticleHitSharingMap::value_type(pPfo, MCParticleToSharedHitsVector())).second)
352  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT); // ATTN maybe overkill
353 
354  if (mcParticleToPfoHitSharingMap.find(pMCParticle) == mcParticleToPfoHitSharingMap.end())
355  if (!mcParticleToPfoHitSharingMap.insert(MCParticleToPfoHitSharingMap::value_type(pMCParticle, PfoToSharedHitsVector())).second)
356  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
357 
358  // Check this Pfo & MCParticle pairing hasn't already been checked
359  MCParticleToSharedHitsVector &mcHitPairs(pfoToMCParticleHitSharingMap.at(pPfo));
360  PfoToSharedHitsVector &pfoHitPairs(mcParticleToPfoHitSharingMap.at(pMCParticle));
361 
362  if (std::any_of(mcHitPairs.begin(), mcHitPairs.end(), [&] (const MCParticleCaloHitListPair &pair) { return (pair.first == pMCParticle); }))
363  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
364 
365  if (std::any_of(pfoHitPairs.begin(), pfoHitPairs.end(), [&] (const PfoCaloHitListPair &pair) { return (pair.first == pPfo); }))
366  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
367 
368  // Add records to maps if there are any shared hits
369  const CaloHitList sharedHits(LArMCParticleHelper::GetSharedHits(pfoToReconstructable2DHitsMap.at(pPfo), mcParticleToHitsMap.at(pMCParticle)));
370 
371  if (!sharedHits.empty())
372  {
373  mcHitPairs.push_back(MCParticleCaloHitListPair(pMCParticle, sharedHits));
374  pfoHitPairs.push_back(PfoCaloHitListPair(pPfo, sharedHits));
375 
376  std::sort(mcHitPairs.begin(), mcHitPairs.end(), [] (const MCParticleCaloHitListPair &a, const MCParticleCaloHitListPair &b) -> bool {
377  return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size() : LArMCParticleHelper::SortByMomentum(a.first, b.first)); });
378 
379  std::sort(pfoHitPairs.begin(), pfoHitPairs.end(), [] (const PfoCaloHitListPair &a, const PfoCaloHitListPair &b) -> bool {
380  return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size() : LArPfoHelper::SortByNHits(a.first, b.first)); });
381  }
382  }
383  }
384  }
385 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
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.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
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.
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
static void lar_content::LArMCParticleHelper::GetPfoToReconstructable2DHitsMap ( const pandora::PfoList &  pfoList,
const MCContributionMap selectedMCParticleToHitsMap,
PfoContributionMap pfoToReconstructable2DHitsMap 
)
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

Referenced by lar_content::EventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::PfoValidationAlgorithm::Run(), and SelectReconstructableMCParticles().

static void lar_content::LArMCParticleHelper::GetPfoToReconstructable2DHitsMap ( const pandora::PfoList &  pfoList,
const MCContributionMapVector selectedMCParticleToHitsMaps,
PfoContributionMap pfoToReconstructable2DHitsMap 
)
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
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 164 of file LArMCParticleHelper.cc.

References IsVisible().

Referenced by GetMCPrimaryMap(), and IsPrimary().

165 {
166  // Navigate upward through MC daughter/parent links - collect this particle and all its parents
167  MCParticleVector mcVector;
168 
169  const MCParticle *pParentMCParticle = pMCParticle;
170  mcVector.push_back(pParentMCParticle);
171 
172  while (!pParentMCParticle->GetParentList().empty())
173  {
174  if (1 != pParentMCParticle->GetParentList().size())
175  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
176 
177  pParentMCParticle = *(pParentMCParticle->GetParentList().begin());
178  mcVector.push_back(pParentMCParticle);
179  }
180 
181  // Navigate downward through MC parent/daughter links - return the first long-lived charged particle
182  for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(), iterEnd = mcVector.rend(); iter != iterEnd; ++iter)
183  {
184  const MCParticle *const pNextParticle = *iter;
185 
186  if (LArMCParticleHelper::IsVisible(pNextParticle))
187  return pNextParticle;
188  }
189 
190  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
191 }
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 151 of file LArMCParticleHelper.cc.

References IsPrimary(), and SortByMomentum().

Referenced by SelectReconstructableMCParticles().

152 {
153  for (const MCParticle *const pMCParticle : *pMCParticleList)
154  {
155  if (LArMCParticleHelper::IsPrimary(pMCParticle))
156  mcPrimaryVector.push_back(pMCParticle);
157  }
158 
159  std::sort(mcPrimaryVector.begin(), mcPrimaryVector.end(), LArMCParticleHelper::SortByMomentum);
160 }
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 
)
staticprivate

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

Referenced by GetPfoMCParticleHitSharingMaps().

595 {
596  CaloHitList sharedHits;
597 
598  for (const CaloHit *const pCaloHit : hitListA)
599  {
600  if (std::find(hitListB.begin(), hitListB.end(), pCaloHit) != hitListB.end())
601  sharedHits.push_back(pCaloHit);
602  }
603 
604  return sharedHits;
605 }
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 121 of file LArMCParticleHelper.cc.

References IsNeutrino(), and SortByMomentum().

Referenced by lar_content::SvmVertexSelectionAlgorithm::GetBestVertex(), lar_content::CheatingNeutrinoCreationAlgorithm::GetMCNeutrinoVector(), lar_content::NeutrinoIdTool::GetNuanceCode(), lar_content::EventWritingAlgorithm::PassNeutrinoVertexFilter(), and lar_content::EventWritingAlgorithm::PassNuanceCodeFilter().

122 {
123  for (const MCParticle *const pMCParticle : *pMCParticleList)
124  {
125  if (LArMCParticleHelper::IsNeutrino(pMCParticle))
126  trueNeutrinos.push_back(pMCParticle);
127  }
128 
129  std::sort(trueNeutrinos.begin(), trueNeutrinos.end(), LArMCParticleHelper::SortByMomentum);
130 }
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.
bool lar_content::LArMCParticleHelper::IsBeamNeutrinoFinalState ( const pandora::MCParticle *const  pMCParticle)
static

Returns true if passed a primary neutrino final state MCParticle.

Definition at line 44 of file LArMCParticleHelper.cc.

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

Referenced by lar_content::EventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::SvmVertexSelectionAlgorithm::GetInteractionType(), IsCosmicRay(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::EventValidationAlgorithm::ProcessOutput(), lar_content::PfoValidationAlgorithm::Run(), and lar_content::MCParticleMonitoringAlgorithm::Run().

45 {
46  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle));
47  return (LArMCParticleHelper::IsPrimary(pMCParticle) && LArMCParticleHelper::IsNeutrino(pParentMCParticle));
48 }
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 52 of file LArMCParticleHelper.cc.

References GetNuanceCode(), and IsPrimary().

Referenced by lar_content::EventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::EventValidationAlgorithm::ProcessOutput(), lar_content::PfoValidationAlgorithm::Run(), lar_content::MCParticleMonitoringAlgorithm::Run(), and lar_content::CheatingBeamParticleIdTool::SelectOutputPfos().

53 {
54  const int nuance(LArMCParticleHelper::GetNuanceCode(pMCParticle));
55  return (LArMCParticleHelper::IsPrimary(pMCParticle) && ((nuance == 2000) || (nuance == 2001)));
56 }
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::IsCosmicRay ( const pandora::MCParticle *const  pMCParticle)
static

Return true if passed a primary cosmic ray MCParticle.

Definition at line 60 of file LArMCParticleHelper.cc.

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

Referenced by lar_content::EventValidationAlgorithm::FillValidationInfo(), lar_content::CheatingCosmicRayTaggingTool::FindAmbiguousPfos(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::EventValidationAlgorithm::ProcessOutput(), lar_content::PfoValidationAlgorithm::Run(), and lar_content::MCParticleMonitoringAlgorithm::Run().

61 {
62  const int nuance(LArMCParticleHelper::GetNuanceCode(pMCParticle));
63  return (LArMCParticleHelper::IsPrimary(pMCParticle) && ((nuance == 3000) || ((nuance == 0) && !LArMCParticleHelper::IsBeamNeutrinoFinalState(pMCParticle))));
64 }
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::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 80 of file LArMCParticleHelper.cc.

References GetNuanceCode().

Referenced by lar_content::NeutrinoIdTool::CountNeutrinoInducedHits(), lar_content::CheatingNeutrinoCreationAlgorithm::GetMCNeutrinoVector(), GetTrueNeutrinos(), IsBeamNeutrinoFinalState(), lar_content::CheatingVertexCreationAlgorithm::Run(), and lar_content::CheatingCosmicRayIdentificationAlg::Run().

81 {
82  const int nuance(LArMCParticleHelper::GetNuanceCode(pMCParticle));
83  if ((nuance == 0) || (nuance == 2000) || (nuance == 2001) || (nuance == 3000))
84  return false;
85 
86  const int absoluteParticleId(std::abs(pMCParticle->GetParticleId()));
87  return ((NU_E == absoluteParticleId) || (NU_MU == absoluteParticleId) || (NU_TAU == absoluteParticleId));
88 }
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
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 92 of file LArMCParticleHelper.cc.

References GetPrimaryMCParticle().

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

93 {
94  try
95  {
96  return (LArMCParticleHelper::GetPrimaryMCParticle(pMCParticle) == pMCParticle);
97  }
98  catch (const StatusCodeException &) {}
99 
100  return false;
101 }
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
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 105 of file LArMCParticleHelper.cc.

Referenced by GetPrimaryMCParticle().

106 {
107  const int absoluteParticleId(std::abs(pMCParticle->GetParticleId()));
108 
109  if ((E_MINUS == absoluteParticleId) || (MU_MINUS == absoluteParticleId) ||
110  (PI_PLUS == absoluteParticleId) || (K_PLUS == absoluteParticleId) ||
111  (SIGMA_MINUS == absoluteParticleId) || (SIGMA_PLUS == absoluteParticleId) || (HYPERON_MINUS == absoluteParticleId) ||
112  (PROTON == absoluteParticleId) || (PHOTON == absoluteParticleId) ||
113  (NEUTRON == absoluteParticleId))
114  return true;
115 
116  return false;
117 }
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 568 of file LArMCParticleHelper.cc.

Referenced by SelectCaloHits().

570 {
571  if (NEUTRON == std::abs(pThisMCParticle->GetParticleId()))
572  return false;
573 
574  if ((PHOTON == pThisMCParticle->GetParticleId()) && (PHOTON != pOriginalPrimary->GetParticleId()) && (E_MINUS != std::abs(pOriginalPrimary->GetParticleId())))
575  {
576  if ((pThisMCParticle->GetEndpoint() - pThisMCParticle->GetVertex()).GetMagnitude() > maxPhotonPropagation)
577  return false;
578  }
579 
580  if (pThisMCParticle == pHitMCParticle)
581  return true;
582 
583  for (const MCParticle *const pDaughterMCParticle : pThisMCParticle->GetDaughterList())
584  {
585  if (PassMCParticleChecks(pOriginalPrimary, pDaughterMCParticle, pHitMCParticle, maxPhotonPropagation))
586  return true;
587  }
588 
589  return false;
590 }
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...
void lar_content::LArMCParticleHelper::SelectCaloHits ( const pandora::CaloHitList *const  pCaloHitList,
const MCRelationMap mcToPrimaryMCMap,
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
mcToPrimaryMCMapthe mc particle to primary mc particle map
selectedCaloHitListto receive the populated selected calo hit list
selectInputHitswhether to select input hits
maxPhotonPropagationthe maximum photon propagation length

Definition at line 430 of file LArMCParticleHelper.cc.

References PassMCParticleChecks().

Referenced by lar_content::NeutrinoIdTool::GetBestMCSliceIndex(), lar_content::BdtBeamParticleIdTool::GetBestMCSliceIndices(), and SelectReconstructableMCParticles().

432 {
433  if (!selectInputHits)
434  {
435  selectedCaloHitList.insert(selectedCaloHitList.end(), pCaloHitList->begin(), pCaloHitList->end());
436  return;
437  }
438 
439  for (const CaloHit *const pCaloHit : *pCaloHitList)
440  {
441  try
442  {
443  const MCParticle *const pHitParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
444 
445  LArMCParticleHelper::MCRelationMap::const_iterator mcIter = mcToPrimaryMCMap.find(pHitParticle);
446 
447  if (mcToPrimaryMCMap.end() == mcIter)
448  continue;
449 
450  const MCParticle *const pPrimaryParticle = mcIter->second;
451 
452  if (PassMCParticleChecks(pPrimaryParticle, pPrimaryParticle, pHitParticle, maxPhotonPropagation))
453  selectedCaloHitList.push_back(pCaloHit);
454  }
455  catch (const StatusCodeException &)
456  {
457  }
458  }
459 }
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...
intermediate_table::const_iterator const_iterator
void lar_content::LArMCParticleHelper::SelectGoodCaloHits ( const pandora::CaloHitList *const  pSelectedCaloHitList,
const MCRelationMap mcToPrimaryMCMap,
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)
mcToPrimaryMCMapthe mc particle to primary 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 463 of file LArMCParticleHelper.cc.

References f, and weight.

Referenced by SelectParticlesByHitCount().

465 {
466  if (!selectInputHits)
467  {
468  selectedGoodCaloHitList.insert(selectedGoodCaloHitList.end(), pSelectedCaloHitList->begin(), pSelectedCaloHitList->end());
469  return;
470  }
471 
472  for (const CaloHit *const pCaloHit : *pSelectedCaloHitList)
473  {
474  MCParticleVector mcParticleVector;
475  for (const auto &mapEntry : pCaloHit->GetMCParticleWeightMap()) mcParticleVector.push_back(mapEntry.first);
476  std::sort(mcParticleVector.begin(), mcParticleVector.end(), PointerLessThan<MCParticle>());
477 
478  MCParticleWeightMap primaryWeightMap;
479 
480  for (const MCParticle *const pMCParticle : mcParticleVector)
481  {
482  const float weight(pCaloHit->GetMCParticleWeightMap().at(pMCParticle));
483  LArMCParticleHelper::MCRelationMap::const_iterator mcIter = mcToPrimaryMCMap.find(pMCParticle);
484 
485  if (mcToPrimaryMCMap.end() != mcIter)
486  primaryWeightMap[mcIter->second] += weight;
487  }
488 
489  MCParticleVector mcPrimaryVector;
490  for (const auto &mapEntry : primaryWeightMap) mcPrimaryVector.push_back(mapEntry.first);
491  std::sort(mcPrimaryVector.begin(), mcPrimaryVector.end(), PointerLessThan<MCParticle>());
492 
493  const MCParticle *pBestPrimaryParticle(nullptr);
494  float bestPrimaryWeight(0.f), primaryWeightSum(0.f);
495 
496  for (const MCParticle *const pPrimaryMCParticle : mcPrimaryVector)
497  {
498  const float primaryWeight(primaryWeightMap.at(pPrimaryMCParticle));
499  primaryWeightSum += primaryWeight;
500 
501  if (primaryWeight > bestPrimaryWeight)
502  {
503  bestPrimaryWeight = primaryWeight;
504  pBestPrimaryParticle = pPrimaryMCParticle;
505  }
506  }
507 
508  if (!pBestPrimaryParticle || (primaryWeightSum < std::numeric_limits<float>::epsilon()) || ((bestPrimaryWeight / primaryWeightSum) < minHitSharingFraction))
509  continue;
510 
511  selectedGoodCaloHitList.push_back(pCaloHit);
512  }
513 }
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
TFile f
Definition: plotHisto.C:6
intermediate_table::const_iterator const_iterator
double weight
Definition: plottest35.C:25
void lar_content::LArMCParticleHelper::SelectParticlesByHitCount ( const pandora::MCParticleVector &  candidateTargets,
const MCContributionMap mcToTrueHitListMap,
const MCRelationMap mcToPrimaryMCMap,
const PrimaryParameters parameters,
MCContributionMap selectedMCParticlesToHitsMap 
)
staticprivate

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

Parameters
candidateTargetscandidate recontructable MCParticles
mcToTrueHitListMapmapping from candidates reconstructable MCParticles to their true hits
mcToPrimaryMCMapthe mc particle to primary 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 529 of file LArMCParticleHelper.cc.

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

Referenced by SelectReconstructableMCParticles().

531 {
532  // Apply restrictions on the number of good hits associated with the MCParticles
533  for (const MCParticle * const pMCTarget : candidateTargets)
534  {
535  MCContributionMap::const_iterator trueHitsIter = mcToTrueHitListMap.find(pMCTarget);
536  if (mcToTrueHitListMap.end() == trueHitsIter)
537  continue;
538 
539  const CaloHitList &caloHitList(trueHitsIter->second);
540 
541  // Remove shared hits where target particle deposits below threshold energy fraction
542  CaloHitList goodCaloHitList;
543  LArMCParticleHelper::SelectGoodCaloHits(&caloHitList, mcToPrimaryMCMap, goodCaloHitList, parameters.m_selectInputHits, parameters.m_minHitSharingFraction);
544 
545  if (goodCaloHitList.size() < parameters.m_minPrimaryGoodHits)
546  continue;
547 
548  unsigned int nGoodViews(0);
549  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, goodCaloHitList) >= parameters.m_minHitsForGoodView)
550  ++nGoodViews;
551 
552  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, goodCaloHitList) >= parameters.m_minHitsForGoodView)
553  ++nGoodViews;
554 
555  if (LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, goodCaloHitList) >= parameters.m_minHitsForGoodView)
556  ++nGoodViews;
557 
558  if (nGoodViews < parameters.m_minPrimaryGoodViews)
559  continue;
560 
561  if (!selectedMCParticlesToHitsMap.insert(MCContributionMap::value_type(pMCTarget, caloHitList)).second)
562  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
563  }
564 }
intermediate_table::const_iterator const_iterator
static void SelectGoodCaloHits(const pandora::CaloHitList *const pSelectedCaloHitList, const MCRelationMap &mcToPrimaryMCMap, 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 
)
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

Definition at line 517 of file LArMCParticleHelper.cc.

Referenced by SelectReconstructableMCParticles().

519 {
520  for (const MCParticle *const pMCParticle : inputMCParticles)
521  {
522  if (fCriteria(pMCParticle))
523  selectedParticles.push_back(pMCParticle);
524  }
525 }
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 primary, 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 279 of file LArMCParticleHelper.cc.

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

Referenced by lar_content::EventValidationAlgorithm::FillValidationInfo(), lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::SvmVertexSelectionAlgorithm::GetInteractionType(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), lar_content::PfoValidationAlgorithm::Run(), and lar_content::MCParticleMonitoringAlgorithm::Run().

281 {
282  // Obtain map: [mc particle -> primary mc particle]
283  LArMCParticleHelper::MCRelationMap mcToPrimaryMCMap;
284  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToPrimaryMCMap);
285 
286  // Remove non-reconstructable hits, e.g. those downstream of a neutron
287  CaloHitList selectedCaloHitList;
288  LArMCParticleHelper::SelectCaloHits(pCaloHitList, mcToPrimaryMCMap, selectedCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
289 
290  // Obtain maps: [hit -> primary mc particle], [primary mc particle -> list of hits]
291  CaloHitToMCMap hitToPrimaryMCMap;
292  MCContributionMap mcToTrueHitListMap;
293  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&selectedCaloHitList, mcToPrimaryMCMap, hitToPrimaryMCMap, mcToTrueHitListMap);
294 
295  // Obtain vector: primary mc particles
296  MCParticleVector mcPrimaryVector;
297  LArMCParticleHelper::GetPrimaryMCParticleList(pMCParticleList, mcPrimaryVector);
298 
299  // Select MCParticles matching criteria
300  MCParticleVector candidateTargets;
301  LArMCParticleHelper::SelectParticlesMatchingCriteria(mcPrimaryVector, fCriteria, candidateTargets);
302 
303  // Ensure the MCParticles have enough "good" hits to be reconstructed
304  LArMCParticleHelper::SelectParticlesByHitCount(candidateTargets, mcToTrueHitListMap, mcToPrimaryMCMap, parameters, selectedMCParticlesToHitsMap);
305 }
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...
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static void SelectCaloHits(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToPrimaryMCMap, pandora::CaloHitList &selectedCaloHitList, const bool selectInputHits, const float maxPhotonPropagation)
Select a subset of calo hits representing those that represent "reconstructable" regions of the event...
static void SelectParticlesByHitCount(const pandora::MCParticleVector &candidateTargets, const MCContributionMap &mcToTrueHitListMap, const MCRelationMap &mcToPrimaryMCMap, const PrimaryParameters &parameters, MCContributionMap &selectedMCParticlesToHitsMap)
Filter an input vector of MCParticles to ensure they have sufficient good hits to be reconstructable...
static void SelectParticlesMatchingCriteria(const pandora::MCParticleVector &inputMCParticles, std::function< bool(const pandora::MCParticle *const)> fCriteria, pandora::MCParticleVector &selectedParticles)
Select mc particles matching given criteria from an input list.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
static void GetPrimaryMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcPrimaryVector)
Get vector of primary MC particles from an input list of MC particles.
std::unordered_map< const pandora::CaloHit *, const pandora::MCParticle * > CaloHitToMCMap
static void GetMCParticleToCaloHitMatches(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToPrimaryMCMap, CaloHitToMCMap &hitToMCMap, MCContributionMap &mcToTrueHitListMap)
Match calo hits to their parent particles.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
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 219 of file LArMCParticleHelper.cc.

Referenced by lar_content::CheatingClusterCreationAlgorithm::CreateClusters(), lar_content::CheatingPfoCreationAlgorithm::CreatePfos(), lar_content::SvmVertexSelectionAlgorithm::GetInteractionType(), GetPfoMCParticleHitSharingMaps(), GetPrimaryMCParticleList(), GetTrueNeutrinos(), lar_content::EventWritingAlgorithm::PassMCParticleFilter(), and lar_content::MasterAlgorithm::Reset().

220 {
221  // Sort by momentum (prefer higher momentum)
222  const float momentumLhs(pLhs->GetMomentum().GetMagnitudeSquared());
223  const float momentumRhs(pRhs->GetMomentum().GetMagnitudeSquared());
224 
225  if (std::fabs(momentumLhs - momentumRhs) > std::numeric_limits<float>::epsilon())
226  return (momentumLhs > momentumRhs);
227 
228  // Sort by energy (prefer lighter particles)
229  if (std::fabs(pLhs->GetEnergy() - pRhs->GetEnergy()) > std::numeric_limits<float>::epsilon())
230  return (pLhs->GetEnergy() < pRhs->GetEnergy());
231 
232  // Sort by PDG code (prefer smaller numbers)
233  if (pLhs->GetParticleId() != pRhs->GetParticleId())
234  return (pLhs->GetParticleId() < pRhs->GetParticleId());
235 
236  // Sort by vertex position (tie-breaker)
237  const float positionLhs(pLhs->GetVertex().GetMagnitudeSquared());
238  const float positionRhs(pRhs->GetVertex().GetMagnitudeSquared());
239 
240  return (positionLhs < positionRhs);
241 }

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