Hit_test.cc
Go to the documentation of this file.
1 /**
2  * @file Hit_test.cc
3  * @brief Simple test on a recob::Hit object
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date 20150113
6  * @version 1.0
7  *
8  * This test simply creates recob::Hit objects and verifies that the values it
9  * can access are the right ones.
10  *
11  * See http://www.boost.org/libs/test for the Boost test library home page.
12  *
13  * Timing:
14  * version 1.0: ~1.5" (debug mode)
15  */
16 
17 // C/C++ standard library
18 #include <numeric> // std::accumulate
19 
20 // Boost libraries
21 /*
22  * Boost Magic: define the name of the module;
23  * and do that before the inclusion of Boost unit test headers
24  * because it will change what they provide.
25  * Among the those, there is a main() function and some wrapping catching
26  * unhandled exceptions and considering them test failures, and probably more.
27  * This also makes fairly complicate to receive parameters from the command line
28  * (for example, a random seed).
29  */
30 #define BOOST_TEST_MODULE ( hit_test )
31 #include "boost/test/unit_test.hpp"
32 
33 
34 // LArSoft libraries
35 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t, raw::TDCtick_t
36 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::View_t
38 
39 
40 
41 //------------------------------------------------------------------------------
42 //--- Test code
43 //
44 
45 
46 void CheckHit(
47  recob::Hit const& hit,
49  raw::TDCtick_t start_tick,
50  raw::TDCtick_t end_tick,
51  float peak_time,
52  float sigma_peak_time,
53  float rms,
54  float peak_amplitude,
55  float sigma_peak_amplitude,
56  float summedADC,
57  float hit_integral,
58  float hit_sigma_integral,
59  short int multiplicity,
60  short int local_index,
61  float goodness_of_fit,
62  int dof,
63  geo::View_t view,
64  geo::SigType_t signal_type,
65  geo::WireID wireID
66 ) {
67 
68  // verify that the values are as expected
69  // - channel ID
70  BOOST_TEST(hit.Channel() == channel);
71 
72  // - view
73  BOOST_TEST(hit.View() == view);
74 
75  // - signal type
76  BOOST_TEST(hit.SignalType() == signal_type);
77 
78  // - start and end tick
79  BOOST_TEST(hit.StartTick() == start_tick);
80  BOOST_TEST(hit.EndTick() == end_tick);
81 
82  // - peak
83  BOOST_TEST(hit.PeakTime() == peak_time);
84  BOOST_TEST(hit.SigmaPeakTime() == sigma_peak_time);
85  BOOST_TEST(hit.PeakAmplitude() == peak_amplitude);
86  BOOST_TEST(hit.SigmaPeakAmplitude() == sigma_peak_amplitude);
87 
88  // the following comparisons are at 0.01%
89  BOOST_CHECK_CLOSE(hit.PeakTimePlusRMS(), peak_time + rms, 0.01);
90  BOOST_CHECK_CLOSE(hit.PeakTimeMinusRMS(), peak_time - rms, 0.01);
91 
92  for (float shift: { 0.0, 0.5, 1.0, 1.5, 2.0, 2.2 }) {
93 
94  const float time_up = peak_time + shift*rms;
95  const float time_down = peak_time - shift*rms;
96 
97  if (time_up == 0.) {
98  BOOST_CHECK_SMALL(hit.PeakTimePlusRMS(shift), 0.01F);
99  BOOST_CHECK_SMALL(hit.PeakTimeMinusRMS(-shift), 0.01F);
100  }
101  else {
102  BOOST_CHECK_CLOSE(hit.PeakTimePlusRMS(shift), time_up, 0.01F);
103  BOOST_CHECK_CLOSE(hit.PeakTimeMinusRMS(-shift), time_up, 0.01F);
104  }
105 
106  if (time_down == 0.) {
107  BOOST_CHECK_SMALL(hit.PeakTimePlusRMS(shift), 0.01F);
108  BOOST_CHECK_SMALL(hit.PeakTimeMinusRMS(-shift), 0.01F);
109  }
110  else {
111  BOOST_CHECK_CLOSE(hit.PeakTimeMinusRMS(shift), time_down, 0.01F);
112  BOOST_CHECK_CLOSE(hit.PeakTimePlusRMS(-shift), time_down, 0.01F);
113  }
114 
115  if (rms > 0.) {
116  if (shift == 0.) {
117  BOOST_CHECK_SMALL(hit.TimeDistanceAsRMS(time_up), 0.01F);
118  BOOST_CHECK_SMALL(hit.TimeDistanceAsRMS(time_down), 0.01F);
119  }
120  else {
121  BOOST_CHECK_CLOSE(hit.TimeDistanceAsRMS(time_up), shift, 0.01F);
122  BOOST_CHECK_CLOSE(hit.TimeDistanceAsRMS(time_down), -shift, 0.01F);
123  }
124  } // if rms is not 0
125 
126  } // for
127 
128  // - width
129  BOOST_TEST(hit.RMS() == rms);
130 
131  // - charge
132  BOOST_TEST(hit.SummedADC() == summedADC);
133  BOOST_TEST(hit.Integral() == hit_integral);
134  BOOST_TEST(hit.SigmaIntegral() == hit_sigma_integral);
135 
136  // - multiplicity
137  BOOST_TEST(hit.Multiplicity() == multiplicity);
138  BOOST_TEST(hit.LocalIndex() == local_index);
139  BOOST_TEST
140  (((hit.LocalIndex() < hit.Multiplicity()) || (hit.LocalIndex() == -1)));
141 
142  // - fit quality
143  BOOST_TEST(hit.GoodnessOfFit() == goodness_of_fit);
144  BOOST_TEST(hit.DegreesOfFreedom() == dof);
145 
146  // - wire ID
147  BOOST_TEST(hit.WireID() == wireID);
148 
149 } // CheckHit()
150 
151 
153 
154  //
155  // Part I: initialization of wire inputs
156  //
157  // these are the values expected for a default-constructed wire
159  raw::TDCtick_t start_tick = 0;
160  raw::TDCtick_t end_tick = 0;
161  float peak_time = 0.0;
162  float sigma_peak_time = -1.0;
163  float rms = 0.0;
164  float peak_amplitude = 0.0;
165  float sigma_peak_amplitude = -1.0;
166  float summedADC = 0.0;
167  float hit_integral = 0.0;
168  float hit_sigma_integral = -1.0;
169  short int multiplicity = 0;
170  short int local_index = -1;
171  float goodness_of_fit = 0.0;
172  int dof = -1;
173  geo::View_t view = geo::kUnknown;
174  geo::SigType_t signal_type = geo::kMysteryType;
175  geo::WireID wireID;
176 
177  //
178  // Part II: default constructor
179  //
180  // step II.1: create a hit with the default constructor
181  recob::Hit hit;
182 
183  // step II.2: verify that the values are as expected
184  CheckHit(hit,
185  channel,
186  start_tick,
187  end_tick,
188  peak_time,
189  sigma_peak_time,
190  rms,
191  peak_amplitude,
192  sigma_peak_amplitude,
193  summedADC,
194  hit_integral,
195  hit_sigma_integral,
196  multiplicity,
197  local_index,
198  goodness_of_fit,
199  dof,
200  view,
201  signal_type,
202  wireID
203  );
204 
205 } // HitTestDefaultConstructor()
206 
207 
209 
210  //
211  // Part I: initialization of wire inputs
212  //
213  // these are the values expected for a default-constructed wire
215  std::vector<float> signal({
216  0.2, 1.2, 1.5, 2.0, 4.7,
217  12.8, 30.7, 85.2, 132.1, 154.7,
218  147.4, 127.0, 86.7, 29.3, 11.8,
219  4.5, 2.2, 1.5, 1.0, 0.3,
220  });
221  raw::TDCtick_t start_tick = 730;
222  raw::TDCtick_t end_tick = start_tick + signal.size();
223  float peak_time = start_tick + signal.size()/2 + 0.7;
224  float sigma_peak_time = 1.3;
225  float rms = signal.size() / 2.7;
226  float peak_amplitude = signal[signal.size()/2] - 0.3;
227  float sigma_peak_amplitude = 2.3;
228  float summedADC
229  = std::accumulate(signal.begin(), signal.end(), 0.0);
230  float hit_integral = summedADC * 0.97;
231  float hit_sigma_integral = peak_amplitude / 10.;
232  short int multiplicity = 2;
233  short int local_index = 1;
234  float goodness_of_fit = 0.95;
235  int dof = signal.size() - 3;
236  geo::View_t view = geo::kU;
237  geo::SigType_t signal_type = geo::kCollection;
238  geo::WireID wireID(0, 1, 2, 546);
239 
240 
241  //
242  // Part II: complete constructor
243  //
244  // step II.1: create a hit with the signal-copying constructor
245  recob::Hit hit1(
246  channel,
247  start_tick,
248  end_tick,
249  peak_time,
250  sigma_peak_time,
251  rms,
252  peak_amplitude,
253  sigma_peak_amplitude,
254  summedADC,
255  hit_integral,
256  hit_sigma_integral,
257  multiplicity,
258  local_index,
259  goodness_of_fit,
260  dof,
261  view,
262  signal_type,
263  wireID
264  );
265 
266  // step II.2: verify that the values are as expected
267  CheckHit(hit1,
268  channel,
269  start_tick,
270  end_tick,
271  peak_time,
272  sigma_peak_time,
273  rms,
274  peak_amplitude,
275  sigma_peak_amplitude,
276  summedADC,
277  hit_integral,
278  hit_sigma_integral,
279  multiplicity,
280  local_index,
281  goodness_of_fit,
282  dof,
283  view,
284  signal_type,
285  wireID
286  );
287 
288 } // HitTestCustomConstructors()
289 
290 
291 //------------------------------------------------------------------------------
292 //--- registration of tests
293 //
294 // Boost needs now to know which tests we want to run.
295 // Tests are "automatically" registered, hence the BOOST_AUTO_TEST_CASE()
296 // macro name. The argument is the name of the test; each step may have a
297 // number of checks and it will fail if any of them does.
298 //
299 
300 BOOST_AUTO_TEST_CASE(HitDefaultConstructor) {
302 }
303 
304 BOOST_AUTO_TEST_CASE(HitCustomConstructors) {
306 }
short int LocalIndex() const
How well do we believe we know this hit?
Definition: Hit.h:227
geo::SigType_t SignalType() const
Signal type for the plane of the hit.
Definition: Hit.h:231
Who knows?
Definition: geo_types.h:147
void CheckHit(recob::Hit const &hit, raw::ChannelID_t channel, raw::TDCtick_t start_tick, raw::TDCtick_t end_tick, float peak_time, float sigma_peak_time, float rms, float peak_amplitude, float sigma_peak_amplitude, float summedADC, float hit_integral, float hit_sigma_integral, short int multiplicity, short int local_index, float goodness_of_fit, int dof, geo::View_t view, geo::SigType_t signal_type, geo::WireID wireID)
Definition: Hit_test.cc:46
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:40
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Unknown view.
Definition: geo_types.h:136
geo::WireID WireID() const
Definition: Hit.h:233
float RMS() const
RMS of the hit shape, in tick units.
Definition: Hit.h:220
float SigmaPeakAmplitude() const
Uncertainty on estimated amplitude of the hit at its peak, in ADC units.
Definition: Hit.h:222
BOOST_AUTO_TEST_CASE(HitDefaultConstructor)
Definition: Hit_test.cc:300
float SigmaIntegral() const
Definition: Hit.h:225
int DegreesOfFreedom() const
Definition: Hit.h:229
void HitTestCustomConstructors()
Definition: Hit_test.cc:208
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
geo::View_t View() const
View for the plane of the hit.
Definition: Hit.h:232
uint8_t channel
Definition: CRTFragment.hh:201
float GoodnessOfFit() const
Degrees of freedom in the determination of the hit signal shape (-1 by default)
Definition: Hit.h:228
short int Multiplicity() const
How many hits could this one be shared with.
Definition: Hit.h:226
float PeakAmplitude() const
The estimated amplitude of the hit at its peak, in ADC units.
Definition: Hit.h:221
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
Planes which measure U.
Definition: geo_types.h:129
float TimeDistanceAsRMS(float time) const
Returns the distance of the specified time from peak, in RMS units.
Definition: Hit.h:242
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
enum geo::_plane_sigtype SigType_t
raw::TDCtick_t StartTick() const
Initial tdc tick for hit.
Definition: Hit.h:216
Definition of data types for geometry description.
float PeakTimeMinusRMS(float sigmas=+1.) const
Definition: Hit.h:239
Detector simulation of raw signals on wires.
raw::TDCtick_t EndTick() const
Final tdc tick for hit.
Definition: Hit.h:217
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
Declaration of signal hit object.
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:223
float SigmaPeakTime() const
Uncertainty for the signal peak, in tick units.
Definition: Hit.h:219
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Definition: Hit.h:236
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
void HitTestDefaultConstructor()
Definition: Hit_test.cc:152
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
Signal from collection planes.
Definition: geo_types.h:146