def write_banner(self, fsock): """create the new banner with the information of the weight""" cid = self.get_id() lowest_id = cid in_scale = False in_pdf = False in_alps = False text = '' default = self.args[0] for arg in self.args[1:]: mur, muf, alps, dyn, pdf = arg[:5] if pdf == self.orig_pdf and alps == 1 and (mur != 1 or muf != 1 or dyn != -1): if not in_scale: text += "<weightgroup name=\"Central scale variation\" combine=\"envelope\">\n" in_scale = True elif in_scale: if (pdf == self.orig_pdf and alps == 1) and arg != default: pass else: text += "</weightgroup> # scale\n" in_scale = False if pdf == self.orig_pdf and mur == muf == 1 and dyn == -1 and alps != 1: if not in_alps: text += "<weightgroup name=\"Emission scale variation\" combine=\"envelope\">\n" in_alps = True elif in_alps: text += "</weightgroup> # ALPS\n" in_alps = False if mur == muf == 1 and dyn == -1 and alps == 1: if pdf.lhapdfID < 0: for central, sets in self.pdfsets.items(): if pdf in sets.set(): misc.sprint(central) if pdf.lhapdfID in self.pdfsets: if in_pdf: text += "</weightgroup> # PDFSET -> PDFSET\n" pdfset = self.pdfsets[pdf.lhapdfID] descrip = pdfset.description.replace('=>', ';').replace( '>', '.gt.').replace('<', '.lt.') text +="<weightgroup name=\"%s\" combine=\"%s\"> # %s: %s\n" %\ (pdfset.name, pdfset.errorType,pdfset.lhapdfID, descrip) in_pdf = pdf.lhapdfID elif pdf.memberID == 0 and (pdf.lhapdfID - pdf.memberID) in self.pdfsets: if in_pdf: text += "</weightgroup> # PDFSET -> PDFSET\n" pdfset = self.pdfsets[pdf.lhapdfID - 1] descrip = pdfset.description.replace('=>', ';').replace( '>', '.gt.').replace('<', '.lt.') text +="<weightgroup name=\"%s\" combine=\"%s\"> # %s: %s\n" %\ (pdfset.name, pdfset.errorType,pdfset.lhapdfID, descrip) in_pdf = pdfset.lhapdfID elif in_pdf and pdf.lhapdfID - pdf.memberID != in_pdf: misc.sprint(pdf.lhapdfID) text += "</weightgroup> # PDFSET -> PDF\n" in_pdf = False elif in_pdf: text += "</weightgroup> PDF \n" in_pdf = False tag, info = '', '' if mur != 1.: tag += 'MUR="%s" ' % mur info += 'MUR=%s ' % mur else: tag += 'MUR="%s" ' % mur if muf != 1.: tag += 'MUF="%s" ' % muf info += 'MUF=%s ' % muf else: tag += 'MUF="%s" ' % muf if alps != 1.: tag += 'ALPSFACT="%s" ' % alps info += 'alpsfact=%s ' % alps if dyn != -1.: tag += 'DYN_SCALE="%s" ' % dyn info += 'dyn_scale_choice=%s ' % { 1: 'sum pt', 2: 'HT', 3: 'HT/2', 4: 'sqrts' }[dyn] if pdf != self.orig_pdf: tag += 'PDF="%s" ' % pdf.lhapdfID info += 'PDF=%s MemberID=%s' % (pdf.lhapdfID - pdf.memberID, pdf.memberID) else: tag += 'PDF="%s" ' % pdf.lhapdfID text += '<weight id="%s" %s> %s </weight>\n' % (cid, tag, info) cid += 1 if in_scale or in_alps or in_pdf: text += "</weightgroup>\n" if 'initrwgt' in self.banner: if not self.remove_wgts: self.banner['initrwgt'] += text else: # remove the line which correspond to removed weight # removed empty group. wgt_in_group = 0 tmp_group_txt = [] out = [] keep_last = False for line in self.banner['initrwgt'].split('\n'): sline = line.strip() if sline.startswith('</weightgroup'): if wgt_in_group: out += tmp_group_txt out.append('</weightgroup>') if '<weightgroup' in line: wgt_in_group = 0 tmp_group_txt = [line[line.index('<weightgroup'):]] elif sline.startswith('<weightgroup'): wgt_in_group = 0 tmp_group_txt = [line] elif sline.startswith('<weight'): name = re.findall(r'\bid=[\'\"]([^\'\"]*)[\'\"]', sline) if self.is_wgt_kept(name[0]): tmp_group_txt.append(line) keep_last = True wgt_in_group += 1 else: keep_last = False elif keep_last: tmp_group_txt.append(line) out.append(text) self.banner['initrwgt'] = '\n'.join(out) else: self.banner['initrwgt'] = text self.banner.write(self.output, close_tag=False) return lowest_id
def get_nlo_wgt(self, event, Dmur, Dmuf, Dalps, dyn, pdf): """return the new weight for NLO event --with weight information-- """ wgt = 0 nloinfo = event.parse_nlo_weight(real_type=(1, 11, 12, 13)) for cevent in nloinfo.cevents: if dyn == 1: mur2 = max(1.0, cevent.get_et_scale(1.)**2) elif dyn == 2: mur2 = max(1.0, cevent.get_ht_scale(1.)**2) elif dyn == 3: mur2 = max(1.0, cevent.get_ht_scale(0.5)**2) elif dyn == 4: mur2 = cevent.get_sqrts_scale(event, 1)**2 else: mur2 = 0 muf2 = mur2 for onewgt in cevent.wgts: if not __debug__ and (dyn == -1 and Dmur == 1 and Dmuf == 1 and pdf == self.orig_pdf): wgt += onewgt.ref_wgt if dyn == -1: mur2 = onewgt.scales2[1] muf2 = onewgt.scales2[2] Q2 = onewgt.scales2[0] # Ellis-Sexton scale wgtpdf = self.get_pdfQ2(pdf, self.b1 * onewgt.pdgs[0], onewgt.bjks[0], Dmuf**2 * muf2) wgtpdf *= self.get_pdfQ2(pdf, self.b2 * onewgt.pdgs[1], onewgt.bjks[1], Dmuf**2 * muf2) tmp = onewgt.pwgt[0] tmp += onewgt.pwgt[1] * math.log(Dmur**2 * mur2 / Q2) tmp += onewgt.pwgt[2] * math.log(Dmuf**2 * muf2 / Q2) if self.b1 == 0 == self.b2: alps = self.alpsrunner(Dmur * math.sqrt(mur2)) else: alps = pdf.alphasQ2(Dmur**2 * mur2) tmp *= math.sqrt(4 * math.pi * alps)**onewgt.qcdpower if wgtpdf == 0: #happens for nn23pdf due to wrong set in lhapdf key = (self.b1 * onewgt.pdgs[0], self.b2 * onewgt.pdgs[1], onewgt.bjks[0], onewgt.bjks[1], muf2) if dyn == -1 and Dmuf == 1 and Dmur == 1 and pdf == self.orig_pdf: wgtpdf = onewgt.ref_wgt / tmp self.pdfQ2[key] = wgtpdf elif key in self.pdfQ2: wgtpdf = self.pdfQ2[key] else: # real zero! wgtpdf = 0 tmp *= wgtpdf wgt += tmp if __debug__ and dyn == -1 and Dmur == 1 and Dmuf == 1 and pdf == self.orig_pdf: if not misc.equal(tmp, onewgt.ref_wgt, sig_fig=2): misc.sprint(tmp, onewgt.ref_wgt, (tmp - onewgt.ref_wgt) / tmp) misc.sprint(onewgt) misc.sprint(cevent) misc.sprint(mur2, muf2) raise Exception, 'not enough agreement between stored value and computed one' return wgt
def write_banner(self, fsock): """create the new banner with the information of the weight""" cid = self.get_id() lowest_id = cid in_scale = False in_pdf = False in_alps = False text = '' default = self.args[0] for arg in self.args[1:]: mur, muf, alps, dyn, pdf = arg[:5] if pdf == self.orig_pdf and alps == 1 and (mur != 1 or muf != 1 or dyn != -1): if not in_scale: text += "<weightgroup name=\"Central scale variation\" combine=\"envelope\">\n" in_scale = True elif in_scale: if (pdf == self.orig_pdf and alps == 1) and arg != default: pass else: text += "</weightgroup> # scale\n" in_scale = False if pdf == self.orig_pdf and mur == muf == 1 and dyn == -1 and alps != 1: if not in_alps: text += "<weightgroup name=\"Emission scale variation\" combine=\"envelope\">\n" in_alps = True elif in_alps: text += "</weightgroup> # ALPS\n" in_alps = False if mur == muf == 1 and dyn == -1 and alps == 1: if pdf.lhapdfID < 0: for central, sets in self.pdfsets.items(): if pdf in sets.set(): misc.sprint(central) if pdf.lhapdfID in self.pdfsets: if in_pdf: text += "</weightgroup> # PDFSET -> PDFSET\n" pdfset = self.pdfsets[pdf.lhapdfID] descrip = pdfset.description.replace('=>', ';').replace( '>', '.gt.').replace('<', '.lt.') text +="<weightgroup name=\"%s\" combine=\"%s\"> # %s: %s\n" %\ (pdfset.name, pdfset.errorType,pdfset.lhapdfID, descrip) in_pdf = pdf.lhapdfID elif pdf.memberID == 0 and (pdf.lhapdfID - pdf.memberID) in self.pdfsets: if in_pdf: text += "</weightgroup> # PDFSET -> PDFSET\n" pdfset = self.pdfsets[pdf.lhapdfID - 1] descrip = pdfset.description.replace('=>', ';').replace( '>', '.gt.').replace('<', '.lt.') text +="<weightgroup name=\"%s\" combine=\"%s\"> # %s: %s\n" %\ (pdfset.name, pdfset.errorType,pdfset.lhapdfID, descrip) in_pdf = pdfset.lhapdfID elif in_pdf and pdf.lhapdfID - pdf.memberID != in_pdf: misc.sprint(pdf.lhapdfID) text += "</weightgroup> # PDFSET -> PDF\n" in_pdf = False elif in_pdf: text += "</weightgroup> PDF \n" in_pdf = False tag, info = '', '' if mur != 1.: tag += 'MUR="%s" ' % mur info += 'MUR=%s ' % mur else: tag += 'MUR="%s" ' % mur if muf != 1.: tag += 'MUF="%s" ' % muf info += 'MUF=%s ' % muf else: tag += 'MUF="%s" ' % muf if alps != 1.: tag += 'ALPSFACT="%s" ' % alps info += 'alpsfact=%s ' % alps if dyn != -1.: tag += 'DYN_SCALE="%s" ' % dyn info += 'dyn_scale_choice=%s ' % { 1: 'sum pt', 2: 'HT', 3: 'HT/2', 4: 'sqrts' }[dyn] if pdf != self.orig_pdf: tag += 'PDF="%s" ' % pdf.lhapdfID info += 'PDF=%s MemberID=%s' % (pdf.lhapdfID - pdf.memberID, pdf.memberID) else: tag += 'PDF="%s" ' % pdf.lhapdfID text += '<weight id="%s" %s> %s </weight>\n' % (cid, tag, info) cid += 1 if in_scale or in_alps or in_pdf: text += "</weightgroup>\n" if 'initrwgt' in self.banner: self.banner['initrwgt'] += text else: self.banner['initrwgt'] = text self.banner.write(self.output, close_tag=False) return lowest_id