|
[Rivet-svn] r2430 - trunk/binblackhole at projects.hepforge.org blackhole at projects.hepforge.orgFri Apr 30 15:14:41 BST 2010
Author: buckley Date: Fri Apr 30 15:20:28 2010 New Revision: 2430 Log: Improvements to root2flat Modified: trunk/bin/root2flat Modified: trunk/bin/root2flat ============================================================================== --- trunk/bin/root2flat Fri Apr 30 15:00:57 2010 (r2429) +++ trunk/bin/root2flat Fri Apr 30 15:20:28 2010 (r2430) @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python """%prog Read in .root files and write out the histograms in FLAT @@ -11,7 +11,6 @@ %prog [options] file1.root Use --help to get information for all options. - """ import os, optparse, logging, ROOT @@ -97,7 +96,7 @@ def convertHisto(R_histo): - """ This sunction read a single ROOT histo and converts it into the + """ This function reads a single ROOT histo and converts it into the FLAT format suitable for plotting with make-plots. """ title = R_histo.GetTitle().replace("#","\\") @@ -163,26 +162,27 @@ head = "# BEGIN PLOT\nTitle=%s\nLegend=1\nLogY=1\nDrawOnly=%s\n"%(title, name) head += "XLabel=%s\nYLabel=%s\n# END PLOT\n"%(xlabel, ylabel) - histo = getFlatHisto(bins, name) + histo = getFlatHisto(bins, name, title) flatname = name.replace("/","_") + ".dat" flatfile = os.path.join(opts.OUTDIR, flatname) f = open(flatfile, "w") f.write(head) + f.write("\n") f.write(histo) f.close() -def getFlatHisto(bins, name): +def getFlatHisto(bins, name, title): """ This returns a histo in the FLAT format. """ - histo= "# BEGIN HISTOGRAM %s\n"%name + histo= "# BEGIN HISTOGRAM %s\n" % name histo += "LineColor=black\n" histo += "ErrorBars=1\n" histo += "PolyMarker=*\n" - histo += "Title=%s\n"%name - for bin in bins: - histo += "%.8e\t%.8e\t%.8e\t%.8e\t%.8e\n"%(bin["xlow"], bin["xhigh"], bin["y"], - bin["y_err_low"], bin["y_err_high"]) + histo += "Title=%s\n" % title + for bin in bins[1:]: # first ROOT bin seems to be under/overflow? At least for TProfile... + histo += "%.8e\t%.8e\t%.8e\t%.8e\t%.8e\n" % (bin["xlow"], bin["xhigh"], + bin["y"], bin["y_err_low"], bin["y_err_high"]) histo += "# END HISTOGRAM\n" return histo
More information about the Rivet-svn mailing list |