8#include <tracking/trackFitting/fitter/base/TrackFitter.h>
10#include <tracking/dataobjects/RecoTrack.h>
12#include <genfit/AbsTrackRep.h>
13#include <genfit/FitStatus.h>
14#include <genfit/AbsFitter.h>
15#include <genfit/DAF.h>
16#include <genfit/KalmanFitterInfo.h>
26 int currentPdgCode = particleType.
getPDGCode();
28 const auto& pdgParticleCharge = particleType.
getParticlePDG()->Charge();
32 B2ASSERT(
"Charge of candidate and PDG particle don't match. (Code assumes |q| = 1).",
33 fabs(pdgParticleCharge) == fabs(recoTrackCharge * 3.0));
39 if (std::signbit(pdgParticleCharge) != std::signbit(recoTrackCharge))
42 return currentPdgCode;
60 return fit(recoTrack, trackRepresentation, resortHits);
68 return fit(recoTrack, trackRepresentation, resortHits);
77 B2DEBUG(28,
"resortHits is set to " << resortHits <<
" when fitting the tracks");
79 }
catch (genfit::Exception& e) {
80 B2WARNING(e.getExcString());
91 genfit::KalmanFitterInfo* kalmanFitterInfo = trackPoint->getKalmanFitterInfo(&trackRepresentation);
92 if (not kalmanFitterInfo) {
93 recoHitInformation->setFlag(RecoHitInformation::RecoHitFlag::c_dismissedByFit);
95 std::vector<double> weights = kalmanFitterInfo->getWeights();
96 for (
const double weight : weights) {
98 recoHitInformation->setFlag(RecoHitInformation::RecoHitFlag::c_dismissedByFit);
110 B2ASSERT(
"No fitter was loaded! Have you reset the fitter to an invalid one?",
m_fitter);
115 B2WARNING(
"No track points (measurements) were added to this reco track. Have you used an invalid measurement adder?");
119 const std::vector<genfit::AbsTrackRep*>& trackRepresentations = recoTrack.
getRepresentations();
120 if (std::find(trackRepresentations.begin(), trackRepresentations.end(), trackRepresentation) == trackRepresentations.end()) {
121 B2FATAL(
"The TrackRepresentation provided is not part of the Reco Track.");
126 B2DEBUG(100,
"Hit content did not change, track representation is already present and you used only default parameters." <<
127 "I will not fit the track again. If you still want to do so, set the dirty flag of the track.");
131 const auto previousSetting = gErrorIgnoreLevel;
133 auto fitWithoutCheckResult =
fitWithoutCheck(recoTrack, *trackRepresentation, resortHits);
134 gErrorIgnoreLevel = previousSetting;
135 return fitWithoutCheckResult;
141 B2FATAL(
"DAF parameters are not available.");
142 genfit::DAF* dafFitter =
new genfit::DAF(
m_DAFparameters->getAnnealingScheme(),
157 if (DAFparams ==
nullptr)
158 B2FATAL(
"DAF parameters are not available.");
Provides a type-safe way to pass members of the chargedStableSet set.
int getPDGCode() const
PDG code.
const TParticlePDG * getParticlePDG() const
Accessor for ROOT TParticlePDG object.
static const ChargedStable pion
charged pion particle
The payload containing the DAF parameters.
int getMaximumIterations() const
Get the maximum number of iterations of annealing scheme.
std::tuple< float, float, int > getAnnealingScheme() const
Get the start and end temperatures and number of iterations for the annealing scheme returns a tuple ...
int getMaximumFailedHits() const
Get the maximum number of failed hits after which the fit should be cancelled.
int getMinimumIterationsForPVal() const
Get the minimum number of iterations for pValue check.
float getDeltaPValue() const
Get the DeltaPValue for p-value convergence criterion.
int getMinimumIterations() const
Get the minimum number of iterations of annealing scheme.
float getProbabilityCut() const
Get the probability cut for the weight calculation for the hits.
float getDeltaWeight() const
Get the DeltaWeight for weight convergence criterion.
bool addMeasurements(RecoTrack &recoTrack) const
After you have filled the internal storage with measurement creators (either by providing your own or...
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
static genfit::AbsTrackRep * createOrReturnRKTrackRep(RecoTrack &recoTrack, int PDGcode)
Checks if a TrackRap for the PDG id of the RecoTrack (and its charge conjugate) does already exit and...
This is the Reconstruction Event-Data Model Track.
const std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
genfit::AbsTrackRep * getCardinalRepresentation() const
Get a pointer to the cardinal track representation. You are not allowed to modify or delete it!
void setDirtyFlag(const bool &dirtyFlag=true)
Set to true, if you want to rebuild the measurements and do the fit independent on changes of the hit...
bool hasTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Check, if there is a fit status for the given representation or for the cardinal one.
const genfit::TrackPoint * getCreatedTrackPoint(const RecoHitInformation *recoHitInformation) const
Get a pointer to the TrackPoint that was created from this hit.
std::vector< RecoHitInformation * > getRecoHitInformations(bool getSorted=false) const
Return a list of all RecoHitInformations associated with the RecoTrack.
bool getDirtyFlag() const
This returns true, if a hit was added after the last fit and measurement creation and a refit should ...
void deleteFittedInformationForRepresentation(const genfit::AbsTrackRep *rep)
Delete all fitted information for the given representations.
short int getChargeSeed() const
Return the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
DBObjPtr< DAFparameters > m_DAFparameters
DAF parameters Database OjbPtr.
static int createCorrectPDGCodeForChargedStable(const Const::ChargedStable &particleType, const RecoTrack &recoTrack)
Helper function to multiply the PDG code of a charged stable with the charge of the reco track (if ne...
static constexpr double s_defaultProbCut
Default probCut for the default DAF fitter.
void resetFitterToUserSettings(DAFparameters *DAFparams)
Use the user settings of the fitter to fit the reco tracks.
bool fitWithoutCheck(RecoTrack &recoTrack, const genfit::AbsTrackRep &trackRepresentation, bool resortHits=false) const
Helper function to do the fit.
static constexpr double s_defaultDeltaPValue
Default deltaPValue for the default DAF fitter.
void resetFitterToDBSettings()
Use the DB settings of the fitter to fit the reco tracks.
bool fit(RecoTrack &recoTrack, genfit::AbsTrackRep *trackRepresentation, bool resortHits=false) const
Fit a reco track with a given non-default track representation.
void resetFitter(const std::shared_ptr< genfit::AbsFitter > &fitter)
Set the internal storage of the fitter to a provided one, if you want to use non-default settings.
MeasurementAdder m_measurementAdder
The measurement adder algorithm class.
Int_t m_gErrorIgnoreLevel
Control the output level of the ROOT functions used by the GenFit fitter. Default is increased from k...
static constexpr unsigned int s_defaultMaxFailedHits
Default maxFailedHits for the default DAF fitter.
std::shared_ptr< genfit::AbsFitter > m_fitter
The internal storage of the used fitting algorithms.
bool m_skipDirtyCheck
Flag to skip the dirty flag check which is needed when using non-default fitters.
void resetFitterToCosmicsSettings()
Use the settings of the fitter to fit the reco tracks for cosmics data.
Abstract base class for different kinds of events.