Belle II Software development
threehitfilters.h
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#include <tracking/vxdCaTracking/ThreeHitFilters.h>
9#include <gtest/gtest.h>
10
11namespace Belle2 {
18 class ThreeHitFiltersTest : public ::testing::Test {
19 protected:
20 };
21
22
24 TEST_F(ThreeHitFiltersTest, simpleTest)
25 {
26 // testing deltaPt-calculator:
27 B2Vector3D innerHit(1., 1., 0.), centerHit(3., 3., 0.), outerHitEvil(6., 3., 0.), outerHitSimple(6., 4., 0.);
28
29 ThreeHitFilters aFilter = ThreeHitFilters(outerHitSimple, centerHit, innerHit);
30
31// B2INFO("now comparing values of calcCircleDist2IP using simple outerHit: \n calcPt: " << aFilter.calcCircleDist2IP())
32// aFilter.resetValues(outerHitSimple,centerHit,innerHit);
33 EXPECT_FLOAT_EQ(0.44499173338941, aFilter.calcCircleDist2IP());
34
35 aFilter.resetValues(outerHitEvil, centerHit, innerHit);
36// B2INFO("now comparing values of calcCircleDist2IP using evil outerHit: \n calcPt: " << aFilter.calcPt())
37// aFilter.resetValues(outerHitEvil,centerHit,innerHit);
38 EXPECT_FLOAT_EQ(0.719806016136754, aFilter.calcCircleDist2IP());
39
40// B2INFO("now tests with 0.976T (and reset between each step): \n")
41 aFilter.resetMagneticField(0.976);
42 aFilter.resetValues(outerHitSimple, centerHit, innerHit);
43// B2INFO("now comparing values of calcCircleDist2IP using simple outerHit: \n calcPt: " << aFilter.calcCircleDist2IP() )
44// aFilter.resetValues(outerHitSimple,centerHit,innerHit);
45 EXPECT_FLOAT_EQ(0.44499173338941, aFilter.calcCircleDist2IP());
46
47 aFilter.resetValues(outerHitEvil, centerHit, innerHit);
48// B2INFO("now comparing values of calcCircleDist2IP using evil outerHit: \n calcPt: " << aFilter.calcPt() )
49// aFilter.resetValues(outerHitEvil,centerHit,innerHit);
50 EXPECT_FLOAT_EQ(0.719806016136754, aFilter.calcCircleDist2IP());
51 }
52
53
55 TEST_F(ThreeHitFiltersTest, TestMagneticField)
56 {
57 B2Vector3D innerHit(1., 1., 0.), centerHit(3., 3., 0.), outerHitEvil(6., 3., 0.), outerHitSimple(6., 4., 0.);
58
59 ThreeHitFilters aFilter = ThreeHitFilters(outerHitSimple, centerHit, innerHit);
60
61 EXPECT_DOUBLE_EQ(1.5, aFilter.getMagneticField()); // standard case
62
63 aFilter.resetMagneticField(1);
64 EXPECT_DOUBLE_EQ(1., aFilter.getMagneticField());
65
66 EXPECT_DOUBLE_EQ(26.5650511770779893515721937204532946712042, aFilter.fullAngle3D()); //angle in degrees
67 }
68
69
71 TEST_F(ThreeHitFiltersTest, TestAngles)
72 {
73 B2Vector3D innerHit(1., 1., 0.), centerHit(3., 3., 0.), outerHit(6., 4., 1.);
74 B2Vector3D cent_inner = centerHit - innerHit, outer_center = outerHit - centerHit;
75
76// B2INFO("now tests with 1T \n")
77 ThreeHitFilters aFilter = ThreeHitFilters(outerHit, centerHit, innerHit);
78
79 EXPECT_DOUBLE_EQ(31.4821541052938556040832384555411729852856, aFilter.fullAngle3D()); //angle in degrees
80 EXPECT_DOUBLE_EQ(0.090909090909090909091, aFilter.calcAngle3D());
81
82 EXPECT_DOUBLE_EQ(26.5650511770779893515721937204532946712042, aFilter.fullAngleXY()); //angle in degrees
83 EXPECT_DOUBLE_EQ(.1, aFilter.calcAngleXY());
84
85 EXPECT_FLOAT_EQ(17.54840061379229806435203716652846677620, aFilter.fullAngleRZ());
86 EXPECT_FLOAT_EQ(cos(17.54840061379229806435203716652846677620 * M_PI / 180.), aFilter.calcAngleRZ());
87
88 EXPECT_DOUBLE_EQ(0.4636476090008061162142562314612144020285, aFilter.fullAngle2D(outer_center, cent_inner)); //angle in radians
89 EXPECT_DOUBLE_EQ(0.89442719099991586, aFilter.calcAngle2D(outer_center, cent_inner));
90 }
91
92
94 TEST_F(ThreeHitFiltersTest, TestSignAndOtherFilters)
95 {
96 B2Vector3D innerHit(1., 1., 0.), centerHit(3., 3., 0.), outerHit(6., 4., 1.), sigma(.01, .01, .01), unrealsigma(2, 2, 2),
97 outerhighHit(4., 6., 1.);
98
99 ThreeHitFilters aFilter = ThreeHitFilters(outerHit, centerHit, innerHit);
100
101 EXPECT_DOUBLE_EQ(0.30627736916966945608, aFilter.calcDeltaSlopeRZ());
102
103 EXPECT_DOUBLE_EQ(0., aFilter.calcHelixFit());
104
105 EXPECT_DOUBLE_EQ(1., aFilter.calcSign(outerHit, centerHit, innerHit, sigma, sigma, sigma));
106 EXPECT_DOUBLE_EQ(-1., aFilter.calcSign(outerhighHit, centerHit, innerHit, sigma, sigma, sigma));
107 EXPECT_DOUBLE_EQ(-1., aFilter.calcSign(innerHit, centerHit, outerHit, sigma, sigma, sigma));
108 EXPECT_DOUBLE_EQ(0., aFilter.calcSign(outerHit, centerHit, innerHit, unrealsigma, unrealsigma,
109 unrealsigma)); //for very large sigma, this track is approximately straight.
110
111 EXPECT_LT(0., aFilter.calcSign(outerHit, centerHit, innerHit));
112 EXPECT_GT(0., aFilter.calcSign(outerhighHit, centerHit, innerHit));
113 EXPECT_GT(0., aFilter.calcSign(innerHit, centerHit, outerHit));
114 EXPECT_LT(0., aFilter.calcSign(outerHit, centerHit, innerHit));
115
116 EXPECT_DOUBLE_EQ(1., aFilter.calcSign(outerHit, centerHit, innerHit));
117 EXPECT_DOUBLE_EQ(-1., aFilter.calcSign(outerhighHit, centerHit, innerHit));
118 EXPECT_DOUBLE_EQ(-1., aFilter.calcSign(innerHit, centerHit, outerHit));
119 }
120
121
123 TEST_F(ThreeHitFiltersTest, TestDeltaSOverZ)
124 {
125 B2Vector3D innerHit(1., 1., 0.), centerHit(3., 3., 1.), outerHit(6., 4., 3.);
126 B2Vector3D cent_inner = centerHit - innerHit, outer_center = outerHit - centerHit;
127 ThreeHitFilters aFilter = ThreeHitFilters(outerHit, centerHit, innerHit);
128
129 EXPECT_FLOAT_EQ(0.31823963, aFilter.calcDeltaSlopeZOverS());
130
131 outerHit.RotateZ(.4);
132 centerHit.RotateZ(.4);
133 innerHit.RotateZ(.4);
134 aFilter.resetValues(outerHit, centerHit, innerHit); //calcDeltaSOverZV2 is invariant under rotations in the r-z plane
135
136 EXPECT_FLOAT_EQ(0.31823963, aFilter.calcDeltaSlopeZOverS());
137 }
138
139
141 TEST_F(ThreeHitFiltersTest, TestCalcPt)
142 {
143 // calcCircleCenterV2 had problems when x_1==x_2 or y_1==y_2
144 B2Vector3D innerHit(1., 2., 0.), centerHit(3., 2., 1.), outerHit(3., 4., 3.);
145 B2Vector3D cent_inner = centerHit - innerHit, outer_center = outerHit - centerHit;
147 B2Vector3D innerHit2(1., 1., 0.), centerHit2(3., 3., 0.), outerHitEvil(6., 3., 0.);
148
149 double pt = 0, ptTrue = 0;
150
151 aFilter.resetValues(outerHit, centerHit, innerHit);
152 ptTrue = aFilter.calcPt(1.414213562373095048801688724209698078570);
153 aFilter.resetValues(outerHit, centerHit, innerHit);
154 pt = aFilter.calcPt();
155 EXPECT_DOUBLE_EQ(ptTrue, pt);
156
157 ptTrue = 0.017118925181688543;
158 aFilter.resetValues(outerHitEvil, centerHit2, innerHit2);
159 pt = aFilter.calcPt();
160 EXPECT_DOUBLE_EQ(ptTrue, pt);
161
162 aFilter.resetValues(outerHit, outerHit, innerHit);
163 //B2WARNING("MUST produce errors: 2 hits are the same: " << ptTrue << ", Pt: " << pt );
164 ptTrue = aFilter.calcPt(1.414213562373095048801688724209698078570);
165 aFilter.resetValues(outerHit, outerHit, innerHit);
166 EXPECT_ANY_THROW(aFilter.calcPt());
167 }
169} // namespace
void RotateZ(DataType angle)
Rotates the B2Vector3 around the z-axis.
Definition: B2Vector3.h:359
Set up a few arrays and objects in the datastore.
The class 'ThreeHitFilters' bundles filter methods using 3 hits which are stored in B2Vector3Ds.
double calcAngle3D()
calculates the angle between the hits/vectors (3D), returning unit: none (calculation for degrees is ...
double fullAngle3D()
calculates the angle between the hits/vectors (3D), returning unit: angle in degrees
void resetValues(const B2Vector3D &outerHit, const B2Vector3D &centerHit, const B2Vector3D &innerHit)
Overrides Constructor-Setup.
double calcPt()
calculates the estimation of the transverse momentum of the 3-hit-tracklet, returning unit: GeV/c
double calcHelixFit()
reverse compatibility, calls calcHelixParameterFit
double fullAngleRZ()
calculates the angle between the hits/vectors (RZ), returning unit: angle in degrees
double calcDeltaSlopeRZ()
calculates deviations in the slope of the inner segment and the outer segment, returning unit: none
double getMagneticField()
returns the set value of the magnetic field in Tesla
double calcAngleRZ()
calculates the angle between the hits/vectors (RZ), returning unit: none (calculation for degrees is ...
double fullAngleXY()
calculates the angle between the hits/vectors (XY), returning unit: angle in degrees
double calcDeltaSlopeZOverS()
compares the "slopes" z over arc length.
double calcCircleDist2IP()
calculates the distance of the point of closest approach of circle to the IP, returning unit: cm
double fullAngle2D(const B2Vector3D &vecA, const B2Vector3D &vecB)
calculates the angle between the hits/vectors (2D), generalized, returning unit: angle in radians WAR...
void resetMagneticField(const double magneticFieldStrength=1.5)
Overrides Constructor-Setup for magnetic field.
double calcAngle2D(const B2Vector3D &vecA, const B2Vector3D &vecB)
calculates the angle between the hits/vectors (2D), generalized, returning unit: none.
double calcAngleXY()
calculates the angle between the hits/vectors (XY), returning unit: none (calculation for degrees is ...
int calcSign(const B2Vector3D &a, const B2Vector3D &b, const B2Vector3D &c)
calculates calculates the sign of the curvature of given 3-hit-tracklet.
B2Vector3D outerHit(0, 0, 0)
testing out of range behavior
Abstract base class for different kinds of events.