Belle II Software  release-08-01-10
BremFindingMatchCompute.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 
9 /* Own header. */
10 #include <ecl/modules/eclTrackBremFinder/BremFindingMatchCompute.h>
11 
12 /* Basf2 headers. */
13 #include <framework/geometry/VectorUtil.h>
14 #include <framework/utilities/Angle.h>
15 #include <mdst/dataobjects/ECLCluster.h>
16 
17 /* Genfit headers. */
18 #include <genfit/MeasuredStateOnPlane.h>
19 
20 /* ROOT headers. */
21 #include <Math/Vector3D.h>
22 
23 using namespace std;
24 using namespace Belle2;
25 
26 bool BremFindingMatchCompute::isMatch()
27 {
28  auto fitted_state = m_measuredStateOnPlane;
29 
30  auto clusterPosition = m_eclCluster.getClusterPosition();
31 
32  TVector3 position = fitted_state.getPos();
33  ROOT::Math::XYZVector fitted_pos(position.X(), position.Y(), position.Z());
34  TVector3 momentum = fitted_state.getMom();
35  ROOT::Math::XYZVector fitted_mom(momentum.X(), momentum.Y(), momentum.Z());
36 
37  auto cov = fitted_state.get6DCov();
38  const double err_px = cov[3][3];
39  const double err_py = cov[4][4];
40  const double err_pz = cov[5][5];
41  const double px = fitted_mom.X();
42  const double py = fitted_mom.Y();
43  const double pz = fitted_mom.Z();
44 
45  const double square_perp = px * px + py * py ;
46  const double perp = std::sqrt(square_perp);
47  const double square_sum = square_perp + pz * pz;
48 
49  const double err_phi = std::sqrt(pow((py / square_perp), 2) * err_px + pow((px / square_perp), 2) * err_py +
50  (py / square_perp) * (px / square_perp) * cov[3][4]);
51  const double err_theta = std::sqrt(pow(((px * pz) / (square_sum * perp)), 2) * err_px +
52  pow(((py * pz) / (square_sum * perp)), 2) * err_py +
53  pow((perp / square_sum), 2) * err_pz +
54  ((px * pz) / (square_sum * perp)) * ((py * pz) / (square_sum * perp)) * cov[3][4] +
55  ((px * pz) / (square_sum * perp)) * (perp / square_sum) * cov[3][5] +
56  ((py * pz) / (square_sum * perp)) * (perp / square_sum) * cov[4][5]);
57 
58 
59  const auto hit_theta = fitted_mom.Theta();
60  double hit_phi = fitted_mom.Phi();
61  if (hit_phi < 0) hit_phi += TMath::TwoPi();
62 
63  PhiAngle hitPhi(hit_phi, err_phi);
64  ThetaAngle hitTheta(hit_theta, err_theta);
65 
66  PhiAngle clusterPhi(0, 0);
67 
68  if ((clusterPosition - fitted_pos).Phi() >= 0) {
69  clusterPhi = PhiAngle((clusterPosition - fitted_pos).Phi(), m_eclCluster.getUncertaintyPhi());
70  } else {
71  clusterPhi = PhiAngle((clusterPosition - fitted_pos).Phi() + TMath::TwoPi(), m_eclCluster.getUncertaintyPhi());
72  }
73  ThetaAngle clusterTheta = ThetaAngle((clusterPosition - fitted_pos).Theta(), m_eclCluster.getUncertaintyTheta());
74 
75  if (clusterPhi.containsIn(hitPhi, m_clusterAcceptanceFactor) &&
76  clusterTheta.containsIn(hitTheta, m_clusterAcceptanceFactor)) {
77 
78  ROOT::Math::XYZVector hitV;
79  VectorUtil::setMagThetaPhi(
80  hitV, 1.0, hitTheta.getAngle(), hitPhi.getAngle());
81  ROOT::Math::XYZVector clusterV;
82  VectorUtil::setMagThetaPhi(
83  clusterV, 1.0, clusterTheta.getAngle(), clusterPhi.getAngle());
84 
85  ROOT::Math::XYZVector distV = hitV - clusterV;
86 
87  m_distanceHitCluster = distV.R();
88 
89  // set the effective acceptance factor
90  double deltaTheta = abs(hitV.Y() - clusterV.Y());
91  m_effAcceptanceFactor = deltaTheta / (err_theta + m_eclCluster.getUncertaintyTheta());
92  double deltaPhi = abs(hitV.Z() - clusterV.Z());
93  double effFactor = deltaPhi / (err_phi + m_eclCluster.getUncertaintyPhi());
94  if (effFactor > m_effAcceptanceFactor) {
95  m_effAcceptanceFactor = effFactor;
96  }
97 
98  return (true);
99 
100  // todo: can use weight here to signal assigment confidence
101 
102  } else {
103  return (false);
104  }
105 }
double getAngle() const
Getter for the angle.
Definition: Angle.h:37
bool containsIn(const PhiAngle &angle, double sigma) const
Check if two angles are compatible.
Definition: Angle.h:175
bool containsIn(const ThetaAngle &angle, double sigma) const
Check if two angles are compatible.
Definition: Angle.h:132
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.