Belle II Software  release-06-00-14
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/datastore/StoreArray.h>
11 #include <framework/logging/Logger.h>
12 
13 #include <mdst/dataobjects/MCParticle.h>
14 #include <mdst/dataobjects/Track.h>
15 #include <mdst/dataobjects/TrackFitResult.h>
16 
17 #include <tracking/dataobjects/RecoTrack.h>
18 #include <tracking/trackFitting/trackBuilder/factories/TrackBuilder.h>
19 #include <tracking/trackFitting/fitter/base/TrackFitter.h>
20 
21 using namespace Belle2;
22 
23 REG_MODULE(TrackCreator)
24 
26  Module()
27 {
28  setDescription(
29  "Build Tracks with the TrackFitResults. Needs RecoTracks as input, creates Belle2::Tracks and Belle2::TrackFitResults as output.");
30  setPropertyFlags(c_ParallelProcessingCertified);
31 
32  // input
33  addParam("recoTrackColName", m_recoTrackColName, "Name of collection holding the RecoTracks (input).",
34  m_recoTrackColName);
35  addParam("mcParticleColName", m_mcParticleColName, "Name of collection holding the MCParticles (input, optional).",
36  m_mcParticleColName);
37  // output
38  addParam("trackColName", m_trackColName, "Name of collection holding the Tracks (output).", m_trackColName);
39  addParam("trackFitResultColName", m_trackFitResultColName, "Name of collection holding the TrackFitResult (output).",
40  m_trackFitResultColName);
41 
42  addParam("beamSpot", m_beamSpot,
43  "BeamSpot (and BeamAxis) define the coordinate system in which the tracks will be extrapolated to the perigee.",
44  m_beamSpot);
45  addParam("beamAxis", m_beamAxis,
46  "(BeamSpot and )BeamAxis define the coordinate system in which the tracks will be extrapolated to the perigee.",
47  m_beamAxis);
48  addParam("pdgCodes", m_pdgCodes,
49  "PDG codes for which TrackFitResults will be created.",
50  m_pdgCodes);
51 
52  addParam("useClosestHitToIP", m_useClosestHitToIP, "Flag to turn on special handling which measurement "
53  "to choose; especially useful for Cosmics.", m_useClosestHitToIP);
54  addParam("useBFieldAtHit", m_useBFieldAtHit, "Flag to calculate the BField at the used hit "
55  "(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.",
56  m_useBFieldAtHit);
57 
58 }
59 
61 {
63  recoTracks.isRequired();
64 
66  const bool mcParticlesPresent = mcParticles.isOptional();
67 
69  const bool tracksRegistered = tracks.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
71  const bool trackFitResultsRegistered = trackFitResults.registerInDataStore();
72 
73  B2ASSERT("Could not register output store arrays.", (tracksRegistered and trackFitResultsRegistered));
74 
75  tracks.registerRelationTo(recoTracks);
76 
77  if (mcParticlesPresent) {
78  tracks.registerRelationTo(mcParticles);
79  }
80 
81  B2ASSERT("BeamSpot should have exactly 3 parameters", m_beamSpot.size() == 3);
82  m_beamSpotAsTVector = TVector3(m_beamSpot[0], m_beamSpot[1], m_beamSpot[2]);
83 
84  B2ASSERT("BeamAxis should have exactly 3 parameters", m_beamAxis.size() == 3);
85  m_beamAxisAsTVector = TVector3(m_beamAxis[0], m_beamAxis[1], m_beamAxis[2]);
86 }
87 
89 {
90  if (!m_trackFitMomentumRange.isValid())
91  B2FATAL("TrackFitMomentumRange parameters are not available.");
92 }
93 
95 {
97  if (recoTracks.getEntries() == 0) {
98  B2DEBUG(20, "RecoTrack StoreArray does not contain any RecoTracks.");
99  }
100 
101  TrackFitter trackFitter;
104  for (auto& recoTrack : 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  B2DEBUG(25, "Trying to fit with PDG = " << pdg);
109  B2DEBUG(25, "PDG hypothesis: " << pdg << "\tMomentum cut: " << m_trackFitMomentumRange->getMomentumRange(
110  pdg) << "\tSeed p: " << recoTrack.getMomentumSeed().Mag());
111  if (recoTrack.getMomentumSeed().Mag() <= m_trackFitMomentumRange->getMomentumRange(pdg)) {
112  trackFitter.fit(recoTrack, Const::ParticleType(abs(pdg)));
113  }
114  }
115  trackBuilder.storeTrackFromRecoTrack(recoTrack, m_useClosestHitToIP);
116  }
117 }
The ParticleType class for identifying different particle types.
Definition: Const.h:289
@ 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
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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
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:40
bool storeTrackFromRecoTrack(RecoTrack &recoTrack, const bool useClosestHitToIP=false, const bool useBFieldAtHit=false)
Stores a Belle2 Track from a Reco Track.
Definition: TrackBuilder.cc:35
Takes RecoTracks coming from the event reconstructions and fits them with the configured list of part...
TVector3 m_beamSpotAsTVector
BeamSpot as TVector3.
std::vector< double > m_beamSpot
BeamSpot define the coordinate system in which the tracks will be extrapolated to the perigee.
void initialize() override
Require and register the store arrays.
void event() override
Build/fit the track fit results.
DBObjPtr< TrackFitMomentumRange > m_trackFitMomentumRange
TrackFitMomentumRange Database OjbPtr.
TVector3 m_beamAxisAsTVector
BeamAxis as TVector3.
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_mcParticleColName
Name of collection holding the MCParticles (input, optional).
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).
Algorithm class to handle the fitting of RecoTrack objects.
Definition: TrackFitter.h:114
bool fit(RecoTrack &recoTrack, genfit::AbsTrackRep *trackRepresentation) const
Fit a reco track with a given non-default track representation.
Definition: TrackFitter.cc:107
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.