Belle II Software  release-08-01-10
TOPAsicShiftsBS13dCollectorModule.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/TOPAsicShiftsBS13dCollectorModule.h>
10 #include <top/geometry/TOPGeometryPar.h>
11 #include <string>
12 #include <vector>
13 #include <TH1F.h>
14 #include <TH2F.h>
15 
16 using namespace std;
17 
18 namespace Belle2 {
24  using namespace TOP;
25 
26  //-----------------------------------------------------------------
28  //-----------------------------------------------------------------
29 
30  REG_MODULE(TOPAsicShiftsBS13dCollector);
31 
32  //-----------------------------------------------------------------
33  // Implementation
34  //-----------------------------------------------------------------
35 
36  TOPAsicShiftsBS13dCollectorModule::TOPAsicShiftsBS13dCollectorModule()
37  {
38  // set module description and processing properties
39  setDescription("A collector for calibration of carrier shifts of BS13d.");
40  setPropertyFlags(c_ParallelProcessingCertified);
41 
42  // module parameters
43  addParam("timeOffset", m_timeOffset, "time offset", 0.0);
44  addParam("nx", m_nx, "number of histogram bins (bin size ~8 ns)", 50);
45  addParam("requireRecBunch", m_requireRecBunch,
46  "if True, require reconstructed bunch (to be used on cdst files only!)",
47  false);
48 
49  }
50 
51 
52  void TOPAsicShiftsBS13dCollectorModule::prepare()
53  {
54 
55  m_topDigits.isRequired();
56  if (m_requireRecBunch) {
57  m_recBunch.isRequired();
58  } else {
59  m_recBunch.isOptional();
60  }
61 
62  const auto* geo = TOPGeometryPar::Instance()->getGeometry();
63  double timeStep = geo->getNominalTDC().getSyncTimeBase() / 6;
64  double xmi = - m_nx * timeStep / 2;
65  double xma = m_nx * timeStep / 2;
66 
67  auto time_vs_BS = new TH2F("time_vs_BS", "time vs BS, slot 13",
68  16, 0.0, 512.0, m_nx, xmi, xma);
69  time_vs_BS->SetXTitle("channel number");
70  time_vs_BS->SetYTitle("time [ns]");
71  registerObject<TH2F>("time_vs_BS", time_vs_BS);
72 
73  auto timeReference = new TH1F("time_reference", "time, slot 13(a, b, c)",
74  m_nx, xmi, xma);
75  timeReference->SetXTitle("time [ns]");
76  timeReference->SetYTitle("entries per bin [arbitrary]");
77  registerObject<TH1F>("time_reference", timeReference);
78 
79  for (unsigned i = 0; i < 4; i++) {
80  string name = "time_carr_" + to_string(i);
81  string title = "time, slot 13d, carrier " + to_string(i);
82  auto h = new TH1F(name.c_str(), title.c_str(), m_nx, xmi, xma);
83  h->SetXTitle("time [ns]");
84  h->SetYTitle("entries per bin [arbitrary]");
85  registerObject<TH1F>(name, h);
86  }
87 
88  }
89 
90 
91  void TOPAsicShiftsBS13dCollectorModule::collect()
92  {
93 
94  if (m_requireRecBunch) {
95  if (not m_recBunch.isValid()) return;
96  if (not m_recBunch->isReconstructed()) return;
97  }
98 
99  auto time_vs_BS = getObjectPtr<TH2F>("time_vs_BS");
100  auto timeReference = getObjectPtr<TH1F>("time_reference");
101  std::vector<TH1F*> timeCarriers;
102  for (unsigned i = 0; i < 4; i++) {
103  string name = "time_carr_" + to_string(i);
104  auto h = getObjectPtr<TH1F>(name);
105  timeCarriers.push_back(h);
106  }
107 
108  for (const auto& digit : m_topDigits) {
109  if (digit.getModuleID() != 13) continue;
110  if (digit.getHitQuality() != TOPDigit::c_Good) continue;
111  double time = digit.getTime() - m_timeOffset;
112  time_vs_BS->Fill(digit.getChannel(), time);
113  if (digit.getBoardstackNumber() < 3) {
114  timeReference->Fill(time);
115  } else {
116  auto c = digit.getCarrierNumber();
117  timeCarriers[c]->Fill(time);
118  }
119  }
120 
121  }
122 
123 
125 } // end namespace Belle2
#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.