Can the variables inside the UserInfo object be used inside Draw?


I have a tree with a UserInfo object. I can access it and check the values stored within:

root [10] .L MyHeader.cpp++
root[11] MyHeader *emh=(MyHeaderr*) tree->GetUserInfo()->At(0)
root[12] emh->GetAverages()
(unsigned short)256

I would like to use the variables stored inside the UserInfo object inside the Draw command, either as varexp or selection strings.

Error in <TTreeFormula::Compile>:  Bad numerical expression : "emh.GetAverages()"

same problem if I use them in the selection field:


Can the variables inside the GetUserInfo object be used at all inside Draw???

One possible way:

root[10] .L MyHeader.cpp++
root[11] MyHeader *emh=(MyHeaderr*) tree->GetUserInfo()->At(0)
root[12] int avr = emh->GetAverages()
root[13] tree->Draw(Form("%d",avr))

Dear Olivier,

thank you for the answer.

But this solution does not work if I want to use the info stored in UserInfo to make a selection. For instance, the data member Averages (returned by GetAverages) is not recognized inside Draw, even if I can access it in the interactive shell:

root[56] emh->Averages
(unsigned short)256
root[57] emh->Draw(“1”,“emh->Averages==256”)
Error in TTreeFormula::Compile: Bad numerical expression : “emh.Averages”

Then, can I answer the question in the original message “Can the variables inside the GetUserInfo object be used at all inside Draw???” with a “no”

Thank you

emh->Averages is a single int in your case. So you can do:

root[56] int avr = emh->Averages
root[57] emh->Draw("1",Form("%d==256",avr))

Note the use of the Form function …

Thank you.

I see that we need then always the workaround of evaluating the value of the variable before the actual Draw.

Therefore I will not be able to plot:


and then, I would say that in general one can not use literally in tree::Draw the variables stored inside UserInfo. Therefore, if you need to plot/make selections in these variables, it is best to store them as leaves of a branch, despite the fact that they may not change inside the file (but they can change between different files, so one can see that change when chaining files).

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