LArHitWidthHelper.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArHelpers/LArHitWidthHelper.h
3  *
4  * @brief Header file for the lar hit width helper class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_HIT_WIDTH_HELPER_H
9 #define LAR_HIT_WIDTH_HELPER_H 1
10 
11 #include "Objects/Cluster.h"
12 
13 namespace lar_content
14 {
15 
16 /**
17  * @brief LArHitWidthHelper class
18  */
20 {
21 public:
22  /**
23  * @brief ConstituentHit class
24  */
26  {
27  public:
28  /**
29  * @brief Constructor
30  *
31  * @param positionVector the central position of the constituent hit
32  * @param hitWidth the hit width of the constituent hit
33  * @param pParentClusterAddress the address of the original, unbroken hit to which it belongs
34  */
35  ConstituentHit(const pandora::CartesianVector &positionVector, const float hitWidth, const pandora::Cluster *const pParentClusterAddress);
36 
37  /**
38  * @brief Returns the constituent hit central position
39  */
40  const pandora::CartesianVector &GetPositionVector() const;
41 
42  /**
43  * @brief Returns the constituent hit width
44  */
45  float GetHitWidth() const;
46 
47  /**
48  * @brief Returns the address of the parent cluster
49  */
50  const pandora::Cluster *GetParentClusterAddress() const;
51 
52  /**
53  * @brief SortByDistanceToPoint class
54  */
56  {
57  public:
58  /**
59  * @brief Constructor
60  *
61  * @param referencePoint the point relative to which constituent hits are ordered
62  */
63  SortByDistanceToPoint(const pandora::CartesianVector referencePoint) : m_referencePoint(referencePoint)
64  {
65  }
66 
67  /**
68  * @brief Sort constituent hits by their position relative to a referencePoint
69  *
70  * @param lhs first constituent hit
71  * @param rhs second constituent hit
72  *
73  * @return whether lhs hit is closer to the referencePoint than the rhs hit
74  */
75  bool operator()(const ConstituentHit &lhs, const ConstituentHit &rhs);
76 
77  private:
78  const pandora::CartesianVector m_referencePoint; ///< The point relative to which constituent hits are ordered
79  };
80 
81  private:
82  pandora::CartesianVector m_positionVector; ///< The central position of the consituent hit
83  float m_hitWidth; ///< The width of the constituent hit
84  const pandora::Cluster *m_pParentClusterAddress; ///< The address of the cluster the constituent hit belongs to
85  };
86 
87  typedef std::vector<ConstituentHit> ConstituentHitVector;
88 
89  /**
90  * @brief ClusterParameters class
91  */
93  {
94  public:
95  /**
96  * @brief Constructor
97  *
98  * @param pCluster from which the parameters will be obtained
99  * @param maxConstituentHitWidth the maximum width of a constituent hit
100  * @param isUniform whether to break up the hit into uniform constituent hits (and pad the hit) or not
101  * in the non-uniform case constituent hits from different hits may have different weights
102  * @param hitWidthScalingFactor the constituent hit width scaling factor
103  */
104  ClusterParameters(const pandora::Cluster *const pCluster, const float maxConsituentHitWidth, const bool isUniformHits,
105  const float hitWidthScalingFactor);
106 
107  /**
108  * @brief Constructor
109  *
110  * @param pCluster from which the parameters will be obtained
111  * @param numCaloHits the number of calo hits within the cluster
112  * @param totalWeight the total weight of the constituent hits
113  * @param constituentHitVector the vector of constituent hits
114  * @param lowerXExtrema the lower x extremal point of the constituent hits
115  * @param higherXExtrema the higher x extremal point of the constituent hits
116  */
117  ClusterParameters(const pandora::Cluster *const pCluster, const unsigned int numCaloHits, const float totalWeight,
118  const ConstituentHitVector &constituentHitVector, const pandora::CartesianVector &lowerXExtrema,
119  const pandora::CartesianVector &higherXExtrema);
120 
121  /**
122  * @brief Returns the address of the cluster
123  */
124  const pandora::Cluster *GetClusterAddress() const;
125 
126  /**
127  * @brief Returns the number of calo hits within the cluster
128  */
129  unsigned int GetNumCaloHits() const;
130 
131  /**
132  * @brief Returns the total weight of the constituent hits
133  */
134  float GetTotalWeight() const;
135 
136  /**
137  * @brief Returns the vector of constituent hits
138  */
139  const ConstituentHitVector &GetConstituentHitVector() const;
140 
141  /**
142  * @brief Returns the lower x extremal point of the constituent hits
143  */
144  const pandora::CartesianVector &GetLowerXExtrema() const;
145 
146  /**
147  * @brief Returns the higher x extremal point of the constituent hits
148  */
149  const pandora::CartesianVector &GetHigherXExtrema() const;
150 
151  private:
152  const pandora::Cluster *m_pCluster; ///< The address of the cluster
153  const unsigned int m_numCaloHits; ///< The number of calo hits within the cluster
154  const ConstituentHitVector m_constituentHitVector; ///< The vector of constituent hits
155  const float m_totalWeight; ///< The total hit weight of the contituent hits
156  const pandora::CartesianVector m_lowerXExtrema; ///< The lower x extremal point of the constituent hits
157  const pandora::CartesianVector m_higherXExtrema; ///< The higher x extremal point of the constituent hits
158  };
159 
160  typedef std::unordered_map<const pandora::Cluster *, const ClusterParameters> ClusterToParametersMap;
161 
162  /**
163  * @brief SortByHigherExtrema class
164  */
166  {
167  public:
168  /**
169  * @brief Constructor
170  *
171  * @param clusterToParametersMap the map [cluster -> cluster parameters]
172  */
173  SortByHigherXExtrema(const ClusterToParametersMap &clusterToParametersMap);
174 
175  /**
176  * @brief Sort clusters by the higher x extremal point of their constituent hits
177  *
178  * @param pLhs first cluster
179  * @param pRhs second cluster
180  *
181  * @return whether the pLhs cluster has a lower higherXExtrema than the pRhs cluster
182  */
183  bool operator()(const pandora::Cluster *const pLhs, const pandora::Cluster *const pRhs);
184 
185  private:
186  const ClusterToParametersMap &m_clusterToParametersMap; ///< The map [cluster -> cluster parameters]
187  };
188 
189  /**
190  * @brief Return the cluster parameters of a given cluster, exception thrown if not found in map [cluster -> cluster parameter] or if map is empty
191  *
192  * @param pCluster the input cluster
193  * @param clusterToParametersMap the map [cluster -> cluster parameter]
194  *
195  * @return the cluster parameters of the input cluster
196  */
197  static const ClusterParameters &GetClusterParameters(const pandora::Cluster *const pCluster, const ClusterToParametersMap &clusterToParametersMap);
198 
199  /**
200  * @brief Return the number of constituent hits that a given cluster would be broken into
201  *
202  * @param pCluster the input cluster
203  * @param maxConstituentHitWidth the maximum width of a constituent hit
204  * @param hitWidthScalingFactor the constituent hit width scaling factor
205  *
206  * @return the number of constituent hits the cluster would be broken into
207  */
208  static unsigned int GetNProposedConstituentHits(
209  const pandora::Cluster *const pCluster, const float maxConstituentHitWidth, const float hitWidthScalingFactor);
210 
211  /**
212  * @brief Break up the cluster hits into constituent hits
213  *
214  * @param pCluster the input cluster
215  * @param maxConstituentHitWidth the maximum width of a constituent hit
216  * @param hitWidthScalingFactor the constituent hit width scaling factor
217  * @param isUniform whether to break up the hit into uniform constituent hits (and pad the hit) or not
218  * in the non-uniform case constituent hits from different hits may have different weights
219  *
220  * @return the vector of constituent hits
221  */
222  static ConstituentHitVector GetConstituentHits(
223  const pandora::Cluster *const pCluster, const float maxConstituentHitWidth, const float hitWidthScalingFactor, const bool isUniform);
224 
225  /**
226  * @brief Break up the calo hit into constituent hits
227  *
228  * @param pCaloHit the input calo hit
229  * @param pCluster the parent cluster
230  * @param numberOfConstituentHits the number of constituent hits the hit will be broken into
231  * @param constituentHitWidth the hit width of the constituent hits
232  * @param constituentHitVector the input vector to which to add the contituent hits
233  *
234  */
235  static void SplitHitIntoConstituents(const pandora::CaloHit *const pCaloHit, const pandora::Cluster *const pCluster,
236  const unsigned int numberOfConstituentHits, const float constituentHitWidth, ConstituentHitVector &constituentHitVector);
237 
238  /**
239  * @brief Obtain a vector of the contituent hit central positions
240  *
241  * @param constituentHitVector the input vector of contituent hits
242  *
243  * @return a vector of constituent hit central positions
244  */
245  static pandora::CartesianPointVector GetConstituentHitPositionVector(const ConstituentHitVector &constituentHitVector);
246 
247  /**
248  * @brief Sum the widths of constituent hits
249  *
250  * @param constituentHitVector the input vector of contituent hits
251  *
252  * @return the total weight sum
253  */
254  static float GetTotalClusterWeight(const ConstituentHitVector &constituentHitVector);
255 
256  /**
257  * @brief Sum the widths of the original, unscaled hits contained within a cluster
258  *
259  * @param pCluster the input cluster
260  *
261  * @return the total weight sum
262  */
263  static float GetOriginalTotalClusterWeight(const pandora::Cluster *const pCluster);
264 
265  /**
266  * @brief Return the lower x extremal point of the constituent hits
267  *
268  * @param constituentHitVector the input vector of contituent hits
269  *
270  * @return the lower x extremal point of the constituent hits
271  */
272  static pandora::CartesianVector GetExtremalCoordinatesLowerX(const ConstituentHitVector &constituentHitVector);
273 
274  /**
275  * @brief Return the higher x extremal point of the constituent hits
276  *
277  * @param constituentHitVector the input vector of contituent hits
278  *
279  * @return the higher x extremal point of the constituent hits
280  */
281  static pandora::CartesianVector GetExtremalCoordinatesHigherX(const ConstituentHitVector &constituentHitVector);
282 
283  /**
284  * @brief Calculate the higher and lower x extremal points of the constituent hits
285  *
286  * @param constituentHitVector the input vector of contituent hits
287  * @param lowerXCoordinate the lower x extremal point
288  * @param higherXCoordinate the higher x extremal point
289  */
290  static void GetExtremalCoordinatesX(const ConstituentHitVector &constituentHitVector, pandora::CartesianVector &lowerXCoordinate,
291  pandora::CartesianVector &higherXCoordinate);
292 
293  /**
294  * @brief Consider the hit width to find the closest position of a calo hit to a specified line
295  *
296  * @param lineStart the start position of the line
297  * @param lineDirection the direction of the line
298  * @param pCaloHit the input calo hit
299  *
300  * @return the closest position
301  */
302  static pandora::CartesianVector GetClosestPointToLine2D(
303  const pandora::CartesianVector &lineStart, const pandora::CartesianVector &lineDirection, const pandora::CaloHit *const pCaloHit);
304 
305  /**
306  * @brief Consider the hit width to find the smallest distance between a calo hit and a given point
307  *
308  * @param pCaloHit the input calo hit
309  * @param point2D the position
310  *
311  * @return the smallest distance
312  */
313  static float GetClosestDistanceToPoint2D(const pandora::CaloHit *const pCaloHit, const pandora::CartesianVector &point2D);
314 };
315 
316 //------------------------------------------------------------------------------------------------------------------------------------------
317 
318 inline const pandora::CartesianVector &LArHitWidthHelper::ConstituentHit::GetPositionVector() const
319 {
320  return m_positionVector;
321 }
322 
323 //------------------------------------------------------------------------------------------------------------------------------------------
324 
326 {
327  return m_hitWidth;
328 }
329 
330 //------------------------------------------------------------------------------------------------------------------------------------------
331 
333 {
335 }
336 
337 //------------------------------------------------------------------------------------------------------------------------------------------
338 //------------------------------------------------------------------------------------------------------------------------------------------
339 
340 inline const pandora::Cluster *LArHitWidthHelper::ClusterParameters::GetClusterAddress() const
341 {
342  return m_pCluster;
343 }
344 
345 //------------------------------------------------------------------------------------------------------------------------------------------
346 
348 {
349  return m_numCaloHits;
350 }
351 
352 //------------------------------------------------------------------------------------------------------------------------------------------
353 
355 {
356  return m_totalWeight;
357 }
358 
359 //------------------------------------------------------------------------------------------------------------------------------------------
360 
362 {
363  return m_constituentHitVector;
364 }
365 
366 //------------------------------------------------------------------------------------------------------------------------------------------
367 
368 inline const pandora::CartesianVector &LArHitWidthHelper::ClusterParameters::GetLowerXExtrema() const
369 {
370  return m_lowerXExtrema;
371 }
372 
373 //------------------------------------------------------------------------------------------------------------------------------------------
374 
375 inline const pandora::CartesianVector &LArHitWidthHelper::ClusterParameters::GetHigherXExtrema() const
376 {
377  return m_higherXExtrema;
378 }
379 
380 //------------------------------------------------------------------------------------------------------------------------------------------
381 //------------------------------------------------------------------------------------------------------------------------------------------
382 
384  m_clusterToParametersMap(clusterToParametersMap)
385 {
386 }
387 
388 } // namespace lar_content
389 
390 #endif // #ifndef LAR_HIT_WIDTH_HELPER_H
const float m_totalWeight
The total hit weight of the contituent hits.
const pandora::CartesianVector & GetLowerXExtrema() const
Returns the lower x extremal point of the constituent hits.
static float GetOriginalTotalClusterWeight(const pandora::Cluster *const pCluster)
Sum the widths of the original, unscaled hits contained within a cluster.
const pandora::CartesianVector m_higherXExtrema
The higher x extremal point of the constituent hits.
static const ClusterParameters & GetClusterParameters(const pandora::Cluster *const pCluster, const ClusterToParametersMap &clusterToParametersMap)
Return the cluster parameters of a given cluster, exception thrown if not found in map [cluster -> cl...
const pandora::Cluster * GetClusterAddress() const
Returns the address of the cluster.
LArHitWidthHelper class.
static void SplitHitIntoConstituents(const pandora::CaloHit *const pCaloHit, const pandora::Cluster *const pCluster, const unsigned int numberOfConstituentHits, const float constituentHitWidth, ConstituentHitVector &constituentHitVector)
Break up the calo hit into constituent hits.
const pandora::CartesianVector m_lowerXExtrema
The lower x extremal point of the constituent hits.
SortByHigherXExtrema(const ClusterToParametersMap &clusterToParametersMap)
Constructor.
static void GetExtremalCoordinatesX(const ConstituentHitVector &constituentHitVector, pandora::CartesianVector &lowerXCoordinate, pandora::CartesianVector &higherXCoordinate)
Calculate the higher and lower x extremal points of the constituent hits.
const pandora::Cluster * GetParentClusterAddress() const
Returns the address of the parent cluster.
static ConstituentHitVector GetConstituentHits(const pandora::Cluster *const pCluster, const float maxConstituentHitWidth, const float hitWidthScalingFactor, const bool isUniform)
Break up the cluster hits into constituent hits.
static pandora::CartesianVector GetClosestPointToLine2D(const pandora::CartesianVector &lineStart, const pandora::CartesianVector &lineDirection, const pandora::CaloHit *const pCaloHit)
Consider the hit width to find the closest position of a calo hit to a specified line.
float m_hitWidth
The width of the constituent hit.
SortByDistanceToPoint(const pandora::CartesianVector referencePoint)
Constructor.
pandora::CartesianVector m_positionVector
The central position of the consituent hit.
unsigned int GetNumCaloHits() const
Returns the number of calo hits within the cluster.
const ClusterToParametersMap & m_clusterToParametersMap
The map [cluster -> cluster parameters].
const pandora::CartesianVector & GetPositionVector() const
Returns the constituent hit central position.
const pandora::CartesianVector & GetHigherXExtrema() const
Returns the higher x extremal point of the constituent hits.
std::vector< ConstituentHit > ConstituentHitVector
static unsigned int GetNProposedConstituentHits(const pandora::Cluster *const pCluster, const float maxConstituentHitWidth, const float hitWidthScalingFactor)
Return the number of constituent hits that a given cluster would be broken into.
static pandora::CartesianPointVector GetConstituentHitPositionVector(const ConstituentHitVector &constituentHitVector)
Obtain a vector of the contituent hit central positions.
float GetTotalWeight() const
Returns the total weight of the constituent hits.
static pandora::CartesianVector GetExtremalCoordinatesLowerX(const ConstituentHitVector &constituentHitVector)
Return the lower x extremal point of the constituent hits.
static float GetTotalClusterWeight(const ConstituentHitVector &constituentHitVector)
Sum the widths of constituent hits.
static float GetClosestDistanceToPoint2D(const pandora::CaloHit *const pCaloHit, const pandora::CartesianVector &point2D)
Consider the hit width to find the smallest distance between a calo hit and a given point...
ConstituentHit(const pandora::CartesianVector &positionVector, const float hitWidth, const pandora::Cluster *const pParentClusterAddress)
Constructor.
static pandora::CartesianVector GetExtremalCoordinatesHigherX(const ConstituentHitVector &constituentHitVector)
Return the higher x extremal point of the constituent hits.
const pandora::CartesianVector m_referencePoint
The point relative to which constituent hits are ordered.
bool operator()(const ConstituentHit &lhs, const ConstituentHit &rhs)
Sort constituent hits by their position relative to a referencePoint.
const unsigned int m_numCaloHits
The number of calo hits within the cluster.
const pandora::Cluster * m_pCluster
The address of the cluster.
const ConstituentHitVector m_constituentHitVector
The vector of constituent hits.
std::unordered_map< const pandora::Cluster *, const ClusterParameters > ClusterToParametersMap
const ConstituentHitVector & GetConstituentHitVector() const
Returns the vector of constituent hits.
float GetHitWidth() const
Returns the constituent hit width.
const pandora::Cluster * m_pParentClusterAddress
The address of the cluster the constituent hit belongs to.