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 {
18
23
25 public:
26
31 c_HeadMagic = 0x0001,
32 c_TailMagic = 0x0002,
33 c_HitMagic = 0x0004,
34 c_HitChecksum = 0x0008
35 };
36
49
53 enum {
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;
534
536
537 };
538
539
541} // end namespace Belle2
542
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)
double getCFDLeadingTime() const
Returns leading edge CFD time.
double getCFDFallingTimeError(double rmsNoise) const
Returns falling edge CFD time uncertainty (assuming uncorrelated noise)
EDataTypes getDataType() const
Returns data type.
unsigned short m_scrodID
SCROD ID.
unsigned short m_carrier
carrier board number
void setIntegral(int integral)
Sets integral of a pulse (e.g.
unsigned getASICNumber() const
Returns ASIC number.
unsigned getCarrierNumber() const
Returns carrier board number.
double getCFDLeadingTimeError(double rmsNoise) const
Returns leading edge CFD time uncertainty (assuming uncorrelated noise)
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)
void setSampleRise(unsigned short sample)
Sets sample number just before 50% CFD crossing at leading edge.
double getLeadingSlope() const
Returns leading edge slope.
int getValueFall1() const
Returns ADC value at falling edge (at m_sampleRise + m_dSampleFall + 1)
std::vector< unsigned short > m_windows
storage windows of waveform segments
double getFallingSlope() const
Returns falling edge slope.
int m_integral
integral of a pulse (proportional to charge)
bool isLeadingEdgeValid() const
Checks if leading edge is consistently defined.
TOPRawDigit()
Default constructor.
Definition TOPRawDigit.h:60
unsigned short getRevo9Counter() const
Returns 127 MHz clock ticks since last revo9 marker.
double timeCFDCrossing(int sample, int value, double slope) const
calculates time of 50% CFD crossing
unsigned short m_revo9Counter
number of clock ticks since last revo9 flag
double getCFDFallingTime() const
Returns falling edge CFD time.
bool m_offline
feature extraction flag: by firmware or software
void setLookBackWindows(unsigned short lookBack)
Sets number of look-back windows.
const std::vector< unsigned short > & getStorageWindows() const
Returns storage window numbers of waveform segments (not always available!)
unsigned short getErrorFlags() const
Returns error flags.
short m_VFall1
ADC value at m_sampleRise + m_dSampleFall + 1.
unsigned short m_channel
ASIC channel number.
unsigned getSampleFall() const
Returns sample number at falling edge just before 50% CFD crossing.
unsigned short m_dSampleFall
same for falling edge, rel.
double getFWHM() const
Returns signal full width half maximum.
bool isMadeOffline() const
Returns offline flag.
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.
void setErrorFlags(unsigned short flags)
Sets error flags.
unsigned getDeltaSamplePeak() const
Returns peak position relative to m_sampleRise.
unsigned short m_asic
ASIC number.
unsigned short m_lookBackWindows
number of look-back windows
unsigned getSampleRise() const
Returns sample number at leading edge just before 50% CFD crossing.
int getValueRise1() const
Returns ADC value at leading edge (at m_sampleRise + 1)
short m_VPeak
ADC value at m_sampleRise + m_dSamplePeak.
void setTFine(unsigned short tfine)
Sets fine timing for 50% CFD at rising edge (within two samples)
void setValueRise0(short adc)
Sets ADC value at m_sampleRise.
@ c_WindowSize
number of samples per window
Definition TOPRawDigit.h:54
void setDeltaSamplePeak(unsigned short dsample)
Sets peak position relative to m_sampleRise.
unsigned short m_lastWriteAddr
current (reference) window number
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
unsigned getTFine() const
Returns fine timing for 50% CFD (within two samples)
void setValuePeak(short adc)
Sets ADC value at m_sampleRise + m_dSamplePeak (e.g.
void setOfflineFlag()
Sets offline flag: telling that this digit was extracted offline in basf2.
unsigned getASICWindow() const
Returns ASIC storage window number.
void setDeltaSampleFall(unsigned short dsample)
Sets falling edge sample number just before 50% CFD crossing relative to m_sampleRise.
unsigned getASICChannel() const
Returns ASIC channel number.
short m_VFall0
ADC value at m_sampleRise + m_dSampleFall.
void setStorageWindows(const std::vector< unsigned short > &windows)
Sets storage windows of waveform segments.
bool checkEdge(int v1, int v2, int vp) const
Checks if values v1, v2 and vp are consistent.
void setValueFall1(short adc)
Sets ADC value at m_sampleRise + m_dSampleFall + 1.
void setValueFall0(short adc)
Sets ADC value at m_sampleRise + m_dSampleFall.
short m_VRise0
ADC value at m_sampleRise.
int getIntegral() const
Returns integral of a pulse (e.g.
bool isFallingEdgeValid() const
Checks if falling edge is consistently defined.
void setPhase(unsigned short phase)
Sets beam orbit synchronisation phase (production firmware only) 9-state count: valid values are 0 - ...
unsigned short m_errorFlags
feature extraction error flags (see enum)
int getValueFall0() const
Returns ADC value at falling edge (at m_sampleRise + m_dSampleFall)
void setLastWriteAddr(unsigned short window)
Sets current (reference) window number.
unsigned getScrodID() const
Returns SCROD ID.
unsigned short getLookBackWindows() const
Returns number of look-back windows.
unsigned short m_window
first ASIC storage window number
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)
unsigned short m_phase
carrier phase
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...
int getValuePeak() const
Returns ADC value at peak (e.g.
unsigned short getPhase() const
Returns beam orbit synchronisation phase (9-state count: valid values are 0 - 8)
unsigned short m_dSamplePeak
peak position relative to m_sampleRise
bool isFEValid() const
Checks if feature extraction points make sense.
void setValueRise1(short adc)
Sets ADC value at m_sampleRise + 1.
unsigned getLastWriteAddr() const
Returns current (reference) ASIC window number.
short m_VRise1
ADC value at m_sampleRise + 1.
unsigned getScrodChannel() const
Returns channel number within SCROD (in the range 0 - 127)
unsigned getSamplePeak() const
Returns peak position.
void setASICNumber(unsigned short asic)
Sets ASIC number.
Definition TOPRawDigit.h:82
EDataTypes m_dataType
data type
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
double correctTime(double time, unsigned short storageDepth=508) const
Corrects time after window discontinuity by adding missing samples.
bool isAtWindowDiscontinuity(unsigned short storageDepth=508) const
Checks if feature extraction points are at window discontinuity (e.g.
double timeErrorCoefficient(double y1, double y2) const
Calculate the coefficient of time error.
bool isPedestalJump() const
Checks if feature extraction finds a pedestal jump.
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...
Abstract base class for different kinds of events.