DeltaRayMatchingAlgorithm.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArCosmicRay/DeltaRayMatchingAlgorithm.h
3  *
4  * @brief Header file for the delta ray matching algorithm class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_DELTA_RAY_MATCHING_ALGORITHM_H
9 #define LAR_DELTA_RAY_MATCHING_ALGORITHM_H 1
10 
11 #include "Pandora/Algorithm.h"
12 
14 
15 namespace lar_content
16 {
17 
18 template <typename, unsigned int>
19 class KDTreeLinkerAlgo;
20 template <typename, unsigned int>
21 class KDTreeNodeInfoT;
22 
23 //------------------------------------------------------------------------------------------------------------------------------------------
24 
25 /**
26  * @brief DeltaRayMatchingAlgorithm class
27  */
28 class DeltaRayMatchingAlgorithm : public pandora::Algorithm
29 {
30 public:
31  /**
32  * @brief Default constructor
33  */
35 
36 private:
37  pandora::StatusCode Run();
38 
39  /**
40  * @brief Particle class
41  */
42  class Particle
43  {
44  public:
45  /**
46  * @brief Constructor
47  *
48  * @param pCluster1 the first cluster
49  * @param pCluster2 the second cluster
50  * @param pCluster3 the third cluster
51  * @param pPfo the parent Pfo
52  */
53  Particle(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3,
54  const pandora::ParticleFlowObject *const pPfo);
55 
56  /**
57  * @brief Get cluster in U view
58  */
59  const pandora::Cluster *GetClusterU() const;
60 
61  /**
62  * @brief Get cluster in V view
63  */
64  const pandora::Cluster *GetClusterV() const;
65 
66  /**
67  * @brief Get cluster in W view
68  */
69  const pandora::Cluster *GetClusterW() const;
70 
71  /**
72  * @brief Get parent Pfo
73  */
74  const pandora::ParticleFlowObject *GetParentPfo() const;
75 
76  /**
77  * @brief Get number of views
78  */
79  unsigned int GetNViews() const;
80 
81  /**
82  * @brief Get number of calo hits
83  */
84  unsigned int GetNCaloHits() const;
85 
86  private:
87  const pandora::Cluster *m_pClusterU; ///< Address of cluster in U view
88  const pandora::Cluster *m_pClusterV; ///< Address of cluster in V view
89  const pandora::Cluster *m_pClusterW; ///< Address of cluster in W view
90  const pandora::ParticleFlowObject *m_pParentPfo; ///< Address of parent Pfo
91  };
92 
93  typedef std::vector<Particle> ParticleList;
94 
97  typedef std::vector<HitKDNode2D> HitKDNode2DList;
98 
99  typedef std::unordered_map<const pandora::Cluster *, pandora::ClusterList> ClusterToClustersMap;
100  typedef std::unordered_map<const pandora::CaloHit *, const pandora::Cluster *> HitToClusterMap;
101 
102  /**
103  * @brief Initialize nearby cluster maps
104  */
106 
107  /**
108  * @brief Initialize a nearby cluster map with details relating to a specific cluster list
109  *
110  * @param clusterListName the cluster list name
111  * @param nearbyClustersMap to receive the nearby clusters map
112  */
113  void InitializeNearbyClusterMap(const std::string &clusterListName, ClusterToClustersMap &nearbyClusters);
114 
115  /**
116  * @brief Clear nearby cluster maps
117  */
118  void ClearNearbyClusterMaps();
119 
120  /**
121  * @brief Get a vector of all Pfos in the provided input Pfo lists
122  *
123  * @param inputPfoListName the input Pfo list name
124  * @param pfoVector the output vector of Pfos
125  */
126  void GetAllPfos(const std::string &inputPfoListName, pandora::PfoVector &pfoVector) const;
127 
128  /**
129  * @brief Get a vector of track-like Pfos in the provided input Pfo lists
130  *
131  * @param inputPfoListName the input Pfo list name
132  * @param pfoVector the output vector of Pfos
133  */
134  void GetTrackPfos(const std::string &inputPfoListName, pandora::PfoVector &pfoVector) const;
135 
136  /**
137  * @brief Get a vector containing all available input clusters in the provided cluster list, storing sliding linear fits
138  * in the algorithm cache.
139  *
140  * @param clusterListName the vector of cluster list names
141  * @param clusterVector to receive the populated cluster vector
142  */
143  void GetClusters(const std::string &clusterListName, pandora::ClusterVector &clusterVector) const;
144 
145  typedef std::unordered_map<const pandora::Cluster *, float> ClusterLengthMap;
146  typedef std::unordered_map<const pandora::ParticleFlowObject *, float> PfoLengthMap;
147 
148  /**
149  * @brief Match clusters using all three views
150  *
151  * @param clusterLengthMap the cluster length map
152  */
153  void ThreeViewMatching(ClusterLengthMap &clusterLengthMap) const;
154 
155  /**
156  * @brief Match clusters using pairs of views
157  *
158  * @param clusterLengthMap the cluster length map
159  */
160  void TwoViewMatching(ClusterLengthMap &clusterLengthMap) const;
161 
162  /**
163  * @brief Match clusters using single views
164  *
165  * @param clusterLengthMap the cluster length map
166  */
167  void OneViewMatching(ClusterLengthMap &clusterLengthMap) const;
168 
169  /**
170  * @brief Match clusters using all three views
171  *
172  * @param clusters1 the list of clusters in the first view
173  * @param clusters2 the list of clusters in the second view
174  * @param clusters3 the list of clusters in the third view
175  * @param clusterLengthMap the cluster length map
176  * @param pfoLengthMap the pfo length map
177  * @param particleList the output list of particles
178  */
179  void ThreeViewMatching(const pandora::ClusterVector &clusters1, const pandora::ClusterVector &clusters2,
180  const pandora::ClusterVector &clusters3, ClusterLengthMap &clusterLengthMap, PfoLengthMap &pfoLengthMap, ParticleList &particleList) const;
181 
182  /**
183  * @brief Match clusters using a pair of views
184  *
185  * @param clusters1 the list of clusters in the first view
186  * @param clusters2 the list of clusters in the second view
187  * @param clusterLengthMap the cluster length map
188  * @param pfoLengthMap the pfo length map
189  * @param particleList the output list of particles
190  */
191  void TwoViewMatching(const pandora::ClusterVector &clusters1, const pandora::ClusterVector &clusters2,
192  ClusterLengthMap &clusterLengthMap, PfoLengthMap &pfoLengthMap, ParticleList &particleList) const;
193 
194  /**
195  * @brief Match clusters using a single view
196  *
197  * @param clusters the list of clusters in the provided view
198  * @param clusterLengthMap the cluster length map
199  * @param pfoLengthMap the pfo length map
200  * @param particleList the output list of particles
201  */
202  void OneViewMatching(const pandora::ClusterVector &clusters, ClusterLengthMap &clusterLengthMap, PfoLengthMap &pfoLengthMap,
203  ParticleList &particleList) const;
204 
205  /**
206  * @brief Resolve any ambiguities between candidate particles
207  *
208  * @param inputParticles the input list of candidate particles
209  * @param clusterLengthMap the cluster length map
210  * @param outputParticles the output list of candidate particles
211  */
212  void SelectParticles(const ParticleList &inputParticles, ClusterLengthMap &clusterLengthMap, ParticleList &outputParticles) const;
213 
214  /**
215  * @brief Build new particle flow objects
216  *
217  * @param particleList the list of candidate particles
218  */
219  void CreateParticles(const ParticleList &particleList) const;
220 
221  /**
222  * @brief Find best Pfo to associate a UVW triplet
223  *
224  * @param pClusterU pointer to U view cluster
225  * @param pClusterV pointer to V view cluster
226  * @param pClusterW pointer to W view cluster
227  * @param clusterLengthMap the cluster length map
228  * @param pfoLengthMap the pfo length map
229  * @param pBestPfo to receive the address of the best Pfo
230  */
231  void FindBestParentPfo(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW,
232  ClusterLengthMap &clusterLengthMap, PfoLengthMap &pfoLengthMap, const pandora::ParticleFlowObject *&pBestPfo) const;
233 
234  /**
235  * @brief Reduce number of length (squared) calculations by caching results when they are first obtained
236  *
237  * @param pCluster the cluster
238  * @param clusterLengthMap the cluster length map
239  *
240  * @return the length (squared)
241  */
242  float GetLengthFromCache(const pandora::Cluster *const pCluster, ClusterLengthMap &clusterLengthMap) const;
243 
244  /**
245  * @brief Reduce number of length (squared) calculations by caching results when they are first obtained
246  *
247  * @param pPfo the pfo
248  * @param pfoLengthMap the pfo length map
249  *
250  * @return the length (squared)
251  */
252  float GetLengthFromCache(const pandora::ParticleFlowObject *const pPfo, PfoLengthMap &pfoLengthMap) const;
253 
254  /**
255  * @brief Get the length (squared) of a candidate particle
256  *
257  * @param particle the particle
258  * @param clusterLengthMap the cluster length map
259  *
260  * @return the length (squared)
261  */
262  float GetLength(const Particle &particle, ClusterLengthMap &clusterLengthMap) const;
263 
264  /**
265  * @brief Look at consistency of a combination of clusters
266  *
267  * @param pCluster1 pointer to first luster
268  * @param pCluster2 pointer to second cluster
269  * @param pCluster3 pointer to third cluster
270  */
271  bool AreClustersMatched(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3) const;
272 
273  /**
274  * @brief Get displacementr between cluster and particle flow object
275  *
276  * @param pCluster pointer to cluster
277  * @param pPfo pointer to particle flow object
278  */
279  float GetDistanceSquaredToPfo(const pandora::Cluster *const pCluster, const pandora::ParticleFlowObject *const pPfo) const;
280 
281  /**
282  * @brief Create a new Pfo from an input cluster list and set up a parent/daughter relationship
283  *
284  * @param clusterList the list of clusters
285  * @param pParentPfo address of the parent pfo
286  */
287  void CreateDaughterPfo(const pandora::ClusterList &clusterList, const pandora::ParticleFlowObject *const pParentPfo) const;
288 
289  /**
290  * @brief Merge an input cluster list with an existing daughter Pfo
291  *
292  * @param clusterList the list of clusters
293  * @param pParentPfo address of the parent pfo
294  */
295  void AddToDaughterPfo(const pandora::ClusterList &clusterList, const pandora::ParticleFlowObject *const pParentPfo) const;
296 
297  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
298 
299  std::string m_parentPfoListName; ///< The parent pfo list name
300  std::string m_daughterPfoListName; ///< The daughter pfo list name for new daughter particles
301 
302  std::string m_inputClusterListNameU; ///< The input cluster list name for the u view
303  std::string m_inputClusterListNameV; ///< The input cluster list name for the v view
304  std::string m_inputClusterListNameW; ///< The input cluster list name for the w view
305 
306  unsigned int m_minCaloHitsPerCluster; ///< The min number of calo hits per candidate cluster
307  float m_xOverlapWindow; ///< The maximum allowed displacement in x position
308  float m_distanceForMatching; ///< The maximum allowed distance between tracks and delta rays
309  float m_pseudoChi2Cut; ///< Pseudo chi2 cut for three view matching
310 
311  float m_searchRegion1D; ///< Search region, applied to each dimension, for look-up from kd-trees
312  ClusterToClustersMap m_nearbyClustersU; ///< The nearby clusters map for the u view
313  ClusterToClustersMap m_nearbyClustersV; ///< The nearby clusters map for the v view
314  ClusterToClustersMap m_nearbyClustersW; ///< The nearby clusters map for the w view
315 };
316 
317 //------------------------------------------------------------------------------------------------------------------------------------------
318 //------------------------------------------------------------------------------------------------------------------------------------------
319 
320 inline const pandora::Cluster *DeltaRayMatchingAlgorithm::Particle::GetClusterU() const
321 {
322  return m_pClusterU;
323 }
324 
325 //------------------------------------------------------------------------------------------------------------------------------------------
326 inline const pandora::Cluster *DeltaRayMatchingAlgorithm::Particle::GetClusterV() const
327 {
328  return m_pClusterV;
329 }
330 
331 //------------------------------------------------------------------------------------------------------------------------------------------
332 inline const pandora::Cluster *DeltaRayMatchingAlgorithm::Particle::GetClusterW() const
333 {
334  return m_pClusterW;
335 }
336 
337 //------------------------------------------------------------------------------------------------------------------------------------------
338 inline const pandora::ParticleFlowObject *DeltaRayMatchingAlgorithm::Particle::GetParentPfo() const
339 {
340  return m_pParentPfo;
341 }
342 
343 } // namespace lar_content
344 
345 #endif // #ifndef LAR_DELTA_RAY_MATCHING_ALGORITHM_H
void InitializeNearbyClusterMap(const std::string &clusterListName, ClusterToClustersMap &nearbyClusters)
Initialize a nearby cluster map with details relating to a specific cluster list. ...
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
float m_xOverlapWindow
The maximum allowed displacement in x position.
float m_pseudoChi2Cut
Pseudo chi2 cut for three view matching.
std::unordered_map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
std::unordered_map< const pandora::Cluster *, float > ClusterLengthMap
const pandora::Cluster * GetClusterV() const
Get cluster in V view.
Particle(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3, const pandora::ParticleFlowObject *const pPfo)
Constructor.
void GetTrackPfos(const std::string &inputPfoListName, pandora::PfoVector &pfoVector) const
Get a vector of track-like Pfos in the provided input Pfo lists.
ClusterToClustersMap m_nearbyClustersU
The nearby clusters map for the u view.
void TwoViewMatching(ClusterLengthMap &clusterLengthMap) const
Match clusters using pairs of views.
ClusterToClustersMap m_nearbyClustersV
The nearby clusters map for the v view.
std::string string
Definition: nybbler.cc:12
void CreateParticles(const ParticleList &particleList) const
Build new particle flow objects.
ClusterToClustersMap m_nearbyClustersW
The nearby clusters map for the w view.
unsigned int GetNCaloHits() const
Get number of calo hits.
unsigned int m_minCaloHitsPerCluster
The min number of calo hits per candidate cluster.
std::string m_inputClusterListNameV
The input cluster list name for the v view.
Data stored in each KDTree node. The dim1/dim2 fields are usually the duplication of some PFRecHit va...
const pandora::Cluster * m_pClusterU
Address of cluster in U view.
void GetAllPfos(const std::string &inputPfoListName, pandora::PfoVector &pfoVector) const
Get a vector of all Pfos in the provided input Pfo lists.
std::string m_parentPfoListName
The parent pfo list name.
std::string m_inputClusterListNameW
The input cluster list name for the w view.
float m_searchRegion1D
Search region, applied to each dimension, for look-up from kd-trees.
void OneViewMatching(ClusterLengthMap &clusterLengthMap) const
Match clusters using single views.
std::unordered_map< const pandora::ParticleFlowObject *, float > PfoLengthMap
void ThreeViewMatching(ClusterLengthMap &clusterLengthMap) const
Match clusters using all three views.
Header file for the lar two dimensional sliding fit result class.
void InitializeNearbyClusterMaps()
Initialize nearby cluster maps.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterToClustersMap
KDTreeLinkerAlgo< const pandora::CaloHit *, 2 > HitKDTree2D
float GetDistanceSquaredToPfo(const pandora::Cluster *const pCluster, const pandora::ParticleFlowObject *const pPfo) const
Get displacementr between cluster and particle flow object.
bool AreClustersMatched(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3) const
Look at consistency of a combination of clusters.
const pandora::ParticleFlowObject * GetParentPfo() const
Get parent Pfo.
void FindBestParentPfo(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, ClusterLengthMap &clusterLengthMap, PfoLengthMap &pfoLengthMap, const pandora::ParticleFlowObject *&pBestPfo) const
Find best Pfo to associate a UVW triplet.
void AddToDaughterPfo(const pandora::ClusterList &clusterList, const pandora::ParticleFlowObject *const pParentPfo) const
Merge an input cluster list with an existing daughter Pfo.
std::string m_inputClusterListNameU
The input cluster list name for the u view.
float m_distanceForMatching
The maximum allowed distance between tracks and delta rays.
const pandora::Cluster * GetClusterW() const
Get cluster in W view.
void CreateDaughterPfo(const pandora::ClusterList &clusterList, const pandora::ParticleFlowObject *const pParentPfo) const
Create a new Pfo from an input cluster list and set up a parent/daughter relationship.
KDTreeNodeInfoT< const pandora::CaloHit *, 2 > HitKDNode2D
float GetLength(const Particle &particle, ClusterLengthMap &clusterLengthMap) const
Get the length (squared) of a candidate particle.
const pandora::ParticleFlowObject * m_pParentPfo
Address of parent Pfo.
void ClearNearbyClusterMaps()
Clear nearby cluster maps.
void SelectParticles(const ParticleList &inputParticles, ClusterLengthMap &clusterLengthMap, ParticleList &outputParticles) const
Resolve any ambiguities between candidate particles.
const pandora::Cluster * m_pClusterV
Address of cluster in V view.
void GetClusters(const std::string &clusterListName, pandora::ClusterVector &clusterVector) const
Get a vector containing all available input clusters in the provided cluster list, storing sliding linear fits in the algorithm cache.
float GetLengthFromCache(const pandora::Cluster *const pCluster, ClusterLengthMap &clusterLengthMap) const
Reduce number of length (squared) calculations by caching results when they are first obtained...
std::vector< art::Ptr< recob::Cluster > > ClusterVector
const pandora::Cluster * m_pClusterW
Address of cluster in W view.
const pandora::Cluster * GetClusterU() const
Get cluster in U view.
unsigned int GetNViews() const
Get number of views.
std::string m_daughterPfoListName
The daughter pfo list name for new daughter particles.