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

commonly used functions More...

Functions

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 78 of file func.h.

79 {
80 x = unfold(x, Nx, A);
81 x = std::max(std::min(x, xma), xmi) - Nx * A;
82 if (Nx % 2 != 0) x = -x;
83 return x;
84 }
double unfold(double x, int nx, double A)
unfold a coordinate.
Definition: func.h:31

◆ 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 59 of file func.h.

60 {
61 nx = lround(xu / A);
62 x = xu - nx * A;
63 if (nx % 2 != 0) {
64 x = -x;
65 kx = -kx;
66 }
67 }

◆ 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 92 of file func.h.

93 {
94 return (j2 - j1 + 1 - std::abs(j1) % 2) / 2;
95 }

◆ 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 114 of file func.h.

115 {
116 auto zAxis = z_Axis.Unit();
117 double cth = zAxis.Z();
118 double sth = sqrt(1 - cth * cth);
119 if (sth == 0) {
120 if (cth < 0) vec = -vec;
121 return;
122 }
123 double cfi = zAxis.X() / sth;
124 double sfi = zAxis.Y() / sth;
125 // rotation by theta around y then by phi around z
126 double x = cth * vec.X() + sth * vec.Z();
127 double y = vec.Y();
128 double z = -sth * vec.X() + cth * vec.Z();
129 vec.SetX(cfi * x - sfi * y);
130 vec.SetY(sfi * x + cfi * y);
131 vec.SetZ(z);
132 }
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 44 of file func.h.

45 {
46 if (nx % 2 == 0) return kx;
47 else return -kx;
48 }

◆ 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 31 of file func.h.

32 {
33 if (nx % 2 == 0) return (nx * A + x);
34 else return (nx * A - x);
35 }

◆ within2PI()

double within2PI ( double  angle)
inline

Returns angle within 0 and 2PI.

Parameters
angleangle
Returns
angle within 0 and 2PI

Definition at line 102 of file func.h.

103 {
104 angle = fmod(angle, 2 * M_PI);
105 if (angle < 0) angle += 2 * M_PI;
106 return angle;
107 }