LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrainedVertexSelectionAlgorithm.h
Go to the documentation of this file.
1 
8 #ifndef LAR_TRAINED_VERTEX_SELECTION_ALGORITHM_H
9 #define LAR_TRAINED_VERTEX_SELECTION_ALGORITHM_H 1
10 
11 #include "Api/PandoraContentApi.h"
12 
16 
18 
20 
21 #include <random>
22 
23 namespace lar_content
24 {
25 
26 template <typename, unsigned int>
27 class KDTreeLinkerAlgo;
28 template <typename, unsigned int>
29 class KDTreeNodeInfoT;
30 
31 //------------------------------------------------------------------------------------------------------------------------------------------
32 
37 {
38 public:
43  {
44  public:
57  VertexFeatureInfo(const float beamDeweighting, const float rPhiFeature, const float energyKick, const float localAsymmetry,
58  const float globalAsymmetry, const float showerAsymmetry, const float dEdxAsymmetry, const float vertexEnergy);
59 
61  float m_rPhiFeature;
62  float m_energyKick;
68  };
69 
70  typedef std::map<const pandora::Vertex *const, VertexFeatureInfo> VertexFeatureInfoMap;
71 
72  //--------------------------------------------------------------------------------------------------------------------------------------
73 
78  {
79  public:
86  VertexSharedFeatureInfo(const float separation, const float axisHits);
87 
88  float m_separation;
89  float m_axisHits;
90  };
91 
92  //--------------------------------------------------------------------------------------------------------------------------------------
93 
98  {
99  public:
111  EventFeatureInfo(const float eventShoweryness, const float eventEnergy, const float eventArea, const float longitudinality,
112  const unsigned int nHits, const unsigned int nClusters, const unsigned int nCandidates);
113 
116  float m_eventArea;
118  unsigned int m_nHits;
119  unsigned int m_nClusters;
120  unsigned int m_nCandidates;
121  };
122 
123  //--------------------------------------------------------------------------------------------------------------------------------------
124 
129 
130 protected:
131  typedef std::pair<pandora::CartesianVector, pandora::CartesianVector> ClusterEndPoints;
132  typedef std::map<const pandora::Cluster *const, ClusterEndPoints> ClusterEndPointsMap;
133  typedef std::vector<LArMvaHelper::MvaFeatureVector> FeatureListVector;
134  typedef std::vector<pandora::VertexVector> VectorOfVertexVectors;
135 
146  virtual void GetVertexScoreList(const pandora::VertexVector &vertexVector, const BeamConstants &beamConstants, HitKDTree2D &kdTreeU,
147  HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, VertexScoreList &vertexScoreList) const = 0;
148 
155  void CalculateShowerClusterList(const pandora::ClusterList &inputClusterList, ShowerClusterList &showerClusterList) const;
156 
165  const pandora::ClusterList &clusterList, pandora::ClusterList &showerLikeClusters, ClusterEndPointsMap &clusterEndPointsMap) const;
166 
169  typedef std::vector<HitKDNode2D> HitKDNode2DList;
170 
171  typedef std::unordered_map<const pandora::CaloHit *, const pandora::Cluster *> HitToClusterMap;
172 
180  void PopulateKdTree(const pandora::ClusterList &clusterList, HitKDTree2D &kdTree, HitToClusterMap &hitToClusterMap) const;
181 
192  bool AddClusterToShower(const ClusterEndPointsMap &clusterEndPointsMap, pandora::ClusterList &availableShowerLikeClusters,
193  const pandora::Cluster *const pCluster, pandora::ClusterList &showerCluster) const;
194 
206  bool AddClusterToShower(HitKDTree2D &kdTree, const HitToClusterMap &hitToClusterMap, pandora::ClusterList &availableShowerLikeClusters,
207  const pandora::Cluster *const pCluster, pandora::ClusterList &showerCluster) const;
208 
219  EventFeatureInfo CalculateEventFeatures(const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV,
220  const pandora::ClusterList &clusterListW, const pandora::VertexVector &vertexVector) const;
221 
230  void IncrementShoweryParameters(const pandora::ClusterList &clusterList, unsigned int &nShoweryHits, unsigned int &nHits, float &eventEnergy) const;
231 
239  bool IsClusterShowerLike(const pandora::Cluster *const pCluster) const;
240 
248  void GetLegacyEventShapeFeatures(const pandora::ClusterList &clusterList, float &eventVolume, float &longitudinality) const;
249 
257  void GetEventShapeFeatures(const ClusterListMap &clusterListMap, float &eventArea, float &longitudinality) const;
258 
266  void Get2DSpan(const pandora::ClusterList &clusterList, float &xSpan, float &zSpan) const;
267 
277  const float minPositionCoord, const float maxPositionCoord, pandora::InputFloat &minCoord, pandora::InputFloat &maxCoord) const;
278 
287  float GetCoordinateSpan(const pandora::InputFloat &minCoord, const pandora::InputFloat &maxCoord) const;
288 
295  void AddEventFeaturesToVector(const EventFeatureInfo &eventFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const;
296 
308  void PopulateVertexFeatureInfoMap(const BeamConstants &beamConstants, const ClusterListMap &clusterListMap,
309  const SlidingFitDataListMap &slidingFitDataListMap, const ShowerClusterListMap &showerClusterListMap, const KDTreeMap &kdTreeMap,
310  const pandora::Vertex *const pVertex, VertexFeatureInfoMap &vertexFeatureInfoMap) const;
311 
319  void PopulateInitialScoreList(VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pVertex, VertexScoreList &initialScoreList) const;
320 
327  void GetBestRegionVertices(VertexScoreList &initialScoreList, pandora::VertexVector &bestRegionVertices) const;
328 
338  void ProduceTrainingSets(const pandora::VertexVector &vertexVector, const pandora::VertexVector &bestRegionVertices,
339  VertexFeatureInfoMap &vertexFeatureInfoMap, const LArMvaHelper::MvaFeatureVector &eventFeatureList, const KDTreeMap &kdTreeMap) const;
340 
348  void CalculateRPhiScores(pandora::VertexVector &vertexVector, VertexFeatureInfoMap &vertexFeatureInfoMap, const KDTreeMap &kdTreeMap) const;
349 
355  std::string GetInteractionType() const;
356 
373  const pandora::Vertex *ProduceTrainingExamples(const pandora::VertexVector &vertexVector, const VertexFeatureInfoMap &vertexFeatureInfoMap,
374  std::bernoulli_distribution &coinFlip, std::mt19937 &generator, const std::string &interactionType, const std::string &trainingOutputFile,
375  const LArMvaHelper::MvaFeatureVector &eventFeatureList, const KDTreeMap &kdTreeMap, const float maxRadius, const bool useRPhi) const;
376 
384  void GetBestVertex(const pandora::VertexVector &vertexVector, const pandora::Vertex *&pBestVertex, float &bestVertexDr) const;
385 
395  void GetSharedFeatures(const pandora::Vertex *const pVertex1, const pandora::Vertex *const pVertex2, const KDTreeMap &kdTreeMap,
396  float &separation, float &axisHits) const;
397 
406  void IncrementSharedAxisValues(const pandora::CartesianVector pos1, const pandora::CartesianVector pos2, HitKDTree2D &kdTree, float &axisHits) const;
407 
419  bool IsHitInBox(const pandora::CartesianVector &hitPos, const pandora::CartesianVector &point1, const pandora::CartesianVector &point2,
420  const pandora::CartesianVector &point3, const pandora::CartesianVector &point4) const;
421 
429  void AddVertexFeaturesToVector(const VertexFeatureInfo &vertexFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector, const bool useRPhi) const;
430 
437  void AddSharedFeaturesToVector(const VertexSharedFeatureInfo &vertexSharedFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const;
438 
447  void PopulateFinalVertexScoreList(const VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pFavouriteVertex,
448  const pandora::VertexVector &vertexVector, VertexScoreList &finalVertexScoreList) const;
449 
450  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
451 
458  std::string m_mcParticleListName;
459  std::string m_caloHitListName;
460 
461  pandora::StringVector m_inputClusterListNames;
462  unsigned int m_minClusterCaloHits;
463  unsigned int m_slidingFitWindow;
465 
471 
473  unsigned int m_minShowerClusterHits;
483 };
484 
485 //------------------------------------------------------------------------------------------------------------------------------------------
486 
487 inline TrainedVertexSelectionAlgorithm::VertexFeatureInfo::VertexFeatureInfo(const float beamDeweighting, const float rPhiFeature, const float energyKick,
488  const float localAsymmetry, const float globalAsymmetry, const float showerAsymmetry, const float dEdxAsymmetry, const float vertexEnergy) :
489  m_beamDeweighting(beamDeweighting),
490  m_rPhiFeature(rPhiFeature),
491  m_energyKick(energyKick),
492  m_localAsymmetry(localAsymmetry),
493  m_globalAsymmetry(globalAsymmetry),
494  m_showerAsymmetry(showerAsymmetry),
495  m_dEdxAsymmetry(dEdxAsymmetry),
496  m_vertexEnergy(vertexEnergy)
497 {
498 }
499 
500 //------------------------------------------------------------------------------------------------------------------------------------------
501 
502 inline TrainedVertexSelectionAlgorithm::EventFeatureInfo::EventFeatureInfo(const float eventShoweryness, const float eventEnergy,
503  const float eventArea, const float longitudinality, const unsigned int nHits, const unsigned int nClusters, const unsigned int nCandidates) :
504  m_eventShoweryness(eventShoweryness),
505  m_eventEnergy(eventEnergy),
506  m_eventArea(eventArea),
507  m_longitudinality(longitudinality),
508  m_nHits(nHits),
509  m_nClusters(nClusters),
510  m_nCandidates(nCandidates)
511 {
512 }
513 
514 //------------------------------------------------------------------------------------------------------------------------------------------
515 
516 inline TrainedVertexSelectionAlgorithm::VertexSharedFeatureInfo::VertexSharedFeatureInfo(const float separation, const float axisHits) :
517  m_separation(separation),
518  m_axisHits(axisHits)
519 {
520 }
521 
522 } // namespace lar_content
523 
524 #endif // #ifndef LAR_TRAINED_VERTEX_SELECTION_ALGORITHM_H
void AddEventFeaturesToVector(const EventFeatureInfo &eventFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const
Add the event features to a vector in the correct order.
void GetLegacyEventShapeFeatures(const pandora::ClusterList &clusterList, float &eventVolume, float &longitudinality) const
Get the event shape features.
std::string m_trainingOutputFileVertex
The training output file for the vertex mva.
unsigned int m_nCandidates
The total number of vertex candidates.
bool m_useShowerClusteringApproximation
Whether to use the shower clustering distance approximation.
bool m_useRPhiFeatureForRegion
Whether to use the r/phi feature for the region vertex.
std::vector< pandora::VertexVector > VectorOfVertexVectors
void GetBestRegionVertices(VertexScoreList &initialScoreList, pandora::VertexVector &bestRegionVertices) const
Get the list of top-N separated vertices.
std::unordered_map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:75
unsigned int m_minClusterCaloHits
The min number of hits parameter in the energy score.
void PopulateInitialScoreList(VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pVertex, VertexScoreList &initialScoreList) const
Populate the initial vertex score list for a given vertex.
VertexFeatureTool::FeatureToolVector m_featureToolVector
The feature tool vector.
void PopulateFinalVertexScoreList(const VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pFavouriteVertex, const pandora::VertexVector &vertexVector, VertexScoreList &finalVertexScoreList) const
Populate the final vertex score list using the r/phi score to find the best vertex in the vicinity...
bool m_legacyEventShapes
Whether to use the old event shapes calculation.
KDTreeLinkerAlgo< const pandora::CaloHit *, 2 > HitKDTree2D
void AddVertexFeaturesToVector(const VertexFeatureInfo &vertexFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector, const bool useRPhi) const
Add the vertex features to a vector in the correct order.
void IncrementSharedAxisValues(const pandora::CartesianVector pos1, const pandora::CartesianVector pos2, HitKDTree2D &kdTree, float &axisHits) const
Increments the axis hits information for one view.
const pandora::Vertex * ProduceTrainingExamples(const pandora::VertexVector &vertexVector, const VertexFeatureInfoMap &vertexFeatureInfoMap, std::bernoulli_distribution &coinFlip, std::mt19937 &generator, const std::string &interactionType, const std::string &trainingOutputFile, const LArMvaHelper::MvaFeatureVector &eventFeatureList, const KDTreeMap &kdTreeMap, const float maxRadius, const bool useRPhi) const
Produce a set of training examples for a binary classifier.
bool IsClusterShowerLike(const pandora::Cluster *const pCluster) const
Find whether a cluster is shower-like.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void CalculateRPhiScores(pandora::VertexVector &vertexVector, VertexFeatureInfoMap &vertexFeatureInfoMap, const KDTreeMap &kdTreeMap) const
Calculate the r/phi scores for the vertices in a vector, possibly erasing those that fail the fast sc...
void Get2DSpan(const pandora::ClusterList &clusterList, float &xSpan, float &zSpan) const
Get the coordinate span in one view.
float m_localAsymmetryConstant
The local asymmetry constant for the initial region score list.
bool IsHitInBox(const pandora::CartesianVector &hitPos, const pandora::CartesianVector &point1, const pandora::CartesianVector &point2, const pandora::CartesianVector &point3, const pandora::CartesianVector &point4) const
Determines whether a hit lies within the box defined by four other positions.
unsigned int m_minShowerClusterHits
The minimum number of shower cluster hits.
Data stored in each KDTree node. The dim1/dim2 fields are usually the duplication of some PFRecHit va...
VertexSharedFeatureInfo(const float separation, const float axisHits)
Constructor.
void ProduceTrainingSets(const pandora::VertexVector &vertexVector, const pandora::VertexVector &bestRegionVertices, VertexFeatureInfoMap &vertexFeatureInfoMap, const LArMvaHelper::MvaFeatureVector &eventFeatureList, const KDTreeMap &kdTreeMap) const
Produce the region and vertex training sets.
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
std::string m_mcParticleListName
The MC particle list for creating training examples.
void PopulateVertexFeatureInfoMap(const BeamConstants &beamConstants, const ClusterListMap &clusterListMap, const SlidingFitDataListMap &slidingFitDataListMap, const ShowerClusterListMap &showerClusterListMap, const KDTreeMap &kdTreeMap, const pandora::Vertex *const pVertex, VertexFeatureInfoMap &vertexFeatureInfoMap) const
Populate the vertex feature info map for a given vertex.
Header file for the lar adaptive boosted decision tree class.
float m_globalAsymmetryConstant
The global asymmetry constant for the initial region score list.
Header file for the lar monte carlo particle helper helper class.
std::pair< pandora::CartesianVector, pandora::CartesianVector > ClusterEndPoints
Header file for the lar support vector machine class.
EventFeatureInfo CalculateEventFeatures(const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV, const pandora::ClusterList &clusterListW, const pandora::VertexVector &vertexVector) const
Calculate the event parameters.
float m_maxTrueVertexRadius
The maximum distance at which a vertex candidate can be considered the &#39;true&#39; vertex.
Header file for the lar two dimensional sliding fit result class.
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
Header file for the vertex selection base algorithm class.
float m_showerAsymmetryConstant
The shower asymmetry constant for the initial region score list.
std::vector< LArMvaHelper::MvaFeatureVector > FeatureListVector
void PopulateKdTree(const pandora::ClusterList &clusterList, HitKDTree2D &kdTree, HitToClusterMap &hitToClusterMap) const
Populate kd tree with information about hits in a provided list of clusters.
float m_beamDeweightingConstant
The beam deweighting constant for the initial region score list.
virtual void GetVertexScoreList(const pandora::VertexVector &vertexVector, const BeamConstants &beamConstants, HitKDTree2D &kdTreeU, HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, VertexScoreList &vertexScoreList) const =0
Get the vertex score list.
bool m_allowClassifyDuringTraining
Whether classification is allowed during training.
void CalculateShowerClusterList(const pandora::ClusterList &inputClusterList, ShowerClusterList &showerClusterList) const
Calculate the shower cluster map for a cluster list.
std::string m_trainingOutputFileRegion
The training output file for the region mva.
bool m_dropFailedRPhiFastScoreCandidates
Whether to drop candidates that fail the r/phi fast score test.
void AddSharedFeaturesToVector(const VertexSharedFeatureInfo &vertexSharedFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const
Add the shared features to a vector in the correct order.
float m_energyKickConstant
The energy kick constant for the initial region score list.
void GetSharedFeatures(const pandora::Vertex *const pVertex1, const pandora::Vertex *const pVertex2, const KDTreeMap &kdTreeMap, float &separation, float &axisHits) const
Calculates the shared features of a pair of vertex candidates.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
void UpdateSpanCoordinate(const float minPositionCoord, const float maxPositionCoord, pandora::InputFloat &minCoord, pandora::InputFloat &maxCoord) const
Update the min/max coordinate spans.
float m_mcVertexXCorrection
The correction to the x-coordinate of the MC vertex position.
std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
Definition: LArMvaHelper.h:36
void IncrementShoweryParameters(const pandora::ClusterList &clusterList, unsigned int &nShoweryHits, unsigned int &nHits, float &eventEnergy) const
Increment the showery hit parameters for a cluster list.
float GetCoordinateSpan(const pandora::InputFloat &minCoord, const pandora::InputFloat &maxCoord) const
Get the coordinate span.
bool m_legacyVariables
Whether to only use the old variables.
KDTreeNodeInfoT< const pandora::CaloHit *, 2 > HitKDNode2D
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
std::map< const pandora::Cluster *const, ClusterEndPoints > ClusterEndPointsMap
void GetEventShapeFeatures(const ClusterListMap &clusterListMap, float &eventArea, float &longitudinality) const
Get the event shape features.
std::string m_caloHitListName
The 2D CaloHit list name.
std::vector< art::Ptr< recob::Vertex > > VertexVector
bool AddClusterToShower(const ClusterEndPointsMap &clusterEndPointsMap, pandora::ClusterList &availableShowerLikeClusters, const pandora::Cluster *const pCluster, pandora::ClusterList &showerCluster) const
Try to add an available cluster to a given shower cluster, using shower clustering approximation...
float m_minShowerSpineLength
The minimum length at which all are considered to be tracks.
void GetShowerLikeClusterEndPoints(const pandora::ClusterList &clusterList, pandora::ClusterList &showerLikeClusters, ClusterEndPointsMap &clusterEndPointsMap) const
Add the endpoints of any shower-like clusters to the map.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
EventFeatureInfo(const float eventShoweryness, const float eventEnergy, const float eventArea, const float longitudinality, const unsigned int nHits, const unsigned int nClusters, const unsigned int nCandidates)
Constructor.
VertexFeatureInfo(const float beamDeweighting, const float rPhiFeature, const float energyKick, const float localAsymmetry, const float globalAsymmetry, const float showerAsymmetry, const float dEdxAsymmetry, const float vertexEnergy)
Constructor.
float m_showerClusteringDistance
The shower clustering distance.
float m_axisHits
The hit density along the axis between the two vertices.
pandora::StringVector m_inputClusterListNames
The list of cluster list names.
std::map< const pandora::Vertex *const, VertexFeatureInfo > VertexFeatureInfoMap
float m_rPhiFineTuningRadius
The maximum distance the r/phi tune can move a vertex.
void GetBestVertex(const pandora::VertexVector &vertexVector, const pandora::Vertex *&pBestVertex, float &bestVertexDr) const
Use the MC information to get the best vertex from a list.
std::string GetInteractionType() const
Get the interaction type string.