Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions | Variables
JMATH Namespace Reference

Auxiliary classes and methods for mathematical operations. More...

Classes

struct  JAverage< JQuaternion3D >
 Template spacialisation for averaging quaternions. More...
 
struct  JLegendre< JQuaternion3D,(size_t)-1 >
 Template specialisation for function evaluation of Legendre polynome of quaternions for undefined number of degrees. More...
 
struct  JLegendre< JQuaternion3D, N >
 Template specialisation for function evaluation of Legendre polynome of quaternions for defined number of degrees. More...
 
struct  JCalculator
 Auxiliary class for arithmetic operations on objects. More...
 
struct  JGauss_t
 Gauss model. More...
 
struct  JGauss
 Gauss function object. More...
 
struct  JLegendre_t
 Base class for Legendre polynome. More...
 
struct  JLegendre
 Template definition for function evaluation of Legendre polynome. More...
 
struct  JLegendre< JOrdinate_t,(size_t)-1 >
 Template specialisation for function evaluation of of Legendre polynome for undefined number of degrees. More...
 
struct  JLimits
 Auxiliary class for minimum and maximum values for any class. More...
 
struct  JLimits< T, true >
 Template spacialisation of JMATH::JLimits for numerical values. More...
 
struct  JLimits< T, false >
 Template spacialisation of JMATH::JRandom for other data types. More...
 
struct  JMath_t
 Auxiliary class to hide data type specific methods. More...
 
struct  JMath
 Auxiliary base class for aritmetic operations of derived class types. More...
 
struct  JMath< T, JNullType >
 Template base class for data structures with arithmetic capabilities. More...
 
struct  JAverage
 Auxiliary class to determine average of set of values. More...
 
class  JMatrix1D
 1 x 1 matrix More...
 
class  JMatrix1S
 1 x 1 symmetric matrix More...
 
class  JMatrix2D
 2 x 2 matrix More...
 
class  JMatrix2S
 2 x 2 symmetric matrix More...
 
class  JMatrix3D
 3 x 3 matrix More...
 
class  JMatrix3S
 3 x 3 symmetric matrix More...
 
class  JMatrix4D
 4 x 4 matrix More...
 
class  JMatrix4S
 4 x 4 symmetric matrix More...
 
class  JMatrix5D
 5 x 5 matrix More...
 
class  JMatrix5S
 5 x 5 symmetric matrix More...
 
struct  JMatrixND_t
 Basic NxN matrix. More...
 
struct  JMatrixND
 NxN matrix. More...
 
struct  JMatrixNS
 N x N symmetric matrix. More...
 
struct  JModel_t
 Fit model. More...
 
struct  JNumber
 Simple wrapper around template data type to ensure that zero is the default value. More...
 
struct  JPolynome_t
 Polynome model. More...
 
struct  JPolynome
 Polynome function object. More...
 
class  JPower
 Power law function object. More...
 
struct  JRandom
 Template definition of random value generator. More...
 
struct  JRandom< T, true >
 Template spacialisation of JMATH::JRandom for numerical values. More...
 
struct  JRandom< T, false >
 Template spacialisation of JMATH::JRandom for non-numerical data types. More...
 
class  JTrigonometric
 Trigonometric function object for sin and cos. More...
 
struct  JVectorND
 Nx1 matrix. More...
 
struct  JZero
 Auxiliary class to assign zero value. More...
 

Functions

template<class T >
const JCalculator< T, 1 > & operator* (const T &first, const T &second)
 Product evaluation of objects. More...
 
template<class T , int N>
const JCalculator< T, N+1 > & operator* (const T &first, const JCalculator< T, N > &second)
 Recursive product evaluation of objects. More...
 
template<class T , int N>
const JCalculator< T, N+1 > & operator* (const JCalculator< T, N > &first, const T &second)
 Recursive product evaluation of objects. More...
 
template<class T >
T pow (const T &x, const double y)
 Power $x^y$. More...
 
template<class T >
T interpolate (const T &first, const T &second, const double alpha)
 Interpolation between objects. More...
 
template<class T >
std::iterator_traits< T >
::value_type 
getAverage (T __begin, T __end)
 Get average. More...
 
template<class JValue_t , size_t N>
JValue_t getAverage (const JValue_t(&array)[N])
 Get average. More...
 
