Belle II Software  release-06-02-00
TwoHitVirtualIPQIFilter.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/TwoHitVirtualIPQIFilter.h>
9 #include <tracking/trackFindingCDC/filters/base/Filter.icc.h>
10 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorMC.h>
11 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorRiemannHelixFit.h>
12 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h>
13 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
14 #include <framework/core/ModuleParamList.templateDetails.h>
15 #include <framework/geometry/BFieldManager.h>
16 #include <framework/database/DBObjPtr.h>
17 #include <mdst/dbobjects/BeamSpot.h>
18 
19 using namespace Belle2;
20 using namespace TrackFindingCDC;
21 using namespace vxdHoughTracking;
22 
23 void TwoHitVirtualIPQIFilter::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
24 {
25  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "trackQualityEstimationMethod"), m_param_EstimationMethod,
26  "Identifier which estimation method to use. Valid identifiers are: [mcInfo, tripletFit, helixFit]",
27  m_param_EstimationMethod);
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  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "MCStrictQualityEstimator"), m_param_MCStrictQualityEstimator,
32  "Only required for MCInfo method. If false combining several MCTracks is allowed.",
33  m_param_MCStrictQualityEstimator);
34 }
35 
36 void TwoHitVirtualIPQIFilter::beginRun()
37 {
38  const double bFieldZ = BFieldManager::getField(0, 0, 0).Z() / Unit::T;
39  m_estimator->setMagneticFieldStrength(bFieldZ);
40 
41  if (m_param_EstimationMethod == "mcInfo") {
42  StoreArray<RecoTrack> mcRecoTracks;
43  mcRecoTracks.isRequired(m_param_MCRecoTracksStoreArrayName);
44  std::string svdClustersName = ""; std::string pxdClustersName = "";
45 
46  if (mcRecoTracks.getEntries() > 0) {
47  svdClustersName = mcRecoTracks[0]->getStoreArrayNameOfSVDHits();
48  pxdClustersName = mcRecoTracks[0]->getStoreArrayNameOfPXDHits();
49  } else {
50  B2WARNING("No Entries in mcRecoTracksStoreArray: using empty cluster name for svd and pxd");
51  }
52 
53  QualityEstimatorMC* MCestimator = static_cast<QualityEstimatorMC*>(m_estimator.get());
54  MCestimator->setClustersNames(svdClustersName, pxdClustersName);
55  }
56 
57 
59  DBObjPtr<BeamSpot> beamSpotDB;
60  if (beamSpotDB.isValid()) {
61  const B2Vector3D& BeamSpotPosition = (*beamSpotDB).getIPPosition();
62  const TMatrixDSym posErr = (*beamSpotDB).getIPPositionCovMatrix();
63  const B2Vector3D BeamSpotPositionError(sqrt(posErr[0][0]), sqrt(posErr[1][1]), sqrt(posErr[2][2]));
64  m_virtualIPSpacePoint = SpacePoint(BeamSpotPosition, BeamSpotPositionError, {0.5, 0.5}, {false, false}, VxdID(0),
66  } else {
67  m_virtualIPSpacePoint = SpacePoint(B2Vector3D(0., 0., 0.), B2Vector3D(0.1, 0.1, 0.5), {0.5, 0.5}, {false, false}, VxdID(0),
69  }
70 
71 }
72 
73 void TwoHitVirtualIPQIFilter::initialize()
74 {
75  // create pointer to chosen estimator
76  if (m_param_EstimationMethod == "mcInfo") {
77  m_estimator = std::make_unique<QualityEstimatorMC>(m_param_MCRecoTracksStoreArrayName, m_param_MCStrictQualityEstimator);
78  } else if (m_param_EstimationMethod == "tripletFit") {
79  m_estimator = std::make_unique<QualityEstimatorTripletFit>();
80  } else if (m_param_EstimationMethod == "helixFit") {
81  m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
82  }
83  B2ASSERT("QualityEstimator could not be initialized with method: " << m_param_EstimationMethod, m_estimator);
84 }
85 
86 TrackFindingCDC::Weight
87 TwoHitVirtualIPQIFilter::operator()(const BasePathFilter::Object& pair)
88 {
89  const std::vector<TrackFindingCDC::WithWeight<const VXDHoughState*>>& previousHits = pair.first;
90 
91  // Do nothing if path is too short or too long
92  if (previousHits.size() != 1) {
93  return NAN;
94  }
95 
96  std::vector<const SpacePoint*> spacePointsVirtIP;
97  spacePointsVirtIP.reserve(previousHits.size() + 2);
98  // Note that the path is always created outside-in.
99  // The tripletFit only works with hits being ordered inside-out, so add the hits in that direction.
100  // First the virtual IP, then the hit that is currently checked, and last the single hit in the path.
101  spacePointsVirtIP.emplace_back(&m_virtualIPSpacePoint);
102  spacePointsVirtIP.emplace_back(pair.second->getHit());
103  spacePointsVirtIP.emplace_back(previousHits.at(0)->getHit());
104  const auto& estimatorResultVirtIP = m_estimator->estimateQualityAndProperties(spacePointsVirtIP);
105 
106  return estimatorResultVirtIP.qualityIndicator;
107 }
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
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.
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
AObject Object
Type of the object to be analysed.
Definition: Filter.dcl.h:33
static const double T
[tesla]
Definition: Unit.h:120
@ VXD
Any type of VXD Sensor.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:493
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Abstract base class for different kinds of events.