Belle II Software development
observerCheckMCPurity.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <gtest/gtest.h>
10
11#include <tracking/trackFindingVXD/filterTools/ObserverCheckMCPurity.h>
12#include <tracking/trackFindingVXD/filterMap/filterFramework/ClosedRange.h>
13#include <tracking/trackFindingVXD/filterMap/threeHitVariables/CircleRadius.h> // used since it is easy for testing
14#include <tracking/spacePointCreation/SpacePoint.h>
15
16#include <tracking/trackFindingVXD/filterMap/filterFramework/Shortcuts.h>
17
18
19using namespace std;
20
21using namespace Belle2;
22
23namespace ObserverCheckMCPurityTests {
24
25
27 class ObserverCheckMCPurityTest : public ::testing::Test {
28 protected:
29 };
30
31
33 TEST_F(ObserverCheckMCPurityTest, TestInitializeAndTerminate)
34 {
35 // accessable instance of the observer:
37
39 // before initialize: all containers should be empty:
40 EXPECT_EQ(0, ObserverCheckMCPurity::s_results.size());
41 EXPECT_EQ(0, ObserverCheckMCPurity::s_wasAccepted.size());
42 EXPECT_EQ(0, ObserverCheckMCPurity::s_wasUsed.size());
43
44 testObserver.initialize< CircleRadius<SpacePoint>, ClosedRange<double, double>>(CircleRadius<SpacePoint>(),
46
47 // after initialize: now the containers are not empty any more:
48 EXPECT_EQ(1, ObserverCheckMCPurity::s_results.size());
49 EXPECT_EQ(1, ObserverCheckMCPurity::s_wasAccepted.size());
50 EXPECT_EQ(1, ObserverCheckMCPurity::s_wasUsed.size());
51
52
53 testObserver.terminate();
54
55 // after terminate: all containers should be empty:
56 EXPECT_EQ(0, ObserverCheckMCPurity::s_results.size());
57 EXPECT_EQ(0, ObserverCheckMCPurity::s_wasAccepted.size());
58 EXPECT_EQ(0, ObserverCheckMCPurity::s_wasUsed.size());
59 }
60
61
62 // JKL March 11th 2016: the following test is currently broken due to some missing-corner-case-treatments in the PurityCalculator (called by prepare).
63// // // /** tests notify and prepare */
64// // // TEST_F(ObserverCheckMCPurityTest, TestNotifyAndPrepare)
65// // // {
66// // // /// prepare some SpacePoints for testing forming a circle-segment of a circle with radius 1:
67// // // auto position1 = B2Vector3D(0., 1., 0.);
68// // // auto position2 = B2Vector3D(1., 0., 0.);
69// // // auto position3 = B2Vector3D(0., -1., 0.);
70// // // auto posError = B2Vector3D(0.1, 0.1, 0.1);
71// // //
72// // // auto sp1 = SpacePoint(position1, posError, {0., 0.}, {true, true}, VxdID(), VXD::SensorInfoBase::SensorType::VXD);
73// // // auto sp2 = SpacePoint(position2, posError, {0., 0.}, {true, true}, VxdID(), VXD::SensorInfoBase::SensorType::VXD);
74// // // auto sp3 = SpacePoint(position3, posError, {0., 0.}, {true, true}, VxdID(), VXD::SensorInfoBase::SensorType::VXD);
75// // //
76// // //
77// // // /// prepare Filters and observer:
78// // // // testFilters used for testing (they use the same Observer!):
79// // // auto testFilterAccept((0.9 < CircleRadius<SpacePoint>() < 1.1).observe(ObserverCheckMCPurity()));
80// // // auto testFilterReject((0.5 < CircleRadius<SpacePoint>() < 0.7).observe(ObserverCheckMCPurity()));
81// // //
82// // // // SelectionVariable to be used for the test (needed since the Filter has no getter for that):
83// // // CircleRadius<SpacePoint> cRadius = CircleRadius<SpacePoint>();
84// // //
85// // // // accessable instance of the observer:
86// // // ObserverCheckMCPurity testObserver = ObserverCheckMCPurity();
87// // // testObserver.initialize< CircleRadius<SpacePoint>, ClosedRange<double, double>>(CircleRadius<SpacePoint>(),
88// // // ClosedRange<double, double>(), nullptr);
89// // //
90// // // B2INFO("A")
91// // //
92// // // /// test notify of observer and if everything is stored as expected:
93// // // // before being notified- observer was not used:
94// // // EXPECT_EQ(false , *(ObserverCheckMCPurity::s_wasUsed.at(cRadius.name())));
95// // //
96// // // B2INFO("B")
97// // //
98// // // bool wasAccepted = testFilterAccept.accept(sp1, sp2, sp3);
99// // // EXPECT_EQ(true , wasAccepted);
100// // //
101// // // B2INFO("C")
102// // //
103// // // EXPECT_EQ(true , *(ObserverCheckMCPurity::s_wasUsed.at(cRadius.name())));
104// // // EXPECT_EQ(true , *(ObserverCheckMCPurity::s_wasAccepted.at(cRadius.name())));
105// // // EXPECT_DOUBLE_EQ(1. , *(ObserverCheckMCPurity::s_results.at(cRadius.name())));
106// // //
107// // // B2INFO("D")
108// // //
109// // // testObserver.prepare(sp1, sp2);
110// // // EXPECT_EQ(false , *(ObserverCheckMCPurity::s_wasUsed.at(cRadius.name())));
111// // // B2INFO("D2")
112// // // wasAccepted = testFilterReject.accept(sp1, sp2, sp3);
113// // // EXPECT_EQ(false , wasAccepted);
114// // //
115// // // B2INFO("E")
116// // //
117// // // EXPECT_EQ(true , *(ObserverCheckMCPurity::s_wasUsed.at(cRadius.name())));
118// // // B2INFO("F")
119// // // EXPECT_EQ(false , *(ObserverCheckMCPurity::s_wasAccepted.at(cRadius.name())));
120// // // B2INFO("G")
121// // // EXPECT_DOUBLE_EQ(1. , *(ObserverCheckMCPurity::s_results.at(cRadius.name())));
122// // // B2INFO("H")
123// // //
124// // // testObserver.terminate();
125// // // }
126}
Represents a closed set of arithmetic types.
Definition: ClosedRange.h:32
this observer searches for mcParticles attached to the hits given and stores the information found to...
static bool initialize(Var var, Range, const types &...)
static method used by the observed object to initialize the observer.
static std::map< std::string, bool * > s_wasAccepted
stores if hits were accepted (->value) for a selectionVariableName (->Key).
static void terminate(const types &...)
static method used by the observed object to terminate the observer.
static std::map< std::string, double * > s_results
stores the results calculated (->value) for a selectionVariableName (->Key).
static std::map< std::string, bool * > s_wasUsed
stores if the filter was actually used this time (->value) for a selectionVariableName (->Key).
Test class for SelectionVariableFactory object.
Abstract base class for different kinds of events.
STL namespace.