CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DebugProposal.cc
Go to the documentation of this file.
1 #include "../interface/DebugProposal.h"
2 #include <RooAbsData.h>
3 #include <RooAbsPdf.h>
4 #include <iostream>
5 #include <memory>
6 #include <RooStats/RooStatsUtils.h>
7 
8 DebugProposal::DebugProposal(RooStats::ProposalFunction *p, RooAbsPdf *pdf, RooAbsData *data, int tries) :
9  RooStats::ProposalFunction(), prop_(p), pdf_(pdf), tries_(tries)
10 {
11  if (pdf && data) {
12  nll_.reset(pdf->createNLL(*data));
13  RooArgSet *par = pdf->getParameters(*data);
14  RooStats::RemoveConstantParameters(par);
15  params_.add(*par);
16  delete par;
17  }
18  if (tries) {
19  p->Print("V");
20  }
21 }
22 
23 // Populate xPrime with a new proposed point
24 void DebugProposal::Propose(RooArgSet& xPrime, RooArgSet& x )
25 {
26  prop_->Propose(xPrime,x);
27  if (tries_ > 0) {
28  std::cout << "DebugProposal::Propose: x'" << std::endl; xPrime.Print("V");
29  std::cout << "DebugProposal::Propose: x " << std::endl; x.Print("V");
30  if (nll_.get()) {
31  RooStats::SetParameters(&xPrime, &params_);
32  double nllXP = nll_->getVal();
33  RooStats::SetParameters(&x, &params_);
34  double nllX = nll_->getVal();
35  std::cout << "DebugProposal::Propose: NLL(x) = " << nllX << std::endl;
36  std::cout << "DebugProposal::Propose: NLL(x') = " << nllXP << std::endl;
37  std::cout << "DebugProposal::Propose: uncorrected acc prob. = " << exp(nllX - nllXP) << std::endl;
38  std::cout << "DebugProposal::Propose: tracing NLL(x')" << std::endl;
39  RooStats::SetParameters(&xPrime, &params_);
40  tracePdf(nll_.get());
41  std::cout << "DebugProposal::Propose: tracing NLL(x)" << std::endl;
42  RooStats::SetParameters(&x, &params_);
43  tracePdf(nll_.get());
44  }
45  --tries_;
46  }
47 }
48 
49 // Return the probability of proposing the point x1 given the starting
50 // point x2
51 Double_t DebugProposal::GetProposalDensity(RooArgSet& x1,
52  RooArgSet& x2)
53 {
54  if (tries_ > 0) {
55  std::cout << "DebugProposal::GetProposalDensity: x1" << std::endl; x1.Print("V");
56  std::cout << "DebugProposal::GetProposalDensity: x2" << std::endl; x2.Print("V");
57  }
58  Double_t ret = prop_->GetProposalDensity(x1,x2);
59  if (tries_ > 0) { std::cout << "DebugProposal::GetProposalDensity: return " << ret << std::endl; }
60  return ret;
61 }
62 
63 
64 Bool_t DebugProposal::IsSymmetric(RooArgSet& x1, RooArgSet& x2) {
65  if (tries_ > 0) {
66  std::cout << "DebugProposal::IsSymmetric: x1" << std::endl; x1.Print("V");
67  std::cout << "DebugProposal::IsSymmetric: x2" << std::endl; x2.Print("V");
68  }
69  Bool_t ret = prop_->IsSymmetric(x1,x2);
70  if (tries_ > 0) { std::cout << "DebugProposal::IsSymmetric: return " << ret << std::endl; }
71  return ret;
72 }
73 
74 void DebugProposal::tracePdf(RooAbsReal *pdf) {
75  RooArgList deps;
76  deps.add(*pdf);
77  pdf->treeNodeServerList(&deps);
78  for (int i = 0, n = deps.getSize(); i < n; ++i) {
79  RooAbsReal *rar = dynamic_cast<RooAbsReal *>(deps.at(i));
80  if (typeid(*rar) == typeid(RooRealVar) || rar->isConstant()) continue;
81  if (rar != 0) {
82  std::cout << " " << rar->GetName() << " = " << rar->getVal() << std::endl;
83  }
84  }
85 }
86 
87 ClassImp(DebugProposal)
int i
Definition: DBlmapReader.cc:9
virtual void Propose(RooArgSet &xPrime, RooArgSet &x)
virtual Double_t GetProposalDensity(RooArgSet &x1, RooArgSet &x2)
virtual Bool_t IsSymmetric(RooArgSet &x1, RooArgSet &x2)
void tracePdf(RooAbsReal *pdf)
RooArgSet params_
Definition: DebugProposal.h:40
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121
ClassDef(DebugProposal, 1) private std::auto_ptr< RooAbsReal > nll_
Definition: DebugProposal.h:34
Definition: DDAxes.h:10