def reduce(dirlist, outdir, listname=""): indirs = dirlist.split(',') pname_wa = 'w' cpname_wa = 'w' oprocesslist = [] ocprocesslist = [] pname = outdir + "/" + listname + "processlist.txt" cpname = outdir + "/" + listname + "creatorlist.txt" if os.path.exists(pname): pname_wa = 'a' with open(pname) as f: oprocesslist = f.readlines() if os.path.exists(cpname): cpname_wa = 'a' with open(cpname) as f: ocprocesslist = f.readlines() processlist = [] cprocesslist = [] processes = TString("") cprocesses = TString("") for folder in indirs: mychain = TChain("DataTree") print "\nAdding: " + folder outnames = folder.rsplit('/')[-1] sourcename = outnames.split('_', 1)[-1] folder += "/out/*.root" mychain.Add(str(folder)) print "Processing " + sourcename ROOT.ExtractData(mychain, TString(sourcename), TString(outdir), processes, cprocesses) for ip in processes.Data().split(','): if ip not in oprocesslist and ip not in processlist and ip != "": ip = re.sub(r'[^\x00-\x7f]', r'', ip) processlist.append(ip) for ip in cprocesses.Data().split(','): if ip not in ocprocesslist and ip not in cprocesslist and ip != "": ip = re.sub(r'[^\x00-\x7f]', r'', ip) cprocesslist.append(ip) with open(pname, pname_wa) as f: for ip in processlist: line = ip + "\n" f.write(line) with open(cpname, cpname_wa) as f: for ip in cprocesslist: line = ip + "\n" f.write(line)
def GetProcesses(filelist, appendagename=""): """ Generates list of processes and creator processes in the dataset for plotting if not already done """ pname = "/global/homes/l/lkorley/myprojectdir/HighNR/lists/" + appendagename + "processlist.txt" cpname = "/global/homes/l/lkorley/myprojectdir/HighNR/lists/" + appendagename + "creatorlist.txt" oprocesslist = [] ocprocesslist = [] if os.path.exists(pname): with open(pname) as f: oprocesslist = f.readlines() else: cmd = "touch " + pname os.system(cmd) if os.path.exists(cpname): with open(cpname) as f: ocprocesslist = f.readlines() else: cmd = "touch " + cpname os.system(cmd) processes = TString("") cprocesses = TString("") for filename in glob.glob(filelist): mychain = TChain("DTree") mychain.Add(str(filename)) ROOT.listprocess(mychain, processes, cprocesses) for ip in processes.Data().split(','): if ip not in oprocesslist: ip = re.sub(r'[^\x00-\x7f]', r'', ip) oprocesslist.append(ip) with open(pname, "a") as f: line = ip + "\n" f.write(line) for ip in cprocesses.Data().split(','): if ip not in ocprocesslist: ip = re.sub(r'[^\x00-\x7f]', r'', ip) ocprocesslist.append(ip) with open(cpname, "a") as f: line = ip + "\n" f.write(line)
def __init__(self, taggerName="DeepFlav", meastype="mujets", wp="Medium", year=2017): taggerName = TString(taggerName) #"DeepFlav","CSVv2";"DeepCSV"; MeasType = TString(meastype) # comb, mujets stringWP = TString(wp) self.fBTagSFnom = BTagSFUtil(MeasType.Data(), pathtolib, taggerName.Data(), stringWP, 0, year, '') self.fBTagSFbUp = BTagSFUtil(MeasType.Data(), pathtolib, taggerName.Data(), stringWP, 1, year, '') self.fBTagSFbDo = BTagSFUtil(MeasType.Data(), pathtolib, taggerName.Data(), stringWP, -1, year, '') self.fBTagSFlUp = BTagSFUtil(MeasType.Data(), pathtolib, taggerName.Data(), stringWP, 3, year, '') self.fBTagSFlDo = BTagSFUtil(MeasType.Data(), pathtolib, taggerName.Data(), stringWP, -3, year, '')
def writeCurrentFile(rootFile): ''' Save a copy of the current script, as a TText, in the current ROOT file nothing happens if a ROOT file is not currently open! ''' import sys, os.path from ROOT import TString, TText, TFile filename = sys.argv[0] if (not os.path.exists(filename)): m_log.error("Could not open file " + filename + "!") return s = TString() t = TText() # Too fresh #with open(filename) as input: input = open(filename) if input: for line in input: s += line t.SetName(os.path.basename(filename)) t.SetText(0, 0, s.Data()) f = TFile(rootFile, 'UPDATE') t.Write() f.Close()
def cms_lumi(pad, iPeriod, iPosX): outOfFrame = False if iPosX / 10 == 0: outOfFrame = True alignY_ = 3 alignX_ = 2 if iPosX / 10 == 0: alignX_ = 1 if iPosX == 0: alignY_ = 1 if iPosX / 10 == 1: alignX_ = 1 if iPosX / 10 == 2: alignX_ = 2 if iPosX / 10 == 3: alignX_ = 3 align_ = 10 * alignX_ + alignY_ H = pad.GetWh() W = pad.GetWw() l = pad.GetLeftMargin() t = pad.GetTopMargin() r = pad.GetRightMargin() b = pad.GetBottomMargin() # e = 0.025 pad.cd() lumiText = TString('') if iPeriod == 1: lumiText += lumi_7TeV lumiText += " (7 TeV)" elif iPeriod == 2: lumiText += lumi_8TeV lumiText += " (8 TeV)" elif iPeriod == 3: lumiText = lumi_8TeV lumiText += " (8 TeV)" lumiText += " + " lumiText += lumi_7TeV lumiText += " (7 TeV)" elif iPeriod == 4: lumiText += lumi_13TeV lumiText += " (13 TeV)" elif iPeriod == 7: if outOfFrame: lumiText += "#scale[0.85]{" lumiText += lumi_13TeV lumiText += " (13 TeV)" lumiText += " + " lumiText += lumi_8TeV lumiText += " (8 TeV)" lumiText += " + " lumiText += lumi_7TeV lumiText += " (7 TeV)" if outOfFrame: lumiText += "}" elif iPeriod == 12: lumiText += "8 TeV" elif iPeriod == 14: lumiText += lumi_14TeV lumiText += ", 14 TeV" elif iPeriod == 1420: lumiText += lumi_1420TeV lumiText += ", 14 TeV" print lumiText latex = TLatex() latex.SetNDC() latex.SetTextAngle(0) latex.SetTextColor(TStyle.kBlack) extraTextSize = extraOverCmsTextSize * cmsTextSize latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(lumiTextSize * t) latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText.Data()) if outOfFrame: latex.SetTextFont(cmsTextFont) latex.SetTextAlign(11) latex.SetTextSize(cmsTextSize * t) latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText) pad.cd() posX_ = 0 if iPosX % 10 <= 1: posX_ = l + relPosX * (1 - l - r) elif iPosX % 10 == 2: posX_ = l + 0.5 * (1 - l - r) elif iPosX % 10 == 3: posX_ = 1 - r - relPosX * (1 - l - r) posY_ = 1 - t - relPosY * (1 - t - b) if not outOfFrame: if drawLogo: posX_ = l + 0.045 * (1 - l - r) * W / H posY_ = 1 - t - 0.045 * (1 - t - b) xl_0 = posX_ yl_0 = posY_ - 0.15 xl_1 = posX_ + 0.15 * H / W yl_1 = posY_ CMS_logo = TASImage("CMS-BW-label.png") pad_logo = TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1) pad_logo.Draw() pad_logo.cd() CMS_logo.Draw("X") pad_logo.Modified() pad.cd() else: latex.SetTextFont(cmsTextFont) latex.SetTextSize(cmsTextSize * t) latex.SetTextAlign(align_) latex.DrawLatex(posX_, posY_, cmsText.Data()) if writeExtraText: latex.SetTextFont(extraTextFont) latex.SetTextAlign(align_) latex.SetTextSize(extraTextSize * t) latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText) elif writeExtraText: if iPosX == 0: posX_ = l + relPosX * (1 - l - r) posY_ = 1 - t + lumiTextOffset * t latex.SetTextFont(extraTextFont) latex.SetTextSize(extraTextSize * t) latex.SetTextAlign(align_) latex.DrawLatex(posX_, posY_, extraText)