100MCMCInterval::MCMCInterval(
const char*
name)
190struct CompareDataHistBins {
191 CompareDataHistBins(
RooDataHist* hist) : fDataHist(hist) {}
193 fDataHist->get(bin1);
195 fDataHist->get(bin2);
202struct CompareSparseHistBins {
203 CompareSparseHistBins(
THnSparse* hist) : fSparseHist(hist) {}
205 Double_t n1 = fSparseHist->GetBinContent(bin1);
206 Double_t n2 = fSparseHist->GetBinContent(bin2);
212struct CompareVectorIndices {
214 fChain(chain), fParam(param) {}
216 Double_t xi = fChain->Get(i)->getRealValue(fParam->GetName());
217 Double_t xj = fChain->Get(j)->getRealValue(fParam->GetName());
255 x[i] =
fAxes[i]->getVal();
285 <<
"Interval type not set. Returning false." << endl;
326 "number of variables in axes (" << size <<
327 ") doesn't match number of parameters ("
331 for (
Int_t i = 0; i < size; i++)
344 <<
"parameters have not been set." << endl;
350 "MCMCInterval::CreateKeysPdf: creation of Keys PDF failed: " <<
351 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
352 "in Markov chain." << endl;
384 coutE(
Eval) <<
"* Error in MCMCInterval::CreateHist(): " <<
385 "Crucial data member was NULL." << endl;
386 coutE(
Eval) <<
"Make sure to fully construct/initialize." << endl;
394 "MCMCInterval::CreateHist: creation of histogram failed: " <<
395 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
396 "in Markov chain." << endl;
402 fHist =
new TH1F(
"posterior",
"MCMC Posterior Histogram",
406 fHist =
new TH2F(
"posterior",
"MCMC Posterior Histogram",
411 fHist =
new TH3F(
"posterior",
"MCMC Posterior Histogram",
417 coutE(
Eval) <<
"* Error in MCMCInterval::CreateHist() : " <<
418 "TH1* couldn't handle dimension: " <<
fDimension << endl;
455 <<
"Crucial data member was NULL." << endl;
485 "MCMCInterval::CreateSparseHist: creation of histogram failed: " <<
486 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
487 "in Markov chain." << endl;
508 coutE(
Eval) <<
"* Error in MCMCInterval::CreateDataHist(): " <<
509 "Crucial data member was NULL or empty." << endl;
510 coutE(
Eval) <<
"Make sure to fully construct/initialize." << endl;
516 "MCMCInterval::CreateDataHist: creation of histogram failed: " <<
517 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
518 "in Markov chain." << endl;
536 "Crucial data member (Markov chain) was NULL." << endl;
544 "MCMCInterval::CreateVector: creation of vector failed: " <<
545 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
546 "in Markov chain." << endl;
554 for (i = 0; i < size; i++) {
561 CompareVectorIndices(
fChain, param));
577 while ((obj = it->
Next()) != NULL) {
581 coutE(
Eval) <<
"* Error in MCMCInterval::SetParameters: " <<
582 obj->
GetName() <<
" not a RooRealVar*" << std::endl;
601 "Error: Interval type not set" << endl;
620 if (fLeftSideTF < 0 || fLeftSideTF > 1) {
622 <<
"Fraction must be in the range [0, 1]. "
629 <<
"Error: Can only find a tail-fraction interval for 1-D intervals"
636 <<
"Crucial data member was NULL." << endl;
688 if (
TMath::Abs(leftTailSum + w - leftTailCutoff) <
703 if (
TMath::Abs(rightTailSum + w - rightTailCutoff) <
744 coutW(
Eval) <<
"Warning: Integral of Keys PDF came out to " << full
745 <<
" instead of expected value 1. Will continue using this "
746 <<
"factor to normalize further integrals of this PDF." << endl;
782 bottomCutoff = topCutoff / 2.0;
803 topCutoff = bottomCutoff * 2.0;
807 coutI(
Eval) <<
"range set: [" << bottomCutoff <<
", " << topCutoff <<
"]"
810 cutoff = (topCutoff + bottomCutoff) / 2.0;
822 bottomCutoff = cutoff;
825 cutoff = (topCutoff + bottomCutoff) / 2.0;
826 coutI(
Eval) <<
"cutoff range: [" << bottomCutoff <<
", "
827 << topCutoff <<
"]" << endl;
862 std::vector<Long_t> bins(numBins);
863 for (
Int_t ibin = 0; ibin < numBins; ibin++)
864 bins[ibin] = (
Long_t)ibin;
865 std::stable_sort(bins.begin(), bins.end(), CompareSparseHistBins(
fSparseHist));
872 for (i = numBins - 1; i >= 0; i--) {
890 for ( ; i >= 0; i--) {
899 for ( ; i < numBins; i++) {
906 if (i == numBins - 1)
932 std::vector<Int_t> bins(numBins);
933 for (
Int_t ibin = 0; ibin < numBins; ibin++)
935 std::stable_sort(bins.begin(), bins.end(), CompareDataHistBins(
fDataHist));
941 for (i = numBins - 1; i >= 0; i--) {
960 for ( ; i >= 0; i--) {
970 for ( ; i < numBins; i++) {
978 if (i == numBins - 1)
1001 <<
"not implemented for this type of interval. Returning 0." << endl;
1017 "Error: Interval type not set" << endl;
1033 "Error: Interval type not set" << endl;
1110 <<
"Sorry, will not compute lower limit unless dimension == 1" << endl;
1118 coutE(
Eval) <<
"In MCMCInterval::LowerLimitBySparseHist: "
1119 <<
"couldn't determine cutoff. Check that num burn in steps < num "
1120 <<
"steps in the Markov chain. Returning param.getMin()." << endl;
1130 for (
Long_t i = 0; i < numBins; i++) {
1133 if (val < lowerLimit)
1154 coutE(
Eval) <<
"In MCMCInterval::LowerLimitByDataHist: "
1155 <<
"couldn't determine cutoff. Check that num burn in steps < num "
1156 <<
"steps in the Markov chain. Returning param.getMin()." << endl;
1165 for (
Int_t i = 0; i < numBins; i++) {
1169 if (val < lowerLimit)
1187 <<
"Sorry, will not compute upper limit unless dimension == 1" << endl;
1195 coutE(
Eval) <<
"In MCMCInterval::UpperLimitBySparseHist: "
1196 <<
"couldn't determine cutoff. Check that num burn in steps < num "
1197 <<
"steps in the Markov chain. Returning param.getMax()." << endl;
1207 for (
Long_t i = 0; i < numBins; i++) {
1210 if (val > upperLimit)
1231 coutE(
Eval) <<
"In MCMCInterval::UpperLimitByDataHist: "
1232 <<
"couldn't determine cutoff. Check that num burn in steps < num "
1233 <<
"steps in the Markov chain. Returning param.getMax()." << endl;
1242 for (
Int_t i = 0; i < numBins; i++) {
1246 if (val > upperLimit)
1270 coutE(
Eval) <<
"in MCMCInterval::LowerLimitByKeys(): "
1271 <<
"couldn't find lower limit, check that the number of burn in "
1272 <<
"steps < number of total steps in the Markov chain. Returning "
1273 <<
"param.getMin()" << endl;
1282 for (
Int_t i = 0; i < numBins; i++) {
1286 if (val < lowerLimit)
1310 coutE(
Eval) <<
"in MCMCInterval::UpperLimitByKeys(): "
1311 <<
"couldn't find upper limit, check that the number of burn in "
1312 <<
"steps < number of total steps in the Markov chain. Returning "
1313 <<
"param.getMax()" << endl;
1322 for (
Int_t i = 0; i < numBins; i++) {
1326 if (val > upperLimit)
1349 coutE(
Eval) <<
"in MCMCInterval::KeysMax(): "
1350 <<
"couldn't find Keys max value, check that the number of burn in "
1351 <<
"steps < number of total steps in the Markov chain. Returning 0"
1359 for (
Int_t i = 0; i < numBins; i++) {
1402 coutI(
Eval) <<
"cutoff = " << cutoff <<
", conf = " << confLevel << endl;
1414 <<
"confidence level not set " << endl;
1431 <<
"confidence level not set " << endl;
1448 <<
"confidence level not set " << endl;
1513 Bool_t tempChangeBinning =
true;
1515 if (!
fAxes[i]->getBinning(NULL,
false,
false).isUniform()) {
1516 tempChangeBinning =
false;
1525 tempChangeBinning =
false;
1527 if (tempChangeBinning) {
1539 "Keys PDF & Heaviside Product Data Hist",
fParameters);
1542 if (tempChangeBinning) {
1547 fAxes[i]->setBins(savedBins[i], NULL);
1561 coutE(
Eval) <<
"MCMCInterval: size is wrong, parameters don't match" << std::endl;
1565 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.
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.
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
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.
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.
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
The RooDataHist is a container class to hold N-dimensional binned data.
Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const
Return the sum of the weights of all hist bins.
virtual Double_t weight() const
virtual Int_t numEntries() const
Return the number of bins.
Int_t getIndex(const RooArgSet &coord, Bool_t fast=kFALSE)
virtual const RooArgSet * get() const
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)}
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.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
RooCmdArg NormSet(const RooArgSet &nset)
RooCmdArg SelectVars(const RooArgSet &vars)
RooCmdArg EventRange(Int_t nStart, Int_t nStop)
Namespace for the RooStats classes.
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
static long int sum(long int i)