EventSlicingTool.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArEventBuilding/EventSlicingTool.h
3  *
4  * @brief Header file for the event slicing tool class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_EVENT_SLICING_TOOL_H
9 #define LAR_EVENT_SLICING_TOOL_H 1
10 
12 
14 
15 #include <unordered_map>
16 
17 namespace lar_content
18 {
19 
20 template <typename, unsigned int>
21 class KDTreeLinkerAlgo;
22 template <typename, unsigned int>
23 class KDTreeNodeInfoT;
24 
25 class SimpleCone;
26 
27 //------------------------------------------------------------------------------------------------------------------------------------------
28 
29 /**
30  * @brief EventSlicingTool class
31  */
33 {
34 public:
35  /**
36  * @brief Default constructor
37  */
39 
40  void RunSlicing(const pandora::Algorithm *const pAlgorithm, const SlicingAlgorithm::HitTypeToNameMap &caloHitListNames,
41  const SlicingAlgorithm::HitTypeToNameMap &clusterListNames, SlicingAlgorithm::SliceList &sliceList);
42 
43 private:
44  /**
45  * @brief Copy all the input hits in an event into a single slice
46  *
47  * @param pAlgorithm the address of the calling algorithm
48  * @param caloHitListNames the hit type to calo hit list name map
49  * @param sliceList the slice list to receive the single new slice
50  */
51  void CopyAllHitsToSingleSlice(const pandora::Algorithm *const pAlgorithm, const SlicingAlgorithm::HitTypeToNameMap &caloHitListNames,
52  SlicingAlgorithm::SliceList &sliceList) const;
53 
54  typedef std::unordered_map<const pandora::Cluster *, const pandora::ParticleFlowObject *> ClusterToPfoMap;
55 
56  /**
57  * @brief Get the 3D clusters from a specified list of pfos, storing the 3D clusters in the provided list and populating
58  * a map from 3D cluster to parent pfo
59  *
60  * @param pAlgorithm the address of the calling algorithm
61  * @param pfoListName the pfo list name
62  * @param clusters3D to receive the list of 3D clusters
63  * @param clusterToPfoMap to receive the mapping from 3D clusters to parent pfos
64  */
65  void GetThreeDClusters(const pandora::Algorithm *const pAlgorithm, const std::string &pfoListName, pandora::ClusterList &clusters3D,
66  ClusterToPfoMap &clusterToPfoMap) const;
67 
68  typedef std::vector<pandora::ClusterVector> ClusterSliceList;
69 
70  /**
71  * @brief Divide the provided lists of 3D track and shower clusters into slices
72  *
73  * @param trackClusters3D the list of 3D track clusters
74  * @param showerClusters3D the list of 3D shower clusters
75  * @param clusterSliceList to receive the list of 3D clusters, divided into slices (one 3D cluster list per slice)
76  */
78  const pandora::ClusterList &trackClusters3D, const pandora::ClusterList &showerClusters3D, ClusterSliceList &clusterSliceList) const;
79 
80  /**
81  * @brief Collect all clusters associated with a provided cluster
82  *
83  * @param pClusterInSlice the address of the cluster already in a slice
84  * @param candidateClusters the list of candidate clusters
85  * @param trackFitResults the map of sliding fit results for track candidate clusters
86  * @param showerConeFitResults the map of sliding const fit results for shower candidate clusters
87  * @param clusterSlice the cluster slice
88  * @param usedClusters the list of clusters already added to slices
89  */
90  void CollectAssociatedClusters(const pandora::Cluster *const pClusterInSlice, const pandora::ClusterVector &candidateClusters,
91  const ThreeDSlidingFitResultMap &trackFitResults, const ThreeDSlidingConeFitResultMap &showerConeFitResults,
92  pandora::ClusterVector &clusterSlice, pandora::ClusterSet &usedClusters) const;
93 
94  /**
95  * @brief Compare the provided clusters to assess whether they are associated via pointing (checks association "both ways")
96  *
97  * @param pClusterInSlice address of a cluster already in the slice
98  * @param pCandidateCluster address of the candidate cluster
99  * @param trackFitResults the map of sliding fit results for track candidate clusters
100  *
101  * @return whether an addition to the cluster slice should be made
102  */
103  bool PassPointing(const pandora::Cluster *const pClusterInSlice, const pandora::Cluster *const pCandidateCluster,
104  const ThreeDSlidingFitResultMap &trackFitResults) const;
105 
106  /**
107  * @brief Compare the provided clusters to assess whether they are associated via pointing
108  *
109  * @param pClusterInSlice address of a cluster already in the slice
110  * @param pCandidateCluster address of the candidate cluster
111  *
112  * @return whether an addition to the cluster slice should be made
113  */
114  bool PassProximity(const pandora::Cluster *const pClusterInSlice, const pandora::Cluster *const pCandidateCluster) const;
115 
116  /**
117  * @brief Compare the provided clusters to assess whether they are associated via cone fits to the shower cluster (single "direction" check)
118  *
119  * @param pClusterInSlice address of a cluster already in the slice
120  * @param pCandidateCluster address of the candidate cluster
121  * @param showerConeFitResults the map of sliding cone fit results for shower candidate clusters
122  *
123  * @return whether an addition to the cluster slice should be made
124  */
125  bool PassShowerCone(const pandora::Cluster *const pConeCluster, const pandora::Cluster *const pNearbyCluster,
126  const ThreeDSlidingConeFitResultMap &showerConeFitResults) const;
127 
128  /**
129  * @brief Check closest approach metrics for a pair of pointing clusters
130  *
131  * @param cluster1 the first pointing cluster
132  * @param cluster2 the second pointing cluster
133  *
134  * @return whether the pointing clusters are declared to be in the same slice
135  */
136  bool CheckClosestApproach(const LArPointingCluster &cluster1, const LArPointingCluster &cluster2) const;
137 
138  /**
139  * @brief Check closest approach metrics for a pair of pointing cluster vertices
140  *
141  * @param vertex1 the first pointing cluster vertex
142  * @param vertex2 the second pointing cluster vertex
143  *
144  * @return whether the pointing clusters are declared to be in the same slice
145  */
146  bool CheckClosestApproach(const LArPointingCluster::Vertex &vertex1, const LArPointingCluster::Vertex &vertex2) const;
147 
148  /**
149  * @brief Check whether a pair of pointing clusters are nodally associated
150  *
151  * @param cluster1 the first pointing cluster
152  * @param cluster2 the second pointing cluster
153  *
154  * @return whether the pointing clusters are declared to be in the same slice
155  */
156  bool IsNode(const LArPointingCluster &cluster1, const LArPointingCluster &cluster2) const;
157 
158  /**
159  * @brief Check whether a pair of pointing clusters are consistent with an emission
160  *
161  * @param cluster1 the first pointing cluster
162  * @param cluster2 the second pointing cluster
163  *
164  * @return whether the pointing clusters are declared to be in the same slice
165  */
166  bool IsEmission(const LArPointingCluster &cluster1, const LArPointingCluster &cluster2) const;
167 
168  typedef std::unordered_map<const pandora::Cluster *, unsigned int> ClusterToSliceIndexMap;
169 
170  /**
171  * @brief Create new slices for each of the groupings of 3D clusters in the provided cluster slice list
172  *
173  * @param clusterSliceList the list of 3D clusters, divided into slices (one 3D cluster list per slice)
174  * @param sliceList the slice list to receive the new slices
175  * @param clusterToSliceIndexMap to receive the mapping from 3D clusters to index in the slice list
176  */
177  void CreateSlices(const ClusterSliceList &clusterSliceList, SlicingAlgorithm::SliceList &sliceList, ClusterToSliceIndexMap &clusterToSliceIndexMap) const;
178 
179  /**
180  * @brief Use 3D clusters in the cluster slice list, find their parent pfos and assign all hits in all 2D clusters in the pfos
181  * to the relevant slice in the output slice list
182  *
183  * @param clusterToSliceIndexMap the mapping from 3D clusters to index in the slice list
184  * @param clusterToPfoMap the mapping from 3D clusters to parent pfos
185  * @param sliceList the list containing slices to be populated with 2D hits
186  * @param assignedClusters to receive the list of 2D clusters with hits assigned to slices
187  */
188  void CopyPfoHitsToSlices(const ClusterToSliceIndexMap &clusterToSliceIndexMap, const ClusterToPfoMap &clusterToPfoMap,
189  SlicingAlgorithm::SliceList &sliceList, pandora::ClusterSet &assignedClusters) const;
190 
191  /**
192  * @brief Get the list of 2D clusters with hits yets to be assigned to slices
193  *
194  * @param pAlgorithm the address of the calling algorithm
195  * @param clusterListNames the hit type to cluster list name map
196  * @param assignedClusters the list of 2D clusters with hits assigned to slices
197  * @param remainingClusters to receive the list of 2D clusters with hits yet to be assigned to slices
198  */
199  void GetRemainingClusters(const pandora::Algorithm *const pAlgorithm, const SlicingAlgorithm::HitTypeToNameMap &clusterListNames,
200  const pandora::ClusterSet &assignedClusters, pandora::ClusterList &remainingClusters) const;
201 
202  /**
203  * @brief Get the list of 2D clusters (from a named 2D cluster list) with hits yets to be assigned to slices
204  *
205  * @param pAlgorithm the address of the calling algorithm
206  * @param clusterListName the cluster list name
207  * @param assignedClusters the list of 2D clusters with hits assigned to slices
208  * @param remainingClusters to receive the list of 2D clusters with hits yet to be assigned to slices
209  */
210  void GetRemainingClusters(const pandora::Algorithm *const pAlgorithm, const std::string &clusterListName,
211  const pandora::ClusterSet &assignedClusters, pandora::ClusterList &remainingClusters) const;
212 
213  /**
214  * @brief Use the list of remaining 2D clusters to assign all remaining 2D hits to existing slices in the slice list
215  *
216  * @param remainingClusters the list of 2D clusters with hits yet to be assigned to slices
217  * @param clusterToSliceIndexMap the mapping from 3D clusters to index in the slice list
218  * @param sliceList the list containing slices to be populated with 2D hits
219  */
220  void AssignRemainingHitsToSlices(const pandora::ClusterList &remainingClusters, const ClusterToSliceIndexMap &clusterToSliceIndexMap,
221  SlicingAlgorithm::SliceList &sliceList) const;
222 
225  typedef std::vector<PointKDNode2D> PointKDNode2DList;
226 
227  typedef std::list<const pandora::CartesianVector *> PointList;
228  typedef std::unordered_map<const pandora::CartesianVector *, unsigned int> PointToSliceIndexMap;
229 
230  /**
231  * @brief Use projections of 3D hits already assigned to slices to populate kd trees to aid assignment of remaining clusters
232  *
233  * @param sliceList the slice list
234  * @param pointsU to receive the points in the u view
235  * @param pointsV to receive the points in the v view
236  * @param pointsW to receive the points in the w view
237  * @param pointToSliceIndexMap to receive the mapping from points to slice index
238  */
239  void GetKDTreeEntries2D(const SlicingAlgorithm::SliceList &sliceList, PointList &pointsU, PointList &pointsV, PointList &pointsW,
240  PointToSliceIndexMap &pointToSliceIndexMap) const;
241 
242  /**
243  * @brief Use 2D hits already assigned to slices to populate kd trees to aid assignment of remaining clusters
244  *
245  * @param clusterToSliceIndexMap the 3D cluster to slice index map
246  * @param pointsU to receive the points in the u view
247  * @param pointsV to receive the points in the v view
248  * @param pointsW to receive the points in the w view
249  * @param pointToSliceIndexMap to receive the mapping from points to slice index
250  */
251  void GetKDTreeEntries3D(const ClusterToSliceIndexMap &clusterToSliceIndexMap, PointList &pointsU, PointList &pointsV,
252  PointList &pointsW, PointToSliceIndexMap &pointToSliceIndexMap) const;
253 
254  /**
255  * @brief Use the provided kd tree to efficiently identify the most appropriate slice for the provided 2D cluster
256  *
257  * @param pCluster2D the address of the 2D cluster
258  * @param kdTree the kd tree
259  *
260  * @return the nearest-neighbour point identified by the kd tree
261  */
262  const PointKDNode2D *MatchClusterToSlice(const pandora::Cluster *const pCluster2D, PointKDTree2D &kdTree) const;
263 
264  /**
265  * @brief Sort points (use Z, followed by X, followed by Y)
266  *
267  * @param pLhs address of first point
268  * @param pRhs address of second point
269  */
270  static bool SortPoints(const pandora::CartesianVector *const pLhs, const pandora::CartesianVector *const pRhs);
271 
272  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
273 
274  std::string m_trackPfoListName; ///< The name of the input track pfo list
275  std::string m_showerPfoListName; ///< The name of the input shower pfo list
276 
277  unsigned int m_minHitsPer3DCluster; ///< The minimum number of hits in a 3D cluster to warrant consideration in slicing
278  unsigned int m_min3DHitsToSeedNewSlice; ///< The minimum number of hits in a 3D cluster to seed a new slice
279  unsigned int m_halfWindowLayers; ///< The number of layers to use for half-window of sliding fit
280 
281  bool m_usePointingAssociation; ///< Whether to use pointing association
282  float m_minVertexLongitudinalDistance; ///< Pointing association check: min longitudinal distance cut
283  float m_maxVertexLongitudinalDistance; ///< Pointing association check: max longitudinal distance cut
284  float m_maxVertexTransverseDistance; ///< Pointing association check: max transverse distance cut
285  float m_vertexAngularAllowance; ///< Pointing association check: pointing angular allowance in degrees
286  float m_maxClosestApproach; ///< Pointing association: max distance of closest approach between straight line fits
287  float m_maxInterceptDistance; ///< Pointing association: max distance from cluster vertex to point of closest approach
288 
289  bool m_useProximityAssociation; ///< Whether to use proximity association
290  float m_maxHitSeparationSquared; ///< Proximity association: max distance allowed between the closest pair of hits
291 
292  bool m_useShowerConeAssociation; ///< Whether to use shower cone association
293  unsigned int m_nConeFitLayers; ///< The number of layers over which to sum fitted direction to obtain cone fit
294  unsigned int m_nConeFits; ///< The number of cone fits to perform, spread roughly uniformly along the shower length
295  float m_coneLengthMultiplier; ///< The cone length multiplier to use when calculating bounded cluster fractions
296  float m_maxConeLength; ///< The maximum allowed cone length to use when calculating bounded cluster fractions
297  float m_coneTanHalfAngle1; ///< The cone tan half angle to use when calculating bounded cluster fractions 1
298  float m_coneBoundedFraction1; ///< The minimum cluster bounded fraction for association 1
299  float m_coneTanHalfAngle2; ///< The cone tan half angle to use when calculating bounded cluster fractions 2
300  float m_coneBoundedFraction2; ///< The minimum cluster bounded fraction for association 2
301 
302  bool m_use3DProjectionsInHitPickUp; ///< Whether to include 3D cluster projections when assigning remaining clusters to slices
303 };
304 
305 } // namespace lar_content
306 
307 #endif // #ifndef LAR_EVENT_SLICING_TOOL_H
void GetThreeDClusters(const pandora::Algorithm *const pAlgorithm, const std::string &pfoListName, pandora::ClusterList &clusters3D, ClusterToPfoMap &clusterToPfoMap) const
Get the 3D clusters from a specified list of pfos, storing the 3D clusters in the provided list and p...
unsigned int m_nConeFits
The number of cone fits to perform, spread roughly uniformly along the shower length.
KDTreeLinkerAlgo< const pandora::CartesianVector *, 2 > PointKDTree2D
void GetClusterSliceList(const pandora::ClusterList &trackClusters3D, const pandora::ClusterList &showerClusters3D, ClusterSliceList &clusterSliceList) const
Divide the provided lists of 3D track and shower clusters into slices.
unsigned int m_min3DHitsToSeedNewSlice
The minimum number of hits in a 3D cluster to seed a new slice.
void CopyPfoHitsToSlices(const ClusterToSliceIndexMap &clusterToSliceIndexMap, const ClusterToPfoMap &clusterToPfoMap, SlicingAlgorithm::SliceList &sliceList, pandora::ClusterSet &assignedClusters) const
Use 3D clusters in the cluster slice list, find their parent pfos and assign all hits in all 2D clust...
float m_maxHitSeparationSquared
Proximity association: max distance allowed between the closest pair of hits.
unsigned int m_nConeFitLayers
The number of layers over which to sum fitted direction to obtain cone fit.
float m_coneTanHalfAngle2
The cone tan half angle to use when calculating bounded cluster fractions 2.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::unordered_map< const pandora::Cluster *, const pandora::ParticleFlowObject * > ClusterToPfoMap
float m_maxVertexTransverseDistance
Pointing association check: max transverse distance cut.
void AssignRemainingHitsToSlices(const pandora::ClusterList &remainingClusters, const ClusterToSliceIndexMap &clusterToSliceIndexMap, SlicingAlgorithm::SliceList &sliceList) const
Use the list of remaining 2D clusters to assign all remaining 2D hits to existing slices in the slice...
float m_coneBoundedFraction2
The minimum cluster bounded fraction for association 2.
std::string m_showerPfoListName
The name of the input shower pfo list.
std::string string
Definition: nybbler.cc:12
Class that implements the KDTree partition of 2D space and a closest point search algorithm...
EventSlicingTool class.
void GetRemainingClusters(const pandora::Algorithm *const pAlgorithm, const SlicingAlgorithm::HitTypeToNameMap &clusterListNames, const pandora::ClusterSet &assignedClusters, pandora::ClusterList &remainingClusters) const
Get the list of 2D clusters with hits yets to be assigned to slices.
bool PassShowerCone(const pandora::Cluster *const pConeCluster, const pandora::Cluster *const pNearbyCluster, const ThreeDSlidingConeFitResultMap &showerConeFitResults) const
Compare the provided clusters to assess whether they are associated via cone fits to the shower clust...
bool PassPointing(const pandora::Cluster *const pClusterInSlice, const pandora::Cluster *const pCandidateCluster, const ThreeDSlidingFitResultMap &trackFitResults) const
Compare the provided clusters to assess whether they are associated via pointing (checks association ...
unsigned int m_minHitsPer3DCluster
The minimum number of hits in a 3D cluster to warrant consideration in slicing.
LArPointingCluster class.
EventSlicingBaseTool class.
float m_coneTanHalfAngle1
The cone tan half angle to use when calculating bounded cluster fractions 1.
void CollectAssociatedClusters(const pandora::Cluster *const pClusterInSlice, const pandora::ClusterVector &candidateClusters, const ThreeDSlidingFitResultMap &trackFitResults, const ThreeDSlidingConeFitResultMap &showerConeFitResults, pandora::ClusterVector &clusterSlice, pandora::ClusterSet &usedClusters) const
Collect all clusters associated with a provided cluster.
const PointKDNode2D * MatchClusterToSlice(const pandora::Cluster *const pCluster2D, PointKDTree2D &kdTree) const
Use the provided kd tree to efficiently identify the most appropriate slice for the provided 2D clust...
Header file for the lar three dimensional sliding cone fit result class.
float m_maxVertexLongitudinalDistance
Pointing association check: max longitudinal distance cut.
Data stored in each KDTree node. The dim1/dim2 fields are usually the duplication of some PFRecHit va...
std::unordered_map< const pandora::CartesianVector *, unsigned int > PointToSliceIndexMap
std::string m_trackPfoListName
The name of the input track pfo list.
KDTreeNodeInfoT< const pandora::CartesianVector *, 2 > PointKDNode2D
bool m_useProximityAssociation
Whether to use proximity association.
float m_maxClosestApproach
Pointing association: max distance of closest approach between straight line fits.
std::unordered_map< const pandora::Cluster *, ThreeDSlidingFitResult > ThreeDSlidingFitResultMap
bool IsNode(const LArPointingCluster &cluster1, const LArPointingCluster &cluster2) const
Check whether a pair of pointing clusters are nodally associated.
static bool SortPoints(const pandora::CartesianVector *const pLhs, const pandora::CartesianVector *const pRhs)
Sort points (use Z, followed by X, followed by Y)
bool m_usePointingAssociation
Whether to use pointing association.
float m_coneLengthMultiplier
The cone length multiplier to use when calculating bounded cluster fractions.
bool PassProximity(const pandora::Cluster *const pClusterInSlice, const pandora::Cluster *const pCandidateCluster) const
Compare the provided clusters to assess whether they are associated via pointing. ...
std::vector< pandora::ClusterVector > ClusterSliceList
void CopyAllHitsToSingleSlice(const pandora::Algorithm *const pAlgorithm, const SlicingAlgorithm::HitTypeToNameMap &caloHitListNames, SlicingAlgorithm::SliceList &sliceList) const
Copy all the input hits in an event into a single slice.
std::unordered_map< const pandora::Cluster *, ThreeDSlidingConeFitResult > ThreeDSlidingConeFitResultMap
std::list< const pandora::CartesianVector * > PointList
bool CheckClosestApproach(const LArPointingCluster &cluster1, const LArPointingCluster &cluster2) const
Check closest approach metrics for a pair of pointing clusters.
std::vector< PointKDNode2D > PointKDNode2DList
std::unordered_map< const pandora::Cluster *, unsigned int > ClusterToSliceIndexMap
EventSlicingTool()
Default constructor.
float m_maxInterceptDistance
Pointing association: max distance from cluster vertex to point of closest approach.
void RunSlicing(const pandora::Algorithm *const pAlgorithm, const SlicingAlgorithm::HitTypeToNameMap &caloHitListNames, const SlicingAlgorithm::HitTypeToNameMap &clusterListNames, SlicingAlgorithm::SliceList &sliceList)
Run the slicing tool.
std::vector< Slice > SliceList
float m_minVertexLongitudinalDistance
Pointing association check: min longitudinal distance cut.
bool IsEmission(const LArPointingCluster &cluster1, const LArPointingCluster &cluster2) const
Check whether a pair of pointing clusters are consistent with an emission.
bool m_use3DProjectionsInHitPickUp
Whether to include 3D cluster projections when assigning remaining clusters to slices.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
float m_maxConeLength
The maximum allowed cone length to use when calculating bounded cluster fractions.
bool m_useShowerConeAssociation
Whether to use shower cone association.
Header file for the master algorithm class.
float m_vertexAngularAllowance
Pointing association check: pointing angular allowance in degrees.
std::map< pandora::HitType, std::string > HitTypeToNameMap
void GetKDTreeEntries2D(const SlicingAlgorithm::SliceList &sliceList, PointList &pointsU, PointList &pointsV, PointList &pointsW, PointToSliceIndexMap &pointToSliceIndexMap) const
Use projections of 3D hits already assigned to slices to populate kd trees to aid assignment of remai...
void GetKDTreeEntries3D(const ClusterToSliceIndexMap &clusterToSliceIndexMap, PointList &pointsU, PointList &pointsV, PointList &pointsW, PointToSliceIndexMap &pointToSliceIndexMap) const
Use 2D hits already assigned to slices to populate kd trees to aid assignment of remaining clusters...
void CreateSlices(const ClusterSliceList &clusterSliceList, SlicingAlgorithm::SliceList &sliceList, ClusterToSliceIndexMap &clusterToSliceIndexMap) const
Create new slices for each of the groupings of 3D clusters in the provided cluster slice list...
float m_coneBoundedFraction1
The minimum cluster bounded fraction for association 1.
unsigned int m_halfWindowLayers
The number of layers to use for half-window of sliding fit.