Consider this example:
void fitslicesytest() {
TString dir = gROOT->GetTutorialDir();
dir.Append("/hsimple.C");
dir.ReplaceAll("/./","/");
if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
TFile *hsimpleFile = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
if (!hsimpleFile) return;
TH2F *hpxpy = (TH2F*)hsimpleFile->Get("hpxpy");
TAxis * Yaxis = hpxpy -> GetYaxis();
TF1 f1 = TF1("f1", "gaus", Yaxis -> GetXmin(), Yaxis -> GetXmax());
f1.SetParameters(100, (Yaxis -> GetXmax() - Yaxis -> GetXmin())/2.0, 0.01);
TObjArray slices;
hpxpy -> FitSlicesY(& f1, 1, hpxpy -> GetNbinsX(), 0, "QNRLM", &slices);
}
I would like to get TFitResult and see the fitted function drawn on each slice. What to do?
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
moneta
2
Hi,
Unfortunately there is now no current way to get the TFitResult object. You would need to modify the TH2::DoFitSlices
function.
For plotting the fitted function remove the options Q
and N
, just use RLM
Lorenzo
1 Like
By removing QN
I dont’ see any fits drawn anywhere.
Is
hpxpy -> FitSlicesY(& f1, 1, hpxpy -> GetNbinsX(), 0, "QNRLM", &slices);
equivalent to
TH1* h = hpxpy -> ProjectionX("proj", 1, 1);
TFitResultPtr r = h -> Fit(&f1, "SRLMQN");
moneta
4
Hi ,
Not really, because TH2::FitSlicesY
will perform in this case 100 fits on each slice.
What is equivalent is the following for the X bin ibin
hpxpy -> FitSlicesY(& f1, ibin, ibin, 0, "QNRLM", &slices);
is equivalent to:
TH1* h = hpxpy -> ProjectionX("proj", ibin, ibin);
TFitResultPtr r = h -> Fit(&f1, "SRLMQN");type or paste code here
and you can get in the second case the fit result and the fitted plot.
Lorenzo
system
Closed
5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.