How to show value of RooFormulaVar on RooPlot?

I have a RooPlot with a paramOn statement that shows all the regular RooRealVar parameters I pass it fine. I want to change one parameter to a RooFormulaVar to fix the way that it relates to another parameter. This works fine in fitting, but I can’t find any way to get it to show the value for the parameter in the text box.

Is there any simple way to do this, or some kind of workaround?

Could you post a small running script reproducing your problem ? I think It will help to solve it.

Here’s an example adapted from rf205_complot.C. Flip the preprocessor conditional to change the parameter from RooRealVar to RooFormulaVar. In the first case mean2 is shown in the parameter box, but in the second case it is not.

In reality these parameters are not fixed but floating, but I want to constrain them by a fixed ratio. But if I approach that as shown here, I then don’t have a simple way of showing both parameters in my plot. Maybe there’s a better approach?

#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooAddPdf.h"
#include "RooChebychev.h"
#include "RooExponential.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit ;

void rf205_compplot_mod()
   // S e t u p   c o m p o s i t e    p d f
   // --------------------------------------
   // Declare observable x
   RooRealVar x("x","x",0,10) ;
   // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
   RooRealVar mean1("mean1","mean of gaussian 1",3.1) ;
#if 1
   RooRealVar mean2("mean2","mean of gaussian 2",3.7) ;
   RooFormulaVar mean2("mean2","mean of gaussian 2","mean1*3.7/3.1",RooArgList(mean1)) ;
   RooRealVar sigma1("sigma1","width of gaussian 1",0.19) ;
   RooRealVar sigma2("sigma2","width of gaussian 2",0.21) ;
   RooGaussian sig1("sig1","Signal component 1",x,mean1,sigma1) ;
   RooGaussian sig2("sig2","Signal component 2",x,mean2,sigma2) ;
   // Sum the signal components into a composite signal p.d.f.
   RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
   RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
   // Build Chebychev polynomial p.d.f.
   RooRealVar a0("a0","a0",0.5,0.,1.) ;
   RooRealVar a1("a1","a1",0.2,0.,1.) ;
   RooChebychev bkg1("bkg1","Background 1",x,RooArgSet(a0,a1)) ;
   // Build exponential pdf
   RooRealVar alpha("alpha","alpha",-1) ;
   RooExponential bkg2("bkg2","Background 2",x,alpha) ;
   // Sum the background components into a composite background p.d.f.
   RooRealVar bkg1frac("sig1frac","fraction of component 1 in background",0.2,0.,1.) ;
   RooAddPdf bkg("bkg","Signal",RooArgList(bkg1,bkg2),sig1frac) ;
   // Sum the composite signal and background
   RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
   RooAddPdf  model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
   // S e t u p   b a s i c   p l o t   w i t h   d a t a   a n d   f u l l   p d f
   // ------------------------------------------------------------------------------
   // Generate a data sample of 1000 events in x from model
   RooDataSet *data = model.generate(x,5000) ;
   // Plot data and complete PDF overlaid
   RooPlot* xframe  = x.frame(Title("Component plotting of pdf=(sig1+sig2)+(bkg1+bkg2)")) ;
   data->plotOn(xframe) ;
   model.plotOn(xframe) ;
   // M a k e   c o m p o n e n t   b y   o b j e c t   r e f e r e n c e
   // --------------------------------------------------------------------
   // Plot single background component specified by object reference
   model.plotOn(xframe,Components(bkg),LineColor(kRed)) ;
   // Plot single background component specified by object reference
   model.plotOn(xframe,Components(bkg2),LineStyle(kDashed),LineColor(kRed)) ;
   // Plot multiple background components specified by object reference
   // Note that specified components may occur at any level in object tree
   // (e.g bkg is component of 'model' and 'sig2' is component 'sig')
   model.plotOn(xframe,Components(RooArgSet(bkg,sig2)),LineStyle(kDotted)) ;
   // Draw the parameters box
   RooArgSet params = RooArgList(mean1, sigma1, mean2, sigma2) ;
   model.paramOn(xframe, Parameters(params), Layout(0.6,0.9,0.9), ShowConstants(kTRUE)) ;
   // Draw the frame on the canvas
   xframe->GetYaxis()->SetTitleOffset(1.4) ;
   xframe->Draw() ;

I think I figured out how to do it, by making the ratio of the two variables into a RooFormulaVar, and then imposing a gaussian constraint to the ratio I want. This has the added benefit of allowing some small perturbations in the ratio if desired.

RooFormulaVar cc_ratio_var("cc_ratio_var", "cc_ratio_var", "mass_psip/mass_jpsi", RooArgList(mass_jpsi, mass_psip));
RooGaussian cc_ratio_constr("cc_ratio_constr", "cc_ratio_constr", cc_ratio_var, RooConst(1.19), RooConst(0.01));
model.fitTo(data, ExternalConstraints(cc_ratio_constr));

This allows me to put the constraint on the parameters and print them both in the box.

However, now I’m wondering how I can print the resulting constrained (perturbed) ratio in the box as well. With this I am having the same problem as in the original example. I could read out the value with cc_ratio_var.evaluate() but am not sure how to put it in the parameter box.

I guess those parameters are not so important. But for future reference it would be nice to know if there’s a simple way to add custom parameters (not necessarily directly involved in fitting) to the parameters box. Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.