Belle II Software  release-08-01-10
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 //-----------------------------------------------------------------
25 //-----------------------------------------------------------------
26  REG_MODULE(TOPChannelMasker);
27 
28 //-----------------------------------------------------------------
29 // Implementation
30 //-----------------------------------------------------------------
31 
32  TOPChannelMaskerModule::TOPChannelMaskerModule() : Module()
33  {
34  // Set module properties
35  setDescription("Masks dead, hot and uncalibrated channels from the reconstruction");
36 
37  // Set property flags
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 
48  {
49  // register data objects
50  m_digits.isRequired();
51  m_eventAsicMask.isOptional();
52  }
53 
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 
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) {
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()) {
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 
110  }
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 (not m_savedAsicMask.isActive(slotID, channel)) {
134  digit.setHitQuality(TOPDigit::c_Masked);
135  const unsigned maxCount = 10; // at HLT this means (10 * number-of-processes) messages before being suppressed
136  if (m_errorCount < maxCount) {
137  B2ERROR("Unexpected hit found in a channel that is masked-out by firmware"
138  << LogVar("slotID", slotID) << LogVar("channel", channel));
139  } else if (m_errorCount == maxCount) {
140  B2ERROR("Unexpected hit found in a channel that is masked-out by firmware"
141  << LogVar("slotID", slotID) << LogVar("channel", channel)
142  << LogVar("... message will be suppressed now, errorCount", m_errorCount));
143  }
144  m_errorCount++;
145  continue;
146  }
147  if (m_maskUncalibratedChannelT0 and not m_channelT0->isCalibrated(slotID, channel)) {
148  digit.setHitQuality(TOPDigit::c_Uncalibrated);
149  continue;
150  }
152  const auto& fe_mapper = TOPGeometryPar::Instance()->getFrontEndMapper();
153  const auto* fe = fe_mapper.getMap(slotID, channel / 128);
154  if (not fe) {
155  B2ERROR("No front-end map found" << LogVar("slotID", slotID) << LogVar("channel", channel));
156  digit.setHitQuality(TOPDigit::c_Uncalibrated);
157  continue;
158  }
159  auto scrodID = fe->getScrodID();
160  const auto* sampleTimes = m_timebase->getSampleTimes(scrodID, channel);
161  if (not sampleTimes->isCalibrated()) {
162  digit.setHitQuality(TOPDigit::c_Uncalibrated);
163  }
164  }
165  }
166 
167  }
168 
170 } // end Belle2 namespace
171 
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
void set(const std::vector< unsigned short > &masks)
Sets bit fields of masked ASIC's.
Definition: TOPAsicMask.h:37
const std::vector< unsigned short > & get() const
Returns bit fields of masked ASIC's.
Definition: TOPAsicMask.h:43
DBObjPtr< TOPCalChannelMask > m_channelMask
list of dead/noisy channels
OptionalDBArray< TOPPmtQE > m_pmtQEData
quantum efficiencies
DBObjPtr< TOPCalTimebase > m_timebase
timebase
DBObjPtr< TOPCalChannelThresholdEff > m_thresholdEff
channel threshold effi.
DBObjPtr< TOPCalChannelT0 > m_channelT0
channel T0
DBObjPtr< TOPCalChannelRQE > m_channelRQE
channel relative quantum effi.
bool m_maskUncalibratedChannelT0
if true mask channelT0-uncalibrated channels
StoreObjPtr< TOPAsicMask > m_eventAsicMask
masked asics in firmware
StoreArray< TOPDigit > m_digits
collection of digits
TOPAsicMask m_savedAsicMask
the default ones or a copy from data store
bool m_maskUncalibratedTimebase
if true mask timebase-uncalibrated channels
OptionalDBArray< TOPPmtInstallation > m_pmtInstalled
PMT installation data.
const FrontEndMapper & getFrontEndMapper() const
Returns front-end mapper (mapping of SCROD's to positions within TOP modules)
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
static void setChannelMask(const DBObjPtr< TOPCalChannelMask > &mask, const TOPAsicMask &asicMask)
Sets channel masks.
static void setChannelEffi()
Sets relative efficiencies of pixels.
static void setUncalibratedChannelsOff(const DBObjPtr< TOPCalChannelT0 > &channelT0)
Sets uncalibrated channels off.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
bool isActive(int moduleID, unsigned channel) const
Returns true if channel is not explicitely labeled as masked.
Definition: TOPAsicMask.cc:17
virtual void initialize() override
initialize method: registers datastore objects (the TOP hits)
virtual void event() override
event method: removes channels from the reconstruction pdf, flags hits from noisy channels as junk
virtual void beginRun() override
Called when entering a new run.
Abstract base class for different kinds of events.