Order of TCuts interpretation when drawing

(not sure if this should go under “CINT discussion”; apologies if it should)

If I have a series of TCuts:
TCut c1 = “…”;
TCut c2 = “…”; , etc
does it make a difference in performance what order the cuts appear in the logic expression when drawing? e.g.

tree->Draw(“x”, c1 && c2 && c3);
vs
tree->Draw(“x”, c3 && c1 && c2);

Certain C++ compilers go from left to right, e.g. if a TCut is a simple calculation and often false, I’d think it’d be better to be placed all the way to the left of the expression to speed things up.

–Christos

[quote=“christos”]tree->Draw(“x”, c3 && c1 && c2);

Certain C++ compilers go from left to right, e.g. if a TCut is a simple calculation and often false, I’d think it’d be better to be placed all the way to the left of the expression to speed things up.
[/quote]

There is a rule how to evaluate “logical expressions”, and the rule says: left to right. It’s very important, otherwise things like
do_something() || exit(); don’t work - first do something, then exit, not the other way around.

The only problem (but a completely different story) is parameter precedence: Some compilers do it from the left to the right, some the other way around, so method(i=1,++i,++i,i=1) can either give method(1,2,3,1) or method(1,3,2,1). Yepp, very nasty to debug.

Summary: for ands, things that almost always fail should go first.
Axel.

Hi Christos,

Currently, TTreeFormula (hence TTree::Draw with TCuts) does not perform any arithmetic optimization and always calculate each of the terms of the expression.

The only case where the order (of comutative operands) would matter is if one (or more) of them call functions or members function with side-effects.

In that case, you might be better served by doing a first pass with that cut and save the result in a TEventList.

Cheers,
Philippe.