# import modules import myFitter as mf # define your model class by deriving from mf.Model class MyModel(mf.Model): def __init__(self): # First call the initialisation method of the base class. mf.Model.__init__(self) # Add a parameters named 'p1' and 'p2' to the model. self.addParameter('p1', default=1.0, bounds=(0.1, None)) self.addParameter('p2', default=1.0, scale=0.5) # Constrain p1*p2 to be less than 1. The dependent quantity # 'p1 p2' must be computed in getDependentQuantities(). self.addConstraint('p1 p2', '<', 1.0, scale=0.5) # Add a Gaussian chi-square contribution for observable 'obs1' # with measured value 2.3 and standard deviation 0.3. self.addGaussianCSC('obs1', 2.05, 0.05, syst=(0.2, 0.1)) # Add a chi-square contribution of three correlated gaussian observables # 'obs2', 'obs3', and 'obs4. 'obs234' is the name of the chi-square # contribution. self.addCorrelatedGaussianCSC('obs234', [('obs2', 0.8, 0.1), ('obs3', 2.3, 0.2), ('obs4', 0.3, 0.1)], # measured values and standard deviations [('obs2', 'obs3', 0.2), ('obs3', 'obs4', -0.8)]) # correlation coefficients # All quantities that depend on the model parameters are calculated here. def getDependentQuantities(self, p): # Always call the method of the base class first. This essentially # copies the dictionary `p`, substitutes default values for any # parameters that have been omitted and adjust the values of parameters # that have been fixed (i.e. are not floating in the fit). q = mf.Model.getDependentQuantities(self, p) # Extract the parameter values from the dictionary q (*not* p). p1 = q['p1'] p2 = q['p2'] # Compute the dependent quantity 'p1 p2' (for the constraint) q['p1 p2'] = p1*p2 # Compute the four observables. q['obs1'] = p1**2 + p2**2 q['obs2'] = p2/p1 q['obs3'] = p1 + p2 q['obs4'] = p1 - p2 # Return the dictionary q. return q