TDataFrame Suggest: !Filters

I’m not sure if suggestions should be made here but I have one.

Often we want to separate two classes of events, those passing a cut, vs those not passing a cut.

If I define a lambda like this

auto cut = [](bool b) {return b == true;};

I’d like to do something like this.

ROOT::Experimental::TDataFrame df("T", "file.root");
df.Filter(cut,{"bool_branch"}).Histo1D("some_other_branch");
df.Filter(!cut,{"bool_branch"}).Histo1D("some_other_branch");

As of now this returns an error. Is anything like this possible/coming in the foreseeable future?

1 Like

Hi,

we take note of this request: it makes sense.

Cheers,
Danilo

Hi Noah,
I agree with Danilo that is a good idea to offer some syntactic sugar for this case.
In the meanwhile, this is as good and performant as it gets:

auto cut = [](bool b) {return b == true;};
auto notcut = [&](bool b) { return !cut(b); }; 

Cheers,
Enrico

Hi Noah, you can copy over the TDF::Not experimental implementation here if you are sorely missing the feature.

Cheers,
Enrico

Thanks, this works perfectly.

For future reference/searches: master now has ROOT/TDFHelpers.hxx which implements TDF::Not which implements a slightly better version of my gist above.
It will be part of the next ROOT release, v6.13

1 Like

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