Belle II Software development
RecoTrackStorer.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/vxdHoughTracking/findlets/RecoTrackStorer.h>
9#include <framework/core/ModuleParamList.h>
10#include <framework/geometry/BFieldManager.h>
11#include <tracking/dataobjects/RecoTrack.h>
12#include <svd/dataobjects/SVDCluster.h>
13#include <tracking/spacePointCreation/SpacePoint.h>
14#include <tracking/spacePointCreation/SpacePointTrackCand.h>
15#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorCircleFit.h>
16#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorMC.h>
17#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorRiemannHelixFit.h>
18#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h>
19#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
20#include <tracking/trackFindingCDC/utilities/Algorithms.h>
21#include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
22
23using namespace Belle2;
24using namespace TrackFindingCDC;
25using namespace vxdHoughTracking;
26
28
32
33void RecoTrackStorer::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
34{
35 Super::exposeParameters(moduleParamList, prefix);
36
37 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "SVDClustersStoreArrayName"), m_SVDClustersStoreArrayName,
38 "Name of the SVDClusters Store Array.", m_SVDClustersStoreArrayName);
39
40 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "RecoTracksStoreArrayName"), m_RecoTracksStoreArrayName,
41 "Name of the RecoTracks Store Array.", m_RecoTracksStoreArrayName);
42
43 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "SVDSpacePointTrackCandsStoreArrayName"),
45 "Name of the SpacePointTrackCand Store Array.", m_SVDSpacePointTrackCandsStoreArrayName);
46
47 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "ResultStorerQualityEstimationMethod"), m_EstimationMethod,
48 "Identifier which estimation method to use. Valid identifiers are: [mcInfo, circleFit, tripletFit, helixFit].",
50
51 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "ResultStorerMCRecoTracksStoreArrayName"),
53 "Only required for MCInfo method. Name of StoreArray containing MCRecoTracks.",
55
56 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "ResultStorerMCStrictQualityEstimator"),
58 "Only required for MCInfo method. If false combining several MCTracks is allowed.",
60}
61
63{
65
71
72 // create pointer to chosen estimator
73 if (m_EstimationMethod == "mcInfo") {
74 StoreArray<RecoTrack> mcRecoTracks;
76 m_estimator = std::make_unique<QualityEstimatorMC>(m_MCRecoTracksStoreArrayName, m_MCStrictQualityEstimator);
77 } else if (m_EstimationMethod == "tripletFit") {
78 m_estimator = std::make_unique<QualityEstimatorTripletFit>();
79 } else if (m_EstimationMethod == "circleFit") {
80 m_estimator = std::make_unique<QualityEstimatorCircleFit>();
81 } else if (m_EstimationMethod == "helixFit") {
82 m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
83 }
84 B2ASSERT("QualityEstimator could not be initialized with method: " << m_EstimationMethod, m_estimator);
85}
86
88{
90
91 // BField is required by all QualityEstimators
92 double bFieldZ = BFieldManager::getField(0, 0, 0).Z() / Unit::T;
93 m_estimator->setMagneticFieldStrength(bFieldZ);
94
95 if (m_EstimationMethod == "mcInfo") {
96 QualityEstimatorMC* MCestimator = static_cast<QualityEstimatorMC*>(m_estimator.get());
97 MCestimator->forceUpdateClusterNames();
98 }
99}
100
102{
104
105 m_usedClusters.clear();
106 m_usedSpacePoints.clear();
107}
108
109void RecoTrackStorer::apply(std::vector<SpacePointTrackCand>& finishedResults,
110 const std::vector<const SpacePoint*>& spacePoints)
111{
112 for (auto& thisSPTC : finishedResults) {
113 // do nothing if the SpacePointTrackCand is not active
114 if (!thisSPTC.hasRefereeStatus(SpacePointTrackCand::c_isActive)) {
115 continue;
116 }
117
118 auto sortedHits = thisSPTC.getSortedHits();
119 const auto& estimatorResult = m_estimator->estimateQualityAndProperties(sortedHits);
120
121 const ROOT::Math::XYZVector trackPosition(sortedHits.front()->X(), sortedHits.front()->Y(), sortedHits.front()->Z());
122 const ROOT::Math::XYZVector& trackMomentum = *estimatorResult.p;
123 const short& trackChargeSeed = estimatorResult.curvatureSign ? -1 * (*(estimatorResult.curvatureSign)) : 0;
124 const double qi = estimatorResult.qualityIndicator;
125
126 RecoTrack* newRecoTrack = m_storeRecoTracks.appendNew(trackPosition, trackMomentum, trackChargeSeed, "",
128
129 // TODO: find out where these numbers come from!
130 // This is copied from the VXDTF2 counterpart tracking/modules/spacePointCreator/SPTCmomentumSeedRetrieverModule !
131 TVectorD stateSeed(6); //(x,y,z,px,py,pz)
132 TMatrixDSym covSeed(6);
133 covSeed(0, 0) = 0.01 ; covSeed(1, 1) = 0.01 ; covSeed(2, 2) = 0.04 ; // 0.01 = 0.1^2 = dx*dx =dy*dy. 0.04 = 0.2^2 = dz*dz
134 covSeed(3, 3) = 0.01 ; covSeed(4, 4) = 0.01 ; covSeed(5, 5) = 0.04 ;
135
136 stateSeed(0) = (sortedHits.front()->X());
137 stateSeed(1) = (sortedHits.front()->Y());
138 stateSeed(2) = (sortedHits.front()->Z());
139 if (estimatorResult.p) {
140 auto momentumSeed = *(estimatorResult.p);
141 stateSeed(3) = momentumSeed.X();
142 stateSeed(4) = momentumSeed.Y();
143 stateSeed(5) = momentumSeed.Z();
144 } else {
145 stateSeed(3) = 0;
146 stateSeed(4) = 0;
147 stateSeed(5) = 0;
148 }
149
150 thisSPTC.set6DSeed(stateSeed);
151 thisSPTC.setCovSeed(covSeed);
152 thisSPTC.setChargeSeed(trackChargeSeed);
153 // until here
154
155 // Set information not required by constructor
156 newRecoTrack->setSeedCovariance(covSeed);
157
158 // Transfer quality indicator from SPTC to RecoTrack
159 newRecoTrack->setQualityIndicator(qi);
160
161 SpacePointTrackCand* newSPTC = m_storeSpacePointTrackCands.appendNew(thisSPTC);
162 // Add relation to SpacePointTrackCandidate
163 newRecoTrack->addRelationTo(newSPTC);
164
165
166 unsigned int sortingParameter = 0;
167 for (const SpacePoint* spacePoint : sortedHits) {
168 m_usedSpacePoints.insert(spacePoint);
169
170 RelationVector<SVDCluster> relatedClusters = spacePoint->getRelationsTo<SVDCluster>(m_SVDClustersStoreArrayName);
171 for (const SVDCluster& relatedCluster : relatedClusters) {
172 m_usedClusters.insert(&relatedCluster);
173 newRecoTrack->addSVDHit(&relatedCluster, sortingParameter, Belle2::RecoHitInformation::c_SVDHough);
174 sortingParameter++;
175 }
176 }
177 }
178
179 for (const SpacePoint* spacePoint : spacePoints) {
180 if (TrackFindingCDC::is_in(spacePoint, m_usedSpacePoints)) {
181 spacePoint->setAssignmentState(true);
182 continue;
183 }
184
185 const auto& relatedClusters = spacePoint->getRelationsTo<SVDCluster>(m_SVDClustersStoreArrayName);
186 for (const SVDCluster& relatedCluster : relatedClusters) {
187 if (TrackFindingCDC::is_in(&relatedCluster, m_usedClusters)) {
188 spacePoint->setAssignmentState(true);
189 break;
190 }
191 }
192 }
193
194}
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition DataStore.h:71
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition DataStore.h:72
The Module parameter list class.
Class implementing the algorithm used for the MC based quality estimation.
void forceUpdateClusterNames()
Setter to force the class to update its cluster names.
This is the Reconstruction Event-Data Model Track.
Definition RecoTrack.h:79
void setSeedCovariance(const TMatrixDSym &seedCovariance)
Set the covariance of the seed. ATTENTION: This is not the fitted covariance.
Definition RecoTrack.h:614
void setQualityIndicator(const float qualityIndicator)
Set the quality index attached to this RecoTrack. 0 means likely fake.
Definition RecoTrack.h:847
static void registerRequiredRelations(StoreArray< RecoTrack > &recoTracks, std::string const &pxdHitsStoreArrayName="", std::string const &svdHitsStoreArrayName="", std::string const &cdcHitsStoreArrayName="", std::string const &bklmHitsStoreArrayName="", std::string const &eklmHitsStoreArrayName="", std::string const &recoHitInformationStoreArrayName="")
Convenience method which registers all relations required to fully use a RecoTrack.
Definition RecoTrack.cc:53
bool addSVDHit(const UsedSVDHit *svdHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a svd hit with the given information to the reco track.
Definition RecoTrack.h:272
Class for type safe access to objects that are referred to in relations.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition SVDCluster.h:29
Storage for (VXD) SpacePoint-based track candidates.
@ c_isActive
bit 11: SPTC is active (i.e.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition SpacePoint.h:42
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
void initialize() override
Receive and dispatch signal before the start of the event processing.
void beginRun() override
Receive and dispatch signal for the beginning of a new run.
void beginEvent() override
Receive and dispatch signal for the start of a new event.
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
Expose the set of parameters of the filter to the module parameter list.
static const double T
[tesla]
Definition Unit.h:120
void apply(std::vector< SpacePointTrackCand > &finishedResults, const std::vector< const SpacePoint * > &spacePoints) override
Store the finishey SpacePointTrackCands into RecoTracks and tag the SpacePoints.
bool m_MCStrictQualityEstimator
Only required for MCInfo method.
void initialize() override
Create the store arrays.
std::string m_SVDSpacePointTrackCandsStoreArrayName
StoreArray name of the SpacePointTrackCandidate StoreArray.
std::string m_EstimationMethod
Identifier which estimation method to use.
std::string m_SVDClustersStoreArrayName
StoreArray name of the SVDCluster StoreArray.
std::set< const SVDCluster * > m_usedClusters
Store the used clusters in the results.
StoreArray< SpacePointTrackCand > m_storeSpacePointTrackCands
Output SpacePointTrackCand Store Array.
TrackFindingCDC::Findlet< SpacePointTrackCand, const SpacePoint *const > Super
Parent class.
std::string m_MCRecoTracksStoreArrayName
sets the name of the expected StoreArray containing MCRecoTracks. Only required for MCInfo method
void beginEvent() override
Reset internal vectors.
std::unique_ptr< QualityEstimatorBase > m_estimator
pointer to the selected QualityEstimator
StoreArray< RecoTrack > m_storeRecoTracks
Output RecoTracks Store Array.
std::set< const SpacePoint * > m_usedSpacePoints
Store the used space points in the results.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
std::string m_RecoTracksStoreArrayName
StoreArray name of the output Track StoreArray.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Abstract base class for different kinds of events.