SPlot, ERROR:Eval -- RooAbsReal::logEvalError(sgn_p) evaluation error

Dear experts,

I am trying to perform a fit to a sWeighted data, then do second sWeight calculation based on my new fit result.

The following is my workflow.

First, I use a binned fit to extract the distribution of signal and background. The binned fit is employed because of the large amount of data ( ~10^6 events originally).

//input original root file
TFile *input_root_1 = new TFile(filename);
TTree tree1 = (TTree)input_root_1->Get(“DecayTree”);

// input root file which stores the sWeighted factor
TFile *input_root_2 = new TFile(sweight_file);
TTree tree2 = (TTree)input_root_2->Get(“DecayTree”);

//add tree friend

//fit variable
RooRealVar ipchi(“log_D_IPCHI2_OWNPV”, “ipchi”, xmin, xmax);
//sweight factor
TString weight(“sig_sw”);

//fit range
Double_t xmin=-6.5, xmax=8.5; Double_t xbins=75;

// create RooDataHist
TH1F *th1f_type1=new TH1F(“th1f_type1”,“th1f_type1”, xbins, xmin, xmax);
tree1->Project(“th1f_type1”,draw_var, weight);
RooDataHist data(“data”,“ipchi”,ipchi, th1f_type1);

//event number of data
double N = data.sumEntries();

//signal distribution
RooRealVar* ap_p;
RooRealVar* sigp_p;
RooRealVar* xi_p;
RooRealVar* rho1_p;
RooRealVar* rho2_p;

TFile* input_ws_file = new TFile(“ws.roott”);
RooWorkspace* w = (RooWorkspace*) input_ws_file->Get(“w”) ;

ap_p = w->var(“ap_p”);
sigp_p = w->var(“sigp_p”);
xi_p = w->var(“xi_p”);
rho1_p = w->var(“rho1_p”);
rho2_p = w->var(“rho2_p”);


//sig pdf
RooBukinPdf sgn_p(“sgn_p”,“sgn_p”,ipchi,*ap_p,*sigp_p,*xi_p,rho1_p,rho2_p);
//sig number
RooRealVar nsig_prompt(“nsig_prompt”, “nsig_prompt”, 0.8
N, 0.6
N, N);

RooRealVar bdecay_mean(“bdecay_mean”,“bdecay_mean”, 4.5, 4.0, 5.0);
RooRealVar bdecay_sigma(“bdecay_sigma”, “bdecay_sigma”, 1.2, 0.8, 2.0);
//bkg pdf
RooGaussian sgn_b(“sgn_b”, “sgn_b”, ipchi, bdecay_mean, bdecay_sigma);
//bkg number
RooRealVar nsig_bdecay(“nsig_bdecay”, “nsig_bdecay”, 0.2N, 0, 0.3N);

// total pdf
RooArgList shapes;
RooArgList yields;
shapes.add(sgn_p); yields.add(nsig_prompt);
shapes.add(sgn_b); yields.add(nsig_bdecay);

RooAddPdf *model = new RooAddPdf(“model”, “sum of all PDFs”, shapes, yields);

// binned fit
m_fitres = model->fitTo(data, NumCPU(40), Save(kTRUE), Extended(kTRUE));


The fit quality is good, as can be seen here.

Next, the RooDataSet is used in order to calculate sWeight factor.

// create sWeighted RooDataSet
RooRealVar* mass_weight = new RooRealVar(“sig_sw”, “sig_sw”, -5, 5);
RooDataSet data_sw(“data_sw”, “ipchi”, tree1, RooArgSet(ipchi,*mass_weight),0, mass_weight->GetName());

RooStats::SPlot* sData = new RooStats::SPlot(“sData”,“An SPlot”, data_sw, model, RooArgList(nsig_prompt, nsig_bdecay));


This plot displays the input RooDataSet and model. It doesn’t look like there’s anything wrong with it.

But I have encounter a problem when caluculating sWeight factor. An Error reminder shows

and it results in fail sWeight calculation.

I know this problem I’m having has been asked before, and in its answer, simply changing the fit parameter floating range can solve it. But I have tried many times and it does not solve the problem.

How can I fix it?


(Previous discussions)

Dear @bshi ,

Thanks for reaching out. Let me ask @jonas to give you a hand on this one.


Hi @bshi,

first, did you check that the ranges of the RooBukinPdf parameters don’t go beyond the definition ranges here?

Maybe fixing the ranges accordingly already helps!

Thank you! I have solved this problem. The problem is caused by the input of “tree1”, where tree1 contains the events which fall outside the fit range.

But I still have a question. For twice sweighted distribution, the total scale factor is “sig_sw1 * sig_sw2”.
To extract the "sig_sw2’, I loop through all event in the dataset and save them event by event. However, the event number of RooDataSet is not equal to the one in my original ROOT file (It should be too, after all it has been weighted). I’m not sure if the weight factor can be corresponded to the events in this case?

Here is my code for saving 2nd sweight factor.

TFile *file = new TFile(out_file, “recreate”);
TTree *result = new TTree (“DecayTree”, “DecayTree”);
double sig_sw_2, n1_sw_2;
Int_t nevent = data_sw.sumEntries();
for(Int_t i=0; inevent; ++i){
sig_sw_2 = sData->GetSWeight(i,“nsig_prompt”);
n1_sw_2 = sData->GetSWeight(i,“nsig_bdecay”);

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