TrackClusterCreationAlgorithm.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArTwoDReco/LArClusterCreation/TrackClusterCreationAlgorithm.h
3  *
4  * @brief Header file for the cluster creation algorithm class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_TRACK_CLUSTER_CREATION_ALGORITHM_H
9 #define LAR_TRACK_CLUSTER_CREATION_ALGORITHM_H 1
10 
11 #include "Pandora/Algorithm.h"
12 
13 #include <unordered_map>
14 
15 namespace lar_content
16 {
17 
18 /**
19  * @brief TrackClusterCreationAlgorithm class
20  */
21 class TrackClusterCreationAlgorithm : public pandora::Algorithm
22 {
23 public:
24  /**
25  * @brief Default constructor
26  */
28 
29 private:
30  /**
31  * @brief HitAssociation class
32  */
34  {
35  public:
36  /**
37  * @brief Constructor
38  *
39  * @param pPrimaryTarget address of the primary target hit
40  * @param primaryDistanceSquared distance to the primary target hit squared
41  */
42  HitAssociation(const pandora::CaloHit *const pPrimaryTarget, const float primaryDistanceSquared);
43 
44  /**
45  * @brief Set secondary target
46  *
47  * @param pSecondaryTarget address of the secondary target hit
48  * @param secondaryDistanceSquared distance to the primary target hit squared
49  */
50  void SetSecondaryTarget(const pandora::CaloHit *const pSecondaryTarget, const float secondaryDistanceSquared);
51 
52  /**
53  * @brief Get the primary target
54  *
55  * @return the target distance
56  */
57  const pandora::CaloHit *GetPrimaryTarget() const;
58 
59  /**
60  * @brief Get the secondary target
61  *
62  * @return the secondary target
63  */
64  const pandora::CaloHit *GetSecondaryTarget() const;
65 
66  /**
67  * @brief Get the primary distance squared
68  *
69  * @return the primary distance squared
70  */
71  float GetPrimaryDistanceSquared() const;
72 
73  /**
74  * @brief Get the secondary distance squared
75  *
76  * @return the secondary distance squared
77  */
78  float GetSecondaryDistanceSquared() const;
79 
80  private:
81  const pandora::CaloHit *m_pPrimaryTarget; ///< the primary target
82  const pandora::CaloHit *m_pSecondaryTarget; ///< the secondary target
83  float m_primaryDistanceSquared; ///< the primary distance squared
84  float m_secondaryDistanceSquared; ///< the secondary distance squared
85  };
86 
87  typedef std::unordered_map<const pandora::CaloHit *, HitAssociation> HitAssociationMap;
88  typedef std::unordered_map<const pandora::CaloHit *, const pandora::CaloHit *> HitJoinMap;
89  typedef std::unordered_map<const pandora::CaloHit *, const pandora::Cluster *> HitToClusterMap;
90 
91  pandora::StatusCode Run();
92  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
93 
94  /**
95  * @brief Filter out low pulse height hits in close proximity to high pulse height hits
96  *
97  * @param pCaloHitList input hit list
98  * @param selectedCaloHitList the output selected list of selected hits
99  * @param rejectedCaloHitList the output rejected list of rejected hits
100  */
101  pandora::StatusCode FilterCaloHits(const pandora::CaloHitList *const pCaloHitList, pandora::OrderedCaloHitList &selectedCaloHitList,
102  pandora::OrderedCaloHitList &rejectedCaloHitList) const;
103 
104  /**
105  * @brief Merge previously filtered hits back into their associated clusters
106  *
107  * @param selectedCaloHitList the ordered list of selected hits
108  * @param rejectedCaloHitList the ordered list of rejected hits
109  * @param hitToClusterMap the mapping between hits and their clusters
110  */
111  pandora::StatusCode AddFilteredCaloHits(const pandora::OrderedCaloHitList &selectedCaloHitList,
112  const pandora::OrderedCaloHitList &rejectedCaloHitList, HitToClusterMap &hitToClusterMap) const;
113 
114  /**
115  * @brief Control primary association formation
116  *
117  * @param orderedCaloHitList the ordered calo hit list
118  * @param forwardHitAssociationMap the forward hit association map
119  * @param backwardHitAssociationMap the backward hit association map
120  */
121  void MakePrimaryAssociations(const pandora::OrderedCaloHitList &orderedCaloHitList, HitAssociationMap &forwardHitAssociationMap,
122  HitAssociationMap &backwardHitAssociationMap) const;
123 
124  /**
125  * @brief Control secondary association formation
126  *
127  * @param orderedCaloHitList the ordered calo hit list
128  * @param forwardHitAssociationMap the forward hit association map
129  * @param backwardHitAssociationMap the backward hit association map
130  */
131  void MakeSecondaryAssociations(const pandora::OrderedCaloHitList &orderedCaloHitList, HitAssociationMap &forwardHitAssociationMap,
132  HitAssociationMap &backwardHitAssociationMap) const;
133 
134  /**
135  * @brief Identify final hit joins for use in cluster formation
136  *
137  * @param orderedCaloHitList the ordered calo hit list
138  * @param forwardHitAssociationMap the forward hit association map
139  * @param backwardHitAssociationMap the backward hit association map
140  * @param hitJoinMap to receive the hit join map
141  */
142  void IdentifyJoins(const pandora::OrderedCaloHitList &orderedCaloHitList, const HitAssociationMap &forwardHitAssociationMap,
143  const HitAssociationMap &backwardHitAssociationMap, HitJoinMap &hitJoinMap) const;
144 
145  /**
146  * @brief Final cluster formation
147  *
148  * @param orderedCaloHitList the ordered calo hit list
149  * @param hitJoinMap the hit join map
150  * @param hitToClusterMap the mapping between hits and their clusters
151  */
152  void CreateClusters(const pandora::OrderedCaloHitList &orderedCaloHitList, const HitJoinMap &hitJoinMap, HitToClusterMap &hitToClusterMap) const;
153 
154  /**
155  * @brief Create primary association if appropriate, hitI<->hitJ
156  *
157  * @param pCaloHitI address of calo hit I
158  * @param pCaloHitJ address of calo hit J
159  * @param forwardHitAssociationMap the forward hit association map
160  * @param backwardHitAssociationMap the backward hit association map
161  */
162  void CreatePrimaryAssociation(const pandora::CaloHit *const pCaloHitI, const pandora::CaloHit *const pCaloHitJ,
163  HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const;
164 
165  /**
166  * @brief Create secondary association if appropriate, hitI<->hitJ
167  *
168  * @param pCaloHitI address of calo hit I
169  * @param pCaloHitJ address of calo hit J
170  * @param forwardHitAssociationMap the forward hit association map
171  * @param backwardHitAssociationMap the backward hit association map
172  */
173  void CreateSecondaryAssociation(const pandora::CaloHit *const pCaloHitI, const pandora::CaloHit *const pCaloHitJ,
174  HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const;
175 
176  /**
177  * @brief Get hit to join by tracing associations via map I, checking via map J
178  *
179  * @param pCaloHit the initial calo hit
180  * @param hitAssociationMapI hit association map I
181  * @param hitAssociationMapJ hit association map J
182  *
183  * @return the hit to join
184  */
185  const pandora::CaloHit *GetJoinHit(const pandora::CaloHit *const pCaloHit, const HitAssociationMap &hitAssociationMapI,
186  const HitAssociationMap &hitAssociationMapJ) const;
187 
188  /**
189  * @brief Get last hit obtained by tracing associations via map I, checking via map J
190  *
191  * @param pCaloHit the initial calo hit
192  * @param hitAssociationMapI hit association map I
193  * @param hitAssociationMapJ hit association map J
194  * @param nSteps to receive the number of association steps
195  *
196  * @return the last hit obtained in the chain of associations
197  */
198  const pandora::CaloHit *TraceHitAssociation(const pandora::CaloHit *const pCaloHit, const HitAssociationMap &hitAssociationMapI,
199  const HitAssociationMap &hitAssociationMapJ, unsigned int &nSteps) const;
200 
201  bool m_mergeBackFilteredHits; ///< Merge rejected hits into their associated clusters
202  unsigned int m_maxGapLayers; ///< Maximum number of layers for a gap
203  float m_maxCaloHitSeparationSquared; ///< Square of maximum calo hit separation
204  float m_minCaloHitSeparationSquared; ///< Square of minimum calo hit separation
205  float m_closeSeparationSquared; ///< Length scale (squared) for close hit separation
206 };
207 
208 //------------------------------------------------------------------------------------------------------------------------------------------
209 
210 inline TrackClusterCreationAlgorithm::HitAssociation::HitAssociation(const pandora::CaloHit *const pPrimaryTarget, const float primaryDistanceSquared) :
211  m_pPrimaryTarget(pPrimaryTarget),
212  m_pSecondaryTarget(NULL),
213  m_primaryDistanceSquared(primaryDistanceSquared),
214  m_secondaryDistanceSquared(std::numeric_limits<float>::max())
215 {
216 }
217 
218 //------------------------------------------------------------------------------------------------------------------------------------------
219 
220 inline void TrackClusterCreationAlgorithm::HitAssociation::SetSecondaryTarget(const pandora::CaloHit *const pSecondaryTarget, const float secondaryDistanceSquared)
221 {
222  m_pSecondaryTarget = pSecondaryTarget;
223  m_secondaryDistanceSquared = secondaryDistanceSquared;
224 }
225 
226 //------------------------------------------------------------------------------------------------------------------------------------------
227 
229 {
230  return m_pPrimaryTarget;
231 }
232 
233 //------------------------------------------------------------------------------------------------------------------------------------------
234 
236 {
237  return m_pSecondaryTarget;
238 }
239 
240 //------------------------------------------------------------------------------------------------------------------------------------------
241 
243 {
245 }
246 
247 //------------------------------------------------------------------------------------------------------------------------------------------
248 
250 {
252 }
253 
254 } // namespace lar_content
255 
256 #endif // #ifndef LAR_TRACK_CLUSTER_CREATION_ALGORITHM_H
const pandora::CaloHit * m_pSecondaryTarget
the secondary target
std::unordered_map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
pandora::StatusCode FilterCaloHits(const pandora::CaloHitList *const pCaloHitList, pandora::OrderedCaloHitList &selectedCaloHitList, pandora::OrderedCaloHitList &rejectedCaloHitList) const
Filter out low pulse height hits in close proximity to high pulse height hits.
float m_maxCaloHitSeparationSquared
Square of maximum calo hit separation.
STL namespace.
pandora::StatusCode AddFilteredCaloHits(const pandora::OrderedCaloHitList &selectedCaloHitList, const pandora::OrderedCaloHitList &rejectedCaloHitList, HitToClusterMap &hitToClusterMap) const
Merge previously filtered hits back into their associated clusters.
void IdentifyJoins(const pandora::OrderedCaloHitList &orderedCaloHitList, const HitAssociationMap &forwardHitAssociationMap, const HitAssociationMap &backwardHitAssociationMap, HitJoinMap &hitJoinMap) const
Identify final hit joins for use in cluster formation.
float GetSecondaryDistanceSquared() const
Get the secondary distance squared.
std::unordered_map< const pandora::CaloHit *, HitAssociation > HitAssociationMap
void MakePrimaryAssociations(const pandora::OrderedCaloHitList &orderedCaloHitList, HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const
Control primary association formation.
const pandora::CaloHit * GetPrimaryTarget() const
Get the primary target.
std::unordered_map< const pandora::CaloHit *, const pandora::CaloHit * > HitJoinMap
float GetPrimaryDistanceSquared() const
Get the primary distance squared.
void SetSecondaryTarget(const pandora::CaloHit *const pSecondaryTarget, const float secondaryDistanceSquared)
Set secondary target.
void CreateClusters(const pandora::OrderedCaloHitList &orderedCaloHitList, const HitJoinMap &hitJoinMap, HitToClusterMap &hitToClusterMap) const
Final cluster formation.
static int max(int a, int b)
void CreatePrimaryAssociation(const pandora::CaloHit *const pCaloHitI, const pandora::CaloHit *const pCaloHitJ, HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const
Create primary association if appropriate, hitI<->hitJ.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
unsigned int m_maxGapLayers
Maximum number of layers for a gap.
const pandora::CaloHit * GetSecondaryTarget() const
Get the secondary target.
const pandora::CaloHit * GetJoinHit(const pandora::CaloHit *const pCaloHit, const HitAssociationMap &hitAssociationMapI, const HitAssociationMap &hitAssociationMapJ) const
Get hit to join by tracing associations via map I, checking via map J.
bool m_mergeBackFilteredHits
Merge rejected hits into their associated clusters.
void MakeSecondaryAssociations(const pandora::OrderedCaloHitList &orderedCaloHitList, HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const
Control secondary association formation.
HitAssociation(const pandora::CaloHit *const pPrimaryTarget, const float primaryDistanceSquared)
Constructor.
void CreateSecondaryAssociation(const pandora::CaloHit *const pCaloHitI, const pandora::CaloHit *const pCaloHitJ, HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const
Create secondary association if appropriate, hitI<->hitJ.
float m_minCaloHitSeparationSquared
Square of minimum calo hit separation.
float m_closeSeparationSquared
Length scale (squared) for close hit separation.
const pandora::CaloHit * TraceHitAssociation(const pandora::CaloHit *const pCaloHit, const HitAssociationMap &hitAssociationMapI, const HitAssociationMap &hitAssociationMapJ, unsigned int &nSteps) const
Get last hit obtained by tracing associations via map I, checking via map J.