CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/HiggsAnalysis/CombinedLimit/src/DebugProposal.cc

Go to the documentation of this file.
00001 #include "../interface/DebugProposal.h"
00002 #include <RooAbsData.h>
00003 #include <RooAbsPdf.h>
00004 #include <iostream>
00005 #include <memory>
00006 #include <RooStats/RooStatsUtils.h>
00007 
00008 DebugProposal::DebugProposal(RooStats::ProposalFunction *p, RooAbsPdf *pdf, RooAbsData *data, int tries) : 
00009     RooStats::ProposalFunction(), prop_(p), pdf_(pdf), tries_(tries) 
00010 {
00011     if (pdf && data) {
00012         nll_.reset(pdf->createNLL(*data));
00013         RooArgSet *par = pdf->getParameters(*data);
00014         RooStats::RemoveConstantParameters(par);
00015         params_.add(*par);
00016         delete par;
00017     }
00018     if (tries) {
00019         p->Print("V");
00020     }
00021 }
00022 
00023 // Populate xPrime with a new proposed point
00024 void DebugProposal::Propose(RooArgSet& xPrime, RooArgSet& x )
00025 {
00026    prop_->Propose(xPrime,x);
00027    if (tries_ > 0) {  
00028         std::cout << "DebugProposal::Propose: x'" << std::endl; xPrime.Print("V"); 
00029         std::cout << "DebugProposal::Propose: x " << std::endl; x.Print("V"); 
00030         if (nll_.get()) {
00031             RooStats::SetParameters(&xPrime, &params_);
00032             double nllXP = nll_->getVal();
00033             RooStats::SetParameters(&x, &params_);
00034             double nllX  = nll_->getVal();
00035             std::cout << "DebugProposal::Propose: NLL(x)  = " << nllX  << std::endl;
00036             std::cout << "DebugProposal::Propose: NLL(x') = " << nllXP << std::endl;
00037             std::cout << "DebugProposal::Propose: uncorrected acc prob. = " << exp(nllX - nllXP) << std::endl;
00038             std::cout << "DebugProposal::Propose: tracing NLL(x')" << std::endl;
00039             RooStats::SetParameters(&xPrime, &params_);
00040             tracePdf(nll_.get());
00041             std::cout << "DebugProposal::Propose: tracing NLL(x)" << std::endl;
00042             RooStats::SetParameters(&x, &params_);
00043             tracePdf(nll_.get());
00044         }
00045         --tries_;
00046    }
00047 }
00048 
00049 // Return the probability of proposing the point x1 given the starting
00050 // point x2
00051 Double_t DebugProposal::GetProposalDensity(RooArgSet& x1,
00052                                           RooArgSet& x2)
00053 {
00054    if (tries_ > 0) {  
00055        std::cout << "DebugProposal::GetProposalDensity: x1" << std::endl; x1.Print("V"); 
00056        std::cout << "DebugProposal::GetProposalDensity: x2" << std::endl; x2.Print("V"); 
00057    }
00058    Double_t ret = prop_->GetProposalDensity(x1,x2);
00059    if (tries_ > 0) { std::cout << "DebugProposal::GetProposalDensity: return " << ret << std::endl; }
00060    return ret;
00061 }
00062 
00063 
00064 Bool_t DebugProposal::IsSymmetric(RooArgSet& x1, RooArgSet& x2) {
00065    if (tries_ > 0) {  
00066        std::cout << "DebugProposal::IsSymmetric: x1" << std::endl; x1.Print("V"); 
00067        std::cout << "DebugProposal::IsSymmetric: x2" << std::endl; x2.Print("V"); 
00068    }
00069    Bool_t ret = prop_->IsSymmetric(x1,x2);
00070    if (tries_ > 0) { std::cout << "DebugProposal::IsSymmetric: return " << ret << std::endl; }
00071    return ret;
00072 }
00073 
00074 void DebugProposal::tracePdf(RooAbsReal *pdf) {
00075    RooArgList deps;
00076    deps.add(*pdf);
00077    pdf->treeNodeServerList(&deps);
00078    for (int i = 0, n = deps.getSize(); i < n; ++i) {
00079       RooAbsReal *rar = dynamic_cast<RooAbsReal *>(deps.at(i));
00080       if (typeid(*rar) == typeid(RooRealVar) || rar->isConstant()) continue;
00081       if (rar != 0) {
00082         std::cout << "   " << rar->GetName() << " = " << rar->getVal() << std::endl;
00083       }
00084    }
00085 }
00086 
00087 ClassImp(DebugProposal)