All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NViewDeltaRayMatchingAlgorithm.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArCosmicRay/NViewDeltaRayMatching.h
3  *
4  * @brief Header file for the n view delta ray matching class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_N_VIEW_DELTA_RAY_MATCHING_ALGORITHM_H
9 #define LAR_N_VIEW_DELTA_RAY_MATCHING_ALGORITHM_H 1
10 
12 
14 
16 
17 namespace lar_content
18 {
19 /**
20  * @brief NViewDeltaRayMatchingAlgorithm class
21  */
22 template <typename T>
24 {
25 public:
26  typedef std::map<const pandora::CaloHit *, const pandora::Cluster *> HitToClusterMap;
27  typedef std::map<const pandora::Cluster *, const pandora::ParticleFlowObject *> ClusterToPfoMap;
28  typedef std::map<const pandora::Cluster *, pandora::ClusterList> ClusterProximityMap;
29 
32  typedef std::vector<HitKDNode2D> HitKDNode2DList;
33 
34  typedef std::vector<pandora::HitType> HitTypeVector;
35 
36  /**
37  * @brief Default constructor
38  */
40 
41  /**
42  * @brief Return the cluster of the common cosmic ray pfo in a given view (function demands there to be only one common CR pfo)
43  *
44  * @param commonMuonPfoList the element's list of common muon pfos
45  * @param hitType the specified view
46  * @param pMuonCluster the output address of the cluster
47  *
48  * @return a status code reflecting if one and only one cosmic ray cluster was found
49  */
50  pandora::StatusCode GetMuonCluster(
51  const pandora::PfoList &commonMuonPfoList, const pandora::HitType hitType, const pandora::Cluster *&pMuonCluster) const;
52 
53  /**
54  * @brief To determine how well three clusters (one in each view) map onto one another expressing this in terms of a chi-squared like parameter
55  *
56  * @param pCluster1 the first cluster
57  * @param pCluster2 the second cluster
58  * @param pCluster3 the third cluster
59  * @param reducedChiSquared the reduced chi squared
60  *
61  * @return a status code reflecting whether the matching procedure ran smoothly and if the outcome is good
62  */
63  pandora::StatusCode PerformThreeViewMatching(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2,
64  const pandora::Cluster *const pCluster3, float &reducedChiSquared) const;
65 
66  /**
67  * @brief To determine how well three clusters (one in each view) map onto one another expressing this in terms of a chi-squared like parameter
68  *
69  * @param pClusterU the U cluster (if the xOverlap object is to be retained this must be the u cluster - for labels to make sense)
70  * @param pClusterV the V cluster
71  * @param pClusterW the W cluster
72  * @param chiSquaredSum the sum of the chi-squared values of the sampled points
73  * @param nSamplingPoints the number of sampled points
74  * @param nMatchedSamplingPoints the number of matched sampled points
75  * @param xOverlap the xOverlap object
76  *
77  * @return a status code reflecting whether the matching procedure ran smoothly and if the outcome is good
78  */
79  pandora::StatusCode PerformThreeViewMatching(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV,
80  const pandora::Cluster *const pClusterW, float &chiSquaredSum, unsigned int &nSamplingPoints, unsigned int &nMatchedSamplingPoints,
81  XOverlap &XOverlap) const;
82 
83  /**
84  * @brief To determine how well three CaloHitLists (one in each view) map onto one another expressing this in terms of a chi-squared like parameter
85  *
86  * @param pCluster1 the first CaloHitList
87  * @param pCluster2 the second CaloHitList
88  * @param pCluster3 the third CaloHitList
89  * @param reducedChiSquared the reduced chi squared
90  *
91  * @return a status code reflecting whether the matching procedure ran smoothly and if the outcome is good
92  */
93  pandora::StatusCode PerformThreeViewMatching(const pandora::CaloHitList &pCluster1, const pandora::CaloHitList &pCluster2,
94  const pandora::CaloHitList &pCluster3, float &reducedChiSquared) const;
95 
96  /**
97  * @brief To determine how well three CaloHitLists (one for each view) map onto one another expressing this in terms of a chi-squared like parameter
98  *
99  * @param clusterU the U CaloHitList (if the xOverlap object is to be retained this must be the u cluster - for labels to make sense)
100  * @param clusterV the V CaloHitList
101  * @param clusterW the W CaloHitList
102  * @param chiSquaredSum the sum of the chi-squared values of the sampled points
103  * @param nSamplingPoints the number of sampled points
104  * @param nMatchedSamplingPoints the number of matched sampled points
105  * @param xOverlap the xOverlap object
106  *
107  * @return a status code reflecting whether the matching procedure ran smoothly and if the outcome is good
108  */
109  pandora::StatusCode PerformThreeViewMatching(const pandora::CaloHitList &clusterU, const pandora::CaloHitList &clusterV,
110  const pandora::CaloHitList &clusterW, float &chiSquaredSum, unsigned int &nSamplingPoints, unsigned int &nMatchedSamplingPoints,
111  XOverlap &XOverlap) const;
112 
113  /**
114  * @brief Use two views of a cosmic ray pfo to calculate projected positions in a given the third view
115  *
116  * @param thirdViewHitType the view to be projected into
117  * @param pParentMuon the input cosmic ray pfo
118  * @param projectedPositions the output projected positions
119  *
120  * @return a status code reflecting whether the procedure ran smoothly and if the outcome is good
121  */
122  pandora::StatusCode ProjectMuonPositions(const pandora::HitType &thirdViewHitType, const pandora::ParticleFlowObject *const pParentMuon,
123  pandora::CartesianPointVector &projectedPositions) const;
124 
125  /**
126  * @brief Use two clusters from different views to calculate projected positions in the remaining third view
127  *
128  * @param pCluster1 the address of the first cluster
129  * @param pCluster2 the address of the second cluster
130  * @param projectedPositions the output projected positions
131  *
132  * @return a status code reflecting whether the procedure ran smoothly and if the outcome is good
133  */
134  pandora::StatusCode GetProjectedPositions(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2,
135  pandora::CartesianPointVector &projectedPositions) const;
136 
137  /**
138  * @brief In one view, pull out any hits from a cosmic ray cluster that belong to the child delta ray cluster
139  *
140  * @param pCluster1 the address of a delta ray cluster in a view that is to go unmodified
141  * @param pCluster2 the address of a delta ray cluster in the other view that is to unmodified
142  * @param pThirdViewCluster the address of the delta ray cluster in the view in which the hit removal process will run
143  * @param pParentMuon the address of the parent cosmic ray pfo
144  * @param minDistanceFromMuon the minimum distance of a hit from the cosmic ray track required for removal
145  * @param maxDistanceToCollected the maximim distance of a hit from the projected delta ray hits required for removal
146  * @param collectedHits the list of hits to be removed from the cosmic ray
147  *
148  * @return a status code reflecting whether the procedure ran smoothly and if the outcome is good
149  */
150  pandora::StatusCode CollectHitsFromMuon(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2,
151  const pandora::Cluster *const pThirdViewCluster, const pandora::ParticleFlowObject *const pParentMuon,
152  const float minDistanceFromMuon, const float maxDistanceToCollected, pandora::CaloHitList &collectedHits) const;
153 
154  /**
155  * @brief In one view, pull out any hits from a cosmic ray cluster that belong to the child delta ray cluster
156  *
157  * @param positionOnMuon the parameterised cosmic ray position
158  * @param muonDirection the parameterised cosmic ray direction
159  * @param pMuon the address of the parent cosmic ray pfo
160  * @param deltaRayProjectedPositions the projected positions of the delta ray
161  * @param minDistanceFromMuon the minimum distance of a hit from the cosmic ray track required for removal
162  * @param maxDistanceToCollected the maximim distance of a hit from the projected delta ray hits required for removal
163  * @param collectedHits the list of hits to be removed from the cosmic ray
164  */
165  void CollectHitsFromMuon(const pandora::CartesianVector &positionOnMuon, const pandora::CartesianVector &muonDirection,
166  const pandora::Cluster *const pMuonCluster, const pandora::CartesianPointVector &deltaRayProjectedPositions,
167  const float &minDistanceFromMuon, const float maxDistanceToCollected, pandora::CaloHitList &collectedHits) const;
168 
169  /**
170  * @brief Parameterise the projection of a cosmic ray track in order to avoid poor/sparse projections
171  *
172  * @param pParentMuon the address of the cosmic ray pfo
173  * @param pDeltaRayCluster the address of the delta ray cluster in the projected view
174  * @param positionOnMuon the output position to localise the parameterisation in space
175  * @param muonDirection the output cosmic ray direction
176  *
177  * @return a status code reflecting whether the procedure ran smoothly and if the outcome is good
178  */
179  pandora::StatusCode ParameteriseMuon(const pandora::ParticleFlowObject *const pParentMuon, const pandora::Cluster *const pDeltaRayCluster,
180  pandora::CartesianVector &positionOnMuon, pandora::CartesianVector &muonDirection) const;
181 
182  /**
183  * @brief Parameterise the projection of a cosmic ray track in order to avoid poor/sparse projections
184  *
185  * @param pParentMuon the address of the cosmic ray pfo
186  * @param deltaRayProjectedPositions the projected positions of the delta ray
187  * @param hitType the view in which the projection is made
188  * @param positionOnMuon the output position to localise the parameterisation in space
189  * @param muonDirection the output cosmic ray direction
190  *
191  * @return a status code reflecting whether the procedure ran smoothly and if the outcome is good
192  */
193  pandora::StatusCode ParameteriseMuon(const pandora::ParticleFlowObject *const pParentMuon, const pandora::CartesianPointVector &deltaRayProjectedPositions,
194  const pandora::HitType hitType, pandora::CartesianVector &positionOnMuon, pandora::CartesianVector &muonDirection) const;
195 
196  /**
197  * @brief Move a list of hits from a cosmic ray cluster into the given child delta ray cluster
198  *
199  * @param clusterListName the pandora list to which the cosmic ray and delta ray clusters belong
200  * @param pMuonCluster the address of the cosmic ray cluster
201  * @param collectedHits the list of hits to reassign
202  * @param pDeltaRayCluster the address of the delta ray cluster (may be a nullptr if cluster is yet to be made)
203  */
204  void SplitMuonCluster(const std::string &clusterListName, const pandora::Cluster *const pMuonCluster,
205  const pandora::CaloHitList &collectedHits, const pandora::Cluster *&pDeltaRayCluster) const;
206 
207  /**
208  * @brief Create delta ray pfos maxmising completeness by searching for and merging in any stray clusters
209  *
210  * @param protoParticleVector the proto particle vector
211  *
212  * @return whether any pfos were created
213  */
214  bool CreatePfos(ProtoParticleVector &protoParticleVector);
215 
216  /**
217  * @brief Add a new cluster to algorithm ownership maps and, if it a delta ray cluster, to the underlying matches container (tensor/matrix)
218  *
219  * @param newClusterVector the vector of clusters to add - the order must match the pfoVector
220  * @param pfoVector the vector of cosmic ray pfos to which the new clusters belong (nullptr for delta ray cluster)
221  */
222  void UpdateForNewClusters(const pandora::ClusterVector &newClusterVector, const pandora::PfoVector &pfoVector);
223 
224  void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster);
225  void SelectInputClusters(const pandora::ClusterList *const pInputClusterList, pandora::ClusterList &selectedClusterList) const;
226  void PrepareInputClusters(pandora::ClusterList &preparedClusterList);
227 
228 protected:
229  /**
230  * @brief To check whether a given cluster meets the requirements to be added into the matching container (tensor/matrix)
231  *
232  * @param pCluster the address of the input cluster
233  *
234  * @return whether the checks were met
235  */
236  virtual bool DoesClusterPassTensorThreshold(const pandora::Cluster *const pCluster) const = 0;
237 
238  /**
239  * @brief Fill the stray cluster list with clusters that do not pass the tensor threshold requirement
240  *
241  * @param hitType the hit type of the list to fill
242  */
243  void FillStrayClusterList(const pandora::HitType hitType);
244 
245  /**
246  * @brief Use the cluster proximity map to travel along paths of nearby clusters finding the cosmic ray clusters on which they terminate
247  *
248  * @param pCluster the address of the input cluster
249  * @param consideredClusters the list of investigated clusters
250  * @param nearbyMuonPfos the output list of the cosmic ray pfos to which the nearby cosmic ray clusters belong
251  */
252  void GetNearbyMuonPfos(const pandora::Cluster *const pCluster, pandora::ClusterList &consideredClusters, pandora::PfoList &nearbyMuonPfos) const;
253 
254  /**
255  * @brief Calculate the xSpan of a list of CaloHits
256  *
257  * @param caloHitList the input list of CaloHits
258  * @param xMin the output minimum x coordinate
259  * @param xMax the output maximum x coordinate
260  */
261  void GetClusterSpanX(const pandora::CaloHitList &caloHitList, float &xMin, float &xMax) const;
262 
263  /**
264  * @brief Calculate the zSpan of a list of CaloHits in a specified x range
265  *
266  * @param caloHitList the input list of CaloHits
267  * @param xMin the minimum x coordinate of the region of interest
268  * @param xMax the maximum x coordinate of the region of interest
269  * @param zMin the output minimum z coordinate
270  * @param zMax the output maximum z coordinate
271  */
272  pandora::StatusCode GetClusterSpanZ(const pandora::CaloHitList &caloHitList, const float xMin, const float xMax, float &zMin, float &zMax) const;
273 
274  /**
275  * @brief Collect the stray clusters that are close to a specified cluster and that lie within a given x range
276  *
277  * @param pClusterToEnlarge the specified cluster
278  * @param rangeMinX the minimum x coordinate of the region of interest
279  * @param rangeMaxX the maximum x coordinate of the region of interest
280  * @param collectedClusters the list of collected stray clusters
281  */
282  void CollectStrayClusters(const pandora::Cluster *const pClusterToEnlarge, const float rangeMinX, const float rangeMaxX,
283  pandora::ClusterList &collectedClusters);
284 
285  /**
286  * @brief Merge in the collected stray clusters of a given delta ray cluster
287  *
288  * @param pClusterToEnlarge the delta ray cluster to enlarge
289  * @param collectedClusters the list of collected stray clusters
290  */
291  void AddInStrayClusters(const pandora::Cluster *const pClusterToEnlarge, const pandora::ClusterList &collectedClusters);
292 
293  void TidyUp();
294  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
295 
296  std::string m_muonPfoListName; ///< The list of reconstructed cosmic ray pfos
297  pandora::ClusterList m_strayClusterListU; ///< The list of U clusters that do not pass the tensor threshold requirement
298  pandora::ClusterList m_strayClusterListV; ///< The list of V clusters that do not pass the tensor threshold requirement
299  pandora::ClusterList m_strayClusterListW; ///< The list of W clusters that do not pass the tensor threshold requirement
300  DeltaRayMatchingContainers m_deltaRayMatchingContainers; ///< The class of hit, cluster and pfo ownership and proximity maps
301  float m_pseudoChi2Cut; ///< Pseudo chi2 cut for three view matching
302  float m_xOverlapWindow; ///< The maximum allowed displacement in x position
303  float m_minMatchedFraction; ///< The threshold matched fraction of sampling points for a good match
304  unsigned int m_minMatchedPoints; ///< The threshold number of matched sampling points for a good match
305  unsigned int m_minProjectedPositions; ///< The threshold number of projected points for a good projection
306  float m_maxCosmicRayHitFraction; ///< The maximum allowed fraction of hits to be removed from the cosmic ray track
307  float m_maxDistanceToCluster; ///< the maximum distance of a projected point to the cosmic ray cluster used when parameterising the cosmic ray cluster
308  float m_maxDistanceToReferencePoint; ///< the maximum distance of a projected point to the cosmic ray vertex used when parameterising the cosmic ray cluster
309  float m_strayClusterSeparation; ///< The maximum allowed separation of a stray cluster and a delta ray cluster for merge
310 };
311 
312 } // namespace lar_content
313 
314 #endif // #ifndef LAR_N_VIEW_DELTA_RAY_MATCHING_ALGORITHM_H
void SelectInputClusters(const pandora::ClusterList *const pInputClusterList, pandora::ClusterList &selectedClusterList) const
Select a subset of input clusters for processing in this algorithm.
std::vector< ProtoParticle > ProtoParticleVector
Header file for the kd tree linker algo template class.
std::map< const pandora::Cluster *, pandora::ClusterList > ClusterProximityMap
NViewMatchingAlgorithm class.
pandora::StatusCode GetProjectedPositions(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, pandora::CartesianPointVector &projectedPositions) const
Use two clusters from different views to calculate projected positions in the remaining third view...
pandora::StatusCode GetClusterSpanZ(const pandora::CaloHitList &caloHitList, const float xMin, const float xMax, float &zMin, float &zMax) const
Calculate the zSpan of a list of CaloHits in a specified x range.
unsigned int m_minProjectedPositions
The threshold number of projected points for a good projection.
pandora::StatusCode CollectHitsFromMuon(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pThirdViewCluster, const pandora::ParticleFlowObject *const pParentMuon, const float minDistanceFromMuon, const float maxDistanceToCollected, pandora::CaloHitList &collectedHits) const
In one view, pull out any hits from a cosmic ray cluster that belong to the child delta ray cluster...
pandora::ClusterList m_strayClusterListU
The list of U clusters that do not pass the tensor threshold requirement.
Header file for the delta ray matching containers class.
void UpdateForNewClusters(const pandora::ClusterVector &newClusterVector, const pandora::PfoVector &pfoVector)
Add a new cluster to algorithm ownership maps and, if it a delta ray cluster, to the underlying match...
void TidyUp()
Tidy member variables in derived class.
float m_pseudoChi2Cut
Pseudo chi2 cut for three view matching.
KDTreeLinkerAlgo< const pandora::CaloHit *, 2 > HitKDTree2D
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster)
Update to reflect cluster deletion.
void PrepareInputClusters(pandora::ClusterList &preparedClusterList)
Perform any preparatory steps required on the input clusters, e.g. caching expensive fit results...
void CollectStrayClusters(const pandora::Cluster *const pClusterToEnlarge, const float rangeMinX, const float rangeMaxX, pandora::ClusterList &collectedClusters)
Collect the stray clusters that are close to a specified cluster and that lie within a given x range...
Header file for the n view matching algorithm class.
void GetClusterSpanX(const pandora::CaloHitList &caloHitList, float &xMin, float &xMax) const
Calculate the xSpan of a list of CaloHits.
Data stored in each KDTree node. The dim1/dim2 fields are usually the duplication of some PFRecHit va...
pandora::StatusCode PerformThreeViewMatching(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3, float &reducedChiSquared) const
To determine how well three clusters (one in each view) map onto one another expressing this in terms...
float m_xOverlapWindow
The maximum allowed displacement in x position.
std::string m_muonPfoListName
The list of reconstructed cosmic ray pfos.
pandora::StatusCode ParameteriseMuon(const pandora::ParticleFlowObject *const pParentMuon, const pandora::Cluster *const pDeltaRayCluster, pandora::CartesianVector &positionOnMuon, pandora::CartesianVector &muonDirection) const
Parameterise the projection of a cosmic ray track in order to avoid poor/sparse projections.
void FillStrayClusterList(const pandora::HitType hitType)
Fill the stray cluster list with clusters that do not pass the tensor threshold requirement.
pandora::ClusterList m_strayClusterListV
The list of V clusters that do not pass the tensor threshold requirement.
pandora::ClusterList m_strayClusterListW
The list of W clusters that do not pass the tensor threshold requirement.
void SplitMuonCluster(const std::string &clusterListName, const pandora::Cluster *const pMuonCluster, const pandora::CaloHitList &collectedHits, const pandora::Cluster *&pDeltaRayCluster) const
Move a list of hits from a cosmic ray cluster into the given child delta ray cluster.
void AddInStrayClusters(const pandora::Cluster *const pClusterToEnlarge, const pandora::ClusterList &collectedClusters)
Merge in the collected stray clusters of a given delta ray cluster.
KDTreeNodeInfoT< const pandora::CaloHit *, 2 > HitKDNode2D
float m_strayClusterSeparation
The maximum allowed separation of a stray cluster and a delta ray cluster for merge.
void GetNearbyMuonPfos(const pandora::Cluster *const pCluster, pandora::ClusterList &consideredClusters, pandora::PfoList &nearbyMuonPfos) const
Use the cluster proximity map to travel along paths of nearby clusters finding the cosmic ray cluster...
virtual bool DoesClusterPassTensorThreshold(const pandora::Cluster *const pCluster) const =0
To check whether a given cluster meets the requirements to be added into the matching container (tens...
float m_maxDistanceToReferencePoint
the maximum distance of a projected point to the cosmic ray vertex used when parameterising the cosmi...
std::map< const pandora::Cluster *, const pandora::ParticleFlowObject * > ClusterToPfoMap
std::vector< art::Ptr< recob::Cluster > > ClusterVector
float m_maxCosmicRayHitFraction
The maximum allowed fraction of hits to be removed from the cosmic ray track.
bool CreatePfos(ProtoParticleVector &protoParticleVector)
Create delta ray pfos maxmising completeness by searching for and merging in any stray clusters...
pandora::StatusCode ProjectMuonPositions(const pandora::HitType &thirdViewHitType, const pandora::ParticleFlowObject *const pParentMuon, pandora::CartesianPointVector &projectedPositions) const
Use two views of a cosmic ray pfo to calculate projected positions in a given the third view...
DeltaRayMatchingContainers m_deltaRayMatchingContainers
The class of hit, cluster and pfo ownership and proximity maps.
XOverlap class.
Definition: LArXOverlap.h:17
std::map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
pandora::StatusCode GetMuonCluster(const pandora::PfoList &commonMuonPfoList, const pandora::HitType hitType, const pandora::Cluster *&pMuonCluster) const
Return the cluster of the common cosmic ray pfo in a given view (function demands there to be only on...
float m_minMatchedFraction
The threshold matched fraction of sampling points for a good match.
unsigned int m_minMatchedPoints
The threshold number of matched sampling points for a good match.
float m_maxDistanceToCluster
the maximum distance of a projected point to the cosmic ray cluster used when parameterising the cosm...