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