Problems with fit using roofit

Hi everybody,
I’m new to using Roofit, and I’m trying to write a code which imports the histogram of data and three histograms which represents three “contributions” to data. My aim is to determine which fraction of each histogram contributes to data. I wrote a code like that:


TFile* f = new TFile("template_2D.root");

      //upload of histograms and data
      TH2F* h1=(TH2F*)f->Get("h1");                             
     
      TH2F* h2=(TH2F*)f->Get("h2"); 
      
      TH2F* h3=(TH2F*)f->Get("h3");                              
     
      TH2F* data=(TH2F*)f->Get("data");                               

 RooRealVar x("x","x",0.,10.) ;    
RooRealVar y("y","y",0.,10.) ; 

RooRealVar c1("c1","c1",0.,10000) ; 
RooRealVar c2("c2","c2",0.,10000) ;

//uploading histograms in RooDataHist using Import
RooDataHist montecarlob_d("montecarlob_d","montecarlob_d",RooArgList(x,y),Import(*h1)) ; 
RooDataHist montecarloc_d("montecarloc_d","montecarloc_d",RooArgList(x,y),Import(*h2)) ; 
RooDataHist montecarloq_d("montecarloq_d","montecarloq_d",RooArgList(x,y),Import(*h3)) ;


  

  RooHistPdf montecarlob("montecarlob","montecarlob",RooArgList(x,y),montecarlob_d);
  RooHistPdf montecarloc("montecarloc","montecarloc",RooArgList(x,y),montecarloc_d);
  RooHistPdf montecarloq("montecarloq","montecarloq",RooArgList(x,y),montecarloq_d); 
   RooAddPdf model("model","model",RooArgList(montecarlob,montecarloc,montecarloq),RooArgList(c1,c2));

RooDataHist datah ("datah","dataset with x",RooArgList(x,y),Import(*data)) ; 


model.fitTo(datah);

So, I interpreted the templates h1,h2,h3 as binned
pdf and built the model with fraction:
model=c1*h1+(1-c2)*h2+(1-c1-c2)*h3
and tried to fit the data. I tried to change initial values for c1 and c2 but nothing changes:

The fit fails giving as output:

[#0] WARNING:Minization -- RooMinuitGlue: Minimized function has error status.
Returning maximum FCN so far (-1e+30) to force MIGRAD to back out of this region. Error log follows
Parameter values: c1=5000, c2=5000
RooNLLVar::nll_model_datah[ paramSet=(c1,c2) ]
     function value is NAN @ paramSet=(c1 = 5000,c2 = 5000)
RooAddPdf::model[ c1 * montecarlob + c2 * montecarloc + [%] * montecarloq ]
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 0/200), !coefficients=(c1 = 5000,c2 = 5000)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 0/200), !coefficients=(c1 = 5000,c2 = 5000)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 0/200), !coefficients=(c1 = 5000,c2 = 5000)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 0/200), !coefficients=(c1 = 5000,c2 = 5000)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 0/200), !coefficients=(c1 = 5000,c2 = 5000)
     p.d.f value is less than zero (-399.960000), forcing value to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 8/200), !coefficients=(c1 = 5000,c2 = 5000)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 8/200), !coefficients=(c1 = 5000,c2 = 5000)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 0/200), !coefficients=(c1 = 5000,c2 = 5000)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(montecarlob = 0/100,montecarloc = 0/150,montecarloq = 0/200), !coefficients=(c1 = 5...........

I found that it can be a problem of pdf evaluated as negative in some points, but It is not my case.
Can anybody help me?
In the attachment I uploaded the histograms and data.template_2D.root (5.3 KB)

Thank you in advance

Laura

perhaps @moneta or @vcroft can help here?

Thank you,
Oksana.

Hi Laura,
I think the issue might be coming from the fact that a RooHistPdf has no parameters (it’s just a non-parametric shape) therefore all three terms are removed from the fit.

The usual practice to to extend each pdf with the expected number of events then you can scale each histogram up and down to fit the data or to make the final number of the events and the fraction of each type.

Whilst I’m here though I will point out that you’ve defined two co-efficients to go from 0, 10000 (and the model you give is different from the one roofit claims in the error message) to me this doesn’t really make much sense because in almost all cases the second histogram is going to be 1-[0,10000] and therefore negative. So have a think about your model and which coefficients you want and what ranges they can take.

I hope this helps and good luck!
~/Vince

1 Like

Hi,

sorry for the delay in my answer, I had to think about these things a lot. Thank you for your contribution, anyway for future readers: the problem in the failed fit was due to the fact that in some of the bins the pdf was zero. I had to set the xrange and yrange in such a way that all the three pdf given by h1,h2,h3 were positive defined in the entire range of fitting and not zero. I thought that it was important only that the pdf was >=0, and not >0. Now it works.
Thank you anyway for all observation.

Laura

1 Like

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