LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
SvmVertexSelectionAlgorithm.h
Go to the documentation of this file.
1 
8 #ifndef LAR_SVM_VERTEX_SELECTION_ALGORITHM_H
9 #define LAR_SVM_VERTEX_SELECTION_ALGORITHM_H 1
10 
11 #include "Api/PandoraContentApi.h"
12 
15 
17 
19 
20 #include <random>
21 
22 namespace lar_content
23 {
24 
25 template<typename, unsigned int> class KDTreeLinkerAlgo;
26 template<typename, unsigned int> class KDTreeNodeInfoT;
27 
28 //------------------------------------------------------------------------------------------------------------------------------------------
29 
34 {
35 public:
40  {
41  public:
52  VertexFeatureInfo(const float beamDeweighting, const float rPhiFeature, const float energyKick, const float localAsymmetry,
53  const float globalAsymmetry, const float showerAsymmetry);
54 
56  float m_rPhiFeature;
57  float m_energyKick;
61  };
62 
63  typedef std::map<const pandora::Vertex *const, VertexFeatureInfo> VertexFeatureInfoMap;
64 
65  //--------------------------------------------------------------------------------------------------------------------------------------
66 
71  {
72  public:
84  EventFeatureInfo(const float eventShoweryness, const float eventEnergy, const float eventVolume, const float longitudinality,
85  const unsigned int nHits, const unsigned int nClusters, const unsigned int nCandidates);
86 
88  float m_eventEnergy;
89  float m_eventVolume;
91  unsigned int m_nHits;
92  unsigned int m_nClusters;
93  unsigned int m_nCandidates;
94  };
95 
96  //--------------------------------------------------------------------------------------------------------------------------------------
97 
102 
103 protected:
104  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
105 
106 private:
107  typedef std::pair<pandora::CartesianVector, pandora::CartesianVector> ClusterEndPoints;
108  typedef std::map<const pandora::Cluster *const, ClusterEndPoints> ClusterEndPointsMap;
109  typedef std::vector<LArMvaHelper::MvaFeatureVector> FeatureListVector;
110  typedef std::vector<pandora::VertexVector> VectorOfVertexVectors;
111 
122  void GetVertexScoreList(const pandora::VertexVector &vertexVector, const BeamConstants &beamConstants, HitKDTree2D &kdTreeU,
123  HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, VertexScoreList &vertexScoreList) const;
124 
131  void CalculateShowerClusterList(const pandora::ClusterList &inputClusterList, ShowerClusterList &showerClusterList) const;
132 
140  void GetShowerLikeClusterEndPoints(const pandora::ClusterList &clusterList, pandora::ClusterList &showerLikeClusters,
141  ClusterEndPointsMap &clusterEndPointsMap) const;
142 
145  typedef std::vector<HitKDNode2D> HitKDNode2DList;
146 
147  typedef std::unordered_map<const pandora::CaloHit*, const pandora::Cluster*> HitToClusterMap;
148 
156  void PopulateKdTree(const pandora::ClusterList &clusterList, HitKDTree2D &kdTree, HitToClusterMap &hitToClusterMap) const;
157 
168  bool AddClusterToShower(const ClusterEndPointsMap &clusterEndPointsMap, pandora::ClusterList &availableShowerLikeClusters,
169  const pandora::Cluster *const pCluster, pandora::ClusterList &showerCluster) const;
170 
182  bool AddClusterToShower(HitKDTree2D &kdTree, const HitToClusterMap &hitToClusterMap, pandora::ClusterList &availableShowerLikeClusters,
183  const pandora::Cluster *const pCluster, pandora::ClusterList &showerCluster) const;
184 
195  EventFeatureInfo CalculateEventFeatures(const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV,
196  const pandora::ClusterList &clusterListW, const pandora::VertexVector &vertexVector) const;
197 
206  void IncrementShoweryParameters(const pandora::ClusterList &clusterList, unsigned int &nShoweryHits, unsigned int &nHits,
207  float &eventEnergy) const;
208 
216  bool IsClusterShowerLike(const pandora::Cluster *const pCluster) const;
217 
225  void GetEventShapeFeatures(const pandora::ClusterList &clusterList, float &eventVolume, float &longitudinality) const;
226 
235  void UpdateSpanCoordinate(const float minPositionCoord, const float maxPositionCoord, pandora::InputFloat &minCoord,
236  pandora::InputFloat &maxCoord) const;
237 
246  float GetCoordinateSpan(const pandora::InputFloat &minCoord, const pandora::InputFloat &maxCoord) const;
247 
254  void AddEventFeaturesToVector(const EventFeatureInfo &eventFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const;
255 
267  void PopulateVertexFeatureInfoMap(const BeamConstants &beamConstants, const ClusterListMap &clusterListMap,
268  const SlidingFitDataListMap &slidingFitDataListMap, const ShowerClusterListMap &showerClusterListMap, const KDTreeMap &kdTreeMap,
269  const pandora::Vertex *const pVertex, VertexFeatureInfoMap &vertexFeatureInfoMap) const;
270 
278  void PopulateInitialScoreList(VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pVertex,
279  VertexScoreList &initialScoreList) const;
280 
287  void GetBestRegionVertices(VertexScoreList &initialScoreList, pandora::VertexVector &bestRegionVertices) const;
288 
298  void ProduceTrainingSets(const pandora::VertexVector &vertexVector, const pandora::VertexVector &bestRegionVertices,
299  VertexFeatureInfoMap &vertexFeatureInfoMap, const LArMvaHelper::MvaFeatureVector &eventFeatureList,const KDTreeMap &kdTreeMap) const;
300 
308  void CalculateRPhiScores(pandora::VertexVector &vertexVector, VertexFeatureInfoMap &vertexFeatureInfoMap, const KDTreeMap &kdTreeMap) const;
309 
315  std::string GetInteractionType() const;
316 
332  const pandora::Vertex * ProduceTrainingExamples(const pandora::VertexVector &vertexVector, const VertexFeatureInfoMap &vertexFeatureInfoMap,
333  std::bernoulli_distribution &coinFlip, std::mt19937 &generator, const std::string &interactionType, const std::string &trainingOutputFile,
334  const LArMvaHelper::MvaFeatureVector &eventFeatureList, const float maxRadius, const bool useRPhi) const;
335 
343  void GetBestVertex(const pandora::VertexVector &vertexVector, const pandora::Vertex *&pBestVertex, float &bestVertexDr) const;
344 
352  void AddVertexFeaturesToVector(const VertexFeatureInfo &vertexFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector, const bool useRPhi) const;
353 
365  const pandora::Vertex * CompareVertices(const pandora::VertexVector &vertexVector, const VertexFeatureInfoMap &vertexFeatureInfoMap,
366  const LArMvaHelper::MvaFeatureVector &eventFeatureList, const SupportVectorMachine &supportVectorMachine, const bool useRPhi) const;
367 
376  void PopulateFinalVertexScoreList(const VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pFavouriteVertex,
377  const pandora::VertexVector &vertexVector, VertexScoreList &finalVertexScoreList) const;
378 
381  std::string m_svmFileName;
382  std::string m_regionSvmName;
383  std::string m_vertexSvmName;
386 
392  std::string m_mcParticleListName;
393  std::string m_caloHitListName;
394 
395  pandora::StringVector m_inputClusterListNames;
396  unsigned int m_minClusterCaloHits;
397  unsigned int m_slidingFitWindow;
399 
405 
407  unsigned int m_minShowerClusterHits;
414 };
415 
416 //------------------------------------------------------------------------------------------------------------------------------------------
417 
418 inline SvmVertexSelectionAlgorithm::VertexFeatureInfo::VertexFeatureInfo(const float beamDeweighting, const float rPhiFeature, const float energyKick,
419  const float localAsymmetry, const float globalAsymmetry, const float showerAsymmetry) :
420  m_beamDeweighting(beamDeweighting),
421  m_rPhiFeature(rPhiFeature),
422  m_energyKick(energyKick),
423  m_localAsymmetry(localAsymmetry),
424  m_globalAsymmetry(globalAsymmetry),
425  m_showerAsymmetry(showerAsymmetry)
426 {
427 }
428 
429 //------------------------------------------------------------------------------------------------------------------------------------------
430 
431 inline SvmVertexSelectionAlgorithm::EventFeatureInfo::EventFeatureInfo(const float eventShoweryness, const float eventEnergy,
432  const float eventVolume, const float longitudinality, const unsigned int nHits, const unsigned int nClusters, const unsigned int nCandidates) :
433  m_eventShoweryness(eventShoweryness),
434  m_eventEnergy(eventEnergy),
435  m_eventVolume(eventVolume),
436  m_longitudinality(longitudinality),
437  m_nHits(nHits),
438  m_nClusters(nClusters),
439  m_nCandidates(nCandidates)
440 {
441 }
442 
443 } // namespace lar_content
444 
445 #endif // #ifndef LAR_SVM_VERTEX_SELECTION_ALGORITHM_H
std::string m_vertexSvmName
The name of the vertex Svm to find.
std::map< const pandora::Vertex *const, VertexFeatureInfo > VertexFeatureInfoMap
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...
void GetBestRegionVertices(VertexScoreList &initialScoreList, pandora::VertexVector &bestRegionVertices) const
Get the list of top-N separated vertices.
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
unsigned int m_nCandidates
The total number of vertex candidates.
void IncrementShoweryParameters(const pandora::ClusterList &clusterList, unsigned int &nShoweryHits, unsigned int &nHits, float &eventEnergy) const
Increment the showery hit parameters for a cluster list.
unsigned int m_minShowerClusterHits
The minimum number of shower cluster hits.
std::vector< LArMvaHelper::MvaFeatureVector > FeatureListVector
float m_globalAsymmetryConstant
The global asymmetry constant for the initial region score list.
Class that implements the KDTree partition of 2D space and a closest point search algorithm...
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...
std::unordered_map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
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 float maxRadius, const bool useRPhi) const
Produce a set of training examples for a binary classifier.
void GetVertexScoreList(const pandora::VertexVector &vertexVector, const BeamConstants &beamConstants, HitKDTree2D &kdTreeU, HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, VertexScoreList &vertexScoreList) const
Get the vertex score list.
bool m_dropFailedRPhiFastScoreCandidates
Whether to drop candidates that fail the r/phi fast score test.
float GetCoordinateSpan(const pandora::InputFloat &minCoord, const pandora::InputFloat &maxCoord) const
Get the coordinate span.
float m_maxTrueVertexRadius
The maximum distance at which a vertex candidate can be considered the &#39;true&#39; vertex.
float m_showerAsymmetryConstant
The shower asymmetry constant for the initial region score list.
bool m_allowClassifyDuringTraining
Whether classification is allowed during training.
VertexFeatureInfo(const float beamDeweighting, const float rPhiFeature, const float energyKick, const float localAsymmetry, const float globalAsymmetry, const float showerAsymmetry)
Constructor.
KDTreeNodeInfoT< const pandora::CaloHit *, 2 > HitKDNode2D
bool IsClusterShowerLike(const pandora::Cluster *const pCluster) const
Find whether a cluster is shower-like.
Data stored in each KDTree node. The dim1/dim2 fields are usually the duplication of some PFRecHit va...
float m_localAsymmetryConstant
The local asymmetry constant for the initial region score list.
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.
float m_regionRadius
The radius for a vertex region.
std::map< const pandora::Cluster *const, ClusterEndPoints > ClusterEndPointsMap
std::string GetInteractionType() const
Get the interaction type string.
std::pair< pandora::CartesianVector, pandora::CartesianVector > ClusterEndPoints
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
void GetEventShapeFeatures(const pandora::ClusterList &clusterList, float &eventVolume, float &longitudinality) const
Get the event shape features.
Header file for the lar monte carlo particle helper helper class.
Header file for the lar support vector machine class.
bool m_useRPhiFeatureForRegion
Whether to use the r/phi feature for the region vertex.
KDTreeLinkerAlgo< const pandora::CaloHit *, 2 > HitKDTree2D
SupportVectorMachine m_svMachineVertex
The vertex support vector machine.
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.
EventFeatureInfo(const float eventShoweryness, const float eventEnergy, const float eventVolume, const float longitudinality, const unsigned int nHits, const unsigned int nClusters, const unsigned int nCandidates)
Constructor.
SupportVectorMachine m_svMachineRegion
The region support vector machine.
float m_minShowerSpineLength
The minimum length at which all are considered to be tracks.
Header file for the vertex selection base algorithm class.
std::string m_mcParticleListName
The MC particle list for creating training examples.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
float m_mcVertexXCorrection
The correction to the x-coordinate of the MC vertex position.
float m_energyKickConstant
The energy kick constant for the initial region score list.
void PopulateInitialScoreList(VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pVertex, VertexScoreList &initialScoreList) const
Populate the initial vertex score list for a given vertex.
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to svm files.
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.
void AddEventFeaturesToVector(const EventFeatureInfo &eventFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const
Add the event features to a vector in the correct order.
std::string m_caloHitListName
The 2D CaloHit list name.
float m_showerClusteringDistance
The shower clustering distance.
void AddVertexFeaturesToVector(const VertexFeatureInfo &vertexFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector, const bool useRPhi) const
Add the vertex features to a vector in the correct order.
std::string m_trainingOutputFileVertex
The training output file for the vertex Svm.
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.
bool m_useShowerClusteringApproximation
Whether to use the shower clustering distance approximation.
float m_beamDeweightingConstant
The beam deweighting constant for the initial region score list.
const pandora::Vertex * CompareVertices(const pandora::VertexVector &vertexVector, const VertexFeatureInfoMap &vertexFeatureInfoMap, const LArMvaHelper::MvaFeatureVector &eventFeatureList, const SupportVectorMachine &supportVectorMachine, const bool useRPhi) const
Used a binary classifier to compare a set of vertices and pick the best one.
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...
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
Definition: LArMvaHelper.h:30
void PopulateKdTree(const pandora::ClusterList &clusterList, HitKDTree2D &kdTree, HitToClusterMap &hitToClusterMap) const
Populate kd tree with information about hits in a provided list of clusters.
std::string m_trainingOutputFileRegion
The training output file for the region Svm.
void UpdateSpanCoordinate(const float minPositionCoord, const float maxPositionCoord, pandora::InputFloat &minCoord, pandora::InputFloat &maxCoord) const
Update the min/max coordinate spans.
std::string m_regionSvmName
The name of the region Svm to find.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
VertexFeatureTool::FeatureToolVector m_featureToolVector
The feature tool vector.
void CalculateShowerClusterList(const pandora::ClusterList &inputClusterList, ShowerClusterList &showerClusterList) const
Calculate the shower cluster map for a cluster list.
EventFeatureInfo CalculateEventFeatures(const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV, const pandora::ClusterList &clusterListW, const pandora::VertexVector &vertexVector) const
Calculate the event parameters.
unsigned int m_minClusterCaloHits
The min number of hits parameter in the energy score.
void GetShowerLikeClusterEndPoints(const pandora::ClusterList &clusterList, pandora::ClusterList &showerLikeClusters, ClusterEndPointsMap &clusterEndPointsMap) const
Add the endpoints of any shower-like clusters to the map.
unsigned int m_nClusters
The number of clusters in the event.
float m_rPhiFineTuningRadius
The maximum distance the r/phi tune can move a vertex.
std::vector< pandora::VertexVector > VectorOfVertexVectors
std::vector< art::Ptr< recob::Vertex > > VertexVector
pandora::StringVector m_inputClusterListNames
The list of cluster list names.