Error from reducing specific bin in RooFit

Hello, When I try to mass fit with Roofit I get the error that some observables have the nan value.
The command is here:

kineCut = Form("pt>%.2f && pt<%.2f && abs(y)>%.2f && abs(y)<%.2f && mass>3.3 && mass<4.1",ptLow, ptHigh, yLow, yHigh);
RooDataSet *dataset = (RooDataSet*)f1->Get("dataset");
  RooWorkspace *ws = new RooWorkspace("workspace");
RooDataSet *datasetW = new RooDataSet("datasetW","A sample",*dataset->get(),Import(*dataset),WeightVar(*ws->var("weight")));
RooDataSet *dsAB = (RooDataSet*)datasetW->reduce(RooArgSet(*(ws->var("ctau3DRes")),*(ws->var("ctau3D")), *(ws->var("ctau3DErr")), *(ws->var("mass")), *(ws->var("pt")), *(ws->var("y"))), kineCut.Data() );

And the result is:

RooRealVar::mass = 3.80474  L(3.3 - 4.1) // [GeV/c^{2}]
DataStore datasetW ( a dataset)
  Contains 198630 entries
    1)  ctau3DRes = nan  L(-100000 - 100000)  "c_{#tau}"
    2)     ctau3D = nan  L(-100000 - 100000) // [mm] "c_{#tau}"
    3)  ctau3DErr = 0.0421883  L(-100000 - 100000) // [mm] "#sigma_{c#tau}"
    4)       mass = 3.9282  L(1 - 6) // [GeV/c^{2}] "mass variable"
    5)         pt = 3.47502  L(0 - 100) // [GeV/c] "pt variable"
    6)          y = 2.01023  L(-5 - 5)  "rapidity of the dimuon pair"
  Dataset variable "weight" is interpreted as the event weight

The ctau3D has the nan value only when I reduce in the specific bin with ptLow is 3 & 1.6<|y|<2.4.
Is anybody know this issue and the solution?

I think @moneta can help.

Hi @gbak!

Sorry it’s impossible without the .root file to debug what the problem is.

Is there any way you can share the input file so we can reproduce the problem?

Thanks and cheers!

Hello @jonas!

I uploaded the file here:
Or you can download the root file from the link.

Thanks a lot!

Hi @gbak, thanks for providing the file so quickly!

I have inspected it, and it seems that the nan value is already in the file itself. You can check it with this simple script:

void repro()
   std::unique_ptr<TFile> f1{
      TFile::Open("OniaRooDataSet_isMC0_Psi2S_pp_y0.00_2.40_Effw0_Accw0_PtW0_TnP0_230117.root", "READ")};

   auto dataset = f1->Get<RooDataSet>("dataset");


   auto &ctau3D = static_cast<RooRealVar &>((*dataset->get())["ctau3D"]);

   // do iteration over dataset to see which values of ctau3D are nan
   for (std::size_t i = 0; i < dataset->numEntries(); ++i) {
      dataset->get(i);              // load entry "i"
      double val = ctau3D.getVal(); // get value of ctau3D for entry "i"
      // simple check for nan values (if it's nan, if will not be in any range)
      if (!(val > ctau3D.getMin() && val < ctau3D.getMax())) {
         std::cout << val << std::endl; // you will see the printed nans here

So you do everything correct. The problem is that the nans are already in the input file. Maybe you should ask the person who gave you the file why it contains nans? We can probably not tell you this here on the forum :slight_smile:


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