Gaussian Fitting for specific peak

Can you help in with thise please !

How can i modify the attached code to make the Gaussian Fitting for the peak 1460 in the range (1455 to 1470).

Code.C (672 Bytes)
file1.txt (174.2 KB)

This is the same issue here: Range of TH1::Fit
So define a TF1 with your range and do h->Fit(“R”)

It dose not work with me,

Can you modify my code to get the goal please !

void Code() {
  auto h = MakeHistoFromFile("file1.txt");
  Double_t xmin = 1455., xmax = 1470.;
  TF1 *f = new TF1("f", "gausn(0) + pol1(3)"); // normalized gaussian peak + linear background
  f->SetParNames("Area", "Mean", "Sigma", "p0", "p1");
  // set "reasonable" initial values for all parameters
  f->SetParameters(h->Integral(h->FindFixBin(xmin), h->FindFixBin(xmax)), // "Area"
                   (xmax + xmin) / 2., (xmax - xmin) / 10., // "Mean", "Sigma"
                   0., 0.); // "p0", "p1"
  h->Fit(f, "", "", xmin, xmax); // fit from "xmin" to "xmax"

Thanks Alot,
Can you please show me the used algorithm, or submit me the link that show the solving way (from the theoretical or the numerical vision ?

ROOT User’s Guide -> Fitting Histograms

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.