LArMCParticleHelper.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArHelpers/LArMCParticleHelper.h
3  *
4  * @brief Header file for the lar monte carlo particle helper helper class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_MC_PARTICLE_HELPER_H
9 #define LAR_MC_PARTICLE_HELPER_H 1
10 
11 #include "Pandora/PandoraInternal.h"
12 
14 
15 #include <functional>
16 #include <unordered_map>
17 
18 namespace lar_content
19 {
20 
21 /**
22  * @brief LArMCParticleHelper class
23  */
25 {
26 public:
27  typedef std::unordered_map<const pandora::MCParticle *, const pandora::MCParticle *> MCRelationMap;
28  typedef std::unordered_map<const pandora::MCParticle *, int> MCParticleIntMap;
29 
30  typedef std::unordered_map<const pandora::MCParticle *, const pandora::ParticleFlowObject *> MCToPfoMap;
31 
32  typedef std::unordered_map<const pandora::CaloHit *, const pandora::MCParticle *> CaloHitToMCMap;
33  typedef std::unordered_map<const pandora::CaloHit *, const pandora::ParticleFlowObject *> CaloHitToPfoMap;
34 
35  typedef std::unordered_map<const pandora::MCParticle *, pandora::CaloHitList> MCContributionMap;
36  typedef std::vector<MCContributionMap> MCContributionMapVector;
37 
38  typedef std::unordered_map<const pandora::Cluster *, pandora::CaloHitList> ClusterContributionMap;
39  typedef std::unordered_map<const pandora::ParticleFlowObject *, pandora::CaloHitList> PfoContributionMap;
40  typedef std::unordered_map<const pandora::MCParticle *, PfoContributionMap> MCToPfoMatchingMap;
41 
42  typedef std::pair<const pandora::MCParticle *, pandora::CaloHitList> MCParticleCaloHitListPair;
43  typedef std::pair<const pandora::ParticleFlowObject *, pandora::CaloHitList> PfoCaloHitListPair;
44  typedef std::pair<const pandora::Cluster *, pandora::CaloHitList> ClusterCaloHitListPair;
45 
46  typedef std::vector<MCParticleCaloHitListPair> MCParticleToSharedHitsVector;
47  typedef std::vector<PfoCaloHitListPair> PfoToSharedHitsVector;
48 
49  typedef std::map<const pandora::ParticleFlowObject *, MCParticleToSharedHitsVector> PfoToMCParticleHitSharingMap;
50  typedef std::map<const pandora::MCParticle *, PfoToSharedHitsVector> MCParticleToPfoHitSharingMap;
51 
52  /**
53  * @brief PrimaryParameters class
54  */
56  {
57  public:
58  /**
59  * @brief Constructor
60  */
62 
63  unsigned int m_minPrimaryGoodHits; ///< the minimum number of primary good Hits
64  unsigned int m_minHitsForGoodView; ///< the minimum number of Hits for a good view
65  unsigned int m_minPrimaryGoodViews; ///< the minimum number of primary good views
66  bool m_selectInputHits; ///< whether to select input hits
67  float m_maxPhotonPropagation; ///< the maximum photon propagation length
68  float m_minHitSharingFraction; ///< the minimum Hit sharing fraction
69  bool m_foldBackHierarchy; ///< whether to fold the hierarchy back to the primary (neutrino) or leading particles (test beam)
70  };
71 
72  /**
73  * @brief Returns true if passed particle whose primary meets the passed criteria
74  *
75  * @param pMCParticle the input mc particle
76  * @param fCriteria the given criteria
77  */
78  static bool DoesPrimaryMeetCriteria(const pandora::MCParticle *const pMCParticle, std::function<bool(const pandora::MCParticle *const)> fCriteria);
79 
80  /**
81  * @brief Returns true if passed particle whose leading meets the passed criteria
82  *
83  * @param pMCParticle the input mc particle
84  * @param fCriteria the given criteria
85  */
86  static bool DoesLeadingMeetCriteria(const pandora::MCParticle *const pMCParticle, std::function<bool(const pandora::MCParticle *const)> fCriteria);
87 
88  /**
89  * @brief Returns true if passed a primary neutrino final state MCParticle
90  */
91  static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle);
92 
93  /**
94  * @brief Returns true if passed a primary triggered beam MCParticle
95  */
96  static bool IsTriggeredBeamParticle(const pandora::MCParticle *const pMCParticle);
97 
98  /**
99  * @brief Returns true if passed a primary beam MCParticle
100  */
101  static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle);
102 
103  /**
104  * @brief Returns true if passed a leading beam MCParticle
105  */
106  static bool IsLeadingBeamParticle(const pandora::MCParticle *const pMCParticle);
107 
108  /**
109  * @brief Return true if passed a primary cosmic ray MCParticle
110  */
111  static bool IsCosmicRay(const pandora::MCParticle *const pMCParticle);
112 
113  /**
114  * @brief Get the nuance code of an MCParticle
115  */
116  static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle);
117 
118  /**
119  * @brief Whether a mc particle is a neutrino or antineutrino
120  *
121  * @param pMCParticle the input mc particle
122  *
123  * @return boolean
124  */
125  static bool IsNeutrino(const pandora::MCParticle *const pMCParticle);
126 
127  /**
128  * @brief Whether a provided mc particle matches the implemented definition of being primary
129  *
130  * @param pMCParticle the address of the mc particle
131  *
132  * @return boolean
133  */
134  static bool IsPrimary(const pandora::MCParticle *const pMCParticle);
135 
136  /**
137  * @brief Whether a provided mc particle matches the implemented definition of being leading
138  *
139  * @param pMCParticle the address of the mc particle
140  *
141  * @return boolean
142  */
143  static bool IsLeading(const pandora::MCParticle *const pMCParticle);
144 
145  /**
146  * @brief Determine the position in the hierarchy for the MCParticle
147  *
148  * @param pMCParticle the address of the mc particle
149  *
150  * @return integer
151  */
152  static int GetHierarchyTier(const pandora::MCParticle *const pMCParticle);
153 
154  /**
155  * @brief Whether a mc particle is visible (i.e. long-lived charged particle)
156  *
157  * @param pMCParticle the input mc particle
158  *
159  * @return boolean
160  */
161  static bool IsVisible(const pandora::MCParticle *const pMCParticle);
162 
163  /**
164  * @brief Get neutrino MC particles from an input MC particle list
165  *
166  * @param pMCParticleList the input MC particle list
167  * @param trueNeutrinos to receive the vector of neutrino MC particles
168  */
169  static void GetTrueNeutrinos(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueNeutrinos);
170 
171  /**
172  * @brief Get triggered test beam MC particles from an input MC particle list
173  *
174  * @param pMCParticleList the input MC particle list
175  * @param trueTestBeamParticles to receive the vector of neutrino MC particles
176  */
177  static void GetTrueTestBeamParticles(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueTestBeamParticles);
178 
179  /**
180  * @brief Get the primary parent mc particle
181  *
182  * @param pMCParticle the input mc particle
183  *
184  * @return address of the primary parent mc particle
185  */
186  static const pandora::MCParticle *GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle);
187 
188  /**
189  * @brief Get the leading particle in the hierarchy, for use at ProtoDUNE
190  *
191  * @param pMCParticle the input mc particle
192  *
193  * @return address of the primary parent mc particle
194  */
195  static const pandora::MCParticle *GetLeadingMCParticle(const pandora::MCParticle *const pMCParticle, const int hierarchyTierLimit = 1);
196 
197  /**
198  * @brief Get vector of primary MC particles from an input list of MC particles
199  *
200  * @param pMCParticleList the input mc particle list
201  * @param mcPrimaryVector the output mc particle vector
202  */
203  static void GetPrimaryMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcPrimaryVector);
204 
205  /**
206  * @brief Get vector of leading MC particles from an input list of MC particles
207  *
208  * @param pMCParticleList the input mc particle list
209  * @param mcLeadingVector the output mc particle vector
210  */
211  static void GetLeadingMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcLeadingVector);
212 
213  /**
214  * @brief Get the parent mc particle
215  *
216  * @param pMCParticle the input mc particle
217  *
218  * @return address of the parent mc particle
219  */
220  static const pandora::MCParticle *GetParentMCParticle(const pandora::MCParticle *const pMCParticle);
221 
222  /**
223  * @brief Get all descendent mc particles
224  *
225  * @param pMCParticle the input mc particle
226  * @param descendentMCParticleList the output descendent mc particle list
227  */
228  static void GetAllDescendentMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &descendentMCParticleList);
229 
230  /**
231  * @brief Get all descendent mc particles, separated into track-like, shower-like and neutron branches.
232  * This method collects together all track-like particles (i.e. not electron, photon or neutron) downstream of the root
233  * particle, stopping at a leading shower or neutron and then storing that leading shower or neutron in a separate list.
234  *
235  * @param pMCParticle the input mc particle
236  * @param descendentTrackParticles the output list of descendent track-like particles
237  * @param leadingShowerParticles the output list of leading shower particles
238  * @param leadingNeutrons the output list of leading neutrons
239  */
240  static void GetAllDescendentMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &descendentTrackParticles,
241  pandora::MCParticleList &leadingShowerParticles, pandora::MCParticleList &leadingNeutrons);
242 
243  /**
244  * @brief Get all ancestor mc particles
245  *
246  * @param pMCParticle the input mc particle
247  * @param ancestorMCParticleList the output ancestor mc particle list
248  */
249  static void GetAllAncestorMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &ancestorMCParticleList);
250 
251  /**
252  * @brief Get mapping from individual mc particles (in a provided list) and their primary parent mc particles
253  *
254  * @param pMCParticleList the input mc particle list
255  * @param mcPrimaryMap the output mapping between mc particles and their parents
256  */
257  static void GetMCPrimaryMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcPrimaryMap);
258 
259  /**
260  * @brief Get mapping from individual mc particles (in a provided list) and their leading parent mc particles
261  *
262  * @param pMCParticleList the input mc particle list
263  * @param mcLeadingMap the output mapping between mc particles and their leading parent
264  */
265  static void GetMCLeadingMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcLeadingMap);
266 
267  /**
268  * @brief Get mapping from individual mc particles (in a provided list) to themselves (to be used when not folding particles to their primaries)
269  *
270  * @param pMCParticleList the input mc particle list
271  * @param mcToSelfMap the output mapping between mc particles and themselves
272  */
273  static void GetMCToSelfMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcToSelfMap);
274 
275  /**
276  * @brief Find the mc particle making the largest contribution to 2D clusters in a specified pfo
277  *
278  * @param pPfo address of the pfo to examine
279  *
280  * @return address of the main mc particle
281  */
282  static const pandora::MCParticle *GetMainMCParticle(const pandora::ParticleFlowObject *const pPfo);
283 
284  /**
285  * @brief Sort mc particles by their momentum
286  *
287  * @param pLhs address of first mc particle
288  * @param pRhs address of second mc particle
289  */
290  static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs);
291 
292  /**
293  * @brief Match calo hits to their parent particles
294  *
295  * @param pCaloHitList the input list of calo hits
296  * @param mcToTargetMCMap the mc particle to target (primary or self) mc particle map
297  * @param hitToMCMap output mapping between calo hits and their main MC particle
298  * @param mcToTrueHitListMap output mapping between MC particles and their associated hits
299  */
300  static void GetMCParticleToCaloHitMatches(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap,
301  CaloHitToMCMap &hitToMCMap, MCContributionMap &mcToTrueHitListMap);
302 
303  /**
304  * @brief Select target, reconstructable mc particles that match given criteria.
305  *
306  * @param pMCParticleList the address of the list of MCParticles
307  * @param pCaloHitList the address of the list of CaloHits
308  * @param parameters validation parameters to decide when an MCParticle is considered reconstructable
309  * @param fCriteria a function which returns a bool (= shouldSelect) for a given input MCParticle
310  * @param selectedMCParticlesToHitsMap the output mapping from selected mcparticles to their hits
311  */
312  static void SelectReconstructableMCParticles(const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList,
313  const PrimaryParameters &parameters, std::function<bool(const pandora::MCParticle *const)> fCriteria,
314  MCContributionMap &selectedMCParticlesToHitsMap);
315 
316  /**
317  * @brief Select target, reconstructable mc particles in the relevant hierarchy that match given criteria.
318  *
319  * @param pMCParticleList the address of the list of MCParticles
320  * @param pCaloHitList the address of the list of CaloHits
321  * @param parameters validation parameters to decide when an MCParticle is considered reconstructable
322  * @param fCriteria a function which returns a bool (= shouldSelect) for a given input MCParticle
323  * @param selectedMCParticlesToHitsMap the output mapping from selected mcparticles to their hits
324  */
325  static void SelectReconstructableTestBeamHierarchyMCParticles(const pandora::MCParticleList *pMCParticleList,
326  const pandora::CaloHitList *pCaloHitList, const PrimaryParameters &parameters,
327  std::function<bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap);
328 
329  /**
330  * @brief Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)
331  *
332  * @param pfoList the input list of Pfos
333  * @param selectedMCParticleToHitsMap the input mapping from selected reconstructable MCParticles to their hits
334  * @param pfoToReconstructable2DHitsMap the output mapping from Pfos to their reconstructable 2D hits
335  * @param foldBackHierarchy whether to fold the particle hierarchy back to the primaries
336  */
337  static void GetPfoToReconstructable2DHitsMap(const pandora::PfoList &pfoList, const MCContributionMap &selectedMCParticleToHitsMap,
338  PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy);
339 
340  /**
341  * @brief Get mapping from Pfo in reconstructed test beam hierarchy to reconstructable 2D hits (=good hits belonging to a selected
342  * reconstructable MCParticle)
343  *
344  * @param pfoList the input list of Pfos
345  * @param selectedMCParticleToHitsMap the input mapping from selected reconstructable MCParticles to their hits
346  * @param pfoToReconstructable2DHitsMap the output mapping from Pfos to their reconstructable 2D hits
347  * @param foldBackHierarchy whether to fold the particle hierarchy back to the leading particles
348  */
349  static void GetTestBeamHierarchyPfoToReconstructable2DHitsMap(const pandora::PfoList &pfoList,
350  const MCContributionMap &selectedMCParticleToHitsMap, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy);
351 
352  /**
353  * @brief Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)
354  *
355  * @param pfoList the input list of Pfos
356  * @param selectedMCParticleToHitsMaps the input vector of mappings from selected reconstructable MCParticles to their hits
357  * @param pfoToReconstructable2DHitsMap the output mapping from Pfos to their reconstructable 2D hits
358  * @param foldToHierarchy whether to fold the particle hierarchy back to the primaries
359  */
360  static void GetPfoToReconstructable2DHitsMap(const pandora::PfoList &pfoList, const MCContributionMapVector &selectedMCParticleToHitsMaps,
361  PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy);
362 
363  /**
364  * @brief Get mapping from Pfo in reconstructed test beam hierarchy to reconstructable 2D hits (=good hits belonging to a selected
365  * reconstructable MCParticle)
366  *
367  * @param pfoList the input list of Pfos
368  * @param selectedMCParticleToHitsMaps the input vector of mappings from selected reconstructable MCParticles to their hits
369  * @param pfoToReconstructable2DHitsMap the output mapping from Pfos to their reconstructable 2D hits
370  * @param foldBackHierarchy whether to fold the particle hierarchy back to the leading particles
371  */
372  static void GetTestBeamHierarchyPfoToReconstructable2DHitsMap(const pandora::PfoList &pfoList,
373  const MCContributionMapVector &selectedMCParticleToHitsMaps, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy);
374 
375  /**
376  * @brief Get mapping from cluster to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)
377  *
378  * @param clusterList the input list of clusters
379  * @param selectedMCToHitsMap the input mapping from selected reconstructable MCParticles to their hits
380  * @param clusterToReconstructable2DHitsMap the output mapping from clusters to their reconstructable 2D hits
381  */
382  static void GetClusterToReconstructable2DHitsMap(const pandora::ClusterList &clusterList, const MCContributionMap &selectedMCToHitsMap,
383  ClusterContributionMap &clusterToReconstructable2DHitsMap);
384 
385  /**
386  * @brief Get mapping from cluster to reconstructable 2D hits (=good hits belonging to a selected reconstructable MCParticle)
387  *
388  * @param clusterList the input list of clusters
389  * @param selectedMCToHitsMaps the input vector of mappings from selected reconstructable MCParticles to their hits
390  * @param clusterToReconstructable2DHitsMap the output mapping from cluster to their reconstructable 2D hits
391  */
392  static void GetClusterToReconstructable2DHitsMap(const pandora::ClusterList &clusterList,
393  const MCContributionMapVector &selectedMCToHitsMaps, ClusterContributionMap &clusterToReconstructable2DHitsMap);
394 
395  /**
396  * @brief Get the mappings from Pfo -> pair (reconstructable MCparticles, number of reconstructable 2D hits shared with Pfo)
397  * reconstructable MCParticle -> pair (Pfo, number of reconstructable 2D hits shared with MCParticle)
398  *
399  * @param pfoToReconstructable2DHitsMap the input mapping from Pfos to reconstructable 2D hits
400  * @param selectedMCParticleToHitsMaps the input mappings from selected reconstructable MCParticles to hits
401  * @param pfoToMCParticleHitSharingMap the output mapping from Pfos to selected reconstructable MCParticles and the number hits shared
402  * @param mcParticleToPfoHitSharingMap the output mapping from selected reconstructable MCParticles to Pfos and the number hits shared
403  */
404  static void GetPfoMCParticleHitSharingMaps(const PfoContributionMap &pfoToReconstructable2DHitsMap,
405  const MCContributionMapVector &selectedMCParticleToHitsMaps, PfoToMCParticleHitSharingMap &pfoToMCParticleHitSharingMap,
406  MCParticleToPfoHitSharingMap &mcParticleToPfoHitSharingMap);
407 
408  /**
409  * @brief Select a subset of calo hits representing those that represent "reconstructable" regions of the event
410  *
411  * @param pCaloHitList the address of the input calo hit list
412  * @param mcToTargetMCMap the mc particle to target (primary or self) mc particle map
413  * @param selectedCaloHitList to receive the populated selected calo hit list
414  * @param selectInputHits whether to select input hits
415  * @param maxPhotonPropagation the maximum photon propagation length
416  */
417  static void SelectCaloHits(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap,
418  pandora::CaloHitList &selectedCaloHitList, const bool selectInputHits, const float maxPhotonPropagation);
419 
420  /**
421  * @brief Determine if the MC particle is a descendent of a particle with the given PDG code.
422  *
423  * @param pMCParticle the descendent particle
424  * @param pdg the PDG code of the ancestor particle
425  * @param isChargeSensitive whether or not to consider the sign of the PDG code when looking for the ancestor (default: false)
426  *
427  * @return true if the MC particle has an ancestor with the matching PDG code, false otherwise
428  */
429  static bool IsDescendentOf(const pandora::MCParticle *const pMCParticle, const int pdg, const bool isChargeSensitive = false);
430 
431  /**
432  * @brief Retrieve a linearised representation of the MC particle hierarchy in breadth first order. This iterates over the MC
433  * hierarchy in a manor that sees primaries at the front of the list, with progressively deeper tiers later in the list.
434  * This is useful for some visualisation cases.
435  *
436  * @param pMCParticle an MC particle in the hierarchy - can be any particle
437  * @param mcParticleList the output MC particle list
438  */
439  static void GetBreadthFirstHierarchyRepresentation(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &mcParticleList);
440 
441  /**
442  * @brief Filter an input vector of MCParticles to ensure they have sufficient good hits to be reconstructable
443  *
444  * @param candidateTargets candidate reconstructable MCParticles
445  * @param mcToTrueHitListMap mapping from candidates reconstructable MCParticles to their true hits
446  * @param mcToTargetMCMap the mc particle to target (primary or self) mc particle map
447  * @param parameters validation parameters to decide when an MCParticle is considered reconstructable
448  * @param selectedMCParticlesToHitsMap the output mapping from selected mcparticles to their hits
449  */
450  static void SelectParticlesByHitCount(const pandora::MCParticleVector &candidateTargets, const MCContributionMap &mcToTrueHitListMap,
451  const MCRelationMap &mcToTargetMCMap, const PrimaryParameters &parameters, MCContributionMap &selectedMCParticlesToHitsMap);
452 
453  /**
454  * @brief Get the hits in the intersection of two hit lists
455  *
456  * @param hitListA an input hit list
457  * @param hitListB another input hit list
458  *
459  * @return The hits that are found in both hitListA and hitListB
460  */
461  static pandora::CaloHitList GetSharedHits(const pandora::CaloHitList &hitListA, const pandora::CaloHitList &hitListB);
462 
463  /*
464  * @brief Check whether or not an MC particle comes from a Bremsstrahlung process
465  *
466  * @param pMCParticle The MC particle to consider
467  *
468  * @return Whether or not the MC particle came from Bremsstrahlung
469  */
470  static bool IsBremsstrahlung(const pandora::MCParticle *const pMCParticle);
471 
472  /**
473  * @brief Check whether or not an MC particle comes from a capture process
474  *
475  * @param pMCParticle The MC particle to consider
476  *
477  * @return Whether or not the MC particle came from capture
478  */
479  static bool IsCapture(const pandora::MCParticle *const pMCParticle);
480 
481  /**
482  * @brief Check whether or not an MC particle comes from a decay process
483  *
484  * @param pMCParticle The MC particle to consider
485  *
486  * @return Whether or not the MC particle came from decay
487  */
488  static bool IsDecay(const pandora::MCParticle *const pMCParticle);
489 
490  /**
491  * @brief Check whether or not an MC particle came from an elastic scattering process
492  *
493  * @param pMCParticle The MC particle to consider
494  *
495  * @return Whether or not the MC particle came from an elastic scatter
496  */
497  static bool IsElasticScatter(const pandora::MCParticle *const pMCParticle);
498 
499  /**
500  * @brief Check whether or not an MC particle came from an inelastic scattering process
501  *
502  * @param pMCParticle The MC particle to consider
503  *
504  * @return Whether or not the MC particle came from an inelastic scatter
505  */
506  static bool IsInelasticScatter(const pandora::MCParticle *const pMCParticle);
507 
508  /**
509  * @brief Check whether or not an MC particle comes from an ionisation process
510  *
511  * @param pMCParticle The MC particle to consider
512  *
513  * @return Whether or not the MC particle came from ionisation
514  */
515  static bool IsIonisation(const pandora::MCParticle *const pMCParticle);
516 
517  /**
518  * @brief Check whether or not an MC particle comes from a nuclear interaction process
519  *
520  * @param pMCParticle The MC particle to consider
521  *
522  * @return Whether or not the MC particle came from nuclear interaction
523  */
524  static bool IsNuclear(const pandora::MCParticle *const pMCParticle);
525 
526  /**
527  * @brief Check whether or not an MC particle comes from a pair production process
528  *
529  * @param pMCParticle The MC particle to consider
530  *
531  * @return Whether or not the MC particle came from pair production
532  */
533  static bool IsPairProduction(const pandora::MCParticle *const pMCParticle);
534 
535  /**
536  * @brief Determine if two MC particles are topologically continuous within a given tolerance.
537  * If the parent does not travel any distance, a travelling parent is sought and the comparison made between this and the child.
538  * If no travelling parent can be found, the particles are treated as continuous.
539  *
540  * @param pMCParent The parent MC particle
541  * @param pMCChild The child MC particle
542  * @param cosAngleTolerance The cosine of the maximum acceptable angular deviation
543  *
544  * @return True if the partiles are topologically continous, false otherwise.
545  */
546  static bool AreTopologicallyContinuous(
547  const pandora::MCParticle *const pMCParent, const pandora::MCParticle *const pMCChild, const float cosAngleTolerance);
548 
549 private:
550  /**
551  * @brief For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle)
552  *
553  * @param pPfo the input pfo
554  * @param selectedMCParticleToHitsMaps the input mappings from selected reconstructable MCParticles to hits
555  * @param reconstructableCaloHitList2D the output list of reconstructable 2D calo hits in the input pfo
556  * @param foldBackHierarchy whether to fold the particle hierarchy back to primaries
557  */
558  static void CollectReconstructable2DHits(const pandora::ParticleFlowObject *const pPfo, const MCContributionMapVector &selectedMCParticleToHitsMaps,
559  pandora::CaloHitList &reconstructableCaloHitList2D, const bool foldBackHierarchy);
560 
561  /**
562  * @brief For a given Pfo, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle)
563  * and belong in the test beam particle interaction hierarchy
564  *
565  * @param pPfo the input pfo
566  * @param selectedMCParticleToHitsMaps the input mappings from selected reconstructable MCParticles to hits
567  * @param reconstructableCaloHitList2D the output list of reconstructable 2D calo hits in the input pfo
568  * @param foldBackHierarchy whether to fold the particle hierarchy back to leading particles
569  */
570  static void CollectReconstructableTestBeamHierarchy2DHits(const pandora::ParticleFlowObject *const pPfo,
571  const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D, const bool foldBackHierarchy);
572 
573  /**
574  * @brief For a given Pfo list, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle)
575  *
576  * @param pfoList the input pfo list
577  * @param selectedMCParticleToHitsMaps the input mappings from selected reconstructable MCParticles to hits
578  * @param reconstructableCaloHitList2D the output list of reconstructable 2D calo hits in the input pfo
579  */
580  static void CollectReconstructable2DHits(const pandora::PfoList &pfoList, const MCContributionMapVector &selectedMCParticleToHitsMaps,
581  pandora::CaloHitList &reconstructableCaloHitList2D);
582 
583  /**
584  * @brief For a given cluster, collect the hits which are reconstructable (=good hits belonging to a selected reconstructable MCParticle)
585  *
586  * @param pCluster the input cluster
587  * @param selectedMCToHitsMaps the input mappings from selected reconstructable MCParticles to hits
588  * @param reconstructableCaloHitList2D the output list of reconstructable 2D calo hits in the input pfo
589  */
590  static void CollectReconstructable2DHits(const pandora::Cluster *const pCluster,
591  const MCContributionMapVector &selectedMCParticleToHitsMaps, pandora::CaloHitList &reconstructableCaloHitList2D);
592 
593  /**
594  * @brief Apply further selection criteria to end up with a collection of "good" calo hits that can be use to define whether
595  * a target mc particle is reconstructable.
596  *
597  * @param pSelectedCaloHitList the address of the calo hit list (typically already been through some selection procedure)
598  * @param mcToTargetMCMap the mc particle to target (primary or self) mc particle map
599  * @param selectedGoodCaloHitList to receive the populated good selected calo hit list
600  * @param selectInputHits whether to select input hits
601  * @param minHitSharingFraction the minimum Hit sharing fraction
602  */
603  static void SelectGoodCaloHits(const pandora::CaloHitList *const pSelectedCaloHitList, const MCRelationMap &mcToTargetMCMap,
604  pandora::CaloHitList &selectedGoodCaloHitList, const bool selectInputHits, const float minHitSharingFraction);
605 
606  /**
607  * @brief Select mc particles matching given criteria from an input list
608  *
609  * @param inputMCParticles input vector of MCParticles
610  * @param fCriteria a function which returns a bool (= shouldSelect) for a given input MCParticle
611  * @param selectedParticles the output vector of particles selected
612  * @param parameters validation parameters to decide when an MCParticle is considered reconstructable
613  * @param isTestBeam whether the mc particles correspond to the test beam case or the neutrino case
614  */
615  static void SelectParticlesMatchingCriteria(const pandora::MCParticleVector &inputMCParticles,
616  std::function<bool(const pandora::MCParticle *const)> fCriteria, pandora::MCParticleVector &selectedParticles,
617  const PrimaryParameters &parameters, const bool isTestBeam);
618 
619  /**
620  * @brief Whether it is possible to navigate from a primary mc particle to a downstream mc particle without "passing through" a neutron
621  *
622  * @param pOriginalPrimary the address of the original primary mc particle
623  * @param pThisMCParticle the address of the current mc particle in the primary decay chain
624  * @param pHitMCParticle the address of the mc particle associated to a calo hit
625  * @param maxPhotonPropagation the maximum photon propagation length
626  *
627  * @return boolean
628  */
629  static bool PassMCParticleChecks(const pandora::MCParticle *const pOriginalPrimary, const pandora::MCParticle *const pThisMCParticle,
630  const pandora::MCParticle *const pHitMCParticle, const float maxPhotonPropagation);
631 };
632 
633 } // namespace lar_content
634 
635 #endif // #ifndef LAR_MC_PARTICLE_HELPER_H
static bool IsVisible(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is visible (i.e. long-lived charged particle)
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...
unsigned int m_minPrimaryGoodViews
the minimum number of primary good views
static bool IsNuclear(const pandora::MCParticle *const pMCParticle)
Check whether or not an MC particle comes from a nuclear interaction process.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
bool m_selectInputHits
whether to select input hits
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
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 belo...
static bool IsPrimary(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being primary.
static void GetLeadingMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcLeadingVector)
Get vector of leading MC particles from an input list of MC particles.
static bool IsLeadingBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a leading beam MCParticle.
unsigned int m_minPrimaryGoodHits
the minimum number of primary good Hits
std::unordered_map< const pandora::CaloHit *, const pandora::ParticleFlowObject * > CaloHitToPfoMap
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 M...
std::unordered_map< const pandora::CaloHit *, const pandora::MCParticle * > CaloHitToMCMap
static int GetHierarchyTier(const pandora::MCParticle *const pMCParticle)
Determine the position in the hierarchy for the MCParticle.
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 sha...
static const pandora::MCParticle * GetPrimaryMCParticle(const pandora::MCParticle *const pMCParticle)
Get the primary parent mc particle.
std::map< const pandora::MCParticle *, PfoToSharedHitsVector > MCParticleToPfoHitSharingMap
std::vector< PfoCaloHitListPair > PfoToSharedHitsVector
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...
std::pair< const pandora::Cluster *, pandora::CaloHitList > ClusterCaloHitListPair
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
bool m_foldBackHierarchy
whether to fold the hierarchy back to the primary (neutrino) or leading particles (test beam) ...
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...
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 bool IsPairProduction(const pandora::MCParticle *const pMCParticle)
Check whether or not an MC particle comes from a pair production process.
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...
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
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.
float m_maxPhotonPropagation
the maximum photon propagation length
std::unordered_map< const pandora::MCParticle *, const pandora::ParticleFlowObject * > MCToPfoMap
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 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 recon...
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
static bool IsCosmicRay(const pandora::MCParticle *const pMCParticle)
Return true if passed a primary cosmic ray MCParticle.
static bool IsInelasticScatter(const pandora::MCParticle *const pMCParticle)
Check whether or not an MC particle came from an inelastic scattering process.
static bool IsLeading(const pandora::MCParticle *const pMCParticle)
Whether a provided mc particle matches the implemented definition of being leading.
static void SelectReconstructableMCParticles(const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters &parameters, std::function< bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap)
Select target, reconstructable mc particles that match given criteria.
static 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...
std::unordered_map< const pandora::MCParticle *, int > MCParticleIntMap
static void GetMCParticleToCaloHitMatches(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, CaloHitToMCMap &hitToMCMap, MCContributionMap &mcToTrueHitListMap)
Match calo hits to their parent particles.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
std::unordered_map< const pandora::Cluster *, pandora::CaloHitList > ClusterContributionMap
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
static bool IsTriggeredBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary triggered beam MCParticle.
float m_minHitSharingFraction
the minimum Hit sharing fraction
Header file for the lar mc particle class.
static void GetMCLeadingMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcLeadingMap)
Get mapping from individual mc particles (in a provided list) and their leading parent mc particles...
static bool IsDecay(const pandora::MCParticle *const pMCParticle)
Check whether or not an MC particle comes from a decay process.
std::vector< MCContributionMap > MCContributionMapVector
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.
static bool IsBremsstrahlung(const pandora::MCParticle *const pMCParticle)
static void GetPrimaryMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcPrimaryVector)
Get vector of primary MC particles from an input list of MC particles.
static bool 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 void GetAllAncestorMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &ancestorMCParticleList)
Get all ancestor mc particles.
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 GetTrueNeutrinos(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueNeutrinos)
Get neutrino MC particles from an input MC particle list.
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
static bool IsCapture(const pandora::MCParticle *const pMCParticle)
Check whether or not an MC particle comes from a capture process.
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...
std::unordered_map< const pandora::MCParticle *, PfoContributionMap > MCToPfoMatchingMap
static bool IsIonisation(const pandora::MCParticle *const pMCParticle)
Check whether or not an MC particle comes from an ionisation process.
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.
std::vector< MCParticleCaloHitListPair > MCParticleToSharedHitsVector
LArMCParticleHelper class.
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.
static void GetTrueTestBeamParticles(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueTestBeamParticles)
Get triggered test beam MC particles from an input MC particle list.
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.
std::unordered_map< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoContributionMap
static void GetAllDescendentMCParticles(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &descendentMCParticleList)
Get all descendent mc particles.
void function(int client, int *resource, int parblock, int *test, int p)
static pandora::CaloHitList GetSharedHits(const pandora::CaloHitList &hitListA, const pandora::CaloHitList &hitListB)
Get the hits in the intersection of two hit lists.
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
static void GetBreadthFirstHierarchyRepresentation(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &mcParticleList)
Retrieve a linearised representation of the MC particle hierarchy in breadth first order...
static bool IsElasticScatter(const pandora::MCParticle *const pMCParticle)
Check whether or not an MC particle came from an elastic scattering process.
std::map< const pandora::ParticleFlowObject *, MCParticleToSharedHitsVector > PfoToMCParticleHitSharingMap
static bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.
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...