60 #include "../include/GblFitStatus.h"
75 #include <Math/SMatrix.h>
77 #include <TVectorDfwd.h>
85 using namespace genfit;
90 GblFitter::~GblFitter() {
91 if (m_segmentController) {
92 delete m_segmentController;
93 m_segmentController =
nullptr;
99 if (m_segmentController) {
100 delete m_segmentController;
101 m_segmentController =
nullptr;
103 m_segmentController = controler;
108 cleanGblInfo(trk, rep);
115 bool fitQoverP =
true;
118 if (!(Bfield > 1.
e-16))
125 double lostWeight = 0.;
139 constructGblInfo(trk, rep)
146 if (m_externalIterations < 1)
151 unsigned int nFailed = 0;
153 std::vector<std::string> gblIterations;
154 gblIterations.push_back(m_gblInternalIterations);
158 for (
unsigned int iIter = 0; iIter < m_externalIterations; iIter++) {
160 int nscat = 0, nmeas = 0, ndummy = 0;
161 std::vector<gbl::GblPoint> points = collectGblPoints(trk, rep);
162 for(
unsigned int ip = 0;
ip<points.size();
ip++) {
173 fitRes = traj.
fit(Chi2, Ndf, lostWeight, (iIter == m_externalIterations - 1) ? m_gblInternalIterations :
"");
176 updateGblInfo(traj, trk, rep);
180 if (m_recalcJacobians > iIter) {
187 prevFitterInfo = currFitterInfo;
206 cout <<
"-------------------------------------------------------" << endl;
207 cout <<
" GBL processed genfit::Track " << endl;
208 cout <<
"-------------------------------------------------------" << endl;
209 cout <<
" # Track Points : " << npoints_all << endl;
210 cout <<
" # Meas. Points : " << npoints_meas << endl;
211 cout <<
" # GBL points all : " << traj.getNumPoints();
213 cout <<
" (" << ndummy <<
" dummy) ";
215 cout <<
" # GBL points meas : " << nmeas << endl;
216 cout <<
" # GBL points scat : " << nscat << endl;
217 cout <<
"-------------- GBL Fit Results ----------- Iteration " << iIter+1 <<
" " << ((iIter < gblIterations.size()) ? gblIterations[iIter] :
"") << endl;
218 cout <<
" Fit q/p parameter : " << (gblfs->
hasCurvature() ? (
"True") : (
"False")) << endl;
219 cout <<
" Valid trajectory : " << ((traj.isValid()) ? (
"True") : (
"False")) << endl;
220 cout <<
" Fit result : " << fitRes <<
" (0 for success)" << endl;
221 cout <<
" GBL track NDF : " << Ndf <<
" (-1 for failure)" << endl;
222 cout <<
" GBL track Chi2 : " << Chi2 << endl;
223 cout <<
" GBL track P-value : " << TMath::Prob(Chi2, Ndf) << endl;
224 cout <<
"-------------------------------------------------------" << endl;
254 double arcLenPos = 0;
257 for (
int ipoint_meas = 0; ipoint_meas < npoints_meas - 1; ipoint_meas++) {
275 std::vector<gbl::GblPoint> thePoints;
315 double&
theta,
double&
s,
double& ds,
316 const double p,
const double mass,
const double charge,
317 const std::vector<genfit::MatStep>&
steps)
const {
318 theta = 0.; s = 0.; ds = 0.; length = 0;
319 if (steps.empty())
return;
333 for (
unsigned int i = 0; i < steps.size(); i++) {
343 sumxx += rho * (xmax -
xmin);
345 sumx2x2 += rho * (xmax * xmax - xmin *
xmin) / 2.;
347 sumx3x3 += rho * (xmax * xmax * xmax - xmin * xmin *
xmin) / 3.;
350 if (sumxx < 1.0
e-10)
return;
354 double beta = p / sqrt(p * p + mass * mass);
355 theta = (0.0136 / p / beta) * fabs(charge) * sqrt(sumxx) * (1. + 0.038 * log(sumxx));
361 double N = 1. / sumxx;
366 double ds_2 = N * (sumx3x3 - 2. * sumx2x2 * s + sumxx * s *
s);
381 TMatrixD jacPointToPoint(dim, dim);
382 jacPointToPoint.UnitMatrix();
393 double sumTrackLen = 0;
395 TMatrixDSym noise; TVectorD deltaState;
398 for (
int ipoint_meas = 0; ipoint_meas < npoints_meas; ipoint_meas++) {
404 TVector3 trackDir = rep->
getDir(reference);
406 double trackMomMag = rep->
getMomMag(reference);
408 double particleCharge = rep->
getCharge(reference);
410 double particleMass = rep->
getMass(reference);
412 double trackLen = 0., scatTheta = 0., scatSMean = 0., scatDeltaS = 0.;
414 double theta1 = 0., theta2 = 0.,
s1 = 0.,
s2 = 0.;
416 TMatrixD jacMeas2Scat(dim, dim);
417 jacMeas2Scat.UnitMatrix();
421 if (ipoint_meas >= npoints_meas - 1) {
441 TVector3 segmentEntry = refCopy.
getPos();
443 TVector3 segmentExit = refCopy.
getPos();
455 s1 = 0.;
s2 = scatSMean + scatDeltaS * scatDeltaS / (scatSMean -
s1);
456 theta1 = sqrt(scatTheta * scatTheta * scatDeltaS * scatDeltaS / (scatDeltaS * scatDeltaS + (scatSMean - s1) * (scatSMean - s1)));
457 theta2 = sqrt(scatTheta * scatTheta * (scatSMean - s1) * (scatSMean - s1) / (scatDeltaS * scatDeltaS + (scatSMean - s1) * (scatSMean - s1)));
460 if (m_segmentController)
461 m_segmentController->controlTrackSegment(segmentEntry, segmentExit, scatTheta,
this);
464 if (m_enableScatterers && !m_enableIntermediateScatterer) {
467 }
else if (!m_enableScatterers) {
500 for (
unsigned int itp = 0; itp < trk->
getNumPoints(); itp++) {
501 if (trk->
getPoint(itp) == point_meas) {
518 cout <<
" ERROR: The extrapolation to measurement point " << (ipoint_meas + 2) <<
" stepped back by " << nextStep <<
"cm !!! Track will be cut before this point." << endl;
529 cout <<
" ERROR: The extrapolation to measurement point " << (ipoint_meas + 2) <<
" stepped back by " << nextStep <<
"cm !!! Track will be cut before this point." << endl;
535 sumTrackLen += trackLen;