# RDataFrame: GetValue() raises an error after appyling a filter

**URL:** <https://root-forum.cern.ch/t/rdataframe-getvalue-raises-an-error-after-appyling-a-filter/49234>\
**Category:** Newbie\
**Created:** [March 17, 2022, 2:39pm UTC](https://root-forum.cern.ch/t/rdataframe-getvalue-raises-an-error-after-appyling-a-filter/49234 "2022-03-17T14:39:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lroehrig](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ce73a5/32.png) [@lroehrig](https://root-forum.cern.ch/u/lroehrig)\
**Post date:** [March 17, 2022, 2:39pm UTC](https://root-forum.cern.ch/t/rdataframe-getvalue-raises-an-error-after-appyling-a-filter/49234/1 "2022-03-17T14:39:56Z")

</div>

Dear forum,

I am new to `ROOT.RDataFrame` using pyroot and when executing

```auto
import ROOT

d = ROOT.RDataFrame("events", "ee_tt_ecm365/processed_file_004760802.root")

cut_muon_pt = "selected_muons_pt > 20."

# before applying the cut
print("Number of events ", d.Count().GetValue())

# applying the cut
entries = d.Filter(cut_muon_pt).Count()

# after applying the cut
print("{} entries passed the filter".format(entries.GetValue()))

```

with `python file.py`, the error message

Number of events 100000  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/input\_line\_9:15:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/etc/dictpch/allHeaders.h:331:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RCsvDS.hxx:14:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDataFrame.hxx:20:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/RInterface.hxx:18:  
/cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/InterfaceUtils.hxx:276:4: error: static\_assert failed due to requirement ‘std::is\_convertible\<ROOT::VecOps::RVec, bool\>::value’ “filter expression returns a type that is not convertible to bool”  
static\_assert(std::is\_convertible\<FilterRet\_t, bool\>::value,  
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
/cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/InterfaceUtils.hxx:389:17: note: in instantiation of function template specialization ‘ROOT::Internal::RDF::CheckFilter\<\_\_rdf::(lambda at input\_line\_62:2:16)\>’ requested here  
RDFInternal::CheckFilter(f);  
^  
input\_line\_65:2:23: note: in instantiation of function template specialization ‘ROOT::Internal::RDF::JitFilterHelper\<\_\_rdf::(lambda at input\_line\_62:2:16) &, ROOT::Detail::RDF::RNodeBase\>’ requested here  
ROOT::Internal::RDF::JitFilterHelper(\_\_rdf::lambda0, new const char\*[1]{“selected\_muons\_pt”}, 1, “”, reinterpret\_cast\<std::weak\_ptr ROOT::Detail::RDF::RJittedFilter\*\>(0x56adcf0), reinterpret\_cast std::shared\_ptrROOT::Detail::RDF::RNodeBase\*\>(0x5729e10),reinterpret\_castROOT::Internal::RDF::RBookedDefines\*\>(0x5d61f70));  
^  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/input\_line\_9:15:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/etc/dictpch/allHeaders.h:331:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RCsvDS.hxx:14:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDataFrame.hxx:20:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/RInterface.hxx:18:  
In file included from /cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/InterfaceUtils.hxx:18:  
/cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/RFilter.hxx:108:14: error: no viable conversion from returned value of type ‘ROOT::VecOps::RVec’ to function return type ‘bool’  
return fFilter(fValues[slot][S]-\>template Get(entry)…);  
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
/cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/RFilter.hxx:92:27: note: in instantiation of function template specialization ‘ROOT::Detail::RDF::RFilter\<\_\_rdf::(lambda at input\_line\_62:2:16), ROOT::Detail::RDF::RNodeBase\>::CheckFilterHelper\<ROOT::VecOps::RVec , 0\>’ requested here  
auto passed = CheckFilterHelper(slot, entry, ColumnTypes\_t{}, TypeInd\_t{});  
^  
/cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/RFilter.hxx:67:4: note: in instantiation of member function ‘ROOT::Detail::RDF::RFilter\<\_\_rdf::(lambda at input\_line\_62:2:16), ROOT::Detail::RDF::RNodeBase\>::CheckFilters’ requested here  
RFilter(FilterF f, const ColumnNames\_t &columns, std::shared\_ptr pd,  
^  
/cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RDF/InterfaceUtils.hxx:398:40: note: in instantiation of member function ‘ROOT::Detail::RDF::RFilter\<\_\_rdf::(lambda at input\_line\_62:2:16), ROOT::Detail::RDF::RNodeBase\>::RFilter’ requested here  
std::unique\_ptr(new F\_t(std::forward(f), cols, _prevNodeOnHeap, defines, name)));  
^  
input\_line\_65:2:23: note: in instantiation of function template specialization ‘ROOT::Internal::RDF::JitFilterHelper\<\_\_rdf::(lambda at input\_line\_62:2:16) &, ROOT::Detail::RDF::RNodeBase\>’ requested here  
ROOT::Internal::RDF::JitFilterHelper(\_\_rdf::lambda0, new const char[1]{“selected\_muons\_pt”}, 1, “”, reinterpret\_cast\<std::weak\_ptr ROOT::Detail::RDF::RJittedFilter \>(0x56adcf0), reinterpret\_cast std::shared\_ptr ROOT::Detail::RDF::RNodeBase\>\>(0x5729e10),reinterpret\_cast ROOT::Internal::RDF::RBookedDefines_\>(0x5d61f70));  
^  
/cvmfs/tmp/spack-stage/gitlab-runner/spack-stage-root-6.24.06-wgcjycjact5ghiy56f7m2laef4ag3e4q/spack-build-wgcjycj/include/ROOT/RVec.hxx:372:4: note: candidate template ignored: could not match ‘RVec’ against ‘bool’  
operator RVec() const  
^  
Traceback (most recent call last):  
File “loop.py”, line 14, in   
print("{} entries passed the filter".format(entries.GetValue()))  
cppyy.gbl.std.runtime\_error: const ULong64\_t& ROOT::RDF::RResultPtr\<ULong64\_t\>::GetValue() =\>  
runtime\_error:  
An error occurred during just-in-time compilation in RLoopManager::Run. The lines above might indicate the cause of the crash  
All RDF objects that have not run their event loop yet should be considered in an invalid state.

is printed. I’m using this setup on lxplus and don’t really have a clue, why the first `GetValue()` function works properly but the second failed after the filter is used. When commenting out the last print command, no error occurs.

_ROOT Version:_ 6.24/06  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 17, 2022, 2:44pm UTC](https://root-forum.cern.ch/t/rdataframe-getvalue-raises-an-error-after-appyling-a-filter/49234/2 "2022-03-17T14:44:49Z")

</div>

Hi @lroehrig ,  
and welcome to the ROOT forum!  
The relevant part of the error message is

> std::is\_convertible\<ROOT::VecOps::RVec, bool\>::value’ “filter expression returns a type that is not convertible to bool”

I guess `selected_muons_pt` is an array, so `"selected_muons_pt > 20."` returns an array (i.e. an RVec) rather than a single boolean value. `Filter` requires expressions to return a single boolean value because it filters whole events.

If you want to keep the pt of muons that are higher than 20, you can use a `Define`, e.g.:

```python
df.Define("good_pts", "selected_muons_pt[selected_muons_pt > 20.]")

```

See also [ROOT: ROOT::RDataFrame Class Reference](https://root.cern/doc/master/classROOT_1_1RDataFrame.html#collections) .

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![lroehrig](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ce73a5/32.png) [@lroehrig](https://root-forum.cern.ch/u/lroehrig)\
**Post date:** [March 17, 2022, 3:09pm UTC](https://root-forum.cern.ch/t/rdataframe-getvalue-raises-an-error-after-appyling-a-filter/49234/3 "2022-03-17T15:09:50Z")

</div>

Hi @eguiraud,

Thanks a lot for this immediate help! So, when applying

```auto
d.Define("good_pts", "selected_muons_pt[selected_muons_pt > 20.]")

```

how exactly do I have to modify `d` such that it only contains the events where the muon pt is greater than 20?

Cheers,  
Lars

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 17, 2022, 4:08pm UTC](https://root-forum.cern.ch/t/rdataframe-getvalue-raises-an-error-after-appyling-a-filter/49234/4 "2022-03-17T16:08:30Z")

</div>

> [@lroehrig](#):
>
> how exactly do I have to modify `d` such that it only contains the events where the muon pt is greater than 20?

There are several muon pts for every event, so the problem is ill formed. For every event, you can select some array elements (e.g. elements of `muon_pt`) that satisfy the condition. That’s done with a `Define` as above.

Cheers,  
Enrico
