11 #include <framework/dbobjects/BeamParameters.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/gearbox/Const.h>
24 constexpr
int getIndex(
unsigned int i,
unsigned int j)
27 return (i < j) ? ((j + 1) * j / 2 + i) : ((i + 1) * i / 2 + j);
31 void BeamParameters::setLER(
double energy,
double angle,
const std::vector<double>& cov)
33 TLorentzVector vec = getFourVector(energy, angle);
35 setCovMatrix(m_covLER, cov,
false);
38 void BeamParameters::setHER(
double energy,
double angle,
const std::vector<double>& cov)
40 TLorentzVector vec = getFourVector(energy, angle);
42 setCovMatrix(m_covHER, cov,
false);
45 void BeamParameters::setVertex(
const TVector3& vertex,
const std::vector<double>& cov)
48 setCovMatrix(m_covVertex, cov,
true);
51 TLorentzVector BeamParameters::getFourVector(
double energy,
double angle)
53 double pz = sqrt(energy * energy - Const::electronMass * Const::electronMass);
54 TLorentzVector vec(0, 0, pz, energy);
55 if (angle < 0) angle = M_PI + angle;
60 TMatrixDSym BeamParameters::getCovMatrix(
const Double32_t* member)
62 TMatrixDSym matrix(3);
63 for (
int iRow = 0; iRow < 3; ++iRow) {
64 for (
int iCol = iRow; iCol < 3; ++iCol) {
65 matrix(iCol, iRow) = matrix(iRow, iCol) = member[getIndex(iRow, iCol)];
71 void BeamParameters::setCovMatrix(Double32_t* matrix,
const TMatrixDSym& cov)
73 for (
int iRow = 0; iRow < 3; ++iRow) {
74 for (
int iCol = iRow; iCol < 3; ++iCol) {
75 matrix[getIndex(iRow, iCol)] = cov(iRow, iCol);
80 void BeamParameters::setCovMatrix(Double32_t* matrix,
const std::vector<double>& cov,
bool common)
82 std::fill_n(matrix, 6, 0);
97 for (
int i = 0; i < 3; ++i) {
98 matrix[getIndex(i, i)] = cov[i % cov.size()];
102 for (
int iRow = 0, n = 0; iRow < 3; ++iRow) {
103 for (
int iCol = iRow; iCol < 3; ++iCol) {
104 matrix[getIndex(iRow, iCol)] = cov[n++];
109 for (
int iRow = 0; iRow < 3; ++iRow) {
110 for (
int iCol = iRow; iCol < 3; ++iCol) {
111 matrix[getIndex(iRow, iCol)] = cov[iRow * 3 + iCol];
116 B2ERROR(
"Number of elements to set covariance matrix must be either 1, 3, 6 or 9 but "
117 << cov.size() <<
" given");