Belle II Software  release-05-01-25
QualityEstimatorTripletFit.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Felix Metzner, Jonas Wagner *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <gtest/gtest.h>
12 
13 #include <vector>
14 
15 #include <framework/geometry/B2Vector3.h>
16 
17 #include "tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h"
18 
19 
20 using namespace Belle2;
21 const static double allowed_chi2_deviation = 1e-20;
22 
23 
24 namespace QualityEstimatorTests {
25 
26  TEST(TripletFitTests, CircleChi2)
27  {
28  // Setup QualityEstimator
29  auto qualityEstimator = QualityEstimatorTripletFit();
30  qualityEstimator.setMagneticFieldStrength(1.5);
31 
32  // Some hitpoints that are exactly on a circle in x,y with radius 1 and m=(1,0,0)
33  auto position1 = B2Vector3<double>(0., 0., 0.);
34  auto position2 = B2Vector3<double>(1., 1., 0.);
35  auto position3 = B2Vector3<double>(2., 0., 0.);
36  B2Vector3<double> sigma;
37 
38  auto spacePoint1 = SpacePoint(position1, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
39  auto spacePoint2 = SpacePoint(position2, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
40  auto spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
41 
42  std::vector<SpacePoint const*> hitlist;
43  hitlist.reserve(3);
44  hitlist.push_back(&spacePoint1);
45  hitlist.push_back(&spacePoint2);
46  hitlist.push_back(&spacePoint3);
47 
48  // Perform fit
49  auto result = qualityEstimator.estimateQualityAndProperties(hitlist);
50 
51  ASSERT_TRUE(result.chiSquared);
52  ASSERT_NEAR(*(result.chiSquared), 0., allowed_chi2_deviation) << "1st perfect circle";
53 
54  // Some hitpoints that are exactly on a circle in rotated 2D-plane with radius 1
55  position1 = B2Vector3<double>(0., 0., 0.);
56  position2 = B2Vector3<double>(1., 1., 1.);
57  position3 = B2Vector3<double>(2., 0., 2.);
58 
59  spacePoint1 = SpacePoint(position1, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
60  spacePoint2 = SpacePoint(position2, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
61  spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
62 
63  hitlist.clear();
64  hitlist.push_back(&spacePoint1);
65  hitlist.push_back(&spacePoint2);
66  hitlist.push_back(&spacePoint3);
67 
68  // Perform fit
69  result = qualityEstimator.estimateQualityAndProperties(hitlist);
70 
71  ASSERT_TRUE(result.chiSquared);
72  ASSERT_NEAR(*(result.chiSquared), 0., allowed_chi2_deviation) << "2nd perfect circle";
73 
74  // Move one hit away from circle
75  position3 = B2Vector3<double>(2., 0., 2. + 1e-6);
76  spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
77 
78  hitlist.clear();
79  hitlist.push_back(&spacePoint1);
80  hitlist.push_back(&spacePoint2);
81  hitlist.push_back(&spacePoint3);
82  // Perform fit
83  result = qualityEstimator.estimateQualityAndProperties(hitlist);
84 
85  ASSERT_TRUE(*(result.chiSquared) > allowed_chi2_deviation) << "1st imperfect circle";
86 
87  // Move one hit away from circle
88  position3 = B2Vector3<double>(2. + 1e-6, 0., 2.);
89  spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
90 
91  hitlist.clear();
92  hitlist.push_back(&spacePoint1);
93  hitlist.push_back(&spacePoint2);
94  hitlist.push_back(&spacePoint3);
95  // Perform fit
96  result = qualityEstimator.estimateQualityAndProperties(hitlist);
97 
98  ASSERT_TRUE(result.chiSquared);
99  ASSERT_TRUE(*(result.chiSquared) > allowed_chi2_deviation) << "2nd imperfect circle";
100  }
101 
102  TEST(TripletFitTests, CombinedCircleChi2)
103  {
104  // Setup QualityEstimator
105  auto qualityEstimator = QualityEstimatorTripletFit();
106  qualityEstimator.setMagneticFieldStrength(1.5);
107 
108  // Some hitpoints that are exactly on a circle in x,y with radius 1 and m=(1,0,0)
109  auto position1 = B2Vector3<double>(0., 0., 0.);
110  auto position2 = B2Vector3<double>(1., 1., 0.);
111  auto position3 = B2Vector3<double>(2., 0., 0.);
112  auto position4 = B2Vector3<double>(1., -1., 0.);
113  B2Vector3<double> sigma;
114 
115  auto spacePoint1 = SpacePoint(position1, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
116  auto spacePoint2 = SpacePoint(position2, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
117  auto spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
118  auto spacePoint4 = SpacePoint(position4, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
119 
120  std::vector<SpacePoint const*> hitlist;
121  hitlist.reserve(4);
122  hitlist.push_back(&spacePoint1);
123  hitlist.push_back(&spacePoint2);
124  hitlist.push_back(&spacePoint3);
125  hitlist.push_back(&spacePoint4);
126  // Perform fit
127  auto result = qualityEstimator.estimateQualityAndProperties(hitlist);
128 
129  ASSERT_TRUE(result.chiSquared);
130  ASSERT_NEAR(*(result.chiSquared), 0., allowed_chi2_deviation) << "1st perfect combined circle";
131 
132  // Combine two triplets with different radii;
133  position4 = B2Vector3<double>(1., -2., 0.);
134  spacePoint4 = SpacePoint(position4, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
135 
136  hitlist.clear();
137  hitlist.reserve(4);
138  hitlist.push_back(&spacePoint1);
139  hitlist.push_back(&spacePoint2);
140  hitlist.push_back(&spacePoint3);
141  hitlist.push_back(&spacePoint4);
142 
143  result = qualityEstimator.estimateQualityAndProperties(hitlist);
144 
145  ASSERT_TRUE(result.chiSquared);
146  ASSERT_TRUE(*(result.chiSquared) > allowed_chi2_deviation) << "Incompatible circle triplets";
147  }
148 
149  TEST(TripletFitTests, Interface)
150  {
151  // Setup QualityEstimator Class
152  auto qualityEstimator = QualityEstimatorTripletFit();
153  qualityEstimator.setMagneticFieldStrength(1.5);
154 
155  // Some hitpoints
156  auto position1 = B2Vector3<double>(0., 0., 0.);
157  auto position2 = B2Vector3<double>(1., 1., 0.);
158  auto position3 = B2Vector3<double>(2., 0., 0.);
159  B2Vector3<double> sigma;
160  auto spacePoint1 = SpacePoint(position1, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
161  auto spacePoint2 = SpacePoint(position2, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
162  auto spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
163 
164  std::vector<SpacePoint const*> hitlist;
165  hitlist.reserve(4);
166  hitlist.push_back(&spacePoint1);
167  hitlist.push_back(&spacePoint2);
168  hitlist.push_back(&spacePoint3);
169 
170  // Test if calcChiSquared and calcCompleteResults return the same values
171  auto result = qualityEstimator.estimateQuality(hitlist);
172  auto resultObject = qualityEstimator.estimateQualityAndProperties(hitlist);
173  ASSERT_EQ(resultObject.qualityIndicator, result);
174 
175  // check if the correct optional values are set
176  ASSERT_FALSE(resultObject.p);
177 
178  ASSERT_TRUE(resultObject.chiSquared);
179  ASSERT_TRUE(resultObject.pt);
180  ASSERT_TRUE(resultObject.pmag);
181  ASSERT_TRUE(resultObject.curvatureSign);
182 
183  // Test if tripletFit handles empty measurements vector correct
184  hitlist.clear();
185 
186  result = qualityEstimator.estimateQuality(hitlist);
187  resultObject = qualityEstimator.estimateQualityAndProperties(hitlist);
188  ASSERT_EQ(result, resultObject.qualityIndicator);
189 
190  // check if the optional values got reset
191  ASSERT_FALSE(resultObject.chiSquared);
192  ASSERT_FALSE(resultObject.p);
193  ASSERT_FALSE(resultObject.pt);
194  ASSERT_FALSE(resultObject.pmag);
195  ASSERT_FALSE(resultObject.curvatureSign);
196  }
197 }
198 
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::QualityEstimatorTripletFit
does a tripletFit of the given hits The filter is based on the paper 'A New Three-Dimensional Track F...
Definition: QualityEstimatorTripletFit.h:31
prepareAsicCrosstalkSimDB.e
e
aux.
Definition: prepareAsicCrosstalkSimDB.py:53
Belle2::VXD::SensorInfoBase::VXD
@ VXD
Any type of VXD Sensor.
Definition: SensorInfoBase.h:47
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::B2Vector3< double >
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TEST
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Definition: utilityFunctions.cc:18
Belle2::gearbox::Interface
Exception to be thrown in case of an empty result.
Definition: Interface.h:37