Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooStats/PdfProposal.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/roostats:$Id$
0002 // Authors: Kevin Belasco        17/06/2009
0003 // Authors: Kyle Cranmer         17/06/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_PdfProposal
0013 #define ROOSTATS_PdfProposal
0014 
0015 #include "Rtypes.h"
0016 
0017 #include "RooStats/ProposalFunction.h"
0018 
0019 #include "RooArgSet.h"
0020 #include "RooMsgService.h"
0021 #include "RooRealVar.h"
0022 #include "RooDataSet.h"
0023 #include "RooAbsPdf.h"
0024 
0025 #include <map>
0026 
0027 
0028 namespace RooStats {
0029 
0030    class PdfProposal : public ProposalFunction {
0031 
0032    public:
0033       PdfProposal();
0034       PdfProposal(RooAbsPdf& pdf);
0035 
0036       /// Populate xPrime with a new proposed point
0037       void Propose(RooArgSet& xPrime, RooArgSet& x) override;
0038 
0039       /// Determine whether or not the proposal density is symmetric for
0040       /// points x1 and x2 - that is, whether the probability of reaching x2
0041       /// from x1 is equal to the probability of reaching x1 from x2
0042       bool IsSymmetric(RooArgSet& x1, RooArgSet& x2) override;
0043 
0044       /// Return the probability of proposing the point x1 given the starting
0045       /// point x2
0046       double GetProposalDensity(RooArgSet& x1, RooArgSet& x2) override;
0047 
0048       /// Set the PDF to be the proposal density function
0049       virtual void SetPdf(RooAbsPdf& pdf) { fPdf = &pdf; }
0050 
0051       /// Get the PDF is the proposal density function
0052       virtual const RooAbsPdf* GetPdf() const { return fPdf; }
0053 
0054       /// specify a mapping between a parameter of the proposal function and
0055       /// a parameter of interest.  this mapping is used to set the value of
0056       /// proposalParam equal to the value of update to determine the
0057       /// proposal function.
0058       /// proposalParam is a parameter of the proposal function that must
0059       /// be set to the value of update (from the current point) in order to
0060       /// propose a new point.
0061       virtual void AddMapping(RooRealVar& proposalParam, RooAbsReal& update);
0062 
0063       virtual void Reset()
0064       {
0065          fCache.reset();
0066          fCachePosition = 0;
0067          fLastX.removeAll();
0068       }
0069 
0070       virtual void printMappings()
0071       {
0072          std::map<RooRealVar*, RooAbsReal*>::iterator it;
0073          for (it = fMap.begin(); it != fMap.end(); it++)
0074             std::cout << it->first->GetName() << " => " << it->second->GetName() << std::endl;
0075       }
0076 
0077       /// Set how many points to generate each time we propose from a new point
0078       /// Default (and minimum) is 1
0079       virtual void SetCacheSize(Int_t size)
0080       {
0081          if (size > 0) {
0082             fCacheSize = size;
0083          } else {
0084             coutE(Eval) << "Warning: Requested non-positive cache size: " << size << ". Cache size unchanged."
0085                         << std::endl;
0086          }
0087       }
0088 
0089       /// set whether we own the PDF that serves as the proposal density function
0090       /// By default, when constructed, PdfProposal does NOT own the PDF.
0091       virtual void SetOwnsPdf(bool ownsPdf) { fOwnsPdf = ownsPdf; }
0092 
0093       //virtual void SetIsAlwaysSymmetric(bool isAlwaysSymmetric)
0094       //{ fIsAlwaysSymmetric = isAlwaysSymmetric; }
0095 
0096       ~PdfProposal() override
0097       {
0098          if (fOwnsPdf)
0099             delete fPdf;
0100       }
0101 
0102    protected:
0103       RooAbsPdf *fPdf = nullptr;               /// the proposal density function
0104       std::map<RooRealVar*, RooAbsReal*> fMap; /// map of values in pdf to update
0105       std::map<RooRealVar*, RooAbsReal*>::iterator fIt; /// pdf iterator
0106       RooArgSet fLastX; /// the last point we were at
0107       Int_t fCacheSize = 1;               /// how many points to generate each time
0108       Int_t fCachePosition = 0;           /// our position in the cached proposal data set
0109       std::unique_ptr<RooDataSet> fCache; /// the cached proposal data set
0110       RooArgSet fMaster; /// pointers to master variables needed for updates
0111       bool fOwnsPdf = false; /// whether we own the proposal density function
0112       // bool fIsAlwaysSymmetric; // does Q(x1 | x2) == Q(x2 | x1) for all x1, x2
0113 
0114       /// determine whether these two RooArgSets represent the same point
0115       virtual bool Equals(RooArgSet& x1, RooArgSet& x2);
0116 
0117       /// Interface for tools setting limits (producing confidence intervals)
0118       ClassDefOverride(PdfProposal,2);
0119    };
0120 }
0121 
0122 #endif