ROOT logo
// @(#)root/mathcore:$Id$
// Authors: Rene Brun, Anna Kreshuk, Eddy Offermann, Fons Rademakers   29/07/95

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TMath
#define ROOT_TMath


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TMath                                                                //
//                                                                      //
// Encapsulate most frequently used Math functions.                     //
// NB. The basic functions Min, Max, Abs and Sign are defined           //
// in TMathBase.                                                        //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif
#ifndef ROOT_TMathBase
#include "TMathBase.h"
#endif

#include "TError.h"
#include <algorithm>
#include <limits>
#include <cmath>

namespace TMath {

   /* ************************* */
   /* * Fundamental constants * */
   /* ************************* */

   inline Double_t Pi()       { return 3.14159265358979323846; }
   inline Double_t TwoPi()    { return 2.0 * Pi(); }
   inline Double_t PiOver2()  { return Pi() / 2.0; }
   inline Double_t PiOver4()  { return Pi() / 4.0; }
   inline Double_t InvPi()    { return 1.0 / Pi(); }
   inline Double_t RadToDeg() { return 180.0 / Pi(); }
   inline Double_t DegToRad() { return Pi() / 180.0; }
   inline Double_t Sqrt2()    { return 1.4142135623730950488016887242097; }

   // e (base of natural log)
   inline Double_t E()        { return 2.71828182845904523536; }

   // natural log of 10 (to convert log to ln)
   inline Double_t Ln10()     { return 2.30258509299404568402; }

   // base-10 log of e  (to convert ln to log)
   inline Double_t LogE()     { return 0.43429448190325182765; }

   // velocity of light
   inline Double_t C()        { return 2.99792458e8; }        // m s^-1
   inline Double_t Ccgs()     { return 100.0 * C(); }         // cm s^-1
   inline Double_t CUncertainty() { return 0.0; }             // exact

   // gravitational constant
   inline Double_t G()        { return 6.673e-11; }           // m^3 kg^-1 s^-2
   inline Double_t Gcgs()     { return G() / 1000.0; }        // cm^3 g^-1 s^-2
   inline Double_t GUncertainty() { return 0.010e-11; }

   // G over h-bar C
   inline Double_t GhbarC()   { return 6.707e-39; }           // (GeV/c^2)^-2
   inline Double_t GhbarCUncertainty() { return 0.010e-39; }

   // standard acceleration of gravity
   inline Double_t Gn()       { return 9.80665; }             // m s^-2
   inline Double_t GnUncertainty() { return 0.0; }            // exact

   // Planck's constant
   inline Double_t H()        { return 6.62606876e-34; }      // J s
   inline Double_t Hcgs()     { return 1.0e7 * H(); }         // erg s
   inline Double_t HUncertainty() { return 0.00000052e-34; }

   // h-bar (h over 2 pi)
   inline Double_t Hbar()     { return 1.054571596e-34; }     // J s
   inline Double_t Hbarcgs()  { return 1.0e7 * Hbar(); }      // erg s
   inline Double_t HbarUncertainty() { return 0.000000082e-34; }

   // hc (h * c)
   inline Double_t HC()       { return H() * C(); }           // J m
   inline Double_t HCcgs()    { return Hcgs() * Ccgs(); }     // erg cm

   // Boltzmann's constant
   inline Double_t K()        { return 1.3806503e-23; }       // J K^-1
   inline Double_t Kcgs()     { return 1.0e7 * K(); }         // erg K^-1
   inline Double_t KUncertainty() { return 0.0000024e-23; }

   // Stefan-Boltzmann constant
   inline Double_t Sigma()    { return 5.6704e-8; }           // W m^-2 K^-4
   inline Double_t SigmaUncertainty() { return 0.000040e-8; }

   // Avogadro constant (Avogadro's Number)
   inline Double_t Na()       { return 6.02214199e+23; }      // mol^-1
   inline Double_t NaUncertainty() { return 0.00000047e+23; }

   // universal gas constant (Na * K)
   // http://scienceworld.wolfram.com/physics/UniversalGasConstant.html
   inline Double_t R()        { return K() * Na(); }          // J K^-1 mol^-1
   inline Double_t RUncertainty() { return R()*((KUncertainty()/K()) + (NaUncertainty()/Na())); }

   // Molecular weight of dry air
   // 1976 US Standard Atmosphere,
   // also see http://atmos.nmsu.edu/jsdap/encyclopediawork.html
   inline Double_t MWair()    { return 28.9644; }             // kg kmol^-1 (or gm mol^-1)

   // Dry Air Gas Constant (R / MWair)
   // http://atmos.nmsu.edu/education_and_outreach/encyclopedia/gas_constant.htm
   inline Double_t Rgair()    { return (1000.0 * R()) / MWair(); }  // J kg^-1 K^-1

   // Euler-Mascheroni Constant
   inline Double_t EulerGamma() { return 0.577215664901532860606512090082402431042; }

   // Elementary charge
   inline Double_t Qe()       { return 1.602176462e-19; }     // C
   inline Double_t QeUncertainty() { return 0.000000063e-19; }

   /* ************************** */
   /* * Mathematical Functions * */
   /* ************************** */

   /* ***************************** */
   /* * Trigonometrical Functions * */
   /* ***************************** */
   inline Double_t Sin(Double_t);
   inline Double_t Cos(Double_t);
   inline Double_t Tan(Double_t);
   inline Double_t SinH(Double_t);
   inline Double_t CosH(Double_t);
   inline Double_t TanH(Double_t);
   inline Double_t ASin(Double_t);
   inline Double_t ACos(Double_t);
   inline Double_t ATan(Double_t);
   inline Double_t ATan2(Double_t, Double_t);
          Double_t ASinH(Double_t);
          Double_t ACosH(Double_t);
          Double_t ATanH(Double_t);
          Double_t Hypot(Double_t x, Double_t y);


   /* ************************ */
   /* * Elementary Functions * */
   /* ************************ */
   inline Double_t Ceil(Double_t x);
   inline Int_t    CeilNint(Double_t x);
   inline Double_t Floor(Double_t x);
   inline Int_t    FloorNint(Double_t x);
   template<typename T>
   inline Int_t    Nint(T x); 

   inline Double_t Sqrt(Double_t x);
   inline Double_t Exp(Double_t x);
   inline Double_t Ldexp(Double_t x, Int_t exp);
          Double_t Factorial(Int_t i);
   inline LongDouble_t Power(LongDouble_t x, LongDouble_t y);
   inline LongDouble_t Power(LongDouble_t x, Long64_t y);
   inline LongDouble_t Power(Long64_t x, Long64_t y);
   inline Double_t Power(Double_t x, Double_t y);
   inline Double_t Power(Double_t x, Int_t y);
   inline Double_t Log(Double_t x);
          Double_t Log2(Double_t x);
   inline Double_t Log10(Double_t x);
   inline Int_t    Finite(Double_t x);
   inline Int_t    IsNaN(Double_t x);

   inline Double_t QuietNaN(); 
   inline Double_t SignalingNaN(); 
   inline Double_t Infinity(); 

   template <typename T> 
   struct Limits { 
      inline static T Min(); 
      inline static T Max(); 
      inline static T Epsilon(); 
   };

   // Some integer math
   Long_t   Hypot(Long_t x, Long_t y);     // sqrt(px*px + py*py)

