# X-maximum and x-minimum values TH1F

Hello, I would know the values of maximum and mininmum x-values of a TH1F
Following this topic How to know maximum value of histogram?

I used

``````int binmax = htempkinensp->GetMaximumBin();
double xMax = htempkinensp->GetXaxis()->GetBinCenter(binmax);
int binmin = htempkinensp->GetMinimumBin();
double xMin = htempkinensp->GetXaxis()->GetBinCenter(binmin);
``````

but I got the values
Maximum= 20575
Minimum= 20005

but it’s impossible because this is the hystogram

muons.cpp (3.8 KB)

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Looking at the plot of your histogram, it seems fine to me:
max. histogram contents (y = around 10) at x = `20575 = 20.575 x 10^3`
min. histogram contents (y = 0 or 1) at x = `20005 = 20.005 x 10^3`

Hi @Wile_E_Coyote … I see…therefore it isn’t what I need…
I need the minimum and maximum (i.e. the x range) values on the x axis (not the count)…
Looking the graph, they sound be approximately 20050 and 23710

min. x. (“included”) = `histogram->GetBinLowEdge(1)`
max. x (“excluded”) = `histogram->GetBinLowEdge(histogram->GetNbinsX() + 1)`

Hello @Wile_E_Coyote thank you but it looks like that this code write the lower and upper limit of the x-range because writing

``````double xMin = htempkinensp->GetBinLowEdge(1);
double xMax = htempkinensp->GetBinLowEdge(htempkinensp->GetNbinsX() + 1);
``````

I get

``````Maximum= 23800
Minimum= 20000
``````

i.e. all the x-range…but by the plot I don’t have counts at 20000MeV and at 23800MeV…As I wrote yesterday they should be approximately they sound be approximately 20050 and 23710

I mean…I want the minimum value of the kinetic energy (it looks like to be approximately 20050MeV) and the maximum one (it looks like to be approximately 23710MeV)

Ps. Data are storered in a TTree (I fill the hysogram by the TTree…) maybe it’s possible to read the minimum and maximum x-values by the TTree?

`int binmin = htempkinensp->FindFirstBinAbove(0.);`
`int binmax = htempkinensp->FindLastBinAbove(0.);`

1 Like

Thank you @Wile_E_Coyote ! it’s what I need

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