9#include <gtest/gtest.h>
12#include <tracking/trackFindingVXD/filterMap/filterFramework/Shortcuts.h>
21namespace 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);
254 EXPECT_TRUE(
filter.accept(x1, x2));
255 EXPECT_FALSE(
filter.accept(x1, x3));
260 TEST_F(FilterTest, SwitchingObservers)
263 auto dummyFilter = ((-10. <= SquaredDistance3D() <= 10.) &&
264 ((-100. <= SquaredDistance2Dxy() <= -10.) ||
265 (-10. <= SquaredDistance1Dx() <= 10.)) &&
267 !(-10. <= SquaredDistance1Dx() <= -10.));
271 spacePoint x1(0.0f, 0.0f, 0.0f);
272 spacePoint x2(0.5f, 0.0f, 0.0f);
273 spacePoint x3(2.0f, 0.0f, 0.0f);
279 dummyFilter.accept(x1, x2);
280 dummyFilter.accept(x1, x3);
290 auto observedDummyFilter = dummyFilter.observe(
Observer());
291 observedDummyFilter.accept(x1, x2);
292 observedDummyFilter.accept(x1, x3);
302 TEST_F(FilterTest, BypassableFilter)
304 bool bypassControl(
false);
307 auto filter = nonBypassableFilter.bypass(bypassControl);
308 spacePoint x1(0.0f, 0.0f, 0.0f);
309 spacePoint x2(2.0f, 0.0f, 0.0f);
312 EXPECT_FALSE(
filter.accept(x1, x2));
319#ifndef __clang_analyzer__
320 bypassControl =
true;
322 EXPECT_TRUE(
filter.accept(x1, x2));
329 TEST_F(FilterTest, Shortcuts)
332 spacePoint x1(0.0f, 0.0f, 0.0f);
333 spacePoint x2(0.5f, 0.0f, 0.0f);
334 spacePoint x3(2.0f, 0.0f, 0.0f);
335 spacePoint x4(1.0f, 0.0f, 0.0f);
337 auto filterSup = (SquaredDistance3D() < 1.) ;
338 EXPECT_TRUE(filterSup.accept(x1, x2));
339 EXPECT_FALSE(filterSup.accept(x1, x4));
340 EXPECT_FALSE(filterSup.accept(x1, x3));
342 auto filterMax = (SquaredDistance3D() <= 1.) ;
343 EXPECT_TRUE(filterMax.accept(x1, x2));
344 EXPECT_TRUE(filterMax.accept(x1, x4));
345 EXPECT_FALSE(filterMax.accept(x1, x3));
348 auto filterSup2 = (1 > SquaredDistance3D()) ;
349 EXPECT_TRUE(filterSup2.accept(x1, x2));
350 EXPECT_FALSE(filterSup2.accept(x1, x3));
351 EXPECT_FALSE(filterSup2.accept(x1, x4));
353 auto filterMax2 = (1 >= SquaredDistance3D()) ;
354 EXPECT_TRUE(filterMax2.accept(x1, x2));
355 EXPECT_FALSE(filterMax2.accept(x1, x3));
356 EXPECT_TRUE(filterMax2.accept(x1, x4));
358 auto filterInf = (SquaredDistance3D() > 1.) ;
359 EXPECT_TRUE(filterInf.accept(x1, x3));
360 EXPECT_FALSE(filterInf.accept(x1, x2));
361 EXPECT_FALSE(filterInf.accept(x1, x4));
363 auto filterMin = (SquaredDistance3D() >= 1.) ;
364 EXPECT_TRUE(filterMin.accept(x1, x3));
365 EXPECT_FALSE(filterMin.accept(x1, x2));
366 EXPECT_TRUE(filterMin.accept(x1, x4));
368 auto filterInf2 = (1 < SquaredDistance3D()) ;
369 EXPECT_TRUE(filterInf2.accept(x1, x3));
370 EXPECT_FALSE(filterInf2.accept(x1, x2));
371 EXPECT_FALSE(filterInf2.accept(x1, x4));
373 auto filterMin2 = (1 <= SquaredDistance3D()) ;
374 EXPECT_TRUE(filterMin2.accept(x1, x3));
375 EXPECT_FALSE(filterMin2.accept(x1, x2));
376 EXPECT_TRUE(filterMin2.accept(x1, x4));
378 auto filterRange = (0. < SquaredDistance3D() < 1);
379 EXPECT_FALSE(filterRange.accept(x1, x1));
380 EXPECT_TRUE(filterRange.accept(x1, x2));
381 EXPECT_FALSE(filterRange.accept(x1, x3));
382 EXPECT_FALSE(filterRange.accept(x1, x4));
385 auto filterClosedRange = (0. <= SquaredDistance3D() <= 1);
386 EXPECT_TRUE(filterClosedRange.accept(x1, x1));
387 EXPECT_TRUE(filterClosedRange.accept(x1, x2));
388 EXPECT_FALSE(filterClosedRange.accept(x1, x3));
389 EXPECT_TRUE(filterClosedRange.accept(x1, x4));
395 TEST_F(FilterTest, BooleanOperations)
399 spacePoint x1(0.0f, 0.0f, 0.0f);
400 spacePoint x2(1.0f, 0.0f, 0.0f);
401 spacePoint x3(2.0f, 0.0f, 0.0f);
403 auto filter = !(SquaredDistance3D() > 1.);
404 EXPECT_TRUE(
filter.accept(x1, x2));
405 EXPECT_TRUE(
filter.accept(x1, x1));
406 EXPECT_FALSE(
filter.accept(x1, x3));
409 !(SquaredDistance3D() > 1.) &&
410 !(SquaredDistance3D() < 1);
412 EXPECT_TRUE(filter2.accept(x1, x2));
413 EXPECT_FALSE(filter2.accept(x1, x1));
414 EXPECT_FALSE(filter2.accept(x1, x3));
418 (SquaredDistance3D() > 1.) ||
419 (SquaredDistance3D() < 1);
421 EXPECT_FALSE(filter3.accept(x1, x2));
422 EXPECT_TRUE(filter3.accept(x1, x1));
423 EXPECT_TRUE(filter3.accept(x1, x3));
430 TEST_F(FilterTest, ShortCircuitsEvaluation)
433 (SquaredDistance2Dxy() < 1).observeLeaf(
Observer()) &&
434 (SquaredDistance3D() < 1).observeLeaf(
Observer())
437 spacePoint x1(0.0f, 0.0f, 0.0f);
438 spacePoint x3(2.0f, 0.0f, 0.0f);
443 EXPECT_FALSE(
filter.accept(x1, x3));
450 EXPECT_TRUE(
filter.accept(x1, x1));
460 TEST_F(FilterTest, BooleanVariableShortcuts)
462 auto filter1(BooleanVariable() ==
true);
463 auto filter2(
false == BooleanVariable());
464 spacePoint x1(0.0f, 0.0f, 0.0f);
465 spacePoint x2(1.0f, 0.0f, 0.0f);
467 EXPECT_TRUE(filter1.accept(x1, x1));
468 EXPECT_FALSE(filter1.accept(x1, x2));
471 EXPECT_FALSE(filter2.accept(x1, x1));
472 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... of objects.
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.
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.