TTree Draw with ternary conditional

Hi,
I have a TTree which has several branches etc. If I want to histogram a certain variable, satisfying certain conditions, I would normally do, for example:

h1= new TH1F("h1","h1",32,0,3.2); tree->Draw("var1>>h1","var2>20");
Now, the problem is that what if I want to draw the value of var1 if condition is satisfied OR some dummy number, let’s say -99, if condition “var2>20” fails? I was trying to do something like a ternary conditional in the Draw:

but this apparently didn’t work. Could someone please suggest how to implement this, if it is possible?

Artur.

Try:

Cheers,
Philippe

Thanks a lot Philippe, this really saved me!
I think it would be very nice if this was documented on TTree webpage, or did I miss it?

Artur.

[quote]I think it would be very nice if this was documented on TTree webpage, or did I miss it? [/quote]This is not documented per se :slight_smile:. This is just a subtle abuse of the usual arithmetic :slight_smile:

Cheers,
Philippe.

PS. Indeed we ought to have such an example :slight_smile:

Yes, now that you gave it, it seems obvious. But as you said, it would be nice to have an example. It is a nice feature, and I imagine could be usefull for many.

Artur.