80 for (i=0;i<
fNin;i++) {
81 xin[i] =
fGin->GetX()[i];
82 yin[i] =
fGin->GetY()[i];
88 for (i=0;i<
fNin;i++) {
89 fGin->SetPoint(i, xin[index[i]], yin[index[i]]);
117 if (opt.
Contains(
"normal")) kernel = 2;
122 Int_t *index =
nullptr;
123 if (xout ==
nullptr) {
128 index =
new Int_t[nout];
139 if (xout ==
nullptr)
fGout->SetPoint(i,
fMinX + i*delta, 0);
140 else fGout->SetPoint(i,xout[index[i]], 0);
143 if (xout ==
nullptr)
fGout->SetPoint(i,
fMaxX + (i + 1 -
fNout)*delta, 0);
144 else fGout->SetPoint(i,xout[index[i]], 0);
150 if (index) {
delete [] index; index =
nullptr;}
176 while ((imin <
n) && (
x[imin] < xp[0] - cutoff))
179 for (
Int_t j=0;j<np;j++) {
184 for (
Int_t i=imin;i<
n;i++) {
185 if (
x[i] < x0 - cutoff) imin = i;
186 if (
x[i] > x0 + cutoff)
break;
188 if (kernel == 1) w = 1;
258 Int_t i, iiter, j, last, m1, m2, nleft, nright, ns;
259 Double_t alpha,
c1, c9, cmad, cut, d1, d2, denom,
r;
280 while (iiter <= iter+1) {
289 d1 =
x[i] -
x[nleft];
290 d2 =
x[nright+1] -
x[i];
303 Lowest(&
x[1], &
y[1],
n,
x[i], ys[i], nleft, nright,
304 res, iterg1, rw, ok);
305 if (!ok) ys[i] =
y[i];
309 denom =
x[i]-
x[last];
312 for(j = last+1; j < i; j++) {
313 alpha = (
x[j]-
x[last])/denom;
314 ys[j] = alpha*ys[i] + (1.-alpha)*ys[last];
322 cut =
x[last] + delta;
323 for (i = last+1; i <=
n; i++) {
326 if (
x[i] ==
x[last]) {
338 res[i] =
y[i+1] - ys[i+1];
353 cmad = 3.*(rw[m1]+rw[m2]);
360 for(i=0 ; i<
n ; i++) {
365 rw[i] = (1.-(
r/cmad)*(
r/cmad))*(1.-(
r/cmad)*(
r/cmad));
407 w[j] = (1.-
d)*(1.-
d)*(1.-
d);
412 }
else if (
x[j] > xs)
424 for(j=nleft ; j<=nrt ; j++)
429 for(j=nleft ; j<=nrt ; j++)
433 for(j=nleft ; j<=nrt ; j++)
434 c += w[j]*(
x[j]-
a)*(
x[j]-
a);
438 for(j=nleft; j <= nrt; j++)
439 w[j] *= (
b*(
x[j]-
a) + 1.);
443 for(j=nleft; j <= nrt; j++)
490 if (span < 0 || span > 1) {
491 std::cout <<
"Error: Span must be between 0 and 1" << std::endl;
503 std::cout <<
"Error: x must be between 0 and 1 for periodic smooth" << std::endl;
512 for (i=0; i<
fNout; i++) {
518 for (i=0; i<
fNin; i++) {
519 if (w ==
nullptr) weight[i] = 1;
520 else weight[i] = w[i];
526 for (i=0; i<nTmp; i++) {
591 Double_t spans[3] = { 0.05, 0.2, 0.5 };
614 if (sw > 0.0)
a = sy / sw;
615 for (j=1;j<=
n;++j) smo[j] =
a;
622 while (scale <= 0.0) {
632 if (iper == 2 && (
x[1] < 0.0 ||
x[
n] > 1.0)) {
635 if (jper < 1 || jper > 2) {
640 &smo[1], &sc[sc_offset]);
645 for (i = 1; i <= 3; ++i) {
646 BDRsmooth(
n, &
x[1], &
y[1], &w[1], spans[i - 1], jper, vsmlsq,
647 &sc[((i<<1)-1)*
n + 1], &sc[
n*7 + 1]);
648 BDRsmooth(
n, &
x[1], &sc[
n*7 + 1], &w[1], spans[1], -jper, vsmlsq,
649 &sc[(i<<1)*
n + 1], &
h[1]);
652 for (j=1; j<=
n; ++j) {
654 for (i=1; i<=3; ++i) {
655 if (sc[j + (i<<1)*
n] < resmin) {
656 resmin = sc[j + (i<<1)*
n];
657 sc[j +
n*7] = spans[i-1];
661 if (alpha>0.0 && alpha<=10.0 && resmin<sc[j +
n*6] && resmin>0.0) {
669 BDRsmooth(
n, &
x[1], &sc[
n*7 + 1], &w[1], spans[1], -jper, vsmlsq,
670 &sc[(
n<<1) + 1], &
h[1]);
672 for (j=1; j<=
n; ++j) {
673 if (sc[j + (
n<<1)] <= spans[0]) {
674 sc[j + (
n<<1)] = spans[0];
676 if (sc[j + (
n<<1)] >= spans[2]) {
677 sc[j + (
n<<1)] = spans[2];
679 f = sc[j + (
n<<1)] - spans[1];
681 f = -
f / (spans[1] - spans[0]);
682 sc[j + (
n<<2)] = (1.0 -
f) * sc[j +
n*3] +
f * sc[j +
n];
684 f /= spans[2] - spans[1];
685 sc[j + (
n<<2)] = (1.0 -
f) * sc[j +
n*3] +
f * sc[j +
n*5];
689 BDRsmooth(
n, &
x[1], &sc[(
n<<2) + 1], &w[1], spans[0], -jper, vsmlsq,
705 Int_t i, j, j0, in, out, it, jper, ibw;
725 ibw = (
Int_t)(span * 0.5 *
n + 0.5);
731 for (i=1; i<=it; ++i) {
745 xm = (fbo * xm + wt * xti) / fbw;
746 ym = (fbo * ym + wt *
y[j]) / fbw;
750 tmp = fbw * wt * (xti - xm) / fbo;
752 var += tmp * (xti - xm);
753 cvar += tmp * (
y[j] - ym);
756 for (j=1; j<=
n; ++j) {
759 if (!(jper != 2 && (out < 1 || in >
n))) {
778 tmp = fbo * wt * (xto - xm) / fbw;
780 var -= tmp * (xto - xm);
781 cvar -= tmp * (
y[out] - ym);
783 xm = (fbo * xm - wt * xto) / fbw;
784 ym = (fbo * ym - wt *
y[out]) / fbw;
790 xm = (fbo * xm + wt * xti) / fbw;
791 ym = (fbo * ym + wt *
y[in]) / fbw;
795 tmp = fbw * wt * (xti - xm) / fbo;
797 var += tmp * (xti - xm);
798 cvar += tmp * (
y[in] - ym);
805 smo[j] =
a * (
x[j] - xm) + ym;
839 if (
x[j + 1] >
x[j]) {
853 for (i=j0; i<=j; ++i) {
876 for (i=0;i<
fNin;i++) {
877 xin[i] =
fGin->GetX()[i];
878 yin[i] =
fGin->GetY()[i];
893 for (i=1;i<
fNin+1;i++) {
895 vMin = vMean = vMax = yin[index[i-1]];
896 while ((i <
fNin) && (rank[index[i]] == rank[index[i-1]])) {
897 vMean += yin[index[i]];
898 vMax = (vMax < yin[index[i]]) ? yin[index[i]] : vMax;
899 vMin = (vMin > yin[index[i]]) ? yin[index[i]] : vMin;
905 x[k] = xin[index[i-1]];
906 if (ndup == 1) {
y[k++] = yin[index[i-1]];}
926 for (i=0;i<
fNin;i++) {
927 fGin->SetPoint(i,
x[i],
y[i]);
940 ylow =
fGin->GetY()[0];
1011 if (opt.
Contains(
"linear")) iKind = 1;
1012 else if (opt.
Contains(
"constant")) iKind = 2;
1015 std::cout <<
"Error: Invalid f value" << std::endl;
1031 std::cout <<
"Error: Method not known: " << ties << std::endl;
1038 Approxin(grin, iKind, ylow, yhigh, rule, iTies);
1043 if (xout ==
nullptr) {
1052 if (xout ==
nullptr)
x =
fMinX + i*delta;
1055 fGout->SetPoint(i,
x, yout);
1058 if (xout ==
nullptr)
x =
fMaxX + delta*(i + 1 -
fNout);
1061 fGout->SetPoint(i,
x, yout);
1080 if(
v <
x[i])
return ylow;
1081 if(
v >
x[j])
return yhigh;
1085 Int_t ij = (i + j)/2;
1086 if(
v <
x[ij]) j = ij;
1091 if(
v ==
x[j])
return y[j];
1092 if(
v ==
x[i])
return y[i];
1095 return y[i] + (
y[j] -
y[i]) * ((
v -
x[i])/(
x[j] -
x[i]));
1097 return y[i] * (1-
f) +
y[j] *
f;
1109 if (
x <
y)
return -1;
1110 if (
x >
y)
return 1;
1124 for (pL = 0, pR =
n - 1; pL < pR; ) {
1126 for(i = pL, j = pR; i <= j;) {
1129 if (i <= j) { w =
x[i];
x[i++] =
x[j];
x[j--] = w; }
1151 for (
Int_t i=0;i<
n;i++) {
1152 if ((i > 0) && (
a[index[i]] ==
a[index[i-1]])) {
1153 rank[index[i]] = i-1;
1156 rank[index[i]] = i-k;
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char).
Double_t fMinX
Minimum value of array X.
TGraph * fGin
Input graph.
Double_t fMaxX
Maximum value of array X.
static Int_t Rcmp(Double_t x, Double_t y)
Static function if (ISNAN(x)) return 1; if (ISNAN(y)) return -1;.
TGraph * SmoothLowess(TGraph *grin, Option_t *option="", Double_t span=0.67, Int_t iter=3, Double_t delta=0)
Smooth data with Lowess smoother.
~TGraphSmooth() override
GraphSmooth destructor.
TGraph * SmoothSuper(TGraph *grin, Option_t *option="", Double_t bass=0, Double_t span=0, Bool_t isPeriodic=kFALSE, Double_t *w=nullptr)
Smooth data with Super smoother.
static void Rank(Int_t n, Double_t *a, Int_t *index, Int_t *rank, Bool_t down=kTRUE)
static function
Int_t fNout
Number of output points.
static void BDRksmooth(Double_t *x, Double_t *y, Int_t n, Double_t *xp, Double_t *yp, Int_t np, Int_t kernel, Double_t bw)
Smooth data with specified kernel.
Int_t fNin
Number of input points.
void Smoothin(TGraph *grin)
Sort input data points.
TGraph * SmoothKern(TGraph *grin, Option_t *option="normal", Double_t bandwidth=0.5, Int_t nout=100, Double_t *xout=nullptr)
Smooth data with Kernel smoother.
TGraph * Approx(TGraph *grin, Option_t *option="linear", Int_t nout=50, Double_t *xout=nullptr, Double_t yleft=0, Double_t yright=0, Int_t rule=0, Double_t f=0, Option_t *ties="mean")
Approximate data points.
static void BDRsupsmu(Int_t n, Double_t *x, Double_t *y, Double_t *w, Int_t iper, Double_t span, Double_t alpha, Double_t *smo, Double_t *sc)
Friedmanns super smoother (Friedman, 1984).
static void Psort(Double_t *x, Int_t n, Int_t k)
Static function based on R function rPsort: adapted to C++ by Christian Stratowa (R source file: R_so...
TGraph * fGout
Output graph.
static void Lowest(Double_t *x, Double_t *y, Int_t n, Double_t &xs, Double_t &ys, Int_t nleft, Int_t nright, Double_t *w, Bool_t userw, Double_t *rw, Bool_t &ok)
Fit value at x[i] Based on R function lowest: Translated to C++ by C.
static void BDRsmooth(Int_t n, Double_t *x, Double_t *y, Double_t *w, Double_t span, Int_t iper, Double_t vsmlsq, Double_t *smo, Double_t *acvr)
Function for super smoother Based on R function supsmu: Translated to C++ by C.
static Double_t Approx1(Double_t v, Double_t f, Double_t *x, Double_t *y, Int_t n, Int_t iKind, Double_t Ylow, Double_t Yhigh)
Approximate one data point.
void Lowess(Double_t *x, Double_t *y, Int_t n, Double_t *ys, Double_t span, Int_t iter, Double_t delta)
Lowess regression smoother.
void Approxin(TGraph *grin, Int_t iKind, Double_t &Ylow, Double_t &Yhigh, Int_t rule, Int_t iTies)
Sort data points and eliminate double x values.
void ToLower()
Change string to lower-case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Double_t Sqrt(Double_t x)
Returns the square root of x.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
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.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.