30 #include "TGraphErrors.h" 33 #include "RooMsgService.h" 35 #include "RooAbsReal.h" 36 #include "RooRealVar.h" 37 #include "RooConstVar.h" 38 #include "RooArgList.h" 50 const vector<double>& heights,
51 const vector<double>& errors,
52 double smooth,
bool constCoeffs) {
53 vector<double> values(heights);
55 assert(
int(errors.size()) == _aux.size());
56 _aux.smooth( values, errors, smooth );
58 _aux.computeCoefficients( values );
59 for (
unsigned int i=0;i<values.size();++i) {
61 _coefList.add( RooFit::RooConst( values[i] ) );
63 stringstream name_str;
64 name_str << name <<
"_bin_" << i;
65 string n(name_str.str());
66 RooRealVar* coeff =
new RooRealVar(n.c_str(), n.c_str(), values[i], 0.0, 10.0);
68 if (i == values.size() - 2){
70 coeff->setConstant(
true);
72 _coefList.add(*coeff);
73 addOwnedComponents( *coeff );
86 const vector<double>& knots,
87 const vector<double>& values,
88 const vector<double>& errors,
89 double smooth,
bool constCoeffs) :
91 _x(
"x",
"Dependent", this, x),
92 _coefList(
"coefficients",
"List of coefficients",this),
93 _aux(knots.begin(),knots.end())
95 init(name, values, errors, smooth, constCoeffs);
100 RooRealVar& x,
const TGraph* graph,
bool constCoeffs) :
102 _x(
"x",
"Dependent", this, x),
103 _coefList(
"coefficients",
"List of coefficients",this),
106 int nPoints = graph->GetN();
107 vector<double> centres, values;
108 for (
int i=0;i<nPoints ;++i) {
110 graph->GetPoint(i,x,y);
111 centres.push_back(x);
116 init(name, values, errs, 0, constCoeffs);
121 RooRealVar& x,
const TH1* hist,
double smooth,
124 _x(
"x",
"Dependent", this, x),
125 _coefList(
"coefficients",
"List of coefficients",this),
129 int nBins = hist->GetNbinsX();
130 vector<double> centres, values;
131 for (
int i=0;i<nBins ;++i) {
132 centres.push_back(hist->GetBinCenter(1+i));
133 values.push_back(hist->GetBinContent(1+i));
138 if (smooth>0)
for (
int i=0;i<nBins ;++i) errs.push_back(hist->GetBinError(1+i));
140 init(name, values, errs, smooth, constCoeffs);
144 RooRealVar& x,
const TGraphErrors* graph,
double smooth,
147 _x(
"x",
"Dependent", this, x),
148 _coefList(
"coefficients",
"List of coefficients",this),
151 int nPoints = graph->GetN();
152 vector<double> centres, values;
153 for (
int i=0;i<nPoints ;++i) {
155 graph->GetPoint(i,x,y);
156 centres.push_back(x);
162 if (smooth>0)
for (
int i=0;i<nPoints ;++i) errs.push_back(graph->GetErrorY(i));
164 init(name, values, errs, smooth, constCoeffs);
169 RooRealVar& x,
const char* knotBinningName,
170 const RooArgList& coefList):
172 _x(
"x",
"Dependent", this, x),
173 _coefList(
"coefficients",
"List of coefficients", this),
178 const RooAbsBinning* binning = x.getBinningPtr(knotBinningName);
180 if ( coefList.getSize()!=2+binning->numBoundaries()) {
181 cout << TString::Format(
"you have specified %d coefficients for %d knots. The differentce should 2!",coefList.getSize(),binning->numBoundaries()) << endl;
182 throw TString::Format(
"you have specified %d coefficients for %d knots. The differentce should 2!",coefList.getSize(),binning->numBoundaries());
186 Double_t* boundaries = binning->array();
192 RooRealVar& x,
const vector<double>& knots,
193 const RooArgList& coefList):
195 _x(
"x",
"Dependent", this, x),
196 _coefList(
"coefficients",
"List of coefficients", this),
197 _aux(knots.begin(), knots.end())
199 assert(
size_t(coefList.getSize()) == 2 +
knots.size());
206 _x(
"x", this, other._x),
207 _coefList(
"coefList", this, other._coefList),
228 if (matchArgs(allVars, analVars,
_x))
return 1;
235 coutE(InputArguments) <<
"RooCubicSplineFun::analyticalIntegral(" << GetName()
236 <<
"): argument \"code\" can only have value 1" << std::endl;
248 return dM(0)*( s_jk(0,0) * K(0) * sc[0] + s_jk(0,1) * K(1) * sc[1] )
249 + dM(1)*( s_jk(1,0) * K(0) * sc[1] );
255 Double_t scale, Double_t offset,
256 const std::complex<double>& z)
const 260 double lo = scale*umin+offset;
261 double hi = scale*umax+offset+1.e-7;
263 std::vector<M_n> M; M.reserve(
knotSize() );
264 for (
unsigned int i=0;i<
knotSize();++i) {
265 double x = (
u(i)-offset)/scale ;
267 if (lo>=
u(i)) x = umin ;
268 if (
u(i)>=hi) x = umax ;
269 M.push_back( M_n( x, z ) );
271 double sc[4];
for (
int i=0;i<4;++i) sc[i] = pow(scale,i);
272 std::complex<double> sum(0,0);
273 if (lo<
u(0)) sum +=
gaussIntegralE(
true, M.front()-M_n( umin,z), K, offset, sc);
274 for (
unsigned i=0;i<
knotSize()-1 &&
u(i)<hi ;++i) {
275 M_n dM = M[i+1]-M[i];
277 for (
int j=0;j<4;++j)
for (
int k=0;k<4-j;++k) sum += dM(j)*s_jk(j,k)*K(k)*sc[j+k];
287 return ( vars.getSize() == 1 && vars.contains(
_x.arg() ) ) ? 1 : 0;
293 coutE(InputArguments) <<
"RooCubicSplineFun::maxVal(" << GetName()
294 <<
"): argument \"code\" can only have value 1" << std::endl;
300 while((c=(RooAbsReal*)iter.next())) {
301 double x = fabs(c->getVal());
302 if (x>res) { res = x; }
RooCubicSplineKnot::S_jk S_jk_sum(int i, const RooArgList &b) const
RooCubicSplineKnot::S_edge S_jk_edge(bool left, const RooArgList &b) const
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName) const
Double_t evaluate() const
double analyticalIntegral(const RooArgList &b) const
void init(const char *name, const std::vector< double > &heights, const std::vector< double > &errors, double smooth, bool constCoeffs)
const std::vector< double > & knots() const
unsigned knotSize() const
Double_t analyticalIntegral(Int_t code, const char *rangeName) const
const std::vector< double > & knots() const
Int_t getMaxVal(const RooArgSet &vars) const
double evaluate(double _u, const RooArgList &b) const
std::complex< double > gaussIntegralE(bool left, const RooGaussModelAcceptance::M_n< 4U > &dM, const RooGaussModelAcceptance::K_n &K, double offset, double *sc) const
std::complex< double > productAnalyticalIntegral(Double_t umin, Double_t umax, Double_t scale, Double_t offset, const std::complex< double > &z) const
Double_t maxVal(Int_t code) const