Hello!
I’m trying to make a template out of two datasets, to fit it into another.
I tried using a method show in https://root.cern.ch/doc/master/rf706__histpdf_8C.html to turn the template datasets into histograms, so I could use RooAddPdf to add them together and fit the result.
This is the relevant part of the code:
TString flatfile = "Data.txt";
TString signal = "Signal1.txt";
TString background = "Background.txt";
RooRealVar* PtPair = new RooRealVar("PtPair","p_{#perp}(#mu^{+}#mu^{-})",0.0,5.0,"GeV");
RooDataSet *datatmp = 0;
RooDataSet *datasignal = 0;
RooDataSet *databackground = 0;
datatmp = RooDataSet::read(flatfile,RooArgList(*PtPair));
datasignal = RooDataSet::read(signal,RooArgList(*PtPair));
databackground = RooDataSet::read(background,RooArgList(*PtPair));
RooDataHist *hist1 = datasignal->binnedClone();
RooHistPdf histpdf1("histpdf1", "histpdf1", *PtPair, *hist1, 0);
RooDataHist *hist2 = databackground->binnedClone();
RooHistPdf histpdf2("histpdf2", "histpdf2", *PtPair, *hist2, 0);
RooAddPdf* totshape = new RooAddPdf("totshape","combined shapes",RooArgList(histpdf1,histpdf2));
RooFitResult *fitres = totshape->fitTo(*datatmp,RooFit::FitOptions("MHTER"));
My issue is that the code throws the following error
[#0] ERROR:InputArguments -- RooHistPdf::ctor(histpdf1) ERROR variable list and RooDataHist must contain the same variables.
[#0] ERROR:InputArguments -- RooHistPdf::ctor(histpdf2) ERROR variable list and RooDataHist must contain the same variables.
I don’t know what that means. “*PtPair” is the only variable in use. What am I missing here?
Also, if anyone knows a better way to do this, your guidance is welcome.