75using std::cout, std::endl, std::vector;
80 fMaxDegree(10), fMaxCorrection(100), fTolerance(tolerance){
88 const char* nominalName,
90 const char* dataName){
96 if (!
x || !nominal || !
data) {
97 cout <<
"Error: wrong name for pdf or variable or dataset - return -1 " << std::endl;
101 std::cout <<
"BernsteinCorrection::ImportCorrectedPdf - Doing initial Fit with nominal model " << std::endl;
107 double lastNll= nominalResult->minNll();
109 if (nominalResult->status() != 0 ) {
110 std::cout <<
"BernsteinCorrection::ImportCorrectedPdf - Error fit with nominal model failed - exit" << std::endl;
115 std::stringstream log;
116 log <<
"------ Begin Bernstein Correction Log --------" << endl;
120 vector<RooRealVar*> coefficients;
125 bool keepGoing =
true;
130 std::stringstream str;
134 "Bernstein basis poly coefficient",
137 coefficients.push_back(newCoef);
154 if (
result->status() != 0) {
155 std::cout <<
"BernsteinCorrection::ImportCorrectedPdf - Error fit with corrected model failed" << std::endl;
162 q = 2*(lastNll -
result->minNll());
180 log <<
"degree = " << degree
181 <<
" -log L("<<degree-1<<
") = " << lastNll
182 <<
" -log L(" << degree <<
") = " <<
result->minNll()
188 lastNll =
result->minNll();
191 log <<
"------ End Bernstein Correction Log --------" << endl;
202 const char* nominalName,
204 const char* dataName,
206 TH1F* samplingDistExtra,
214 if (!
x || !nominal || !
data) {
215 cout <<
"Error: wrong name for pdf or variable or dataset ! " << std::endl;
220 std::stringstream log;
221 log <<
"------ Begin Bernstein Correction Log --------" << endl;
227 vector<RooRealVar*> coefficients;
230 for(
int i = 0; i<=degree+1; ++i) {
232 std::stringstream str;
236 "Bernstein basis poly coefficient",
240 if(i<degree) coeffNull.
add(*newCoef);
241 if(i<=degree) coeff.
add(*newCoef);
242 coeffExtra.
add(*newCoef);
243 coefficients.push_back(newCoef);
252 =
new RooBernstein(
"polyNull",
"Bernstein poly", *
x, coeffNull);
256 =
new RooBernstein(
"polyExtra",
"Bernstein poly", *
x, coeffExtra);
260 =
new RooEffProd(
"corrected",
"",*nominal,*poly);
263 =
new RooEffProd(
"correctedNull",
"",*nominal,*polyNull);
266 =
new RooEffProd(
"correctedExtra",
"",*nominal,*polyExtra);
269 cout <<
"made pdfs, make toy generator" << endl;
278 if (printLevel < 0) {
287 for (
int i = 0; i < nToys; ++i) {
288 cout <<
"on toy " << i << endl;
290 std::unique_ptr<RooDataSet> tmpData{toyGen.
generate(*
x,
data->numEntries())};
292 std::unique_ptr<RooFitResult>
result{
295 std::unique_ptr<RooFitResult> resultNull{
298 std::unique_ptr<RooFitResult> resultExtra{
303 q = 2 * (resultNull->minNll() -
result->minNll());
305 qExtra = 2 * (
result->minNll() - resultExtra->minNll());
307 samplingDist->
Fill(
q);
308 samplingDistExtra->
Fill(qExtra);
309 if (printLevel > 0) {
310 cout <<
"NLL Results: null " << resultNull->minNll() <<
" ref = " <<
result->minNll() <<
" extra"
311 << resultExtra->minNll() << endl;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
static int DefaultPrintLevel()
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Abstract base class for binned and unbinned datasets.
Abstract interface for all probability density functions.
RooFit::OwningPtr< RooFitResult > fitTo(RooAbsData &data, CmdArgs_t const &... cmdArgs)
Fit PDF to given dataset.
RooFit::OwningPtr< RooDataSet > generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={})
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
void setConstant(bool value=true)
RooArgList is a container object that can hold multiple RooAbsArg objects.
Bernstein basis polynomials are positive-definite in the range [0,1].
Container class to hold N-dimensional binned data.
The class RooEffProd implements the product of a PDF with an efficiency function.
A propability density function sampled from a multidimensional histogram.
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
BernsteinCorrection is a utility in RooStats to augment a nominal PDF with a polynomial correction te...
Int_t ImportCorrectedPdf(RooWorkspace *, const char *, const char *, const char *)
Main method for Bernstein correction.
double fMaxCorrection
maximum correction factor at any point (default is 100)
BernsteinCorrection(double tolerance=0.05)
double fTolerance
probability to add an unnecessary term
Int_t fMaxDegree
maximum polynomial degree correction (default is 10)
void CreateQSamplingDist(RooWorkspace *wks, const char *nominalName, const char *varName, const char *dataName, TH1F *, TH1F *, Int_t degree, Int_t nToys=500)
Create sampling distribution for q given degree-1 vs. degree corrections.
Persistable container for RooFit projects.
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
RooAbsData * data(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
1-D histogram with a float per channel (see TH1 documentation)
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
RooCmdArg Hesse(bool flag=true)
RooCmdArg Save(bool flag=true)
RooCmdArg Minos(bool flag=true)
RooCmdArg PrintLevel(Int_t code)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Namespace for the RooStats classes.
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...