Belle II Software  release-05-02-19
TrackCreatorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Tobias Schlüter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/modules/trackCreator/TrackCreatorModule.h>
11 
12 #include <framework/datastore/StoreArray.h>
13 #include <framework/logging/Logger.h>
14 
15 #include <mdst/dataobjects/MCParticle.h>
16 #include <mdst/dataobjects/Track.h>
17 #include <mdst/dataobjects/TrackFitResult.h>
18 
19 #include <tracking/dataobjects/RecoTrack.h>
20 #include <tracking/trackFitting/trackBuilder/factories/TrackBuilder.h>
21 #include <tracking/trackFitting/fitter/base/TrackFitter.h>
22 
23 using namespace Belle2;
24 
25 REG_MODULE(TrackCreator)
26 
28  Module()
29 {
30  setDescription(
31  "Build Tracks with the TrackFitResults. Needs RecoTracks as input, creates Belle2::Tracks and Belle2::TrackFitResults as output.");
32  setPropertyFlags(c_ParallelProcessingCertified);
33 
34  // input
35  addParam("recoTrackColName", m_recoTrackColName, "Name of collection holding the RecoTracks (input).",
36  m_recoTrackColName);
37  addParam("mcParticleColName", m_mcParticleColName, "Name of collection holding the MCParticles (input, optional).",
38  m_mcParticleColName);
39  // output
40  addParam("trackColName", m_trackColName, "Name of collection holding the Tracks (output).", m_trackColName);
41  addParam("trackFitResultColName", m_trackFitResultColName, "Name of collection holding the TrackFitResult (output).",
42  m_trackFitResultColName);
43 
44  addParam("beamSpot", m_beamSpot,
45  "BeamSpot (and BeamAxis) define the coordinate system in which the tracks will be extrapolated to the perigee.",
46  m_beamSpot);
47  addParam("beamAxis", m_beamAxis,
48  "(BeamSpot and )BeamAxis define the coordinate system in which the tracks will be extrapolated to the perigee.",
49  m_beamAxis);
50  addParam("pdgCodes", m_pdgCodes,
51  "PDG codes for which TrackFitResults will be created.",
52  m_pdgCodes);
53 
54  addParam("useClosestHitToIP", m_useClosestHitToIP, "Flag to turn on special handling which measurement "
55  "to choose; especially useful for Cosmics.", m_useClosestHitToIP);
56  addParam("useBFieldAtHit", m_useBFieldAtHit, "Flag to calculate the BField at the used hit "
57  "(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.",
58  m_useBFieldAtHit);
59 
60 }
61 
63 {
65  recoTracks.isRequired();
66 
68  const bool mcParticlesPresent = mcParticles.isOptional();
69 
71  const bool tracksRegistered = tracks.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
73  const bool trackFitResultsRegistered = trackFitResults.registerInDataStore();
74 
75  B2ASSERT((tracksRegistered and trackFitResultsRegistered), "Could not register output store arrays.");
76 
77  tracks.registerRelationTo(recoTracks);
78 
79  if (mcParticlesPresent) {
80  tracks.registerRelationTo(mcParticles);
81  }
82 
83  B2ASSERT("BeamSpot should have exactly 3 parameters", m_beamSpot.size() == 3);
84  m_beamSpotAsTVector = TVector3(m_beamSpot[0], m_beamSpot[1], m_beamSpot[2]);
85 
86  B2ASSERT("BeamAxis should have exactly 3 parameters", m_beamAxis.size() == 3);
87  m_beamAxisAsTVector = TVector3(m_beamAxis[0], m_beamAxis[1], m_beamAxis[2]);
88 }
89 
91 {
93  if (recoTracks.getEntries() == 0) {
94  B2DEBUG(20, "RecoTrack StoreArray does not contain any RecoTracks.");
95  }
96 
97  TrackFitter trackFitter;
100  for (auto& recoTrack : recoTracks) {
101  for (const auto& pdg : m_pdgCodes) {
102  // Does not refit in case the particle hypotheses demanded in this module have already been fitted before.
103  // Otherwise fits them with the default fitter.
104  B2DEBUG(200, "Trying to fit with PDG = " << pdg);
105  trackFitter.fit(recoTrack, Const::ParticleType(abs(pdg)));
106  }
107  trackBuilder.storeTrackFromRecoTrack(recoTrack, m_useClosestHitToIP);
108  }
109 }
Belle2::TrackBuilder
TrackBuilder class to create the Track/TrackFitResult mdst output from the RecoTrack.
Definition: TrackBuilder.h:50
Belle2::TrackCreatorModule::m_useClosestHitToIP
bool m_useClosestHitToIP
Flag to turn on special handling which measurement to choose; especially useful for Cosmics.
Definition: TrackCreatorModule.h:77
Belle2::TrackFitter::fit
bool fit(RecoTrack &recoTrack, genfit::AbsTrackRep *trackRepresentation) const
Fit a reco track with a given non-default track representation.
Definition: TrackFitter.cc:109
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::TrackCreatorModule::m_trackColName
std::string m_trackColName
Name of collection holding the Tracks (output).
Definition: TrackCreatorModule.h:61
Belle2::TrackCreatorModule::event
void event() override
Build/fit the track fit results.
Definition: TrackCreatorModule.cc:90
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::TrackCreatorModule::m_beamAxisAsTVector
TVector3 m_beamAxisAsTVector
BeamAxis as TVector3.
Definition: TrackCreatorModule.h:72
Belle2::TrackFitter
Algorithm class to handle the fitting of RecoTrack objects.
Definition: TrackFitter.h:116
Belle2::TrackCreatorModule::initialize
void initialize() override
Require and register the store arrays.
Definition: TrackCreatorModule.cc:62
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackCreatorModule::m_trackFitResultColName
std::string m_trackFitResultColName
Name of collection holding the TrackFitResult (output).
Definition: TrackCreatorModule.h:63
Belle2::TrackCreatorModule::m_recoTrackColName
std::string m_recoTrackColName
Name of collection holding the RecoTracks (input).
Definition: TrackCreatorModule.h:55
Belle2::TrackCreatorModule::m_pdgCodes
std::vector< int > m_pdgCodes
PDG codes for which TrackFitResults will be created.
Definition: TrackCreatorModule.h:74
Belle2::TrackCreatorModule::m_beamSpotAsTVector
TVector3 m_beamSpotAsTVector
BeamSpot as TVector3.
Definition: TrackCreatorModule.h:68
Belle2::TrackCreatorModule::m_beamAxis
std::vector< double > m_beamAxis
BeamAxis define the coordinate system in which the tracks will be extrapolated to the perigee.
Definition: TrackCreatorModule.h:70
Belle2::DataStore::c_ErrorIfAlreadyRegistered
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:74
Belle2::Const::ParticleType
The ParticleType class for identifying different particle types.
Definition: Const.h:284
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TrackCreatorModule::m_mcParticleColName
std::string m_mcParticleColName
Name of collection holding the MCParticles (input, optional).
Definition: TrackCreatorModule.h:57
Belle2::TrackBuilder::storeTrackFromRecoTrack
bool storeTrackFromRecoTrack(RecoTrack &recoTrack, const bool useClosestHitToIP=false, const bool useBFieldAtHit=false)
Stores a Belle2 Track from a Reco Track.
Definition: TrackBuilder.cc:28
Belle2::TrackCreatorModule::m_beamSpot
std::vector< double > m_beamSpot
BeamSpot define the coordinate system in which the tracks will be extrapolated to the perigee.
Definition: TrackCreatorModule.h:66
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::TrackCreatorModule
Takes RecoTracks coming from the event reconstructions and fits them with the configured list of part...
Definition: TrackCreatorModule.h:40