Belle II Software  release-06-01-15
BaseRecoFitterModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/modules/fitter/BaseRecoFitterModule.h>
9 #include <tracking/dataobjects/RecoTrack.h>
10 
11 #include <genfit/KalmanFitStatus.h>
12 #include <genfit/FitStatus.h>
13 #include <genfit/MaterialEffects.h>
14 #include <genfit/FieldManager.h>
15 
16 #include <framework/datastore/StoreArray.h>
17 #include <tracking/trackFitting/fitter/base/TrackFitter.h>
18 
19 #include <simulation/monopoles/MonopoleConstants.h>
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 BaseRecoFitterModule::BaseRecoFitterModule() :
25  Module()
26 {
27  setDescription("Fit the given reco tracks with the given fitter parameters.");
29 
30  addParam("recoTracksStoreArrayName", m_param_recoTracksStoreArrayName, "StoreArray name of the input and output reco tracks.",
32 
33  addParam("pxdHitsStoreArrayName", m_param_pxdHitsStoreArrayName, "StoreArray name of the input PXD hits.",
35  addParam("svdHitsStoreArrayName", m_param_svdHitsStoreArrayName, "StoreArray name of the input SVD hits.",
37  addParam("cdcHitsStoreArrayName", m_param_cdcHitsStoreArrayName, "StoreArray name of the input CDC hits.",
39  addParam("bklmHitsStoreArrayName", m_param_bklmHitsStoreArrayName, "StoreArray name of the input BKLM hits.",
41  addParam("eklmHitsStoreArrayName", m_param_eklmHitsStoreArrayName, "StoreArray name of the input EKLM hits.",
43 
44  addParam("pdgCodesToUseForFitting", m_param_pdgCodesToUseForFitting,
45  "Use these particle hypotheses for fitting. Please use positive pdg codes only.",
47 
48  addParam("resortHits", m_param_resortHits, "Resort the hits while fitting.",
50 
51  addParam("initializeCDCTranslators", m_param_initializeCDCTranslators,
52  "Configures whether the CDC Translators should be initialized by the FitterModule",
54  addParam("monopoleMagCharge", Monopoles::monopoleMagCharge,
55  "Sets monopole magnetic charge hypothesis if it is in the pdgCodesToUseForFitting",
56  Monopoles::monopoleMagCharge);
57 }
58 
60 {
62  recoTracks.isRequired();
63 
64  if (!genfit::MaterialEffects::getInstance()->isInitialized()) {
65  B2FATAL("Material effects not set up. Please use SetupGenfitExtrapolationModule.");
66  }
67 
68  if (!genfit::FieldManager::getInstance()->isInitialized()) {
69  B2FATAL("Magnetic field not set up. Please use SetupGenfitExtrapolationModule.");
70  }
71 
72  genfit::MaterialEffects::getInstance()->setMagCharge(Monopoles::monopoleMagCharge);
73 }
74 
75 
77 {
79 
80  // The used fitting algorithm class.
83 
84  const std::shared_ptr<genfit::AbsFitter>& genfitFitter = createFitter();
85  if (genfitFitter) {
86  fitter.resetFitter(genfitFitter);
87  }
88 
89  B2DEBUG(100, "Number of reco track candidates to process: " << recoTracks.getEntries());
90  unsigned int recoTrackCounter = 0;
91 
92  for (RecoTrack& recoTrack : recoTracks) {
93  if (recoTrack.getNumberOfTotalHits() < 3) {
94  B2WARNING("Genfit2Module: only " << recoTrack.getNumberOfTotalHits() << " were assigned to the Track! " <<
95  "This Track will not be fitted!");
96  continue;
97  }
98 
99  B2DEBUG(100, "Fitting reco track candidate number " << recoTrackCounter);
100  B2DEBUG(100, "Reco track candidate has start values: ");
101  B2DEBUG(100, "Momentum: " << recoTrack.getMomentumSeed().X() << " " << recoTrack.getMomentumSeed().Y() << " " <<
102  recoTrack.getMomentumSeed().Z());
103  B2DEBUG(100, "Position: " << recoTrack.getPositionSeed().X() << " " << recoTrack.getPositionSeed().Y() << " " <<
104  recoTrack.getPositionSeed().Z());
105  B2DEBUG(100, "Charge: " << recoTrack.getChargeSeed());
106  B2DEBUG(100, "Total number of hits assigned to the track: " << recoTrack.getNumberOfTotalHits());
107 
108  for (const unsigned int pdgCodeToUseForFitting : m_param_pdgCodesToUseForFitting) {
109  bool wasFitSuccessful;
110  if (pdgCodeToUseForFitting != Monopoles::c_monopolePDGCode) {
111  Const::ChargedStable particleUsedForFitting(pdgCodeToUseForFitting);
112  B2DEBUG(100, "PDG: " << pdgCodeToUseForFitting);
113  wasFitSuccessful = fitter.fit(recoTrack, particleUsedForFitting);
114  } else {
115  // Different call signature for monopoles in order not to change Const::ChargedStable types
116  wasFitSuccessful = fitter.fit(recoTrack, pdgCodeToUseForFitting);
117  }
118  const genfit::AbsTrackRep* trackRep = recoTrack.getTrackRepresentationForPDG(pdgCodeToUseForFitting);
119 
120  if (!trackRep) {
121  B2FATAL("TrackRepresentation for PDG id " << pdgCodeToUseForFitting << " not present in RecoTrack although it " <<
122  "should have been created.");
123  }
124 
125  B2DEBUG(99, "-----> Fit results:");
126  if (wasFitSuccessful) {
127  const genfit::FitStatus* fs = recoTrack.getTrackFitStatus(trackRep);
128  const genfit::KalmanFitStatus* kfs = dynamic_cast<const genfit::KalmanFitStatus*>(fs);
129  B2DEBUG(99, " Chi2 of the fit: " << kfs->getChi2());
130  B2DEBUG(99, " NDF of the fit: " << kfs->getBackwardNdf());
131  //Calculate probability
132  double pValue = recoTrack.getTrackFitStatus(trackRep)->getPVal();
133  B2DEBUG(99, " pValue of the fit: " << pValue);
134  const genfit::MeasuredStateOnPlane& mSoP = recoTrack.getMeasuredStateOnPlaneFromFirstHit(trackRep);
135  B2DEBUG(99, "Charge after fit " << mSoP.getCharge());
136  B2DEBUG(99, "Position after fit " << mSoP.getPos().X() << " " << mSoP.getPos().Y() << " " << mSoP.getPos().Z());
137  B2DEBUG(99, "Momentum after fit " << mSoP.getMom().X() << " " << mSoP.getMom().Y() << " " << mSoP.getMom().Z());
138  } else {
139  B2DEBUG(99, " fit failed!");
140  }
141  }
142  recoTrackCounter += 1;
143  }
144 }
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.
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.
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.
Definition: Const.h:470
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ 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:80
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:76
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Algorithm class to handle the fitting of RecoTrack objects.
Definition: TrackFitter.h:114
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
static FieldManager * getInstance()
Get singleton instance.
Definition: FieldManager.h:119
Class where important numbers and properties of a fit can be stored.
Definition: FitStatus.h:80
double getChi2() const
Get chi^2 of the fit.
Definition: FitStatus.h:120
FitStatus for use with AbsKalmanFitter implementations.
#StateOnPlane with additional covariance matrix.
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:560
Abstract base class for different kinds of events.