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 1386 of file trfUtils.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1398 of file trfUtils.py.

1398 def __init__(self, **kwargs):
1399 # extract parameters
1400 self._model = kwargs.get('model', 'linear')
1401 self._x = kwargs.get('x', None)
1402 self._y = kwargs.get('y', None)
1403 self._math = math()
1404
1405 if not self._x or not self._y:
1406 msg.warning('input data not defined')
1407
1408 if len(self._x) != len(self._y):
1409 msg.warning('input data (lists) have different lengths')
1410
1411 # base calculations
1412 if self._model == 'linear':
1413 self._ss = self._math.sum_square_dev(self._x)
1414 self._ss2 = self._math.sum_dev(self._x, self._y)
1415 self.set_slope()
1416 self._xm = self._math.mean(self._x)
1417 self._ym = self._math.mean(self._y)
1418 self.set_intersect()
1419 self.set_chi2()
1420
1421 else:
1422 msg.warning("\'{0}\' model is not implemented".format(self._model))
1423
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 1443 of file trfUtils.py.

1443 def chi2(self):
1444 #Return the chi2 value.
1445 return self._chi2
1446
double chi2(TH1 *h0, TH1 *h1)

◆ fit()

python.trfUtils.Fit.fit ( self)

Definition at line 1424 of file trfUtils.py.

1424 def fit(self):
1425 #Return fitting object.
1426 return self
1427

◆ intersect()

python.trfUtils.Fit.intersect ( self)

Definition at line 1465 of file trfUtils.py.

1465 def intersect(self):
1466 #Return the intersect value.
1467 return self._intersect
1468
1469

◆ set_chi2()

python.trfUtils.Fit.set_chi2 ( self)

Definition at line 1432 of file trfUtils.py.

1432 def set_chi2(self):
1433 #Calculate and set the chi2 value.
1434 y_observed = self._y
1435 y_expected = []
1436 for x in self._x:
1437 y_expected.append(self.value(x))
1438 if y_observed and y_observed != [] and y_expected and y_expected != []:
1439 self._chi2 = self._math.chi2(y_observed, y_expected)
1440 else:
1441 self._chi2 = None
1442

◆ set_intersect()

python.trfUtils.Fit.set_intersect ( self)

Definition at line 1458 of file trfUtils.py.

1458 def set_intersect(self):
1459 #Calculate and set the intersect of the linear fit.
1460 if self._ym and self._slope and self._xm:
1461 self._intersect = self._ym - self._slope * self._xm
1462 else:
1463 self._intersect = None
1464

◆ set_slope()

python.trfUtils.Fit.set_slope ( self)

Definition at line 1447 of file trfUtils.py.

1447 def set_slope(self):
1448 #Calculate and set the slope of the linear fit.
1449 if self._ss2 and self._ss and self._ss != 0:
1450 self._slope = self._ss2 / self._ss
1451 else:
1452 self._slope = None
1453

◆ slope()

python.trfUtils.Fit.slope ( self)

Definition at line 1454 of file trfUtils.py.

1454 def slope(self):
1455 #Return the slope value.
1456 return self._slope
1457

◆ value()

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

Definition at line 1428 of file trfUtils.py.

1428 def value(self, t):
1429 #Return the value y(x=t) of a linear fit y(x) = slope * x + intersect.
1430 return self._slope * t + self._intersect
1431

Member Data Documentation

◆ _chi2

python.trfUtils.Fit._chi2 = None
staticprotected

Definition at line 1396 of file trfUtils.py.

◆ _intersect

python.trfUtils.Fit._intersect = None
staticprotected

Definition at line 1395 of file trfUtils.py.

◆ _math

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

Definition at line 1403 of file trfUtils.py.

◆ _model

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

Definition at line 1387 of file trfUtils.py.

◆ _slope

python.trfUtils.Fit._slope = None
staticprotected

Definition at line 1394 of file trfUtils.py.

◆ _ss

python.trfUtils.Fit._ss = None
staticprotected

Definition at line 1392 of file trfUtils.py.

◆ _ss2

python.trfUtils.Fit._ss2 = None
staticprotected

Definition at line 1393 of file trfUtils.py.

◆ _x

python.trfUtils.Fit._x = None
staticprotected

Definition at line 1388 of file trfUtils.py.

◆ _xm

python.trfUtils.Fit._xm = None
staticprotected

Definition at line 1390 of file trfUtils.py.

◆ _y

python.trfUtils.Fit._y = None
staticprotected

Definition at line 1389 of file trfUtils.py.

◆ _ym

python.trfUtils.Fit._ym = None
staticprotected

Definition at line 1391 of file trfUtils.py.


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