template<class JElement_t , class JAllocator_t >
JElement_t getAverage (const array_type< JElement_t, JAllocator_t > &buffer)
 Get average. More...
 
template<class T >
std::iterator_traits< T >
::value_type 
getAverage (T __begin, T __end, typename std::iterator_traits< T >::value_type value)
 Get average. More...
 
template<class JValue_t , size_t N>
JValue_t getAverage (const JValue_t(&array)[N], typename JLANG::JClass< JValue_t >::argument_type value)
 Get average. More...
 
template<class JElement_t , class JAllocator_t >
JElement_t getAverage (const array_type< JElement_t, JAllocator_t > &buffer, typename JLANG::JClass< JElement_t >::argument_type value)
 Get average. More...
 
double gauss (const double x, const double sigma)
 Gauss function (normalised to 1 at x = 0). More...
 
double gauss (const double x, const double x0, const double sigma)
 Gauss function (normalised to 1 at x = x0). More...
 
double Gauss (const double x, const double sigma)
 Normalised Gauss function. More...
 
double Gauss (const double x, const double x0, const double sigma)
 Normalised Gauss function. More...
 
double Gamma (const double a, const double x)
 Incomplete gamma function. More...
 
double legendre (const unsigned int n, const double x)
 Legendre polynome. More...
 
double binomial (const int n, const int k)
 Binomial function. More...
 
void randomize (JMatrix1S *p)
 Randomize matrix. More...
 
void randomize (JMatrix2S *p)
 Randomize matrix. More...
 
void randomize (JMatrix3S *p)
 Randomize matrix. More...
 
void randomize (JMatrix4S *p)
 Randomize matrix. More...
 
void randomize (JMatrix5S *p)
 Randomize matrix. More...
 
long long int factorial (const long long int n)
 Determine factorial. More...
 
long long int factorial (const long long int n, const long long int m)
 Determine combinatorics. More...
 
