|
[Rivet-svn] r3460 - in branches/2011-07-aida2yoda: bin docblackhole at projects.hepforge.org blackhole at projects.hepforge.orgMon Oct 24 17:04:59 BST 2011
Author: hoeth Date: Mon Oct 24 17:04:58 2011 New Revision: 3460 Log: merge r3445-3448 from trunk Modified: branches/2011-07-aida2yoda/bin/Makefile.am branches/2011-07-aida2yoda/bin/make-plots branches/2011-07-aida2yoda/bin/root2flat branches/2011-07-aida2yoda/doc/make-plots.txt Modified: branches/2011-07-aida2yoda/bin/Makefile.am ============================================================================== --- branches/2011-07-aida2yoda/bin/Makefile.am Mon Oct 24 17:03:20 2011 (r3459) +++ branches/2011-07-aida2yoda/bin/Makefile.am Mon Oct 24 17:04:58 2011 (r3460) @@ -20,4 +20,4 @@ noinst_PROGRAMS = rivet-nopy rivet_nopy_SOURCES = rivet-nopy.cc rivet_nopy_CPPFLAGS = -I$(top_srcdir)/include $(AM_CPPFLAGS) -rivet_nopy_LDADD = ../src/libRivet.la +rivet_nopy_LDADD = ../src/libRivet.la -lHepMC Modified: branches/2011-07-aida2yoda/bin/make-plots ============================================================================== --- branches/2011-07-aida2yoda/bin/make-plots Mon Oct 24 17:03:20 2011 (r3459) +++ branches/2011-07-aida2yoda/bin/make-plots Mon Oct 24 17:04:58 2011 (r3460) @@ -962,8 +962,11 @@ out = "" out += ('\n%\n% Special\n%\n') import re - regex = re.compile(r'^(.*?)(\\physics[xy]?coor)\(([0-9\.\s]+),([0-9\.\s]+)\)(.*)') - for i in range(len(self.data)): + regex = re.compile(r'^(.*?)(\\physics[xy]?coor)\(\s?([0-9\.eE+-]+)\s?,\s?([0-9\.eE+-]+)\s?\)(.*)') + # TODO: More precise number string matching, something like this: + # num = r"-?[0-9]*(?:\.[0-9]*)(?:[eE][+-]?\d+]" + # regex = re.compile(r'^(.*?)(\\physics[xy]?coor)\(\s?(' + num + ')\s?,\s?(' + num + ')\s?\)(.*)') + for i in xrange(len(self.data)): while regex.search(self.data[i]): match = regex.search(self.data[i]) xcoor, ycoor = float(match.group(3)), float(match.group(4)) @@ -1270,6 +1273,23 @@ 'Content': foo/float(rebin), 'Error': [sqrt(barl)/float(rebin),sqrt(baru)/float(rebin)]}) self.data=newdata + if self.description.has_key('EnvelopeRebin') and self.description['EnvelopeRebin']!='': + rebin=int(self.description['EnvelopeRebin']) + newdata=[] + if rebin>=2: + for i in range(0,(len(self.data)/rebin)*rebin,rebin): + newcentral=0. + newmax=0. + newmin=0. + for j in range(rebin): + newcentral +=self.data[i+j]['Content'] + newmin +=self.data[i+j]['Content']-self.data[i+j]['Error'][0] + newmax +=self.data[i+j]['Content']+self.data[i+j]['Error'][1] + newdata.append({'LowEdge': self.data[i]['LowEdge'], + 'UpEdge': self.data[i+rebin-1]['UpEdge'], + 'Content': newcentral/float(rebin), + 'Error': [(newcentral-newmin)/float(rebin),(newmax-newcentral)/float(rebin)]}) + self.data=newdata def add(self,name): if len(self.data)!=len(name.data): @@ -1623,10 +1643,10 @@ bottom = inputdata.description['BottomMargin']+0.1 # - out += ('\\rput(0,1){\\psline[linewidth=%scm,linecolor=%s](%scm,%scm)(%scm,%scm)}' %(top, color, -left, top/2, width+right, top/2)) - out += ('\\rput(0,%scm){\\psline[linewidth=%scm,linecolor=%s](%scm,%scm)(%scm,%scm)}' %(height[1], bottom, color, -left, -bottom/2, width+right, -bottom/2)) - out += ('\\rput(0,0){\\psline[linewidth=%scm,linecolor=%s](%scm,%scm)(%scm,%scm)}' %(left, color, -left/2, height[1]-0.05, -left/2, height[0]+0.05)) - out += ('\\rput(1,0){\\psline[linewidth=%scm,linecolor=%s](%scm,%scm)(%scm,%scm)}' %(right, color, right/2, height[1]-0.05, right/2, height[0]+0.05)) + out += ('\\rput(0,1){\\psline[linewidth=%scm,linecolor=%s](%scm,%scm)(%scm,%scm)}\n' %(top, color, -left, top/2, width+right, top/2)) + out += ('\\rput(0,%scm){\\psline[linewidth=%scm,linecolor=%s](%scm,%scm)(%scm,%scm)}\n' %(height[1], bottom, color, -left, -bottom/2, width+right, -bottom/2)) + out += ('\\rput(0,0){\\psline[linewidth=%scm,linecolor=%s](%scm,%scm)(%scm,%scm)}\n' %(left, color, -left/2, height[1]-0.05, -left/2, height[0]+0.05)) + out += ('\\rput(1,0){\\psline[linewidth=%scm,linecolor=%s](%scm,%scm)(%scm,%scm)}\n' %(right, color, right/2, height[1]-0.05, right/2, height[0]+0.05)) out += ('\\psframe[linewidth='+self.framelinewidth+',dimen=middle](0,0)(1,1)\n') Modified: branches/2011-07-aida2yoda/bin/root2flat ============================================================================== --- branches/2011-07-aida2yoda/bin/root2flat Mon Oct 24 17:03:20 2011 (r3459) +++ branches/2011-07-aida2yoda/bin/root2flat Mon Oct 24 17:04:58 2011 (r3460) @@ -21,15 +21,18 @@ import os, optparse, logging, ROOT -# try: -# from IPython.Shell import IPShellEmbed -# ipshell = IPShellEmbed([]) -# except: -# print "Ipython shell not available." ## Parse options parser = optparse.OptionParser(usage = __doc__) +parser.add_option("-a", dest="ANALYSIS", default=None, + help = "Optionally add analysis name to histogram keys") +parser.add_option("-e", dest="ENUM", default=False, action='store_true', + help = "Enumerate histos hepdata style") +parser.add_option("-f", dest="FILENAME", default=None, + help = "Force output of all histos in single file") +parser.add_option("-x", dest="XCLUDE", default=None, + help = "Exclude histos from conversion based on string pattern") parser.add_option("-o", dest="OUTDIR", default=".", help = "specify directory in which to write out converted files") (opts, args) = parser.parse_args() @@ -39,27 +42,29 @@ """ This is the main function that opens a ROOT file, browses its contents for histograms and tries to write the converted histos to files. """ + global nobs # Open the ROOT file f = ROOT.TFile(rootfile) # Initial browse to see the structure subdirs, histonames, tgraphnames = browse(f) - # Keep browding if there are subdirectories TODO: Make this work for + # Keep browsing if there are subdirectories TODO: Make this work for # arbitrarily deep directory structures if len(subdirs) > 0: for sd in subdirs: t_s, t_h = browse(f, sd) histonames.extend(t_h) - #primary_keys = f.GetListOfKeys() - #iter_primaries = ROOT.TListIter(primary_keys) - # This will convert and write the histos - for histoname in histonames: - writeHisto(histoname, f.Get(histoname)) - for tgraphname in tgraphnames: - writeHisto(tgraphname, f.Get(tgraphname), True) + for num, histoname in enumerate(histonames): + writeHisto(histoname, f.Get(histoname), num+nobs) + for num, tgraphname in enumerate(tgraphnames): + writeHisto(tgraphname, f.Get(tgraphname), num + len(histonames)+nobs, True) + + nobs += len(histonames) + nobs += len(tgraphnames) + @@ -90,10 +95,12 @@ t_n = iter_primaries.Next().GetName() # Make sure we don't have a NoneType object here if f.Get(t_n): - # Check if the curent hing is a directory + if opts.XCLUDE is not None and opts.XCLUDE in t_n: + continue + # Check if the curent object is a directory if type(f.Get(t_n)) == ROOT.TDirectoryFile: subdirs.append(t_n) - # Check if the curent hing is a histogram + # Check if the curent object is a histogram elif f.Get(t_n).InheritsFrom("TH1") or f.Get(t_n).InheritsFrom("TProfile"): histos.append(t_n) elif f.Get(t_n).InheritsFrom("TGraphAsymmErrors"): @@ -160,7 +167,7 @@ return allbins -def writeHisto(name, R_histo, tgraph=False): +def writeHisto(name, R_histo, rivetid, tgraph=False): """ This writes the histogram into a single file, ready to plot with make-plots. """ @@ -171,13 +178,28 @@ 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, title) + if opts.ANALYSIS and opts.ENUM: + name = os.path.join(opts.ANALYSIS, "d"+str(rivetid).zfill(2)+"-x01-y01") + elif opts.ANALYSIS and not opts.ENUM: + name = os.path.join(opts.ANALYSIS, name) + histo = getFlatHisto(bins, name, title) flatname = name.replace("/","_") + ".dat" + if flatname.startswith("_"): flatname = flatname[1:] flatfile = os.path.join(opts.OUTDIR, flatname) - f = open(flatfile, "w") + + if not opts.FILENAME: + f = open(flatfile, "w") + else: + global nobs + if os.path.exists(opts.FILENAME) and rivetid == 1: + print "Error, outputfile '%s' exists! Exiting..."%opts.FILENAME + sys.exit(1) + else: + f = open(opts.FILENAME, "a") + f.write(head) f.write("\n") f.write(histo) @@ -194,13 +216,17 @@ 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 += "# END HISTOGRAM\n" + histo += "# END HISTOGRAM\n\n" return histo if __name__ == "__main__": + nobs = 1 for infile in args: if not os.path.exists(opts.OUTDIR): os.mkdir(opts.OUTDIR) readROOT(infile) - print "Done. Written all plot files to %s" % opts.OUTDIR + dest = opts.OUTDIR + if opts.FILENAME: + dest=opts.FILENAME + print "Done. Written all converted histos to %s" % dest Modified: branches/2011-07-aida2yoda/doc/make-plots.txt ============================================================================== --- branches/2011-07-aida2yoda/doc/make-plots.txt Mon Oct 24 17:03:20 2011 (r3459) +++ branches/2011-07-aida2yoda/doc/make-plots.txt Mon Oct 24 17:04:58 2011 (r3460) @@ -566,6 +566,13 @@ (i.e. if the original histogram has 10 bins and <nbins> is 3, the plotted histogram shows three bins combining the bins 1--9 of the original histogram). +-------------------- +EnvelopeRebin=<nbins> +-------------------- +Rebin an envelope histogram where the error bars represent an envelope. Thus, +they are combined linearly instead of as sum of squares. The functionality +is the same as 'Rebin' otherwise. + FUNCTION ~~~~~~~~
More information about the Rivet-svn mailing list |