Belle II Software  release-06-00-14
TOPChannelMaskerModule.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/TOPChannelMasker/TOPChannelMaskerModule.h>
10 #include <top/reconstruction_cpp/TOPRecoManager.h>
11 #include <top/geometry/TOPGeometryPar.h>
12 
13 using namespace std;
14 
15 namespace Belle2 {
21  using namespace TOP;
22 
23 //-----------------------------------------------------------------
24 // Register the Module
25 //-----------------------------------------------------------------
26  REG_MODULE(TOPChannelMasker)
27 
28 //-----------------------------------------------------------------
29 // Implementation
30 //-----------------------------------------------------------------
31 
33  {
34  // Set module properties
35  setDescription("Masks dead, hot and uncalibrated channels from the reconstruction");
36 
37  // Set property flags
38  setPropertyFlags(c_ParallelProcessingCertified);
39 
40  // Add parameters
41  addParam("maskUncalibratedChannelT0", m_maskUncalibratedChannelT0,
42  "if true, mask channelT0-uncalibrated channels", true);
43  addParam("maskUncalibratedTimebase", m_maskUncalibratedTimebase,
44  "if true, mask timebase-uncalibrated channels ", true);
45  }
46 
47  void TOPChannelMaskerModule::initialize()
48  {
49  // register data objects
50  m_digits.isRequired();
51  m_eventAsicMask.isOptional();
52  }
53 
54  void TOPChannelMaskerModule::beginRun()
55  {
56 
57  if (not m_channelMask.isValid()) {
58  B2FATAL("channel mask not available");
59  }
60  if (not m_channelT0.isValid()) {
61  B2FATAL("channel T0 calibration not available");
62  }
63  if (not m_timebase.isValid()) {
64  B2FATAL("timebase calibration not available");
65  }
66 
67  }
68 
69  void TOPChannelMaskerModule::event()
70  {
71 
72  // have those payloads changed?
73 
74  bool pmtInstalled = m_pmtInstalled.hasChanged();
75  bool pmtQEData = m_pmtQEData.hasChanged();
76  bool channelRQE = m_channelRQE.hasChanged();
77  bool thresholdEff = m_thresholdEff.hasChanged();
78 
79  // if at least one then pass pixel relative efficiencies to the reconstructon code
80 
81  if (pmtInstalled or pmtQEData or channelRQE or thresholdEff) {
82  TOPRecoManager::setChannelEffi();
83  }
84 
85  // have asic masks changed?
86 
87  bool asicMasksChanged = false;
88  if (m_eventAsicMask.isValid()) {
89  if (m_eventAsicMask->get() != m_savedAsicMask.get()) {
90  m_savedAsicMask.set(m_eventAsicMask->get());
91  asicMasksChanged = true;
92  }
93  }
94 
95  // have channel masks or calibration changed?
96 
97  bool channelMaskChanged = m_channelMask.hasChanged();
98  bool channelT0Changed = m_channelT0.hasChanged();
99  bool timebaseChanged = m_timebase.hasChanged();
100 
101  // if at least one then pass the new masking to the reconstruction code
102 
103  if (channelMaskChanged or asicMasksChanged or
104  (m_maskUncalibratedChannelT0 and channelT0Changed) or
105  (m_maskUncalibratedTimebase and timebaseChanged)) {
106 
107  TOPRecoManager::setChannelMask(m_channelMask, m_savedAsicMask);
108  if (m_maskUncalibratedChannelT0) {
109  TOPRecoManager::setUncalibratedChannelsOff(m_channelT0);
110  }
111  if (m_maskUncalibratedTimebase) {
112  TOPRecoManager::setUncalibratedChannelsOff(m_timebase);
113  }
114  }
115 
116  // now flag actual data Cherenkov hits as coming from masked channels
117 
118  for (auto& digit : m_digits) {
119  // if already set switch the state back to c_Good (e.g. for digits read from file)
120  if (digit.getHitQuality() == TOPDigit::c_Masked or
121  digit.getHitQuality() == TOPDigit::c_Uncalibrated) {
122  digit.setHitQuality(TOPDigit::c_Good);
123  }
124  if (digit.getHitQuality() != TOPDigit::c_Good) continue;
125 
126  // now do the new masking of c_Good
127  auto slotID = digit.getModuleID();
128  auto channel = digit.getChannel();
129  if (not m_channelMask->isActive(slotID, channel)) {
130  digit.setHitQuality(TOPDigit::c_Masked);
131  continue;
132  }
133  if (m_maskUncalibratedChannelT0 and not m_channelT0->isCalibrated(slotID, channel)) {
134  digit.setHitQuality(TOPDigit::c_Uncalibrated);
135  continue;
136  }
137  if (m_maskUncalibratedTimebase) {
138  const auto& fe_mapper = TOPGeometryPar::Instance()->getFrontEndMapper();
139  const auto* fe = fe_mapper.getMap(slotID, channel / 128);
140  if (not fe) {
141  B2ERROR("No front-end map found" << LogVar("slotID", slotID) << LogVar("channel", channel));
142  digit.setHitQuality(TOPDigit::c_Uncalibrated);
143  continue;
144  }
145  auto scrodID = fe->getScrodID();
146  const auto* sampleTimes = m_timebase->getSampleTimes(scrodID, channel);
147  if (not sampleTimes->isCalibrated()) {
148  digit.setHitQuality(TOPDigit::c_Uncalibrated);
149  }
150  }
151  }
152 
153  }
154 
156 } // end Belle2 namespace
157 
Base class for Modules.
Definition: Module.h:72
Masks dead PMs from the reconstruction.
Class to store variables with their name which were sent to the logging service.
#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.