def minimize(self): w = self.model.w nll = w.pdf('model').createNLL(w.data('data'), *self.fitArgs[:-1]) minu = r.RooMinuit(nll) minu.setPrintLevel(-1) minu.setNoWarn() for j in range(10): minu.setStrategy(2) for i in range(10): self.fitstatus = minu.migrad() print>>self.log, i + 10*j, self.log.flush() if not self.fitstatus: break if not self.fitstatus: break minu.setStrategy(1) minu.migrad() print>>self.log self.NLL = nll.getVal() pll = nll.createProfile(w.argSet(','.join(self.profileVars))) print>>self.log, roo.str(nll) print>>self.log, roo.str(pll) if hasattr(pll,'minimizer'): pll.minimizer().setStrategy(2) else: pll.minuit().setStrategy(2) return pll
def minimize(self): w = self.model.w nll = w.pdf('model').createNLL(w.data('data'), *self.fitArgs[:-1]) minu = r.RooMinuit(nll) minu.setPrintLevel(-1) minu.setNoWarn() for j in range(10): minu.setStrategy(2) for i in range(10): self.fitstatus = minu.migrad() print >> self.log, i + 10 * j, self.log.flush() if not self.fitstatus: break if not self.fitstatus: break minu.setStrategy(1) minu.migrad() print >> self.log self.NLL = nll.getVal() pll = nll.createProfile(w.argSet(','.join(self.profileVars))) print >> self.log, roo.str(nll) print >> self.log, roo.str(pll) if hasattr(pll, 'minimizer'): pll.minimizer().setStrategy(2) else: pll.minuit().setStrategy(2) return pll
def minimize(self): w = self.model.w nll = w.pdf(self.nobg+'model'+self.only).createNLL(w.data('data'+self.only), *self.fitArgs[:-1]) minu = r.RooMinuit(nll) minu.setPrintLevel(-1) minu.setNoWarn() for j in range(10): minu.setStrategy(2) for i in range(10): self.fitstatus = minu.migrad() print>>self.log, i + 10*j, self.log.flush() if not self.fitstatus: break if not self.fitstatus: break minu.setStrategy(1) minu.migrad() print>>self.log print>>self.log, roo.str(w.arg('alpha')) self.NLL = nll.getVal() alpha = w.arg('alpha').getVal(), w.arg('alpha').getError() pll = nll.createProfile(w.argSet('alpha')) print>>self.log, roo.str(nll) print>>self.log, roo.str(pll) if hasattr(pll,'minimizer'): pll.minimizer().setStrategy(2) else: pll.minuit().setStrategy(2) return alpha,pll
def doFit(self): w = self.model.w contourPoints = None while not contourPoints: pll = self.minimize() p0, contourPoints = self.contourPoints(pll) ell = enclosing_ellipse([p[:2] for p in contourPoints], p0[:2]) self.profVal = p0[:2] self.profErr = ell.sigmas2 self.profPLL = p0[2] self.scales = np.array( [w.arg(a).getVal() for a in ['Ac_y_ttqq', 'Ac_y_ttqg']]) self.scalesPhi = [ w.arg('Ac_phi_%s' % n).getVal() for n in ['ttqq', 'ttgg', 'ttag', 'ttqg', 'tt'] ] self.correction = w.arg('Ac_y_ttgg').getVal() * w.arg('f_gg').getVal() self.fractionHats = [ w.arg('f_%s_hat' % a).getVal() for a in ['gg', 'qg', 'qq', 'ag'] ] fitXY = self.profVal * self.scales sigmas2 = np.diag(self.scales).dot(self.profErr).dot( np.diag(self.scales)) self.fitX, self.fitY = [float(i) for i in fitXY] self.fitXX = float(sigmas2[0, 0]) self.fitXY = float(sigmas2[0, 1]) self.fitYY = float(sigmas2[1, 1]) self.sigmaX = math.sqrt(self.fitXX / (2 * oneSigmaNLL)) self.sigmaY = math.sqrt(self.fitYY / (2 * oneSigmaNLL)) self.contourPointsX, self.contourPointsY, = zip( *[[float(i) for i in self.scales * p] for p in contourPoints]) if not self.quiet: print >> self.log, self.profVal, self.profPLL print >> self.log, self.profErr for item in [ 'd_qq', 'd_xs_tt', 'd_xs_wj', 'factor_elqcd', 'factor_muqcd', 'f_gg', 'f_qq', 'f_qg', 'f_ag', 'R_ag', 'slosh', 'alphaL', 'alphaT' ]: print >> self.log, '\t', roo.str(w.arg(item)) self.pll = pll w.arg('falphaL').setVal(p0[0]) w.arg('falphaT').setVal(p0[1]) pll.getVal() return
def doFit(self): w = self.model.w (alpha,alphaE), pll = self.minimize() def pllEval(p): w.arg('alpha').setVal(p) return pll.getVal() step = 0.2 * alphaE points = [alpha+i*step for i in range(-10,11)] pllPoints = [pllEval(p) for p in points] iL = min((abs(1-v),i) for i,v in list(enumerate(pllPoints))[:10])[1] iR = min((abs(1-v),i) for i,v in list(enumerate(pllPoints))[10:])[1] iBounds = (iL, iR) parb = parabola([(points[i],pllPoints[i]) for i in (10,)+iBounds]) self.profVal = float(parb.xmin) self.profErr = parb.dx(0.5) self.scale = w.arg('Ac_tt').getVal() self.fit = self.profVal * self.scale self.sigma = self.profErr * self.scale self.profPLL = pllEval(self.profVal) for item in ['pll','points','pllPoints']: setattr(self,item,eval(item)) self.parbABC = list(parb.ABC) if not self.quiet: print>>self.log print>>self.log, 'Ac: %f +/- %f'% (self.fit, self.sigma) print>>self.log print>>self.log, "fit alpha: %f +/- %f"%(alpha,alphaE) print>>self.log, "parb alpha: %f +/- %f"%(self.profVal, self.profErr) print>>self.log, "min PLL:", self.profPLL print>>self.log, parb for item in ['d_xs_tt','d_xs_wj','factor_elqcd','factor_muqcd']: print>>self.log, '\t', roo.str(w.arg(item)) print>>self.log print>>self.log, 'iBounds', iBounds for i,(p,v) in enumerate(zip(points,pllPoints)): print>>self.log, i, p, v w.arg('alpha').setError(self.profErr) return
def doFit(self): w = self.model.w contourPoints=None while not contourPoints: pll = self.minimize() p0, contourPoints = self.contourPoints(pll) ell = enclosing_ellipse([p[:2] for p in contourPoints],p0[:2]) self.profVal = p0[:2] self.profErr = ell.sigmas2 self.profPLL = p0[2] self.scales = np.array([w.arg(a).getVal() for a in ['Ac_y_ttqq', 'Ac_y_ttqg']]) self.scalesPhi= [w.arg('Ac_phi_%s'%n).getVal() for n in ['ttqq','ttgg','ttag','ttqg','tt']] self.correction = w.arg('Ac_y_ttgg').getVal() * w.arg('f_gg').getVal() self.fractionHats = [w.arg('f_%s_hat' % a).getVal() for a in ['gg','qg','qq','ag']] fitXY = self.profVal*self.scales sigmas2 = np.diag(self.scales).dot(self.profErr).dot(np.diag(self.scales)) self.fitX,self.fitY = [float(i) for i in fitXY] self.fitXX = float(sigmas2[0,0]) self.fitXY = float(sigmas2[0,1]) self.fitYY = float(sigmas2[1,1]) self.sigmaX = math.sqrt( self.fitXX / (2*oneSigmaNLL)) self.sigmaY = math.sqrt( self.fitYY / (2*oneSigmaNLL)) self.contourPointsX,self.contourPointsY, = zip(*[[float(i) for i in self.scales*p] for p in contourPoints]) if not self.quiet: print>>self.log, self.profVal, self.profPLL print>>self.log, self.profErr for item in ['d_qq','d_xs_tt','d_xs_wj', 'factor_elqcd','factor_muqcd', 'f_gg','f_qq','f_qg','f_ag', 'R_ag','slosh','alphaL','alphaT']: print>>self.log, '\t', roo.str(w.arg(item)) self.pll = pll w.arg('falphaL').setVal(p0[0]) w.arg('falphaT').setVal(p0[1]) pll.getVal() return