Hi,
Sounds like very interesting task for the students!
Of course, the best solution, would be to fit the following data with cos()/sin() function and get parameter which is responsible for frequency or period directly.
Unfortunately, I found it quite difficult to achieve reasonable fit of the given data with cos()… So one has to really invest into setting boundaries for fit parameters and play with it…
Eventually I managed to make fit for blue graph work:
The fit result is. As a formula I used: [0]*cos([1]*x + [2]) + [3]
. So [1]
parameter will be circular frequency.
And one easily can get period: T = 2pi/p1
FCN=9.06803e-08 FROM MIGRAD STATUS=CONVERGED 57 CALLS 58 TOTAL
EDM=1.81365e-07 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 1.00000e+00 2.84318e-02 6.21307e-05 6.23625e-05
2 p1 1.00000e+00 4.24227e-03 9.50349e-07 1.46318e-01
3 p2 -1.57082e+00 7.56994e-02 6.62167e-06 7.77469e-04
4 p3 -6.03777e-07 2.19177e-02 1.07383e-04 -1.65714e-04
I guess more data points would make it easier to fit…
I did the fit directly in the TBrowser
right-clicking on the graph
and going to the FitPanel
button.
There you should enter formula, set boundaries for parameters, and click “fit” button many times till it works 
One can do the same Fit procedure inside the code, something like:
TF1* fit_graph2 = new TF1("fit_graph2", "[0]*cos([1]*x + [2]) + [3]");
fit_graph2->SetNpx(500);
fit_graph2->SetParNames("Amplitude", "Frequency", "Phase", "Bias");
fit_graph2->SetParameters(1., 1., -1.5, 0.);
fit_graph2->SetParLimits(0, 0.9, 1.1);
fit_graph2->SetParLimits(1, 0.7, 1.5);
fit_graph2->SetParLimits(2, -2, 2);
fit_graph2->SetParLimits(3, -0.05, 0.05);
graph2->Fit(fit_graph2);
however, I found it very hard to make it converge using it in the code…
Of course one could alsofit each individual peak with parabola pol2
within some proximity and get their peak positions and thus extract the period…
Maybe ROOT experts will have some other ideas…
cheers,
Bohdan