source: trunk/Mars/mbase/MMath.h@ 18045

Last change on this file since 18045 was 17161, checked in by tbretz, 11 years ago
Added a version of GetIntersectionPoint which allows to check for success.
File size: 4.0 KB
Line 
1#ifndef MARS_MMath
2#define MARS_MMath
3
4#ifndef _MATH_H
5#include <math.h> // Needed for darwin
6#endif
7
8#ifndef ROOT_TMath
9#include <TMath.h> // TMath is included here for convinience
10#endif
11
12class TVector2;
13class TVector3;
14class TArrayD;
15
16namespace MMath
17{
18 Double_t GaussProb(Double_t x, Double_t sigma=1, Double_t mean=0);
19 Double_t GaussProb2D(Double_t x, Double_t sigma=1);
20
21 template <class Size, class Element> void ReSortImp(Size n, Element *a, Bool_t down=kFALSE);
22 void ReSort(Long64_t n, Short_t *a, Bool_t down=kFALSE);
23 void ReSort(Long64_t n, Int_t *a, Bool_t down=kFALSE);
24 void ReSort(Long64_t n, Float_t *a, Bool_t down=kFALSE);
25 void ReSort(Long64_t n, Double_t *a, Bool_t down=kFALSE);
26
27 template <class Size, class Element> Double_t MedianDevImp(Size n, const Element *a) { Double_t med; return MedianDevImp(n, a, med); }
28 template <class Size, class Element> Double_t MedianDevImp(Size n, const Element *a, Double_t &med);
29 Double_t MedianDev(Long64_t n, const Short_t *a, Double_t &med);
30 Double_t MedianDev(Long64_t n, const Int_t *a, Double_t &med);
31 Double_t MedianDev(Long64_t n, const Float_t *a, Double_t &med);
32 Double_t MedianDev(Long64_t n, const Double_t *a, Double_t &med);
33 Double_t MedianDev(Long64_t n, const Long_t *a, Double_t &med);
34 Double_t MedianDev(Long64_t n, const Long64_t *a, Double_t &med);
35 Double_t MedianDev(Long64_t n, const Short_t *a);
36 Double_t MedianDev(Long64_t n, const Int_t *a);
37 Double_t MedianDev(Long64_t n, const Float_t *a);
38 Double_t MedianDev(Long64_t n, const Double_t *a);
39 Double_t MedianDev(Long64_t n, const Long_t *a);
40 Double_t MedianDev(Long64_t n, const Long64_t *a);
41
42 Double_t Significance(Double_t s, Double_t b);
43 Double_t SignificanceSym(Double_t s, Double_t b);
44 Double_t SignificanceLiMa(Double_t s, Double_t b, Double_t alpha=1);
45 Double_t SignificanceLiMaSigned(Double_t s, Double_t b, Double_t alpha=1);
46 Double_t SignificanceExc(Double_t s, Double_t b, Double_t alpha=1);
47 Double_t ErrorExc(Double_t s, Double_t b, Double_t alpha=1);
48
49 void ReducePrecision(Float_t &val);
50
51 TVector3 GetParab(const TVector3 &x, const TVector3 &y);
52 Double_t InterpolParabLin(const TVector3 &vx, const TVector3 &vy, Double_t x);
53 Double_t InterpolParabLin(const TVector3 &vy, Double_t x);
54 Double_t InterpolParabLog(const TVector3 &vx, const TVector3 &vy, Double_t x);
55 Double_t InterpolParabCos(const TVector3 &vx, const TVector3 &vy, Double_t x);
56
57 TVector2 GetIntersectionPoint(const TVector2 &x1, const TVector2 &y1, const TVector2 &x2, const TVector2 &y2, Bool_t &rc);
58 TVector2 GetIntersectionPoint(const TVector2 &x1, const TVector2 &y1, const TVector2 &x2, const TVector2 &y2);
59
60 inline Int_t SolvePol1(Double_t c, Double_t d, Double_t &x1)
61 {
62 if (c==0)
63 return 0;
64
65 x1 = -d/c;
66 return 1;
67 }
68 Int_t SolvePol2(Double_t c, Double_t d, Double_t &x1, Double_t &x2);
69 inline Int_t SolvePol2(Double_t b, Double_t c, Double_t d, Double_t &x1, Double_t &x2)
70 {
71 return b==0 ? SolvePol1(c, d, x1) : SolvePol2(c/b, d/b, x1, x2);
72 }
73 Int_t SolvePol3(Double_t b, Double_t c, Double_t d, Double_t &x1, Double_t &x2, Double_t &x3);
74 inline Int_t SolvePol3(Double_t a, Double_t b, Double_t c, Double_t d, Double_t &x1, Double_t &x2, Double_t &x3)
75 {
76 return a==0 ? SolvePol2(b, c, d, x1, x2) : SolvePol3(b/a, c/a, d/a, x1, x2, x3);
77 }
78
79 TArrayD LeastSqFitExpW1(Int_t n, Double_t *x, Double_t *y);
80 TArrayD LeastSqFitExp(Int_t n, Double_t *x, Double_t *y);
81 TArrayD LeastSqFitLog(Int_t n, Double_t *x, Double_t *y);
82 TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y);
83
84 inline Int_t ModF(Double_t dbl, Double_t &frac) { Double_t rc; frac = ::modf(dbl, &rc); return TMath::Nint(rc); }
85
86 inline Double_t Sqrt3(Double_t x) { return ::cbrt(x); }
87
88 inline Double_t Sgn(Double_t d) { return d<0 ? -1 : 1; }
89
90 void Format(Double_t &v, Double_t &e);
91
92 Double_t RndmExp(Double_t tau);
93}
94
95#endif
Note: See TracBrowser for help on using the repository browser.