Belle II Software  release-05-02-19
BaseRecoFitterModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/modules/fitter/BaseRecoFitterModule.h>
11 #include <tracking/dataobjects/RecoTrack.h>
12 
13 #include <genfit/KalmanFitStatus.h>
14 #include <genfit/FitStatus.h>
15 #include <genfit/MaterialEffects.h>
16 #include <genfit/FieldManager.h>
17 
18 #include <framework/datastore/StoreArray.h>
19 #include <tracking/trackFitting/fitter/base/TrackFitter.h>
20 
21 #include <simulation/monopoles/MonopoleConstants.h>
22 
23 using namespace std;
24 using namespace Belle2;
25 
26 BaseRecoFitterModule::BaseRecoFitterModule() :
27  Module()
28 {
29  setDescription("Fit the given reco tracks with the given fitter parameters.");
31 
32  addParam("recoTracksStoreArrayName", m_param_recoTracksStoreArrayName, "StoreArray name of the input and output reco tracks.",
34 
35  addParam("pxdHitsStoreArrayName", m_param_pxdHitsStoreArrayName, "StoreArray name of the input PXD hits.",
37  addParam("svdHitsStoreArrayName", m_param_svdHitsStoreArrayName, "StoreArray name of the input SVD hits.",
39  addParam("cdcHitsStoreArrayName", m_param_cdcHitsStoreArrayName, "StoreArray name of the input CDC hits.",
41  addParam("bklmHitsStoreArrayName", m_param_bklmHitsStoreArrayName, "StoreArray name of the input BKLM hits.",
43  addParam("eklmHitsStoreArrayName", m_param_eklmHitsStoreArrayName, "StoreArray name of the input EKLM hits.",
45 
46  addParam("pdgCodesToUseForFitting", m_param_pdgCodesToUseForFitting,
47  "Use these particle hypotheses for fitting. Please use positive pdg codes only.",
49 
50  addParam("resortHits", m_param_resortHits, "Resort the hits while fitting.",
52 
53  addParam("initializeCDCTranslators", m_param_initializeCDCTranslators,
54  "Configures whether the CDC Translators should be initialized by the FitterModule",
56  addParam("monopoleMagCharge", Monopoles::monopoleMagCharge,
57  "Sets monopole magnetic charge hypothesis if it is in the pdgCodesToUseForFitting",
58  Monopoles::monopoleMagCharge);
59 }
60 
62 {
64  recoTracks.isRequired();
65 
66  if (!genfit::MaterialEffects::getInstance()->isInitialized()) {
67  B2FATAL("Material effects not set up. Please use SetupGenfitExtrapolationModule.");
68  }
69 
70  if (!genfit::FieldManager::getInstance()->isInitialized()) {
71  B2FATAL("Magnetic field not set up. Please use SetupGenfitExtrapolationModule.");
72  }
73 
74  genfit::MaterialEffects::getInstance()->setMagCharge(Monopoles::monopoleMagCharge);
75 }
76 
77 
79 {
81 
82  // The used fitting algorithm class.
85 
86  const std::shared_ptr<genfit::AbsFitter>& genfitFitter = createFitter();
87  if (genfitFitter) {
88  fitter.resetFitter(genfitFitter);
89  }
90 
91  B2DEBUG(100, "Number of reco track candidates to process: " << recoTracks.getEntries());
92  unsigned int recoTrackCounter = 0;
93 
94  for (RecoTrack& recoTrack : recoTracks) {
95  if (recoTrack.getNumberOfTotalHits() < 3) {
96  B2WARNING("Genfit2Module: only " << recoTrack.getNumberOfTotalHits() << " were assigned to the Track! " <<
97  "This Track will not be fitted!");
98  continue;
99  }
100 
101  B2DEBUG(100, "Fitting reco track candidate number " << recoTrackCounter);
102  B2DEBUG(100, "Reco track candidate has start values: ");
103  B2DEBUG(100, "Momentum: " << recoTrack.getMomentumSeed().X() << " " << recoTrack.getMomentumSeed().Y() << " " <<
104  recoTrack.getMomentumSeed().Z());
105  B2DEBUG(100, "Position: " << recoTrack.getPositionSeed().X() << " " << recoTrack.getPositionSeed().Y() << " " <<
106  recoTrack.getPositionSeed().Z());
107  B2DEBUG(100, "Charge: " << recoTrack.getChargeSeed());
108  B2DEBUG(100, "Total number of hits assigned to the track: " << recoTrack.getNumberOfTotalHits());
109 
110  for (const unsigned int pdgCodeToUseForFitting : m_param_pdgCodesToUseForFitting) {
111  bool wasFitSuccessful;
112  if (pdgCodeToUseForFitting != Monopoles::c_monopolePDGCode) {
113  Const::ChargedStable particleUsedForFitting(pdgCodeToUseForFitting);
114  B2DEBUG(100, "PDG: " << pdgCodeToUseForFitting);
115  wasFitSuccessful = fitter.fit(recoTrack, particleUsedForFitting);
116  } else {
117  // Different call signature for monopoles in order not to change Const::ChargedStable types
118  wasFitSuccessful = fitter.fit(recoTrack, pdgCodeToUseForFitting);
119  }
120  const genfit::AbsTrackRep* trackRep = recoTrack.getTrackRepresentationForPDG(pdgCodeToUseForFitting);
121 
122  if (!trackRep) {
123  B2FATAL("TrackRepresentation for PDG id " << pdgCodeToUseForFitting << " not present in RecoTrack although it " <<
124  "should have been created.");
125  }
126 
127  B2DEBUG(99, "-----> Fit results:");
128  if (wasFitSuccessful) {
129  const genfit::FitStatus* fs = recoTrack.getTrackFitStatus(trackRep);
130  const genfit::KalmanFitStatus* kfs = dynamic_cast<const genfit::KalmanFitStatus*>(fs);
131  B2DEBUG(99, " Chi2 of the fit: " << kfs->getChi2());
132  B2DEBUG(99, " NDF of the fit: " << kfs->getBackwardNdf());
133  //Calculate probability
134  double pValue = recoTrack.getTrackFitStatus(trackRep)->getPVal();
135  B2DEBUG(99, " pValue of the fit: " << pValue);
136  const genfit::MeasuredStateOnPlane& mSoP = recoTrack.getMeasuredStateOnPlaneFromFirstHit(trackRep);
137  B2DEBUG(99, "Charge after fit " << mSoP.getCharge());
138  B2DEBUG(99, "Position after fit " << mSoP.getPos().X() << " " << mSoP.getPos().Y() << " " << mSoP.getPos().Z());
139  B2DEBUG(99, "Momentum after fit " << mSoP.getMom().X() << " " << mSoP.getMom().Y() << " " << mSoP.getMom().Z());
140  } else {
141  B2DEBUG(99, " fit failed!");
142  }
143  }
144  recoTrackCounter += 1;
145  }
146 }
genfit::FitStatus::getChi2
double getChi2() const
Get chi^2 of the fit.
Definition: FitStatus.h:120
Belle2::BaseRecoFitterModule::m_param_eklmHitsStoreArrayName
std::string m_param_eklmHitsStoreArrayName
StoreArray name of the EKLM hits.
Definition: BaseRecoFitterModule.h:70
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
genfit::MeasuredStateOnPlane
#StateOnPlane with additional covariance matrix.
Definition: MeasuredStateOnPlane.h:39
genfit::KalmanFitStatus
FitStatus for use with AbsKalmanFitter implementations.
Definition: KalmanFitStatus.h:36
Belle2::Module::c_ParallelProcessingCertified
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:82
Belle2::BaseRecoFitterModule::m_param_resortHits
bool m_param_resortHits
Resort the hits while fitting.
Definition: BaseRecoFitterModule.h:74
Belle2::BaseRecoFitterModule::initialize
void initialize() override
Initialize the store ararys and check for the material effects.
Definition: BaseRecoFitterModule.cc:61
genfit::AbsTrackRep
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
Belle2::BaseRecoFitterModule::createFitter
virtual std::shared_ptr< genfit::AbsFitter > createFitter() const =0
Method to create the used filter.
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2::TrackFitter
Algorithm class to handle the fitting of RecoTrack objects.
Definition: TrackFitter.h:116
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::BaseRecoFitterModule::m_param_pxdHitsStoreArrayName
std::string m_param_pxdHitsStoreArrayName
StoreArray name of the PXD hits.
Definition: BaseRecoFitterModule.h:62
Belle2::BaseRecoFitterModule::event
void event() override
Do the fitting using the created fitter.
Definition: BaseRecoFitterModule.cc:78
Belle2::BaseRecoFitterModule::m_param_recoTracksStoreArrayName
std::string m_param_recoTracksStoreArrayName
StoreArray name of the input and output reco tracks.
Definition: BaseRecoFitterModule.h:60
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::BaseRecoFitterModule::m_param_pdgCodesToUseForFitting
std::vector< unsigned int > m_param_pdgCodesToUseForFitting
Use these particle hypotheses for fitting.
Definition: BaseRecoFitterModule.h:72
Belle2::Module::addParam
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:562
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::BaseRecoFitterModule::m_param_cdcHitsStoreArrayName
std::string m_param_cdcHitsStoreArrayName
StoreArray name of the CDC hits.
Definition: BaseRecoFitterModule.h:66
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::BaseRecoFitterModule::m_param_svdHitsStoreArrayName
std::string m_param_svdHitsStoreArrayName
StoreArray name of the SVD hits.
Definition: BaseRecoFitterModule.h:64
genfit::FieldManager::getInstance
static FieldManager * getInstance()
Get singleton instance.
Definition: FieldManager.h:119
genfit::FitStatus
Class where important numbers and properties of a fit can be stored.
Definition: FitStatus.h:80
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::BaseRecoFitterModule::m_param_bklmHitsStoreArrayName
std::string m_param_bklmHitsStoreArrayName
StoreArray name of the BKLM hits.
Definition: BaseRecoFitterModule.h:68
Belle2::BaseRecoFitterModule::m_param_initializeCDCTranslators
bool m_param_initializeCDCTranslators
Configures whether the CDC Translators should be initialized by the FitterModule especially useful fo...
Definition: BaseRecoFitterModule.h:78