Belle II Software development
TOPTimeRecalibratorModule.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// Own header.
10#include <top/modules/TOPTimeRecalibrator/TOPTimeRecalibratorModule.h>
11
12// TOP headers.
13#include <top/geometry/TOPGeometryPar.h>
14
15// framework - DataStore
16#include <framework/datastore/StoreArray.h>
17#include <framework/datastore/StoreObjPtr.h>
18
19// framework aux
20#include <framework/logging/Logger.h>
21
22
23using namespace std;
24
25namespace Belle2 {
31 using namespace TOP;
32
33 //-----------------------------------------------------------------
35 //-----------------------------------------------------------------
36
37 REG_MODULE(TOPTimeRecalibrator);
38
39 //-----------------------------------------------------------------
40 // Implementation
41 //-----------------------------------------------------------------
42
44
45 {
46 // set module description
47 setDescription("Utility module for re-calibrating time of TOPDigits. "
48 "Useful for checking new calibrations on existing cDST files. "
49 "Note that pulseWidth and timeError are not changed "
50 "although they also depend on time calibration.");
52
53 // Add parameters
54 addParam("useSampleTimeCalibration", m_useSampleTimeCalibration,
55 "if true, use sample time calibration", true);
56 addParam("useAsicShiftCalibration", m_useAsicShiftCalibration,
57 "if true, use ASIC shifts calibration", true);
58 addParam("useChannelT0Calibration", m_useChannelT0Calibration,
59 "if true, use channel T0 calibration", true);
60 addParam("useModuleT0Calibration", m_useModuleT0Calibration,
61 "if true, use module T0 calibration", true);
62 addParam("useCommonT0Calibration", m_useCommonT0Calibration,
63 "if true, use common T0 calibration", true);
64 addParam("useTimeWalkCalibration", m_useTimeWalkCalibration,
65 "if true, use time-walk calibration", true);
66 addParam("subtractBunchTime", m_subtractBunchTime,
67 "if true, subtract reconstructed bunch time", true);
68
69 }
70
72 {
73
74 // registration of objects in datastore
75 m_digits.isRequired();
76 m_recBunch.isRequired();
77
78 // equidistant sample times in case calibration is not required
79 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
80 m_syncTimeBase = geo->getNominalTDC().getSyncTimeBase();
82
83 }
84
86 {
88
89 // check if calibrations are available when needed - if not, terminate
90
92 if (not m_timebase.isValid()) {
93 B2FATAL("Sample time calibration requested but not available for run "
94 << evtMetaData->getRun()
95 << " of experiment " << evtMetaData->getExperiment());
96 }
97 }
99 if (not m_channelT0.isValid()) {
100 B2FATAL("Channel T0 calibration requested but not available for run "
101 << evtMetaData->getRun()
102 << " of experiment " << evtMetaData->getExperiment());
103 }
104 }
106 if (not m_asicShift.isValid()) {
107 B2FATAL("ASIC shifts calibration requested but not available for run "
108 << evtMetaData->getRun()
109 << " of experiment " << evtMetaData->getExperiment());
110 }
111 }
113 if (not m_moduleT0.isValid()) {
114 B2FATAL("Module T0 calibration requested but not available for run "
115 << evtMetaData->getRun()
116 << " of experiment " << evtMetaData->getExperiment());
117 }
118 }
120 if (not m_commonT0.isValid()) {
121 B2FATAL("Common T0 calibration requested but not available for run "
122 << evtMetaData->getRun()
123 << " of experiment " << evtMetaData->getExperiment());
124 }
125 }
127 if (not m_timeWalk.isValid()) {
128 // B2FATAL("Time-walk calibration requested but not available for run "
129 B2WARNING("Time-walk calibration is not available for run "
130 << evtMetaData->getRun()
131 << " of experiment " << evtMetaData->getExperiment());
132 }
133 }
134
135 if (not m_feSetting.isValid()) {
136 B2FATAL("Front-end settings are not available for run "
137 << evtMetaData->getRun()
138 << " of experiment " << evtMetaData->getExperiment());
139 }
140
141 }
142
144 {
145 int revo9cnt = m_recBunch->getRevo9Counter();
146 double SSTfrac = (revo9cnt % 6) / 6.0;
147 double offset = m_feSetting->getOffset() / 24.0;
148 double timeOffset = (SSTfrac + offset) * m_syncTimeBase; // in [ns], to be subtracted
149 const auto& feMapper = TOPGeometryPar::Instance()->getFrontEndMapper();
150 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
151
152 for (auto& digit : m_digits) {
153
154 // save MC offset status
155 bool offsetStatus = digit.hasStatus(TOPDigit::c_OffsetSubtracted);
156
157 // reset status bits
158 unsigned short statusBits = 0;
159 digit.setStatus(statusBits);
160
161 // get what's needed from a digit
162 double rawTimeLeading = digit.getRawTime();
163 auto window = digit.getFirstWindow();
164 auto moduleID = digit.getModuleID();
165 auto channel = digit.getChannel();
166
167 // convert raw time to time using equidistant or calibrated time base
168 const auto* sampleTimes = &m_sampleTimes; // equidistant sample times
170 auto bs = channel / 128;
171 const auto* feemap = feMapper.getMap(moduleID, bs);
172 if (not feemap) {
173 B2ERROR("No front-end map available."
174 << LogVar("slot", moduleID)
175 << LogVar("boardstack", bs));
176 continue;
177 }
178 auto scrodID = feemap->getScrodID();
179 sampleTimes = m_timebase->getSampleTimes(scrodID, channel % 128);
180 if (sampleTimes->isCalibrated()) {
181 statusBits |= TOPDigit::c_TimeBaseCalibrated;
182 }
183 }
184 double time = sampleTimes->getTime(window, rawTimeLeading) - timeOffset;
185
186 // apply other calibrations
187 if (m_useTimeWalkCalibration and m_timeWalk.isValid()) {
188 if (m_timeWalk->isCalibrated()) {
189 time -= m_timeWalk->getTimeWalk(digit.getPulseHeight());
190 }
191 }
193 const auto& cal = m_channelT0;
194 if (cal->isCalibrated(moduleID, channel)) {
195 time -= cal->getT0(moduleID, channel);
196 statusBits |= TOPDigit::c_ChannelT0Calibrated;
197 }
198 }
200 auto asic = channel / 8;
201 if (m_asicShift->isCalibrated(moduleID, asic)) {
202 time -= m_asicShift->getT0(moduleID, asic);
203 }
204 }
206 const auto& cal = m_moduleT0;
207 if (cal->isCalibrated(moduleID)) {
208 time -= cal->getT0(moduleID);
209 statusBits |= TOPDigit::c_ModuleT0Calibrated;
210 }
211 }
213 const auto& cal = m_commonT0;
214 if (cal->isCalibrated()) {
215 time -= cal->getT0();
216 statusBits |= TOPDigit::c_CommonT0Calibrated;
217 }
218 }
219
220 // subtract bunch time
221 if (m_subtractBunchTime and m_recBunch->isReconstructed()) {
222 time -= m_recBunch->getTime();
223 statusBits |= TOPDigit::c_EventT0Subtracted;
224 }
225
226 // subtract offset used in MC if status bit was set in this digit
227 if (offsetStatus) {
228 time -= geo->getNominalTDC().getOffset();
229 statusBits |= TOPDigit::c_OffsetSubtracted;
230 }
231
232 // set re-calibrated time and status bits
233 digit.setTime(time);
234 digit.setStatus(statusBits);
235 }
236
237 }
238
239
241} // end Belle2 namespace
242
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
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool m_subtractBunchTime
if true, subtract reconstructed bunch time
DBObjPtr< TOPCalTimebase > m_timebase
sample time calibration constants
StoreObjPtr< TOPRecBunch > m_recBunch
reconstructed bunch
DBObjPtr< TOPCalAsicShift > m_asicShift
ASIC shifts calibration constants.
DBObjPtr< TOPFrontEndSetting > m_feSetting
front-end settings
DBObjPtr< TOPCalCommonT0 > m_commonT0
common T0 calibration constants
bool m_useAsicShiftCalibration
if true, use asic shifts calibration
bool m_useSampleTimeCalibration
if true, use sample time calibration
DBObjPtr< TOPCalChannelT0 > m_channelT0
channel T0 calibration constants
bool m_useTimeWalkCalibration
if true, use time-walk calibration
OptionalDBObjPtr< TOPCalTimeWalk > m_timeWalk
time-walk calibration constants
bool m_useChannelT0Calibration
if true, use channel T0 calibration
bool m_useCommonT0Calibration
if true, use common T0 calibration
bool m_useModuleT0Calibration
if true, use module T0 calibration
StoreArray< TOPDigit > m_digits
collection of digits
DBObjPtr< TOPCalModuleT0 > m_moduleT0
module T0 calibration constants
TOPSampleTimes m_sampleTimes
equidistant in case no calibration required
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
const FrontEndMapper & getFrontEndMapper() const
Returns front-end mapper (mapping of SCROD's to positions within TOP modules)
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
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void beginRun() override
Called when entering a new run.
void setTimeAxis(double syncTimeBase)
Sets equidistant time axis (uncalibrated).
Abstract base class for different kinds of events.
STL namespace.