Belle II Software development
TimeDigitizer.h
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#pragma once
10
11#include <top/dataobjects/TOPSimHit.h>
12#include <top/dataobjects/TOPDigit.h>
13#include <top/dataobjects/TOPRawDigit.h>
14#include <top/dataobjects/TOPRawWaveform.h>
15#include <framework/datastore/StoreArray.h>
16#include <top/dbobjects/TOPSampleTimes.h>
17#include <top/dbobjects/TOPSignalShape.h>
18#include <top/dbobjects/TOPCalTimeWalk.h>
19#include <framework/database/DBObjPtr.h>
20
21#include <map>
22#include <vector>
23
24namespace Belle2 {
29 namespace TOP {
34
35 public:
36
40 enum EType {
41 c_Hit = 0,
42 c_ChargeShare = 1,
43 c_CrossTalk = 2,
44 c_CalPulse = 3
45 };
46
50 struct Hit {
51 double pulseHeight = 0;
52 EType type = c_Hit;
53 const TOPSimHit* simHit = 0;
54 const TOPSignalShape* shape = 0;
55 };
56
67 TimeDigitizer(int moduleID, int pixelID, double timeOffset, double calErrorsSq,
68 int shift, double rmsNoise, const TOPSampleTimes& sampleTimes);
69
74 static void setStorageDepth(unsigned storageDepth) {s_storageDepth = storageDepth;}
75
80 static void setReadoutWindows(unsigned numWin) {s_readoutWindows = numWin;}
81
86 static void setOffsetWindows(int offsetWin) {s_offsetWindows = offsetWin;}
87
92 static void setFirstWindow(unsigned window) {s_window = window;}
93
98 static void maskSamples(bool maskThem) {s_maskSamples = maskThem;}
99
103 static void setTimeWalk(DBObjPtr<TOPCalTimeWalk>* timeWalk) {s_timeWalk = timeWalk;}
104
109 void setSampleTimes(const TOPSampleTimes* sampleTimes)
110 {
111 if (sampleTimes) {
112 m_sampleTimes = sampleTimes;
113 } else {
114 B2ERROR("TOP::TimeDigitizer::setSampleTimes: argument is NULL pointer");
115 }
116 }
117
122 void setNoise(double rmsNoise) {m_rmsNoise = rmsNoise;}
123
131 void addTimeOfHit(double t, double pulseHeight, EType type,
132 const TOPSimHit* simHit = 0);
133
138 int getModuleID() const { return m_moduleID; }
139
144 int getPixelID() const { return m_pixelID; }
145
150 unsigned getUniqueID() const {return m_pixelID + (m_moduleID << 16);}
151
156 unsigned getASICWindow() const {return s_window;}
157
162 unsigned int getChannel() const { return m_channel; }
163
168 unsigned getScrodID() const {return m_scrodID;}
169
174 unsigned getCarrierNumber() const {return m_carrier;}
175
180 unsigned getASICNumber() const {return m_asic;}
181
186 unsigned getASICChannel() const {return m_chan;}
187
192 bool isValid() const {return m_valid;}
193
206 void digitize(StoreArray<TOPRawDigit>& rawDigits,
207 StoreArray<TOPDigit>& digits,
208 int threshold = 0,
209 int thresholdCount = 0,
210 double timeJitter = 0) const;
211
225 void digitize(StoreArray<TOPRawWaveform>& waveforms,
226 StoreArray<TOPRawDigit>& rawDigits,
227 StoreArray<TOPDigit>& digits,
228 int threshold,
229 int hysteresis = 0,
230 int thresholdCount = 0) const;
231
232 private:
233
241 double gauss(double x, double mean, double sigma) const
242 {
243 double xx = (x - mean) / sigma;
244 return exp(-0.5 * xx * xx);
245 }
246
258 std::vector<short> generateWaveform(int startSample,
259 const std::vector<double>& baselines,
260 const std::vector<double>& rmsNoises,
261 const std::vector<double>& pedestals,
262 int ADCRange) const;
263
270 double generateTimeWalk(double hitTime, double peakTime) const;
271
272 static unsigned s_storageDepth;
273 static unsigned s_readoutWindows;
274 static int s_offsetWindows;
275 static unsigned s_window;
276 static bool s_maskSamples;
279 int m_moduleID = 0;
280 int m_pixelID = 0;
281 double m_timeOffset = 0;
282 double m_calErrorsSq = 0;
283 double m_rmsNoise = 0;
287 unsigned m_channel = 0;
288 unsigned m_scrodID = 0;
289 unsigned m_carrier = 0;
290 unsigned m_asic = 0;
291 unsigned m_chan = 0;
292 bool m_valid = false;
294 std::multimap<double, const Hit> m_times;
296 };
297
298 } // TOP namespace
300} // Belle2 namespace
301
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Calibration constants of a singe ASIC channel: time axis (sample times)
Normalized shape of single photon pulse (waveform) Pulse must be positive.
Class to store simulated hits of Cherenkov photons on PMT's input for digitization module (TOPDigitiz...
Definition: TOPSimHit.h:27
Time digitization of simulated hits in a single electronic channel.
Definition: TimeDigitizer.h:33
static void setReadoutWindows(unsigned numWin)
Sets the number of readout windows.
Definition: TimeDigitizer.h:80
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.
unsigned getASICNumber() const
Returns ASIC number.
unsigned getCarrierNumber() const
Returns carrier board number.
static void maskSamples(bool maskThem)
Mask samples at the end of a window to emulate phase-2 data.
Definition: TimeDigitizer.h:98
static void setStorageDepth(unsigned storageDepth)
Sets storage depth.
Definition: TimeDigitizer.h:74
void setSampleTimes(const TOPSampleTimes *sampleTimes)
Sets sample times.
unsigned m_asic
ASIC number.
int m_windowShift
additional wf window shift due to asic mis-alignment
unsigned m_scrodID
SCROD ID.
double m_rmsNoise
r.m.s of noise [ADC counts]
static unsigned s_storageDepth
ASIC analog storage depth.
unsigned m_channel
hardware channel number (0-based)
static DBObjPtr< TOPCalTimeWalk > * s_timeWalk
pointer to DB object
double m_calErrorsSq
calibration uncertainties squared
const TOPSampleTimes * m_sampleTimes
sample times
bool isValid() const
Check if digitizer instance is valid (e.g.
int getPixelID() const
Return pixel ID.
unsigned int getChannel() const
Returns hardware channel number.
int m_moduleID
module ID (1-based)
int getModuleID() const
Return bar ID.
unsigned getASICWindow() const
Returns ASIC storage window number.
unsigned getASICChannel() const
Returns ASIC channel number.
bool m_valid
true, if module/pixel is mapped to hardware
static int s_offsetWindows
number of windows before first wf window
static void setTimeWalk(DBObjPtr< TOPCalTimeWalk > *timeWalk)
Stores pointer to time walk DB object defined in TOPDigitizerModule.
unsigned getUniqueID() const
Return unique pixel ID.
double generateTimeWalk(double hitTime, double peakTime) const
Generate time walk by taking into account pile-up of hits.
static unsigned s_window
first window number
double gauss(double x, double mean, double sigma) const
Gauss function (pulse shape approximation)
unsigned getScrodID() const
Returns SCROD ID.
static void setOffsetWindows(int offsetWin)
Sets the number of windows before the first ASIC window.
Definition: TimeDigitizer.h:86
void addTimeOfHit(double t, double pulseHeight, EType type, const TOPSimHit *simHit=0)
Add time of simulated hit.
static bool s_maskSamples
mask samples at window boundary (phase-2)
void setNoise(double rmsNoise)
Sets noise level.
double m_timeOffset
time offset [ns]
std::multimap< double, const Hit > m_times
hits sorted by time
static unsigned s_readoutWindows
number of readout windows
static void setFirstWindow(unsigned window)
Sets first ASIC window.
Definition: TimeDigitizer.h:92
unsigned m_carrier
carrier board number
EType
hit type enumerators
Definition: TimeDigitizer.h:40
unsigned m_chan
ASIC channel number.
Abstract base class for different kinds of events.
hit data other than time
Definition: TimeDigitizer.h:50
double pulseHeight
generated pulse height
Definition: TimeDigitizer.h:51
const TOPSimHit * simHit
pointer to simulated hit
Definition: TimeDigitizer.h:53
const TOPSignalShape * shape
waveform shape of this hit
Definition: TimeDigitizer.h:54