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