RooFit when Histogram has negative values

Dear experts, I’m using a model A * (s0 + a1*d1 + a2*d2) to fit the data energy spectrum. s0 is a nominal spectrum. And d1, d2 are difference spectra. I would like to how to construct this model. I used the following method. But the fitting result doesn’t seem right. Setting a1, a2 as constant just for test. The green line is A*original normalize s0 hist. Could you help me?

RooDataHist dh_s0(“dh_s0”, “nominal shape data”, RooArgSet(x), mc_hists[0]);

RooHistPdf s0("s0_pdf", "nominal shape", RooArgSet(x), dh_s0); 

RooDataHist dh_d1("dh_d1", "delta1 shape data", RooArgSet(x), delta1);

RooHistFunc d1("d1", "delta1 shape", RooArgSet(x), dh_d1);

RooDataHist dh_d2("dh_d2", "delta2 shape data", RooArgSet(x), delta2);

RooHistFunc d2("d2", "delta2 shape", RooArgSet(x), dh_d2);

RooRealVar A("A", "whole factor", dataIntegral\*0.6, 1000, 2000);

RooRealVar a1("a1", "Δ1", 0, 0, 0.01);

RooRealVar a2("a2", "Δ2", 0, 0,0.01);

a1.setConstant(true);

a2.setConstant(true);

RooFormulaVar model_val(“model_val”, “s0 + a1*d1 + a2*d2”, RooArgList(s0, a1, d1, a2, d2));

RooGenericPdf shape_pdf("shape_pdf", "@0", RooArgList(model_val, x));  

RooExtendPdf corrected_pdf("corrected_pdf", "extended model", shape_pdf, A);

RooFitResult* result_chi2 = corrected_pdf.chi2FitTo(data,

    RooFit::Save(true),       

    RooFit::PrintLevel(-1),   

    RooFit::Strategy(1),       

    RooFit::Minimizer("Minuit2", "Migrad"),

    RooFit::Hesse(true),

    RooFit::Extended(true)

);

Hi @Jasmine,

thanks for your question. I will add @jonas to give you some insights.

Cheers,

Marta