ROOT logo
// @(#)root/roostats:$Id: ProposalHelper.h 39391 2011-05-26 09:51:59Z moneta $
// Authors: Kevin Belasco        7/22/2009
// Authors: Kyle Cranmer         7/22/2009
/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef RooStats_ProposalHelper
#define RooStats_ProposalHelper

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif
#ifndef ROOSTATS_ProposalFunction
#include "RooStats/ProposalFunction.h"
#endif
#ifndef ROOSTATS_UniformProposal
#include "RooStats/UniformProposal.h"
#endif
#ifndef ROOSTATS_PdfProposal
#include "RooStats/PdfProposal.h"
#endif
#ifndef ROO_ARG_SET
#include "RooArgSet.h"
#endif
#ifndef ROO_MSG_SERVICE
#include "RooMsgService.h"
#endif
#ifndef ROO_REAL_VAR
#include "RooRealVar.h"
#endif
#ifndef ROOT_TObject
#include "TObject.h"
#endif

#include <map>

using namespace std;

namespace RooStats {

   class ProposalHelper : public TObject {

   public:
      ProposalHelper();

      // Set the PDF to be the proposal density function
      virtual void SetPdf(RooAbsPdf& pdf) { fPdf = &pdf; }
      // Set the bank of clues to add to the current proposal density function
      virtual void SetClues(RooDataSet& clues) { fClues = &clues; }

      // Get the ProposalFunction that we've been designing
      virtual ProposalFunction* GetProposalFunction();

      virtual void SetCacheSize(Int_t size)
      {
         if (size > 0)
            fCacheSize = size;
         else
            coutE(Eval) << "Warning: Requested non-positive cache size: " <<
                           size << ". Cache size unchanged." << endl;
      }

      virtual void SetUpdateProposalParameters(Bool_t updateParams)
      { fUseUpdates = updateParams; }

      virtual void SetVariables(RooArgList& vars)
      { fVars = &vars; }

      virtual void SetVariables(const RooArgList& vars)
      { fVars = new RooArgList(vars); fOwnsVars = kTRUE; }

      // set what fraction of the proposal density function should come from
      // a uniform proposal distribution
      virtual void SetUniformFraction(Double_t uniFrac) { fUniFrac = uniFrac; }

      // set what fraction of the proposal density function should come from
      // the bank of clues
      virtual void SetCluesFraction(Double_t cluesFrac) { fCluesFrac = cluesFrac; }

      // set the covariance matrix to use for a multi-variate Gaussian proposal
      virtual void SetCovMatrix(const TMatrixDSym& covMatrix)
      { fCovMatrix = new TMatrixDSym(covMatrix); }

      // set what divisor we will use when dividing the range of a variable to
      // determine the width of the proposal function for each dimension
      // e.g. divisor = 6 for sigma = 1/6th
      virtual void SetWidthRangeDivisor(Double_t divisor)
      { if (divisor > 0.) fSigmaRangeDivisor = divisor; }

      // set the option string to pass to the RooNDKeysPdf constructor
      // if the bank of clues pdf is being automatically generated by this
      // ProposalHelper
      virtual void SetCluesOptions(const Option_t* options)
      { if (options != NULL) fCluesOptions = options; }

      virtual void SetVariables(RooArgSet& vars)
      {
         RooArgList* argList = new RooArgList(vars);
         SetVariables(*argList);
         fOwnsVars = kTRUE;
      }

      virtual ~ProposalHelper()
      {
         if (fOwnsPdfProp)      delete fPdfProp;
         if (fOwnsPdf)          delete fPdf;
         if (fOwnsCluesPdf)     delete fCluesPdf;
         if (fOwnsVars)         delete fVars;
         delete fCovMatrix;
         delete fUniformPdf;
      }

   protected:
      RooAbsPdf* fPdf; // the main proposal density function
      RooAbsPdf* fCluesPdf; // proposal dens. func. with clues for certain points
      RooAbsPdf* fUniformPdf; // uniform proposal dens. func.
      RooDataSet* fClues; // data set of clues
      TMatrixDSym* fCovMatrix; // covariance matrix for multi var gaussian pdf
      PdfProposal* fPdfProp; // the PdfProposal we are (probably) going to return
      RooArgList* fVars; // the RooRealVars to generate proposals for
      Int_t fCacheSize; // for generating proposals from PDFs
      Double_t fSigmaRangeDivisor; // range divisor to get sigma for each variable
      Double_t fUniFrac; // what fraction of the PDF integral is uniform
      Double_t fCluesFrac; // what fraction of the PDF integral comes from clues
      Bool_t fOwnsPdfProp; // whether we own the PdfProposal; equivalent to:
                           // !(whether we have returned it in GetProposalFunction)
      Bool_t fOwnsPdf; // whether we created (and own) the main pdf
      Bool_t fOwnsCluesPdf; // whether we created (and own) the clues pdf
      Bool_t fOwnsVars; // whether we own fVars
      Bool_t fUseUpdates; // whether to set updates for proposal params in PdfProposal
      const Option_t* fCluesOptions; // option string for clues RooNDKeysPdf

