Belle II Software  release-05-02-19
TOPChannelMaskerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: *
7  * Jan Strube (jan.strube@pnnl.gov) *
8  * Sam Cunliffe (sam.cunliffe@desy.de) *
9  * *
10  * This software is provided "as is" without any warranty. *
11  **************************************************************************/
12 
13 #include <top/modules/TOPChannelMasker/TOPChannelMaskerModule.h>
14 #include <top/reconstruction/TOPreco.h> // reconstruction wrapper
15 #include <top/reconstruction/TOPconfigure.h>
16 
17 using namespace std;
18 
19 namespace Belle2 {
25  using namespace TOP;
26 
27 //-----------------------------------------------------------------
28 // Register the Module
29 //-----------------------------------------------------------------
30  REG_MODULE(TOPChannelMasker)
31 
32 //-----------------------------------------------------------------
33 // Implementation
34 //-----------------------------------------------------------------
35 
37  {
38  // Set module properties
39  setDescription("Masks dead PMs from the reconstruction");
40 
41  // Set property flags
42  setPropertyFlags(c_ParallelProcessingCertified);
43 
44  // Add parameters
45  addParam("printMask", m_printMask,
46  "if true, print channel mask as set in reconstruction", false);
47  addParam("maskUncalibratedChannelT0", m_maskUncalibratedChannelT0,
48  "if true, mask channelT0-uncalibrated channels", true);
49  addParam("maskUncalibratedTimebase", m_maskUncalibratedTimebase,
50  "if true, mask timebase-uncalibrated channels ", true);
51  }
52 
53  void TOPChannelMaskerModule::initialize()
54  {
55  // register data objects
56  m_digits.isRequired();
57  m_eventAsicMask.isOptional();
58 
59  // Configure TOP detector in FORTRAN code
60  TOPconfigure config;
61  }
62 
63  void TOPChannelMaskerModule::beginRun()
64  {
65 
66  if (not m_channelMask.isValid()) {
67  B2FATAL("channel mask not available");
68  }
69  if (not m_channelT0.isValid()) {
70  B2FATAL("channel T0 calibration not available");
71  }
72  if (not m_timebase.isValid()) {
73  B2FATAL("timebase calibration not available");
74  }
75 
76  }
77 
78  void TOPChannelMaskerModule::event()
79  {
80 
81  // have those payloads changed?
82 
83  bool pmtInstalled = m_pmtInstalled.hasChanged();
84  bool pmtQEData = m_pmtQEData.hasChanged();
85  bool channelRQE = m_channelRQE.hasChanged();
86  bool thresholdEff = m_thresholdEff.hasChanged();
87 
88  // if at least one then pass pixel relative efficiencies to the reconstructon code
89 
90  if (pmtInstalled or pmtQEData or channelRQE or thresholdEff) {
91  TOPreco::setChannelEffi();
92  }
93 
94  // have asic masks changed?
95 
96  bool asicMasksChanged = false;
97  if (m_eventAsicMask.isValid()) {
98  if (m_eventAsicMask->get() != m_savedAsicMask.get()) {
99  m_savedAsicMask.set(m_eventAsicMask->get());
100  asicMasksChanged = true;
101  }
102  }
103 
104  // have channel masks or calibration changed?
105 
106  bool channelMaskChanged = m_channelMask.hasChanged();
107  bool channelT0Changed = m_channelT0.hasChanged();
108  bool timebaseChanged = m_timebase.hasChanged();
109 
110  // if at least one then pass the new masking to the reconstruction code
111 
112  if (channelMaskChanged or asicMasksChanged or
113  (m_maskUncalibratedChannelT0 and channelT0Changed) or
114  (m_maskUncalibratedTimebase and timebaseChanged)) {
115 
116  TOPreco::setChannelMask(m_channelMask, m_savedAsicMask);
117  if (m_maskUncalibratedChannelT0) TOPreco::setUncalibratedChannelsOff(m_channelT0);
118  if (m_maskUncalibratedTimebase) TOPreco::setUncalibratedChannelsOff(m_timebase);
119  if (m_printMask) TOPreco::printChannelMask();
120  }
121 
122  // now flag actual data Cherenkov hits as coming from masked channels
123 
124  for (auto& digit : m_digits) {
125  // if already set switch the state back to c_Good (e.g. for digits read from file)
126  if (digit.getHitQuality() == TOPDigit::c_Masked or
127  digit.getHitQuality() == TOPDigit::c_Uncalibrated) {
128  digit.setHitQuality(TOPDigit::c_Good);
129  }
130  // skip digit if not c_Good
131  if (digit.getHitQuality() != TOPDigit::c_Good) continue;
132  // now do the new masking of c_Good
133  if (not m_channelMask->isActive(digit.getModuleID(), digit.getChannel())) {
134  digit.setHitQuality(TOPDigit::c_Masked);
135  }
136  if (m_maskUncalibratedChannelT0 and not digit.isChannelT0Calibrated()) {
137  digit.setHitQuality(TOPDigit::c_Uncalibrated);
138  }
139  if (m_maskUncalibratedTimebase and not digit.isTimeBaseCalibrated()) {
140  digit.setHitQuality(TOPDigit::c_Uncalibrated);
141  }
142  }
143 
144  }
145 
147 } // end Belle2 namespace
148 
Belle2::TOPChannelMaskerModule
Masks dead PMs from the reconstruction.
Definition: TOPChannelMaskerModule.h:52
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOP::TOPconfigure
Configure TOP geometry for reconstruction: provides interface to fortran code.
Definition: TOPconfigure.h:36