Belle II Software development
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/trackingUtilities/eventdata/trajectories/CDCBFieldUtil.h>
9
10#include <tracking/trackingUtilities/geometry/VectorUtil.h>
11
12#include <tracking/trackingUtilities/numerics/ERotation.h>
13#include <tracking/trackingUtilities/numerics/ESign.h>
14
15#include <framework/geometry/BFieldManager.h>
16
17#include <framework/geometry/B2Vector3.h>
18
19#include <Math/Vector3D.h>
20#include <Math/Vector2D.h>
21#include <TMath.h>
22#include <cmath>
23
24using namespace Belle2;
25using namespace TrackingUtilities;
26
28{
29 double b = BFieldManager::getField(0, 0, 0).R();
30 double c_EarthMagneticField = 3.2e-5 * Unit::T;
31 return not(b > 5 * c_EarthMagneticField);
32}
33
38
40{
41 return getBFieldZ(ROOT::Math::XYZVector(0, 0, 0));
42}
43
44double CDCBFieldUtil::getBFieldZ(const ROOT::Math::XYVector& pos2D)
45{
46 return getBFieldZ(ROOT::Math::XYZVector(pos2D.X(), pos2D.Y(), 0));
47}
48
49double CDCBFieldUtil::getBFieldZ(const ROOT::Math::XYZVector& pos3D)
50{
51 // The BFieldMap can not handle positions with not a number coordinates
52 // which can occur if fits fail.
53 // Return NAN to the caller and let him decide what to do next.
54 if (VectorUtil::hasNAN(pos3D)) return NAN;
55 auto mag3D = BFieldManager::getField(pos3D.x(), pos3D.y(), pos3D.z());
56 return mag3D.Z() / Unit::T;
57}
58
59
60
62{
63 return 1.0 / (bField * TMath::C()) * 1E11;
64}
65
66double CDCBFieldUtil::getAlphaZ(const ROOT::Math::XYVector& pos2D)
67{
68 return getAlphaFromBField(getBFieldZ(pos2D));
69}
70
71double CDCBFieldUtil::getAlphaZ(const ROOT::Math::XYZVector& pos3D)
72{
73 return getAlphaFromBField(getBFieldZ(pos3D));
74}
75
76ESign CDCBFieldUtil::ccwInfoToChargeSign(ERotation ccwInfo)
77{
78 return static_cast<ESign>(- ccwInfo * getBFieldZSign());
79}
80
81ERotation CDCBFieldUtil::chargeSignToERotation(ESign chargeSign)
82{
83 return static_cast<ERotation>(- chargeSign * getBFieldZSign());
84}
85
86ERotation CDCBFieldUtil::chargeToERotation(double charge)
87{
88 return chargeSignToERotation(sign(charge));
89}
90
92 double bZ)
93{
94 // In case of zero magnetic field return something large
95 return std::fmin(4440, absMom2D / (bZ * 0.00299792458));
96}
97
99 const ROOT::Math::XYVector& pos2D)
100{
101 return absMom2DToBendRadius(absMom2D, getBFieldZ(pos2D));
102}
103
105 const ROOT::Math::XYZVector& pos3D)
106{
107 return absMom2DToBendRadius(absMom2D, getBFieldZ(pos3D));
108}
109
111 double charge,
112 double bZ)
113{
114 return - charge * bZ * 0.00299792458 * std::fmax(0, 1 / absMom2D);
115}
116
118 double charge,
119 const ROOT::Math::XYVector& pos2D)
120{
121 return absMom2DToCurvature(absMom2D, charge, getBFieldZ(pos2D));
122}
123
125 double charge,
126 const ROOT::Math::XYZVector& pos3D)
127{
128 return absMom2DToCurvature(absMom2D, charge, getBFieldZ(pos3D));
129}
130
132 double bZ)
133{
134 return std::fmin(20, std::fabs(bZ * 0.00299792458 / curvature));
135}
136
138 const ROOT::Math::XYVector& pos2D)
139{
140 return curvatureToAbsMom2D(curvature, getBFieldZ(pos2D));
141}
142
144 const ROOT::Math::XYZVector& pos3D)
145{
146 return curvatureToAbsMom2D(curvature, getBFieldZ(pos3D));
147}
static double curvatureToAbsMom2D(double curvature, double bZ)
Conversion helper for two dimensional curvature to momenta.
static double getAlphaZ(const ROOT::Math::XYVector &pos2D)
Getter for the signed alpha of the magnetic field in z direction.
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 strength 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 getAlphaFromBField(double bField)
Translator 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.
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.
Abstract base class for different kinds of events.