ROOT  6.06/09
Reference Guide
TMath.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: Rene Brun, Anna Kreshuk, Eddy Offermann, Fons Rademakers 29/07/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TMath
13 #define ROOT_TMath
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TMath //
19 // //
20 // Encapsulate most frequently used Math functions. //
21 // NB. The basic functions Min, Max, Abs and Sign are defined //
22 // in TMathBase. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #ifndef ROOT_Rtypes
27 #include "Rtypes.h"
28 #endif
29 #ifndef ROOT_TMathBase
30 #include "TMathBase.h"
31 #endif
32 
33 #include "TError.h"
34 #include <algorithm>
35 #include <limits>
36 #include <cmath>
37 
38 namespace TMath {
39 
40  /* ************************* */
41  /* * Fundamental constants * */
42  /* ************************* */
43 
44  inline Double_t Pi() { return 3.14159265358979323846; }
45  inline Double_t TwoPi() { return 2.0 * Pi(); }
46  inline Double_t PiOver2() { return Pi() / 2.0; }
47  inline Double_t PiOver4() { return Pi() / 4.0; }
48  inline Double_t InvPi() { return 1.0 / Pi(); }
49  inline Double_t RadToDeg() { return 180.0 / Pi(); }
50  inline Double_t DegToRad() { return Pi() / 180.0; }
51  inline Double_t Sqrt2() { return 1.4142135623730950488016887242097; }
52 
53  // e (base of natural log)
54  inline Double_t E() { return 2.71828182845904523536; }
55 
56  // natural log of 10 (to convert log to ln)
57  inline Double_t Ln10() { return 2.30258509299404568402; }
58 
59  // base-10 log of e (to convert ln to log)
60  inline Double_t LogE() { return 0.43429448190325182765; }
61 
62  // velocity of light
63  inline Double_t C() { return 2.99792458e8; } // m s^-1
64  inline Double_t Ccgs() { return 100.0 * C(); } // cm s^-1
65  inline Double_t CUncertainty() { return 0.0; } // exact
66 
67  // gravitational constant
68  inline Double_t G() { return 6.673e-11; } // m^3 kg^-1 s^-2
69  inline Double_t Gcgs() { return G() / 1000.0; } // cm^3 g^-1 s^-2
70  inline Double_t GUncertainty() { return 0.010e-11; }
71 
72  // G over h-bar C
73  inline Double_t GhbarC() { return 6.707e-39; } // (GeV/c^2)^-2
74  inline Double_t GhbarCUncertainty() { return 0.010e-39; }
75 
76  // standard acceleration of gravity
77  inline Double_t Gn() { return 9.80665; } // m s^-2
78  inline Double_t GnUncertainty() { return 0.0; } // exact
79 
80  // Planck's constant
81  inline Double_t H() { return 6.62606876e-34; } // J s
82  inline Double_t Hcgs() { return 1.0e7 * H(); } // erg s
83  inline Double_t HUncertainty() { return 0.00000052e-34; }
84 
85  // h-bar (h over 2 pi)
86  inline Double_t Hbar() { return 1.054571596e-34; } // J s
87  inline Double_t Hbarcgs() { return 1.0e7 * Hbar(); } // erg s
88  inline Double_t HbarUncertainty() { return 0.000000082e-34; }
89 
90  // hc (h * c)
91  inline Double_t HC() { return H() * C(); } // J m
92  inline Double_t HCcgs() { return Hcgs() * Ccgs(); } // erg cm
93 
94  // Boltzmann's constant
95  inline Double_t K() { return 1.3806503e-23; } // J K^-1
96  inline Double_t Kcgs() { return 1.0e7 * K(); } // erg K^-1
97  inline Double_t KUncertainty() { return 0.0000024e-23; }
98 
99  // Stefan-Boltzmann constant
100  inline Double_t Sigma() { return 5.6704e-8; } // W m^-2 K^-4
101  inline Double_t SigmaUncertainty() { return 0.000040e-8; }
102 
103  // Avogadro constant (Avogadro's Number)
104  inline Double_t Na() { return 6.02214199e+23; } // mol^-1
105  inline Double_t NaUncertainty() { return 0.00000047e+23; }
106 
107  // universal gas constant (Na * K)
108  // http://scienceworld.wolfram.com/physics/UniversalGasConstant.html
109  inline Double_t R() { return K() * Na(); } // J K^-1 mol^-1
110  inline Double_t RUncertainty() { return R()*((KUncertainty()/K()) + (NaUncertainty()/Na())); }
111 
112  // Molecular weight of dry air
113  // 1976 US Standard Atmosphere,
114  // also see http://atmos.nmsu.edu/jsdap/encyclopediawork.html
115  inline Double_t MWair() { return 28.9644; } // kg kmol^-1 (or gm mol^-1)
116 
117  // Dry Air Gas Constant (R / MWair)
118  // http://atmos.nmsu.edu/education_and_outreach/encyclopedia/gas_constant.htm
119  inline Double_t Rgair() { return (1000.0 * R()) / MWair(); } // J kg^-1 K^-1
120 
121  // Euler-Mascheroni Constant
122  inline Double_t EulerGamma() { return 0.577215664901532860606512090082402431042; }
123 
124  // Elementary charge
125  inline Double_t Qe() { return 1.602176462e-19; } // C
126  inline Double_t QeUncertainty() { return 0.000000063e-19; }
127 
128  /* ************************** */
129  /* * Mathematical Functions * */
130  /* ************************** */
131 
132  /* ***************************** */
133  /* * Trigonometrical Functions * */
134  /* ***************************** */
135  inline Double_t Sin(Double_t);
136  inline Double_t Cos(Double_t);
137  inline Double_t Tan(Double_t);
138  inline Double_t SinH(Double_t);
139  inline Double_t CosH(Double_t);
140  inline Double_t TanH(Double_t);
141  inline Double_t ASin(Double_t);
142  inline Double_t ACos(Double_t);
143  inline Double_t ATan(Double_t);
144  inline Double_t ATan2(Double_t, Double_t);
149 
150 
151  /* ************************ */
152  /* * Elementary Functions * */
153  /* ************************ */
154  inline Double_t Ceil(Double_t x);
155  inline Int_t CeilNint(Double_t x);
156  inline Double_t Floor(Double_t x);
157  inline Int_t FloorNint(Double_t x);
158  template<typename T>
159  inline Int_t Nint(T x);
160 
161  inline Double_t Sq(Double_t x);
162  inline Double_t Sqrt(Double_t x);
163  inline Double_t Exp(Double_t x);
164  inline Double_t Ldexp(Double_t x, Int_t exp);
168  inline LongDouble_t Power(Long64_t x, Long64_t y);
169  inline Double_t Power(Double_t x, Double_t y);
170  inline Double_t Power(Double_t x, Int_t y);
171  inline Double_t Log(Double_t x);
173  inline Double_t Log10(Double_t x);
174  inline Int_t Finite(Double_t x);
175  inline Int_t IsNaN(Double_t x);
176 
177  inline Double_t QuietNaN();
178  inline Double_t SignalingNaN();
179  inline Double_t Infinity();
180 
181  template <typename T>
182  struct Limits {
183  inline static T Min();
184  inline static T Max();
185  inline static T Epsilon();
186  };
187 
188  // Some integer math
189  Long_t Hypot(Long_t x, Long_t y); // sqrt(px*px + py*py)
190 
191  // Comparing floating points
193  //return kTRUE if absolute difference between af and bf is less than epsilon
194  return TMath::Abs(af-bf) < epsilon;
195  }
196  inline Bool_t AreEqualRel(Double_t af, Double_t bf, Double_t relPrec) {
197  //return kTRUE if relative difference between af and bf is less than relPrec
198  return TMath::Abs(af-bf) <= 0.5*relPrec*(TMath::Abs(af)+TMath::Abs(bf));
199  }
200 
201  /* ******************** */
202  /* * Array Algorithms * */
203  /* ******************** */
204 
205  // Min, Max of an array
206  template <typename T> T MinElement(Long64_t n, const T *a);
207  template <typename T> T MaxElement(Long64_t n, const T *a);
208 
209  // Locate Min, Max element number in an array
210  template <typename T> Long64_t LocMin(Long64_t n, const T *a);
211  template <typename Iterator> Iterator LocMin(Iterator first, Iterator last);
212  template <typename T> Long64_t LocMax(Long64_t n, const T *a);
213  template <typename Iterator> Iterator LocMax(Iterator first, Iterator last);
214 
215  // Binary search
216  template <typename T> Long64_t BinarySearch(Long64_t n, const T *array, T value);
217  template <typename T> Long64_t BinarySearch(Long64_t n, const T **array, T value);
218  template <typename Iterator, typename Element> Iterator BinarySearch(Iterator first, Iterator last, Element value);
219 
220  // Hashing
221  ULong_t Hash(const void *txt, Int_t ntxt);
222  ULong_t Hash(const char *str);
223 
224  // Sorting
225  template <typename Element, typename Index>
226  void Sort(Index n, const Element* a, Index* index, Bool_t down=kTRUE);
227  template <typename Iterator, typename IndexIterator>
228  void SortItr(Iterator first, Iterator last, IndexIterator index, Bool_t down=kTRUE);
229 
230  void BubbleHigh(Int_t Narr, Double_t *arr1, Int_t *arr2);
231  void BubbleLow (Int_t Narr, Double_t *arr1, Int_t *arr2);
232 
233  Bool_t Permute(Int_t n, Int_t *a); // Find permutations
234 
235  /* ************************* */
236  /* * Geometrical Functions * */
237  /* ************************* */
238 
239  //Sample quantiles
240  void Quantiles(Int_t n, Int_t nprob, Double_t *x, Double_t *quantiles, Double_t *prob,
241  Bool_t isSorted=kTRUE, Int_t *index = 0, Int_t type=7);
242 
243  // IsInside
244  template <typename T> Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y);
245 
246  // Calculate the Cross Product of two vectors
247  template <typename T> T *Cross(const T v1[3],const T v2[3], T out[3]);
248 
249  Float_t Normalize(Float_t v[3]); // Normalize a vector
250  Double_t Normalize(Double_t v[3]); // Normalize a vector
251 
252  //Calculate the Normalized Cross Product of two vectors
253  template <typename T> inline T NormCross(const T v1[3],const T v2[3],T out[3]);
254 
255  // Calculate a normal vector of a plane
256  template <typename T> T *Normal2Plane(const T v1[3],const T v2[3],const T v3[3], T normal[3]);
257 
258  /* ************************ */
259  /* * Polynomial Functions * */
260  /* ************************ */
261 
262  Bool_t RootsCubic(const Double_t coef[4],Double_t &a, Double_t &b, Double_t &c);
263 
264  /* *********************** */
265  /* * Statistic Functions * */
266  /* *********************** */
267 
268  Double_t Binomial(Int_t n,Int_t k); // Calculate the binomial coefficient n over k
275  Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE);
277  Double_t KolmogorovTest(Int_t na, const Double_t *a, Int_t nb, const Double_t *b, Option_t *option);
282  Double_t LogNormal(Double_t x, Double_t sigma, Double_t theta=0, Double_t m=1);
286  Double_t Prob(Double_t chi2,Int_t ndf);
290  Double_t Vavilov(Double_t x, Double_t kappa, Double_t beta2);
291  Double_t VavilovI(Double_t x, Double_t kappa, Double_t beta2);
292  Double_t Voigt(Double_t x, Double_t sigma, Double_t lg, Int_t r = 4);
293 
294  /* ************************** */
295  /* * Statistics over arrays * */
296  /* ************************** */
297 
298  //Mean, Geometric Mean, Median, RMS(sigma)
299 
300  template <typename T> Double_t Mean(Long64_t n, const T *a, const Double_t *w=0);
301  template <typename Iterator> Double_t Mean(Iterator first, Iterator last);
302  template <typename Iterator, typename WeightIterator> Double_t Mean(Iterator first, Iterator last, WeightIterator wfirst);
303 
304  template <typename T> Double_t GeomMean(Long64_t n, const T *a);
305  template <typename Iterator> Double_t GeomMean(Iterator first, Iterator last);
306 
307  template <typename T> Double_t RMS(Long64_t n, const T *a, const Double_t *w=0);
308  template <typename Iterator> Double_t RMS(Iterator first, Iterator last);
309  template <typename Iterator, typename WeightIterator> Double_t RMS(Iterator first, Iterator last, WeightIterator wfirst);
310 
311  template <typename T> Double_t StdDev(Long64_t n, const T *a, const Double_t * w = 0) { return RMS<T>(n,a,w); }
312  template <typename Iterator> Double_t StdDev(Iterator first, Iterator last) { return RMS<Iterator>(first,last); }
313  template <typename Iterator, typename WeightIterator> Double_t StdDev(Iterator first, Iterator last, WeightIterator wfirst) { return RMS<Iterator,WeightIterator>(first,last,wfirst); }
314 
315  template <typename T> Double_t Median(Long64_t n, const T *a, const Double_t *w=0, Long64_t *work=0);
316 
317  //k-th order statistic
318  template <class Element, typename Size> Element KOrdStat(Size n, const Element *a, Size k, Size *work = 0);
319 
320  /* ******************* */
321  /* * Special Functions */
322  /* ******************* */
323 
329 
330  // Bessel functions
331  Double_t BesselI(Int_t n,Double_t x); // integer order modified Bessel function I_n(x)
332  Double_t BesselK(Int_t n,Double_t x); // integer order modified Bessel function K_n(x)
333  Double_t BesselI0(Double_t x); // modified Bessel function I_0(x)
334  Double_t BesselK0(Double_t x); // modified Bessel function K_0(x)
335  Double_t BesselI1(Double_t x); // modified Bessel function I_1(x)
336  Double_t BesselK1(Double_t x); // modified Bessel function K_1(x)
337  Double_t BesselJ0(Double_t x); // Bessel function J0(x) for any real x
338  Double_t BesselJ1(Double_t x); // Bessel function J1(x) for any real x
339  Double_t BesselY0(Double_t x); // Bessel function Y0(x) for positive x
340  Double_t BesselY1(Double_t x); // Bessel function Y1(x) for positive x
341  Double_t StruveH0(Double_t x); // Struve functions of order 0
342  Double_t StruveH1(Double_t x); // Struve functions of order 1
343  Double_t StruveL0(Double_t x); // Modified Struve functions of order 0
344  Double_t StruveL1(Double_t x); // Modified Struve functions of order 1
345 
347  Double_t Erf(Double_t x);
356 }
357 
358 
359 //---- Trig and other functions ------------------------------------------------
360 
361 #include <float.h>
362 
363 #if defined(R__WIN32) && !defined(__CINT__)
364 # ifndef finite
365 # define finite _finite
366 # define isnan _isnan
367 # endif
368 #endif
369 #if defined(R__AIX) || defined(R__SOLARIS_CC50) || \
370  defined(R__HPUX11) || defined(R__GLIBC) || \
371  (defined(R__MACOSX) && (defined(__INTEL_COMPILER) || defined(__arm__)))
372 // math functions are defined inline so we have to include them here
373 # include <math.h>
374 # ifdef R__SOLARIS_CC50
375  extern "C" { int finite(double); }
376 # endif
377 // # if defined(R__GLIBC) && defined(__STRICT_ANSI__)
378 // # ifndef finite
379 // # define finite __finite
380 // # endif
381 // # ifndef isnan
382 // # define isnan __isnan
383 // # endif
384 // # endif
385 #else
386 // don't want to include complete <math.h>
387 extern "C" {
388  extern double sin(double);
389  extern double cos(double);
390  extern double tan(double);
391  extern double sinh(double);
392  extern double cosh(double);
393  extern double tanh(double);
394  extern double asin(double);
395  extern double acos(double);
396  extern double atan(double);
397  extern double atan2(double, double);
398  extern double sqrt(double);
399  extern double exp(double);
400  extern double pow(double, double);
401  extern double log(double);
402  extern double log10(double);
403 #ifndef R__WIN32
404 # if !defined(finite)
405  extern int finite(double);
406 # endif
407 # if !defined(isnan)
408  extern int isnan(double);
409 # endif
410  extern double ldexp(double, int);
411  extern double ceil(double);
412  extern double floor(double);
413 #else
414  _CRTIMP double ldexp(double, int);
415  _CRTIMP double ceil(double);
416  _CRTIMP double floor(double);
417 #endif
418 }
419 #endif
420 
422  { return sin(x); }
423 
425  { return cos(x); }
426 
428  { return tan(x); }
429 
431  { return sinh(x); }
432 
434  { return cosh(x); }
435 
437  { return tanh(x); }
438 
440  { if (x < -1.) return -TMath::Pi()/2;
441  if (x > 1.) return TMath::Pi()/2;
442  return asin(x);
443  }
444 
446  { if (x < -1.) return TMath::Pi();
447  if (x > 1.) return 0;
448  return acos(x);
449  }
450 
452  { return atan(x); }
453 
455  { if (x != 0) return atan2(y, x);
456  if (y == 0) return 0;
457  if (y > 0) return Pi()/2;
458  else return -Pi()/2;
459  }
460 
462  { return x*x; }
463 
465  { return sqrt(x); }
466 
468  { return ceil(x); }
469 
471  { return TMath::Nint(ceil(x)); }
472 
474  { return floor(x); }
475 
477  { return TMath::Nint(floor(x)); }
478 
479 template<typename T>
480 inline Int_t TMath::Nint(T x)
481 {
482  // Round to nearest integer. Rounds half integers to the nearest
483  // even integer.
484  int i;
485  if (x >= 0) {
486  i = int(x + 0.5);
487  if ( i & 1 && x + 0.5 == T(i) ) i--;
488  } else {
489  i = int(x - 0.5);
490  if ( i & 1 && x - 0.5 == T(i) ) i++;
491  }
492  return i;
493 }
494 
496  { return exp(x); }
497 
499  { return ldexp(x, exp); }
500 
502  { return std::pow(x,y); }
503 
505  { return std::pow(x,(LongDouble_t)y); }
506 
508 #if __cplusplus >= 201103 /*C++11*/
509  { return std::pow(x,y); }
510 #else
511  { return std::pow((LongDouble_t)x,(LongDouble_t)y); }
512 #endif
513 
515  { return pow(x, y); }
516 
518 #ifdef R__ANSISTREAM
519  return std::pow(x, y);
520 #else
521  return pow(x, (Double_t) y);
522 #endif
523 }
524 
525 
527  { return log(x); }
528 
530  { return log10(x); }
531 
533 #if defined(R__FAST_MATH)
534 /* Check if it is finite with a mask in order to be consistent in presence of
535  * fast math.
536  * Inspired from the CMSSW FWCore/Utilities package
537  */
538 {
539  const unsigned long long mask = 0x7FF0000000000000LL;
540  union { unsigned long long l; double d;} v;
541  v.d =x;
542  return (v.l&mask)!=mask;
543 }
544 #else
545 # if defined(R__HPUX11)
546  { return isfinite(x); }
547 # elif defined(R__MACOSX)
548 # ifdef isfinite
549  // from math.h
550  { return isfinite(x); }
551 # else
552  // from cmath
553  { return std::isfinite(x); }
554 # endif
555 # else
556  { return finite(x); }
557 # endif
558 #endif
559 
560 #if defined (R__FAST_MATH)
561 /* This namespace provides all the routines necessary for checking if a number
562  * is a NaN also in presence of optimisations affecting the behaviour of the
563  * floating point calculations.
564  * Inspired from the CMSSW FWCore/Utilities package
565  */
566 namespace detailsForFastMath {
567 // abridged from GNU libc 2.6.1 - in detail from
568 // math/math_private.h
569 // sysdeps/ieee754/ldbl-96/math_ldbl.h
570 
571 // part of ths file:
572  /*
573  * ====================================================
574  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
575  *
576  * Developed at SunPro, a Sun Microsystems, Inc. business.
577  * Permission to use, copy, modify, and distribute this
578  * software is freely granted, provided that this notice
579  * is preserved.
580  * ====================================================
581  */
582 
583  // A union which permits us to convert between a double and two 32 bit ints.
584  typedef union {
585  double value;
586  struct {
587  UInt_t lsw;
588  UInt_t msw;
589  } parts;
590  } ieee_double_shape_type;
591 
592 #define EXTRACT_WORDS(ix0,ix1,d) \
593  do { \
594  ieee_double_shape_type ew_u; \
595  ew_u.value = (d); \
596  (ix0) = ew_u.parts.msw; \
597  (ix1) = ew_u.parts.lsw; \
598  } while (0)
599 
600  inline int IsNaN(double x)
601  {
602  UInt_t hx, lx;
603  ieee_double_shape_type ew_u;
604  ew_u.value = (x);
605  hx = ew_u.parts.msw;
606  lx = ew_u.parts.lsw;
607 
608  EXTRACT_WORDS(hx, lx, x);
609 
610  lx |= hx & 0xfffff;
611  hx &= 0x7ff00000;
612  return (hx == 0x7ff00000) && (lx != 0);
613  }
614 }
615 #endif
616 
618 #if defined(R__FAST_MATH)
619  {return detailsForFastMath::IsNaN(x);}
620 #else
621 # if (defined(R__ANSISTREAM) || (defined(R__MACOSX) && defined(__arm__))) && !defined(_AIX) && !defined(__CUDACC__)
622 # if defined(isnan) || defined(R__SOLARIS_CC50) || defined(__INTEL_COMPILER)
623  // from math.h
624  { return ::isnan(x); }
625 # else
626  // from cmath
627  { return std::isnan(x); }
628 # endif
629 # else
630  { return isnan(x); }
631 # endif
632 #endif
633 //--------wrapper to numeric_limits
634 //____________________________________________________________________________
636  // returns a quiet NaN as defined by IEEE 754
637  // see http://en.wikipedia.org/wiki/NaN#Quiet_NaN
638  return std::numeric_limits<Double_t>::quiet_NaN();
639 }
640 
641 //____________________________________________________________________________
643  // returns a signaling NaN as defined by IEEE 754
644  // see http://en.wikipedia.org/wiki/NaN#Signaling_NaN
645  return std::numeric_limits<Double_t>::signaling_NaN();
646 }
647 
649  // returns an infinity as defined by the IEEE standard
651 }
652 
653 template<typename T>
655  // returns maximum representation for type T
656  return (std::numeric_limits<T>::min)(); //N.B. use this signature to avoid class with macro min() on Windows
657 }
658 
659 template<typename T>
661  // returns minimum double representation
662  return (std::numeric_limits<T>::max)(); //N.B. use this signature to avoid class with macro max() on Windows
663 }
664 
665 template<typename T>
667  // returns minimum double representation
669 }
670 
671 
672 //-------- Advanced -------------
673 
674 template <typename T> inline T TMath::NormCross(const T v1[3],const T v2[3],T out[3])
675 {
676  // Calculate the Normalized Cross Product of two vectors
677  return Normalize(Cross(v1,v2,out));
678 }
679 
680 template <typename T>
682  // Return minimum of array a of length n.
683 
684  return *std::min_element(a,a+n);
685 }
686 
687 template <typename T>
689  // Return maximum of array a of length n.
690 
691  return *std::max_element(a,a+n);
692 }
693 
694 template <typename T>
696  // Return index of array with the minimum element.
697  // If more than one element is minimum returns first found.
698 
699  // Implement here since this one is found to be faster (mainly on 64 bit machines)
700  // than stl generic implementation.
701  // When performing the comparison, the STL implementation needs to de-reference both the array iterator
702  // and the iterator pointing to the resulting minimum location
703 
704  if (n <= 0 || !a) return -1;
705  T xmin = a[0];
706  Long64_t loc = 0;
707  for (Long64_t i = 1; i < n; i++) {
708  if (xmin > a[i]) {
709  xmin = a[i];
710  loc = i;
711  }
712  }
713  return loc;
714 }
715 
716 template <typename Iterator>
717 Iterator TMath::LocMin(Iterator first, Iterator last) {
718  // Return index of array with the minimum element.
719  // If more than one element is minimum returns first found.
720  return std::min_element(first, last);
721 }
722 
723 template <typename T>
725  // Return index of array with the maximum element.
726  // If more than one element is maximum returns first found.
727 
728  // Implement here since it is faster (see comment in LocMin function)
729 
730  if (n <= 0 || !a) return -1;
731  T xmax = a[0];
732  Long64_t loc = 0;
733  for (Long64_t i = 1; i < n; i++) {
734  if (xmax < a[i]) {
735  xmax = a[i];
736  loc = i;
737  }
738  }
739  return loc;
740 }
741 
742 template <typename Iterator>
743 Iterator TMath::LocMax(Iterator first, Iterator last)
744 {
745  // Return index of array with the maximum element.
746  // If more than one element is maximum returns first found.
747 
748  return std::max_element(first, last);
749 }
750 
751 template<typename T>
752 struct CompareDesc {
753 
754  CompareDesc(T d) : fData(d) {}
755 
756  template<typename Index>
757  bool operator()(Index i1, Index i2) {
758  return *(fData + i1) > *(fData + i2);
759  }
760 
762 };
763 
764 template<typename T>
765 struct CompareAsc {
766 
767  CompareAsc(T d) : fData(d) {}
768 
769  template<typename Index>
770  bool operator()(Index i1, Index i2) {
771  return *(fData + i1) < *(fData + i2);
772  }
773 
775 };
776 
777 template <typename Iterator>
778 Double_t TMath::Mean(Iterator first, Iterator last)
779 {
780  // Return the weighted mean of an array defined by the iterators.
781 
782  Double_t sum = 0;
783  Double_t sumw = 0;
784  while ( first != last )
785  {
786  sum += *first;
787  sumw += 1;
788  first++;
789  }
790 
791  return sum/sumw;
792 }
793 
794 template <typename Iterator, typename WeightIterator>
795 Double_t TMath::Mean(Iterator first, Iterator last, WeightIterator w)
796 {
797  // Return the weighted mean of an array defined by the first and
798  // last iterators. The w iterator should point to the first element
799  // of a vector of weights of the same size as the main array.
800 
801  Double_t sum = 0;
802  Double_t sumw = 0;
803  int i = 0;
804  while ( first != last ) {
805  if ( *w < 0) {
806  ::Error("TMath::Mean","w[%d] = %.4e < 0 ?!",i,*w);
807  return 0;
808  }
809  sum += (*w) * (*first);
810  sumw += (*w) ;
811  ++w;
812  ++first;
813  ++i;
814  }
815  if (sumw <= 0) {
816  ::Error("TMath::Mean","sum of weights == 0 ?!");
817  return 0;
818  }
819 
820  return sum/sumw;
821 }
822 
823 template <typename T>
825 {
826  // Return the weighted mean of an array a with length n.
827 
828  if (w) {
829  return TMath::Mean(a, a+n, w);
830  } else {
831  return TMath::Mean(a, a+n);
832  }
833 }
834 
835 template <typename Iterator>
836 Double_t TMath::GeomMean(Iterator first, Iterator last)
837 {
838  // Return the geometric mean of an array defined by the iterators.
839  // geometric_mean = (Prod_i=0,n-1 |a[i]|)^1/n
840 
841  Double_t logsum = 0.;
842  Long64_t n = 0;
843  while ( first != last ) {
844  if (*first == 0) return 0.;
845  Double_t absa = (Double_t) TMath::Abs(*first);
846  logsum += TMath::Log(absa);
847  ++first;
848  ++n;
849  }
850 
851  return TMath::Exp(logsum/n);
852 }
853 
854 template <typename T>
856 {
857  // Return the geometric mean of an array a of size n.
858  // geometric_mean = (Prod_i=0,n-1 |a[i]|)^1/n
859 
860  return TMath::GeomMean(a, a+n);
861 }
862 
863 template <typename Iterator>
864 Double_t TMath::RMS(Iterator first, Iterator last)
865 {
866  // Return the Standard Deviation of an array defined by the iterators.
867  // Note that this function returns the sigma(standard deviation) and
868  // not the root mean square of the array.
869 
870  // Use the two pass algorithm, which is slower (! a factor of 2) but much more
871  // precise. Since we have a vector the 2 pass algorithm is still faster than the
872  // Welford algorithm. (See also ROOT-5545)
873 
874  Double_t n = 0;
875 
876  Double_t tot = 0;
877  Double_t mean = TMath::Mean(first,last);
878  while ( first != last ) {
879  Double_t x = Double_t(*first);
880  tot += (x - mean)*(x - mean);
881  ++first;
882  ++n;
883  }
884  Double_t rms = (n > 1) ? TMath::Sqrt(tot/(n-1)) : 0.0;
885  return rms;
886 }
887 
888 template <typename Iterator, typename WeightIterator>
889 Double_t TMath::RMS(Iterator first, Iterator last, WeightIterator w)
890 {
891  // Return the weighted Standard Deviation of an array defined by the iterators.
892  // Note that this function returns the sigma(standard deviation) and
893  // not the root mean square of the array.
894 
895  // As in the unweighted case use the two pass algorithm
896 
897  Double_t tot = 0;
898  Double_t sumw = 0;
899  Double_t sumw2 = 0;
900  Double_t mean = TMath::Mean(first,last,w);
901  while ( first != last ) {
902  Double_t x = Double_t(*first);
903  sumw += *w;
904  sumw2 += (*w) * (*w);
905  tot += (*w) * (x - mean)*(x - mean);
906  ++first;
907  ++w;
908  }
909  // use the correction neff/(neff -1) for the unbiased formula
910  Double_t rms = TMath::Sqrt(tot * sumw/ (sumw*sumw - sumw2) );
911  return rms;
912 }
913 
914 
915 template <typename T>
916 Double_t TMath::RMS(Long64_t n, const T *a, const Double_t * w)
917 {
918  // Return the Standard Deviation of an array a with length n.
919  // Note that this function returns the sigma(standard deviation) and
920  // not the root mean square of the array.
921 
922  return (w) ? TMath::RMS(a, a+n, w) : TMath::RMS(a, a+n);
923 }
924 
925 template <typename Iterator, typename Element>
926 Iterator TMath::BinarySearch(Iterator first, Iterator last, Element value)
927 {
928  // Binary search in an array defined by its iterators.
929  //
930  // The values in the iterators range are supposed to be sorted
931  // prior to this call. If match is found, function returns
932  // position of element. If no match found, function gives nearest
933  // element smaller than value.
934 
935  Iterator pind;
936  pind = std::lower_bound(first, last, value);
937  if ( (pind != last) && (*pind == value) )
938  return pind;
939  else
940  return ( pind - 1);
941 }
942 
943 
944 template <typename T> Long64_t TMath::BinarySearch(Long64_t n, const T *array, T value)
945 {
946  // Binary search in an array of n values to locate value.
947  //
948  // Array is supposed to be sorted prior to this call.
949  // If match is found, function returns position of element.
950  // If no match found, function gives nearest element smaller than value.
951 
952  const T* pind;
953  pind = std::lower_bound(array, array + n, value);
954  if ( (pind != array + n) && (*pind == value) )
955  return (pind - array);
956  else
957  return ( pind - array - 1);
958 }
959 
960 template <typename T> Long64_t TMath::BinarySearch(Long64_t n, const T **array, T value)
961 {
962  // Binary search in an array of n values to locate value.
963  //
964  // Array is supposed to be sorted prior to this call.
965  // If match is found, function returns position of element.
966  // If no match found, function gives nearest element smaller than value.
967 
968  const T* pind;
969  pind = std::lower_bound(*array, *array + n, value);
970  if ( (pind != *array + n) && (*pind == value) )
971  return (pind - *array);
972  else
973  return ( pind - *array - 1);
974 }
975 
976 template <typename Iterator, typename IndexIterator>
977 void TMath::SortItr(Iterator first, Iterator last, IndexIterator index, Bool_t down)
978 {
979  // Sort the n1 elements of the Short_t array defined by its
980  // iterators. In output the array index contains the indices of
981  // the sorted array. If down is false sort in increasing order
982  // (default is decreasing order).
983 
984  // NOTE that the array index must be created with a length bigger
985  // or equal than the main array before calling this function.
986 
987  int i = 0;
988 
989  IndexIterator cindex = index;
990  for ( Iterator cfirst = first; cfirst != last; ++cfirst )
991  {
992  *cindex = i++;
993  ++cindex;
994  }
995 
996  if ( down )
997  std::sort(index, cindex, CompareDesc<Iterator>(first) );
998  else
999  std::sort(index, cindex, CompareAsc<Iterator>(first) );
1000 }
1001 
1002 template <typename Element, typename Index> void TMath::Sort(Index n, const Element* a, Index* index, Bool_t down)
1003 {
1004  // Sort the n elements of the array a of generic templated type Element.
1005  // In output the array index of type Index contains the indices of the sorted array.
1006  // If down is false sort in increasing order (default is decreasing order).
1007 
1008  // NOTE that the array index must be created with a length >= n
1009  // before calling this function.
1010  // NOTE also that the size type for n must be the same type used for the index array
1011  // (templated type Index)
1012 
1013  for(Index i = 0; i < n; i++) { index[i] = i; }
1014  if ( down )
1015  std::sort(index, index + n, CompareDesc<const Element*>(a) );
1016  else
1017  std::sort(index, index + n, CompareAsc<const Element*>(a) );
1018 }
1019 
1020 template <typename T> T *TMath::Cross(const T v1[3],const T v2[3], T out[3])
1021 {
1022  // Calculate the Cross Product of two vectors:
1023  // out = [v1 x v2]
1024 
1025  out[0] = v1[1] * v2[2] - v1[2] * v2[1];
1026  out[1] = v1[2] * v2[0] - v1[0] * v2[2];
1027  out[2] = v1[0] * v2[1] - v1[1] * v2[0];
1028 
1029  return out;
1030 }
1031 
1032 template <typename T> T * TMath::Normal2Plane(const T p1[3],const T p2[3],const T p3[3], T normal[3])
1033 {
1034  // Calculate a normal vector of a plane.
1035  //
1036  // Input:
1037  // Float_t *p1,*p2,*p3 - 3 3D points belonged the plane to define it.
1038  //
1039  // Return:
1040  // Pointer to 3D normal vector (normalized)
1041 
1042  T v1[3], v2[3];
1043 
1044  v1[0] = p2[0] - p1[0];
1045  v1[1] = p2[1] - p1[1];
1046  v1[2] = p2[2] - p1[2];
1047 
1048  v2[0] = p3[0] - p1[0];
1049  v2[1] = p3[1] - p1[1];
1050  v2[2] = p3[2] - p1[2];
1051 
1052  NormCross(v1,v2,normal);
1053  return normal;
1054 }
1055 
1056 template <typename T> Bool_t TMath::IsInside(T xp, T yp, Int_t np, T *x, T *y)
1057 {
1058  // Function which returns kTRUE if point xp,yp lies inside the
1059  // polygon defined by the np points in arrays x and y, kFALSE otherwise.
1060  // Note that the polygon may be open or closed.
1061 
1062  Int_t i, j = np-1 ;
1063  Bool_t oddNodes = kFALSE;
1064 
1065  for (i=0; i<np; i++) {
1066  if ((y[i]<yp && y[j]>=yp) || (y[j]<yp && y[i]>=yp)) {
1067  if (x[i]+(yp-y[i])/(y[j]-y[i])*(x[j]-x[i])<xp) {
1068  oddNodes = !oddNodes;
1069  }
1070  }
1071  j=i;
1072  }
1073 
1074  return oddNodes;
1075 }
1076 
1077 template <typename T> Double_t TMath::Median(Long64_t n, const T *a, const Double_t *w, Long64_t *work)
1078 {
1079  // Return the median of the array a where each entry i has weight w[i] .
1080  // Both arrays have a length of at least n . The median is a number obtained
1081  // from the sorted array a through
1082  //
1083  // median = (a[jl]+a[jh])/2. where (using also the sorted index on the array w)
1084  //
1085  // sum_i=0,jl w[i] <= sumTot/2
1086  // sum_i=0,jh w[i] >= sumTot/2
1087  // sumTot = sum_i=0,n w[i]
1088  //
1089  // If w=0, the algorithm defaults to the median definition where it is
1090  // a number that divides the sorted sequence into 2 halves.
1091  // When n is odd or n > 1000, the median is kth element k = (n + 1) / 2.
1092  // when n is even and n < 1000the median is a mean of the elements k = n/2 and k = n/2 + 1.
1093  //
1094  // If the weights are supplied (w not 0) all weights must be >= 0
1095  //
1096  // If work is supplied, it is used to store the sorting index and assumed to be
1097  // >= n . If work=0, local storage is used, either on the stack if n < kWorkMax
1098  // or on the heap for n >= kWorkMax .
1099 
1100  const Int_t kWorkMax = 100;
1101 
1102  if (n <= 0 || !a) return 0;
1103  Bool_t isAllocated = kFALSE;
1104  Double_t median;
1105  Long64_t *ind;
1106  Long64_t workLocal[kWorkMax];
1107 
1108  if (work) {
1109  ind = work;
1110  } else {
1111  ind = workLocal;
1112  if (n > kWorkMax) {
1113  isAllocated = kTRUE;
1114  ind = new Long64_t[n];
1115  }
1116  }
1117 
1118  if (w) {
1119  Double_t sumTot2 = 0;
1120  for (Int_t j = 0; j < n; j++) {
1121  if (w[j] < 0) {
1122  ::Error("TMath::Median","w[%d] = %.4e < 0 ?!",j,w[j]);
1123  if (isAllocated) delete [] ind;
1124  return 0;
1125  }
1126  sumTot2 += w[j];
1127  }
1128 
1129  sumTot2 /= 2.;
1130 
1131  Sort(n, a, ind, kFALSE);
1132 
1133  Double_t sum = 0.;
1134  Int_t jl;
1135  for (jl = 0; jl < n; jl++) {
1136  sum += w[ind[jl]];
1137  if (sum >= sumTot2) break;
1138  }
1139 
1140  Int_t jh;
1141  sum = 2.*sumTot2;
1142  for (jh = n-1; jh >= 0; jh--) {
1143  sum -= w[ind[jh]];
1144  if (sum <= sumTot2) break;
1145  }
1146 
1147  median = 0.5*(a[ind[jl]]+a[ind[jh]]);
1148 
1149  } else {
1150 
1151  if (n%2 == 1)
1152  median = KOrdStat(n, a,n/2, ind);
1153  else {
1154  median = 0.5*(KOrdStat(n, a, n/2 -1, ind)+KOrdStat(n, a, n/2, ind));
1155  }
1156  }
1157 
1158  if (isAllocated)
1159  delete [] ind;
1160  return median;
1161 }
1162 
1163 
1164 
1165 
1166 template <class Element, typename Size>
1167 Element TMath::KOrdStat(Size n, const Element *a, Size k, Size *work)
1168 {
1169  // Returns k_th order statistic of the array a of size n
1170  // (k_th smallest element out of n elements).
1171  //
1172  // C-convention is used for array indexing, so if you want
1173  // the second smallest element, call KOrdStat(n, a, 1).
1174  //
1175  // If work is supplied, it is used to store the sorting index and
1176  // assumed to be >= n. If work=0, local storage is used, either on
1177  // the stack if n < kWorkMax or on the heap for n >= kWorkMax.
1178  // Note that the work index array will not contain the sorted indices but
1179  // all indeces of the smaller element in arbitrary order in work[0,...,k-1] and
1180  // all indeces of the larger element in arbitrary order in work[k+1,..,n-1]
1181  // work[k] will contain instead the index of the returned element.
1182  //
1183  // Taken from "Numerical Recipes in C++" without the index array
1184  // implemented by Anna Khreshuk.
1185  //
1186  // See also the declarations at the top of this file
1187 
1188  const Int_t kWorkMax = 100;
1189 
1190  typedef Size Index;
1191 
1192  Bool_t isAllocated = kFALSE;
1193  Size i, ir, j, l, mid;
1194  Index arr;
1195  Index *ind;
1196  Index workLocal[kWorkMax];
1197  Index temp;
1198 
1199  if (work) {
1200  ind = work;
1201  } else {
1202  ind = workLocal;
1203  if (n > kWorkMax) {
1204  isAllocated = kTRUE;
1205  ind = new Index[n];
1206  }
1207  }
1208 
1209  for (Size ii=0; ii<n; ii++) {
1210  ind[ii]=ii;
1211  }
1212  Size rk = k;
1213  l=0;
1214  ir = n-1;
1215  for(;;) {
1216  if (ir<=l+1) { //active partition contains 1 or 2 elements
1217  if (ir == l+1 && a[ind[ir]]<a[ind[l]])
1218  {temp = ind[l]; ind[l]=ind[ir]; ind[ir]=temp;}
1219  Element tmp = a[ind[rk]];
1220  if (isAllocated)
1221  delete [] ind;
1222  return tmp;
1223  } else {
1224  mid = (l+ir) >> 1; //choose median of left, center and right
1225  {temp = ind[mid]; ind[mid]=ind[l+1]; ind[l+1]=temp;}//elements as partitioning element arr.
1226  if (a[ind[l]]>a[ind[ir]]) //also rearrange so that a[l]<=a[l+1]
1227  {temp = ind[l]; ind[l]=ind[ir]; ind[ir]=temp;}
1228 
1229  if (a[ind[l+1]]>a[ind[ir]])
1230  {temp=ind[l+1]; ind[l+1]=ind[ir]; ind[ir]=temp;}
1231 
1232  if (a[ind[l]]>a[ind[l+1]])
1233  {temp = ind[l]; ind[l]=ind[l+1]; ind[l+1]=temp;}
1234 
1235  i=l+1; //initialize pointers for partitioning
1236  j=ir;
1237  arr = ind[l+1];
1238  for (;;){
1239  do i++; while (a[ind[i]]<a[arr]);
1240  do j--; while (a[ind[j]]>a[arr]);
1241  if (j<i) break; //pointers crossed, partitioning complete
1242  {temp=ind[i]; ind[i]=ind[j]; ind[j]=temp;}
1243  }
1244  ind[l+1]=ind[j];
1245  ind[j]=arr;
1246  if (j>=rk) ir = j-1; //keep active the partition that
1247  if (j<=rk) l=i; //contains the k_th element
1248  }
1249  }
1250 }
1251 
1252 #endif
Double_t ACosH(Double_t)
Definition: TMath.cxx:80
Double_t HCcgs()
Definition: TMath.h:92
Double_t BesselI(Int_t n, Double_t x)
Compute the Integer Order Modified Bessel function I_n(x) for n=0,1,2,...
Definition: TMath.cxx:1553
Double_t RUncertainty()
Definition: TMath.h:110
double par[1]
Definition: unuranDistr.cxx:38
Double_t FDist(Double_t F, Double_t N, Double_t M)
Computes the density function of F-distribution (probability function, integral of density...
Definition: TMath.cxx:2224
Double_t Landau(Double_t x, Double_t mpv=0, Double_t sigma=1, Bool_t norm=kFALSE)
The LANDAU function.
Definition: TMath.cxx:473
Double_t ErfInverse(Double_t x)
returns the inverse error function x must be <-1
Definition: TMath.cxx:206
Double_t BreitWigner(Double_t x, Double_t mean=0, Double_t gamma=1)
Calculate a Breit Wigner function with mean and gamma.
Definition: TMath.cxx:442
Double_t NaUncertainty()
Definition: TMath.h:105
float xmin
Definition: THbookFile.cxx:93
Double_t FDistI(Double_t F, Double_t N, Double_t M)
Calculates the cumulative distribution function of F-distribution, this function occurs in the statis...
Definition: TMath.cxx:2242
Double_t G()
Definition: TMath.h:68
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
Double_t PoissonI(Double_t x, Double_t par)
compute the Poisson distribution function for (x,par) This is a non-smooth function.
Definition: TMath.cxx:592
Double_t Floor(Double_t x)
Definition: TMath.h:473
double tanh(double)
Double_t TanH(Double_t)
Definition: TMath.h:436
Double_t Sq(Double_t x)
Definition: TMath.h:461
long long Long64_t
Definition: RtypesCore.h:69
Double_t H()
Definition: TMath.h:81
Float_t Normalize(Float_t v[3])
Normalize a vector v in place.
Definition: TMath.cxx:499
Long64_t LocMax(Long64_t n, const T *a)
Definition: TMath.h:724
bool operator()(Index i1, Index i2)
Definition: TMath.h:757
const Double_t * v1
Definition: TArcBall.cxx:33
static double p3(double t, double a, double b, double c, double d)
Double_t Log(Double_t x)
Definition: TMath.h:526
float Float_t
Definition: RtypesCore.h:53
Double_t PiOver4()
Definition: TMath.h:47
const char Option_t
Definition: RtypesCore.h:62
Double_t KolmogorovProb(Double_t z)
Calculates the Kolmogorov distribution function, Begin_Html.
Definition: TMath.cxx:635
const char * Size
Definition: TXMLSetup.cxx:56
Double_t QuietNaN()
Definition: TMath.h:635
double T(double x)
Definition: ChebyshevPol.h:34
Double_t HbarUncertainty()
Definition: TMath.h:88
Double_t LaplaceDistI(Double_t x, Double_t alpha=0, Double_t beta=1)
Computes the distribution function of Laplace distribution at point x, with location parameter alpha ...
Definition: TMath.cxx:2297
Double_t StudentQuantile(Double_t p, Double_t ndf, Bool_t lower_tail=kTRUE)
Computes quantiles of the Student's t-distribution 1st argument is the probability, at which the quantile is computed 2nd argument - the number of degrees of freedom of the Student distribution When the 3rd argument lower_tail is kTRUE (default)- the algorithm returns such x0, that P(x < x0)=p upper tail (lower_tail is kFALSE)- the algorithm returns such x0, that P(x > x0)=p the algorithm was taken from G.W.Hill, "Algorithm 396, Student's t-quantiles" "Communications of the ACM", 13(10), October 1970.
Definition: TMath.cxx:2553
Double_t NormQuantile(Double_t p)
Computes quantiles for standard normal distribution N(0, 1) at probability p ALGORITHM AS241 APPL...
Definition: TMath.cxx:2342
Double_t KUncertainty()
Definition: TMath.h:97
Double_t DegToRad()
Definition: TMath.h:50
Double_t Sqrt2()
Definition: TMath.h:51
Double_t BetaDist(Double_t x, Double_t p, Double_t q)
Computes the probability density function of the Beta distribution (the distribution function is comp...
Definition: TMath.cxx:2033
Double_t LaplaceDist(Double_t x, Double_t alpha=0, Double_t beta=1)
Computes the probability density function of Laplace distribution at point x, with location parameter...
Definition: TMath.cxx:2281
Double_t HUncertainty()
Definition: TMath.h:83
Double_t Gn()
Definition: TMath.h:77
Double_t Log2(Double_t x)
Definition: TMath.cxx:104
#define N
Double_t RadToDeg()
Definition: TMath.h:49
Double_t StruveH1(Double_t x)
Struve Functions of Order 1.
Definition: TMath.cxx:1809
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
CompareAsc(T d)
Definition: TMath.h:767
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
void BubbleHigh(Int_t Narr, Double_t *arr1, Int_t *arr2)
Bubble sort variant to obtain the order of an array's elements into an index in order to do more usef...
Definition: TMath.cxx:1277
Double_t EulerGamma()
Definition: TMath.h:122
Int_t FloorNint(Double_t x)
Definition: TMath.h:476
Double_t Gamma(Double_t z)
Computation of gamma(z) for all z.
Definition: TMath.cxx:352
Double_t GeomMean(Long64_t n, const T *a)
Definition: TMath.h:855
Double_t BesselJ1(Double_t x)
Returns the Bessel function J1(x) for any real x.
Definition: TMath.cxx:1632
static Vc_ALWAYS_INLINE Vector< T >::Mask isfinite(const Vector< T > &x)
Definition: vector.h:454
Double_t Qe()
Definition: TMath.h:125
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
double cos(double)
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Definition: TMath.cxx:619
Double_t StudentI(Double_t T, Double_t ndf)
Calculates the cumulative distribution function of Student's t-distribution second parameter stands f...
Definition: TMath.cxx:2529
Double_t Kcgs()
Definition: TMath.h:96
Double_t InvPi()
Definition: TMath.h:48
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:501
double beta(double x, double y)
Calculates the beta function.
Double_t Ldexp(Double_t x, Int_t exp)
Definition: TMath.h:498
T * Normal2Plane(const T v1[3], const T v2[3], const T v3[3], T normal[3])
Definition: TMath.h:1032
Double_t Hbarcgs()
Definition: TMath.h:87
Double_t RMS(Long64_t n, const T *a, const Double_t *w=0)
Definition: TMath.h:916
T NormCross(const T v1[3], const T v2[3], T out[3])
Definition: TMath.h:674
double sqrt(double)
Double_t BesselY1(Double_t x)
Returns the Bessel function Y1(x) for positive x.
Definition: TMath.cxx:1702
T fData
Definition: TMath.h:774
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.
Definition: TMath.cxx:2141
Double_t x[n]
Definition: legend1.C:17
Double_t C()
Definition: TMath.h:63
Double_t R()
Definition: TMath.h:109
double acos(double)
double sinh(double)
Double_t Ln10()
Definition: TMath.h:57
void Quantiles(Int_t n, Int_t nprob, Double_t *x, Double_t *quantiles, Double_t *prob, Bool_t isSorted=kTRUE, Int_t *index=0, Int_t type=7)
Computes sample quantiles, corresponding to the given probabilities Parameters: x -the data sample n ...
Definition: TMath.cxx:1173
double log10(double)
Double_t ASinH(Double_t)
Definition: TMath.cxx:67
Double_t Log10(Double_t x)
Definition: TMath.h:529
Double_t BesselI1(Double_t x)
Compute the modified Bessel function I_1(x) for any real x.
Definition: TMath.cxx:1457
static double p2(double t, double a, double b, double c)
Double_t Freq(Double_t x)
Computation of the normal frequency function freq(x).
Definition: TMath.cxx:268
double pow(double, double)
bool operator()(Index i1, Index i2)
Definition: TMath.h:770
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMath.h:1002
Int_t Finite(Double_t x)
Definition: TMath.h:532
Double_t ATan2(Double_t, Double_t)
Definition: TMath.h:454
Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y)
Definition: TMath.h:1056
Double_t TwoPi()
Definition: TMath.h:45
double sin(double)
Double_t Infinity()
Definition: TMath.h:648
void BubbleLow(Int_t Narr, Double_t *arr1, Int_t *arr2)
Opposite ordering of the array arr2[] to that of BubbleHigh.
Definition: TMath.cxx:1316
void Error(const char *location, const char *msgfmt,...)
Double_t Erfc(Double_t x)
Compute the complementary error function erfc(x).
Definition: TMath.cxx:197
Double_t SigmaUncertainty()
Definition: TMath.h:101
char * out
Definition: TBase64.cxx:29
Double_t DiLog(Double_t x)
The DiLogarithm function Code translated by R.Brun from CERNLIB DILOG function C332.
Definition: TMath.cxx:113
Double_t Normalize(Double_t v[3])
Normalize a vector v in place.
Definition: TMath.cxx:516
Double_t GnUncertainty()
Definition: TMath.h:78
Double_t MWair()
Definition: TMath.h:115
Double_t Sigma()
Definition: TMath.h:100
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Definition: TMath.h:192
Bool_t AreEqualRel(Double_t af, Double_t bf, Double_t relPrec)
Definition: TMath.h:196
#define F(x, y, z)
int isnan(double)
double gamma(double x)
ROOT::R::TRInterface & r
Definition: Object.C:4
Double_t VavilovI(Double_t x, Double_t kappa, Double_t beta2)
Returns the value of the Vavilov distribution function Parameters: 1st - the point were the density f...
Definition: TMath.cxx:2653
Double_t CUncertainty()
Definition: TMath.h:65
SVector< double, 2 > v
Definition: Dict.h:5
Double_t GhbarC()
Definition: TMath.h:73
Double_t BesselY0(Double_t x)
Returns the Bessel function Y0(x) for positive x.
Definition: TMath.cxx:1668
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Definition: TMath.cxx:187
Double_t BetaDistI(Double_t x, Double_t p, Double_t q)
Computes the distribution function of the Beta distribution.
Definition: TMath.cxx:2051
Double_t StruveL1(Double_t x)
Modified Struve Function of Order 1.
Definition: TMath.cxx:1932
double cosh(double)
Double_t Voigt(Double_t x, Double_t sigma, Double_t lg, Int_t r=4)
Computation of Voigt function (normalised).
Definition: TMath.cxx:875
Bool_t Permute(Int_t n, Int_t *a)
Simple recursive algorithm to find the permutations of n natural numbers, not necessarily all distinc...
Definition: TMath.cxx:2443
Double_t StruveL0(Double_t x)
Modified Struve Function of Order 0.
Definition: TMath.cxx:1886
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
Definition: TMath.h:824
Double_t Hbar()
Definition: TMath.h:86
unsigned int UInt_t
Definition: RtypesCore.h:42
Double_t KolmogorovTest(Int_t na, const Double_t *a, Int_t nb, const Double_t *b, Option_t *option)
Statistical test whether two one-dimensional sets of points are compatible with coming from the same ...
Definition: TMath.cxx:784
TMarker * m
Definition: textangle.C:8
Double_t K()
Definition: TMath.h:95
Double_t Binomial(Int_t n, Int_t k)
Calculate the binomial coefficient n over k.
Definition: TMath.cxx:2072
Double_t E()
Definition: TMath.h:54
double floor(double)
Double_t LandauI(Double_t x)
Returns the value of the Landau distribution function at point x.
Definition: TMath.cxx:2682
TLine * l
Definition: textangle.C:4
long double LongDouble_t
Definition: RtypesCore.h:57
Double_t ACos(Double_t)
Definition: TMath.h:445
Double_t BesselJ0(Double_t x)
Returns the Bessel function J0(x) for any real x.
Definition: TMath.cxx:1597
static double p1(double t, double a, double b)
float xmax
Definition: THbookFile.cxx:93
Double_t ErfcInverse(Double_t x)
Definition: TMath.cxx:233
const Double_t infinity
Definition: CsgOps.cxx:85
Double_t SignalingNaN()
Definition: TMath.h:642
T * Cross(const T v1[3], const T v2[3], T out[3])
Definition: TMath.h:1020
double asin(double)
ULong_t Hash(const void *txt, Int_t ntxt)
Calculates hash index from any char string.
Definition: TMath.cxx:1371
Double_t GhbarCUncertainty()
Definition: TMath.h:74
REAL epsilon
Definition: triangle.c:617
static T Min()
Definition: TMath.h:654
Double_t Poisson(Double_t x, Double_t par)
compute the Poisson distribution function for (x,par) The Poisson PDF is implemented by means of Eule...
Definition: TMath.cxx:564
Double_t Student(Double_t T, Double_t ndf)
Computes density function for Student's t- distribution (the probability function (integral of densit...
Definition: TMath.cxx:2508
Double_t Beta(Double_t p, Double_t q)
Calculates Beta-function Gamma(p)*Gamma(q)/Gamma(p+q).
Definition: TMath.cxx:1973
Double_t Cos(Double_t)
Definition: TMath.h:424
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculate a gaussian function with mean and sigma.
Definition: TMath.cxx:453
Double_t BesselI0(Double_t x)
Compute the modified Bessel function I_0(x) for any real x.
Definition: TMath.cxx:1389
Double_t Pi()
Definition: TMath.h:44
Double_t BesselK(Int_t n, Double_t x)
Compute the Integer Order Modified Bessel function K_n(x) for n=0,1,2,...
Definition: TMath.cxx:1524
Double_t StdDev(Long64_t n, const T *a, const Double_t *w=0)
Definition: TMath.h:311
long Long_t
Definition: RtypesCore.h:50
Double_t Gcgs()
Definition: TMath.h:69
RooCmdArg Index(RooCategory &icat)
Double_t Exp(Double_t x)
Definition: TMath.h:495
double Double_t
Definition: RtypesCore.h:55
Double_t StruveH0(Double_t x)
Struve Functions of Order 0.
Definition: TMath.cxx:1740
Double_t Rgair()
Definition: TMath.h:119
double atan2(double, double)
int type
Definition: TGX11.cxx:120
Double_t Median(Long64_t n, const T *a, const Double_t *w=0, Long64_t *work=0)
Definition: TMath.h:1077
unsigned long ULong_t
Definition: RtypesCore.h:51
T MaxElement(Long64_t n, const T *a)
Definition: TMath.h:688
double atan(double)
Double_t Hypot(Double_t x, Double_t y)
Definition: TMath.cxx:60
Double_t Hcgs()
Definition: TMath.h:82
Double_t Ccgs()
Definition: TMath.h:64
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
Double_t BesselK0(Double_t x)
Compute the modified Bessel function K_0(x) for positive real x.
Definition: TMath.cxx:1423
Double_t Na()
Definition: TMath.h:104
Double_t BinomialI(Double_t p, Int_t n, Int_t k)
Suppose an event occurs with probability p per trial Then the probability P of its occuring k or more...
Definition: TMath.cxx:2097
Double_t PiOver2()
Definition: TMath.h:46
Double_t BetaCf(Double_t x, Double_t a, Double_t b)
Continued fraction evaluation by modified Lentz's method used in calculation of incomplete Beta funct...
Definition: TMath.cxx:1982
Element KOrdStat(Size n, const Element *a, Size k, Size *work=0)
Definition: TMath.h:1167
CompareDesc(T d)
Definition: TMath.h:754
Double_t GUncertainty()
Definition: TMath.h:70
Double_t GammaDist(Double_t x, Double_t gamma, Double_t mu=0, Double_t beta=1)
Computes the density function of Gamma distribution at point x.
Definition: TMath.cxx:2259
double ceil(double)
Int_t IsNaN(Double_t x)
Definition: TMath.h:617
int finite(double)
double tan(double)
Double_t Factorial(Int_t i)
Compute factorial(n).
Definition: TMath.cxx:250
Double_t Sin(Double_t)
Definition: TMath.h:421
Double_t Ceil(Double_t x)
Definition: TMath.h:467
Double_t ASin(Double_t)
Definition: TMath.h:439
Double_t BesselK1(Double_t x)
Compute the modified Bessel function K_1(x) for positive real x.
Definition: TMath.cxx:1492
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
Definition: TMath.cxx:490
Double_t LogNormal(Double_t x, Double_t sigma, Double_t theta=0, Double_t m=1)
Computes the density of LogNormal distribution at point x.
Definition: TMath.cxx:2319
Double_t SinH(Double_t)
Definition: TMath.h:430
TGLVector3 Cross(const TGLVector3 &v1, const TGLVector3 &v2)
Definition: TGLUtil.h:328
Bool_t RootsCubic(const Double_t coef[4], Double_t &a, Double_t &b, Double_t &c)
Calculates roots of polynomial of 3rd order a*x^3 + b*x^2 + c*x + d, where a == coef[3], b == coef[2], c == coef[1], d == coef[0] coef[3] must be different from 0 If the boolean returned by the method is false: ==> there are 3 real roots a,b,c If the boolean returned by the method is true: ==> there is one real root a and 2 complex conjugates roots (b+i*c,b-i*c) Author: Francois-Xavier Gentit.
Definition: TMath.cxx:1077
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
double exp(double)
Double_t BetaIncomplete(Double_t x, Double_t a, Double_t b)
Calculates the incomplete Beta-function.
Definition: TMath.cxx:2064
Long64_t LocMin(Long64_t n, const T *a)
Definition: TMath.h:695
static T Max()
Definition: TMath.h:660
const Bool_t kTRUE
Definition: Rtypes.h:91
float * q
Definition: THbookFile.cxx:87
Double_t CauchyDist(Double_t x, Double_t t=0, Double_t s=1)
Computes the density of Cauchy distribution at point x by default, standard Cauchy distribution is us...
Definition: TMath.cxx:2125
float value
Definition: math.cpp:443
static T Epsilon()
Definition: TMath.h:666
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
Int_t Nint(T x)
Definition: TMath.h:480
const Int_t n
Definition: legend1.C:16
Double_t ATanH(Double_t)
Definition: TMath.cxx:93
Double_t QeUncertainty()
Definition: TMath.h:126
Double_t CosH(Double_t)
Definition: TMath.h:433
Int_t CeilNint(Double_t x)
Definition: TMath.h:470
Double_t Tan(Double_t)
Definition: TMath.h:427
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMath.h:944
double log(double)
Double_t LogE()
Definition: TMath.h:60
double ldexp(double, int)
Double_t HC()
Definition: TMath.h:91
void SortItr(Iterator first, Iterator last, IndexIterator index, Bool_t down=kTRUE)
Definition: TMath.h:977
Double_t Vavilov(Double_t x, Double_t kappa, Double_t beta2)
Returns the value of the Vavilov density function Parameters: 1st - the point were the density functi...
Definition: TMath.cxx:2620
T MinElement(Long64_t n, const T *a)
Definition: TMath.h:681
Double_t ATan(Double_t)
Definition: TMath.h:451