Belle II Software development
TrackCreatorModule.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/trackCreator/TrackCreatorModule.h>
9
10#include <framework/logging/Logger.h>
11
12#include <mdst/dataobjects/MCParticle.h>
13#include <mdst/dataobjects/Track.h>
14#include <mdst/dataobjects/TrackFitResult.h>
15
16#include <tracking/trackFitting/trackBuilder/factories/TrackBuilder.h>
17#include <tracking/trackFitting/fitter/base/TrackFitter.h>
18
19using namespace Belle2;
20
21REG_MODULE(TrackCreator);
22
24 Module()
25{
27 "Build Tracks with the TrackFitResults. Needs RecoTracks as input, creates Belle2::Tracks and Belle2::TrackFitResults as output.");
29
30 // input
31 addParam("recoTrackColName", m_recoTrackColName, "Name of collection holding the RecoTracks (input).",
33 // output
34 addParam("trackColName", m_trackColName, "Name of collection holding the Tracks (output).", m_trackColName);
35 addParam("trackFitResultColName", m_trackFitResultColName, "Name of collection holding the TrackFitResult (output).",
37
38 addParam("beamSpot", m_beamSpot,
39 "BeamSpot (and BeamAxis) define the coordinate system in which the tracks will be extrapolated to the perigee.",
41 addParam("beamAxis", m_beamAxis,
42 "(BeamSpot and )BeamAxis define the coordinate system in which the tracks will be extrapolated to the perigee.",
44 addParam("pdgCodes", m_pdgCodes,
45 "PDG codes for which TrackFitResults will be created.",
47
48 addParam("useClosestHitToIP", m_useClosestHitToIP, "Flag to turn on special handling which measurement "
49 "to choose; especially useful for Cosmics.", m_useClosestHitToIP);
50 addParam("useBFieldAtHit", m_useBFieldAtHit, "Flag to calculate the BField at the used hit "
51 "(closest to IP or first one), instead of the one at the POCA. Use this for cosmics to prevent problems, when cosmics reconstruction end up in the QCS magnet.",
53 addParam("useSeedForTrackFitMomentumRange", m_useSeedForTrackFitMomentumRange, "Flag to use the momentum seed of the RecoTrack "
54 "for the TrackFitMomentumRange selection. By default the fitted value is used", m_useSeedForTrackFitMomentumRange);
55
56}
57
59{
61
63 const bool tracksRegistered = tracks.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
65 const bool trackFitResultsRegistered = trackFitResults.registerInDataStore();
66
67 B2ASSERT("Could not register output store arrays.", (tracksRegistered and trackFitResultsRegistered));
68
69 tracks.registerRelationTo(m_RecoTracks);
70
71
72 B2ASSERT("BeamSpot should have exactly 3 parameters", m_beamSpot.size() == 3);
74
75 B2ASSERT("BeamAxis should have exactly 3 parameters", m_beamAxis.size() == 3);
77}
78
80{
81 if (!m_trackFitMomentumRange.isValid())
82 B2FATAL("TrackFitMomentumRange parameters are not available.");
83}
84
86{
87 if (m_RecoTracks.getEntries() == 0) {
88 B2DEBUG(20, "RecoTrack StoreArray does not contain any RecoTracks.");
89 }
90
91 TrackFitter trackFitter;
93 for (auto& recoTrack : m_RecoTracks) {
94 for (const auto& pdg : m_pdgCodes) {
95 // Does not refit in case the particle hypotheses demanded in this module have already been fitted before.
96 // Otherwise fits them with the default fitter.
97
98 double initialTotalMomentum = recoTrack.getMomentumSeed().R(); // this is the MomentumSeed
100 // if we decide to use the previous track fit momentum for the trackFitMomentumRange selection
101 if (recoTrack.wasFitSuccessful()) {
102 // If the previous fit has been successful
103 genfit::MeasuredStateOnPlane msop = recoTrack.getMeasuredStateOnPlaneFromFirstHit();
104 initialTotalMomentum = recoTrack.getCardinalRepresentation()->getMomMag(msop);
105 } else {
106 B2DEBUG(25, "No previous successful fit, using seed value instead");
107 }
108 }
109
110 B2DEBUG(25, "Trying to fit with PDG = " << pdg);
111 B2DEBUG(25, "PDG hypothesis: " << pdg << "\tMomentum cut: " << m_trackFitMomentumRange->getMomentumRange(
112 pdg) << "\tSeed p: " << initialTotalMomentum);
113
114 if (initialTotalMomentum <= m_trackFitMomentumRange->getMomentumRange(pdg)) {
115 trackFitter.fit(recoTrack, Const::ParticleType(abs(pdg)));
116 }
117 }
118 trackBuilder.storeTrackFromRecoTrack(recoTrack, m_useClosestHitToIP);
119 }
120}
The ParticleType class for identifying different particle types.
Definition Const.h:408
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition DataStore.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
Module()
Constructor.
Definition Module.cc:30
@ 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
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
TrackBuilder class to create the Track/TrackFitResult mdst output from the RecoTrack.
bool storeTrackFromRecoTrack(RecoTrack &recoTrack, const bool useClosestHitToIP=false, const bool useBFieldAtHit=false)
Stores a Belle2 Track from a Reco Track.
std::vector< double > m_beamSpot
BeamSpot define the coordinate system in which the tracks will be extrapolated to the perigee.
B2Vector3D m_beamSpotAsTVector
BeamSpot as B2Vector3D.
void initialize() override
Require and register the store arrays.
B2Vector3D m_beamAxisAsTVector
BeamAxis as B2Vector3D.
void event() override
Build/fit the track fit results.
DBObjPtr< TrackFitMomentumRange > m_trackFitMomentumRange
TrackFitMomentumRange Database OjbPtr.
TrackCreatorModule()
Constructor adding the description and properties.
bool m_useBFieldAtHit
Flag to calculate the BField at the used hit (closest to IP or first one), instead of the one at the ...
bool m_useSeedForTrackFitMomentumRange
Flag to use the momentum seed of the RecoTrack for the TrackFitMomentumRange selection (instead of th...
bool m_useClosestHitToIP
Flag to turn on special handling which measurement to choose; especially useful for Cosmics.
std::vector< double > m_beamAxis
BeamAxis define the coordinate system in which the tracks will be extrapolated to the perigee.
std::string m_trackColName
Name of collection holding the Tracks (output).
void beginRun() override
Called when entering a new run, to load TrackFitMomentumRange parameters.
std::string m_recoTrackColName
Name of collection holding the RecoTracks (input).
std::vector< int > m_pdgCodes
PDG codes for which TrackFitResults will be created.
std::string m_trackFitResultColName
Name of collection holding the TrackFitResult (output).
StoreArray< RecoTrack > m_RecoTracks
RecoTracks StoreArray.
Algorithm class to handle the fitting of RecoTrack objects.
bool fit(RecoTrack &recoTrack, genfit::AbsTrackRep *trackRepresentation, bool resortHits=false) const
Fit a reco track with a given non-default track representation.
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition B2Vector3.h:516
Abstract base class for different kinds of events.