ROOT Version: 6.24
Platform: Red Hat Enterprise Linux 7.9
Compiler: GCC 10.2.0
Dear experts,
I am trying to create a composite PDF from two RooHistPdf’s and then perform a fit to a RooDataHist. Each RooHistPdf is created in one script and saved into a RooWorkspace to be opened in another script:
//Open input file
TFile * f1 = new TFile("Rho_FullExtractedYieldMap.root");
RooRealVar mpipi0("InvM_pipi0", "M_{#pi#pi^{0}}", 0.25, 3.5);
//Project the 2D histogram down into 1D
TH2F * sigYieldHist = (TH2F * ) f1 -> Get("yieldHist");
TH1D * sig1DYieldHist = sigYieldHist -> ProjectionY("sig1DYieldHist", 1, 10);
//Create binned dataset from histogram
RooDataHist * dataHist1 = new RooDataHist("dataHist1", "dataHist1", mpipi0, Import(* sig1DYieldHist));
//Create histogram PDF from the binned dataset
RooHistPdf * histPdf = new RooHistPdf("histPdf", "histPdf", mpipi0, *dataHist1)
//Save the result
TFile * f2 = new TFile("Rho_Mpipi0WeightedPDF.root", "RECREATE");
RooWorkspace *myWorkspace = new RooWorkspace("myWorkspace","myWorkspace");
myWorkspace -> import(*histPdf);
myWorkspace -> Print();
myWorkspace -> Write();
f2 -> Close();
And I open and try to fit it here:
//Prepare file to fit to
TFile * f1 = new TFile("SigRho_10-90FullExtractedYieldMap.root");
TH2F * sigrhoYieldHist = (TH2F * ) f1 -> Get("yieldHist");
TH1D * sigrho1DYieldHist = sigrhoYieldHist -> ProjectionY("sigrho1DYieldHist", 1, 10);
double TotalSize = sigrho1DYieldHist -> GetEntries();
RooRealVar mpipi0("InvM_pipi0", "M_{#pi#pi^{0}}", 0.25, 3.5);
RooDataHist * dataHist = new RooDataHist("dataHist", "dataHist", mpipi0, Import(* sigrho1DYieldHist));
//Prepare PDF to fit
TFile * f2 = new TFile("Sig_Mpipi0WeightedPDF.root");
TFile * f3 = new TFile("Rho_Mpipi0WeightedPDF.root");
RooWorkspace * sigWorkspace = (RooWorkspace *) f2 -> Get("myWorkspace");
RooWorkspace * rhoWorkspace = (RooWorkspace *) f3 -> Get("myWorkspace");
RooAbsPdf * sigMpipi0Pdf = sigWorkspace -> pdf("histPdf");
RooAbsPdf * rhoMpipi0Pdf = rhoWorkspace -> pdf("histPdf");
double sigMean = sigFrac*TotalSize*0.01;
double rhoMean = rhoFrac*TotalSize*0.01;
RooRealVar nSig("nSig", "Number of signal events", sigMean, 0.9*sigMean, 1.1*sigMean);
RooRealVar nRho("nRho", "Number of D rho events", rhoMean, 0.9*rhoMean, 1.1*rhoMean);
RooExtendPdf * sigExtended = new RooExtendPdf("sigExtended", "sigExtended", * sigMpipi0Pdf, nSig);
RooExtendPdf * rhoExtended = new RooExtendPdf("rhoExtended", "rhoExtended", * rhoMpipi0Pdf, nRho);
RooAddPdf * totalPdf = new RooAddPdf("totalPdf", "totalPdf", RooArgSet(* sigExtended, * rhoExtended), RooArgSet(nSig, nRho));
//Do the fit
RooFitResult * fitRes = totalPdf -> fitTo( * dataHist, Extended(kTRUE), SumW2Error(kTRUE), Offset(kTRUE), NumCPU(16), PrintLevel(1), Save());
//Plot the full result
RooPlot * range = mpipi0.frame(Name("range"), Title("Mixed Sample"));
dataHist -> plotOn(range, MarkerColor(kBlack), Name("data"), DataError(RooAbsData::SumW2));
totalPdf -> plotOn(range, LineColor(kBlue), Name("model"));
range -> Draw();
I expect the minuit/migrad fitter to find the best values of ‘nSig’ and ‘nRho’ that give the best proportion of the two RooHistPdf’s that match the ‘dataHist’. Instead I get this error:
[#0] ERROR:Eval -- RooAbsReal::logEvalError(totalPdf) evaluation error,
origin : RooAddPdf::totalPdf[ nSig * sigExtended + nRho * rhoExtended ]
[#1] INFO:Minization -- RooNLLVar::evaluatePartition(nll_totalPdf_dataHist_GOF13) first = 16 last = 17 Likelihood offset now set to 360775
message : getLogVal() top-level p.d.f evaluates to zero
server values: !refCoefNorm=(), !pdfs=(sigExtended = 0/1,rhoExtended = 0/1), !coefficients=(nSig = 5.05246e+06,nRho = 561385)
[#1] INFO:Minization -- RooNLLVar::evaluatePartition(nll_totalPdf_dataHist_GOF15) first = 18 last = 20 Likelihood offset now set to -nan
[#0] ERROR:Eval -- RooAbsReal::logEvalError(nll_totalPdf_dataHist_GOF15) evaluation error,
origin : RooNLLVar::nll_totalPdf_dataHist_GOF15[ paramSet=(nRho,nSig) ]
message : function value is NAN
server values: paramSet=(nRho = 561385,nSig = 5.05246e+06)
RooMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-inf) to force MIGRAD to back out of this region. Error log follows.
Parameter values: nRho=561385 nSig=5.05246e+06
RooNLLVar::nll_totalPdf_dataHist[ paramSet=(nRho,nSig) ]
function value is NAN @ paramSet=(nRho = 561385,nSig = 5.05246e+06)
This last error is repeated many times. What I find strange is that the final plot where I draw totalPdf shows a well defined pdf across the whole range.
Regards, Kim