9 #include <gtest/gtest.h>
12 #include <tracking/trackFindingVXD/filterMap/filterFramework/Shortcuts.h>
21 namespace VXDTFfilterTest {
27 spacePoint(
float x,
float y,
float z): tuple<float, float, float>(x, y, z)
40 static const std::string
name(
void) {
return "SquaredDistance3D"; };
46 pow(get<0>(p1) - get<0>(p2) , 2) +
47 pow(get<1>(p1) - get<1>(p2) , 2) +
48 pow(get<2>(p1) - get<2>(p2) , 2) ;
57 static const std::string
name(
void) {
return "SquaredDistance2Dxy"; };
63 pow(get<0>(p1) - get<0>(p2) , 2) +
64 pow(get<1>(p1) - get<1>(p2) , 2) ;
73 static const std::string
name(
void) {
return "SquaredDistance1Dx"; };
79 pow(get<0>(p1) - get<0>(p2) , 2);
88 static const std::string
name(
void) {
return "BooleanVariable"; };
94 get<0>(p1) - get<0>(p2) == 0.;
127 template<
class Var,
typename ... otherTypes>
129 const otherTypes& ...)
148 EXPECT_TRUE(range.contains(0.5));
149 EXPECT_FALSE(range.contains(-1.));
150 EXPECT_FALSE(range.contains(0.));
151 EXPECT_FALSE(range.contains(1.));
152 EXPECT_FALSE(range.contains(2.));
153 EXPECT_EQ(0. , range.getInf());
154 EXPECT_EQ(1. , range.getSup());
162 EXPECT_TRUE(range.contains(0.5));
163 EXPECT_FALSE(range.contains(-1.));
164 EXPECT_TRUE(range.contains(0.));
165 EXPECT_TRUE(range.contains(1.));
166 EXPECT_FALSE(range.contains(2.));
167 EXPECT_EQ(0. , range.getInf());
168 EXPECT_EQ(1. , range.getSup());
177 EXPECT_TRUE(upperBoundedSet.contains(-1.));
178 EXPECT_FALSE(upperBoundedSet.contains(0.));
179 EXPECT_FALSE(upperBoundedSet.contains(1.));
180 EXPECT_EQ(0. , upperBoundedSet.getSup());
188 EXPECT_TRUE(upperBoundedSet.contains(-1.));
189 EXPECT_TRUE(upperBoundedSet.contains(0.));
190 EXPECT_FALSE(upperBoundedSet.contains(1.));
191 EXPECT_EQ(0. , upperBoundedSet.getSup());
200 EXPECT_TRUE(lowerBoundedSet.contains(1.));
201 EXPECT_FALSE(lowerBoundedSet.contains(0.));
202 EXPECT_FALSE(lowerBoundedSet.contains(-1.));
203 EXPECT_EQ(0. , lowerBoundedSet.getInf());
211 EXPECT_TRUE(lowerBoundedSet.contains(1.));
212 EXPECT_TRUE(lowerBoundedSet.contains(0.));
213 EXPECT_FALSE(lowerBoundedSet.contains(-1.));
214 EXPECT_EQ(0. , lowerBoundedSet.getInf());
219 TEST_F(FilterTest, SelectionVariableName)
222 EXPECT_EQ(
"SquaredDistance3D" , SquaredDistance3D().name());
227 TEST_F(FilterTest, BasicFilter)
232 spacePoint x1(0.0f , 0.0f, 0.0f);
233 spacePoint x2(0.5f , 0.0f, 0.0f);
234 spacePoint x3(2.0f , 0.0f, 0.0f);
236 EXPECT_TRUE(
filter.accept(x1, x2));
237 EXPECT_FALSE(
filter.accept(x1, x3));
243 TEST_F(FilterTest, ObservedFilter)
249 spacePoint x1(0.0f , 0.0f, 0.0f);
250 spacePoint x2(0.5f , 0.0f, 0.0f);
251 spacePoint x3(2.0f , 0.0f, 0.0f);
252 counter< SquaredDistance3D >::N = 0;
254 EXPECT_TRUE(
filter.accept(x1, x2));
255 EXPECT_FALSE(
filter.accept(x1, x3));
256 EXPECT_EQ(2 , counter< SquaredDistance3D >::N);
260 TEST_F(FilterTest, SwitchingObservers)
263 auto dummyFilter = ((-10. <= SquaredDistance3D() <= 10.) &&
264 ((-100. <= SquaredDistance2Dxy() <= -10.) ||
265 (-10. <= SquaredDistance1Dx() <= 10.)) &&
266 !(-10. <= SquaredDistance1Dx() <= -10.));
270 spacePoint x1(0.0f , 0.0f, 0.0f);
271 spacePoint x2(0.5f , 0.0f, 0.0f);
272 spacePoint x3(2.0f , 0.0f, 0.0f);
274 counter< SquaredDistance3D >::N = 0;
275 counter< SquaredDistance1Dx >::N = 0;
276 counter< SquaredDistance2Dxy >::N = 0;
278 dummyFilter.accept(x1, x2);
279 dummyFilter.accept(x1, x3);
282 EXPECT_EQ(0 , counter< SquaredDistance3D >::N);
283 EXPECT_EQ(0 , counter< SquaredDistance2Dxy >::N);
284 EXPECT_EQ(0 , counter< SquaredDistance1Dx >::N);
289 auto observedDummyFilter = dummyFilter.observe(
Observer());
290 observedDummyFilter.accept(x1, x2);
291 observedDummyFilter.accept(x1, x3);
293 EXPECT_EQ(2 , counter< SquaredDistance3D >::N);
294 EXPECT_EQ(2 , counter< SquaredDistance2Dxy >::N);
296 EXPECT_EQ(4 , counter< SquaredDistance1Dx >::N);
301 TEST_F(FilterTest, BypassableFilter)
303 bool bypassControl(
false);
306 auto filter = nonBypassableFilter.bypass(bypassControl);
307 spacePoint x1(0.0f , 0.0f, 0.0f);
308 spacePoint x2(2.0f , 0.0f, 0.0f);
309 counter< SquaredDistance3D >::N = 0;
311 EXPECT_FALSE(
filter.accept(x1, x2));
312 EXPECT_EQ(1 , counter< SquaredDistance3D >::N);
314 bypassControl =
true;
315 EXPECT_TRUE(
filter.accept(x1, x2));
316 EXPECT_EQ(2 , counter< SquaredDistance3D >::N);
322 TEST_F(FilterTest, Shortcuts)
325 spacePoint x1(0.0f , 0.0f, 0.0f);
326 spacePoint x2(0.5f , 0.0f, 0.0f);
327 spacePoint x3(2.0f , 0.0f, 0.0f);
328 spacePoint x4(1.0f , 0.0f, 0.0f);
330 auto filterSup = (SquaredDistance3D() < 1.) ;
331 EXPECT_TRUE(filterSup.accept(x1, x2));
332 EXPECT_FALSE(filterSup.accept(x1, x4));
333 EXPECT_FALSE(filterSup.accept(x1, x3));
335 auto filterMax = (SquaredDistance3D() <= 1.) ;
336 EXPECT_TRUE(filterMax.accept(x1, x2));
337 EXPECT_TRUE(filterMax.accept(x1, x4));
338 EXPECT_FALSE(filterMax.accept(x1, x3));
341 auto filterSup2 = (1 > SquaredDistance3D()) ;
342 EXPECT_TRUE(filterSup2.accept(x1, x2));
343 EXPECT_FALSE(filterSup2.accept(x1, x3));
344 EXPECT_FALSE(filterSup2.accept(x1, x4));
346 auto filterMax2 = (1 >= SquaredDistance3D()) ;
347 EXPECT_TRUE(filterMax2.accept(x1, x2));
348 EXPECT_FALSE(filterMax2.accept(x1, x3));
349 EXPECT_TRUE(filterMax2.accept(x1, x4));
351 auto filterInf = (SquaredDistance3D() > 1.) ;
352 EXPECT_TRUE(filterInf.accept(x1, x3));
353 EXPECT_FALSE(filterInf.accept(x1, x2));
354 EXPECT_FALSE(filterInf.accept(x1, x4));
356 auto filterMin = (SquaredDistance3D() >= 1.) ;
357 EXPECT_TRUE(filterMin.accept(x1, x3));
358 EXPECT_FALSE(filterMin.accept(x1, x2));
359 EXPECT_TRUE(filterMin.accept(x1, x4));
361 auto filterInf2 = (1 < SquaredDistance3D()) ;
362 EXPECT_TRUE(filterInf2.accept(x1, x3));
363 EXPECT_FALSE(filterInf2.accept(x1, x2));
364 EXPECT_FALSE(filterInf2.accept(x1, x4));
366 auto filterMin2 = (1 <= SquaredDistance3D()) ;
367 EXPECT_TRUE(filterMin2.accept(x1, x3));
368 EXPECT_FALSE(filterMin2.accept(x1, x2));
369 EXPECT_TRUE(filterMin2.accept(x1, x4));
371 auto filterRange = (0. < SquaredDistance3D() < 1);
372 EXPECT_FALSE(filterRange.accept(x1, x1));
373 EXPECT_TRUE(filterRange.accept(x1, x2));
374 EXPECT_FALSE(filterRange.accept(x1, x3));
375 EXPECT_FALSE(filterRange.accept(x1, x4));
378 auto filterClosedRange = (0. <= SquaredDistance3D() <= 1);
379 EXPECT_TRUE(filterClosedRange.accept(x1, x1));
380 EXPECT_TRUE(filterClosedRange.accept(x1, x2));
381 EXPECT_FALSE(filterClosedRange.accept(x1, x3));
382 EXPECT_TRUE(filterClosedRange.accept(x1, x4));
388 TEST_F(FilterTest, BooleanOperations)
392 spacePoint x1(0.0f , 0.0f, 0.0f);
393 spacePoint x2(1.0f , 0.0f, 0.0f);
394 spacePoint x3(2.0f , 0.0f, 0.0f);
396 auto filter = !(SquaredDistance3D() > 1.);
397 EXPECT_TRUE(
filter.accept(x1, x2));
398 EXPECT_TRUE(
filter.accept(x1, x1));
399 EXPECT_FALSE(
filter.accept(x1, x3));
402 !(SquaredDistance3D() > 1.) &&
403 !(SquaredDistance3D() < 1);
405 EXPECT_TRUE(filter2.accept(x1, x2));
406 EXPECT_FALSE(filter2.accept(x1, x1));
407 EXPECT_FALSE(filter2.accept(x1, x3));
411 (SquaredDistance3D() > 1.) ||
412 (SquaredDistance3D() < 1);
414 EXPECT_FALSE(filter3.accept(x1, x2));
415 EXPECT_TRUE(filter3.accept(x1, x1));
416 EXPECT_TRUE(filter3.accept(x1, x3));
423 TEST_F(FilterTest, ShortCircuitsEvaluation)
426 (SquaredDistance2Dxy() < 1).observeLeaf(
Observer()) &&
427 (SquaredDistance3D() < 1).observeLeaf(
Observer())
430 spacePoint x1(0.0f , 0.0f, 0.0f);
431 spacePoint x3(2.0f , 0.0f, 0.0f);
433 counter< SquaredDistance3D >::N = 0;
434 counter< SquaredDistance2Dxy >::N = 0;
436 EXPECT_FALSE(
filter.accept(x1, x3));
439 EXPECT_EQ(1 , counter< SquaredDistance2Dxy >::N);
441 EXPECT_EQ(0 , counter< SquaredDistance3D >::N);
443 EXPECT_TRUE(
filter.accept(x1, x1));
445 EXPECT_EQ(2 , counter< SquaredDistance2Dxy >::N);
447 EXPECT_EQ(1 , counter< SquaredDistance3D >::N);
453 TEST_F(FilterTest, BooleanVariableShortcuts)
455 auto filter1(BooleanVariable() ==
true);
456 auto filter2(
false == BooleanVariable());
457 spacePoint x1(0.0f , 0.0f, 0.0f);
458 spacePoint x2(1.0f , 0.0f, 0.0f);
460 EXPECT_TRUE(filter1.accept(x1, x1));
461 EXPECT_FALSE(filter1.accept(x1, x2));
464 EXPECT_FALSE(filter2.accept(x1, x1));
465 EXPECT_TRUE(filter2.accept(x1, x2));
Represents a closed lower bounded set of arithmetic types.
Represents a closed set of arithmetic types.
Represents an upper bounded set of arithmetic types.
This class is used to select pairs, triplets...
Represents a lower bounded set of arithmetic types.
Observer base class which can be used to evaluate the VXDTF2's Filters.
Represents a range of arithmetic types.
Base class of the selection variable objects used for pair filtering.
Represents an upper bounded set of arithmetic types.
The most CPU efficient Observer for the VXDTF filter tools (even if useless).
a small filter illustrating the behavior of a filter which is compatible with boolean comparisons
static float value(const spacePoint &p1, const spacePoint &p2)
value function does the actual calculation of this class.
static const std::string name(void)
return name of the class
Test class for Filter object.
this observer does simply count the number of times, the attached Filter was used
static void notify(const Var &, const otherTypes &...)
notify function is called by the filter, this one increases the counter.
a small filter illustrating the behavior of a distance1D-filter in X
static float value(const spacePoint &p1, const spacePoint &p2)
value function does the actual calculation of this class.
static const std::string name(void)
return name of the class
a small filter illustrating the behavior of a distance2D-filter in XY
static float value(const spacePoint &p1, const spacePoint &p2)
value function does the actual calculation of this class.
static const std::string name(void)
return name of the class
a small filter illustrating the behavior of a distance3D-filter
static float value(const spacePoint &p1, const spacePoint &p2)
value function does the actual calculation of this class.
static const std::string name(void)
return name of the class
small class counting usage.
just a small proto-container storing coordinates
spacePoint(const spacePoint &)=delete
private copy constructor to test that all the arguments are passed by reference.
spacePoint(float x, float y, float z)
Constructor accepting coordinates.
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
std::map< ExpRun, std::pair< double, double > > filter(const std::map< ExpRun, std::pair< double, double >> &runs, double cut, std::map< ExpRun, std::pair< double, double >> &runsRemoved)
filter events to remove runs shorter than cut, it stores removed runs in runsRemoved
Abstract base class for different kinds of events.