template<class JFirst_t , class JSecond_t >
bool equals (const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
 Check equality. More...
 
template<class JFirst_t , class JSecond_t >
double getDistanceSquared (const JFirst_t &first, const JSecond_t &second)
 Get square of distance between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getDistance (const JFirst_t &first, const JSecond_t &second)
 Get distance between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getDot (const JFirst_t &first, const JSecond_t &second)
 Get dot product of objects. More...
 
template<class JFirst_t , class JSecond_t >
double getAngle (const JFirst_t &first, const JSecond_t &second)
 Get space angle between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getPerpDot (const JFirst_t &first, const JSecond_t &second)
 Get perpendicular dot product of objects. More...
 
template<class T >
T getCross (const T &first, const T &second)
 Get cross product of objects. More...
 
template<class T >
std::vector< Tconvolve (const std::vector< T > &input, const std::vector< T > &kernel)
 Convolute data with given kernel. More...
 
template<class T >
T getRandom ()
 Get random value. More...
 
template<class T >
T getRandom (const T min, const T max)
 Get uniformly distributed random value between given limits. More...
 
template<class T >
T getRandom (const T min, const T max, const T precision)
 Get uniformly distributed random value between given limits. More...
 
template<>
double getRandom (const double min, const double max, const double precision)
 Template specialisation for data type double. More...
 
template<class T >
T getZero ()
 Get zero value for a given data type. More...
 
template<>
bool getZero< bool > ()
 Get zero value for bool. More...
 
template<>
float getZero< float > ()
 Get zero value for float. More...
 
template<>
double getZero< double > ()
 Get zero value for double. More...
 
template<>
long double getZero< long double > ()
 Get zero value for long double. More...
 

Variables

static const double PI = acos(-1.0)
 Mathematical constants. More...
 
static const double EULER = 0.577215664901533
 Euler number. More...
 
static const long long int KILOBYTE = 1024
 Computing quantities. More...
 
static const long long int MEGABYTE = KILOBYTE*KILOBYTE
 Number of bytes in a kilo-byte. More...
 
static const long long int GIGABYTE = MEGABYTE*KILOBYTE
 Number of bytes in a mega-byte. More...
 
static const JZero zero
 Function object to assign zero value. More...
 

Detailed Description

Auxiliary classes and methods for mathematical operations.

Author
mdejong

Function Documentation

template<class T >
const JCalculator<T, 1>& JMATH::operator* ( const T first,
const T second 
)
inline

Product evaluation of objects.

Multiply objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 53 of file JCalculator.hh.

54  {
56 
58  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Auxiliary class for arithmetic operations on objects.
Definition: JCalculator.hh:18
template<class T , int N>
const JCalculator<T, N+1>& JMATH::operator* ( const T first,
const JCalculator< T, N > &  second 
)
inline

Recursive product evaluation of objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 69 of file JCalculator.hh.

70  {
72 
74  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Auxiliary class for arithmetic operations on objects.
Definition: JCalculator.hh:18
template<class T , int N>
const JCalculator<T, N+1>& JMATH::operator* ( const JCalculator< T, N > &  first,
const T second 
)
inline

Recursive product evaluation of objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 85 of file JCalculator.hh.

86  {
87  JCalculator<T, N+1>::calculator.mul(first, second);
88 
90  }
Auxiliary class for arithmetic operations on objects.
Definition: JCalculator.hh:18
template<class T >
T JMATH::pow ( const T x,
const double  y 
)
inline

Power $x^y$.

Parameters
xvalue
ypower
Returns
result

Definition at line 98 of file JMath.hh.

99  {
100  using namespace JPP;
101 
102  return JMath_t::pow(x, y, JBool<JClass<T>::is_primitive>());
103  }
static T pow(const T &x, const double y, const JLANG::JBool< true > option)
Power .
Definition: JMath.hh:66
template<class T >
T JMATH::interpolate ( const T first,
const T second,
const double  alpha 
)
inline

Interpolation between objects.

The result is equal to result = (1 - alpha) * (first) + (alpha) * (second).

Parameters
firstfirst object
secondsecond object
alphainterpolation factor [0, 1]
Returns
result

Definition at line 400 of file JMath.hh.

403  {
404  return T(first).interpolate(second, alpha);
405  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
do set_variable OUTPUT_DIRECTORY $WORKDIR T
template<class T >
std::iterator_traits<T>::value_type JMATH::getAverage ( T  __begin,
T  __end 
)

Get average.

Parameters
__beginbegin of data
__endend of data
Returns
average value

Definition at line 497 of file JMath.hh.

498  {
499  typedef typename std::iterator_traits<T>::value_type value_type;
500 
501  return JAverage<value_type>(__begin, __end);
502  }
Auxiliary class to determine average of set of values.
Definition: JMath.hh:412
template<class JValue_t , size_t N>
JValue_t JMATH::getAverage ( const JValue_t(&)  array[N])
inline

Get average.

Parameters
arrayc-array of values
Returns
average value

Definition at line 512 of file JMath.hh.

513  {
514  typedef JValue_t value_type;
515 
516  return JAverage<value_type>((const value_type*) array, (const value_type*) array + N);
517  }
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37
Auxiliary class to determine average of set of values.
Definition: JMath.hh:412
template<class JElement_t , class JAllocator_t >
JElement_t JMATH::getAverage ( const array_type< JElement_t, JAllocator_t > &  buffer)

Get average.

Parameters
bufferinput data
Returns
average value

Definition at line 527 of file JMath.hh.

528  {
529  return JAverage<JElement_t>(buffer.begin(), buffer.end());
530  }
Auxiliary class to determine average of set of values.
Definition: JMath.hh:412
template<class T >
std::iterator_traits<T>::value_type JMATH::getAverage ( T  __begin,
T  __end,
typename std::iterator_traits< T >::value_type  value 
)

Get average.

Parameters
__beginbegin of data
__endend of data
valuedefault value
Returns
average value

Definition at line 542 of file JMath.hh.

543  {
544  try {
545  return getAverage(__begin, __end);
546  }
547  catch(const std::exception&) {
548  return value;
549  }
550  }
std::iterator_traits< T >::value_type getAverage(T __begin, T __end)
Get average.
Definition: JMath.hh:497
template<class JValue_t , size_t N>
JValue_t JMATH::getAverage ( const JValue_t(&)  array[N],
typename JLANG::JClass< JValue_t >::argument_type  value 
)
inline

Get average.

Parameters
arrayc-array of values
valuedefault value
Returns
average value

Definition at line 561 of file JMath.hh.

562  {
563  try {
564  return getAverage(array);
565  }
566  catch(const std::exception&) {
567  return value;
568  }
569  }
std::iterator_traits< T >::value_type getAverage(T __begin, T __end)
Get average.
Definition: JMath.hh:497
template<class JElement_t , class JAllocator_t >
JElement_t JMATH::getAverage ( const array_type< JElement_t, JAllocator_t > &  buffer,
typename JLANG::JClass< JElement_t >::argument_type  value 
)

Get average.

Parameters
bufferinput data
valuedefault value
Returns
average value

Definition at line 580 of file JMath.hh.

581  {
582  try {
583  return getAverage(buffer);
584  }
585  catch(const std::exception&) {
586  return value;
587  }
588  }
std::iterator_traits< T >::value_type getAverage(T __begin, T __end)
Get average.
Definition: JMath.hh:497
double JMATH::gauss ( const double  x,
const double  sigma 
)
inline

Gauss function (normalised to 1 at x = 0).

Parameters
xx
sigmasigma
Returns
function value

Definition at line 33 of file JMath/JMathSupportkit.hh.

34  {
35  const double u = x / sigma;
36 
37  if (fabs(u) < 10.0)
38  return exp(-0.5*u*u);
39  else
40  return 0.0;
41  }
then set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))*exp(-0.5 *(y-[1])*(y-[1])/([2]*[2]))" JF2 -o $WORKDIR/f2.root -F "$FORMULA" -@ "p0
double u[N+1]
Definition: JPolint.hh:739
double JMATH::gauss ( const double  x,
const double  x0,
const double  sigma 
)
inline

Gauss function (normalised to 1 at x = x0).

Parameters
xx
x0central value
sigmasigma
Returns
function value

Definition at line 52 of file JMath/JMathSupportkit.hh.

53  {
54  return gauss(x - x0, sigma);
55  }
double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).
double JMATH::Gauss ( const double  x,
const double  sigma 
)
inline

Normalised Gauss function.

Parameters
xx
sigmasigma
Returns
function value

Definition at line 65 of file JMath/JMathSupportkit.hh.

66  {
67  return gauss(x, sigma) / sqrt(2.0*PI) / sigma;
68  }
static const double PI
Mathematical constants.
double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).
double JMATH::Gauss ( const double  x,
const double  x0,
const double  sigma 
)
inline

