Newer
Older
TB_Chris / TbAlignment / src / .svn / text-base / TbAlignmentSurvey.cpp.svn-base
  1. // ROOT
  2. #include "TH1.h"
  3.  
  4. // Gaudi
  5. #include "GaudiKernel/IHistogramSvc.h"
  6. #include "GaudiUtils/Aida2ROOT.h"
  7.  
  8. // Local
  9. #include "TbAlignmentSurvey.h"
  10.  
  11. DECLARE_TOOL_FACTORY(TbAlignmentSurvey)
  12.  
  13. //=============================================================================
  14. // Standard constructor, initializes variables
  15. //=============================================================================
  16. TbAlignmentSurvey::TbAlignmentSurvey(const std::string& type,
  17. const std::string& name,
  18. const IInterface* parent)
  19. : TbAlignmentBase(type, name, parent) {}
  20.  
  21. //=============================================================================
  22. // Destructor
  23. //=============================================================================
  24. TbAlignmentSurvey::~TbAlignmentSurvey() {}
  25.  
  26. //=============================================================================
  27. // Initialization
  28. //=============================================================================
  29. StatusCode TbAlignmentSurvey::initialize() {
  30.  
  31. // Initialise the base class.
  32. StatusCode sc = TbAlignmentBase::initialize();
  33. if (sc.isFailure()) return sc;
  34.  
  35. return StatusCode::SUCCESS;
  36. }
  37.  
  38. void TbAlignmentSurvey::align(std::vector<TbAlignmentTrack*>& /*tracks*/) {
  39.  
  40. info() << "Survey alignment" << endmsg;
  41. for (unsigned int i = 0; i < m_nPlanes; ++i) {
  42. if (masked(i)) continue;
  43. const std::string plane = std::to_string(i);
  44. const std::string path = "Tb/TbClusterPlots/Differences/";
  45. const std::string titlex = path + "x/Plane" + plane;
  46. const std::string titley = path + "y/Plane" + plane;
  47. double tx = m_modules[i]->x();
  48. double ty = m_modules[i]->y();
  49.  
  50. if (m_dofs[0]) {
  51. AIDA::IHistogram1D* hAida = NULL;
  52. StatusCode sc = GaudiTool::histoSvc()->retrieveObject(titlex, hAida);
  53. if (sc.isFailure() || !hAida) {
  54. warning() << "Cannot retrieve histogram " << titlex << endmsg;
  55. } else {
  56. auto hRoot = Gaudi::Utils::Aida2ROOT::aida2root(hAida);
  57. tx -= hRoot->GetBinCenter(hRoot->GetMaximumBin());
  58. }
  59. }
  60. if (m_dofs[1]) {
  61. AIDA::IHistogram1D* hAida = NULL;
  62. StatusCode sc = GaudiTool::histoSvc()->retrieveObject(titley, hAida);
  63. if (sc.isFailure() || !hAida) {
  64. warning() << "Cannot retrieve histogram " << titley << endmsg;
  65. } else {
  66. auto hRoot = Gaudi::Utils::Aida2ROOT::aida2root(hAida);
  67. ty -= hRoot->GetBinCenter(hRoot->GetMaximumBin());
  68. }
  69. }
  70. const double rx = m_modules[i]->rotX();
  71. const double ry = m_modules[i]->rotY();
  72. const double rz = m_modules[i]->rotZ();
  73. const double tz = m_modules[i]->z();
  74. m_modules[i]->setAlignment(tx, ty, tz, rx, ry, rz, 0., 0., 0., 0., 0., 0.);
  75. }
  76. }