Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:45

0001 // @(#)root/roostats:$Id$
0002 // Authors: Kevin Belasco        7/22/2009
0003 // Authors: Kyle Cranmer         7/22/2009
0004 /*************************************************************************
0005  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef RooStats_ProposalHelper
0013 #define RooStats_ProposalHelper
0014 
0015 #include "Rtypes.h"
0016 #include "RooStats/ProposalFunction.h"
0017 #include "RooStats/UniformProposal.h"
0018 #include "RooStats/PdfProposal.h"
0019 #include "RooArgSet.h"
0020 #include "RooMsgService.h"
0021 #include "RooRealVar.h"
0022 #include "TMatrixDSym.h"
0023 #include "TObject.h"
0024 
0025 
0026 
0027 namespace RooStats {
0028 
0029    class ProposalHelper : public TObject {
0030 
0031    public:
0032       ProposalHelper();
0033 
0034       /// Set the PDF to be the proposal density function
0035       virtual void SetPdf(RooAbsPdf& pdf) { fPdf = &pdf; }
0036       /// Set the bank of clues to add to the current proposal density function
0037       virtual void SetClues(RooDataSet& clues) { fClues = &clues; }
0038 
0039       /// Get the ProposalFunction that we've been designing
0040       virtual ProposalFunction* GetProposalFunction();
0041 
0042       virtual void SetCacheSize(Int_t size)
0043       {
0044          if (size > 0) {
0045             fCacheSize = size;
0046          } else {
0047             coutE(Eval) << "Warning: Requested non-positive cache size: " << size << ". Cache size unchanged."
0048                         << std::endl;
0049          }
0050       }
0051 
0052       virtual void SetUpdateProposalParameters(bool updateParams)
0053       { fUseUpdates = updateParams; }
0054 
0055       virtual void SetVariables(RooArgList& vars)
0056       { fVars = &vars; }
0057 
0058       virtual void SetVariables(const RooArgList& vars)
0059       { fVars = new RooArgList(vars); fOwnsVars = true; }
0060 
0061       /// set what fraction of the proposal density function should come from
0062       /// a uniform proposal distribution
0063       virtual void SetUniformFraction(double uniFrac) { fUniFrac = uniFrac; }
0064 
0065       /// set what fraction of the proposal density function should come from
0066       /// the bank of clues
0067       virtual void SetCluesFraction(double cluesFrac) { fCluesFrac = cluesFrac; }
0068 
0069       /// set the covariance matrix to use for a multi-variate Gaussian proposal
0070       virtual void SetCovMatrix(const TMatrixDSym& covMatrix)
0071       { fCovMatrix = new TMatrixDSym(covMatrix); }
0072 
0073       /// set what divisor we will use when dividing the range of a variable to
0074       /// determine the width of the proposal function for each dimension
0075       /// e.g. divisor = 6 for sigma = 1/6th
0076       virtual void SetWidthRangeDivisor(double divisor)
0077       { if (divisor > 0.) fSigmaRangeDivisor = divisor; }
0078 
0079       /// set the option string to pass to the RooNDKeysPdf constructor
0080       /// if the bank of clues pdf is being automatically generated by this
0081       /// ProposalHelper
0082       virtual void SetCluesOptions(const Option_t* options)
0083       { if (options != nullptr) fCluesOptions = options; }
0084 
0085       virtual void SetVariables(RooArgSet& vars)
0086       {
0087          RooArgList* argList = new RooArgList(vars);
0088          SetVariables(*argList);
0089          fOwnsVars = true;
0090       }
0091 
0092       ~ProposalHelper() override
0093       {
0094          if (fOwnsPdfProp)      delete fPdfProp;
0095          if (fOwnsPdf)          delete fPdf;
0096          if (fOwnsCluesPdf)     delete fCluesPdf;
0097          if (fOwnsVars)         delete fVars;
0098          delete fCovMatrix;
0099          delete fUniformPdf;
0100       }
0101 
0102    protected:
0103       RooAbsPdf *fPdf = nullptr;         ///< the main proposal density function
0104       RooAbsPdf *fCluesPdf = nullptr;    ///< proposal dens. func. with clues for certain points
0105       RooAbsPdf *fUniformPdf = nullptr;  ///< uniform proposal dens. func.
0106       RooDataSet *fClues = nullptr;      ///< data set of clues
0107       TMatrixDSym *fCovMatrix = nullptr; ///< covariance matrix for multi var gaussian pdf
0108       PdfProposal* fPdfProp = nullptr;   ///< the PdfProposal we are (probably) going to return
0109       RooArgList *fVars = nullptr;   ///< the RooRealVars to generate proposals for
0110       Int_t fCacheSize = -1;         ///< for generating proposals from PDFs
0111       double fSigmaRangeDivisor;   ///< range divisor to get sigma for each variable
0112       double fUniFrac = -1;        ///< what fraction of the PDF integral is uniform
0113       double fCluesFrac = -1;      ///< what fraction of the PDF integral comes from clues
0114       bool fOwnsPdfProp = true;    ///< whether we own the PdfProposal; equivalent to:
0115                                    ///< !(whether we have returned it in GetProposalFunction)
0116       bool fOwnsPdf = false;       ///< whether we created (and own) the main pdf
0117       bool fOwnsCluesPdf = false;  ///< whether we created (and own) the clues pdf
0118       bool fOwnsVars = false;      ///< whether we own fVars
0119       bool fUseUpdates = false;    ///< whether to set updates for proposal params in PdfProposal
0120       const Option_t *fCluesOptions = nullptr; ///< option string for clues RooNDKeysPdf
0121 
0122       void CreatePdf();
0123       void CreateCluesPdf();
0124       void CreateUniformPdf();
0125       void CreateCovMatrix(RooArgList& xVec);
0126 
0127       ClassDefOverride(ProposalHelper,1)
0128    };
0129 }
0130 #endif