18 #ifndef ROOSTATS_MCMCIntervalPlot 33 #ifndef ROOT_TObjArray 63 #ifndef ROO_GLOBAL_FUNC 83 MCMCIntervalPlot::MCMCIntervalPlot()
87 fPosteriorHist =
NULL;
88 fPosteriorKeysPdf =
NULL;
89 fPosteriorKeysProduct =
NULL;
103 fPosteriorHistHistCopy =
NULL;
104 fPosteriorHistTFCopy =
NULL;
109 SetMCMCInterval(interval);
110 fPosteriorHist =
NULL;
111 fPosteriorKeysPdf =
NULL;
112 fPosteriorKeysProduct =
NULL;
125 fPosteriorHistHistCopy =
NULL;
126 fPosteriorHistTFCopy =
NULL;
129 MCMCIntervalPlot::~MCMCIntervalPlot()
140 delete fPosteriorKeysPdf;
141 delete fPosteriorKeysProduct;
152 fInterval = &interval;
154 fParameters = fInterval->GetParameters();
159 DrawInterval(options);
162 void MCMCIntervalPlot::DrawPosterior(
const Option_t* options)
164 if (fInterval->GetUseKeys())
165 DrawPosteriorKeysPdf(options);
167 DrawPosteriorHist(options);
170 void* MCMCIntervalPlot::DrawPosteriorHist(
const Option_t* ,
171 const char* title,
Bool_t scale)
173 if (fPosteriorHist ==
NULL)
174 fPosteriorHist = fInterval->GetPosteriorHist();
176 if (fPosteriorHist ==
NULL) {
178 <<
"Couldn't get posterior histogram." << endl;
192 fPosteriorHist->Scale(1/fPosteriorHist->GetBinContent(
193 fPosteriorHist->GetMaximumBin()));
195 TString ourTitle(GetTitle());
196 if (ourTitle.CompareTo(
"") == 0) {
198 fPosteriorHist->SetTitle(title);
200 fPosteriorHist->SetTitle(GetTitle());
204 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);
258 void MCMCIntervalPlot::DrawInterval(
const Option_t* options)
260 switch (fInterval->GetIntervalType()) {
261 case MCMCInterval::kShortest:
262 DrawShortestInterval(options);
264 case MCMCInterval::kTailFraction:
265 DrawTailFractionInterval(options);
269 "Interval type not supported" << endl;
274 void MCMCIntervalPlot::DrawShortestInterval(
const Option_t* options)
276 if (fInterval->GetUseKeys())
277 DrawKeysPdfInterval(options);
279 DrawHistInterval(options);
282 void MCMCIntervalPlot::DrawKeysPdfInterval(
const Option_t* options)
284 TString title(GetTitle());
285 Bool_t isEmpty = (title.CompareTo(
"") == 0);
287 if (fDimension == 1) {
295 Double_t height = fInterval->GetKeysMax();
298 Double_t ul = fInterval->UpperLimitByKeys(*p);
299 Double_t ll = fInterval->LowerLimitByKeys(*p);
301 if (frame !=
NULL && fPosteriorKeysPdf !=
NULL) {
309 fPosteriorKeysPdf->plotOn(frame,
320 fPosteriorKeysPdf->plotOn(frame,
324 frame->
Draw(options);
333 llLine->
Draw(options);
334 ulLine->
Draw(options);
335 }
else if (fDimension == 2) {
336 if (fPosteriorKeysPdf ==
NULL)
337 fPosteriorKeysPdf = fInterval->GetPosteriorKeysPdf();
339 if (fPosteriorKeysPdf ==
NULL) {
341 <<
"Couldn't get posterior Keys PDF." << endl;
348 TH2F* contHist = (
TH2F*)fPosteriorKeysPdf->createHistogram(
362 TString tmpOpt(options);
363 if (!tmpOpt.Contains(
"CONT2")) tmpOpt.Append(
"CONT2");
365 Double_t cutoff = fInterval->GetKeysPdfCutoff();
369 contHist->
Draw(tmpOpt.Data());
373 <<
" Sorry: " << fDimension <<
"-D plots not currently supported" << endl;
377 void MCMCIntervalPlot::DrawHistInterval(
const Option_t* options)
379 TString title(GetTitle());
380 Bool_t isEmpty = (title.CompareTo(
"") == 0);
382 if (fDimension == 1) {
385 Double_t ul = fInterval->UpperLimitByHist(*p);
386 Double_t ll = fInterval->LowerLimitByHist(*p);
391 TH1F* hist = (
TH1F*)DrawPosteriorHist(options,
NULL,
false);
392 if (hist ==
NULL)
return;
401 Double_t histCutoff = fInterval->GetHistCutoff();
406 for (i = 1; i <= nBins; i++) {
409 if (height < histCutoff) {
422 copy->
Draw(
"HIST SAME");
424 fPosteriorHistHistCopy = copy;
432 llLine->
Draw(options);
433 ulLine->
Draw(options);
435 }
else if (fDimension == 2) {
436 if (fPosteriorHist ==
NULL)
437 fPosteriorHist = fInterval->GetPosteriorHist();
439 if (fPosteriorHist ==
NULL) {
441 <<
"Couldn't get posterior histogram." << endl;
453 fPosteriorHist->SetTitle(GetTitle());
455 fPosteriorHist->SetTitle(
NULL);
458 fPosteriorHist->SetStats(
kFALSE);
460 TString tmpOpt(options);
461 if (!tmpOpt.Contains(
"CONT2")) tmpOpt.Append(
"CONT2");
463 Double_t cutoff = fInterval->GetHistCutoff();
464 fPosteriorHist->SetContour(1, &cutoff);
465 fPosteriorHist->SetLineColor(fLineColor);
466 fPosteriorHist->SetLineWidth(fLineWidth);
467 fPosteriorHist->Draw(tmpOpt.Data());
470 <<
" Sorry: " << fDimension <<
"-D plots not currently supported" << endl;
474 void MCMCIntervalPlot::DrawTailFractionInterval(
const Option_t* options)
476 TString title(GetTitle());
477 Bool_t isEmpty = (title.CompareTo(
"") == 0);
479 if (fDimension == 1) {
483 Double_t ul = fInterval->UpperLimitTailFraction(*p);
484 Double_t ll = fInterval->LowerLimitTailFraction(*p);
486 TH1F* hist = (
TH1F*)DrawPosteriorHist(options,
NULL,
false);
487 if (hist ==
NULL)
return;
500 for (i = 1; i <= nBins; i++) {
503 if (center < ll || center > ul) {
515 copy->
Draw(
"hist same");
524 llLine->
Draw(options);
525 ulLine->
Draw(options);
528 <<
" Sorry: " << fDimension <<
"-D plots not currently supported" 533 void* MCMCIntervalPlot::DrawPosteriorKeysProduct(
const Option_t* options)
535 if (fPosteriorKeysProduct ==
NULL)
536 fPosteriorKeysProduct = fInterval->GetPosteriorKeysProduct();
538 if (fPosteriorKeysProduct ==
NULL) {
540 <<
"Couldn't get posterior Keys product." << endl;
546 TString title(GetTitle());
547 Bool_t isEmpty = (title.CompareTo(
"") == 0);
549 if (fDimension == 1) {
551 if (!frame)
return NULL;
553 frame->
SetTitle(
Form(
"Posterior Keys PDF * Heaviside product for %s",
558 fPosteriorKeysProduct->plotOn(frame,
560 frame->
Draw(options);
562 }
else if (fDimension == 2) {
565 TH2F* productHist = (
TH2F*)fPosteriorKeysProduct->createHistogram(
569 Form(
"MCMC Posterior Keys Product Hist. for %s, %s",
573 productHist->
Draw(options);
582 const MarkovChain* markovChain = fInterval->GetChain();
587 burnInSteps = fInterval->GetNumBurnInSteps();
595 if (burnInSteps > 0) {
596 burnInX =
new Double_t[burnInSteps];
597 burnInY =
new Double_t[burnInSteps];
602 for (
Int_t i = burnInSteps; i < size; i++) {
607 for (
Int_t i = 0; i < burnInSteps; i++) {
615 TString title(GetTitle());
616 Bool_t isEmpty = (title.CompareTo(
"") == 0);
620 walk->
SetTitle(
Form(
"2-D Scatter Plot of Markov chain for %s, %s",
632 walk->
Draw(
"A,L,P,same");
635 if (burnInX !=
NULL && burnInY !=
NULL) {
636 burnIn =
new TGraph(burnInSteps - 1, burnInX, burnInY);
640 burnIn->
Draw(
"L,P,same");
648 first->
Draw(
"L,P,same");
653 if (burnInX !=
NULL)
delete [] burnInX;
654 if (burnInY !=
NULL)
delete [] burnInY;
660 void MCMCIntervalPlot::DrawParameterVsTime(
RooRealVar& param)
662 const MarkovChain* markovChain = fInterval->GetChain();
664 Int_t numEntries = 2 * size;
670 for (
Int_t i = 0; i < size; i++) {
674 value[2*i + 1] = val;
680 TString title(GetTitle());
681 Bool_t isEmpty = (title.CompareTo(
"") == 0);
683 TGraph* paramGraph =
new TGraph(numEntries, time, value);
691 paramGraph->
Draw(
"A,L,same");
697 void MCMCIntervalPlot::DrawNLLVsTime()
699 const MarkovChain* markovChain = fInterval->GetChain();
701 Int_t numEntries = 2 * size;
707 for (
Int_t i = 0; i < size; i++) {
708 nll = markovChain->
NLL(i);
711 nllValue[2*i + 1] = nll;
717 TString title(GetTitle());
718 Bool_t isEmpty = (title.CompareTo(
"") == 0);
720 TGraph* nllGraph =
new TGraph(numEntries, time, nllValue);
722 nllGraph->
SetTitle(
"NLL value vs. time in Markov chain");
728 nllGraph->
Draw(
"A,L,same");
734 void MCMCIntervalPlot::DrawNLLHist(
const Option_t* options)
736 if (fNLLHist ==
NULL) {
737 const MarkovChain* markovChain = fInterval->GetChain();
741 for (
Int_t i = 0; i < size; i++)
742 if (markovChain->
NLL(i) > maxNLL)
743 maxNLL = markovChain->
NLL(i);
745 fNLLHist =
new TH1F(
"mcmc_nll_hist",
"MCMC NLL Histogram",
747 TString title(GetTitle());
748 Bool_t isEmpty = (title.CompareTo(
"") == 0);
750 fNLLHist->SetTitle(GetTitle());
751 fNLLHist->GetXaxis()->SetTitle(
"-log(likelihood)");
752 for (
Int_t i = 0; i < size; i++)
753 fNLLHist->Fill(markovChain->
NLL(i), markovChain->
Weight());
755 fNLLHist->Draw(options);
758 void MCMCIntervalPlot::DrawWeightHist(
const Option_t* options)
760 if (fWeightHist ==
NULL) {
761 const MarkovChain* markovChain = fInterval->GetChain();
765 for (
Int_t i = 0; i < size; i++)
766 if (markovChain->
Weight(i) > maxWeight)
767 maxWeight = markovChain->
Weight(i);
768 fWeightHist =
new TH1F(
"mcmc_weight_hist",
"MCMC Weight Histogram",
769 (
Int_t)(maxWeight + 1), 0, maxWeight * 1.02);
770 for (
Int_t i = 0; i < size; i++)
771 fWeightHist->Fill(markovChain->
Weight(i));
773 fWeightHist->Draw(options);
778 // 3-d plot of the parameter points
780 // also plot the points in the markov chain
781 RooDataSet* markovChainData = ((MCMCInterval*)mcmcint)->GetChainAsDataSet();
783 TTree& chain = ((RooTreeDataStore*) markovChainData->store())->tree();
784 chain.SetMarkerStyle(6);
785 chain.SetMarkerColor(kRed);
786 chain.Draw("s:ratioSigEff:ratioBkgEff","","box"); // 3-d box proporional to posterior
788 // the points used in the profile construction
789 TTree& parameterScan = ((RooTreeDataStore*) fc.GetPointsToScan()->store())->tree();
790 parameterScan.SetMarkerStyle(24);
791 parameterScan.Draw("s:ratioSigEff:ratioBkgEff","","same");
793 chain.SetMarkerStyle(6);
794 chain.SetMarkerColor(kRed);
795 //chain.Draw("s:ratioSigEff:ratioBkgEff", "_MarkovChain_local_nll","box");
796 //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
tomato 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)
See convention for numbering bins in TH1::GetBin.
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
tomato 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)
Change (i.e.
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.