Belle II Software  release-06-02-00
QualityIndicatorFilter.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/filters/pathFilters/QualityIndicatorFilter.h>
9 #include <tracking/trackFindingCDC/filters/base/Filter.icc.h>
10 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorCircleFit.h>
11 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorMC.h>
12 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorRiemannHelixFit.h>
13 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h>
14 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
15 #include <framework/core/ModuleParamList.templateDetails.h>
16 #include <framework/geometry/BFieldManager.h>
17 
18 using namespace Belle2;
19 using namespace TrackFindingCDC;
20 using namespace vxdHoughTracking;
21 
22 void QualityIndicatorFilter::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
23 {
24  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "trackQualityEstimationMethod"), m_param_EstimationMethod,
25  "Identifier which estimation method to use. Valid identifiers are: [mcInfo, circleFit, tripletFit, helixFit]",
26  m_param_EstimationMethod);
27 
28  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "MCRecoTracksStoreArrayName"), m_param_MCRecoTracksStoreArrayName,
29  "Only required for MCInfo method. Name of StoreArray containing MCRecoTracks.",
30  m_param_MCRecoTracksStoreArrayName);
31 
32  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "MCStrictQualityEstimator"), m_param_MCStrictQualityEstimator,
33  "Only required for MCInfo method. If false combining several MCTracks is allowed.",
34  m_param_MCStrictQualityEstimator);
35 
36  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "QICut"), m_param_QIcut,
37  "Cut on the quality indicator. Only process QI values larger than this.", m_param_QIcut);
38 }
39 
40 void QualityIndicatorFilter::beginRun()
41 {
42  const double bFieldZ = BFieldManager::getField(0, 0, 0).Z() / Unit::T;
43  m_estimator->setMagneticFieldStrength(bFieldZ);
44 
45  if (m_param_EstimationMethod == "mcInfo") {
46  StoreArray<RecoTrack> mcRecoTracks;
47  mcRecoTracks.isRequired(m_param_MCRecoTracksStoreArrayName);
48  std::string svdClustersName = ""; std::string pxdClustersName = "";
49 
50  if (mcRecoTracks.getEntries() > 0) {
51  svdClustersName = mcRecoTracks[0]->getStoreArrayNameOfSVDHits();
52  pxdClustersName = mcRecoTracks[0]->getStoreArrayNameOfPXDHits();
53  } else {
54  B2WARNING("No Entries in mcRecoTracksStoreArray: using empty cluster name for svd and pxd");
55  }
56 
57  QualityEstimatorMC* MCestimator = static_cast<QualityEstimatorMC*>(m_estimator.get());
58  MCestimator->setClustersNames(svdClustersName, pxdClustersName);
59  }
60 }
61 
62 void QualityIndicatorFilter::initialize()
63 {
64  // create pointer to chosen estimator
65  if (m_param_EstimationMethod == "mcInfo") {
66  m_estimator = std::make_unique<QualityEstimatorMC>(m_param_MCRecoTracksStoreArrayName, m_param_MCStrictQualityEstimator);
67  } else if (m_param_EstimationMethod == "tripletFit") {
68  m_estimator = std::make_unique<QualityEstimatorTripletFit>();
69  } else if (m_param_EstimationMethod == "circleFit") {
70  m_estimator = std::make_unique<QualityEstimatorCircleFit>();
71  } else if (m_param_EstimationMethod == "helixFit") {
72  m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
73  }
74  B2ASSERT("QualityEstimator could not be initialized with method: " << m_param_EstimationMethod, m_estimator);
75 }
76 
77 TrackFindingCDC::Weight
78 QualityIndicatorFilter::operator()(const BasePathFilter::Object& pair)
79 {
80  const std::vector<TrackFindingCDC::WithWeight<const VXDHoughState*>>& previousHits = pair.first;
81 
82  std::vector<const SpacePoint*> spacePoints;
83  spacePoints.reserve(previousHits.size() + 1);
84  for (auto& hit : previousHits) {
85  spacePoints.emplace_back(hit->getHit());
86  }
87  spacePoints.emplace_back(pair.second->getHit());
88 
89  // The path is outwards-in, and thus the SPs are added outwards-in, too.
90  // The tripletFit only works with hits inside-out, so reverse the SP vector
91  std::reverse(spacePoints.begin(), spacePoints.end());
92 
93  const auto& estimatorResult = m_estimator->estimateQualityAndProperties(spacePoints);
94 
95  if (estimatorResult.qualityIndicator < m_param_QIcut) {
96  return NAN;
97  }
98 
99  return estimatorResult.qualityIndicator;
100 }
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.
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
AObject Object
Type of the object to be analysed.
Definition: Filter.dcl.h:33
static const double T
[tesla]
Definition: Unit.h:120
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.