Belle II Software development
Belle2::TOP::func Namespace Reference

commonly used functions More...

Functions

long lround (double x)
 Rounds to the nearest integer, halfway cases away from zero.
 
double unfold (double x, int nx, double A)
 unfold a coordinate.
 
double unfold (double kx, int nx)
 unfold a direction.
 
void fold (double xu, double A, double &x, double &kx, int &nx)
 fold a coordinate (inverse of unfold).
 
double clip (double x, int Nx, double A, double xmi, double xma)
 Performs a clip on x w.r.t xmi and xma.
 
int getNumOfEven (int j1, int j2)
 Returns number of even numbers in the range given by arguments.
 
double within2PI (double angle)
 Returns angle within 0 and 2PI.
 
void rotateUz (ROOT::Math::XYZVector &vec, const ROOT::Math::XYZVector &z_Axis)
 Replacement for a function TVector3::RotateUz which is not implemented in GenVector classes.
 

Detailed Description

commonly used functions

Function Documentation

◆ clip()

double clip ( double x,
int Nx,
double A,
double xmi,
double xma )
inline

Performs a clip on x w.r.t xmi and xma.

Parameters
xtrue coordinate
Nxsigned number of reflections
Asize for folding/unfolding
xmilower limit on unfolded coordinate x
xmaupper limit on unfolded coordinate x
Returns
clipped x

Definition at line 98 of file func.h.

99 {
100 x = unfold(x, Nx, A);
101 x = std::max(std::min(x, xma), xmi) - Nx * A;
102 if (Nx % 2 != 0) x = -x;
103 return x;
104 }
double unfold(double x, int nx, double A)
unfold a coordinate.
Definition func.h:51

◆ fold()

void fold ( double xu,
double A,
double & x,
double & kx,
int & nx )
inline

fold a coordinate (inverse of unfold).

Parameters
xuunfolded coordinate (position of image)
Asize for folding
xtrue position [out]
kxtrue direction component [in/out]
nxsigned number of reflections [out]

Definition at line 79 of file func.h.

80 {
81 nx = func::lround(xu / A);
82 x = xu - nx * A;
83 if (nx % 2 != 0) {
84 x = -x;
85 kx = -kx;
86 }
87 }
long lround(double x)
Rounds to the nearest integer, halfway cases away from zero.
Definition func.h:31

◆ getNumOfEven()

int getNumOfEven ( int j1,
int j2 )
inline

Returns number of even numbers in the range given by arguments.

Parameters
j1first number
j2last number (exclusive)
Returns
number of even numbers

Definition at line 112 of file func.h.

113 {
114 return (j2 - j1 + 1 - std::abs(j1) % 2) / 2;
115 }

◆ lround()

long lround ( double x)
inline

Rounds to the nearest integer, halfway cases away from zero.

Bit-for-bit equivalent to std::lround, but inlined instead of calling into libm, which matters because this is used in the innermost ray-tracing loops.

Parameters
xvalue to round
Returns
the rounded value

Definition at line 31 of file func.h.

32 {
33 // 2^52: above it every double is already an integer, and the conversion below could overflow
34 if (std::abs(x) < 4503599627370496.0) {
35 x += 0.5;
36 long n = static_cast<long>(std::abs(x)); // truncation towards zero
37 if (x > 0) return n;
38 return -(n + 1);
39 }
40 return std::lround(x); // also takes care of NaN and infinity
41 }

◆ rotateUz()

void rotateUz ( ROOT::Math::XYZVector & vec,
const ROOT::Math::XYZVector & z_Axis )
inline

Replacement for a function TVector3::RotateUz which is not implemented in GenVector classes.

Parameters
vecvector to be rotated from frame S' [in] to frame S [out]
z_Axisvector representing z-axis of the frame S' expressed in the coordinates of frame S

Definition at line 134 of file func.h.

135 {
136 auto zAxis = z_Axis.Unit();
137 double cth = zAxis.Z();
138 double sth = sqrt(1 - cth * cth);
139 if (sth == 0) {
140 if (cth < 0) vec = -vec;
141 return;
142 }
143 double cfi = zAxis.X() / sth;
144 double sfi = zAxis.Y() / sth;
145 // rotation by theta around y then by phi around z
146 double x = cth * vec.X() + sth * vec.Z();
147 double y = vec.Y();
148 double z = -sth * vec.X() + cth * vec.Z();
149 vec.SetX(cfi * x - sfi * y);
150 vec.SetY(sfi * x + cfi * y);
151 vec.SetZ(z);
152 }
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28

◆ unfold() [1/2]

double unfold ( double kx,
int nx )
inline

unfold a direction.

Parameters
kxtrue direction component
nxsigned number of reflections
Returns
unfolded direction component

Definition at line 64 of file func.h.

65 {
66 if (nx % 2 == 0) return kx;
67 else return -kx;
68 }

◆ unfold() [2/2]

double unfold ( double x,
int nx,
double A )
inline

unfold a coordinate.

Parameters
xtrue position
nxsigned number of reflections
Asize for unfolding
Returns
unfolded coordinate (position of image)

Definition at line 51 of file func.h.

52 {
53 if (nx % 2 == 0) return (nx * A + x);
54 else return (nx * A - x);
55 }

◆ within2PI()

double within2PI ( double angle)
inline

Returns angle within 0 and 2PI.

Parameters
angleangle
Returns
angle within 0 and 2PI

Definition at line 122 of file func.h.

123 {
124 angle = fmod(angle, 2 * M_PI);
125 if (angle < 0) angle += 2 * M_PI;
126 return angle;
127 }