Hello!
I am facing a problem when running a fit on a binned dataset in RooFit.
I write down the piece of code I am using to set up all my observables. Basically I am taking data from some Trees and I want to fit them using the sum of two landaus.
TFile* finput_iso = new TFile("2017/fit_iso.root");
TTree* tData_iso = (TTree*) finput_iso->Get("T");
RooRealVar *sip = new RooRealVar("sip","sip",0,400);
RooRealVar *iso = new RooRealVar("iso","iso",0,100);
RooRealVar *lepid = new RooRealVar("lepid", "lepid",-20,20);
RooRealVar *id1 = new RooRealVar("id","id",0,3);
RooRealVar *z1flav = new RooRealVar("z1flav","z1flav",120,170);
RooDataSet *tdata_iso = new RooDataSet("tdata_iso","tdata_iso",tData_iso, RooArgSet(*id1,*sip,*iso,*lepid,*z1flav));
RooDataSet *tdata_mu_iso = (RooDataSet *)tdata_iso->reduce("abs(lepid)==13 && id==1 && iso < 0.35 && abs(z1flav)==169");
RooDataSet *tdata_ele_iso = (RooDataSet *)tdata_iso->reduce("abs(lepid)==11 && id==1 && abs(z1flav)==121");
sip->setRange("range_ext", 0, 40);
RooRealVar *ml3 = new RooRealVar("mean3","mean3",0.7,0.,5.);
RooRealVar *sl3 = new RooRealVar("sigma3","sigma3", 0.3,0.1,10.);
RooRealVar *ml4 = new RooRealVar("mean4","mean4",4.,2.5,20.);
RooRealVar *sl4 = new RooRealVar("sigma4","sigma4", 4.5,0.1,10.);
RooLandau* landau3 = new RooLandau("landau3","landau3 ",*sip,*ml3,*sl3);
RooLandau* landau4 = new RooLandau("landau4","landau4 ",*sip,*ml4,*sl4);
RooRealVar *frac3 = new RooRealVar("frac3","fraction of component 1",0.9,0.,1.);
RooAddPdf *model_ee_isoCut = new RooAddPdf("model_ee_isoCut","landau2+landau1", RooArgList(*landau4,*landau3),RooArgList(*frac3));
I have always run the fit using unbinned data, now I have to rerun the fit using binned data for some crosschecks. To run the binned fit I use the following commands:
TH1 *hh_ele = (TH1 *)tdata_ele_iso->createHistogram("sip", 20);
RooDataHist *tdata_ele_iso_binned = new RooDataHist("tdata_ele_iso_binned", "tdata_ele_iso_binned", *sip, hh_ele);
RooFitResult *result_Fit_ele_isoCut = model_ee_isoCut->fitTo(*tdata_ele_iso_binned,RooFit::Range("range_ext"), RooFit::Save(), RooFit::NumCPU(16));
After the last command the code hangs. No warning, no errors, no outputs at all.
I have tried to fit using only one landau, instead of the sum, and the fit works. Using unbinned data it works perfectly, too. It seems the problem is when I move to binned data.
If you have any insight of this problem, it will be extremely useful.
Thanks,
Alessandro