def langaufun(x, par): ''' Fit parameters: par[0]=Width (scale) parameter of Landau density par[1]=Most Probable (MP, location) parameter of Landau density par[2]=Total area (integral -inf to inf, normalization constant) par[3]=Width (sigma) of convoluted Gaussian function In the Landau distribution (represented by the CERNLIB approximation), the maximum is located at x=-0.22278298 with the location parameter=0. This shift is corrected within this function, so that the actual maximum is identical to the MP parameter. ''' # control constants ns = 100 # number of convolution steps sc = 5.0 # convolution extends to +-sc Gaussian sigmas # MP shift correction mpc = par[1] - mpshift * par[0] xlow = x[0] - sc * par[3] xupp = x[0] + sc * par[3] step = (xupp - xlow) / ns sumup = 0 for i in range(1, ns / 2): xx = xlow + (i - 0.5) * step fland = TMath.Landau(xx, mpc, par[0]) / par[0] sumup += fland * TMath.Gaus(x[0], xx, par[3]) xx = xupp - (i - .5) * step fland = TMath.Landau(xx, mpc, par[0]) / par[0] sumup += fland * TMath.Gaus(x[0], xx, par[3]) return par[2] * step * sumup * invsq2pi / par[3]
def langaufun(x, par): """Convoluted Landau and Gaussian Fitting Function source: https://root.cern.ch/root/html/tutorials/fit/langaus.C.html translated to python by Benjamin Rottler ([email protected]) parameters: par[0] = Width (scale) parameter of Landau density par[1] = Most Probable (MP, location) parameter of Landau density par[2] = Total area (integral -inf to inf, normalization constant) par[3] = Width (sigma) of convoluted Gaussian function In the Landau distribution (represented by the CERNLIB approximation), the maximum is located at x=-0.22278298 with the location parameter=0. This shift is corrected within this function, so that the actual maximum is identical to the MP parameter. """ # numeric constants invsq2pi = (2 * pi)**(-1 / 2) mpshift = -0.22278298 # Landau maximum location # control constants np = 500 # number of convolution steps sc = 5 # convolution extends to +-sc Guassion sigmas # mp shift correction mpc = par[1] - mpshift * par[0] # range of convolution integral xlow, xupp = x[0] - sc * par[3], x[0] + sc * par[3] # Convolution integral of Landau and Gaussion by sum i = 1 step = (xupp - xlow) / np s = 0 while i <= np / 2: xx = xlow + (i - 0.5) * step fland = TMath.Landau(xx, mpc, par[0]) / par[0] s += fland * TMath.Gaus(x[0], xx, par[3]) xx = xupp - (i - 0.5) * step fland = TMath.Landau(xx, mpc, par[0]) / par[0] s += fland * TMath.Gaus(x[0], xx, par[3]) i += 1 return (par[2] * step * s * invsq2pi / par[3])
def DeltaDeltaR(tau_4vec, lep_4vec, MET_2vec): """ Calculate the difference in dR between the expected dR (from Landau function) and measured dR between tau and lepton """ visTauLep = tau_4vec + lep_4vec MET_4Vec = TLorentzVector() MET_4Vec.SetPtEtaPhiM(MET_2vec.Mod(), 0, MET_2vec.Phi(), 0) TauLep = visTauLep + MET_4Vec TauLepPt = TauLep.Pt() / 1000 expecteddR = 18.5279 * TMath.Landau(TauLepPt, -14.8407, 67.7441) dR = tau_4vec.DeltaR(lep_4vec) return abs(dR - expecteddR), dR, TauLepPt
def ApplyTheFakeRate(x, p, parametrization): if parametrization == 'Jet': Land = p[2] * TMath.Landau(x, p[3], p[4]) Pol0 = p[0] + p[1] * x return Land + Pol0 elif parametrization == 'Lepton': if x > 250: x = 250 Land = p[0] + p[1] * pow(x, 1) + p[2] * pow(x, 2) + p[3] * pow( x, 3) + p[4] * pow(x, 4) # Land = p[2] * TMath.Landau(x, p[3], p[4]) # Pol0 = p[0] # return Land + Pol0 return Land else: raise Exception("Not a valid parametrization")
def _FIT_Jet(x, p): Land = p[2] * TMath.Landau(x[0], p[3], p[4]) Pol0 = p[0] + p[1] * x[0] return Land + Pol0
def _FIT_Jet_Function(x, p): Land = p[2] * TMath.Landau(x, p[3], p[4]) Pol0 = p[0]+p[1]*x return Land + Pol0
def NoisePlusLandauGaus(x, par): #p_noise comes from a template histogram and is normalized to 1.0 p_noise = 0 if (x[0] >= 0 and x[0] < 2): p_noise = 0.0219891 elif (x[0] >= 2 and x[0] < 4): p_noise = 0.120234 elif (x[0] >= 4 and x[0] < 6): p_noise = 0.201533 elif (x[0] >= 6 and x[0] < 8): p_noise = 0.208594 elif (x[0] >= 8 and x[0] < 10): p_noise = 0.150293 elif (x[0] >= 10 and x[0] < 12): p_noise = 0.103087 elif (x[0] >= 12 and x[0] < 14): p_noise = 0.0691951 elif (x[0] >= 14 and x[0] < 16): p_noise = 0.0490216 elif (x[0] >= 16 and x[0] < 18): p_noise = 0.0344967 elif (x[0] >= 18 and x[0] < 20): p_noise = 0.0217874 elif (x[0] >= 20 and x[0] < 22): p_noise = 0.0117006 elif (x[0] >= 22 and x[0] < 24): p_noise = 0.00484164 else: p_noise = 0.003228 #p_landau = TMath.Landau(x[0],par[2],par[3],False) invsq2pi = 0.3989422804014 # (2 pi)^(-1/2) mpshift = -0.22278298 # Landau maximum location np = 500.0 # number of convolution steps sc = 5.0 # convolution extends to +-sc Gaussian sigmas #integral result sum = 0.0 #MP shift correction mpc = par[2] - mpshift * par[3] #Range of convolution integral xlow = x[0] - sc * par[4] xupp = x[0] + sc * par[4] step = (xupp - xlow) / np #Convolution integral of Landau and Gaussian by sum for i in range(1, int(np / 2) + 1): xx = xlow + (i - .5) * step fland = TMath.Landau(xx, mpc, par[3]) / par[3] sum += fland * TMath.Gaus(x[0], xx, par[4]) xx = xupp - (i - .5) * step fland = TMath.Landau(xx, mpc, par[3]) / par[3] sum += fland * TMath.Gaus(x[0], xx, par[4]) p_landauGaus = step * sum * invsq2pi / par[4] return par[0] * ((1 - par[1]) * p_noise + par[1] * p_landauGaus)
def _FIT_Lepton_Function(x, p): Land = p[2] * TMath.Landau(x, p[3], p[4]) # Pol0 = p[0]+p[1]*x Pol0 = p[0] + p[1] return Land + Pol0