Skip to content

Instantly share code, notes, and snippets.

@wiso
Created July 13, 2015 09:54
Show Gist options
  • Save wiso/d9b5d31d02a378057907 to your computer and use it in GitHub Desktop.
Save wiso/d9b5d31d02a378057907 to your computer and use it in GitHub Desktop.
RooSpline
#include "RooFit.h"
#include "RooTrace.h"
#include "Riostream.h"
#include <vector>
#include <string>
#include "RooSpline.h"
#include "RooNameReg.h"
#include "RooAbsReal.h"
#include "RooErrorHandler.h"
#include "RooMsgService.h"
#include "RooTrace.h"
#include "TSpline.h"
#include "TGraph.h"
using namespace std ;
ClassImp(RooSpline)
;
RooSpline::RooSpline()
: m_spline(0)
{
TRACE_CREATE
}
RooSpline::~RooSpline()
{
if (m_spline) { delete m_spline; }
TRACE_DESTROY
}
RooSpline::RooSpline(const char *name, const char *title,
RooAbsReal& x,
const TGraph* gr,
int order)
: RooAbsReal(name, title),
m_x("x", "x", this, x)
{
const std::string title_spline = std::string(title) + "_spline";
if (order == 3) {
m_spline = new TSpline3(title_spline.c_str(), gr);
}
else if (order == 5) {
m_spline = new TSpline5(title_spline.c_str(), gr);
}
else {
coutE(InputArguments) << "supported orders are 3 or 5" << std::endl;
}
TRACE_CREATE
}
RooSpline::RooSpline(const char *name, const char *title,
RooAbsReal& x,
const std::vector<double>& x0, const std::vector<double>& y0,
int order)
: RooAbsReal(name, title),
m_x("x", "x", this, x)
{
const std::string title_spline = std::string(title) + "_spline";
if (x0.size() != y0.size())
{
coutE(InputArguments) << "RooSpline::ctor(" << GetName() << ") ERROR: size of x and y are not equal" << std::endl;
}
// TSpline3 wants Double_t[] as input (non-const, why?)
std::vector<double> x_noncosnt(x0);
std::vector<double> y_nonconst(y0);
if (order == 3) {
m_spline = new TSpline3(title_spline.c_str(),
&x_noncosnt[0],
&y_nonconst[0],
x0.size());
}
else if (order == 5) {
m_spline = new TSpline5(title_spline.c_str(),
&x_noncosnt[0],
&y_nonconst[0],
x0.size());
}
else {
coutE(InputArguments) << "supported orders are 3 or 5" << std::endl;
}
TRACE_CREATE
}
RooSpline::RooSpline(const RooSpline& other, const char* name) :
RooAbsReal(other, name),
m_spline((TSpline*)other.m_spline->Clone()),
m_x("x", this, other.m_x)
{
TRACE_CREATE
}
Double_t RooSpline::evaluate() const
{
const double x_val = m_x;
return m_spline->Eval(x_val);
}
#ifndef ROO_ROOSPLINE
#define ROO_ROOSPLINE
#include <vector>
#include "RooAbsReal.h"
#include "RooRealProxy.h"
#include "RooListProxy.h"
#include "RooObjCacheManager.h"
class RooRealVar;
class RooArgList;
class TSpline3;
class TGraph;
class RooSpline : public RooAbsReal {
public:
RooSpline();
RooSpline(const char *name, const char *title,
RooAbsReal& x,
const std::vector<double>& x0, const std::vector<double>& y0,
int order=3);
RooSpline(const char *name, const char *title,
RooAbsReal& x,
const TGraph* gr,
int order=3);
RooSpline(const RooSpline& other, const char* name = 0);
virtual TObject* clone(const char* newname) const { return new RooSpline(*this, newname); }
virtual ~RooSpline();
protected:
Double_t evaluate() const;
private:
TSpline* m_spline;
RooRealProxy m_x;
ClassDef(RooSpline, 1)
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment