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
101 : ConfInterval(name), fChain(&chain), fTFLower(-RooNumber::infinity()), fTFUpper(RooNumber::infinity())
102{
103 fVector.clear();
104 SetParameters(parameters);
105}
106
107////////////////////////////////////////////////////////////////////////////////
108
110{
111 // destructor
112 delete[] fAxes;
113 delete fHist;
114 delete fChain;
115 // kbelasco: check here for memory management errors
116 delete fDataHist;
117 delete fSparseHist;
118 delete fKeysPdf;
119 delete fProduct;
120 delete fHeaviside;
121 delete fKeysDataHist;
122 delete fCutoffVar;
123}
124
126 CompareDataHistBins(RooDataHist* hist) : fDataHist(hist) {}
128 fDataHist->get(bin1);
129 double n1 = fDataHist->weight();
130 fDataHist->get(bin2);
131 double n2 = fDataHist->weight();
132 return (n1 < n2);
133 }
135};
136
138 CompareSparseHistBins(THnSparse* hist) : fSparseHist(hist) {}
140 double n1 = fSparseHist->GetBinContent(bin1);
141 double n2 = fSparseHist->GetBinContent(bin2);
142 return (n1 < n2);
143 }
145};
146
149 fChain(chain), fParam(param) {}
151 double xi = fChain->Get(i)->getRealValue(fParam->GetName());
152 double xj = fChain->Get(j)->getRealValue(fParam->GetName());
153 return (xi < xj);
154 }
157};
158
159////////////////////////////////////////////////////////////////////////////////
160/// kbelasco: for this method, consider running DetermineInterval() if
161/// fKeysPdf==nullptr, fSparseHist==nullptr, fDataHist==nullptr, or fVector.empty()
162/// rather than just returning false. Though this should not be an issue
163/// because nobody should be able to get an MCMCInterval that has their interval
164/// or posterior representation nullptr/empty since they should only get this
165/// through the MCMCCalculator
166
167bool MCMCInterval::IsInInterval(const RooArgSet& point) const
168{
169 if (fIntervalType == kShortest) {
170 if (fUseKeys) {
171 if (fKeysPdf == nullptr)
172 return false;
173
174 // evaluate keyspdf at point and return whether >= cutoff
175 RooStats::SetParameters(&point, const_cast<RooArgSet *>(&fParameters));
177 } else {
178 if (fUseSparseHist) {
179 if (fSparseHist == nullptr)
180 return false;
181
182 // evaluate sparse hist at bin where point lies and return
183 // whether >= cutoff
185 const_cast<RooArgSet*>(&fParameters));
186 Long_t bin;
187 // kbelasco: consider making x static
188 std::vector<double> x(fDimension);
189 for (Int_t i = 0; i < fDimension; i++)
190 x[i] = fAxes[i]->getVal();
191 bin = fSparseHist->GetBin(x.data(), false);
192 double weight = fSparseHist->GetBinContent((Long64_t)bin);
193 return (weight >= (double)fHistCutoff);
194 } else {
195 if (fDataHist == nullptr)
196 return false;
197
198 // evaluate data hist at bin where point lies and return whether
199 // >= cutoff
200 Int_t bin;
201 bin = fDataHist->getIndex(point);
202 fDataHist->get(bin);
203 return (fDataHist->weight() >= (double)fHistCutoff);
204 }
205 }
206 } else if (fIntervalType == kTailFraction) {
207 if (fVector.empty())
208 return false;
209
210 // return whether value of point is within the range
211 double x = point.getRealValue(fAxes[0]->GetName());
212 if (fTFLower <= x && x <= fTFUpper)
213 return true;
214
215 return false;
216 }
217
218 coutE(InputArguments) << "Error in MCMCInterval::IsInInterval: "
219 << "Interval type not set. Returning false." << std::endl;
220 return false;
221}
222
223////////////////////////////////////////////////////////////////////////////////
224
226{
227 fConfidenceLevel = cl;
229}
230
231// kbelasco: update this or just take it out
232// kbelasco: consider keeping this around but changing the implementation
233// to set the number of bins for each RooRealVar and then recreating the
234// histograms
235//void MCMCInterval::SetNumBins(Int_t numBins)
236//{
237// if (numBins > 0) {
238// fPreferredNumBins = numBins;
239// for (Int_t d = 0; d < fDimension; d++)
240// fNumBins[d] = numBins;
241// }
242// else {
243// coutE(Eval) << "* Error in MCMCInterval::SetNumBins: " <<
244// "Negative number of bins given: " << numBins << std::endl;
245// return;
246// }
247//
248// // If the histogram already exists, recreate it with the new bin numbers
249// if (fHist != nullptr)
250// CreateHist();
251//}
252
253////////////////////////////////////////////////////////////////////////////////
254
256{
257 Int_t size = axes.size();
258 if (size != fDimension) {
259 coutE(InputArguments) << "* Error in MCMCInterval::SetAxes: " <<
260 "number of variables in axes (" << size <<
261 ") doesn't match number of parameters ("
262 << fDimension << ")" << std::endl;
263 return;
264 }
265 for (Int_t i = 0; i < size; i++)
266 fAxes[i] = static_cast<RooRealVar*>(axes.at(i));
267}
268
269////////////////////////////////////////////////////////////////////////////////
270
272{
273 // kbelasco: check here for memory leak. does RooNDKeysPdf use
274 // the RooArgList passed to it or does it make a clone?
275 // also check for memory leak from chain, does RooNDKeysPdf clone that?
276 if (fAxes == nullptr || fParameters.empty()) {
277 coutE(InputArguments) << "Error in MCMCInterval::CreateKeysPdf: "
278 << "parameters have not been set." << std::endl;
279 return;
280 }
281
282 if (fNumBurnInSteps >= fChain->Size()) {
284 "MCMCInterval::CreateKeysPdf: creation of Keys PDF failed: " <<
285 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
286 "in Markov chain." << std::endl;
287 delete fKeysPdf;
288 delete fCutoffVar;
289 delete fHeaviside;
290 delete fProduct;
291 fKeysPdf = nullptr;
292 fCutoffVar = nullptr;
293 fHeaviside = nullptr;
294 fProduct = nullptr;
295 return;
296 }
297
298 std::unique_ptr<RooAbsData> chain{fChain->GetAsConstDataSet()->reduce(SelectVars(fParameters), EventRange(fNumBurnInSteps, fChain->Size()))};
299
301 for (Int_t i = 0; i < fDimension; i++)
302 paramsList->add(*fAxes[i]);
303
304 fKeysPdf = new RooNDKeysPdf("keysPDF", "Keys PDF", *paramsList, static_cast<RooDataSet&>(*chain), "a");
305 fCutoffVar = new RooRealVar("cutoff", "cutoff", 0);
306 fHeaviside = new Heaviside("heaviside", "Heaviside", *fKeysPdf, *fCutoffVar);
307 fProduct = new RooProduct("product", "Keys PDF & Heaviside Product",
309}
310
311////////////////////////////////////////////////////////////////////////////////
312
314{
315 if (fAxes == nullptr || fChain == nullptr) {
316 coutE(Eval) << "* Error in MCMCInterval::CreateHist(): " <<
317 "Crucial data member was nullptr." << std::endl;
318 coutE(Eval) << "Make sure to fully construct/initialize." << std::endl;
319 return;
320 }
321 if (fHist != nullptr) {
322 delete fHist;
323 fHist = nullptr;
324 }
325
326 if (fNumBurnInSteps >= fChain->Size()) {
328 "MCMCInterval::CreateHist: creation of histogram failed: " <<
329 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
330 "in Markov chain." << std::endl;
331 return;
332 }
333
334 if (fDimension == 1) {
335 fHist = new TH1F("posterior", "MCMC Posterior Histogram",
336 fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax());
337
338 } else if (fDimension == 2) {
339 fHist = new TH2F("posterior", "MCMC Posterior Histogram",
340 fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax(),
341 fAxes[1]->numBins(), fAxes[1]->getMin(), fAxes[1]->getMax());
342
343 } else if (fDimension == 3) {
344 fHist = new TH3F("posterior", "MCMC Posterior Histogram",
345 fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax(),
346 fAxes[1]->numBins(), fAxes[1]->getMin(), fAxes[1]->getMax(),
347 fAxes[2]->numBins(), fAxes[2]->getMin(), fAxes[2]->getMax());
348
349 } else {
350 coutE(Eval) << "* Error in MCMCInterval::CreateHist() : " <<
351 "TH1* couldn't handle dimension: " << fDimension << std::endl;
352 return;
353 }
354
355 // Fill histogram
356 Int_t size = fChain->Size();
357 const RooArgSet* entry;
358 for (Int_t i = fNumBurnInSteps; i < size; i++) {
359 entry = fChain->Get(i);
360 if (fDimension == 1) {
361 (static_cast<TH1F*>(fHist))->Fill(entry->getRealValue(fAxes[0]->GetName()),
362 fChain->Weight());
363 } else if (fDimension == 2) {
364 (static_cast<TH2F*>(fHist))->Fill(entry->getRealValue(fAxes[0]->GetName()),
365 entry->getRealValue(fAxes[1]->GetName()),
366 fChain->Weight());
367 } else {
368 (static_cast<TH3F *>(fHist))
369 ->Fill(entry->getRealValue(fAxes[0]->GetName()), entry->getRealValue(fAxes[1]->GetName()),
370 entry->getRealValue(fAxes[2]->GetName()), fChain->Weight());
371 }
372 }
373
374 if (fDimension >= 1)
376 if (fDimension >= 2)
378 if (fDimension >= 3)
380}
381
382////////////////////////////////////////////////////////////////////////////////
383
385{
386 if (fAxes == nullptr || fChain == nullptr) {
387 coutE(InputArguments) << "* Error in MCMCInterval::CreateSparseHist(): "
388 << "Crucial data member was nullptr." << std::endl;
389 coutE(InputArguments) << "Make sure to fully construct/initialize."
390 << std::endl;
391 return;
392 }
393 if (fSparseHist != nullptr)
394 delete fSparseHist;
395
396 std::vector<double> min(fDimension);
397 std::vector<double> max(fDimension);
398 std::vector<Int_t> bins(fDimension);
399 for (Int_t i = 0; i < fDimension; i++) {
400 min[i] = fAxes[i]->getMin();
401 max[i] = fAxes[i]->getMax();
402 bins[i] = fAxes[i]->numBins();
403 }
404 fSparseHist = new THnSparseF("posterior", "MCMC Posterior Histogram",
405 fDimension, bins.data(), min.data(), max.data());
406
407 // kbelasco: it appears we need to call Sumw2() just to get the
408 // histogram to keep a running total of the weight so that Getsumw doesn't
409 // just return 0
411
412 if (fNumBurnInSteps >= fChain->Size()) {
414 "MCMCInterval::CreateSparseHist: creation of histogram failed: " <<
415 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
416 "in Markov chain." << std::endl;
417 }
418
419 // Fill histogram
420 Int_t size = fChain->Size();
421 const RooArgSet* entry;
422 std::vector<double> x(fDimension);
423 for (Int_t i = fNumBurnInSteps; i < size; i++) {
424 entry = fChain->Get(i);
425 for (Int_t ii = 0; ii < fDimension; ii++)
426 x[ii] = entry->getRealValue(fAxes[ii]->GetName());
427 fSparseHist->Fill(x.data(), fChain->Weight());
428 }
429}
430
431////////////////////////////////////////////////////////////////////////////////
432
434{
435 if (fParameters.empty() || fChain == nullptr) {
436 coutE(Eval) << "* Error in MCMCInterval::CreateDataHist(): " <<
437 "Crucial data member was nullptr or empty." << std::endl;
438 coutE(Eval) << "Make sure to fully construct/initialize." << std::endl;
439 return;
440 }
441
442 if (fNumBurnInSteps >= fChain->Size()) {
444 "MCMCInterval::CreateDataHist: creation of histogram failed: " <<
445 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
446 "in Markov chain." << std::endl;
447 fDataHist = nullptr;
448 return;
449 }
450
451 std::unique_ptr<RooAbsData> data{fChain->GetAsConstDataSet()->reduce(SelectVars(fParameters), EventRange(fNumBurnInSteps, fChain->Size()))};
452 fDataHist = static_cast<RooDataSet &>(*data).binnedClone();
453}
454
455////////////////////////////////////////////////////////////////////////////////
456
458{
459 fVector.clear();
460 fVecWeight = 0;
461
462 if (fChain == nullptr) {
463 coutE(InputArguments) << "* Error in MCMCInterval::CreateVector(): " <<
464 "Crucial data member (Markov chain) was nullptr." << std::endl;
465 coutE(InputArguments) << "Make sure to fully construct/initialize."
466 << std::endl;
467 return;
468 }
469
470 if (fNumBurnInSteps >= fChain->Size()) {
472 "MCMCInterval::CreateVector: creation of vector failed: " <<
473 "Number of burn-in steps (num steps to ignore) >= number of steps " <<
474 "in Markov chain." << std::endl;
475 }
476
477 // Fill vector
479 fVector.resize(size);
480 Int_t i;
482 for (i = 0; i < size; i++) {
484 fVector[i] = chainIndex;
486 }
487
488 stable_sort(fVector.begin(), fVector.end(),
490}
491
492////////////////////////////////////////////////////////////////////////////////
493
495{
497 fParameters.add(parameters);
499 if (fAxes != nullptr)
500 delete[] fAxes;
502 Int_t n = 0;
503 for (auto *obj : fParameters) {
504 if (dynamic_cast<RooRealVar *>(obj) != nullptr) {
505 fAxes[n] = static_cast<RooRealVar*>(obj);
506 } else {
507 coutE(Eval) << "* Error in MCMCInterval::SetParameters: " << obj->GetName() << " not a RooRealVar*"
508 << std::endl;
509 }
510 n++;
511 }
512}
513
514////////////////////////////////////////////////////////////////////////////////
515
517{
518 switch (fIntervalType) {
519 case kShortest:
521 break;
522 case kTailFraction:
524 break;
525 default:
526 coutE(InputArguments) << "MCMCInterval::DetermineInterval(): " <<
527 "Error: Interval type not set" << std::endl;
528 break;
529 }
530}
531
532////////////////////////////////////////////////////////////////////////////////
533
535{
536 if (fUseKeys) {
538 } else {
540 }
541}
542
543////////////////////////////////////////////////////////////////////////////////
544
546{
548 coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval: "
549 << "Fraction must be in the range [0, 1]. "
550 << fLeftSideTF << "is not allowed." << std::endl;
551 return;
552 }
553
554 if (fDimension != 1) {
555 coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval(): "
556 << "Error: Can only find a tail-fraction interval for 1-D intervals"
557 << std::endl;
558 return;
559 }
560
561 if (fAxes == nullptr) {
562 coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval(): "
563 << "Crucial data member was nullptr." << std::endl;
564 coutE(InputArguments) << "Make sure to fully construct/initialize."
565 << std::endl;
566 return;
567 }
568
569 // kbelasco: fill in code here to find interval
570 //
571 // also make changes so that calling GetPosterior...() returns nullptr
572 // when fIntervalType == kTailFraction, since there really
573 // is no posterior for this type of interval determination
574 if (fVector.empty())
576
577 if (fVector.empty() || fVecWeight == 0) {
578 // if size is still 0, then creation failed.
579 // if fVecWeight == 0, then there are no entries (indicates the same
580 // error as fVector.empty() because that only happens when
581 // fNumBurnInSteps >= fChain->Size())
582 // either way, reset and return
583 fVector.clear();
584 fTFLower = -1.0 * RooNumber::infinity();
586 fTFConfLevel = 0.0;
587 fVecWeight = 0;
588 return;
589 }
590
591 RooRealVar* param = fAxes[0];
592
593 double c = fConfidenceLevel;
594 double leftTailCutoff = fVecWeight * (1 - c) * fLeftSideTF;
595 double rightTailCutoff = fVecWeight * (1 - c) * (1 - fLeftSideTF);
596 double leftTailSum = 0;
597 double rightTailSum = 0;
598
599 // kbelasco: consider changing these values to +infinity and -infinity
600 double ll = param->getMin();
601 double ul = param->getMax();
602
603 double x;
604 double w;
605
606 // save a lot of GetName() calls if compiler does not already optimize this
607 const char* name = param->GetName();
608
609 // find lower limit
610 Int_t i;
611 for (i = 0; i < (Int_t)fVector.size(); i++) {
612 x = fChain->Get(fVector[i])->getRealValue(name);
613 w = fChain->Weight();
614
615 if (std::abs(leftTailSum + w - leftTailCutoff) <
616 std::abs(leftTailSum - leftTailCutoff)) {
617 // moving the lower limit to x would bring us closer to the desired
618 // left tail size
619 ll = x;
620 leftTailSum += w;
621 } else
622 break;
623 }
624
625 // find upper limit
626 for (i = (Int_t)fVector.size() - 1; i >= 0; i--) {
627 x = fChain->Get(fVector[i])->getRealValue(name);
628 w = fChain->Weight();
629
630 if (std::abs(rightTailSum + w - rightTailCutoff) <
631 std::abs(rightTailSum - rightTailCutoff)) {
632 // moving the lower limit to x would bring us closer to the desired
633 // left tail size
634 ul = x;
635 rightTailSum += w;
636 } else
637 break;
638 }
639
640 fTFLower = ll;
641 fTFUpper = ul;
643}
644
645////////////////////////////////////////////////////////////////////////////////
646
648{
649 if (fKeysPdf == nullptr)
651
652 if (fKeysPdf == nullptr) {
653 // if fKeysPdf is still nullptr, then it means CreateKeysPdf failed
654 // so clear all the data members this function would normally determine
655 // and return
656 fFull = 0.0;
657 fKeysCutoff = -1;
658 fKeysConfLevel = 0.0;
659 return;
660 }
661
662 // now we have a keys pdf of the posterior
663
664 double cutoff = 0.0;
666 double full = std::unique_ptr<RooAbsReal>{fProduct->createIntegral(fParameters, NormSet(fParameters))}->getVal(fParameters);
667 fFull = full;
668 if (full < 0.98) {
669 coutW(Eval) << "Warning: Integral of Keys PDF came out to " << full
670 << " instead of expected value 1. Will continue using this "
671 << "factor to normalize further integrals of this PDF." << std::endl;
672 }
673
674 // kbelasco: Is there a better way to set the search range?
675 // from 0 to max value of Keys
676 // kbelasco: how to get max value?
677 //double max = product.maxVal(product.getMaxVal(fParameters));
678
679 double volume = 1.0;
681 volume *= (var->getMax() - var->getMin());
682
683 double topCutoff = full / volume;
684 double bottomCutoff = topCutoff;
685 double confLevel = CalcConfLevel(topCutoff, full);
689 return;
690 }
691 bool changed = false;
692 // find high end of range
693 while (confLevel > fConfidenceLevel) {
694 topCutoff *= 2.0;
699 return;
700 }
701 changed = true;
702 }
703 if (changed) {
704 bottomCutoff = topCutoff / 2.0;
705 } else {
706 changed = false;
707 bottomCutoff /= 2.0;
712 return;
713 }
714 while (confLevel < fConfidenceLevel) {
715 bottomCutoff /= 2.0;
720 return;
721 }
722 changed = true;
723 }
724 if (changed) {
725 topCutoff = bottomCutoff * 2.0;
726 }
727 }
728
729 coutI(Eval) << "range set: [" << bottomCutoff << ", " << topCutoff << "]"
730 << std::endl;
731
732 cutoff = (topCutoff + bottomCutoff) / 2.0;
734
735 // need to use WithinDeltaFraction() because sometimes the integrating the
736 // posterior in this binary search seems to not have enough granularity to
737 // find an acceptable conf level (small no. of strange cases).
738 // WithinDeltaFraction causes the search to terminate when
739 // topCutoff is essentially equal to bottomCutoff (compared to the magnitude
740 // of their mean).
745 } else if (confLevel < fConfidenceLevel) {
747 }
748 cutoff = (topCutoff + bottomCutoff) / 2.0;
749 coutI(Eval) << "cutoff range: [" << bottomCutoff << ", "
750 << topCutoff << "]" << std::endl;
752 }
753
756}
757
758////////////////////////////////////////////////////////////////////////////////
759
761{
762 if (fUseSparseHist) {
764 } else {
766 }
767}
768
769////////////////////////////////////////////////////////////////////////////////
770
772{
773 Long_t numBins;
774 if (fSparseHist == nullptr)
776
777 if (fSparseHist == nullptr) {
778 // if fSparseHist is still nullptr, then CreateSparseHist failed
779 fHistCutoff = -1;
780 fHistConfLevel = 0.0;
781 return;
782 }
783
784 numBins = (Long_t)fSparseHist->GetNbins();
785
786 std::vector<Long_t> bins(numBins);
787 for (Int_t ibin = 0; ibin < numBins; ibin++)
788 bins[ibin] = (Long_t)ibin;
789 std::stable_sort(bins.begin(), bins.end(), CompareSparseHistBins(fSparseHist));
790
791 double nEntries = fSparseHist->GetSumw();
792 double sum = 0;
793 double content;
794 Int_t i;
795 // see above note on indexing to understand numBins - 3
796 for (i = numBins - 1; i >= 0; i--) {
798 if ((sum + content) / nEntries >= fConfidenceLevel) {
800 if (fIsHistStrict) {
801 sum += content;
802 i--;
803 break;
804 } else {
805 i++;
806 break;
807 }
808 }
809 sum += content;
810 }
811
812 if (fIsHistStrict) {
813 // keep going to find the sum
814 for ( ; i >= 0; i--) {
816 if (content == fHistCutoff) {
817 sum += content;
818 } else {
819 break; // content must be < fHistCutoff
820 }
821 }
822 } else {
823 // backtrack to find the cutoff and sum
824 for ( ; i < numBins; i++) {
826 if (content > fHistCutoff) {
828 break;
829 } else // content == fHistCutoff
830 sum -= content;
831 if (i == numBins - 1) {
832 // still haven't set fHistCutoff correctly yet, and we have no bins
833 // left, so set fHistCutoff to something higher than the tallest bin
834 fHistCutoff = content + 1.0;
835 }
836 }
837 }
838
840}
841
842////////////////////////////////////////////////////////////////////////////////
843
845{
846 Int_t numBins;
847 if (fDataHist == nullptr)
849 if (fDataHist == nullptr) {
850 // if fDataHist is still nullptr, then CreateDataHist failed
851 fHistCutoff = -1;
852 fHistConfLevel = 0.0;
853 return;
854 }
855
856 numBins = fDataHist->numEntries();
857
858 std::vector<Int_t> bins(numBins);
859 for (Int_t ibin = 0; ibin < numBins; ibin++)
860 bins[ibin] = ibin;
861 std::stable_sort(bins.begin(), bins.end(), CompareDataHistBins(fDataHist));
862
863 double nEntries = fDataHist->sum(false);
864 double sum = 0;
865 double content;
866 Int_t i;
867 for (i = numBins - 1; i >= 0; i--) {
868 fDataHist->get(bins[i]);
870 if ((sum + content) / nEntries >= fConfidenceLevel) {
872 if (fIsHistStrict) {
873 sum += content;
874 i--;
875 break;
876 } else {
877 i++;
878 break;
879 }
880 }
881 sum += content;
882 }
883
884 if (fIsHistStrict) {
885 // keep going to find the sum
886 for ( ; i >= 0; i--) {
887 fDataHist->get(bins[i]);
889 if (content == fHistCutoff) {
890 sum += content;
891 } else {
892 break; // content must be < fHistCutoff
893 }
894 }
895 } else {
896 // backtrack to find the cutoff and sum
897 for ( ; i < numBins; i++) {
898 fDataHist->get(bins[i]);
900 if (content > fHistCutoff) {
902 break;
903 } else // content == fHistCutoff
904 sum -= content;
905 if (i == numBins - 1) {
906 // still haven't set fHistCutoff correctly yet, and we have no bins
907 // left, so set fHistCutoff to something higher than the tallest bin
908 fHistCutoff = content + 1.0;
909 }
910 }
911 }
912
914}
915
916////////////////////////////////////////////////////////////////////////////////
917
919{
920 if (fIntervalType == kShortest) {
921 if (fUseKeys) {
922 return fKeysConfLevel;
923 } else {
924 return fHistConfLevel;
925 }
926 } else if (fIntervalType == kTailFraction) {
927 return fTFConfLevel;
928 } else {
929 coutE(InputArguments) << "MCMCInterval::GetActualConfidenceLevel: "
930 << "not implemented for this type of interval. Returning 0." << std::endl;
931 return 0;
932 }
933}
934
935////////////////////////////////////////////////////////////////////////////////
936
938{
939 switch (fIntervalType) {
940 case kShortest:
941 return LowerLimitShortest(param);
942 case kTailFraction:
943 return LowerLimitTailFraction(param);
944 default:
945 coutE(InputArguments) << "MCMCInterval::LowerLimit(): " <<
946 "Error: Interval type not set" << std::endl;
947 return RooNumber::infinity();
948 }
949}
950
951////////////////////////////////////////////////////////////////////////////////
952
954{
955 switch (fIntervalType) {
956 case kShortest:
957 return UpperLimitShortest(param);
958 case kTailFraction:
959 return UpperLimitTailFraction(param);
960 default:
961 coutE(InputArguments) << "MCMCInterval::UpperLimit(): " <<
962 "Error: Interval type not set" << std::endl;
963 return RooNumber::infinity();
964 }
965}
966
967////////////////////////////////////////////////////////////////////////////////
968
970{
971 if (fTFLower == -1.0 * RooNumber::infinity())
973
974 return fTFLower;
975}
976
977////////////////////////////////////////////////////////////////////////////////
978
986
987////////////////////////////////////////////////////////////////////////////////
988
990{
991 if (fUseKeys) {
992 return LowerLimitByKeys(param);
993 } else {
994 return LowerLimitByHist(param);
995 }
996}
997
998////////////////////////////////////////////////////////////////////////////////
999
1001{
1002 if (fUseKeys) {
1003 return UpperLimitByKeys(param);
1004 } else {
1005 return UpperLimitByHist(param);
1006 }
1007}
1008
1009////////////////////////////////////////////////////////////////////////////////
1010/// Determine the lower limit for param on this interval
1011/// using the binned data set
1012
1014{
1015 if (fUseSparseHist) {
1016 return LowerLimitBySparseHist(param);
1017 } else {
1018 return LowerLimitByDataHist(param);
1019 }
1020}
1021
1022////////////////////////////////////////////////////////////////////////////////
1023/// Determine the upper limit for param on this interval
1024/// using the binned data set
1025
1027{
1028 if (fUseSparseHist) {
1029 return UpperLimitBySparseHist(param);
1030 } else {
1031 return UpperLimitByDataHist(param);
1032 }
1033}
1034
1035////////////////////////////////////////////////////////////////////////////////
1036/// Determine the lower limit for param on this interval
1037/// using the binned data set
1038
1040{
1041 if (fDimension != 1) {
1042 coutE(InputArguments) << "In MCMCInterval::LowerLimitBySparseHist: "
1043 << "Sorry, will not compute lower limit unless dimension == 1" << std::endl;
1044 return param.getMin();
1045 }
1046 if (fHistCutoff < 0)
1047 DetermineBySparseHist(); // this initializes fSparseHist
1048
1049 if (fHistCutoff < 0) {
1050 // if fHistCutoff < 0 still, then determination of interval failed
1051 coutE(Eval) << "In MCMCInterval::LowerLimitBySparseHist: "
1052 << "couldn't determine cutoff. Check that num burn in steps < num "
1053 << "steps in the Markov chain. Returning param.getMin()." << std::endl;
1054 return param.getMin();
1055 }
1056
1057 std::vector<Int_t> coord(fDimension);
1058 for (Int_t d = 0; d < fDimension; d++) {
1059 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1060 Long_t numBins = (Long_t)fSparseHist->GetNbins();
1061 double lowerLimit = param.getMax();
1062 double val;
1063 for (Long_t i = 0; i < numBins; i++) {
1064 if (fSparseHist->GetBinContent(i, &coord[0]) >= fHistCutoff) {
1066 if (val < lowerLimit)
1067 lowerLimit = val;
1068 }
1069 }
1070 return lowerLimit;
1071 }
1072 }
1073 return param.getMin();
1074}
1075
1076////////////////////////////////////////////////////////////////////////////////
1077/// Determine the lower limit for param on this interval
1078/// using the binned data set
1079
1081{
1082 if (fHistCutoff < 0)
1083 DetermineByDataHist(); // this initializes fDataHist
1084
1085 if (fHistCutoff < 0) {
1086 // if fHistCutoff < 0 still, then determination of interval failed
1087 coutE(Eval) << "In MCMCInterval::LowerLimitByDataHist: "
1088 << "couldn't determine cutoff. Check that num burn in steps < num "
1089 << "steps in the Markov chain. Returning param.getMin()." << std::endl;
1090 return param.getMin();
1091 }
1092
1093 for (Int_t d = 0; d < fDimension; d++) {
1094 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1095 Int_t numBins = fDataHist->numEntries();
1096 double lowerLimit = param.getMax();
1097 double val;
1098 for (Int_t i = 0; i < numBins; i++) {
1099 fDataHist->get(i);
1100 if (fDataHist->weight() >= fHistCutoff) {
1101 val = fDataHist->get()->getRealValue(param.GetName());
1102 if (val < lowerLimit)
1103 lowerLimit = val;
1104 }
1105 }
1106 return lowerLimit;
1107 }
1108 }
1109 return param.getMin();
1110}
1111
1112////////////////////////////////////////////////////////////////////////////////
1113/// Determine the upper limit for param on this interval
1114/// using the binned data set
1115
1117{
1118 if (fDimension != 1) {
1119 coutE(InputArguments) << "In MCMCInterval::UpperLimitBySparseHist: "
1120 << "Sorry, will not compute upper limit unless dimension == 1" << std::endl;
1121 return param.getMax();
1122 }
1123 if (fHistCutoff < 0)
1124 DetermineBySparseHist(); // this initializes fSparseHist
1125
1126 if (fHistCutoff < 0) {
1127 // if fHistCutoff < 0 still, then determination of interval failed
1128 coutE(Eval) << "In MCMCInterval::UpperLimitBySparseHist: "
1129 << "couldn't determine cutoff. Check that num burn in steps < num "
1130 << "steps in the Markov chain. Returning param.getMax()." << std::endl;
1131 return param.getMax();
1132 }
1133
1134 std::vector<Int_t> coord(fDimension);
1135 for (Int_t d = 0; d < fDimension; d++) {
1136 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1137 Long_t numBins = (Long_t)fSparseHist->GetNbins();
1138 double upperLimit = param.getMin();
1139 double val;
1140 for (Long_t i = 0; i < numBins; i++) {
1141 if (fSparseHist->GetBinContent(i, &coord[0]) >= fHistCutoff) {
1143 if (val > upperLimit)
1144 upperLimit = val;
1145 }
1146 }
1147 return upperLimit;
1148 }
1149 }
1150 return param.getMax();
1151}
1152
1153////////////////////////////////////////////////////////////////////////////////
1154/// Determine the upper limit for param on this interval
1155/// using the binned data set
1156
1158{
1159 if (fHistCutoff < 0)
1160 DetermineByDataHist(); // this initializes fDataHist
1161
1162 if (fHistCutoff < 0) {
1163 // if fHistCutoff < 0 still, then determination of interval failed
1164 coutE(Eval) << "In MCMCInterval::UpperLimitByDataHist: "
1165 << "couldn't determine cutoff. Check that num burn in steps < num "
1166 << "steps in the Markov chain. Returning param.getMax()." << std::endl;
1167 return param.getMax();
1168 }
1169
1170 for (Int_t d = 0; d < fDimension; d++) {
1171 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1172 Int_t numBins = fDataHist->numEntries();
1173 double upperLimit = param.getMin();
1174 double val;
1175 for (Int_t i = 0; i < numBins; i++) {
1176 fDataHist->get(i);
1177 if (fDataHist->weight() >= fHistCutoff) {
1178 val = fDataHist->get()->getRealValue(param.GetName());
1179 if (val > upperLimit)
1180 upperLimit = val;
1181 }
1182 }
1183 return upperLimit;
1184 }
1185 }
1186 return param.getMax();
1187}
1188
1189////////////////////////////////////////////////////////////////////////////////
1190/// Determine the lower limit for param on this interval
1191/// using the keys pdf
1192
1194{
1195 if (fKeysCutoff < 0)
1197
1198 if (fKeysDataHist == nullptr)
1200
1201 if (fKeysCutoff < 0 || fKeysDataHist == nullptr) {
1202 // failure in determination of cutoff and/or creation of histogram
1203 coutE(Eval) << "in MCMCInterval::LowerLimitByKeys(): "
1204 << "couldn't find lower limit, check that the number of burn in "
1205 << "steps < number of total steps in the Markov chain. Returning "
1206 << "param.getMin()" << std::endl;
1207 return param.getMin();
1208 }
1209
1210 for (Int_t d = 0; d < fDimension; d++) {
1211 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1212 Int_t numBins = fKeysDataHist->numEntries();
1213 double lowerLimit = param.getMax();
1214 double val;
1215 for (Int_t i = 0; i < numBins; i++) {
1216 fKeysDataHist->get(i);
1217 if (fKeysDataHist->weight() >= fKeysCutoff) {
1218 val = fKeysDataHist->get()->getRealValue(param.GetName());
1219 if (val < lowerLimit)
1220 lowerLimit = val;
1221 }
1222 }
1223 return lowerLimit;
1224 }
1225 }
1226 return param.getMin();
1227}
1228
1229////////////////////////////////////////////////////////////////////////////////
1230/// Determine the upper limit for param on this interval
1231/// using the keys pdf
1232
1234{
1235 if (fKeysCutoff < 0)
1237
1238 if (fKeysDataHist == nullptr)
1240
1241 if (fKeysCutoff < 0 || fKeysDataHist == nullptr) {
1242 // failure in determination of cutoff and/or creation of histogram
1243 coutE(Eval) << "in MCMCInterval::UpperLimitByKeys(): "
1244 << "couldn't find upper limit, check that the number of burn in "
1245 << "steps < number of total steps in the Markov chain. Returning "
1246 << "param.getMax()" << std::endl;
1247 return param.getMax();
1248 }
1249
1250 for (Int_t d = 0; d < fDimension; d++) {
1251 if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1252 Int_t numBins = fKeysDataHist->numEntries();
1253 double upperLimit = param.getMin();
1254 double val;
1255 for (Int_t i = 0; i < numBins; i++) {
1256 fKeysDataHist->get(i);
1257 if (fKeysDataHist->weight() >= fKeysCutoff) {
1258 val = fKeysDataHist->get()->getRealValue(param.GetName());
1259 if (val > upperLimit)
1260 upperLimit = val;
1261 }
1262 }
1263 return upperLimit;
1264 }
1265 }
1266 return param.getMax();
1267}
1268
1269////////////////////////////////////////////////////////////////////////////////
1270/// Determine the approximate maximum value of the Keys PDF
1271
1273{
1274 if (fKeysCutoff < 0)
1276
1277 if (fKeysDataHist == nullptr)
1279
1280 if (fKeysDataHist == nullptr) {
1281 // failure in determination of cutoff and/or creation of histogram
1282 coutE(Eval) << "in MCMCInterval::KeysMax(): "
1283 << "couldn't find Keys max value, check that the number of burn in "
1284 << "steps < number of total steps in the Markov chain. Returning 0"
1285 << std::endl;
1286 return 0;
1287 }
1288
1289 Int_t numBins = fKeysDataHist->numEntries();
1290 double max = 0;
1291 double w;
1292 for (Int_t i = 0; i < numBins; i++) {
1293 fKeysDataHist->get(i);
1294 w = fKeysDataHist->weight();
1295 if (w > max)
1296 max = w;
1297 }
1298
1299 return max;
1300}
1301
1302////////////////////////////////////////////////////////////////////////////////
1303
1305{
1306 if (fHistCutoff < 0)
1308
1309 return fHistCutoff;
1310}
1311
1312////////////////////////////////////////////////////////////////////////////////
1313
1315{
1316 if (fKeysCutoff < 0)
1318
1319 // kbelasco: if fFull hasn't been set (because Keys creation failed because
1320 // fNumBurnInSteps >= fChain->Size()) then this will return infinity, which
1321 // seems ok to me since it will indicate error
1322
1323 return fKeysCutoff / fFull;
1324}
1325
1326////////////////////////////////////////////////////////////////////////////////
1327
1328double MCMCInterval::CalcConfLevel(double cutoff, double full)
1329{
1331 std::unique_ptr<RooAbsReal> integral{fProduct->createIntegral(fParameters, NormSet(fParameters))};
1332 double confLevel = integral->getVal(fParameters) / full;
1333 coutI(Eval) << "cutoff = " << cutoff << ", conf = " << confLevel << std::endl;
1334 return confLevel;
1335}
1336
1337////////////////////////////////////////////////////////////////////////////////
1338
1340{
1341 if (fConfidenceLevel == 0) {
1342 coutE(InputArguments) << "Error in MCMCInterval::GetPosteriorHist: "
1343 << "confidence level not set " << std::endl;
1344 }
1345 if (fHist == nullptr)
1346 CreateHist();
1347
1348 if (fHist == nullptr) {
1349 // if fHist is still nullptr, then CreateHist failed
1350 return nullptr;
1351 }
1352
1353 return static_cast<TH1*>(fHist->Clone("MCMCposterior_hist"));
1354}
1355
1356////////////////////////////////////////////////////////////////////////////////
1357
1359{
1360 if (fConfidenceLevel == 0) {
1361 coutE(InputArguments) << "Error in MCMCInterval::GetPosteriorKeysPdf: "
1362 << "confidence level not set " << std::endl;
1363 }
1364 if (fKeysPdf == nullptr)
1365 CreateKeysPdf();
1366
1367 if (fKeysPdf == nullptr) {
1368 // if fKeysPdf is still nullptr, then it means CreateKeysPdf failed
1369 return nullptr;
1370 }
1371
1372 return static_cast<RooNDKeysPdf*>(fKeysPdf->Clone("MCMCPosterior_keys"));
1373}
1374
1375////////////////////////////////////////////////////////////////////////////////
1376
1378{
1379 if (fConfidenceLevel == 0) {
1380 coutE(InputArguments) << "MCMCInterval::GetPosteriorKeysProduct: "
1381 << "confidence level not set " << std::endl;
1382 }
1383 if (fProduct == nullptr) {
1384 CreateKeysPdf();
1386 }
1387
1388 if (fProduct == nullptr) {
1389 // if fProduct is still nullptr, then it means CreateKeysPdf failed
1390 return nullptr;
1391 }
1392
1393 return static_cast<RooProduct*>(fProduct->Clone("MCMCPosterior_keysproduct"));
1394}
1395
1396////////////////////////////////////////////////////////////////////////////////
1397
1399{
1400 // returns list of parameters
1401 return new RooArgSet(fParameters);
1402}
1403
1404////////////////////////////////////////////////////////////////////////////////
1405
1407{
1408 return (std::abs(confLevel - fConfidenceLevel) < fEpsilon);
1409}
1410
1411////////////////////////////////////////////////////////////////////////////////
1412
1414{
1415 return (std::abs(a - b) < std::abs(fDelta * (a + b)/2));
1416}
1417
1418////////////////////////////////////////////////////////////////////////////////
1419
1421{
1422 if (fAxes == nullptr)
1423 return;
1424 if (fProduct == nullptr)
1426 if (fProduct == nullptr) {
1427 // if fProduct still nullptr, then creation failed
1428 return;
1429 }
1430
1431 //RooAbsBinning** savedBinning = new RooAbsBinning*[fDimension];
1432 std::vector<Int_t> savedBins(fDimension);
1433 Int_t i;
1434 double numBins;
1435 RooRealVar* var;
1436
1437 // kbelasco: Note - the accuracy is only increased here if the binning for
1438 // each RooRealVar is uniform
1439
1440 // kbelasco: look into why saving the binnings and replacing them doesn't
1441 // work (replaces with 1 bin always).
1442 // Note: this code modifies the binning for the parameters (if they are
1443 // uniform) and sets them back to what they were. If the binnings are not
1444 // uniform, this code does nothing.
1445
1446 // first scan through fAxes to make sure all binnings are uniform, or else
1447 // we can't change the number of bins because there seems to be an error
1448 // when setting the binning itself rather than just the number of bins
1449 bool tempChangeBinning = true;
1450 for (i = 0; i < fDimension; i++) {
1451 if (!fAxes[i]->getBinning(nullptr, false, false).isUniform()) {
1452 tempChangeBinning = false;
1453 break;
1454 }
1455 }
1456
1457 // kbelasco: for 1 dimension this should be fine, but for more dimensions
1458 // the total number of bins in the histogram increases exponentially with
1459 // the dimension, so don't do this above 1-D for now.
1460 if (fDimension >= 2)
1461 tempChangeBinning = false;
1462
1463 if (tempChangeBinning) {
1464 // set high number of bins for high accuracy on lower/upper limit by keys
1465 for (i = 0; i < fDimension; i++) {
1466 var = fAxes[i];
1467 //savedBinning[i] = &var->getBinning("__binning_clone", false, true);
1468 savedBins[i] = var->getBinning(nullptr, false, false).numBins();
1469 numBins = (var->getMax() - var->getMin()) / fEpsilon;
1470 var->setBins((Int_t)numBins);
1471 }
1472 }
1473
1474 fKeysDataHist = new RooDataHist("_productDataHist",
1475 "Keys PDF & Heaviside Product Data Hist", fParameters);
1477
1478 if (tempChangeBinning) {
1479 // set the binning back to normal
1480 for (i = 0; i < fDimension; i++) {
1481 //fAxes[i]->setBinning(*savedBinning[i], nullptr);
1482 //fAxes[i]->setBins(savedBinning[i]->numBins(), nullptr);
1483 fAxes[i]->setBins(savedBins[i], nullptr);
1484 }
1485 }
1486}
1487
1488////////////////////////////////////////////////////////////////////////////////
1489
1491{
1492 // check that the parameters are correct
1493
1494 if (parameterPoint.size() != fParameters.size() ) {
1495 coutE(Eval) << "MCMCInterval: size is wrong, parameters don't match" << std::endl;
1496 return false;
1497 }
1498 if ( ! parameterPoint.equals( fParameters ) ) {
1499 coutE(Eval) << "MCMCInterval: size is ok, but parameters don't match" << std::endl;
1500 return false;
1501 }
1502 return true;
1503}
#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
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition TGX11.cxx:110
THnSparseT< TArrayF > THnSparseF
Definition THnSparse.h:222
TRObject operator()(const T1 &t1) const
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:89
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 Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Int_t numBins(const char *rangeName=nullptr) const override
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.
RooDataHist * fillDataHist(RooDataHist *hist, const RooArgSet *nset, double scaleFactor, bool correctForBinVolume=false, bool showProgress=false) const
Fill a RooDataHist with values sampled from this function at the bin centers.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
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
double sum(bool correctForBinSize, bool inverseCorr=false) const
Return the sum of the weights of all bins in the histogram.
Int_t getIndex(const RooAbsCollection &coord, bool fast=false) const
Calculate bin number of the given coordinates.
double weight(std::size_t i) const
Return weight of i-th bin.
const RooArgSet * get() const override
Get bin centre of current bin.
Definition RooDataHist.h:82
Container class to hold unbinned data.
Definition RooDataSet.h:34
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.
Provides numeric constants used in RooFit.
Definition RooNumber.h:22
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 setVal(double value) override
Set value of variable to 'value'.
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
void setBins(Int_t nBins, const char *name=nullptr)
Create a uniform binning under name 'name' for this variable.
ConfInterval is an interface class for a generic interval in the RooStats framework.
Represents the Heaviside function.
Definition Heaviside.h:21
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)
RooDataHist * fDataHist
the binned Markov Chain data
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)
TH1 * fHist
the binned Markov Chain data
virtual double UpperLimitBySparseHist(RooRealVar &param)
determine upper limit using histogram
enum IntervalType fIntervalType
virtual double UpperLimit(RooRealVar &param)
get the highest value of param that is within the confidence interval
RooRealVar * fCutoffVar
cutoff variable to use for integrating keys pdf
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.
RooProduct * fProduct
the (keysPdf * heaviside) product
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);
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
RooRealVar ** fAxes
array of pointers to RooRealVars representing the axes of the histogram fAxes[0] represents x-axis,...
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()
Heaviside * fHeaviside
the Heaviside function
double fFull
Value of intergral of fProduct.
virtual double UpperLimitByDataHist(RooRealVar &param)
determine upper limit using histogram
virtual void DetermineInterval()
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...
THnSparse * fSparseHist
the binned Markov Chain data
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
MarkovChain * fChain
the markov chain
RooArgSet * GetParameters() const override
return a set containing the parameters of this interval the caller owns the returned RooArgSet*
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
virtual void CreateHist()
bool fUseKeys
whether to use kernel estimation
RooDataHist * fKeysDataHist
data hist representing product
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()
RooNDKeysPdf * fKeysPdf
the kernel estimation pdf
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
virtual const RooArgSet * Get(Int_t i) const
get the entry at position i
Definition MarkovChain.h:47
virtual double Weight() const
get the weight of the current (last indexed) entry
virtual const RooDataSet * GetAsConstDataSet() const
Definition MarkovChain.h:64
virtual Int_t Size() const
get the number of steps in the chain
Definition MarkovChain.h:45
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:482
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:647
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
TAxis * GetZaxis()
Definition TH1.h:343
TAxis * GetXaxis()
Definition TH1.h:341
TAxis * GetYaxis()
Definition TH1.h:342
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2723
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
3-D histogram with a float per channel (see TH1 documentation)
Definition TH3.h:317
Long64_t Fill(const Double_t *x, Double_t w=1.)
Definition THnBase.h:153
Double_t GetSumw() const
Definition THnBase.h:217
TAxis * GetAxis(Int_t dim) const
Definition THnBase.h:134
Efficient multidimensional histogram.
Definition THnSparse.h:37
Double_t GetBinContent(const Int_t *idx) const
Forwards to THnBase::GetBinContent() overload.
Definition THnSparse.h:126
Long64_t GetBin(const Int_t *idx) const override
Definition THnSparse.h:101
void Sumw2() override
Enable calculation of errors.
Long64_t GetNbins() const override
Definition THnSparse.h:98
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:174
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:64
@ InputArguments
Namespace for the RooStats classes.
Definition CodegenImpl.h:58
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:2345