Belle II Software  release-05-02-19
PlaneTriggerTrackTimeEstimatorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/modules/fitter/timeEstimator/PlaneTriggerTrackTimeEstimatorModule.h>
11 
12 #include <tracking/dataobjects/RecoTrack.h>
13 #include <framework/dataobjects/Helix.h>
14 #include <framework/geometry/BFieldManager.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 REG_MODULE(PlaneTriggerTrackTimeEstimator)
20 
22 {
23  addParam("triggerPlanePosition", m_param_triggerPlanePosition, "3-Position of the plane of the trigger.",
24  m_param_triggerPlanePosition);
25 
26  addParam("triggerPlaneDirection", m_param_triggerPlaneNormalDirection, "3-Normal direction of the plane of the trigger.",
27  m_param_triggerPlaneNormalDirection);
28 }
29 
30 double PlaneTriggerTrackTimeEstimatorModule::estimateFlightLengthUsingFittedInformation(genfit::MeasuredStateOnPlane&
31  measuredStateOnPlane)
32 const
33 {
34  B2ASSERT("Position must have 3 components.", m_param_triggerPlanePosition.size() == 3);
35  B2ASSERT("Normal direction must have 3 components.", m_param_triggerPlaneNormalDirection.size() == 3);
36 
37  TVector3 triggerPlanePosition(m_param_triggerPlanePosition[0], m_param_triggerPlanePosition[1], m_param_triggerPlanePosition[2]);
38  TVector3 triggerPlaneNormalDirection(m_param_triggerPlaneNormalDirection[0], m_param_triggerPlaneNormalDirection[1],
39  m_param_triggerPlaneNormalDirection[2]);
40 
41  try {
42  const double s = measuredStateOnPlane.extrapolateToPlane(genfit::SharedPlanePtr(new genfit::DetPlane(triggerPlanePosition,
43  triggerPlaneNormalDirection)));
44 
45  // Negative, because we extrapolated in the wrong direction
46  return -s;
47  } catch (const genfit::Exception& e) {
48  B2WARNING("Extrapolation failed: " << e.what());
49  return 0;
50  }
51 
52 }
53 
54 double PlaneTriggerTrackTimeEstimatorModule::estimateFlightLengthUsingSeedInformation(const RecoTrack& recoTrack) const
55 {
56  B2ASSERT("Position must have 3 components.", m_param_triggerPlanePosition.size() == 3);
57  B2ASSERT("Normal direction must have 3 components.", m_param_triggerPlaneNormalDirection.size() == 3);
58 
59  const TVector3& momentum = recoTrack.getMomentumSeed();
60  const short int charge = recoTrack.getChargeSeed();
61  const TVector3& position = recoTrack.getPositionSeed();
62 
63  const double bZ = BFieldManager::getField(0, 0, 0).Z() / Unit::T;
64  const Helix h(position, momentum, charge, bZ);
65 
66  const double arcLengthAtPosition = h.getArcLength2DAtXY(position.X(), position.Y());
67 
68  double arcLengthOfIntersection = NAN;
69 
70  TVector3 triggerPlanePosition(m_param_triggerPlanePosition[0], m_param_triggerPlanePosition[1], m_param_triggerPlanePosition[2]);
71  TVector3 triggerPlaneNormalDirection(m_param_triggerPlaneNormalDirection[0], m_param_triggerPlaneNormalDirection[1],
72  m_param_triggerPlaneNormalDirection[2]);
73 
74  // Currently, there are only one cases implemented!
75  // Case 1: Plane for a certain z:
76  if (triggerPlaneNormalDirection.X() == 0 and triggerPlaneNormalDirection.Y() == 0) {
77  // This is the easiest case: We just have so solve tan lambda * arcLength + z0 = p_z
78  arcLengthOfIntersection = (triggerPlanePosition.Z() - h.getZ0()) / h.getTanLambda();
79  } else if (triggerPlaneNormalDirection.Z() == 0) {
80  // This case is a bit harder. We have to find solutions for n_x * x + n_y * y = n_x * p_x + n_y * p_y
81  // with n_i the i-th component of the normal vector, p_i the i-th component of the position vector
82  // and x or y given by the helix function.
83 
84  // We make our life a bit easier and rotate the plane (as well as the normal vector) by -phi0. This makes the
85  // helix (and all the equations) much easier.
86  triggerPlaneNormalDirection.RotateZ(-h.getPhi0());
87  triggerPlanePosition.RotateZ(-h.getPhi0());
88 
89  const double n_x = triggerPlaneNormalDirection.X();
90  const double n_y = triggerPlaneNormalDirection.Y();
91 
92  // We first define n_x * p_x + n_y * p_y as alpha
93  const double alpha = triggerPlanePosition.Dot(triggerPlaneNormalDirection);
94 
95  // we do a case distinction between cosmics and "normal" tracks:
96  if (fabs(h.getOmega()) < 1e-3) {
97  // in case of cosmics, this is quite easy
98  const double arcLengthOfTrigger = (alpha + n_y * h.getD0()) / n_x;
99 
100  arcLengthOfIntersection = arcLengthAtPosition - arcLengthOfTrigger;
101  } else {
102  // And then we define a reoccuring element in the equation as beta
103  const double beta = n_y * h.getOmega() * h.getD0() + alpha * h.getOmega();
104 
105  // The equation we have top solve is now
106  // -n_x * A - n_y * (1 - sqrt(1 - A^2)) = beta
107  // with A = sin(\chi) and cos = sqrt(1 - sin^2)
108 
109  // there are two possible solutions, and we want the positive one
110  const double A1 = (sqrt(n_x * n_x * n_y * n_y - 2 * beta * n_y * n_y * n_y - beta * beta * n_y * n_y) - beta * n_x - n_x * n_y) /
111  (n_x * n_x + n_y * n_y);
112  const double A2 = (-sqrt(n_x * n_x * n_y * n_y - 2 * beta * n_y * n_y * n_y - beta * beta * n_y * n_y) - beta * n_x - n_x * n_y) /
113  (n_x * n_x + n_y * n_y);
114 
115  const double x1_unrotated = -A1 / h.getOmega();
116  const double y1_unrotated = -(1 - sqrt(1 - A1 * A1)) / h.getOmega() - h.getD0();
117  const double x2_unrotated = -A2 / h.getOmega();
118  const double y2_unrotated = -(1 - sqrt(1 - A2 * A2)) / h.getOmega() - h.getD0();
119 
120  const double x1_rotated = h.getCosPhi0() * x1_unrotated + h.getSinPhi0() * y1_unrotated;
121  const double y1_rotated = -h.getSinPhi0() * x1_unrotated + h.getCosPhi0() * y1_unrotated;
122  const double x2_rotated = h.getCosPhi0() * x2_unrotated + h.getSinPhi0() * y2_unrotated;
123  const double y2_rotated = -h.getSinPhi0() * x2_unrotated + h.getCosPhi0() * y2_unrotated;
124 
125  // Finaly, we can calculate the arc length
126  const double arcLengthOfTrigger1 = h.getArcLength2DAtXY(x1_rotated, y1_rotated);
127  const double arcLengthOfTrigger2 = h.getArcLength2DAtXY(x2_rotated, y2_rotated);
128 
129  const double arcLengthOfIntersection1 = arcLengthAtPosition - arcLengthOfTrigger1;
130  const double arcLengthOfIntersection2 = arcLengthAtPosition - arcLengthOfTrigger2;
131 
132  arcLengthOfIntersection = fabs(arcLengthOfIntersection1) < fabs(arcLengthOfIntersection2) ? arcLengthOfIntersection1 :
133  arcLengthOfIntersection2;
134  }
135  } else {
136  // All the other cases are not algebraically solvable. As I do not think they will be necessary, we do not
137  // spend time on constructing a numerical solution here.
138  B2FATAL("This case for the normal direction is not implemented for using tracking seeds!");
139  }
140 
141  const double s = arcLengthOfIntersection * hypot(1, h.getTanLambda());
142  return s;
143 }
genfit::Exception
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
genfit::SharedPlanePtr
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
Definition: SharedPlanePtr.h:40
genfit::MeasuredStateOnPlane
#StateOnPlane with additional covariance matrix.
Definition: MeasuredStateOnPlane.h:39
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::RecoTrack::getPositionSeed
TVector3 getPositionSeed() const
Return the position seed stored in the reco track. ATTENTION: This is not the fitted position.
Definition: RecoTrack.h:477
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDC::Helix
Helix parameter class.
Definition: Helix.h:51
Belle2::RecoTrack::getMomentumSeed
TVector3 getMomentumSeed() const
Return the momentum seed stored in the reco track. ATTENTION: This is not the fitted momentum.
Definition: RecoTrack.h:484
genfit::DetPlane
Detector plane.
Definition: DetPlane.h:59
Belle2::RecoTrack::getChargeSeed
short int getChargeSeed() const
Return the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
Definition: RecoTrack.h:497
Belle2::BaseTrackTimeEstimatorModule
Base Module estimating the track time of RecoTracks - before or after the fit.
Definition: BaseTrackTimeEstimatorModule.h:30
Belle2::PlaneTriggerTrackTimeEstimatorModule
Module estimating the track time of RecoTracks - before or after the fit.
Definition: PlaneTriggerTrackTimeEstimatorModule.h:33