Belle II Software development
TOPRawDigit.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 <framework/datastore/RelationsObject.h>
12
13namespace Belle2 {
25 public:
26
31 c_HeadMagic = 0x0001,
32 c_TailMagic = 0x0002,
33 c_HitMagic = 0x0004,
34 c_HitChecksum = 0x0008
35 };
36
43 c_MC = 1,
47 c_Other = 99
48 };
49
53 enum {
54 c_WindowSize = 64
55 };
56
61 {}
62
68 TOPRawDigit(unsigned short scrodID, EDataTypes dataType):
69 m_scrodID(scrodID), m_dataType(dataType)
70 {}
71
76 void setCarrierNumber(unsigned short carrier) {m_carrier = carrier;}
77
82 void setASICNumber(unsigned short asic) {m_asic = asic;}
83
88 void setASICChannel(unsigned short channel) {m_channel = channel;}
89
94 void setASICWindow(unsigned short window) {m_window = window;}
95
100 void setStorageWindows(const std::vector<unsigned short>& windows)
101 {
102 m_windows = windows;
103 }
104
109 void setLastWriteAddr(unsigned short window) {m_lastWriteAddr = window;}
110
115 void setTFine(unsigned short tfine) {m_TFine = tfine;}
116
121 void setSampleRise(unsigned short sample) {m_sampleRise = sample;}
122
127 void setDeltaSamplePeak(unsigned short dsample) {m_dSamplePeak = dsample;}
128
134 void setDeltaSampleFall(unsigned short dsample) {m_dSampleFall = dsample;}
135
140 void setValueRise0(short adc) {m_VRise0 = adc;}
141
146 void setValueRise1(short adc) {m_VRise1 = adc;}
147
152 void setValuePeak(short adc) {m_VPeak = adc;}
153
158 void setValueFall0(short adc) {m_VFall0 = adc;}
159
164 void setValueFall1(short adc) {m_VFall1 = adc;}
165
170 void setIntegral(int integral) {m_integral = integral;}
171
176 void setRevo9Counter(unsigned short revo9Counter) {m_revo9Counter = revo9Counter;}
177
183 void setPhase(unsigned short phase) {m_phase = phase;}
184
189 void setLookBackWindows(unsigned short lookBack) {m_lookBackWindows = lookBack;}
190
195 void setErrorFlags(unsigned short flags) {m_errorFlags = flags;}
196
200 void setOfflineFlag() {m_offline = true;}
201
207
212 unsigned getScrodID() const {return m_scrodID;}
213
218 unsigned getCarrierNumber() const {return m_carrier;}
219
224 unsigned getASICNumber() const {return m_asic;}
225
230 unsigned getASICChannel() const {return m_channel;}
231
232
237 unsigned getScrodChannel() const {return m_channel + m_asic * 8 + m_carrier * 32;}
238
243 unsigned getASICWindow() const {return m_window;}
244
249 const std::vector<unsigned short>& getStorageWindows() const {return m_windows;}
250
255 unsigned getLastWriteAddr() const {return m_lastWriteAddr;}
256
261 unsigned getTFine() const {return m_TFine;}
262
267 unsigned getSampleRise() const {return m_sampleRise;}
268
273 unsigned getDeltaSamplePeak() const {return m_dSamplePeak;}
274
279 unsigned getSamplePeak() const {return m_sampleRise + m_dSamplePeak;}
280
285 unsigned getDeltaSampleFall() const {return m_dSampleFall;}
286
291 unsigned getSampleFall() const {return m_sampleRise + m_dSampleFall;}
292
297 int getValueRise0() const {return m_VRise0;}
298
303 int getValueRise1() const {return m_VRise1;}
304
309 int getValuePeak() const {return m_VPeak;}
310
315 int getValueFall0() const {return m_VFall0;}
316
321 int getValueFall1() const {return m_VFall1;}
322
327 int getIntegral() const {return m_integral;}
328
333 unsigned short getRevo9Counter() const {return m_revo9Counter;}
334
339 unsigned short getLookBackWindows() const {return m_lookBackWindows;}
340
345 unsigned short getPhase() const {return m_phase;}
346
351 unsigned short getErrorFlags() const {return m_errorFlags;}
352
357 double getLeadingSlope() const {return getValueRise1() - getValueRise0();}
358
363 double getFallingSlope() const {return getValueFall1() - getValueFall0();}
364
369 double getCFDLeadingTime() const
370 {
372 }
373
378 double getCFDFallingTime() const
379 {
381 }
382
388 double getCFDLeadingTimeError(double rmsNoise) const
389 {
390 return rmsNoise * timeErrorCoefficient(m_VRise0, m_VRise1);
391 }
392
398 double getCFDFallingTimeError(double rmsNoise) const
399 {
400 return rmsNoise * timeErrorCoefficient(m_VFall0, m_VFall1);
401 }
402
407 double getFWHM() const {return getCFDFallingTime() - getCFDLeadingTime();}
408
414
420
425 bool isFEValid() const
426 {
428 }
429
434 bool isPedestalJump() const;
435
443 bool isAtWindowDiscontinuity(unsigned short storageDepth = 508) const;
444
452 bool areWindowsInOrder(unsigned short storageDepth = 508) const;
453
460 double correctTime(double time, unsigned short storageDepth = 508) const;
461
468 {
469 if (m_windows.empty()) return true;
470 return m_windows[0] == m_window;
471 }
472
477 bool isMadeOffline() const {return m_offline;}
478
479 private:
480
488 double timeCFDCrossing(int sample, int value, double slope) const
489 {
490 if (slope == 0) return sample;
491 return (int(m_VPeak) - 2 * value) / (2 * slope) + sample;
492 }
493
500 double timeErrorCoefficient(double y1, double y2) const;
501
505 bool checkEdge(int v1, int v2, int vp) const
506 {
507 return (vp > 0 and v1 < v2 and 2 * v1 <= vp and v2 <= vp)
508 or (vp < 0 and v1 > v2 and 2 * v1 >= vp and v2 >= vp);
509 }
510
511 unsigned short m_scrodID = 0;
512 unsigned short m_carrier = 0;
513 unsigned short m_asic = 0;
514 unsigned short m_channel = 0;
515 unsigned short m_window = 0;
516 unsigned short m_TFine = 0;
517 unsigned short m_sampleRise = 0;
518 unsigned short m_dSamplePeak = 0;
519 unsigned short m_dSampleFall = 0;
520 short m_VRise0 = 0;
521 short m_VRise1 = 0;
522 short m_VPeak = 0;
523 short m_VFall0 = 0;
524 short m_VFall1 = 0;
525 int m_integral = 0;
526 unsigned short m_revo9Counter = 0;
527 unsigned short m_phase = 0;
528 unsigned short m_lookBackWindows = 0;
529 unsigned short m_errorFlags = 0;
530 unsigned short m_lastWriteAddr = 0;
531 std::vector<unsigned short> m_windows;
532 bool m_offline = false;
537 };
538
539
541} // end namespace Belle2
542
Defines interface for accessing relations of objects in StoreArray.
Class to store unpacked raw data (hits in feature-extraction format) It provides also calculation of ...
Definition: TOPRawDigit.h:24
void setASICChannel(unsigned short channel)
Sets ASIC channel number.
Definition: TOPRawDigit.h:88
EDataTypes
Enum for data types needed to steer time conversion in TOPRawDigitConverter.
Definition: TOPRawDigit.h:41
@ c_Interim
from interim feature extraction
Definition: TOPRawDigit.h:44
@ c_ProductionDebug
from production debugging format
Definition: TOPRawDigit.h:46
@ c_Production
from the future production format
Definition: TOPRawDigit.h:45
@ c_MC
from MC digitization
Definition: TOPRawDigit.h:43
@ c_Undefined
undefined
Definition: TOPRawDigit.h:42
int getValueRise0() const
Returns ADC value at leading edge (at m_sampleRise)
Definition: TOPRawDigit.h:297
double getCFDLeadingTime() const
Returns leading edge CFD time.
Definition: TOPRawDigit.h:369
double getCFDFallingTimeError(double rmsNoise) const
Returns falling edge CFD time uncertainty (assuming uncorrelated noise)
Definition: TOPRawDigit.h:398
EDataTypes getDataType() const
Returns data type.
Definition: TOPRawDigit.h:206
unsigned short m_scrodID
SCROD ID.
Definition: TOPRawDigit.h:511
@ c_WindowSize
number of samples per window
Definition: TOPRawDigit.h:54
unsigned short m_carrier
carrier board number
Definition: TOPRawDigit.h:512
void setIntegral(int integral)
Sets integral of a pulse (e.g.
Definition: TOPRawDigit.h:170
unsigned getASICNumber() const
Returns ASIC number.
Definition: TOPRawDigit.h:224
unsigned getCarrierNumber() const
Returns carrier board number.
Definition: TOPRawDigit.h:218
double getCFDLeadingTimeError(double rmsNoise) const
Returns leading edge CFD time uncertainty (assuming uncorrelated noise)
Definition: TOPRawDigit.h:388
void setCarrierNumber(unsigned short carrier)
Sets carrier board number.
Definition: TOPRawDigit.h:76
void setRevo9Counter(unsigned short revo9Counter)
Sets number of global clock tics since last revo9 flag (production firmware only)
Definition: TOPRawDigit.h:176
void setSampleRise(unsigned short sample)
Sets sample number just before 50% CFD crossing at leading edge.
Definition: TOPRawDigit.h:121
double getLeadingSlope() const
Returns leading edge slope.
Definition: TOPRawDigit.h:357
int getValueFall1() const
Returns ADC value at falling edge (at m_sampleRise + m_dSampleFall + 1)
Definition: TOPRawDigit.h:321
std::vector< unsigned short > m_windows
storage windows of waveform segments
Definition: TOPRawDigit.h:531
double getFallingSlope() const
Returns falling edge slope.
Definition: TOPRawDigit.h:363
int m_integral
integral of a pulse (proportional to charge)
Definition: TOPRawDigit.h:525
bool isLeadingEdgeValid() const
Checks if leading edge is consistently defined.
Definition: TOPRawDigit.h:413
TOPRawDigit()
Default constructor.
Definition: TOPRawDigit.h:60
unsigned short getRevo9Counter() const
Returns 127 MHz clock ticks since last revo9 marker.
Definition: TOPRawDigit.h:333
double timeCFDCrossing(int sample, int value, double slope) const
calculates time of 50% CFD crossing
Definition: TOPRawDigit.h:488
unsigned short m_revo9Counter
number of clock ticks since last revo9 flag
Definition: TOPRawDigit.h:526
double getCFDFallingTime() const
Returns falling edge CFD time.
Definition: TOPRawDigit.h:378
bool m_offline
feature extraction flag: by firmware or software
Definition: TOPRawDigit.h:532
void setLookBackWindows(unsigned short lookBack)
Sets number of look-back windows.
Definition: TOPRawDigit.h:189
const std::vector< unsigned short > & getStorageWindows() const
Returns storage window numbers of waveform segments (not always available!)
Definition: TOPRawDigit.h:249
unsigned short getErrorFlags() const
Returns error flags.
Definition: TOPRawDigit.h:351
short m_VFall1
ADC value at m_sampleRise + m_dSampleFall + 1.
Definition: TOPRawDigit.h:524
unsigned short m_channel
ASIC channel number.
Definition: TOPRawDigit.h:514
unsigned getSampleFall() const
Returns sample number at falling edge just before 50% CFD crossing.
Definition: TOPRawDigit.h:291
unsigned short m_dSampleFall
same for falling edge, rel.
Definition: TOPRawDigit.h:519
double getFWHM() const
Returns signal full width half maximum.
Definition: TOPRawDigit.h:407
bool isMadeOffline() const
Returns offline flag.
Definition: TOPRawDigit.h:477
TOPRawDigit(unsigned short scrodID, EDataTypes dataType)
Usefull constructor.
Definition: TOPRawDigit.h:68
unsigned getDeltaSampleFall() const
Returns sample number at falling edge just before 50% CFD relative to m_sampleRise.
Definition: TOPRawDigit.h:285
void setErrorFlags(unsigned short flags)
Sets error flags.
Definition: TOPRawDigit.h:195
unsigned getDeltaSamplePeak() const
Returns peak position relative to m_sampleRise.
Definition: TOPRawDigit.h:273
unsigned short m_asic
ASIC number.
Definition: TOPRawDigit.h:513
unsigned short m_lookBackWindows
number of look-back windows
Definition: TOPRawDigit.h:528
unsigned getSampleRise() const
Returns sample number at leading edge just before 50% CFD crossing.
Definition: TOPRawDigit.h:267
int getValueRise1() const
Returns ADC value at leading edge (at m_sampleRise + 1)
Definition: TOPRawDigit.h:303
short m_VPeak
ADC value at m_sampleRise + m_dSamplePeak.
Definition: TOPRawDigit.h:522
void setTFine(unsigned short tfine)
Sets fine timing for 50% CFD at rising edge (within two samples)
Definition: TOPRawDigit.h:115
void setValueRise0(short adc)
Sets ADC value at m_sampleRise.
Definition: TOPRawDigit.h:140
void setDeltaSamplePeak(unsigned short dsample)
Sets peak position relative to m_sampleRise.
Definition: TOPRawDigit.h:127
unsigned short m_lastWriteAddr
current (reference) window number
Definition: TOPRawDigit.h:530
ClassDef(TOPRawDigit, 6)
ClassDef.
void setASICWindow(unsigned short window)
Sets first storage window number (logical window number)
Definition: TOPRawDigit.h:94
unsigned short m_sampleRise
sample number just before 50% CFD crossing
Definition: TOPRawDigit.h:517
unsigned getTFine() const
Returns fine timing for 50% CFD (within two samples)
Definition: TOPRawDigit.h:261
void setValuePeak(short adc)
Sets ADC value at m_sampleRise + m_dSamplePeak (e.g.
Definition: TOPRawDigit.h:152
void setOfflineFlag()
Sets offline flag: telling that this digit was extracted offline in basf2.
Definition: TOPRawDigit.h:200
unsigned getASICWindow() const
Returns ASIC storage window number.
Definition: TOPRawDigit.h:243
void setDeltaSampleFall(unsigned short dsample)
Sets falling edge sample number just before 50% CFD crossing relative to m_sampleRise.
Definition: TOPRawDigit.h:134
unsigned getASICChannel() const
Returns ASIC channel number.
Definition: TOPRawDigit.h:230
short m_VFall0
ADC value at m_sampleRise + m_dSampleFall.
Definition: TOPRawDigit.h:523
void setStorageWindows(const std::vector< unsigned short > &windows)
Sets storage windows of waveform segments.
Definition: TOPRawDigit.h:100
bool checkEdge(int v1, int v2, int vp) const
Checks if values v1, v2 and vp are consistent.
Definition: TOPRawDigit.h:505
void setValueFall1(short adc)
Sets ADC value at m_sampleRise + m_dSampleFall + 1.
Definition: TOPRawDigit.h:164
void setValueFall0(short adc)
Sets ADC value at m_sampleRise + m_dSampleFall.
Definition: TOPRawDigit.h:158
short m_VRise0
ADC value at m_sampleRise.
Definition: TOPRawDigit.h:520
int getIntegral() const
Returns integral of a pulse (e.g.
Definition: TOPRawDigit.h:327
bool isFallingEdgeValid() const
Checks if falling edge is consistently defined.
Definition: TOPRawDigit.h:419
void setPhase(unsigned short phase)
Sets beam orbit synchronisation phase (production firmware only) 9-state count: valid values are 0 - ...
Definition: TOPRawDigit.h:183
unsigned short m_errorFlags
feature extraction error flags (see enum)
Definition: TOPRawDigit.h:529
int getValueFall0() const
Returns ADC value at falling edge (at m_sampleRise + m_dSampleFall)
Definition: TOPRawDigit.h:315
void setLastWriteAddr(unsigned short window)
Sets current (reference) window number.
Definition: TOPRawDigit.h:109
unsigned getScrodID() const
Returns SCROD ID.
Definition: TOPRawDigit.h:212
unsigned short getLookBackWindows() const
Returns number of look-back windows.
Definition: TOPRawDigit.h:339
unsigned short m_window
first ASIC storage window number
Definition: TOPRawDigit.h:515
ErrorFlags
Enum for error flags; bits set if corresponding data not consistent.
Definition: TOPRawDigit.h:30
@ c_HitMagic
if magic number not 0xB
Definition: TOPRawDigit.h:33
@ c_TailMagic
if magic bits not '101' = 0x5
Definition: TOPRawDigit.h:32
@ c_HitChecksum
if sum of 16-bit words not zero
Definition: TOPRawDigit.h:34
@ c_HeadMagic
if magic number not 0xA
Definition: TOPRawDigit.h:31
unsigned short m_TFine
fine timing for 50% CFD (within two samples)
Definition: TOPRawDigit.h:516
unsigned short m_phase
carrier phase
Definition: TOPRawDigit.h:527
bool isWindowConsistent() const
Checks if the first window number is the same as the first one in m_windows Note: returns true if m_w...
Definition: TOPRawDigit.h:467
int getValuePeak() const
Returns ADC value at peak (e.g.
Definition: TOPRawDigit.h:309
unsigned short getPhase() const
Returns beam orbit synchronisation phase (9-state count: valid values are 0 - 8)
Definition: TOPRawDigit.h:345
unsigned short m_dSamplePeak
peak position relative to m_sampleRise
Definition: TOPRawDigit.h:518
bool isFEValid() const
Checks if feature extraction points make sense.
Definition: TOPRawDigit.h:425
void setValueRise1(short adc)
Sets ADC value at m_sampleRise + 1.
Definition: TOPRawDigit.h:146
unsigned getLastWriteAddr() const
Returns current (reference) ASIC window number.
Definition: TOPRawDigit.h:255
short m_VRise1
ADC value at m_sampleRise + 1.
Definition: TOPRawDigit.h:521
unsigned getScrodChannel() const
Returns channel number within SCROD (in the range 0 - 127)
Definition: TOPRawDigit.h:237
unsigned getSamplePeak() const
Returns peak position.
Definition: TOPRawDigit.h:279
void setASICNumber(unsigned short asic)
Sets ASIC number.
Definition: TOPRawDigit.h:82
EDataTypes m_dataType
data type
Definition: TOPRawDigit.h:533
double correctTime(double time, unsigned short storageDepth=508) const
Corrects time after window discontinuity by adding missing samples.
Definition: TOPRawDigit.cc:66
bool isAtWindowDiscontinuity(unsigned short storageDepth=508) const
Checks if feature extraction points are at window discontinuity (e.g.
Definition: TOPRawDigit.cc:34
double timeErrorCoefficient(double y1, double y2) const
Calculate the coefficient of time error.
Definition: TOPRawDigit.cc:84
bool isPedestalJump() const
Checks if feature extraction finds a pedestal jump.
Definition: TOPRawDigit.cc:23
bool areWindowsInOrder(unsigned short storageDepth=508) const
Checks if storage windows come in the consecutive order before the last sample (no gaps before the la...
Definition: TOPRawDigit.cc:52
Abstract base class for different kinds of events.