How to access the values in RooArgSet

Hello Experts,

Here is my RooGaussian object with preferred mean and sigma :

double centralplusval_bin1 = 7.30927e+06;
double JESsigmaUp = 117186;

RooRealVar entries(“entries”,“entries”,-10JESsigmaUp+centralplusval_bin1,10JESsigmaUp+centralplusval_bin1);
RooRealVar mean_bin1(“mean_bin1”, “mean_bin1 of gaussian”,centralplusval_bin1,centralplusval_bin1-100,centralplusval_bin1+100);
RooRealVar sigma1_bin1(“sigma1_bin1”, “sigma1_bin1 of gaussian”,JESsigmaUp,JESsigmaUp0.1,JESsigmaUp10);
RooGaussian gauss(“gauss”, “gaussian PDF”, entries, mean_bin1, sigma1_bin1);

I generate 1000 data points with this function :
RooDataSet* data = gauss.generate(entries,1000);

Then I fit the data points with the same gaussian function :
gauss.fitTo(*data);

I could plot the two (data and fitted gaussian) on a single frame.
RooPlot* entriesframe = entries.frame();
data->plotOn(entriesframe);
gauss.plotOn(entriesframe);
gauss.paramOn(entriesframe);
entriesframe->Draw();

It prints the parameters on the frame.

I want to fetch these parameters now, which I can do with :
cout << “################” << endl;
RooArgSet* model_params2 = gauss.getParameters(data) ;
model_params2->Print(“v”);
cout << “################” << endl;

And it does print the parameters on the terminal.
################

  1. 0x1b62090 RooRealVar:: mean_bin1 = 7.30937e+06 +/- 111.843 L(7.30917e+06 - 7.30937e+06) “mean_bin1 of gaussian”
  2. 0x1b62d10 RooRealVar:: sigma1_bin1 = 121660 +/- 2720.36 L(11718.6 - 1.17186e+06) “sigma1_bin1 of gaussian”
    ################

I want now to use these parameters in the same code further.

My question is, how can I assign these parameters to say double variables?

Hi,

you have in hands the very parameters: getting the value is as simple as

auto m = mean_bin1.getVal();
auto s = sigma1_bin1.getVal();

note that you can always express your models via the WS factory: it’s much easier and the programming model much slimmer. You can see all the examples here: root.cern/doc/master/group__tut … oofit.html , namely rf511, rf512 and rf513.

Cheers,
Danilo

Thank you Danilo :slight_smile:

I will certainly use the workspaces.