Belle II Software development
KLMTime.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 <klm/time/KLMTime.h>
11
12using namespace Belle2;
13
15{
16 static KLMTime klmElementNumbers;
17 return klmElementNumbers;
18}
19
21{
23 1.0 / m_HardwareClockSettings->getClockFrequency(Const::KLM, "TDC");
24 m_CTimePeriod = 1.0 / m_HardwareClockSettings->getGlobalClockFrequency();
25}
26
27double KLMTime::getScintillatorTime(int ctime, int tdc, int triggerCTime) const
28{
29 int cTimeShift = m_KLMTimeConversion->getCTimeShift();
30 /* Relative time in TDC periods for scintillators. */
31 int relativeTime;
32 /*
33 * All time values were shifted by 2 bits for the phase2 data.
34 */
35 int correctedCTime = (((ctime << cTimeShift) & 0xFFFF) << 3) + (tdc & 0x7);
36 int correctedTriggerCTime = ((triggerCTime << cTimeShift) & 0xFFFF) << 3;
37 /* Scintillator: 16-bit CTIME. */
38 if (correctedCTime <= correctedTriggerCTime)
39 relativeTime = correctedCTime - correctedTriggerCTime;
40 else
41 relativeTime = correctedCTime - correctedTriggerCTime - (0x10000 << 3);
42 /* Get time in TDC periods. */
43 return relativeTime * m_TDCPeriod;
44}
45
46std::pair<int, double> KLMTime::getRPCTimes(int ctime, int tdc, int triggerTime) const
47{
48 /* Relative time in TDC periods for RPC hits. */
49 int relativeTime = tdc & 0x7FF;
50 /*
51 * TDC frequency is 8 times greater than revo9 frequency.
52 * The 2 last bits are zero, thus, the precision is 4 * (TDC period).
53 * The TDC has 11 bits of dynamic range. Shift the triggerTime by
54 * 10 ticks to align the new prompt-time peak with the old
55 * TriggerCTime-relative peak (for backward compatibility of calibration).
56 */
57 int trigger = ((triggerTime - 10) & 0x0FF) << 3;
58 if (relativeTime <= trigger)
59 relativeTime -= trigger;
60 else
61 relativeTime -= trigger + 0x800;
62 return std::pair<int, double>(ctime - triggerTime,
63 relativeTime * m_TDCPeriod);
64}
65
66double KLMTime::getTimeSimulation(int tdc, bool scintillator) const
67{
68 double timeOffset = m_KLMTimeConversion->getTimeOffset();
69 (void)scintillator;
70 return tdc * m_TDCPeriod + timeOffset;
71}
72
73uint16_t KLMTime::getTDCByTime(double time) const
74{
75 double timeOffset = m_KLMTimeConversion->getTimeOffset();
76 return (time - timeOffset) / m_TDCPeriod;
77}
KLM time conversion.
Definition: KLMTime.h:27
double m_TDCPeriod
TDC period (stored here because getting it from m_HardwareClockSettings requires to search in a map).
Definition: KLMTime.h:112
std::pair< int, double > getRPCTimes(int ctime, int tdc, int triggerTime) const
Get coarse and fine times for RPC.
Definition: KLMTime.cc:46
double getTimeSimulation(int tdc, bool scintillator) const
Get time for simulation.
Definition: KLMTime.cc:66
double getScintillatorTime(int ctime, int tdc, int triggerCTime) const
Get time for scintillator.
Definition: KLMTime.cc:27
uint16_t getTDCByTime(double time) const
Get TDC by time.
Definition: KLMTime.cc:73
double m_CTimePeriod
CTIME period.
Definition: KLMTime.h:115
void updateConstants()
Update constants from database objects.
Definition: KLMTime.cc:20
static KLMTime & Instance()
Instantiation.
Definition: KLMTime.cc:14
DBObjPtr< HardwareClockSettings > m_HardwareClockSettings
Hardware clock settings.
Definition: KLMTime.h:106
DBObjPtr< KLMTimeConversion > m_KLMTimeConversion
KLM time conversion.
Definition: KLMTime.h:103
Abstract base class for different kinds of events.