Go to the documentation of this file.00001 #include "../interface/TestProposal.h"
00002 #include <RooArgSet.h>
00003 #include <iostream>
00004 #include <memory>
00005 #include <TIterator.h>
00006 #include <RooRandom.h>
00007 #include <RooStats/RooStatsUtils.h>
00008
00009 TestProposal::TestProposal(double divisor, const RooRealVar *alwaysStepMe) :
00010 RooStats::ProposalFunction(),
00011 divisor_(1./divisor),
00012 poiDivisor_(divisor_)
00013 {
00014 alwaysStepMe_.add(*alwaysStepMe);
00015 }
00016
00017 TestProposal::TestProposal(double divisor, const RooArgList &alwaysStepMe) :
00018 RooStats::ProposalFunction(),
00019 divisor_(1./divisor),
00020 poiDivisor_(divisor_),
00021 alwaysStepMe_(alwaysStepMe)
00022 {
00023 if (alwaysStepMe.getSize() > 1) poiDivisor_ /= sqrt(double(alwaysStepMe.getSize()));
00024 }
00025
00026
00027
00028 void TestProposal::Propose(RooArgSet& xPrime, RooArgSet& x )
00029 {
00030 RooStats::SetParameters(&x, &xPrime);
00031 RooLinkedListIter it(xPrime.iterator());
00032 RooRealVar* var;
00033 int n = xPrime.getSize(), j = floor(RooRandom::uniform()*n);
00034 for (int i = 0; (var = (RooRealVar*)it.Next()) != NULL; ++i) {
00035 if (i == j) {
00036 if (alwaysStepMe_.contains(*var)) break;
00037 double val = var->getVal(), max = var->getMax(), min = var->getMin(), len = max - min;
00038 val += RooRandom::gaussian() * len * divisor_;
00039 while (val > max) val -= len;
00040 while (val < min) val += len;
00041 var->setVal(val);
00042 break;
00043 }
00044 }
00045 it = alwaysStepMe_.iterator();
00046 for (RooRealVar *poi = (RooRealVar*)it.Next(); poi != NULL; poi = (RooRealVar*)it.Next()) {
00047 RooRealVar *var = (RooRealVar*) xPrime.find(poi->GetName());
00048 double val = var->getVal(), max = var->getMax(), min = var->getMin(), len = max - min;
00049 val += RooRandom::gaussian() * len * poiDivisor_;
00050 while (val > max) val -= len;
00051 while (val < min) val += len;
00052 var->setVal(val);
00053 }
00054 }
00055
00056 Bool_t TestProposal::IsSymmetric(RooArgSet& x1, RooArgSet& x2) {
00057 return true;
00058 }
00059
00060
00061
00062 Double_t TestProposal::GetProposalDensity(RooArgSet& x1,
00063 RooArgSet& x2)
00064 {
00065 return 1.0;
00066 }
00067
00068 ClassImp(TestProposal)