Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MCMCInterval.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Authors: Kevin Belasco 17/06/2009
3// Authors: Kyle Cranmer 17/06/2009
4/*************************************************************************
5 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class RooStats::MCMCInterval
13 \ingroup Roostats
14
15 MCMCInterval is a concrete implementation of the RooStats::ConfInterval
16 interface. It takes as input Markov Chain of data points in the parameter
17 space generated by Monte Carlo using the Metropolis algorithm. From the Markov
18 Chain, the confidence interval can be determined in two ways:
19
20#### Using a Kernel-Estimated PDF: (not the default method)
21
22 A RooNDKeysPdf is constructed from the data set using adaptive kernel width.
23 With this RooNDKeysPdf F, we then integrate over the most likely domain in the
24 parameter space (tallest points in the posterior RooNDKeysPdf) until the target
25 confidence level is reached within an acceptable neighborhood as defined by
26 SetEpsilon(). More specifically: we calculate the following for different
27 cutoff values C until we reach the target confidence level: \f$\int_{ F >= C } F
28 d{normset} \f$.
29 Important note: this is not the default method because of a bug in constructing
30 the RooNDKeysPdf from a weighted data set. Configure to use this method by
31 calling SetUseKeys(true), and the data set will be interpreted without weights.
32
33
34#### Using a binned data set: (the default method)
35
36 This is the binned analog of the continuous integrative method that uses the
37 kernel-estimated PDF. The points in the Markov Chain are put into a binned
38 data set and the interval is then calculated by adding the heights of the bins
39 in decreasing order until the desired level of confidence has been reached.
40 Note that this means the actual confidence level is >= the confidence level
41 prescribed by the client (unless the user calls SetHistStrict(false)). This
42 method is the default but may not remain as such in future releases, so you may
43 wish to explicitly configure to use this method by calling SetUseKeys(false)
44
45
46 These are not the only ways for the confidence interval to be determined, and
47 other possibilities are being considered being added, especially for the
48 1-dimensional case.
49
50
51 One can ask an MCMCInterval for the lower and upper limits on a specific
52 parameter of interest in the interval. Note that this works better for some
53 distributions (ones with exactly one local maximum) than others, and sometimes
54 has little value.
55*/
56
57
58#include "Rtypes.h"
59
60#include "TMath.h"
61
64#include "RooStats/Heaviside.h"
65#include "RooDataHist.h"
66#include "RooNDKeysPdf.h"
67#include "RooProduct.h"
69#include "RooRealVar.h"
70#include "RooArgList.h"
71#include "TH1.h"
72#include "TH1F.h"
73#include "TH2F.h"
74#include "TH3F.h"
75#include "RooMsgService.h"
76#include "RooGlobalFunc.h"
77#include "TObject.h"
78#include "THnSparse.h"
79#include "RooNumber.h"
80
81#include <cstdlib>
82#include <string>
83#include <algorithm>
84
85
86using namespace RooFit;
87using namespace RooStats;
88using std::endl;
89
90////////////////////////////////////////////////////////////////////////////////
91
93 : ConfInterval(name), fTFLower(-RooNumber::infinity()), fTFUpper(RooNumber::infinity())
94{
95 fVector.clear();
96}
97
98////////////////////////////////////////////////////////////////////////////////
99
100MCMCInterval::MCMCInterval(const char *name, const RooArgSet &parameters, MarkovChain &chain)
101 : ConfInterval(name), fChain(&chain), fTFLower(-RooNumber::infinity()), fTFUpper(RooNumber::infinity())
102{
103 fVector.clear();
104 SetParameters(parameters);
105}
106
107////////////////////////////////////////////////////////////////////////////////
108
110
112 CompareDataHistBins(RooDataHist* hist) : fDataHist(hist) {}
113 bool operator() (Int_t bin1 , Int_t bin2) {
114 double n1 = fDataHist->weight(bin1);
115 double n2 = fDataHist->weight(bin2);
116 return (n1 < n2);
117 }
119};
120
122 CompareSparseHistBins(THnSparse* hist) : fSparseHist(hist) {}
123 bool operator() (Long_t bin1, Long_t bin2) {
124 double n1 = fSparseHist->GetBinContent(bin1);
125 double n2 = fSparseHist->GetBinContent(bin2);
126 return (n1 < n2);
127 }
129};
130
133 fChain(chain), fParam(param) {}
134 bool operator() (Int_t i, Int_t j) {
135 double xi = fChain->Get(i)->getRealValue(fParam->GetName());
136 double xj = fChain->Get(j)->getRealValue(fParam->GetName());
137 return (xi < xj);
138 }
141};
142
143////////////////////////////////////////////////////////////////////////////////
144/// kbelasco: for this method, consider running DetermineInterval() if
145/// fKeysPdf==nullptr, fSparseHist==nullptr, fDataHist==nullptr, or fVector.empty()
146/// rather than just returning false. Though this should not be an issue
147/// because nobody should be able to get an MCMCInterval that has their interval
148/// or posterior representation nullptr/empty since they should only get this
149/// through the MCMCCalculator
150
151bool MCMCInterval::IsInInterval(const RooArgSet& point) const
152{
153 if (fIntervalType == kShortest) {
154 if (fUseKeys) {
155 if (fKeysPdf == nullptr)
156 return false;
157
158 // evaluate keyspdf at point and return whether >= cutoff
159 RooStats::SetParameters(&point, const_cast<RooArgSet *>(&fParameters));
160 return fKeysPdf->getVal(&fParameters) >= fKeysCutoff;
161 } else {
162 if (fUseSparseHist) {
163 if (fSparseHist == nullptr)
164 return false;
165
166 // evaluate sparse hist at bin where point lies and return
167 // whether >= cutoff
169 const_cast<RooArgSet*>(&fParameters));
170 Long_t bin;
171 // kbelasco: consider making x static
172 std::vector<double> x(fDimension);
173 for (Int_t i = 0; i < fDimension; i++)
174 x[i] = fAxes[i]->getVal();
175 bin = fSparseHist->GetBin(x.data(), false);
176 double weight = fSparseHist->GetBinContent((Long64_t)bin);
177 return (weight >= (double)fHistCutoff);
178 } else {
179 if (fDataHist == nullptr)
180 return false;
181
182 // evaluate data hist at bin where point lies and return whether
183 // >= cutoff
184 Int_t bin;
185 bin = fDataHist->getIndex(point);
186 return (fDataHist->weight(bin) >= (double)fHistCutoff);
187 }
188 }
189 } else if (fIntervalType == kTailFraction) {
190 if (fVector.empty())
191 return false;
192
193 // return whether value of point is within the range
194 double x = point.getRealValue(fAxes[0]->GetName());
195 if (fTFLower <= x && x <= fTFUpper)
196 return true;
197
198 return false;
199 }
200
201 coutE(InputArguments) << "Error in MCMCInterval::IsInInterval: "
202 << "Interval type not set. Returning false." << std::endl;
203 return false;
204}
205
206////////////////////////////////////////////////////////////////////////////////
207
209{
210 fConfidenceLevel = cl;
212}
213
214// kbelasco: update this or just take it out
215// kbelasco: consider keeping this around but changing the implementation
216// to set the number of bins for each RooRealVar and then recreating the
217// histograms
218//void MCMCInterval::SetNumBins(Int_t numBins)
219//{
220// if (numBins > 0) {
221// fPreferredNumBins = numBins;
222// for (Int_t d = 0; d < fDimension; d++)
223// fNumBins[d] = numBins;
224// }
225// else {
226// coutE(Eval) << "* Error in MCMCInterval::SetNumBins: " <<
227// "Negative number of bins given: " << numBins << std::endl;
228// return;
229// }
230//
231// // If the histogram already exists, recreate it with the new bin numbers
232// if (fHist != nullptr)
233// CreateHist();
234//}
235
236////////////////////////////////////////////////////////////////////////////////
237
239{
240 Int_t size = axes.size();
241 if (size != fDimension) {
242 coutE(InputArguments) << "* Error in MCMCInterval::SetAxes: " <<
243 "number of variables in axes (" << size <<
244 ") doesn't match number of parameters ("
245 << fDimension << ")" << std::endl;
246 return;
247 }
248 for (Int_t i = 0; i < size; i++)
249 fAxes[i] = static_cast<RooRealVar*>(axes.at(i));
250}
251
252////////////////////////////////////////////////////////////////////////////////
253
255{
256 // kbelasco: check here for memory leak. does RooNDKeysPdf use
257 // the RooArgList passed to it or does it make a clone?
258 // also check for memory leak from chain, does RooNDKeysPdf clone that?
259 if (fAxes.empty() || fParameters.empty()) {
260 coutE(InputArguments) << "Error in MCMCInterval::CreateKeysPdf: "
261 << "parameters have not been set." << std::endl;
262 return;
263 }
264
265 if (fNumBurnInSteps >= fChain->Size()) {
267 "MCMCInterval::CreateKeysPdf: creation of Keys PDF failed: " <<
268 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
269 "in Markov chain." << std::endl;
270 fKeysPdf.reset();
271 fCutoffVar.reset();
272 fHeaviside.reset();
273 fProduct.reset();
274 return;
275 }
276
277 std::unique_ptr<RooAbsData> chain{fChain->GetAsConstDataSet()->reduce(SelectVars(fParameters), EventRange(fNumBurnInSteps, fChain->Size()))};
278
279 RooArgList paramsList;
280 for (Int_t i = 0; i < fDimension; i++)
281 paramsList.add(*fAxes[i]);
282
283 fKeysPdf = std::make_unique<RooNDKeysPdf>("keysPDF", "Keys PDF", paramsList, static_cast<RooDataSet&>(*chain), "a");
284 fCutoffVar = std::make_unique<RooRealVar>("cutoff", "cutoff", 0);
285 fHeaviside = std::make_unique<Heaviside>("heaviside", "Heaviside", *fKeysPdf, *fCutoffVar);
286 fProduct = std::make_unique<RooProduct>("product", "Keys PDF & Heaviside Product",
288}
289
290////////////////////////////////////////////////////////////////////////////////
291
293{
294 if (fAxes.empty() || fChain == nullptr) {
295 coutE(Eval) << "* Error in MCMCInterval::CreateHist(): " <<
296 "Crucial data member was nullptr." << std::endl;
297 coutE(Eval) << "Make sure to fully construct/initialize." << std::endl;
298 return;
299 }
300 fHist.reset();
301
302 if (fNumBurnInSteps >= fChain->Size()) {
304 "MCMCInterval::CreateHist: creation of histogram failed: " <<
305 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
306 "in Markov chain." << std::endl;
307 return;
308 }
309
310 if (fDimension == 1) {
311 fHist = std::make_unique<TH1F>("posterior", "MCMC Posterior Histogram",
312 fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax());
313
314 } else if (fDimension == 2) {
315 fHist = std::make_unique<TH2F>("posterior", "MCMC Posterior Histogram",
316 fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax(),
317 fAxes[1]->numBins(), fAxes[1]->getMin(), fAxes[1]->getMax());
318
319 } else if (fDimension == 3) {
320 fHist = std::make_unique<TH3F>("posterior", "MCMC Posterior Histogram",
321 fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax(),
322 fAxes[1]->numBins(), fAxes[1]->getMin(), fAxes[1]->getMax(),
323 fAxes[2]->numBins(), fAxes[2]->getMin(), fAxes[2]->getMax());
324
325 } else {
326 coutE(Eval) << "* Error in MCMCInterval::CreateHist() : " <<
327 "TH1* couldn't handle dimension: " << fDimension << std::endl;
328 return;
329 }
330
331 // Fill histogram
332 Int_t size = fChain->Size();
333 const RooArgSet* entry;
334 for (Int_t i = fNumBurnInSteps; i < size; i++) {
335 entry = fChain->Get(i);
336 if (fDimension == 1) {
337 (static_cast<TH1F&>(*fHist)).Fill(entry->getRealValue(fAxes[0]->GetName()),
338 fChain->Weight());
339 } else if (fDimension == 2) {
340 (static_cast<TH2F&>(*fHist)).Fill(entry->getRealValue(fAxes[0]->GetName()),
341 entry->getRealValue(fAxes[1]->GetName()),
342 fChain->Weight());
343 } else {
344 (static_cast<TH3F &>(*fHist))
345 .Fill(entry->getRealValue(fAxes[0]->GetName()), entry->getRealValue(fAxes[1]->GetName()),
346 entry->getRealValue(fAxes[2]->GetName()), fChain->Weight());
347 }
348 }
349
350 if (fDimension >= 1)
351 fHist->GetXaxis()->SetTitle(fAxes[0]->GetName());
352 if (fDimension >= 2)
353 fHist->GetYaxis()->SetTitle(fAxes[1]->GetName());
354 if (fDimension >= 3)
355 fHist->GetZaxis()->SetTitle(fAxes[2]->GetName());
356}
357
358////////////////////////////////////////////////////////////////////////////////
359
361{
362 if (fAxes.empty() || fChain == nullptr) {
363 coutE(InputArguments) << "* Error in MCMCInterval::CreateSparseHist(): "
364 << "Crucial data member was nullptr." << std::endl;
365 coutE(InputArguments) << "Make sure to fully construct/initialize."
366 << std::endl;
367 return;
368 }
369 std::vector<double> min(fDimension);
370 std::vector<double> max(fDimension);
371 std::vector<Int_t> bins(fDimension);
372 for (Int_t i = 0; i < fDimension; i++) {
373 min[i] = fAxes[i]->getMin();
374 max[i] = fAxes[i]->getMax();
375 bins[i] = fAxes[i]->numBins();
376 }
377 fSparseHist = std::make_unique<THnSparseF>("posterior", "MCMC Posterior Histogram",
378 fDimension, bins.data(), min.data(), max.data());
379
380 // kbelasco: it appears we need to call Sumw2() just to get the
381 // histogram to keep a running total of the weight so that Getsumw doesn't
382 // just return 0
383 fSparseHist->Sumw2();
384
385 if (fNumBurnInSteps >= fChain->Size()) {
387 "MCMCInterval::CreateSparseHist: creation of histogram failed: " <<
388 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
389 "in Markov chain." << std::endl;
390 }
391
392 // Fill histogram
393 Int_t size = fChain->Size();
394 const RooArgSet* entry;
395 std::vector<double> x(fDimension);
396 for (Int_t i = fNumBurnInSteps; i < size; i++) {
397 entry = fChain->Get(i);
398 for (Int_t ii = 0; ii < fDimension; ii++)
399 x[ii] = entry->getRealValue(fAxes[ii]->GetName());
400 fSparseHist->Fill(x.data(), fChain->Weight());
401 }
402}
403
404////////////////////////////////////////////////////////////////////////////////
405
407{
408 if (fParameters.empty() || fChain == nullptr) {
409 coutE(Eval) << "* Error in MCMCInterval::CreateDataHist(): " <<
410 "Crucial data member was nullptr or empty." << std::endl;
411 coutE(Eval) << "Make sure to fully construct/initialize." << std::endl;
412 return;
413 }
414
415 if (fNumBurnInSteps >= fChain->Size()) {
417 "MCMCInterval::CreateDataHist: creation of histogram failed: " <<
418 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
419 "in Markov chain." << std::endl;
420 fDataHist = nullptr;
421 return;
422 }
423
424 std::unique_ptr<RooAbsData> data{fChain->GetAsConstDataSet()->reduce(SelectVars(fParameters), EventRange(fNumBurnInSteps, fChain->Size()))};
425 fDataHist = std::unique_ptr<RooDataHist>{static_cast<RooDataSet &>(*data).binnedClone()};
426}
427
428////////////////////////////////////////////////////////////////////////////////
429
431{
432 fVector.clear();
433 fVecWeight = 0;
434
435 if (fChain == nullptr) {
436 coutE(InputArguments) << "* Error in MCMCInterval::CreateVector(): " <<
437 "Crucial data member (Markov chain) was nullptr." << std::endl;
438 coutE(InputArguments) << "Make sure to fully construct/initialize."
439 << std::endl;
440 return;
441 }
442
443 if (fNumBurnInSteps >= fChain->Size()) {
445 "MCMCInterval::CreateVector: creation of vector failed: " <<
446 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
447 "in Markov chain." << std::endl;
448 }
449
450 // Fill vector
451 Int_t size = fChain->Size() - fNumBurnInSteps;
452 fVector.resize(size);
453 Int_t i;
454 Int_t chainIndex;
455 for (i = 0; i < size; i++) {
456 chainIndex = i + fNumBurnInSteps;
457 fVector[i] = chainIndex;
458 fVecWeight += fChain->Weight(chainIndex);
459 }
460
461 stable_sort(fVector.begin(), fVector.end(),
462 CompareVectorIndices(fChain.get(), param));
463}
464
465////////////////////////////////////////////////////////////////////////////////
466
468{
470 fParameters.add(parameters);
472 fAxes.resize(fDimension);
473 Int_t n = 0;
474 for (auto *obj : fParameters) {
475 if (dynamic_cast<RooRealVar *>(obj) != nullptr) {
476 fAxes[n] = static_cast<RooRealVar*>(obj);
477 } else {
478 coutE(Eval) << "* Error in MCMCInterval::SetParameters: " << obj->GetName() << " not a RooRealVar*"
479 << std::endl;
480 }
481 n++;
482 }
483}
484
485////////////////////////////////////////////////////////////////////////////////
486
488{
489 switch (fIntervalType) {
490 case kShortest:
492 break;
493 case kTailFraction:
495 break;
496 default:
497 coutE(InputArguments) << "MCMCInterval::DetermineInterval(): " <<
498 "Error: Interval type not set" << std::endl;
499 break;
500 }
501}
502
503////////////////////////////////////////////////////////////////////////////////
504
506{
507 if (fUseKeys) {
509 } else {
511 }
512}
513
514////////////////////////////////////////////////////////////////////////////////
515
517{
518 if (fLeftSideTF < 0 || fLeftSideTF > 1) {
519 coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval: "
520 << "Fraction must be in the range [0, 1]. "
521 << fLeftSideTF << "is not allowed." << std::endl;
522 return;
523 }
524
525 if (fDimension != 1) {
526 coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval(): "
527 << "Error: Can only find a tail-fraction interval for 1-D intervals"
528 << std::endl;
529 return;
530 }
531
532 if (fAxes.empty()) {
533 coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval(): "
534 << "Crucial data member was nullptr." << std::endl;
535 coutE(InputArguments) << "Make sure to fully construct/initialize."
536 << std::endl;
537 return;
538 }
539
540 // kbelasco: fill in code here to find interval
541 //
542 // also make changes so that calling GetPosterior...() returns nullptr
543 // when fIntervalType == kTailFraction, since there really
544 // is no posterior for this type of interval determination
545 if (fVector.empty())
547
548 if (fVector.empty() || fVecWeight == 0) {
549 // if size is still 0, then creation failed.
550 // if fVecWeight == 0, then there are no entries (indicates the same
551 // error as fVector.empty() because that only happens when
552 // fNumBurnInSteps >= fChain->Size())
553 // either way, reset and return
554 fVector.clear();
555 fTFLower = -1.0 * RooNumber::infinity();
557 fTFConfLevel = 0.0;
558 fVecWeight = 0;
559 return;
560 }
561
562 RooRealVar* param = fAxes[0];
563
564 double c = fConfidenceLevel;
565 double leftTailCutoff = fVecWeight * (1 - c) * fLeftSideTF;
566 double rightTailCutoff = fVecWeight * (1 - c) * (1 - fLeftSideTF);
567 double leftTailSum = 0;
568 double rightTailSum = 0;
569
570 // kbelasco: consider changing these values to +infinity and -infinity
571 double ll = param->getMin();
572 double ul = param->getMax();
573
574 double x;
575 double w;
576
577 // save a lot of GetName() calls if compiler does not already optimize this
578 const char* name = param->GetName();
579
580 // find lower limit
581 Int_t i;
582 for (i = 0; i < (Int_t)fVector.size(); i++) {
583 x = fChain->Get(fVector[i])->getRealValue(name);
584 w = fChain->Weight();
585
586 if (std::abs(leftTailSum + w - leftTailCutoff) <
587 std::abs(leftTailSum - leftTailCutoff)) {
588 // moving the lower limit to x would bring us closer to the desired
589 // left tail size
590 ll = x;
591 leftTailSum += w;
592 } else {
593 break;
594 }
595 }
596
597 // find upper limit
598 for (i = (Int_t)fVector.size() - 1; i >= 0; i--) {
599 x = fChain->Get(fVector[i])->getRealValue(name);
600 w = fChain->Weight();
601
602 if (std::abs(rightTailSum + w - rightTailCutoff) <
603 std::abs(rightTailSum - rightTailCutoff)) {
604 // moving the lower limit to x would bring us closer to the desired
605 // left tail size
606 ul = x;
607 rightTailSum += w;
608 } else {
609 break;
610 }
611 }
612
613 fTFLower = ll;
614 fTFUpper = ul;
615 fTFConfLevel = 1 - (leftTailSum + rightTailSum) / fVecWeight;
616}
617
618////////////////////////////////////////////////////////////////////////////////
619
621{
622 if (fKeysPdf == nullptr)
624
625 if (fKeysPdf == nullptr) {
626 // if fKeysPdf is still nullptr, then it means CreateKeysPdf failed
627 // so clear all the data members this function would normally determine
628 // and return
629 fFull = 0.0;
630 fKeysCutoff = -1;
631 fKeysConfLevel = 0.0;
632 return;
633 }
634
635 // now we have a keys pdf of the posterior
636
637 double cutoff = 0.0;
638 fCutoffVar->setVal(cutoff);
639 double full = std::unique_ptr<RooAbsReal>{fProduct->createIntegral(fParameters, NormSet(fParameters))}->getVal(fParameters);
640 fFull = full;
641 if (full < 0.98) {
642 coutW(Eval) << "Warning: Integral of Keys PDF came out to " << full
643 << " instead of expected value 1. Will continue using this "
644 << "factor to normalize further integrals of this PDF." << std::endl;
645 }
646
647 // kbelasco: Is there a better way to set the search range?
648 // from 0 to max value of Keys
649 // kbelasco: how to get max value?
650 //double max = product.maxVal(product.getMaxVal(fParameters));
651
652 double volume = 1.0;
653 for (auto *var : static_range_cast<RooRealVar*>(fParameters))
654 volume *= (var->getMax() - var->getMin());
655
656 double topCutoff = full / volume;
657 double bottomCutoff = topCutoff;
658 double confLevel = CalcConfLevel(topCutoff, full);
659 if (AcceptableConfLevel(confLevel)) {
660 fKeysConfLevel = confLevel;
661 fKeysCutoff = topCutoff;
662 return;
663 }
664 bool changed = false;
665 // find high end of range
666 while (confLevel > fConfidenceLevel) {
667 topCutoff *= 2.0;
668 confLevel = CalcConfLevel(topCutoff, full);
669 if (AcceptableConfLevel(confLevel)) {
670 fKeysConfLevel = confLevel;
671 fKeysCutoff = topCutoff;
672 return;
673 }
674 changed = true;
675 }
676 if (changed) {
677 bottomCutoff = topCutoff / 2.0;
678 } else {
679 changed = false;
680 bottomCutoff /= 2.0;
681 confLevel = CalcConfLevel(bottomCutoff, full);
682 if (AcceptableConfLevel(confLevel)) {
683 fKeysConfLevel = confLevel;
684 fKeysCutoff = bottomCutoff;
685 return;
686 }
687 while (confLevel < fConfidenceLevel) {
688 bottomCutoff /= 2.0;
689 confLevel = CalcConfLevel(bottomCutoff, full);
690 if (AcceptableConfLevel(confLevel)) {
691 fKeysConfLevel = confLevel;
692 fKeysCutoff = bottomCutoff;
693 return;
694 }
695 changed = true;
696 }
697 if (changed) {
698 topCutoff = bottomCutoff * 2.0;
699 }
700 }
701
702 coutI(Eval) << "range set: [" << bottomCutoff << ", " << topCutoff << "]"
703 << std::endl;
704
705 cutoff = (topCutoff + bottomCutoff) / 2.0;
706 confLevel = CalcConfLevel(cutoff, full);
707
708 // need to use WithinDeltaFraction() because sometimes the integrating the
709 // posterior in this binary search seems to not have enough granularity to
710 // find an acceptable conf level (small no. of strange cases).
711 // WithinDeltaFraction causes the search to terminate when
712 // topCutoff is essentially equal to bottomCutoff (compared to the magnitude
713 // of their mean).
714 while (!AcceptableConfLevel(confLevel) &&
715 !WithinDeltaFraction(topCutoff, bottomCutoff)) {
716 if (confLevel > fConfidenceLevel) {
717 bottomCutoff = cutoff;
718 } else if (confLevel < fConfidenceLevel) {
719 topCutoff = cutoff;
720 }
721 cutoff = (topCutoff + bottomCutoff) / 2.0;
722 coutI(Eval) << "cutoff range: [" << bottomCutoff << ", "
723 << topCutoff << "]" << std::endl;
724 confLevel = CalcConfLevel(cutoff, full);
725 }
726
727 fKeysCutoff = cutoff;
728 fKeysConfLevel = confLevel;
729}
730
731////////////////////////////////////////////////////////////////////////////////
732
734{
735 if (fUseSparseHist) {
737 } else {
739 }
740}
741
742////////////////////////////////////////////////////////////////////////////////
743
745{
746 Long_t numBins;
747 if (fSparseHist == nullptr)
749
750 if (fSparseHist == nullptr) {
751 // if fSparseHist is still nullptr, then CreateSparseHist failed
752 fHistCutoff = -1;
753 fHistConfLevel = 0.0;
754 return;
755 }
756
757 numBins = (Long_t)fSparseHist->GetNbins();
758
759 std::vector<Long_t> bins(numBins);
760 for (Int_t ibin = 0; ibin < numBins; ibin++)
761 bins[ibin] = (Long_t)ibin;
762 std::stable_sort(bins.begin(), bins.end(), CompareSparseHistBins(fSparseHist.get()));
763
764 double nEntries = fSparseHist->GetSumw();
765 double sum = 0;
766 double content;
767 Int_t i;
768 // see above note on indexing to understand numBins - 3
769 for (i = numBins - 1; i >= 0; i--) {
770 content = fSparseHist->GetBinContent(bins[i]);
771 if ((sum + content) / nEntries >= fConfidenceLevel) {
772 fHistCutoff = content;
773 if (fIsHistStrict) {
774 sum += content;
775 i--;
776 break;
777 } else {
778 i++;
779 break;
780 }
781 }
782 sum += content;
783 }
784
785 if (fIsHistStrict) {
786 // keep going to find the sum
787 for ( ; i >= 0; i--) {
788 content = fSparseHist->GetBinContent(bins[i]);
789 if (content == fHistCutoff) {
790 sum += content;
791 } else {
792 break; // content must be < fHistCutoff
793 }
794 }
795 } else {
796 // backtrack to find the cutoff and sum
797 for ( ; i < numBins; i++) {
798 content = fSparseHist->GetBinContent(bins[i]);
799 if (content > fHistCutoff) {
800 fHistCutoff = content;
801 break;
802 } else { // content == fHistCutoff
803 sum -= content;
804 }
805 if (i == numBins - 1) {
806 // still haven't set fHistCutoff correctly yet, and we have no bins
807 // left, so set fHistCutoff to something higher than the tallest bin
808 fHistCutoff = content + 1.0;
809 }
810 }
811 }
812
813 fHistConfLevel = sum / nEntries;
814}
815
816////////////////////////////////////////////////////////////////////////////////
817
819{
820 Int_t numBins;
821 if (fDataHist == nullptr)
823 if (fDataHist == nullptr) {
824 // if fDataHist is still nullptr, then CreateDataHist failed
825 fHistCutoff = -1;
826 fHistConfLevel = 0.0;
827 return;
828 }
829
830 numBins = fDataHist->numEntries();
831
832 std::vector<Int_t> bins(numBins);
833 for (Int_t ibin = 0; ibin < numBins; ibin++)
834 bins[ibin] = ibin;
835 std::stable_sort(bins.begin(), bins.end(), CompareDataHistBins(fDataHist.get()));
836
837 double nEntries = fDataHist->sum(false);
838 double sum = 0;
839 double content;
840 Int_t i;
841 for (i = numBins - 1; i >= 0; i--) {
842 content = fDataHist->weight(bins[i]);
843 if ((sum + content) / nEntries >= fConfidenceLevel) {
844 fHistCutoff = content;
845 if (fIsHistStrict) {
846 sum += content;
847 i--;
848 break;
849 } else {
850 i++;
851 break;
852 }
853 }
854 sum += content;
855 }
856
857 if (fIsHistStrict) {
858 // keep going to find the sum
859 for ( ; i >= 0; i--) {
860 content = fDataHist->weight(bins[i]);
861 if (content == fHistCutoff) {
862 sum += content;
863 } else {
864 break; // content must be < fHistCutoff
865 }
866 }
867 } else {
868 // backtrack to find the cutoff and sum
869 for ( ; i < numBins; i++) {
870 content = fDataHist->weight(bins[i]);
871 if (content > fHistCutoff) {
872 fHistCutoff = content;
873 break;
874 } else { // content == fHistCutoff
875 sum -= content;
876 }
877 if (i == numBins - 1) {
878 // still haven't set fHistCutoff correctly yet, and we have no bins
879 // left, so set fHistCutoff to something higher than the tallest bin
880 fHistCutoff = content + 1.0;
881 }
882 }
883 }
884
885 fHistConfLevel = sum / nEntries;
886}
887
888////////////////////////////////////////////////////////////////////////////////
889
891{
892 if (fIntervalType == kShortest) {
893 if (fUseKeys) {
894 return fKeysConfLevel;
895 } else {
896 return fHistConfLevel;
897 }
898 } else if (fIntervalType == kTailFraction) {
899 return fTFConfLevel;
900 } else {
901 coutE(InputArguments) << "MCMCInterval::GetActualConfidenceLevel: "
902 << "not implemented for this type of interval. Returning 0." << std::endl;
903 return 0;
904 }
905}
906
907////////////////////////////////////////////////////////////////////////////////
908
910{
911 switch (fIntervalType) {
912 case kShortest:
913 return LowerLimitShortest(param);
914 case kTailFraction:
915 return LowerLimitTailFraction(param);
916 default:
917 coutE(InputArguments) << "MCMCInterval::LowerLimit(): " <<
918 "Error: Interval type not set" << std::endl;
919 return RooNumber::infinity();
920 }
921}
922
923////////////////////////////////////////////////////////////////////////////////
924
926{
927 switch (fIntervalType) {
928 case kShortest:
929 return UpperLimitShortest(param);
930 case kTailFraction:
931 return UpperLimitTailFraction(param);
932 default:
933 coutE(InputArguments) << "MCMCInterval::UpperLimit(): " <<
934 "Error: Interval type not set" << std::endl;
935 return RooNumber::infinity();
936 }
937}
938
939////////////////////////////////////////////////////////////////////////////////
940
942{
943 if (fTFLower == -1.0 * RooNumber::infinity())
945
946 return fTFLower;
947}
948
949////////////////////////////////////////////////////////////////////////////////
950
958
959////////////////////////////////////////////////////////////////////////////////
960
962{
963 if (fUseKeys) {
964 return LowerLimitByKeys(param);
965 } else {
966 return LowerLimitByHist(param);
967 }
968}
969
970////////////////////////////////////////////////////////////////////////////////
971
973{
974 if (fUseKeys) {
975 return UpperLimitByKeys(param);
976 } else {
977 return UpperLimitByHist(param);
978 }
979}
980
981////////////////////////////////////////////////////////////////////////////////
982/// Determine the lower limit for param on this interval
983/// using the binned data set
984
986{
987 if (fUseSparseHist) {
988 return LowerLimitBySparseHist(param);
989 } else {
990 return LowerLimitByDataHist(param);
991 }
992}
993
994////////////////////////////////////////////////////////////////////////////////
995/// Determine the upper limit for param on this interval
996/// using the binned data set
997
999{
1000 if (fUseSparseHist) {
1001 return UpperLimitBySparseHist(param);
1002 } else {
1003 return UpperLimitByDataHist(param);
1004 }
1005}
1006
1007////////////////////////////////////////////////////////////////////////////////
1008/// Determine the lower limit for param on this interval
1009/// using the binned data set
1010
1012{
1013 if (fDimension != 1) {
1014 coutE(InputArguments) << "In MCMCInterval::LowerLimitBySparseHist: "
1015 << "Sorry, will not compute lower limit unless dimension == 1" << std::endl;
1016 return param.getMin();
1017 }
1018 if (fHistCutoff < 0)
1019 DetermineBySparseHist(); // this initializes fSparseHist
1020
1021 if (fHistCutoff < 0) {
1022 // if fHistCutoff < 0 still, then determination of interval failed
1023 coutE(Eval) << "In MCMCInterval::LowerLimitBySparseHist: "
1024 << "couldn't determine cutoff. Check that num burn in steps < num "
1025 << "steps in the Markov chain. Returning param.getMin()." << std::endl;
1026 return param.getMin();
1027 }
1028
1029 std::vector<Int_t> coord(fDimension);
1030 for (Int_t d = 0; d < fDimension; d++) {
1031 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1032 Long_t numBins = (Long_t)fSparseHist->GetNbins();
1033 double lowerLimit = param.getMax();
1034 double val;
1035 for (Long_t i = 0; i < numBins; i++) {
1036 if (fSparseHist->GetBinContent(i, &coord[0]) >= fHistCutoff) {
1037 val = fSparseHist->GetAxis(d)->GetBinCenter(coord[d]);
1038 if (val < lowerLimit)
1039 lowerLimit = val;
1040 }
1041 }
1042 return lowerLimit;
1043 }
1044 }
1045 return param.getMin();
1046}
1047
1048////////////////////////////////////////////////////////////////////////////////
1049/// Determine the lower limit for param on this interval
1050/// using the binned data set
1051
1053{
1054 if (fHistCutoff < 0)
1055 DetermineByDataHist(); // this initializes fDataHist
1056
1057 if (fHistCutoff < 0) {
1058 // if fHistCutoff < 0 still, then determination of interval failed
1059 coutE(Eval) << "In MCMCInterval::LowerLimitByDataHist: "
1060 << "couldn't determine cutoff. Check that num burn in steps < num "
1061 << "steps in the Markov chain. Returning param.getMin()." << std::endl;
1062 return param.getMin();
1063 }
1064
1065 for (Int_t d = 0; d < fDimension; d++) {
1066 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1067 Int_t numBins = fDataHist->numEntries();
1068 double lowerLimit = param.getMax();
1069 double val;
1070 for (Int_t i = 0; i < numBins; i++) {
1071 if (fDataHist->weight(i) >= fHistCutoff) {
1072 val = fDataHist->get(i)->getRealValue(param.GetName());
1073 if (val < lowerLimit)
1074 lowerLimit = val;
1075 }
1076 }
1077 return lowerLimit;
1078 }
1079 }
1080 return param.getMin();
1081}
1082
1083////////////////////////////////////////////////////////////////////////////////
1084/// Determine the upper limit for param on this interval
1085/// using the binned data set
1086
1088{
1089 if (fDimension != 1) {
1090 coutE(InputArguments) << "In MCMCInterval::UpperLimitBySparseHist: "
1091 << "Sorry, will not compute upper limit unless dimension == 1" << std::endl;
1092 return param.getMax();
1093 }
1094 if (fHistCutoff < 0)
1095 DetermineBySparseHist(); // this initializes fSparseHist
1096
1097 if (fHistCutoff < 0) {
1098 // if fHistCutoff < 0 still, then determination of interval failed
1099 coutE(Eval) << "In MCMCInterval::UpperLimitBySparseHist: "
1100 << "couldn't determine cutoff. Check that num burn in steps < num "
1101 << "steps in the Markov chain. Returning param.getMax()." << std::endl;
1102 return param.getMax();
1103 }
1104
1105 std::vector<Int_t> coord(fDimension);
1106 for (Int_t d = 0; d < fDimension; d++) {
1107 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1108 Long_t numBins = (Long_t)fSparseHist->GetNbins();
1109 double upperLimit = param.getMin();
1110 double val;
1111 for (Long_t i = 0; i < numBins; i++) {
1112 if (fSparseHist->GetBinContent(i, &coord[0]) >= fHistCutoff) {
1113 val = fSparseHist->GetAxis(d)->GetBinCenter(coord[d]);
1114 if (val > upperLimit)
1115 upperLimit = val;
1116 }
1117 }
1118 return upperLimit;
1119 }
1120 }
1121 return param.getMax();
1122}
1123
1124////////////////////////////////////////////////////////////////////////////////
1125/// Determine the upper limit for param on this interval
1126/// using the binned data set
1127
1129{
1130 if (fHistCutoff < 0)
1131 DetermineByDataHist(); // this initializes fDataHist
1132
1133 if (fHistCutoff < 0) {
1134 // if fHistCutoff < 0 still, then determination of interval failed
1135 coutE(Eval) << "In MCMCInterval::UpperLimitByDataHist: "
1136 << "couldn't determine cutoff. Check that num burn in steps < num "
1137 << "steps in the Markov chain. Returning param.getMax()." << std::endl;
1138 return param.getMax();
1139 }
1140
1141 for (Int_t d = 0; d < fDimension; d++) {
1142 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1143 Int_t numBins = fDataHist->numEntries();
1144 double upperLimit = param.getMin();
1145 double val;
1146 for (Int_t i = 0; i < numBins; i++) {
1147 if (fDataHist->weight(i) >= fHistCutoff) {
1148 val = fDataHist->get(i)->getRealValue(param.GetName());
1149 if (val > upperLimit)
1150 upperLimit = val;
1151 }
1152 }
1153 return upperLimit;
1154 }
1155 }
1156 return param.getMax();
1157}
1158
1159////////////////////////////////////////////////////////////////////////////////
1160/// Determine the lower limit for param on this interval
1161/// using the keys pdf
1162
1164{
1165 if (fKeysCutoff < 0)
1167
1168 if (fKeysDataHist == nullptr)
1170
1171 if (fKeysCutoff < 0 || fKeysDataHist == nullptr) {
1172 // failure in determination of cutoff and/or creation of histogram
1173 coutE(Eval) << "in MCMCInterval::LowerLimitByKeys(): "
1174 << "couldn't find lower limit, check that the number of burn in "
1175 << "steps < number of total steps in the Markov chain. Returning "
1176 << "param.getMin()" << std::endl;
1177 return param.getMin();
1178 }
1179
1180 for (Int_t d = 0; d < fDimension; d++) {
1181 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1182 Int_t numBins = fKeysDataHist->numEntries();
1183 double lowerLimit = param.getMax();
1184 double val;
1185 for (Int_t i = 0; i < numBins; i++) {
1186 if (fKeysDataHist->weight(i) >= fKeysCutoff) {
1187 val = fKeysDataHist->get(i)->getRealValue(param.GetName());
1188 if (val < lowerLimit)
1189 lowerLimit = val;
1190 }
1191 }
1192 return lowerLimit;
1193 }
1194 }
1195 return param.getMin();
1196}
1197
1198////////////////////////////////////////////////////////////////////////////////
1199/// Determine the upper limit for param on this interval
1200/// using the keys pdf
1201
1203{
1204 if (fKeysCutoff < 0)
1206
1207 if (fKeysDataHist == nullptr)
1209
1210 if (fKeysCutoff < 0 || fKeysDataHist == nullptr) {
1211 // failure in determination of cutoff and/or creation of histogram
1212 coutE(Eval) << "in MCMCInterval::UpperLimitByKeys(): "
1213 << "couldn't find upper limit, check that the number of burn in "
1214 << "steps < number of total steps in the Markov chain. Returning "
1215 << "param.getMax()" << std::endl;
1216 return param.getMax();
1217 }
1218
1219 for (Int_t d = 0; d < fDimension; d++) {
1220 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1221 Int_t numBins = fKeysDataHist->numEntries();
1222 double upperLimit = param.getMin();
1223 double val;
1224 for (Int_t i = 0; i < numBins; i++) {
1225 if (fKeysDataHist->weight(i) >= fKeysCutoff) {
1226 val = fKeysDataHist->get(i)->getRealValue(param.GetName());
1227 if (val > upperLimit)
1228 upperLimit = val;
1229 }
1230 }
1231 return upperLimit;
1232 }
1233 }
1234 return param.getMax();
1235}
1236
1237////////////////////////////////////////////////////////////////////////////////
1238/// Determine the approximate maximum value of the Keys PDF
1239
1241{
1242 if (fKeysCutoff < 0)
1244
1245 if (fKeysDataHist == nullptr)
1247
1248 if (fKeysDataHist == nullptr) {
1249 // failure in determination of cutoff and/or creation of histogram
1250 coutE(Eval) << "in MCMCInterval::KeysMax(): "
1251 << "couldn't find Keys max value, check that the number of burn in "
1252 << "steps < number of total steps in the Markov chain. Returning 0"
1253 << std::endl;
1254 return 0;
1255 }
1256
1257 Int_t numBins = fKeysDataHist->numEntries();
1258 double max = 0;
1259 double w;
1260 for (Int_t i = 0; i < numBins; i++) {
1261 w = fKeysDataHist->weight(i);
1262 if (w > max)
1263 max = w;
1264 }
1265
1266 return max;
1267}
1268
1269////////////////////////////////////////////////////////////////////////////////
1270
1272{
1273 if (fHistCutoff < 0)
1275
1276 return fHistCutoff;
1277}
1278
1279////////////////////////////////////////////////////////////////////////////////
1280
1282{
1283 if (fKeysCutoff < 0)
1285
1286 // kbelasco: if fFull hasn't been set (because Keys creation failed because
1287 // fNumBurnInSteps >= fChain->Size()) then this will return infinity, which
1288 // seems ok to me since it will indicate error
1289
1290 return fKeysCutoff / fFull;
1291}
1292
1293////////////////////////////////////////////////////////////////////////////////
1294
1295double MCMCInterval::CalcConfLevel(double cutoff, double full)
1296{
1297 fCutoffVar->setVal(cutoff);
1298 std::unique_ptr<RooAbsReal> integral{fProduct->createIntegral(fParameters, NormSet(fParameters))};
1299 double confLevel = integral->getVal(fParameters) / full;
1300 coutI(Eval) << "cutoff = " << cutoff << ", conf = " << confLevel << std::endl;
1301 return confLevel;
1302}
1303
1304////////////////////////////////////////////////////////////////////////////////
1305
1307{
1308 if (fConfidenceLevel == 0) {
1309 coutE(InputArguments) << "Error in MCMCInterval::GetPosteriorHist: "
1310 << "confidence level not set " << std::endl;
1311 }
1312 if (fHist == nullptr)
1313 CreateHist();
1314
1315 if (fHist == nullptr) {
1316 // if fHist is still nullptr, then CreateHist failed
1317 return nullptr;
1318 }
1319
1320 return static_cast<TH1*>(fHist->Clone("MCMCposterior_hist"));
1321}
1322
1323////////////////////////////////////////////////////////////////////////////////
1324
1326{
1327 if (fConfidenceLevel == 0) {
1328 coutE(InputArguments) << "Error in MCMCInterval::GetPosteriorKeysPdf: "
1329 << "confidence level not set " << std::endl;
1330 }
1331 if (fKeysPdf == nullptr)
1332 CreateKeysPdf();
1333
1334 if (fKeysPdf == nullptr) {
1335 // if fKeysPdf is still nullptr, then it means CreateKeysPdf failed
1336 return nullptr;
1337 }
1338
1339 return static_cast<RooNDKeysPdf*>(fKeysPdf->Clone("MCMCPosterior_keys"));
1340}
1341
1342////////////////////////////////////////////////////////////////////////////////
1343
1345{
1346 if (fConfidenceLevel == 0) {
1347 coutE(InputArguments) << "MCMCInterval::GetPosteriorKeysProduct: "
1348 << "confidence level not set " << std::endl;
1349 }
1350 if (fProduct == nullptr) {
1351 CreateKeysPdf();
1353 }
1354
1355 if (fProduct == nullptr) {
1356 // if fProduct is still nullptr, then it means CreateKeysPdf failed
1357 return nullptr;
1358 }
1359
1360 return static_cast<RooProduct*>(fProduct->Clone("MCMCPosterior_keysproduct"));
1361}
1362
1363////////////////////////////////////////////////////////////////////////////////
1364
1366{
1367 // returns list of parameters
1368 return new RooArgSet(fParameters);
1369}
1370
1371////////////////////////////////////////////////////////////////////////////////
1372
1374{
1375 return (std::abs(confLevel - fConfidenceLevel) < fEpsilon);
1376}
1377
1378////////////////////////////////////////////////////////////////////////////////
1379
1381{
1382 return (std::abs(a - b) < std::abs(fDelta * (a + b)/2));
1383}
1384
1385////////////////////////////////////////////////////////////////////////////////
1386
1388{
1389 if (fAxes.empty())
1390 return;
1391 if (fProduct == nullptr)
1393 if (fProduct == nullptr) {
1394 // if fProduct still nullptr, then creation failed
1395 return;
1396 }
1397
1398 //RooAbsBinning** savedBinning = new RooAbsBinning*[fDimension];
1399 std::vector<Int_t> savedBins(fDimension);
1400 Int_t i;
1401 double numBins;
1402 RooRealVar* var;
1403
1404 // kbelasco: Note - the accuracy is only increased here if the binning for
1405 // each RooRealVar is uniform
1406
1407 // kbelasco: look into why saving the binnings and replacing them doesn't
1408 // work (replaces with 1 bin always).
1409 // Note: this code modifies the binning for the parameters (if they are
1410 // uniform) and sets them back to what they were. If the binnings are not
1411 // uniform, this code does nothing.
1412
1413 // first scan through fAxes to make sure all binnings are uniform, or else
1414 // we can't change the number of bins because there seems to be an error
1415 // when setting the binning itself rather than just the number of bins
1416 bool tempChangeBinning = true;
1417 for (i = 0; i < fDimension; i++) {
1418 if (!fAxes[i]->getBinning(nullptr, false, false).isUniform()) {
1419 tempChangeBinning = false;
1420 break;
1421 }
1422 }
1423
1424 // kbelasco: for 1 dimension this should be fine, but for more dimensions
1425 // the total number of bins in the histogram increases exponentially with
1426 // the dimension, so don't do this above 1-D for now.
1427 if (fDimension >= 2)
1428 tempChangeBinning = false;
1429
1430 if (tempChangeBinning) {
1431 // set high number of bins for high accuracy on lower/upper limit by keys
1432 for (i = 0; i < fDimension; i++) {
1433 var = fAxes[i];
1434 //savedBinning[i] = &var->getBinning("__binning_clone", false, true);
1435 savedBins[i] = var->getBinning(nullptr, false, false).numBins();
1436 numBins = (var->getMax() - var->getMin()) / fEpsilon;
1437 var->setBins((Int_t)numBins);
1438 }
1439 }
1440
1441 fKeysDataHist = std::make_unique<RooDataHist>("_productDataHist",
1442 "Keys PDF & Heaviside Product Data Hist", fParameters);
1443 fProduct->fillDataHist(fKeysDataHist.get(), &fParameters, 1.);
1444
1445 if (tempChangeBinning) {
1446 // set the binning back to normal
1447 for (i = 0; i < fDimension; i++) {
1448 //fAxes[i]->setBinning(*savedBinning[i], nullptr);
1449 //fAxes[i]->setBins(savedBinning[i]->numBins(), nullptr);
1450 fAxes[i]->setBins(savedBins[i], nullptr);
1451 }
1452 }
1453}
1454
1455////////////////////////////////////////////////////////////////////////////////
1456
1457bool MCMCInterval::CheckParameters(const RooArgSet& parameterPoint) const
1458{
1459 // check that the parameters are correct
1460
1461 if (parameterPoint.size() != fParameters.size() ) {
1462 coutE(Eval) << "MCMCInterval: size is wrong, parameters don't match" << std::endl;
1463 return false;
1464 }
1465 if ( ! parameterPoint.equals( fParameters ) ) {
1466 coutE(Eval) << "MCMCInterval: size is ok, but parameters don't match" << std::endl;
1467 return false;
1468 }
1469 return true;
1470}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define coutI(a)
#define coutW(a)
#define coutE(a)
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:84
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition TGX11.cxx:142
Int_t numBins() const
Return number of bins.
bool equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
double getRealValue(const char *name, double defVal=0.0, bool verbose=false) const
Get value of a RooAbsReal stored in set with given name.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:40
Container class to hold unbinned data.
Definition RooDataSet.h:32
RooFit::OwningPtr< RooDataHist > binnedClone(const char *newName=nullptr, const char *newTitle=nullptr) const
Return binned clone of this dataset.
Generic N-dimensional implementation of a kernel estimation p.d.f.
static constexpr double infinity()
Return internal infinity representation.
Definition RooNumber.h:25
Represents the product of a given set of RooAbsReal objects.
Definition RooProduct.h:29
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setBins(Int_t nBins, const char *name=nullptr, bool shared=true)
Create a uniform binning under name 'name' for this variable.
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false, bool shared=true) const override
Return binning definition with name.
ConfInterval is an interface class for a generic interval in the RooStats framework.
virtual void CreateDataHist()
virtual void DetermineByDataHist()
virtual void DetermineShortestInterval()
virtual double GetActualConfidenceLevel()
virtual double GetKeysPdfCutoff() { return fKeysCutoff; }
double fKeysConfLevel
the actual conf level determined by keys
virtual void CreateVector(RooRealVar *param)
std::unique_ptr< Heaviside > fHeaviside
the Heaviside function
virtual double LowerLimitByDataHist(RooRealVar &param)
determine lower limit using histogram
double fDelta
topCutoff (a) considered == bottomCutoff (b) iff (std::abs(a - b) < std::abs(fDelta * (a + b)/2)); Th...
double fConfidenceLevel
Requested confidence level (eg. 0.95 for 95% CL)
virtual double UpperLimitBySparseHist(RooRealVar &param)
determine upper limit using histogram
std::unique_ptr< MarkovChain > fChain
the markov chain
enum IntervalType fIntervalType
virtual double UpperLimit(RooRealVar &param)
get the highest value of param that is within the confidence interval
std::unique_ptr< RooDataHist > fDataHist
the binned Markov Chain data
virtual void SetAxes(RooArgList &axes)
Set which parameters go on which axis.
virtual void DetermineByKeys()
double fTFLower
lower limit of the tail-fraction interval
bool fUseSparseHist
whether to use sparse hist (vs. RooDataHist)
double fVecWeight
sum of weights of all entries in fVector
double fLeftSideTF
left side tail-fraction for interval
bool AcceptableConfLevel(double confLevel)
virtual void DetermineBySparseHist()
double GetKeysMax()
Determine the approximate maximum value of the Keys PDF.
virtual double LowerLimitBySparseHist(RooRealVar &param)
determine lower limit using histogram
bool WithinDeltaFraction(double a, double b)
double fKeysCutoff
cutoff keys pdf value to be in interval
virtual double LowerLimitShortest(RooRealVar &param)
get the lower limit of param in the shortest confidence interval Note that this works better for some...
virtual double LowerLimitTailFraction(RooRealVar &param)
determine lower limit of the lower confidence interval
virtual TH1 * GetPosteriorHist()
set the number of bins to use (same for all axes, for now) virtual void SetNumBins(Int_t numBins);
std::unique_ptr< RooRealVar > fCutoffVar
cutoff variable to use for integrating keys pdf
Int_t fDimension
number of variables
void SetConfidenceLevel(double cl) override
set the desired confidence level (see GetActualConfidenceLevel()) Note: calling this function trigger...
MCMCInterval(const char *name=nullptr)
default constructor
std::unique_ptr< RooProduct > fProduct
the (keysPdf * heaviside) product
std::vector< RooRealVar * > fAxes
array of pointers to RooRealVars representing
virtual void DetermineTailFractionInterval()
double fTFConfLevel
the actual conf level of tail-fraction interval
double fHistConfLevel
the actual conf level determined by hist
virtual void CreateSparseHist()
double fFull
Value of intergral of fProduct.
std::unique_ptr< RooDataHist > fKeysDataHist
data hist representing product
virtual double UpperLimitByDataHist(RooRealVar &param)
determine upper limit using histogram
virtual void DetermineInterval()
std::unique_ptr< TH1 > fHist
the binned Markov Chain data
virtual double CalcConfLevel(double cutoff, double full)
virtual double LowerLimitByHist(RooRealVar &param)
determine lower limit using histogram
virtual double LowerLimit(RooRealVar &param)
get the lowest value of param that is within the confidence interval
virtual double UpperLimitShortest(RooRealVar &param)
get the upper limit of param in the confidence interval Note that this works better for some distribu...
bool CheckParameters(const RooArgSet &point) const override
check if parameters are correct. (dummy implementation to start)
std::vector< Int_t > fVector
vector containing the Markov chain data
virtual double LowerLimitByKeys(RooRealVar &param)
determine lower limit in the shortest interval by using keys pdf
virtual RooProduct * GetPosteriorKeysProduct()
Get a clone of the (keyspdf * heaviside) product of the posterior.
double fTFUpper
upper limit of the tail-fraction interval
double fHistCutoff
cutoff bin size to be in interval
RooArgSet * GetParameters() const override
return a set containing the parameters of this interval the caller owns the returned RooArgSet*
std::unique_ptr< RooNDKeysPdf > fKeysPdf
the kernel estimation pdf
virtual double UpperLimitTailFraction(RooRealVar &param)
determine upper limit of the lower confidence interval
bool fIsHistStrict
whether the specified confidence level is a floor for the actual confidence level (strict),...
virtual RooNDKeysPdf * GetPosteriorKeysPdf()
Get a clone of the keys pdf of the posterior.
virtual double UpperLimitByHist(RooRealVar &param)
determine upper limit using histogram
virtual void CreateKeysPdf()
virtual double UpperLimitByKeys(RooRealVar &param)
determine upper limit in the shortest interval by using keys pdf
Int_t fNumBurnInSteps
number of steps to discard as burn in, starting from the first
std::unique_ptr< THnSparse > fSparseHist
the binned Markov Chain data
virtual void CreateHist()
bool fUseKeys
whether to use kernel estimation
RooArgSet fParameters
parameters of interest for this interval
bool IsInInterval(const RooArgSet &point) const override
determine whether this point is in the confidence interval
virtual void DetermineByHist()
virtual void SetParameters(const RooArgSet &parameters)
Set the parameters of interest for this interval and change other internal data members accordingly.
virtual void CreateKeysDataHist()
double fEpsilon
acceptable error for Keys interval determination
virtual double GetKeysPdfCutoff()
get the cutoff RooNDKeysPdf value for being considered in the confidence interval
virtual double GetHistCutoff()
get the cutoff bin height for being considered in the confidence interval
Stores the steps in a Markov Chain of points.
Definition MarkovChain.h:26
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:907
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:125
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
3-D histogram with a float per channel (see TH1 documentation)
Definition TH3.h:369
Efficient multidimensional histogram.
Definition THnSparse.h:37
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
RooCmdArg SelectVars(const RooArgSet &vars)
RooCmdArg EventRange(Int_t nStart, Int_t nStop)
RooCmdArg NormSet(Args_t &&... argsOrArgSet)
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:73
@ InputArguments
Namespace for the RooStats classes.
Definition CodegenImpl.h:67
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
RooDataHist * fDataHist
CompareDataHistBins(RooDataHist *hist)
CompareSparseHistBins(THnSparse *hist)
CompareVectorIndices(MarkovChain *chain, RooRealVar *param)
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2335