9#include <gtest/gtest.h>
11#include <tracking/spacePointCreation/SpacePoint.h>
12#include <tracking/trackFindingVXD/filterMap/twoHitVariables/Distance3DSquared.h>
13#include <tracking/trackFindingVXD/filterMap/twoHitVariables/Distance2DXYSquared.h>
14#include <tracking/trackFindingVXD/filterMap/twoHitVariables/Distance1DZ.h>
15#include <tracking/trackFindingVXD/filterMap/twoHitVariables/SlopeRZ.h>
16#include <tracking/trackFindingVXD/filterMap/twoHitVariables/CosDirectionXY.h>
17#include <tracking/trackFindingVXD/filterMap/twoHitVariables/Distance3DNormed.h>
19#include <tracking/trackFindingVXD/filterMap/filterFramework/Shortcuts.h>
21#include <vxd/geometry/SensorInfoBase.h>
31namespace VXDTFtwoHitFilterTest {
46 r1.SetAngles(45, 20, 30);
47 TGeoTranslation t1(globalX, globalY, globalZ);
48 TGeoCombiTrans c1(t1, r1);
49 TGeoHMatrix transform = c1;
50 sensorInfoBase.setTransformation(transform);
52 sensorInfoBase.setTransformation(transform,
true);
54 return sensorInfoBase;
59 SpacePoint provideSpacePointDummy(
double X,
double Y,
double Z)
64 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
111 template<
class Var,
typename ... otherTypes>
127 template<
class Var,
class Range,
typename ... otherTypes>
129 static void notify(
const Var& filterType,
130 typename Var::variableType fResult,
132 const typename Var::argumentType&
outerHit,
133 const typename Var::argumentType& innerHit,
136 B2ERROR(
" Filter " << filterType.name() <<
" got result of " << fResult);
149 template<
class Var,
class Range,
typename ... otherTypes>
150 static void notify(
const Var& filterType,
151 typename Var::variableType fResult,
153 const typename Var::argumentType&
outerHit,
154 const typename Var::argumentType& innerHit,
157 B2WARNING(
" Filter " << filterType.name() <<
" with outerhit/innerhit: " <<
outerHit.getPosition().
PrintStringXYZ() <<
"/" <<
158 innerHit.getPosition().PrintStringXYZ() <<
" got result of " << fResult);
171 typedef std::function< void (
const typename FilterType::argumentType&,
const typename FilterType::argumentType&,
const FilterType&,
typename FilterType::variableType)>
175 using CStyleFunctionPointer = void(*)(
const typename FilterType::argumentType&,
const typename FilterType::argumentType&,
176 const FilterType&,
typename FilterType::variableType) ;
179 template<
typename ... otherTypes>
180 static void notify(
const FilterType& filterType,
181 typename FilterType::variableType fResult,
182 const typename FilterType::argumentType&
outerHit,
183 const typename FilterType::argumentType& innerHit,
186 B2INFO(
" Filter " << filterType.name() <<
" with Mag of outer-/innerHit " <<
outerHit.getPosition().
Mag() <<
"/" <<
187 innerHit.getPosition().Mag() <<
" got result of " << fResult <<
" and Observer-Vector sm_collectedObservers got " <<
189 B2INFO(
" Filter " << filterType.name() <<
" with Mag of outer-/innerHit " <<
outerHit.getPosition().
Mag() <<
"/" <<
190 innerHit.getPosition().Mag() <<
" got result of " << fResult <<
" and Observer-Vector sm_collectedObserversCSTYLE got " <<
202 template <
typename ObserverType>
206 FilterType(), std::placeholders::_3));
220 template<
typename FilterType> std::vector< typename VectorOfObservers<FilterType>::observerFunction >
223 template<
typename FilterType> std::vector< typename VectorOfObservers<FilterType>::CStyleFunctionPointer >
231 TEST_F(TwoHitFilterTest, TestObserverFlexibility)
239 SpacePoint x1 = provideSpacePointDummy(0.0f, 0.0f, 0.0f);
240 SpacePoint x2 = provideSpacePointDummy(0.5f, 0.0f, 0.0f);
241 SpacePoint x3 = provideSpacePointDummy(2.0f, 0.0f, 0.0f);
242 auto myCounter = counter<Distance3DSquared<SpacePoint>>();
243 myCounter.resetCounter();
250 auto storeFuncVariantB = std::bind(((VectorOfObservers<Distance3DSquared<SpacePoint>>::CStyleFunctionPointer)
252 std::placeholders::_3);
254 char* realname(
nullptr);
256 realname = abi::__cxa_demangle(
typeid(storeFuncVariantB).name(), 0, 0, &status);
257 std::string name(realname);
259 B2INFO(
"storeFuncVariantB is of type: " << name);
274 EXPECT_EQ(0, myCounter.used);
281 TEST_F(TwoHitFilterTest, SpacePointCreation)
283 SpacePoint testSP = provideSpacePointDummy(1.2, 2.3, 4.2);
292 TEST_F(TwoHitFilterTest, SelectionVariableName)
294 auto dist3D = Distance3DSquared<SpacePoint>();
295 EXPECT_EQ(
"Distance3DSquared", dist3D.name());
296 auto dist2DXY = Distance2DXYSquared<SpacePoint>();
297 EXPECT_EQ(
"Distance2DXYSquared", dist2DXY.name());
298 auto dist1DZ = Distance1DZ<SpacePoint>();
299 EXPECT_EQ(
"Distance1DZ", dist1DZ.name());
300 auto slopeRZ = SlopeRZ<SpacePoint>();
301 EXPECT_EQ(
"SlopeRZ", slopeRZ.name());
307 TEST_F(TwoHitFilterTest, BasicFilterTestDistance3DSquared)
312 SpacePoint x1 = provideSpacePointDummy(0., 0., 0.);
313 SpacePoint x2 = provideSpacePointDummy(.5, 0., 0.);
314 SpacePoint x3 = provideSpacePointDummy(2., 0., 0.);
316 EXPECT_TRUE(
filter.accept(x1, x2));
317 EXPECT_FALSE(
filter.accept(x1, x3));
323 TEST_F(TwoHitFilterTest, BasicFilterTestDistance2DXYSquared)
328 SpacePoint x1 = provideSpacePointDummy(0., 0., 0.);
329 SpacePoint x2 = provideSpacePointDummy(.5, 0., 0.);
330 SpacePoint x3 = provideSpacePointDummy(2., 0., 0.);
331 SpacePoint x4 = provideSpacePointDummy(0., 0., 2.);
333 EXPECT_TRUE(
filter.accept(x1, x2));
334 EXPECT_FALSE(
filter.accept(x1, x3));
335 EXPECT_TRUE(
filter.accept(x2, x4));
341 TEST_F(TwoHitFilterTest, BasicFilterTestDistance1DZ)
346 SpacePoint x1 = provideSpacePointDummy(0., 0., 0.);
347 SpacePoint x2 = provideSpacePointDummy(0., 0., .5);
348 SpacePoint x3 = provideSpacePointDummy(.25, .25, 0.);
349 SpacePoint x4 = provideSpacePointDummy(0., 0., 1.);
351 EXPECT_TRUE(
filter.accept(x2, x1));
352 EXPECT_FALSE(
filter.accept(x1, x2));
353 EXPECT_FALSE(
filter.accept(x1, x3));
354 EXPECT_FALSE(
filter.accept(x1, x4));
360 TEST_F(TwoHitFilterTest, TemplateFilterTestDistance1DZ)
365 SpacePoint x1 = provideSpacePointDummy(0., 0., 0.);
366 SpacePoint x2 = provideSpacePointDummy(0., 0., .5);
367 SpacePoint x3 = provideSpacePointDummy(.25, .25, 0.);
368 SpacePoint x4 = provideSpacePointDummy(0., 0., 1.);
370 EXPECT_TRUE(
filter.accept(x2, x1));
371 EXPECT_FALSE(
filter.accept(x1, x2));
372 EXPECT_FALSE(
filter.accept(x1, x3));
373 EXPECT_FALSE(
filter.accept(x1, x4));
379 TEST_F(TwoHitFilterTest, BasicFilterTestSlopeRZ)
384 SpacePoint innerSP = provideSpacePointDummy(1, 2, 3);
385 SpacePoint outerSP1 = provideSpacePointDummy(1, 4, 4);
386 SpacePoint outerSP2 = provideSpacePointDummy(1, 4, 3.95);
387 SpacePoint outerSP3 = provideSpacePointDummy(1, 4, 4.05);
388 SpacePoint outerSP4 = provideSpacePointDummy(1, 3, 3.45);
389 SpacePoint outerSP5 = provideSpacePointDummy(1, 3, 3.55);
390 SpacePoint outerSP6 = provideSpacePointDummy(1, 4, 3);
391 SpacePoint outerSP7 = provideSpacePointDummy(1, 0, 4);
393 EXPECT_FALSE(
filter.accept(outerSP3, innerSP));
394 EXPECT_FALSE(
filter.accept(outerSP1, innerSP));
395 EXPECT_TRUE(
filter.accept(outerSP2, innerSP));
396 EXPECT_FALSE(
filter.accept(innerSP, outerSP2));
397 EXPECT_TRUE(
filter.accept(outerSP4, innerSP));
398 EXPECT_FALSE(
filter.accept(outerSP5, innerSP));
399 EXPECT_EQ(
filter.accept(outerSP1, innerSP),
filter.accept(outerSP7,
403 auto sRZ = SlopeRZ<SpacePoint>();
404 EXPECT_FLOAT_EQ(0., sRZ.value(innerSP, innerSP));
405 EXPECT_FLOAT_EQ(
atan(2.), sRZ.value(outerSP1, innerSP));
406 EXPECT_FLOAT_EQ(
atan(2. / 0.95), sRZ.value(outerSP2, innerSP));
407 EXPECT_FLOAT_EQ(M_PI - sRZ.value(outerSP2, innerSP),
408 sRZ.value(innerSP, outerSP2));
409 EXPECT_FLOAT_EQ(
atan(2. / 1.05), sRZ.value(outerSP3, innerSP));
410 EXPECT_FLOAT_EQ(
atan(1. / 0.45), sRZ.value(outerSP4, innerSP));
411 EXPECT_FLOAT_EQ(
atan(1. / 0.55), sRZ.value(outerSP5, innerSP));
412 EXPECT_FLOAT_EQ(M_PI * 0.5, sRZ.value(outerSP6, innerSP));
413 EXPECT_FLOAT_EQ(
atan(2. / 1.05), sRZ.value(outerSP3, innerSP));
414 EXPECT_FLOAT_EQ(sRZ.value(outerSP1, innerSP), sRZ.value(outerSP7,
421 TEST_F(TwoHitFilterTest, BasicFilterTestDistance3DNormed)
424 SpacePoint innerSP = provideSpacePointDummy(1, 2, 3);
425 SpacePoint outerSP1 = provideSpacePointDummy(2, 3, 4);
426 SpacePoint outerSP2 = provideSpacePointDummy(1, 2, 4);
427 SpacePoint outerSP3 = provideSpacePointDummy(2, 3, 3);
429 auto d3Dn = Distance3DNormed<SpacePoint>();
430 EXPECT_FLOAT_EQ(2. / 3., d3Dn.value(outerSP1, innerSP));
431 EXPECT_FLOAT_EQ(0., d3Dn.value(outerSP2, innerSP));
432 EXPECT_FLOAT_EQ(1., d3Dn.value(outerSP3, innerSP));
433 EXPECT_FLOAT_EQ(0., d3Dn.value(innerSP, innerSP));
439 TEST_F(TwoHitFilterTest, ObservedFilter)
446 SpacePoint x1 = provideSpacePointDummy(0.0f, 0.0f, 0.0f);
447 SpacePoint x2 = provideSpacePointDummy(0.5f, 0.0f, 0.0f);
448 SpacePoint x3 = provideSpacePointDummy(2.0f, 0.0f, 0.0f);
449 auto myCounter = counter<Distance3DSquared<SpacePoint>>();
450 myCounter.resetCounter();
452 EXPECT_TRUE(
filter.accept(x1, x2));
453 EXPECT_FALSE(
filter.accept(x1, x3));
454 EXPECT_EQ(2, myCounter.used);
459 TEST_F(TwoHitFilterTest, BypassableFilter)
461 bool bypassControl(
false);
465 auto filter = nonBypassableFilter.bypass(bypassControl);
466 SpacePoint x1 = provideSpacePointDummy(0.0f, 0.0f, 0.0f);
467 SpacePoint x2 = provideSpacePointDummy(2.0f, 0.0f, 0.0f);
468 auto myCounter = counter<Distance3DSquared<SpacePoint>>();
469 myCounter.resetCounter();
471 EXPECT_FALSE(
filter.accept(x1, x2));
472 EXPECT_EQ(1, myCounter.used);
478#ifndef __clang_analyzer__
479 bypassControl =
true;
481 EXPECT_TRUE(
filter.accept(x1, x2));
482 EXPECT_EQ(2, myCounter.used);
488 TEST_F(TwoHitFilterTest, Shortcuts)
491 SpacePoint x1 = provideSpacePointDummy(0.0f, 0.0f, 0.0f);
492 SpacePoint x2 = provideSpacePointDummy(0.5f, 0.0f, 0.0f);
493 SpacePoint x3 = provideSpacePointDummy(2.0f, 0.0f, 0.0f);
495 auto filterSup = (Distance3DSquared<SpacePoint>() < 1.) ;
496 EXPECT_TRUE(filterSup.accept(x1, x2));
497 EXPECT_FALSE(filterSup.accept(x1, x3));
499 auto filterSup2 = (1 > Distance3DSquared<SpacePoint>()) ;
500 EXPECT_TRUE(filterSup2.accept(x1, x2));
501 EXPECT_FALSE(filterSup2.accept(x1, x3));
503 auto filterInf = (Distance3DSquared<SpacePoint>() > 1.) ;
504 EXPECT_TRUE(filterInf.accept(x1, x3));
505 EXPECT_FALSE(filterInf.accept(x1, x2));
507 auto filterInf2 = (1 < Distance3DSquared<SpacePoint>()) ;
508 EXPECT_TRUE(filterInf2.accept(x1, x3));
509 EXPECT_FALSE(filterInf2.accept(x1, x2));
511 auto filterRange = (0.1 < Distance3DSquared<SpacePoint>() < 1);
512 EXPECT_FALSE(filterRange.accept(x1, x1));
513 EXPECT_TRUE(filterRange.accept(x1, x2));
514 EXPECT_FALSE(filterRange.accept(x1, x3));
520 TEST_F(TwoHitFilterTest, BooleanOperations)
523 SpacePoint x1 = provideSpacePointDummy(0.0f, 0.0f, 0.0f);
524 SpacePoint x2 = provideSpacePointDummy(1.0f, 0.0f, 0.0f);
525 SpacePoint x3 = provideSpacePointDummy(2.0f, 0.0f, 0.0f);
527 auto filter = !(Distance3DSquared<SpacePoint>() > 1.);
528 EXPECT_TRUE(
filter.accept(x1, x2));
529 EXPECT_TRUE(
filter.accept(x1, x1));
530 EXPECT_FALSE(
filter.accept(x1, x3));
533 !(Distance3DSquared<SpacePoint>() > 1.) &&
534 !(Distance3DSquared<SpacePoint>() < 1);
536 EXPECT_TRUE(filter2.accept(x1, x2));
537 EXPECT_FALSE(filter2.accept(x1, x1));
538 EXPECT_FALSE(filter2.accept(x1, x3));
542 (Distance3DSquared<SpacePoint>() > 1.) ||
543 (Distance3DSquared<SpacePoint>() < 1);
545 EXPECT_FALSE(filter3.accept(x1, x2));
546 EXPECT_TRUE(filter3.accept(x1, x1));
547 EXPECT_TRUE(filter3.accept(x1, x3));
553 TEST_F(TwoHitFilterTest, ShortCircuitsEvaluation)
556 ((Distance2DXYSquared<SpacePoint>() < 1) &&
557 (Distance3DSquared<SpacePoint>() < 1)).observe(CountingObserver())
560 SpacePoint x1 = provideSpacePointDummy(0.0f, 0.0f, 0.0f);
561 SpacePoint x3 = provideSpacePointDummy(2.0f, 0.0f, 0.0f);
563 auto counter3D = counter<Distance3DSquared<SpacePoint>>();
564 auto counter2D = counter<Distance2DXYSquared<SpacePoint>>();
568 EXPECT_FALSE(
filter.accept(x1, x3));
569 EXPECT_EQ(1, counter2D.used);
570 EXPECT_EQ(0, counter3D.used);
572 EXPECT_TRUE(
filter.accept(x1, x1));
573 EXPECT_EQ(2, counter2D.used);
574 EXPECT_EQ(1, counter3D.used);
579 TEST_F(TwoHitFilterTest, TestCosDirectionXY)
581 SpacePoint x1 = provideSpacePointDummy(2.0f, 1.0f, 0.0f);
582 SpacePoint x2 = provideSpacePointDummy(1.0f, -2.0f, 0.0f);
583 SpacePoint x3 = provideSpacePointDummy(1.0f, 0.0f, 0.0f);
584 SpacePoint x4 = provideSpacePointDummy(0.5f, 0.86602540378443f, 0.0f);
586 EXPECT_FLOAT_EQ(0., CosDirectionXY<SpacePoint>::value(x1, x2));
587 EXPECT_NEAR(0.5, CosDirectionXY<SpacePoint>::value(x3, x4), 0.0000001);
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
std::string PrintStringXYZ(unsigned precision=4) const
create a string containing vector in cartesian coordinates
DataType Y() const
access variable Y (= .at(1) without boundary check)
DataType Mag() const
The magnitude (rho in spherical coordinate system).
This class is used to select pairs, triplets... of objects.
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Represents a range of arithmetic types.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
const B2Vector3D & getPosition() const
return the position vector in global coordinates
Base class to provide Sensor Information for PXD and SVD.
The most CPU efficient Observer for the VXDTF filter tools (even if useless).
Class to uniquely identify a any structure of the PXD and SVD.
this observer does simply count the number of times, the attached Filter was used
static void notify(const Var &, otherTypes ...)
notifier counting how often a SelectionVariable was used
this observer does simply print the name of the SelectionVariable and the result of its value-functio...
static void notify(const Var &filterType, typename Var::variableType fResult, const Range &range, const typename Var::argumentType &outerHit, const typename Var::argumentType &innerHit, otherTypes ...)
notifier: print the name of the SelectionVariable and the result of its value-function as an Error.
this observer does simply print the name of the SelectionVariable and the result of its value-functio...
static void notify(const Var &filterType, typename Var::variableType fResult, const Range &, const typename Var::argumentType &outerHit, const typename Var::argumentType &innerHit, otherTypes ...)
notifier: print the name of the SelectionVariable and the result of its value-function as a Warning.
Test class for these new and shiny two-hit-filters.
this observer does simply collect other observers which are to be executed during the call of the cor...
static std::vector< observerFunction > sm_collectedObservers
collects observers with std::function to be executed during notify (variant A)
static std::vector< CStyleFunctionPointer > sm_collectedObserversCSTYLE
collects observers with c-style function pointers to be executed during notify (variant B)
static void addObserver(observerFunction newObserver)
collects observers to be executed during notify (can not be used so far, but is long-term goal)
std::function< void(const typename FilterType::argumentType &, const typename FilterType::argumentType &, const FilterType &, typename FilterType::variableType)> observerFunction
a typedef to make the stuff more readable
static void notify(const FilterType &filterType, typename FilterType::variableType fResult, const typename FilterType::argumentType &outerHit, const typename FilterType::argumentType &innerHit, otherTypes ...)
iterate over all stored Observers and execute their notify-function
void(*)(const typename FilterType::argumentType &, const typename FilterType::argumentType &, const FilterType &, typename FilterType::variableType) CStyleFunctionPointer
a typedef to make the c-style pointer more readable (can not be done with classic typedef)
a tiny counter class for counting stuff
static unsigned int accepted
count number of times result was accepted
static void resetCounter()
destructor.
static unsigned int wasInf
count number of times result was inf
static unsigned int used
count number of times used
static unsigned int rejected
count number of times result was rejected
static unsigned int wasNan
count number of times result was nan
double atan(double a)
atan for double
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
B2Vector3D outerHit(0, 0, 0)
testing out of range behavior
Abstract base class for different kinds of events.