Integer division of Iteration$ returns a Double_t

Hi,

When I do an integer division (using the forward slash /) on the tree special variable Iteration$ by an integer, I was expecting an integer result, but instead I get a double.

My task is this: I have a 2-D array on a tree branch, say array[4][3] of type float. To plot the entries as a 2-D histogram. I do this:

tree->Draw(“array:iteration$%4:iteration$/4”).

The term iteration$%/4 gives correct integer values, ranging from 0 to 3.

The term iteration$/4 should have returned integer values in the following order: 0 0 0 0 1 1 1 1 2 2 2 2
Instead, I get: 0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.25 2.5 2.75.

Why integer division did not work in the above situation?

Is there a simple way to cast the result to an integer? (I tried various rounding methods (e.g. round(iteration$/4), but the formula is not accepted when explicitly given).

Is there a simple solution?

Thanks for your help

Vi-Hoa

Hi,

All the arithmetic in TTree::Draw is done in double precision.

You can not used round, but you can use the function in TMath, for example TMath::Floor:tree->Draw("array:iteration$%/4:TMath::Floor(iteration$/4)");

Cheers,
Philippe.

Thanks Philippe for the solution

Vi-Hoa