All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArPandoraSliceIdHelper.h
Go to the documentation of this file.
1 /**
2  * @file larpandora/LArPandoraEventBuilding/LArPandoraSliceIdHelper.h
3  *
4  * @brief helper class for slice id tools
5  *
6  */
7 #ifndef LAR_PANDORA_SLICE_ID_HELPER_H
8 #define LAR_PANDORA_SLICE_ID_HELPER_H
9 
12 
13 namespace recob { class Hit; }
14 
15 namespace simb {
16  class MCNeutrino;
17  class MCTruth;
18 }
19 
20 namespace art { class Event; }
21 
22 #include "canvas/Persistency/Common/Ptr.h"
23 
24 #include <string>
25 #include <unordered_map>
26 #include <vector>
27 
28 namespace lar_pandora
29 {
30 
31 /**
32  * @brief Helper class for slice id tools
33  */
35 {
36 public:
37  /**
38  * @brief Class to hold MC metdata about slices
39  */
41  {
42  public:
43  /**
44  * @brief Default constructor
45  */
46  SliceMetadata();
47 
48  float m_purity; ///< The fraction of hits in the slice that are neutrino induced
49  float m_completeness; ///< The fraction of all neutrino induced hits that are in the slice
50  unsigned int m_nHits; ///< The number of hits in the slice
51  bool m_isMostComplete; ///< If the slice has the highest completeness in the event
52  };
53 
54  typedef std::vector<SliceMetadata> SliceMetadataVector;
55 
56  /**
57  * @brief Get MC metadata about each slice
58  *
59  * @param slices the input vector of slices
60  * @param evt the art event
61  * @param truthLabel the label of the MCTruth producer
62  * @param mcParticleLabel the label of the MCParticle producer
63  * @param hitLabel the label of the Hit producer
64  * @param backtrackLabel the label of the Hit -> MCParticle association producer
65  * @param pandoraLabel the label of the Pandora all outcomes producer
66  * @param sliceMetadata the output vector of slice metadata (mapping 1:1 to the slices)
67  * @param interactionType the output true interaction type code of the MCNeutrino
68  * @param nuEnergy the output true energy of the neutrino
69  * @param nuNeutrino the mc neutrino from the beam neutrino MCTruth block
70  */
71  static void GetSliceMetadata(const SliceVector &slices, const art::Event &evt, const std::string &truthLabel,
72  const std::string &mcParticleLabel, const std::string &hitLabel, const std::string &backtrackLabel, const std::string &pandoraLabel,
73  SliceMetadataVector &sliceMetadata, simb::MCNeutrino &mcNeutrino);
74 
75 private:
76  typedef std::unordered_map<art::Ptr<recob::Hit>, bool> HitToBoolMap;
77 
78  /**
79  * @brief Get the MCTruth block for the simulated beam neutrino
80  *
81  * @param evt the art event
82  * @param truthLabel the label of the MCTruth producer
83  *
84  * @return the MCTruth block for the simulated beam neutrino
85  */
86  static art::Ptr<simb::MCTruth> GetBeamNeutrinoMCTruth(const art::Event &evt, const std::string &truthLabel);
87 
88  /**
89  * @brief Collect all MCParticles that come from the beam neutrino interaction
90  *
91  * @param evt the art event
92  * @param truthLabel the label of the MCTruth producer
93  * @param mcParticleLabel the label of the MCParticle producer
94  * @param beamNuMCTruth the MCTruth block for the beam neutrino
95  * @param mcParticles the output vector of neutrino induced MCParticles
96  */
97  static void CollectNeutrinoMCParticles(const art::Event &evt, const std::string &truthLabel, const std::string &mcParticleLabel,
98  const art::Ptr<simb::MCTruth> &beamNuMCTruth, MCParticleVector &mcParticles);
99 
100  /**
101  * @brief For each hit in the event, determine if any of it's charge was deposited by a neutrino induced particle
102  *
103  * @param evt the art event
104  * @param hitLabel the label of the Hit producer
105  * @param backtrackLabel the label of the Hit->MCParticle association producer - backtracker
106  * @param mcParticles the input vector of neutrino induced MCParticles
107  * @param hits the output vector of all hits
108  * @param hitToIsNuInducedMap the output mapping from hits to a bool = true if hit is neutrino induced
109  */
110  static void GetHitOrigins(const art::Event &evt, const std::string &hitLabel, const std::string &backtrackLabel,
111  const MCParticleVector &mcParticles, HitVector &hits, HitToBoolMap &hitToIsNuInducedMap);
112 
113  /**
114  * @brief Count the number of hits in an input vector that are neutrino induced
115  *
116  * @param hits the input vector of hits
117  * @param hitToIsNuInducedMap the mapping from hits to isNuInduced boolean
118  *
119  * @return the number of hits that are neutrino induced
120  */
121  static unsigned int CountNeutrinoHits(const HitVector &hits, const HitToBoolMap &hitToIsNuInducedMap);
122 
123  /**
124  * @brief Get the mapping from PFParticles to associated hits (via clusters)
125  *
126  * @param evt the art event
127  * @param pandoraLabel the label of the PFParticle <-> Cluster and Cluster <-> Hit associations - Pandora pattern recognition
128  * @param pfParticleToHitsMap the output mapping from PFParticles to associated hits
129  */
130  static void GetPFParticleToHitsMap(const art::Event &evt, const std::string &pandoraLabel, PFParticlesToHits &pfParticleToHitsMap);
131 
132  /**
133  * @brief Collect the hits in the slice that have been added to a PFParticle (under either reconstruction hypothesis)
134  *
135  * @param slice the input slice
136  * @param pfParticleToHitsMap the input mapping from PFParticles to hits
137  * @param hits the output vector of reconstructed hits in the slice
138  */
139  static void GetReconstructedHitsInSlice(const Slice &slice, const PFParticlesToHits &pfParticleToHitsMap, HitVector &hits);
140 
141  /**
142  * @brief Collect the hits in a given vector of PFParticles
143  *
144  * @param pfParticles the input vector of PFParticles
145  * @param pfParticleToHitsMap the input mapping from PFParticles to hits
146  * @param hits the output vector of hits
147  */
148  static void CollectHits(const PFParticleVector &pfParticles, const PFParticlesToHits &pfParticleToHitsMap, HitVector &hits);
149 
150  /**
151  * @brief Calculate the MC slice metadata
152  *
153  * @param slices the input vector of slices
154  * @param pfParticleToHitsMap the input mapping from PFParticles to hits
155  * @param hitToIsNuInducedMap the input mapping from hits to isNuInduced boolean
156  * @param nNuHits the total number of neutrino induced hits in the event
157  * @param sliceMetadata the output vector of metadata objects correspoinding 1:1 to the input slices
158  */
159  static void GetSliceMetadata(const SliceVector &slices, const PFParticlesToHits &pfParticleToHitsMap,
160  const HitToBoolMap &hitToIsNuInducedMap, const unsigned int nNuHits, SliceMetadataVector &sliceMetadata);
161 };
162 
163 } // namespace lar_pandora
164 
165 #endif // LAR_PANDORA_SLICE_ID_HELPER_H
std::unordered_map< art::Ptr< recob::Hit >, bool > HitToBoolMap
static unsigned int CountNeutrinoHits(const HitVector &hits, const HitToBoolMap &hitToIsNuInducedMap)
Count the number of hits in an input vector that are neutrino induced.
static void CollectNeutrinoMCParticles(const art::Event &evt, const std::string &truthLabel, const std::string &mcParticleLabel, const art::Ptr< simb::MCTruth > &beamNuMCTruth, MCParticleVector &mcParticles)
Collect all MCParticles that come from the beam neutrino interaction.
float m_purity
The fraction of hits in the slice that are neutrino induced.
static void CollectHits(const PFParticleVector &pfParticles, const PFParticlesToHits &pfParticleToHitsMap, HitVector &hits)
Collect the hits in a given vector of PFParticles.
unsigned int m_nHits
The number of hits in the slice.
static void GetPFParticleToHitsMap(const art::Event &evt, const std::string &pandoraLabel, PFParticlesToHits &pfParticleToHitsMap)
Get the mapping from PFParticles to associated hits (via clusters)
static void GetHitOrigins(const art::Event &evt, const std::string &hitLabel, const std::string &backtrackLabel, const MCParticleVector &mcParticles, HitVector &hits, HitToBoolMap &hitToIsNuInducedMap)
For each hit in the event, determine if any of it&#39;s charge was deposited by a neutrino induced partic...
std::vector< SliceMetadata > SliceMetadataVector
static void GetReconstructedHitsInSlice(const Slice &slice, const PFParticlesToHits &pfParticleToHitsMap, HitVector &hits)
Collect the hits in the slice that have been added to a PFParticle (under either reconstruction hypot...
Helper class for slice id tools.
float m_completeness
The fraction of all neutrino induced hits that are in the slice.
static void GetSliceMetadata(const SliceVector &slices, const art::Event &evt, const std::string &truthLabel, const std::string &mcParticleLabel, const std::string &hitLabel, const std::string &backtrackLabel, const std::string &pandoraLabel, SliceMetadataVector &sliceMetadata, simb::MCNeutrino &mcNeutrino)
Get MC metadata about each slice.
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
std::map< art::Ptr< recob::PFParticle >, HitVector > PFParticlesToHits
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
header for the lar pandora slice class
std::vector< TCSlice > slices
Definition: DataStructs.cxx:13
std::vector< art::Ptr< recob::Hit > > HitVector
static art::Ptr< simb::MCTruth > GetBeamNeutrinoMCTruth(const art::Event &evt, const std::string &truthLabel)
Get the MCTruth block for the simulated beam neutrino.
bool m_isMostComplete
If the slice has the highest completeness in the event.
TCEvent evt
Definition: DataStructs.cxx:8
helper function for LArPandoraInterface producer module