Hello,
I am trying to create histogram which will have only positively charged hadronic taus in it using RDataFrame and I get following error :
Error in <TTreeReaderValueBase::CreateProxy()>: The branch GenVisTau_charge contains data of type {UNDETERMINED TYPE}, which does not have a dictionary.
terminate called after throwing an instance of 'std::runtime_error'
what(): An error was encountered while processing the data. TTreeReader status code is: 6
The main script which is supposed to return tau pt for only + charge is following:
auto genVisTau_pt_plus = df.Define("GenVisTau_pt_plus", [] (
const uint& nGenVisTau,
const int& charge,
const rvec<float>& genVisTau_pt){
rvec<float> gentau_pt;
for(uint i = 0 ; i < nGenVisTau ; i++){
if( charge == 1){
gentau_pt.push_back(genVisTau_pt[i]);
}
}
return gentau_pt;
} , {"nGenVisTau", "GenVisTau_charge", "GenVisTau_pt"});
What I normally would have tried is instead of
if ( charge == 1 )
if ( charge[i] == 1 )
, but it does not seem to work. With the later one I get invalid types 'int[int]' for array subscript
error, after which I googled and tried this if ( charge[i][0] == 1 )
, but it also does not work.
As it seems I have a caveat in understanding how this works in RDataFrame. I would appreciate any help, thanks!
Worked like this, maybe can be useful for someone else 
const uint& nGenVisTau,
const rvec<int>& charge,
const rvec<float>& genVisTau_pt){
rvec<float> gentau_pt;
for(uint i = 0 ; i < nGenVisTau ; i++){
if( charge[i] == 1 && charge[i] != -1){
gentau_pt.push_back(genVisTau_pt[i]);
}
}
return gentau_pt;
} , {"nGenVisTau", "GenVisTau_charge", "GenVisTau_pt"});
Hi @beg1nner ,
sorry for the trouble! If GenVisTau_charge
is an array of integers, then the right type to use to read it is ROOT::RVec<int>
(or, with the latest ROOT, ROOT::RVecI
). You can check what type the column is with df.GetColumnType("GenVisTau_charge")
.
Now, you should not get that error message if you use the wrong type for a column. RDF should print a message that’s a bit friendlier and tells you about the type mismatch issue.
What ROOT version are you using?
Cheers,
Enrico
Hi @eguiraud ,
Thank you for your response. I have posted the solution to my question shortly before your answer. Indeed, using RVec
solved the issue.
I’m using ROOT 6.24/00 with g++ (GCC) 10.1.0 . As you said, it would be nicer to see a friendlier error, because with this one I did not immediately get that it has problems with type.
Cheers
it would be nicer to see a friendlier error, because with this one I did not immediately get that it has problems with type
I totally agree – the weird thing is, you should have gotten a friendlier error
If you can share a minimal reproducer with me (including data) I could check what the behavior is with the latest ROOT version.
For example the following code:
#include <ROOT/RDataFrame.hxx>
int main()
{
// write an array of ints
ROOT::RDataFrame(10).Define("arr", "ROOT::RVec<int>{1,2,3}").Snapshot("t", "test.root");
// read it back as int instead of RVec<int>
ROOT::RDataFrame("t", "test.root").Define("x", [](int a) { return a; }, {"arr"}).Count().GetValue();
}
produces:
Error in <TTreeReaderValueBase::CreateProxy()>: The branch arr contains data of type ROOT::VecOps::RVec<int>. It cannot be accessed by a TTreeReaderValue<int>
terminate called after throwing an instance of 'std::runtime_error'
what(): An error was encountered while processing the data. TTreeReader status code is: 6
fish: Job 1, './foo' terminated by signal SIGABRT (Abort)
Cheers,
Enrico