187struct CompareDataHistBins {
188 CompareDataHistBins(
RooDataHist* hist) : fDataHist(hist) {}
190 fDataHist->get(bin1);
192 fDataHist->get(bin2);
199struct CompareSparseHistBins {
200 CompareSparseHistBins(
THnSparse* hist) : fSparseHist(hist) {}
202 Double_t n1 = fSparseHist->GetBinContent(bin1);
203 Double_t n2 = fSparseHist->GetBinContent(bin2);
209struct CompareVectorIndices {
211 fChain(chain), fParam(param) {}
213 Double_t xi = fChain->Get(i)->getRealValue(fParam->GetName());
214 Double_t xj = fChain->Get(j)->getRealValue(fParam->GetName());
252 x[i] =
fAxes[i]->getVal();
282 <<
"Interval type not set. Returning false." << endl;
323 "number of variables in axes (" << size <<
324 ") doesn't match number of parameters ("
328 for (
Int_t i = 0; i < size; i++)
341 <<
"parameters have not been set." << endl;
347 "MCMCInterval::CreateKeysPdf: creation of Keys PDF failed: " <<
348 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
349 "in Markov chain." << endl;
381 coutE(
Eval) <<
"* Error in MCMCInterval::CreateHist(): " <<
382 "Crucial data member was NULL." << endl;
383 coutE(
Eval) <<
"Make sure to fully construct/initialize." << endl;
391 "MCMCInterval::CreateHist: creation of histogram failed: " <<
392 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
393 "in Markov chain." << endl;
399 fHist =
new TH1F(
"posterior",
"MCMC Posterior Histogram",
403 fHist =
new TH2F(
"posterior",
"MCMC Posterior Histogram",
408 fHist =
new TH3F(
"posterior",
"MCMC Posterior Histogram",
414 coutE(
Eval) <<
"* Error in MCMCInterval::CreateHist() : " <<
415 "TH1* couldn't handle dimension: " <<
fDimension << endl;
452 <<
"Crucial data member was NULL." << endl;
482 "MCMCInterval::CreateSparseHist: creation of histogram failed: " <<
483 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
484 "in Markov chain." << endl;
505 coutE(
Eval) <<
"* Error in MCMCInterval::CreateDataHist(): " <<
506 "Crucial data member was NULL or empty." << endl;
507 coutE(
Eval) <<
"Make sure to fully construct/initialize." << endl;
513 "MCMCInterval::CreateDataHist: creation of histogram failed: " <<
514 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
515 "in Markov chain." << endl;
533 "Crucial data member (Markov chain) was NULL." << endl;
541 "MCMCInterval::CreateVector: creation of vector failed: " <<
542 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
543 "in Markov chain." << endl;
551 for (i = 0; i < size; i++) {
558 CompareVectorIndices(
fChain, param));
574 while ((obj = it->
Next()) != NULL) {
578 coutE(
Eval) <<
"* Error in MCMCInterval::SetParameters: " <<
579 obj->
GetName() <<
" not a RooRealVar*" << std::endl;
598 "Error: Interval type not set" << endl;
617 if (fLeftSideTF < 0 || fLeftSideTF > 1) {
619 <<
"Fraction must be in the range [0, 1]. "
626 <<
"Error: Can only find a tail-fraction interval for 1-D intervals"
633 <<
"Crucial data member was NULL." << endl;
685 if (
TMath::Abs(leftTailSum + w - leftTailCutoff) <
700 if (
TMath::Abs(rightTailSum + w - rightTailCutoff) <
741 coutW(
Eval) <<
"Warning: Integral of Keys PDF came out to " << full
742 <<
" instead of expected value 1. Will continue using this "
743 <<
"factor to normalize further integrals of this PDF." << endl;
779 bottomCutoff = topCutoff / 2.0;
800 topCutoff = bottomCutoff * 2.0;
804 coutI(
Eval) <<
"range set: [" << bottomCutoff <<
", " << topCutoff <<
"]"
807 cutoff = (topCutoff + bottomCutoff) / 2.0;
819 bottomCutoff = cutoff;
822 cutoff = (topCutoff + bottomCutoff) / 2.0;
823 coutI(
Eval) <<
"cutoff range: [" << bottomCutoff <<
", "
824 << topCutoff <<
"]" << endl;
859 std::vector<Long_t> bins(numBins);
860 for (
Int_t ibin = 0; ibin < numBins; ibin++)
861 bins[ibin] = (
Long_t)ibin;
862 std::stable_sort(bins.begin(), bins.end(), CompareSparseHistBins(
fSparseHist));
869 for (i = numBins - 1; i >= 0; i--) {
887 for ( ; i >= 0; i--) {
896 for ( ; i < numBins; i++) {
903 if (i == numBins - 1)
929 std::vector<Int_t> bins(numBins);
930 for (
Int_t ibin = 0; ibin < numBins; ibin++)
932 std::stable_sort(bins.begin(), bins.end(), CompareDataHistBins(
fDataHist));
938 for (i = numBins - 1; i >= 0; i--) {
957 for ( ; i >= 0; i--) {
967 for ( ; i < numBins; i++) {
975 if (i == numBins - 1)
998 <<
"not implemented for this type of interval. Returning 0." << endl;
1014 "Error: Interval type not set" << endl;
1030 "Error: Interval type not set" << endl;
1107 <<
"Sorry, will not compute lower limit unless dimension == 1" << endl;
1115 coutE(
Eval) <<
"In MCMCInterval::LowerLimitBySparseHist: "
1116 <<
"couldn't determine cutoff. Check that num burn in steps < num "
1117 <<
"steps in the Markov chain. Returning param.getMin()." << endl;
1127 for (
Long_t i = 0; i < numBins; i++) {
1130 if (val < lowerLimit)
1151 coutE(
Eval) <<
"In MCMCInterval::LowerLimitByDataHist: "
1152 <<
"couldn't determine cutoff. Check that num burn in steps < num "
1153 <<
"steps in the Markov chain. Returning param.getMin()." << endl;
1162 for (
Int_t i = 0; i < numBins; i++) {
1166 if (val < lowerLimit)
1184 <<
"Sorry, will not compute upper limit unless dimension == 1" << endl;
1192 coutE(
Eval) <<
"In MCMCInterval::UpperLimitBySparseHist: "
1193 <<
"couldn't determine cutoff. Check that num burn in steps < num "
1194 <<
"steps in the Markov chain. Returning param.getMax()." << endl;
1204 for (
Long_t i = 0; i < numBins; i++) {
1207 if (val > upperLimit)
1228 coutE(
Eval) <<
"In MCMCInterval::UpperLimitByDataHist: "
1229 <<
"couldn't determine cutoff. Check that num burn in steps < num "
1230 <<
"steps in the Markov chain. Returning param.getMax()." << endl;
1239 for (
Int_t i = 0; i < numBins; i++) {
1243 if (val > upperLimit)
1267 coutE(
Eval) <<
"in MCMCInterval::LowerLimitByKeys(): "
1268 <<
"couldn't find lower limit, check that the number of burn in "
1269 <<
"steps < number of total steps in the Markov chain. Returning "
1270 <<
"param.getMin()" << endl;
1279 for (
Int_t i = 0; i < numBins; i++) {
1283 if (val < lowerLimit)
1307 coutE(
Eval) <<
"in MCMCInterval::UpperLimitByKeys(): "
1308 <<
"couldn't find upper limit, check that the number of burn in "
1309 <<
"steps < number of total steps in the Markov chain. Returning "
1310 <<
"param.getMax()" << endl;
1319 for (
Int_t i = 0; i < numBins; i++) {
1323 if (val > upperLimit)
1346 coutE(
Eval) <<
"in MCMCInterval::KeysMax(): "
1347 <<
"couldn't find Keys max value, check that the number of burn in "
1348 <<
"steps < number of total steps in the Markov chain. Returning 0"
1356 for (
Int_t i = 0; i < numBins; i++) {
1399 coutI(
Eval) <<
"cutoff = " << cutoff <<
", conf = " << confLevel << endl;
1411 <<
"confidence level not set " << endl;
1428 <<
"confidence level not set " << endl;
1445 <<
"confidence level not set " << endl;
1510 Bool_t tempChangeBinning =
true;
1512 if (!
fAxes[i]->getBinning(NULL,
false,
false).isUniform()) {
1513 tempChangeBinning =
false;
1522 tempChangeBinning =
false;
1524 if (tempChangeBinning) {
1536 "Keys PDF & Heaviside Product Data Hist",
fParameters);
1539 if (tempChangeBinning) {
1544 fAxes[i]->setBins(savedBins[i], NULL);
1558 coutE(
Eval) <<
"MCMCInterval: size is wrong, parameters don't match" << std::endl;
1562 coutE(
Eval) <<
"MCMCInterval: size is ok, but parameters don't match" << std::endl;
static const Double_t DEFAULT_DELTA
static const Double_t DEFAULT_EPSILON
THnSparseT< TArrayF > THnSparseF
TRObject operator()(const T1 &t1) const
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Int_t numBins() const
Return number of bins.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
virtual Int_t numBins(const char *rangeName=0) const
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
RooDataHist * fillDataHist(RooDataHist *hist, const RooArgSet *nset, Double_t scaleFactor, Bool_t correctForBinVolume=kFALSE, Bool_t showProgress=kFALSE) const
Fill a RooDataHist with values sampled from this function at the bin centers.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
The RooDataHist is a container class to hold N-dimensional binned data.
double weight(std::size_t i) const
Return weight of i-th bin.
Int_t getIndex(const RooArgSet &coord, Bool_t fast=false) const
Calculate bin number of the given coordinates.
Int_t numEntries() const override
Return the number of bins.
const RooArgSet * get() const override
Get bin centre of current bin.
Double_t sum(bool correctForBinSize, bool inverseCorr=false) const
Return the sum of the weights of all bins in the histogram.
RooDataSet is a container class to hold unbinned data.
Generic N-dimensional implementation of a kernel estimation p.d.f.
static Double_t infinity()
Return internal infinity representation.
A RooProduct represents the product of a given set of RooAbsReal objects.
RooRealVar represents a variable that can be changed from the outside.
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
ConfInterval is an interface class for a generic interval in the RooStats framework.
Represents the Heaviside function.
MCMCInterval is a concrete implementation of the RooStats::ConfInterval interface.
virtual void CreateDataHist()
virtual Double_t LowerLimitBySparseHist(RooRealVar ¶m)
determine lower limit using histogram
virtual void DetermineByDataHist()
virtual Double_t UpperLimitByKeys(RooRealVar ¶m)
determine upper limit in the shortest interval by using keys pdf
virtual void DetermineShortestInterval()
virtual void CreateVector(RooRealVar *param)
virtual Double_t UpperLimit(RooRealVar ¶m)
get the highest value of param that is within the confidence interval
virtual Bool_t IsInInterval(const RooArgSet &point) const
determine whether this point is in the confidence interval
Bool_t CheckParameters(const RooArgSet &point) const
check if parameters are correct. (dummy implementation to start)
virtual Double_t UpperLimitShortest(RooRealVar ¶m)
get the upper limit of param in the confidence interval Note that this works better for some distribu...
enum IntervalType fIntervalType
virtual Double_t UpperLimitBySparseHist(RooRealVar ¶m)
determine upper limit using histogram
virtual void SetAxes(RooArgList &axes)
Set which parameters go on which axis.
virtual void DetermineByKeys()
virtual void DetermineBySparseHist()
virtual TH1 * GetPosteriorHist()
set the number of bins to use (same for all axes, for now) virtual void SetNumBins(Int_t numBins);
virtual Double_t LowerLimitByKeys(RooRealVar ¶m)
determine lower limit in the shortest interval by using keys pdf
virtual Double_t GetHistCutoff()
get the cutoff bin height for being considered in the confidence interval
virtual Double_t UpperLimitTailFraction(RooRealVar ¶m)
determine upper limit of the lower confidence interval
MCMCInterval(const char *name=0)
default constructor
virtual void DetermineTailFractionInterval()
virtual void CreateSparseHist()
Double_t fConfidenceLevel
virtual void DetermineInterval()
Bool_t AcceptableConfLevel(Double_t confLevel)
virtual Double_t GetActualConfidenceLevel()
virtual Double_t GetKeysPdfCutoff() { return fKeysCutoff; }
virtual void SetConfidenceLevel(Double_t cl)
set the desired confidence level (see GetActualConfidenceLevel()) Note: calling this function trigger...
virtual Double_t LowerLimitShortest(RooRealVar ¶m)
get the lower limit of param in the shortest confidence interval Note that this works better for some...
virtual Double_t LowerLimit(RooRealVar ¶m)
get the lowest value of param that is within the confidence interval
virtual Double_t GetKeysPdfCutoff()
get the cutoff RooNDKeysPdf value for being considered in the confidence interval
std::vector< Int_t > fVector
virtual Double_t LowerLimitTailFraction(RooRealVar ¶m)
determine lower limit of the lower confidence interval
virtual RooProduct * GetPosteriorKeysProduct()
Get a clone of the (keyspdf * heaviside) product of the posterior.
virtual Double_t UpperLimitByHist(RooRealVar ¶m)
determine upper limit using histogram
virtual Double_t UpperLimitByDataHist(RooRealVar ¶m)
determine upper limit using histogram
virtual Double_t LowerLimitByHist(RooRealVar ¶m)
determine lower limit using histogram
virtual RooNDKeysPdf * GetPosteriorKeysPdf()
Get a clone of the keys pdf of the posterior.
virtual void CreateKeysPdf()
virtual Double_t LowerLimitByDataHist(RooRealVar ¶m)
determine lower limit using histogram
virtual void CreateHist()
RooDataHist * fKeysDataHist
virtual Double_t CalcConfLevel(Double_t cutoff, Double_t full)
virtual void DetermineByHist()
virtual void SetParameters(const RooArgSet ¶meters)
Set the parameters of interest for this interval and change other internal data members accordingly.
virtual void CreateKeysDataHist()
Double_t GetKeysMax()
Determine the approximate maximum value of the Keys PDF.
Bool_t WithinDeltaFraction(Double_t a, Double_t b)
virtual RooArgSet * GetParameters() const
return a set containing the parameters of this interval the caller owns the returned RooArgSet*
Stores the steps in a Markov Chain of points.
virtual Double_t Weight() const
get the weight of the current (last indexed) entry
virtual RooDataHist * GetAsDataHist(RooArgSet *whichVars=NULL) const
get this MarkovChain as a RooDataHist whose entries contain the values of whichVars.
virtual const RooArgSet * Get(Int_t i) const
get the entry at position i
virtual RooDataSet * GetAsDataSet(RooArgSet *whichVars=NULL) const
get this MarkovChain as a RooDataSet whose entries contain the values of whichVars.
virtual Int_t Size() const
get the number of steps in the chain
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
1-D histogram with a float per channel (see TH1 documentation)}
TH1 is the base class of all histogram classes in ROOT.
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
2-D histogram with a float per channel (see TH1 documentation)}
3-D histogram with a float per channel (see TH1 documentation)}
Long64_t Fill(const Double_t *x, Double_t w=1.)
TAxis * GetAxis(Int_t dim) const
Efficient multidimensional histogram.
Long64_t GetBin(const Int_t *idx) const
Double_t GetBinContent(const Int_t *idx) const
Forwards to THnBase::GetBinContent() overload.
void Sumw2()
Enable calculation of errors.
Long64_t GetNbins() const
Iterator abstract base class.
virtual TObject * Next()=0
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
RooCmdArg NormSet(const RooArgSet &nset)
RooCmdArg SelectVars(const RooArgSet &vars)
RooCmdArg EventRange(Int_t nStart, Int_t nStop)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
static uint64_t sum(uint64_t i)