This is a simple problem to which I can’t find any but complicated solutions.
I have some histogram drawn, and then, later, some other function draws
an overlay on this histogram (same x-scale) - now, I’d like the histogram
to rescale if the overlay has bin contents that extend beyond the scale of
the original histogram. I don’t have a direct handle on the original histogram - but I do have a ref to the PAD in which it is (and where the overlay will be plotted) - is there an easy way to do this ?
Get a pointer to your original histogram (you must know at least its name)
TH1 *h = (TH1*)PAD->GetPrimitive("histogram name");
Now add your TF1* f function to its list of functions (you can have as many functions as you want in this list). When drawing the histogram, the best scale in Y will be computed to accomodate the histogram and its functions.
h->GetListOfFunctions()->Add(f);
Note that you should not call f->Draw(). This is done automatically when the histogram is redrawn, eg via PAD->Modified(); PAD->Update(), or simply
by clicking with the left mouse button into the pad.