   // Comparing floating points
   inline Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon) {
      //return kTRUE if absolute difference between af and bf is less than epsilon
      return TMath::Abs(af-bf) < epsilon;
   }
   inline Bool_t AreEqualRel(Double_t af, Double_t bf, Double_t relPrec) {
      //return kTRUE if relative difference between af and bf is less than relPrec
      return TMath::Abs(af-bf) <= 0.5*relPrec*(TMath::Abs(af)+TMath::Abs(bf));
   }

   /* ******************** */
   /* * Array Algorithms * */
   /* ******************** */

   // Min, Max of an array
   template <typename T> T MinElement(Long64_t n, const T *a);
   template <typename T> T MaxElement(Long64_t n, const T *a);

   // Locate Min, Max element number in an array
   template <typename T> Long64_t  LocMin(Long64_t n, const T *a);
   template <typename Iterator> Iterator LocMin(Iterator first, Iterator last);
   template <typename T> Long64_t  LocMax(Long64_t n, const T *a);
   template <typename Iterator> Iterator LocMax(Iterator first, Iterator last);

   // Binary search
   template <typename T> Long64_t BinarySearch(Long64_t n, const T  *array, T value);
   template <typename T> Long64_t BinarySearch(Long64_t n, const T **array, T value);
   template <typename Iterator, typename Element> Iterator BinarySearch(Iterator first, Iterator last, Element value);

   // Hashing
   ULong_t Hash(const void *txt, Int_t ntxt);
   ULong_t Hash(const char *str);

   // Sorting
   template <typename Element, typename Index>
   void Sort(Index n, const Element* a, Index* index, Bool_t down=kTRUE);
   template <typename Iterator, typename IndexIterator>
   void SortItr(Iterator first, Iterator last, IndexIterator index, Bool_t down=kTRUE);

   void BubbleHigh(Int_t Narr, Double_t *arr1, Int_t *arr2);
   void BubbleLow (Int_t Narr, Double_t *arr1, Int_t *arr2);

   Bool_t   Permute(Int_t n, Int_t *a); // Find permutations

   /* ************************* */
   /* * Geometrical Functions * */
   /* ************************* */

   //Sample quantiles
   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);

   // IsInside
   template <typename T> Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y);

   // Calculate the Cross Product of two vectors
   template <typename T> T *Cross(const T v1[3],const T v2[3], T out[3]);

   Float_t   Normalize(Float_t v[3]);  // Normalize a vector
   Double_t  Normalize(Double_t v[3]); // Normalize a vector

   //Calculate the Normalized Cross Product of two vectors
   template <typename T> inline T NormCross(const T v1[3],const T v2[3],T out[3]);

   // Calculate a normal vector of a plane
   template <typename T> T *Normal2Plane(const T v1[3],const T v2[3],const T v3[3], T normal[3]);

   /* ************************ */
   /* * Polynomial Functions * */
   /* ************************ */

   Bool_t    RootsCubic(const Double_t coef[4],Double_t &a, Double_t &b, Double_t &c);

   /* *********************** */
   /* * Statistic Functions * */
   /* *********************** */

   Double_t Binomial(Int_t n,Int_t k);  // Calculate the binomial coefficient n over k
   Double_t BinomialI(Double_t p, Int_t n, Int_t k);
   Double_t BreitWigner(Double_t x, Double_t mean=0, Double_t gamma=1);
   Double_t CauchyDist(Double_t x, Double_t t=0, Double_t s=1);
   Double_t ChisquareQuantile(Double_t p, Double_t ndf);
   Double_t FDist(Double_t F, Double_t N, Double_t M);
   Double_t FDistI(Double_t F, Double_t N, Double_t M);
   Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE);
   Double_t KolmogorovProb(Double_t z);
   Double_t KolmogorovTest(Int_t na, const Double_t *a, Int_t nb, const Double_t *b, Option_t *option);
   Double_t Landau(Double_t x, Double_t mpv=0, Double_t sigma=1, Bool_t norm=kFALSE);
   Double_t LandauI(Double_t x);
   Double_t LaplaceDist(Double_t x, Double_t alpha=0, Double_t beta=1);
   Double_t LaplaceDistI(Double_t x, Double_t alpha=0, Double_t beta=1);
   Double_t LogNormal(Double_t x, Double_t sigma, Double_t theta=0, Double_t m=1);
   Double_t NormQuantile(Double_t p);
   Double_t Poisson(Double_t x, Double_t par);
   Double_t PoissonI(Double_t x, Double_t par);
   Double_t Prob(Double_t chi2,Int_t ndf);
   Double_t Student(Double_t T, Double_t ndf);
   Double_t StudentI(Double_t T, Double_t ndf);
   Double_t StudentQuantile(Double_t p, Double_t ndf, Bool_t lower_tail=kTRUE);
   Double_t Vavilov(Double_t x, Double_t kappa, Double_t beta2);
   Double_t VavilovI(Double_t x, Double_t kappa, Double_t beta2);
   Double_t Voigt(Double_t x, Double_t sigma, Double_t lg, Int_t r = 4);

   /* ************************** */
   /* * Statistics over arrays * */
   /* ************************** */

   //Mean, Geometric Mean, Median, RMS(sigma)

   template <typename T> Double_t Mean(Long64_t n, const T *a, const Double_t *w=0);
   template <typename Iterator> Double_t Mean(Iterator first, Iterator last);
   template <typename Iterator, typename WeightIterator> Double_t Mean(Iterator first, Iterator last, WeightIterator wfirst);

   template <typename T> Double_t GeomMean(Long64_t n, const T *a);
   template <typename Iterator> Double_t GeomMean(Iterator first, Iterator last);

   template <typename T> Double_t RMS(Long64_t n, const T *a, const Double_t *w=0);
   template <typename Iterator> Double_t RMS(Iterator first, Iterator last);
   template <typename Iterator, typename WeightIterator> Double_t RMS(Iterator first, Iterator last, WeightIterator wfirst);

   template <typename T> Double_t StdDev(Long64_t n, const T *a, const Double_t * w = 0) { return RMS<T>(n,a,w); }
   template <typename Iterator> Double_t StdDev(Iterator first, Iterator last) { return RMS<Iterator>(first,last); }
   template <typename Iterator, typename WeightIterator> Double_t StdDev(Iterator first, Iterator last, WeightIterator wfirst) { return RMS<Iterator,WeightIterator>(first,last,wfirst); }

   template <typename T> Double_t Median(Long64_t n, const T *a,  const Double_t *w=0, Long64_t *work=0);

   //k-th order statistic
   template <class Element, typename Size> Element KOrdStat(Size n, const Element *a, Size k, Size *work = 0);

   /* ******************* */
   /* * Special Functions */
   /* ******************* */

   Double_t Beta(Double_t p, Double_t q);
   Double_t BetaCf(Double_t x, Double_t a, Double_t b);
   Double_t BetaDist(Double_t x, Double_t p, Double_t q);
   Double_t BetaDistI(Double_t x, Double_t p, Double_t q);
   Double_t BetaIncomplete(Double_t x, Double_t a, Double_t b);

   // Bessel functions
   Double_t BesselI(Int_t n,Double_t x);  // integer order modified Bessel function I_n(x)
   Double_t BesselK(Int_t n,Double_t x);  // integer order modified Bessel function K_n(x)
   Double_t BesselI0(Double_t x);         // modified Bessel function I_0(x)
   Double_t BesselK0(Double_t x);         // modified Bessel function K_0(x)
   Double_t BesselI1(Double_t x);         // modified Bessel function I_1(x)
   Double_t BesselK1(Double_t x);         // modified Bessel function K_1(x)
   Double_t BesselJ0(Double_t x);         // Bessel function J0(x) for any real x
   Double_t BesselJ1(Double_t x);         // Bessel function J1(x) for any real x
   Double_t BesselY0(Double_t x);         // Bessel function Y0(x) for positive x
   Double_t BesselY1(Double_t x);         // Bessel function Y1(x) for positive x
   Double_t StruveH0(Double_t x);         // Struve functions of order 0
   Double_t StruveH1(Double_t x);         // Struve functions of order 1
   Double_t StruveL0(Double_t x);         // Modified Struve functions of order 0
   Double_t StruveL1(Double_t x);         // Modified Struve functions of order 1

   Double_t DiLog(Double_t x);
   Double_t Erf(Double_t x);
   Double_t ErfInverse(Double_t x);
   Double_t Erfc(Double_t x);
   Double_t ErfcInverse(Double_t x);
   Double_t Freq(Double_t x);
   Double_t Gamma(Double_t z);
   Double_t Gamma(Double_t a,Double_t x);
   Double_t GammaDist(Double_t x, Double_t gamma, Double_t mu=0, Double_t beta=1);
   Double_t LnGamma(Double_t z);
}


//---- Trig and other functions ------------------------------------------------

#include <float.h>

#if defined(R__WIN32) && !defined(__CINT__)
#   ifndef finite
#      define finite _finite
#      define isnan  _isnan
#   endif
#endif
#if defined(R__AIX) || defined(R__SOLARIS_CC50) || \
    defined(R__HPUX11) || defined(R__GLIBC) || \
    (defined(R__MACOSX) && (defined(__INTEL_COMPILER) || defined(__arm__)))
// math functions are defined inline so we have to include them here
#   include <math.h>
#   ifdef R__SOLARIS_CC50
       extern "C" { int finite(double); }
