RDataFrame Filter Error not seen

Dear ROOT developers,

I am using RDataFrame with pyROOT. I was applying a filter in the following way:

rdf = RDataFrame('ttree', 'file')
sel = rdf.Filter('1. < var < 2.')

The problem now was that my resulting histogram

histo = sel.Histo1D('var')

did not just show values of ‘var’ between 1 and 2, as expected, but had not been filtered at all. I believe that the reason for this is that I had not entered valid C++ code for my filter. However, ROOT did not throw an error. If the string in the filter was ‘1 < var < 2’, I did get an error, but changing the ints to floats prevented ROOT from showing them.

Kind Regards,

ROOT Version: 6.14/04
Platform: Cent OS 7

Hi Ben,

interesting riddle :slightly_smiling_face:
The filter strings, as well as the define ones, are proper C++. What is happening is that your expression is evaluated as follows: (1. < var) < 2. which is always true.
The right string to use is 1. < var && var < .2.


Hi D,

thank you for that explanation! Now I understand, why ROOT gives me that error message, when both bounds are integers. However it does not give me that error, if the right value is a double, as you wrote. Is there a possibility to make ROOT do that? (like typecasting both numbers in the check or similar)


ROOT internally picks your string, which must be valid C++, and constructs a C++ function which is then jitted by ROOT’s interpreter. I think there is not much to do on ROOT’s side while on the other hand, on the user side, there is quite some freedom.


1 Like

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