Belle II Software development
TOPRawWaveform.cc
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#include <top/dataobjects/TOPRawWaveform.h>
10
11using namespace std;
12
13namespace Belle2 {
19 int TOPRawWaveform::getIntegral(int sampleRise, int samplePeak, int sampleFall) const
20 {
21 sampleRise -= m_startSample;
22 samplePeak -= m_startSample;
23 sampleFall -= m_startSample;
24
25 return Integral(sampleRise, samplePeak, sampleFall);
26 }
27
28 int TOPRawWaveform::Integral(int sampleRise, int samplePeak, int sampleFall) const
29 {
30 int min = samplePeak - 3 * (samplePeak - sampleRise);
31 if (min < 0) min = 0;
32 int max = samplePeak + 4 * (sampleFall + 1 - samplePeak);
33 int size = m_data.size();
34 if (max > size) max = size;
35 int integral = 0;
36 while (min < max) {
37 integral += m_data[min];
38 min++;
39 }
40 return integral;
41 }
42
43
44 int TOPRawWaveform::featureExtraction(int threshold, int hysteresis,
45 int thresholdCount) const
46 {
47
48 m_features.clear();
49
50 int currentThr = threshold;
51 bool lastState = false;
52 int samplePeak = 0;
53 int size = m_data.size();
54 int aboveThr = 0;
55 for (int i = 0; i < size; i++) {
56 const auto& adc = m_data[i];
57 if (adc > currentThr and i < size - 1) {
58 currentThr = threshold - hysteresis;
59 if (!lastState or adc > m_data[samplePeak]) samplePeak = i;
60 lastState = true;
61 aboveThr++;
62 } else {
63 currentThr = threshold;
64 if (lastState and aboveThr >= thresholdCount) {
65 auto halfValue = m_data[samplePeak] / 2;
66 auto sampleRise = samplePeak;
67 while (sampleRise > 0 and m_data[sampleRise] > halfValue) sampleRise--;
68 if (sampleRise == 0 and m_data[sampleRise] > halfValue) continue;
69 auto sampleFall = samplePeak;
70 while (sampleFall < size - 1 and m_data[sampleFall] > halfValue) sampleFall++;
71 if (sampleFall == size - 1 and m_data[sampleFall] > halfValue) continue;
72 sampleFall--;
73 FeatureExtraction feature;
74 feature.sampleRise = sampleRise + m_startSample;
75 feature.samplePeak = samplePeak + m_startSample;
76 feature.sampleFall = sampleFall + m_startSample;
77 feature.vRise0 = m_data[sampleRise];
78 feature.vRise1 = m_data[sampleRise + 1];
79 feature.vPeak = m_data[samplePeak];
80 feature.vFall0 = m_data[sampleFall];
81 feature.vFall1 = m_data[sampleFall + 1];
82 feature.integral = Integral(sampleRise, samplePeak, sampleFall);
83 m_features.push_back(feature);
84 }
85 lastState = false;
86 aboveThr = 0;
87 }
88 }
89
90 return m_features.size();
91 }
92
94} // end Belle2 namespace
95
int m_startSample
sample number of the first waveform sample
std::vector< short > m_data
waveform ADC values
std::vector< FeatureExtraction > m_features
cache for feature extraction data
int getIntegral(int sampleRise, int samplePeak, int sampleFall) const
Returns integral of a peak.
int Integral(int sampleRise, int samplePeak, int sampleFall) const
Returns integral of a peak.
int featureExtraction(int threshold, int hysteresis, int thresholdCount) const
Do feature extraction.
Abstract base class for different kinds of events.
STL namespace.
short vFall0
ADC value at sampleFall.
short vRise1
ADC value at sampleRise + 1.
short vRise0
ADC value at sampleRise.
short vPeak
ADC value at samplePeak.
int integral
integral of a pulse (proportional to charge)
int samplePeak
sample number at maximum
int sampleRise
sample number just before 50% CFD crossing
short vFall1
ADC value at sampleFall + 1.