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