How to generate toy samples with simultaneous pdf

Dear experts,
Could you please tell me how to generate toy samples and fit it with simultaneous pdf? The script is as following:

RooRealVar m_pmu("m_pmu","m_pmu",4867, 5867);
gROOT->ProcessLine(".L ../Bs2pmuFit/mass_calibration/RooDoubleCBandGauss.cxx+");
R__LOAD_LIBRARY(../Bs2pmuFit/mass_calibration/RooDoubleCBandGauss_cxx.so);


TFile f("../Bs2pmuFit/gauss_constraint/bpmu_wofirstMLPbin.root");
RooWorkspace *w = (RooWorkspace*)f.Get("w");
RooCategory mybin("mybin","mybin");
RooArgSet* constraints = (RooArgSet*)w->set("constraints");
RooAbsPdf *pdf[8];
RooArgSet* observables = (RooArgSet*)w->set("observables");
RooSimultaneous simNew("simNew","simNew",mybin);
 
observables->add(mybin);

RooRealVar * BR_Bd = (RooRealVar*)w->var("BR_Bd");
RooRealVar * BR_Bs = (RooRealVar*)w->var("BR_Bs");
BR_Bd->setVal(1e-8);
BR_Bd->setMin(-3e-9);
BR_Bd->setMax(4e-8);
BR_Bs->setConstant();BR_Bs->setVal(0);
//BR_Bs->setVal(1e-8);
//BR_Bs->setMin(-1e-8);
//BR_Bs->setMax(4e-8);
//BR_Bd->setConstant();BR_Bd->setVal(0);

RooDataSet* data = simNew.generate(*observables, Extended());
//simNew.fitTo(*data);
 
RooPlot *frame = m_pmu.frame();
data->plotOn(frame);
//simNew.plotOn(frame);

TCanvas* c = new TCanvas("rf801_mcstudy","rf801_mcstudy",900,900) ;
frame->Draw() ;
c->SaveAs("toy_fit.pdf");

So simNew is the simultaneous pdf, and the variable m_pmu is actually what I would like to generate, and m_pmu is also in observable. It seems I should use generate(*observable), but I could not use RooPlot *frame = observable->frame(); Could anyone tell me how to generate some samples and plot them?

Many thanks in advance!
Lingzhu

Hi,
Generation seems correct, otherwise you can always generate the separate samples.
The problem is in plotting where you need to project the different pdf components.
The best is looking and understanding the simultaneous pdf tutorial:

Lorenzo

Thanks for the reply @moneta !
from the simultanetous pdf tutorial, it generates the separate samples first, and then fit it back. And my question is could I generate samples using the simultaneous pdf, and then extract the dataset of each components, like this:

RooDataSet *data = simNew.generate(*observables, Extended());
ww.import(*data);
ww.Print();
cout<<"name: "<<data->GetName()<<endl;
Ad[1] = (RooDataSet*)ww.data("????");

So simNew is a simultaneous pdf, and now I would like to extract the samples of each components. But I do not know the name of each components, which means I do not know what ???? is.

Thanks,
Lingzhu

Hi,
If your pdf components are extended, you can generate the data from the simultaneous pdf as you show in the code above. Note that th eobservables must include the category variable.

If you want to extract the sample you can just use the function RooAbsData::getSimData():

RooDataSet *data = simNew.generate(*observables, Extended());
auto data1 = data.getSimData("name_category1");
auto data2 = data.getSimData("name_category2");

Lorenzo

1 Like

Thanks!! that’s very help!

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