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 <<
"_smoothed_bin_" << i;
65 string n(name_str.str());
66 RooRealVar* coeff =
new RooRealVar(n.c_str(), n.c_str(), values[i], 0.0, 1.0);
67 if (i == 0 || i == values.size() - 1) coeff->setConstant(
true);
68 _coefList.add(*coeff);
69 addOwnedComponents( *coeff );
82 const vector<double>& _knots,
83 const vector<double>& values,
84 const vector<double>& errors,
85 double smooth,
bool constCoeffs) :
86 RooAbsPdf(name, title),
87 _x(
"x",
"Dependent", this, x),
88 _coefList(
"coefficients",
"List of coefficients",this),
89 _aux(_knots.begin(),_knots.end())
91 init(name, values, errors, smooth, constCoeffs);
96 RooRealVar& x,
const TGraph* graph,
bool constCoeffs) :
97 RooAbsPdf(name, title),
98 _x(
"x",
"Dependent", this, x),
99 _coefList(
"coefficients",
"List of coefficients",this),
102 int nPoints = graph->GetN();
103 vector<double> centres, values;
104 for (
int i=0;i<nPoints ;++i) {
106 graph->GetPoint(i,xx,yy);
107 centres.push_back(xx);
108 values.push_back(yy);
112 init(name, values, errs, 0, constCoeffs);
117 RooRealVar& x,
const TH1* hist,
double smooth,
119 RooAbsPdf(name, title),
120 _x(
"x",
"Dependent", this, x),
121 _coefList(
"coefficients",
"List of coefficients",this),
125 int nBins = hist->GetNbinsX();
126 vector<double> centres, values;
127 for (
int i=0;i<nBins ;++i) {
128 centres.push_back(hist->GetBinCenter(1+i));
129 values.push_back(hist->GetBinContent(1+i));
134 if (smooth>0)
for (
int i=0;i<nBins ;++i) errs.push_back(hist->GetBinError(1+i));
136 init(name, values, errs, smooth, constCoeffs);
140 RooRealVar& x,
const TGraphErrors* graph,
double smooth,
142 RooAbsPdf(name, title),
143 _x(
"x",
"Dependent", this, x),
144 _coefList(
"coefficients",
"List of coefficients",this),
147 int nPoints = graph->GetN();
148 vector<double> centres, values;
149 for (
int i=0;i<nPoints ;++i) {
151 graph->GetPoint(i,xx,yy);
152 centres.push_back(xx);
153 values.push_back(yy);
158 if (smooth>0)
for (
int i=0;i<nPoints ;++i) errs.push_back(graph->GetErrorY(i));
160 init(name, values, errs, smooth, constCoeffs);
165 RooRealVar& x,
const char* knotBinningName,
166 const RooArgList& coefList):
167 RooAbsPdf(name, title),
168 _x(
"x",
"Dependent", this, x),
169 _coefList(
"coefficients",
"List of coefficients", this),
174 const RooAbsBinning* binning = x.getBinningPtr(knotBinningName);
176 if ( coefList.getSize()!=2+binning->numBoundaries()) {
177 cout << TString::Format(
"you have specified %d coefficients for %d knots. The differentce should 2!",coefList.getSize(),binning->numBoundaries()) << endl;
178 throw TString::Format(
"you have specified %d coefficients for %d knots. The differentce should 2!",coefList.getSize(),binning->numBoundaries());
182 Double_t* boundaries = binning->array();
188 RooRealVar& x,
const vector<double>& _knots,
189 const RooArgList& coefList):
190 RooAbsPdf(name, title),
191 _x(
"x",
"Dependent", this, x),
192 _coefList(
"coefficients",
"List of coefficients", this),
193 _aux(_knots.begin(), _knots.end())
195 assert(
size_t(coefList.getSize()) == 2 + _knots.size());
201 RooAbsPdf(other, name),
202 _x(
"x", this, other._x),
203 _coefList(
"coefList", this, other._coefList),
224 if (matchArgs(allVars, analVars,
_x))
return 1;
231 coutE(InputArguments) <<
"RooCubicSplinePdf::analyticalIntegral(" << GetName()
232 <<
"): argument \"code\" can only have value 1" << std::endl;
244 return dM(0)*( s_jk(0,0) * K(0) * sc[0] + s_jk(0,1) * K(1) * sc[1] )
245 + dM(1)*( s_jk(1,0) * K(0) * sc[1] );
251 Double_t scale, Double_t _offset,
252 const std::complex<double>& z)
const 257 std::vector<M_n> M; M.reserve(
knotSize() );
258 for (
unsigned int i=0;i<
knotSize();++i) {
259 double x = (
u(i)-_offset)/scale ;
260 M.push_back( M_n( x, z ) );
262 double sc[4];
for (
int i=0;i<4;++i) sc[i] = pow(scale,i);
263 double lo = scale*umin+_offset;
264 double hi = scale*umax+_offset;
265 std::complex<double> sum(0,0);
268 if (lo<
u(0)) sum +=
gaussIntegralE(
true, M.front()-M_n( umin,z), K, _offset, sc);
269 for (
unsigned i=0;i<
knotSize()-1 &&
u(i)<hi ;++i) {
270 if (
u(i+1)<lo)
continue;
274 M_n dM = M[i+1]-M[i];
276 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) <<
"RooCubicSplinePdf::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
unsigned knotSize() const
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName) const
void init(const char *name, const std::vector< double > &heights, const std::vector< double > &errors, double smooth, bool constCoeffs)
Int_t getMaxVal(const RooArgSet &vars) const
RooCubicSplineKnot::S_edge S_jk_edge(bool left, 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 analyticalIntegral(const RooArgList &b) const
const std::vector< double > & knots() const
double evaluate(double _u, const RooArgList &b) const
Double_t maxVal(Int_t code) const
Double_t analyticalIntegral(Int_t code, const char *rangeName) const
Double_t evaluate() const