LArTwoDSlidingFitObjects.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArObjects/LArTwoDSlidingFitObjects.h
3  *
4  * @brief Header file for the lar two dimensional sliding fit objects.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_TWO_D_SLIDING_FIT_OBJECTS_H
9 #define LAR_TWO_D_SLIDING_FIT_OBJECTS_H 1
10 
11 #include "Pandora/StatusCodes.h"
12 
13 #include <cmath>
14 #include <map>
15 #include <vector>
16 
17 namespace lar_content
18 {
19 
20 /**
21  * @brief TransverseDirection enum
22  */
24 {
29 };
30 
31 //------------------------------------------------------------------------------------------------------------------------------------------
32 
33 /**
34  * @brief class LayerFitResult
35  */
37 {
38 public:
39  /**
40  * @brief Constructor
41  *
42  * @param l the l coordinate
43  * @param fitT the fitted t coordinate
44  * @param gradient the fitted gradient dt/dl
45  * @param rms the rms of the fit residuals
46  */
47  LayerFitResult(const double l, const double fitT, const double gradient, const double rms);
48 
49  /**
50  * @brief Get the l coordinate
51  *
52  * @return the l coordinate
53  */
54  double GetL() const;
55 
56  /**
57  * @brief Get the fitted t coordinate
58  *
59  * @return the fitted t coordinate
60  */
61  double GetFitT() const;
62 
63  /**
64  * @brief Get the fitted gradient dt/dz
65  *
66  * @return the fitted gradient dt/dl
67  */
68  double GetGradient() const;
69 
70  /**
71  * @brief Get the rms of the fit residuals
72  *
73  * @return the rms of the fit residuals
74  */
75  double GetRms() const;
76 
77 private:
78  double m_l; ///< The l coordinate
79  double m_fitT; ///< The fitted t coordinate
80  double m_gradient; ///< The fitted gradient dt/dl
81  double m_rms; ///< The rms of the fit residuals
82 };
83 
84 typedef std::map<int, LayerFitResult> LayerFitResultMap;
85 
86 //------------------------------------------------------------------------------------------------------------------------------------------
87 
88 /**
89  * @brief LayerFitContribution class
90  */
92 {
93 public:
94  /**
95  * @brief Default constructor
96  */
98 
99  /**
100  * @brief Add point to layer fit
101  *
102  * @param l the longitudinal coordinate
103  * @param t the transverse coordinate
104  */
105  void AddPoint(const float l, const float t);
106 
107  /**
108  * @brief Get the sum t
109  *
110  * @return the sum t
111  */
112  double GetSumT() const;
113 
114  /**
115  * @brief Get the sum l
116  *
117  * @return the sum l
118  */
119  double GetSumL() const;
120 
121  /**
122  * @brief Get the sum t * t
123  *
124  * @return the sum t * t
125  */
126  double GetSumTT() const;
127 
128  /**
129  * @brief Get the sum l * t
130  *
131  * @return the sum l * t
132  */
133  double GetSumLT() const;
134 
135  /**
136  * @brief Get the sum l * l
137  *
138  * @return the sum z * z
139  */
140  double GetSumLL() const;
141 
142  /**
143  * @brief Get the number of points used
144  *
145  * @return the number of points used
146  */
147  unsigned int GetNPoints() const;
148 
149 private:
150  double m_sumT; ///< The sum t
151  double m_sumL; ///< The sum l
152  double m_sumTT; ///< The sum t * t
153  double m_sumLT; ///< The sum l * t
154  double m_sumLL; ///< The sum l * l
155  unsigned int m_nPoints; ///< The number of points used
156 };
157 
158 typedef std::map<int, LayerFitContribution> LayerFitContributionMap;
159 
160 //------------------------------------------------------------------------------------------------------------------------------------------
161 
162 /**
163  * @brief LayerInterpolation class
164  */
166 {
167 public:
168  /**
169  * @brief Default constructor
170  */
172 
173  /**
174  * @brief Constructor
175  *
176  * @param firstayerIter the iterator for the upstream layer
177  * @param secondLayerIter the iterator for the downstream layer
178  * @param firstWeight the weight to be applied to the upstream layer
179  * @param secondWeight the weight to be applied to the downstream layer
180  */
181  LayerInterpolation(const LayerFitResultMap::const_iterator &firstLayerIter, const LayerFitResultMap::const_iterator &secondLayerIter,
182  const double firstWeight, const double secondWeight);
183 
184  /**
185  * @brief Whether the object is initialized
186  *
187  * @return boolean
188  */
189  bool IsInitialized() const;
190 
191  /**
192  * @brief Get the start layer iterator
193  *
194  * @return the iterator for the start layer
195  */
196  LayerFitResultMap::const_iterator GetStartLayerIter() const;
197 
198  /**
199  * @brief Get the end layer iterator
200  *
201  * @return the iterator for the end layer
202  */
203  LayerFitResultMap::const_iterator GetEndLayerIter() const;
204 
205  /**
206  * @brief Get the start layer weight
207  *
208  * @return the weight for the start layer
209  */
210  double GetStartLayerWeight() const;
211 
212  /**
213  * @brief Get the end layer weight
214  *
215  * @return the weight for the end layer
216  */
217  double GetEndLayerWeight() const;
218 
219 private:
220  bool m_isInitialized; ///< Whether the object is initialized
223  double m_startLayerWeight; ///< The start layer weight
224  double m_endLayerWeight; ///< The end layer weight
225 };
226 
227 typedef std::vector<LayerInterpolation> LayerInterpolationList;
228 
229 //------------------------------------------------------------------------------------------------------------------------------------------
230 
231 /**
232  * @brief FitSegment class
233  */
235 {
236 public:
237  /**
238  * @brief Constructor
239  *
240  * @param startLayer the start layer
241  * @param endLayer the end layer
242  * @param startX the x position at the start layer
243  * @param endX the x position at the end layer
244  */
245  FitSegment(const int startLayer, const int endLayer, const double startX, const double endX);
246 
247  /**
248  * @brief Get start layer
249  *
250  * @return the start layer
251  */
252  int GetStartLayer() const;
253 
254  /**
255  * @brief Get end layer
256  *
257  * @return the end layer
258  */
259  int GetEndLayer() const;
260 
261  /**
262  * @brief Get the minimum x value
263  *
264  * @return the minimum x value
265  */
266  double GetMinX() const;
267 
268  /**
269  * @brief Get the maximum x value
270  *
271  * @return the maximum x value
272  */
273  double GetMaxX() const;
274 
275  /**
276  * @brief Whether the x coordinate increases between the start and end layers
277  *
278  * @return boolean
279  */
280  bool IsIncreasingX() const;
281 
282 private:
283  int m_startLayer; ///< The start layer
284  int m_endLayer; ///< The end layer
285  double m_minX; ///< The minimum x value
286  double m_maxX; ///< The maximum x value
287  bool m_isIncreasingX; ///< Whether the x coordinate increases between the start and end layers
288 };
289 
290 typedef std::vector<FitSegment> FitSegmentList;
291 
292 //------------------------------------------------------------------------------------------------------------------------------------------
293 //------------------------------------------------------------------------------------------------------------------------------------------
294 
295 inline LayerFitResult::LayerFitResult(const double l, const double fitT, const double gradient, const double rms) :
296  m_l(l),
297  m_fitT(fitT),
298  m_gradient(gradient),
299  m_rms(rms)
300 {
301 }
302 
303 //------------------------------------------------------------------------------------------------------------------------------------------
304 
305 inline double LayerFitResult::GetL() const
306 {
307  return m_l;
308 }
309 
310 //------------------------------------------------------------------------------------------------------------------------------------------
311 
312 inline double LayerFitResult::GetFitT() const
313 {
314  return m_fitT;
315 }
316 
317 //------------------------------------------------------------------------------------------------------------------------------------------
318 
319 inline double LayerFitResult::GetGradient() const
320 {
321  return m_gradient;
322 }
323 
324 //------------------------------------------------------------------------------------------------------------------------------------------
325 
326 inline double LayerFitResult::GetRms() const
327 {
328  return m_rms;
329 }
330 
331 //------------------------------------------------------------------------------------------------------------------------------------------
332 //------------------------------------------------------------------------------------------------------------------------------------------
333 
334 inline LayerFitContribution::LayerFitContribution() : m_sumT(0.), m_sumL(0.), m_sumTT(0.), m_sumLT(0.), m_sumLL(0.), m_nPoints(0)
335 {
336 }
337 
338 //------------------------------------------------------------------------------------------------------------------------------------------
339 
340 inline void LayerFitContribution::AddPoint(const float l, const float t)
341 {
342  const double T = static_cast<double>(t);
343  const double L = static_cast<double>(l);
344 
345  m_sumT += T;
346  m_sumL += L;
347  m_sumTT += T * T;
348  m_sumLT += L * T;
349  m_sumLL += L * L;
350  ++m_nPoints;
351 }
352 
353 //------------------------------------------------------------------------------------------------------------------------------------------
354 
355 inline double LayerFitContribution::GetSumT() const
356 {
357  return m_sumT;
358 }
359 
360 //------------------------------------------------------------------------------------------------------------------------------------------
361 
362 inline double LayerFitContribution::GetSumL() const
363 {
364  return m_sumL;
365 }
366 
367 //------------------------------------------------------------------------------------------------------------------------------------------
368 
369 inline double LayerFitContribution::GetSumLT() const
370 {
371  return m_sumLT;
372 }
373 
374 //------------------------------------------------------------------------------------------------------------------------------------------
375 
376 inline double LayerFitContribution::GetSumLL() const
377 {
378  return m_sumLL;
379 }
380 
381 //------------------------------------------------------------------------------------------------------------------------------------------
382 
383 inline double LayerFitContribution::GetSumTT() const
384 {
385  return m_sumTT;
386 }
387 
388 //------------------------------------------------------------------------------------------------------------------------------------------
389 
390 inline unsigned int LayerFitContribution::GetNPoints() const
391 {
392  return m_nPoints;
393 }
394 
395 //------------------------------------------------------------------------------------------------------------------------------------------
396 //------------------------------------------------------------------------------------------------------------------------------------------
397 
398 inline LayerInterpolation::LayerInterpolation() : m_isInitialized(false), m_startLayerWeight(0.f), m_endLayerWeight(0.f)
399 {
400 }
401 
402 //------------------------------------------------------------------------------------------------------------------------------------------
403 
405  const LayerFitResultMap::const_iterator &endLayerIter, const double startLayerWeight, const double endLayerWeight) :
406  m_isInitialized(true),
407  m_startLayerIter(startLayerIter),
408  m_endLayerIter(endLayerIter),
409  m_startLayerWeight(startLayerWeight),
410  m_endLayerWeight(endLayerWeight)
411 {
412 }
413 
414 //------------------------------------------------------------------------------------------------------------------------------------------
415 
417 {
418  return m_isInitialized;
419 }
420 
421 //------------------------------------------------------------------------------------------------------------------------------------------
422 
424 {
425  if (!m_isInitialized)
426  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_INITIALIZED);
427 
428  return m_startLayerIter;
429 }
430 
431 //------------------------------------------------------------------------------------------------------------------------------------------
432 
434 {
435  if (!m_isInitialized)
436  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_INITIALIZED);
437 
438  return m_endLayerIter;
439 }
440 
441 //------------------------------------------------------------------------------------------------------------------------------------------
442 
444 {
445  if (!m_isInitialized)
446  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_INITIALIZED);
447 
448  return m_startLayerWeight;
449 }
450 
451 //------------------------------------------------------------------------------------------------------------------------------------------
452 
454 {
455  if (!m_isInitialized)
456  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_INITIALIZED);
457 
458  return m_endLayerWeight;
459 }
460 
461 //------------------------------------------------------------------------------------------------------------------------------------------
462 //------------------------------------------------------------------------------------------------------------------------------------------
463 
464 inline FitSegment::FitSegment(const int startLayer, const int endLayer, const double startX, const double endX) :
465  m_startLayer(startLayer),
466  m_endLayer(endLayer)
467 {
468  m_minX = std::min(startX, endX);
469  m_maxX = std::max(startX, endX);
470  m_isIncreasingX = (endX > startX);
471 }
472 
473 //------------------------------------------------------------------------------------------------------------------------------------------
474 
475 inline int FitSegment::GetStartLayer() const
476 {
477  return m_startLayer;
478 }
479 
480 //------------------------------------------------------------------------------------------------------------------------------------------
481 
482 inline int FitSegment::GetEndLayer() const
483 {
484  return m_endLayer;
485 }
486 
487 //------------------------------------------------------------------------------------------------------------------------------------------
488 
489 inline double FitSegment::GetMinX() const
490 {
491  return m_minX;
492 }
493 
494 //------------------------------------------------------------------------------------------------------------------------------------------
495 
496 inline double FitSegment::GetMaxX() const
497 {
498  return m_maxX;
499 }
500 
501 //------------------------------------------------------------------------------------------------------------------------------------------
502 
503 inline bool FitSegment::IsIncreasingX() const
504 {
505  return m_isIncreasingX;
506 }
507 
508 } // namespace lar_content
509 
510 #endif // #ifndef LAR_TWO_D_SLIDING_FIT_OBJECTS_H
double GetSumLL() const
Get the sum l * l.
bool IsIncreasingX() const
Whether the x coordinate increases between the start and end layers.
LayerFitResultMap::const_iterator m_startLayerIter
The start layer iterator.
int GetStartLayer() const
Get start layer.
int m_startLayer
The start layer.
double GetEndLayerWeight() const
Get the end layer weight.
void AddPoint(const float l, const float t)
Add point to layer fit.
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:40
TransverseDirection
TransverseDirection enum.
double GetSumLT() const
Get the sum l * t.
std::vector< FitSegment > FitSegmentList
intermediate_table::const_iterator const_iterator
bool m_isIncreasingX
Whether the x coordinate increases between the start and end layers.
double m_maxX
The maximum x value.
static QStrList * l
Definition: config.cpp:1044
double GetSumTT() const
Get the sum t * t.
std::map< int, LayerFitContribution > LayerFitContributionMap
unsigned int GetNPoints() const
Get the number of points used.
double GetFitT() const
Get the fitted t coordinate.
LayerFitResultMap::const_iterator GetEndLayerIter() const
Get the end layer iterator.
bool m_isInitialized
Whether the object is initialized.
double GetStartLayerWeight() const
Get the start layer weight.
LayerFitResult(const double l, const double fitT, const double gradient, const double rms)
Constructor.
double m_startLayerWeight
The start layer weight.
std::map< int, LayerFitResult > LayerFitResultMap
static int max(int a, int b)
double GetGradient() const
Get the fitted gradient dt/dz.
std::vector< LayerInterpolation > LayerInterpolationList
double m_rms
The rms of the fit residuals.
double m_gradient
The fitted gradient dt/dl.
double GetSumL() const
Get the sum l.
double m_fitT
The fitted t coordinate.
double GetRms() const
Get the rms of the fit residuals.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
LayerFitResultMap::const_iterator m_endLayerIter
The end layer iterator.
double m_endLayerWeight
The end layer weight.
double GetMinX() const
Get the minimum x value.
unsigned int m_nPoints
The number of points used.
LayerFitResultMap::const_iterator GetStartLayerIter() const
Get the start layer iterator.
double GetL() const
Get the l coordinate.
double m_minX
The minimum x value.
int GetEndLayer() const
Get end layer.
double GetSumT() const
Get the sum t.
double GetMaxX() const
Get the maximum x value.
bool IsInitialized() const
Whether the object is initialized.
FitSegment(const int startLayer, const int endLayer, const double startX, const double endX)
Constructor.