Belle II Software  release-05-02-19
TimeDigitizer.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - 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 #pragma once
12 
13 #include <top/dataobjects/TOPSimHit.h>
14 #include <top/dataobjects/TOPDigit.h>
15 #include <top/dataobjects/TOPRawDigit.h>
16 #include <top/dataobjects/TOPRawWaveform.h>
17 #include <framework/datastore/StoreArray.h>
18 #include <top/dbobjects/TOPSampleTimes.h>
19 #include <top/dbobjects/TOPSignalShape.h>
20 #include <top/dbobjects/TOPCalTimeWalk.h>
21 #include <framework/database/DBObjPtr.h>
22 
23 #include <map>
24 #include <vector>
25 
26 namespace Belle2 {
31  namespace TOP {
35  class TimeDigitizer {
36 
37  public:
38 
42  enum EType {
43  c_Hit = 0,
44  c_ChargeShare = 1,
45  c_CrossTalk = 2,
46  c_CalPulse = 3
47  };
48 
52  struct Hit {
53  double pulseHeight = 0;
54  EType type = c_Hit;
55  const TOPSimHit* simHit = 0;
56  const TOPSignalShape* shape = 0;
57  };
58 
69  TimeDigitizer(int moduleID, int pixelID, double timeOffset, double calErrorsSq,
70  int shift, double rmsNoise, const TOPSampleTimes& sampleTimes);
71 
76  static void setStorageDepth(unsigned storageDepth) {s_storageDepth = storageDepth;}
77 
82  static void setReadoutWindows(unsigned numWin) {s_readoutWindows = numWin;}
83 
88  static void setOffsetWindows(int offsetWin) {s_offsetWindows = offsetWin;}
89 
94  static void setFirstWindow(unsigned window) {s_window = window;}
95 
100  static void maskSamples(bool maskThem) {s_maskSamples = maskThem;}
101 
105  static void setTimeWalk(DBObjPtr<TOPCalTimeWalk>* timeWalk) {s_timeWalk = timeWalk;}
106 
111  void setSampleTimes(const TOPSampleTimes* sampleTimes)
112  {
113  if (sampleTimes) {
114  m_sampleTimes = sampleTimes;
115  } else {
116  B2ERROR("TOP::TimeDigitizer::setSampleTimes: argument is NULL pointer");
117  }
118  }
119 
124  void setNoise(double rmsNoise) {m_rmsNoise = rmsNoise;}
125 
133  void addTimeOfHit(double t, double pulseHeight, EType type,
134  const TOPSimHit* simHit = 0);
135 
140  int getModuleID() const { return m_moduleID; }
141 
146  int getPixelID() const { return m_pixelID; }
147 
152  unsigned getUniqueID() const {return m_pixelID + (m_moduleID << 16);}
153 
158  unsigned getASICWindow() const {return s_window;}
159 
164  unsigned int getChannel() const { return m_channel; }
165 
170  unsigned getScrodID() const {return m_scrodID;}
171 
176  unsigned getCarrierNumber() const {return m_carrier;}
177 
182  unsigned getASICNumber() const {return m_asic;}
183 
188  unsigned getASICChannel() const {return m_chan;}
189 
194  bool isValid() const {return m_valid;}
195 
208  void digitize(StoreArray<TOPRawDigit>& rawDigits,
209  StoreArray<TOPDigit>& digits,
210  int threshold = 0,
211  int thresholdCount = 0,
212  double timeJitter = 0) const;
213 
227  void digitize(StoreArray<TOPRawWaveform>& waveforms,
228  StoreArray<TOPRawDigit>& rawDigits,
229  StoreArray<TOPDigit>& digits,
230  int threshold,
231  int hysteresis = 0,
232  int thresholdCount = 0) const;
233 
234  private:
235 
243  double gauss(double x, double mean, double sigma) const
244  {
245  double xx = (x - mean) / sigma;
246  return exp(-0.5 * xx * xx);
247  }
248 
260  std::vector<short> generateWaveform(int startSample,
261  const std::vector<double>& baselines,
262  const std::vector<double>& rmsNoises,
263  const std::vector<double>& pedestals,
264  int ADCRange) const;
265 
266  static unsigned s_storageDepth;
267  static unsigned s_readoutWindows;
268  static int s_offsetWindows;
269  static unsigned s_window;
270  static bool s_maskSamples;
271  static DBObjPtr<TOPCalTimeWalk>* s_timeWalk;
273  int m_moduleID = 0;
274  int m_pixelID = 0;
275  double m_timeOffset = 0;
276  double m_calErrorsSq = 0;
277  double m_rmsNoise = 0;
279  int m_windowShift = 0;
281  unsigned m_channel = 0;
282  unsigned m_scrodID = 0;
283  unsigned m_carrier = 0;
284  unsigned m_asic = 0;
285  unsigned m_chan = 0;
286  bool m_valid = false;
288  std::multimap<double, const Hit> m_times;
290  };
291 
292  } // TOP namespace
294 } // Belle2 namespace
295 
Belle2::TOP::TimeDigitizer::s_maskSamples
static bool s_maskSamples
mask samples at window boundary (phase-2)
Definition: TimeDigitizer.h:278
Belle2::TOP::TimeDigitizer::getASICNumber
unsigned getASICNumber() const
Returns ASIC number.
Definition: TimeDigitizer.h:190
Belle2::TOP::TimeDigitizer::s_storageDepth
static unsigned s_storageDepth
ASIC analog storage depth.
Definition: TimeDigitizer.h:274
Belle2::TOP::TimeDigitizer::getModuleID
int getModuleID() const
Return bar ID.
Definition: TimeDigitizer.h:148
Belle2::TOP::TimeDigitizer::setOffsetWindows
static void setOffsetWindows(int offsetWin)
Sets the number of windows before the first ASIC window.
Definition: TimeDigitizer.h:96
Belle2::TOP::TimeDigitizer::setReadoutWindows
static void setReadoutWindows(unsigned numWin)
Sets the number of readout windows.
Definition: TimeDigitizer.h:90
Belle2::TOP::TimeDigitizer::s_readoutWindows
static unsigned s_readoutWindows
number of readout windows
Definition: TimeDigitizer.h:275
Belle2::TOPSimHit
Class to store simulated hits of Cherenkov photons on PMT's input for digitization module (TOPDigitiz...
Definition: TOPSimHit.h:37
Belle2::TOP::TimeDigitizer::Hit::simHit
const TOPSimHit * simHit
pointer to simulated hit
Definition: TimeDigitizer.h:63
Belle2::TOP::TimeDigitizer::m_calErrorsSq
double m_calErrorsSq
calibration uncertainties squared
Definition: TimeDigitizer.h:284
Belle2::TOP::TimeDigitizer::getASICWindow
unsigned getASICWindow() const
Returns ASIC storage window number.
Definition: TimeDigitizer.h:166
Belle2::TOP::TimeDigitizer::isValid
bool isValid() const
Check if digitizer instance is valid (e.g.
Definition: TimeDigitizer.h:202
Belle2::TOP::TimeDigitizer::digitize
void digitize(StoreArray< TOPRawDigit > &rawDigits, StoreArray< TOPDigit > &digits, int threshold=0, int thresholdCount=0, double timeJitter=0) const
Do time digitization using simplified pile-up and double-hit-resolution model.
Definition: TimeDigitizer.cc:95
Belle2::TOP::TimeDigitizer::m_times
std::multimap< double, const Hit > m_times
hits sorted by time
Definition: TimeDigitizer.h:296
Belle2::TOP::TimeDigitizer::s_window
static unsigned s_window
first window number
Definition: TimeDigitizer.h:277
Belle2::TOP::TimeDigitizer::setStorageDepth
static void setStorageDepth(unsigned storageDepth)
Sets storage depth.
Definition: TimeDigitizer.h:84
Belle2::TOP::TimeDigitizer::getCarrierNumber
unsigned getCarrierNumber() const
Returns carrier board number.
Definition: TimeDigitizer.h:184
Belle2::TOPSignalShape
Normalized shape of single photon pulse (waveform) Pulse must be positive.
Definition: TOPSignalShape.h:35
Belle2::TOP::TimeDigitizer::s_timeWalk
static DBObjPtr< TOPCalTimeWalk > * s_timeWalk
pointer to DB object
Definition: TimeDigitizer.h:279
Belle2::TOP::TimeDigitizer::m_channel
unsigned m_channel
hardware channel number (0-based)
Definition: TimeDigitizer.h:289
Belle2::TOP::TimeDigitizer::m_carrier
unsigned m_carrier
carrier board number
Definition: TimeDigitizer.h:291
Belle2::TOP::TimeDigitizer::setFirstWindow
static void setFirstWindow(unsigned window)
Sets first ASIC window.
Definition: TimeDigitizer.h:102
Belle2::TOP::TimeDigitizer::getUniqueID
unsigned getUniqueID() const
Return unique pixel ID.
Definition: TimeDigitizer.h:160
Belle2::TOPSampleTimes
Calibration constants of a singe ASIC channel: time axis (sample times)
Definition: TOPSampleTimes.h:34
Belle2::TOP::TimeDigitizer::Hit::pulseHeight
double pulseHeight
generated pulse height
Definition: TimeDigitizer.h:61
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOP::TimeDigitizer::TimeDigitizer
TimeDigitizer(int moduleID, int pixelID, double timeOffset, double calErrorsSq, int shift, double rmsNoise, const TOPSampleTimes &sampleTimes)
Constructor.
Definition: TimeDigitizer.cc:33
Belle2::TOP::TimeDigitizer::Hit::type
EType type
hit type
Definition: TimeDigitizer.h:62
Belle2::TOP::TimeDigitizer::m_sampleTimes
const TOPSampleTimes * m_sampleTimes
sample times
Definition: TimeDigitizer.h:286
Belle2::TOP::TimeDigitizer::gauss
double gauss(double x, double mean, double sigma) const
Gauss function (pulse shape approximation)
Definition: TimeDigitizer.h:251
Belle2::TOP::TimeDigitizer::addTimeOfHit
void addTimeOfHit(double t, double pulseHeight, EType type, const TOPSimHit *simHit=0)
Add time of simulated hit.
Definition: TimeDigitizer.cc:62
Belle2::TOP::TimeDigitizer::m_rmsNoise
double m_rmsNoise
r.m.s of noise [ADC counts]
Definition: TimeDigitizer.h:285
Belle2::TOP::TimeDigitizer::m_pixelID
int m_pixelID
pixel (e.g.
Definition: TimeDigitizer.h:282
Belle2::TOP::TimeDigitizer::m_timeOffset
double m_timeOffset
time offset [ns]
Definition: TimeDigitizer.h:283
Belle2::TOP::TimeDigitizer::m_valid
bool m_valid
true, if module/pixel is mapped to hardware
Definition: TimeDigitizer.h:294
Belle2::TOP::TimeDigitizer::maskSamples
static void maskSamples(bool maskThem)
Mask samples at the end of a window to emulate phase-2 data.
Definition: TimeDigitizer.h:108
Belle2::TOP::TimeDigitizer::getScrodID
unsigned getScrodID() const
Returns SCROD ID.
Definition: TimeDigitizer.h:178
Belle2::TOP::TimeDigitizer::m_scrodID
unsigned m_scrodID
SCROD ID.
Definition: TimeDigitizer.h:290
Belle2::TOP::TimeDigitizer::m_windowShift
int m_windowShift
additional wf window shift due to asic mis-alignment
Definition: TimeDigitizer.h:287
Belle2::TOP::TimeDigitizer::m_asic
unsigned m_asic
ASIC number.
Definition: TimeDigitizer.h:292
Belle2::TOP::TimeDigitizer::Hit::shape
const TOPSignalShape * shape
waveform shape of this hit
Definition: TimeDigitizer.h:64
Belle2::TOP::TimeDigitizer::m_moduleID
int m_moduleID
module ID (1-based)
Definition: TimeDigitizer.h:281
Belle2::TOP::TimeDigitizer::getChannel
unsigned int getChannel() const
Returns hardware channel number.
Definition: TimeDigitizer.h:172
Belle2::TOP::TimeDigitizer::m_chan
unsigned m_chan
ASIC channel number.
Definition: TimeDigitizer.h:293
Belle2::TOP::TimeDigitizer::generateWaveform
std::vector< short > generateWaveform(int startSample, const std::vector< double > &baselines, const std::vector< double > &rmsNoises, const std::vector< double > &pedestals, int ADCRange) const
Generate waveform.
Definition: TimeDigitizer.cc:415
Belle2::TOP::TimeDigitizer::getPixelID
int getPixelID() const
Return pixel ID.
Definition: TimeDigitizer.h:154
Belle2::TOP::TimeDigitizer::s_offsetWindows
static int s_offsetWindows
number of windows before first wf window
Definition: TimeDigitizer.h:276
Belle2::TOP::TimeDigitizer::EType
EType
hit type enumerators
Definition: TimeDigitizer.h:50
Belle2::TOP::TimeDigitizer::getASICChannel
unsigned getASICChannel() const
Returns ASIC channel number.
Definition: TimeDigitizer.h:196
Belle2::TOP::TimeDigitizer::setNoise
void setNoise(double rmsNoise)
Sets noise level.
Definition: TimeDigitizer.h:132
Belle2::Hit
Structure to hold some of the calpulse data.
Definition: TOPTimeBaseCalibratorModule.h:40
Belle2::TOP::TimeDigitizer::setSampleTimes
void setSampleTimes(const TOPSampleTimes *sampleTimes)
Sets sample times.
Definition: TimeDigitizer.h:119
Belle2::TOP::TimeDigitizer::setTimeWalk
static void setTimeWalk(DBObjPtr< TOPCalTimeWalk > *timeWalk)
Stores pointer to time walk DB object defined in TOPDigitizerModule.
Definition: TimeDigitizer.h:113