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        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 
0013 
0014 
0015 #ifndef ROOSTATS_ProposalFunction
0016 #define ROOSTATS_ProposalFunction
0017 
0018 #include "Rtypes.h"
0019 
0020 #include "RooArgSet.h"
0021 #include "RooMsgService.h"
0022 #include "RooRealVar.h"
0023 
0024 
0025 namespace RooStats {
0026 
0027 /** \class ProposalFunction
0028     \ingroup Roostats
0029 ProposalFunction is an interface for all proposal functions that would be used
0030 with a Markov Chain Monte Carlo algorithm.
0031 Given a current point in the parameter space it proposes a new point.
0032 Proposal functions may or may not be symmetric, in the sense that the
0033 probability to propose X1 given we are at X2
0034 need not be the same as the probability to propose X2 given that we are at X1.
0035 In this case, the IsSymmetric method
0036 should return false, and the Metropolis algorithm will need to take into account
0037 the proposal density to maintain detailed balance.
0038 */
0039 
0040 
0041    class ProposalFunction : public TObject {
0042 
0043    public:
0044       ///Default constructor
0045       ProposalFunction() {}
0046 
0047       /// Populate xPrime with the new proposed point,
0048       /// possibly based on the current point x
0049       virtual void Propose(RooArgSet& xPrime, RooArgSet& x) = 0;
0050 
0051       /// Determine whether or not the proposal density is symmetric for
0052       /// points x1 and x2 - that is, whether the probability of reaching x2
0053       /// from x1 is equal to the probability of reaching x1 from x2
0054       virtual bool IsSymmetric(RooArgSet& x1, RooArgSet& x2) = 0;
0055 
0056       /// Return the probability of proposing the point x1 given the starting
0057       /// point x2
0058       virtual double GetProposalDensity(RooArgSet& x1, RooArgSet& x2) = 0;
0059 
0060       /// Check the parameters for which the ProposalFunction will
0061       /// propose values to make sure they are all RooRealVars
0062       /// Return true if all objects are RooRealVars, false otherwise
0063       virtual bool CheckParameters(RooArgSet& params)
0064       {
0065          for (auto *obj : params){
0066             if (!dynamic_cast<RooRealVar*>(obj)) {
0067                coutE(Eval) << "Error when checking parameters in"
0068                            << "ProposalFunction: "
0069                            << "Object \"" << obj->GetName() << "\" not of type "
0070                            << "RooRealVar" << std::endl;
0071                return false;
0072             }
0073          }
0074          // Made it here, so all parameters are RooRealVars
0075          return true;
0076       }
0077 
0078    protected:
0079       ClassDefOverride(ProposalFunction,1) /// Interface for the proposal function used with Markov Chain Monte Carlo
0080    };
0081 }
0082 
0083 #endif