Belle II Software development
BeamSpotUT.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#include <mdst/dbobjects/BeamSpot.h>
9#include <gtest/gtest.h>
10
11#include <limits>
12#include <functional>
13
14namespace Belle2 {
20 class BeamSpotTest : public ::testing::Test {
21 protected:
22 };
23
25 TEST_F(BeamSpotTest, Basic)
26 {
27 BeamSpot bs;
28 EXPECT_EQ(bs.getIPPosition().X(), 0.);
29 EXPECT_EQ(bs.getIPPosition().Y(), 0.);
30 EXPECT_EQ(bs.getIPPosition().Z(), 0.);
31
32 std::function<float (int, int)> sizeElement = [ & sizeElement](int i, int j) {
33 return j >= i ? (i + 1) + 10 * (j + 1) : sizeElement(j, i) ;
34 };
35
36 std::function<float (int, int)> errorElement = [& errorElement](int i, int j) {
37 return j >= i ? 100 + (i + 1) + 10 * (j + 1) : errorElement(j, i);
38 };
39
40 TMatrixDSym size(3), positionError(3);
41 for (int i = 0; i < 3; i++)
42 for (int j = i; j < 3; j++) {
43 size(i, j) = size(j, i) = sizeElement(i, j);
44 positionError(i, j) = positionError(j, i) = errorElement(i, j);
45 }
46
47 TVector3 position;
48 position.SetXYZ(1., 2., 3.);
49
50 bs.setSizeCovMatrix(size);
51 bs.setIP(position, positionError);
52
53 TVector3 testPosition = bs.getIPPosition();
54 EXPECT_EQ(testPosition.X(), 1.);
55 EXPECT_EQ(testPosition.Y(), 2.);
56 EXPECT_EQ(testPosition.Z(), 3.);
57
58 TMatrixDSym testError = bs.getIPPositionCovMatrix();
59 for (int i = 0; i < 3; i++)
60 for (int j = 0; j < 3; j++)
61 EXPECT_EQ(testError(i, j), errorElement(i, j));
62
63 TMatrixDSym testSize = bs.getSizeCovMatrix();
64 for (int i = 0; i < 3; i++)
65 for (int j = 0; j < 3; j++)
66 EXPECT_EQ(testSize(i, j), sizeElement(i, j));
67
68
69 TMatrixDSym testCovVertex = bs.getCovVertex();
70 for (int i = 0; i < 3; i++)
71 for (int j = 0; j < 3; j++)
72 EXPECT_EQ(testCovVertex(i, j), (sizeElement(i, j) + errorElement(i, j)));
73
74 EXPECT_EQ(bs.getGlobalUniqueID(), 1);
75 BeamSpot bs2(bs);
76 EXPECT_EQ(bs == bs2, true);
77
78 BeamSpot bs3;
79 bs3 = bs;
80 EXPECT_EQ(bs == bs3, true);
81
82 BeamSpot bs4;
83 bs4 = bs3;
84 size(2, 2) = 0.;
85
86 bs3.setSizeCovMatrix(size);
87 size(2, 2) = std::numeric_limits<double>::min();
88 bs4.setSizeCovMatrix(size);
89
90 EXPECT_EQ(bs4 == bs3, false);
91 }
92
94}
This class contains the beam spot position and size modeled as a gaussian distribution in space.
Definition: BeamSpot.h:22
void setSizeCovMatrix(const TMatrixDSym &size)
Set the covariance matrix of the size of the IP position.
Definition: BeamSpot.h:50
Abstract base class for different kinds of events.