Making a template out of two datasets

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.

Have you tried to create the RooAddPdf passing as well the RooArgList of yield parameters?

According to the documentation of RooAddPdf the constructor passing only a list of pdf is valid if the pdfs passed are already extended, i.e have a yield associated. I suspect this might be the reason of the error

1 Like

Hi @Kim_Enghusen, welcome to the ROOT forum!

The problem why this doesn’t work is an undocumented feature of RooDataSet::read(), which silently adds a “blindState” column to the dataset. If you would print your datasignal for example, you would see this:

RooDataSet::dataset[PtPair,blindState] = x entries

But to create the RooHistPdf, it should not have these superfluous columns. You need to create another temporary dataset with only the PtPair column. You can do this with RooAbsData::reduce(), like:

RooDataSet * datasignalreduced = static_cast<RooDataSet*>(datasignal->reduce(RooFit::SelectVars(PtPair)));

Hope this helps, sorry for the additional complication!

And of course @RENATO_QUAGLIANI is also right, you can’t use the RooAddPdf constructor that doesn’t take coefficients if your PDF is not an extended PDF.

Also, you should not use the deprecated FitOptions in the call to RooAbsPdf::fitTo(). Please use the right command arguments to achieve what you want to do.

Cheers,
Jonas

1 Like

Thank you! There was an error complainig that “SelectVars” was an undeclared identifier, but it seemed to work fine with just “…reduce(*PtPair)…”.

As for @RENATO_QUAGLIANI, I added the coeficcients to RooAddPdf. Thank you, too!

Right, sorry it should have been RooFit::SelectVars. I edited that in my original answer.

1 Like

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