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
54}
55
57{
59
61 const bool tracksRegistered = tracks.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
63 const bool trackFitResultsRegistered = trackFitResults.registerInDataStore();
64
65 B2ASSERT("Could not register output store arrays.", (tracksRegistered and trackFitResultsRegistered));
66
67 tracks.registerRelationTo(m_RecoTracks);
68
69
70 B2ASSERT("BeamSpot should have exactly 3 parameters", m_beamSpot.size() == 3);
72
73 B2ASSERT("BeamAxis should have exactly 3 parameters", m_beamAxis.size() == 3);
75}
76
78{
79 if (!m_trackFitMomentumRange.isValid())
80 B2FATAL("TrackFitMomentumRange parameters are not available.");
81}
82
84{
85 if (m_RecoTracks.getEntries() == 0) {
86 B2DEBUG(20, "RecoTrack StoreArray does not contain any RecoTracks.");
87 }
88
89 TrackFitter trackFitter;
91 for (auto& recoTrack : m_RecoTracks) {
92 for (const auto& pdg : m_pdgCodes) {
93 // Does not refit in case the particle hypotheses demanded in this module have already been fitted before.
94 // Otherwise fits them with the default fitter.
95 B2DEBUG(25, "Trying to fit with PDG = " << pdg);
96 B2DEBUG(25, "PDG hypothesis: " << pdg << "\tMomentum cut: " << m_trackFitMomentumRange->getMomentumRange(
97 pdg) << "\tSeed p: " << recoTrack.getMomentumSeed().R());
98 if (recoTrack.getMomentumSeed().R() <= m_trackFitMomentumRange->getMomentumRange(pdg)) {
99 trackFitter.fit(recoTrack, Const::ParticleType(abs(pdg)));
100 }
101 }
102 trackBuilder.storeTrackFromRecoTrack(recoTrack, m_useClosestHitToIP);
103 }
104}
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
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
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
TrackBuilder class to create the Track/TrackFitResult mdst output from the RecoTrack.
Definition: TrackBuilder.h:41
bool storeTrackFromRecoTrack(RecoTrack &recoTrack, const bool useClosestHitToIP=false, const bool useBFieldAtHit=false)
Stores a Belle2 Track from a Reco Track.
Definition: TrackBuilder.cc:34
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_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.
Definition: TrackFitter.h:121
bool fit(RecoTrack &recoTrack, genfit::AbsTrackRep *trackRepresentation, bool resortHits=false) const
Fit a reco track with a given non-default track representation.
Definition: TrackFitter.cc:108
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
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:516
Abstract base class for different kinds of events.