#   endif
// #   if defined(R__GLIBC) && defined(__STRICT_ANSI__)
// #      ifndef finite
// #         define finite __finite
// #      endif
// #      ifndef isnan
// #         define isnan  __isnan
// #      endif
// #   endif
#else
// don't want to include complete <math.h>
extern "C" {
   extern double sin(double);
   extern double cos(double);
   extern double tan(double);
   extern double sinh(double);
   extern double cosh(double);
   extern double tanh(double);
   extern double asin(double);
   extern double acos(double);
   extern double atan(double);
   extern double atan2(double, double);
   extern double sqrt(double);
   extern double exp(double);
   extern double pow(double, double);
   extern double log(double);
   extern double log10(double);
#ifndef R__WIN32
#   if !defined(finite)
       extern int finite(double);
#   endif
#   if !defined(isnan)
       extern int isnan(double);
#   endif
   extern double ldexp(double, int);
   extern double ceil(double);
   extern double floor(double);
#else
   _CRTIMP double ldexp(double, int);
   _CRTIMP double ceil(double);
   _CRTIMP double floor(double);
#endif
}
#endif

inline Double_t TMath::Sin(Double_t x)
   { return sin(x); }

inline Double_t TMath::Cos(Double_t x)
   { return cos(x); }

inline Double_t TMath::Tan(Double_t x)
   { return tan(x); }

inline Double_t TMath::SinH(Double_t x)
   { return sinh(x); }

inline Double_t TMath::CosH(Double_t x)
   { return cosh(x); }

inline Double_t TMath::TanH(Double_t x)
   { return tanh(x); }

inline Double_t TMath::ASin(Double_t x)
   { if (x < -1.) return -TMath::Pi()/2;
     if (x >  1.) return  TMath::Pi()/2;
     return asin(x);
   }

inline Double_t TMath::ACos(Double_t x)
   { if (x < -1.) return TMath::Pi();
     if (x >  1.) return 0;
     return acos(x);
   }

inline Double_t TMath::ATan(Double_t x)
   { return atan(x); }

inline Double_t TMath::ATan2(Double_t y, Double_t x)
   { if (x != 0) return  atan2(y, x);
     if (y == 0) return  0;
     if (y >  0) return  Pi()/2;
     else        return -Pi()/2;
   }

inline Double_t TMath::Sqrt(Double_t x)
   { return sqrt(x); }

inline Double_t TMath::Ceil(Double_t x)
   { return ceil(x); }

inline Int_t TMath::CeilNint(Double_t x)
   { return TMath::Nint(ceil(x)); }

inline Double_t TMath::Floor(Double_t x)
   { return floor(x); }

inline Int_t TMath::FloorNint(Double_t x)
   { return TMath::Nint(floor(x)); }

template<typename T> 
inline Int_t TMath::Nint(T x)
{
   // Round to nearest integer. Rounds half integers to the nearest
   // even integer.
   int i;
   if (x >= 0) {
      i = int(x + 0.5);
      if ( i & 1 && x + 0.5 == T(i) ) i--;
   } else {
      i = int(x - 0.5);
      if ( i & 1 && x - 0.5 == T(i) ) i++;
   }
   return i;
}

inline Double_t TMath::Exp(Double_t x)
   { return exp(x); }

inline Double_t TMath::Ldexp(Double_t x, Int_t exp)
   { return ldexp(x, exp); }

inline LongDouble_t TMath::Power(LongDouble_t x, LongDouble_t y)
   { return std::pow(x,y); }

inline LongDouble_t TMath::Power(LongDouble_t x, Long64_t y)
   { return std::pow(x,(LongDouble_t)y); }

inline LongDouble_t TMath::Power(Long64_t x, Long64_t y)
#if __cplusplus >= 201103 /*C++11*/
   { return std::pow(x,y); }
#else
   { return std::pow((LongDouble_t)x,(LongDouble_t)y); }
#endif

inline Double_t TMath::Power(Double_t x, Double_t y)
   { return pow(x, y); }

inline Double_t TMath::Power(Double_t x, Int_t y) {
#ifdef R__ANSISTREAM
   return std::pow(x, y); 
#else
   return pow(x, (Double_t) y); 
#endif
}


inline Double_t TMath::Log(Double_t x)
   { return log(x); }

inline Double_t TMath::Log10(Double_t x)
   { return log10(x); }

inline Int_t TMath::Finite(Double_t x)
#if defined(R__HPUX11)
   { return isfinite(x); }
#elif defined(R__MACOSX)
#ifdef isfinite
   // from math.h
   { return isfinite(x); }
#else
   // from cmath
   { return std::isfinite(x); }
#endif
#else
   { return finite(x); }
#endif

inline Int_t TMath::IsNaN(Double_t x)
#if (defined(R__ANSISTREAM) || (defined(R__MACOSX) && defined(__arm__))) && !defined(_AIX) && !defined(__CUDACC__) 
#if defined(isnan) || defined(R__SOLARIS_CC50) || defined(__INTEL_COMPILER)
   // from math.h
  { return ::isnan(x); }
#else
   // from cmath
   { return std::isnan(x); }
#endif
#else
   { return isnan(x); }
#endif

//--------wrapper to numeric_limits
//____________________________________________________________________________
inline Double_t TMath::QuietNaN() { 
   // returns a quiet NaN as defined by IEEE 754 
   // see http://en.wikipedia.org/wiki/NaN#Quiet_NaN
   return std::numeric_limits<Double_t>::quiet_NaN(); 
}

//____________________________________________________________________________
inline Double_t TMath::SignalingNaN() { 
   // returns a signaling NaN as defined by IEEE 754 
   // see http://en.wikipedia.org/wiki/NaN#Signaling_NaN
   return std::numeric_limits<Double_t>::signaling_NaN(); 
}

inline Double_t TMath::Infinity() { 
   // returns an infinity as defined by the IEEE standard
   return std::numeric_limits<Double_t>::infinity(); 
}

template<typename T> 
inline T TMath::Limits<T>::Min() { 
   // returns maximum representation for type T
   return (std::numeric_limits<T>::min)();    //N.B. use this signature to avoid class with macro min() on Windows 
}

template<typename T> 
inline T TMath::Limits<T>::Max() { 
   // returns minimum double representation
   return (std::numeric_limits<T>::max)();  //N.B. use this signature to avoid class with macro max() on Windows 
}

template<typename T> 
inline T TMath::Limits<T>::Epsilon() { 
   // returns minimum double representation
   return std::numeric_limits<T>::epsilon(); 
}


//-------- Advanced -------------

template <typename T> inline T TMath::NormCross(const T v1[3],const T v2[3],T out[3])
{
   // Calculate the Normalized Cross Product of two vectors
   return Normalize(Cross(v1,v2,out));
}

template <typename T>
T TMath::MinElement(Long64_t n, const T *a) {
   // Return minimum of array a of length n.

   return *std::min_element(a,a+n);
}

template <typename T>
T TMath::MaxElement(Long64_t n, const T *a) {
   // Return maximum of array a of length n.

   return *std::max_element(a,a+n);
}

template <typename T>
Long64_t TMath::LocMin(Long64_t n, const T *a) {
   // Return index of array with the minimum element.
   // If more than one element is minimum returns first found.

   // Implement here since this one is found to be faster (mainly on 64 bit machines)
   // than stl generic implementation.
   // When performing the comparison,  the STL implementation needs to de-reference both the array iterator
   // and the iterator pointing to the resulting minimum location

   if  (n <= 0 || !a) return -1;
   T xmin = a[0];
   Long64_t loc = 0;
   for  (Long64_t i = 1; i < n; i++) {
      if (xmin > a[i])  {
         xmin = a[i];
         loc = i;
      }
   }
   return loc;
}

template <typename Iterator>
Iterator TMath::LocMin(Iterator first, Iterator last) {
   // Return index of array with the minimum element.
   // If more than one element is minimum returns first found.
   return std::min_element(first, last);
}

template <typename T>
Long64_t TMath::LocMax(Long64_t n, const T *a) {
   // Return index of array with the maximum element.
   // If more than one element is maximum returns first found.

   // Implement here since it is faster (see comment in LocMin function)

   if  (n <= 0 || !a) return -1;
   T xmax = a[0];
   Long64_t loc = 0;
   for  (Long64_t i = 1; i < n; i++) {
      if (xmax < a[i])  {
         xmax = a[i];
         loc = i;
      }
   }
   return loc;
}

template <typename Iterator>
Iterator TMath::LocMax(Iterator first, Iterator last)
{
   // Return index of array with the maximum element.
   // If more than one element is maximum returns first found.

   return std::max_element(first, last);
}

template<typename T>
struct CompareDesc {

