All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NeutrinoIdTool.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArControlFlow/NeutrinoIdTool.h
3  *
4  * @brief Header file for the neutrino id tool class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_NEUTRINO_ID_TOOL_H
9 #define LAR_NEUTRINO_ID_TOOL_H 1
10 
12 
15 
16 #include <functional>
17 
18 namespace lar_content
19 {
20 
21 /**
22  * @brief NeutrinoIdTool class
23  *
24  * Compares the neutrino and cosmic hypotheses of all of the slices in the event. Uses an MVA to calculate the probability of each slice
25  * containing a neutrino interaction. The N slices with the highest probabilities are identified as a neutrino (if sufficiently probable)
26  * all other slices are deemed cosmogenic.
27  *
28  * If training mode is switched on, then the tool will write MVA training exmples to the specified output file. The events selected for
29  * training must pass (user configurable) slicing quality cuts. Users may also select events based on their interaction type (nuance code).
30  */
31 template <typename T>
33 {
34 public:
35  /**
36  * @brief Default constructor
37  */
39 
40  void SelectOutputPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses,
41  const SliceHypotheses &crSliceHypotheses, pandora::PfoList &selectedPfos);
42 
43 private:
44  /**
45  * @brief Slice features class
46  */
48  {
49  public:
50  /**
51  * @brief Constructor
52  *
53  * @param nuPfos input list of Pfos reconstructed under the neutrino hypothesis
54  * @param crPfos input list of Pfos reconstructed under the cosmic ray hypothesis
55  * @param pTool address of the tool using this class
56  */
57  SliceFeatures(const pandora::PfoList &nuPfos, const pandora::PfoList &crPfos, const NeutrinoIdTool *const pTool);
58 
59  /**
60  * @brief Check if all features were calculable
61  *
62  * @return true if the feature vector is available
63  */
64  bool IsFeatureVectorAvailable() const;
65 
66  /**
67  * @brief Get the feature vector for the MVA
68  *
69  * @param featuresVector empty feature vector to populate
70  */
71  void GetFeatureVector(LArMvaHelper::MvaFeatureVector &featureVector) const;
72 
73  /**
74  * @brief Get the feature map for the MVA
75  *
76  * @param featuresMap empty feature map to populate
77  */
78  void GetFeatureMap(LArMvaHelper::DoubleMap &featureMap) const;
79 
80  /**
81  * @brief Get the probability that this slice contains a neutrino interaction
82  *
83  * @param t the MVA used to calculate the probability
84  *
85  * @return the probability that the slice contains a neutrino interaction
86  */
87  float GetNeutrinoProbability(const T &t) const;
88 
89  private:
90  /**
91  * @brief Get the recontructed neutrino the input list of neutrino Pfos
92  *
93  * @param nuPfos input list of neutrino pfos
94  */
95  const pandora::ParticleFlowObject *GetNeutrino(const pandora::PfoList &nuPfos) const;
96 
97  /**
98  * @brief Get the 3D space points in a given pfo
99  *
100  * @param pPfo input pfo
101  * @param spacePoints vector to hold the 3D space points associated with the input pfo
102  */
103  void GetSpacePoints(const pandora::ParticleFlowObject *const pPfo, pandora::CartesianPointVector &spacePoints) const;
104 
105  /**
106  * @brief Use a sliding fit to get the direction of a collection of spacepoints
107  *
108  * @param spacePoints the input spacepoints to fit
109  * @param fShouldChooseA a function that when given two fitted endpoints A and B, will return true if A is the endpoint at which to calculate the direction
110  *
111  * @return the direction of the input spacepoints
112  */
113  pandora::CartesianVector GetDirection(const pandora::CartesianPointVector &spacePoints,
114  std::function<bool(const pandora::CartesianVector &pointA, const pandora::CartesianVector &pointB)> fShouldChooseA) const;
115 
116  /**
117  * @brief Use a sliding fit to get the direction of a collection of spacepoint near a vertex position
118  *
119  * @param spacePoints the input spacepoints to fit
120  * @param vertex the position from which the fitted direction should be calculated
121  *
122  * @return the direction of the input space points from the vertex supplied
123  */
124  pandora::CartesianVector GetDirectionFromVertex(const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex) const;
125 
126  /**
127  * @brief Use a sliding fit to get the upper direction of a collection of spacepoints
128  *
129  * @param spacePoints the input spacepoints to fit
130  *
131  * @return the direction of the upper input space points
132  */
133  pandora::CartesianVector GetUpperDirection(const pandora::CartesianPointVector &spacePoints) const;
134 
135  /**
136  * @brief Use a sliding fit to get the lower direction of a collection of spacepoints
137  *
138  * @param spacePoints the input spacepoints to fit
139  *
140  * @return the direction of the lower input space points
141  */
142  pandora::CartesianVector GetLowerDirection(const pandora::CartesianPointVector &spacePoints) const;
143 
144  /**
145  * @brief Get a vector of spacepoints within a given radius of a vertex point
146  *
147  * @param spacePoints the input spacepoints
148  * @param vertex the center of the sphere
149  * @param radius the radius of the sphere
150  * @param spacePointsInSphere the vector to hold the spacepoint in the sphere
151  */
152  void GetPointsInSphere(const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex, const float radius,
153  pandora::CartesianPointVector &spacePointsInSphere) const;
154 
155  bool m_isAvailable; ///< Is the feature vector available
156  LArMvaHelper::MvaFeatureVector m_featureVector; ///< The MVA feature vector
157  LArMvaHelper::DoubleMap m_featureMap; ///< A map between MVA features and their names
158  const NeutrinoIdTool *const m_pTool; ///< The tool that owns this
159  };
160 
161  typedef std::pair<unsigned int, float> UintFloatPair;
162  typedef std::vector<SliceFeatures> SliceFeaturesVector;
163 
164  /**
165  * @brief Get the features of each slice
166  *
167  * @param pTool the address of the this NeutrinoId tool
168  * @param nuSliceHypotheses the input neutrino slice hypotheses
169  * @param crSliceHypotheses the input cosmic slice hypotheses
170  * @param sliceFeaturesVector vector to hold the slice features
171  */
172  void GetSliceFeatures(const NeutrinoIdTool *const pTool, const SliceHypotheses &nuSliceHypotheses,
173  const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const;
174 
175  /**
176  * @brief Get the slice with the most neutrino induced hits using Monte-Carlo information
177  *
178  * @param pAlgorithm address of the master algorithm
179  * @param nuSliceHypotheses the input neutrino slice hypotheses
180  * @param crSliceHypotheses the input cosmic slice hypotheses
181  * @param bestSliceIndex the index of the slice with the most neutrino hits
182  *
183  * @return does the best slice pass the quality cuts for training?
184  */
185  bool GetBestMCSliceIndex(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses,
186  const SliceHypotheses &crSliceHypotheses, unsigned int &bestSliceIndex) const;
187 
188  /**
189  * @brief Determine if the event passes the selection cuts for training and has the required NUANCE code
190  *
191  * @param pAlgorithm address of the master algorithm
192  * @param purity purity of best slice
193  * @param completeness completeness of best slice
194  *
195  * @return does the evenr pass the quality cuts on purity and completeness and has the required NUANCE code
196  */
197  bool PassesQualityCuts(const pandora::Algorithm *const pAlgorithm, const float purity, const float completeness) const;
198 
199  /**
200  * @brief Collect all 2D hits in a supplied list of Pfos and push them on to an existing hit list, check so not to double count
201  *
202  * @param pfos input list of pfos
203  * @param reconstructedCaloHitList output list of all 2d hits in the input pfos
204  * @param reconstructableCaloHitSet set of reconstructable calo hits
205  */
206  void Collect2DHits(const pandora::PfoList &pfos, pandora::CaloHitList &reconstructedCaloHitList,
207  const pandora::CaloHitSet &reconstructableCaloHitSet) const;
208 
209  /**
210  * @brief Count the number of neutrino induced hits in a given list using MC information
211  *
212  * @param caloHitSet input list of calo hits
213  *
214  * @return the number of neutrino induced hits in the input list
215  */
216  unsigned int CountNeutrinoInducedHits(const pandora::CaloHitList &caloHitList) const;
217 
218  /**
219  * @brief Use the current MCParticle list to get the nuance code of the neutrino in the event
220  *
221  * @param pAlgorithm address of the master algorithm
222  *
223  * @return the nuance code of the event
224  */
225  int GetNuanceCode(const pandora::Algorithm *const pAlgorithm) const;
226 
227  /**
228  * @brief Select all pfos under the same hypothesis
229  *
230  * @param pAlgorithm address of the master algorithm
231  * @param hypotheses the lists of slices under a certain hypothesis
232  * @param selectedPfos the list of pfos to populate
233  */
234  void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const;
235 
236  /**
237  * @brief Select pfos based on the probability that their slice contains a neutrino interaction
238  *
239  * @param pAlgorithm address of the master algorithm
240  * @param nuSliceHypotheses the input neutrino slice hypotheses
241  * @param crSliceHypotheses the input cosmic slice hypotheses
242  * @param sliceFeaturesVector vector holding the slice features
243  * @param selectedPfos the list of pfos to populate
244  */
245  void SelectPfosByProbability(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses,
246  const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const;
247 
248  /**
249  * @brief Add the given pfos to the selected Pfo list
250  *
251  * @param pfos the pfos to select
252  * @param selectedPfos the list of pfos to populate
253  */
254  void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const;
255 
256  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
257 
258  // Training
259  bool m_useTrainingMode; ///< Should use training mode. If true, training examples will be written to the output file
260  std::string m_trainingOutputFile; ///< Output file name for training examples
261  bool m_selectNuanceCode; ///< Should select training events by nuance code
262  int m_nuance; ///< Nuance code to select for training
263  float m_minPurity; ///< Minimum purity of the best slice to use event for training
264  float m_minCompleteness; ///< Minimum completeness of the best slice to use event for training
265 
266  // Classification
267  float m_minProbability; ///< Minimum probability required to classify a slice as the neutrino
268  unsigned int m_maxNeutrinos; ///< The maximum number of neutrinos to select in any one event
269 
270  bool m_persistFeatures; ///< If true, the mva features will be persisted in the metadata
271 
272  T m_mva; ///< The mva
273  std::string m_filePathEnvironmentVariable; ///< The environment variable providing a list of paths to mva files
274 };
275 
278 
279 } // namespace lar_content
280 
281 #endif // #ifndef LAR_NEUTRINO_ID_TOOL_H
process_name vertex
Definition: cheaterreco.fcl:51
bool PassesQualityCuts(const pandora::Algorithm *const pAlgorithm, const float purity, const float completeness) const
Determine if the event passes the selection cuts for training and has the required NUANCE code...
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:72
bool GetBestMCSliceIndex(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, unsigned int &bestSliceIndex) const
Get the slice with the most neutrino induced hits using Monte-Carlo information.
SliceFeatures(const pandora::PfoList &nuPfos, const pandora::PfoList &crPfos, const NeutrinoIdTool *const pTool)
Constructor.
void GetFeatureMap(LArMvaHelper::DoubleMap &featureMap) const
Get the feature map for the MVA.
bool IsFeatureVectorAvailable() const
Check if all features were calculable.
NeutrinoIdTool()
Default constructor.
float m_minProbability
Minimum probability required to classify a slice as the neutrino.
int GetNuanceCode(const pandora::Algorithm *const pAlgorithm) const
Use the current MCParticle list to get the nuance code of the neutrino in the event.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
const NeutrinoIdTool *const m_pTool
The tool that owns this.
void SelectOutputPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::PfoList &selectedPfos)
Select which reconstruction hypotheses to use; neutrino outcomes or cosmic-ray muon outcomes for each...
void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const
Select all pfos under the same hypothesis.
LArMvaHelper::DoubleMap m_featureMap
A map between MVA features and their names.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to mva files.
void Collect2DHits(const pandora::PfoList &pfos, pandora::CaloHitList &reconstructedCaloHitList, const pandora::CaloHitSet &reconstructableCaloHitSet) const
Collect all 2D hits in a supplied list of Pfos and push them on to an existing hit list...
bool m_selectNuanceCode
Should select training events by nuance code.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
unsigned int CountNeutrinoInducedHits(const pandora::CaloHitList &caloHitList) const
Count the number of neutrino induced hits in a given list using MC information.
std::pair< unsigned int, float > UintFloatPair
void GetFeatureVector(LArMvaHelper::MvaFeatureVector &featureVector) const
Get the feature vector for the MVA.
float GetNeutrinoProbability(const T &t) const
Get the probability that this slice contains a neutrino interaction.
pandora::CartesianVector GetLowerDirection(const pandora::CartesianPointVector &spacePoints) const
Use a sliding fit to get the lower direction of a collection of spacepoints.
void GetSliceFeatures(const NeutrinoIdTool *const pTool, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const
Get the features of each slice.
Header file for the master algorithm class.
Header file for the lar adaptive boosted decision tree class.
std::map< std::string, double > DoubleMap
Definition: LArMvaHelper.h:73
int m_nuance
Nuance code to select for training.
bool m_isAvailable
Is the feature vector available.
Header file for the lar support vector machine class.
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
std::vector< pandora::PfoList > SliceHypotheses
float m_minPurity
Minimum purity of the best slice to use event for training.
LArMvaHelper::MvaFeatureVector m_featureVector
The MVA feature vector.
const pandora::ParticleFlowObject * GetNeutrino(const pandora::PfoList &nuPfos) const
Get the recontructed neutrino the input list of neutrino Pfos.
void SelectPfosByProbability(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const
Select pfos based on the probability that their slice contains a neutrino interaction.
std::vector< SliceFeatures > SliceFeaturesVector
bool m_persistFeatures
If true, the mva features will be persisted in the metadata.
NeutrinoIdTool class.
SliceIdBaseTool class.
pandora::CartesianVector GetDirectionFromVertex(const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex) const
Use a sliding fit to get the direction of a collection of spacepoint near a vertex position...
pandora::CartesianVector GetUpperDirection(const pandora::CartesianPointVector &spacePoints) const
Use a sliding fit to get the upper direction of a collection of spacepoints.
pandora::CartesianVector GetDirection(const pandora::CartesianPointVector &spacePoints, std::function< bool(const pandora::CartesianVector &pointA, const pandora::CartesianVector &pointB)> fShouldChooseA) const
Use a sliding fit to get the direction of a collection of spacepoints.
void GetPointsInSphere(const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex, const float radius, pandora::CartesianPointVector &spacePointsInSphere) const
Get a vector of spacepoints within a given radius of a vertex point.
void GetSpacePoints(const pandora::ParticleFlowObject *const pPfo, pandora::CartesianPointVector &spacePoints) const
Get the 3D space points in a given pfo.
std::string m_trainingOutputFile
Output file name for training examples.
NeutrinoIdTool< AdaBoostDecisionTree > BdtNeutrinoIdTool
NeutrinoIdTool< SupportVectorMachine > SvmNeutrinoIdTool