def _tf2_(self, xmin=neg_infinity, xmax=pos_infinity, ymin=neg_infinity, ymax=pos_infinity, npars=0, *args): """Convert the function to TF2 >>> obj = ... >>> fun = obj.tf2 ( 3.0 , 3.2 , 3.0 , 3.2 ) >>> fun.Draw() """ ## if not hasattr(self, '_wo2'): self._wo2 = _WO2_(self) if not self._wo2: self._wo2 = _WO2_(self) ## if hasattr(self, 'xmin'): xmin = max(xmin, self.xmin()) if hasattr(self, 'xmax'): xmax = min(xmax, self.xmax()) if hasattr(self, 'ymin'): ymin = max(ymin, self.ymin()) if hasattr(self, 'ymax'): ymax = min(ymax, self.ymax()) if hasattr(self, 'npars'): npars = max(npars, self.npars()) # _wo = self._wo2 fun = ROOT.TF2(funID(), _wo, xmin, xmax, ymin, ymax, npars, *args) fun.SetNpx(100) fun.SetNpy(100) # return fun
def qgsmTF1(ptmax, ptmin=0, mass=None, name=''): """Create QGSM functin (as TF1) for fitting pt-spectra >>> histo = >>> fun = qgsmTF1 ( ptmax = 50 ) >>> histo.Fit( fun , 'SI' ) """ if ptmax <= ptmin: raise ArrtibuteError("QGSM/TF1: wrong ptmin/ptmax: %s/%s" % (ptmin, ptmax)) obj = QGSMFun(ptmax, ptmin) if not name: name = funID() func = ROOT.TF1(name, obj, ptmin, ptmax, 3) func._obj = obj func.SetParNames( 'norm', ## 0 'm', ## 1 'b') ## 2 ## if isinstance(mass, float) and 0 <= mass: func.FixParameter(1, mass) else: func.SetParameter(1, 0) ## func.SetParameter(0, 1) ## norm func.SetParameter(2, 1) ## return func
def tsallisTF1(ptmax, ptmin=0, mass=None, name=''): """Create Tsallis function (as TF1) for fitting pt-spectra: >>> histo = >>> fun = tsallisFun ( ptmax = 50 ) >>> histo.Fit( fun , 'SI' ) """ if ptmax <= ptmin: raise ArrtibuteError("Tsallis/TF1: wrong ptmin/ptmax: %s/%s" % (ptmin, ptmax)) obj = TsallisFun(ptmax, ptmin) if not name: name = funID() func = ROOT.TF1(name, obj, ptmin, ptmax, 4) func._obj = obj func.SetParNames( 'norm', ## 0 'm', ## 1 'n', ## 2 'T') ## 3 ## if isinstance(mass, float) and 0 <= mass: func.FixParameter(1, mass) else: func.SetParameter(1, 0) ## func.SetParameter(0, 1) ## norm func.SetParameter(2, 10) func.SetParameter(3, 1.1) ## return func
def _as_TF1_(obj, xmin, xmax): """Convert the objects to the functions""" from ostap.core.core import funID fobj = _WF1(obj) fun = ROOT.TF1(funID(), fobj, xmin, xmax) fun._obj = fobj fun.SetNpx(500) return fun
def _as_TF2_(obj, xmin, xmax, ymin, ymax): """Convert the objects to the function""" from ostap.core.core import funID fobj = _WF2(obj) fun = ROOT.TF2(funID(), fobj, xmin, xmax, ymin, ymax) fun._obj = fobj fun.SetNpx(250) fun.SetNpy(250) return fun
def _tf3_(self, xmin=neg_infinity, xmax=pos_infinity, ymin=neg_infinity, ymax=pos_infinity, zmin=neg_infinity, zmax=pos_infinity, npars=0, *args): """Convert the function to TF3 >>> obj = ... >>> fun = obj.tf3 ( 3.0 , 3.2 , 3.0 , 3.2 , 1 , 2 ) >>> fun.Draw() """ ## if not hasattr(self, '_wo3'): self._wo3 = _WO3_(self) if not self._wo3: self._wo3 = _WO3_(self) ## if hasattr(self, 'xmin'): xmin = max(xmin, self.xmin()) if hasattr(self, 'xmax'): xmax = min(xmax, self.xmax()) if hasattr(self, 'ymin'): ymin = max(ymin, self.ymin()) if hasattr(self, 'ymax'): ymax = min(ymax, self.ymax()) if hasattr(self, 'zmin'): zmin = max(zmin, self.zmin()) if hasattr(self, 'zmax'): zmax = min(zmax, self.zmax()) if hasattr(self, 'npars'): npars = max(npars, self.npars()) # assert xmin > neg_infinity, \ "``xmin''-parameter needs to be specified %s" % xmin assert xmax < pos_infinity, \ "``xmax''-parameter needs to be specified %s" % xmax assert ymin > neg_infinity, \ "``ymin''-parameter needs to be specified %s" % ymin assert ymax < pos_infinity, \ "``ymax''-parameter needs to be specified %s" % ymax assert zmin > neg_infinity, \ "``zmin''-parameter needs to be specified %s" % zmin assert zmax < pos_infinity, \ "``zmax''-parameter needs to be specified %s" % zmax # _wo = self._wo3 fun = ROOT.TF3(funID(), _wo, xmin, xmax, ymin, ymax, zmin, zmax, npars, *args) fun.SetNpx(40) fun.SetNpy(40) fun.SetNpy(40) # return fun
def _tf1_(self, xmin=neg_infinity, xmax=pos_infinity, npars=0, *args): """Convert the function to TF1 >>> obj = ... >>> fun = obj.tf1 ( 3.0 , 3.2 ) >>> fun.Draw() """ # if not hasattr(self, '_wo1'): self._wo1 = _WO1_(self) if not self._wo1: self._wo1 = _WO1_(self) # if hasattr(self, 'xmin'): xmin = max(xmin, self.xmin()) if hasattr(self, 'xmax'): xmax = min(xmax, self.xmax()) if hasattr(self, 'npars'): npars = max(npars, self.npars()) # _wo = self._wo1 fun = ROOT.TF1(funID(), _wo, xmin, xmax, npars, *args) fun.SetNpx(500) # return fun
def gammaDistTF1(ptmax, ptmin=0, mass=None, name=''): """ Create GammaDist function (as TF1) for fitting pt-spectra >>> histo = >>> fun = gammaDistTF1 ( ptmax = 50 ) >>> histo.Fit( fun , 'SI' ) """ if ptmax <= ptmin: raise ArrtibuteError("GammaDist/TF1: wrong ptmin/ptmax: %s/%s" % (ptmin, ptmax)) obj = GammaDistFun(ptmax, ptmin) if not name: name = funID() func = ROOT.TF1(name, obj, ptmin, ptmax, 3) func._obj = obj func.SetParNames( 'norm', ## 0 'k', ## 1 'theta') ## 2 ## func.SetParameter(0, 1) ## norm func.SetParameter(1, 2) func.SetParameter(2, 2) ## return func