Belle II Software  release-05-01-25
TOPNominalTDC.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <top/dbobjects/TOPNominalTDC.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/gearbox/Unit.h>
14 #include <iostream>
15 
16 using namespace std;
17 
18 namespace Belle2 {
24  TOPNominalTDC::TOPNominalTDC(int numWindows,
25  int subBits,
26  double syncTimeBase,
27  int numofBunches,
28  double offset,
29  double pileupTime,
30  double doubleHitResolution,
31  double timeJitter,
32  double efficiency,
33  const std::string& name):
34  TOPGeoBase(name),
35  m_numWindows(numWindows), m_subBits(subBits), m_syncTimeBase(syncTimeBase),
36  m_numofBunches(numofBunches),
37  m_offset(offset), m_pileupTime(pileupTime), m_doubleHitResolution(doubleHitResolution),
38  m_timeJitter(timeJitter), m_efficiency(efficiency)
39  {
40  if (numWindows <= 0)
41  B2FATAL("TOPNominalTDC: numWindows must be > 0");
42  if (subBits < 0)
43  B2FATAL("TOPNominalTDC: subBits must be >= 0");
44 
45  int numSamples = numWindows * c_WindowSize;
46  int numBits = subBits - 1;
47  int k = numSamples;
48  do {
49  numBits++;
50  k /= 2;
51  } while (k > 0);
52  if (numSamples > (1 << (numBits - subBits))) numBits++;
53  m_numBits = numBits;
54 
55  int syncSamples = c_syncWindows * c_WindowSize;
56  m_sampleWidth = syncTimeBase / syncSamples;
57  m_binWidth = m_sampleWidth / (1 << subBits);
58  }
59 
60  int TOPNominalTDC::getTDCcount(double time) const
61  {
62  time += m_offset;
63  int overflow = getOverflowValue();
64  if (time < 0) return overflow;
65  if (time > overflow * m_binWidth) return overflow;
66  return int(time / m_binWidth);
67  }
68 
69  int TOPNominalTDC::getSample(double time) const
70  {
71  time += m_offset;
72  if (time > 0) {
73  return int(time / m_sampleWidth);
74  } else {
75  return int(time / m_sampleWidth) - 1;
76  }
77  }
78 
79  bool TOPNominalTDC::isSampleValid(int sample) const
80  {
81  if (sample < 0) return false;
82  if (sample >= (int) m_numWindows * c_WindowSize) return false;
83  return true;
84  }
85 
87  {
88  if (m_pileupTime < 0) return false;
89  if (m_doubleHitResolution < 0) return false;
90  if (m_timeJitter < 0) return false;
91  if (m_efficiency <= 0 or m_efficiency > 1) return false;
92  return true;
93  }
94 
95  void TOPNominalTDC::print(const std::string& title) const
96  {
98  cout << " range: [" << getTimeMin() << ", " << getTimeMax() << "] ns" << endl;
99  cout << " offset: " << getOffset() << " ns" << endl;
100  cout << " number of bits: " << getNumBits() << endl;
101  cout << " bin width: " << getBinWidth() / Unit::ps << " ps" << endl;
102  cout << " number of ASIC windows: " << getNumWindows() << endl;
103  cout << " number of bits per sample: " << getSubBits() << endl;
104  cout << " synchonization time base: " << getSyncTimeBase() << " ns" << endl;
105  cout << " pile-up time: " << getPileupTime() << " ns" << endl;
106  cout << " double hit resolution: " << getDoubleHitResolution() << " ns" << endl;
107  cout << " r.m.s. of time jitter: " << getTimeJitter() / Unit::ps << " ps" << endl;
108  cout << " electronic efficiency: " << getEfficiency() << endl;
109  }
110 
112 } // end Belle2 namespace
Belle2::TOPNominalTDC::c_WindowSize
@ c_WindowSize
number of samples per ASIC window
Definition: TOPNominalTDC.h:38
Belle2::TOPNominalTDC::m_numBits
unsigned m_numBits
number of bits
Definition: TOPNominalTDC.h:289
Belle2::Unit::ps
static const double ps
[picosecond]
Definition: Unit.h:108
Belle2::TOPNominalTDC::m_numWindows
unsigned m_numWindows
number of ASIC windows per waveform
Definition: TOPNominalTDC.h:279
Belle2::TOPGeoBase
Base class for geometry parameters.
Definition: TOPGeoBase.h:35
Belle2::TOPNominalTDC::m_sampleWidth
float m_sampleWidth
time between two samples
Definition: TOPNominalTDC.h:291
Belle2::TOPNominalTDC::getNumBits
unsigned getNumBits() const
Returns number of bits.
Definition: TOPNominalTDC.h:195
Belle2::TOPNominalTDC::m_pileupTime
float m_pileupTime
pile-up time
Definition: TOPNominalTDC.h:284
Belle2::TOPNominalTDC::m_doubleHitResolution
float m_doubleHitResolution
double hit resolution time
Definition: TOPNominalTDC.h:285
Belle2::TOPNominalTDC::print
void print(const std::string &title="Nominal time-to-digit conversion parameters") const override
Print the content of the class.
Definition: TOPNominalTDC.cc:95
Belle2::TOPNominalTDC::isSampleValid
bool isSampleValid(int sample) const
Check for the validity of sample number.
Definition: TOPNominalTDC.cc:79
Belle2::TOPNominalTDC::getSample
int getSample(double time) const
Converts time to sample number.
Definition: TOPNominalTDC.cc:69
Belle2::TOPNominalTDC::getPileupTime
double getPileupTime() const
Returns pile-up time.
Definition: TOPNominalTDC.h:171
Belle2::TOPNominalTDC::m_offset
float m_offset
time offset
Definition: TOPNominalTDC.h:283
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOPGeoBase::printUnderlined
void printUnderlined(const std::string &title) const
Print the content of the class.
Definition: TOPGeoBase.cc:37
Belle2::TOPNominalTDC::getDoubleHitResolution
double getDoubleHitResolution() const
Returns double hit resolution time.
Definition: TOPNominalTDC.h:177
Belle2::TOPNominalTDC::getOverflowValue
int getOverflowValue() const
Returns TDC overflow value.
Definition: TOPNominalTDC.h:213
Belle2::TOPNominalTDC::isConsistent
bool isConsistent() const override
Check for consistency of data members.
Definition: TOPNominalTDC.cc:86
Belle2::TOPNominalTDC::getEfficiency
double getEfficiency() const
Returns electronic efficiency.
Definition: TOPNominalTDC.h:189
Belle2::TOPNominalTDC::getSubBits
unsigned getSubBits() const
Returns number of bits per sample.
Definition: TOPNominalTDC.h:141
Belle2::TOPNominalTDC::getTimeMin
double getTimeMin() const
Returns time range lower limit.
Definition: TOPNominalTDC.h:226
Belle2::TOPNominalTDC::m_binWidth
float m_binWidth
time width of a TDC bin
Definition: TOPNominalTDC.h:290
Belle2::TOPNominalTDC::getTimeMax
double getTimeMax() const
Returns time range upper limit.
Definition: TOPNominalTDC.h:232
Belle2::TOPNominalTDC::getOffset
double getOffset() const
Returns time offset.
Definition: TOPNominalTDC.h:165
Belle2::TOPNominalTDC::m_timeJitter
float m_timeJitter
r.m.s.
Definition: TOPNominalTDC.h:286
Belle2::TOPNominalTDC::getSyncTimeBase
double getSyncTimeBase() const
Returns synchonization time base (time width of c_syncWindows)
Definition: TOPNominalTDC.h:147
Belle2::TOPNominalTDC::getNumWindows
unsigned getNumWindows() const
Returns number of ASIC windows per waveform.
Definition: TOPNominalTDC.h:136
Belle2::TOPNominalTDC::getBinWidth
double getBinWidth() const
Returns time width of a TDC bin.
Definition: TOPNominalTDC.h:201
Belle2::TOPNominalTDC::c_syncWindows
@ c_syncWindows
number of windows corresponding to syncTimeBase
Definition: TOPNominalTDC.h:39
Belle2::TOPNominalTDC::getTimeJitter
double getTimeJitter() const
Returns r.m.s.
Definition: TOPNominalTDC.h:183
Belle2::TOPNominalTDC::getTDCcount
int getTDCcount(double time) const
Converts time to TDC count.
Definition: TOPNominalTDC.cc:60