Rescaling of histograms with overlay


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 ?


That’s rather unrealistic situation that you do not have your hist pointer.
How did you create your hist?

As a trick - you can ask your pad to give you its list of primitives - one of them will be hist. Something like this:

[code]void sample()
TCanvas * c = new TCanvas;
TH2F * hist = new TH2F(“a”, “a”, 10, -1., 1., 10, -1., 1.);
TList * lst = c->GetListOfPrimitives();
TObject * p = lst->FindObject(“a”);
TH2F * h = (TH2F *)p;//static_cast<TH2F *>§;


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.