Belle II Software  release-08-01-10
TOPOffsetCollectorModule.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/TOPOffsetCollectorModule.h>
10 #include <framework/logging/Logger.h>
11 #include <TH1F.h>
12 
13 
14 using namespace std;
15 
16 namespace Belle2 {
22  //-----------------------------------------------------------------
24  //-----------------------------------------------------------------
25 
26  REG_MODULE(TOPOffsetCollector);
27 
28  //-----------------------------------------------------------------
29  // Implementation
30  //-----------------------------------------------------------------
31 
32  TOPOffsetCollectorModule::TOPOffsetCollectorModule()
33  {
34  // set module description and processing properties
35  setDescription("A collector for eventT0 and fill pattern offset calibrations");
36  setPropertyFlags(c_ParallelProcessingCertified);
37 
38  }
39 
40 
41  void TOPOffsetCollectorModule::prepare()
42  {
43  m_recBunch.isRequired();
44  m_eventT0.isRequired();
45 
46  m_names[Const::SVD] = "svdOffset";
47  m_names[Const::CDC] = "cdcOffset";
48  for (const auto& x : m_names) {
49  registerObject<TH1F>(x.second, new TH1F(x.second.c_str(), "Event T0 difference w.r.t TOP; #Delta T_{0} [ns]",
50  500, -50, 50));
51  }
52 
53  int RFBuckets = m_bunchStructure->getRFBucketsPerRevolution();
54  registerObject<TH1F>("fillPattern", new TH1F("fillPattern", "Fill pattern from DB; bucket number",
55  RFBuckets, 0, RFBuckets));
56  registerObject<TH1F>("recBuckets", new TH1F("recBuckets", "Reconstructed buckets; bucket number",
57  RFBuckets, 0, RFBuckets));
58  }
59 
60 
61  void TOPOffsetCollectorModule::collect()
62  {
63  if (m_firstEvent) {
64  m_firstEvent = false;
65  if (m_bunchStructure->isSet()) {
66  auto h = getObjectPtr<TH1F>("fillPattern");
67  int RFBuckets = m_bunchStructure->getRFBucketsPerRevolution();
68  for (int i = 0; i < RFBuckets; i++) {
69  if (m_bunchStructure->getBucket(i)) h->SetBinContent(i + 1, 1);
70  }
71  }
72  }
73 
74  if (not m_recBunch->isReconstructed()) return;
75 
76  for (const auto& x : m_names) {
77  const auto& detector = x.first;
78  if (m_eventT0->hasTemporaryEventT0(detector)) {
79  auto eventT0s = m_eventT0->getTemporaryEventT0s(detector);
80  if (eventT0s.empty()) continue;
81  if (detector == Const::CDC and eventT0s.back().algorithm != "chi2") continue;
82  double t0 = eventT0s.back().eventT0;
83  auto h = getObjectPtr<TH1F>(x.second);
84  h->Fill(t0 - m_recBunch->getTime());
85  }
86  }
87 
88  auto h = getObjectPtr<TH1F>("recBuckets");
89  h->Fill(m_recBunch->getBucketNumber(0, m_bunchStructure->getRFBucketsPerRevolution()));
90  }
91 
93 }
#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.