Drawing associated fit

I have an application where I want to fit a TH1F in one function but not draw it, and then draw the TH1F later in a different function. I am calling Fit with options “Q0” (I’ve also tried “Q0+”) to prevent the drawing. Later when I draw the histogram I see the fit results in the stats pave, but the TF1 is not drawn. If I explicitly grab the TF1 by calling FindObject(“gauss”) it draws correctly, however this doesn’t solve my use case as (in general) the TF1 name is not known at the time the TH1F is being drawn. I’ve also observed that, if I remove the “0” from the fit options, the TF1 is correctly drawn in the 2nd function when TH1F::Draw is called. This also doesn’t solve my use case, as I don’t want canvases popping up in the first function. Is there a way to force the TH1F to always draw its associated TF1 when TH1F::Draw is called after fitting with option “0”?

thanks, David Brown

TH1F* test = new TH1F(“test”,“test”,100,-10,10);
TF1* g = new TF1(“g”,“gaus”);
g->SetParameters(100,0.0,1.0);
test->FillRandom(“g”);
test->Fit(“gaus”,“Q0”);
test->Draw();
test->GetFunction(“gaus”)->Draw(“same”);
test->Fit(“gaus”,“Q”);
test->Draw();

Search for the … Warning when using the option “0” … in the TH1::Fit method description (replace “->[url=http://root.cern.ch/root/html/TObject.html#TObject:ResetBit]ResetBit/url;” with “->[url=http://root.cern.ch/root/html/TObject.html#TObject:ResetBit]ResetBit/url;” in the example code given therein).
See also: [url]Multiple fitted histograms not drawing on same pad