sumEntries(, cutRange) in pyROOT

There does not appear to be a way to sumEntries in a range directly using pyROOT. Calling

data.sumEntries('', 'somerange')

results in a complaint that the formula cannot compile:

Error in <RooFormula::Compile>:  Empty String
[#0] ERROR:InputArguments -- RooFormula::RooFormula(select): compile error
[#0] ERROR:Eval -- RooFormula::eval(select): Formula doesn't compile: 
[#0] ERROR:Eval -- RooFormula::eval(select): Formula doesn't compile: 

ad infinitum.

But I also cannot just pass 0 as in C++ because it throws a TypeError:

data.sumEntries(0, 'somerange')
TypeError: none of the 2 overloaded methods succeeded. Full details:
  double RooDataSet::sumEntries() =>
    takes at most 0 arguments (2 given)
  double RooDataSet::sumEntries(const char* cutSpec, const char* cutRange = 0) =>
    could not convert argument 1 (expected string or Unicode object, int found)

I can manually construct the range as a cutSpec, but this is, for obvious reasons, not preferable. Any advice?

@StephanH, can you take a look please here?

Thanks,
Oksana.

Could you try:

data.sumEntries(ROOT.nullptr, 'range')
data.sumEntries(ROOT.nullptr, "testrange")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-0759a04daf10> in <module>()
----> 1 data.sumEntries(ROOT.nullptr, "testrange")

TypeError: none of the 2 overloaded methods succeeded. Full details:
  double RooDataSet::sumEntries() =>
    takes at most 0 arguments (2 given)
  double RooDataSet::sumEntries(const char* cutSpec, const char* cutRange = 0) =>
    could not convert argument 1 (expected string or Unicode object, nullptr_t found)

Ok, that will only work with the new cppyy. I can add a fix that it also handles an empty string gracefully. That can be released in the next version of ROOT 6.16 and ROOT 6.18.

You might be able to pass something that evaluates to a true value. Try “1” as selection formula.

Thank you for the workaround:

In [8]: data.sumEntries("1", "testrange")
Out[8]: 459928.0
In [9]: data.sumEntries()
Out[9]: 1710337.0
In [10]: data.sumEntries("1")
Out[10]: 1710337.0

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