Belle II Software development
TOPNominalTDC.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#include <top/dbobjects/TOPNominalTDC.h>
10#include <framework/logging/Logger.h>
11#include <framework/gearbox/Unit.h>
12#include <iostream>
13
14using namespace std;
15
16namespace Belle2 {
23 int subBits,
24 double syncTimeBase,
25 int numofBunches,
26 double offset,
27 double pileupTime,
28 double doubleHitResolution,
29 double timeJitter,
30 double efficiency,
31 const std::string& name):
32 TOPGeoBase(name),
33 m_numWindows(numWindows), m_subBits(subBits), m_syncTimeBase(syncTimeBase),
34 m_numofBunches(numofBunches),
35 m_offset(offset), m_pileupTime(pileupTime), m_doubleHitResolution(doubleHitResolution),
36 m_timeJitter(timeJitter), m_efficiency(efficiency)
37 {
38 if (numWindows <= 0)
39 B2FATAL("TOPNominalTDC: numWindows must be > 0");
40 if (subBits < 0)
41 B2FATAL("TOPNominalTDC: subBits must be >= 0");
42
43 int numSamples = numWindows * c_WindowSize;
44 int numBits = subBits - 1;
45 int k = numSamples;
46 do {
47 numBits++;
48 k /= 2;
49 } while (k > 0);
50 if (numSamples > (1 << (numBits - subBits))) numBits++;
51 m_numBits = numBits;
52
53 int syncSamples = c_syncWindows * c_WindowSize;
54 m_sampleWidth = syncTimeBase / syncSamples;
55 m_binWidth = m_sampleWidth / (1 << subBits);
56 }
57
58 int TOPNominalTDC::getTDCcount(double time) const
59 {
60 time += m_offset;
61 int overflow = getOverflowValue();
62 if (time < 0) return overflow;
63 if (time > overflow * m_binWidth) return overflow;
64 return int(time / m_binWidth);
65 }
66
67 int TOPNominalTDC::getSample(double time) const
68 {
69 time += m_offset;
70 if (time > 0) {
71 return int(time / m_sampleWidth);
72 } else {
73 return int(time / m_sampleWidth) - 1;
74 }
75 }
76
77 bool TOPNominalTDC::isSampleValid(int sample) const
78 {
79 if (sample < 0) return false;
80 if (sample >= (int) m_numWindows * c_WindowSize) return false;
81 return true;
82 }
83
85 {
86 if (m_pileupTime < 0) return false;
87 if (m_doubleHitResolution < 0) return false;
88 if (m_timeJitter < 0) return false;
89 if (m_efficiency <= 0 or m_efficiency > 1) return false;
90 return true;
91 }
92
93 void TOPNominalTDC::print(const std::string& title) const
94 {
96 cout << " range: [" << getTimeMin() << ", " << getTimeMax() << "] ns" << endl;
97 cout << " offset: " << getOffset() << " ns" << endl;
98 cout << " number of bits: " << getNumBits() << endl;
99 cout << " bin width: " << getBinWidth() / Unit::ps << " ps" << endl;
100 cout << " number of ASIC windows: " << getNumWindows() << endl;
101 cout << " number of bits per sample: " << getSubBits() << endl;
102 cout << " synchonization time base: " << getSyncTimeBase() << " ns" << endl;
103 cout << " pile-up time: " << getPileupTime() << " ns" << endl;
104 cout << " double hit resolution: " << getDoubleHitResolution() << " ns" << endl;
105 cout << " r.m.s. of time jitter: " << getTimeJitter() / Unit::ps << " ps" << endl;
106 cout << " electronic efficiency: " << getEfficiency() << endl;
107 }
108
110} // end Belle2 namespace
Base class for geometry parameters.
Definition: TOPGeoBase.h:25
unsigned m_numBits
number of bits
double getTimeJitter() const
Returns r.m.s.
float m_offset
time offset
@ c_syncWindows
number of windows corresponding to syncTimeBase
Definition: TOPNominalTDC.h:29
@ c_WindowSize
number of samples per ASIC window
Definition: TOPNominalTDC.h:28
float m_pileupTime
pile-up time
int getOverflowValue() const
Returns TDC overflow value.
TOPNominalTDC()
Default constructor.
Definition: TOPNominalTDC.h:35
double getPileupTime() const
Returns pile-up time.
float m_doubleHitResolution
double hit resolution time
double getTimeMin() const
Returns time range lower limit.
double getTimeMax() const
Returns time range upper limit.
double getSyncTimeBase() const
Returns synchonization time base (time width of c_syncWindows)
double getOffset() const
Returns time offset.
double getDoubleHitResolution() const
Returns double hit resolution time.
double getEfficiency() const
Returns electronic efficiency.
float m_timeJitter
r.m.s.
unsigned getSubBits() const
Returns number of bits per sample.
float m_sampleWidth
time between two samples
double getBinWidth() const
Returns time width of a TDC bin.
float m_binWidth
time width of a TDC bin
unsigned m_numWindows
number of ASIC windows per waveform
unsigned getNumWindows() const
Returns number of ASIC windows per waveform.
unsigned getNumBits() const
Returns number of bits.
static const double ps
[picosecond]
Definition: Unit.h:98
bool isConsistent() const override
Check for consistency of data members.
void printUnderlined(const std::string &title) const
Print the content of the class.
Definition: TOPGeoBase.cc:35
int getTDCcount(double time) const
Converts time to TDC count.
void print(const std::string &title="Nominal time-to-digit conversion parameters") const override
Print the content of the class.
bool isSampleValid(int sample) const
Check for the validity of sample number.
int getSample(double time) const
Converts time to sample number.
Abstract base class for different kinds of events.
STL namespace.