Newer
Older
TB_Chris / TbAlgorithms / src / .svn / text-base / TbClustering.h.svn-base
  1. #ifndef TB_CLUSTERING_H
  2. #define TB_CLUSTERING_H 1
  3.  
  4. // Tb/TbEvent
  5. #include "Event/TbHit.h"
  6. #include "Event/TbCluster.h"
  7.  
  8. // Tb/TbKernel
  9. #include "TbKernel/TbAlgorithm.h"
  10.  
  11. /** @class TbClustering TbClustering.h
  12. *
  13. * Algorithm to group together touching Timepix3 pixel hits.
  14. *
  15. * @author Dan Saunders
  16. */
  17.  
  18. class TbClustering : public TbAlgorithm {
  19. public:
  20. /// Constructor
  21. TbClustering(const std::string& name, ISvcLocator* pSvcLocator);
  22. /// Destructor
  23. virtual ~TbClustering() {}
  24.  
  25. virtual StatusCode initialize(); ///< Algorithm initialization
  26. virtual StatusCode execute(); ///< Algorithm execution
  27.  
  28. private:
  29. /// TES location prefix of hits
  30. std::string m_hitLocation;
  31. /// TES location prefix of clusters
  32. std::string m_clusterLocation;
  33. /// Time window (in ns)
  34. double m_twindow;
  35. /// Max. distance between two pixels to be grouped together
  36. int m_searchDist;
  37. /// Cluster error calculation (0 for constant, 1 for COG error propagation
  38. int m_clusterErrorMethod;
  39. /// Eta-correction parameterisation.
  40. struct EtaCorrection {
  41. double xmin, xmax;
  42. std::vector<double> coefficients;
  43. };
  44. /// Set of eta-correction parameters per plane, direction, and cluster width.
  45. std::vector<std::array<std::vector<std::vector<EtaCorrection> >, 2> > m_eta;
  46.  
  47. /// Add pixels to a given seed pixel.
  48. void addNeighbouringHits(std::vector<const LHCb::TbHit*>& pixels,
  49. LHCb::TbHits::const_iterator begin,
  50. LHCb::TbHits::const_iterator end,
  51. std::vector<bool>& used);
  52. /// Check if a hit touches any of the pixels in a given cluster.
  53. bool hitTouchesCluster(const int scol, const int row,
  54. const std::vector<const LHCb::TbHit*>& pixels) const {
  55.  
  56. bool result = false;
  57. for (auto it = pixels.cbegin(), end = pixels.cend(); it != end; ++it) {
  58. if ((abs(int((*it)->scol()) - scol) <= m_searchDist) &&
  59. (abs(int((*it)->row()) - row) <= m_searchDist)) {
  60. result = true;
  61. break;
  62. }
  63. }
  64. return result;
  65. }
  66.  
  67. /// Set cluster attributes (position, time, ADC).
  68. void completeCluster(const unsigned int plane,
  69. const std::vector<const LHCb::TbHit*>& pixels,
  70. LHCb::TbClusters* clusters);
  71. /// Calculate the cluster errors.
  72. void setClusterError(LHCb::TbCluster* cluster) const;
  73. /// Calculate the eta-correction.
  74. void etaCorrection(double& xLocal, double& yLocal,
  75. const unsigned int nCols, const unsigned int nRows,
  76. const unsigned int plane) const;
  77. void readEta(const std::string& filename);
  78.  
  79. };
  80. #endif