   CompareDesc(T d) : fData(d) {}

   template<typename Index>
   bool operator()(Index i1, Index i2) {
      return *(fData + i1) > *(fData + i2);
   }

   T fData;
};

template<typename T>
struct CompareAsc {

   CompareAsc(T d) : fData(d) {}

   template<typename Index>
   bool operator()(Index i1, Index i2) {
      return *(fData + i1) < *(fData + i2);
   }

   T fData;
};

template <typename Iterator>
Double_t TMath::Mean(Iterator first, Iterator last)
{
   // Return the weighted mean of an array defined by the iterators.

   Double_t sum = 0;
   Double_t sumw = 0;
   while ( first != last )
   {
      sum += *first;
      sumw += 1;
      first++;
   }

   return sum/sumw;
}

template <typename Iterator, typename WeightIterator>
Double_t TMath::Mean(Iterator first, Iterator last, WeightIterator w)
{
   // Return the weighted mean of an array defined by the first and
   // last iterators. The w iterator should point to the first element
   // of a vector of weights of the same size as the main array.

   Double_t sum = 0;
   Double_t sumw = 0;
   int i = 0;
   while ( first != last ) {
      if ( *w < 0) {
         ::Error("TMath::Mean","w[%d] = %.4e < 0 ?!",i,*w);
         return 0;
      }
      sum  += (*w) * (*first);
      sumw += (*w) ;
      ++w;
      ++first;
      ++i;
   }
   if (sumw <= 0) {
      ::Error("TMath::Mean","sum of weights == 0 ?!");
      return 0;
   }

   return sum/sumw;
}

template <typename T>
Double_t TMath::Mean(Long64_t n, const T *a, const Double_t *w)
{
   // Return the weighted mean of an array a with length n.

   if (w) {
      return TMath::Mean(a, a+n, w);
   } else {
      return TMath::Mean(a, a+n);
   }
}

template <typename Iterator>
Double_t TMath::GeomMean(Iterator first, Iterator last)
{
   // Return the geometric mean of an array defined by the iterators.
   // geometric_mean = (Prod_i=0,n-1 |a[i]|)^1/n

   Double_t logsum = 0.;
   Long64_t n = 0;
   while ( first != last ) {
      if (*first == 0) return 0.;
      Double_t absa = (Double_t) TMath::Abs(*first);
      logsum += TMath::Log(absa);
      ++first;
      ++n;
   }

   return TMath::Exp(logsum/n);
}

template <typename T>
Double_t TMath::GeomMean(Long64_t n, const T *a)
{
   // Return the geometric mean of an array a of size n.
   // geometric_mean = (Prod_i=0,n-1 |a[i]|)^1/n

   return TMath::GeomMean(a, a+n);
}

template <typename Iterator>
Double_t TMath::RMS(Iterator first, Iterator last)
{
   // Return the Standard Deviation of an array defined by the iterators.
   // Note that this function returns the sigma(standard deviation) and
   // not the root mean square of the array.

   // Use the two pass algorithm, which is slower (! a factor of 2) but much more 
   // precise.  Since we have a vector the 2 pass algorithm is still faster than the 
   // Welford algorithm. (See also ROOT-5545)

   Double_t n = 0;

   Double_t tot = 0;
   Double_t mean = TMath::Mean(first,last);
   while ( first != last ) {
      Double_t x = Double_t(*first);
      tot += (x - mean)*(x - mean); 
      ++first;
      ++n;
   }
   Double_t rms = (n > 1) ? TMath::Sqrt(tot/(n-1)) : 0.0;
   return rms;
}

template <typename Iterator, typename WeightIterator>
Double_t TMath::RMS(Iterator first, Iterator last, WeightIterator w)
{
   // Return the weighted Standard Deviation of an array defined by the iterators.
   // Note that this function returns the sigma(standard deviation) and
   // not the root mean square of the array.

   // As in the unweighted case use the two pass algorithm

   Double_t tot = 0;
   Double_t sumw = 0;
   Double_t sumw2 = 0;
   Double_t mean = TMath::Mean(first,last,w);
   while ( first != last ) {
      Double_t x = Double_t(*first);
      sumw += *w;
      sumw2 += (*w) * (*w); 
      tot += (*w) * (x - mean)*(x - mean);
      ++first;
      ++w;
   }
   // use the correction neff/(neff -1) for the unbiased formula
   Double_t rms =  TMath::Sqrt(tot * sumw/ (sumw*sumw - sumw2) );
   return rms;
}


template <typename T>
Double_t TMath::RMS(Long64_t n, const T *a, const Double_t * w)
{
   // Return the Standard Deviation of an array a with length n.
   // Note that this function returns the sigma(standard deviation) and
   // not the root mean square of the array.

   return (w) ? TMath::RMS(a, a+n, w) : TMath::RMS(a, a+n);
}

template <typename Iterator, typename Element>
Iterator TMath::BinarySearch(Iterator first, Iterator last, Element value)
{
   // Binary search in an array defined by its iterators.
   //
   // The values in the iterators range are supposed to be sorted
   // prior to this call.  If match is found, function returns
   // position of element.  If no match found, function gives nearest
   // element smaller than value.

   Iterator pind;
   pind = std::lower_bound(first, last, value);
   if ( (pind != last) && (*pind == value) )
      return pind;
   else
      return ( pind - 1);
}


template <typename T> Long64_t TMath::BinarySearch(Long64_t n, const T  *array, T value)
{
   // Binary search in an array of n values to locate value.
   //
   // Array is supposed  to be sorted prior to this call.
   // If match is found, function returns position of element.
   // If no match found, function gives nearest element smaller than value.

   const T* pind;
   pind = std::lower_bound(array, array + n, value);
   if ( (pind != array + n) && (*pind == value) )
      return (pind - array);
   else
      return ( pind - array - 1);
}

template <typename T> Long64_t TMath::BinarySearch(Long64_t n, const T **array, T value)
{
   // Binary search in an array of n values to locate value.
   //
   // Array is supposed  to be sorted prior to this call.
   // If match is found, function returns position of element.
   // If no match found, function gives nearest element smaller than value.

   const T* pind;
   pind = std::lower_bound(*array, *array + n, value);
   if ( (pind != *array + n) && (*pind == value) )
      return (pind - *array);
   else
      return ( pind - *array - 1);
}

template <typename Iterator, typename IndexIterator>
void TMath::SortItr(Iterator first, Iterator last, IndexIterator index, Bool_t down)
{
   // Sort the n1 elements of the Short_t array defined by its
   // iterators.  In output the array index contains the indices of
   // the sorted array.  If down is false sort in increasing order
   // (default is decreasing order).

   // NOTE that the array index must be created with a length bigger
   // or equal than the main array before calling this function.

   int i = 0;

   IndexIterator cindex = index;
   for ( Iterator cfirst = first; cfirst != last; ++cfirst )
   {
      *cindex = i++;
      ++cindex;
   }

   if ( down )
      std::sort(index, cindex, CompareDesc<Iterator>(first) );
   else
      std::sort(index, cindex, CompareAsc<Iterator>(first) );
}

template <typename Element, typename Index> void TMath::Sort(Index n, const Element* a, Index* index, Bool_t down)
{
   // Sort the n elements of the  array a of generic templated type Element.
   // In output the array index of type Index contains the indices of the sorted array.
   // If down is false sort in increasing order (default is decreasing order).

   // NOTE that the array index must be created with a length >= n
   // before calling this function.
   // NOTE also that the size type for n must be the same type used for the index array
   // (templated type Index)

   for(Index i = 0; i < n; i++) { index[i] = i; }
   if ( down )
      std::sort(index, index + n, CompareDesc<const Element*>(a) );
   else
      std::sort(index, index + n, CompareAsc<const Element*>(a) );
}

template <typename T> T *TMath::Cross(const T v1[3],const T v2[3], T out[3])
{
   // Calculate the Cross Product of two vectors:
   //         out = [v1 x v2]

   out[0] = v1[1] * v2[2] - v1[2] * v2[1];
   out[1] = v1[2] * v2[0] - v1[0] * v2[2];
   out[2] = v1[0] * v2[1] - v1[1] * v2[0];

   return out;
}

