RPhiFeatureTool.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArVertex/RPhiFeatureTool.h
3  *
4  * @brief Header file for the r/phi feature tool class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_RPHI_FEATURE_TOOL_H
9 #define LAR_RPHI_FEATURE_TOOL_H 1
10 
12 
14 
15 namespace lar_content
16 {
17 
18 /**
19  * @brief RPhiFeatureTool class
20  */
22 {
23 public:
24  /**
25  * @brief Default constructor
26  */
28 
29  /**
30  * @brief Run the tool
31  *
32  * @param pAlgorithm address of the calling algorithm
33  * @param pVertex address of the vertex
34  * @param kdTreeMap map of the hit kd trees
35  * @param beamDeweightingScore the beam deweighting score for this vertex
36  * @param bestFastScore the best fast score
37  *
38  * @return the r/phi feature
39  */
40  void Run(LArMvaHelper::MvaFeatureVector &featureVector, const VertexSelectionBaseAlgorithm *const pAlgorithm,
43  const VertexSelectionBaseAlgorithm::ShowerClusterListMap &, const float beamDeweightingScore, float &bestFastScore);
44 
45 private:
46  /**
47  * @brief Kernel estimate class
48  */
50  {
51  public:
52  /**
53  * @brief Constructor
54  *
55  * @param sigma the width associated with the kernel estimate
56  */
57  KernelEstimate(const float sigma);
58 
59  /**
60  * @brief Sample the parameterised distribution at a specified x coordinate
61  *
62  * @param x the position at which to sample
63  *
64  * @return the sample value
65  */
66  float Sample(const float x) const;
67 
68  typedef std::multimap<float, float> ContributionList; ///< Map from x coord to weight, ATTN avoid map.find, etc. with float key
69 
70  /**
71  * @brief Get the contribution list
72  *
73  * @return the contribution list
74  */
75  const ContributionList &GetContributionList() const;
76 
77  /**
78  * @brief Get the assigned width
79  *
80  * @return the assigned width
81  */
82  float GetSigma() const;
83 
84  /**
85  * @brief Add a contribution to the distribution
86  *
87  * @param x the position
88  * @param weight the weight
89  */
90  void AddContribution(const float x, const float weight);
91 
92  private:
93  ContributionList m_contributionList; ///< The contribution list
94  const float m_sigma; ///< The assigned width
95  };
96 
97  //--------------------------------------------------------------------------------------------------------------------------------------
98 
99  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
100 
101  /**
102  * @brief Get the score for a trio of kernel estimations, using fast histogram approach
103  *
104  * @param kernelEstimateU the kernel estimate for the u view
105  * @param kernelEstimateV the kernel estimate for the v view
106  * @param kernelEstimateW the kernel estimate for the w view
107  *
108  * @return the fast score
109  */
110  float GetFastScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const;
111 
112  /**
113  * @brief Get the score for a trio of kernel estimations, using kernel density estimation but with reduced (binned) sampling
114  *
115  * @param kernelEstimateU the kernel estimate for the u view
116  * @param kernelEstimateV the kernel estimate for the v view
117  * @param kernelEstimateW the kernel estimate for the w view
118  *
119  * @return the midway score
120  */
121  float GetMidwayScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const;
122 
123  /**
124  * @brief Get the score for a trio of kernel estimations, using kernel density estimation and full hit-by-hit sampling
125  *
126  * @param kernelEstimateU the kernel estimate for the u view
127  * @param kernelEstimateV the kernel estimate for the v view
128  * @param kernelEstimateW the kernel estimate for the w view
129  *
130  * @return the full score
131  */
132  float GetFullScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const;
133 
134  /**
135  * @brief Use hits in clusters (in the provided kd tree) to fill a provided kernel estimate with hit-vertex relationship information
136  *
137  * @param pVertex the address of the vertex
138  * @param hitType the relevant hit type
139  * @param kdTree the relevant kd tree
140  * @param kernelEstimate to receive the populated kernel estimate
141  */
142  void FillKernelEstimate(const pandora::Vertex *const pVertex, const pandora::HitType hitType,
143  VertexSelectionBaseAlgorithm::HitKDTree2D &kdTree, KernelEstimate &kernelEstimate) const;
144 
145  /**
146  * @brief Whether to accept a candidate vertex, based on its spatial position in relation to other selected candidates
147  *
148  * @param pVertex the address of the vertex
149  * @param selectedVertexList the selected vertex list
150  *
151  * @return boolean
152  */
153  bool AcceptVertexLocation(const pandora::Vertex *const pVertex, const pandora::VertexList &selectedVertexList) const;
154 
155  /**
156  * @brief Fast estimate of std::atan2 function. Rather coarse (max |error| > 0.01) but should suffice for this use-case.
157  *
158  * @param y the y coordinate
159  * @param x the x coordinate
160  *
161  * @return estimate of std::atan2
162  */
163  float atan2Fast(const float y, const float x) const;
164 
165  bool m_fastScoreCheck; ///< Whether to use the fast histogram based score to selectively avoid calling full or midway scores
166  bool m_fastScoreOnly; ///< Whether to use the fast histogram based score only
167  bool m_fullScore; ///< Whether to use the full kernel density estimation score, as opposed to the midway score
168 
169  float m_kernelEstimateSigma; ///< The Gaussian width to use for kernel estimation
170  float m_kappa; ///< Hit-deweighting offset, of form: weight = 1 / sqrt(distance + kappa), units cm
171  float m_maxHitVertexDisplacement1D; ///< Max hit-vertex displacement in *any one dimension* for contribution to kernel estimation
172 
173  float m_minFastScoreFraction; ///< Fast score must be at least this fraction of best fast score to calculate full score
174  unsigned int m_fastHistogramNPhiBins; ///< Number of bins to use for fast score histograms
175  float m_fastHistogramPhiMin; ///< Min value for fast score histograms
176  float m_fastHistogramPhiMax; ///< Max value for fast score histograms
177 
178  bool m_enableFolding; ///< Whether to enable folding of -pi -> +pi phi distribution into 0 -> +pi region only
179 };
180 
181 //------------------------------------------------------------------------------------------------------------------------------------------
182 
184 {
185  if (m_sigma < std::numeric_limits<float>::epsilon())
186  throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
187 }
188 
189 //------------------------------------------------------------------------------------------------------------------------------------------
190 
192 {
193  return m_contributionList;
194 }
195 
196 //------------------------------------------------------------------------------------------------------------------------------------------
197 
199 {
200  return m_sigma;
201 }
202 
203 } // namespace lar_content
204 
205 #endif // #ifndef LAR_RPHI_FEATURE_TOOL_H
bool m_fastScoreCheck
Whether to use the fast histogram based score to selectively avoid calling full or midway scores...
Header file for the kd tree linker algo template class.
bool AcceptVertexLocation(const pandora::Vertex *const pVertex, const pandora::VertexList &selectedVertexList) const
Whether to accept a candidate vertex, based on its spatial position in relation to other selected can...
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
void Run(LArMvaHelper::MvaFeatureVector &featureVector, const VertexSelectionBaseAlgorithm *const pAlgorithm, const pandora::Vertex *const pVertex, const VertexSelectionBaseAlgorithm::SlidingFitDataListMap &, const VertexSelectionBaseAlgorithm::ClusterListMap &, const VertexSelectionBaseAlgorithm::KDTreeMap &kdTreeMap, const VertexSelectionBaseAlgorithm::ShowerClusterListMap &, const float beamDeweightingScore, float &bestFastScore)
Run the tool.
enum cvn::HType HitType
unsigned int m_fastHistogramNPhiBins
Number of bins to use for fast score histograms.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
float m_fastHistogramPhiMin
Min value for fast score histograms.
RPhiFeatureTool class.
float m_kappa
Hit-deweighting offset, of form: weight = 1 / sqrt(distance + kappa), units cm.
float GetSigma() const
Get the assigned width.
bool m_fastScoreOnly
Whether to use the fast histogram based score only.
weight
Definition: test.py:257
const ContributionList & GetContributionList() const
Get the contribution list.
float m_minFastScoreFraction
Fast score must be at least this fraction of best fast score to calculate full score.
float atan2Fast(const float y, const float x) const
Fast estimate of std::atan2 function. Rather coarse (max |error| > 0.01) but should suffice for this ...
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
float GetFastScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const
Get the score for a trio of kernel estimations, using fast histogram approach.
float Sample(const float x) const
Sample the parameterised distribution at a specified x coordinate.
float m_maxHitVertexDisplacement1D
Max hit-vertex displacement in any one dimension for contribution to kernel estimation.
KernelEstimate(const float sigma)
Constructor.
float GetFullScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const
Get the score for a trio of kernel estimations, using kernel density estimation and full hit-by-hit s...
float m_fastHistogramPhiMax
Max value for fast score histograms.
bool m_fullScore
Whether to use the full kernel density estimation score, as opposed to the midway score...
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
float m_kernelEstimateSigma
The Gaussian width to use for kernel estimation.
Header file for the vertex selection base algorithm class.
bool m_enableFolding
Whether to enable folding of -pi -> +pi phi distribution into 0 -> +pi region only.
RPhiFeatureTool()
Default constructor.
ContributionList m_contributionList
The contribution list.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
float GetMidwayScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const
Get the score for a trio of kernel estimations, using kernel density estimation but with reduced (bin...
void FillKernelEstimate(const pandora::Vertex *const pVertex, const pandora::HitType hitType, VertexSelectionBaseAlgorithm::HitKDTree2D &kdTree, KernelEstimate &kernelEstimate) const
Use hits in clusters (in the provided kd tree) to fill a provided kernel estimate with hit-vertex rel...
void AddContribution(const float x, const float weight)
Add a contribution to the distribution.
list x
Definition: train.py:276
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
std::multimap< float, float > ContributionList
Map from x coord to weight, ATTN avoid map.find, etc. with float key.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
MvaFeatureTool class template.
Definition: LArMvaHelper.h:27
std::list< Vertex > VertexList
Definition: DCEL.h:182
const float m_sigma
The assigned width.