Belle II Software  release-08-01-10
TOPCommonT0BFCollectorModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <top/modules/collectors/TOPCommonT0BFCollectorModule.h>
10 #include <top/geometry/TOPGeometryPar.h>
11 
12 // framework aux
13 #include <TH1F.h>
14 
15 using namespace std;
16 
17 namespace Belle2 {
23  using namespace TOP;
24 
25  //-----------------------------------------------------------------
27  //-----------------------------------------------------------------
28 
29  REG_MODULE(TOPCommonT0BFCollector);
30 
31  //-----------------------------------------------------------------
32  // Implementation
33  //-----------------------------------------------------------------
34 
35  TOPCommonT0BFCollectorModule::TOPCommonT0BFCollectorModule()
36  {
37  // set module description and processing properties
38  setDescription("A collector for common T0 calibration with a fit of bunch finder residuals (method BF)");
39  setPropertyFlags(c_ParallelProcessingCertified);
40 
41  // module parameters
42  addParam("bunchesPerSSTclk", m_bunchesPerSSTclk,
43  "number of bunches per SST clock period", 24);
44  addParam("nx", m_nx, "number of histogram bins", 200);
45 
46  }
47 
48 
49  void TOPCommonT0BFCollectorModule::prepare()
50  {
51 
52  m_recBunch.isRequired();
53 
54  const auto* geo = TOPGeometryPar::Instance()->getGeometry();
55  m_bunchTimeSep = geo->getNominalTDC().getSyncTimeBase() / m_bunchesPerSSTclk;
56 
57  auto h1a = new TH1F("offset_a", "current offset; offset [ns]",
58  m_nx, -m_bunchTimeSep / 2, m_bunchTimeSep / 2);
59  registerObject<TH1F>("offset_a", h1a);
60 
61  auto h1b = new TH1F("offset_b", "current offset; offset [ns]",
62  m_nx, 0.0, m_bunchTimeSep);
63  registerObject<TH1F>("offset_b", h1b);
64 
65  }
66 
67 
68  void TOPCommonT0BFCollectorModule::collect()
69  {
70 
71  if (not m_recBunch.isValid()) return;
72  if (not m_recBunch->isReconstructed()) return;
73  if (m_recBunch->getNumTracks() != 2) return;
74 
75  auto h1a = getObjectPtr<TH1F>("offset_a");
76  auto h1b = getObjectPtr<TH1F>("offset_b");
77  auto offset = m_recBunch->getCurrentOffset();
78  if (m_commonT0->isCalibrated()) offset += m_commonT0->getT0();
79 
80  // wrap-around into [-1/2, 1/2] of bunch cycle
81  auto a = offset - round(offset / m_bunchTimeSep) * m_bunchTimeSep;
82  h1a->Fill(a);
83 
84  // wrap-around into [0, 1] of bunch cycle
85  auto b = offset - round(offset / m_bunchTimeSep - 0.5) * m_bunchTimeSep;
86  h1b->Fill(b);
87 
88  }
89 
91 }
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.