15#ifdef XROOFIT_USE_PRAGMA_ONCE
18#if !defined(XROOFIT_XROONLLVAR_H) || defined(XROOFIT_USE_PRAGMA_ONCE)
19#ifndef XROOFIT_USE_PRAGMA_ONCE
20#define XROOFIT_XROONLLVAR_H
52class HypoTestInverterResult;
64 double value()
const {
return std::pair<double, double>::first; }
65 double error()
const {
return std::pair<double, double>::second; }
73 xRooNLLVar(
const std::shared_ptr<RooAbsPdf> &pdf,
const std::shared_ptr<RooAbsData> &
data,
75 xRooNLLVar(
const std::shared_ptr<RooAbsPdf> &pdf,
76 const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &
data,
90 std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
92 std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
93 generate(
bool expected =
false,
int seed = 0);
100 const std::shared_ptr<xRooNLLVar> &nll =
nullptr);
106 std::shared_ptr<xRooNLLVar>
nll()
const {
return fNll; }
111 ?
RooArgList(*std::unique_ptr<RooAbsCollection>(get()->floatParsFinal().selectByAttrib(
"poi",
true)))
117 xRooFitResult cfit(
const char *poiValues,
const char *alias =
nullptr);
121 double impact(
const char *poi,
const char *
np,
bool up =
true,
bool prefit =
false,
bool approx =
false);
122 double impact(
const char *
np,
bool up =
true,
bool prefit =
false,
bool approx =
false)
125 if (_poi.size() != 1)
126 throw std::runtime_error(
"xRooFitResult::impact: not one POI");
127 return impact(poi().contentsString().c_str(),
np, up, prefit, approx);
133 double conditionalError(
const char *poi,
const char *nps,
bool up =
true,
bool approx =
false);
138 RooArgList ranknp(
const char *poi,
bool up =
true,
bool prefit =
false,
139 double approxThreshold = std::numeric_limits<double>::infinity());
142 ranknp(
bool up =
true,
bool prefit =
false,
double approxThreshold = std::numeric_limits<double>::infinity())
145 if (_poi.size() != 1)
146 throw std::runtime_error(
"xRooFitResult::ranknp: not one POI");
147 return ranknp(poi().contentsString().c_str(), up, prefit, approxThreshold);
151 std::shared_ptr<xRooNLLVar>
fNll;
153 std::shared_ptr<std::map<std::string, xRooFitResult>>
fCfits;
156 xRooFitResult minimize(
const std::shared_ptr<ROOT::Fit::FitConfig> & =
nullptr);
158 void SetFitConfig(
const std::shared_ptr<ROOT::Fit::FitConfig> &in) { fFitConfig = in; }
159 std::shared_ptr<ROOT::Fit::FitConfig> fitConfig();
166 void Print(
Option_t *opt =
"")
const override;
175 std::shared_ptr<const RooFitResult> ufit(
bool readOnly =
false);
176 std::shared_ptr<const RooFitResult> cfit_null(
bool readOnly =
false);
177 std::shared_ptr<const RooFitResult> cfit_alt(
bool readOnly =
false);
178 std::shared_ptr<const RooFitResult> cfit_lbound(
bool readOnly =
false);
179 std::shared_ptr<const RooFitResult>
gfit() {
return fGenFit; }
181 std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
fData;
182 std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
data();
187 xValueWithError pNull_asymp(
double nSigma = std::numeric_limits<double>::quiet_NaN());
188 xValueWithError pAlt_asymp(
double nSigma = std::numeric_limits<double>::quiet_NaN());
189 xValueWithError pCLs_asymp(
double nSigma = std::numeric_limits<double>::quiet_NaN());
190 xValueWithError ts_asymp(
double nSigma = std::numeric_limits<double>::quiet_NaN());
192 xValueWithError pNull_toys(
double nSigma = std::numeric_limits<double>::quiet_NaN());
193 xValueWithError pAlt_toys(
double nSigma = std::numeric_limits<double>::quiet_NaN());
196 if (fNullVal() == fAltVal())
197 return std::pair<double, double>(1, 0);
198 auto null = pNull_toys(nSigma);
199 auto alt = pAlt_toys(nSigma);
200 double nom = (null.first == 0) ? 0 : null.first / alt.first;
207 return std::pair<double, double>(nom, (alt.first - alt.second <= 0)
208 ? std::numeric_limits<double>::infinity()
209 : (sqrt(pow(null.second, 2) + pow(alt.second * nom, 2)) / alt.first));
212 xValueWithError ts_toys(
double nSigma = std::numeric_limits<double>::quiet_NaN());
221 addNullToys(
int nToys = 1,
int seed = 0,
double target = std::numeric_limits<double>::quiet_NaN(),
222 double target_nSigma = std::numeric_limits<double>::quiet_NaN());
224 addAltToys(
int nToys = 1,
int seed = 0,
double target = std::numeric_limits<double>::quiet_NaN(),
225 double target_nSigma = std::numeric_limits<double>::quiet_NaN());
227 addCLsToys(
int nToys = 1,
int seed = 0,
double target = std::numeric_limits<double>::quiet_NaN(),
228 double target_nSigma = std::numeric_limits<double>::quiet_NaN());
234 std::shared_ptr<xRooHypoPoint>
235 asimov(
bool readOnly =
239 const char *fPOIName();
245 void setNullVal(
double val);
246 void setAltVal(
double val);
251 fPllType = xRooFit::Asymptotics::Unknown;
255 fPllType = xRooFit::Asymptotics::Unknown;
256 nullToys.emplace_back(std::make_tuple(seed,
value, weight));
260 fPllType = xRooFit::Asymptotics::Unknown;
261 altToys.emplace_back(std::make_tuple(seed,
value, weight));
264 std::shared_ptr<const RooAbsCollection>
coords;
266 std::shared_ptr<const RooFitResult> fUfit, fNull_cfit,
fAlt_cfit, fLbound_cfit;
268 bool isExpected =
false;
269 double obs_ts = std::numeric_limits<double>::quiet_NaN();
270 double obs_ts_err = std::numeric_limits<double>::quiet_NaN();
272 std::shared_ptr<xRooHypoPoint>
276 std::vector<std::tuple<int, double, double>>
nullToys;
278 std::vector<std::tuple<int, double, double>>
altToys;
280 std::shared_ptr<xRooNLLVar> nllVar =
nullptr;
281 std::shared_ptr<RooStats::HypoTestResult> hypoTestResult =
nullptr;
282 std::shared_ptr<const RooFitResult> retrieveFit(
int type);
284 TString tsTitle(
bool inWords =
false)
const;
287 xValueWithError pX_toys(
bool alt,
double nSigma = std::numeric_limits<double>::quiet_NaN());
288 size_t addToys(
bool alt,
int nToys,
int initialSeed = 0,
double target = std::numeric_limits<double>::quiet_NaN(),
289 double target_nSigma = std::numeric_limits<double>::quiet_NaN(),
bool targetCLs =
false,
290 double relErrThreshold = 2.,
size_t maxToys = 10000);
295 double alt_value = std::numeric_limits<double>::quiet_NaN(),
300 xRooHypoPoint hypoPoint(
double value,
double alt_value = std::numeric_limits<double>::quiet_NaN(),
307 public std::vector<xRooHypoPoint> {
313 bool AddModel(
const xRooNode &pdf,
const char *validity =
"");
319 int AddPoints(
const char *parName,
size_t nPoints,
double low,
double high);
321 void Print(
Option_t *opt =
"")
const override;
326 std::shared_ptr<RooArgSet>
pars()
const {
return fPars; };
340 std::shared_ptr<TGraphErrors> graph(
const char *opt)
const;
343 std::shared_ptr<TMultiGraph> graphs(
const char *opt);
346 xValueWithError findlimit(
const char *opt,
double relUncert = std::numeric_limits<double>::infinity(),
347 unsigned int maxTries = 20);
350 xValueWithError limit(
const char *
type =
"cls",
double nSigma = std::numeric_limits<double>::quiet_NaN())
const;
351 int scan(
const char *
type,
size_t nPoints,
double low = std::numeric_limits<double>::quiet_NaN(),
352 double high = std::numeric_limits<double>::quiet_NaN(),
353 const std::vector<double> &nSigmas = {0, 1, 2, -1, -2, std::numeric_limits<double>::quiet_NaN()},
354 double relUncert = 0.1);
356 const std::vector<double> &nSigmas = {0, 1, 2, -1, -2, std::numeric_limits<double>::quiet_NaN()},
357 double relUncert = 0.1)
359 return scan(
type, 0, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
362 int scan(
const char *
type,
double nSigma,
double relUncert = 0.1)
364 return scan(
type, std::vector<double>{nSigma}, relUncert);
369 std::map<std::string, xValueWithError>
370 limits(
const char *opt =
"cls",
371 const std::vector<double> &nSigmas = {0, 1, 2, -1, -2, std::numeric_limits<double>::quiet_NaN()},
372 double relUncert = std::numeric_limits<double>::infinity());
375 std::shared_ptr<xRooNode> pdf(
const char *parValues =
"")
const;
384 static xValueWithError GetLimit(
const TGraph &pValues,
double target = std::numeric_limits<double>::quiet_NaN());
391 std::map<std::shared_ptr<xRooNode>, std::shared_ptr<xRooNLLVar>>
fNlls;
393 std::set<std::pair<std::shared_ptr<RooArgList>, std::shared_ptr<xRooNode>>>
fPdfs;
398 xRooHypoSpace hypoSpace(
const char *parName,
int nPoints,
double low,
double high,
399 double alt_value = std::numeric_limits<double>::quiet_NaN(),
404 double alt_value = std::numeric_limits<double>::quiet_NaN());
405 xRooHypoSpace hypoSpace(
int nPoints,
double low,
double high,
406 double alt_value = std::numeric_limits<double>::quiet_NaN(),
409 double low = std::numeric_limits<double>::quiet_NaN(),
410 double high = std::numeric_limits<double>::quiet_NaN(),
411 double alt_value = std::numeric_limits<double>::quiet_NaN())
413 return hypoSpace(parName, nPoints, low, high, alt_value, xRooFit::Asymptotics::Unknown, tsType);
416 std::shared_ptr<RooArgSet> pars(
bool stripGlobalObs =
true)
const;
420 TObject *Scan(
const RooArgList &scanPars,
const std::vector<std::vector<double>> &coords,
422 TObject *Scan(
const char *scanPars,
const std::vector<std::vector<double>> &coords,
424 TObject *
Scan(
const char *scanPars,
size_t nPoints,
double low,
double high,
size_t nPointsY,
double ylow,
427 std::vector<std::vector<double>> coords;
429 double step = (high - low) / (nPoints);
430 for (
size_t i = 0; i < nPoints; i++) {
431 std::vector<double> coord({low + step * i});
433 double stepy = (yhigh - ylow) / (nPointsY);
434 for (
size_t j = 0; j < nPointsY; j++) {
435 coord.push_back({ylow + stepy * j});
436 coords.push_back(coord);
440 coords.push_back(coord);
444 return Scan(scanPars, coords, profilePars);
449 return Scan(scanPars, nPoints, low, high, 0, 0, 0, profilePars);
452 std::shared_ptr<RooAbsReal> func()
const;
453 std::shared_ptr<RooAbsPdf>
pdf()
const {
return fPdf; }
466 double mainTermVal()
const;
467 double constraintTermVal()
const;
469 double getEntryVal(
size_t entry)
const;
470 double extendedTermVal()
const;
471 double simTermVal()
const;
472 double binnedDataTermVal()
const;
473 double getEntryBinWidth(
size_t entry)
const;
476 double saturatedVal()
const;
479 return saturatedConstraintTermVal();
481 double saturatedConstraintTermVal()
const;
482 [[deprecated(
"Use saturatedMainTermVal()")]]
double saturatedMainTerm()
const {
return saturatedMainTermVal(); }
483 double saturatedMainTermVal()
const;
485 double mainTermPgof()
const;
486 double mainTermNdof()
const;
488 std::set<std::string> binnedChannels()
const;
491 bool setData(
const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &_data);
492 bool setData(
const std::shared_ptr<RooAbsData> &
data,
const std::shared_ptr<const RooAbsCollection> &globs)
494 return setData(std::make_pair(
data, globs));
500 std::shared_ptr<RooAbsPdf>
fPdf;
502 std::shared_ptr<const RooAbsCollection>
fGlobs;
504 std::shared_ptr<RooLinkedList>
fOpts;
512 bool kReuseNLL =
true;
519std::string printValue(
const XROOFIT_NAMESPACE_NAME::xRooNLLVar::xValueWithError *val);
520std::string printValue(
const std::map<std::string, XROOFIT_NAMESPACE_NAME::xRooNLLVar::xValueWithError> *
m);
const char Option_t
Option string (const char)
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
double impact(const char *poi, const char *np, bool up=true, bool prefit=false, bool approx=false)
std::shared_ptr< xRooNLLVar > fNll
RooArgList ranknp(bool up=true, bool prefit=false, double approxThreshold=std::numeric_limits< double >::infinity())
std::shared_ptr< xRooNLLVar > nll() const
std::shared_ptr< xRooNode > fNode
double impact(const char *np, bool up=true, bool prefit=false, bool approx=false)
std::shared_ptr< std::map< std::string, xRooFitResult > > fCfits
std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > fData
std::vector< std::tuple< int, double, double > > altToys
std::shared_ptr< const RooAbsCollection > coords
void addNullToy(double value, double weight=1., int seed=0)
std::vector< std::tuple< int, double, double > > nullToys
void setObsTS(double val, double err)
std::shared_ptr< const RooFitResult > fAlt_cfit
std::shared_ptr< const RooFitResult > fGenFit
void addAltToy(double value, double weight=1., int seed=0)
static std::set< int > allowedStatusCodes
std::shared_ptr< xRooHypoPoint > fAsimov
xValueWithError pCLs_toys(double nSigma=std::numeric_limits< double >::quiet_NaN())
std::shared_ptr< const RooFitResult > gfit()
std::shared_ptr< RooArgSet > pars() const
xRooHypoPoint & point(size_t i)
int scan(const char *type="cls", const std::vector< double > &nSigmas={0, 1, 2, -1, -2, std::numeric_limits< double >::quiet_NaN()}, double relUncert=0.1)
TDirectory * fitCache() const
std::map< std::shared_ptr< xRooNode >, std::shared_ptr< xRooNLLVar > > fNlls
int scan(const char *type, double nSigma, double relUncert=0.1)
std::shared_ptr< RooArgSet > fPars
std::shared_ptr< TDirectory > fFitDb
std::set< std::pair< std::shared_ptr< RooArgList >, std::shared_ptr< xRooNode > > > fPdfs
This xRooNLLVar object has several special methods, e.g.
std::shared_ptr< RooAbsCollection > fFuncGlobs
double saturatedMainTerm() const
std::shared_ptr< const RooAbsCollection > fGlobs
bool setData(const std::shared_ptr< RooAbsData > &data, const std::shared_ptr< const RooAbsCollection > &globs)
xRooHypoPoint hypoPoint(const char *parValues, double alt_value, const xRooFit::Asymptotics::PLLType &pllType)
std::shared_ptr< RooLinkedList > fOpts
std::shared_ptr< ROOT::Fit::FitConfig > fFitConfig
void SetFitConfig(const std::shared_ptr< ROOT::Fit::FitConfig > &in)
xRooHypoSpace hypoSpace(const char *parName, xRooFit::TestStatistic::Type tsType, int nPoints=0, double low=std::numeric_limits< double >::quiet_NaN(), double high=std::numeric_limits< double >::quiet_NaN(), double alt_value=std::numeric_limits< double >::quiet_NaN())
std::shared_ptr< RooAbsCollection > fConstVars
std::shared_ptr< RooAbsPdf > pdf() const
void AddOption(const RooCmdArg &opt)
RooAbsReal * operator->() const
TObject * Scan(const char *scanPars, size_t nPoints, double low, double high, size_t nPointsY, double ylow, double yhigh, const RooArgList &profilePars=RooArgList())
const RooAbsCollection * globs() const
std::string fFuncCreationLog
std::shared_ptr< RooAbsCollection > fFuncVars
double saturatedConstraintTerm() const
std::shared_ptr< RooAbsData > fData
std::shared_ptr< RooAbsPdf > fPdf
TObject * Scan(const char *scanPars, size_t nPoints, double low, double high, const RooArgList &profilePars=RooArgList())
The xRooNode class is designed to wrap over a TObject and provide functionality to aid with interacti...
Generic interface for defining configuration options of a numerical algorithm.
Abstract container object that can hold multiple RooAbsArg objects.
Storage_t const & get() const
Const access to the underlying stl container.
Abstract base class for binned and unbinned datasets.
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value and implements functionality common to al...
RooArgList is a container object that can hold multiple RooAbsArg objects.
Named container for two doubles, two integers two object points and three string pointers that can be...
Calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent constraint function...
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
Variable that can be changed from the outside.
HypoTestInverterResult class holds the array of hypothesis test results and compute a confidence inte...
HypoTestResult is a base class for results from hypothesis tests.
Fill Area Attributes class.
Describe directory structure in memory.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
A TGraphErrors is a TGraph with error bars.
A TGraph is an object made of two arrays X and Y with npoints each.
A TMultiGraph is a collection of TGraph (or derived) objects.
The TNamed class is the base class for all named ROOT classes.
Mother of all ROOT objects.
Namespace for the RooStats classes.
#define BEGIN_XROOFIT_NAMESPACE
#define END_XROOFIT_NAMESPACE
xValueWithError(const std::pair< double, double > &in={0, 0})
std::string __repr__() const