Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-16 09:54:51

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: " <<
0085                size << ". Cache size unchanged." << std::endl;
0086       }
0087 
0088       /// set whether we own the PDF that serves as the proposal density function
0089       /// By default, when constructed, PdfProposal does NOT own the PDF.
0090       virtual void SetOwnsPdf(bool ownsPdf) { fOwnsPdf = ownsPdf; }
0091 
0092       //virtual void SetIsAlwaysSymmetric(bool isAlwaysSymmetric)
0093       //{ fIsAlwaysSymmetric = isAlwaysSymmetric; }
0094 
0095       ~PdfProposal() override
0096       {
0097          if (fOwnsPdf)
0098             delete fPdf;
0099       }
0100 
0101    protected:
0102       RooAbsPdf* fPdf; /// the proposal density function
0103       std::map<RooRealVar*, RooAbsReal*> fMap; /// map of values in pdf to update
0104       std::map<RooRealVar*, RooAbsReal*>::iterator fIt; /// pdf iterator
0105       RooArgSet fLastX; /// the last point we were at
0106       Int_t fCacheSize; /// how many points to generate each time
0107       Int_t fCachePosition; /// our position in the cached proposal data set
0108       std::unique_ptr<RooDataSet> fCache; /// the cached proposal data set
0109       RooArgSet fMaster; /// pointers to master variables needed for updates
0110       bool fOwnsPdf; /// whether we own the proposal density function
0111       //bool fIsAlwaysSymmetric; // does Q(x1 | x2) == Q(x2 | x1) for all x1, x2
0112 
0113       /// determine whether these two RooArgSets represent the same point
0114       virtual bool Equals(RooArgSet& x1, RooArgSet& x2);
0115 
0116       /// Interface for tools setting limits (producing confidence intervals)
0117       ClassDefOverride(PdfProposal,2);
0118    };
0119 }
0120 
0121 #endif