Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ProposalHelper.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Authors: Kevin Belasco 7/22/2009
3// Authors: Kyle Cranmer 7/22/2009
4/*************************************************************************
5 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class RooStats::ProposalHelper
13 \ingroup Roostats
14*/
15
16#include "Rtypes.h"
20#include "RooArgSet.h"
21#include "RooDataSet.h"
22#include "RooAbsPdf.h"
23#include "RooAddPdf.h"
24#include "RooNDKeysPdf.h"
25#include "RooUniform.h"
26#include "RooMsgService.h"
27#include "RooRealVar.h"
28#include "RooMultiVarGaussian.h"
29#include "RooConstVar.h"
30#include "TString.h"
31
32#include <map>
33
34namespace RooStats {
35 class ProposalFunction;
36}
37
39
40using namespace RooFit;
41using namespace RooStats;
42using namespace std;
43
44//static const double DEFAULT_UNI_FRAC = 0.10;
45static const double DEFAULT_CLUES_FRAC = 0.20;
46//static const double SIGMA_RANGE_DIVISOR = 6;
47static const double SIGMA_RANGE_DIVISOR = 5;
48//static const Int_t DEFAULT_CACHE_SIZE = 100;
49//static const Option_t* CLUES_OPTIONS = "a";
50
51////////////////////////////////////////////////////////////////////////////////
52
54{
55 fPdfProp = new PdfProposal();
56 fVars = nullptr;
57 fOwnsPdfProp = true;
58 fOwnsPdf = false;
59 fOwnsCluesPdf = false;
60 fOwnsVars = false;
61 fUseUpdates = false;
62 fPdf = nullptr;
64 fCluesPdf = nullptr;
65 fUniformPdf = nullptr;
66 fClues = nullptr;
67 fCovMatrix = nullptr;
68 fCluesFrac = -1;
69 fUniFrac = -1;
70 fCacheSize = -1;
71 fCluesOptions = nullptr;
72}
73
74////////////////////////////////////////////////////////////////////////////////
75
77{
78 if (fPdf == nullptr)
79 CreatePdf();
80 RooArgList components;
81 RooArgList coeffs;
82 if (fCluesPdf == nullptr)
84 if (fCluesPdf != nullptr) {
85 if (fCluesFrac < 0)
87 printf("added clues from dataset %s with fraction %g\n",
89 components.add(*fCluesPdf);
90 coeffs.add(RooConst(fCluesFrac));
91 }
92 if (fUniFrac > 0.) {
94 components.add(*fUniformPdf);
95 coeffs.add(RooConst(fUniFrac));
96 }
97 components.add(*fPdf);
98 RooAddPdf* addPdf = new RooAddPdf("proposalFunction", "Proposal Density",
99 components, coeffs);
100 fPdfProp->SetPdf(*addPdf);
101 fPdfProp->SetOwnsPdf(true);
102 if (fCacheSize > 0)
104 fOwnsPdfProp = false;
105 return fPdfProp;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109
111{
112 if (fVars == nullptr) {
113 coutE(InputArguments) << "ProposalHelper::CreatePdf(): " <<
114 "Variables to create proposal function for are not set." << endl;
115 return;
116 }
117 RooArgList xVec{};
118 RooArgList muVec{};
119 RooRealVar* clone;
120 for (auto *r : static_range_cast<RooRealVar *> (*fVars)){
121 xVec.add(*r);
122 TString cloneName = TString::Format("%s%s", "mu__", r->GetName());
123 clone = static_cast<RooRealVar*>(r->clone(cloneName.Data()));
124 muVec.add(*clone);
125 if (fUseUpdates)
126 fPdfProp->AddMapping(*clone, *r);
127 }
128 if (fCovMatrix == nullptr)
129 CreateCovMatrix(xVec);
130 fPdf = new RooMultiVarGaussian("mvg", "MVG Proposal", xVec, muVec,
131 *fCovMatrix);
132}
133
134////////////////////////////////////////////////////////////////////////////////
135
137{
138 Int_t size = xVec.getSize();
140 RooRealVar* r;
141 for (Int_t i = 0; i < size; i++) {
142 r = (RooRealVar*)xVec.at(i);
143 double range = r->getMax() - r->getMin();
144 (*fCovMatrix)(i,i) = range / fSigmaRangeDivisor;
145 }
146}
147
148////////////////////////////////////////////////////////////////////////////////
149
151{
152 if (fClues != nullptr) {
153 if (fCluesOptions == nullptr)
154 fCluesPdf = new RooNDKeysPdf("cluesPdf", "Clues PDF", *fVars, *fClues);
155 else
156 fCluesPdf = new RooNDKeysPdf("cluesPdf", "Clues PDF", *fVars, *fClues,
158 }
159}
160
161////////////////////////////////////////////////////////////////////////////////
162
164{
165 fUniformPdf = new RooUniform("uniform", "Uniform Proposal PDF",
166 RooArgSet(*fVars));
167}
static const double SIGMA_RANGE_DIVISOR
static const double DEFAULT_CLUES_FRAC
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
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 r
TMatrixTSym< Double_t > TMatrixDSym
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:34
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Multivariate Gaussian p.d.f.
Generic N-dimensional implementation of a kernel estimation p.d.f.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
PdfProposal is a concrete implementation of the ProposalFunction interface.
Definition PdfProposal.h:30
virtual void AddMapping(RooRealVar &proposalParam, RooAbsReal &update)
specify a mapping between a parameter of the proposal function and a parameter of interest.
virtual void SetCacheSize(Int_t size)
Set how many points to generate each time we propose from a new point Default (and minimum) is 1.
Definition PdfProposal.h:80
virtual void SetOwnsPdf(bool ownsPdf)
set whether we own the PDF that serves as the proposal density function By default,...
Definition PdfProposal.h:91
virtual void SetPdf(RooAbsPdf &pdf)
Set the PDF to be the proposal density function.
Definition PdfProposal.h:49
ProposalFunction is an interface for all proposal functions that would be used with a Markov Chain Mo...
double fUniFrac
what fraction of the PDF integral is uniform
RooDataSet * fClues
data set of clues
bool fOwnsCluesPdf
whether we created (and own) the clues pdf
bool fUseUpdates
whether to set updates for proposal params in PdfProposal
void CreateCovMatrix(RooArgList &xVec)
bool fOwnsVars
whether we own fVars
double fCluesFrac
what fraction of the PDF integral comes from clues
virtual ProposalFunction * GetProposalFunction()
Get the ProposalFunction that we've been designing.
const Option_t * fCluesOptions
option string for clues RooNDKeysPdf
RooAbsPdf * fPdf
the main proposal density function
bool fOwnsPdfProp
whether we own the PdfProposal; equivalent to:
Int_t fCacheSize
for generating proposals from PDFs
RooAbsPdf * fUniformPdf
uniform proposal dens. func.
RooArgList * fVars
the RooRealVars to generate proposals for
TMatrixDSym * fCovMatrix
covariance matrix for multi var gaussian pdf
PdfProposal * fPdfProp
the PdfProposal we are (probably) going to return
double fSigmaRangeDivisor
range divisor to get sigma for each variable
RooAbsPdf * fCluesPdf
proposal dens. func. with clues for certain points
bool fOwnsPdf
whether we created (and own) the main pdf
Flat p.d.f.
Definition RooUniform.h:24
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:380
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2356
RooConstVar & RooConst(double val)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition Common.h:18
@ InputArguments
Namespace for the RooStats classes.
Definition Asimov.h:19