LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
BdtBeamParticleIdTool.h
Go to the documentation of this file.
1 
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 
24 {
25 public:
30 
36  BdtBeamParticleIdTool(const BdtBeamParticleIdTool &rhs) = default;
37 
44 
48  ~BdtBeamParticleIdTool() = default;
49 
50  void SelectOutputPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &beamSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::PfoList &selectedPfos);
51 
52 private:
56  class Plane
57  {
58  public:
65  Plane(const pandora::CartesianVector &normal, const pandora::CartesianVector &point);
66 
73  pandora::CartesianVector GetLineIntersection(const pandora::CartesianVector &point, const pandora::CartesianVector &direction) const;
74 
75  private:
76  pandora::CartesianVector m_unitNormal;
77  pandora::CartesianVector m_point;
78  double m_d;
79  };
80 
81  typedef std::vector<Plane> PlaneVector;
82 
87  {
88  public:
93 
104  void Initialize(const float larTPCMinX, const float larTPCMaxX, const float larTPCMinY, const float larTPCMaxY, const float larTPCMinZ, const float larTPCMaxZ);
105 
111  void SetBeamLArTPCIntersection(const pandora::CartesianVector &beamLArTPCIntersection);
112 
118  void SetBeamDirection(const pandora::CartesianVector &beamDirection);
119 
125  void SetSelectedFraction(const float selectedFraction);
126 
132  void SetNSelectedHits(const unsigned int nSelectedHits);
133 
139  void SetContainmentLimit(const float containmentLimit);
140 
144  float GetLArTPCMinX() const;
145 
149  float GetLArTPCMaxX() const;
150 
154  float GetLArTPCMinY() const;
155 
159  float GetLArTPCMaxY() const;
160 
164  float GetLArTPCMinZ() const;
165 
169  float GetLArTPCMaxZ() const;
170 
174  const PlaneVector &GetPlanes() const;
175 
179  const pandora::CartesianVector &GetBeamLArTPCIntersection() const;
180 
184  const pandora::CartesianVector &GetBeamDirection() const;
185 
189  float GetSelectedFraction() const;
190 
194  unsigned int GetNSelectedHits() const;
195 
199  float GetContainmentLimit() const;
200 
201  private:
202  float m_larTPCMinX;
203  float m_larTPCMaxX;
204  float m_larTPCMinY;
205  float m_larTPCMaxY;
206  float m_larTPCMinZ;
207  float m_larTPCMaxZ;
208  PlaneVector m_larTPCPlanes;
209  pandora::CartesianVector m_beamLArTPCIntersection;
210  pandora::CartesianVector m_beamDirection;
212  unsigned int m_nSelectedHits;
214  };
215 
220  {
221  public:
229  SliceFeatures(const pandora::PfoList &nuPfos, const pandora::PfoList &crPfos, const SliceFeatureParameters &sliceFeatureParameters);
230 
236  SliceFeatures(const SliceFeatures &rhs) = default;
237 
243  SliceFeatures &operator=(const SliceFeatures &rhs) = default;
244 
248  ~SliceFeatures() = default;
249 
255  bool IsFeatureVectorAvailable() const;
256 
262  void FillFeatureVector(LArMvaHelper::MvaFeatureVector &featureVector) const;
263 
271  float GetAdaBoostDecisionTreeScore(const AdaBoostDecisionTree &adaBoostDecisionTree) const;
272 
273  private:
281  void GetLeadingCaloHits(const pandora::CaloHitList &inputCaloHitList, pandora::CaloHitList &outputCaloHitList,
282  double &closestHitToFaceDistance) const;
283 
292  void GetLArTPCIntercepts(const pandora::CartesianVector &a0, const pandora::CartesianVector &majorAxis,
293  pandora::CartesianVector &interceptOne, pandora::CartesianVector &interceptTwo) const;
294 
300  bool IsContained(const pandora::CartesianVector &spacePoint, const float limit) const;
301 
305  };
306 
307  typedef std::vector<SliceFeatures> SliceFeaturesVector;
308  typedef std::pair<unsigned int, float> UintFloatPair;
309  typedef std::unordered_map<const pandora::MCParticle*, int> MCParticleToIntMap;
310 
311  pandora::StatusCode Initialize();
312 
320  void GetSliceFeatures(const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const;
321 
329  void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const;
330 
337  void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const;
338 
347  void GetBestMCSliceIndices(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::IntVector &bestSliceIndices) const;
348 
355  void PopulateMCParticleToHitsMap(MCParticleToIntMap &mcParticleToIntMap, const pandora::CaloHitList &caloHitList) const;
356 
364  void Collect2DHits(const pandora::PfoList &pfos, pandora::CaloHitList &caloHitList, const pandora::CaloHitSet &reconstructableCaloHitSet) const;
365 
374  bool PassesQualityCuts(const float purity, const float completeness) const;
375 
385  void SelectPfosByAdaBDTScore(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const;
386 
387  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
388 
389  // Training
391  std::string m_trainingOutputFile;
392  std::string m_caloHitListName;
393  std::string m_mcParticleListName;
394  float m_minPurity;
396 
397  // Classification
400  unsigned int m_maxNeutrinos;
403 };
404 
405 //------------------------------------------------------------------------------------------------------------------------------------------
406 
407 inline void BdtBeamParticleIdTool::SliceFeatureParameters::SetBeamLArTPCIntersection(const pandora::CartesianVector &beamLArTPCIntersection)
408 {
409  m_beamLArTPCIntersection = beamLArTPCIntersection;
410 }
411 
412 //------------------------------------------------------------------------------------------------------------------------------------------
413 
414 inline void BdtBeamParticleIdTool::SliceFeatureParameters::SetBeamDirection(const pandora::CartesianVector &beamDirection)
415 {
416  m_beamDirection = beamDirection;
417 }
418 
419 //------------------------------------------------------------------------------------------------------------------------------------------
420 
422 {
423  m_selectedFraction = selectedFraction;
424 }
425 
426 //------------------------------------------------------------------------------------------------------------------------------------------
427 
428 inline void BdtBeamParticleIdTool::SliceFeatureParameters::SetNSelectedHits(const unsigned int nSelectedHits)
429 {
430  m_nSelectedHits = nSelectedHits;
431 }
432 
433 //------------------------------------------------------------------------------------------------------------------------------------------
434 
436 {
437  m_containmentLimit = containmentLimit;
438 }
439 
440 //------------------------------------------------------------------------------------------------------------------------------------------
441 
443 {
444  return m_larTPCMinX;
445 }
446 
447 //------------------------------------------------------------------------------------------------------------------------------------------
448 
450 {
451  return m_larTPCMaxX;
452 }
453 
454 //------------------------------------------------------------------------------------------------------------------------------------------
455 
457 {
458  return m_larTPCMinY;
459 }
460 
461 //------------------------------------------------------------------------------------------------------------------------------------------
462 
464 {
465  return m_larTPCMaxY;
466 }
467 
468 //------------------------------------------------------------------------------------------------------------------------------------------
469 
471 {
472  return m_larTPCMinZ;
473 }
474 
475 //------------------------------------------------------------------------------------------------------------------------------------------
476 
478 {
479  return m_larTPCMaxZ;
480 }
481 
482 //------------------------------------------------------------------------------------------------------------------------------------------
483 
485 {
486  return m_larTPCPlanes;
487 }
488 
489 //------------------------------------------------------------------------------------------------------------------------------------------
490 
492 {
493  return m_beamLArTPCIntersection;
494 }
495 
496 //------------------------------------------------------------------------------------------------------------------------------------------
497 
498 inline const pandora::CartesianVector &BdtBeamParticleIdTool::SliceFeatureParameters::GetBeamDirection() const
499 {
500  return m_beamDirection;
501 }
502 
503 //------------------------------------------------------------------------------------------------------------------------------------------
504 
506 {
507  return m_selectedFraction;
508 }
509 
510 //------------------------------------------------------------------------------------------------------------------------------------------
511 
513 {
514  return m_nSelectedHits;
515 }
516 
517 //------------------------------------------------------------------------------------------------------------------------------------------
518 
520 {
521  return m_containmentLimit;
522 }
523 
524 //------------------------------------------------------------------------------------------------------------------------------------------
525 
527 {
528  return m_isAvailable;
529 }
530 
531 } // namespace lar_content
532 
533 #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
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
BdtBeamParticleIdTool & operator=(const BdtBeamParticleIdTool &rhs)=default
Assignment operator.
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.
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.
std::unordered_map< const pandora::MCParticle *, int > MCParticleToIntMap
float m_larTPCMaxZ
Global LArTPC volume maximum z extent.
pandora::CartesianVector m_point
A point on the plane.
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.