9 #include <top/dbobjects/TOPSampleTimes.h>
11 #include <framework/logging/Logger.h>
23 void TOPSampleTimes::setTimeAxis(
double syncTimeBase)
25 double DTime = 2 * syncTimeBase;
26 double timeBin = DTime /
static_cast<double>(c_TimeAxisSize);
27 for (
unsigned i = 0; i < c_TimeAxisSize; i++) m_timeAxis[i] = timeBin * i;
28 m_timeAxis[c_TimeAxisSize] = DTime;
29 m_calibrated = c_Default;
33 void TOPSampleTimes::setTimeAxis(
const std::vector<double>& sampleTimes,
36 if (sampleTimes.size() < c_TimeAxisSize) {
37 B2FATAL(
"TOPSampleTimes::setTimeAxis: vector too short");
41 for (
unsigned i = 0; i < c_TimeAxisSize; i++) m_timeAxis[i] = sampleTimes[i];
42 double DTime = 2 * syncTimeBase;
43 m_timeAxis[c_TimeAxisSize] = DTime;
44 m_calibrated = c_Calibrated;
48 std::vector<double> TOPSampleTimes::getTimeAxis()
const
50 std::vector<double> timeAxis;
51 for (
unsigned i = 0; i < c_TimeAxisSize + 1; i++) {
52 timeAxis.push_back(m_timeAxis[i]);
58 double TOPSampleTimes::getFullTime(
int window,
double sample)
const
61 int sampleNum = int(sample);
62 if (sample < 0) sampleNum--;
63 double frac = sample - sampleNum;
65 sampleNum += window * c_WindowSize;
66 int n = sampleNum / c_TimeAxisSize;
67 int k = sampleNum % c_TimeAxisSize;
73 double time = n * getTimeRange() + m_timeAxis[k];
74 time += (m_timeAxis[k + 1] - m_timeAxis[k]) * frac;
80 double TOPSampleTimes::getSample(
int window,
double time)
const
82 time += window * getTimeRange() / 4.0;
83 int n = int(time / getTimeRange());
86 double t = time - getTimeRange() * n;
88 int i2 = c_TimeAxisSize;
90 int i = (i1 + i2) / 2;
91 if (t > m_timeAxis[i]) {
98 return (n * c_TimeAxisSize - window * c_WindowSize + i1 +
99 (t - m_timeAxis[i1]) / (m_timeAxis[i2] - m_timeAxis[i1]));
104 double TOPSampleTimes::getTimeBin(
int window,
int sampleNumber)
const
106 int i = (window * c_WindowSize + sampleNumber) % c_TimeAxisSize;
107 if (i < 0) i += c_TimeAxisSize;
108 return m_timeAxis[i + 1] - m_timeAxis[i];
Abstract base class for different kinds of events.