ATLAS Offline Software
Loading...
Searching...
No Matches
python.trfUtils.Fit Class Reference

Low-level fitting class. More...

Collaboration diagram for python.trfUtils.Fit:

Public Member Functions

 __init__ (self, **kwargs)
 fit (self)
 value (self, t)
 set_chi2 (self)
 chi2 (self)
 set_slope (self)
 slope (self)
 set_intersect (self)
 intersect (self)

Protected Attributes

 _math = math()

Static Protected Attributes

str _model = 'linear'
 _x = None
 _y = None
 _xm = None
 _ym = None
 _ss = None
 _ss2 = None
 _slope = None
 _intersect = None
 _chi2 = None

Detailed Description

Low-level fitting class.

Definition at line 1375 of file trfUtils.py.

Constructor & Destructor Documentation

◆ __init__()

python.trfUtils.Fit.__init__ ( self,
** kwargs )

Definition at line 1387 of file trfUtils.py.

1387 def __init__(self, **kwargs):
1388 # extract parameters
1389 self._model = kwargs.get('model', 'linear')
1390 self._x = kwargs.get('x', None)
1391 self._y = kwargs.get('y', None)
1392 self._math = math()
1393
1394 if not self._x or not self._y:
1395 msg.warning('input data not defined')
1396
1397 if len(self._x) != len(self._y):
1398 msg.warning('input data (lists) have different lengths')
1399
1400 # base calculations
1401 if self._model == 'linear':
1402 self._ss = self._math.sum_square_dev(self._x)
1403 self._ss2 = self._math.sum_dev(self._x, self._y)
1404 self.set_slope()
1405 self._xm = self._math.mean(self._x)
1406 self._ym = self._math.mean(self._y)
1407 self.set_intersect()
1408 self.set_chi2()
1409
1410 else:
1411 msg.warning("\'{0}\' model is not implemented".format(self._model))
1412
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")

Member Function Documentation

◆ chi2()

python.trfUtils.Fit.chi2 ( self)

Definition at line 1432 of file trfUtils.py.

1432 def chi2(self):
1433 #Return the chi2 value.
1434 return self._chi2
1435
double chi2(TH1 *h0, TH1 *h1)

◆ fit()

python.trfUtils.Fit.fit ( self)

Definition at line 1413 of file trfUtils.py.

1413 def fit(self):
1414 #Return fitting object.
1415 return self
1416

◆ intersect()

python.trfUtils.Fit.intersect ( self)

Definition at line 1454 of file trfUtils.py.

1454 def intersect(self):
1455 #Return the intersect value.
1456 return self._intersect
1457
1458

◆ set_chi2()

python.trfUtils.Fit.set_chi2 ( self)

Definition at line 1421 of file trfUtils.py.

1421 def set_chi2(self):
1422 #Calculate and set the chi2 value.
1423 y_observed = self._y
1424 y_expected = []
1425 for x in self._x:
1426 y_expected.append(self.value(x))
1427 if y_observed and y_observed != [] and y_expected and y_expected != []:
1428 self._chi2 = self._math.chi2(y_observed, y_expected)
1429 else:
1430 self._chi2 = None
1431

◆ set_intersect()

python.trfUtils.Fit.set_intersect ( self)

Definition at line 1447 of file trfUtils.py.

1447 def set_intersect(self):
1448 #Calculate and set the intersect of the linear fit.
1449 if self._ym and self._slope and self._xm:
1450 self._intersect = self._ym - self._slope * self._xm
1451 else:
1452 self._intersect = None
1453

◆ set_slope()

python.trfUtils.Fit.set_slope ( self)

Definition at line 1436 of file trfUtils.py.

1436 def set_slope(self):
1437 #Calculate and set the slope of the linear fit.
1438 if self._ss2 and self._ss and self._ss != 0:
1439 self._slope = self._ss2 / self._ss
1440 else:
1441 self._slope = None
1442

◆ slope()

python.trfUtils.Fit.slope ( self)

Definition at line 1443 of file trfUtils.py.

1443 def slope(self):
1444 #Return the slope value.
1445 return self._slope
1446

◆ value()

python.trfUtils.Fit.value ( self,
t )

Definition at line 1417 of file trfUtils.py.

1417 def value(self, t):
1418 #Return the value y(x=t) of a linear fit y(x) = slope * x + intersect.
1419 return self._slope * t + self._intersect
1420

Member Data Documentation

◆ _chi2

python.trfUtils.Fit._chi2 = None
staticprotected

Definition at line 1385 of file trfUtils.py.

◆ _intersect

python.trfUtils.Fit._intersect = None
staticprotected

Definition at line 1384 of file trfUtils.py.

◆ _math

python.trfUtils.Fit._math = math()
protected

Definition at line 1392 of file trfUtils.py.

◆ _model

python.trfUtils.Fit._model = 'linear'
staticprotected

Definition at line 1376 of file trfUtils.py.

◆ _slope

python.trfUtils.Fit._slope = None
staticprotected

Definition at line 1383 of file trfUtils.py.

◆ _ss

python.trfUtils.Fit._ss = None
staticprotected

Definition at line 1381 of file trfUtils.py.

◆ _ss2

python.trfUtils.Fit._ss2 = None
staticprotected

Definition at line 1382 of file trfUtils.py.

◆ _x

python.trfUtils.Fit._x = None
staticprotected

Definition at line 1377 of file trfUtils.py.

◆ _xm

python.trfUtils.Fit._xm = None
staticprotected

Definition at line 1379 of file trfUtils.py.

◆ _y

python.trfUtils.Fit._y = None
staticprotected

Definition at line 1378 of file trfUtils.py.

◆ _ym

python.trfUtils.Fit._ym = None
staticprotected

Definition at line 1380 of file trfUtils.py.


The documentation for this class was generated from the following file: