Belle II Software  release-05-02-19
BremFindingMatchCompute.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * Contributors: Thomas Hauth, Patrick Ecker *
5  * *
6  * This software is provided "as is" without any warranty. *
7  **************************************************************************/
8 //This module
9 #include <ecl/modules/eclTrackBremFinder/BremFindingMatchCompute.h>
10 
11 //Framework
12 #include <framework/utilities/Angle.h>
13 
14 //MDST
15 #include <mdst/dataobjects/ECLCluster.h>
16 
17 //genfit
18 #include <genfit/MeasuredStateOnPlane.h>
19 
20 using namespace std;
21 using namespace Belle2;
22 
23 bool BremFindingMatchCompute::isMatch()
24 {
25  auto fitted_state = m_measuredStateOnPlane;
26 
27  auto clusterPosition = m_eclCluster.getClusterPosition();
28 
29  auto fitted_pos = fitted_state.getPos();
30  auto fitted_mom = fitted_state.getMom();
31  auto fitted_dir = fitted_state.getDir();
32 
33  auto cov = fitted_state.get6DCov();
34  const double err_px = cov[3][3];
35  const double err_py = cov[4][4];
36  const double err_pz = cov[5][5];
37  const double px = fitted_mom.X();
38  const double py = fitted_mom.Y();
39  const double pz = fitted_mom.Z();
40 
41  const double square_perp = px * px + py * py ;
42  const double perp = std::sqrt(square_perp);
43  const double square_sum = square_perp + pz * pz;
44 
45  const double err_phi = std::sqrt(pow((py / square_perp), 2) * err_px + pow((px / square_perp), 2) * err_py +
46  (py / square_perp) * (px / square_perp) * cov[3][4]);
47  const double err_theta = std::sqrt(pow(((px * pz) / (square_sum * perp)), 2) * err_px +
48  pow(((py * pz) / (square_sum * perp)), 2) * err_py +
49  pow((perp / square_sum), 2) * err_pz +
50  ((px * pz) / (square_sum * perp)) * ((py * pz) / (square_sum * perp)) * cov[3][4] +
51  ((px * pz) / (square_sum * perp)) * (perp / square_sum) * cov[3][5] +
52  ((py * pz) / (square_sum * perp)) * (perp / square_sum) * cov[4][5]);
53 
54 
55  const auto hit_theta = fitted_mom.Theta();
56  const auto hit_phi = fitted_mom.Phi();
57 
58  PhiAngle hitPhi = PhiAngle(0, 0);
59  if (hit_phi >= 0) {
60  hitPhi = PhiAngle(hit_phi, err_phi);
61  } else {
62  hitPhi = PhiAngle(hit_phi + TMath::TwoPi(), err_phi);
63  }
64  ThetaAngle hitTheta(hit_theta, err_theta);
65 
66  PhiAngle clusterPhi = PhiAngle(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  TVector3 hitV;
79  hitV.SetMagThetaPhi(1.0f, hitTheta.getAngle(), hitPhi.getAngle());
80  TVector3 clusterV;
81  clusterV.SetMagThetaPhi(1.0f, clusterTheta.getAngle(), clusterPhi.getAngle());
82 
83  auto distV = hitV - clusterV;
84 
85  m_distanceHitCluster = distV.Mag();
86 
87  // set the effective acceptance factor
88  double deltaTheta = abs(hitV.Y() - clusterV.Y());
89  m_effAcceptanceFactor = deltaTheta / (err_theta + m_eclCluster.getUncertaintyTheta());
90  double deltaPhi = abs(hitV.Z() - clusterV.Z());
91  double effFactor = deltaPhi / (err_phi + m_eclCluster.getUncertaintyPhi());
92  if (effFactor > m_effAcceptanceFactor) {
93  m_effAcceptanceFactor = effFactor;
94  }
95 
96  return (true);
97 
98  // todo: can use weight here to signal assigment confidence
99 
100  } else {
101  return (false);
102  }
103 }
Belle2::ThetaAngle
Definition: Angle.h:115
Belle2::PhiAngle
Definition: Angle.h:158
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PhiAngle::containsIn
bool containsIn(const PhiAngle &angle, double sigma) const
Check if two angles are compatible.
Definition: Angle.h:185
Belle2::BaseAngle::getAngle
double getAngle() const
Getter for the angle.
Definition: Angle.h:47
Belle2::ThetaAngle::containsIn
bool containsIn(const ThetaAngle &angle, double sigma) const
Check if two angles are compatible.
Definition: Angle.h:142