11 #include <top/dbobjects/TOPSampleTimes.h>
13 #include <framework/logging/Logger.h>
25 void TOPSampleTimes::setTimeAxis(
double syncTimeBase)
27 double DTime = 2 * syncTimeBase;
28 double timeBin = DTime / c_TimeAxisSize;
29 for (
unsigned i = 0; i < c_TimeAxisSize; i++) m_timeAxis[i] = timeBin * i;
30 m_timeAxis[c_TimeAxisSize] = DTime;
31 m_calibrated = c_Default;
35 void TOPSampleTimes::setTimeAxis(
const std::vector<double>& sampleTimes,
38 if (sampleTimes.size() < c_TimeAxisSize) {
39 B2FATAL(
"TOPSampleTimes::setTimeAxis: vector too short");
43 for (
unsigned i = 0; i < c_TimeAxisSize; i++) m_timeAxis[i] = sampleTimes[i];
44 double DTime = 2 * syncTimeBase;
45 m_timeAxis[c_TimeAxisSize] = DTime;
46 m_calibrated = c_Calibrated;
50 std::vector<double> TOPSampleTimes::getTimeAxis()
const
52 std::vector<double> timeAxis;
53 for (
unsigned i = 0; i < c_TimeAxisSize + 1; i++) {
54 timeAxis.push_back(m_timeAxis[i]);
60 double TOPSampleTimes::getFullTime(
int window,
double sample)
const
63 int sampleNum = int(sample);
64 if (sample < 0) sampleNum--;
65 double frac = sample - sampleNum;
67 sampleNum += window * c_WindowSize;
68 int n = sampleNum / c_TimeAxisSize;
69 int k = sampleNum % c_TimeAxisSize;
75 double time = n * getTimeRange() + m_timeAxis[k];
76 time += (m_timeAxis[k + 1] - m_timeAxis[k]) * frac;
82 double TOPSampleTimes::getSample(
int window,
double time)
const
84 time += window * getTimeRange() / 4.0;
85 int n = int(time / getTimeRange());
88 double t = time - getTimeRange() * n;
90 int i2 = c_TimeAxisSize;
92 int i = (i1 + i2) / 2;
93 if (t > m_timeAxis[i]) {
100 return (n * c_TimeAxisSize - window * c_WindowSize + i1 +
101 (t - m_timeAxis[i1]) / (m_timeAxis[i2] - m_timeAxis[i1]));
106 double TOPSampleTimes::getTimeBin(
int window,
int sampleNumber)
const
108 int i = (window * c_WindowSize + sampleNumber) % c_TimeAxisSize;
109 if (i < 0) i += c_TimeAxisSize;
110 return m_timeAxis[i + 1] - m_timeAxis[i];