OpFlashAlg_test.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE ( OpFlashAlg_test )
2 #include "boost/test/unit_test.hpp"
3 
5 
6 constexpr float FlashThreshold = 50;
7 constexpr double WidthTolerance = 0.5;
8 
10 
11 BOOST_AUTO_TEST_SUITE(OpFlashAlg_test)
12 
13 BOOST_AUTO_TEST_CASE(checkGetAccumIndex)
14 {
15 
16  BOOST_TEST(opdet::GetAccumIndex(10.0,0,1,0) == 10ul);
17  BOOST_TEST(opdet::GetAccumIndex(10.0,0,2,0) == 5ul);
18  BOOST_TEST(opdet::GetAccumIndex(10.0,0,3,0) == 3ul);
19 
20  BOOST_TEST(opdet::GetAccumIndex(10.0,-5,1,0) == 15ul);
21  BOOST_TEST(opdet::GetAccumIndex(10.0,-5,2,0) == 7ul);
22  BOOST_TEST(opdet::GetAccumIndex(10.0,-5,3,0) == 5ul);
23 
24  BOOST_TEST(opdet::GetAccumIndex(10.0,-5,1,0.5) == 15ul);
25  BOOST_TEST(opdet::GetAccumIndex(10.0,-5,2,1) == 8ul);
26 
27 }
28 
29 BOOST_AUTO_TEST_CASE(FillAccumulator_checkBelowThreshold){
30 
31  const size_t vector_size = 1;
32  const double PE_base = 10;
33 
34  unsigned int AccumIndex = 0;
35  unsigned int HitIndex = 0;
36  double PE = 10;
37  std::vector<double> Binned(vector_size,PE_base);
38  std::vector< std::vector<int> > Contributors(vector_size);
39  std::vector<int> FlashesInAccumulator;
40 
41  opdet::FillAccumulator(AccumIndex,HitIndex,PE,FlashThreshold,
42  Binned,Contributors,FlashesInAccumulator);
43 
44  BOOST_TEST( Contributors.at(AccumIndex).size() == 1U);
45  BOOST_TEST( Contributors.at(AccumIndex).at(0) == (int)HitIndex );
46  BOOST_TEST( Binned.at(AccumIndex) == PE+PE_base );
47  BOOST_TEST( FlashesInAccumulator.size() == 0U);
48 
49 }
50 
51 BOOST_AUTO_TEST_CASE(FillAccumulator_checkAboveThreshold){
52 
53  const size_t vector_size = 1;
54  const double PE_base = 10;
55 
56  unsigned int AccumIndex = 0;
57  unsigned int HitIndex = 0;
58  double PE = 40;
59  std::vector<double> Binned(vector_size,PE_base);
60  std::vector< std::vector<int> > Contributors(vector_size);
61  std::vector<int> FlashesInAccumulator;
62 
63  opdet::FillAccumulator(AccumIndex,HitIndex,PE,FlashThreshold,
64  Binned,Contributors,FlashesInAccumulator);
65 
66  BOOST_TEST( Contributors.at(AccumIndex).size() == 1U);
67  BOOST_TEST( Contributors.at(AccumIndex).at(0) == (int)HitIndex );
68  BOOST_TEST( Binned.at(AccumIndex) == PE+PE_base );
69  BOOST_TEST( FlashesInAccumulator.size() == 1U);
70 
71 }
72 
73 BOOST_AUTO_TEST_CASE(FillAccumulator_checkMultipleHits){
74 
75  const size_t vector_size = 1;
76  const double PE_base = 10;
77 
78  unsigned int AccumIndex = 0;
79  unsigned int HitIndex = 0;
80  double PE = 25;
81  std::vector<double> Binned(vector_size,PE_base);
82  std::vector< std::vector<int> > Contributors(vector_size);
83  std::vector<int> FlashesInAccumulator;
84 
85  opdet::FillAccumulator(AccumIndex,HitIndex,PE,FlashThreshold,
86  Binned,Contributors,FlashesInAccumulator);
87 
88  BOOST_TEST( Contributors.at(AccumIndex).size() == 1U);
89  BOOST_TEST( Contributors.at(AccumIndex).at(0) == (int)HitIndex );
90  BOOST_TEST( Binned.at(AccumIndex) == PE+PE_base );
91  BOOST_TEST( FlashesInAccumulator.size() == 0U);
92 
93 
94  unsigned int HitIndex2 = 1;
95  opdet::FillAccumulator(AccumIndex,HitIndex2,PE,FlashThreshold,
96  Binned,Contributors,FlashesInAccumulator);
97 
98  BOOST_TEST( Contributors.at(AccumIndex).size() == 2U);
99  BOOST_TEST( Contributors.at(AccumIndex).at(0) == (int)HitIndex );
100  BOOST_TEST( Contributors.at(AccumIndex).at(1) == (int)HitIndex2 );
101  BOOST_TEST( Binned.at(AccumIndex) == PE*2+PE_base );
102  BOOST_TEST( FlashesInAccumulator.size() == 1U);
103 
104 }
105 
106 BOOST_AUTO_TEST_CASE(FillFlashesBySizeMap_checkNoFlash)
107 {
108  const size_t vector_size = 10;
109  const double PE_vals = 10;
110 
111  std::vector<double> BinnedPE(vector_size,PE_vals);
112  std::vector<int> FlashesInAccumulator;
113  std::map<double, std::map<int,std::vector<int> >, std::greater<double> > FlashesBySize;
114 
115  opdet::FillFlashesBySizeMap(FlashesInAccumulator,BinnedPE,1,FlashesBySize);
116 
117  BOOST_TEST( FlashesBySize.size() == 0U );
118 
119 }
120 
121 BOOST_AUTO_TEST_CASE(FillFlashesBySizeMap_checkOneFlash)
122 {
123  const size_t vector_size = 10;
124  const double PE_vals = 10;
125 
126  std::vector<double> BinnedPE(vector_size,PE_vals);
127  BinnedPE[2] = 50;
128 
129  std::vector<int> FlashesInAccumulator(1,2);
130 
131  std::map<double, std::map<int,std::vector<int> >, std::greater<double> > FlashesBySize;
132 
133  opdet::FillFlashesBySizeMap(FlashesInAccumulator,BinnedPE,1,FlashesBySize);
134 
135  BOOST_TEST( FlashesBySize.size() == 1U );
136  BOOST_TEST( FlashesBySize.count(50) == 1U );
137  BOOST_TEST( FlashesBySize.count(10) == 0U );
138  BOOST_TEST( FlashesBySize[50].size() == 1U );
139  BOOST_TEST( FlashesBySize[50].count(1) == 1U );
140  BOOST_TEST( FlashesBySize[50][1].size() == 1U );
141  BOOST_TEST( FlashesBySize[50][1][0] == 2 );
142 
143 }
144 
145 BOOST_AUTO_TEST_CASE(FillFlashesBySizeMap_checkTwoFlashes)
146 {
147  const size_t vector_size = 10;
148  const double PE_vals = 10;
149 
150  std::vector<double> BinnedPE(vector_size,PE_vals);
151  BinnedPE[2] = 50;
152  BinnedPE[8] = 50;
153 
154  std::vector<int> FlashesInAccumulator { 2, 8 };
155 
156  std::map<double, std::map<int,std::vector<int> >, std::greater<double> > FlashesBySize;
157 
158  opdet::FillFlashesBySizeMap(FlashesInAccumulator,BinnedPE,1,FlashesBySize);
159 
160  BOOST_TEST( FlashesBySize.size() == 1U );
161  BOOST_TEST( FlashesBySize.count(50) == 1U );
162  BOOST_TEST( FlashesBySize.count(10) == 0U );
163 
164  BOOST_TEST( FlashesBySize[50].size() == 1U );
165  BOOST_TEST( FlashesBySize[50].count(1) == 1U );
166  BOOST_TEST( FlashesBySize[50][1].size() == 2U );
167  BOOST_TEST( FlashesBySize[50][1][0] == 2 );
168  BOOST_TEST( FlashesBySize[50][1][1] == 8 );
169 
170 }
171 
172 BOOST_AUTO_TEST_CASE(FillFlashesBySizeMap_checkTwoAccumulators)
173 {
174  const size_t vector_size = 10;
175  const double PE_vals = 10;
176 
177  std::vector<double> BinnedPE1(vector_size,PE_vals);
178  BinnedPE1[2] = 50;
179  BinnedPE1[5] = 60;
180  std::vector<double> BinnedPE2(vector_size,PE_vals);
181  BinnedPE2[8] = 50;
182 
183  std::vector<int> FlashesInAccumulator1 { 2, 5 };
184  std::vector<int> FlashesInAccumulator2(1,8);
185 
186  std::map<double, std::map<int,std::vector<int> >, std::greater<double> > FlashesBySize;
187 
188  opdet::FillFlashesBySizeMap(FlashesInAccumulator1,BinnedPE1,1,FlashesBySize);
189  opdet::FillFlashesBySizeMap(FlashesInAccumulator2,BinnedPE2,2,FlashesBySize);
190 
191  BOOST_TEST( FlashesBySize.size() == 2U );
192 
193  BOOST_TEST( FlashesBySize.count(50) == 1U );
194  BOOST_TEST( FlashesBySize.count(60) == 1U );
195  BOOST_TEST( FlashesBySize.count(10) == 0U );
196 
197  auto map_begin = FlashesBySize.begin();
198  BOOST_TEST( map_begin->first == 60 );
199 
200  auto map_last = FlashesBySize.end();
201  map_last--;
202  BOOST_TEST( map_last->first == 50 );
203 
204  BOOST_TEST( FlashesBySize[50].size() == 2U );
205  BOOST_TEST( FlashesBySize[50].count(1) == 1U );
206  BOOST_TEST( FlashesBySize[50].count(2) == 1U );
207 
208  BOOST_TEST( FlashesBySize[50][1].size() == 1U );
209  BOOST_TEST( FlashesBySize[50][1][0] == 2 );
210  BOOST_TEST( FlashesBySize[50][2].size() == 1U );
211  BOOST_TEST( FlashesBySize[50][2][0] == 8 );
212 
213  BOOST_TEST( FlashesBySize[60].size() == 1U );
214  BOOST_TEST( FlashesBySize[60].count(1) == 1U );
215  BOOST_TEST( FlashesBySize[60].count(2) == 0U );
216  BOOST_TEST( FlashesBySize[60][1].size() == 1U );
217  BOOST_TEST( FlashesBySize[60][1][0] == 5 );
218 }
219 
220 BOOST_AUTO_TEST_CASE(FillHitsThisFlash_EmptyContributors)
221 {
222 
223  size_t NHits = 10;
224 
225  const size_t vector_size = 1;
226  std::vector< std::vector<int> > Contributors(vector_size);
227  int Bin = 0;
228 
229  std::vector<int> HitClaimedByFlash(NHits,-1);
230  std::vector<int> HitsThisFlash;
231 
232  opdet::FillHitsThisFlash(Contributors,
233  Bin,
234  HitClaimedByFlash,
235  HitsThisFlash);
236 
237  BOOST_TEST( HitsThisFlash.size() == 0U);
238 }
239 
240 BOOST_AUTO_TEST_CASE(FillHitsThisFlash_NoPrevClaimedHits)
241 {
242 
243  size_t NHits = 10;
244 
245  const size_t vector_size = 1;
246  std::vector< std::vector<int> > Contributors(vector_size);
247  int Bin = 0;
248  Contributors[0].push_back(1); Contributors[0].push_back(3);
249 
250  std::vector<int> HitClaimedByFlash(NHits,-1);
251  std::vector<int> HitsThisFlash;
252 
253  opdet::FillHitsThisFlash(Contributors,
254  Bin,
255  HitClaimedByFlash,
256  HitsThisFlash);
257 
258  BOOST_TEST( HitsThisFlash.size() == 2U );
259  BOOST_TEST( HitsThisFlash[0] == 1 );
260  BOOST_TEST( HitsThisFlash[1] == 3 );
261 }
262 
263 BOOST_AUTO_TEST_CASE(FillHitsThisFlash_PrevClaimedHits)
264 {
265 
266  size_t NHits = 10;
267 
268  const size_t vector_size = 1;
269  std::vector< std::vector<int> > Contributors(vector_size);
270  int Bin = 0;
271  Contributors[0].push_back(1); Contributors[0].push_back(3);
272 
273  std::vector<int> HitClaimedByFlash(NHits,-1);
274  HitClaimedByFlash[1] = 0;
275  HitClaimedByFlash[2] = 1;
276  std::vector<int> HitsThisFlash;
277 
278  opdet::FillHitsThisFlash(Contributors,
279  Bin,
280  HitClaimedByFlash,
281  HitsThisFlash);
282 
283  BOOST_TEST( HitsThisFlash.size() == 1U );
284  BOOST_TEST( HitsThisFlash[0] == 3 );
285 }
286 
287 BOOST_AUTO_TEST_CASE(FillHitsThisFlash_MultipleContributorVectors)
288 {
289 
290  size_t NHits = 10;
291 
292  const size_t vector_size = 2;
293  std::vector< std::vector<int> > Contributors(vector_size);
294  Contributors[0].push_back(1); Contributors[0].push_back(3);
295  Contributors[1].push_back(5); Contributors[1].push_back(6);
296 
297  std::vector<int> HitClaimedByFlash(NHits,-1);
298  HitClaimedByFlash[1] = 0;
299  HitClaimedByFlash[2] = 1;
300  std::vector<int> HitsThisFlash;
301 
302  opdet::FillHitsThisFlash(Contributors,
303  1,
304  HitClaimedByFlash,
305  HitsThisFlash);
306 
307  BOOST_TEST( HitsThisFlash.size() == 2U );
308  BOOST_TEST( HitsThisFlash[0] == 5 );
309  BOOST_TEST( HitsThisFlash[1] == 6 );
310 }
311 
312 BOOST_AUTO_TEST_CASE(ClaimHits_NoHitsThisFlash)
313 {
314  size_t NHits = 1;
315 
316  //need this part to make a hit...
317  double hit_pe = 10;
318  std::vector<recob::OpHit> HitVector;
319  for(size_t i=0; i<NHits; i++)
320  HitVector.emplace_back(0,0,0,0,0,0,0,hit_pe,0);
321 
322  std::vector<int> HitsThisFlash;
323  std::vector< std::vector<int> > HitsPerFlash;
324 
325  std::vector<int> HitClaimedByFlash(NHits,-1);
326 
327  opdet::ClaimHits(HitVector,
328  HitsThisFlash,
330  HitsPerFlash,
331  HitClaimedByFlash);
332 
333  BOOST_TEST( HitsPerFlash.size() == 0U);
334  BOOST_TEST( HitClaimedByFlash[0] == -1);
335 }
336 
337 BOOST_AUTO_TEST_CASE(ClaimHits_BelowFlashThreshold)
338 {
339  size_t NHits = 1;
340 
341  //need this part to make a hit...
342  double hit_pe = 10;
343  std::vector<recob::OpHit> HitVector;
344  for(size_t i=0; i<NHits; i++)
345  HitVector.emplace_back(0,0,0,0,0,0,0,hit_pe,0);
346 
347  std::vector<int> HitsThisFlash(1,0);
348  std::vector< std::vector<int> > HitsPerFlash;
349 
350  std::vector<int> HitClaimedByFlash(NHits,-1);
351 
352  opdet::ClaimHits(HitVector,
353  HitsThisFlash,
355  HitsPerFlash,
356  HitClaimedByFlash);
357 
358  BOOST_TEST( HitsPerFlash.size() == 0U);
359  BOOST_TEST( HitClaimedByFlash[0] == -1);
360 }
361 
362 BOOST_AUTO_TEST_CASE(ClaimHits_AboveFlashThreshold)
363 {
364  size_t NHits = 1;
365 
366  //need this part to make a hit...
367  double hit_pe = 100;
368  std::vector<recob::OpHit> HitVector;
369  for(size_t i=0; i<NHits; i++)
370  HitVector.emplace_back(0,0,0,0,0,0,0,hit_pe,0);
371 
372  std::vector<int> HitsThisFlash(1,0);
373  std::vector< std::vector<int> > HitsPerFlash;
374 
375  std::vector<int> HitClaimedByFlash(NHits,-1);
376 
377  opdet::ClaimHits(HitVector,
378  HitsThisFlash,
380  HitsPerFlash,
381  HitClaimedByFlash);
382 
383  BOOST_TEST( HitsPerFlash.size() == 1U);
384  BOOST_TEST( HitsPerFlash[0][0] == 0);
385  BOOST_TEST( HitClaimedByFlash[0] == 0);
386 }
387 
388 BOOST_AUTO_TEST_CASE(ClaimHits_OneHitThisFlash)
389 {
390  size_t NHits = 2;
391 
392  //need this part to make a hit...
393  double hit_pe = 100;
394  std::vector<recob::OpHit> HitVector;
395  for(size_t i=0; i<NHits; i++)
396  HitVector.emplace_back(0,0,0,0,0,0,0,hit_pe,0);
397 
398  std::vector<int> HitsThisFlash(1,0);
399  std::vector< std::vector<int> > HitsPerFlash;
400 
401  std::vector<int> HitClaimedByFlash(NHits,-1);
402 
403  opdet::ClaimHits(HitVector,
404  HitsThisFlash,
406  HitsPerFlash,
407  HitClaimedByFlash);
408 
409  BOOST_TEST( HitsPerFlash.size() == 1U);
410  BOOST_TEST( HitsPerFlash[0][0] == 0);
411  BOOST_TEST( HitClaimedByFlash[0] == 0);
412  BOOST_TEST( HitClaimedByFlash[1] == -1);
413 }
414 
415 BOOST_AUTO_TEST_CASE(ClaimHits_TwoHitsThisFlash_BelowThreshold)
416 {
417  size_t NHits = 2;
418 
419  //need this part to make a hit...
420  double hit_pe = 10;
421  std::vector<recob::OpHit> HitVector;
422  for(size_t i=0; i<NHits; i++)
423  HitVector.emplace_back(0,0,0,0,0,0,0,hit_pe,0);
424 
425  std::vector<int> HitsThisFlash;
426  HitsThisFlash.push_back(0); HitsThisFlash.push_back(1);
427  std::vector< std::vector<int> > HitsPerFlash;
428 
429  std::vector<int> HitClaimedByFlash(NHits,-1);
430 
431  opdet::ClaimHits(HitVector,
432  HitsThisFlash,
434  HitsPerFlash,
435  HitClaimedByFlash);
436 
437  BOOST_TEST( HitsPerFlash.size() == 0U);
438  BOOST_TEST( HitClaimedByFlash[0] == -1);
439  BOOST_TEST( HitClaimedByFlash[1] == -1);
440 }
441 
442 BOOST_AUTO_TEST_CASE(ClaimHits_TwoHitsThisFlash_AboveThreshold)
443 {
444  size_t NHits = 2;
445 
446  //need this part to make a hit...
447  double hit_pe = 30;
448  std::vector<recob::OpHit> HitVector;
449  for(size_t i=0; i<NHits; i++)
450  HitVector.emplace_back(0,0,0,0,0,0,0,hit_pe,0);
451 
452  std::vector<int> HitsThisFlash;
453  HitsThisFlash.push_back(0); HitsThisFlash.push_back(1);
454  std::vector< std::vector<int> > HitsPerFlash;
455 
456  std::vector<int> HitClaimedByFlash(NHits,-1);
457 
458  opdet::ClaimHits(HitVector,
459  HitsThisFlash,
461  HitsPerFlash,
462  HitClaimedByFlash);
463 
464  BOOST_TEST( HitsPerFlash.size() == 1U);
465  BOOST_TEST( HitsPerFlash[0][0] == 0);
466  BOOST_TEST( HitsPerFlash[0][1] == 1);
467  BOOST_TEST( HitClaimedByFlash[0] == 0);
468  BOOST_TEST( HitClaimedByFlash[1] == 0);
469 }
470 
471 BOOST_AUTO_TEST_CASE(FindSeedHit_AllUsed)
472 {
473 
474  size_t NHits = 5;
475 
476  std::vector<int> HitsThisRefinedFlash;
477  double PEAccumulated=0, FlashMaxTime=0, FlashMinTime=0;
478 
479  double hit_pe = 20;
480  double peak_time = 0;
481  double width = 10;
482  std::vector<recob::OpHit> HitVector;
483  for(size_t i=0; i<NHits; i++){
484  HitVector.emplace_back(0,peak_time,0,0,width,0,0,hit_pe,0);
485  hit_pe+=10;
486  peak_time+=1;
487  }
488 
489  std::map<double, std::vector<int>, std::greater<double> > HitsBySize;
490  for(size_t i=0; i<NHits; i++)
491  HitsBySize[HitVector.at(i).PE()].push_back(i);
492 
493  std::vector<bool> HitsUsed(NHits,true);
494 
495  opdet::FindSeedHit(HitsBySize,
496  HitsUsed,
497  HitVector,
498  HitsThisRefinedFlash,
499  PEAccumulated,
500  FlashMaxTime,
501  FlashMinTime);
502 
503  BOOST_TEST( HitsThisRefinedFlash.size() == 0U );
504  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == (int)NHits);
505  BOOST_TEST( PEAccumulated == 0 );
506  BOOST_TEST( FlashMaxTime == 0 );
507  BOOST_TEST( FlashMinTime == 0 );
508 
509 }
510 
511 BOOST_AUTO_TEST_CASE(FindSeedHit_NoneUsed)
512 {
513 
514  size_t NHits = 5;
515 
516  std::vector<int> HitsThisRefinedFlash;
517  double PEAccumulated=0, FlashMaxTime=0, FlashMinTime=0;
518 
519  double hit_pe = 20;
520  double peak_time = 0;
521  double width = 10;
522  std::vector<recob::OpHit> HitVector;
523  for(size_t i=0; i<NHits; i++){
524  HitVector.emplace_back(0,peak_time,0,0,width,0,0,hit_pe,0);
525  hit_pe+=10;
526  peak_time+=1;
527  }
528 
529  std::map<double, std::vector<int>, std::greater<double> > HitsBySize;
530  for(size_t i=0; i<NHits; i++)
531  HitsBySize[HitVector.at(i).PE()].push_back(i);
532 
533  std::vector<bool> HitsUsed(NHits,false);
534 
535  opdet::FindSeedHit(HitsBySize,
536  HitsUsed,
537  HitVector,
538  HitsThisRefinedFlash,
539  PEAccumulated,
540  FlashMaxTime,
541  FlashMinTime);
542 
543  BOOST_TEST( HitsThisRefinedFlash.size() == 1U );
544  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 1);
545  BOOST_TEST( HitsUsed.at(NHits-1) == true);
546  BOOST_TEST( PEAccumulated == 60 );
547  BOOST_TEST( FlashMaxTime == 9. );
548  BOOST_TEST( FlashMinTime == -1. );
549 
550 }
551 
552 BOOST_AUTO_TEST_CASE(FindSeedHit_FirstUsed)
553 {
554 
555  size_t NHits = 5;
556 
557  std::vector<int> HitsThisRefinedFlash;
558  double PEAccumulated=0, FlashMaxTime=0, FlashMinTime=0;
559 
560  double hit_pe = 20;
561  double peak_time = 0;
562  double width = 10;
563  std::vector<recob::OpHit> HitVector;
564  for(size_t i=0; i<NHits; i++){
565  HitVector.emplace_back(0,peak_time,0,0,width,0,0,hit_pe,0);
566  hit_pe+=10;
567  peak_time+=1;
568  }
569 
570  std::map<double, std::vector<int>, std::greater<double> > HitsBySize;
571  for(size_t i=0; i<NHits; i++)
572  HitsBySize[HitVector.at(i).PE()].push_back(i);
573 
574  std::vector<bool> HitsUsed(NHits,false);
575  HitsUsed[NHits-1] = true;
576 
577  opdet::FindSeedHit(HitsBySize,
578  HitsUsed,
579  HitVector,
580  HitsThisRefinedFlash,
581  PEAccumulated,
582  FlashMaxTime,
583  FlashMinTime);
584 
585  BOOST_TEST( HitsThisRefinedFlash.size() == 1U );
586  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 2);
587  BOOST_TEST( HitsUsed.at(NHits-1) == true);
588  BOOST_TEST( HitsUsed.at(NHits-2) == true);
589  BOOST_TEST( PEAccumulated == 50 );
590  BOOST_TEST( FlashMaxTime == 8. );
591  BOOST_TEST( FlashMinTime == -2. );
592 
593 }
594 
595 BOOST_AUTO_TEST_CASE(AddHitToFlash_UsedHit)
596 {
597 
598  size_t NHits = 5;
599 
600  std::vector<int> HitsThisRefinedFlash;
601  double PEAccumulated=0, FlashMaxTime=0, FlashMinTime=0;
602 
603  double hit_pe = 20;
604  double peak_time = 0;
605  double width = 10;
606  std::vector<recob::OpHit> HitVector;
607  for(size_t i=0; i<NHits; i++){
608  HitVector.emplace_back(0,peak_time,0,0,width,0,0,hit_pe,0);
609  hit_pe+=10;
610  peak_time+=1;
611  }
612 
613  std::map<double, std::vector<int>, std::greater<double> > HitsBySize;
614  for(size_t i=0; i<NHits; i++)
615  HitsBySize[HitVector.at(i).PE()].push_back(i);
616  std::vector<bool> HitsUsed(NHits,false);
617 
618  opdet::FindSeedHit(HitsBySize,
619  HitsUsed,
620  HitVector,
621  HitsThisRefinedFlash,
622  PEAccumulated,
623  FlashMaxTime,
624  FlashMinTime);
625 
626  int HitID = 4;
627  opdet::AddHitToFlash( HitID,
628  HitsUsed,
629  HitVector.at(HitID),
631  HitsThisRefinedFlash,
632  PEAccumulated,
633  FlashMaxTime,
634  FlashMinTime);
635 
636  BOOST_TEST( HitsThisRefinedFlash.size() == 1U );
637  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 1);
638  BOOST_TEST( HitsUsed.at(NHits-1) == true);
639  BOOST_TEST( PEAccumulated == 60 );
640  BOOST_TEST( FlashMaxTime == 9. );
641  BOOST_TEST( FlashMinTime == -1. );
642 
643 }
644 
645 BOOST_AUTO_TEST_CASE(AddHitToFlash_NewHit)
646 {
647 
648  size_t NHits = 5;
649 
650  std::vector<int> HitsThisRefinedFlash;
651  double PEAccumulated=0, FlashMaxTime=0, FlashMinTime=0;
652 
653  double hit_pe = 20;
654  double peak_time = 0;
655  double width = 10;
656  std::vector<recob::OpHit> HitVector;
657  for(size_t i=0; i<NHits; i++){
658  HitVector.emplace_back(0,peak_time,0,0,width,0,0,hit_pe,0);
659  hit_pe+=10;
660  peak_time+=1;
661  }
662 
663  std::map<double, std::vector<int>, std::greater<double> > HitsBySize;
664  for(size_t i=0; i<NHits; i++)
665  HitsBySize[HitVector.at(i).PE()].push_back(i);
666  std::vector<bool> HitsUsed(NHits,false);
667 
668  opdet::FindSeedHit(HitsBySize,
669  HitsUsed,
670  HitVector,
671  HitsThisRefinedFlash,
672  PEAccumulated,
673  FlashMaxTime,
674  FlashMinTime);
675 
676  int HitID = 3;
677  opdet::AddHitToFlash( HitID,
678  HitsUsed,
679  HitVector.at(HitID),
681  HitsThisRefinedFlash,
682  PEAccumulated,
683  FlashMaxTime,
684  FlashMinTime);
685 
686  BOOST_TEST( HitsThisRefinedFlash.size() == 2U );
687  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 2);
688  BOOST_TEST( HitsUsed.at(NHits-1) == true);
689  BOOST_TEST( HitsUsed.at(NHits-2) == true);
690  BOOST_TEST( PEAccumulated == 110 );
691  BOOST_TEST( FlashMaxTime == 9. );
692  BOOST_TEST( FlashMinTime == -2. );
693 
694 }
695 
696 BOOST_AUTO_TEST_CASE(AddHitToFlash_OutsideWidth)
697 {
698 
699  size_t NHits = 5;
700 
701  std::vector<int> HitsThisRefinedFlash;
702  double PEAccumulated=0, FlashMaxTime=0, FlashMinTime=0;
703 
704  double hit_pe = 20;
705  double peak_time = 0;
706  double width = 0.1;
707  std::vector<recob::OpHit> HitVector;
708  for(size_t i=0; i<NHits; i++){
709  HitVector.emplace_back(0,peak_time,0,0,width,0,0,hit_pe,0);
710  hit_pe+=10;
711  peak_time+=1;
712  }
713 
714  std::map<double, std::vector<int>, std::greater<double> > HitsBySize;
715  for(size_t i=0; i<NHits; i++)
716  HitsBySize[HitVector.at(i).PE()].push_back(i);
717  std::vector<bool> HitsUsed(NHits,false);
718 
719  opdet::FindSeedHit(HitsBySize,
720  HitsUsed,
721  HitVector,
722  HitsThisRefinedFlash,
723  PEAccumulated,
724  FlashMaxTime,
725  FlashMinTime);
726 
727  int HitID = 3;
728  opdet::AddHitToFlash( HitID,
729  HitsUsed,
730  HitVector.at(HitID),
732  HitsThisRefinedFlash,
733  PEAccumulated,
734  FlashMaxTime,
735  FlashMinTime);
736 
737  BOOST_TEST( HitsThisRefinedFlash.size() == 1U );
738  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 1);
739  BOOST_TEST( HitsUsed.at(NHits-1) == true);
740  BOOST_TEST( HitsUsed.at(NHits-2) == false);
741  BOOST_TEST( PEAccumulated == 60 );
742  BOOST_TEST( FlashMaxTime == 4.05 );
743  BOOST_TEST( FlashMinTime == 3.95 );
744 
745 }
746 
747 BOOST_AUTO_TEST_CASE(CheckAndStoreFlash_AboveThreshold)
748 {
749  std::vector< std::vector<int> > RefinedHitsPerFlash;
750 
751  std::vector<int> HitsThisRefinedFlash{0,1,2};
752  std::vector<bool> HitsUsed{true,true,true,false,false};
753  double PEAccumulated = 60;
754 
755  opdet::CheckAndStoreFlash( RefinedHitsPerFlash,
756  HitsThisRefinedFlash,
757  PEAccumulated,
759  HitsUsed );
760 
761  BOOST_TEST( RefinedHitsPerFlash.size() == 1U );
762  BOOST_TEST( RefinedHitsPerFlash[0].size() == 3U );
763  BOOST_TEST( RefinedHitsPerFlash[0][0] == 0 );
764  BOOST_TEST( RefinedHitsPerFlash[0][1] == 1 );
765  BOOST_TEST( RefinedHitsPerFlash[0][2] == 2 );
766  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 3);
767 
768 }
769 
770 BOOST_AUTO_TEST_CASE(CheckAndStoreFlash_AboveThreshold_OneHit)
771 {
772  std::vector< std::vector<int> > RefinedHitsPerFlash;
773 
774  std::vector<int> HitsThisRefinedFlash{0};
775  std::vector<bool> HitsUsed{true,false,false,false,false};
776  double PEAccumulated = 60;
777 
778  opdet::CheckAndStoreFlash( RefinedHitsPerFlash,
779  HitsThisRefinedFlash,
780  PEAccumulated,
782  HitsUsed );
783 
784  BOOST_TEST( RefinedHitsPerFlash.size() == 1U );
785  BOOST_TEST( RefinedHitsPerFlash[0].size() == 1U );
786  BOOST_TEST( RefinedHitsPerFlash[0][0] == 0 );
787  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 1);
788 
789 }
790 
791 BOOST_AUTO_TEST_CASE(CheckAndStoreFlash_BelowThreshold_OneHit)
792 {
793  std::vector< std::vector<int> > RefinedHitsPerFlash;
794 
795  std::vector<int> HitsThisRefinedFlash{0};
796  std::vector<bool> HitsUsed{true,false,false,false,false};
797  double PEAccumulated = 30;
798 
799  opdet::CheckAndStoreFlash( RefinedHitsPerFlash,
800  HitsThisRefinedFlash,
801  PEAccumulated,
803  HitsUsed );
804 
805  BOOST_TEST( RefinedHitsPerFlash.size() == 0U );
806  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 1);
807  BOOST_TEST( HitsUsed[0] == true);
808 
809 }
810 
811 BOOST_AUTO_TEST_CASE(CheckAndStoreFlash_BelowThreshold_MultipleHits)
812 {
813  std::vector< std::vector<int> > RefinedHitsPerFlash;
814 
815  std::vector<int> HitsThisRefinedFlash{0,1,2};
816  std::vector<bool> HitsUsed{true,true,true,false,false};
817  double PEAccumulated = 30;
818 
819  opdet::CheckAndStoreFlash( RefinedHitsPerFlash,
820  HitsThisRefinedFlash,
821  PEAccumulated,
823  HitsUsed );
824 
825  BOOST_TEST( RefinedHitsPerFlash.size() == 0U );
826  BOOST_TEST( std::count(HitsUsed.begin(),HitsUsed.end(),true) == 1);
827  BOOST_TEST( HitsUsed[0] == true);
828  BOOST_TEST( HitsUsed[1] == false);
829  BOOST_TEST( HitsUsed[2] == false);
830 
831 }
832 
833 BOOST_AUTO_TEST_CASE(AddHitContribution_AddFirstHit)
834 {
835  double MaxTime = -1e9, MinTime = 1e9;
836  double TotalPE=0, AveTime=0, AveAbsTime=0, FastToTotal=0;
837 
838  size_t NOpChannels = 5;
839  std::vector<double> PEs(NOpChannels,0);
840 
841  double hit_pe = 20;
842  double peak_time = 1;
843  double width = 5;
844  int op_channel = 0;
845  recob::OpHit currentHit(op_channel,peak_time,0,0,width,0,0,hit_pe,0);
846 
847  opdet::AddHitContribution( currentHit,
848  MaxTime,
849  MinTime,
850  AveTime,
851  FastToTotal,
852  AveAbsTime,
853  TotalPE,
854  PEs);
855 
856  BOOST_TEST( MaxTime == peak_time );
857  BOOST_TEST( MinTime == peak_time );
858  BOOST_TEST( AveTime == peak_time*hit_pe );
859  BOOST_TEST( AveAbsTime == 0 );
860  BOOST_TEST( FastToTotal == 0 );
861  BOOST_TEST( TotalPE == hit_pe );
862  BOOST_TEST( PEs.at(op_channel) == hit_pe );
863  BOOST_TEST( PEs.at(4) == 0 );
864 }
865 
866 BOOST_AUTO_TEST_CASE(AddHitContribution_AddSecondHit)
867 {
868  double MaxTime = 1, MinTime = 1;
869  double TotalPE=20, AveTime=20, AveAbsTime=0, FastToTotal=0;
870 
871  size_t NOpChannels = 5;
872  std::vector<double> PEs(NOpChannels,0);
873  PEs.at(0)+=20;
874 
875  double hit_pe = 30;
876  double peak_time = 5;
877  double width = 5;
878  int op_channel = 2;
879  recob::OpHit currentHit(op_channel,peak_time,0,0,width,0,0,hit_pe,0);
880 
881  opdet::AddHitContribution( currentHit,
882  MaxTime,
883  MinTime,
884  AveTime,
885  FastToTotal,
886  AveAbsTime,
887  TotalPE,
888  PEs);
889 
890  BOOST_TEST( MaxTime == peak_time );
891  BOOST_TEST( MinTime == 1 );
892  BOOST_TEST( AveTime == peak_time*hit_pe+20 );
893  BOOST_TEST( AveAbsTime == 0 );
894  BOOST_TEST( FastToTotal == 0 );
895  BOOST_TEST( TotalPE == hit_pe+20 );
896  BOOST_TEST( PEs.at(op_channel) == hit_pe );
897  BOOST_TEST( PEs.at(0) == 20 );
898  BOOST_TEST( PEs.at(4) == 0 );
899 }
900 
901 
902 BOOST_AUTO_TEST_CASE(GetLikelihoodLateLight_BackwardsTime)
903 {
904 
905  double iPE = 100; double iTime = 0; double iWidth=0.5;
906  double jPE = 100; double jTime = -1; double jWidth=0.5;
907 
908  double result = opdet::GetLikelihoodLateLight(iPE, iTime, iWidth,
909  jPE, jTime, jWidth);
910 
911  BOOST_TEST( result == 1e6, tolerance);
912 }
913 
914 BOOST_AUTO_TEST_CASE(GetLikelihoodLateLight_EqualFlashes)
915 {
916 
917  double iPE = 100; double iTime = 0; double iWidth=0.5;
918  double jPE = 100; double jTime = 0; double jWidth=0.5;
919 
920  double result = opdet::GetLikelihoodLateLight(iPE, iTime, iWidth,
921  jPE, jTime, jWidth);
922 
923  BOOST_TEST( result == 0, tolerance);
924 }
925 
926 BOOST_AUTO_TEST_CASE(GetLikelihoodLateLight_LateFlash)
927 {
928 
929  double iPE = 100; double iTime = 0; double iWidth=0.5;
930  double jPE = 10; double jTime = 1.6; double jWidth=0.5;
931 
932  double result = opdet::GetLikelihoodLateLight(iPE, iTime, iWidth,
933  jPE, jTime, jWidth);
934 
935  double good_result = (jPE - std::exp(-1)*iPE)/(std::sqrt(std::exp(-1)*iPE));
936 
937  BOOST_TEST( result == good_result, tolerance);
938 }
939 
940 BOOST_AUTO_TEST_CASE(GetLikelihoodLateLight_VeryLateFlash)
941 {
942 
943  double iPE = 100; double iTime = 0; double iWidth=0.5;
944  double jPE = 10; double jTime = 16; double jWidth=0.5;
945 
946  double result = opdet::GetLikelihoodLateLight(iPE, iTime, iWidth,
947  jPE, jTime, jWidth);
948 
949  double good_result = (jPE - std::exp(-10)*iPE)/(std::sqrt(std::exp(-10)*iPE));
950 
951  BOOST_TEST( result == good_result, tolerance);
952 }
953 
954 BOOST_AUTO_TEST_CASE(GetLikelihoodLateLight_UnequalWidths)
955 {
956 
957  double iPE = 100; double iTime = 0; double iWidth=1;
958  double jPE = 10; double jTime = 1.6; double jWidth=0.5;
959 
960  double result = opdet::GetLikelihoodLateLight(iPE, iTime, iWidth,
961  jPE, jTime, jWidth);
962 
963  double good_result = (jPE - std::exp(-1)*iPE*0.5)/(std::sqrt(std::exp(-1)*iPE*0.5));
964 
965  BOOST_TEST( result == good_result, tolerance);
966 }
967 
968 BOOST_AUTO_TEST_CASE(MarkFlashesForRemoval_NoFlashes)
969 {
970  size_t NFlashes=5;
971  size_t BeginFlash=5; //that is, no new flashes to look at
972 
973  std::vector<recob::OpFlash> FlashVector(NFlashes);
974  std::vector<bool> MarkedForRemoval(NFlashes-BeginFlash,false);
975 
976  opdet::MarkFlashesForRemoval(FlashVector,
977  BeginFlash,
978  MarkedForRemoval);
979 
980  BOOST_TEST( MarkedForRemoval.size() == 0U );
981 
982 }
983 
984 BOOST_AUTO_TEST_CASE(MarkFlashesForRemoval_OneFlash)
985 {
986  size_t NFlashes=1;
987  size_t BeginFlash=0;
988 
989  std::vector<double> PEs(30,0);
990  PEs.at(0) = 100;
991  std::vector<double> WireCenters(3,0);
992  std::vector<double> WireWidths(3,0);
993 
994  std::vector<recob::OpFlash> FlashVector;
995  FlashVector.emplace_back(0, //time
996  0.5, //TimeWidth,
997  0, //AveAbsTime,
998  0, //Frame,
999  PEs,
1000  0, //InBeamFrame,
1001  0, //OnBeamTime,
1002  0, //FastToTotal,
1003  0, //meany,
1004  0, //widthy,
1005  0, //meanz,
1006  0, //widthz,
1007  WireCenters,
1008  WireWidths);
1009  std::vector<bool> MarkedForRemoval(NFlashes-BeginFlash,false);
1010 
1011  opdet::MarkFlashesForRemoval(FlashVector,
1012  BeginFlash,
1013  MarkedForRemoval);
1014 
1015  BOOST_TEST( MarkedForRemoval.size() == 1U );
1016  BOOST_TEST( MarkedForRemoval[0] == false );
1017  BOOST_TEST( FlashVector.size() == 1U );
1018  BOOST_TEST( FlashVector[0].Time() == 0 );
1019  BOOST_TEST( FlashVector[0].TimeWidth() == 0.5 );
1020 
1021 }
1022 
1023 BOOST_AUTO_TEST_CASE(MarkFlashesForRemoval_TwoIndieFlashes)
1024 {
1025  size_t NFlashes=2;
1026  size_t BeginFlash=0;
1027 
1028  std::vector<double> PEs(30,0);
1029  PEs.at(0) = 100;
1030  std::vector<double> WireCenters(3,0);
1031  std::vector<double> WireWidths(3,0);
1032 
1033  std::vector<recob::OpFlash> FlashVector;
1034  FlashVector.emplace_back(0, //time
1035  0.5, //TimeWidth,
1036  0, //AveAbsTime,
1037  0, //Frame,
1038  PEs,
1039  0, //InBeamFrame,
1040  0, //OnBeamTime,
1041  0, //FastToTotal,
1042  0, //meany,
1043  0, //widthy,
1044  0, //meanz,
1045  0, //widthz,
1046  WireCenters,
1047  WireWidths);
1048  FlashVector.emplace_back(1e6, //time
1049  0.5, //TimeWidth,
1050  0, //AveAbsTime,
1051  0, //Frame,
1052  PEs,
1053  0, //InBeamFrame,
1054  0, //OnBeamTime,
1055  0, //FastToTotal,
1056  0, //meany,
1057  0, //widthy,
1058  0, //meanz,
1059  0, //widthz,
1060  WireCenters,
1061  WireWidths);
1062  std::vector<bool> MarkedForRemoval(NFlashes-BeginFlash,false);
1063 
1064  opdet::MarkFlashesForRemoval(FlashVector,
1065  BeginFlash,
1066  MarkedForRemoval);
1067 
1068  BOOST_TEST( MarkedForRemoval.size() == 2U );
1069  BOOST_TEST( MarkedForRemoval[0] == false );
1070  BOOST_TEST( MarkedForRemoval[1] == false );
1071  BOOST_TEST( FlashVector.size() == 2U );
1072  BOOST_TEST( FlashVector[0].Time() == 0 );
1073  BOOST_TEST( FlashVector[1].Time() == 1e6 );
1074 
1075 }
1076 
1077 BOOST_AUTO_TEST_CASE(MarkFlashesForRemoval_RemoveOneFlash)
1078 {
1079  size_t NFlashes=3;
1080  size_t BeginFlash=0;
1081 
1082  std::vector<double> PEs(30,0);
1083  PEs.at(0) = 100;
1084  std::vector<double> PEs_Small(30,0);
1085  PEs_Small.at(0) = 5;
1086  std::vector<double> WireCenters(3,0);
1087  std::vector<double> WireWidths(3,0);
1088 
1089  std::vector<recob::OpFlash> FlashVector;
1090  FlashVector.emplace_back(0, //time
1091  0.5, //TimeWidth,
1092  0, //AveAbsTime,
1093  0, //Frame,
1094  PEs,
1095  0, //InBeamFrame,
1096  0, //OnBeamTime,
1097  0, //FastToTotal,
1098  0, //meany,
1099  0, //widthy,
1100  0, //meanz,
1101  0, //widthz,
1102  WireCenters,
1103  WireWidths);
1104  FlashVector.emplace_back(1.6, //time
1105  0.5, //TimeWidth,
1106  0, //AveAbsTime,
1107  0, //Frame,
1108  PEs_Small,
1109  0, //InBeamFrame,
1110  0, //OnBeamTime,
1111  0, //FastToTotal,
1112  0, //meany,
1113  0, //widthy,
1114  0, //meanz,
1115  0, //widthz,
1116  WireCenters,
1117  WireWidths);
1118  FlashVector.emplace_back(1e6, //time
1119  0.5, //TimeWidth,
1120  0, //AveAbsTime,
1121  0, //Frame,
1122  PEs,
1123  0, //InBeamFrame,
1124  0, //OnBeamTime,
1125  0, //FastToTotal,
1126  0, //meany,
1127  0, //widthy,
1128  0, //meanz,
1129  0, //widthz,
1130  WireCenters,
1131  WireWidths);
1132  std::vector<bool> MarkedForRemoval(NFlashes-BeginFlash,false);
1133 
1134  opdet::MarkFlashesForRemoval(FlashVector,
1135  BeginFlash,
1136  MarkedForRemoval);
1137 
1138  BOOST_TEST( MarkedForRemoval.size() == 3U );
1139  BOOST_TEST( MarkedForRemoval[0] == false );
1140  BOOST_TEST( MarkedForRemoval[1] == true );
1141  BOOST_TEST( MarkedForRemoval[2] == false );
1142  BOOST_TEST( FlashVector.size() == 3U );
1143  BOOST_TEST( FlashVector[0].Time() == 0 );
1144  BOOST_TEST( FlashVector[0].TotalPE() == 100 );
1145  BOOST_TEST( FlashVector[1].Time() == 1.6 );
1146  BOOST_TEST( FlashVector[1].TotalPE() == 5 );
1147  BOOST_TEST( FlashVector[2].Time() == 1e6 );
1148  BOOST_TEST( FlashVector[2].TotalPE() == 100 );
1149 
1150 }
1151 
1152 BOOST_AUTO_TEST_CASE(MarkFlashesForRemoval_IgnoreFirstFlash)
1153 {
1154  size_t NFlashes=4;
1155  size_t BeginFlash=1;
1156 
1157  std::vector<double> PEs(30,0);
1158  PEs.at(0) = 100;
1159  std::vector<double> PEs_Small(30,0);
1160  PEs_Small.at(0) = 5;
1161  std::vector<double> WireCenters(3,0);
1162  std::vector<double> WireWidths(3,0);
1163 
1164  std::vector<recob::OpFlash> FlashVector;
1165  FlashVector.emplace_back(-1e6, //time
1166  0.5, //TimeWidth,
1167  0, //AveAbsTime,
1168  0, //Frame,
1169  PEs,
1170  0, //InBeamFrame,
1171  0, //OnBeamTime,
1172  0, //FastToTotal,
1173  0, //meany,
1174  0, //widthy,
1175  0, //meanz,
1176  0, //widthz,
1177  WireCenters,
1178  WireWidths);
1179  FlashVector.emplace_back(0, //time
1180  0.5, //TimeWidth,
1181  0, //AveAbsTime,
1182  0, //Frame,
1183  PEs,
1184  0, //InBeamFrame,
1185  0, //OnBeamTime,
1186  0, //FastToTotal,
1187  0, //meany,
1188  0, //widthy,
1189  0, //meanz,
1190  0, //widthz,
1191  WireCenters,
1192  WireWidths);
1193  FlashVector.emplace_back(1.6, //time
1194  0.5, //TimeWidth,
1195  0, //AveAbsTime,
1196  0, //Frame,
1197  PEs_Small,
1198  0, //InBeamFrame,
1199  0, //OnBeamTime,
1200  0, //FastToTotal,
1201  0, //meany,
1202  0, //widthy,
1203  0, //meanz,
1204  0, //widthz,
1205  WireCenters,
1206  WireWidths);
1207  FlashVector.emplace_back(1e6, //time
1208  0.5, //TimeWidth,
1209  0, //AveAbsTime,
1210  0, //Frame,
1211  PEs,
1212  0, //InBeamFrame,
1213  0, //OnBeamTime,
1214  0, //FastToTotal,
1215  0, //meany,
1216  0, //widthy,
1217  0, //meanz,
1218  0, //widthz,
1219  WireCenters,
1220  WireWidths);
1221  std::vector<bool> MarkedForRemoval(NFlashes-BeginFlash,false);
1222 
1223  opdet::MarkFlashesForRemoval(FlashVector,
1224  BeginFlash,
1225  MarkedForRemoval);
1226 
1227  BOOST_TEST( MarkedForRemoval.size() == 3U );
1228  BOOST_TEST( MarkedForRemoval[0] == false );
1229  BOOST_TEST( MarkedForRemoval[1] == true );
1230  BOOST_TEST( MarkedForRemoval[2] == false );
1231  BOOST_TEST( FlashVector.size() == 4U );
1232  BOOST_TEST( FlashVector[0].Time() == -1e6 );
1233  BOOST_TEST( FlashVector[0].TotalPE() == 100 );
1234  BOOST_TEST( FlashVector[1].Time() == 0 );
1235  BOOST_TEST( FlashVector[1].TotalPE() == 100 );
1236  BOOST_TEST( FlashVector[2].Time() == 1.6 );
1237  BOOST_TEST( FlashVector[2].TotalPE() == 5 );
1238  BOOST_TEST( FlashVector[3].Time() == 1e6 );
1239  BOOST_TEST( FlashVector[3].TotalPE() == 100 );
1240 
1241 }
1242 
1243 BOOST_AUTO_TEST_CASE(RemoveFlashesFromVectors_IgnoreFirstFlash)
1244 {
1245  size_t NFlashes=4;
1246  size_t BeginFlash=1;
1247 
1248  std::vector<double> PEs(30,0);
1249  PEs.at(0) = 100;
1250  std::vector<double> PEs_Small(30,0);
1251  PEs_Small.at(0) = 5;
1252  std::vector<double> WireCenters(3,0);
1253  std::vector<double> WireWidths(3,0);
1254 
1255  std::vector<recob::OpFlash> FlashVector;
1256  FlashVector.emplace_back(-1e6, //time
1257  0.5, //TimeWidth,
1258  0, //AveAbsTime,
1259  0, //Frame,
1260  PEs,
1261  0, //InBeamFrame,
1262  0, //OnBeamTime,
1263  0, //FastToTotal,
1264  0, //meany,
1265  0, //widthy,
1266  0, //meanz,
1267  0, //widthz,
1268  WireCenters,
1269  WireWidths);
1270  FlashVector.emplace_back(0, //time
1271  0.5, //TimeWidth,
1272  0, //AveAbsTime,
1273  0, //Frame,
1274  PEs,
1275  0, //InBeamFrame,
1276  0, //OnBeamTime,
1277  0, //FastToTotal,
1278  0, //meany,
1279  0, //widthy,
1280  0, //meanz,
1281  0, //widthz,
1282  WireCenters,
1283  WireWidths);
1284  FlashVector.emplace_back(1.6, //time
1285  0.5, //TimeWidth,
1286  0, //AveAbsTime,
1287  0, //Frame,
1288  PEs_Small,
1289  0, //InBeamFrame,
1290  0, //OnBeamTime,
1291  0, //FastToTotal,
1292  0, //meany,
1293  0, //widthy,
1294  0, //meanz,
1295  0, //widthz,
1296  WireCenters,
1297  WireWidths);
1298  FlashVector.emplace_back(1e6, //time
1299  0.5, //TimeWidth,
1300  0, //AveAbsTime,
1301  0, //Frame,
1302  PEs,
1303  0, //InBeamFrame,
1304  0, //OnBeamTime,
1305  0, //FastToTotal,
1306  0, //meany,
1307  0, //widthy,
1308  0, //meanz,
1309  0, //widthz,
1310  WireCenters,
1311  WireWidths);
1312  std::vector<bool> MarkedForRemoval{false, true, false};
1313  std::vector< std::vector<int> > RefinedHitsPerFlash(NFlashes-BeginFlash);
1314  RefinedHitsPerFlash[0].push_back(0);
1315  RefinedHitsPerFlash[1].push_back(1);
1316  RefinedHitsPerFlash[2].push_back(2);
1317 
1318  opdet::RemoveFlashesFromVectors(MarkedForRemoval,
1319  FlashVector,
1320  BeginFlash,
1321  RefinedHitsPerFlash);
1322 
1323  BOOST_TEST( FlashVector.size() == 3U );
1324  BOOST_TEST( FlashVector[0].Time() == -1e6 );
1325  BOOST_TEST( FlashVector[0].TotalPE() == 100 );
1326  BOOST_TEST( FlashVector[1].Time() == 0 );
1327  BOOST_TEST( FlashVector[1].TotalPE() == 100 );
1328  BOOST_TEST( FlashVector[2].Time() == 1e6 );
1329  BOOST_TEST( FlashVector[2].TotalPE() == 100 );
1330 
1331  BOOST_TEST( RefinedHitsPerFlash.size() == 2U );
1332  BOOST_TEST( RefinedHitsPerFlash[0][0] == 0 );
1333  BOOST_TEST( RefinedHitsPerFlash[1][0] == 2 );
1334 
1335 }
1336 
1337 BOOST_AUTO_TEST_CASE(RemoveFlashesFromVectors_NoFlashes)
1338 {
1339  size_t NFlashes=5;
1340  size_t BeginFlash=5; //that is, no new flashes to look at
1341 
1342  std::vector<recob::OpFlash> FlashVector(NFlashes);
1343  std::vector<bool> MarkedForRemoval(NFlashes-BeginFlash,false);
1344  std::vector< std::vector<int> > RefinedHitsPerFlash(NFlashes-BeginFlash);
1345 
1346  opdet::RemoveFlashesFromVectors(MarkedForRemoval,
1347  FlashVector,
1348  BeginFlash,
1349  RefinedHitsPerFlash);
1350 
1351  BOOST_TEST( FlashVector.size() == NFlashes );
1352 
1353 }
1354 
1355 
1356 BOOST_AUTO_TEST_SUITE_END()
void FillHitsThisFlash(std::vector< std::vector< int >> const &Contributors, int const &Bin, std::vector< int > const &HitClaimedByFlash, std::vector< int > &HitsThisFlash)
Definition: OpFlashAlg.cxx:213
void CheckAndStoreFlash(std::vector< std::vector< int >> &RefinedHitsPerFlash, std::vector< int > const &HitsThisRefinedFlash, double const PEAccumulated, float const FlashThreshold, std::vector< bool > &HitsUsed)
Definition: OpFlashAlg.cxx:358
static QCString result
auto const tolerance
void AddHitContribution(recob::OpHit const &currentHit, double &MaxTime, double &MinTime, double &AveTime, double &FastToTotal, double &AveAbsTime, double &TotalPE, std::vector< double > &PEs)
Definition: OpFlashAlg.cxx:455
void FindSeedHit(std::map< double, std::vector< int >, std::greater< double >> const &HitsBySize, std::vector< bool > &HitsUsed, std::vector< recob::OpHit > const &HitVector, std::vector< int > &HitsThisRefinedFlash, double &PEAccumulated, double &FlashMaxTime, double &FlashMinTime)
Definition: OpFlashAlg.cxx:300
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
void MarkFlashesForRemoval(std::vector< recob::OpFlash > const &FlashVector, size_t const BeginFlash, std::vector< bool > &MarkedForRemoval)
Definition: OpFlashAlg.cxx:622
const double e
void ClaimHits(std::vector< recob::OpHit > const &HitVector, std::vector< int > const &HitsThisFlash, float const FlashThreshold, std::vector< std::vector< int >> &HitsPerFlash, std::vector< int > &HitClaimedByFlash)
Definition: OpFlashAlg.cxx:226
constexpr float FlashThreshold
void FillFlashesBySizeMap(std::vector< int > const &FlashesInAccumulator, std::vector< double > const &BinnedPE, int const &Accumulator, std::map< double, std::map< int, std::vector< int >>, std::greater< double >> &FlashesBySize)
Definition: OpFlashAlg.cxx:201
BOOST_AUTO_TEST_CASE(checkGetAccumIndex)
void AddHitToFlash(int const &HitID, std::vector< bool > &HitsUsed, recob::OpHit const &currentHit, double const WidthTolerance, std::vector< int > &HitsThisRefinedFlash, double &PEAccumulated, double &FlashMaxTime, double &FlashMinTime)
Definition: OpFlashAlg.cxx:330
std::vector< reco::ClusterHit2D * > HitVector
What follows are several highly useful typedefs which we want to expose to the outside world...
Index NOpChannels(Index)
unsigned int GetAccumIndex(double const PeakTime, double const MinTime, double const BinWidth, double const BinOffset)
Definition: OpFlashAlg.cxx:171
constexpr double WidthTolerance
void RemoveFlashesFromVectors(std::vector< bool > const &MarkedForRemoval, std::vector< recob::OpFlash > &FlashVector, size_t const BeginFlash, std::vector< std::vector< int >> &RefinedHitsPerFlash)
Definition: OpFlashAlg.cxx:650
void FillAccumulator(unsigned int const &AccumIndex, unsigned int const &HitIndex, double const PE, float const FlashThreshold, std::vector< double > &Binned, std::vector< std::vector< int >> &Contributors, std::vector< int > &FlashesInAccumulator)
Definition: OpFlashAlg.cxx:181
double GetLikelihoodLateLight(double const iPE, double const iTime, double const iWidth, double const jPE, double const jTime, double const jWidth)
Definition: OpFlashAlg.cxx:604