BdtBeamParticleIdTool.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArControlFlow/BdtBeamParticleIdTool.h
3  *
4  * @brief Header file for the beam particle id tool class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_BDT_BEAM_PARTICLE_ID_TOOL_H
9 #define LAR_BDT_BEAM_PARTICLE_ID_TOOL_H 1
10 
12 
14 
16 
17 namespace lar_content
18 {
19 
20 /**
21  * @brief BdtBeamParticleIdTool class
22  */
24 {
25 public:
26  /**
27  * @brief Constructor
28  */
30 
31  /**
32  * @brief Copy constructor
33  *
34  * @param BdtBeamParticleIdTool to copy
35  */
37 
38  /**
39  * @brief Assignment operator
40  *
41  * @param The BdtBeamParticleIdTool to assign
42  */
44 
45  /**
46  * @brief Destructor
47  */
48  ~BdtBeamParticleIdTool() = default;
49 
50  void SelectOutputPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &beamSliceHypotheses,
51  const SliceHypotheses &crSliceHypotheses, pandora::PfoList &selectedPfos);
52 
53 private:
54  /**
55  * @brief Plane class
56  */
57  class Plane
58  {
59  public:
60  /**
61  * @brief Constructor, using equation of plane: m_a*x + m_b*y + m_c*z + m_d = 0.
62  *
63  * @param normal a Cartesian vector that points in a direction that is normal to the plane
64  * @param point a Cartesian vector that corresponds to any point on the plane
65  */
66  Plane(const pandora::CartesianVector &normal, const pandora::CartesianVector &point);
67 
68  /**
69  * @brief Return the intersection between the plane and a line
70  *
71  * @param point a point on the line
72  * @param direction vector pointing along the line
73  */
74  pandora::CartesianVector GetLineIntersection(const pandora::CartesianVector &point, const pandora::CartesianVector &direction) const;
75 
76  private:
77  pandora::CartesianVector m_unitNormal; ///< Unit normal to plane
78  pandora::CartesianVector m_point; ///< A point on the plane
79  double m_d; ///< Parameter defining a plane
80  };
81 
82  typedef std::vector<Plane> PlaneVector;
83 
84  /**
85  * @brief SliceFeatureParameters class
86  */
88  {
89  public:
90  /**
91  * @brief Constructor
92  */
94 
95  /**
96  * @brief Set LArTPC geometry information
97  *
98  * @param larTPCMinX the global LArTPC volume minimum x extent
99  * @param larTPCMaxX the global LArTPC volume maximum x extent
100  * @param larTPCMinY the global LArTPC volume minimum y extent
101  * @param larTPCMaxY the global LArTPC volume maximum y extent
102  * @param larTPCMinZ the global LArTPC volume minimum z extent
103  * @param larTPCMaxZ the global LArTPC volume maximum z extent
104  */
105  void Initialize(const float larTPCMinX, const float larTPCMaxX, const float larTPCMinY, const float larTPCMaxY,
106  const float larTPCMinZ, const float larTPCMaxZ);
107 
108  /**
109  * @brief Set m_beamLArTPCIntersection
110  *
111  * @param beamLArTPCIntersection intersection of beam and TPC
112  */
113  void SetBeamLArTPCIntersection(const pandora::CartesianVector &beamLArTPCIntersection);
114 
115  /**
116  * @brief Set m_beamDirection
117  *
118  * @param beamDirection direction of beam
119  */
120  void SetBeamDirection(const pandora::CartesianVector &beamDirection);
121 
122  /**
123  * @brief Set m_selectedFraction
124  *
125  * @param selectedFraction fraction of hits to use in 3D cluster fits
126  */
127  void SetSelectedFraction(const float selectedFraction);
128 
129  /**
130  * @brief Set m_nSelectedHits
131  *
132  * @param nSelectedHits minimum number of hits to use in 3D cluster fits
133  */
134  void SetNSelectedHits(const unsigned int nSelectedHits);
135 
136  /**
137  * @brief Set m_containmentLimit
138  *
139  * @param containmentLimit limit used in is contained definition
140  */
141  void SetContainmentLimit(const float containmentLimit);
142 
143  /**
144  * @brief Get m_larTPCMinX
145  */
146  float GetLArTPCMinX() const;
147 
148  /**
149  * @brief Get m_larTPCMaxX
150  */
151  float GetLArTPCMaxX() const;
152 
153  /**
154  * @brief Get m_larTPCMinY
155  */
156  float GetLArTPCMinY() const;
157 
158  /**
159  * @brief Get m_larTPCMaxY
160  */
161  float GetLArTPCMaxY() const;
162 
163  /**
164  * @brief Get m_larTPCMinZ
165  */
166  float GetLArTPCMinZ() const;
167 
168  /**
169  * @brief Get m_larTPCMaxZ
170  */
171  float GetLArTPCMaxZ() const;
172 
173  /**
174  * @brief Get vector of planes
175  */
176  const PlaneVector &GetPlanes() const;
177 
178  /**
179  * @brief Get the beam LArTPC intersection
180  */
181  const pandora::CartesianVector &GetBeamLArTPCIntersection() const;
182 
183  /**
184  * @brief Get the beam direction
185  */
186  const pandora::CartesianVector &GetBeamDirection() const;
187 
188  /**
189  * @brief Get m_selectedFraction
190  */
191  float GetSelectedFraction() const;
192 
193  /**
194  * @brief Get m_nSelectedHits
195  */
196  unsigned int GetNSelectedHits() const;
197 
198  /**
199  * @brief Get m_containmentLimit
200  */
201  float GetContainmentLimit() const;
202 
203  private:
204  float m_larTPCMinX; ///< Global LArTPC volume minimum x extent
205  float m_larTPCMaxX; ///< Global LArTPC volume maximum x extent
206  float m_larTPCMinY; ///< Global LArTPC volume minimum y extent
207  float m_larTPCMaxY; ///< Global LArTPC volume maximum y extent
208  float m_larTPCMinZ; ///< Global LArTPC volume minimum z extent
209  float m_larTPCMaxZ; ///< Global LArTPC volume maximum z extent
210  PlaneVector m_larTPCPlanes; ///< Vector of all planes making up global LArTPC volume
211  pandora::CartesianVector m_beamLArTPCIntersection; ///< Intersection of beam and global LArTPC volume
212  pandora::CartesianVector m_beamDirection; ///< Beam direction
213  float m_selectedFraction; ///< Fraction of hits to use in 3D cluster fits
214  unsigned int m_nSelectedHits; ///< Minimum number of hits to use in 3D cluster fits
215  float m_containmentLimit; ///< Limit applied in is contained definition
216  };
217 
218  /**
219  * @brief Slice features class
220  */
222  {
223  public:
224  /**
225  * @brief Constructor
226  *
227  * @param nuPfos input list of Pfos reconstructed under the neutrino hypothesis
228  * @param crPfos input list of Pfos reconstructed under the cosmic ray hypothesis
229  * @param geometryInfo geometry information block
230  */
231  SliceFeatures(const pandora::PfoList &nuPfos, const pandora::PfoList &crPfos, const SliceFeatureParameters &sliceFeatureParameters);
232 
233  /**
234  * @brief Copy constructor
235  *
236  * @param The SliceFeatures to copy
237  */
238  SliceFeatures(const SliceFeatures &) = default;
239 
240  /**
241  * @brief Destructor
242  */
243  ~SliceFeatures() = default;
244 
245  /**
246  * @brief Check if all features were calculable
247  *
248  * @return true if the feature vector is available
249  */
250  bool IsFeatureVectorAvailable() const;
251 
252  /**
253  * @brief Get the feature vector for the SVM
254  *
255  * @param featuresVector empty feature vector to populate
256  */
257  void FillFeatureVector(LArMvaHelper::MvaFeatureVector &featureVector) const;
258 
259  /**
260  * @brief Get the probability that this slice contains a beam particle
261  *
262  * @param adaBoostDecisionTree the adaptive boost decision tree used to calculate the probability
263  *
264  * @return the probability that the slice contains a beam particle
265  */
266  float GetAdaBoostDecisionTreeScore(const AdaBoostDecisionTree &adaBoostDecisionTree) const;
267 
268  private:
269  /**
270  * @brief Select a given fraction of a slice's calo hits that are closest to the beam spot
271  *
272  * @param inputCaloHitList all calo hits in slice
273  * @param outputCaloHitList to receive the list of selected calo hits
274  * @param closestHitToFaceDistance to receive the distance of closest hit to beam spot
275  */
276  void GetLeadingCaloHits(
277  const pandora::CaloHitList &inputCaloHitList, pandora::CaloHitList &outputCaloHitList, double &closestHitToFaceDistance) const;
278 
279  /**
280  * @brief Find the intercepts of a line with the protoDUNE detector
281  *
282  * @param a0 a point on the line in question
283  * @param majorAxis the direction of the line in question
284  * @param interceptOne to receive the first intersection between line and protoDUNE detector
285  * @param interceptTwo to receive the second intersection between line and protoDUNE detector
286  */
287  void GetLArTPCIntercepts(const pandora::CartesianVector &a0, const pandora::CartesianVector &majorAxis,
288  pandora::CartesianVector &interceptOne, pandora::CartesianVector &interceptTwo) const;
289 
290  /**
291  * @brief Check if a given 3D spacepoint is inside the global LArTPC volume
292  *
293  * @param spacePoint
294  */
295  bool IsContained(const pandora::CartesianVector &spacePoint, const float limit) const;
296 
297  bool m_isAvailable; ///< Is the feature vector available
298  const SliceFeatureParameters m_sliceFeatureParameters; ///< Geometry information block
299  LArMvaHelper::MvaFeatureVector m_featureVector; ///< The MVA feature vector
300  };
301 
302  typedef std::vector<SliceFeatures> SliceFeaturesVector;
303  typedef std::pair<unsigned int, float> UintFloatPair;
304  typedef std::unordered_map<const pandora::MCParticle *, int> MCParticleToIntMap;
305 
306  pandora::StatusCode Initialize();
307 
308  /**
309  * @brief Get the features of each slice
310  *
311  * @param nuSliceHypotheses the input neutrino slice hypotheses
312  * @param crSliceHypotheses the input cosmic slice hypotheses
313  * @param sliceFeaturesVector vector to hold the slice features
314  */
315  void GetSliceFeatures(
316  const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const;
317 
318  /**
319  * @brief Select all pfos under the same hypothesis
320  *
321  * @param pAlgorithm address of the master algorithm
322  * @param hypotheses the lists of slices under a certain hypothesis
323  * @param selectedPfos the list of pfos to populate
324  */
325  void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const;
326 
327  /**
328  * @brief Add the given pfos to the selected Pfo list
329  *
330  * @param pfos the pfos to select
331  * @param selectedPfos the list of pfos to populate
332  */
333  void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const;
334 
335  /**
336  * @brief Get the slice with the most neutrino induced hits using Monte-Carlo information
337  *
338  * @param pAlgorithm address of the master algorithm
339  * @param nuSliceHypotheses the input neutrino slice hypotheses
340  * @param crSliceHypotheses the input cosmic slice hypotheses
341  * @param bestSliceIndices vector of slice indices passing quality cuts
342  */
343  void GetBestMCSliceIndices(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses,
344  const SliceHypotheses &crSliceHypotheses, pandora::IntVector &bestSliceIndices) const;
345 
346  /**
347  * @brief Fill mc particle to nHits map from calo hit list
348  *
349  * @param mcParticleToIntMap map to fill
350  * @param caloHitList the input calo hits
351  */
352  void PopulateMCParticleToHitsMap(MCParticleToIntMap &mcParticleToIntMap, const pandora::CaloHitList &caloHitList) const;
353 
354  /**
355  * @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
356  *
357  * @param pfos input list of pfos
358  * @param caloHitList output list of all 2d hits in the input pfos
359  * @param reconstructableCaloHitSet to check if part of before adding
360  */
361  void Collect2DHits(const pandora::PfoList &pfos, pandora::CaloHitList &caloHitList, const pandora::CaloHitSet &reconstructableCaloHitSet) const;
362 
363  /**
364  * @brief Determine if the event passes the selection cuts for training
365  *
366  * @param purity purity of best slice
367  * @param completeness completeness of best slice
368  *
369  * @return does the evenr pass the quality cuts on purity and completeness
370  */
371  bool PassesQualityCuts(const float purity, const float completeness) const;
372 
373  /**
374  * @brief Select pfos based on the AdaBDT score that the slice contains a beam particle interaction
375  *
376  * @param pAlgorithm address of the master algorithm
377  * @param nuSliceHypotheses the input neutrino slice hypotheses
378  * @param crSliceHypotheses the input cosmic slice hypotheses
379  * @param sliceFeaturesVector vector holding the slice features
380  * @param selectedPfos the list of pfos to populate
381  */
382  void SelectPfosByAdaBDTScore(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses,
383  const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const;
384 
385  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
386 
387  // Training
388  bool m_useTrainingMode; ///< Should use training mode. If true, training examples will be written to the output file
389  std::string m_trainingOutputFile; ///< Output file name for training examples
390  std::string m_caloHitListName; ///< Name of input calo hit list
391  std::string m_mcParticleListName; ///< Name of input MC particle list
392  float m_minPurity; ///< Minimum purity of the best slice to use event for training
393  float m_minCompleteness; ///< Minimum completeness of the best slice to use event for training
394 
395  // Classification
396  AdaBoostDecisionTree m_adaBoostDecisionTree; ///< The adaptive boost decision tree
397  std::string m_filePathEnvironmentVariable; ///< The environment variable providing a list of paths to bdt files
398  unsigned int m_maxNeutrinos; ///< The maximum number of neutrinos to select in any one event
399  float m_minAdaBDTScore; ///< Minimum score required to classify a slice as a beam particle
400  SliceFeatureParameters m_sliceFeatureParameters; ///< Geometry information block
401 };
402 
403 //------------------------------------------------------------------------------------------------------------------------------------------
404 
405 inline void BdtBeamParticleIdTool::SliceFeatureParameters::SetBeamLArTPCIntersection(const pandora::CartesianVector &beamLArTPCIntersection)
406 {
407  m_beamLArTPCIntersection = beamLArTPCIntersection;
408 }
409 
410 //------------------------------------------------------------------------------------------------------------------------------------------
411 
412 inline void BdtBeamParticleIdTool::SliceFeatureParameters::SetBeamDirection(const pandora::CartesianVector &beamDirection)
413 {
414  m_beamDirection = beamDirection;
415 }
416 
417 //------------------------------------------------------------------------------------------------------------------------------------------
418 
420 {
421  m_selectedFraction = selectedFraction;
422 }
423 
424 //------------------------------------------------------------------------------------------------------------------------------------------
425 
426 inline void BdtBeamParticleIdTool::SliceFeatureParameters::SetNSelectedHits(const unsigned int nSelectedHits)
427 {
428  m_nSelectedHits = nSelectedHits;
429 }
430 
431 //------------------------------------------------------------------------------------------------------------------------------------------
432 
434 {
435  m_containmentLimit = containmentLimit;
436 }
437 
438 //------------------------------------------------------------------------------------------------------------------------------------------
439 
441 {
442  return m_larTPCMinX;
443 }
444 
445 //------------------------------------------------------------------------------------------------------------------------------------------
446 
448 {
449  return m_larTPCMaxX;
450 }
451 
452 //------------------------------------------------------------------------------------------------------------------------------------------
453 
455 {
456  return m_larTPCMinY;
457 }
458 
459 //------------------------------------------------------------------------------------------------------------------------------------------
460 
462 {
463  return m_larTPCMaxY;
464 }
465 
466 //------------------------------------------------------------------------------------------------------------------------------------------
467 
469 {
470  return m_larTPCMinZ;
471 }
472 
473 //------------------------------------------------------------------------------------------------------------------------------------------
474 
476 {
477  return m_larTPCMaxZ;
478 }
479 
480 //------------------------------------------------------------------------------------------------------------------------------------------
481 
483 {
484  return m_larTPCPlanes;
485 }
486 
487 //------------------------------------------------------------------------------------------------------------------------------------------
488 
490 {
491  return m_beamLArTPCIntersection;
492 }
493 
494 //------------------------------------------------------------------------------------------------------------------------------------------
495 
496 inline const pandora::CartesianVector &BdtBeamParticleIdTool::SliceFeatureParameters::GetBeamDirection() const
497 {
498  return m_beamDirection;
499 }
500 
501 //------------------------------------------------------------------------------------------------------------------------------------------
502 
504 {
505  return m_selectedFraction;
506 }
507 
508 //------------------------------------------------------------------------------------------------------------------------------------------
509 
511 {
512  return m_nSelectedHits;
513 }
514 
515 //------------------------------------------------------------------------------------------------------------------------------------------
516 
518 {
519  return m_containmentLimit;
520 }
521 
522 //------------------------------------------------------------------------------------------------------------------------------------------
523 
525 {
526  return m_isAvailable;
527 }
528 
529 } // namespace lar_content
530 
531 #endif // #ifndef LAR_BDT_BEAM_PARTICLE_ID_TOOL_H
void SetBeamLArTPCIntersection(const pandora::CartesianVector &beamLArTPCIntersection)
Set m_beamLArTPCIntersection.
double m_d
Parameter defining a plane.
const SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to bdt files.
std::string m_mcParticleListName
Name of input MC particle list.
float m_larTPCMinY
Global LArTPC volume minimum y extent.
Plane(const pandora::CartesianVector &normal, const pandora::CartesianVector &point)
Constructor, using equation of plane: m_a*x + m_b*y + m_c*z + m_d = 0.
float m_minAdaBDTScore
Minimum score required to classify a slice as a beam particle.
float m_larTPCMaxX
Global LArTPC volume maximum x extent.
unsigned int GetNSelectedHits() const
Get m_nSelectedHits.
pandora::CartesianVector GetLineIntersection(const pandora::CartesianVector &point, const pandora::CartesianVector &direction) const
Return the intersection between the plane and a line.
#define a0
std::string string
Definition: nybbler.cc:12
PlaneVector m_larTPCPlanes
Vector of all planes making up global LArTPC volume.
unsigned int m_nSelectedHits
Minimum number of hits to use in 3D cluster fits.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
void SelectPfosByAdaBDTScore(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const
Select pfos based on the AdaBDT score that the slice contains a beam particle interaction.
float m_selectedFraction
Fraction of hits to use in 3D cluster fits.
std::vector< SliceFeatures > SliceFeaturesVector
void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const
Select all pfos under the same hypothesis.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::vector< int > IntVector
bool IsFeatureVectorAvailable() const
Check if all features were calculable.
float m_larTPCMaxY
Global LArTPC volume maximum y extent.
bool m_isAvailable
Is the feature vector available.
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
bool PassesQualityCuts(const float purity, const float completeness) const
Determine if the event passes the selection cuts for training.
void SetBeamDirection(const pandora::CartesianVector &beamDirection)
Set m_beamDirection.
void SetNSelectedHits(const unsigned int nSelectedHits)
Set m_nSelectedHits.
const pandora::CartesianVector & GetBeamDirection() const
Get the beam direction.
Header file for the master algorithm class.
Header file for the lar adaptive boosted decision tree class.
std::string m_trainingOutputFile
Output file name for training examples.
void SetSelectedFraction(const float selectedFraction)
Set m_selectedFraction.
pandora::CartesianVector m_beamDirection
Beam direction.
float m_minPurity
Minimum purity of the best slice to use event for training.
std::vector< pandora::PfoList > SliceHypotheses
void Collect2DHits(const pandora::PfoList &pfos, pandora::CaloHitList &caloHitList, const pandora::CaloHitSet &reconstructableCaloHitSet) const
Collect all 2D hits in a supplied list of Pfos and push them on to an existing hit list...
void GetBestMCSliceIndices(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::IntVector &bestSliceIndices) const
Get the slice with the most neutrino induced hits using Monte-Carlo information.
LArMvaHelper::MvaFeatureVector m_featureVector
The MVA feature vector.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
void PopulateMCParticleToHitsMap(MCParticleToIntMap &mcParticleToIntMap, const pandora::CaloHitList &caloHitList) const
Fill mc particle to nHits map from calo hit list.
BdtBeamParticleIdTool & operator=(const BdtBeamParticleIdTool &)=default
Assignment operator.
const pandora::CartesianVector & GetBeamLArTPCIntersection() const
Get the beam LArTPC intersection.
pandora::CartesianVector m_unitNormal
Unit normal to plane.
~BdtBeamParticleIdTool()=default
Destructor.
float m_containmentLimit
Limit applied in is contained definition.
void SetContainmentLimit(const float containmentLimit)
Set m_containmentLimit.
const PlaneVector & GetPlanes() const
Get vector of planes.
void GetSliceFeatures(const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const
Get the features of each slice.
float m_larTPCMinX
Global LArTPC volume minimum x extent.
SliceIdBaseTool class.
float m_larTPCMaxZ
Global LArTPC volume maximum z extent.
pandora::CartesianVector m_point
A point on the plane.
std::unordered_map< const pandora::MCParticle *, int > MCParticleToIntMap
void SelectOutputPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &beamSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::PfoList &selectedPfos)
Select which reconstruction hypotheses to use; neutrino outcomes or cosmic-ray muon outcomes for each...
BdtBeamParticleIdTool class.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
std::string m_caloHitListName
Name of input calo hit list.
std::pair< unsigned int, float > UintFloatPair
pandora::CartesianVector m_beamLArTPCIntersection
Intersection of beam and global LArTPC volume.
float m_larTPCMinZ
Global LArTPC volume minimum z extent.
AdaBoostDecisionTree m_adaBoostDecisionTree
The adaptive boost decision tree.
SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.