62 unsigned int nTry = 1000;
63 unsigned int nLayer = 10;
64 std::cout <<
" Gbltst-eigen $Id$ " << nTry <<
", " << nLayer
69 clock_t startTime = clock();
71 double sinLambda = 0.3;
72 double cosLambda = sqrt(1.0 - sinLambda * sinLambda);
74 double cosPhi = sqrt(1.0 - sinPhi * sinPhi);
77 Matrix<double, 2, 3> uvDir;
78 uvDir(0, 0) = -sinPhi;
81 uvDir(1, 0) = -sinLambda * cosPhi;
82 uvDir(1, 1) = -sinLambda * sinPhi;
83 uvDir(1, 2) = cosLambda;
86 measErr << 0.001, 0.001;
88 measPrec << 1.0 / (measErr(0) * measErr(0)), 1.0 / (measErr(1) * measErr(1));
91 measInvCov(0, 0) = measPrec[0];
92 measInvCov(1, 1) = measPrec[1];
95 scatErr << 0.003, 0.003;
97 scatPrec << 1.0 / (scatErr(0) * scatErr(0)), 1.0 / (scatErr(1) * scatErr(1));
101 clErr << 0.001, -0.1, 0.2, -0.15, 0.25;
103 unsigned int seedLabel = 99999;
108 double bfac = 0.2998;
109 double step = 1.5 / cosLambda;
116 for (
unsigned int iTry = 1; iTry <= nTry; ++iTry) {
118 for (
unsigned int i = 0; i < 5; ++i) {
119 clPar[i] = clErr[i] *
unrm();
122 for (
unsigned int i = 0; i < 5; ++i) {
123 clCov(i, i) = 1.0 * (clErr[i] * clErr[i]);
130 jacPointToPoint.setIdentity();
132 std::vector<GblPoint> listOfPoints;
133 listOfPoints.reserve(2 * nLayer);
135 for (
unsigned int iLayer = 0; iLayer < nLayer; ++iLayer) {
138 double sinStereo = (iLayer % 2 == 0) ? 0. : 0.1;
139 double cosStereo = sqrt(1.0 - sinStereo * sinStereo);
140 Matrix<double, 3, 2> mDirT;
142 mDirT(1, 0) = cosStereo;
143 mDirT(2, 0) = sinStereo;
144 mDirT(1, 1) = -sinStereo;
145 mDirT(2, 1) = cosStereo;
147 Matrix2d proM2l = uvDir * mDirT;
149 Matrix2d proL2m = proM2l.inverse();
151 GblPoint pointMeas(jacPointToPoint);
153 Vector2d meas = proL2m * clPar.tail(2);
154 for (
unsigned int i = 0; i < 2; ++i) {
155 meas[i] += measErr[i] *
unrm();
172 Matrix2d addDer = proL2m * (s - sScat);
177 listOfPoints.push_back(pointMeas);
178 unsigned int iLabel = listOfPoints.size();
179 if (iLabel == seedLabel) {
180 clSeed = clCov.inverse();
184 clPar = jacPointToPoint * clPar;
185 clCov = jacPointToPoint * clCov * jacPointToPoint.transpose();
187 if (iLayer < nLayer - 1) {
188 Vector2d scat(0., 0.);
190 GblPoint pointScat(jacPointToPoint);
197 listOfPoints.push_back(pointScat);
198 iLabel = listOfPoints.size();
199 if (iLabel == seedLabel) {
200 clSeed = clCov.inverse();
203 for (
unsigned int i = 0; i < 2; ++i) {
204 clPar[i + 1] += scatErr[i] *
unrm();
205 clCov(i + 1, i + 1) += scatErr[i] * scatErr[i];
208 clPar = jacPointToPoint * clPar;
209 clCov = jacPointToPoint * clCov * jacPointToPoint.transpose();
220 std::cout <<
" Invalid GblTrajectory -> skip" << std::endl;
227 traj.
fit(Chi2, Ndf, lostWeight);
229 VectorXd aCorrection(7);
230 MatrixXd aCovariance(7, 7);
231 traj.
getResults(10, aCorrection, aCovariance);
233 scatVar(0) += aCorrection(5) * aCorrection(5);
234 scatVar(1) += aCorrection(6) * aCorrection(6);
236 scatVar(0) -= aCovariance(5, 5);
237 scatVar(1) -= aCovariance(6, 6);
258 LostSum += lostWeight;
262 clock_t endTime = clock();
263 double diff = endTime - startTime;
264 double cps = CLOCKS_PER_SEC;
265 std::cout <<
" Time elapsed " << diff / cps <<
" s" << std::endl;
266 std::cout <<
" Chi2/Ndf = " << Chi2Sum / NdfSum << std::endl;
267 std::cout <<
" Tracks fitted " << numFit << std::endl;
268 std::cout <<
" ScatErr4 " << sqrt(scatVar[0] / numFit) <<
" "
269 << sqrt(scatVar[1] / numFit) << std::endl;
271 std::cout <<
" Weight lost " << LostSum << std::endl;
GblTrajectory definition.
Definitions for GBL utilities.
void addMeasurement(const Eigen::MatrixBase< Projection > &aProjection, const Eigen::MatrixBase< Residuals > &aResiduals, const Eigen::MatrixBase< Precision > &aPrecision, double minPrecision=0.)
Add a measurement to a point.
void addLocals(const Eigen::MatrixBase< Derivative > &aDerivatives)
Add local derivatives to a point.
void addScatterer(const Eigen::Vector2d &aResiduals, const Eigen::Matrix2d &aPrecision)
Add a thin scatterer to a point.
bool isValid() const
Retrieve validity of trajectory.
unsigned int getResults(int aSignedLabel, Eigen::VectorXd &localPar, Eigen::MatrixXd &localCov) const
Get fit results at point.
unsigned int fit(double &Chi2, int &Ndf, double &lostWeight, const std::string &optionList="", unsigned int aLabel=0)
Perform fit of (valid) trajectory.
Namespace for the general broken lines package.
double unrm()
unit normal distribution, Box-Muller method, polar form
Eigen::Matrix< double, 5, 1 > Vector5d
Matrix5d gblSimpleJacobian(double ds, double cosl, double bfac)
Simple jacobian.
Eigen::Matrix< double, 5, 5 > Matrix5d