8 #include <tracking/modules/fitter/BaseRecoFitterModule.h>
10 #include <genfit/KalmanFitStatus.h>
11 #include <genfit/FitStatus.h>
12 #include <genfit/MaterialEffects.h>
13 #include <genfit/FieldManager.h>
15 #include <tracking/trackFitting/fitter/base/TrackFitter.h>
17 #include <simulation/monopoles/MonopoleConstants.h>
24 setDescription(
"Fit the given reco tracks with the given fitter parameters.");
42 "Use these particle hypotheses for fitting. Please use positive pdg codes only.",
49 "Configures whether the CDC Translators should be initialized by the FitterModule",
51 addParam(
"monopoleMagCharge", Monopoles::monopoleMagCharge,
52 "Sets monopole magnetic charge hypothesis if it is in the pdgCodesToUseForFitting",
53 Monopoles::monopoleMagCharge);
56 "If true changes seed charge of the RecoTrack to the one found by the track fit (if it differs).",
64 if (!genfit::MaterialEffects::getInstance()->isInitialized()) {
65 B2FATAL(
"Material effects not set up. Please use SetupGenfitExtrapolationModule.");
69 B2FATAL(
"Magnetic field not set up. Please use SetupGenfitExtrapolationModule.");
72 genfit::MaterialEffects::getInstance()->setMagCharge(Monopoles::monopoleMagCharge);
82 const std::shared_ptr<genfit::AbsFitter>& genfitFitter =
createFitter();
84 fitter.resetFitter(genfitFitter);
88 unsigned int recoTrackCounter = 0;
92 if (recoTrack.getNumberOfTotalHits() < 3) {
93 B2WARNING(
"Genfit2Module: only " << recoTrack.getNumberOfTotalHits() <<
" were assigned to the Track! " <<
94 "This Track will not be fitted!");
98 B2DEBUG(29,
"Fitting reco track candidate number " << recoTrackCounter);
99 B2DEBUG(29,
"Reco track candidate has start values: ");
100 B2DEBUG(29,
"Momentum: " << recoTrack.getMomentumSeed().X() <<
" " << recoTrack.getMomentumSeed().Y() <<
" " <<
101 recoTrack.getMomentumSeed().Z());
102 B2DEBUG(29,
"Position: " << recoTrack.getPositionSeed().X() <<
" " << recoTrack.getPositionSeed().Y() <<
" " <<
103 recoTrack.getPositionSeed().Z());
104 B2DEBUG(29,
"Charge: " << recoTrack.getChargeSeed());
105 B2DEBUG(29,
"Total number of hits assigned to the track: " << recoTrack.getNumberOfTotalHits());
109 bool flippedCharge =
false;
111 bool wasFitSuccessful;
113 if (pdgCodeToUseForFitting != Monopoles::c_monopolePDGCode) {
115 B2DEBUG(29,
"PDG: " << pdgCodeToUseForFitting);
116 wasFitSuccessful = fitter.fit(recoTrack, particleUsedForFitting);
120 && recoTrack.getCardinalRepresentation() == recoTrack.getTrackRepresentationForPDG(pdgCodeToUseForFitting)) {
123 flippedCharge |= recoTrack.getChargeSeed() != recoTrack.getMeasuredStateOnPlaneFromFirstHit().getCharge();
127 B2DEBUG(29,
"Refitting with opposite charge PDG: " << pdgCodeToUseForFitting);
134 wasFitSuccessful = fitter.fit(recoTrack, pdgCodeToUseForFitting);
136 const genfit::AbsTrackRep* trackRep = recoTrack.getTrackRepresentationForPDG(pdgCodeToUseForFitting);
139 B2FATAL(
"TrackRepresentation for PDG id " << pdgCodeToUseForFitting <<
" not present in RecoTrack although it " <<
140 "should have been created.");
143 B2DEBUG(28,
"-----> Fit results:");
144 if (wasFitSuccessful) {
147 B2DEBUG(28,
" Chi2 of the fit: " << kfs->
getChi2());
148 B2DEBUG(28,
" NDF of the fit: " << kfs->getBackwardNdf());
150 double pValue = recoTrack.getTrackFitStatus(trackRep)->getPVal();
151 B2DEBUG(28,
" pValue of the fit: " << pValue);
153 B2DEBUG(28,
"Charge after fit " << mSoP.getCharge());
154 B2DEBUG(28,
"Position after fit " << mSoP.getPos().X() <<
" " << mSoP.getPos().Y() <<
" " << mSoP.getPos().Z());
155 B2DEBUG(28,
"Momentum after fit " << mSoP.getMom().X() <<
" " << mSoP.getMom().Y() <<
" " << mSoP.getMom().Z());
157 B2DEBUG(28,
" fit failed!");
163 recoTrack.setChargeSeed(-recoTrack.getChargeSeed());
165 for (
const auto trackRep : recoTrack.getRepresentations()) {
167 fitter.fit(recoTrack, particleUsedForFitting);
170 recoTrackCounter += 1;
std::string m_param_bklmHitsStoreArrayName
StoreArray name of the BKLM hits.
bool m_param_resortHits
Resort the hits while fitting.
std::vector< unsigned int > m_param_pdgCodesToUseForFitting
Use these particle hypotheses for fitting.
std::string m_param_pxdHitsStoreArrayName
StoreArray name of the PXD hits.
void initialize() override
Initialize the store ararys and check for the material effects.
void event() override
Do the fitting using the created fitter.
std::string m_param_eklmHitsStoreArrayName
StoreArray name of the EKLM hits.
BaseRecoFitterModule()
Constructor.
bool m_correctSeedCharge
if true resets the charge seed of the RecoTrack if track fit prefers the other charge
std::string m_param_recoTracksStoreArrayName
StoreArray name of the input and output reco tracks.
std::string m_param_svdHitsStoreArrayName
StoreArray name of the SVD hits.
std::string m_param_cdcHitsStoreArrayName
StoreArray name of the CDC hits.
StoreArray< RecoTrack > m_recoTracks
RecoTracks StoreArray.
virtual std::shared_ptr< genfit::AbsFitter > createFitter() const =0
Method to create the used filter.
bool m_param_initializeCDCTranslators
Configures whether the CDC Translators should be initialized by the FitterModule especially useful fo...
Provides a type-safe way to pass members of the chargedStableSet set.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
This is the Reconstruction Event-Data Model Track.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
int getEntries() const
Get the number of objects in the array.
Algorithm class to handle the fitting of RecoTrack objects.
Abstract base class for a track representation.
static FieldManager * getInstance()
Get singleton instance.
Class where important numbers and properties of a fit can be stored.
double getChi2() const
Get chi^2 of the fit.
FitStatus for use with AbsKalmanFitter implementations.
#StateOnPlane with additional covariance matrix.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Abstract base class for different kinds of events.