9 #include <framework/dbobjects/BeamParameters.h>
10 #include <framework/logging/Logger.h>
11 #include <framework/gearbox/Const.h>
22 constexpr
int getIndex(
unsigned int i,
unsigned int j)
25 return (i < j) ? ((j + 1) * j / 2 + i) : ((i + 1) * i / 2 + j);
29 void BeamParameters::setLER(
double energy,
double angleX,
double angleY,
const std::vector<double>& cov)
31 TLorentzVector vec = getFourVector(energy, angleX, angleY);
33 setCovMatrix(m_covLER, cov,
false);
36 void BeamParameters::setHER(
double energy,
double angleX,
double angleY,
const std::vector<double>& cov)
38 TLorentzVector vec = getFourVector(energy, angleX, angleY);
40 setCovMatrix(m_covHER, cov,
false);
43 void BeamParameters::setVertex(
const TVector3& vertex,
const std::vector<double>& cov)
46 setCovMatrix(m_covVertex, cov,
true);
49 TLorentzVector BeamParameters::getFourVector(
double energy,
double angleX,
double angleY)
51 double p = sqrt(pow(energy, 2) - pow(Const::electronMass, 2));
53 angleX = M_PI + angleX;
54 angleY = M_PI + angleY;
57 double Sign = cos(angleX) < 0 ? -1 : 1;
59 double pzTerm = 1 - pow(sin(angleX), 2) - pow(sin(angleY), 2);
60 B2ASSERT(
"Angular term should be positive", pzTerm >= 0);
62 double pz = Sign * p * sqrt(pzTerm);
64 return TLorentzVector(p * sin(angleX), p * sin(angleY), pz, energy);
68 TMatrixDSym BeamParameters::getCovMatrix(
const Double32_t* member)
70 TMatrixDSym matrix(3);
71 for (
int iRow = 0; iRow < 3; ++iRow) {
72 for (
int iCol = iRow; iCol < 3; ++iCol) {
73 matrix(iCol, iRow) = matrix(iRow, iCol) = member[getIndex(iRow, iCol)];
79 void BeamParameters::setCovMatrix(Double32_t* matrix,
const TMatrixDSym& cov)
81 for (
int iRow = 0; iRow < 3; ++iRow) {
82 for (
int iCol = iRow; iCol < 3; ++iCol) {
83 matrix[getIndex(iRow, iCol)] = cov(iRow, iCol);
88 void BeamParameters::setCovMatrix(Double32_t* matrix,
const std::vector<double>& cov,
bool common)
90 std::fill_n(matrix, 6, 0);
105 for (
int i = 0; i < 3; ++i) {
106 matrix[getIndex(i, i)] = cov[i % cov.size()];
110 for (
int iRow = 0, n = 0; iRow < 3; ++iRow) {
111 for (
int iCol = iRow; iCol < 3; ++iCol) {
112 matrix[getIndex(iRow, iCol)] = cov[n++];
117 for (
int iRow = 0; iRow < 3; ++iRow) {
118 for (
int iCol = iRow; iCol < 3; ++iCol) {
119 matrix[getIndex(iRow, iCol)] = cov[iRow * 3 + iCol];
124 B2ERROR(
"Number of elements to set covariance matrix must be either 1, 3, 6 or 9 but "
125 << cov.size() <<
" given");
Abstract base class for different kinds of events.