10 #include <top/modules/TOPTimeRecalibrator/TOPTimeRecalibratorModule.h>
11 #include <top/geometry/TOPGeometryPar.h>
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/datastore/StoreObjPtr.h>
18 #include <framework/logging/Logger.h>
45 setDescription(
"Utility module for re-calibrating time of TOPDigits. "
46 "Useful for checking new calibrations on existing cDST files. "
47 "Note that pulseWidth and timeError are not changed "
48 "although they also depend on time calibration.");
49 setPropertyFlags(c_ParallelProcessingCertified);
52 addParam(
"useSampleTimeCalibration", m_useSampleTimeCalibration,
53 "if true, use sample time calibration",
true);
54 addParam(
"useAsicShiftCalibration", m_useAsicShiftCalibration,
55 "if true, use ASIC shifts calibration",
true);
56 addParam(
"useChannelT0Calibration", m_useChannelT0Calibration,
57 "if true, use channel T0 calibration",
true);
58 addParam(
"useModuleT0Calibration", m_useModuleT0Calibration,
59 "if true, use module T0 calibration",
true);
60 addParam(
"useCommonT0Calibration", m_useCommonT0Calibration,
61 "if true, use common T0 calibration",
true);
62 addParam(
"useTimeWalkCalibration", m_useTimeWalkCalibration,
63 "if true, use time-walk calibration",
true);
64 addParam(
"subtractBunchTime", m_subtractBunchTime,
65 "if true, subtract reconstructed bunch time",
true);
69 void TOPTimeRecalibratorModule::initialize()
73 m_digits.isRequired();
74 m_recBunch.isRequired();
77 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
78 m_syncTimeBase = geo->getNominalTDC().getSyncTimeBase();
79 m_sampleTimes.setTimeAxis(m_syncTimeBase);
83 void TOPTimeRecalibratorModule::beginRun()
89 if (m_useSampleTimeCalibration) {
90 if (not m_timebase.isValid()) {
91 B2FATAL(
"Sample time calibration requested but not available for run "
92 << evtMetaData->getRun()
93 <<
" of experiment " << evtMetaData->getExperiment());
96 if (m_useChannelT0Calibration) {
97 if (not m_channelT0.isValid()) {
98 B2FATAL(
"Channel T0 calibration requested but not available for run "
99 << evtMetaData->getRun()
100 <<
" of experiment " << evtMetaData->getExperiment());
103 if (m_useAsicShiftCalibration) {
104 if (not m_asicShift.isValid()) {
105 B2FATAL(
"ASIC shifts calibration requested but not available for run "
106 << evtMetaData->getRun()
107 <<
" of experiment " << evtMetaData->getExperiment());
110 if (m_useModuleT0Calibration) {
111 if (not m_moduleT0.isValid()) {
112 B2FATAL(
"Module T0 calibration requested but not available for run "
113 << evtMetaData->getRun()
114 <<
" of experiment " << evtMetaData->getExperiment());
117 if (m_useCommonT0Calibration) {
118 if (not m_commonT0.isValid()) {
119 B2FATAL(
"Common T0 calibration requested but not available for run "
120 << evtMetaData->getRun()
121 <<
" of experiment " << evtMetaData->getExperiment());
124 if (m_useTimeWalkCalibration) {
125 if (not m_timeWalk.isValid()) {
127 B2WARNING(
"Time-walk calibration is not available for run "
128 << evtMetaData->getRun()
129 <<
" of experiment " << evtMetaData->getExperiment());
133 if (not m_feSetting.isValid()) {
134 B2FATAL(
"Front-end settings are not available for run "
135 << evtMetaData->getRun()
136 <<
" of experiment " << evtMetaData->getExperiment());
141 void TOPTimeRecalibratorModule::event()
143 int revo9cnt = m_recBunch->getRevo9Counter();
144 double SSTfrac = (revo9cnt % 6) / 6.0;
145 double offset = m_feSetting->getOffset() / 24.0;
146 double timeOffset = (SSTfrac + offset) * m_syncTimeBase;
147 const auto& feMapper = TOPGeometryPar::Instance()->getFrontEndMapper();
148 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
150 for (
auto& digit : m_digits) {
153 bool offsetStatus = digit.hasStatus(TOPDigit::c_OffsetSubtracted);
156 unsigned short statusBits = 0;
157 digit.setStatus(statusBits);
160 double rawTimeLeading = digit.getRawTime();
161 auto window = digit.getFirstWindow();
162 auto moduleID = digit.getModuleID();
163 auto channel = digit.getChannel();
166 const auto* sampleTimes = &m_sampleTimes;
167 if (m_useSampleTimeCalibration) {
168 auto bs = channel / 128;
169 const auto* feemap = feMapper.getMap(moduleID, bs);
171 B2ERROR(
"No front-end map available."
172 <<
LogVar(
"slot", moduleID)
173 <<
LogVar(
"boardstack", bs));
176 auto scrodID = feemap->getScrodID();
177 sampleTimes = m_timebase->getSampleTimes(scrodID, channel % 128);
178 if (sampleTimes->isCalibrated()) {
179 statusBits |= TOPDigit::c_TimeBaseCalibrated;
182 double time = sampleTimes->getTime(window, rawTimeLeading) - timeOffset;
185 if (m_useTimeWalkCalibration and m_timeWalk.isValid()) {
186 if (m_timeWalk->isCalibrated()) {
187 time -= m_timeWalk->getTimeWalk(digit.getPulseHeight());
190 if (m_useChannelT0Calibration) {
191 const auto& cal = m_channelT0;
192 if (cal->isCalibrated(moduleID, channel)) {
193 time -= cal->getT0(moduleID, channel);
194 statusBits |= TOPDigit::c_ChannelT0Calibrated;
197 if (m_useAsicShiftCalibration) {
198 auto asic = channel / 8;
199 if (m_asicShift->isCalibrated(moduleID, asic)) {
200 time -= m_asicShift->getT0(moduleID, asic);
203 if (m_useModuleT0Calibration) {
204 const auto& cal = m_moduleT0;
205 if (cal->isCalibrated(moduleID)) {
206 time -= cal->getT0(moduleID);
207 statusBits |= TOPDigit::c_ModuleT0Calibrated;
210 if (m_useCommonT0Calibration) {
211 const auto& cal = m_commonT0;
212 if (cal->isCalibrated()) {
213 time -= cal->getT0();
214 statusBits |= TOPDigit::c_CommonT0Calibrated;
219 if (m_subtractBunchTime and m_recBunch->isReconstructed()) {
220 time -= m_recBunch->getTime();
221 statusBits |= TOPDigit::c_EventT0Subtracted;
226 time -= geo->getNominalTDC().getOffset();
227 statusBits |= TOPDigit::c_OffsetSubtracted;
232 digit.setStatus(statusBits);
Type-safe access to single objects in the data store.
Utility module for re-calibrating time of TOPDigits pulseWidth and timeError are not changed although...
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.
Abstract base class for different kinds of events.