Belle II Software development
BeamParameters.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 <framework/dbobjects/BeamParameters.h>
9
10#include <gtest/gtest.h>
11
12using namespace std;
13using namespace Belle2;
14
15namespace {
16 TEST(BeamParameters, BoostUpsilon4SToLab)
17 {
18 BeamParameters beamparams;
19 //some values from Belle
20 beamparams.setLER(3.49841, M_PI, 0, std::vector<double>());
21 beamparams.setHER(7.99638, 0.022, 0, std::vector<double>());
22
23 const ROOT::Math::PxPyPzEVector upsVec = beamparams.getHER() + beamparams.getLER();
24 ROOT::Math::PxPyPzEVector upsVecCMS = beamparams.getLabToCMS() * upsVec;
25
26 const double mUpsilon = 10.5794;
27 EXPECT_TRUE(fabs(upsVecCMS.E() - mUpsilon) < 1e-2);
28 EXPECT_TRUE(fabs(upsVecCMS.X()) < 1e-15);
29 EXPECT_TRUE(fabs(upsVecCMS.Y()) < 1e-15);
30 EXPECT_TRUE(fabs(upsVecCMS.Z()) < 2e-15) << fabs(upsVecCMS.Z());
31
32 EXPECT_TRUE(fabs(beamparams.getMass() - mUpsilon) < 1e-2);
33 }
34
35 TEST(BeamParameters, BoostIntoCMSAndBack)
36 {
37 BeamParameters beamparams;
38 //some values from Belle
39 beamparams.setLER(3.49841, M_PI, 0, std::vector<double>());
40 beamparams.setHER(7.99638, 0.022, 0, std::vector<double>());
41
42 auto backAndForth = beamparams.getCMSToLab() * (beamparams.getLabToCMS());
43 ROOT::Math::PxPyPzEVector vec(1, 1, 1, 1);
44 vec = backAndForth * vec;
45 EXPECT_TRUE(fabs(vec.X() - 1) < 1e-15);
46 EXPECT_TRUE(fabs(vec.Y() - 1) < 1e-15);
47 EXPECT_TRUE(fabs(vec.Z() - 1) < 1e-15);
48 }
49
52 TEST(BeamParameters, CovFromMatrix)
53 {
54 BeamParameters beamparams;
55 TMatrixDSym upper(3), sym(3);
56 int n(0);
57 for (int i = 0; i < 3; i++) {
58 for (int j = 0; j < 3; j++) {
59 upper(i, j) = (j >= i) ? ++n : -1;
60 if (j >= i) sym(i, j) = sym(j, i) = upper(i, j);
61 }
62 }
63 beamparams.setCovHER(upper);
64 EXPECT_EQ(sym, beamparams.getCovHER());
65 }
66
68 TEST(BeamParameters, ZeroElement)
69 {
70 BeamParameters beamparams;
71 std::vector<double> cov;
72 TMatrixDSym matrix(3);
73 beamparams.setHER(0, 0, 0, cov);
74 beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
75 EXPECT_EQ(matrix, beamparams.getCovHER());
76 EXPECT_EQ(matrix, beamparams.getCovVertex());
77 }
78
81 TEST(BeamParameters, OneElement)
82 {
83 BeamParameters beamparams;
84 for (int i = 0; i < 10; ++i) {
85 std::vector<double> cov{1.*i};
86 TMatrixDSym beam(3), vertex(3);
87 beam(0, 0) = i;
88 vertex(0, 0) = i;
89 vertex(1, 1) = i;
90 vertex(2, 2) = i;
91 beamparams.setHER(0, 0, 0, cov);
92 beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
93 EXPECT_EQ(beam, beamparams.getCovHER());
94 EXPECT_EQ(vertex, beamparams.getCovVertex());
95 }
96 }
97
100 TEST(BeamParameters, ThreeElements)
101 {
102 BeamParameters beamparams;
103 std::vector<double> cov{1., 2., 3.};
104 TMatrixDSym matrix(3);
105 matrix(0, 0) = 1;
106 matrix(1, 1) = 2;
107 matrix(2, 2) = 3;
108 beamparams.setHER(0, 0, 0, cov);
109 beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
110 EXPECT_EQ(matrix, beamparams.getCovHER());
111 EXPECT_EQ(matrix, beamparams.getCovVertex());
112 }
113
115 TEST(BeamParameters, SixElements)
116 {
117 BeamParameters beamparams;
118 std::vector<double> cov{1., 2., 3., 4., 5., 6.};
119 TMatrixDSym matrix(3);
120 matrix(0, 0) = 1;
121 matrix(0, 1) = matrix(1, 0) = 2;
122 matrix(0, 2) = matrix(2, 0) = 3;
123 matrix(1, 1) = 4;
124 matrix(1, 2) = matrix(2, 1) = 5;
125 matrix(2, 2) = 6;
126 beamparams.setHER(0, 0, 0, cov);
127 beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
128 EXPECT_EQ(matrix, beamparams.getCovHER());
129 EXPECT_EQ(matrix, beamparams.getCovVertex());
130 }
131
133 TEST(BeamParameters, NineElements)
134 {
135 BeamParameters beamparams;
136 std::vector<double> cov{1., 2., 3., 4., 5., 6., 7., 8., 9.};
137 TMatrixDSym matrix(3);
138 matrix(0, 0) = 1;
139 matrix(0, 1) = matrix(1, 0) = 2;
140 matrix(0, 2) = matrix(2, 0) = 3;
141 matrix(1, 1) = 5;
142 matrix(1, 2) = matrix(2, 1) = 6;
143 matrix(2, 2) = 9;
144 beamparams.setHER(0, 0, 0, cov);
145 beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
146 EXPECT_EQ(matrix, beamparams.getCovHER());
147 EXPECT_EQ(matrix, beamparams.getCovVertex());
148 }
149
150} // namespace
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
void setHER(double energy, double angleX, double angleY, const std::vector< double > &cov)
Set the HER FourVector and error matrix from beam energy, angle and covariance entries.
TMatrixDSym getCovVertex() const
Get the covariance matrix of the vertex position.
void setLER(double energy, double angleX, double angleY, const std::vector< double > &cov)
Set the LER FourVector and error matrix from beam energy, angle and covariance entries.
void setCovHER(const TMatrixDSym &cov)
Set the covariance matrix for HER (E, theta_x, theta_y) where E is the energy, theta_x is the horizon...
TMatrixDSym getCovHER() const
Get the covariance matrix of HER (E, theta_x, theta_y) where E is the energy, theta_x is the horizont...
void setVertex(const ROOT::Math::XYZVector &vertex, const std::vector< double > &cov)
Set the vertex position and error matrix.
const ROOT::Math::PxPyPzEVector & getHER() const
Get 4vector of the high energy beam.
const ROOT::Math::PxPyPzEVector & getLER() const
Get 4vector of the low energy beam.
const ROOT::Math::LorentzRotation & getLabToCMS() const
Return the LorentzRotation to convert from lab to CMS frame.
const ROOT::Math::LorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
Abstract base class for different kinds of events.
STL namespace.