Drawing vector of custom class to a tree including string

I have a custom class Hit and I create a branch in my tree with a std::vector.
Hit contains the std::string detectorname.
When want to draw Hit.detectorname or use a filter based on it, it doesn’t work, because Hit.detectorname always gives me the first element of the vector of my Entry. The same happens with Scan.
When I look at my class in a TBrowser, I get the same error as descibed in I cannot store string in tree - #4 by Goktug_Bayram or Writing a TString into a TTree
This just happens with the std:string and not with other class members.
As a workaround, I can use Hit.detectorname.c_str(). This works, but just Hit.detectorname doesn’t.
Why doesn’t a std::string directly work? How can I use Draw/Scan without calling a method?
A bit related, but no solution:
Storing vector<string> class member in TTree
Possible bug in TTree::Draw with vector of strings

Hi,

Thanks for the post and welcome to the ROOT Community!
I am sorry you are experiencing this issue. I add @pcanal in the loop.

In the meantime, I have a suggestion. Have you tried to use RDataFrame for your study? That is the interface we support and suggest to study columnar datasets.

If you are willing to share with the community the input file, I can provide an initial straperson implementation of the selection you can then work on to achieve exactly what you are after.

Cheers,
D

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