ThreeDHitCreationAlgorithm.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArHitCreation/ThreeDHitCreationAlgorithm.h
3  *
4  * @brief Header file for the three dimensional hit creation algorithm class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_THREE_D_HIT_CREATION_ALGORITHM_H
9 #define LAR_THREE_D_HIT_CREATION_ALGORITHM_H 1
10 
11 #include "Pandora/Algorithm.h"
12 #include "Pandora/AlgorithmTool.h"
13 
14 #include <vector>
15 
16 namespace lar_content
17 {
18 
19 class HitCreationBaseTool;
20 class ThreeDSlidingFitResult;
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
24 /**
25  * @brief ThreeDHitCreationAlgorithm::Algorithm class
26  */
27 class ThreeDHitCreationAlgorithm : public pandora::Algorithm
28 {
29 public:
30  /**
31  * @brief Trajectory samples record the results of sampling a particles in a particular view
32  */
34  {
35  public:
36  /**
37  * @brief Constructor
38  */
39  TrajectorySample(const pandora::CartesianVector &position, const pandora::HitType hitType, const double sigma);
40 
41  /**
42  * @brief Get the sampling position
43  *
44  * @return the sampling position
45  */
46  const pandora::CartesianVector &GetPosition() const;
47 
48  /**
49  * @brief Get the sampling hit type
50  *
51  * @return the sampling hit type
52  */
54 
55  /**
56  * @brief Get the sampling sigma
57  *
58  * @return the sampling sigma
59  */
60  double GetSigma() const;
61 
62  private:
63  pandora::CartesianVector m_position; ///< The sampling position
64  pandora::HitType m_hitType; ///< The sampling hit type
65  double m_sigma; ///< The sampling sigma
66  };
67 
68  typedef std::vector<TrajectorySample> TrajectorySampleVector;
69 
70  /**
71  * @brief Proto hits are temporary constructs to be used during iterative 3D hit procedure
72  */
73  class ProtoHit
74  {
75  public:
76  /**
77  * @brief Constructor
78  *
79  * @param pParentCaloHit2D the address of the parent 2D calo hit
80  */
81  ProtoHit(const pandora::CaloHit *const pParentCaloHit2D);
82 
83  /**
84  * @brief Get the address of the parent 2D calo hit
85  *
86  * @return the address of the parent 2D calo hit
87  */
88  const pandora::CaloHit *GetParentCaloHit2D() const;
89 
90  /**
91  * @brief Whether the proto hit position is set
92  *
93  * @return boolean
94  */
95  bool IsPositionSet() const;
96 
97  /**
98  * @brief Get the output 3D position
99  *
100  * @return the output 3D position, if set
101  *
102  * @throws StatusCodeException
103  */
104  const pandora::CartesianVector &GetPosition3D() const;
105 
106  /**
107  * @brief Get the chi squared value
108  *
109  * @return the chi squared value, if set
110  *
111  * @throws StatusCodeException
112  */
113  double GetChi2() const;
114 
115  /**
116  * @brief Get the number of trajectory samples
117  *
118  * @return the number of trajectory samples
119  */
120  unsigned int GetNTrajectorySamples() const;
121 
122  /**
123  * @brief Get the first trajectory sample
124  *
125  * @return the first trajectory sample, if at least one sample is present
126  *
127  * @throws StatusCodeException
128  */
129  const TrajectorySample &GetFirstTrajectorySample() const;
130 
131  /**
132  * @brief Get the last trajectory sample
133  *
134  * @return the last trajectory sample, if at least two samples are present
135  *
136  * @throws StatusCodeException
137  */
138  const TrajectorySample &GetLastTrajectorySample() const;
139 
140  /**
141  * @brief Set position 3D
142  *
143  * @param the output 3D position
144  * @param the output chi squared value
145  */
146  void SetPosition3D(const pandora::CartesianVector &position3D, const double chi2);
147 
148  /**
149  * @brief Add a trajectory sample
150  *
151  * @param the trajectory sample
152  */
153  void AddTrajectorySample(const TrajectorySample &trajectorySample);
154 
155  private:
156  const pandora::CaloHit *m_pParentCaloHit2D; ///< The address of the parent 2D calo hit
157  bool m_isPositionSet; ///< Whether the output 3D position has been set
158  pandora::CartesianVector m_position3D; ///< The output 3D position
159  double m_chi2; ///< The output chi squared value
160  TrajectorySampleVector m_trajectorySampleVector; ///< The trajectory sample vector
161  };
162 
163  typedef std::vector<ProtoHit> ProtoHitVector;
164 
165  /**
166  * @brief Default constructor
167  */
169 
170  /**
171  * @brief Get the subset of a provided calo hit vector corresponding to a specified hit type
172  *
173  * @param inputCaloHitVector the input calo hit vector
174  * @param hitType the hit type to filter upon
175  * @param outputCaloHitVector to receive the output calo hit vector
176  */
178  const pandora::CaloHitVector &inputCaloHitVector, const pandora::HitType hitType, pandora::CaloHitVector &outputCaloHitVector) const;
179 
180 private:
181  pandora::StatusCode Run();
182 
183  /**
184  * @brief Get the list of 2D calo hits in a pfo for which 3D hits have and have not been created
185  *
186  * @param pPfo the address of the pfo
187  * @param protoHitVector the vector of proto hits, describing current state of 3D hit construction
188  * @param remainingHitVector to receive the vector of 2D calo hits for which 3D hits have not been created
189  */
190  void SeparateTwoDHits(const pandora::ParticleFlowObject *const pPfo, const ProtoHitVector &protoHitVector,
191  pandora::CaloHitVector &remainingHitVector) const;
192 
193  /**
194  * @brief Improve initial 3D hits by fitting proto hits and iteratively creating consisted 3D hit trajectory
195  *
196  * @param protoHitVector the vector of proto hits, describing current state of 3D hit construction
197  */
198  void IterativeTreatment(ProtoHitVector &protoHitVector) const;
199 
200  /**
201  * @brief Extract key results from a provided proto hit vector
202  *
203  * @param protoHitVector the proto hit vector
204  * @param chi2 to receive the sum of the proto hit chi2 values
205  * @param pointVector to receive a vector of proto hit 3D positions
206  */
207  void ExtractResults(const ProtoHitVector &protoHitVector, double &chi2, pandora::CartesianPointVector &pointVector) const;
208 
209  /**
210  * @brief Receive a chi2 value indicating consistency of a list of proto hits with a provided 3D sliding fit trajectory
211  *
212  * @param slidingFitResult the 3D sliding fit result
213  * @param protoHitVector the proto hit vector
214  *
215  * @return the chi2 value
216  */
217  double GetChi2WrtFit(const ThreeDSlidingFitResult &slidingFitResult, const ProtoHitVector &protoHitVector) const;
218 
219  /**
220  * @brief Receive a chi2 value indicating consistency of a list of proto hits with the original, input hit positions
221  *
222  * @param protoHitVector the proto hit vector
223  *
224  * @return the chi2 value
225  */
226  double GetHitMovementChi2(const ProtoHitVector &protoHitVector) const;
227 
228  /**
229  * @brief Refine the 3D hit positions (and chi2) for a list of proto hits, in accordance with a provided 3D sliding fit trajectory
230  *
231  * @param slidingFitResult the 3D sliding fit result
232  * @param protoHitVector the proto hit vector, non const as proto hit properties will be updated
233  */
234  void RefineHitPositions(const ThreeDSlidingFitResult &slidingFitResult, ProtoHitVector &protoHitVector) const;
235 
236  /**
237  * @brief Create new three dimensional hits from two dimensional hits
238  *
239  * @param protoHitVector the input proto hit vector
240  * @param newThreeDHits to receive the addresses of the new three dimensional calo hits
241  */
242  void CreateThreeDHits(const ProtoHitVector &protoHitVector, pandora::CaloHitList &newThreeDHits) const;
243 
244  /**
245  * @brief Create a new three dimensional hit from a two dimensional hit
246  *
247  * @param protoHit the proto hit containing all required information
248  * @param pCaloHit3D to receive the address of the new three dimensional calo hit
249  */
250  void CreateThreeDHit(const ProtoHit &protoHit, const pandora::CaloHit *&pCaloHit3D) const;
251 
252  /**
253  * @brief Check that a new three dimensional position is not unphysical
254  *
255  * @param protoHit the proto hit
256  *
257  * @param boolean
258  */
259  bool CheckThreeDHit(const ProtoHit &protoHit) const;
260 
261  /**
262  * @brief Add a specified list of three dimensional hits to a cluster in a pfo, creating the new cluster if required
263  *
264  * @param pPfo the address of the pfo
265  * @param caloHitList the list of three dimensional hits
266  */
267  void AddThreeDHitsToPfo(const pandora::ParticleFlowObject *const pPfo, const pandora::CaloHitList &caloHitList) const;
268 
269  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
270 
271  typedef std::vector<HitCreationBaseTool *> HitCreationToolVector;
272  HitCreationToolVector m_algorithmToolVector; ///< The algorithm tool vector
273 
274  std::string m_inputPfoListName; ///< The name of the input pfo list
275  std::string m_outputCaloHitListName; ///< The name of the output calo hit list
276  std::string m_outputClusterListName; ///< The name of the output cluster list
277 
278  bool m_iterateTrackHits; ///< Whether to enable iterative improvement of 3D hits for track trajectories
279  bool m_iterateShowerHits; ///< Whether to enable iterative improvement of 3D hits for showers
280  unsigned int m_slidingFitHalfWindow; ///< The sliding linear fit half window
281  unsigned int m_nHitRefinementIterations; ///< The maximum number of hit refinement iterations
282  double m_sigma3DFitMultiplier; ///< Multiplicative factor: sigmaUVW (same as sigmaHit and sigma2DFit) to sigma3DFit
283  double m_iterationMaxChi2Ratio; ///< Max ratio between current and previous chi2 values to cease iterations
284 };
285 
286 //------------------------------------------------------------------------------------------------------------------------------------------
287 
289  const pandora::CartesianVector &position, const pandora::HitType hitType, const double sigma) :
290  m_position(position),
291  m_hitType(hitType),
292  m_sigma(sigma)
293 {
294 }
295 
296 //------------------------------------------------------------------------------------------------------------------------------------------
297 
298 inline const pandora::CartesianVector &ThreeDHitCreationAlgorithm::TrajectorySample::GetPosition() const
299 {
300  return m_position;
301 }
302 
303 //------------------------------------------------------------------------------------------------------------------------------------------
304 
306 {
307  return m_hitType;
308 }
309 
310 //------------------------------------------------------------------------------------------------------------------------------------------
311 
313 {
314  return m_sigma;
315 }
316 
317 //------------------------------------------------------------------------------------------------------------------------------------------
318 //------------------------------------------------------------------------------------------------------------------------------------------
319 
320 inline ThreeDHitCreationAlgorithm::ProtoHit::ProtoHit(const pandora::CaloHit *const pParentCaloHit2D) :
321  m_pParentCaloHit2D(pParentCaloHit2D),
322  m_isPositionSet(false),
323  m_position3D(0.f, 0.f, 0.f),
324  m_chi2(std::numeric_limits<double>::max())
325 {
326 }
327 
328 //------------------------------------------------------------------------------------------------------------------------------------------
329 
330 inline const pandora::CaloHit *ThreeDHitCreationAlgorithm::ProtoHit::GetParentCaloHit2D() const
331 {
332  return m_pParentCaloHit2D;
333 }
334 
335 //------------------------------------------------------------------------------------------------------------------------------------------
336 
338 {
339  return m_isPositionSet;
340 }
341 
342 //------------------------------------------------------------------------------------------------------------------------------------------
343 
345 {
346  return m_trajectorySampleVector.size();
347 }
348 
349 //------------------------------------------------------------------------------------------------------------------------------------------
350 
351 inline void ThreeDHitCreationAlgorithm::ProtoHit::SetPosition3D(const pandora::CartesianVector &position3D, const double chi2)
352 {
353  m_position3D = position3D;
354  m_chi2 = chi2;
355  m_isPositionSet = true;
356 }
357 
358 //------------------------------------------------------------------------------------------------------------------------------------------
359 
361 {
362  m_trajectorySampleVector.push_back(trajectorySample);
363 }
364 
365 } // namespace lar_content
366 
367 #endif // #ifndef LAR_THREE_D_HIT_CREATION_ALGORITHM_H
void IterativeTreatment(ProtoHitVector &protoHitVector) const
Improve initial 3D hits by fitting proto hits and iteratively creating consisted 3D hit trajectory...
const pandora::CaloHit * m_pParentCaloHit2D
The address of the parent 2D calo hit.
Proto hits are temporary constructs to be used during iterative 3D hit procedure. ...
ProtoHit(const pandora::CaloHit *const pParentCaloHit2D)
Constructor.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::string m_inputPfoListName
The name of the input pfo list.
unsigned int m_slidingFitHalfWindow
The sliding linear fit half window.
bool CheckThreeDHit(const ProtoHit &protoHit) const
Check that a new three dimensional position is not unphysical.
std::vector< TrajectorySample > TrajectorySampleVector
enum cvn::HType HitType
std::string string
Definition: nybbler.cc:12
unsigned int GetNTrajectorySamples() const
Get the number of trajectory samples.
const pandora::CaloHit * GetParentCaloHit2D() const
Get the address of the parent 2D calo hit.
std::string m_outputCaloHitListName
The name of the output calo hit list.
void SeparateTwoDHits(const pandora::ParticleFlowObject *const pPfo, const ProtoHitVector &protoHitVector, pandora::CaloHitVector &remainingHitVector) const
Get the list of 2D calo hits in a pfo for which 3D hits have and have not been created.
STL namespace.
void RefineHitPositions(const ThreeDSlidingFitResult &slidingFitResult, ProtoHitVector &protoHitVector) const
Refine the 3D hit positions (and chi2) for a list of proto hits, in accordance with a provided 3D sli...
bool IsPositionSet() const
Whether the proto hit position is set.
void CreateThreeDHit(const ProtoHit &protoHit, const pandora::CaloHit *&pCaloHit3D) const
Create a new three dimensional hit from a two dimensional hit.
double GetHitMovementChi2(const ProtoHitVector &protoHitVector) const
Receive a chi2 value indicating consistency of a list of proto hits with the original, input hit positions.
void AddTrajectorySample(const TrajectorySample &trajectorySample)
Add a trajectory sample.
unsigned int m_nHitRefinementIterations
The maximum number of hit refinement iterations.
pandora::CartesianVector m_position
The sampling position.
std::string m_outputClusterListName
The name of the output cluster list.
double GetChi2WrtFit(const ThreeDSlidingFitResult &slidingFitResult, const ProtoHitVector &protoHitVector) const
Receive a chi2 value indicating consistency of a list of proto hits with a provided 3D sliding fit tr...
bool m_isPositionSet
Whether the output 3D position has been set.
bool m_iterateTrackHits
Whether to enable iterative improvement of 3D hits for track trajectories.
TrajectorySampleVector m_trajectorySampleVector
The trajectory sample vector.
pandora::CartesianVector m_position3D
The output 3D position.
bool m_iterateShowerHits
Whether to enable iterative improvement of 3D hits for showers.
static int max(int a, int b)
TrajectorySample(const pandora::CartesianVector &position, const pandora::HitType hitType, const double sigma)
Constructor.
void CreateThreeDHits(const ProtoHitVector &protoHitVector, pandora::CaloHitList &newThreeDHits) const
Create new three dimensional hits from two dimensional hits.
pandora::HitType GetHitType() const
Get the sampling hit type.
const pandora::CartesianVector & GetPosition() const
Get the sampling position.
void ExtractResults(const ProtoHitVector &protoHitVector, double &chi2, pandora::CartesianPointVector &pointVector) const
Extract key results from a provided proto hit vector.
Trajectory samples record the results of sampling a particles in a particular view.
ThreeDHitCreationAlgorithm::Algorithm class.
HitCreationToolVector m_algorithmToolVector
The algorithm tool vector.
void SetPosition3D(const pandora::CartesianVector &position3D, const double chi2)
Set position 3D.
std::vector< HitCreationBaseTool * > HitCreationToolVector
double m_sigma3DFitMultiplier
Multiplicative factor: sigmaUVW (same as sigmaHit and sigma2DFit) to sigma3DFit.
double m_iterationMaxChi2Ratio
Max ratio between current and previous chi2 values to cease iterations.
void AddThreeDHitsToPfo(const pandora::ParticleFlowObject *const pPfo, const pandora::CaloHitList &caloHitList) const
Add a specified list of three dimensional hits to a cluster in a pfo, creating the new cluster if req...
void FilterCaloHitsByType(const pandora::CaloHitVector &inputCaloHitVector, const pandora::HitType hitType, pandora::CaloHitVector &outputCaloHitVector) const
Get the subset of a provided calo hit vector corresponding to a specified hit type.