Hello, I’m trying to fit some histograms and get the fitting parameters. I want for example to make a “gaus” fit on a histogram and save the 3 fitting parameters in variables. I’m working on c++ code and the documentation for Root Browser is no good.
Could someone provide me with an example code of how I could do this or point me to a similar topic if it exists?
ROOT Version: v5.34.38
Platform: Ubuntu 14
Compiler: g++
couet
June 1, 2018, 2:26pm
2
For instance you can do something like that:
$ root
-------------------------------------------------------------------
| Welcome to ROOT 6.15/01 http://root.cern.ch |
| (c) 1995-2018, The ROOT Team |
| Built for macosx64 |
| From heads/master@v6-13-04-241-gc27a4eaee1, Jun 01 2018, 08:33:01 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
-------------------------------------------------------------------
root [0] TH1D *histo = new TH1D("histo", "", 100, -4, 4);
root [1] histo->FillRandom("gaus");
root [2] histo->Fit("gaus");
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
FCN=65.0502 FROM MIGRAD STATUS=CONVERGED 54 CALLS 55 TOTAL
EDM=9.21369e-07 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 Constant 1.57425e+02 2.76819e+00 8.89596e-03 -5.39870e-04
2 Mean 1.38321e-02 1.43799e-02 5.69927e-05 8.22303e-04
3 Sigma 1.00178e+00 1.04857e-02 1.11224e-05 -4.31183e-01
root [3] TF1 *g = (TF1*)histo->GetListOfFunctions()->FindObject("gaus");
root [4] double c = g->GetParameter(0);
root [5] cout << c << endl;
157.425
root [6]
It should work the same way with ROOT 5.34
1 Like
system
Closed
June 15, 2018, 2:26pm
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.