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