I’ll have couple of follow up questions about the discussion for the update. I start to change the code’s approach a bit.
Problems in my mind:
TH1F or TH1D, which one is more suitable to the data?
I got round of error on gross area 1, how can be fixed? I’ll attach the terminal view.
After all is done properly, I may fill the histogram with the integrals from functions instead of the real data. I think it will be pre-defined MODEL based analysis in that way. What is your thought about that?
In your case, I don’t think it makes sense to try to “minimize” the RAM usage by using single-precision, instead of the default double-precision, floating-point format for histograms’ contents.
I forgot. Is this epsilon (1e-6) related to the precision of finding the mean? Should I keep playing with that number until the roundoff error is demolished? I found Moneta mentioned about that.
My conclusion: error disappears as I play with my integral limits. If I go from Lower bin 400 to upper bin 530, I see NO ERROR. Thus, it’s a matter of limits and the ability of fitting procedure within those limits. Am I right?
I see the terminal resuls and the fit result DONOT MATCH. First parameters of each gaussian should be the integral of those peaks due to the usage of Gausn, but the results give different outcomes comparison to parameter outcomes.
What happens when I fix the break point parameter which I needed. Otherwise, it will be wrong.
I fixed it to the bin number 460, and it looks like OK.
However, the roundoff error 18 is so sensitive to the limits I choose. It only worked from 400 to 460 for the 1st peak and from 460 to 430 bin numbers for the 2nd peak.
Do you think that it’s totally OK to play with numbers until getting NO ERROR?
BTW. Note that the “area” parameter of a “gausn” is always its “full” integral. You integrate the function from some “xmin” to some “xmax”, so such “integral” will always be <= “area”.
When you say full integral, it is the value of this first part below: 1/sigma*squareRoot(2Pi) .
The integral, however , is the value below.
A bit confusing. When we fit gausn instead of gaus, do we tell somewhere in the code before it prints out the information, show the area as the 1st parameter. Obviously, the area is NOT equal to normalizating constant.
Ok. let me try my shot to explain my confusion.
In gaus, we give height as parameter, it draws the shape nicely. In gausn, we need to give area to be drawn. By looking at the histogram, I can easily give the hight but not the area. I need to calculate the area from height x sigma x sqrt(2 x Pi) . Isn’t it tiring?
{
TCanvas *c1 = new TCanvas("c1", "c1", 800,400);
c1->Divide(2,1);
c1->cd(1);
TF1 *f = (TF1*)gROOT->GetFunction("gausn");
Double_t area1 = 100., mean1 = 0., sigma1 = 1.;
f->SetParameters(area1, mean1, sigma1);
f->Draw();
std::cout << "area 1 = " << area1 << std::endl;
std::cout << "height 1 = " << area1/ (sigma1*sqrt(2.*TMath::Pi()) ) << std::endl;
Int_t i;
cout << "To see the percentage of the marked area in the range of stated sigma in PDF" << endl;
for (i = 1; i < 10; i++)
std::cout << i << " area 1: "<< area1 << " integral: " << f->Integral(mean1 - i * sigma1, mean1 + i * sigma1) << "\t\tThe rest: " << area1- f->Integral(mean1 - i * sigma1, mean1 + i * sigma1) << std::endl;
c1->cd(2);
TF1 *f2 = (TF1*)gROOT->GetFunction("gaus");
Double_t height2 = 100., mean2 = 0., sigma2 = 1.;
f2->SetParameters(height2, mean2, sigma2);
f2->Draw();
std::cout << "area 2 = " << sqrt(2.*TMath::Pi()) *height*sigma2 << std::endl;
for ( i = 1; i < 10; i++)
std::cout << i << " : " << f2->Integral(mean2 - i * sigma2, mean2 + i * sigma2) << std::endl;
}
I added more on that teaching code. What was your point about gausn?
BTW, I am suprised about the gaus plot above. Its x axis range is between + sigma and - sigma when we do not state it explicitly. Anyways.
That’s interesting because I wasn’t imagining the ROOT is calculating it like that. Surely, this calculation should be only valid for common (linked) background line, not for the separate bcg line approach. Right! I guess it won’t be valid if the peaks are way apart from each other, then in this case, we need to define 2 bcg functions. I guess ROOT regards the broken line as continous as if there was 1 line.
Question: When we say g1, don’t we mean the net area + its background ?
Answer: Ohh. NO, it’S not because we use the integral of g1 when we get the NET area of g1.
Namely, g1 and g2 are our NET sginals.
That’ amazing to see how easily the ROOT finds the net area.
The “toy MC” (by default) sets the “sigma” parameter = 10 for both “gausn” peaks. Try to play with “sigma” = 5 and then with “sigma” = 20 (for both peaks, of course).
My little adapted code above, says nothing changes.
I mean I knew that after around 5 sigma, the integral percentage reaches to 100 percent already, so no need to go to infinity to retrieve the whole integral.