Skip to content

A utility to perform a linear fit without ROOT

During testing of OT-2S-service hybrids, a calibration of the lpGBT's ADC is performed via an external DAC. In order to perform a kind of automated evaluation a fit or chi^2 test was proposed. A natural choice would be using the ROOT toolkit, especially considering the fact that this test is not to be performed inside the detector.

However, I started working on a utility for this purpose (somewhat as a personal exercise). It is now able to perform a linear fit from two vectors (option to include a y-error vector) of the same datatype and also provides the errors on the parameters. The math is based on https://pages.mtu.edu/~fmorriso/cm3215/UncertaintySlopeInterceptOfLeastSquaresFit.pdf and gives the same result as ROOT does.

You can find the code here:

https://gitlab.cern.ch/apauls/Ph2_ACF/-/blob/fa7495479c7a73181c1cf8dca6448c8bc0b4dd8f/Utils/linearFitter.h

an example use here:

https://gitlab.cern.ch/apauls/Ph2_ACF/-/blob/fa7495479c7a73181c1cf8dca6448c8bc0b4dd8f/tools/SEHTester.cc#L195

Stuff to potentially add in the future depending on the needs: Different data types for std::vector<T> datasetX, std::vector<T> datasetY, and std::vector<T> datasetYerrors include calculation of chi^2 and NDF, use of x-errors ...