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