Belle II Software  release-06-00-14
CDCBFieldUtil.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/trackFindingCDC/eventdata/trajectories/CDCBFieldUtil.h>
9 
10 #include <tracking/trackFindingCDC/geometry/Vector3D.h>
11 
12 #include <tracking/trackFindingCDC/numerics/ERotation.h>
13 #include <tracking/trackFindingCDC/numerics/ESign.h>
14 
15 #include <framework/geometry/BFieldManager.h>
16 
17 #include <framework/geometry/B2Vector3.h>
18 
19 #include <TMath.h>
20 #include <cmath>
21 
22 using namespace Belle2;
23 using namespace TrackFindingCDC;
24 
26 {
27  B2Vector3D origin(0, 0, 0);
28  double b = BFieldManager::getField(origin).Mag();
29  double c_EarthMagneticField = 3.2e-5 * Unit::T;
30  return not(b > 5 * c_EarthMagneticField);
31 }
32 
34 {
35  return sign(CDCBFieldUtil::getBFieldZ());
36 }
37 
39 {
40  return getBFieldZ(Vector3D(0, 0, 0));
41 }
42 
43 double CDCBFieldUtil::getBFieldZ(const Vector2D& pos2D)
44 {
45  return getBFieldZ(Vector3D(pos2D, 0));
46 }
47 
48 double CDCBFieldUtil::getBFieldZ(const Vector3D& pos3D)
49 {
50  // The BFieldMap can not handle positions with not a number coordinates
51  // which can occure if fits fail.
52  // Return NAN to the caller and let him decide what to do next.
53  if (pos3D.hasNAN()) return NAN;
54  auto mag3D = BFieldManager::getField(pos3D.x(), pos3D.y(), pos3D.z());
55  return mag3D.Z() / Unit::T;
56 }
57 
58 
59 
60 double CDCBFieldUtil::getAlphaFromBField(double bField)
61 {
62  return 1.0 / (bField * TMath::C()) * 1E11;
63 }
64 
65 double CDCBFieldUtil::getAlphaZ(const Vector2D& pos2D)
66 {
67  return getAlphaFromBField(getBFieldZ(pos2D));
68 }
69 
70 double CDCBFieldUtil::getAlphaZ(const Vector3D& pos3D)
71 {
72  return getAlphaFromBField(getBFieldZ(pos3D));
73 }
74 
76 {
77  return static_cast<ESign>(- ccwInfo * getBFieldZSign());
78 }
79 
81 {
82  return static_cast<ERotation>(- chargeSign * getBFieldZSign());
83 }
84 
86 {
87  return chargeSignToERotation(sign(charge));
88 }
89 
90 double CDCBFieldUtil::absMom2DToBendRadius(double absMom2D,
91  double bZ)
92 {
93  // In case of zero magnetic field return something large
94  return std::fmin(4440, absMom2D / (bZ * 0.00299792458));
95 }
96 
97 double CDCBFieldUtil::absMom2DToBendRadius(double absMom2D,
98  const Vector2D& pos2D)
99 {
100  return absMom2DToBendRadius(absMom2D, getBFieldZ(pos2D));
101 }
102 
103 double CDCBFieldUtil::absMom2DToBendRadius(double absMom2D,
104  const Vector3D& pos3D)
105 {
106  return absMom2DToBendRadius(absMom2D, getBFieldZ(pos3D));
107 }
108 
109 double CDCBFieldUtil::absMom2DToCurvature(double absMom2D,
110  double charge,
111  double bZ)
112 {
113  return - charge * bZ * 0.00299792458 * std::fmax(0, 1 / absMom2D);
114 }
115 
116 double CDCBFieldUtil::absMom2DToCurvature(double absMom2D,
117  double charge,
118  const Vector2D& pos2D)
119 {
120  return absMom2DToCurvature(absMom2D, charge, getBFieldZ(pos2D));
121 }
122 
123 double CDCBFieldUtil::absMom2DToCurvature(double absMom2D,
124  double charge,
125  const Vector3D& pos3D)
126 {
127  return absMom2DToCurvature(absMom2D, charge, getBFieldZ(pos3D));
128 }
129 
130 double CDCBFieldUtil::curvatureToAbsMom2D(double curvature,
131  double bZ)
132 {
133  return std::fmin(20, std::fabs(bZ * 0.00299792458 / curvature));
134 }
135 
136 double CDCBFieldUtil::curvatureToAbsMom2D(double curvature,
137  const Vector2D& pos2D)
138 {
139  return curvatureToAbsMom2D(curvature, getBFieldZ(pos2D));
140 }
141 
142 double CDCBFieldUtil::curvatureToAbsMom2D(double curvature,
143  const Vector3D& pos3D)
144 {
145  return curvatureToAbsMom2D(curvature, getBFieldZ(pos3D));
146 }
static double curvatureToAbsMom2D(double curvature, double bZ)
Conversion helper for two dimensional curvature to momenta.
static bool isOff()
Indicator if the magnetic field is off in the current geometry.
static ESign getBFieldZSign()
Getter for the sign of the magnetic field in z direction.
static ESign ccwInfoToChargeSign(ERotation ccwInfo)
Conversion helper from clockwise or counterclockwise travel to the charge sign.
static double getBFieldZ()
Getter for the signed magnetic field stength in z direction at the origin ( in Tesla )
static ERotation chargeSignToERotation(ESign chargeSign)
Conversion helper from the charge sign to clockwise or counterclockwise travel.
static ERotation chargeToERotation(double charge)
Conversion help for charges to clockwise or counterclockwise travel.
static double absMom2DToCurvature(double absMom2D, double charge, double bZ)
Conversion helper for momenta to two dimensional curvature.
static double getAlphaZ(const Vector2D &pos2D)
Getter for the signed alpha of the magnetic field in z direction.
static double getAlphaFromBField(double bField)
Translater from magnetic field strength in Tesla to the alpha value.
static double absMom2DToBendRadius(double absMom2D, double bZ)
Conversion helper for momenta to two dimensional (absolute) bend radius.
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:35
A three dimensional vector.
Definition: Vector3D.h:32
double x() const
Getter for the x coordinate.
Definition: Vector3D.h:462
bool hasNAN() const
Checks if one of the coordinates is NAN.
Definition: Vector3D.h:155
double y() const
Getter for the y coordinate.
Definition: Vector3D.h:474
double z() const
Getter for the z coordinate.
Definition: Vector3D.h:486
static const double T
[tesla]
Definition: Unit.h:120
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition: Cell.h:34
ESign
Enumeration for the distinct sign values of floating point variables.
Definition: ESign.h:27
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: ERotation.h:25
Abstract base class for different kinds of events.