GetEntries selection string help

I need some help using the GetEntries command in root. I have a root file with 3 million entries in a tree named “store” and I know that by using the command

store->GetEntries(“x_det>-100”)

Root will return the number of entries that fit these criteria. But with the data set I have I need to put this statement in a loop so that I have something like

store->GetEntries(“x_det>-100 && x_det <10”)
store->GetEntries(“x_det>-100 && x_det <9.5”)
etc.

So my first test was to see if I could define a string, named “selection”, that is defined as follows

string str = "\"x_det>-"+to_string(100)+"\"";
const char* selection = str.c_str();

And then have selection be the argument in GetEntries(). I’ve printed the selection string to the terminal and confirmed that it is “x_det>-100”, but putting it in the GetEntries just returns the number of entries in the whole tree, as opposed to the 2.4 million or so entries that fit the constraint that x_det>-100. So I was wondering if my approach was correct, or if there is an easier way to accomplish what I need.

ROOT Version: 6.14.06
Platform: Linux
Compiler: Not Provided


You can do it on different ways, but to keep your method, just don’t explicitly inlcude the quotes (\") in str.

1 Like

That worked, thank you!