Belle II Software  release-06-02-00
func.h
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 
9 #pragma once
10 #include <cmath>
11 
12 namespace Belle2 {
17  namespace TOP {
18 
20  namespace func {
21 
29  inline double unfold(double x, int nx, double A)
30  {
31  if (nx % 2 == 0) return (nx * A + x);
32  else return (nx * A - x);
33  }
34 
35 
42  inline double unfold(double kx, int nx)
43  {
44  if (nx % 2 == 0) return kx;
45  else return -kx;
46  }
47 
48 
57  inline void fold(double xu, double A, double& x, double& kx, int& nx)
58  {
59  nx = lround(xu / A);
60  x = xu - nx * A;
61  if (nx % 2 != 0) {
62  x = -x;
63  kx = -kx;
64  }
65  }
66 
76  inline double clip(double x, int Nx, double A, double xmi, double xma)
77  {
78  x = unfold(x, Nx, A);
79  x = std::max(std::min(x, xma), xmi) - Nx * A;
80  if (Nx % 2 != 0) x = -x;
81  return x;
82  }
83 
90  inline int getNumOfEven(int j1, int j2)
91  {
92  return (j2 - j1 + 1 - abs(j1) % 2) / 2;
93  }
94 
100  inline double within2PI(double angle)
101  {
102  angle = fmod(angle, 2 * M_PI);
103  if (angle < 0) angle += 2 * M_PI;
104  return angle;
105  }
106 
107  } // func
108  } // TOP
110 } // Belle2
double unfold(double x, int nx, double A)
unfold a coordinate.
Definition: func.h:29
double clip(double x, int Nx, double A, double xmi, double xma)
Performs a clip on x w.r.t xmi and xma.
Definition: func.h:76
void fold(double xu, double A, double &x, double &kx, int &nx)
fold a coordinate (inverse of unfold).
Definition: func.h:57
int getNumOfEven(int j1, int j2)
Returns number of even numbers in the range given by arguments.
Definition: func.h:90
double within2PI(double angle)
Returns angle within 0 and 2PI.
Definition: func.h:100
Abstract base class for different kinds of events.