00001 #include "../interface/RooSpline1D.h" 00002 00003 #include <stdexcept> 00004 00005 RooSpline1D::RooSpline1D(const char *name, const char *title, RooAbsReal &xvar, unsigned int npoints, const double *xvals, const double *yvals, const char *algo) : 00006 RooAbsReal(name,title), 00007 xvar_("xvar","Variable", this, xvar), 00008 x_(npoints), y_(npoints), type_(algo), 00009 interp_(0) 00010 { 00011 for (unsigned int i = 0; i < npoints; ++i) { 00012 x_[i] = xvals[i]; 00013 y_[i] = yvals[i]; 00014 } 00015 } 00016 00017 RooSpline1D::RooSpline1D(const char *name, const char *title, RooAbsReal &xvar, unsigned int npoints, const float *xvals, const float *yvals, const char *algo) : 00018 RooAbsReal(name,title), 00019 xvar_("xvar","Variable", this, xvar), 00020 x_(npoints), y_(npoints), type_(algo), 00021 interp_(0) 00022 { 00023 for (unsigned int i = 0; i < npoints; ++i) { 00024 x_[i] = xvals[i]; 00025 y_[i] = yvals[i]; 00026 } 00027 } 00028 00029 00030 RooSpline1D::~RooSpline1D() 00031 { 00032 delete interp_; 00033 } 00034 00035 00036 TObject *RooSpline1D::clone(const char *newname) const 00037 { 00038 return new RooSpline1D(newname, this->GetTitle(), const_cast<RooAbsReal &>(xvar_.arg()), x_.size(), &x_[0], &y_[0], type_.c_str()); 00039 } 00040 00041 void RooSpline1D::init() const { 00042 delete interp_; 00043 if (type_ == "CSPLINE") interp_ = new ROOT::Math::Interpolator(x_, y_, ROOT::Math::Interpolation::kCSPLINE); 00044 else if (type_ == "LINEAR") interp_ = new ROOT::Math::Interpolator(x_, y_, ROOT::Math::Interpolation::kLINEAR); 00045 else if (type_ == "POLYNOMIAL") interp_ = new ROOT::Math::Interpolator(x_, y_, ROOT::Math::Interpolation::kPOLYNOMIAL); 00046 else if (type_ == "CSPLINE_PERIODIC") interp_ = new ROOT::Math::Interpolator(x_, y_, ROOT::Math::Interpolation::kCSPLINE_PERIODIC); 00047 else if (type_ == "AKIMA") interp_ = new ROOT::Math::Interpolator(x_, y_, ROOT::Math::Interpolation::kAKIMA); 00048 else if (type_ == "AKIMA_PERIODIC") interp_ = new ROOT::Math::Interpolator(x_, y_, ROOT::Math::Interpolation::kAKIMA_PERIODIC); 00049 else throw std::invalid_argument("Unknown interpolation type '"+type_+"'"); 00050 } 00051 00052 Double_t RooSpline1D::evaluate() const { 00053 if (interp_ == 0) init(); 00054 return interp_->Eval(xvar_); 00055 } 00056 00057 00058 ClassImp(RooSpline1D)