9 #include <generators/utilities/InitialParticleGeneration.h>
10 #include <framework/logging/Logger.h>
11 #include <generators/utilities/beamHelpers.h>
13 #include <Eigen/Dense>
42 return TMatrixDSym(3);
46 for (
int i = 0; i < 3; ++i)
47 cov(i, 0) = cov(0, i) = 0;
52 for (
int i = 1; i < 3; ++i)
53 for (
int j = 1; j < 3; ++j)
54 cov(i, j) = cov(j, i) = 0;
63 static Eigen::MatrixXd
toEigen(TMatrixDSym m)
65 Eigen::MatrixXd mEig(m.GetNrows(), m.GetNcols());
66 for (
int i = 0; i < m.GetNrows(); ++i)
67 for (
int j = 0; j < m.GetNcols(); ++j)
76 const ROOT::Math::PxPyPzEVector& pLER,
const TMatrixDSym& covHER,
const TMatrixDSym& covLER)
79 double E0her = pHER.E();
80 double thX0her =
std::atan(pHER.Px() / pHER.Pz());
81 double thY0her =
std::atan(pHER.Py() / pHER.Pz());
84 double E0ler = pLER.E();
85 double thX0ler =
std::atan(pLER.Px() / pLER.Pz());
86 double thY0ler =
std::atan(pLER.Py() / pLER.Pz());
89 Eigen::MatrixXd grad =
getGradientMatrix(E0her, thX0her, thY0her, E0ler, thX0ler, thY0ler);
90 Eigen::VectorXd mu =
getCentralValues(E0her, thX0her, thY0her, E0ler, thX0ler, thY0ler);
110 double E0 = initial.E();
111 double thX0 =
std::atan(initial.Px() / initial.Pz());
112 double thY0 =
std::atan(initial.Py() / initial.Pz());
115 if (gen.
size() != 3) gen.
setMeanCov(ROOT::Math::XYZVector(E0, thX0, thY0), cov);
136 bool isHER = initial.Z() > 0;
151 B2FATAL(
"Cannot generate beam without valid BeamParameters");
165 m_event->setGenerationFlags(0);
166 her =
m_event->getLabToCMS() * her;
167 ler =
m_event->getLabToCMS() * ler;
182 B2FATAL(
"Cannot generate beam without valid BeamParameters");
205 B2FATAL(
"Cannot generate beam without valid BeamParameters");
226 auto previous =
m_event->getVertex();
230 return vtx - previous;
static ROOT::Math::PxPyPzEVector getFourVector(double energy, double angleX, double angleY, bool isHER)
Calculate FourVector of a beam from energy and angles in xz and yz planes.
Class implementing n-dimensional random number generator from Gaussian distribution where the first c...
DBObjPtr< BeamParameters > m_beamParams
Datastore object containing the nominal beam parameters.
int m_allowedFlags
Allowed generation flags.
MultivariateNormalGenerator m_generateHER
Generator for HER.
StoreObjPtr< MCInitialParticles > m_event
Datastore object containing the generated event.
MultivariateNormalGenerator m_generateLER
Generator for LER.
MultivariateNormalGenerator m_generateVertex
Generator for Vertex.
ConditionalGaussGenerator m_generateLorentzTransformation
Generator of the Lorentz transformation.
This class contains the initial state for the given event.
@ c_smearVertex
smear vertex
@ c_smearBeam
smear the full beam momentum (energy and direction)
@ c_generateCMS
generate initial event in CMS instead of lab
@ c_smearBeamEnergy
smear energy of HER and LER (but not direction)
@ c_smearBeamDirection
smear direction of HER and LER (but not energy)
Class to generate normal distributed, correlated random numbers given the mean values and the covaria...
size_t size() const
Return the number of elements to be generated on generate()
bool setMeanCov(int n, const double *mean, const double *cov)
set the mean and covariance for the distribution with array interface: mean and covariance are passed...
Eigen::VectorXd generate() const
Generate a set of correlated random numbers with the previouly set mean and covariance.
void reset()
reset the generator setting the size to 0.
TVector3 generateVec3() const
Generate a set of correlated random numbers with the previouly set mean and covariance and return a T...
Eigen::VectorXd getCentralValues(double eH, double thXH, double thYH, double eL, double thXL, double thYL)
get vector including (Ecms, boostX, boostY, boostZ, angleXZ, angleYZ) from beam energies and angles
ROOT::Math::XYZVector getVertexConditional()
Generate vertex position and possibly update the generator of Lorentz transformation.
void initialize()
function to be executed on initialize()
ROOT::Math::XYZVector updateVertex(bool force=false)
Update the vertex position:
Eigen::MatrixXd transformCov(const Eigen::MatrixXd &covHER, const Eigen::MatrixXd &covLER, const Eigen::MatrixXd &grad)
transform covariance matrix to the variables (Ecms, boostX, boostY, boostZ, angleXZ,...
MCInitialParticles & generate()
Generate a new event.
static Eigen::MatrixXd toEigen(TMatrixDSym m)
transform matrix from ROOT to Eigen format
ROOT::Math::XYZVector generateVertex(const ROOT::Math::XYZVector &initial, const TMatrixDSym &cov, MultivariateNormalGenerator &gen) const
generate the vertex
ConditionalGaussGenerator initConditionalGenerator(const ROOT::Math::PxPyPzEVector &pHER, const ROOT::Math::PxPyPzEVector &pLER, const TMatrixDSym &covHER, const TMatrixDSym &covLER)
Initialize the conditional generator using HER & LER 4-vectors and HER & LER covariance matrices desc...
TMatrixDSym adjustCovMatrix(TMatrixDSym cov) const
adjust smearing covariance matrix based on the generation flags
double atan(double a)
atan for double
Eigen::MatrixXd getGradientMatrix(double eH, double thXH, double thYH, double eL, double thXL, double thYL)
get gradient matrix of (eH, thXH, thYH, eL, thXL, thYL) -> (eCMS, boostX, boostY, boostY,...
ROOT::Math::PxPyPzEVector generateBeam(const ROOT::Math::PxPyPzEVector &initial, const TMatrixDSym &cov, MultivariateNormalGenerator &gen) const
generate 4 vector for one beam
Abstract base class for different kinds of events.