All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WaveformBaseline_test.cc
Go to the documentation of this file.
1 /**
2  * @file test/PMT/Data/WaveformBaseline_test.cc
3  * @brief Unit test for `WaveformBaseline.h` header.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date September 11, 2020
6  * @see `icaruscode/PMT/Data/WaveformBaseline.h`
7  *
8  * The main purpose of this test is to make sure `TriggerGateData` code is
9  * compiled, since it is just a header.
10  */
11 
12 // ICARUS libraries
15 
16 // LArSoft libraries
18 
19 // Boost libraries
20 #define BOOST_TEST_MODULE ( WaveformBaseline_test )
21 #include <boost/test/unit_test.hpp>
22 
23 // C/C++ standard library
24 #include <sstream>
25 #include <vector>
26 #include <cmath> // std::round()
27 
28 
29 // -----------------------------------------------------------------------------
30 // --- WaveformBaseline tests
31 // -----------------------------------------------------------------------------
32 
34 
35  constexpr float baselineValue { 6.6f };
36 
37  icarus::WaveformBaseline const baseline { baselineValue };
38 
39  BOOST_TEST((baseline.fBaseline == baselineValue));
40  BOOST_TEST((baseline.baseline() == baselineValue));
41  BOOST_TEST((baseline() == baselineValue));
42 
43  std::ostringstream sstr;
44  sstr << baseline;
45  std::string const baselineStr { sstr.str() };
46  sstr.str("");
47  sstr << baselineValue;
48  std::string const baselineValueStr { sstr.str() };
49 
50  BOOST_TEST((baselineStr == baselineValueStr));
51 
52 } // WaveformBaseline_value_test()
53 
54 
56 
57  std::ostringstream sstr;
58 
59  /*
60  * icarus::WaveformBaseline const baseline { 1.2f };
61  *
62  * std::cout << "Baseline: " << baseline << " ADC" << std::endl;
63  */
64 
65  icarus::WaveformBaseline const baseline { 1.2f };
66 
67  sstr << "Baseline: " << baseline << " ADC";
68 
69 
70  BOOST_TEST((sstr.str() == "Baseline: 1.2 ADC"));
71 
72 } // WaveformBaseline_documentation1_test()
73 
74 
76  /*
77  *
78  */
79 
80  //
81  // initialization
82  //
83  using ADCCount_t = util::quantities::counts;
84  std::vector<ADCCount_t> const data
85  { ADCCount_t{ -6 }, ADCCount_t{ -8 }, ADCCount_t{ -2 } };
86 
87  //
88  // test code
89  //
90  icarus::WaveformBaseline const baseline { -1.8 };
91 
93  waveOps { baseline() };
94 
95  std::vector<ADCCount_t> subtracted;
96  subtracted.reserve(data.size());
97  for (ADCCount_t sample: data) {
98  subtracted.emplace_back
99  (std::round(waveOps.subtractBaseline(sample.value())));
100  }
101 
102  //
103  // checks
104  //
105  BOOST_TEST((subtracted.size() == data.size()));
106 
107  BOOST_TEST((subtracted[0U] == ADCCount_t{ 4 }));
108  BOOST_TEST((subtracted[1U] == ADCCount_t{ 6 }));
109  BOOST_TEST((subtracted[2U] == ADCCount_t{ 0 }));
110 
111 } // WaveformBaseline_documentation2_test()
112 
113 
114 // -----------------------------------------------------------------------------
115 // BEGIN Test cases -----------------------------------------------------------
116 // -----------------------------------------------------------------------------
117 BOOST_AUTO_TEST_CASE(WaveformBaseline_documentation_testcase) {
118 
120 
123 
124 } // BOOST_AUTO_TEST_CASE(WaveformBaseline_documentation_testcase)
125 
126 
127 // -----------------------------------------------------------------------------
128 // END Test cases -------------------------------------------------------------
129 // -----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(AllTests)
void WaveformBaseline_documentation2_test()
void WaveformBaseline_value_test()
void WaveformBaseline_documentation1_test()
Operations< Sample,-1 > NegativePolarityOperations
Waveform operations for negative polarity waveforms.
counts_as<> counts
Number of ADC counts, represented by signed short int.
Definition: electronics.h:116
BEGIN_PROLOG baseline
Operations on waveform samples.
Dimensioned variables related to electronics.
Class containing a waveform baseline value.