AlgoThreshold_test.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE ( AlgoThreshold_test )
3 
6 
7 
9 
12 
13 };
14 
15 double const tolerance = 1e-6;
16 
17 BOOST_FIXTURE_TEST_SUITE(AlgoThreshold_test, AlgoThresholdFixture)
18 
19 BOOST_AUTO_TEST_CASE(checkZeroVector)
20 {
21 
22  std::vector<short> wf(20,0);
23  std::vector<double> ped_mean(20,0);
24  std::vector<double> ped_sigma(20,0.1);
25  myAlgoThreshold.Reconstruct(wf,ped_mean,ped_sigma);
26 
27  BOOST_CHECK_EQUAL(myAlgoThreshold.GetNPulse(),0ul);
28 
29  //BOOST_FAIL("This test fails");
30 
31 }
32 
34 {
35  std::vector<short> wf(20,0);
36  std::vector<double> ped_mean(20,0);
37  std::vector<double> ped_sigma(20,0.1);
38  wf[10]=10;
39 
40  myAlgoThreshold.Reconstruct(wf,ped_mean,ped_sigma);
41  BOOST_CHECK_EQUAL(myAlgoThreshold.GetNPulse(),1ul);
42  //BOOST_CHECK_NE(myAlgoThreshold.GetPulse(0),(void*)0);
43  //BOOST_CHECK_EQUAL(myAlgoThreshold.GetPulse(1),(void*)0);
44 
45 }
46 BOOST_AUTO_TEST_CASE(checkSquarePulse)
47 {
48 
49  std::vector<short> wf(20,0);
50  std::vector<double> ped_mean(20,0);
51  std::vector<double> ped_sigma(20,0.1);
52  //
53 
54  double area = 0;
55  for(size_t iter=0; iter<wf.size(); iter++){
56  if(iter>5 && iter<15) {
57  wf[iter] += 10;
58  area += wf[iter];
59  }
60  }
61 
62  myAlgoThreshold.Reconstruct(wf,ped_mean,ped_sigma);
63 
64  BOOST_CHECK_EQUAL(myAlgoThreshold.GetNPulse(),1ul);
65  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_start,5,tolerance);
66  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_end,15,tolerance);
67  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_max,6,tolerance);
68  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).area,area,tolerance);
69  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).peak,10.0,tolerance);
70 }
71 
72 BOOST_AUTO_TEST_CASE(checkTrianglePulse)
73 {
74 
75  std::vector<short> wf(20,0);
76  std::vector<double> ped_mean(20,0);
77  std::vector<double> ped_sigma(20,0.1);
78  //
79 
80  double area = 0;
81  for(size_t iter=0; iter<wf.size(); iter++){
82  if(iter<=10)
83  wf[iter] += iter;
84  else if(iter>10)
85  wf[iter] += 20-iter;
86 
87  if(wf[iter]>=3)
88  area += wf[iter];
89 
90  }
91 
92  myAlgoThreshold.Reconstruct(wf,ped_mean,ped_sigma);
93  BOOST_CHECK_EQUAL(myAlgoThreshold.GetNPulse(),1ul);
94  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_start,1,tolerance);
95  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_end,19,tolerance);
96  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_max,10,tolerance);
97  //BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).area,area,tolerance);
98  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).peak,10.0,tolerance);
99 }
100 
101 BOOST_AUTO_TEST_CASE(checkNonZeroPed)
102 {
103 
104  double ped = 2;
105  std::vector<short> wf(20,(short)ped);
106  std::vector<double> ped_mean(20,ped);
107  std::vector<double> ped_sigma(20,0.1);
108 
109  double area = 0;
110  for(size_t iter=0; iter<wf.size(); iter++){
111  if(iter<=10)
112  wf[iter] += iter;
113  else if(iter>10)
114  wf[iter] += 20-iter;
115 
116  if(wf[iter]>=3+ped)
117  area += wf[iter] - ped;
118 
119  }
120 
121  myAlgoThreshold.Reconstruct(wf,ped_mean,ped_sigma);
122  BOOST_CHECK_EQUAL(myAlgoThreshold.GetNPulse(),1ul);
123  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_start,0,tolerance);
124  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_end,19,tolerance);
125  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_max,10,tolerance);
126  //BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).area,area,tolerance);
127  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).peak,10.0,tolerance);
128 }
129 
130 BOOST_AUTO_TEST_CASE(checkPulseOffEnd)
131 {
132 
133  std::vector<short> wf(20,0);
134  std::vector<double> ped_mean(20,0);
135  std::vector<double> ped_sigma(20,0.1);
136 
137 
138  wf[18] = 5; wf[19] = 10;
139  double area = 15;
140 
141  myAlgoThreshold.Reconstruct(wf,ped_mean,ped_sigma);
142  BOOST_CHECK_EQUAL(myAlgoThreshold.GetNPulse(),1ul);
143  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_start,17,tolerance);
144  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_end,19,tolerance);
145  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_max,19,tolerance);
146  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).area,area,tolerance);
147  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).peak,10.0,tolerance);
148 }
149 
150 BOOST_AUTO_TEST_CASE(checkPulseOffFront)
151 {
152 
153  std::vector<short> wf(20,0);
154  std::vector<double> ped_mean(20,0);
155  std::vector<double> ped_sigma(20,0.1);
156 
157 
158  wf[0] = 10; wf[1] = 5;
159  double area = 15;
160 
161  myAlgoThreshold.Reconstruct(wf,ped_mean,ped_sigma);
162  BOOST_CHECK_EQUAL(myAlgoThreshold.GetNPulse(),1ul);
163  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_start,0,tolerance);
164  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_end,2,tolerance);
165  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_max,0,tolerance);
166  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).area,area,tolerance);
167  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).peak,10.0,tolerance);
168 }
169 
170 BOOST_AUTO_TEST_CASE(checkDoublePulse)
171 {
172 
173  std::vector<short> wf(20,0);
174  std::vector<double> ped_mean(20,0);
175  std::vector<double> ped_sigma(20,0.1);
176 
177 
178  wf[4] = 5; wf[5] = 10; wf[6] = 5;
179  wf[14] = 5; wf[15] = 10; wf[16] = 5;
180  double area = 20;
181 
182  myAlgoThreshold.Reconstruct(wf,ped_mean,ped_sigma);
183  BOOST_CHECK_EQUAL(myAlgoThreshold.GetNPulse(),2ul);
184 
185  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_start,3,tolerance);
186  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_end,7,tolerance);
187  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).t_max,5,tolerance);
188  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).area,area,tolerance);
189  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(0).peak,10.0,tolerance);
190 
191  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(1).t_start,13,tolerance);
192  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(1).t_end,17,tolerance);
193  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(1).t_max,15,tolerance);
194  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(1).area,area,tolerance);
195  BOOST_CHECK_CLOSE(myAlgoThreshold.GetPulse(1).peak,10.0,tolerance);
196 
197 }
198 
199 BOOST_AUTO_TEST_SUITE_END()
double const tolerance
BOOST_AUTO_TEST_CASE(checkZeroVector)
size_t GetNPulse() const
A getter for the number of reconstructed pulses from the input waveform.
const double e
Class definition file of AlgoThreshold.
bool Reconstruct(const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)
pmtana::AlgoThreshold myAlgoThreshold
const pulse_param & GetPulse(size_t index=0) const