Belle II Software  release-08-01-10
SVDShaperDigit.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 <vxd/dataobjects/VxdID.h>
10 #include <svd/dataobjects/SVDShaperDigit.h>
11 #include <vector>
12 #include <string>
13 #include <limits>
14 #include <gtest/gtest.h>
15 
16 namespace Belle2 {
21  namespace SVD {
22 
26  TEST(SVDShaperDigit, ConstructEmpty)
27  {
28  // Create an empty 6-digit
29  SVDShaperDigit digit;
30  // Test getters
31  EXPECT_EQ(VxdID{0}, digit.getSensorID());
32  EXPECT_TRUE(digit.isUStrip());
33  EXPECT_EQ(0, digit.getCellID());
34  const SVDShaperDigit::APVFloatSamples& samples = digit.getSamples();
35  for (auto sample : samples)
36  EXPECT_EQ(SVDShaperDigit::APVFloatSampleType(0), sample);
37  EXPECT_EQ(0.0, digit.getFADCTime());
38  }
39 
43  TEST(SVDShaperDigit, ConstructFromContainer)
44  {
45  // Create an arbitrary 6-digit
46  VxdID sensorID(3, 4, 1);
47  short int cellID = 132;
48  char digitFADCTime(-16);
49 
50  std::vector<int> init_samples({0, 5, 10, 9, 6, 5});
51  SVDShaperDigit digit(sensorID, false, cellID, init_samples, digitFADCTime);
52  // Test getters
53  EXPECT_EQ(sensorID, digit.getSensorID());
54  EXPECT_FALSE(digit.isUStrip());
55  EXPECT_EQ(cellID, digit.getCellID());
56  const SVDShaperDigit::APVFloatSamples& samples = digit.getSamples();
57  for (size_t isample = 0; isample < SVDShaperDigit::c_nAPVSamples; ++isample)
58  EXPECT_EQ(static_cast<SVDShaperDigit::APVFloatSampleType>(init_samples[isample]),
59  samples[isample]);
60  EXPECT_EQ(static_cast<float>(digitFADCTime), digit.getFADCTime());
61  }
62 
66  TEST(SVDShaperDigit, ConstructFromCArray)
67  {
68  // Create an arbitrary 6-digit
69  VxdID sensorID(3, 4, 1);
70  short int cellID = 132;
71  char digitFADCTime(-16);
72 
73  // floats must work, too.
74  float init_samples[SVDShaperDigit::c_nAPVSamples] = {0, 5, 10, 9, 6, 5};
75  SVDShaperDigit digit(
76  sensorID, false, cellID, init_samples, digitFADCTime);
77  // Test getters
78  EXPECT_EQ(sensorID, digit.getSensorID());
79  EXPECT_FALSE(digit.isUStrip());
80  EXPECT_EQ(cellID, digit.getCellID());
81  const SVDShaperDigit::APVFloatSamples& samples = digit.getSamples();
82  for (size_t isample = 0; isample < SVDShaperDigit::c_nAPVSamples; ++isample)
83  EXPECT_EQ(static_cast<SVDShaperDigit::APVFloatSampleType>(init_samples[isample]),
84  samples[isample]);
85  EXPECT_EQ(static_cast<float>(digitFADCTime), digit.getFADCTime());
86  }
90  TEST(SVDShaperDigit, ConstructDefaultTimeMode)
91  {
92  // Create an arbitrary 6-digit
93  VxdID sensorID(3, 4, 1);
94  short int cellID = 132;
95 
96  double init_samples[6] = {0, 5, 10, 9, 6, 5};
97  SVDShaperDigit digit(sensorID, false, cellID, init_samples);
98  // Test that time and error are set correctly.
99  EXPECT_EQ(0.0, digit.getFADCTime());
100  }
101 
103  TEST(SVDShaperDigit, SampleTrimming)
104  {
105  // Create an arbitrary 6-digit
106  VxdID sensorID(3, 4, 1);
107  short int cellID = 132;
108 
109  auto sampleMin =
110  static_cast<SVDShaperDigit::APVFloatSampleType>(std::numeric_limits<SVDShaperDigit::APVRawSampleType>::lowest());
111  auto sampleMax =
112  static_cast<SVDShaperDigit::APVFloatSampleType>(std::numeric_limits<SVDShaperDigit::APVRawSampleType>::max());
113 
114  std::vector<float> init_samples({0, -10, 255, 256, 500, -1});
115  SVDShaperDigit digit(sensorID, false, cellID, init_samples);
116  const auto& samples = digit.getSamples();
117  for (size_t isample = 0; isample < SVDShaperDigit::c_nAPVSamples; ++isample) {
118  auto trimmedSample = std::max(sampleMin, std::min(sampleMax, init_samples[isample]));
119  EXPECT_EQ(trimmedSample, samples[isample]);
120  }
121  }
122 
124  TEST(SVDShaperDigit, TrimmingFunction)
125  {
126 
127  // Create an arbitrary 6-digit
128  auto sampleMin =
129  static_cast<SVDShaperDigit::APVFloatSampleType>(std::numeric_limits<SVDShaperDigit::APVRawSampleType>::lowest());
130  auto sampleMax =
131  static_cast<SVDShaperDigit::APVFloatSampleType>(std::numeric_limits<SVDShaperDigit::APVRawSampleType>::max());
132 
133  std::vector<float> init_samples({0, -10, 255, 256, 500, -1});
134  for (size_t isample = 0; isample < SVDShaperDigit::c_nAPVSamples; ++isample) {
135  auto trimmedSample = std::max(sampleMin, std::min(sampleMax, init_samples[isample]));
136  EXPECT_EQ(trimmedSample, SVDShaperDigit::trimToSampleRange(init_samples[isample]));
137  }
138  }
139  } // namespace SVD
141 } // namespace Belle2
The SVD ShaperDigit class.
static const std::size_t c_nAPVSamples
Number of APV samples stored.
static SVDShaperDigit::APVRawSampleType trimToSampleRange(T x)
Convert a value to sample range.
std::array< APVFloatSampleType, c_nAPVSamples > APVFloatSamples
array of APVFloatSampleType objects
float APVFloatSampleType
Types for array of samples for processing.
VxdID getSensorID() const
Get the sensor ID.
APVFloatSamples getSamples() const
Get array of samples.
short int getCellID() const
Get strip ID.
bool isUStrip() const
Get strip direction.
float getFADCTime() const
Get digit FADCTime estimate.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
TEST(NNTimeFitter, DISABLED_CompareNetworkCoefficient)
Compare NN fitter parameter dump from Python with internal data representation in C++ to verify that ...
Definition: NNFitterTest.cc:35
Abstract base class for different kinds of events.