TH1D* h = new TH1D("h", "Histogram", 100, -5, 5); // Fill the histogram with some data TF1* f = new TF1("f", "gaus", -5, 5); // Fit the histogram using the Gaussian function h->Fit("f"); // Get the resulting fit parameters and their errors Double_t mean = f->GetParameter(1); Double_t sigma = f->GetParameter(2); Double_t meanError = f->GetParError(1); Double_t sigmaError = f->GetParError(2);
TH1D* h = new TH1D("h", "Histogram", 100, -5, 5); // Fill the histogram with some data TF1* f = new TF1("f", "sin(x)/x", -5, 5); // Set the initial parameters for the fit function f->SetParameter(0, 1); f->SetParameter(1, 1); // Fit the histogram using the custom function h->Fit("f", "M"); // Get the resulting fit parameters and their errors Double_t amplitude = f->GetParameter(0); Double_t frequency = f->GetParameter(1); Double_t amplitudeError = f->GetParError(0); Double_t frequencyError = f->GetParError(1);In this example, we create a histogram with 100 bins ranging from -5 to 5. We fill the histogram with some data and then create a custom function using the `TF1` class. We set the initial parameters for the fit function using the `SetParameter` function. We fit the histogram using the custom function and the `M` option to use the MINUIT minimization algorithm. We then get the resulting fit parameters and their errors using the `GetParameter` and `GetParError` functions. The package library for TH1D Fit is the ROOT framework, which can be downloaded from the CERN website.