def evalTwoNllFullMu(self, x=None, y=None, values=None): """ h is a dictionary of channel:(muTmuW histograms,mapFunction). For the muTmuW plot, mapFunc is the identity. For the coupling plots, mapFunction is the map from couplings to muTmuW. """ if x != None: self.pois[0] = x if y != None: self.pois[1] = y if values != None: for k, v in zip(self.nuisanceParameters.keys(), values): self.nuisanceParameters[k] = v twoNll = 0.0 for hist, etas, mapFunc in self.inputs: muT, muW = mapFunc(self.pois[0], self.pois[1]) muR = self.responseFunctionInv({'muT': muT, 'muW': muW}, etas) twoNll += interpolate(hist, muR['muT'], muR['muW'], outOfRangeValue=1e6) twoNll += self.constraintTerms() return twoNll
def evalTwoNllFast(self, etasAndPhi, npArray): twoNll = 0.0 for hist, etas, mapFunc in self.inputs: mu = numpy.matrix(mapFunc(self.pois[0], self.pois[1])).transpose() muR = self.responseFunctionFast(mu, etasAndPhi, npArray) twoNll += interpolate(hist, muR[0], muR[1]) # constraint term fast twoNll += sum(v * v for v in npArray) return twoNll
def evalTwoNllFast( self, etasAndPhi, npArray ): twoNll = 0.0 for hist,etas,mapFunc in self.inputs: mu = numpy.matrix( mapFunc(self.pois[0], self.pois[1]) ).transpose() muR = self.responseFunctionFast( mu, etasAndPhi, npArray ) twoNll += interpolate( hist, muR[0], muR[1] ) # constraint term fast twoNll += sum( v*v for v in npArray ) return twoNll
def evalTwoNllFullMu( self, x=None, y=None, values=None ): """ h is a dictionary of channel:(muTmuW histograms,mapFunction). For the muTmuW plot, mapFunc is the identity. For the coupling plots, mapFunction is the map from couplings to muTmuW. """ if x != None: self.pois[0] = x if y != None: self.pois[1] = y if values!=None: for k,v in zip(self.nuisanceParameters.keys(),values): self.nuisanceParameters[k] = v twoNll = 0.0 for hist,etas,mapFunc in self.inputs: muT,muW = mapFunc(self.pois[0], self.pois[1]) muR = self.responseFunctionInv( {'muT':muT, 'muW':muW}, etas ) twoNll += interpolate( hist, muR['muT'], muR['muW'], outOfRangeValue=1e6 ) twoNll += self.constraintTerms() return twoNll
def getConstraintTermsHists(self, filename, suffix=None, useAverage=False, priority=None): """ Constructs constraint term values as a function of muT,muW but only keeps terms that were not seens in a previous channel. """ if not priority: priority = reversed(["2ph", "4l", "lvlv"]) f = ROOT.TFile.Open(filename, "READ") l = f.GetListOfKeys() nuisParams = [] for i in range(l.GetSize()): if "nuisParValue_" == l.At(i).GetName()[:13]: nuisName = l.At(i).GetName()[13:] nuisName = nuisName[:nuisName.rfind( "_")] # remove channel label if suffix: if suffix not in nuisName: continue nuisName = nuisName.replace(suffix, "") else: containsSuffix = False for possibleSuffix in [ "_eff", "_forCouplingsFromProdModes" ]: if possibleSuffix in nuisName: containsSuffix = True break if containsSuffix: continue if nuisName in nuisParams: continue nuisParams.append(nuisName) print( "======== Nuisance Parameters taken into account for constraint term ========" ) print(nuisParams) print("") # Average nuisance parameter value. # When having three Gaussians with the same width at different positions # (or as here, the same Gaussian three times with different pulls), then # the maximum of the product of the three Gaussians is at the arithmetic # mean of the three Gaussian mean values. # # Do not use for now because the different histogram boundaries between # the channels are a problem. # averageNuisParValues = {} # for n in nuisParams: # maxBinsMuT,maxBinsMuW = (0,0) # maxMuT,maxMuW = (0,0) # minMuT,minMuW = (10,10) # for c in ["4l","2ph","lvlv"]: # give priority to 4l because we need the maximum parameter range # n_h = f.Get( "nuisParValue_"+n+suffix+"_"+c ) # if not n_h: continue # muT = [ n_h.GetXaxis().GetNbins(), n_h.GetXaxis().GetXmin(), n_h.GetXaxis().GetXmax() ] # muW = [ n_h.GetYaxis().GetNbins(), n_h.GetYaxis().GetXmin(), n_h.GetYaxis().GetXmax() ] # if muT[0] > maxBinsMuT: maxBinsMuT = muT[0] # if muW[0] > maxBinsMuW: maxBinsMuW = muW[0] # if muT[1] < minMuT: minMuT = muT[1] # if muW[1] < minMuW: minMuW = muW[1] # if muT[2] > maxMuT: maxMuT = muT[2] # if muW[2] > maxMuW: maxMuW = muW[2] # if n in averageNuisParValues.keys(): # averageNuisParValues[n].append( n_h ) # else: # averageNuisParValues[n] = [ n_h ] # muT = [ 2*maxBinsMuT, minMuT, maxMuT ] # muW = [ 2*maxBinsMuW, minMuW, maxMuW ] # h_average = ROOT.TH2F( "average_"+n, "Average value of "+n+";muT;muW;average value", muT[0], muT[1], muT[2], muW[0], muW[1], muW[2] ) # for x in range(muT[0] ): # muTVal = muT[1] + (x+0.5)*(muT[2]-muT[1]) / muT[0] # for y in range( muW[0] ): # muWVal = muW[1] + (y+0.5)*(muW[2]-muW[1]) / muW[0] # count = 0 # sumVal = 0.0 # for h in averageNuisParValues[n]: # val = interpolate( h, muTVal, muWVal, outOfRangeValue=2345789 ) # if val != 2345789: # sumVal += val # count += 1 # if count > 0: # bin = h_average.FindBin( muTVal, muWVal ) # h_average.SetBinContent( bin, sumVal/count ) # averageNuisParValues[n] = h_average h = {"2ph": None, "4l": None, "lvlv": None} seenNuisParams = [] for c in priority: muT, muW = (None, None) for n in nuisParams: n_h = f.Get("nuisParValue_" + n + suffix + "_" + c) if not n_h: continue if h[c] is None: muT = [ n_h.GetXaxis().GetNbins(), n_h.GetXaxis().GetXmin(), n_h.GetXaxis().GetXmax() ] muW = [ n_h.GetYaxis().GetNbins(), n_h.GetYaxis().GetXmin(), n_h.GetYaxis().GetXmax() ] h[c] = ROOT.TH2F( "constr_" + c, "Constraint term value for " + c + ";muT;muW;-2 ln #Lambda", muT[0], muT[1], muT[2], muW[0], muW[1], muW[2]) if (not useAverage) and n not in seenNuisParams: seenNuisParams.append(n) else: for x in range(muT[0]): muTVal = muT[1] + (x + 0.5) * (muT[2] - muT[1]) / muT[0] for y in range(muW[0]): muWVal = muW[1] + (y + 0.5) * (muW[2] - muW[1]) / muW[0] bin = h[c].FindBin(muTVal, muWVal) if n_h: v = n_h.GetBinContent(bin) ave = 0.0 if useAverage: ave = interpolate(averageNuisParValues[n], muTVal, muWVal, outOfRangeValue=0.0) h[c].SetBinContent( bin, h[c].GetBinContent(bin) + (v - ave) * (v - ave)) container.append(h) return (h["2ph"], h["4l"], h["lvlv"])
def getConstraintTermsHists( self, filename, suffix=None, useAverage=False, priority=None ): """ Constructs constraint term values as a function of muT,muW but only keeps terms that were not seens in a previous channel. """ if not priority: priority = reversed(["2ph","4l","lvlv"]) f = ROOT.TFile.Open( filename, "READ" ) l = f.GetListOfKeys() nuisParams = [] for i in range( l.GetSize() ): if "nuisParValue_" == l.At(i).GetName()[:13]: nuisName = l.At(i).GetName()[13:] nuisName = nuisName[:nuisName.rfind("_")] # remove channel label if suffix: if suffix not in nuisName: continue nuisName = nuisName.replace(suffix, "") else: containsSuffix = False for possibleSuffix in ["_eff","_forCouplingsFromProdModes"]: if possibleSuffix in nuisName: containsSuffix = True break if containsSuffix: continue if nuisName in nuisParams: continue nuisParams.append( nuisName ) print( "======== Nuisance Parameters taken into account for constraint term ========") print( nuisParams ) print( "" ) # Average nuisance parameter value. # When having three Gaussians with the same width at different positions # (or as here, the same Gaussian three times with different pulls), then # the maximum of the product of the three Gaussians is at the arithmetic # mean of the three Gaussian mean values. # # Do not use for now because the different histogram boundaries between # the channels are a problem. # averageNuisParValues = {} # for n in nuisParams: # maxBinsMuT,maxBinsMuW = (0,0) # maxMuT,maxMuW = (0,0) # minMuT,minMuW = (10,10) # for c in ["4l","2ph","lvlv"]: # give priority to 4l because we need the maximum parameter range # n_h = f.Get( "nuisParValue_"+n+suffix+"_"+c ) # if not n_h: continue # muT = [ n_h.GetXaxis().GetNbins(), n_h.GetXaxis().GetXmin(), n_h.GetXaxis().GetXmax() ] # muW = [ n_h.GetYaxis().GetNbins(), n_h.GetYaxis().GetXmin(), n_h.GetYaxis().GetXmax() ] # if muT[0] > maxBinsMuT: maxBinsMuT = muT[0] # if muW[0] > maxBinsMuW: maxBinsMuW = muW[0] # if muT[1] < minMuT: minMuT = muT[1] # if muW[1] < minMuW: minMuW = muW[1] # if muT[2] > maxMuT: maxMuT = muT[2] # if muW[2] > maxMuW: maxMuW = muW[2] # if n in averageNuisParValues.keys(): # averageNuisParValues[n].append( n_h ) # else: # averageNuisParValues[n] = [ n_h ] # muT = [ 2*maxBinsMuT, minMuT, maxMuT ] # muW = [ 2*maxBinsMuW, minMuW, maxMuW ] # h_average = ROOT.TH2F( "average_"+n, "Average value of "+n+";muT;muW;average value", muT[0], muT[1], muT[2], muW[0], muW[1], muW[2] ) # for x in range(muT[0] ): # muTVal = muT[1] + (x+0.5)*(muT[2]-muT[1]) / muT[0] # for y in range( muW[0] ): # muWVal = muW[1] + (y+0.5)*(muW[2]-muW[1]) / muW[0] # count = 0 # sumVal = 0.0 # for h in averageNuisParValues[n]: # val = interpolate( h, muTVal, muWVal, outOfRangeValue=2345789 ) # if val != 2345789: # sumVal += val # count += 1 # if count > 0: # bin = h_average.FindBin( muTVal, muWVal ) # h_average.SetBinContent( bin, sumVal/count ) # averageNuisParValues[n] = h_average h = { "2ph":None, "4l":None, "lvlv":None } seenNuisParams = [] for c in priority: muT,muW = (None,None) for n in nuisParams: n_h = f.Get( "nuisParValue_"+n+suffix+"_"+c ) if not n_h: continue if h[c] is None: muT = [ n_h.GetXaxis().GetNbins(), n_h.GetXaxis().GetXmin(), n_h.GetXaxis().GetXmax() ] muW = [ n_h.GetYaxis().GetNbins(), n_h.GetYaxis().GetXmin(), n_h.GetYaxis().GetXmax() ] h[c] = ROOT.TH2F( "constr_"+c, "Constraint term value for "+c+";muT;muW;-2 ln #Lambda", muT[0], muT[1], muT[2], muW[0], muW[1], muW[2] ) if (not useAverage) and n not in seenNuisParams: seenNuisParams.append( n ) else: for x in range(muT[0] ): muTVal = muT[1] + (x+0.5)*(muT[2]-muT[1]) / muT[0] for y in range( muW[0] ): muWVal = muW[1] + (y+0.5)*(muW[2]-muW[1]) / muW[0] bin = h[c].FindBin( muTVal, muWVal ) if n_h: v = n_h.GetBinContent(bin) ave = 0.0 if useAverage: ave = interpolate( averageNuisParValues[n], muTVal, muWVal, outOfRangeValue=0.0 ) h[c].SetBinContent( bin, h[c].GetBinContent(bin) + (v-ave)*(v-ave) ) container.append( h ) return (h["2ph"],h["4l"],h["lvlv"])