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