61 unsigned int nTry = 1000;
62 unsigned int nLayer = 10;
63 std::cout <<
" Gbltst-eigen $Id$ " << nTry <<
", " << nLayer
68 clock_t startTime = clock();
70 double sinLambda = 0.3;
71 double cosLambda = sqrt(1.0 - sinLambda * sinLambda);
73 double cosPhi = sqrt(1.0 - sinPhi * sinPhi);
75 double ti = cosLambda * cosPhi;
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.001, 0.001;
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 double bfac = 0.2998;
104 double step = 1.5 / cosLambda;
111 for (
unsigned int iTry = 1; iTry <= nTry; ++iTry) {
113 for (
unsigned int i = 0; i < 5; ++i) {
114 clPar[i] = clErr[i] *
unrm();
124 jacPointToPoint.setIdentity();
126 oldM2c.setIdentity();
128 std::vector<GblPoint> listOfPoints;
129 listOfPoints.reserve(2 * nLayer);
131 for (
unsigned int iLayer = 0; iLayer < nLayer; ++iLayer) {
134 double sinStereo = (iLayer % 2 == 0) ? 0. : 0.1;
135 double cosStereo = sqrt(1.0 - sinStereo * sinStereo);
136 Matrix<double, 3, 2> mDirT;
138 mDirT(1, 0) = cosStereo;
139 mDirT(2, 0) = sinStereo;
140 mDirT(1, 1) = -sinStereo;
141 mDirT(2, 1) = cosStereo;
142 double c1 = cosStereo * cosLambda * sinPhi + sinStereo * sinLambda;
143 double c2 = -sinStereo * cosLambda * sinPhi + cosStereo * sinLambda;
145 Matrix2d proM2l = uvDir * mDirT;
147 Matrix2d proL2m = proM2l.inverse();
151 meas2crvl(0, 0) = 1.;
152 meas2crvl.block<2, 2>(1, 1) = proM2l * ti;
153 meas2crvl.block<2, 2>(3, 3) = proM2l;
154 Matrix5d crvl2meas = meas2crvl.inverse();
156 GblPoint pointMeas(crvl2meas * jacPointToPoint * oldM2c);
158 Vector2d meas = proL2m * clPar.tail(2);
159 for (
unsigned int i = 0; i < 2; ++i) {
160 meas[i] += measErr[i] *
unrm();
165 listOfPoints.push_back(pointMeas);
169 clPar = jacPointToPoint * clPar;
171 if (iLayer < nLayer - 1) {
172 Vector2d scat(0., 0.);
174 GblPoint pointScat(crvl2meas * jacPointToPoint * meas2crvl);
177 double fac = scatPrec(0) * (1 - c1 * c1 - c2 * c2);
178 scatP(0, 0) = fac * (1 - c1 * c1);
179 scatP(0, 1) = fac * (-c1 * c2);
180 scatP(1, 0) = fac * (-c1 * c2);
181 scatP(1, 1) = fac * (1 - c2 * c2);
183 listOfPoints.push_back(pointScat);
185 for (
unsigned int i = 0; i < 2; ++i) {
186 clPar[i + 1] += scatErr[i] *
unrm();
189 clPar = jacPointToPoint * clPar;
208 traj.
fit(Chi2, Ndf, lostWeight);
239 LostSum += lostWeight;
243 clock_t endTime = clock();
244 double diff = endTime - startTime;
245 double cps = CLOCKS_PER_SEC;
246 std::cout <<
" Time elapsed " << diff / cps <<
" s" << std::endl;
247 std::cout <<
" Chi2/Ndf = " << Chi2Sum / NdfSum << std::endl;
248 std::cout <<
" Tracks fitted " << numFit << std::endl;
250 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 addScatterer(const Eigen::Vector2d &aResiduals, const Eigen::Matrix2d &aPrecision)
Add a thin scatterer to a 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