Belle II Software prerelease-11-00-00a
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 addParam("stopOnSuccessfulTrackFit", m_stopOnSuccessfulTrackFit, "Flag to stop creating new tracks when a particle hypothesis "
56 "leads to a successful track fit. Switched off by default (fit all given pdg codes) but turned on before HLT filter for optimzation",
58
59}
60
62{
64
66 if (!tracks.isOptional()) {
67 const bool tracksRegistered = tracks.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
68 B2ASSERT("Could not register output store arrays for tracks.", tracksRegistered);
69 }
71 if (!trackFitResults.isOptional()) {
72 const bool trackFitResultsRegistered = trackFitResults.registerInDataStore();
73 B2ASSERT("Could not register output store arrays for track fit results.", trackFitResultsRegistered);
74 }
75
76 if (!tracks.hasRelationTo(m_RecoTracks)) {
77 tracks.registerRelationTo(m_RecoTracks);
78 }
79
80
81 B2ASSERT("BeamSpot should have exactly 3 parameters", m_beamSpot.size() == 3);
83
84 B2ASSERT("BeamAxis should have exactly 3 parameters", m_beamAxis.size() == 3);
86}
87
89{
90 if (!m_trackFitMomentumRange.isValid())
91 B2FATAL("TrackFitMomentumRange parameters are not available.");
92}
93
95{
96 if (m_RecoTracks.getEntries() == 0) {
97 B2DEBUG(20, "RecoTrack StoreArray does not contain any RecoTracks.");
98 }
99
100 // Here, the last parameter is fromTrackCreator, necessary to set the priority of eventT0
101 const bool fromTrackCreator = !m_trackFitResultColName.ends_with("_flipped");
102 TrackFitter trackFitter(DAFConfiguration::c_Default, "", "", "", "", "", true, fromTrackCreator);
104 for (auto& recoTrack : m_RecoTracks) {
105 for (const auto& pdg : m_pdgCodes) {
106 // Does not refit in case the particle hypotheses demanded in this module have already been fitted before.
107 // Otherwise fits them with the default fitter.
108
109 double initialTotalMomentum = recoTrack.getMomentumSeed().R(); // this is the MomentumSeed
111 // if we decide to use the previous track fit momentum for the trackFitMomentumRange selection
112 if (recoTrack.wasFitSuccessful()) {
113 // If the previous fit has been successful
114 genfit::MeasuredStateOnPlane msop = recoTrack.getMeasuredStateOnPlaneFromFirstHit();
115 initialTotalMomentum = recoTrack.getCardinalRepresentation()->getMomMag(msop);
116 } else {
117 B2DEBUG(25, "No previous successful fit, using seed value instead");
118 }
119 }
120
121 B2DEBUG(25, "Trying to fit with PDG = " << pdg);
122 B2DEBUG(25, "PDG hypothesis: " << pdg << "\tMomentum cut: " << m_trackFitMomentumRange->getMomentumRange(
123 pdg) << "\tSeed p: " << initialTotalMomentum);
124
125 if (initialTotalMomentum <= m_trackFitMomentumRange->getMomentumRange(pdg)) {
126 trackFitter.fit(recoTrack, Const::ParticleType(abs(pdg)));
127 }
129 if (recoTrack.wasFitSuccessful()) {
130 break;
131 }
132 }
133 }
134 trackBuilder.storeTrackFromRecoTrack(recoTrack, m_useClosestHitToIP);
135 }
136}
The ParticleType class for identifying different particle types.
Definition Const.h:408
@ c_Default
default configuration
@ 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 isOptional(const std::string &name="")
Tell the DataStore about an optional input.
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.
bool m_stopOnSuccessfulTrackFit
Flag to stop the module when a particle hypothesis leads to a successiful track fit (used in prefilte...
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.