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 probability that this slice contains a neutrino interaction
75  *
76  * @param t the MVA used to calculate the probability
77  *
78  * @return the probability that the slice contains a neutrino interaction
79  */
80  float GetNeutrinoProbability(const T &t) const;
81 
82  private:
83  /**
84  * @brief Get the recontructed neutrino the input list of neutrino Pfos
85  *
86  * @param nuPfos input list of neutrino pfos
87  */
88  const pandora::ParticleFlowObject *GetNeutrino(const pandora::PfoList &nuPfos) const;
89 
90  /**
91  * @brief Get the 3D space points in a given pfo
92  *
93  * @param pPfo input pfo
94  * @param spacePoints vector to hold the 3D space points associated with the input pfo
95  */
96  void GetSpacePoints(const pandora::ParticleFlowObject *const pPfo, pandora::CartesianPointVector &spacePoints) const;
97 
98  /**
99  * @brief Use a sliding fit to get the direction of a collection of spacepoints
100  *
101  * @param spacePoints the input spacepoints to fit
102  * @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
103  *
104  * @return the direction of the input spacepoints
105  */
106  pandora::CartesianVector GetDirection(const pandora::CartesianPointVector &spacePoints,
107  std::function<bool(const pandora::CartesianVector &pointA, const pandora::CartesianVector &pointB)> fShouldChooseA) const;
108 
109  /**
110  * @brief Use a sliding fit to get the direction of a collection of spacepoint near a vertex position
111  *
112  * @param spacePoints the input spacepoints to fit
113  * @param vertex the position from which the fitted direction should be calculated
114  *
115  * @return the direction of the input space points from the vertex supplied
116  */
117  pandora::CartesianVector GetDirectionFromVertex(const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex) const;
118 
119  /**
120  * @brief Use a sliding fit to get the upper direction of a collection of spacepoints
121  *
122  * @param spacePoints the input spacepoints to fit
123  *
124  * @return the direction of the upper input space points
125  */
126  pandora::CartesianVector GetUpperDirection(const pandora::CartesianPointVector &spacePoints) const;
127 
128  /**
129  * @brief Use a sliding fit to get the lower direction of a collection of spacepoints
130  *
131  * @param spacePoints the input spacepoints to fit
132  *
133  * @return the direction of the lower input space points
134  */
135  pandora::CartesianVector GetLowerDirection(const pandora::CartesianPointVector &spacePoints) const;
136 
137  /**
138  * @brief Get a vector of spacepoints within a given radius of a vertex point
139  *
140  * @param spacePoints the input spacepoints
141  * @param vertex the center of the sphere
142  * @param radius the radius of the sphere
143  * @param spacePointsInSphere the vector to hold the spacepoint in the sphere
144  */
145  void GetPointsInSphere(const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex, const float radius,
146  pandora::CartesianPointVector &spacePointsInSphere) const;
147 
148  bool m_isAvailable; ///< Is the feature vector available
149  LArMvaHelper::MvaFeatureVector m_featureVector; ///< The MVA feature vector
150  const NeutrinoIdTool *const m_pTool; ///< The tool that owns this
151  };
152 
153  typedef std::pair<unsigned int, float> UintFloatPair;
154  typedef std::vector<SliceFeatures> SliceFeaturesVector;
155 
156  /**
157  * @brief Get the features of each slice
158  *
159  * @param pTool the address of the this NeutrinoId tool
160  * @param nuSliceHypotheses the input neutrino slice hypotheses
161  * @param crSliceHypotheses the input cosmic slice hypotheses
162  * @param sliceFeaturesVector vector to hold the slice features
163  */
164  void GetSliceFeatures(const NeutrinoIdTool *const pTool, const SliceHypotheses &nuSliceHypotheses,
165  const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const;
166 
167  /**
168  * @brief Get the slice with the most neutrino induced hits using Monte-Carlo information
169  *
170  * @param pAlgorithm address of the master algorithm
171  * @param nuSliceHypotheses the input neutrino slice hypotheses
172  * @param crSliceHypotheses the input cosmic slice hypotheses
173  * @param bestSliceIndex the index of the slice with the most neutrino hits
174  *
175  * @return does the best slice pass the quality cuts for training?
176  */
177  bool GetBestMCSliceIndex(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses,
178  const SliceHypotheses &crSliceHypotheses, unsigned int &bestSliceIndex) const;
179 
180  /**
181  * @brief Determine if the event passes the selection cuts for training and has the required NUANCE code
182  *
183  * @param pAlgorithm address of the master algorithm
184  * @param purity purity of best slice
185  * @param completeness completeness of best slice
186  *
187  * @return does the evenr pass the quality cuts on purity and completeness and has the required NUANCE code
188  */
189  bool PassesQualityCuts(const pandora::Algorithm *const pAlgorithm, const float purity, const float completeness) const;
190 
191  /**
192  * @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
193  *
194  * @param pfos input list of pfos
195  * @param reconstructedCaloHitList output list of all 2d hits in the input pfos
196  * @param reconstructableCaloHitSet set of reconstructable calo hits
197  */
198  void Collect2DHits(const pandora::PfoList &pfos, pandora::CaloHitList &reconstructedCaloHitList,
199  const pandora::CaloHitSet &reconstructableCaloHitSet) const;
200 
201  /**
202  * @brief Count the number of neutrino induced hits in a given list using MC information
203  *
204  * @param caloHitSet input list of calo hits
205  *
206  * @return the number of neutrino induced hits in the input list
207  */
208  unsigned int CountNeutrinoInducedHits(const pandora::CaloHitList &caloHitList) const;
209 
210  /**
211  * @brief Use the current MCParticle list to get the nuance code of the neutrino in the event
212  *
213  * @param pAlgorithm address of the master algorithm
214  *
215  * @return the nuance code of the event
216  */
217  int GetNuanceCode(const pandora::Algorithm *const pAlgorithm) const;
218 
219  /**
220  * @brief Select all pfos under the same hypothesis
221  *
222  * @param pAlgorithm address of the master algorithm
223  * @param hypotheses the lists of slices under a certain hypothesis
224  * @param selectedPfos the list of pfos to populate
225  */
226  void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const;
227 
228  /**
229  * @brief Select pfos based on the probability that their slice contains a neutrino interaction
230  *
231  * @param pAlgorithm address of the master algorithm
232  * @param nuSliceHypotheses the input neutrino slice hypotheses
233  * @param crSliceHypotheses the input cosmic slice hypotheses
234  * @param sliceFeaturesVector vector holding the slice features
235  * @param selectedPfos the list of pfos to populate
236  */
237  void SelectPfosByProbability(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses,
238  const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const;
239 
240  /**
241  * @brief Add the given pfos to the selected Pfo list
242  *
243  * @param pfos the pfos to select
244  * @param selectedPfos the list of pfos to populate
245  */
246  void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const;
247 
248  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
249 
250  // Training
251  bool m_useTrainingMode; ///< Should use training mode. If true, training examples will be written to the output file
252  std::string m_trainingOutputFile; ///< Output file name for training examples
253  bool m_selectNuanceCode; ///< Should select training events by nuance code
254  int m_nuance; ///< Nuance code to select for training
255  float m_minPurity; ///< Minimum purity of the best slice to use event for training
256  float m_minCompleteness; ///< Minimum completeness of the best slice to use event for training
257 
258  // Classification
259  float m_minProbability; ///< Minimum probability required to classify a slice as the neutrino
260  unsigned int m_maxNeutrinos; ///< The maximum number of neutrinos to select in any one event
261 
262  T m_mva; ///< The mva
263  std::string m_filePathEnvironmentVariable; ///< The environment variable providing a list of paths to mva files
264 };
265 
268 
269 } // namespace lar_content
270 
271 #endif // #ifndef LAR_NEUTRINO_ID_TOOL_H
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:58
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.
bool IsFeatureVectorAvailable() const
Check if all features were calculable.
NeutrinoIdTool()
Default constructor.
std::string string
Definition: nybbler.cc:12
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.
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.
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
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.
void function(int client, int *resource, int parblock, int *test, int p)
NeutrinoIdTool< AdaBoostDecisionTree > BdtNeutrinoIdTool
NeutrinoIdTool< SupportVectorMachine > SvmNeutrinoIdTool
vertex reconstruction