software, phd, latex
Today, a bit of a blast from the past. I’m still working on getting some results published from my PhD days, and part of that is getting some old Python 2 scripts to work. Well, thankfully that isn’t very hard, they were written for Python 2(.7), which hasn’t changed and is still very available. Python 2 really is the Latin of programming languages; we (scientists) will be using in for a looooong time precisely because it isn’t receiving updates anymore. Not everyone appreciates that property, but in science, with people ever moving on and nobody having time to do maintenance, it’s actually a nice feature.
Anyway, the main thing that has changed is that I’m no longer a ROOT user (if I ever was) and am too lazy to setup ROOT (and it’s Python (2) bindings). Gate produces ROOT files containing TTree’s (PhaseSpaceActor) or TH1D’s (AugerActor), so I need to read them. At the tail end of my PhD I came across Uproot, a Python implementation of a ROOT file reader. So not of the ROOT software, just the file format. Well, that was the simplest update I’ve ever had the joy of doing, because it’s a very Pythonic library and it just werks. I even could simplify my code from this:
def thist2np_xy_cache(infile,key): assert(infile.endswith(".root")) npzfile = infile+"."+str(key)+".npz" if os.path.isfile(npzfile): cached = np.load(npzfile) return [cached['x'].tolist(),cached['y'].tolist()] else: tfile=r.TFile(infile,"READ") for item in tfile.GetListOfKeys(): outname=item.ReadObj().GetName() if outname == key: outdata_x= outdata_y= for i in range(item.ReadObj().GetNbinsX()): outdata_x.append(float(item.ReadObj().GetXaxis().GetBinCenter(i+1))) outdata_y.append(float(item.ReadObj().GetBinContent(i+1))) np.savez(npzfile, x=np.array(outdata_x), y=np.array(outdata_y)) return [outdata_x,outdata_y]
def thist_to_np_xy(infile,key='reconstructedProfileHisto'): assert(infile.endswith(".root")) f=uproot.open(infile) outdata_x=binedges_to_centers(f[key].edges) outdata_y=f[key].values return [outdata_x,outdata_y]
Note that I omitted the caching function, which wasn’t necessary anymore because Uproot is also much faster then ROOT’s Python bindings. Fantastico.
Second, TexLive 2019 was released today. It reminded me of my ol' PhD thesis, which I still hadn’t converted to html using tex4ht. It’s ofcouse a somewhat complex document, and today I gave it my third attempt, but failed. So I’ve given up, and decided to use Mozilla’s pdf.js. See here the result.