Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include "TMathBase.h"
16
17#include "TError.h"
18#include <algorithm>
19#include <limits>
20#include <cmath>
21
22////////////////////////////////////////////////////////////////////////////////
23///
24/// TMath
25///
26/// Encapsulate most frequently used Math functions.
27/// NB. The basic functions Min, Max, Abs and Sign are defined
28/// in TMathBase.
29
30namespace TMath {
31
32////////////////////////////////////////////////////////////////////////////////
33// Fundamental constants
34
35////////////////////////////////////////////////////////////////////////////////
36/// \f$ \pi\f$
37constexpr Double_t Pi()
38{
39 return 3.14159265358979323846;
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// \f$ 2\pi\f$
44constexpr Double_t TwoPi()
45{
46 return 2.0 * Pi();
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// \f$ \frac{\pi}{2} \f$
51constexpr Double_t PiOver2()
52{
53 return Pi() / 2.0;
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// \f$ \frac{\pi}{4} \f$
58constexpr Double_t PiOver4()
59{
60 return Pi() / 4.0;
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// \f$ \frac{1.}{\pi}\f$
65constexpr Double_t InvPi()
66{
67 return 1.0 / Pi();
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Conversion from radian to degree: \f$ \frac{180}{\pi} \f$
72constexpr Double_t RadToDeg()
73{
74 return 180.0 / Pi();
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Conversion from degree to radian: \f$ \frac{\pi}{180} \f$
79constexpr Double_t DegToRad()
80{
81 return Pi() / 180.0;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// \f$ \sqrt{2} \f$
86constexpr Double_t Sqrt2()
87{
88 return 1.4142135623730950488016887242097;
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Base of natural log: \f$ e \f$
93constexpr Double_t E()
94{
95 return 2.71828182845904523536;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Natural log of 10 (to convert log to ln)
100constexpr Double_t Ln10()
101{
102 return 2.30258509299404568402;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Base-10 log of e (to convert ln to log)
107constexpr Double_t LogE()
108{
109 return 0.43429448190325182765;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Velocity of light in \f$ m s^{-1} \f$
114constexpr Double_t C()
115{
116 return 2.99792458e8;
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// \f$ cm s^{-1} \f$
121constexpr Double_t Ccgs()
122{
123 return 100.0 * C();
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Speed of light uncertainty.
129{
130 return 0.0;
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Gravitational constant in: \f$ m^{3} kg^{-1} s^{-2} \f$
135constexpr Double_t G()
136{
137 // use 2018 value from NIST (https://physics.nist.gov/cgi-bin/cuu/Value?bg|search_for=G)
138 return 6.67430e-11;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// \f$ cm^{3} g^{-1} s^{-2} \f$
143constexpr Double_t Gcgs()
144{
145 return G() * 1000.0;
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Gravitational constant uncertainty.
151{
152 // use 2018 value from NIST
153 return 0.00015e-11;
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// \f$ \frac{G}{\hbar C} \f$ in \f$ (GeV/c^{2})^{-2} \f$
158constexpr Double_t GhbarC()
159{
160 // use new value from NIST (2018)
161 return 6.70883e-39;
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// \f$ \frac{G}{\hbar C} \f$ uncertainty.
167{
168 // use new value from NIST (2018)
169 return 0.00015e-39;
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Standard acceleration of gravity in \f$ m s^{-2} \f$
174constexpr Double_t Gn()
175{
176 return 9.80665;
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Standard acceleration of gravity uncertainty.
182{
183 return 0.0;
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Planck's constant in \f$ J s \f$: \f$ h \f$
188constexpr Double_t H()
189{
190 return 6.62607015e-34;
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// \f$ erg s \f$
195constexpr Double_t Hcgs()
196{
197 return 1.0e7 * H();
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Planck's constant uncertainty.
203{
204 // Planck constant is exact according to 2019 redefinition
205 // (https://en.wikipedia.org/wiki/2019_redefinition_of_the_SI_base_units)
206 return 0.0;
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// \f$ \hbar \f$ in \f$ J s \f$: \f$ \hbar = \frac{h}{2\pi} \f$
211constexpr Double_t Hbar()
212{
213 return 1.054571817e-34;
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// \f$ erg s \f$
218constexpr Double_t Hbarcgs()
219{
220 return 1.0e7 * Hbar();
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// \f$ \hbar \f$ uncertainty.
226{
227 // hbar is an exact constant
228 return 0.0;
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// \f$ hc \f$ in \f$ J m \f$
233constexpr Double_t HC()
234{
235 return H() * C();
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// \f$ erg cm \f$
240constexpr Double_t HCcgs()
241{
242 return Hcgs() * Ccgs();
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Boltzmann's constant in \f$ J K^{-1} \f$: \f$ k \f$
247constexpr Double_t K()
248{
249 return 1.380649e-23;
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// \f$ erg K^{-1} \f$
254constexpr Double_t Kcgs()
255{
256 return 1.0e7 * K();
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Boltzmann's constant uncertainty.
262{
263 // constant is exact according to 2019 redefinition
264 // (https://en.wikipedia.org/wiki/2019_redefinition_of_the_SI_base_units)
265 return 0.0;
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Stefan-Boltzmann constant in \f$ W m^{-2} K^{-4}\f$: \f$ \sigma \f$
270constexpr Double_t Sigma()
271{
272 return 5.670373e-8;
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Stefan-Boltzmann constant uncertainty.
278{
279 return 0.0;
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Avogadro constant (Avogadro's Number) in \f$ mol^{-1} \f$
284constexpr Double_t Na()
285{
286 return 6.02214076e+23;
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Avogadro constant (Avogadro's Number) uncertainty.
292{
293 // constant is exact according to 2019 redefinition
294 // (https://en.wikipedia.org/wiki/2019_redefinition_of_the_SI_base_units)
295 return 0.0;
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// [Universal gas constant](http://scienceworld.wolfram.com/physics/UniversalGasConstant.html)
300/// (\f$ Na K \f$) in \f$ J K^{-1} mol^{-1} \f$
301//
302constexpr Double_t R()
303{
304 return K() * Na();
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// Universal gas constant uncertainty.
310{
311 return R() * ((KUncertainty() / K()) + (NaUncertainty() / Na()));
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// [Molecular weight of dry air 1976 US Standard Atmosphere](http://atmos.nmsu.edu/jsdap/encyclopediawork.html)
316/// in \f$ kg kmol^{-1} \f$ or \f$ gm mol^{-1} \f$
317constexpr Double_t MWair()
318{
319 return 28.9644;
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// [Dry Air Gas Constant (R / MWair)](http://atmos.nmsu.edu/education_and_outreach/encyclopedia/gas_constant.htm)
324/// in \f$ J kg^{-1} K^{-1} \f$
325constexpr Double_t Rgair()
326{
327 return (1000.0 * R()) / MWair();
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Euler-Mascheroni Constant.
333{
334 return 0.577215664901532860606512090082402431042;
335}
336
337////////////////////////////////////////////////////////////////////////////////
338/// Elementary charge in \f$ C \f$ .
339constexpr Double_t Qe()
340{
341 return 1.602176634e-19;
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Elementary charge uncertainty.
347{
348 // constant is exact according to 2019 redefinition
349 // (https://en.wikipedia.org/wiki/2019_redefinition_of_the_SI_base_units)
350 return 0.0;
351}
352
353////////////////////////////////////////////////////////////////////////////////
354// Mathematical Functions
355
356////////////////////////////////////////////////////////////////////////////////
357// Trigonometrical Functions
358
359inline Double_t Sin(Double_t);
360inline Double_t Cos(Double_t);
361inline Double_t Tan(Double_t);
362inline Double_t SinH(Double_t);
363inline Double_t CosH(Double_t);
364inline Double_t TanH(Double_t);
365inline Double_t ASin(Double_t);
366inline Double_t ACos(Double_t);
367inline Double_t ATan(Double_t);
373
374////////////////////////////////////////////////////////////////////////////////
375// Elementary Functions
376
377inline Double_t Ceil(Double_t x);
378inline Int_t CeilNint(Double_t x);
379inline Double_t Floor(Double_t x);
380inline Int_t FloorNint(Double_t x);
381template <typename T>
382inline Int_t Nint(T x);
383
384inline Double_t Sq(Double_t x);
385inline Double_t Sqrt(Double_t x);
386inline Double_t Exp(Double_t x);
387inline Double_t Ldexp(Double_t x, Int_t exp);
393inline Double_t Power(Double_t x, Int_t y);
394inline Double_t Log(Double_t x);
396inline Double_t Log10(Double_t x);
397inline Int_t Finite(Double_t x);
398inline Int_t Finite(Float_t x);
399inline Bool_t IsNaN(Double_t x);
400inline Bool_t IsNaN(Float_t x);
401
402inline Double_t QuietNaN();
403inline Double_t SignalingNaN();
404inline Double_t Infinity();
405
406template <typename T>
407struct Limits {
408 inline static T Min();
409 inline static T Max();
410 inline static T Epsilon();
411 };
412
413 // Some integer math
415
416 /// Comparing floating points.
417 /// Returns `kTRUE` if the absolute difference between `af` and `bf` is less than `epsilon`.
418 inline Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon) {
419 return af == bf || // shortcut for exact equality (necessary because otherwise (inf != inf))
420 TMath::Abs(af-bf) < epsilon ||
421 TMath::Abs(af - bf) < Limits<Double_t>::Min(); // handle 0 < 0 case
422
423 }
424 /// Comparing floating points.
425 /// Returns `kTRUE` if the relative difference between `af` and `bf` is less than `relPrec`.
426 inline Bool_t AreEqualRel(Double_t af, Double_t bf, Double_t relPrec) {
427 return af == bf || // shortcut for exact equality (necessary because otherwise (inf != inf))
428 TMath::Abs(af - bf) <= 0.5 * relPrec * (TMath::Abs(af) + TMath::Abs(bf)) ||
429 TMath::Abs(af - bf) < Limits<Double_t>::Min(); // handle denormals
430 }
431
432 /////////////////////////////////////////////////////////////////////////////
433 // Array Algorithms
434
435 // Min, Max of an array
436 template <typename T> T MinElement(Long64_t n, const T *a);
437 template <typename T> T MaxElement(Long64_t n, const T *a);
438
439 // Locate Min, Max element number in an array
440 template <typename T> Long64_t LocMin(Long64_t n, const T *a);
441 template <typename Iterator> Iterator LocMin(Iterator first, Iterator last);
442 template <typename T> Long64_t LocMax(Long64_t n, const T *a);
443 template <typename Iterator> Iterator LocMax(Iterator first, Iterator last);
444
445 // Derivatives of an array
446 template <typename T> T *Gradient(Long64_t n, T *f, double h = 1);
447 template <typename T> T *Laplacian(Long64_t n, T *f, double h = 1);
448
449 // Hashing
450 ULong_t Hash(const void *txt, Int_t ntxt);
451 ULong_t Hash(const char *str);
452
453 void BubbleHigh(Int_t Narr, Double_t *arr1, Int_t *arr2);
454 void BubbleLow (Int_t Narr, Double_t *arr1, Int_t *arr2);
455
456 Bool_t Permute(Int_t n, Int_t *a); // Find permutations
457
458 /////////////////////////////////////////////////////////////////////////////
459 // Geometrical Functions
460
461 //Sample quantiles
462 void Quantiles(Int_t n, Int_t nprob, Double_t *x, Double_t *quantiles, Double_t *prob,
463 Bool_t isSorted=kTRUE, Int_t *index = nullptr, Int_t type=7);
464
465 // IsInside
466 template <typename T> Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y);
467
468 // Calculate the Cross Product of two vectors
469 template <typename T> T *Cross(const T v1[3],const T v2[3], T out[3]);
470
471 Float_t Normalize(Float_t v[3]); // Normalize a vector
472 Double_t Normalize(Double_t v[3]); // Normalize a vector
473
474 //Calculate the Normalized Cross Product of two vectors
475 template <typename T> inline T NormCross(const T v1[3],const T v2[3],T out[3]);
476
477 // Calculate a normal vector of a plane
478 template <typename T> T *Normal2Plane(const T v1[3],const T v2[3],const T v3[3], T normal[3]);
479
480 /////////////////////////////////////////////////////////////////////////////
481 // Polynomial Functions
482
483 Bool_t RootsCubic(const Double_t coef[4],Double_t &a, Double_t &b, Double_t &c);
484
485 /////////////////////////////////////////////////////////////////////////////
486 // Statistic Functions
487
488 Double_t Binomial(Int_t n,Int_t k); // Calculate the binomial coefficient n over k
507 Double_t Prob(Double_t chi2,Int_t ndf);
514
515 /////////////////////////////////////////////////////////////////////////////
516 // Statistics over arrays
517
518 //Mean, Geometric Mean, Median, RMS(sigma)
519
520 template <typename T> Double_t Mean(Long64_t n, const T *a, const Double_t *w=nullptr);
521 template <typename Iterator> Double_t Mean(Iterator first, Iterator last);
522 template <typename Iterator, typename WeightIterator> Double_t Mean(Iterator first, Iterator last, WeightIterator wfirst);
523
524 template <typename T> Double_t GeomMean(Long64_t n, const T *a);
525 template <typename Iterator> Double_t GeomMean(Iterator first, Iterator last);
526
527 template <typename T> Double_t RMS(Long64_t n, const T *a, const Double_t *w=nullptr);
528 template <typename Iterator> Double_t RMS(Iterator first, Iterator last);
529 template <typename Iterator, typename WeightIterator> Double_t RMS(Iterator first, Iterator last, WeightIterator wfirst);
530
531 template <typename T> Double_t StdDev(Long64_t n, const T *a, const Double_t * w = nullptr) { return RMS<T>(n,a,w); } /// Same as RMS
532 template <typename Iterator> Double_t StdDev(Iterator first, Iterator last) { return RMS<Iterator>(first,last); } /// Same as RMS
533 template <typename Iterator, typename WeightIterator> Double_t StdDev(Iterator first, Iterator last, WeightIterator wfirst) { return RMS<Iterator,WeightIterator>(first,last,wfirst); } /// Same as RMS
534
535 template <typename T> Double_t Median(Long64_t n, const T *a, const Double_t *w=nullptr, Long64_t *work=nullptr);
536
537 //k-th order statistic
538 template <class Element, typename Size> Element KOrdStat(Size n, const Element *a, Size k, Size *work = 0);
539
540 /////////////////////////////////////////////////////////////////////////////
541 // Special Functions
542
548
549 // Bessel functions
550 Double_t BesselI(Int_t n,Double_t x); /// Integer order modified Bessel function I_n(x)
551 Double_t BesselK(Int_t n,Double_t x); /// Integer order modified Bessel function K_n(x)
552 Double_t BesselI0(Double_t x); /// Modified Bessel function I_0(x)
553 Double_t BesselK0(Double_t x); /// Modified Bessel function K_0(x)
554 Double_t BesselI1(Double_t x); /// Modified Bessel function I_1(x)
555 Double_t BesselK1(Double_t x); /// Modified Bessel function K_1(x)
556 Double_t BesselJ0(Double_t x); /// Bessel function J0(x) for any real x
557 Double_t BesselJ1(Double_t x); /// Bessel function J1(x) for any real x
558 Double_t BesselY0(Double_t x); /// Bessel function Y0(x) for positive x
559 Double_t BesselY1(Double_t x); /// Bessel function Y1(x) for positive x
560 Double_t StruveH0(Double_t x); /// Struve functions of order 0
561 Double_t StruveH1(Double_t x); /// Struve functions of order 1
562 Double_t StruveL0(Double_t x); /// Modified Struve functions of order 0
563 Double_t StruveL1(Double_t x); /// Modified Struve functions of order 1
564
573 Double_t GammaDist(Double_t x, Double_t gamma, Double_t mu=0, Double_t beta=1);
575}
576
577////////////////////////////////////////////////////////////////////////////////
578// Trig and other functions
579
580#include <cfloat>
581#include <cmath>
582
583#if defined(R__WIN32)
584# ifndef finite
585# define finite _finite
586# endif
587#endif
588
589////////////////////////////////////////////////////////////////////////////////
590/// Returns the sine of an angle of `x` radians.
591
593 { return sin(x); }
594
595////////////////////////////////////////////////////////////////////////////////
596/// Returns the cosine of an angle of `x` radians.
597
599 { return cos(x); }
600
601////////////////////////////////////////////////////////////////////////////////
602/// Returns the tangent of an angle of `x` radians.
603
605 { return tan(x); }
606
607////////////////////////////////////////////////////////////////////////////////
608/// Returns the hyperbolic sine of `x.
609
611 { return sinh(x); }
612
613////////////////////////////////////////////////////////////////////////////////
614/// Returns the hyperbolic cosine of `x`.
615
617 { return cosh(x); }
618
619////////////////////////////////////////////////////////////////////////////////
620/// Returns the hyperbolic tangent of `x`.
621
623 { return tanh(x); }
624
625////////////////////////////////////////////////////////////////////////////////
626/// Returns the principal value of the arc sine of `x`, expressed in radians.
627
629 {
630 return asin(x);
631 }
632
633////////////////////////////////////////////////////////////////////////////////
634/// Returns the principal value of the arc cosine of `x`, expressed in radians.
635
637 {
638 return acos(x);
639 }
640
641////////////////////////////////////////////////////////////////////////////////
642/// Returns the principal value of the arc tangent of `x`, expressed in radians.
643
645 { return atan(x); }
646
647////////////////////////////////////////////////////////////////////////////////
648/// Returns the principal value of the arc tangent of `y/x`, expressed in radians.
649
651 { if (x != 0) return atan2(y, x);
652 if (y == 0) return 0;
653 if (y > 0) return Pi()/2;
654 else return -Pi()/2;
655 }
656
657////////////////////////////////////////////////////////////////////////////////
658/// Returns `x*x`.
659
661 { return x*x; }
662
663////////////////////////////////////////////////////////////////////////////////
664/// Returns the square root of x.
665
667 { return sqrt(x); }
668
669////////////////////////////////////////////////////////////////////////////////
670/// Rounds `x` upward, returning the smallest integral value that is not less than `x`.
671
673 { return ceil(x); }
674
675////////////////////////////////////////////////////////////////////////////////
676/// Returns the nearest integer of `TMath::Ceil(x)`.
677
679 { return TMath::Nint(ceil(x)); }
680
681////////////////////////////////////////////////////////////////////////////////
682/// Rounds `x` downward, returning the largest integral value that is not greater than `x`.
683
685 { return floor(x); }
686
687////////////////////////////////////////////////////////////////////////////////
688/// Returns the nearest integer of `TMath::Floor(x)`.
689
691 { return TMath::Nint(floor(x)); }
692
693////////////////////////////////////////////////////////////////////////////////
694/// Round to nearest integer. Rounds half integers to the nearest even integer.
695
696template<typename T>
698{
699 int i;
700 if (x >= 0) {
701 i = int(x + 0.5);
702 if ( i & 1 && x + 0.5 == T(i) ) i--;
703 } else {
704 i = int(x - 0.5);
705 if ( i & 1 && x - 0.5 == T(i) ) i++;
706 }
707 return i;
708}
709
710////////////////////////////////////////////////////////////////////////////////
711/// Returns the base-e exponential function of x, which is e raised to the power `x`.
712
714 { return exp(x); }
715
716////////////////////////////////////////////////////////////////////////////////
717/// Returns the result of multiplying `x` (the significant) by 2 raised to the power of `exp` (the exponent).
718
720 { return ldexp(x, exp); }
721
722////////////////////////////////////////////////////////////////////////////////
723/// Returns `x` raised to the power `y`.
724
726 { return std::pow(x,y); }
727
728////////////////////////////////////////////////////////////////////////////////
729/// Returns `x` raised to the power `y`.
730
732 { return std::pow(x,(LongDouble_t)y); }
733
734////////////////////////////////////////////////////////////////////////////////
735/// Returns `x` raised to the power `y`.
736
738 { return std::pow(x,y); }
739
740////////////////////////////////////////////////////////////////////////////////
741/// Returns `x` raised to the power `y`.
742
744 { return pow(x, y); }
745
746////////////////////////////////////////////////////////////////////////////////
747/// Returns `x` raised to the power `y`.
748
750#ifdef R__ANSISTREAM
751 return std::pow(x, y);
752#else
753 return pow(x, (Double_t) y);
754#endif
755}
756
757////////////////////////////////////////////////////////////////////////////////
758/// Returns the natural logarithm of `x`.
759
761 { return log(x); }
762
763////////////////////////////////////////////////////////////////////////////////
764/// Returns the common (base-10) logarithm of `x`.
765
767 { return log10(x); }
768
769////////////////////////////////////////////////////////////////////////////////
770/// Check if it is finite with a mask in order to be consistent in presence of
771/// fast math.
772/// Inspired from the CMSSW FWCore/Utilities package
773
775#if defined(R__FAST_MATH)
776
777{
778 const unsigned long long mask = 0x7FF0000000000000LL;
779 union { unsigned long long l; double d;} v;
780 v.d =x;
781 return (v.l&mask)!=mask;
782}
783#else
784# if defined(R__HPUX11)
785 { return isfinite(x); }
786# elif defined(R__MACOSX)
787# ifdef isfinite
788 // from math.h
789 { return isfinite(x); }
790# else
791 // from cmath
792 { return std::isfinite(x); }
793# endif
794# else
795 { return finite(x); }
796# endif
797#endif
798
799////////////////////////////////////////////////////////////////////////////////
800/// Check if it is finite with a mask in order to be consistent in presence of
801/// fast math.
802/// Inspired from the CMSSW FWCore/Utilities package
803
805#if defined(R__FAST_MATH)
806
807{
808 const unsigned int mask = 0x7f800000;
809 union { unsigned int l; float d;} v;
810 v.d =x;
811 return (v.l&mask)!=mask;
812}
813#else
814{ return std::isfinite(x); }
815#endif
816
817// This namespace provides all the routines necessary for checking if a number
818// is a NaN also in presence of optimisations affecting the behaviour of the
819// floating point calculations.
820// Inspired from the CMSSW FWCore/Utilities package
821
822#if defined (R__FAST_MATH)
823namespace ROOT {
824namespace Internal {
825namespace Math {
826// abridged from GNU libc 2.6.1 - in detail from
827// math/math_private.h
828// sysdeps/ieee754/ldbl-96/math_ldbl.h
829
830// part of this file:
831 /*
832 * ====================================================
833 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
834 *
835 * Developed at SunPro, a Sun Microsystems, Inc. business.
836 * Permission to use, copy, modify, and distribute this
837 * software is freely granted, provided that this notice
838 * is preserved.
839 * ====================================================
840 */
841
842 // A union which permits us to convert between a double and two 32 bit ints.
843 typedef union {
845 struct {
846 UInt_t lsw;
847 UInt_t msw;
848 } parts;
849 } ieee_double_shape_type;
850
851#define EXTRACT_WORDS(ix0,ix1,d) \
852 do { \
853 ieee_double_shape_type ew_u; \
854 ew_u.value = (d); \
855 (ix0) = ew_u.parts.msw; \
856 (ix1) = ew_u.parts.lsw; \
857 } while (0)
858
859 inline Bool_t IsNaN(Double_t x)
860 {
861 UInt_t hx, lx;
862
863 EXTRACT_WORDS(hx, lx, x);
864
865 lx |= hx & 0xfffff;
866 hx &= 0x7ff00000;
867 return (hx == 0x7ff00000) && (lx != 0);
868 }
869
870 typedef union {
872 UInt_t word;
873 } ieee_float_shape_type;
874
875#define GET_FLOAT_WORD(i,d) \
876 do { \
877 ieee_float_shape_type gf_u; \
878 gf_u.value = (d); \
879 (i) = gf_u.word; \
880 } while (0)
881
882 inline Bool_t IsNaN(Float_t x)
883 {
884 UInt_t wx;
885 GET_FLOAT_WORD (wx, x);
886 wx &= 0x7fffffff;
887 return (Bool_t)(wx > 0x7f800000);
888 }
889} } } // end NS ROOT::Internal::Math
890#endif // End R__FAST_MATH
891
892#if defined(R__FAST_MATH)
893 inline Bool_t TMath::IsNaN(Double_t x) { return ROOT::Internal::Math::IsNaN(x); }
894 inline Bool_t TMath::IsNaN(Float_t x) { return ROOT::Internal::Math::IsNaN(x); }
895#else
896 inline Bool_t TMath::IsNaN(Double_t x) { return std::isnan(x); }
897 inline Bool_t TMath::IsNaN(Float_t x) { return std::isnan(x); }
898#endif
899
900////////////////////////////////////////////////////////////////////////////////
901// Wrapper to numeric_limits
902
903////////////////////////////////////////////////////////////////////////////////
904/// Returns a quiet NaN as [defined by IEEE 754](http://en.wikipedia.org/wiki/NaN#Quiet_NaN).
905
907
908 return std::numeric_limits<Double_t>::quiet_NaN();
909}
910
911////////////////////////////////////////////////////////////////////////////////
912/// Returns a signaling NaN as defined by IEEE 754](http://en.wikipedia.org/wiki/NaN#Signaling_NaN).
913
915 return std::numeric_limits<Double_t>::signaling_NaN();
916}
917
918////////////////////////////////////////////////////////////////////////////////
919/// Returns an infinity as defined by the IEEE standard.
920
922 return std::numeric_limits<Double_t>::infinity();
923}
924
925////////////////////////////////////////////////////////////////////////////////
926/// Returns maximum representation for type T.
927
928template<typename T>
930 return (std::numeric_limits<T>::min)(); //N.B. use this signature to avoid class with macro min() on Windows
931}
932
933////////////////////////////////////////////////////////////////////////////////
934/// Returns minimum double representation.
935
936template<typename T>
938 return (std::numeric_limits<T>::max)(); //N.B. use this signature to avoid class with macro max() on Windows
939}
940
941////////////////////////////////////////////////////////////////////////////////
942/// Returns minimum double representation.
943
944template<typename T>
946 return std::numeric_limits<T>::epsilon();
947}
948
949////////////////////////////////////////////////////////////////////////////////
950// Advanced.
951
952////////////////////////////////////////////////////////////////////////////////
953/// Calculates the Normalized Cross Product of two vectors.
954
955template <typename T> inline T TMath::NormCross(const T v1[3],const T v2[3],T out[3])
956{
957 return Normalize(Cross(v1,v2,out));
958}
959
960////////////////////////////////////////////////////////////////////////////////
961/// Returns minimum of array a of length n.
962
963template <typename T>
965 return *std::min_element(a,a+n);
966}
967
968////////////////////////////////////////////////////////////////////////////////
969/// Returns maximum of array a of length n.
970
971template <typename T>
973 return *std::max_element(a,a+n);
974}
975
976////////////////////////////////////////////////////////////////////////////////
977/// Returns index of array with the minimum element.
978/// If more than one element is minimum returns first found.
979///
980/// Implement here since this one is found to be faster (mainly on 64 bit machines)
981/// than stl generic implementation.
982/// When performing the comparison, the STL implementation needs to de-reference both the array iterator
983/// and the iterator pointing to the resulting minimum location
984
985template <typename T>
987 if (n <= 0 || !a) return -1;
988 T xmin = a[0];
989 Long64_t loc = 0;
990 for (Long64_t i = 1; i < n; i++) {
991 if (xmin > a[i]) {
992 xmin = a[i];
993 loc = i;
994 }
995 }
996 return loc;
997}
998
999////////////////////////////////////////////////////////////////////////////////
1000/// Returns index of array with the minimum element.
1001/// If more than one element is minimum returns first found.
1002
1003template <typename Iterator>
1004Iterator TMath::LocMin(Iterator first, Iterator last) {
1005
1006 return std::min_element(first, last);
1007}
1008
1009////////////////////////////////////////////////////////////////////////////////
1010/// \brief Calculate the one-dimensional gradient of an array with length n.
1011/// The first value in the returned array is a forward difference,
1012/// the next n-2 values are central differences, and the last is a backward difference.
1013///
1014/// \note Function leads to undefined behavior if n does not match the length of f
1015/// \param n the number of points in the array
1016/// \param f the array of points.
1017/// \param h the step size. The default step size is 1.
1018/// \return an array of size n with the gradient. Returns nullptr if n < 2 or f empty. Ownership is transferred to the
1019/// caller.
1020
1021template <typename T>
1022T *TMath::Gradient(const Long64_t n, T *f, const double h)
1023{
1024 if (!f) {
1025 ::Error("TMath::Gradient", "Input parameter f is empty.");
1026 return nullptr;
1027 } else if (n < 2) {
1028 ::Error("TMath::Gradient", "Input parameter n=%lld is smaller than 2.", n);
1029 return nullptr;
1030 }
1031 Long64_t i = 1;
1032 T *result = new T[n];
1033
1034 // Forward difference
1035 result[0] = (f[1] - f[0]) / h;
1036
1037 // Central difference
1038 while (i < n - 1) {
1039 result[i] = (f[i + 1] - f[i - 1]) / (2 * h);
1040 i++;
1041 }
1042 // Backward difference
1043 result[i] = (f[i] - f[i - 1]) / h;
1044 return result;
1045}
1046
1047////////////////////////////////////////////////////////////////////////////////
1048/// \brief Calculate the Laplacian of an array with length n.
1049/// The first value in the returned array is a forward difference,
1050/// the next n-2 values are central differences, and the last is a backward difference.
1051///
1052/// \note Function leads to undefined behavior if n does not match the length of f
1053/// \param n the number of points in the array
1054/// \param f the array of points.
1055/// \param h the step size. The default step size is 1.
1056/// \return an array of size n with the laplacian. Returns nullptr if n < 4 or f empty. Ownership is transferred to the
1057/// caller.
1058
1059template <typename T>
1060T *TMath::Laplacian(const Long64_t n, T *f, const double h)
1061{
1062 if (!f) {
1063 ::Error("TMath::Laplacian", "Input parameter f is empty.");
1064 return nullptr;
1065 } else if (n < 4) {
1066 ::Error("TMath::Laplacian", "Input parameter n=%lld is smaller than 4.", n);
1067 return nullptr;
1068 }
1069 Long64_t i = 1;
1070 T *result = new T[n];
1071
1072 // Forward difference
1073 result[0] = (4 * f[2] + 2 * f[0] - 5 * f[1] - f[3]) / (4 * h * h);
1074
1075 // Central difference
1076 while (i < n - 1) {
1077 result[i] = (f[i + 1] + f[i - 1] - 2 * f[i]) / (4 * h * h);
1078 i++;
1079 }
1080 // Backward difference
1081 result[i] = (2 * f[i] - 5 * f[i - 1] + 4 * f[i - 2] - f[i - 3]) / (4 * h * h);
1082 return result;
1083}
1084
1085////////////////////////////////////////////////////////////////////////////////
1086/// Returns index of array with the maximum element.
1087/// If more than one element is maximum returns first found.
1088///
1089/// Implement here since it is faster (see comment in LocMin function)
1090
1091template <typename T>
1093 if (n <= 0 || !a) return -1;
1094 T xmax = a[0];
1095 Long64_t loc = 0;
1096 for (Long64_t i = 1; i < n; i++) {
1097 if (xmax < a[i]) {
1098 xmax = a[i];
1099 loc = i;
1100 }
1101 }
1102 return loc;
1103}
1104
1105////////////////////////////////////////////////////////////////////////////////
1106/// Returns index of array with the maximum element.
1107/// If more than one element is maximum returns first found.
1108
1109template <typename Iterator>
1110Iterator TMath::LocMax(Iterator first, Iterator last)
1111{
1112
1113 return std::max_element(first, last);
1114}
1115
1116////////////////////////////////////////////////////////////////////////////////
1117/// Returns the weighted mean of an array defined by the iterators.
1118
1119template <typename Iterator>
1120Double_t TMath::Mean(Iterator first, Iterator last)
1121{
1122 Double_t sum = 0;
1123 Double_t sumw = 0;
1124 while ( first != last )
1125 {
1126 sum += *first;
1127 sumw += 1;
1128 first++;
1129 }
1130
1131 return sum/sumw;
1132}
1133
1134////////////////////////////////////////////////////////////////////////////////
1135/// Returns the weighted mean of an array defined by the first and
1136/// last iterators. The w iterator should point to the first element
1137/// of a vector of weights of the same size as the main array.
1138
1139template <typename Iterator, typename WeightIterator>
1140Double_t TMath::Mean(Iterator first, Iterator last, WeightIterator w)
1141{
1142
1143 Double_t sum = 0;
1144 Double_t sumw = 0;
1145 int i = 0;
1146 while ( first != last ) {
1147 if ( *w < 0) {
1148 ::Error("TMath::Mean","w[%d] = %.4e < 0 ?!",i,*w);
1149 return 0;
1150 }
1151 sum += (*w) * (*first);
1152 sumw += (*w) ;
1153 ++w;
1154 ++first;
1155 ++i;
1156 }
1157 if (sumw <= 0) {
1158 ::Error("TMath::Mean","sum of weights == 0 ?!");
1159 return 0;
1160 }
1161
1162 return sum/sumw;
1163}
1164
1165////////////////////////////////////////////////////////////////////////////////
1166/// Returns the weighted mean of an array a with length n.
1167
1168template <typename T>
1170{
1171 if (w) {
1172 return TMath::Mean(a, a+n, w);
1173 } else {
1174 return TMath::Mean(a, a+n);
1175 }
1176}
1177
1178////////////////////////////////////////////////////////////////////////////////
1179/// Returns the geometric mean of an array defined by the iterators.
1180/// \f[ GeomMean = (\prod_{i=0}^{n-1} |a[i]|)^{1/n} \f]
1181
1182template <typename Iterator>
1183Double_t TMath::GeomMean(Iterator first, Iterator last)
1184{
1185 Double_t logsum = 0.;
1186 Long64_t n = 0;
1187 while ( first != last ) {
1188 if (*first == 0) return 0.;
1189 Double_t absa = (Double_t) TMath::Abs(*first);
1190 logsum += TMath::Log(absa);
1191 ++first;
1192 ++n;
1193 }
1194
1195 return TMath::Exp(logsum/n);
1196}
1197
1198////////////////////////////////////////////////////////////////////////////////
1199/// Returns the geometric mean of an array a of size n.
1200/// \f[ GeomMean = (\prod_{i=0}^{n-1} |a[i]|)^{1/n} \f]
1201
1202template <typename T>
1204{
1205 return TMath::GeomMean(a, a+n);
1206}
1207
1208////////////////////////////////////////////////////////////////////////////////
1209/// Returns the Standard Deviation of an array defined by the iterators.
1210/// Note that this function returns the sigma(standard deviation) and
1211/// not the root mean square of the array.
1212///
1213/// Use the two pass algorithm, which is slower (! a factor of 2) but much more
1214/// precise. Since we have a vector the 2 pass algorithm is still faster than the
1215/// Welford algorithm. (See also ROOT-5545)
1216
1217template <typename Iterator>
1218Double_t TMath::RMS(Iterator first, Iterator last)
1219{
1220
1221 Double_t n = 0;
1222
1223 Double_t tot = 0;
1224 Double_t mean = TMath::Mean(first,last);
1225 while ( first != last ) {
1226 Double_t x = Double_t(*first);
1227 tot += (x - mean)*(x - mean);
1228 ++first;
1229 ++n;
1230 }
1231 Double_t rms = (n > 1) ? TMath::Sqrt(tot/(n-1)) : 0.0;
1232 return rms;
1233}
1234
1235////////////////////////////////////////////////////////////////////////////////
1236/// Returns the weighted Standard Deviation of an array defined by the iterators.
1237/// Note that this function returns the sigma(standard deviation) and
1238/// not the root mean square of the array.
1239///
1240/// As in the unweighted case use the two pass algorithm
1241
1242template <typename Iterator, typename WeightIterator>
1243Double_t TMath::RMS(Iterator first, Iterator last, WeightIterator w)
1244{
1245 Double_t tot = 0;
1246 Double_t sumw = 0;
1247 Double_t sumw2 = 0;
1248 Double_t mean = TMath::Mean(first,last,w);
1249 while ( first != last ) {
1250 Double_t x = Double_t(*first);
1251 sumw += *w;
1252 sumw2 += (*w) * (*w);
1253 tot += (*w) * (x - mean)*(x - mean);
1254 ++first;
1255 ++w;
1256 }
1257 // use the correction neff/(neff -1) for the unbiased formula
1258 Double_t rms = TMath::Sqrt(tot * sumw/ (sumw*sumw - sumw2) );
1259 return rms;
1260}
1261
1262////////////////////////////////////////////////////////////////////////////////
1263/// Returns the Standard Deviation of an array a with length n.
1264/// Note that this function returns the sigma(standard deviation) and
1265/// not the root mean square of the array.
1266
1267template <typename T>
1269{
1270 return (w) ? TMath::RMS(a, a+n, w) : TMath::RMS(a, a+n);
1271}
1272
1273////////////////////////////////////////////////////////////////////////////////
1274/// Calculates the Cross Product of two vectors:
1275/// out = [v1 x v2]
1276
1277template <typename T> T *TMath::Cross(const T v1[3],const T v2[3], T out[3])
1278{
1279 out[0] = v1[1] * v2[2] - v1[2] * v2[1];
1280 out[1] = v1[2] * v2[0] - v1[0] * v2[2];
1281 out[2] = v1[0] * v2[1] - v1[1] * v2[0];
1282
1283 return out;
1284}
1285
1286////////////////////////////////////////////////////////////////////////////////
1287/// Calculates a normal vector of a plane.
1288///
1289/// \param[in] p1, p2,p3 3 3D points belonged the plane to define it.
1290/// \param[out] normal Pointer to 3D normal vector (normalized)
1291
1292template <typename T> T * TMath::Normal2Plane(const T p1[3],const T p2[3],const T p3[3], T normal[3])
1293{
1294 T v1[3], v2[3];
1295
1296 v1[0] = p2[0] - p1[0];
1297 v1[1] = p2[1] - p1[1];
1298 v1[2] = p2[2] - p1[2];
1299
1300 v2[0] = p3[0] - p1[0];
1301 v2[1] = p3[1] - p1[1];
1302 v2[2] = p3[2] - p1[2];
1303
1304 NormCross(v1,v2,normal);
1305 return normal;
1306}
1307
1308////////////////////////////////////////////////////////////////////////////////
1309/// Function which returns kTRUE if point xp,yp lies inside the
1310/// polygon defined by the np points in arrays x and y, kFALSE otherwise.
1311/// Note that the polygon may be open or closed.
1312
1313template <typename T> Bool_t TMath::IsInside(T xp, T yp, Int_t np, T *x, T *y)
1314{
1315 Int_t i, j = np-1 ;
1316 Bool_t oddNodes = kFALSE;
1317
1318 for (i=0; i<np; i++) {
1319 if ((y[i]<yp && y[j]>=yp) || (y[j]<yp && y[i]>=yp)) {
1320 if (x[i]+(yp-y[i])/(y[j]-y[i])*(x[j]-x[i])<xp) {
1321 oddNodes = !oddNodes;
1322 }
1323 }
1324 j=i;
1325 }
1326
1327 return oddNodes;
1328}
1329
1330////////////////////////////////////////////////////////////////////////////////
1331/// Returns the median of the array a where each entry i has weight w[i] .
1332/// Both arrays have a length of at least n . The median is a number obtained
1333/// from the sorted array a through
1334///
1335/// median = (a[jl]+a[jh])/2. where (using also the sorted index on the array w)
1336///
1337/// sum_i=0,jl w[i] <= sumTot/2
1338/// sum_i=0,jh w[i] >= sumTot/2
1339/// sumTot = sum_i=0,n w[i]
1340///
1341/// If w=0, the algorithm defaults to the median definition where it is
1342/// a number that divides the sorted sequence into 2 halves.
1343/// When n is odd or n > 1000, the median is kth element k = (n + 1) / 2.
1344/// when n is even and n < 1000the median is a mean of the elements k = n/2 and k = n/2 + 1.
1345///
1346/// If the weights are supplied (w not 0) all weights must be >= 0
1347///
1348/// If work is supplied, it is used to store the sorting index and assumed to be
1349/// >= n . If work=0, local storage is used, either on the stack if n < kWorkMax
1350/// or on the heap for n >= kWorkMax .
1351
1352template <typename T> Double_t TMath::Median(Long64_t n, const T *a, const Double_t *w, Long64_t *work)
1353{
1354
1355 const Int_t kWorkMax = 100;
1356
1357 if (n <= 0 || !a) return 0;
1358 Bool_t isAllocated = kFALSE;
1359 Double_t median;
1360 Long64_t *ind;
1361 Long64_t workLocal[kWorkMax];
1362
1363 if (work) {
1364 ind = work;
1365 } else {
1366 ind = workLocal;
1367 if (n > kWorkMax) {
1368 isAllocated = kTRUE;
1369 ind = new Long64_t[n];
1370 }
1371 }
1372
1373 if (w) {
1374 Double_t sumTot2 = 0;
1375 for (Int_t j = 0; j < n; j++) {
1376 if (w[j] < 0) {
1377 ::Error("TMath::Median","w[%d] = %.4e < 0 ?!",j,w[j]);
1378 if (isAllocated) delete [] ind;
1379 return 0;
1380 }
1381 sumTot2 += w[j];
1382 }
1383
1384 sumTot2 /= 2.;
1385
1386 Sort(n, a, ind, kFALSE);
1387
1388 Double_t sum = 0.;
1389 Int_t jl;
1390 for (jl = 0; jl < n; jl++) {
1391 sum += w[ind[jl]];
1392 if (sum >= sumTot2) break;
1393 }
1394
1395 Int_t jh;
1396 sum = 2.*sumTot2;
1397 for (jh = n-1; jh >= 0; jh--) {
1398 sum -= w[ind[jh]];
1399 if (sum <= sumTot2) break;
1400 }
1401
1402 median = 0.5*(a[ind[jl]]+a[ind[jh]]);
1403
1404 } else {
1405
1406 if (n%2 == 1)
1407 median = KOrdStat(n, a,n/2, ind);
1408 else {
1409 median = 0.5*(KOrdStat(n, a, n/2 -1, ind)+KOrdStat(n, a, n/2, ind));
1410 }
1411 }
1412
1413 if (isAllocated)
1414 delete [] ind;
1415 return median;
1416}
1417
1418////////////////////////////////////////////////////////////////////////////////
1419/// Returns k_th order statistic of the array a of size n
1420/// (k_th smallest element out of n elements).
1421///
1422/// C-convention is used for array indexing, so if you want
1423/// the second smallest element, call KOrdStat(n, a, 1).
1424///
1425/// If work is supplied, it is used to store the sorting index and
1426/// assumed to be >= n. If work=0, local storage is used, either on
1427/// the stack if n < kWorkMax or on the heap for n >= kWorkMax.
1428/// Note that the work index array will not contain the sorted indices but
1429/// all indices of the smaller element in arbitrary order in work[0,...,k-1] and
1430/// all indices of the larger element in arbitrary order in work[k+1,..,n-1]
1431/// work[k] will contain instead the index of the returned element.
1432///
1433/// Taken from "Numerical Recipes in C++" without the index array
1434/// implemented by Anna Khreshuk.
1435///
1436/// See also the declarations at the top of this file
1437
1438template <class Element, typename Size>
1439Element TMath::KOrdStat(Size n, const Element *a, Size k, Size *work)
1440{
1441
1442 const Int_t kWorkMax = 100;
1443
1444 typedef Size Index;
1445
1446 Bool_t isAllocated = kFALSE;
1447 Size i, ir, j, l, mid;
1448 Index arr;
1449 Index *ind;
1450 Index workLocal[kWorkMax];
1451 Index temp;
1452
1453 if (work) {
1454 ind = work;
1455 } else {
1456 ind = workLocal;
1457 if (n > kWorkMax) {
1458 isAllocated = kTRUE;
1459 ind = new Index[n];
1460 }
1461 }
1462
1463 for (Size ii=0; ii<n; ii++) {
1464 ind[ii]=ii;
1465 }
1466 Size rk = k;
1467 l=0;
1468 ir = n-1;
1469 for(;;) {
1470 if (ir<=l+1) { //active partition contains 1 or 2 elements
1471 if (ir == l+1 && a[ind[ir]]<a[ind[l]])
1472 {temp = ind[l]; ind[l]=ind[ir]; ind[ir]=temp;}
1473 Element tmp = a[ind[rk]];
1474 if (isAllocated)
1475 delete [] ind;
1476 return tmp;
1477 } else {
1478 mid = (l+ir) >> 1; //choose median of left, center and right
1479 {temp = ind[mid]; ind[mid]=ind[l+1]; ind[l+1]=temp;}//elements as partitioning element arr.
1480 if (a[ind[l]]>a[ind[ir]]) //also rearrange so that a[l]<=a[l+1]
1481 {temp = ind[l]; ind[l]=ind[ir]; ind[ir]=temp;}
1482
1483 if (a[ind[l+1]]>a[ind[ir]])
1484 {temp=ind[l+1]; ind[l+1]=ind[ir]; ind[ir]=temp;}
1485
1486 if (a[ind[l]]>a[ind[l+1]])
1487 {temp = ind[l]; ind[l]=ind[l+1]; ind[l+1]=temp;}
1488
1489 i=l+1; //initialize pointers for partitioning
1490 j=ir;
1491 arr = ind[l+1];
1492 for (;;){
1493 do i++; while (a[ind[i]]<a[arr]);
1494 do j--; while (a[ind[j]]>a[arr]);
1495 if (j<i) break; //pointers crossed, partitioning complete
1496 {temp=ind[i]; ind[i]=ind[j]; ind[j]=temp;}
1497 }
1498 ind[l+1]=ind[j];
1499 ind[j]=arr;
1500 if (j>=rk) ir = j-1; //keep active the partition that
1501 if (j<=rk) l=i; //contains the k_th element
1502 }
1503 }
1504}
1505
1506#endif
#define IsNaN(a)
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
long double LongDouble_t
Definition RtypesCore.h:61
long long Long64_t
Definition RtypesCore.h:69
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
#define N
TGLVector3 Cross(const TGLVector3 &v1, const TGLVector3 &v2)
Definition TGLUtil.h:323
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
float xmin
float * q
float xmax
const Double_t sigma
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
#define F(x, y, z)
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TMath.
Definition TMathBase.h:35
Double_t FDistI(Double_t F, Double_t N, Double_t M)
Calculates the cumulative distribution function of F-distribution (see ROOT::Math::fdistribution_cdf)...
Definition TMath.cxx:2297
Double_t GeomMean(Long64_t n, const T *a)
Returns the geometric mean of an array a of size n.
Definition TMath.h:1203
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:2437
T * Laplacian(Long64_t n, T *f, double h=1)
Calculate the Laplacian of an array with length n.
Definition TMath.h:1060
constexpr Double_t G()
Gravitational constant in: .
Definition TMath.h:135
Double_t CosH(Double_t)
Returns the hyperbolic cosine of x.
Definition TMath.h:616
T * Normal2Plane(const T v1[3], const T v2[3], const T v3[3], T normal[3])
Calculates a normal vector of a plane.
Definition TMath.h:1292
Double_t DiLog(Double_t x)
Modified Struve functions of order 1.
Definition TMath.cxx:116
Double_t BetaDist(Double_t x, Double_t p, Double_t q)
Computes the probability density function of the Beta distribution (the cumulative distribution funct...
Definition TMath.cxx:2071
Double_t ACos(Double_t)
Returns the principal value of the arc cosine of x, expressed in radians.
Definition TMath.h:636
Double_t BesselI(Int_t n, Double_t x)
Computes the Integer Order Modified Bessel function I_n(x) for n=0,1,2,... and any real x.
Definition TMath.cxx:1590
Element KOrdStat(Size n, const Element *a, Size k, Size *work=0)
Returns k_th order statistic of the array a of size n (k_th smallest element out of n elements).
Definition TMath.h:1439
T * Gradient(Long64_t n, T *f, double h=1)
Calculate the one-dimensional gradient of an array with length n.
Definition TMath.h:1022
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculates a gaussian function with mean and sigma.
Definition TMath.cxx:471
Bool_t IsNaN(Double_t x)
Definition TMath.h:896
constexpr Double_t GUncertainty()
Gravitational constant uncertainty.
Definition TMath.h:150
constexpr Double_t C()
Velocity of light in .
Definition TMath.h:114
Double_t Factorial(Int_t i)
Computes factorial(n).
Definition TMath.cxx:252
Double_t RMS(Long64_t n, const T *a, const Double_t *w=nullptr)
Returns the Standard Deviation of an array a with length n.
Definition TMath.h:1268
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:805
constexpr Double_t GhbarCUncertainty()
uncertainty.
Definition TMath.h:166
Long64_t LocMin(Long64_t n, const T *a)
Returns index of array with the minimum element.
Definition TMath.h:986
constexpr Double_t Ccgs()
Definition TMath.h:121
constexpr Double_t SigmaUncertainty()
Stefan-Boltzmann constant uncertainty.
Definition TMath.h:277
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:697
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 occurring k or mor...
Definition TMath.cxx:2141
Double_t Vavilov(Double_t x, Double_t kappa, Double_t beta2)
Returns the value of the Vavilov probability density function.
Definition TMath.cxx:2778
Double_t Binomial(Int_t n, Int_t k)
Calculates the binomial coefficient n over k.
Definition TMath.cxx:2111
Float_t Normalize(Float_t v[3])
Normalize a vector v in place.
Definition TMath.cxx:518
constexpr Double_t NaUncertainty()
Avogadro constant (Avogadro's Number) uncertainty.
Definition TMath.h:291
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:637
Bool_t 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 array...
Definition TMath.h:1313
Double_t ASin(Double_t)
Returns the principal value of the arc sine of x, expressed in radians.
Definition TMath.h:628
Double_t Log2(Double_t x)
Returns the binary (base-2) logarithm of x.
Definition TMath.cxx:107
Double_t BesselK1(Double_t x)
Modified Bessel function I_1(x)
Definition TMath.cxx:1529
Double_t Median(Long64_t n, const T *a, const Double_t *w=nullptr, Long64_t *work=nullptr)
Same as RMS.
Definition TMath.h:1352
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:1314
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Definition TMath.h:713
Double_t BesselI1(Double_t x)
Modified Bessel function K_0(x)
Definition TMath.cxx:1494
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Definition TMath.cxx:190
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:2557
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
Definition TMath.h:906
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition TMath.h:684
Double_t PoissonI(Double_t x, Double_t par)
Computes the Discrete Poisson distribution function for (x,par).
Definition TMath.cxx:615
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:2175
Double_t ATan(Double_t)
Returns the principal value of the arc tangent of x, expressed in radians.
Definition TMath.h:644
Double_t StruveL1(Double_t x)
Modified Struve functions of order 0.
Definition TMath.cxx:1970
constexpr Double_t Gn()
Standard acceleration of gravity in .
Definition TMath.h:174
Double_t ASinH(Double_t)
Returns the area hyperbolic sine of x.
Definition TMath.cxx:67
Double_t LaplaceDistI(Double_t x, Double_t alpha=0, Double_t beta=1)
Computes the cumulative distribution function (lower tail integral) of Laplace distribution at point ...
Definition TMath.cxx:2380
ULong_t Hash(const void *txt, Int_t ntxt)
Calculates hash index from any char string.
Definition TMath.cxx:1408
constexpr Double_t QeUncertainty()
Elementary charge uncertainty.
Definition TMath.h:346
constexpr Double_t K()
Boltzmann's constant in : .
Definition TMath.h:247
Double_t BreitWigner(Double_t x, Double_t mean=0, Double_t gamma=1)
Calculates a Breit Wigner function with mean and gamma.
Definition TMath.cxx:442
constexpr Double_t Sqrt2()
Definition TMath.h:86
constexpr Double_t KUncertainty()
Boltzmann's constant uncertainty.
Definition TMath.h:261
constexpr Double_t Hbarcgs()
Definition TMath.h:218
Double_t Landau(Double_t x, Double_t mpv=0, Double_t sigma=1, Bool_t norm=kFALSE)
The LANDAU function.
Definition TMath.cxx:492
Double_t Voigt(Double_t x, Double_t sigma, Double_t lg, Int_t r=4)
Computation of Voigt function (normalised).
Definition TMath.cxx:898
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:2623
constexpr Double_t CUncertainty()
Speed of light uncertainty.
Definition TMath.h:128
constexpr Double_t Qe()
Elementary charge in .
Definition TMath.h:339
Double_t Ceil(Double_t x)
Rounds x upward, returning the smallest integral value that is not less than x.
Definition TMath.h:672
constexpr Double_t PiOver2()
Definition TMath.h:51
constexpr Double_t HCcgs()
Definition TMath.h:240
T MinElement(Long64_t n, const T *a)
Returns minimum of array a of length n.
Definition TMath.h:964
Double_t BetaDistI(Double_t x, Double_t p, Double_t q)
Computes the cumulative distribution function of the Beta distribution, i.e.
Definition TMath.cxx:2090
T NormCross(const T v1[3], const T v2[3], T out[3])
Calculates the Normalized Cross Product of two vectors.
Definition TMath.h:955
Int_t Finite(Double_t x)
Check if it is finite with a mask in order to be consistent in presence of fast math.
Definition TMath.h:774
Double_t TanH(Double_t)
Returns the hyperbolic tangent of x.
Definition TMath.h:622
Int_t FloorNint(Double_t x)
Returns the nearest integer of TMath::Floor(x).
Definition TMath.h:690
Double_t ACosH(Double_t)
Returns the nonnegative area hyperbolic cosine of x.
Definition TMath.cxx:81
Double_t BesselK0(Double_t x)
Modified Bessel function I_0(x)
Definition TMath.cxx:1460
Double_t BesselY0(Double_t x)
Bessel function J1(x) for any real x.
Definition TMath.cxx:1705
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
Definition TMath.h:650
constexpr Double_t RUncertainty()
Universal gas constant uncertainty.
Definition TMath.h:309
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:2020
Long64_t LocMax(Long64_t n, const T *a)
Returns index of array with the maximum element.
Definition TMath.h:1092
Double_t ErfInverse(Double_t x)
Returns the inverse error function.
Definition TMath.cxx:208
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:2364
constexpr Double_t E()
Base of natural log: .
Definition TMath.h:93
constexpr Double_t GnUncertainty()
Standard acceleration of gravity uncertainty.
Definition TMath.h:181
constexpr Double_t Hcgs()
Definition TMath.h:195
constexpr Double_t HUncertainty()
Planck's constant uncertainty.
Definition TMath.h:202
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:760
constexpr Double_t DegToRad()
Conversion from degree to radian: .
Definition TMath.h:79
Double_t Erfc(Double_t x)
Computes the complementary error function erfc(x).
Definition TMath.cxx:199
Double_t VavilovI(Double_t x, Double_t kappa, Double_t beta2)
Returns the value of the Vavilov cumulative distribution function (lower tail integral of the probabi...
Definition TMath.cxx:2815
constexpr Double_t Sigma()
Stefan-Boltzmann constant in : .
Definition TMath.h:270
Double_t Beta(Double_t p, Double_t q)
Calculates Beta-function Gamma(p)*Gamma(q)/Gamma(p+q).
Definition TMath.cxx:2011
constexpr Double_t Kcgs()
Definition TMath.h:254
Double_t Sq(Double_t x)
Returns x*x.
Definition TMath.h:660
Double_t Poisson(Double_t x, Double_t par)
Computes the Poisson distribution function for (x,par).
Definition TMath.cxx:587
constexpr Double_t H()
Planck's constant in : .
Definition TMath.h:188
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:666
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:725
Int_t CeilNint(Double_t x)
Returns the nearest integer of TMath::Ceil(x).
Definition TMath.h:678
Double_t Ldexp(Double_t x, Int_t exp)
Returns the result of multiplying x (the significant) by 2 raised to the power of exp (the exponent).
Definition TMath.h:719
Double_t BesselJ0(Double_t x)
Modified Bessel function K_1(x)
Definition TMath.cxx:1634
constexpr Double_t LogE()
Base-10 log of e (to convert ln to log)
Definition TMath.h:107
Double_t Gamma(Double_t z)
Computation of gamma(z) for all z.
Definition TMath.cxx:353
constexpr Double_t MWair()
Molecular weight of dry air 1976 US Standard Atmosphere in or
Definition TMath.h:317
constexpr Double_t Gcgs()
Definition TMath.h:143
Double_t StruveL0(Double_t x)
Struve functions of order 1.
Definition TMath.cxx:1923
Double_t NormQuantile(Double_t p)
Computes quantiles for standard normal distribution N(0, 1) at probability p.
Definition TMath.cxx:2456
constexpr Double_t Ln10()
Natural log of 10 (to convert log to ln)
Definition TMath.h:100
Double_t Hypot(Double_t x, Double_t y)
Returns sqrt(x*x + y*y)
Definition TMath.cxx:59
constexpr Double_t EulerGamma()
Euler-Mascheroni Constant.
Definition TMath.h:332
constexpr Double_t PiOver4()
Definition TMath.h:58
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:598
void Quantiles(Int_t n, Int_t nprob, Double_t *x, Double_t *quantiles, Double_t *prob, Bool_t isSorted=kTRUE, Int_t *index=nullptr, Int_t type=7)
Computes sample quantiles, corresponding to the given probabilities.
Definition TMath.cxx:1207
constexpr Double_t Pi()
Definition TMath.h:37
Double_t StruveH0(Double_t x)
Bessel function Y1(x) for positive x.
Definition TMath.cxx:1777
constexpr Double_t R()
Universal gas constant ( ) in
Definition TMath.h:302
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
Definition TMath.cxx:509
Bool_t AreEqualRel(Double_t af, Double_t bf, Double_t relPrec)
Comparing floating points.
Definition TMath.h:426
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Comparing floating points.
Definition TMath.h:418
Double_t Mean(Long64_t n, const T *a, const Double_t *w=nullptr)
Returns the weighted mean of an array a with length n.
Definition TMath.h:1169
Double_t KolmogorovProb(Double_t z)
Calculates the Kolmogorov distribution function,.
Definition TMath.cxx:679
constexpr Double_t InvPi()
Definition TMath.h:65
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.
Definition TMath.cxx:1107
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.
Definition TMath.cxx:2193
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:592
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:2277
Double_t SignalingNaN()
Returns a signaling NaN as defined by IEEE 754](http://en.wikipedia.org/wiki/NaN#Signaling_NaN).
Definition TMath.h:914
Double_t BreitWignerRelativistic(Double_t x, Double_t median=0, Double_t gamma=1)
Calculates a Relativistic Breit Wigner function with median and gamma.
Definition TMath.cxx:452
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Sort the n elements of the array a of generic templated type Element.
Definition TMathBase.h:431
T * Cross(const T v1[3], const T v2[3], T out[3])
Calculates the Cross Product of two vectors: out = [v1 x v2].
Definition TMath.h:1277
void BubbleLow(Int_t Narr, Double_t *arr1, Int_t *arr2)
Opposite ordering of the array arr2[] to that of BubbleHigh.
Definition TMath.cxx:1353
Double_t BesselK(Int_t n, Double_t x)
Integer order modified Bessel function I_n(x)
Definition TMath.cxx:1561
constexpr Double_t Na()
Avogadro constant (Avogadro's Number) in .
Definition TMath.h:284
T MaxElement(Long64_t n, const T *a)
Returns maximum of array a of length n.
Definition TMath.h:972
Double_t BesselJ1(Double_t x)
Bessel function J0(x) for any real x.
Definition TMath.cxx:1669
Double_t BetaIncomplete(Double_t x, Double_t a, Double_t b)
Calculates the incomplete Beta-function.
Definition TMath.cxx:2103
constexpr Double_t Rgair()
Dry Air Gas Constant (R / MWair) in
Definition TMath.h:325
constexpr Double_t Hbar()
in :
Definition TMath.h:211
Double_t StruveH1(Double_t x)
Struve functions of order 0.
Definition TMath.cxx:1846
Double_t Freq(Double_t x)
Computation of the normal frequency function freq(x).
Definition TMath.cxx:270
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:604
Double_t LandauI(Double_t x)
Returns the cumulative (lower tail integral) of the Landau distribution function at point x.
Definition TMath.cxx:2845
Double_t StdDev(Long64_t n, const T *a, const Double_t *w=nullptr)
Definition TMath.h:531
Double_t ATanH(Double_t)
Returns the area hyperbolic tangent of x.
Definition TMath.cxx:95
constexpr Double_t RadToDeg()
Conversion from radian to degree: .
Definition TMath.h:72
Double_t BesselI0(Double_t x)
Integer order modified Bessel function K_n(x)
Definition TMath.cxx:1426
Double_t Log10(Double_t x)
Returns the common (base-10) logarithm of x.
Definition TMath.h:766
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:2646
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,...
Definition TMath.cxx:2674
Double_t BesselY1(Double_t x)
Bessel function Y0(x) for positive x.
Definition TMath.cxx:1739
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
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:2347
constexpr Double_t GhbarC()
in
Definition TMath.h:158
constexpr Double_t HC()
in
Definition TMath.h:233
constexpr Double_t TwoPi()
Definition TMath.h:44
constexpr Double_t HbarUncertainty()
uncertainty.
Definition TMath.h:225
Double_t Infinity()
Returns an infinity as defined by the IEEE standard.
Definition TMath.h:921
Double_t ErfcInverse(Double_t x)
Returns the inverse of the complementary error function.
Definition TMath.cxx:242
Double_t SinH(Double_t)
Returns the hyperbolic sine of `x.
Definition TMath.h:610
static T Min()
Returns maximum representation for type T.
Definition TMath.h:929
static T Epsilon()
Returns minimum double representation.
Definition TMath.h:945
static T Max()
Returns minimum double representation.
Definition TMath.h:937
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345