Belle II Software  release-08-01-10
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_EstimationMethod,
26  "Identifier which estimation method to use. Valid identifiers are: [mcInfo, tripletFit, helixFit]",
27  m_EstimationMethod);
28  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "MCRecoTracksStoreArrayName"), m_MCRecoTracksStoreArrayName,
29  "Only required for MCInfo method. Name of StoreArray containing MCRecoTracks.",
30  m_MCRecoTracksStoreArrayName);
31  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "MCStrictQualityEstimator"), m_MCStrictQualityEstimator,
32  "Only required for MCInfo method. If false combining several MCTracks is allowed.",
33  m_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_EstimationMethod == "mcInfo") {
42  QualityEstimatorMC* MCestimator = static_cast<QualityEstimatorMC*>(m_estimator.get());
43  MCestimator->forceUpdateClusterNames();
44  }
45 
46 
48  DBObjPtr<BeamSpot> beamSpotDB;
49  if (beamSpotDB.isValid()) {
50  const B2Vector3D& BeamSpotPosition = (*beamSpotDB).getIPPosition();
51  const TMatrixDSym posErr = (*beamSpotDB).getIPPositionCovMatrix();
52  const B2Vector3D BeamSpotPositionError(sqrt(posErr[0][0]), sqrt(posErr[1][1]), sqrt(posErr[2][2]));
53  m_virtualIPSpacePoint = SpacePoint(BeamSpotPosition, BeamSpotPositionError, {0.5, 0.5}, {false, false}, VxdID(0),
55  } else {
56  m_virtualIPSpacePoint = SpacePoint(B2Vector3D(0., 0., 0.), B2Vector3D(0.1, 0.1, 0.5), {0.5, 0.5}, {false, false}, VxdID(0),
58  }
59 
60 }
61 
62 void TwoHitVirtualIPQIFilter::initialize()
63 {
64  // create pointer to chosen estimator
65  if (m_EstimationMethod == "mcInfo") {
66  StoreArray<RecoTrack> mcRecoTracks;
67  mcRecoTracks.isRequired(m_MCRecoTracksStoreArrayName);
68  m_estimator = std::make_unique<QualityEstimatorMC>(m_MCRecoTracksStoreArrayName, m_MCStrictQualityEstimator);
69  } else if (m_EstimationMethod == "tripletFit") {
70  m_estimator = std::make_unique<QualityEstimatorTripletFit>();
71  } else if (m_EstimationMethod == "helixFit") {
72  m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
73  }
74  B2ASSERT("QualityEstimator could not be initialized with method: " << m_EstimationMethod, m_estimator);
75 }
76 
77 TrackFindingCDC::Weight
78 TwoHitVirtualIPQIFilter::operator()(const BasePathFilter::Object& pair)
79 {
80  const std::vector<TrackFindingCDC::WithWeight<const VXDHoughState*>>& previousHits = pair.first;
81 
82  // Do nothing if path is too short or too long
83  if (previousHits.size() != 1) {
84  return NAN;
85  }
86 
87  std::vector<const SpacePoint*> spacePointsVirtIP;
88  spacePointsVirtIP.reserve(previousHits.size() + 2);
89  // Note that the path is always created outside-in.
90  // The tripletFit only works with hits being ordered inside-out, so add the hits in that direction.
91  // First the virtual IP, then the hit that is currently checked, and last the single hit in the path.
92  spacePointsVirtIP.emplace_back(&m_virtualIPSpacePoint);
93  spacePointsVirtIP.emplace_back(pair.second->getHit());
94  spacePointsVirtIP.emplace_back(previousHits.at(0)->getHit());
95  const auto& estimatorResultVirtIP = m_estimator->estimateQualityAndProperties(spacePointsVirtIP);
96 
97  return estimatorResultVirtIP.qualityIndicator;
98 }
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 forceUpdateClusterNames()
Setter to force the class to update its cluster names.
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.
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:516
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Definition: BFieldManager.h:91
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.