Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MCMCIntervalPlot.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 * Project: RooStats *
6 * Package: RooFit/RooStats *
7 *************************************************************************
8 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
15/** \class RooStats::MCMCIntervalPlot
16 \ingroup Roostats
17
18This class provides simple and straightforward utilities to plot a MCMCInterval
19object. Basic use only requires a few lines once you have an MCMCInterval*:
20
21~~~ {.cpp}
22 MCMCIntervalPlot plot(*interval);
23 plot.Draw();
24~~~
25
26The standard Draw() function will currently draw the confidence interval
27range with bars if 1-D and a contour if 2-D. The MCMC posterior will also be
28plotted for the 1-D case.
29
30*/
31
35
36#include "TLine.h"
37#include "TGraph.h"
38#include "RooRealVar.h"
39#include "RooPlot.h"
40#include "TH2.h"
41#include "TH1F.h"
42#include "RooArgList.h"
43#include "TAxis.h"
44#include "RooGlobalFunc.h"
45
46#include <iostream>
47
48// Extra draw commands
49//static const char* POSTERIOR_HIST = "posterior_hist";
50//static const char* POSTERIOR_KEYS_PDF = "posterior_keys_pdf";
51//static const char* POSTERIOR_KEYS_PRODUCT = "posterior_keys_product";
52//static const char* HIST_INTERVAL = "hist_interval";
53//static const char* KEYS_PDF_INTERVAL = "keys_pdf_interval";
54//static const char* TAIL_FRACTION_INTERVAL = "tail_fraction_interval";
55//static const char* OPTION_SEP = ":";
56
58
59using namespace std;
60using namespace RooStats;
61
62////////////////////////////////////////////////////////////////////////////////
63
65{
66 fInterval = nullptr;
67 fParameters = nullptr;
68 fPosteriorHist = nullptr;
69 fPosteriorKeysPdf = nullptr;
70 fPosteriorKeysProduct = nullptr;
71 fDimension = 0;
74 fLineWidth = 1;
75 //fContourColor = kBlack;
76 fShowBurnIn = true;
77 fWalk = nullptr;
78 fBurnIn = nullptr;
79 fFirst = nullptr;
80 fParamGraph = nullptr;
81 fNLLGraph = nullptr;
82 fNLLHist = nullptr;
83 fWeightHist = nullptr;
84 fPosteriorHistHistCopy = nullptr;
85 fPosteriorHistTFCopy = nullptr;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89
91{
92 SetMCMCInterval(interval);
93 fPosteriorHist = nullptr;
94 fPosteriorKeysPdf = nullptr;
95 fPosteriorKeysProduct = nullptr;
98 fLineWidth = 1;
99 //fContourColor = kBlack;
100 fShowBurnIn = true;
101 fWalk = nullptr;
102 fBurnIn = nullptr;
103 fFirst = nullptr;
104 fParamGraph = nullptr;
105 fNLLGraph = nullptr;
106 fNLLHist = nullptr;
107 fWeightHist = nullptr;
108 fPosteriorHistHistCopy = nullptr;
109 fPosteriorHistTFCopy = nullptr;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113
115{
116 delete fParameters;
117 // kbelasco: why does deleting fPosteriorHist remove the graphics
118 // but deleting TGraphs doesn't?
119 //delete fPosteriorHist;
120 // can we delete fNLLHist and fWeightHist?
121 //delete fNLLHist;
122 //delete fWeightHist;
123
124 // kbelasco: should we delete fPosteriorKeysPdf and fPosteriorKeysProduct?
125 delete fPosteriorKeysPdf;
127
128 delete fWalk;
129 delete fBurnIn;
130 delete fFirst;
131 delete fParamGraph;
132 delete fNLLGraph;
133}
134
135////////////////////////////////////////////////////////////////////////////////
136
138{
139 fInterval = &interval;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145
147{
148 DrawInterval(options);
149}
150
151////////////////////////////////////////////////////////////////////////////////
152
154{
155 if (fInterval->GetUseKeys())
156 DrawPosteriorKeysPdf(options);
157 else
158 DrawPosteriorHist(options);
159}
160
161////////////////////////////////////////////////////////////////////////////////
162
164 const char* title, bool scale)
165{
166 if (fPosteriorHist == nullptr)
168
169 if (fPosteriorHist == nullptr) {
170 coutE(InputArguments) << "MCMCIntervalPlot::DrawPosteriorHist: "
171 << "Couldn't get posterior histogram." << endl;
172 return nullptr;
173 }
174
175 // kbelasco: annoying hack because histogram drawing fails when it sees
176 // an un-recognized option like POSTERIOR_HIST, etc.
177 //const Option_t* myOpt = nullptr;
178
179 //TString tmpOpt(options);
180 //if (tmpOpt.Contains("same"))
181 // myOpt = "same";
182
183 // scale so highest bin has height 1
184 if (scale)
187
188 TString ourTitle(GetTitle());
189 if (ourTitle.CompareTo("") == 0) {
190 if (title)
191 fPosteriorHist->SetTitle(title);
192 } else
194
195 //fPosteriorHist->Draw(myOpt);
196
197 return (void*)fPosteriorHist;
198}
199
200////////////////////////////////////////////////////////////////////////////////
201
203{
204 if (fPosteriorKeysPdf == nullptr)
206
207 if (fPosteriorKeysPdf == nullptr) {
208 coutE(InputArguments) << "MCMCIntervalPlot::DrawPosteriorKeysPdf: "
209 << "Couldn't get posterior Keys PDF." << endl;
210 return nullptr;
211 }
212
213 TString title(GetTitle());
214 bool isEmpty = (title.CompareTo("") == 0);
215
216 if (fDimension == 1) {
218 RooPlot* frame = v->frame();
219 if (frame == nullptr) {
220 coutE(InputArguments) << "MCMCIntervalPlot::DrawPosteriorKeysPdf: "
221 << "Invalid parameter" << endl;
222 return nullptr;
223 }
224 if (isEmpty)
225 frame->SetTitle(("Posterior Keys PDF for " + std::string(v->GetName())).c_str());
226 else
227 frame->SetTitle(GetTitle());
228 //fPosteriorKeysPdf->plotOn(frame);
229 //fPosteriorKeysPdf->plotOn(frame,
230 // RooFit::Normalization(1, RooAbsReal::Raw));
231 //frame->Draw(options);
232 return (void*)frame;
233 } else if (fDimension == 2) {
234 RooArgList* axes = fInterval->GetAxes();
235 RooRealVar* xVar = (RooRealVar*)axes->at(0);
236 RooRealVar* yVar = (RooRealVar*)axes->at(1);
238 "keysPlot2D", *xVar, RooFit::YVar(*yVar), RooFit::Scaling(false));
239 if (isEmpty)
240 keysHist->SetTitle(
241 Form("MCMC histogram of posterior Keys PDF for %s, %s",
242 axes->at(0)->GetName(), axes->at(1)->GetName()));
243 else
244 keysHist->SetTitle(GetTitle());
245
246 keysHist->Draw(options);
247 delete axes;
248 return nullptr;
249 }
250 return nullptr;
251}
252
253////////////////////////////////////////////////////////////////////////////////
254
256{
257 switch (fInterval->GetIntervalType()) {
259 DrawShortestInterval(options);
260 break;
263 break;
264 default:
265 coutE(InputArguments) << "MCMCIntervalPlot::DrawInterval(): " <<
266 "Interval type not supported" << endl;
267 break;
268 }
269}
270
271////////////////////////////////////////////////////////////////////////////////
272
274{
275 if (fInterval->GetUseKeys())
276 DrawKeysPdfInterval(options);
277 else
278 DrawHistInterval(options);
279}
280
281////////////////////////////////////////////////////////////////////////////////
282
284{
285 TString title(GetTitle());
286 bool isEmpty = (title.CompareTo("") == 0);
287
288 if (fDimension == 1) {
289 // Draw the posterior keys PDF as well so the user can see where the
290 // limit bars line up
291 // fDimension == 1, so we know we will receive a RooPlot
292 RooPlot* frame = (RooPlot*)DrawPosteriorKeysPdf(options);
293
294 //double height = 1;
295 //double height = 2.0 * fInterval->GetKeysPdfCutoff();
296 double height = fInterval->GetKeysMax();
297
299 double ul = fInterval->UpperLimitByKeys(*p);
300 double ll = fInterval->LowerLimitByKeys(*p);
301
302 if (frame != nullptr && fPosteriorKeysPdf != nullptr) {
303 // draw shading in interval
304 if (isEmpty)
305 frame->SetTitle(nullptr);
306 else
307 frame->SetTitle(GetTitle());
308 frame->GetYaxis()->SetTitle(("Posterior for parameter " + std::string(p->GetName())).c_str());
311 RooFit::Range(ll, ul, false),
316
317 // hack - this is drawn twice now:
318 // once by DrawPosteriorKeysPdf (which also configures things and sets
319 // the title), and once again here so the shading shows up behind.
322 }
323 if (frame) {
324 frame->Draw(options);
325 }
326
327 TLine* llLine = new TLine(ll, 0, ll, height);
328 TLine* ulLine = new TLine(ul, 0, ul, height);
329 llLine->SetLineColor(fLineColor);
330 ulLine->SetLineColor(fLineColor);
331 llLine->SetLineWidth(fLineWidth);
332 ulLine->SetLineWidth(fLineWidth);
333 llLine->Draw(options);
334 ulLine->Draw(options);
335 } else if (fDimension == 2) {
336 if (fPosteriorKeysPdf == nullptr)
338
339 if (fPosteriorKeysPdf == nullptr) {
340 coutE(InputArguments) << "MCMCIntervalPlot::DrawKeysPdfInterval: "
341 << "Couldn't get posterior Keys PDF." << endl;
342 return;
343 }
344
345 RooArgList* axes = fInterval->GetAxes();
346 RooRealVar* xVar = (RooRealVar*)axes->at(0);
347 RooRealVar* yVar = (RooRealVar*)axes->at(1);
349 "keysContour2D", *xVar, RooFit::YVar(*yVar), RooFit::Scaling(false));
350 //if (isEmpty)
351 // contHist->SetTitle(Form("MCMC Keys conf. interval for %s, %s",
352 // axes->at(0)->GetName(), axes->at(1)->GetName()));
353 //else
354 // contHist->SetTitle(GetTitle());
355 if (!isEmpty)
356 contHist->SetTitle(GetTitle());
357 else
358 contHist->SetTitle(nullptr);
359
360 contHist->SetStats(false);
361
362 TString tmpOpt(options);
363 if (!tmpOpt.Contains("CONT2")) tmpOpt.Append("CONT2");
364
365 double cutoff = fInterval->GetKeysPdfCutoff();
366 contHist->SetContour(1, &cutoff);
367 contHist->SetLineColor(fLineColor);
368 contHist->SetLineWidth(fLineWidth);
369 contHist->Draw(tmpOpt.Data());
370 delete axes;
371 } else {
372 coutE(InputArguments) << "MCMCIntervalPlot::DrawKeysPdfInterval: "
373 << " Sorry: " << fDimension << "-D plots not currently supported" << endl;
374 }
375}
376
377////////////////////////////////////////////////////////////////////////////////
378
380{
381 TString title(GetTitle());
382 bool isEmpty = (title.CompareTo("") == 0);
383
384 if (fDimension == 1) {
385 // draw lower and upper limits
387 double ul = fInterval->UpperLimitByHist(*p);
388 double ll = fInterval->LowerLimitByHist(*p);
389
390 // Draw the posterior histogram as well so the user can see where the
391 // limit bars line up
392 // fDimension == 1, so we know will get a TH1F*
393 TH1F* hist = (TH1F*)DrawPosteriorHist(options, nullptr, false);
394 if (hist == nullptr) return;
395 if (isEmpty)
396 hist->SetTitle(nullptr);
397 else
398 hist->SetTitle(GetTitle());
399 hist->GetYaxis()->SetTitle(("Posterior for parameter " + std::string(p->GetName())).c_str());
400 hist->SetStats(false);
401 TH1F* copy = static_cast<TH1F*>(hist->Clone((std::string(hist->GetTitle()) + "_copy").c_str()));
402 double histCutoff = fInterval->GetHistCutoff();
403
404 Int_t i;
405 Int_t nBins = copy->GetNbinsX();
406 double height;
407 for (i = 1; i <= nBins; i++) {
408 // remove bins with height < cutoff
409 height = copy->GetBinContent(i);
410 if (height < histCutoff) {
411 copy->SetBinContent(i, 0);
412 copy->SetBinError(i, 0);
413 }
414 }
415
416 hist->Scale(1/hist->GetBinContent(hist->GetMaximumBin()));
417 copy->Scale(1/copy->GetBinContent(hist->GetMaximumBin()));
418
419 copy->SetFillStyle(1001);
421 hist->Draw(options);
422 // to show the interval area
423 copy->Draw("HIST SAME");
424
426
427 TLine* llLine = new TLine(ll, 0, ll, 1);
428 TLine* ulLine = new TLine(ul, 0, ul, 1);
429 llLine->SetLineColor(fLineColor);
430 ulLine->SetLineColor(fLineColor);
431 llLine->SetLineWidth(fLineWidth);
432 ulLine->SetLineWidth(fLineWidth);
433 llLine->Draw(options);
434 ulLine->Draw(options);
435
436 } else if (fDimension == 2) {
437 if (fPosteriorHist == nullptr)
439
440 if (fPosteriorHist == nullptr) {
441 coutE(InputArguments) << "MCMCIntervalPlot::DrawHistInterval: "
442 << "Couldn't get posterior histogram." << endl;
443 return;
444 }
445
446 RooArgList* axes = fInterval->GetAxes();
447 //if (isEmpty)
448 // fPosteriorHist->SetTitle(
449 // Form("MCMC histogram conf. interval for %s, %s",
450 // axes->at(0)->GetName(), axes->at(1)->GetName()));
451 //else
452 // fPosteriorHist->SetTitle(GetTitle());
453 if (!isEmpty)
455 else
456 fPosteriorHist->SetTitle(nullptr);
457 delete axes;
458
459 fPosteriorHist->SetStats(false);
460
461 TString tmpOpt(options);
462 if (!tmpOpt.Contains("CONT2")) tmpOpt.Append("CONT2");
463
464 double cutoff = fInterval->GetHistCutoff();
465 fPosteriorHist->SetContour(1, &cutoff);
468 fPosteriorHist->Draw(tmpOpt.Data());
469 } else {
470 coutE(InputArguments) << "MCMCIntervalPlot::DrawHistInterval: "
471 << " Sorry: " << fDimension << "-D plots not currently supported" << endl;
472 }
473}
474
475////////////////////////////////////////////////////////////////////////////////
476
478{
479 TString title(GetTitle());
480 bool isEmpty = (title.CompareTo("") == 0);
481
482 if (fDimension == 1) {
483 // Draw the posterior histogram as well so the user can see where the
484 // limit bars line up
486 double ul = fInterval->UpperLimitTailFraction(*p);
487 double ll = fInterval->LowerLimitTailFraction(*p);
488
489 TH1F* hist = (TH1F*)DrawPosteriorHist(options, nullptr, false);
490 if (hist == nullptr) return;
491 if (isEmpty)
492 hist->SetTitle(nullptr);
493 else
494 hist->SetTitle(GetTitle());
495 hist->GetYaxis()->SetTitle(Form("Posterior for parameter %s",
496 p->GetName()));
497 hist->SetStats(false);
498 TH1F* copy = (TH1F*)hist->Clone(Form("%s_copy", hist->GetTitle()));
499
500 Int_t i;
501 Int_t nBins = copy->GetNbinsX();
502 double center;
503 for (i = 1; i <= nBins; i++) {
504 // remove bins outside interval
505 center = copy->GetBinCenter(i);
506 if (center < ll || center > ul) {
507 copy->SetBinContent(i, 0);
508 copy->SetBinError(i, 0);
509 }
510 }
511
512 hist->Scale(1/hist->GetBinContent(hist->GetMaximumBin()));
513 copy->Scale(1/copy->GetBinContent(hist->GetMaximumBin()));
514
515 copy->SetFillStyle(1001);
517 hist->Draw(options);
518 copy->Draw("hist same");
519
520 // draw lower and upper limits
521 TLine* llLine = new TLine(ll, 0, ll, 1);
522 TLine* ulLine = new TLine(ul, 0, ul, 1);
523 llLine->SetLineColor(fLineColor);
524 ulLine->SetLineColor(fLineColor);
525 llLine->SetLineWidth(fLineWidth);
526 ulLine->SetLineWidth(fLineWidth);
527 llLine->Draw(options);
528 ulLine->Draw(options);
529 } else {
530 coutE(InputArguments) << "MCMCIntervalPlot::DrawTailFractionInterval: "
531 << " Sorry: " << fDimension << "-D plots not currently supported"
532 << endl;
533 }
534}
535
536////////////////////////////////////////////////////////////////////////////////
537
539{
540 if (fPosteriorKeysProduct == nullptr)
542
543 if (fPosteriorKeysProduct == nullptr) {
544 coutE(InputArguments) << "MCMCIntervalPlot::DrawPosteriorKeysProduct: "
545 << "Couldn't get posterior Keys product." << endl;
546 return nullptr;
547 }
548
549 RooArgList* axes = fInterval->GetAxes();
550
551 TString title(GetTitle());
552 bool isEmpty = (title.CompareTo("") == 0);
553
554 if (fDimension == 1) {
555 RooPlot* frame = ((RooRealVar*)fParameters->first())->frame();
556 if (!frame) return nullptr;
557 if (isEmpty)
558 frame->SetTitle(Form("Posterior Keys PDF * Heaviside product for %s",
559 axes->at(0)->GetName()));
560 else
561 frame->SetTitle(GetTitle());
562 //fPosteriorKeysProduct->plotOn(frame);
565 frame->Draw(options);
566 return (void*)frame;
567 } else if (fDimension == 2) {
568 RooRealVar* xVar = (RooRealVar*)axes->at(0);
569 RooRealVar* yVar = (RooRealVar*)axes->at(1);
571 "prodPlot2D", *xVar, RooFit::YVar(*yVar), RooFit::Scaling(false));
572 if (isEmpty)
573 productHist->SetTitle(
574 Form("MCMC Posterior Keys Product Hist. for %s, %s",
575 axes->at(0)->GetName(), axes->at(1)->GetName()));
576 else
577 productHist->SetTitle(GetTitle());
578 productHist->Draw(options);
579 return nullptr;
580 }
581 delete axes;
582 return nullptr;
583}
584
585////////////////////////////////////////////////////////////////////////////////
586
588{
589 const MarkovChain* markovChain = fInterval->GetChain();
590
591 Int_t size = markovChain->Size();
592 Int_t burnInSteps;
593 if (fShowBurnIn)
594 burnInSteps = fInterval->GetNumBurnInSteps();
595 else
596 burnInSteps = 0;
597
598 double* x = new double[size - burnInSteps];
599 double* y = new double[size - burnInSteps];
600 double* burnInX = nullptr;
601 double* burnInY = nullptr;
602 if (burnInSteps > 0) {
603 burnInX = new double[burnInSteps];
604 burnInY = new double[burnInSteps];
605 }
606 double firstX;
607 double firstY;
608
609 for (Int_t i = burnInSteps; i < size; i++) {
610 x[i - burnInSteps] = markovChain->Get(i)->getRealValue(xVar.GetName());
611 y[i - burnInSteps] = markovChain->Get(i)->getRealValue(yVar.GetName());
612 }
613
614 for (Int_t i = 0; i < burnInSteps; i++) {
615 burnInX[i] = markovChain->Get(i)->getRealValue(xVar.GetName());
616 burnInY[i] = markovChain->Get(i)->getRealValue(yVar.GetName());
617 }
618
619 firstX = markovChain->Get(0)->getRealValue(xVar.GetName());
620 firstY = markovChain->Get(0)->getRealValue(yVar.GetName());
621
622 TString title(GetTitle());
623 bool isEmpty = (title.CompareTo("") == 0);
624
625 TGraph* walk = new TGraph(size - burnInSteps, x, y);
626 if (isEmpty)
627 walk->SetTitle(Form("2-D Scatter Plot of Markov chain for %s, %s",
628 xVar.GetName(), yVar.GetName()));
629 else
630 walk->SetTitle(GetTitle());
631 // kbelasco: figure out how to set TGraph variable ranges
632 walk->GetXaxis()->Set(xVar.numBins(), xVar.getMin(), xVar.getMax());
633 walk->GetXaxis()->SetTitle(xVar.GetName());
634 walk->GetYaxis()->Set(yVar.numBins(), yVar.getMin(), yVar.getMax());
635 walk->GetYaxis()->SetTitle(yVar.GetName());
636 walk->SetLineColor(kGray);
637 walk->SetMarkerStyle(6);
638 walk->SetMarkerColor(kViolet);
639 walk->Draw("A,L,P,same");
640
641 TGraph* burnIn = nullptr;
642 if (burnInX != nullptr && burnInY != nullptr) {
643 burnIn = new TGraph(burnInSteps - 1, burnInX, burnInY);
644 burnIn->SetLineColor(kPink);
645 burnIn->SetMarkerStyle(6);
646 burnIn->SetMarkerColor(kPink);
647 burnIn->Draw("L,P,same");
648 }
649
650 TGraph* first = new TGraph(1, &firstX, &firstY);
651 first->SetLineColor(kGreen);
652 first->SetMarkerStyle(3);
653 first->SetMarkerSize(2);
654 first->SetMarkerColor(kGreen);
655 first->Draw("L,P,same");
656
657 //walkCanvas->Update();
658 delete [] x;
659 delete [] y;
660 if (burnInX != nullptr) delete [] burnInX;
661 if (burnInY != nullptr) delete [] burnInY;
662 //delete walk;
663 //delete burnIn;
664 //delete first;
665}
666
667////////////////////////////////////////////////////////////////////////////////
668
670{
671 const MarkovChain* markovChain = fInterval->GetChain();
672 Int_t size = markovChain->Size();
673 Int_t numEntries = 2 * size;
674 double* value = new double[numEntries];
675 double* time = new double[numEntries];
676 double val;
677 Int_t weight;
678 Int_t t = 0;
679 for (Int_t i = 0; i < size; i++) {
680 val = markovChain->Get(i)->getRealValue(param.GetName());
681 weight = (Int_t)markovChain->Weight();
682 value[2*i] = val;
683 value[2*i + 1] = val;
684 time[2*i] = t;
685 t += weight;
686 time[2*i + 1] = t;
687 }
688
689 TString title(GetTitle());
690 bool isEmpty = (title.CompareTo("") == 0);
691
692 TGraph* paramGraph = new TGraph(numEntries, time, value);
693 if (isEmpty)
694 paramGraph->SetTitle(Form("%s vs. time in Markov chain",param.GetName()));
695 else
696 paramGraph->SetTitle(GetTitle());
697 paramGraph->GetXaxis()->SetTitle("Time (discrete steps)");
698 paramGraph->GetYaxis()->SetTitle(param.GetName());
699 //paramGraph->SetLineColor(fLineColor);
700 paramGraph->Draw("A,L,same");
701 delete [] value;
702 delete [] time;
703 //gPad->Update();
704}
705
706////////////////////////////////////////////////////////////////////////////////
707
709{
710 const MarkovChain* markovChain = fInterval->GetChain();
711 Int_t size = markovChain->Size();
712 Int_t numEntries = 2 * size;
713 double* nllValue = new double[numEntries];
714 double* time = new double[numEntries];
715 double nll;
716 Int_t weight;
717 Int_t t = 0;
718 for (Int_t i = 0; i < size; i++) {
719 nll = markovChain->NLL(i);
720 weight = (Int_t)markovChain->Weight();
721 nllValue[2*i] = nll;
722 nllValue[2*i + 1] = nll;
723 time[2*i] = t;
724 t += weight;
725 time[2*i + 1] = t;
726 }
727
728 TString title(GetTitle());
729 bool isEmpty = (title.CompareTo("") == 0);
730
731 TGraph* nllGraph = new TGraph(numEntries, time, nllValue);
732 if (isEmpty)
733 nllGraph->SetTitle("NLL value vs. time in Markov chain");
734 else
735 nllGraph->SetTitle(GetTitle());
736 nllGraph->GetXaxis()->SetTitle("Time (discrete steps)");
737 nllGraph->GetYaxis()->SetTitle("NLL (-log(likelihood))");
738 //nllGraph->SetLineColor(fLineColor);
739 nllGraph->Draw("A,L,same");
740 //gPad->Update();
741 delete [] nllValue;
742 delete [] time;
743}
744
745////////////////////////////////////////////////////////////////////////////////
746
748{
749 if (fNLLHist == nullptr) {
750 const MarkovChain* markovChain = fInterval->GetChain();
751 // find the max NLL value
752 double maxNLL = 0;
753 Int_t size = markovChain->Size();
754 for (Int_t i = 0; i < size; i++)
755 if (markovChain->NLL(i) > maxNLL)
756 maxNLL = markovChain->NLL(i);
757 RooRealVar* nllVar = fInterval->GetNLLVar();
758 fNLLHist = new TH1F("mcmc_nll_hist", "MCMC NLL Histogram",
759 nllVar->getBins(), 0, maxNLL);
760 TString title(GetTitle());
761 bool isEmpty = (title.CompareTo("") == 0);
762 if (!isEmpty)
764 fNLLHist->GetXaxis()->SetTitle("-log(likelihood)");
765 for (Int_t i = 0; i < size; i++)
766 fNLLHist->Fill(markovChain->NLL(i), markovChain->Weight());
767 }
768 fNLLHist->Draw(options);
769}
770
771////////////////////////////////////////////////////////////////////////////////
772
774{
775 if (fWeightHist == nullptr) {
776 const MarkovChain* markovChain = fInterval->GetChain();
777 // find the max weight value
778 double maxWeight = 0;
779 Int_t size = markovChain->Size();
780 for (Int_t i = 0; i < size; i++)
781 if (markovChain->Weight(i) > maxWeight)
782 maxWeight = markovChain->Weight(i);
783 fWeightHist = new TH1F("mcmc_weight_hist", "MCMC Weight Histogram",
784 (Int_t)(maxWeight + 1), 0, maxWeight * 1.02);
785 for (Int_t i = 0; i < size; i++)
786 fWeightHist->Fill(markovChain->Weight(i));
787 }
788 fWeightHist->Draw(options);
789}
790
791/*
792/////////////////////////////////////////////////////////////////////
793 // 3-d plot of the parameter points
794 dataCanvas->cd(2);
795 // also plot the points in the markov chain
796 RooDataSet* markovChainData = ((MCMCInterval*)mcmcint)->GetChainAsDataSet();
797
798 TTree& chain = ((RooTreeDataStore*) markovChainData->store())->tree();
799 chain.SetMarkerStyle(6);
800 chain.SetMarkerColor(kRed);
801 chain.Draw("s:ratioSigEff:ratioBkgEff","","box"); // 3-d box proportional to posterior
802
803 // the points used in the profile construction
804 TTree& parameterScan = ((RooTreeDataStore*) fc.GetPointsToScan()->store())->tree();
805 parameterScan.SetMarkerStyle(24);
806 parameterScan.Draw("s:ratioSigEff:ratioBkgEff","","same");
807
808 chain.SetMarkerStyle(6);
809 chain.SetMarkerColor(kRed);
810 //chain.Draw("s:ratioSigEff:ratioBkgEff", "_MarkovChain_local_nll","box");
811 //chain.Draw("_MarkovChain_local_nll");
812////////////////////////////////////////////////////////////////////
813*/
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define coutE(a)
int Int_t
Definition RtypesCore.h:45
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
@ kGray
Definition Rtypes.h:65
@ kPink
Definition Rtypes.h:67
@ kBlack
Definition Rtypes.h:65
@ kGreen
Definition Rtypes.h:66
@ kViolet
Definition Rtypes.h:67
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
double getRealValue(const char *name, double defVal=0.0, bool verbose=false) const
Get value of a RooAbsReal stored in set with given name.
RooAbsArg * first() const
RooPlot * plotOn(RooPlot *frame, 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 RooCmdArg &arg9={}, const RooCmdArg &arg10={}) const override
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
Definition RooAbsPdf.h:123
Int_t numBins(const char *rangeName=nullptr) const override
virtual Int_t getBins(const char *name=nullptr) const
Get number of bins of currently defined range.
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.
TH1 * createHistogram(RooStringView varNameList, Int_t xbins=0, Int_t ybins=0, Int_t zbins=0) const
Create and fill a ROOT histogram TH1, TH2 or TH3 with the values of this function for the variables w...
virtual RooPlot * plotOn(RooPlot *frame, 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 RooCmdArg &arg9={}, const RooCmdArg &arg10={}) const
Plot (project) PDF on specified frame.
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
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:239
void SetTitle(const char *name) override
Set the title of the RooPlot to 'title'.
Definition RooPlot.cxx:1258
TAxis * GetYaxis() const
Definition RooPlot.cxx:1279
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:652
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:37
This class provides simple and straightforward utilities to plot a MCMCInterval object.
void DrawNLLHist(const Option_t *options=nullptr)
void Draw(const Option_t *options=nullptr) override
void * DrawPosteriorHist(const Option_t *options=nullptr, const char *title=nullptr, bool scale=true)
void DrawChainScatter(RooRealVar &xVar, RooRealVar &yVar)
void DrawTailFractionInterval(const Option_t *options=nullptr)
void SetMCMCInterval(MCMCInterval &interval)
~MCMCIntervalPlot() override
Destructor of SamplingDistribution.
void DrawPosterior(const Option_t *options=nullptr)
void DrawHistInterval(const Option_t *options=nullptr)
void * DrawPosteriorKeysProduct(const Option_t *options=nullptr)
void DrawWeightHist(const Option_t *options=nullptr)
void DrawInterval(const Option_t *options=nullptr)
void DrawParameterVsTime(RooRealVar &param)
void * DrawPosteriorKeysPdf(const Option_t *options=nullptr)
void DrawShortestInterval(const Option_t *options=nullptr)
void DrawKeysPdfInterval(const Option_t *options=nullptr)
MCMCInterval is a concrete implementation of the RooStats::ConfInterval interface.
virtual bool GetUseKeys()
get whether we used kernel estimation to determine the interval
virtual enum IntervalType GetIntervalType()
Return the type of this interval.
double GetKeysMax()
Determine the approximate maximum value of the Keys PDF.
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);
virtual RooArgList * GetAxes()
return a list of RooRealVars representing the axes you own the returned RooArgList
virtual Int_t GetNumBurnInSteps()
get the number of steps in the chain to discard as burn-in,
virtual RooRealVar * GetNLLVar() const
Get a clone of the NLL variable from the markov chain.
virtual const MarkovChain * GetChain()
Get the markov chain on which this interval is based You do not own the returned MarkovChain*.
virtual double LowerLimitByHist(RooRealVar &param)
determine lower limit using histogram
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.
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
virtual RooNDKeysPdf * GetPosteriorKeysPdf()
Get a clone of the keys pdf of the posterior.
virtual double UpperLimitByHist(RooRealVar &param)
determine upper limit using histogram
virtual double UpperLimitByKeys(RooRealVar &param)
determine upper limit in the shortest interval by using keys pdf
virtual Int_t GetDimension() const
Get the number of parameters of interest in this interval.
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:30
virtual double NLL(Int_t i) const
get the NLL value of entry at position i
virtual const RooArgSet * Get(Int_t i) const
get the entry at position i
Definition MarkovChain.h:51
virtual double Weight() const
get the weight of the current (last indexed) entry
virtual Int_t Size() const
get the number of steps in the chain
Definition MarkovChain.h:49
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:39
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition TAxis.cxx:794
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:809
TAxis * GetXaxis() const
Get x axis of the graph.
Definition TGraph.cxx:1540
TAxis * GetYaxis() const
Get y axis of the graph.
Definition TGraph.cxx:1549
void SetTitle(const char *title="") override
Change (i.e.
Definition TGraph.cxx:2370
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:577
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:9058
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6707
TAxis * GetXaxis()
Definition TH1.h:322
virtual Int_t GetNbinsX() const
Definition TH1.h:295
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
Definition TH1.cxx:9123
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3345
TAxis * GetYaxis()
Definition TH1.h:323
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3067
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9139
virtual Int_t GetMaximumBin() const
Return location of bin with maximum value in the range.
Definition TH1.cxx:8494
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5032
virtual void SetContour(Int_t nlevels, const Double_t *levels=nullptr)
Set the number and values of contour levels.
Definition TH1.cxx:8400
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition TH1.cxx:6593
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2734
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8907
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:258
Use the TLine constructor to create a simple line.
Definition TLine.h:22
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
Basic string class.
Definition TString.h:139
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:450
const char * Data() const
Definition TString.h:380
TString & Append(const char *cs)
Definition TString.h:576
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg={})
RooCmdArg Scaling(bool flag)
RooCmdArg FillColor(Color_t color)
RooCmdArg DrawOption(const char *opt)
RooCmdArg Range(const char *rangeName, bool adjustNorm=true)
RooCmdArg Normalization(double scaleFactor)
RooCmdArg MoveToBack()
RooCmdArg VLines()
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Namespace for the RooStats classes.
Definition Asimov.h:19
Definition first.py:1