How to perform fit on (n-1) data events by dropping one event each time


Let’s say I have .root file of 100 entries/events (0,1,2,…,99). I want to perform fit on the sample containing 99 entries on each go, i.e., first I will fit 1,2,…,99 events, then 0,2,…,99, then 0,1,3,…,99 events and so on. Here is a sample which shows how I call all the 100 events

 TFile *file = new TFile("data.root");
 TTree *tree =(TTree*)file->Get("h1");
 RooRealVar mbc("mbc","mbc",5.2,5.29);
 Float_t s_mbc;
    RooDataSet *data = new RooDataSet("data","data",RooArgSet(mbc));
    for(int i=0; i < tree->GetEntries();i++){

What should I modify to get a data sample (RooDataSet) which will account (n-1) events at a time?

Hey, I formatted the code, so it shows more nicely (tips for posting code).

It sounds like you want to do some kind of bootstrapping. I see two options:

  1. if (i == j) continue;, and j is a number that you count up from 0 to 99. So you make 100 different datasets, where event j is missing.
  2. You make weighted datasets, and set one weight to zero. This tutorial shows how to use event weights:

Hi @StephanH,

Thank you very much for your response.
The procedure 1 what you have described above is the one I want to do.
Here is my modified code according to your suggestion,

        double nll_nominal;
        RooDataSet *data = new RooDataSet("data","data",RooArgSet(mbc));
        for(int j=0; j < tree->GetEntries(); j++){
        for(int i=0; i < tree->GetEntries(); i++){
        if (i == j) continue; 
        model.fitTo(*data, Extended(kTRUE), Minos(kTRUE));
        RooNLLVar nll("nll","nll",model,*data);
	nll_nominal = nll.getVal();
        cout <<j<<"\t"<<nll_nominal<<"\t"<<n_sig.getVal()<<endl;

Here, “model” is RooAddPdf of (signal_pdf, bkg_pdf) and (n_sig,n_bkg), where the signal is fitted with a Gaussian and background with Argus function.
It seems the current loop keeps the information of the previous loop, i.e., nll_nominal of j=3 is equal to nll_nominal of j=1+2+3.
I know, there is some silly mistake, but I am unable to figure it out!

You need to re-create data for every iteration of the loop over j. Currently, you are adding each event 99 times.

Hi @StephanH,

Thanks, it works.

1 Like

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