Normalised Gauss function.

Parameters
xx
x0central value
sigmasigma
Returns
function value

Definition at line 79 of file JMath/JMathSupportkit.hh.

80  {
81  return Gauss(x - x0, sigma);
82  }
double Gauss(const double x, const double sigma)
Normalised Gauss function.
double JMATH::Gamma ( const double  a,
const double  x 
)
inline

Incomplete gamma function.

Parameters
aa
xx
Returns
function value

Definition at line 92 of file JMath/JMathSupportkit.hh.

93  {
94  using namespace std;
95 
96  const int max = 100;
97 
98  if (x < 0.0) { THROW(JValueOutOfRange, "x < 0 " << x); }
99  if (a <= 0.0) { THROW(JValueOutOfRange, "a <= 0 " << a); }
100 
101  const double gln = lgamma(a);
102 
103  if (x < a + 1.0) {
104 
105  if (x <= 0.0) {
106  THROW(JValueOutOfRange, "x <= 0 " << x);
107  }
108 
109  double ap = a;
110  double sum = 1.0 /a;
111  double del = sum;
112 
113  for (int i = 1; i != max; ++i) {
114 
115  ap += 1.0;
116  del *= x/ap;
117  sum += del;
118 
119  if (fabs(del) < fabs(sum)*numeric_limits<double>::epsilon()) {
120  return sum*exp(-x + a*log(x) - gln);
121  }
122  }
123 
124  } else {
125 
126  double b = x + 1.0 - a;
127  double c = numeric_limits<double>::epsilon() / numeric_limits<double>::min();
128  double d = 1.0 / b;
129  double h = d;
130 
131  for (int i = 1; i != max; ++i) {
132 
133  const double an = -i * (i-a);
134 
135  b += 2.0;
136  d = an*d + b;
137 
138  if (fabs(d) < numeric_limits<double>::min()) {
139  d = numeric_limits<double>::min();
140  }
141 
142  c = b + an/c;
143 
144  if (fabs(c) < numeric_limits<double>::min()) {
145  c = numeric_limits<double>::min();
146  }
147 
148  d = 1.0/d;
149 
150  const double del = d*c;
151 
152  h *= del;
153 
154  if (fabs(del - 1.0) < numeric_limits<double>::epsilon()) {
155  return 1.0 - exp(-x + a*log(x) - gln) * h;
156  }
157  }
158 
159  THROW(JValueOutOfRange, "a " << a);
160  }
161 
162  return 0.0;
163  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
then set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))*exp(-0.5 *(y-[1])*(y-[1])/([2]*[2]))" JF2 -o $WORKDIR/f2.root -F "$FORMULA" -@ "p0
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:45
then JCalibrateToT a
Definition: JTuneHV.sh:103
double JMATH::legendre ( const unsigned int  n,
const double  x 
)
inline

