Belle II Software  release-06-02-00
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/core/ModuleParamList.templateDetails.h>
11 #include <framework/geometry/BFieldManager.h>
12 #include <tracking/dataobjects/RecoTrack.h>
13 #include <svd/dataobjects/SVDCluster.h>
14 #include <tracking/spacePointCreation/SpacePoint.h>
15 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
16 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorCircleFit.h>
17 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorMC.h>
18 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorRiemannHelixFit.h>
19 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h>
20 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
21 #include <tracking/trackFindingCDC/utilities/Algorithms.h>
22 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
23 
24 using namespace Belle2;
25 using namespace TrackFindingCDC;
26 using namespace vxdHoughTracking;
27 
28 RecoTrackStorer::~RecoTrackStorer() = default;
29 
30 RecoTrackStorer::RecoTrackStorer() : Super()
31 {
32 }
33 
34 void RecoTrackStorer::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
35 {
36  Super::exposeParameters(moduleParamList, prefix);
37 
38  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "SVDClustersStoreArrayName"), m_param_SVDClustersStoreArrayName,
39  "Name of the SVDClusters Store Array.", m_param_SVDClustersStoreArrayName);
40 
41  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "RecoTracksStoreArrayName"), m_param_RecoTracksStoreArrayName,
42  "Name of the RecoTracks Store Array.", m_param_RecoTracksStoreArrayName);
43 
44  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "ResultStorerQualityEstimationMethod"), m_param_EstimationMethod,
45  "Identifier which estimation method to use. Valid identifiers are: [mcInfo, circleFit, tripletFit, helixFit].",
47 
48  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "ResultStorerMCRecoTracksStoreArrayName"),
50  "Only required for MCInfo method. Name of StoreArray containing MCRecoTracks.",
52 
53  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "ResultStorerMCStrictQualityEstimator"),
55  "Only required for MCInfo method. If false combining several MCTracks is allowed.",
57 }
58 
60 {
62 
65 
66  // create pointer to chosen estimator
67  if (m_param_EstimationMethod == "mcInfo") {
69  } else if (m_param_EstimationMethod == "tripletFit") {
70  m_estimator = std::make_unique<QualityEstimatorTripletFit>();
71  } else if (m_param_EstimationMethod == "circleFit") {
72  m_estimator = std::make_unique<QualityEstimatorCircleFit>();
73  } else if (m_param_EstimationMethod == "helixFit") {
74  m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
75  }
76  B2ASSERT("QualityEstimator could not be initialized with method: " << m_param_EstimationMethod, m_estimator);
77 }
78 
80 {
82 
83  // BField is required by all QualityEstimators
84  double bFieldZ = BFieldManager::getField(0, 0, 0).Z() / Unit::T;
85  m_estimator->setMagneticFieldStrength(bFieldZ);
86 
87  if (m_param_EstimationMethod == "mcInfo") {
88  StoreArray<RecoTrack> mcRecoTracks;
90  std::string svdClustersName = m_param_SVDClustersStoreArrayName;
91  std::string pxdClustersName = "";
92 
93  if (mcRecoTracks.getEntries() > 0) {
94  svdClustersName = mcRecoTracks[0]->getStoreArrayNameOfSVDHits();
95  pxdClustersName = mcRecoTracks[0]->getStoreArrayNameOfPXDHits();
96  } else {
97  B2WARNING("No Entries in mcRecoTracksStoreArray: using empty cluster name for svd and pxd");
98  }
99 
100  QualityEstimatorMC* MCestimator = static_cast<QualityEstimatorMC*>(m_estimator.get());
101  MCestimator->setClustersNames(svdClustersName, pxdClustersName);
102  }
103 }
104 
106 {
108 
109  m_usedClusters.clear();
110  m_usedSpacePoints.clear();
111 }
112 
113 void RecoTrackStorer::apply(const std::vector<SpacePointTrackCand>& finishedResults,
114  const std::vector<const SpacePoint*>& spacePoints)
115 {
116  for (auto& thisSPTC : finishedResults) {
117  // do nothing if the SpacePointTrackCand is not active
118  if (!thisSPTC.hasRefereeStatus(SpacePointTrackCand::c_isActive)) {
119  continue;
120  }
121 
122  auto sortedHits = thisSPTC.getSortedHits();
123  const auto& estimatorResult = m_estimator->estimateQualityAndProperties(sortedHits);
124 
125  // const TVector3& trackPosition = TVector3(0., 0., 0.); // initial version, since there in principal is no better POCA estimate
126  const TVector3& trackPosition = TVector3(sortedHits.front()->X(), sortedHits.front()->Y(), sortedHits.front()->Z());
127  const TVector3& trackMomentum = *estimatorResult.p;
128  const short& trackChargeSeed = estimatorResult.curvatureSign ? -1 * (*(estimatorResult.curvatureSign)) : 0;
129  const double qi = estimatorResult.qualityIndicator;
130 
131  RecoTrack* newRecoTrack = m_storeRecoTracks.appendNew(trackPosition, trackMomentum, trackChargeSeed, "",
133 
134  // TODO: find out where these numbers come from!
135  // This is copied from the VXDTF2 counterpart tracking/modules/spacePointCreator/SPTCmomentumSeedRetrieverModule !
136  TMatrixDSym covSeed(6);
137  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
138  covSeed(3, 3) = 0.01 ; covSeed(4, 4) = 0.01 ; covSeed(5, 5) = 0.04 ;
139  // until here
140 
141  // Set information not required by constructor
142  newRecoTrack->setSeedCovariance(covSeed);
143 
144  // Transfer quality indicator from SPTC to RecoTrack
145  newRecoTrack->setQualityIndicator(qi);
146 
147 
148  unsigned int sortingParameter = 0;
149  for (const SpacePoint* spacePoint : sortedHits) {
150  m_usedSpacePoints.insert(spacePoint);
151 
152  RelationVector<SVDCluster> relatedClusters = spacePoint->getRelationsTo<SVDCluster>(m_param_SVDClustersStoreArrayName);
153  for (const SVDCluster& relatedCluster : relatedClusters) {
154  m_usedClusters.insert(&relatedCluster);
155  newRecoTrack->addSVDHit(&relatedCluster, sortingParameter);
156  sortingParameter++;
157  }
158  }
159  }
160 
161  for (const SpacePoint* spacePoint : spacePoints) {
162  if (TrackFindingCDC::is_in(spacePoint, m_usedSpacePoints)) {
163  spacePoint->setAssignmentState(true);
164  continue;
165  }
166 
167  const auto& relatedClusters = spacePoint->getRelationsTo<SVDCluster>(m_param_SVDClustersStoreArrayName);
168  for (const SVDCluster& relatedCluster : relatedClusters) {
169  if (TrackFindingCDC::is_in(&relatedCluster, m_usedClusters)) {
170  spacePoint->setAssignmentState(true);
171  break;
172  }
173  }
174  }
175 
176 }
The Module parameter list class.
Class implementing the algorithm used for the MC based quality estimation.
void setClustersNames(const std::string &svdClustersName, const std::string &pxdClustersName)
Setter for StoreArray names of SVD and PXD clusters.
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:76
void setSeedCovariance(const TMatrixDSym &seedCovariance)
Set the covariance of the seed. ATTENTION: This is not the fitted covariance.
Definition: RecoTrack.h:529
void setQualityIndicator(const float qualityIndicator)
Set the quality index attached to this RecoTrack. 0 means likely fake.
Definition: RecoTrack.h:735
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:49
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:267
Class for type safe access to objects that are referred to in relations.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:28
@ 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
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
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)
Forward prefixed parameters of this findlet to the module parameter list.
Definition: Findlet.h:69
Interface for an algorithm part that needs to receive the module processing signals.
static const double T
[tesla]
Definition: Unit.h:120
std::string m_param_EstimationMethod
Identifier which estimation method to use.
void initialize() override
Create the store arrays.
bool m_param_MCStrictQualityEstimator
Only required for MCInfo method.
std::set< const SVDCluster * > m_usedClusters
Store the used clusters in the results.
std::string m_param_RecoTracksStoreArrayName
StoreArray name of the output Track StoreArray.
std::string m_param_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
void apply(const std::vector< SpacePointTrackCand > &finishedResults, const std::vector< const SpacePoint * > &spacePoints) override
Store the finishey SpacePointTrackCands into RecoTracks and tag the SpacePoints.
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_param_SVDClustersStoreArrayName
StoreArray name of the SVDCluster 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.