template <typename T> T * TMath::Normal2Plane(const T p1[3],const T p2[3],const T p3[3], T normal[3])
{
   // Calculate a normal vector of a plane.
   //
   //  Input:
   //     Float_t *p1,*p2,*p3  -  3 3D points belonged the plane to define it.
   //
   //  Return:
   //     Pointer to 3D normal vector (normalized)

   T v1[3], v2[3];

   v1[0] = p2[0] - p1[0];
   v1[1] = p2[1] - p1[1];
   v1[2] = p2[2] - p1[2];

   v2[0] = p3[0] - p1[0];
   v2[1] = p3[1] - p1[1];
   v2[2] = p3[2] - p1[2];

   NormCross(v1,v2,normal);
   return normal;
}

template <typename T> Bool_t TMath::IsInside(T xp, T yp, Int_t np, T *x, T *y)
{
   // Function which returns kTRUE if point xp,yp lies inside the
   // polygon defined by the np points in arrays x and y, kFALSE otherwise.
   // Note that the polygon may be open or closed.

   Int_t i, j = np-1 ;
   Bool_t oddNodes = kFALSE;

   for (i=0; i<np; i++) {
      if ((y[i]<yp && y[j]>=yp) || (y[j]<yp && y[i]>=yp)) {
         if (x[i]+(yp-y[i])/(y[j]-y[i])*(x[j]-x[i])<xp) {
            oddNodes = !oddNodes;
         }
      }
      j=i;
   }

   return oddNodes;
}

template <typename T> Double_t TMath::Median(Long64_t n, const T *a,  const Double_t *w, Long64_t *work)
{
   // Return the median of the array a where each entry i has weight w[i] .
   // Both arrays have a length of at least n . The median is a number obtained
   // from the sorted array a through
   //
   // median = (a[jl]+a[jh])/2.  where (using also the sorted index on the array w)
   //
   // sum_i=0,jl w[i] <= sumTot/2
   // sum_i=0,jh w[i] >= sumTot/2
   // sumTot = sum_i=0,n w[i]
   //
   // If w=0, the algorithm defaults to the median definition where it is
   // a number that divides the sorted sequence into 2 halves.
   // When n is odd or n > 1000, the median is kth element k = (n + 1) / 2.
   // when n is even and n < 1000the median is a mean of the elements k = n/2 and k = n/2 + 1.
   //
   // If the weights are supplied (w not 0) all weights must be >= 0
   //
   // If work is supplied, it is used to store the sorting index and assumed to be
   // >= n . If work=0, local storage is used, either on the stack if n < kWorkMax
   // or on the heap for n >= kWorkMax .

   const Int_t kWorkMax = 100;

   if (n <= 0 || !a) return 0;
   Bool_t isAllocated = kFALSE;
   Double_t median;
   Long64_t *ind;
   Long64_t workLocal[kWorkMax];

   if (work) {
      ind = work;
   } else {
      ind = workLocal;
      if (n > kWorkMax) {
         isAllocated = kTRUE;
         ind = new Long64_t[n];
      }
   }

   if (w) {
      Double_t sumTot2 = 0;
      for (Int_t j = 0; j < n; j++) {
         if (w[j] < 0) {
            ::Error("TMath::Median","w[%d] = %.4e < 0 ?!",j,w[j]);
            if (isAllocated)  delete [] ind;
            return 0;
         }
         sumTot2 += w[j];
      }

      sumTot2 /= 2.;

      Sort(n, a, ind, kFALSE);

      Double_t sum = 0.;
      Int_t jl;
      for (jl = 0; jl < n; jl++) {
         sum += w[ind[jl]];
         if (sum >= sumTot2) break;
      }

      Int_t jh;
      sum = 2.*sumTot2;
      for (jh = n-1; jh >= 0; jh--) {
         sum -= w[ind[jh]];
         if (sum <= sumTot2) break;
      }

      median = 0.5*(a[ind[jl]]+a[ind[jh]]);

   } else {

      if (n%2 == 1)
         median = KOrdStat(n, a,n/2, ind);
      else {
         median = 0.5*(KOrdStat(n, a, n/2 -1, ind)+KOrdStat(n, a, n/2, ind));
      }
   }

   if (isAllocated)
      delete [] ind;
   return median;
}




template <class Element, typename Size>
Element TMath::KOrdStat(Size n, const Element *a, Size k, Size *work)
{
   // Returns k_th order statistic of the array a of size n
   // (k_th smallest element out of n elements).
   //
   // C-convention is used for array indexing, so if you want
   // the second smallest element, call KOrdStat(n, a, 1).
   //
   // If work is supplied, it is used to store the sorting index and
   // assumed to be >= n. If work=0, local storage is used, either on
   // the stack if n < kWorkMax or on the heap for n >= kWorkMax.
   // Note that the work index array will not contain the sorted indices but 
   // all indeces of the smaller element in arbitrary order in work[0,...,k-1] and 
   // all indeces of the larger element in arbitrary order in work[k+1,..,n-1]
   // work[k] will contain instead the index of the returned element.
   //
   // Taken from "Numerical Recipes in C++" without the index array
   // implemented by Anna Khreshuk.
   //
   // See also the declarations at the top of this file

   const Int_t kWorkMax = 100;

   typedef Size Index;

   Bool_t isAllocated = kFALSE;
   Size i, ir, j, l, mid;
   Index arr;
   Index *ind;
   Index workLocal[kWorkMax];
   Index temp;

   if (work) {
      ind = work;
   } else {
      ind = workLocal;
      if (n > kWorkMax) {
         isAllocated = kTRUE;
         ind = new Index[n];
      }
   }

   for (Size ii=0; ii<n; ii++) {
      ind[ii]=ii;
   }
   Size rk = k;
   l=0;
   ir = n-1;
   for(;;) {
      if (ir<=l+1) { //active partition contains 1 or 2 elements
         if (ir == l+1 && a[ind[ir]]<a[ind[l]])
            {temp = ind[l]; ind[l]=ind[ir]; ind[ir]=temp;}
         Element tmp = a[ind[rk]];
         if (isAllocated)
            delete [] ind;
         return tmp;
      } else {
         mid = (l+ir) >> 1; //choose median of left, center and right
         {temp = ind[mid]; ind[mid]=ind[l+1]; ind[l+1]=temp;}//elements as partitioning element arr.
         if (a[ind[l]]>a[ind[ir]])  //also rearrange so that a[l]<=a[l+1]
            {temp = ind[l]; ind[l]=ind[ir]; ind[ir]=temp;}

         if (a[ind[l+1]]>a[ind[ir]])
            {temp=ind[l+1]; ind[l+1]=ind[ir]; ind[ir]=temp;}

         if (a[ind[l]]>a[ind[l+1]])
            {temp = ind[l]; ind[l]=ind[l+1]; ind[l+1]=temp;}

         i=l+1;        //initialize pointers for partitioning
         j=ir;
         arr = ind[l+1];
         for (;;){
            do i++; while (a[ind[i]]<a[arr]);
            do j--; while (a[ind[j]]>a[arr]);
            if (j<i) break;  //pointers crossed, partitioning complete
               {temp=ind[i]; ind[i]=ind[j]; ind[j]=temp;}
         }
         ind[l+1]=ind[j];
         ind[j]=arr;
         if (j>=rk) ir = j-1; //keep active the partition that
         if (j<=rk) l=i;      //contains the k_th element
      }
   }
}

