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 ROOT::Math::PxPyPzEVector vec =
getFourVector(energy, angleX, angleY,
false);
33 setCovMatrix(m_covLER, cov,
false);
36 void BeamParameters::setHER(
double energy,
double angleX,
double angleY,
const std::vector<double>& cov)
38 ROOT::Math::PxPyPzEVector vec =
getFourVector(energy, angleX, angleY,
true);
40 setCovMatrix(m_covHER, cov,
false);
43 void BeamParameters::setVertex(
const ROOT::Math::XYZVector& vertex,
const std::vector<double>& cov)
46 setCovMatrix(m_covVertex, cov,
true);
51 double p =
sqrt(pow(energy, 2) - pow(Const::electronMass, 2));
52 double dir = isHER ? 1 : -1;
54 double pz = dir * p /
sqrt(1 + pow(
tan(angleX), 2) + pow(
tan(angleY), 2));
56 return ROOT::Math::PxPyPzEVector(pz *
tan(angleX), pz *
tan(angleY), pz, energy);
59 TMatrixDSym BeamParameters::getCovMatrix(
const Double32_t* member)
61 TMatrixDSym matrix(3);
62 for (
int iRow = 0; iRow < 3; ++iRow) {
63 for (
int iCol = iRow; iCol < 3; ++iCol) {
64 matrix(iCol, iRow) = matrix(iRow, iCol) = member[getIndex(iRow, iCol)];
70 void BeamParameters::setCovMatrix(Double32_t* matrix,
const TMatrixDSym& cov)
72 for (
int iRow = 0; iRow < 3; ++iRow) {
73 for (
int iCol = iRow; iCol < 3; ++iCol) {
74 matrix[getIndex(iRow, iCol)] = cov(iRow, iCol);
79 void BeamParameters::setCovMatrix(Double32_t* matrix,
const std::vector<double>& cov,
bool common)
81 std::fill_n(matrix, 6, 0);
96 for (
int i = 0; i < 3; ++i) {
97 matrix[getIndex(i, i)] = cov[i % cov.size()];
101 for (
int iRow = 0, n = 0; iRow < 3; ++iRow) {
102 for (
int iCol = iRow; iCol < 3; ++iCol) {
103 matrix[getIndex(iRow, iCol)] = cov[n++];
108 for (
int iRow = 0; iRow < 3; ++iRow) {
109 for (
int iCol = iRow; iCol < 3; ++iCol) {
110 matrix[getIndex(iRow, iCol)] = cov[iRow * 3 + iCol];
115 B2ERROR(
"Number of elements to set covariance matrix must be either 1, 3, 6 or 9 but "
116 << cov.size() <<
" given");
double sqrt(double a)
sqrt for double
GeneralVector< T > getFourVector(T energy, T angleX, T angleY, bool isHER)
get 4-momentum from energy and angles of beam
double tan(double a)
tan for double
Abstract base class for different kinds of events.