ThreeViewShowersAlgorithm.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArShowerMatching/ThreeViewShowersAlgorithm.h
3  *
4  * @brief Header file for the three view showers algorithm class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_THREE_VIEW_SHOWERS_ALGORITHM_H
9 #define LAR_THREE_VIEW_SHOWERS_ALGORITHM_H 1
10 
11 #include "Pandora/Algorithm.h"
12 
15 
18 
19 namespace lar_content
20 {
21 
22 class ShowerTensorTool;
23 
24 //------------------------------------------------------------------------------------------------------------------------------------------
25 
26 /**
27  * @brief ThreeViewShowersAlgorithm class
28  */
29 class ThreeViewShowersAlgorithm : public NViewMatchingAlgorithm<ThreeViewMatchingControl<ShowerOverlapResult>>
30 {
31 public:
33 
34  /**
35  * @brief Default constructor
36  */
38 
39  /**
40  * @brief Get a sliding shower fit result from the algorithm cache
41  *
42  * @param pCluster address of the relevant cluster
43  */
44  const TwoDSlidingShowerFitResult &GetCachedSlidingFitResult(const pandora::Cluster *const pCluster) const;
45 
46  void UpdateForNewCluster(const pandora::Cluster *const pNewCluster);
47  void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster);
48  void SelectInputClusters(const pandora::ClusterList *const pInputClusterList, pandora::ClusterList &selectedClusterList) const;
49  void PrepareInputClusters(pandora::ClusterList &preparedClusterList);
50 
51 private:
52  /**
53  * @brief XSampling class
54  */
55  class XSampling
56  {
57  public:
58  /**
59  * @brief Constructor
60  *
61  * @param fitResultU the sliding fit result for the u view
62  * @param fitResultV the sliding fit result for the v view
63  * @param fitResultW the sliding fit result for the w view
64  */
65  XSampling(const TwoDSlidingFitResult &fitResultU, const TwoDSlidingFitResult &fitResultV, const TwoDSlidingFitResult &fitResultW);
66 
67  /**
68  * @brief Convert an x position into a sampling bin
69  *
70  * @param x the input x coordinate
71  * @param xBin to receive the x bin
72  *
73  * @return status code, faster than throwing in regular use-cases
74  */
75  pandora::StatusCode GetBin(const float x, int &xBin) const;
76 
77  float m_uMinX; ///< The min x value in the u view
78  float m_uMaxX; ///< The max x value in the u view
79  float m_vMinX; ///< The min x value in the v view
80  float m_vMaxX; ///< The max x value in the v view
81  float m_wMinX; ///< The min x value in the w view
82  float m_wMaxX; ///< The max x value in the w view
83  float m_minX; ///< The min x value of the common x-overlap range
84  float m_maxX; ///< The max x value of the common x-overlap range
85  float m_xOverlapSpan; ///< The x-overlap span
86  float m_nPoints; ///< The number of sampling points to be used
87  };
88 
89  void TidyUp();
90 
91  /**
92  * @brief Add a new sliding fit result, for the specified cluster, to the algorithm cache
93  *
94  * @param pCluster address of the relevant cluster
95  */
96  void AddToSlidingFitCache(const pandora::Cluster *const pCluster);
97 
98  /**
99  * @brief Remova an existing sliding fit result, for the specified cluster, from the algorithm cache
100  *
101  * @param pCluster address of the relevant cluster
102  */
103  void RemoveFromSlidingFitCache(const pandora::Cluster *const pCluster);
104 
105  void CalculateOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW);
106 
107  /**
108  * @brief Calculate the overlap result for given group of clusters
109  *
110  * @param pClusterU the cluster from the U view
111  * @param pClusterV the cluster from the V view
112  * @param pClusterW the cluster from the W view
113  * @param overlapResult to receive the overlap result
114  */
115  pandora::StatusCode CalculateOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV,
116  const pandora::Cluster *const pClusterW, ShowerOverlapResult &overlapResult);
117 
118  typedef std::pair<ShowerPositionMap, ShowerPositionMap> ShowerPositionMapPair;
119 
120  /**
121  * @brief Get the shower position maps
122  *
123  * @param fitResultU the sliding shower fit result for the u view
124  * @param fitResultV the sliding shower fit result for the v view
125  * @param fitResultW the sliding shower fit result for the w view
126  * @param xSampling the x sampling details
127  * @param positionMapsU to receive the shower position maps for the u view
128  * @param positionMapsV to receive the shower position maps for the v view
129  * @param positionMapsW to receive the shower position maps for the w view
130  */
131  void GetShowerPositionMaps(const TwoDSlidingShowerFitResult &fitResultU, const TwoDSlidingShowerFitResult &fitResultV,
132  const TwoDSlidingShowerFitResult &fitResultW, const XSampling &xSampling, ShowerPositionMapPair &positionMapsU,
133  ShowerPositionMapPair &positionMapsV, ShowerPositionMapPair &positionMapsW) const;
134 
135  /**
136  * @brief Get the best fraction of hits, in the common x-overlap range, contained within the provided pair of shower boundaries
137  *
138  * @param pCluster the address of the candidate cluster
139  * @param xSampling the x sampling details
140  * @param positionMaps the shower edge position maps
141  * @param nSampledHits to receive the number of hits in the common x-overlap range
142  * @param nMatchedHits to receive the number of sampled hits contained within the shower edges
143  */
144  void GetBestHitOverlapFraction(const pandora::Cluster *const pCluster, const XSampling &xSampling,
145  const ShowerPositionMapPair &positionMaps, unsigned int &nSampledHits, unsigned int &nMatchedHits) const;
146 
148  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
149 
150  typedef std::vector<ShowerTensorTool *> TensorToolVector;
151  TensorToolVector m_algorithmToolVector; ///< The algorithm tool vector
152  unsigned int m_nMaxTensorToolRepeats; ///< The maximum number of repeat loops over tensor tools
153 
154  unsigned int m_slidingFitWindow; ///< The layer window for the sliding linear fits
155  TwoDSlidingShowerFitResultMap m_slidingFitResultMap; ///< The sliding shower fit result map
156 
157  bool m_ignoreUnavailableClusters; ///< Whether to ignore (skip-over) unavailable clusters
158  unsigned int m_minClusterCaloHits; ///< The min number of hits in base cluster selection method
159  float m_minClusterLengthSquared; ///< The min length (squared) in base cluster selection method
160 
161  float m_minShowerMatchedFraction; ///< The minimum shower matched sampling fraction to allow shower grouping
162  unsigned int m_minShowerMatchedPoints; ///< The minimum number of matched shower sampling points to allow shower grouping
163  bool m_visualize; ///< Visualize cluster matching procedure
164 };
165 
166 //------------------------------------------------------------------------------------------------------------------------------------------
167 
168 /**
169  * @brief ShowerTensorTool class
170  */
171 class ShowerTensorTool : public pandora::AlgorithmTool
172 {
173 public:
175  typedef std::vector<TensorType::ElementList::const_iterator> IteratorList;
176 
177  /**
178  * @brief Run the algorithm tool
179  *
180  * @param pAlgorithm address of the calling algorithm
181  * @param overlapTensor the overlap tensor
182  *
183  * @return whether changes have been made by the tool
184  */
185  virtual bool Run(ThreeViewShowersAlgorithm *const pAlgorithm, TensorType &overlapTensor) = 0;
186 };
187 
188 } // namespace lar_content
189 
190 #endif // #ifndef LAR_THREE_VIEW_SHOWERS_ALGORITHM_H
pandora::StatusCode GetBin(const float x, int &xBin) const
Convert an x position into a sampling bin.
Header file for the lar two dimensional sliding shower fit result class.
NViewMatchingAlgorithm class.
std::vector< ShowerTensorTool * > TensorToolVector
TensorToolVector m_algorithmToolVector
The algorithm tool vector.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
unsigned int m_nMaxTensorToolRepeats
The maximum number of repeat loops over tensor tools.
XSampling(const TwoDSlidingFitResult &fitResultU, const TwoDSlidingFitResult &fitResultV, const TwoDSlidingFitResult &fitResultW)
Constructor.
NViewMatchingAlgorithm< ThreeViewMatchingControl< ShowerOverlapResult > > BaseAlgorithm
void RemoveFromSlidingFitCache(const pandora::Cluster *const pCluster)
Remova an existing sliding fit result, for the specified cluster, from the algorithm cache...
Header file for the n view matching algorithm class.
float m_minX
The min x value of the common x-overlap range.
void AddToSlidingFitCache(const pandora::Cluster *const pCluster)
Add a new sliding fit result, for the specified cluster, to the algorithm cache.
void CalculateOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW)
Calculate cluster overlap result and store in container.
std::pair< ShowerPositionMap, ShowerPositionMap > ShowerPositionMapPair
void SelectInputClusters(const pandora::ClusterList *const pInputClusterList, pandora::ClusterList &selectedClusterList) const
Select a subset of input clusters for processing in this algorithm.
std::vector< TensorType::ElementList::const_iterator > IteratorList
TwoDSlidingShowerFitResultMap m_slidingFitResultMap
The sliding shower fit result map.
unsigned int m_minClusterCaloHits
The min number of hits in base cluster selection method.
ThreeViewShowersAlgorithm::MatchingType::TensorType TensorType
unsigned int m_minShowerMatchedPoints
The minimum number of matched shower sampling points to allow shower grouping.
float m_minClusterLengthSquared
The min length (squared) in base cluster selection method.
void ExamineOverlapContainer()
Examine contents of overlap container, collect together best-matching 2D particles and modify cluster...
void PrepareInputClusters(pandora::ClusterList &preparedClusterList)
Perform any preparatory steps required on the input clusters, e.g. caching expensive fit results...
bool m_visualize
Visualize cluster matching procedure.
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
Header file for the lar shower overlap result class.
void GetShowerPositionMaps(const TwoDSlidingShowerFitResult &fitResultU, const TwoDSlidingShowerFitResult &fitResultV, const TwoDSlidingShowerFitResult &fitResultW, const XSampling &xSampling, ShowerPositionMapPair &positionMapsU, ShowerPositionMapPair &positionMapsV, ShowerPositionMapPair &positionMapsW) const
Get the shower position maps.
void UpdateForNewCluster(const pandora::Cluster *const pNewCluster)
Update to reflect addition of a new cluster to the problem space.
bool m_ignoreUnavailableClusters
Whether to ignore (skip-over) unavailable clusters.
void TidyUp()
Tidy member variables in derived class.
void GetBestHitOverlapFraction(const pandora::Cluster *const pCluster, const XSampling &xSampling, const ShowerPositionMapPair &positionMaps, unsigned int &nSampledHits, unsigned int &nMatchedHits) const
Get the best fraction of hits, in the common x-overlap range, contained within the provided pair of s...
float m_nPoints
The number of sampling points to be used.
float m_minShowerMatchedFraction
The minimum shower matched sampling fraction to allow shower grouping.
float m_maxX
The max x value of the common x-overlap range.
Header file for the three view matching control class.
std::unordered_map< const pandora::Cluster *, TwoDSlidingShowerFitResult > TwoDSlidingShowerFitResultMap
list x
Definition: train.py:276
const TwoDSlidingShowerFitResult & GetCachedSlidingFitResult(const pandora::Cluster *const pCluster) const
Get a sliding shower fit result from the algorithm cache.
void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster)
Update to reflect cluster deletion.