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