Newer
Older
TB_Chris / TbKernel / src / .svn / text-base / TbKalmanTrackFit.cpp.svn-base
  1. // Tb/TbEvent
  2. #include "Event/TbCluster.h"
  3. #include "Event/TbTrack.h"
  4. #include "Event/TbKalmanTrack.h"
  5. #include "Event/TbKalmanNode.h"
  6.  
  7. // Local
  8. #include "TbKalmanTrackFit.h"
  9.  
  10. DECLARE_TOOL_FACTORY(TbKalmanTrackFit)
  11.  
  12. //=============================================================================
  13. // Standard constructor, initializes variables
  14. //=============================================================================
  15. TbKalmanTrackFit::TbKalmanTrackFit(const std::string& type,
  16. const std::string& name,
  17. const IInterface* parent)
  18. : GaudiTool(type, name, parent), m_fitter(nullptr), m_geomSvc(nullptr) {
  19.  
  20. declareInterface<ITbTrackFit>(this);
  21.  
  22. declareProperty("MaskedPlanes", m_maskedPlanes = {});
  23. declareProperty("HitError", m_hiterror = 0.004);
  24. declareProperty("Noise2", m_scat2 = 1.2e-8);
  25.  
  26. m_hiterror2 = m_hiterror * m_hiterror;
  27. }
  28.  
  29. //=============================================================================
  30. // Destructor
  31. //=============================================================================
  32. TbKalmanTrackFit::~TbKalmanTrackFit() {}
  33.  
  34. //=============================================================================
  35. // Initialisation
  36. //=============================================================================
  37. StatusCode TbKalmanTrackFit::initialize() {
  38.  
  39. // Initialise the base class.
  40. StatusCode sc = GaudiTool::initialize();
  41. if (sc.isFailure()) return sc;
  42. // Get the straight-line fit tool (used for seeding the Kalman filter).
  43. m_fitter = tool<ITbTrackFit>("TbTrackFit", "StraightLineFitter", this);
  44. // Get the number of telescope planes.
  45. const auto nPlanes = geomSvc()->modules().size();
  46. // Set the flags whether a plane is masked or not.
  47. m_masked.resize(nPlanes, false);
  48. for (const unsigned int plane : m_maskedPlanes) {
  49. m_masked[plane] = true;
  50. m_fitter->maskPlane(plane);
  51. }
  52. return StatusCode::SUCCESS;
  53. }
  54.  
  55. //=============================================================================
  56. // Exclude a plane from the fit
  57. //=============================================================================
  58. void TbKalmanTrackFit::maskPlane(const unsigned int plane) {
  59.  
  60. m_masked[plane] = true;
  61. m_fitter->maskPlane(plane);
  62. }
  63.  
  64. //=============================================================================
  65. // (Re-)include a plane in the fit
  66. //=============================================================================
  67. void TbKalmanTrackFit::unmaskPlane(const unsigned int plane) {
  68.  
  69. m_masked[plane] = false;
  70. m_fitter->unmaskPlane(plane);
  71. }
  72.  
  73. //=========================================================================
  74. // Perform the fit
  75. //=========================================================================
  76. void TbKalmanTrackFit::fit(LHCb::TbTrack* track) {
  77.  
  78. // Make a straight-line fit.
  79. m_fitter->fit(track);
  80. // Create a Kalman track.
  81. LHCb::TbKalmanTrack ktrack(*track, m_hiterror2, m_scat2);
  82. // Run the Kalman filter.
  83. ktrack.fit();
  84. // Update the track states.
  85. track->clearStates();
  86. auto nodes = ktrack.nodes();
  87. for (auto it = nodes.cbegin(), end = nodes.cend(); it != end; ++it) {
  88. track->addToStates((*it)->state());
  89. }
  90. // Set the chi2.
  91. track->setChi2PerNdof(ktrack.chi2PerNdof());
  92. track->setNdof(ktrack.ndof());
  93. }