How to round values before plotting 2D histogram from TTree

Hi,

I want to plot a 2D histogram from a TTree, I use the following command :

tree11->Draw("(1.6*QdcQ[1]/1.5):1.6*QdcQ[0]>>h12");

and I get the following plot :

image

But it seems that I have decimal values (as I multiply and divide with decimal numbers before plotting), I would like to round the values in the branches before plotting, how can I do it, I tried using Nint but it doesn’t work.

Thank you !

ntuple->Draw("TMath::Nint(px):py")

I tried this but still it doesn’t work :

What I did was I set the maximum of the histogram and then plot like :

h12->SetMaximum(5);
tree11->Draw("TMath::Nint(1.6*QdcQ[1]/1.5):(TMath::Nint(1.6*QdcQ[0]))>>h12");

and I have the same figure.

You said:

That is exactly what TMath::Nint does in the last command you posted. What should be an integer? axis value or the histogram content (the histogram content is also btw)?

I see that in the color palette, I have values from 1 to 5 (from the figure), with decimal values, I want to have rounded values here ie., I want to round the histogram content.

The histogram h12 is filled with integer values because by default the weight of each “fill” is 1. The fact palette axis shows decimal values does not mean your histogram has decimal contents. It is only because the number of divisions for the Z axis is too large. Reduce it until you see integer values only.

Also, if your historgam has only 4 values on Z you might want to have a palette with 4 colors only.

I tried to reduce the Z axis but still I dont get integer values, also I made a palette with 4 colours.
I am attaching the root file here with.
[try.root|attachment]
nez.root (1.8 MB)

h12->GetZaxis()->SetNdivisions(5);

Amazing! That works…
Thank you for the prompt response.

1 Like

If that’s you want I am not sure you need the Nint in the draw command