Newer
Older
TB_Chris / TbAlgorithms / src / .svn / text-base / TbHitMonitor.cpp.svn-base
  1. // Gaudi
  2. #include "GaudiUtils/HistoLabels.h"
  3.  
  4. // Tb/TbEvent
  5. #include "Event/TbHit.h"
  6.  
  7. // Tb/TbKernel
  8. #include "TbKernel/TbConstants.h"
  9. #include "TbKernel/TbModule.h"
  10.  
  11. // Local
  12. #include "TbHitMonitor.h"
  13.  
  14. using namespace Gaudi::Utils::Histos;
  15.  
  16. DECLARE_ALGORITHM_FACTORY(TbHitMonitor)
  17.  
  18. //=============================================================================
  19. // Standard constructor
  20. //=============================================================================
  21. TbHitMonitor::TbHitMonitor(const std::string& name, ISvcLocator* pSvcLocator)
  22. : TbAlgorithm(name, pSvcLocator),
  23. m_parToT("", 0.5, 1024.5, 1024),
  24. m_parCharge("", 0., 20000., 200),
  25. m_parHitsInEvent("", 0., 10000., 100),
  26. m_parDeltaT("", 0., 100., 200),
  27. m_nEvents(0) {
  28.  
  29. declareProperty("HitLocation", m_hitLocation = LHCb::TbHitLocation::Default);
  30.  
  31. declareProperty("ParametersToT", m_parToT);
  32. declareProperty("ParametersCharge", m_parCharge);
  33. declareProperty("ParametersHitsInEvent", m_parHitsInEvent);
  34. declareProperty("ParametersDeltaT", m_parDeltaT);
  35. }
  36.  
  37. //=============================================================================
  38. // Destructor
  39. //=============================================================================
  40. TbHitMonitor::~TbHitMonitor() {}
  41.  
  42. //=============================================================================
  43. // Initialisation
  44. //=============================================================================
  45. StatusCode TbHitMonitor::initialize() {
  46.  
  47. // Initialise the base class.
  48. StatusCode sc = TbAlgorithm::initialize();
  49. if (sc.isFailure()) return sc;
  50.  
  51. // Setup the histograms.
  52. for (unsigned int i = 0; i < m_nPlanes; ++i) {
  53. const std::string plane = std::to_string(i);
  54. const std::string title = geomSvc()->modules().at(i)->id();
  55. const unsigned int nRows = Tb::NRows;
  56. const unsigned int nCols = geomSvc()->modules().at(i)->cols();
  57. std::string name = "HitMap/Plane" + plane;
  58.  
  59. m_hHitMap.push_back(book2D(name, title, -0.5, nCols - 0.5, nCols, -0.5,
  60. nRows - 0.5, nRows));
  61. setAxisLabels(m_hHitMap[i], "column", "row");
  62.  
  63. int bins = m_parToT.bins();
  64. double low = m_parToT.lowEdge();
  65. double high = m_parToT.highEdge();
  66. name = "ToT/Plane" + plane;
  67. m_hToT.push_back(book1D(name, title, low, high, bins));
  68. setAxisLabels(m_hToT[i], "ToT", "entries");
  69.  
  70. bins = m_parCharge.bins();
  71. low = m_parCharge.lowEdge();
  72. high = m_parCharge.highEdge();
  73. name = "Charge/Plane" + plane;
  74. m_hCharge.push_back(book1D(name, title, low, high, bins));
  75. setAxisLabels(m_hCharge[i], "charge [electrons]", "entries");
  76.  
  77. name = "ToTvsCol/Plane" + plane;
  78. m_hToTvsCol.push_back(bookProfile1D(name, title,
  79. -0.5, nCols - 0.5, nCols));
  80. setAxisLabels(m_hToTvsCol[i], "column", "ToT");
  81.  
  82. name = "ChargevsCol/Plane" + plane;
  83. m_hChargevsCol.push_back(bookProfile1D(name, title,
  84. -0.5, nCols - 0.5, nCols));
  85. setAxisLabels(m_hChargevsCol[i], "column", "charge [electrons]");
  86.  
  87. bins = m_parHitsInEvent.bins();
  88. low = m_parHitsInEvent.lowEdge();
  89. high = m_parHitsInEvent.highEdge();
  90. name = "HitsInEvent/Plane" + plane;
  91. m_hHitsInEvent.push_back(book1D(name, title, low, high, bins));
  92. setAxisLabels(m_hHitsInEvent[i], "number of hits", "events");
  93. name = "HitsInEventTrend/Plane" + plane;
  94. m_hHitsInEventTrend.push_back(book1D(name, title, -0.5, 999.5, 1000));
  95. setAxisLabels(m_hHitsInEventTrend[i], "event", "number of hits");
  96.  
  97. bins = m_parDeltaT.bins();
  98. low = m_parDeltaT.lowEdge();
  99. high = m_parDeltaT.highEdge();
  100. name = "TimeBetweenHits/Plane" + plane;
  101. m_hTimeBetweenHits.push_back(book1D(name, title, low, high, bins));
  102. setAxisLabels(m_hTimeBetweenHits[i], "#Deltat [ns]", "entries");
  103. }
  104. return StatusCode::SUCCESS;
  105. }
  106.  
  107. //=============================================================================
  108. // Main execution
  109. //=============================================================================
  110. StatusCode TbHitMonitor::execute() {
  111.  
  112. for (unsigned int i = 0; i < m_nPlanes; ++i) {
  113. // Grab the hits.
  114. const std::string hitLocation = m_hitLocation + std::to_string(i);
  115. const LHCb::TbHits* hits = getIfExists<LHCb::TbHits>(hitLocation);
  116. if (!hits) continue;
  117. m_hHitsInEvent[i]->fill(hits->size());
  118. m_hHitsInEventTrend[i]->fill(m_nEvents, hits->size());
  119. if (hits->empty()) continue;
  120. double tprev = 0.;
  121. LHCb::TbHits::const_iterator begin = hits->begin();
  122. LHCb::TbHits::const_iterator end = hits->end();
  123. for (LHCb::TbHits::const_iterator ith = begin; ith != end; ++ith) {
  124. const LHCb::TbHit* hit = *ith;
  125. m_hToT[i]->fill(hit->ToT());
  126. m_hCharge[i]->fill(hit->charge());
  127. m_hToTvsCol[i]->fill(hit->scol(), hit->ToT());
  128. m_hChargevsCol[i]->fill(hit->scol(), hit->charge());
  129. m_hHitMap[i]->fill(hit->scol(), hit->row());
  130. const double t = hit->htime();
  131. if (ith != begin) m_hTimeBetweenHits[i]->fill(t - tprev);
  132. tprev = t;
  133. }
  134. }
  135. ++m_nEvents;
  136. return StatusCode::SUCCESS;
  137. }