75#include <Math/SMatrix.h>
77#include <TVectorDfwd.h>
115 bool fitQoverP =
true;
118 if (!(Bfield > 1.e-16))
125 double lostWeight = 0.;
151 unsigned int nFailed = 0;
154 std::vector<std::string> gblIterations;
161 int nscat = 0, nmeas = 0, ndummy = 0;
163 for(
unsigned int ip = 0;ip<points.size(); ip++) {
184 for (
unsigned int ip = 0; ip < trk->
getNumPoints(); ip++) {
188 prevFitterInfo = currFitterInfo;
207 cout <<
"-------------------------------------------------------" << endl;
208 cout <<
" GBL processed genfit::Track " << endl;
209 cout <<
"-------------------------------------------------------" << endl;
210 cout <<
" # Track Points : " << npoints_all << endl;
211 cout <<
" # Meas. Points : " << npoints_meas << endl;
214 cout <<
" (" << ndummy <<
" dummy) ";
216 cout <<
" # GBL points meas : " << nmeas << endl;
217 cout <<
" # GBL points scat : " << nscat << endl;
218 cout <<
"-------------- GBL Fit Results ----------- Iteration " << iIter+1 <<
" " << ((iIter < gblIterations.size()) ? gblIterations[iIter] :
"") << endl;
219 cout <<
" Fit q/p parameter : " << (gblfs->
hasCurvature() ? (
"True") : (
"False")) << endl;
220 cout <<
" Valid trajectory : " << ((traj.
isValid()) ? (
"True") : (
"False")) << endl;
221 cout <<
" Fit result : " << fitRes <<
" (0 for success)" << endl;
222 cout <<
" GBL track NDF : " << Ndf <<
" (-1 for failure)" << endl;
223 cout <<
" GBL track Chi2 : " << Chi2 << endl;
224 cout <<
" GBL track P-value : " << TMath::Prob(Chi2, Ndf) << endl;
225 cout <<
"-------------------------------------------------------" << endl;
255 double arcLenPos = 0;
258 for (
int ipoint_meas = 0; ipoint_meas < npoints_meas - 1; ipoint_meas++) {
276 std::vector<gbl::GblPoint> thePoints;
280 for (
unsigned int ip = 0; ip < trk->
getNumPoints(); ip++) {
296 for (
unsigned int ip = 0; ip < trk->
getNumPoints(); ip++) {
316 double& theta,
double& s,
double& ds,
317 const double p,
const double mass,
const double charge,
318 const std::vector<genfit::MatStep>& steps)
const {
319 theta = 0.; s = 0.; ds = 0.; length = 0;
320 if (steps.empty())
return;
335 for (
unsigned int i = 0; i < steps.size(); i++) {
336 const MatStep step = steps.at(i);
345 sumxx += rho * (xmax - xmin);
347 sumx2x2 += rho * (xmax * xmax - xmin * xmin) / 2.;
349 sumx3x3 += rho * (xmax * xmax * xmax - xmin * xmin * xmin) / 3.;
352 if (sumxx < 1.0e-10)
return;
356 double beta = p / sqrt(p * p + mass * mass);
357 theta = (0.0136 / p / beta) * fabs(charge) * sqrt(sumxx) * (1. + 0.038 * log(sumxx));
363 double N = 1. / sumxx;
368 double ds_2 = N * (sumx3x3 - 2. * sumx2x2 * s + sumxx * s * s);
383 TMatrixD jacPointToPoint(dim, dim);
384 jacPointToPoint.UnitMatrix();
395 double sumTrackLen = 0;
397 TMatrixDSym noise; TVectorD deltaState;
400 for (
int ipoint_meas = 0; ipoint_meas < npoints_meas; ipoint_meas++) {
406 TVector3 trackDir = rep->
getDir(reference);
408 double trackMomMag = rep->
getMomMag(reference);
410 double particleCharge = rep->
getCharge(reference);
412 double particleMass = rep->
getMass(reference);
414 double trackLen = 0., scatTheta = 0., scatSMean = 0., scatDeltaS = 0.;
416 double theta1 = 0., theta2 = 0., s1 = 0., s2 = 0.;
418 TMatrixD jacMeas2Scat(dim, dim);
419 jacMeas2Scat.UnitMatrix();
423 if (ipoint_meas >= npoints_meas - 1) {
443 TVector3 segmentEntry = refCopy.
getPos();
445 TVector3 segmentExit = refCopy.
getPos();
457 s1 = 0.; s2 = scatSMean + scatDeltaS * scatDeltaS / (scatSMean - s1);
458 theta1 = sqrt(scatTheta * scatTheta * scatDeltaS * scatDeltaS / (scatDeltaS * scatDeltaS + (scatSMean - s1) * (scatSMean - s1)));
459 theta2 = sqrt(scatTheta * scatTheta * (scatSMean - s1) * (scatSMean - s1) / (scatDeltaS * scatDeltaS + (scatSMean - s1) * (scatSMean - s1)));
502 for (
unsigned int itp = 0; itp < trk->
getNumPoints(); itp++) {
503 if (trk->
getPoint(itp) == point_meas) {
520 cout <<
" ERROR: The extrapolation to measurement point " << (ipoint_meas + 2) <<
" stepped back by " << nextStep <<
"cm !!! Track will be cut before this point." << endl;
531 cout <<
" ERROR: The extrapolation to measurement point " << (ipoint_meas + 2) <<
" stepped back by " << nextStep <<
"cm !!! Track will be cut before this point." << endl;
537 sumTrackLen += trackLen;
unsigned int hasMeasurement() const
Check for measurement at a point.
bool hasScatterer() const
Check for scatterer at a point.
unsigned int fit(double &Chi2, int &Ndf, double &lostWeight, std::string optionList="")
Perform fit of (valid) trajectory.
bool isValid() const
Retrieve validity of trajectory.
unsigned int getNumPoints() const
Retrieve number of point from trajectory.
virtual SharedPlanePtr constructPlane(const StateOnPlane &state) const =0
Abstract base class for a track representation.
virtual double extrapolateToPlane(StateOnPlane &state, const genfit::SharedPlanePtr &plane, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to plane, and returns the extrapolation length and, via reference,...
TVector3 getDir(const StateOnPlane &state) const
Get the direction vector of a state.
virtual std::vector< genfit::MatStep > getSteps() const =0
Get stepsizes and material properties of crossed materials of the last extrapolation.
virtual void setTime(StateOnPlane &state, double time) const =0
Set time at which the state was defined.
virtual void setPosMom(StateOnPlane &state, const TVector3 &pos, const TVector3 &mom) const =0
Set position and momentum of state.
virtual double getCharge(const StateOnPlane &state) const =0
Get the (fitted) charge of a state. This is not always equal the pdg charge (e.g. if the charge sign ...
double getMass(const StateOnPlane &state) const
Get tha particle mass in GeV/c^2.
virtual double getMomMag(const StateOnPlane &state) const =0
get the magnitude of the momentum in GeV.
virtual void getForwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const =0
Get the jacobian and noise matrix of the last extrapolation.
virtual unsigned int getDim() const =0
Get the dimension of the state vector used by the track representation.
virtual double extrapolateBy(StateOnPlane &state, double step, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state by step (cm) and returns the extrapolation length and, via reference,...
TVector3 getFieldVal(const TVector3 &position)
This does NOT use the cache!
static FieldManager * getInstance()
Get singleton instance.
void setNdf(const double &ndf)
void setIsFitConvergedPartially(bool fitConverged=true)
void setIsFitted(bool fitted=true)
void setNFailedPoints(int nFailedPoints)
void setIsFitConvergedFully(bool fitConverged=true)
void setChi2(const double &chi2)
void setCharge(double charge)
FitStatus for use with GblFitter.
void setTrackLen(double trackLen)
void setIsFittedWithReferenceTrack(bool fittedWithReferenceTrack=true)
void setNumIterations(unsigned int numIterations)
void setCurvature(bool useCurvature)
unsigned int m_recalcJacobians
unsigned int m_externalIterations
void updateGblInfo(gbl::GblTrajectory &traj, genfit::Track *trk, const genfit::AbsTrackRep *rep)
Populate all fitter infos in track for rep with results of trajectory fit.
void cleanGblInfo(Track *trk, const AbsTrackRep *rep) const
Remove all previous gbl fitter data from track Also removes trackpoints without measurement.
void processTrackWithRep(Track *trk, const AbsTrackRep *rep, bool resortHits=false) override
double constructGblInfo(Track *trk, const AbsTrackRep *rep)
Propagate seed, populate track with scatterers and GblFitterInfos with reference state set.
std::string m_gblInternalIterations
void getScattererFromMatList(double &length, double &theta, double &s, double &ds, const double p, const double mass, const double charge, const std::vector< genfit::MatStep > &steps) const
Evaluates moments of radiation length distribution from list of material steps and computes parameter...
GblTrackSegmentController * m_segmentController
void setTrackSegmentController(GblTrackSegmentController *controler)
void sortHits(Track *trk, const AbsTrackRep *rep) const
Sort hits in track by arc-len using extrapolation.
std::vector< gbl::GblPoint > collectGblPoints(genfit::Track *trk, const genfit::AbsTrackRep *rep)
Constructs all GBL points and returns them in vector for trajectory construction.
bool m_enableIntermediateScatterer
Collects information needed and produced by a GblFitter/GBL and is specific to one AbsTrackRep of the...
void updateFitResults(gbl::GblTrajectory &traj)
Update fitter info from GBL fit results.
void recalculateJacobian(GblFitterInfo *prevFitterInfo)
Re-extrapolates between prevFitterInfo and this point using forward state to update the Jacobian (if ...
void setJacobian(TMatrixD jacobian)
Set the Jacobian for further GblPoint construction.
gbl::GblPoint constructGblPoint()
Collect all data and create a GblPoint.
TrackSegmentController for use with GblFitter.
A state with arbitrary dimension defined in a DetPlane.
double extrapolateToPlane(const SharedPlanePtr &plane, bool stopAtBoundary=false, bool calcJacobianNoise=false)
const SharedPlanePtr & getPlane() const
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
TrackPoint * getPoint(int id) const
unsigned int getNumPoints() const
const TVectorD & getStateSeed() const
double getTimeSeed() const
TrackPoint * getPointWithMeasurement(int id) const
unsigned int getNumPointsWithMeasurement() const
void insertPoint(TrackPoint *point, int id=-1)
Insert TrackPoint BEFORE TrackPoint with position id, if id >= 0.
bool sort()
Sort TrackPoint and according to their sorting parameters.
const MeasuredStateOnPlane & getFittedState(int id=0, const AbsTrackRep *rep=nullptr, bool biased=true) const
Shortcut to get FittedStates.
void setFitStatus(FitStatus *fitStatus, const AbsTrackRep *rep)
Object containing AbsMeasurement and AbsFitterInfo objects.
bool hasFitterInfo(const AbsTrackRep *rep) const
void deleteFitterInfo(const AbsTrackRep *rep)
void setScatterer(ThinScatterer *scatterer)
bool hasRawMeasurements() const
void setSortingParameter(double sortingParameter)
void setFitterInfo(genfit::AbsFitterInfo *fitterInfo)
Takes Ownership.
AbsFitterInfo * getFitterInfo(const AbsTrackRep *rep=nullptr) const
Get fitterInfo for rep. Per default, use cardinal rep.
AbsMeasurement * getRawMeasurement(int i=0) const
double getSortingParameter() const
Namespace for the general broken lines package.
Defines for I/O streams used for error and debug printing.
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
Simple struct containing MaterialProperties and stepsize in the material.
double radiationLength
Mass number in g / mol.