1 #ifndef ROO_CUBICSPLINEKNOT 2 #define ROO_CUBICSPLINEKNOT 5 #include "RooArgList.h" 18 ,
double valueLeft=0,
double valueRight=0 )
31 double u(
int i)
const {
35 return _u[std::min(std::max(0,i),
size()-1)]; }
36 int size()
const {
return _u.size(); }
37 double evaluate(
double _u,
const RooArgList& b)
const;
40 void computeCoefficients(std::vector<double>& y, BoundaryConditions bc = BoundaryConditions() )
const ;
41 void smooth(std::vector<double>& y,
const std::vector<double>& dy,
double lambda)
const;
43 const std::vector<double>&
knots()
const {
return _u; }
48 S_jk(
double a,
double b,
double c) :
t(a*b*c),
d(0.5*(a*b+a*c+b*c) ),
s( 0.25*(a+b+c) ),
o(0.125) { }
49 S_jk(
const S_jk& other,
double offset=0) :
t(other.
t),
d(other.
d),
s(other.
s),
o(other.
o) {
51 t+=offset*(-2*
d+offset*(4*
s-offset*
o*8));
52 d+=offset*(-8*
s+3*offset*
o*8)/2;
68 if (j>k) std::swap(j,k);
91 S2_jk(
double a1,
double b1,
double c1,
double a2,
double b2,
double c2) :
92 t0(a1*b1*c1*a2*b2*c2),
93 t1(1./2.*((a1*b1*c1)*(a2*b2+a2*c2+b2*c2)+(a2*b2*c2)*(a1*b1+a1*c1+b1*c1))),
94 t2(1./4.*((a1*b1*c1)*(a2+b2+c2)+(a2*b2*c2)*(a1+b1+c1)+(a1*b1+a1*c1+b1*c1)*(a2*b2+a2*c2+b2*c2))),
95 t3(1./8.*((a1*b1*c1)+(a2*b2*c2)+(a1+b1+c1)*(a2*b2+a2*c2+b2*c2)+(a2+b2+c2)*(a1*b1+a1*c1+b1*c1))),
96 t4(1./16.*((a1*b1+a1*c1+b1*c1)+(a2*b2+a2*c2+b2*c2)+(a1+b1+c1)*(a2+b2+c2))),
97 t5(1./32.*((a1+b1+c1)+(a2+b2+c2))),
102 t0+=offset*(-2*
t1+offset*(4*
t2+offset*(-8*
t3+offset*(16*
t4+offset*(-32*
t5+offset*64*
t6)))));
103 t1+=offset*(-8*
t2+offset*(3*8*
t3+offset*(-4*16*
t4+offset*(5*32*
t5-6*offset*64*
t6))))/2;
104 t2+=offset*(-3*8*
t3+offset*(6*16*
t4+offset*(-10*32*
t5+15*offset*64*
t6)))/4;
105 t3+=offset*(-4*16*
t4+offset*(10*32*
t5-20*offset*64*
t6))/8;
106 t4+=offset*(-5*32*
t5+15*offset*64*
t6)/16;
107 t5-=offset*6*64*
t6/32;
122 if (j>k) std::swap(j,k);
134 case 8:
return -3*
t3;
136 case 10:
return -5*
t5;
139 case 15:
return -10*
t5;
140 case 16:
return 15*
t6;
141 case 21:
return 20*
t6;
159 assert(0<=(j+k) && (j+k)<2);
170 S2_edge(
double a1,
double b1,
double a2,
double b2) :
172 t1(1./2.*(a1*b2+a2*b1)),
177 t0+=offset*(2*
t1+offset*4*
t2);
182 if (j>k) std::swap(j,k);
202 double expIntegral(
const TH1* hist,
double gamma,
TVectorD& coefficients, TMatrixD& covarianceMatrix)
const;
207 int index(
double u_)
const;
210 double A(
double u_,
int i)
const{
return -
cub(
d(u_,i+1))/
P(i); }
211 double B(
double u_,
int i)
const{
return sqr(
d(u_,i+1))*
d(u_,i-2)/
P(i) +
d(u_,i-1)*
d(u_,i+2)*
d(u_,i+1)/
Q(i) +
d(u_,i )*
sqr(
d(u_,i+2))/
R(i); }
212 double C(
double u_,
int i)
const{
return -
sqr(
d(u_,i-1))*
d(u_,i+1)/
Q(i) -
d(u_,i )*
d(u_,i+2)*
d(u_,i-1)/
R(i) -
d(u_,i+3)*
sqr(
d(u_,i ))/
S(i); }
213 double D(
double u_,
int i)
const{
return cub(
d(u_,i ))/
S(i); }
216 double ma(
int i,
bool bc[])
const {
218 return (i!=
size()-1) ?
A(
u(i),i)
219 : (bc[1] ) ?
double(6)/(
h(i,i-2)*
h(i-1))
223 double mc(
int i,
bool bc[])
const {
224 return (i!=0) ?
C(
u(i),i)
225 : bc[0] ? double(6)/(
h(2,0)*
h(0))
229 double mb(
int i,
bool bc[])
const {
230 if (i!=0 && i!=
size()-1)
return B(
u(i),i);
233 return bc[0] ? -(double(6)/
h(i)+double(6)/
h(i+2,i))/
h(i)
236 return bc[1] ? -(double(6)/
h(i-1)+double(6)/
h(i,i-2))/
h(i-1)
237 : - double(3)/
h(i-1);
251 static double sqr(
double x) {
return x*x; }
252 static double cub(
double x) {
return x*
sqr(x); }
254 double d(
double u_,
int j)
const {
return u_-
u(j); }
255 double d(
double u_,
int i,
int j,
int k)
const {
return d(u_,i)*
d(u_,j)*
d(u_,k); }
256 double h(
int i,
int j)
const {
return u(i)-
u(j); }
257 double h(
int i)
const {
return h(i+1,i); }
258 double r(
int i)
const {
return double(3)/
h(i); }
259 double f(
int i)
const {
return -
r(i-1)-
r(i); }
260 double p(
int i)
const {
return 2*
h(i-1)+
h(i); }
262 std::vector<double>
_u;
265 mutable std::vector<RooCubicSplineKnot::S_jk>
_S_jk;
266 mutable std::vector<RooCubicSplineKnot::S2_jk>
_S2_jk;
RooCubicSplineKnot::S_jk S_jk_sum(int i, const RooArgList &b) const
S2_jk & operator *=(double z)
S_jk operator/(double z) const
double mb(int i, bool bc[]) const
RooCubicSplineKnot::S2_jk S2_jk_sum(int i, const RooArgList &b1, const RooArgList &b2) const
std::vector< RooCubicSplineKnot::S_jk > _S_jk
double operator()(int j, int k) const
S2_edge(const S2_edge &other, double offset=0)
double D(double u_, int i) const
double C(double u_, int i) const
double B(double u_, int i) const
RooCubicSplineKnot::S2_edge S2_jk_edge(bool left, const RooArgList &b1, const RooArgList &b2) const
RooCubicSplineKnot(const double *array, int nEntries)
S_jk & operator *=(double z)
S2_jk & operator-=(const S2_jk &other)
S_edge(double a, double b)
BoundaryConditions(bool leftSecondDerivative=true, bool rightSecondDerivative=true, double valueLeft=0, double valueRight=0)
S2_jk operator+(const S2_jk &other) const
static double cub(double x)
double operator()(int j, int k) const
std::vector< double > _PQRS
double d(double u_, int i, int j, int k) const
RooCubicSplineKnot(const std::vector< double > &knots)
int index(double u_) const
S_jk operator+(const S_jk &other) const
S_jk operator *(double z) const
RooCubicSplineKnot::S_edge S_jk_edge(bool left, const RooArgList &b) const
S_jk operator-(const S_jk &other) const
double h(int i, int j) const
S2_jk(const S2_jk &other, double offset=0)
static double qua(double x)
static double sqr(double x)
void smooth(std::vector< double > &y, const std::vector< double > &dy, double lambda) const
double mc(int i, bool bc[]) const
S2_jk operator-(const S2_jk &other) const
double analyticalIntegral(const RooArgList &b) const
double d(double u_, int j) const
S2_jk operator *(double z) const
std::vector< RooCubicSplineKnot::S2_jk > _S2_jk
S2_jk operator/(double z) const
double expIntegral(const TH1 *hist, double gamma, TVectorD &coefficients, TMatrixD &covarianceMatrix) const
S2_jk & operator+=(const S2_jk &other)
S_jk & operator/=(double z)
S_jk & operator+=(const S_jk &other)
void computeCoefficients(std::vector< double > &y, BoundaryConditions bc=BoundaryConditions()) const
double operator()(int j, int k) const
TVectorT< Double_t > TVectorD
S_jk(const S_jk &other, double offset=0)
const std::vector< double > & knots() const
double evaluate(double _u, const RooArgList &b) const
RooCubicSplineKnot(Iter begin, Iter end)
S_jk & operator-=(const S_jk &other)
S_jk(double a, double b, double c)
double lambda(double x, double y, double z)
double operator()(int j, int k) const
S2_jk & operator/=(double z)
S2_jk(double a1, double b1, double c1, double a2, double b2, double c2)
S2_edge(double a1, double b1, double a2, double b2)
std::vector< double > _IABCD
double A(double u_, int i) const
double ma(int i, bool bc[]) const