Legendre polynome.

Parameters
ndegree
xx
Returns
function value

Definition at line 173 of file JMath/JMathSupportkit.hh.

174  {
175  switch (n) {
176 
177  case 0:
178  return 1.0;
179 
180  case 1:
181  return x;
182 
183  default:
184  {
185  double p0;
186  double p1 = 1.0;
187  double p2 = x;
188 
189  for (unsigned int i = 2; i <= n; ++i) {
190  p0 = p1;
191  p1 = p2;
192  p2 = ((2*i-1) * x*p1 - (i-1) * p0) / i;
193  }
194 
195  return p2;
196  }
197  }
198  }
TPaveText * p1
p2
Definition: module-Z:fit.sh:48
alias put_queue eval echo n
Definition: qlib.csh:19
double JMATH::binomial ( const int  n,
const int  k 
)
inline

Binomial function.

Parameters
nn
kk
Returns
function value

Definition at line 208 of file JMath/JMathSupportkit.hh.

209  {
210  if (k == 0 || n == k) {
211  return 1.0;
212  }
213 
214  if (n <= 0 || k < 0 || n < k) {
215  return 0.0;
216  }
217 
218  const int k1 = std::min(k, n - k);
219  const int k2 = n - k1;
220 
221  double value = k2 + 1;
222 
223  for (int i = k1; i != 1; --i) {
224  value *= (double) (k2 + i) / (double) i;
225  }
226 
227  return value;
228  }
then fatal No sound hydrophone file $HYDROPHONE_TXT fi JGraph f $HYDROPHONE_TXT o $HYDROPHONE_ROOT sort gr k
alias put_queue eval echo n
Definition: qlib.csh:19
void JMATH::randomize ( JMatrix1S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 29 of file JMathTestkit.hh.

30  {
31  new (p) JMatrix1S(getRandom<double>(-1.0, +1.0));
32  }
1 x 1 symmetric matrix
Definition: JMatrix1S.hh:26
void JMATH::randomize ( JMatrix2S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 40 of file JMathTestkit.hh.

41  {
42  new (p) JMatrix2S(getRandom<double>(-1.0,+1.0),
43  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0));
44 
45  p->a01 = p->a10;
46  }
2 x 2 symmetric matrix
Definition: JMatrix2S.hh:26
void JMATH::randomize ( JMatrix3S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 54 of file JMathTestkit.hh.

55  {
56  new (p) JMatrix3S(getRandom<double>(-1.0,+1.0),
57  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
58  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0));
59 
60  p->a01 = p->a10;
61  p->a02 = p->a20;
62  p->a12 = p->a21;
63  }
3 x 3 symmetric matrix
Definition: JMatrix3S.hh:26
void JMATH::randomize ( JMatrix4S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 71 of file JMathTestkit.hh.

72  {
73  new (p) JMatrix4S(getRandom<double>(-1.0,+1.0),
74  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
75  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
76  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0));
77 
78  p->a01 = p->a10;
79  p->a02 = p->a20;
80  p->a03 = p->a30;
81  p->a12 = p->a21;
82  p->a13 = p->a31;
83  p->a23 = p->a32;
84  }
4 x 4 symmetric matrix
Definition: JMatrix4S.hh:26
void JMATH::randomize ( JMatrix5S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 92 of file JMathTestkit.hh.

93  {
94  new (p) JMatrix5S(getRandom<double>(-1.0,+1.0),
95  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
96  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
97  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
98  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0));
99 
100  p->a01 = p->a10;
101  p->a02 = p->a20;
102  p->a03 = p->a30;
103  p->a04 = p->a40;
104  p->a12 = p->a21;
105  p->a13 = p->a31;
106  p->a14 = p->a41;
107  p->a23 = p->a32;
108  p->a24 = p->a42;
109  p->a34 = p->a43;
110  }
5 x 5 symmetric matrix
Definition: JMatrix5S.hh:26
long long int JMATH::factorial ( const long long int  n)
inline

Determine factorial.

Parameters
nnumber
Returns
factorial (= n!)

Definition at line 42 of file JMathToolkit.hh.

43  {
44  if (n < 0) {
45  THROW(JValueOutOfRange, "JMATH::factorial(): invalid argument " << n);
46  }
47 
48  if (n != 1)
49  return n * factorial(n - 1);
50  else
51  return 1;
52  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
long long int factorial(const long long int n)
Determine factorial.
Definition: JMathToolkit.hh:42
alias put_queue eval echo n
Definition: qlib.csh:19
long long int JMATH::factorial ( const long long int  n,
const long long int  m 
)
inline

Determine combinatorics.

Parameters
nnumber
mnumber
Returns
n!/(m!*(n-m)!)

Definition at line 62 of file JMathToolkit.hh.

63  {
64  if (n < 0 || m < 0 || n < m) {
65  THROW(JValueOutOfRange, "JMATH::factorial(): invalid argument " << n << ' ' << m);
66  }
67 
68  if (n == m)
69  return 1;
70  else if (m == 0)
71  return 1;
72  else
73  return factorial(n - 1, m - 1) + factorial(n - 1, m);
74  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
long long int factorial(const long long int n)
Determine factorial.
Definition: JMathToolkit.hh:42
alias put_queue eval echo n
Definition: qlib.csh:19
template<class JFirst_t , class JSecond_t >
bool JMATH::equals ( const JFirst_t &  first,
const JSecond_t &  second,
const double  precision = std::numeric_limits<double>::min() 
)
inline

Check equality.

Parameters
firstfirst object
secondsecond object
precisionprecision
Returns
true if two objects are equals; else false

Definition at line 86 of file JMathToolkit.hh.

89  {
90  return first.equals(second, precision);
91  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
template<class JFirst_t , class JSecond_t >
double JMATH::getDistanceSquared ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get square of distance between objects.

Parameters
firstfirst object
secondsecond object
Returns
square of distance

Definition at line 102 of file JMathToolkit.hh.

104  {
105  return first.getDistanceSquared(second);
106  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
template<class JFirst_t , class JSecond_t >
double JMATH::getDistance ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get distance between objects.

Parameters
firstfirst object
secondsecond object
Returns
distance

Definition at line 117 of file JMathToolkit.hh.

119  {
120  return first.getDistance(second);
121  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
template<class JFirst_t , class JSecond_t >
double JMATH::getDot ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get dot product of objects.

Parameters
firstfirst object
secondsecond object
Returns
dot product

Definition at line 132 of file JMathToolkit.hh.

134  {
135  return first.getDot(second);
136  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
template<class JFirst_t , class JSecond_t >
double JMATH::getAngle ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get space angle between objects.

Parameters
firstfirst object
secondsecond object
Returns
angle [deg]

Definition at line 147 of file JMathToolkit.hh.

149  {
150  const double dot = getDot(first,second);
151 
152  if (dot >= +1.0)
153  return 0.0;
154  else if (dot <= -1.0)
155  return 180.0;
156  else
157  return acos(dot) * 180.0 / acos(-1.0);
158  }
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:409
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
template<class JFirst_t , class JSecond_t >
double JMATH::getPerpDot ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get perpendicular dot product of objects.

Parameters
firstfirst object
secondsecond object
Returns
perpendicular dot product

Definition at line 169 of file JMathToolkit.hh.

171  {
172  return first.getPerpDot(second);
173  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
template<class T >
T JMATH::getCross ( const T first,
const T second 
)
inline

Get cross product of objects.

Parameters
firstfirst object
secondsecond object
Returns
cross product

Definition at line 184 of file JMathToolkit.hh.

186  {
187  return T().getCross(first, second);
188  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
do set_variable OUTPUT_DIRECTORY $WORKDIR T
template<class T >
std::vector<T> JMATH::convolve ( const std::vector< T > &  input,
const std::vector< T > &  kernel 
)
inline

Convolute data with given kernel.

Parameters
inputinput data
kernelconvolution kernel
Returns
convoluted data

Definition at line 199 of file JMathToolkit.hh.

200  {
201  const size_t k = kernel.size();
202  const size_t n = input .size() - k + 1;
203 
204  std::vector<T> out(n, getZero<T>());
205 
206  for (size_t i = 0; i != n; ++i) {
207  for (size_t j = 0; j != k; ++j) {
208  out[i] += input[i + j] * kernel[k - j - 1];
209  }
210  }
211 
212  return out;
213  }
then fatal No sound hydrophone file $HYDROPHONE_TXT fi JGraph f $HYDROPHONE_TXT o $HYDROPHONE_ROOT sort gr k
alias put_queue eval echo n
Definition: qlib.csh:19
int j
Definition: JPolint.hh:666
template<class T >
T JMATH::getRandom ( )
inline

Get random value.

Returns
random value

Definition at line 113 of file JRandom.hh.

114  {
115  return JRandom<T>::getRandom();
116  }
T getRandom()
Get random value.
Definition: JRandom.hh:113
template<class T >
T JMATH::getRandom ( const T  min,
const T  max 
)
inline

Get uniformly distributed random value between given limits.

Parameters
minminimal value
maxmaximal value
Returns
random value

Definition at line 127 of file JRandom.hh.

129  {
130  return JRandom<T, true>::getRandom(min, max);
131  }
T getRandom()
Get random value.
Definition: JRandom.hh:113
template<class T >
T JMATH::getRandom ( const T  min,
const T  max,
const T  precision 
)
inline

Get uniformly distributed random value between given limits.

Parameters
minminimal value
maxmaximal value
precisionprecision
Returns
random value

Definition at line 143 of file JRandom.hh.

146  {
147  return JRandom<T, true>::getRandom(min, max);
148  }
T getRandom()
Get random value.
Definition: JRandom.hh:113
template<>
double JMATH::getRandom ( const double  min,
const double  max,
const double  precision 
)
inline

Template specialisation for data type double.

Definition at line 155 of file JRandom.hh.

158  {
159  double value = getRandom<double>(min, max);
160 
161  if (precision != 0.0) {
162 
163  const long long int ip = (long long int) (1.0 / precision);
164 
165  value = ((double) ((long long int) (value * ip))) / ip;
166  }
167 
168  return value;
169  }
template<class T >
T JMATH::getZero ( )
inline

Get zero value for a given data type.

The default implementation of this method returns an object which is created with the default constructor. This method should be specialised if this value does not correspond to the equivalent of a zero result.

Returns
zero

Definition at line 26 of file JZero.hh.

27  {
28  return T();
29  }
do set_variable OUTPUT_DIRECTORY $WORKDIR T
template<>
bool JMATH::getZero< bool > ( )
inline

Get zero value for bool.

Returns
false

Definition at line 37 of file JZero.hh.

38  {
39  return false;
40  }
template<>
float JMATH::getZero< float > ( )
inline

Get zero value for float.

Returns
zero

Definition at line 48 of file JZero.hh.

49  {
50  return float(0.0);
51  }
template<>
double JMATH::getZero< double > ( )
inline

Get zero value for double.

Returns
zero

Definition at line 60 of file JZero.hh.

61  {
62  return double(0.0);
63  }
template<>
long double JMATH::getZero< long double > ( )
inline

Get zero value for long double.

Returns
zero

Definition at line 72 of file JZero.hh.

73  {
74  return (long double)(0.0);
75  }

Variable Documentation

const double JMATH::PI = acos(-1.0)
static

Mathematical constants.

pi

Definition at line 20 of file JMath/JConstants.hh.

const double JMATH::EULER = 0.577215664901533
static

Euler number.

Definition at line 21 of file JMath/JConstants.hh.

const long long int JMATH::KILOBYTE = 1024
static

Computing quantities.

Definition at line 26 of file JMath/JConstants.hh.

const long long int JMATH::MEGABYTE = KILOBYTE*KILOBYTE
static

Number of bytes in a kilo-byte.

Definition at line 27 of file JMath/JConstants.hh.

const long long int JMATH::GIGABYTE = MEGABYTE*KILOBYTE
static

Number of bytes in a mega-byte.

Definition at line 28 of file JMath/JConstants.hh.

const JZero JMATH::zero
static

Function object to assign zero value.

Definition at line 105 of file JZero.hh.