Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooJeffreysPrior.cxx
Go to the documentation of this file.
1/** \class RooJeffreysPrior
2\ingroup Roofit
3
4Implementation of Jeffrey's prior. This class estimates the fisher information matrix by generating
5a binned Asimov dataset from the supplied PDFs, fitting it, retrieving the covariance matrix and inverting
6it. It returns the square root of the determinant of this matrix.
7Numerical integration is used to normalise. Since each integration step requires fits to be run,
8evaluating complicated PDFs may take long.
9
10Check the tutorial rs302_JeffreysPriorDemo.C for a demonstration with a simple PDF.
11**/
12
13#include "RooJeffreysPrior.h"
14
15#include "RooAbsPdf.h"
16#include "RooErrorHandler.h"
17#include "RooArgSet.h"
18#include "RooMsgService.h"
19#include "RooFitResult.h"
20#include "TMatrixDSym.h"
21#include "RooDataHist.h"
22#include "RooNumIntConfig.h"
23#include "RooRealVar.h"
24#include "RooHelpers.h"
25
27
28using namespace RooFit;
29
30////////////////////////////////////////////////////////////////////////////////
31/// Construct a new JeffreysPrior.
32/// \param[in] name Name of this object.
33/// \param[in] title Title (for plotting)
34/// \param[in] nominal The PDF to base Jeffrey's prior on.
35/// \param[in] paramSet Parameters of the PDF.
36/// \param[in] obsSet Observables of the PDF.
37
38RooJeffreysPrior::RooJeffreysPrior(const char* name, const char* title,
39 RooAbsPdf& nominal,
40 const RooArgList& paramSet,
41 const RooArgList& obsSet) :
42 RooAbsPdf(name, title),
43 _nominal("nominal","nominal",this, nominal, false, false),
44 _obsSet("!obsSet","Observables",this, false, false),
45 _paramSet("!paramSet","Parameters",this),
46 _cacheMgr(this, 1, true, false)
47{
49 _paramSet.addTyped<RooAbsReal>(paramSet);
50
51 // use a different integrator by default.
52 if(paramSet.size()==1)
53 this->specialIntegratorConfig(true)->method1D().setLabel("RooAdaptiveGaussKronrodIntegrator1D") ;
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Copy constructor
58
60 RooAbsPdf(other, name),
61 _nominal("!nominal",this,other._nominal),
62 _obsSet("!obsSet",this,other._obsSet),
63 _paramSet("!paramSet",this,other._paramSet),
64 _cacheMgr(this, 1, true, false)
65{
66
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Calculate and return current value of self
71
73{
75
76
77 CacheElem* cacheElm = static_cast<CacheElem*>(_cacheMgr.getObj(nullptr));
78 if (!cacheElm) {
79 //Internally, we have to enlarge the range of fit parameters to make
80 //fits converge even if we are close to the limit of a parameter. Therefore, we clone the pdf and its
81 //observables here. If something happens to the external PDF, the cache is wiped,
82 //and we start to clone again.
83 auto& pdf = _nominal.arg();
84 RooAbsPdf* clonePdf = static_cast<RooAbsPdf*>(pdf.cloneTree());
85 std::unique_ptr<RooArgSet> vars{clonePdf->getParameters(_obsSet)};
86 for (auto varTmp : *vars) {
87 auto& var = static_cast<RooRealVar&>(*varTmp);
88 auto range = var.getRange();
89 double span = range.second - range.first;
90 var.setRange(range.first - 0.1*span, range.second + 0.1 * span);
91 }
92
93 cacheElm = new CacheElem;
94 cacheElm->_pdf.reset(clonePdf);
95 cacheElm->_pdfVariables = std::move(vars);
96
97 _cacheMgr.setObj(nullptr, cacheElm);
98 }
99
100 auto& cachedPdf = *cacheElm->_pdf;
101 auto& pdfVars = *cacheElm->_pdfVariables;
102 pdfVars.assign(_paramSet);
103
104 std::unique_ptr<RooDataHist> data( cachedPdf.generateBinned(_obsSet,ExpectedData()) );
105 std::unique_ptr<RooFitResult> res( cachedPdf.fitTo(*data, Save(),PrintLevel(-1),Minos(false),SumW2Error(false)) );
106 TMatrixDSym cov = res->covarianceMatrix();
107 cov.Invert();
108
109 return sqrt(cov.Determinant());
110}
111
#define ClassImp(name)
Definition Rtypes.h:382
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition TGX11.cxx:110
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Storage_t::size_type size() const
bool addTyped(const RooAbsCollection &list, bool silent=false)
Adds elements of a given RooAbsCollection to the container if they match the specified type.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
std::pair< double, double > getRange(const char *name=nullptr) const
Get low and high bound of the variable.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=nullptr)
Setter function without integration set.
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=nullptr, const TNamed *isetRangeName=nullptr)
Getter function without integration set.
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Switches the message service to a different level while the instance is alive.
Definition RooHelpers.h:37
Implementation of Jeffrey's prior.
RooTemplateProxy< RooAbsPdf > _nominal
double evaluate() const override
Calculate and return current value of self.
RooObjCacheManager _cacheMgr
RooListProxy _obsSet
RooListProxy _paramSet
RooCategory & method1D()
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Double_t Determinant() const override
TMatrixTSym< Element > & Invert(Double_t *det=nullptr)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
RooCmdArg Save(bool flag=true)
RooCmdArg SumW2Error(bool flag)
RooCmdArg Minos(bool flag=true)
RooCmdArg PrintLevel(Int_t code)
RooCmdArg ExpectedData(bool flag=true)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
std::unique_ptr< RooAbsPdf > _pdf
std::unique_ptr< RooArgSet > _pdfVariables