CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TestProposal.cc
Go to the documentation of this file.
1 #include "../interface/TestProposal.h"
2 #include <RooArgSet.h>
3 #include <iostream>
4 #include <memory>
5 #include <TIterator.h>
6 #include <RooRandom.h>
7 #include <RooStats/RooStatsUtils.h>
8 
9 TestProposal::TestProposal(double divisor, const RooRealVar *alwaysStepMe) :
10  RooStats::ProposalFunction(),
11  divisor_(1./divisor),
12  poiDivisor_(divisor_)
13 {
14  alwaysStepMe_.add(*alwaysStepMe);
15 }
16 
17 TestProposal::TestProposal(double divisor, const RooArgList &alwaysStepMe) :
18  RooStats::ProposalFunction(),
19  divisor_(1./divisor),
20  poiDivisor_(divisor_),
21  alwaysStepMe_(alwaysStepMe)
22 {
23  if (alwaysStepMe.getSize() > 1) poiDivisor_ /= sqrt(double(alwaysStepMe.getSize()));
24 }
25 
26 
27 // Populate xPrime with a new proposed point
28 void TestProposal::Propose(RooArgSet& xPrime, RooArgSet& x )
29 {
30  RooStats::SetParameters(&x, &xPrime);
31  RooLinkedListIter it(xPrime.iterator());
32  RooRealVar* var;
33  int n = xPrime.getSize(), j = floor(RooRandom::uniform()*n);
34  for (int i = 0; (var = (RooRealVar*)it.Next()) != NULL; ++i) {
35  if (i == j) {
36  if (alwaysStepMe_.contains(*var)) break; // don't step twice
37  double val = var->getVal(), max = var->getMax(), min = var->getMin(), len = max - min;
38  val += RooRandom::gaussian() * len * divisor_;
39  while (val > max) val -= len;
40  while (val < min) val += len;
41  var->setVal(val);
42  break;
43  }
44  }
45  it = alwaysStepMe_.iterator();
46  for (RooRealVar *poi = (RooRealVar*)it.Next(); poi != NULL; poi = (RooRealVar*)it.Next()) {
47  RooRealVar *var = (RooRealVar*) xPrime.find(poi->GetName());
48  double val = var->getVal(), max = var->getMax(), min = var->getMin(), len = max - min;
49  val += RooRandom::gaussian() * len * poiDivisor_;
50  while (val > max) val -= len;
51  while (val < min) val += len;
52  var->setVal(val);
53  }
54 }
55 
56 Bool_t TestProposal::IsSymmetric(RooArgSet& x1, RooArgSet& x2) {
57  return true;
58 }
59 
60 // Return the probability of proposing the point x1 given the starting
61 // point x2
62 Double_t TestProposal::GetProposalDensity(RooArgSet& x1,
63  RooArgSet& x2)
64 {
65  return 1.0; // should not be needed
66 }
67 
68 ClassImp(TestProposal)
int i
Definition: DBlmapReader.cc:9
virtual void Propose(RooArgSet &xPrime, RooArgSet &x)
Definition: TestProposal.cc:28
#define NULL
Definition: scimark2.h:8
#define min(a, b)
Definition: mlp_lapack.h:161
ClassDef(TestProposal, 1) private RooArgList alwaysStepMe_
Definition: TestProposal.h:33
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:46
virtual Bool_t IsSymmetric(RooArgSet &x1, RooArgSet &x2)
Definition: TestProposal.cc:56
int j
Definition: DBlmapReader.cc:9
virtual Double_t GetProposalDensity(RooArgSet &x1, RooArgSet &x2)
Definition: TestProposal.cc:62
Definition: DDAxes.h:10