Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
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
12
16
18
20
21#include <random>
22
23namespace lar_content
24{
25
26template <typename, unsigned int>
27class KDTreeLinkerAlgo;
28template <typename, unsigned int>
29class KDTreeNodeInfoT;
30
31//------------------------------------------------------------------------------------------------------------------------------------------
32
37{
38public:
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
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
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
118 unsigned int m_nHits;
119 unsigned int m_nClusters;
120 unsigned int m_nCandidates;
121 };
122
123 //--------------------------------------------------------------------------------------------------------------------------------------
124
129
130protected:
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
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
451
459 std::string m_caloHitListName;
460
462 unsigned int m_minClusterCaloHits;
463 unsigned int m_slidingFitWindow;
465
471
483};
484
485//------------------------------------------------------------------------------------------------------------------------------------------
486
487inline 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
502inline 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
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
Header file for the lar adaptive boosted decision tree class.
Header file for the lar monte carlo particle helper helper class.
Header file for the lar support vector machine class.
Header file for the lar two dimensional sliding fit result class.
Header file for the pandora content api class.
Header file for the vertex selection base algorithm class.
Data stored in each KDTree node. The dim1/dim2 fields are usually the duplication of some PFRecHit va...
MvaTypes::MvaFeatureVector MvaFeatureVector
std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
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_axisHits
The hit density along the axis between the two vertices.
VertexSharedFeatureInfo(const float separation, const float axisHits)
Constructor.
float m_showerAsymmetryConstant
The shower 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.
bool m_legacyVariables
Whether to only use the old variables.
void AddEventFeaturesToVector(const EventFeatureInfo &eventFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const
Add the event features to a vector in the correct order.
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_rPhiFineTuningRadius
The maximum distance the r/phi tune can move a vertex.
float m_showerClusteringDistance
The shower clustering distance.
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.
pandora::StringVector m_inputClusterListNames
The list of cluster list names.
void IncrementShoweryParameters(const pandora::ClusterList &clusterList, unsigned int &nShoweryHits, unsigned int &nHits, float &eventEnergy) const
Increment the showery hit parameters for a cluster list.
bool IsClusterShowerLike(const pandora::Cluster *const pCluster) const
Find whether a cluster is shower-like.
unsigned int m_minClusterCaloHits
The min number of hits parameter in the energy score.
void IncrementSharedAxisValues(const pandora::CartesianVector pos1, const pandora::CartesianVector pos2, HitKDTree2D &kdTree, float &axisHits) const
Increments the axis hits information for one view.
float GetCoordinateSpan(const pandora::InputFloat &minCoord, const pandora::InputFloat &maxCoord) const
Get the coordinate span.
bool m_legacyEventShapes
Whether to use the old event shapes calculation.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
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 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 GetBestRegionVertices(VertexScoreList &initialScoreList, pandora::VertexVector &bestRegionVertices) const
Get the list of top-N separated vertices.
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::string m_mcParticleListName
The MC particle list for creating training examples.
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 AddVertexFeaturesToVector(const VertexFeatureInfo &vertexFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector, const bool useRPhi) const
Add the vertex features to a vector in the correct order.
VertexFeatureTool::FeatureToolVector m_featureToolVector
The feature tool vector.
void UpdateSpanCoordinate(const float minPositionCoord, const float maxPositionCoord, pandora::InputFloat &minCoord, pandora::InputFloat &maxCoord) const
Update the min/max coordinate spans.
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
std::string GetInteractionType() const
Get the interaction type string.
bool m_useShowerClusteringApproximation
Whether to use the shower clustering distance approximation.
std::vector< LArMvaHelper::MvaFeatureVector > FeatureListVector
void GetLegacyEventShapeFeatures(const pandora::ClusterList &clusterList, float &eventVolume, float &longitudinality) const
Get the event shape features.
std::pair< pandora::CartesianVector, pandora::CartesianVector > ClusterEndPoints
float m_globalAsymmetryConstant
The global asymmetry constant for the initial region score list.
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.
void GetShowerLikeClusterEndPoints(const pandora::ClusterList &clusterList, pandora::ClusterList &showerLikeClusters, ClusterEndPointsMap &clusterEndPointsMap) const
Add the endpoints of any shower-like clusters to the map.
std::unordered_map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
std::map< const pandora::Vertex *const, VertexFeatureInfo > VertexFeatureInfoMap
std::string m_trainingOutputFileRegion
The training output file for the region mva.
void AddSharedFeaturesToVector(const VertexSharedFeatureInfo &vertexSharedFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const
Add the shared features to a vector in the correct order.
void CalculateShowerClusterList(const pandora::ClusterList &inputClusterList, ShowerClusterList &showerClusterList) const
Calculate the shower cluster map for a cluster list.
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.
std::map< const pandora::Cluster *const, ClusterEndPoints > ClusterEndPointsMap
float m_mcVertexXCorrection
The correction to the x-coordinate of the MC vertex position.
float m_maxTrueVertexRadius
The maximum distance at which a vertex candidate can be considered the 'true' vertex.
bool m_useRPhiFeatureForRegion
Whether to use the r/phi feature for the region 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.
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_trainingOutputFileVertex
The training output file for the vertex mva.
float m_minShowerSpineLength
The minimum length at which all are considered to be tracks.
KDTreeNodeInfoT< const pandora::CaloHit *, 2 > HitKDNode2D
float m_localAsymmetryConstant
The local asymmetry constant for the initial region score list.
bool m_allowClassifyDuringTraining
Whether classification is allowed during training.
bool m_dropFailedRPhiFastScoreCandidates
Whether to drop candidates that fail the r/phi fast score test.
void PopulateInitialScoreList(VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pVertex, VertexScoreList &initialScoreList) const
Populate the initial vertex score list for a given vertex.
float m_energyKickConstant
The energy kick constant for the initial region score list.
unsigned int m_minShowerClusterHits
The minimum number of shower cluster hits.
KDTreeLinkerAlgo< const pandora::CaloHit *, 2 > HitKDTree2D
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.
float m_beamDeweightingConstant
The beam deweighting constant for the initial region score list.
void GetEventShapeFeatures(const ClusterListMap &clusterListMap, float &eventArea, float &longitudinality) const
Get the event shape features.
void Get2DSpan(const pandora::ClusterList &clusterList, float &xSpan, float &zSpan) const
Get the coordinate span in one view.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
CartesianVector class.
Cluster class.
Definition Cluster.h:31
Vertex class.
Definition Vertex.h:26
MANAGED_CONTAINER< const Cluster * > ClusterList
std::vector< std::string > StringVector
StatusCode
The StatusCode enum.
std::vector< const Vertex * > VertexVector