Newer
Older
TB_Chris / TbAlgorithms / src / .svn / text-base / TbCalibration.h.svn-base
  1. #pragma once
  2.  
  3. // Tb/TbEvent
  4. #include "Event/TbCluster.h"
  5.  
  6. // Tb/TbKernel
  7. #include "TbKernel/TbAlgorithm.h"
  8.  
  9. /** @class TbCalibration TbCalibration.h
  10. *
  11. * Algorithm to produce timing and pixel configurations
  12. * Try to make as independent as possible from the rest of Kepler
  13. * (Relies on clustering and EventBuilder only)
  14. *
  15. * @author T. Evans
  16. *
  17. */
  18.  
  19. class TbCalibration : public TbAlgorithm {
  20. public:
  21. /// Constructor
  22. TbCalibration(const std::string& name, ISvcLocator* pSvcLocator);
  23. /// Destructor
  24. virtual ~TbCalibration() {};
  25.  
  26. virtual StatusCode initialize(); ///< Algorithm initialization
  27. virtual StatusCode execute(); ///< Algorithm execution
  28. virtual StatusCode finalize();
  29.  
  30. private:
  31. // profile structure
  32. struct POINT {
  33. POINT() : total(0), nData(0) {};
  34. double total;
  35. double nData;
  36. double avg() const { return nData == 0 ? 0 : total / nData; }
  37. double val() const { return total; }
  38. double n() const { return nData; }
  39. void add(double data) {
  40. total += data;
  41. nData++;
  42. }
  43. };
  44.  
  45. struct PROFILE1D : public std::vector<POINT> {
  46. PROFILE1D(unsigned int size = 0) : std::vector<POINT>(size, POINT()) {}
  47. };
  48.  
  49. struct PROFILE2D : public std::vector<std::vector<POINT>> {
  50. PROFILE2D(unsigned int size_x = 0, unsigned int size_y = 0)
  51. : std::vector<std::vector<POINT>>(
  52. size_x, std::vector<POINT>(size_y, POINT())) {};
  53.  
  54. inline POINT element(const unsigned int x, const unsigned int y) const {
  55. std::vector<POINT> tmp = *(begin() + x);
  56. return tmp[y];
  57. }
  58.  
  59. std::vector<double> neighbours(const unsigned int x,
  60. const unsigned int y) const {
  61. std::vector<double> return_value;
  62. return_value.clear();
  63. unsigned int ix_begin = x > 0 ? x - 1 : 0;
  64. unsigned int ix_end = x < size() - 1 ? x + 1 : size() - 1;
  65. unsigned int iy_begin = y > 0 ? y - 1 : 0;
  66. unsigned int iy_end = y < size() - 1 ? y + 1 : size() - 1;
  67. for (unsigned int ix = ix_begin; ix <= ix_end; ++ix) {
  68. for (unsigned int iy = iy_begin; iy <= iy_end; ++iy)
  69. if (!(ix == x && iy == y))
  70. return_value.push_back(element(ix, iy).n());
  71. }
  72. return return_value;
  73. }
  74. };
  75.  
  76. /// TES location of tracks
  77. std::string m_trackLocation;
  78. /// TES location of clusters
  79. std::string m_clusterLocation;
  80. std::string m_hitLocation;
  81. std::string m_pixelSvcConfig;
  82. std::string m_timingSvcConfig;
  83.  
  84. bool m_checkHotPixels;
  85. bool m_checkSyncronisation;
  86. bool m_checkColumnOffsets;
  87. unsigned int m_syncMethod;
  88. unsigned int m_dut; /// synchronisation of the DUT is kept separate and
  89. /// doesn't affect the telescope timing
  90. std::vector<PROFILE1D> m_offsets;
  91. std::vector<PROFILE2D> m_hitMaps;
  92. PROFILE1D m_sync;
  93. // hot pixel identification, analyses the work done by execute
  94. void hotPixelAnalysis(const PROFILE2D& hitMap, const std::string& plane,
  95. std::ostream& os = std::cout);
  96. void hotPixel_execute(const LHCb::TbHits* hits);
  97.  
  98. void syncAnalysis(const double& sync, const std::string& plane,
  99. std::ostream& os = std::cout);
  100. void sync_execute(const std::vector<LHCb::TbClusters*>& clusters);
  101.  
  102. double nearestHit(const LHCb::TbCluster* cluster,
  103. const LHCb::TbClusters* clusters);
  104.  
  105. void columnOffsetAnalysis(const PROFILE1D& avg_difference,
  106. const std::string& plane,
  107. std::ostream& os = std::cout);
  108. void columnOffset_execute(const LHCb::TbClusters* clusters);
  109.  
  110. void syncOffset2(std::ostream& os = std::cout);
  111. class lowerBound {
  112. public:
  113. bool operator()(const LHCb::TbCluster* lhs, const double t) const {
  114. return lhs->htime() < t;
  115. }
  116. };
  117. };