hep icon indicating copy to clipboard operation
hep copied to clipboard

hbook: retrieve x position of maximum within given range for H1D

Open sbinet opened this issue 7 years ago • 3 comments

From @ebusato on October 12, 2016 15:10

Hi,

I'd like to retrieve the position on the x axis of the y maximum of the histogram within a certain range provided by the user. Right now you have the Max() method that returns the y maximum. What do you think would be the best option to implement what I need :

  1. Change the Max() method by adding two parameters to specify the range and one return value which is the maximum position on the x axis
  2. Create a new method and let Max() untouched in order to not impact clients.

?

Let me know and I'll send a PR.

Emmanuel

Copied from original issue: go-hep/hbook#8

sbinet avatar Mar 10 '17 13:03 sbinet

I see 2 additional options:

  1. make Max() a variadic method, like Integral():

    // Max returns the maximum y value of this histogram.
    func (h *H1D) Max(args ...float64) float64 { ... }
    
  2. make Max() take a Range1D argument:

    type Range1D [2]float64
    
    // Max returns the maximum y value of this histogram.
    func (h *H1D) Max(span Range1D) float64 { ... }
    

    where Range1D default value (0,0) would implicitly mean the whole 1D axis.

sbinet avatar Mar 10 '17 13:03 sbinet

From @ebusato on October 13, 2016 8:56

Right. I would go for the variadic option, with the aditionnal return value. So the signature would be:

// Max returns the maximum y value of this histogram and the corresponding x value. func (h *H1D) Max(args ...float64) (float64, float64) { ... }

Would that be ok for you ?

sbinet avatar Mar 10 '17 13:03 sbinet

sounds good to me

sbinet avatar Mar 10 '17 13:03 sbinet