#endif
 TMath.h:1
 TMath.h:2
 TMath.h:3
 TMath.h:4
 TMath.h:5
 TMath.h:6
 TMath.h:7
 TMath.h:8
 TMath.h:9
 TMath.h:10
 TMath.h:11
 TMath.h:12
 TMath.h:13
 TMath.h:14
 TMath.h:15
 TMath.h:16
 TMath.h:17
 TMath.h:18
 TMath.h:19
 TMath.h:20
 TMath.h:21
 TMath.h:22
 TMath.h:23
 TMath.h:24
 TMath.h:25
 TMath.h:26
 TMath.h:27
 TMath.h:28
 TMath.h:29
 TMath.h:30
 TMath.h:31
 TMath.h:32
 TMath.h:33
 TMath.h:34
 TMath.h:35
 TMath.h:36
 TMath.h:37
 TMath.h:38
 TMath.h:39
 TMath.h:40
 TMath.h:41
 TMath.h:42
 TMath.h:43
 TMath.h:44
 TMath.h:45
 TMath.h:46
 TMath.h:47
 TMath.h:48
 TMath.h:49
 TMath.h:50
 TMath.h:51
 TMath.h:52
 TMath.h:53
 TMath.h:54
 TMath.h:55
 TMath.h:56
 TMath.h:57
 TMath.h:58
 TMath.h:59
 TMath.h:60
 TMath.h:61
 TMath.h:62
 TMath.h:63
 TMath.h:64
 TMath.h:65
 TMath.h:66
 TMath.h:67
 TMath.h:68
 TMath.h:69
 TMath.h:70
 TMath.h:71
 TMath.h:72
 TMath.h:73
 TMath.h:74
 TMath.h:75
 TMath.h:76
 TMath.h:77
 TMath.h:78
 TMath.h:79
 TMath.h:80
 TMath.h:81
 TMath.h:82
 TMath.h:83
 TMath.h:84
 TMath.h:85
 TMath.h:86
 TMath.h:87
 TMath.h:88
 TMath.h:89
 TMath.h:90
 TMath.h:91
 TMath.h:92
 TMath.h:93
 TMath.h:94
 TMath.h:95
 TMath.h:96
 TMath.h:97
 TMath.h:98
 TMath.h:99
 TMath.h:100
 TMath.h:101
 TMath.h:102
 TMath.h:103
 TMath.h:104
 TMath.h:105
 TMath.h:106
 TMath.h:107
 TMath.h:108
 TMath.h:109
 TMath.h:110
 TMath.h:111
 TMath.h:112
 TMath.h:113
 TMath.h:114
 TMath.h:115
 TMath.h:116
 TMath.h:117
 TMath.h:118
 TMath.h:119
 TMath.h:120
 TMath.h:121
 TMath.h:122
 TMath.h:123
 TMath.h:124
 TMath.h:125
 TMath.h:126
 TMath.h:127
 TMath.h:128
 TMath.h:129
 TMath.h:130
 TMath.h:131
 TMath.h:132
 TMath.h:133
 TMath.h:134
 TMath.h:135
 TMath.h:136
 TMath.h:137
 TMath.h:138
 TMath.h:139
 TMath.h:140
 TMath.h:141
 TMath.h:142
 TMath.h:143
 TMath.h:144
 TMath.h:145
 TMath.h:146
 TMath.h:147
 TMath.h:148
 TMath.h:149
 TMath.h:150
 TMath.h:151
 TMath.h:152
 TMath.h:153
 TMath.h:154
 TMath.h:155
 TMath.h:156
 TMath.h:157
 TMath.h:158
 TMath.h:159
 TMath.h:160
 TMath.h:161
 TMath.h:162
 TMath.h:163
 TMath.h:164
 TMath.h:165
 TMath.h:166
 TMath.h:167
 TMath.h:168
 TMath.h:169
 TMath.h:170
 TMath.h:171
 TMath.h:172
 TMath.h:173
 TMath.h:174
 TMath.h:175
 TMath.h:176
 TMath.h:177
 TMath.h:178
 TMath.h:179
 TMath.h:180
 TMath.h:181
 TMath.h:182
 TMath.h:183
 TMath.h:184
 TMath.h:185
 TMath.h:186
 TMath.h:187
 TMath.h:188
 TMath.h:189
 TMath.h:190
 TMath.h:191
 TMath.h:192
 TMath.h:193
 TMath.h:194
 TMath.h:195
 TMath.h:196
 TMath.h:197
 TMath.h:198
 TMath.h:199
 TMath.h:200
 TMath.h:201
 TMath.h:202
 TMath.h:203
 TMath.h:204
 TMath.h:205
 TMath.h:206
 TMath.h:207
 TMath.h:208
 TMath.h:209
 TMath.h:210
 TMath.h:211
 TMath.h:212
 TMath.h:213
 TMath.h:214
 TMath.h:215
 TMath.h:216
 TMath.h:217
 TMath.h:218
 TMath.h:219
 TMath.h:220
 TMath.h:221
 TMath.h:222
 TMath.h:223
 TMath.h:224
 TMath.h:225
 TMath.h:226
 TMath.h:227
 TMath.h:228
 TMath.h:229
 TMath.h:230
 TMath.h:231
 TMath.h:232
 TMath.h:233
 TMath.h:234
 TMath.h:235
 TMath.h:236
 TMath.h:237
 TMath.h:238
 TMath.h:239
 TMath.h:240
 TMath.h:241
 TMath.h:242
 TMath.h:243
 TMath.h:244
 TMath.h:245
 TMath.h:246
 TMath.h:247
 TMath.h:248
 TMath.h:249
 TMath.h:250
 TMath.h:251
 TMath.h:252
 TMath.h:253
 TMath.h:254
 TMath.h:255
 TMath.h:256
 TMath.h:257
 TMath.h:258
 TMath.h:259
 TMath.h:260
 TMath.h:261
 TMath.h:262
 TMath.h:263
 TMath.h:264
 TMath.h:265
 TMath.h:266
 TMath.h:267
 TMath.h:268
 TMath.h:269
 TMath.h:270
 TMath.h:271
 TMath.h:272
 TMath.h:273
 TMath.h:274
 TMath.h:275
 TMath.h:276
 TMath.h:277
 TMath.h:278
 TMath.h:279
 TMath.h:280
 TMath.h:281
 TMath.h:282
 TMath.h:283
 TMath.h:284
 TMath.h:285
 TMath.h:286
 TMath.h:287
 TMath.h:288
 TMath.h:289
 TMath.h:290
 TMath.h:291
 TMath.h:292
 TMath.h:293
 TMath.h:294
 TMath.h:295
 TMath.h:296
 TMath.h:297
 TMath.h:298
 TMath.h:299
 TMath.h:300
 TMath.h:301
 TMath.h:302
 TMath.h:303
 TMath.h:304
 TMath.h:305
 TMath.h:306
 TMath.h:307
 TMath.h:308
 TMath.h:309
 TMath.h:310
 TMath.h:311
 TMath.h:312
 TMath.h:313
 TMath.h:314
 TMath.h:315
 TMath.h:316
 TMath.h:317
 TMath.h:318
 TMath.h:319
 TMath.h:320
 TMath.h:321
 TMath.h:322
 TMath.h:323
 TMath.h:324
 TMath.h:325
 TMath.h:326
 TMath.h:327
 TMath.h:328
 TMath.h:329
 TMath.h:330
 TMath.h:331
 TMath.h:332
 TMath.h:333
 TMath.h:334
 TMath.h:335
 TMath.h:336
 TMath.h:337
 TMath.h:338
 TMath.h:339
 TMath.h:340
 TMath.h:341
 TMath.h:342
 TMath.h:343
 TMath.h:344
 TMath.h:345
 TMath.h:346
 TMath.h:347
 TMath.h:348
 TMath.h:349
 TMath.h:350
 TMath.h:351
 TMath.h:352
 TMath.h:353
 TMath.h:354
 TMath.h:355
 TMath.h:356
 TMath.h:357
 TMath.h:358
 TMath.h:359
 TMath.h:360
 TMath.h:361
 TMath.h:362
 TMath.h:363
 TMath.h:364
 TMath.h:365
 TMath.h:366
 TMath.h:367
 TMath.h:368
 TMath.h:369
 TMath.h:370
 TMath.h:371
 TMath.h:372
 TMath.h:373
 TMath.h:374
 TMath.h:375
 TMath.h:376
 TMath.h:377
 TMath.h:378
 TMath.h:379
 TMath.h:380
 TMath.h:381
 TMath.h:382
 TMath.h:383
 TMath.h:384
 TMath.h:385
 TMath.h:386
 TMath.h:387
 TMath.h:388
 TMath.h:389
 TMath.h:390
 TMath.h:391
 TMath.h:392
 TMath.h:393
 TMath.h:394
 TMath.h:395
 TMath.h:396
 TMath.h:397
 TMath.h:398
 TMath.h:399
 TMath.h:400
 TMath.h:401
 TMath.h:402
 TMath.h:403
 TMath.h:404
 TMath.h:405
 TMath.h:406
 TMath.h:407
 TMath.h:408
 TMath.h:409
 TMath.h:410
 TMath.h:411
 TMath.h:412
 TMath.h:413
 TMath.h:414
 TMath.h:415
 TMath.h:416
 TMath.h:417
 TMath.h:418
 TMath.h:419
 TMath.h:420
 TMath.h:421
 TMath.h:422
 TMath.h:423
 TMath.h:424
 TMath.h:425
 TMath.h:426
 TMath.h:427
 TMath.h:428
 TMath.h:429
 TMath.h:430
 TMath.h:431
 TMath.h:432
 TMath.h:433
 TMath.h:434
 TMath.h:435
 TMath.h:436
 TMath.h:437
 TMath.h:438
 TMath.h:439
 TMath.h:440
 TMath.h:441
 TMath.h:442
 TMath.h:443
 TMath.h:444
 TMath.h:445
 TMath.h:446
 TMath.h:447
 TMath.h:448
 TMath.h:449
 TMath.h:450
 TMath.h:451
 TMath.h:452
 TMath.h:453
 TMath.h:454
 TMath.h:455
 TMath.h:456
 TMath.h:457
 TMath.h:458
 TMath.h:459
 TMath.h:460
 TMath.h:461
 TMath.h:462
 TMath.h:463
 TMath.h:464
 TMath.h:465
 TMath.h:466
 TMath.h:467
 TMath.h:468
 TMath.h:469
 TMath.h:470
 TMath.h:471
 TMath.h:472
 TMath.h:473
 TMath.h:474
 TMath.h:475
 TMath.h:476
 TMath.h:477
 TMath.h:478
 TMath.h:479
 TMath.h:480
 TMath.h:481
 TMath.h:482
 TMath.h:483
 TMath.h:484
 TMath.h:485
 TMath.h:486
 TMath.h:487
 TMath.h:488
 TMath.h:489
 TMath.h:490
 TMath.h:491
 TMath.h:492
 TMath.h:493
 TMath.h:494
 TMath.h:495
 TMath.h:496
 TMath.h:497
 TMath.h:498
 TMath.h:499
 TMath.h:500
 TMath.h:501
 TMath.h:502
 TMath.h:503
 TMath.h:504
 TMath.h:505
 TMath.h:506
 TMath.h:507
 TMath.h:508
 TMath.h:509
 TMath.h:510
 TMath.h:511
 TMath.h:512
 TMath.h:513
 TMath.h:514
 TMath.h:515
 TMath.h:516
 TMath.h:517
 TMath.h:518
 TMath.h:519
 TMath.h:520
 TMath.h:521
 TMath.h:522
 TMath.h:523
 TMath.h:524
 TMath.h:525
 TMath.h:526
 TMath.h:527
 TMath.h:528
 TMath.h:529
 TMath.h:530
 TMath.h:531
 TMath.h:532
 TMath.h:533
 TMath.h:534
 TMath.h:535
 TMath.h:536
 TMath.h:537
 TMath.h:538
 TMath.h:539
 TMath.h:540
 TMath.h:541
 TMath.h:542
 TMath.h:543
 TMath.h:544
 TMath.h:545
 TMath.h:546
 TMath.h:547
 TMath.h:548
 TMath.h:549
 TMath.h:550
 TMath.h:551
 TMath.h:552
 TMath.h:553
 TMath.h:554
 TMath.h:555
 TMath.h:556
 TMath.h:557
 TMath.h:558
 TMath.h:559
 TMath.h:560
 TMath.h:561
 TMath.h:562
 TMath.h:563
 TMath.h:564
 TMath.h:565
 TMath.h:566
 TMath.h:567
 TMath.h:568
 TMath.h:569
 TMath.h:570
 TMath.h:571
 TMath.h:572
 TMath.h:573
 TMath.h:574
 TMath.h:575
 TMath.h:576
 TMath.h:577
 TMath.h:578
 TMath.h:579
 TMath.h:580
 TMath.h:581
 TMath.h:582
 TMath.h:583
 TMath.h:584
 TMath.h:585
 TMath.h:586
 TMath.h:587
 TMath.h:588
 TMath.h:589
 TMath.h:590
 TMath.h:591
 TMath.h:592
 TMath.h:593
 TMath.h:594
 TMath.h:595
 TMath.h:596
 TMath.h:597
 TMath.h:598
 TMath.h:599
 TMath.h:600
 TMath.h:601
 TMath.h:602
 TMath.h:603
 TMath.h:604
 TMath.h:605
 TMath.h:606
 TMath.h:607
 TMath.h:608
 TMath.h:609
 TMath.h:610
 TMath.h:611
 TMath.h:612
 TMath.h:613
 TMath.h:614
 TMath.h:615
 TMath.h:616
 TMath.h:617
 TMath.h:618
 TMath.h:619
 TMath.h:620
 TMath.h:621
 TMath.h:622
 TMath.h:623
 TMath.h:624
 TMath.h:625
 TMath.h:626
 TMath.h:627
 TMath.h:628
 TMath.h:629
 TMath.h:630
 TMath.h:631
 TMath.h:632
 TMath.h:633
 TMath.h:634
 TMath.h:635
 TMath.h:636
 TMath.h:637
 TMath.h:638
 TMath.h:639
 TMath.h:640
 TMath.h:641
 TMath.h:642
 TMath.h:643
 TMath.h:644
 TMath.h:645
 TMath.h:646
 TMath.h:647
 TMath.h:648
 TMath.h:649
 TMath.h:650
 TMath.h:651
 TMath.h:652
 TMath.h:653
 TMath.h:654
 TMath.h:655
 TMath.h:656
 TMath.h:657
 TMath.h:658
 TMath.h:659
 TMath.h:660
 TMath.h:661
 TMath.h:662
 TMath.h:663
 TMath.h:664
 TMath.h:665
 TMath.h:666
 TMath.h:667
 TMath.h:668
 TMath.h:669
 TMath.h:670
 TMath.h:671
 TMath.h:672
 TMath.h:673
 TMath.h:674
 TMath.h:675
 TMath.h:676
 TMath.h:677
 TMath.h:678
 TMath.h:679
 TMath.h:680
 TMath.h:681
 TMath.h:682
 TMath.h:683
 TMath.h:684
 TMath.h:685
 TMath.h:686
 TMath.h:687
 TMath.h:688
 TMath.h:689
 TMath.h:690
 TMath.h:691
 TMath.h:692
 TMath.h:693
 TMath.h:694
 TMath.h:695
 TMath.h:696
 TMath.h:697
 TMath.h:698
 TMath.h:699
 TMath.h:700
 TMath.h:701
 TMath.h:702
 TMath.h:703
 TMath.h:704
 TMath.h:705
 TMath.h:706
 TMath.h:707
 TMath.h:708
 TMath.h:709
 TMath.h:710
 TMath.h:711
 TMath.h:712
 TMath.h:713
 TMath.h:714
 TMath.h:715
 TMath.h:716
 TMath.h:717
 TMath.h:718
 TMath.h:719
 TMath.h:720
 TMath.h:721
 TMath.h:722
 TMath.h:723
 TMath.h:724
 TMath.h:725
 TMath.h:726
 TMath.h:727
 TMath.h:728
 TMath.h:729
 TMath.h:730
 TMath.h:731
 TMath.h:732
 TMath.h:733
 TMath.h:734
 TMath.h:735
 TMath.h:736
 TMath.h:737
 TMath.h:738
 TMath.h:739
 TMath.h:740
 TMath.h:741
 TMath.h:742
 TMath.h:743
 TMath.h:744
 TMath.h:745
 TMath.h:746
 TMath.h:747
 TMath.h:748
 TMath.h:749
 TMath.h:750
 TMath.h:751
 TMath.h:752
 TMath.h:753
 TMath.h:754
 TMath.h:755
 TMath.h:756
 TMath.h:757
 TMath.h:758
 TMath.h:759
 TMath.h:760
 TMath.h:761
 TMath.h:762
 TMath.h:763
 TMath.h:764
 TMath.h:765
 TMath.h:766
 TMath.h:767
 TMath.h:768
 TMath.h:769
 TMath.h:770
 TMath.h:771
 TMath.h:772
 TMath.h:773
 TMath.h:774
 TMath.h:775
 TMath.h:776
 TMath.h:777
 TMath.h:778
 TMath.h:779
 TMath.h:780
 TMath.h:781
 TMath.h:782
 TMath.h:783
 TMath.h:784
 TMath.h:785
 TMath.h:786
 TMath.h:787
 TMath.h:788
 TMath.h:789
 TMath.h:790
 TMath.h:791
 TMath.h:792
 TMath.h:793
 TMath.h:794
 TMath.h:795
 TMath.h:796
 TMath.h:797
 TMath.h:798
 TMath.h:799
 TMath.h:800
 TMath.h:801
 TMath.h:802
 TMath.h:803
 TMath.h:804
 TMath.h:805
 TMath.h:806
 TMath.h:807
 TMath.h:808
 TMath.h:809
 TMath.h:810
 TMath.h:811
 TMath.h:812
 TMath.h:813
 TMath.h:814
 TMath.h:815
 TMath.h:816
 TMath.h:817
 TMath.h:818
 TMath.h:819
 TMath.h:820
 TMath.h:821
 TMath.h:822
 TMath.h:823
 TMath.h:824
 TMath.h:825
 TMath.h:826
 TMath.h:827
 TMath.h:828
 TMath.h:829
 TMath.h:830
 TMath.h:831
 TMath.h:832
 TMath.h:833
 TMath.h:834
 TMath.h:835
 TMath.h:836
 TMath.h:837
 TMath.h:838
 TMath.h:839
 TMath.h:840
 TMath.h:841
 TMath.h:842
 TMath.h:843
 TMath.h:844
 TMath.h:845
 TMath.h:846
 TMath.h:847
 TMath.h:848
 TMath.h:849
 TMath.h:850
 TMath.h:851
 TMath.h:852
 TMath.h:853
 TMath.h:854
 TMath.h:855
 TMath.h:856
 TMath.h:857
 TMath.h:858
 TMath.h:859
 TMath.h:860
 TMath.h:861
 TMath.h:862
 TMath.h:863
 TMath.h:864
 TMath.h:865
 TMath.h:866
 TMath.h:867
 TMath.h:868
 TMath.h:869
 TMath.h:870
 TMath.h:871
 TMath.h:872
 TMath.h:873
 TMath.h:874
 TMath.h:875
 TMath.h:876
 TMath.h:877
 TMath.h:878
 TMath.h:879
 TMath.h:880
 TMath.h:881
 TMath.h:882
 TMath.h:883
 TMath.h:884
 TMath.h:885
 TMath.h:886
 TMath.h:887
 TMath.h:888
 TMath.h:889
 TMath.h:890
 TMath.h:891
 TMath.h:892
 TMath.h:893
 TMath.h:894
 TMath.h:895
 TMath.h:896
 TMath.h:897
 TMath.h:898
 TMath.h:899
 TMath.h:900
 TMath.h:901
 TMath.h:902
 TMath.h:903
 TMath.h:904
 TMath.h:905
 TMath.h:906
 TMath.h:907
 TMath.h:908
 TMath.h:909
 TMath.h:910
 TMath.h:911
 TMath.h:912
 TMath.h:913
 TMath.h:914
 TMath.h:915
 TMath.h:916
 TMath.h:917
 TMath.h:918
 TMath.h:919
 TMath.h:920
 TMath.h:921
 TMath.h:922
 TMath.h:923
 TMath.h:924
 TMath.h:925
 TMath.h:926
 TMath.h:927
 TMath.h:928
 TMath.h:929
 TMath.h:930
 TMath.h:931
 TMath.h:932
 TMath.h:933
 TMath.h:934
 TMath.h:935
 TMath.h:936
 TMath.h:937
 TMath.h:938
 TMath.h:939
 TMath.h:940
 TMath.h:941
 TMath.h:942
 TMath.h:943
 TMath.h:944
 TMath.h:945
 TMath.h:946
 TMath.h:947
 TMath.h:948
 TMath.h:949
 TMath.h:950
 TMath.h:951
 TMath.h:952
 TMath.h:953
 TMath.h:954
 TMath.h:955
 TMath.h:956
 TMath.h:957
 TMath.h:958
 TMath.h:959
 TMath.h:960
 TMath.h:961
 TMath.h:962
 TMath.h:963
 TMath.h:964
 TMath.h:965
 TMath.h:966
 TMath.h:967
 TMath.h:968
 TMath.h:969
 TMath.h:970
 TMath.h:971
 TMath.h:972
 TMath.h:973
 TMath.h:974
 TMath.h:975
 TMath.h:976
 TMath.h:977
 TMath.h:978
 TMath.h:979
 TMath.h:980
 TMath.h:981
 TMath.h:982
 TMath.h:983
 TMath.h:984
 TMath.h:985
 TMath.h:986
 TMath.h:987
 TMath.h:988
 TMath.h:989
 TMath.h:990
 TMath.h:991
 TMath.h:992
 TMath.h:993
 TMath.h:994
 TMath.h:995
 TMath.h:996
 TMath.h:997
 TMath.h:998
 TMath.h:999
 TMath.h:1000
 TMath.h:1001
 TMath.h:1002
 TMath.h:1003
 TMath.h:1004
 TMath.h:1005
 TMath.h:1006
 TMath.h:1007
 TMath.h:1008
 TMath.h:1009
 TMath.h:1010
 TMath.h:1011
 TMath.h:1012
 TMath.h:1013
 TMath.h:1014
 TMath.h:1015
 TMath.h:1016
 TMath.h:1017
 TMath.h:1018
 TMath.h:1019
 TMath.h:1020
 TMath.h:1021
 TMath.h:1022
 TMath.h:1023
 TMath.h:1024
 TMath.h:1025
 TMath.h:1026
 TMath.h:1027
 TMath.h:1028
 TMath.h:1029
 TMath.h:1030
 TMath.h:1031
 TMath.h:1032
 TMath.h:1033
 TMath.h:1034
 TMath.h:1035
 TMath.h:1036
 TMath.h:1037
 TMath.h:1038
 TMath.h:1039
 TMath.h:1040
 TMath.h:1041
 TMath.h:1042
 TMath.h:1043
 TMath.h:1044
 TMath.h:1045
 TMath.h:1046
 TMath.h:1047
 TMath.h:1048
 TMath.h:1049
 TMath.h:1050
 TMath.h:1051
 TMath.h:1052
 TMath.h:1053
 TMath.h:1054
 TMath.h:1055
 TMath.h:1056
 TMath.h:1057
 TMath.h:1058
 TMath.h:1059
 TMath.h:1060
 TMath.h:1061
 TMath.h:1062
 TMath.h:1063
 TMath.h:1064
 TMath.h:1065
 TMath.h:1066
 TMath.h:1067
 TMath.h:1068
 TMath.h:1069
 TMath.h:1070
 TMath.h:1071
 TMath.h:1072
 TMath.h:1073
 TMath.h:1074
 TMath.h:1075
 TMath.h:1076
 TMath.h:1077
 TMath.h:1078
 TMath.h:1079
 TMath.h:1080
 TMath.h:1081
 TMath.h:1082
 TMath.h:1083
 TMath.h:1084
 TMath.h:1085
 TMath.h:1086
 TMath.h:1087
 TMath.h:1088
 TMath.h:1089
 TMath.h:1090
 TMath.h:1091
 TMath.h:1092
 TMath.h:1093
 TMath.h:1094
 TMath.h:1095
 TMath.h:1096
 TMath.h:1097
 TMath.h:1098
 TMath.h:1099
 TMath.h:1100
 TMath.h:1101
 TMath.h:1102
 TMath.h:1103
 TMath.h:1104
 TMath.h:1105
 TMath.h:1106
 TMath.h:1107
 TMath.h:1108
 TMath.h:1109
 TMath.h:1110
 TMath.h:1111
 TMath.h:1112
 TMath.h:1113
 TMath.h:1114
 TMath.h:1115
 TMath.h:1116
 TMath.h:1117
 TMath.h:1118
 TMath.h:1119
 TMath.h:1120
 TMath.h:1121
 TMath.h:1122
 TMath.h:1123
 TMath.h:1124
 TMath.h:1125
 TMath.h:1126
 TMath.h:1127
 TMath.h:1128
 TMath.h:1129
 TMath.h:1130
 TMath.h:1131
 TMath.h:1132
 TMath.h:1133
 TMath.h:1134
 TMath.h:1135
 TMath.h:1136
 TMath.h:1137
 TMath.h:1138
 TMath.h:1139
 TMath.h:1140
 TMath.h:1141
 TMath.h:1142
 TMath.h:1143
 TMath.h:1144
 TMath.h:1145
 TMath.h:1146
 TMath.h:1147
 TMath.h:1148
 TMath.h:1149
 TMath.h:1150
 TMath.h:1151
 TMath.h:1152
 TMath.h:1153
 TMath.h:1154
 TMath.h:1155
 TMath.h:1156
 TMath.h:1157
 TMath.h:1158
 TMath.h:1159
 TMath.h:1160
 TMath.h:1161
 TMath.h:1162
 TMath.h:1163
 TMath.h:1164
 TMath.h:1165
 TMath.h:1166
 TMath.h:1167
 TMath.h:1168
 TMath.h:1169
 TMath.h:1170
 TMath.h:1171
 TMath.h:1172
 TMath.h:1173
 TMath.h:1174
 TMath.h:1175