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?
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!