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

Hi,

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;
 tree->SetBranchAddress("mbc",&s_mbc);
    RooDataSet *data = new RooDataSet("data","data",RooArgSet(mbc));
    for(int i=0; i < tree->GetEntries();i++){
   tree->GetEntry(i);
      mbc.setVal(s_mbc);
      data->add(RooArgSet(mbc));
   }

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:
    https://root.cern/doc/master/rf403__weightedevts_8C.html

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++){
        tree->GetEntry(i);
        mbc.setVal(s_mbc);
        if (i == j) continue; 
        data->add(RooArgSet(mbc)); 
        } 
        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.
:smiley:

1 Like

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