18 #ifndef ROOSTATS_MCMCIntervalPlot
31 #ifndef ROOT_TObjArray
61 #ifndef ROO_GLOBAL_FUNC
79 MCMCIntervalPlot::MCMCIntervalPlot()
83 fPosteriorHist =
NULL;
84 fPosteriorKeysPdf =
NULL;
85 fPosteriorKeysProduct =
NULL;
99 fPosteriorHistHistCopy =
NULL;
100 fPosteriorHistTFCopy =
NULL;
103 MCMCIntervalPlot::MCMCIntervalPlot(MCMCInterval& interval)
105 SetMCMCInterval(interval);
106 fPosteriorHist =
NULL;
107 fPosteriorKeysPdf =
NULL;
108 fPosteriorKeysProduct =
NULL;
121 fPosteriorHistHistCopy =
NULL;
122 fPosteriorHistTFCopy =
NULL;
125 MCMCIntervalPlot::~MCMCIntervalPlot()
136 delete fPosteriorKeysPdf;
137 delete fPosteriorKeysProduct;
146 void MCMCIntervalPlot::SetMCMCInterval(MCMCInterval& interval)
148 fInterval = &interval;
149 fDimension = fInterval->GetDimension();
150 fParameters = fInterval->GetParameters();
155 DrawInterval(options);
158 void MCMCIntervalPlot::DrawPosterior(
const Option_t* options)
160 if (fInterval->GetUseKeys())
161 DrawPosteriorKeysPdf(options);
163 DrawPosteriorHist(options);
166 void* MCMCIntervalPlot::DrawPosteriorHist(
const Option_t* ,
167 const char* title,
Bool_t scale)
169 if (fPosteriorHist ==
NULL)
170 fPosteriorHist = fInterval->GetPosteriorHist();
172 if (fPosteriorHist ==
NULL) {
174 <<
"Couldn't get posterior histogram." << endl;
188 fPosteriorHist->Scale(1/fPosteriorHist->GetBinContent(
189 fPosteriorHist->GetMaximumBin()));
194 fPosteriorHist->SetTitle(title);
196 fPosteriorHist->SetTitle(GetTitle());
200 return (
void*)fPosteriorHist;
203 void* MCMCIntervalPlot::DrawPosteriorKeysPdf(
const Option_t* options)
205 if (fPosteriorKeysPdf ==
NULL)
206 fPosteriorKeysPdf = fInterval->GetPosteriorKeysPdf();
208 if (fPosteriorKeysPdf ==
NULL) {
210 <<
"Couldn't get posterior Keys PDF." << endl;
217 if (fDimension == 1) {
222 <<
"Invalid parameter" << endl;
234 }
else if (fDimension == 2) {
238 TH2F* keysHist = (
TH2F*)fPosteriorKeysPdf->createHistogram(
242 Form(
"MCMC histogram of posterior Keys PDF for %s, %s",
247 keysHist->
Draw(options);
254 void MCMCIntervalPlot::DrawInterval(
const Option_t* options)
256 switch (fInterval->GetIntervalType()) {
257 case MCMCInterval::kShortest:
258 DrawShortestInterval(options);
260 case MCMCInterval::kTailFraction:
261 DrawTailFractionInterval(options);
265 "Interval type not supported" << endl;
270 void MCMCIntervalPlot::DrawShortestInterval(
const Option_t* options)
272 if (fInterval->GetUseKeys())
273 DrawKeysPdfInterval(options);
275 DrawHistInterval(options);
278 void MCMCIntervalPlot::DrawKeysPdfInterval(
const Option_t* options)
283 if (fDimension == 1) {
291 Double_t height = fInterval->GetKeysMax();
294 Double_t ul = fInterval->UpperLimitByKeys(*p);
295 Double_t ll = fInterval->LowerLimitByKeys(*p);
297 if (frame !=
NULL && fPosteriorKeysPdf !=
NULL) {
305 fPosteriorKeysPdf->plotOn(frame,
316 fPosteriorKeysPdf->plotOn(frame,
320 frame->
Draw(options);
329 llLine->
Draw(options);
330 ulLine->
Draw(options);
331 }
else if (fDimension == 2) {
332 if (fPosteriorKeysPdf ==
NULL)
333 fPosteriorKeysPdf = fInterval->GetPosteriorKeysPdf();
335 if (fPosteriorKeysPdf ==
NULL) {
337 <<
"Couldn't get posterior Keys PDF." << endl;
344 TH2F* contHist = (
TH2F*)fPosteriorKeysPdf->createHistogram(
361 Double_t cutoff = fInterval->GetKeysPdfCutoff();
369 <<
" Sorry: " << fDimension <<
"-D plots not currently supported" << endl;
373 void MCMCIntervalPlot::DrawHistInterval(
const Option_t* options)
378 if (fDimension == 1) {
381 Double_t ul = fInterval->UpperLimitByHist(*p);
382 Double_t ll = fInterval->LowerLimitByHist(*p);
387 TH1F* hist = (
TH1F*)DrawPosteriorHist(options,
NULL,
false);
388 if (hist ==
NULL)
return;
397 Double_t histCutoff = fInterval->GetHistCutoff();
402 for (i = 1; i <= nBins; i++) {
405 if (height < histCutoff)
417 fPosteriorHistHistCopy = copy;
425 llLine->
Draw(options);
426 ulLine->
Draw(options);
428 }
else if (fDimension == 2) {
429 if (fPosteriorHist ==
NULL)
430 fPosteriorHist = fInterval->GetPosteriorHist();
432 if (fPosteriorHist ==
NULL) {
434 <<
"Couldn't get posterior histogram." << endl;
446 fPosteriorHist->SetTitle(GetTitle());
448 fPosteriorHist->SetTitle(
NULL);
451 fPosteriorHist->SetStats(
kFALSE);
456 Double_t cutoff = fInterval->GetHistCutoff();
457 fPosteriorHist->SetContour(1, &cutoff);
458 fPosteriorHist->SetLineColor(fLineColor);
459 fPosteriorHist->SetLineWidth(fLineWidth);
460 fPosteriorHist->Draw(tmpOpt.
Data());
463 <<
" Sorry: " << fDimension <<
"-D plots not currently supported" << endl;
467 void MCMCIntervalPlot::DrawTailFractionInterval(
const Option_t* options)
472 if (fDimension == 1) {
476 Double_t ul = fInterval->UpperLimitTailFraction(*p);
477 Double_t ll = fInterval->LowerLimitTailFraction(*p);
479 TH1F* hist = (
TH1F*)DrawPosteriorHist(options,
NULL,
false);
480 if (hist ==
NULL)
return;
493 for (i = 1; i <= nBins; i++) {
496 if (center < ll || center > ul) {
517 llLine->
Draw(options);
518 ulLine->
Draw(options);
521 <<
" Sorry: " << fDimension <<
"-D plots not currently supported"
526 void* MCMCIntervalPlot::DrawPosteriorKeysProduct(
const Option_t* options)
528 if (fPosteriorKeysProduct ==
NULL)
529 fPosteriorKeysProduct = fInterval->GetPosteriorKeysProduct();
531 if (fPosteriorKeysProduct ==
NULL) {
533 <<
"Couldn't get posterior Keys product." << endl;
542 if (fDimension == 1) {
544 if (!frame)
return NULL;
546 frame->
SetTitle(
Form(
"Posterior Keys PDF * Heaviside product for %s",
551 fPosteriorKeysProduct->plotOn(frame,
553 frame->
Draw(options);
555 }
else if (fDimension == 2) {
558 TH2F* productHist = (
TH2F*)fPosteriorKeysProduct->createHistogram(
562 Form(
"MCMC Posterior Keys Product Hist. for %s, %s",
566 productHist->
Draw(options);
575 const MarkovChain* markovChain = fInterval->GetChain();
580 burnInSteps = fInterval->GetNumBurnInSteps();
588 if (burnInSteps > 0) {
589 burnInX =
new Double_t[burnInSteps];
590 burnInY =
new Double_t[burnInSteps];
595 for (
Int_t i = burnInSteps; i < size; i++) {
600 for (
Int_t i = 0; i < burnInSteps; i++) {
613 walk->
SetTitle(
Form(
"2-D Scatter Plot of Markov chain for %s, %s",
625 walk->
Draw(
"A,L,P,same");
628 if (burnInX !=
NULL && burnInY !=
NULL) {
629 burnIn =
new TGraph(burnInSteps - 1, burnInX, burnInY);
633 burnIn->
Draw(
"L,P,same");
641 first->
Draw(
"L,P,same");
646 if (burnInX !=
NULL)
delete [] burnInX;
647 if (burnInY !=
NULL)
delete [] burnInY;
653 void MCMCIntervalPlot::DrawParameterVsTime(
RooRealVar& param)
655 const MarkovChain* markovChain = fInterval->GetChain();
657 Int_t numEntries = 2 * size;
663 for (
Int_t i = 0; i < size; i++) {
667 value[2*i + 1] = val;
676 TGraph* paramGraph =
new TGraph(numEntries, time, value);
684 paramGraph->
Draw(
"A,L,same");
690 void MCMCIntervalPlot::DrawNLLVsTime()
692 const MarkovChain* markovChain = fInterval->GetChain();
694 Int_t numEntries = 2 * size;
700 for (
Int_t i = 0; i < size; i++) {
701 nll = markovChain->
NLL(i);
704 nllValue[2*i + 1] = nll;
713 TGraph* nllGraph =
new TGraph(numEntries, time, nllValue);
715 nllGraph->
SetTitle(
"NLL value vs. time in Markov chain");
721 nllGraph->
Draw(
"A,L,same");
727 void MCMCIntervalPlot::DrawNLLHist(
const Option_t* options)
729 if (fNLLHist ==
NULL) {
730 const MarkovChain* markovChain = fInterval->GetChain();
734 for (
Int_t i = 0; i < size; i++)
735 if (markovChain->
NLL(i) > maxNLL)
736 maxNLL = markovChain->
NLL(i);
738 fNLLHist =
new TH1F(
"mcmc_nll_hist",
"MCMC NLL Histogram",
741 Bool_t isEmpty = (title.CompareTo(
"") == 0);
743 fNLLHist->SetTitle(GetTitle());
744 fNLLHist->GetXaxis()->SetTitle(
"-log(likelihood)");
745 for (
Int_t i = 0; i < size; i++)
746 fNLLHist->Fill(markovChain->
NLL(i), markovChain->
Weight());
748 fNLLHist->Draw(options);
751 void MCMCIntervalPlot::DrawWeightHist(
const Option_t* options)
753 if (fWeightHist ==
NULL) {
754 const MarkovChain* markovChain = fInterval->GetChain();
758 for (
Int_t i = 0; i < size; i++)
759 if (markovChain->
Weight(i) > maxWeight)
760 maxWeight = markovChain->
Weight(i);
761 fWeightHist =
new TH1F(
"mcmc_weight_hist",
"MCMC Weight Histogram",
762 (
Int_t)(maxWeight + 1), 0, maxWeight * 1.02);
763 for (
Int_t i = 0; i < size; i++)
764 fWeightHist->Fill(markovChain->
Weight(i));
766 fWeightHist->Draw(options);
771 // 3-d plot of the parameter points
773 // also plot the points in the markov chain
774 RooDataSet* markovChainData = ((MCMCInterval*)mcmcint)->GetChainAsDataSet();
776 TTree& chain = ((RooTreeDataStore*) markovChainData->store())->tree();
777 chain.SetMarkerStyle(6);
778 chain.SetMarkerColor(kRed);
779 chain.Draw("s:ratioSigEff:ratioBkgEff","","box"); // 3-d box proporional to posterior
781 // the points used in the profile construction
782 TTree& parameterScan = ((RooTreeDataStore*) fc.GetPointsToScan()->store())->tree();
783 parameterScan.SetMarkerStyle(24);
784 parameterScan.Draw("s:ratioSigEff:ratioBkgEff","","same");
786 chain.SetMarkerStyle(6);
787 chain.SetMarkerColor(kRed);
788 //chain.Draw("s:ratioSigEff:ratioBkgEff", "_MarkovChain_local_nll","box");
789 //chain.Draw("_MarkovChain_local_nll");
ClassImp(RooStats::MCMCIntervalPlot)
virtual const char * GetTitle() const
Returns title of object.
virtual void SetLineWidth(Width_t lwidth)
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
RooCmdArg DrawOption(const char *opt)
virtual Int_t numBins(const char *rangeName=0) const
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
This class provides simple and straightforward utilities to plot a MCMCInterval object.
virtual Int_t GetMaximumBin() const
Return location of bin with maximum value in the range.
virtual void SetContour(Int_t nlevels, const Double_t *levels=0)
Set the number and values of contour levels.
virtual Double_t NLL(Int_t i) const
get the NLL value of entry at position i
1-D histogram with a float per channel (see TH1 documentation)}
virtual Double_t getMin(const char *name=0) const
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual void SetFillStyle(Style_t fstyle)
virtual void SetTitle(const char *title="")
Set graph title.
void SetTitle(const char *name)
Set the title of the RooPlot to 'title'.
virtual Int_t GetNbinsX() const
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
const char * Data() const
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
virtual Int_t getBins(const char *name=0) const
virtual void SetMarkerColor(Color_t mcolor=1)
TString & Append(const char *cs)
virtual void SetBinError(Int_t bin, Double_t error)
see convention for numbering bins in TH1::GetBin
virtual void SetLineColor(Color_t lcolor)
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
TAxis * GetXaxis() const
Get x axis of the graph.
virtual void Draw(Option_t *option="")
Draw this histogram with options.
virtual void SetFillColor(Color_t fcolor)
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 const char * GetName() const
Returns name of object.
virtual void SetMarkerStyle(Style_t mstyle=1)
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
virtual void SetMarkerSize(Size_t msize=1)
Stores the steps in a Markov Chain of points.
Namespace for the RooStats classes.
RooAbsArg * at(Int_t idx) const
RooCmdArg FillColor(Color_t color)
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg Normalization(Double_t scaleFactor)
RooCmdArg Scaling(Bool_t flag)
TAxis * GetYaxis() const
Get y axis of the graph.
virtual Double_t getMax(const char *name=0) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
A Graph is a graphics object made of two arrays X and Y with npoints each.
virtual Int_t Size() const
get the number of steps in the chain
virtual void SetTitle(const char *title)
Change (i.e.
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
virtual const RooArgSet * Get(Int_t i) const
get the entry at position i
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
virtual Double_t Weight() const
get the weight of the current (last indexed) entry
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
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.