      void CreatePdf();
      void CreateCluesPdf();
      void CreateUniformPdf();
      void CreateCovMatrix(RooArgList& xVec);

      ClassDef(ProposalHelper,1)
   };
}
#endif
 ProposalHelper.h:1
 ProposalHelper.h:2
 ProposalHelper.h:3
 ProposalHelper.h:4
 ProposalHelper.h:5
 ProposalHelper.h:6
 ProposalHelper.h:7
 ProposalHelper.h:8
 ProposalHelper.h:9
 ProposalHelper.h:10
 ProposalHelper.h:11
 ProposalHelper.h:12
 ProposalHelper.h:13
 ProposalHelper.h:14
 ProposalHelper.h:15
 ProposalHelper.h:16
 ProposalHelper.h:17
 ProposalHelper.h:18
 ProposalHelper.h:19
 ProposalHelper.h:20
 ProposalHelper.h:21
 ProposalHelper.h:22
 ProposalHelper.h:23
 ProposalHelper.h:24
 ProposalHelper.h:25
 ProposalHelper.h:26
 ProposalHelper.h:27
 ProposalHelper.h:28
 ProposalHelper.h:29
 ProposalHelper.h:30
 ProposalHelper.h:31
 ProposalHelper.h:32
 ProposalHelper.h:33
 ProposalHelper.h:34
 ProposalHelper.h:35
 ProposalHelper.h:36
 ProposalHelper.h:37
 ProposalHelper.h:38
 ProposalHelper.h:39
 ProposalHelper.h:40
 ProposalHelper.h:41
 ProposalHelper.h:42
 ProposalHelper.h:43
 ProposalHelper.h:44
 ProposalHelper.h:45
 ProposalHelper.h:46
 ProposalHelper.h:47
 ProposalHelper.h:48
 ProposalHelper.h:49
 ProposalHelper.h:50
 ProposalHelper.h:51
 ProposalHelper.h:52
 ProposalHelper.h:53
 ProposalHelper.h:54
 ProposalHelper.h:55
 ProposalHelper.h:56
 ProposalHelper.h:57
 ProposalHelper.h:58
 ProposalHelper.h:59
 ProposalHelper.h:60
 ProposalHelper.h:61
 ProposalHelper.h:62
 ProposalHelper.h:63
 ProposalHelper.h:64
 ProposalHelper.h:65
 ProposalHelper.h:66
 ProposalHelper.h:67
 ProposalHelper.h:68
 ProposalHelper.h:69
 ProposalHelper.h:70
 ProposalHelper.h:71
 ProposalHelper.h:72
 ProposalHelper.h:73
 ProposalHelper.h:74
 ProposalHelper.h:75
 ProposalHelper.h:76
 ProposalHelper.h:77
 ProposalHelper.h:78
 ProposalHelper.h:79
 ProposalHelper.h:80
 ProposalHelper.h:81
 ProposalHelper.h:82
 ProposalHelper.h:83
 ProposalHelper.h:84
 ProposalHelper.h:85
 ProposalHelper.h:86
 ProposalHelper.h:87
 ProposalHelper.h:88
 ProposalHelper.h:89
 ProposalHelper.h:90
 ProposalHelper.h:91
 ProposalHelper.h:92
 ProposalHelper.h:93
 ProposalHelper.h:94
 ProposalHelper.h:95
 ProposalHelper.h:96
 ProposalHelper.h:97
 ProposalHelper.h:98
 ProposalHelper.h:99
 ProposalHelper.h:100
 ProposalHelper.h:101
 ProposalHelper.h:102
 ProposalHelper.h:103
 ProposalHelper.h:104
 ProposalHelper.h:105
 ProposalHelper.h:106
 ProposalHelper.h:107
 ProposalHelper.h:108
 ProposalHelper.h:109
 ProposalHelper.h:110
 ProposalHelper.h:111
 ProposalHelper.h:112
 ProposalHelper.h:113
 ProposalHelper.h:114
 ProposalHelper.h:115
 ProposalHelper.h:116
 ProposalHelper.h:117
 ProposalHelper.h:118
 ProposalHelper.h:119
 ProposalHelper.h:120
 ProposalHelper.h:121
 ProposalHelper.h:122
 ProposalHelper.h:123
 ProposalHelper.h:124
 ProposalHelper.h:125
 ProposalHelper.h:126
 ProposalHelper.h:127
 ProposalHelper.h:128
 ProposalHelper.h:129
 ProposalHelper.h:130
 ProposalHelper.h:131
 ProposalHelper.h:132
 ProposalHelper.h:133
 ProposalHelper.h:134
 ProposalHelper.h:135
 ProposalHelper.h:136
 ProposalHelper.h:137
 ProposalHelper.h:138
 ProposalHelper.h:139
 ProposalHelper.h:140
 ProposalHelper.h:141
 ProposalHelper.h:142
 ProposalHelper.h:143
 ProposalHelper.h:144
 ProposalHelper.h:145
 ProposalHelper.h:146