Problem in estimation of sigma and bin range while fitting gaussian peak

Hi, @couet @Wile_E_Coyote @moneta
I have uploaded all the necessary files. In the C file I have use “?” because i am not sure to some of the estimated values.
And I am trying to fit the peak which has a mean~1126.
d9.pdf (20.5 KB) d9_1.C (991 Bytes) d9_1.txt (16.0 KB)

ROOT Version: 6.14
Platform: Linux
Compiler: Not Provided


I am asking this question because if i change the bin range then it will effect sigma, area and error in area and in sigma.
So, in order to get the area correctly i used bin range from (mean-3sigma to mean+3sigma)
but for that i require sigma that i am not sure at the first place.

I am having a problem in fitting the gaussian peak having the range of 1102 to 1150.
Could you please help me?
Have a nice day!

d9_1.cxx (1.9 KB)

BTW. Note that:

  h->Fit(f, "IL+", "", xmin, xmax); // e.g. "IL+" or "I+" or "L+" or "+"

is fully equivalent to:

  f->SetRange(xmin, xmax);
  h->Fit(f, "ILR+"); // e.g. "ILR+" or "IR+" or "LR+" or "R+"

Thanks @Wile_E_Coyote


I’m getting this using your code.
Now, the thing that i am concern about is the height of fitted peaks. Why it is going higher than its original value?
Could you please also explain me how you have selected the bin ranges for both the peaks?

The histogram’s “bin width” is quite big (8 channels) when compared to peaks’ sigmas (around 4 to 5 channels).

@Wile_E_Coyote
Sorry, But I am not getting it. Please elaborate

Also, please tell me about the heights of the fitted peaks.

Try the following example:

{
  gStyle->SetOptStat("nemrI");
  gStyle->SetOptFit(111);
  TH1F *h1 = new TH1F("h1", "h1", 100, -5., 5.); // bin width = 0.1
#if 0 /* 0 or 1 */
  ((TF1*)gROOT->GetFunction("gaus"))->SetParameter(2, 2.); // 2 = sigma
#elif 0 /* 0 or 1 */
  ((TF1*)gROOT->GetFunction("gaus"))->SetParameter(2, 0.5); // 2 = sigma
#endif /* 0 or 1 */
  h1->FillRandom("gaus", 10000); // default mean = 0., default sigma = 1.
  TH1F *h2 = (TH1F*)h1->Clone("h2"); h2->SetTitle("h2");
  TH1F *h3 = (TH1F*)h1->Clone("h3"); h3->SetTitle("h3");
  TH1F *h4 = (TH1F*)h1->Clone("h4"); h4->SetTitle("h4");
  Int_t ngroup = 25; // e.g. 10, 20, 25
  h2->Rebin(ngroup); // bin width = 0.1 * ngroup
  h4->Rebin(ngroup); // bin width = 0.1 * ngroup
  Double_t xl = h1->GetBinCenter(1); // the first bin
  Double_t xr = h1->GetBinCenter(h1->GetNbinsX()); // the last bin
#if 0 /* 0 or 1 */
  xl = -2.; xr = 2.; // set "narrow" fit range
#endif /* 0 or 1 */
  TCanvas *c = new TCanvas("c", "c");
  c->Divide(2, 2);
  c->cd(1);
  h1->SetTitle("L"); h1->Fit("gausn", "L", "", xl, xr); // "L" or ""
  c->cd(2);
  h2->SetTitle("L"); h2->Fit("gausn", "L", "", xl, xr); // "L" or ""
  c->cd(3);
  h3->SetTitle("IL"); h3->Fit("gausn", "IL", "", xl, xr); // "IL" or "I"
  c->cd(4);
  h4->SetTitle("IL"); h4->Fit("gausn", "IL", "", xl, xr); // "IL" or "I"
  c->cd(0);
}

@Wile_E_Coyote
8-channel width means that the raw data is having bin range from 0 to 8192 but there are only 1023 entries in the histogram. Do you mean this or anything else?
Still unable to figure out how you set the bin ranges of peak around 1126 and 1710?
Also, when you set range of peak around 1710 i.e.(1680 to 1755) it does not give a mean of 1710.

Please elaborate.

@Wile_E_Coyote
Also could you please help in fitting the other peaks.
Could you please help me in setting the range of other peaks?
because i don’t know how you taken the bin range.

@Wile_E_Coyote
One more question is that do I need to take bin range using (mean - 3sigma) to (mean + 3sigma)??
Does this gives me 99.9 % area under the curve??
Knowing this is so important because changing bins can easily affect the area by some good margin.

@Wile_E_Coyote
Does the sigma that we get in the root terminal (while fitting the “gaus” function) does not have any connection with bin range or does it have?

Still unable to figure out when you set the bin ranges of peak around 1710 i.e.(1680 to 1755) it does not give a mean of 1710. ?
Then, how you would have decide that range??
Even, if I use (1650, 1785) I got almost the same area but still the mean is not 1710 if you see analytically.

Also, tell me about this “ILR”.

It’s the “data analyst’s” responsibility to choose an appropriate fit range so that the peak and the background can be described well enough.

Histogram fit options are described e.g. in: TH1::Fit

@Wile_E_Coyote
Does the value of the area that I am getting involves background subtraction or not??

Write a simple dedicated simulation (e.g. several big peaks plus some non-egligible background) and play with it, e.g.:

{
  TH1F *h = new TH1F("h", "h", 1000, 0., 10000.); // bin width = 10.
#if 1 /* 0 or 1 */
  ((TF1*)gROOT->GetFunction("pol1"))->SetParameters(10000., -1.);
  h->FillRandom("pol1", 100000); // linear background
#else /* 0 or 1 */
  h->FillRandom("pol0", 100000); // constant background
#endif /* 0 or 1 */
  TF1 *f = (TF1*)gROOT->GetFunction("gaus");
  f->SetParameters(1., 1000.,  2.5); h->FillRandom("gaus", 1000);
  f->SetParameters(1., 2000.,  5.0); h->FillRandom("gaus", 1000);
  f->SetParameters(1., 3000.,  7.5); h->FillRandom("gaus", 1000);
  f->SetParameters(1., 4000., 10.0); h->FillRandom("gaus", 1000);
  f->SetParameters(1., 5000., 15.0); h->FillRandom("gaus", 1000);
  f->SetParameters(1., 6000., 20.0); h->FillRandom("gaus", 1000);
  f->SetParameters(1., 7000., 25.0); h->FillRandom("gaus", 1000);
  f->SetParameters(1., 8000., 30.0); h->FillRandom("gaus", 1000);
  f->SetParameters(1., 9000., 40.0); h->FillRandom("gaus", 1000);
  h->Draw(""); // e.g. "" or "HIST"
}

The two curves that I am getting are as follows:


First one is with constant background and second one is with linear background.
Now, if i choose any two peaks to fit in the histogram.
then how does their areas gets changed with the different (linear and constant backgrounds)?.
Could you please help me in doing that?

Learning by doing :thinking:
Trial and error :wink:

1 Like

Hi @arorastacy - don’t misinterpret Wile_E’s helpfulness as a substitution for your own physics expertise. This is the ROOT forum, we’re happy to help with ROOT! Your questions are in the area of supervision: we shouldn’t be answering “Please tell me everything is fine or not?” - that’s for your supervisor and physics group to answer. Please don’t hesitate to ask any technical, specific question with using ROOT.

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