def getFom(thresh, classifier, relSysErr=0.05, lepCharge=0, verbose=False, resType="fom"): cut = setup['preselection'] if lepCharge == -1: cut += "&&softIsolatedMuCharge==-1" if lepCharge == 1: cut += "&&softIsolatedMuCharge==+1" yieldStot = getYield(data['allTestEvents'], setup, reader, allMethods[classifier]['config'], cut + '&&type==1&&mstop==300&&mlsp==270', -999, weightFunc=getScaledWeight) yieldS = getYield(data['allTestEvents'], setup, reader, allMethods[classifier]['config'], cut + '&&type==1&&mstop==300&&mlsp==270', thresh, weightFunc=getScaledWeight) yieldB = getYield(data['allTestEvents'], setup, reader, allMethods[classifier]['config'], cut + '&&type==0', thresh, weightFunc=getScaledWeight) # yieldS = getYieldFromChain(cSignal, cut, weight = "weight") # yieldB = getYieldFromChain(cBkg, cut, weight = "weight") if yieldS <= 0. or yieldB <= 0.: return -999. fom = yieldS / sqrt(yieldB + (relSysErr * yieldB)**2) if verbose: print "thresh", thresh, "fom:", fom, 'cut', cut, 'sigEff:', yieldS / yieldStot if resType == "fom": return fom else: return { 'fom': fom, 'yieldS': yieldS, "yieldB": yieldB, 'sigEff': yieldS / yieldStot }
def getFom(thresh, classifier, relSysErr=0.05, lepCharge=0, verbose=False, resType="fom"): cut = setup["preselection"] if lepCharge == -1: cut += "&&softIsolatedMuCharge==-1" if lepCharge == 1: cut += "&&softIsolatedMuCharge==+1" yieldStot = getYield( data["allTestEvents"], setup, reader, allMethods[classifier]["config"], cut + "&&type==1&&mstop==300&&mlsp==270", -999, weightFunc=getScaledWeight, ) yieldS = getYield( data["allTestEvents"], setup, reader, allMethods[classifier]["config"], cut + "&&type==1&&mstop==300&&mlsp==270", thresh, weightFunc=getScaledWeight, ) yieldB = getYield( data["allTestEvents"], setup, reader, allMethods[classifier]["config"], cut + "&&type==0", thresh, weightFunc=getScaledWeight, ) # yieldS = getYieldFromChain(cSignal, cut, weight = "weight") # yieldB = getYieldFromChain(cBkg, cut, weight = "weight") if yieldS <= 0.0 or yieldB <= 0.0: return -999.0 fom = yieldS / sqrt(yieldB + (relSysErr * yieldB) ** 2) if verbose: print "thresh", thresh, "fom:", fom, "cut", cut, "sigEff:", yieldS / yieldStot if resType == "fom": return fom else: return {"fom": fom, "yieldS": yieldS, "yieldB": yieldB, "sigEff": yieldS / yieldStot}
def getExpExcl(thresh, retType=None): bkg = lumiFac*getYield(data['simu'], setup, reader, allMethods[methodName]['config'], setup["preselection"]+"&&type==0", thresh, weight) sig = lumiFac*getYield(data['simu'], setup, reader, allMethods[methodName]['config'], setup["preselection"]+"&&type==1&&osetMgl=="+str(mgl)+"&&osetMN=="+str(mN), thresh, weight) c = cardFileWriter() c.addBin('Bin0', ['bkg'], 'Bin0') c.specifyObservation('Bin0', int(bkg)) c.specifyExpectation('Bin0', 'bkg', bkg) c.specifyExpectation('Bin0', 'signal', sig) c.addUncertainty('globalUnc', 'lnN') c.specifyUncertainty('globalUnc', 'Bin0', 'bkg', 1.2) if bkg==0. or sig==0.: res={'0.500':float('nan')} else: res= c.calcLimit('opt.txt',options=opt) print "#########################", methodName, "##################################" print "Now at thresh",thresh, "bkg/sig", bkg,"/", sig, print "Results",res print "################################################################" if not retType: return res['0.500'] else: return res
def getSigEffDev(thresh): sig = lumiFac*getYield(data['simu'], setup, reader, allMethods[methodName]['config'], setup["preselection"]+"&&type==1&&osetMgl=="+str(mgl)+"&&osetMN=="+str(mN), thresh, weight) res= sig/float(sigInc) print "Optimizing MVA cut for targetSigEff of ",targetSigEff,". Testing threshold",thresh,"found sig eff.:", res return abs(res-targetSigEff)
nev = data['simu'].GetEntries('osetMgl=='+str(mgl)+'&&osetMN=='+str(mN)) if nev==0: print "No events in dataset for mgl/mN ",mgl, "/",mN continue from cardFileWriter import cardFileWriter # targetBkg=3. for methodName in [ 'MLP21']:#, 'myCut']: import numpy as np from scipy import optimize # def getBkgDev(thresh): # res= getYield(data['simu'], setup, reader, allMethods[methodName]['config'], setup["preselection"]+"&&type==0", thresh, 'weightLumi') # print "Optimizing MVA cut for bkg estimation of ",targetBkg,". Testing threshold",thresh,"found bkg exp.:",res # return abs(res-targetBkg) # x0 = np.array([0.9]) # optThresh = optimize.fmin(getBkgDev, x0) sigInc = lumiFac*getYield(data['simu'], setup, reader, allMethods[methodName]['config'], setup["preselection"]+"&&type==1&&osetMgl=="+str(mgl)+"&&osetMN=="+str(mN), -1, weight) def getSigEffDev(thresh): sig = lumiFac*getYield(data['simu'], setup, reader, allMethods[methodName]['config'], setup["preselection"]+"&&type==1&&osetMgl=="+str(mgl)+"&&osetMN=="+str(mN), thresh, weight) res= sig/float(sigInc) print "Optimizing MVA cut for targetSigEff of ",targetSigEff,". Testing threshold",thresh,"found sig eff.:", res return abs(res-targetSigEff) # x0 = np.array([0.9]) # optThresh = optimize.fmin(getSigEffDev, x0) if (model=="T1tttt" or model=="T1tttt-madgraph") and mgl<=950 and mN<=400: opt = "--rMax 10.0" else: opt = "" def getExpExcl(thresh, retType=None):