69 MCMCIntervalPlot::MCMCIntervalPlot()
73 fPosteriorHist = NULL;
74 fPosteriorKeysPdf = NULL;
75 fPosteriorKeysProduct = NULL;
89 fPosteriorHistHistCopy = NULL;
90 fPosteriorHistTFCopy = NULL;
97 SetMCMCInterval(interval);
98 fPosteriorHist = NULL;
99 fPosteriorKeysPdf = NULL;
100 fPosteriorKeysProduct = NULL;
113 fPosteriorHistHistCopy = NULL;
114 fPosteriorHistTFCopy = NULL;
119 MCMCIntervalPlot::~MCMCIntervalPlot()
130 delete fPosteriorKeysPdf;
131 delete fPosteriorKeysProduct;
144 fInterval = &interval;
146 fParameters = fInterval->GetParameters();
153 DrawInterval(options);
158 void MCMCIntervalPlot::DrawPosterior(
const Option_t* options)
160 if (fInterval->GetUseKeys())
161 DrawPosteriorKeysPdf(options);
163 DrawPosteriorHist(options);
168 void* MCMCIntervalPlot::DrawPosteriorHist(
const Option_t* ,
169 const char* title,
Bool_t scale)
171 if (fPosteriorHist == NULL)
172 fPosteriorHist = fInterval->GetPosteriorHist();
174 if (fPosteriorHist == NULL) {
176 <<
"Couldn't get posterior histogram." << endl;
190 fPosteriorHist->Scale(1/fPosteriorHist->GetBinContent(
191 fPosteriorHist->GetMaximumBin()));
193 TString ourTitle(GetTitle());
194 if (ourTitle.CompareTo(
"") == 0) {
196 fPosteriorHist->SetTitle(title);
198 fPosteriorHist->SetTitle(GetTitle());
202 return (
void*)fPosteriorHist;
207 void* MCMCIntervalPlot::DrawPosteriorKeysPdf(
const Option_t* options)
209 if (fPosteriorKeysPdf == NULL)
210 fPosteriorKeysPdf = fInterval->GetPosteriorKeysPdf();
212 if (fPosteriorKeysPdf == NULL) {
214 <<
"Couldn't get posterior Keys PDF." << endl;
218 TString title(GetTitle());
219 Bool_t isEmpty = (title.CompareTo(
"") == 0);
221 if (fDimension == 1) {
226 <<
"Invalid parameter" << endl;
238 }
else if (fDimension == 2) {
242 TH2F* keysHist = (
TH2F*)fPosteriorKeysPdf->createHistogram(
246 Form(
"MCMC histogram of posterior Keys PDF for %s, %s",
251 keysHist->
Draw(options);
260 void MCMCIntervalPlot::DrawInterval(
const Option_t* options)
262 switch (fInterval->GetIntervalType()) {
263 case MCMCInterval::kShortest:
264 DrawShortestInterval(options);
266 case MCMCInterval::kTailFraction:
267 DrawTailFractionInterval(options);
271 "Interval type not supported" << endl;
278 void MCMCIntervalPlot::DrawShortestInterval(
const Option_t* options)
280 if (fInterval->GetUseKeys())
281 DrawKeysPdfInterval(options);
283 DrawHistInterval(options);
288 void MCMCIntervalPlot::DrawKeysPdfInterval(
const Option_t* options)
290 TString title(GetTitle());
291 Bool_t isEmpty = (title.CompareTo(
"") == 0);
293 if (fDimension == 1) {
301 Double_t height = fInterval->GetKeysMax();
304 Double_t ul = fInterval->UpperLimitByKeys(*p);
305 Double_t ll = fInterval->LowerLimitByKeys(*p);
307 if (frame != NULL && fPosteriorKeysPdf != NULL) {
315 fPosteriorKeysPdf->plotOn(frame,
326 fPosteriorKeysPdf->plotOn(frame,
330 frame->
Draw(options);
339 llLine->
Draw(options);
340 ulLine->
Draw(options);
341 }
else if (fDimension == 2) {
342 if (fPosteriorKeysPdf == NULL)
343 fPosteriorKeysPdf = fInterval->GetPosteriorKeysPdf();
345 if (fPosteriorKeysPdf == NULL) {
347 <<
"Couldn't get posterior Keys PDF." << endl;
354 TH2F* contHist = (
TH2F*)fPosteriorKeysPdf->createHistogram(
368 TString tmpOpt(options);
369 if (!tmpOpt.Contains(
"CONT2")) tmpOpt.Append(
"CONT2");
371 Double_t cutoff = fInterval->GetKeysPdfCutoff();
375 contHist->
Draw(tmpOpt.Data());
379 <<
" Sorry: " << fDimension <<
"-D plots not currently supported" << endl;
385 void MCMCIntervalPlot::DrawHistInterval(
const Option_t* options)
387 TString title(GetTitle());
388 Bool_t isEmpty = (title.CompareTo(
"") == 0);
390 if (fDimension == 1) {
393 Double_t ul = fInterval->UpperLimitByHist(*p);
394 Double_t ll = fInterval->LowerLimitByHist(*p);
399 TH1F* hist = (
TH1F*)DrawPosteriorHist(options, NULL,
false);
400 if (hist == NULL)
return;
409 Double_t histCutoff = fInterval->GetHistCutoff();
414 for (i = 1; i <= nBins; i++) {
417 if (height < histCutoff) {
430 copy->
Draw(
"HIST SAME");
432 fPosteriorHistHistCopy = copy;
440 llLine->
Draw(options);
441 ulLine->
Draw(options);
443 }
else if (fDimension == 2) {
444 if (fPosteriorHist == NULL)
445 fPosteriorHist = fInterval->GetPosteriorHist();
447 if (fPosteriorHist == NULL) {
449 <<
"Couldn't get posterior histogram." << endl;
461 fPosteriorHist->SetTitle(GetTitle());
463 fPosteriorHist->SetTitle(NULL);
466 fPosteriorHist->SetStats(
kFALSE);
468 TString tmpOpt(options);
469 if (!tmpOpt.Contains(
"CONT2")) tmpOpt.Append(
"CONT2");
471 Double_t cutoff = fInterval->GetHistCutoff();
472 fPosteriorHist->SetContour(1, &cutoff);
473 fPosteriorHist->SetLineColor(fLineColor);
474 fPosteriorHist->SetLineWidth(fLineWidth);
475 fPosteriorHist->Draw(tmpOpt.Data());
478 <<
" Sorry: " << fDimension <<
"-D plots not currently supported" << endl;
484 void MCMCIntervalPlot::DrawTailFractionInterval(
const Option_t* options)
486 TString title(GetTitle());
487 Bool_t isEmpty = (title.CompareTo(
"") == 0);
489 if (fDimension == 1) {
493 Double_t ul = fInterval->UpperLimitTailFraction(*p);
494 Double_t ll = fInterval->LowerLimitTailFraction(*p);
496 TH1F* hist = (
TH1F*)DrawPosteriorHist(options, NULL,
false);
497 if (hist == NULL)
return;
510 for (i = 1; i <= nBins; i++) {
513 if (center < ll || center > ul) {
525 copy->
Draw(
"hist same");
534 llLine->
Draw(options);
535 ulLine->
Draw(options);
538 <<
" Sorry: " << fDimension <<
"-D plots not currently supported" 545 void* MCMCIntervalPlot::DrawPosteriorKeysProduct(
const Option_t* options)
547 if (fPosteriorKeysProduct == NULL)
548 fPosteriorKeysProduct = fInterval->GetPosteriorKeysProduct();
550 if (fPosteriorKeysProduct == NULL) {
552 <<
"Couldn't get posterior Keys product." << endl;
558 TString title(GetTitle());
559 Bool_t isEmpty = (title.CompareTo(
"") == 0);
561 if (fDimension == 1) {
563 if (!frame)
return NULL;
565 frame->
SetTitle(
Form(
"Posterior Keys PDF * Heaviside product for %s",
570 fPosteriorKeysProduct->plotOn(frame,
572 frame->
Draw(options);
574 }
else if (fDimension == 2) {
577 TH2F* productHist = (
TH2F*)fPosteriorKeysProduct->createHistogram(
581 Form(
"MCMC Posterior Keys Product Hist. for %s, %s",
585 productHist->
Draw(options);
596 const MarkovChain* markovChain = fInterval->GetChain();
601 burnInSteps = fInterval->GetNumBurnInSteps();
609 if (burnInSteps > 0) {
610 burnInX =
new Double_t[burnInSteps];
611 burnInY =
new Double_t[burnInSteps];
616 for (
Int_t i = burnInSteps; i < size; i++) {
621 for (
Int_t i = 0; i < burnInSteps; i++) {
629 TString title(GetTitle());
630 Bool_t isEmpty = (title.CompareTo(
"") == 0);
634 walk->
SetTitle(
Form(
"2-D Scatter Plot of Markov chain for %s, %s",
646 walk->
Draw(
"A,L,P,same");
649 if (burnInX != NULL && burnInY != NULL) {
650 burnIn =
new TGraph(burnInSteps - 1, burnInX, burnInY);
654 burnIn->
Draw(
"L,P,same");
662 first->
Draw(
"L,P,same");
667 if (burnInX != NULL)
delete [] burnInX;
668 if (burnInY != NULL)
delete [] burnInY;
676 void MCMCIntervalPlot::DrawParameterVsTime(
RooRealVar& param)
678 const MarkovChain* markovChain = fInterval->GetChain();
680 Int_t numEntries = 2 * size;
686 for (
Int_t i = 0; i < size; i++) {
690 value[2*i + 1] = val;
696 TString title(GetTitle());
697 Bool_t isEmpty = (title.CompareTo(
"") == 0);
699 TGraph* paramGraph =
new TGraph(numEntries, time, value);
707 paramGraph->
Draw(
"A,L,same");
715 void MCMCIntervalPlot::DrawNLLVsTime()
717 const MarkovChain* markovChain = fInterval->GetChain();
719 Int_t numEntries = 2 * size;
725 for (
Int_t i = 0; i < size; i++) {
726 nll = markovChain->
NLL(i);
729 nllValue[2*i + 1] = nll;
735 TString title(GetTitle());
736 Bool_t isEmpty = (title.CompareTo(
"") == 0);
738 TGraph* nllGraph =
new TGraph(numEntries, time, nllValue);
740 nllGraph->
SetTitle(
"NLL value vs. time in Markov chain");
746 nllGraph->
Draw(
"A,L,same");
754 void MCMCIntervalPlot::DrawNLLHist(
const Option_t* options)
756 if (fNLLHist == NULL) {
757 const MarkovChain* markovChain = fInterval->GetChain();
761 for (
Int_t i = 0; i < size; i++)
762 if (markovChain->
NLL(i) > maxNLL)
763 maxNLL = markovChain->
NLL(i);
765 fNLLHist =
new TH1F(
"mcmc_nll_hist",
"MCMC NLL Histogram",
767 TString title(GetTitle());
768 Bool_t isEmpty = (title.CompareTo(
"") == 0);
770 fNLLHist->SetTitle(GetTitle());
771 fNLLHist->GetXaxis()->SetTitle(
"-log(likelihood)");
772 for (
Int_t i = 0; i < size; i++)
773 fNLLHist->Fill(markovChain->
NLL(i), markovChain->
Weight());
775 fNLLHist->Draw(options);
780 void MCMCIntervalPlot::DrawWeightHist(
const Option_t* options)
782 if (fWeightHist == NULL) {
783 const MarkovChain* markovChain = fInterval->GetChain();
787 for (
Int_t i = 0; i < size; i++)
788 if (markovChain->
Weight(i) > maxWeight)
789 maxWeight = markovChain->
Weight(i);
790 fWeightHist =
new TH1F(
"mcmc_weight_hist",
"MCMC Weight Histogram",
791 (
Int_t)(maxWeight + 1), 0, maxWeight * 1.02);
792 for (
Int_t i = 0; i < size; i++)
793 fWeightHist->Fill(markovChain->
Weight(i));
795 fWeightHist->Draw(options);
800 // 3-d plot of the parameter points
802 // also plot the points in the markov chain
803 RooDataSet* markovChainData = ((MCMCInterval*)mcmcint)->GetChainAsDataSet();
805 TTree& chain = ((RooTreeDataStore*) markovChainData->store())->tree();
806 chain.SetMarkerStyle(6);
807 chain.SetMarkerColor(kRed);
808 chain.Draw("s:ratioSigEff:ratioBkgEff","","box"); // 3-d box proportional to posterior
810 // the points used in the profile construction
811 TTree& parameterScan = ((RooTreeDataStore*) fc.GetPointsToScan()->store())->tree();
812 parameterScan.SetMarkerStyle(24);
813 parameterScan.Draw("s:ratioSigEff:ratioBkgEff","","same");
815 chain.SetMarkerStyle(6);
816 chain.SetMarkerColor(kRed);
817 //chain.Draw("s:ratioSigEff:ratioBkgEff", "_MarkovChain_local_nll","box");
818 //chain.Draw("_MarkovChain_local_nll");
virtual Double_t getMin(const char *name=0) const
virtual const char * GetName() const
Returns name of object.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
RooCmdArg DrawOption(const char *opt)
virtual Double_t getMax(const char *name=0) const
This class provides simple and straightforward utilities to plot a MCMCInterval object.
virtual Int_t numBins(const char *rangeName=0) const
virtual void SetContour(Int_t nlevels, const Double_t *levels=0)
Set the number and values of contour levels.
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
TAxis * GetYaxis() const
Get y axis of the graph.
virtual Int_t Size() const
get the number of steps in the chain
1-D histogram with a float per channel (see TH1 documentation)}
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetTitle(const char *title="")
Set graph title.
void SetTitle(const char *name)
Set the title of the RooPlot to 'title'.
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
virtual const RooArgSet * Get(Int_t i) const
get the entry at position i
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
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...
virtual Int_t GetDimension() const
Get the number of parameters of interest in this interval.
RooRealVar represents a fundamental (non-derived) real valued object.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void Draw(Option_t *option="")
Draw this histogram with options.
RooAbsArg * at(Int_t idx) const
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual Double_t NLL(Int_t i) const
get the NLL value of entry at position i
2-D histogram with a float per channel (see TH1 documentation)}
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...
char * Form(const char *fmt,...)
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
RooPlot * frame(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
TAxis * GetXaxis() const
Get x axis of the graph.
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Stores the steps in a Markov Chain of points.
Namespace for the RooStats classes.
RooCmdArg FillColor(Color_t color)
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg Normalization(Double_t scaleFactor)
virtual Double_t Weight() const
get the weight of the current (last indexed) entry
RooCmdArg Scaling(Bool_t flag)
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
A Graph is a graphics object made of two arrays X and Y with npoints each.
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
virtual Int_t getBins(const char *name=0) const
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
virtual Int_t GetNbinsX() const
MCMCInterval is a concrete implementation of the RooStats::ConfInterval interface.
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual Int_t GetMaximumBin() const
Return location of bin with maximum value in the range.
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
virtual const char * GetTitle() const
Returns title of object.