Belle II Software  release-08-01-10
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 ROOT::Math::PxPyPzEVector upsVec = beamparams.getHER() + beamparams.getLER();
25  ROOT::Math::PxPyPzEVector upsVecCMS = beamparams.getLabToCMS() * upsVec;
26 
27  const double mUpsilon = 10.5794;
28  EXPECT_TRUE(fabs(upsVecCMS.E() - mUpsilon) < 1e-2);
29  EXPECT_TRUE(fabs(upsVecCMS.X()) < 1e-15);
30  EXPECT_TRUE(fabs(upsVecCMS.Y()) < 1e-15);
31  EXPECT_TRUE(fabs(upsVecCMS.Z()) < 2e-15) << fabs(upsVecCMS.Z());
32 
33  EXPECT_TRUE(fabs(beamparams.getMass() - mUpsilon) < 1e-2);
34  }
35 
36  TEST(BeamParameters, BoostIntoCMSAndBack)
37  {
38  BeamParameters beamparams;
39  //some values from Belle
40  beamparams.setLER(3.49841, M_PI, 0, std::vector<double>());
41  beamparams.setHER(7.99638, 0.022, 0, std::vector<double>());
42 
43  auto backAndForth = beamparams.getCMSToLab() * (beamparams.getLabToCMS());
44  ROOT::Math::PxPyPzEVector vec(1, 1, 1, 1);
45  vec = backAndForth * vec;
46  EXPECT_TRUE(fabs(vec.X() - 1) < 1e-15);
47  EXPECT_TRUE(fabs(vec.Y() - 1) < 1e-15);
48  EXPECT_TRUE(fabs(vec.Z() - 1) < 1e-15);
49  }
50 
53  TEST(BeamParameters, CovFromMatrix)
54  {
55  BeamParameters beamparams;
56  TMatrixDSym upper(3), sym(3);
57  int n(0);
58  for (int i = 0; i < 3; i++) {
59  for (int j = 0; j < 3; j++) {
60  upper(i, j) = (j >= i) ? ++n : -1;
61  if (j >= i) sym(i, j) = sym(j, i) = upper(i, j);
62  }
63  }
64  beamparams.setCovHER(upper);
65  EXPECT_EQ(sym, beamparams.getCovHER());
66  }
67 
69  TEST(BeamParameters, ZeroElement)
70  {
71  BeamParameters beamparams;
72  std::vector<double> cov;
73  TMatrixDSym matrix(3);
74  beamparams.setHER(0, 0, 0, cov);
75  beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
76  EXPECT_EQ(matrix, beamparams.getCovHER());
77  EXPECT_EQ(matrix, beamparams.getCovVertex());
78  }
79 
82  TEST(BeamParameters, OneElement)
83  {
84  BeamParameters beamparams;
85  for (int i = 0; i < 10; ++i) {
86  std::vector<double> cov{1.*i};
87  TMatrixDSym beam(3), vertex(3);
88  beam(0, 0) = i;
89  vertex(0, 0) = i;
90  vertex(1, 1) = i;
91  vertex(2, 2) = i;
92  beamparams.setHER(0, 0, 0, cov);
93  beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
94  EXPECT_EQ(beam, beamparams.getCovHER());
95  EXPECT_EQ(vertex, beamparams.getCovVertex());
96  }
97  }
98 
101  TEST(BeamParameters, ThreeElements)
102  {
103  BeamParameters beamparams;
104  std::vector<double> cov{1., 2., 3.};
105  TMatrixDSym matrix(3);
106  matrix(0, 0) = 1;
107  matrix(1, 1) = 2;
108  matrix(2, 2) = 3;
109  beamparams.setHER(0, 0, 0, cov);
110  beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
111  EXPECT_EQ(matrix, beamparams.getCovHER());
112  EXPECT_EQ(matrix, beamparams.getCovVertex());
113  }
114 
116  TEST(BeamParameters, SixElements)
117  {
118  BeamParameters beamparams;
119  std::vector<double> cov{1., 2., 3., 4., 5., 6.};
120  TMatrixDSym matrix(3);
121  matrix(0, 0) = 1;
122  matrix(0, 1) = matrix(1, 0) = 2;
123  matrix(0, 2) = matrix(2, 0) = 3;
124  matrix(1, 1) = 4;
125  matrix(1, 2) = matrix(2, 1) = 5;
126  matrix(2, 2) = 6;
127  beamparams.setHER(0, 0, 0, cov);
128  beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
129  EXPECT_EQ(matrix, beamparams.getCovHER());
130  EXPECT_EQ(matrix, beamparams.getCovVertex());
131  }
132 
134  TEST(BeamParameters, NineElements)
135  {
136  BeamParameters beamparams;
137  std::vector<double> cov{1., 2., 3., 4., 5., 6., 7., 8., 9.};
138  TMatrixDSym matrix(3);
139  matrix(0, 0) = 1;
140  matrix(0, 1) = matrix(1, 0) = 2;
141  matrix(0, 2) = matrix(2, 0) = 3;
142  matrix(1, 1) = 5;
143  matrix(1, 2) = matrix(2, 1) = 6;
144  matrix(2, 2) = 9;
145  beamparams.setHER(0, 0, 0, cov);
146  beamparams.setVertex(ROOT::Math::XYZVector(0, 0, 0), cov);
147  EXPECT_EQ(matrix, beamparams.getCovHER());
148  EXPECT_EQ(matrix, beamparams.getCovVertex());
149  }
150 
151 } // 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 & getLER() const
Get 4vector of the low energy beam.
const ROOT::Math::PxPyPzEVector & getHER() const
Get 4vector of the high 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)
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.