diff --git a/Tests/python/merge-DIS b/Tests/python/merge-DIS --- a/Tests/python/merge-DIS +++ b/Tests/python/merge-DIS @@ -1,155 +1,155 @@ #! /usr/bin/env python import logging import sys if sys.version_info[:3] < (2,4,0): print "rivet scripts require Python version >= 2.4.0... exiting" sys.exit(1) import os, yoda # ############################################# def fillAbove(desthisto, sourcehistosbyq2): q2high=1e100 q2low=-1e100 for q2,h in sorted(sourcehistosbyq2.iteritems(),reverse=True) : q2low=q2 for i in range(0,h.numBins) : if(h.bins[i].xMin >= q2low and h.bins[i].xMin < q2high ) : desthisto.bins[i] += h.bins[i] q2high=q2 def merge(hpath): global inhistos global outhistos try: fillAbove(outhistos[hpath], inhistos[hpath]) except: pass def useOne(hpath, q2): global inhistos global outhistos try: outhistos[hpath] = inhistos[hpath][float(q2)] except: pass if __name__ == "__main__": import logging from optparse import OptionParser, OptionGroup parser = OptionParser(usage="%prog name") verbgroup = OptionGroup(parser, "Verbosity control") verbgroup.add_option("-v", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL", default=logging.INFO, help="print debug (very verbose) messages") verbgroup.add_option("-q", "--quiet", action="store_const", const=logging.WARNING, dest="LOGLEVEL", default=logging.INFO, help="be very quiet") parser.add_option_group(verbgroup) (opts, args) = parser.parse_args() logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s") ## Check args if len(args) < 1: logging.error("Must specify at least the name of the files") sys.exit(1) # ####################################### yodafiles=["-e--LowQ2","-e+-LowQ2","-e+-HighQ2"] ## Get histos inhistos = {} outhistos={} weights = {} for f in yodafiles: file = "Rivet-%s%s.yoda" % (args[0], f) if(file.find("Low")> 0) : q2=0 elif(file.find("High")>0) : q2=50 if not os.access(file, os.R_OK): logging.error("%s can not be read" % file) - break + continue try: aos = yoda.read(file) except: logging.error("%s can not be parsed as YODA" % file) - break + continue ## Get histos from this YODA file for aopath, ao in aos.iteritems() : if("RAW" in aopath) :continue if(aopath.find("4129130")>0 ) : if not inhistos.has_key(aopath): inhistos[aopath] = {} tmpE = inhistos[aopath] if not tmpE.has_key(q2): tmpE[q2] = ao else: raise Exception("A set with q2 = %s already exists" % ( q2 )) elif(aopath.find("2919893")>0 ) : outhistos[aopath] = ao elif(aopath.find("_XSEC")>=0 or aopath.find("_EVTCOUNT")>=0) : continue else : logging.error("Analysis %s is unknown" % aopath) sys.exit(1) ## Make empty output histos if needed for hpath,hsets in inhistos.iteritems(): if( hpath.find("4129130")>0 and (hpath.find("d33")>0 or hpath.find("d34")>0)) : if(type(hsets.values()[0])==yoda.core.Scatter2D) : outhistos[hpath] = yoda.core.Scatter2D(hsets.values()[0].path,hsets.values()[0].title) elif(type(hsets.values()[0])==yoda.core.Profile1D) : outhistos[hpath] = yoda.core.Profile1D(hsets.values()[0].path,hsets.values()[0].title) for i in range(0,hsets.values()[0].numBins) : outhistos[hpath].addBin(hsets.values()[0].bins[i].xMin,hsets.values()[0].bins[i].xMax) else : logging.error("Histogram %s is of unknown type" % hpath) sys.exit(1) # H1 transverse energy useOne("/H1_2000_S4129130/d01-x01-y01","0") useOne("/H1_2000_S4129130/d02-x01-y01","0") useOne("/H1_2000_S4129130/d03-x01-y01","0") useOne("/H1_2000_S4129130/d04-x01-y01","0") useOne("/H1_2000_S4129130/d05-x01-y01","0") useOne("/H1_2000_S4129130/d06-x01-y01","0") useOne("/H1_2000_S4129130/d07-x01-y01","0") useOne("/H1_2000_S4129130/d08-x01-y01","0") useOne("/H1_2000_S4129130/d09-x01-y01","0") useOne("/H1_2000_S4129130/d10-x01-y01","0") useOne("/H1_2000_S4129130/d11-x01-y01","0") useOne("/H1_2000_S4129130/d12-x01-y01","0") useOne("/H1_2000_S4129130/d13-x01-y01","0") useOne("/H1_2000_S4129130/d14-x01-y01","0") useOne("/H1_2000_S4129130/d15-x01-y01","0") useOne("/H1_2000_S4129130/d16-x01-y01","50") useOne("/H1_2000_S4129130/d17-x01-y01","50") useOne("/H1_2000_S4129130/d18-x01-y01","50") useOne("/H1_2000_S4129130/d19-x01-y01","50") useOne("/H1_2000_S4129130/d20-x01-y01","50") useOne("/H1_2000_S4129130/d21-x01-y01","50") useOne("/H1_2000_S4129130/d22-x01-y01","50") useOne("/H1_2000_S4129130/d23-x01-y01","50") useOne("/H1_2000_S4129130/d24-x01-y01","50") useOne("/H1_2000_S4129130/d25-x01-y01","0") useOne("/H1_2000_S4129130/d26-x01-y01","0") useOne("/H1_2000_S4129130/d27-x01-y01","0") useOne("/H1_2000_S4129130/d28-x01-y01","0") useOne("/H1_2000_S4129130/d29-x01-y01","50") useOne("/H1_2000_S4129130/d30-x01-y01","50") useOne("/H1_2000_S4129130/d31-x01-y01","50") useOne("/H1_2000_S4129130/d32-x01-y01","50") merge("/H1_2000_S4129130/d33-x01-y01") merge("/H1_2000_S4129130/d34-x01-y01") # Choose output file name = args[0]+".yoda" # output the yoda file yoda.writeYODA(outhistos,name) sys.exit(0) diff --git a/Tests/python/merge-LHC-EW b/Tests/python/merge-LHC-EW --- a/Tests/python/merge-LHC-EW +++ b/Tests/python/merge-LHC-EW @@ -1,402 +1,402 @@ #! /usr/bin/env python import logging import sys import os, yoda """%prog Script for merging aida files """ def fillAbove(scale,desthisto, sourcehistosbyptmin) : pthigh= 1e100 ptlow =-1e100 for pt, h in sorted(sourcehistosbyptmin.iteritems(),reverse=True): ptlow=pt if(type(desthisto)==yoda.core.Scatter2D) : for i in range(0,h.numPoints) : xMin = h.points[i].x-h.points[i].xErrs.minus if( xMin*scale >= ptlow and xMin*scale < pthigh ) : desthisto.addPoint(h.points[i]) elif(type(desthisto)==yoda.core.Profile1D) : for i in range(0,h.numBins) : if(h.bins[i].xMin*scale >= ptlow and h.bins[i].xMin*scale < pthigh ) : desthisto.bins[i] += h.bins[i] elif(type(desthisto)==yoda.core.Histo1D) : for i in range(0,h.numBins) : if(h.bins[i].xMin*scale >= ptlow and h.bins[i].xMin*scale < pthigh ) : desthisto.bins[i] += h.bins[i] else : logging.error("Can't merge %s, unknown type" % desthisto.path) sys.exit(1) pthigh=pt def mergeByMass(hpath, sqrts, scale=1.): global inhistos_mass global outhistos try: fillAbove(scale,outhistos[hpath], inhistos_mass[hpath][float(sqrts)]) except: pass def useOneMass(hpath, sqrts, ptmin): global inhistos_mass global outhistos try: ## Find best pT_min match ptmins = inhistos_mass[hpath][float(sqrts)].keys() closest_ptmin = None for ptm in ptmins: if closest_ptmin is None or \ abs(ptm-float(ptmin)) < abs(closest_ptmin-float(ptmin)): closest_ptmin = ptm if closest_ptmin != float(ptmin): logging.warning("Inexact match for requested pTmin=%s: " % ptmin + \ "using pTmin=%e instead" % closest_ptmin) outhistos[hpath] = inhistos_mass[hpath][float(sqrts)][closest_ptmin] except: pass import sys if sys.version_info[:3] < (2,4,0): print "rivet scripts require Python version >= 2.4.0... exiting" sys.exit(1) if __name__ == "__main__": import logging from optparse import OptionParser, OptionGroup parser = OptionParser(usage="%prog base") verbgroup = OptionGroup(parser, "Verbosity control") verbgroup.add_option("-v", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL", default=logging.INFO, help="print debug (very verbose) messages") verbgroup.add_option("-q", "--quiet", action="store_const", const=logging.WARNING, dest="LOGLEVEL", default=logging.INFO, help="be very quiet") parser.add_option_group(verbgroup) (opts, args) = parser.parse_args() logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s") ## Check args if len(args) < 1: logging.error("Must specify at least the name of the files") sys.exit(1) yodafiles=["-13-Z-e","-13-Z-mu","-Z-HighMass1-e","-Z-HighMass2-e", "-8-Z-Mass1-e","-8-Z-Mass1-mu","-8-Z-Mass2-e","-8-Z-Mass2-mu","-8-Z-Mass3-e","-8-Z-Mass3-mu","-8-Z-Mass4-e","-8-Z-Mass4-mu", "-W-e","-W-mu","-Z-e","-Z-mu","-Z-mu-Short","-Z-LowMass-e","-Z-LowMass-mu", "-Z-MedMass-e","-W-Z-e","-W-Z-mu", "-WW-emu","-WW-ll","-WZ","-ZZ-ll","-ZZ-lv","-8-WZ","-13-WZ","-8-ZZ-lv","-8-WW-ll", "-7-W-Jet-1-e","-7-W-Jet-2-e","-7-W-Jet-3-e","-7-Z-Jet-1-e","-7-Z-Jet-2-e","-7-Z-Jet-3-e", "-7-WGamma-e","-7-WGamma-mu","-7-ZGamma-e","-7-ZGamma-mu"] ## Get histos outhistos={} inhistos_mass = {} for f in yodafiles: file='Rivet-'+args[0]+f+".yoda" if not os.access(file, os.R_OK): logging.error("%s can not be read" % file) - break + continue try: aos = yoda.read(file) except: logging.error("%s can not be parsed as yoda" % file) - break + continue mass=66 if(file.find("HighMass1")>=0) : mass = 116 elif(file.find("HighMass2")>=0) : mass = 400 elif(file.find("Mass1")>=0) : mass = 12 elif(file.find("Mass2")>=0) : mass = 30 elif(file.find("Mass3")>=0) : mass = 66 elif(file.find("Mass4")>=0) : mass = 116 ## Get histos from this YODA file for aopath, ao in aos.iteritems() : if("RAW" in aopath) :continue if(aopath.find("ATLAS_2010_S8919674")>0) : if((aopath.find("d01")>0 or aopath.find("d05")>0 or aopath.find("d07")>0) and file.find("-e")>0) : outhistos[aopath] = ao elif((aopath.find("d02")>0 or aopath.find("d06")>0 or aopath.find("d08")>0) and file.find("-mu")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2011_S9131140")>0) : if(aopath.find("d01")>0 and file.find("-e")>0) : outhistos[aopath] = ao elif(aopath.find("d02")>0 and file.find("-mu")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2011_I925932")>0) : if(aopath.find("d01")>0 and file.find("-e")>0) : outhistos[aopath] = ao elif(aopath.find("d02")>0 and file.find("-mu")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2011_I945498")>0) : if(aopath.find("y01")>0 and file.find("-e")>0) : outhistos[aopath] = ao elif(aopath.find("y02")>0 and file.find("-mu")>0) : outhistos[aopath] = ao elif(aopath.find("y03")>0 and file.find("-mu")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2013_I1217867")>0) : if(aopath.find("y01")>0 and file.find("-e")>0) : outhistos[aopath] = ao elif(aopath.find("y02")>0 and file.find("-mu")>0) : outhistos[aopath] = ao elif (aopath.find("CMS_2012_I941555")>0) : if((aopath.find("y01")>0 or aopath.find("y03")>0 ) and file.find("-mu")>0) : outhistos[aopath] = ao elif(aopath.find("y02")>0 and file.find("-e")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2014_I1300647" )>0) : if(aopath.find("y01")>0 and file.find("-e")>0) : outhistos[aopath] = ao elif((not aopath.find("y01")>0) and file.find("-mu")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2014_I1288706" )>0) : if(aopath.find("y02")>0 and file.find("-e")>0) : outhistos[aopath] = ao elif(aopath.find("y01")>0 and file.find("-mu")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2012_I1204784" )>0) : if( file.find("-e")>0 and ( aopath.find("d03")>0 or ((aopath.find("d01")>0 or aopath.find("d02")>0) and aopath.find("y01")>0))) : outhistos[aopath] = ao elif(file.find("-mu")>0 and ( aopath.find("d04")>0 or ((aopath.find("d01")>0 or aopath.find("d02")>0) and aopath.find("y02")>0))) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2014_I1312627_EL") >0) : if(file.find("-e")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2014_I1312627_MU") >0) : if(file.find("-mu")>0) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2014_I1312627") >0) : if(file.find("-e")>0) : outhistos[aopath] = ao elif (aopath.find("CMS_2013_I1224539_WJET" )>0) : if(file.find("-1-e")>0 and (aopath.find("d52")>0 or aopath.find("d53")>0 or aopath.find("d56")>0 or aopath.find("d57")>0 or aopath.find("d60")>0 or aopath.find("d61")>0 or aopath.find("d64")>0 or aopath.find("d65")>0 or aopath.find("d68")>0 or aopath.find("d69")>0 or aopath.find("d72")>0)) : outhistos[aopath] = ao elif(file.find("-2-e")>0 and (aopath.find("d54")>0 or aopath.find("d58")>0 or aopath.find("d62")>0 or aopath.find("d66")>0 or aopath.find("d70")>0 or aopath.find("d73")>0)) : outhistos[aopath] = ao elif(file.find("-3-e")>0 and (aopath.find("d55")>0 or aopath.find("d59")>0 or aopath.find("d63")>0 or aopath.find("d67")>0 or aopath.find("d71")>0 or aopath.find("d74")>0)) : outhistos[aopath] = ao elif (aopath.find("CMS_2013_I1224539_ZJET" )>0) : if(file.find("-1-e")>0 and (aopath.find("d29")>0 or aopath.find("d30")>0 or aopath.find("d33")>0 or aopath.find("d34")>0 or aopath.find("d37")>0 or aopath.find("d38")>0 or aopath.find("d41")>0 or aopath.find("d42")>0 or aopath.find("d45")>0 or aopath.find("d46")>0 or aopath.find("d49")>0)) : outhistos[aopath] = ao elif(file.find("-2-e")>0 and (aopath.find("d31")>0 or aopath.find("d35")>0 or aopath.find("d39")>0 or aopath.find("d43")>0 or aopath.find("d47")>0 or aopath.find("d50")>0)) : outhistos[aopath] = ao elif(file.find("-3-e")>0 and (aopath.find("d32")>0 or aopath.find("d36")>0 or aopath.find("d40")>0 or aopath.find("d44")>0 or aopath.find("d48")>0 or aopath.find("d51")>0)) : outhistos[aopath] = ao elif (aopath.find("CMS_2013_I1258128")>0) : if(aopath.find("d01")>0 or aopath.find("d02")>0 or aopath.find("d03")>0 or aopath.find("d04")>0) : outhistos[aopath] = ao elif (aopath.find("CMS_2013_I1209721" )>0 and file.find("-0")>0 ) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2011_I928289")>0) : if(file.find("-e")>=0 and (aopath.find("y01")>=0 or aopath.find("y02")>=0)) : outhistos[aopath] = ao elif(file.find("-mu")>=0 and (aopath.find("y03")>=0 or aopath.find("y04")>=0)) : outhistos[aopath] = ao elif (aopath.find("CMS_2013_I1122847")>0) : if(file.find("-mu")>=0 and aopath.find("d01")>=0 ) : outhistos[aopath] = ao elif(file.find("-e")>=0 and (aopath.find("d02")>=0 or aopath.find("d03")>=0)) : outhistos[aopath] = ao elif (aopath.find("ATLAS_2016_I1424838")>0) : if(file.find("-mu")>=0 and aopath.find("x02")>=0 ) : outhistos[aopath] = ao elif(file.find("-e")>=0 and (aopath.find("x01")>=0)) : outhistos[aopath] = ao elif (aopath.find("CMS_2015_I1310737")>0) : if aopath in outhistos : outhistos[aopath] += ao else : outhistos[aopath] = ao elif (aopath.find("ATLAS_2015_I1351916")>=0) : if(aopath.find("-y01")>=0) : pathBase = aopath.replace("-y01","") hp = aos[pathBase+"-y02"] hm = aos[pathBase+"-y03"] ratio = (hp-hm)/(hp+hm) hnew = yoda.Scatter2D(aopath,ao.title) hnew.combineWith(ratio) outhistos[aopath] = hnew else : continue elif (aopath.find("ATLAS_2014_I1282447")>=0) : if((aopath.find("/ATLAS_2014_I1282447/d02-x01-y01")>=0 or aopath.find("/ATLAS_2014_I1282447/d08-x01-y01")>=0 or aopath.find("/ATLAS_2014_I1282447/d02-x01-y02")>=0 or aopath.find("/ATLAS_2014_I1282447/d02-x01-y01")>=0 or aopath.find("/ATLAS_2014_I1282447/d05-x01-y02")>=0 or aopath.find("/ATLAS_2014_I1282447/d05-x01-y03")>=0 or aopath.find("/ATLAS_2014_I1282447/d06-x01-y01")>=0 or aopath.find("/ATLAS_2014_I1282447/d06-x01-y02")>=0 or aopath.find("/ATLAS_2014_I1282447/d06-x01-y03")>=0 or aopath.find("/ATLAS_2014_I1282447/d06-x01-y04")>=0) and not (aopath.find("plus")>=0 or aopath.find("minus")>=0 or aopath.find("inc")>=0)) : continue if aopath in outhistos : outhistos[aopath] += ao else : outhistos[aopath] = ao elif (aopath.find("ATLAS_2015_I1408516")>=0) : if not inhistos_mass.has_key(aopath): inhistos_mass[aopath] = {} tmpE = inhistos_mass[aopath] sqrts=8000 if not tmpE.has_key(sqrts): tmpE[sqrts] = {} tmpP = tmpE[sqrts] if not tmpP.has_key(mass): tmpP[mass] = ao else: raise Exception("A set with mass = %s already exists" % ( mass)) elif (aopath.find("ATLAS_2013_I1234228")>=0) : if not inhistos_mass.has_key(aopath): inhistos_mass[aopath] = {} tmpE = inhistos_mass[aopath] sqrts=7000 if not tmpE.has_key(sqrts): tmpE[sqrts] = {} tmpP = tmpE[sqrts] if not tmpP.has_key(mass): tmpP[mass] = ao else: raise Exception("A set with mass = %s already exists" % ( mass)) else : outhistos[aopath] = ao for hpath,hsets in inhistos_mass.iteritems(): if(hpath!="/ATLAS_2015_I1408516_EL/d41-x01-y01" and hpath!="/ATLAS_2015_I1408516_MU/d41-x01-y02" and hpath!="/ATLAS_2013_I1234228/d01-x01-y02" ) : continue if(type(hsets.values()[0].values()[0])==yoda.core.Scatter2D) : outhistos[hpath] = yoda.core.Scatter2D(hsets.values()[0].values()[0].path, hsets.values()[0].values()[0].title) elif(type(hsets.values()[0].values()[0])==yoda.core.Profile1D) : outhistos[hpath] = yoda.core.Profile1D(hsets.values()[0].values()[0].path, hsets.values()[0].values()[0].title) for i in range(0,hsets.values()[0].values()[0].numBins) : outhistos[hpath].addBin(hsets.values()[0].values()[0].bins[i].xMin, hsets.values()[0].values()[0].bins[i].xMax) elif(type(hsets.values()[0].values()[0])==yoda.core.Histo1D) : outhistos[hpath] = yoda.core.Histo1D(hsets.values()[0].values()[0].path, hsets.values()[0].values()[0].title) for i in range(0,hsets.values()[0].values()[0].numBins) : outhistos[hpath].addBin(hsets.values()[0].values()[0].bins[i].xMin, hsets.values()[0].values()[0].bins[i].xMax) else : logging.error("Histogram %s is of unknown type" % hpath) sys.exit(1) # sort out mass bins for ATLAS Z-> e,mu at 8 TeV for ltype in ["EL","MU"] : if(ltype=="EL") : y = "y01" mergeByMass("/ATLAS_2015_I1408516_EL/d41-x01-y01", "8000") else : y = "y04" mergeByMass("/ATLAS_2015_I1408516_MU/d41-x01-y02", "8000") for d in [2,3,04,14,26,38]: useOneMass("/ATLAS_2015_I1408516_%s/d%02d-x01-%s" % (ltype,d,y), "8000", "30" ) for d in [5,6,7,8,9,10,15,17,18,19,20,21,22,27,29,30,31,32,33,34,39]: useOneMass("/ATLAS_2015_I1408516_%s/d%02d-x01-%s" % (ltype,d,y), "8000", "66" ) for d in [11,12,13,16,28,40]: useOneMass("/ATLAS_2015_I1408516_%s/d%02d-x01-%s" % (ltype,d,y), "8000", "116" ) for d in [23,35]: useOneMass("/ATLAS_2015_I1408516_%s/d%02d-x01-%s" % (ltype,d,y), "8000", "12" ) for d in [24,36]: useOneMass("/ATLAS_2015_I1408516_%s/d%02d-x01-%s" % (ltype,d,y), "8000", "12" ) for d in [25,37]: useOneMass("/ATLAS_2015_I1408516_%s/d%02d-x01-%s" % (ltype,d,y), "8000", "30" ) # sort out ratios for ATLAS W+c if("/ATLAS_2014_I1282447/d02-x01-y01_plus" in outhistos and "/ATLAS_2014_I1282447/d02-x01-y01_minus" in outhistos) : d02y01_plus = outhistos["/ATLAS_2014_I1282447/d02-x01-y01_plus"] d02y01_minus = outhistos["/ATLAS_2014_I1282447/d02-x01-y01_minus"] ratio_d02y01 = d02y01_plus/d02y01_minus ratio_d02y01.path = "/ATLAS_2014_I1282447/d02-x01-y01" del outhistos["/ATLAS_2014_I1282447/d02-x01-y01_plus"] del outhistos["/ATLAS_2014_I1282447/d02-x01-y01_minus"] outhistos["/ATLAS_2014_I1282447/d02-x01-y01"] = ratio_d02y01 if("/ATLAS_2014_I1282447/d02-x01-y02_plus" in outhistos and "/ATLAS_2014_I1282447/d02-x01-y02_minus" in outhistos) : d02y02_plus = outhistos["/ATLAS_2014_I1282447/d02-x01-y02_plus"] d02y02_minus = outhistos["/ATLAS_2014_I1282447/d02-x01-y02_minus"] ratio_d02y02 = d02y02_plus/d02y02_minus ratio_d02y02.path = "/ATLAS_2014_I1282447/d02-x01-y02" del outhistos["/ATLAS_2014_I1282447/d02-x01-y02_plus"] del outhistos["/ATLAS_2014_I1282447/d02-x01-y02_minus"] outhistos["/ATLAS_2014_I1282447/d02-x01-y02"] = ratio_d02y02 if("/ATLAS_2014_I1282447/d08-x01-y01_plus" in outhistos and "/ATLAS_2014_I1282447/d08-x01-y01_minus" in outhistos) : d08y01_plus = outhistos["/ATLAS_2014_I1282447/d08-x01-y01_plus"] d08y01_minus = outhistos["/ATLAS_2014_I1282447/d08-x01-y01_minus"] ratio_d08y01 = d08y01_plus/d08y01_minus ratio_d08y01.path = "/ATLAS_2014_I1282447/d08-x01-y01" del outhistos["/ATLAS_2014_I1282447/d08-x01-y01_plus"] del outhistos["/ATLAS_2014_I1282447/d08-x01-y01_minus"] outhistos["/ATLAS_2014_I1282447/d08-x01-y01"] = ratio_d08y01 if ("/ATLAS_2014_I1282447/d05-x01-y01" in outhistos and "/ATLAS_2014_I1282447/d01-x01-y02" in outhistos) : h_winc = outhistos["/ATLAS_2014_I1282447/d05-x01-y01"] h_d = outhistos["/ATLAS_2014_I1282447/d01-x01-y02"] ratio_wd = h_d/h_winc ratio_wd.path = "/ATLAS_2014_I1282447/d05-x01-y02" outhistos["/ATLAS_2014_I1282447/d05-x01-y02"] = ratio_wd if ("/ATLAS_2014_I1282447/d05-x01-y01" in outhistos and "/ATLAS_2014_I1282447/d01-x01-y03" in outhistos) : h_winc = outhistos["/ATLAS_2014_I1282447/d05-x01-y01"] h_dstar= outhistos["/ATLAS_2014_I1282447/d01-x01-y03"] ratio_wdstar = h_dstar/h_winc ratio_wdstar.path = "/ATLAS_2014_I1282447/d05-x01-y03" outhistos["/ATLAS_2014_I1282447/d05-x01-y03"] = ratio_wdstar if("/ATLAS_2014_I1282447/d06-x01-y01_winc" in outhistos and "/ATLAS_2014_I1282447/d06-x01-y02_winc" in outhistos) : h_winc_plus = outhistos["/ATLAS_2014_I1282447/d06-x01-y01_winc"] h_winc_minus = outhistos["/ATLAS_2014_I1282447/d06-x01-y02_winc"] if( "/ATLAS_2014_I1282447/d06-x01-y01_wplus" in outhistos ) : h_wd_plus = outhistos["/ATLAS_2014_I1282447/d06-x01-y01_wplus"] ratio_wd_plus = h_wd_plus/h_winc_plus ratio_wd_plus.path = "/ATLAS_2014_I1282447/d06-x01-y01" outhistos["/ATLAS_2014_I1282447/d06-x01-y01"] = ratio_wd_plus del outhistos["/ATLAS_2014_I1282447/d06-x01-y01_wplus"] if( "/ATLAS_2014_I1282447/d06-x01-y02_wminus" in outhistos ) : h_wd_minus = outhistos["/ATLAS_2014_I1282447/d06-x01-y02_wminus"] ratio_wd_minus = h_wd_minus/h_winc_minus ratio_wd_minus.path = "/ATLAS_2014_I1282447/d06-x01-y02" outhistos["/ATLAS_2014_I1282447/d06-x01-y02"] = ratio_wd_minus del outhistos["/ATLAS_2014_I1282447/d06-x01-y02_wminus"] if ( "/ATLAS_2014_I1282447/d06-x01-y03_wplus" in outhistos) : h_wdstar_plus = outhistos["/ATLAS_2014_I1282447/d06-x01-y03_wplus"] ratio_wdstar_plus = h_wdstar_plus/h_winc_plus ratio_wdstar_plus.path = "/ATLAS_2014_I1282447/d06-x01-y03" outhistos["/ATLAS_2014_I1282447/d06-x01-y03"] = ratio_wdstar_plus del outhistos["/ATLAS_2014_I1282447/d06-x01-y03_wplus"] if ( "/ATLAS_2014_I1282447/d06-x01-y04_wminus" in outhistos) : h_wdstar_minus = outhistos["/ATLAS_2014_I1282447/d06-x01-y04_wminus"] ratio_wdstar_minus = h_wdstar_minus/h_winc_minus ratio_wdstar_minus.path = "/ATLAS_2014_I1282447/d06-x01-y04" outhistos["/ATLAS_2014_I1282447/d06-x01-y04"] = ratio_wdstar_minus del outhistos["/ATLAS_2014_I1282447/d06-x01-y04_wminus"] del outhistos["/ATLAS_2014_I1282447/d06-x01-y01_winc"] del outhistos["/ATLAS_2014_I1282447/d06-x01-y02_winc"] mergeByMass("/ATLAS_2013_I1234228/d01-x01-y02", "7000") # Choose output file name = args[0]+"-EW.yoda" yoda.writeYODA(outhistos,name) sys.exit(0) diff --git a/Tests/python/merge-LHC-Photon b/Tests/python/merge-LHC-Photon --- a/Tests/python/merge-LHC-Photon +++ b/Tests/python/merge-LHC-Photon @@ -1,298 +1,298 @@ #! /usr/bin/env python import logging import sys import os, yoda """%prog Script for merging aida files """ def fillAbove(scale,desthisto, sourcehistosbyptmin): pthigh= 1e100 ptlow =-1e100 for pt, h in sorted(sourcehistosbyptmin.iteritems(),reverse=True): ptlow=pt if(type(desthisto)==yoda.core.Scatter2D) : for i in range(0,h.numPoints) : xMin = h.points[i].x-h.points[i].xErrs.minus if( xMin*scale >= ptlow and xMin*scale < pthigh ) : desthisto.addPoint(h.points[i]) elif(type(desthisto)==yoda.core.Profile1D) : for i in range(0,h.numBins) : if(h.bins[i].xMin*scale >= ptlow and h.bins[i].xMin*scale < pthigh ) : desthisto.bins[i] += h.bins[i] elif(type(desthisto)==yoda.core.Histo1D) : for i in range(0,h.numBins) : if(h.bins[i].xMin*scale >= ptlow and h.bins[i].xMin*scale < pthigh ) : desthisto.bins[i] += h.bins[i] else : logging.error("Can't merge %s, unknown type" % desthisto.path) sys.exit(1) pthigh=pt def mergeByPt(hpath, scale=1.): global inhistos global outhistos try: fillAbove(scale,outhistos[hpath], inhistos[hpath]) except: pass def useOnePt(hpath, ptmin): global inhistos global outhistos try: ## Find best pT_min match ptmins = inhistos[hpath].keys() closest_ptmin = None for ptm in ptmins: if closest_ptmin is None or \ abs(ptm-float(ptmin)) < abs(closest_ptmin-float(ptmin)): closest_ptmin = ptm if closest_ptmin != float(ptmin): logging.warning("Inexact match for requested pTmin=%s: " % ptmin + \ "using pTmin=%e instead" % closest_ptmin) outhistos[hpath] = inhistos[hpath][closest_ptmin] except: pass if sys.version_info[:3] < (2,4,0): print "rivet scripts require Python version >= 2.4.0... exiting" sys.exit(1) if __name__ == "__main__": import logging from optparse import OptionParser, OptionGroup parser = OptionParser(usage="%prog base") verbgroup = OptionGroup(parser, "Verbosity control") verbgroup.add_option("-v", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL", default=logging.INFO, help="print debug (very verbose) messages") verbgroup.add_option("-q", "--quiet", action="store_const", const=logging.WARNING, dest="LOGLEVEL", default=logging.INFO, help="be very quiet") parser.add_option_group(verbgroup) (opts, args) = parser.parse_args() logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s") ## Check args if len(args) < 1: logging.error("Must specify at least the name of the files") sys.exit(1) files=["-7-DiPhoton-GammaGamma.yoda","-7-DiPhoton-GammaJet.yoda","-GammaGamma-7.yoda", "-8-DiPhoton-GammaGamma.yoda","-8-DiPhoton-GammaJet.yoda","-GammaGamma-8.yoda"] for i in [7,8,13] : for j in range(1,5) : files.append("-%s-PromptPhoton-%s.yoda" % (i,j)) ## Get histos inhistos = {} outhistos={} for f in files: file='Rivet-'+args[0]+f if not os.access(file, os.R_OK): logging.error("%s can not be read" % file) continue try: aos = yoda.read(file) except: logging.error("%s can not be parsed as XML" % file) - break + continue if(file.find("PromptPhoton")>=0) : if(file.find("PromptPhoton-1")>0) : ptmin=0. elif(file.find("PromptPhoton-2")>0) : ptmin=35. elif(file.find("PromptPhoton-3")>0) : ptmin=90. elif(file.find("PromptPhoton-4")>0) : ptmin=170. ## Get histos from this YODA file for aopath, ao in aos.iteritems() : if("RAW" in aopath) :continue if not inhistos.has_key(aopath): inhistos[aopath] = {} if (aopath.find("CMS_2013_I1258128")>0) : if(aopath.find("d05")>0 or aopath.find("d06")>0 or aopath.find("d07")>0 or aopath.find("d08")>0) : inhistos[aopath][ptmin] = ao else : inhistos[aopath][ptmin] = ao else : ## Get histos from this YODA file for aopath, ao in aos.iteritems() : if("RAW" in aopath) :continue if(aopath.find("XSEC")>=0 or aopath.find("EVTCOUNT")>=0) : continue if ( aopath in outhistos ) : aotype = type(ao) if aotype in (yoda.Counter, yoda.Histo1D, yoda.Histo2D, yoda.Profile1D, yoda.Profile2D): outhistos[aopath] += ao else : quit() else: outhistos[aopath] = ao for hpath,hsets in inhistos.iteritems(): if( hpath.find("1263495")>0 or hpath.find("1093738")>0 or hpath.find("921594" )>0 or hpath.find("8914702")>0 or hpath.find("1244522")>0 or hpath.find("1457605")>0 or hpath.find("1632756")>0 or hpath.find("1266056")>0 or hpath.find("1645627")>0) : if(type(hsets.values()[0])==yoda.core.Scatter2D) : outhistos[hpath] = yoda.core.Scatter2D(hsets.values()[0].path, hsets.values()[0].title) elif(type(hsets.values()[0])==yoda.core.Profile1D) : outhistos[hpath] = yoda.core.Profile1D(hsets.values()[0].path, hsets.values()[0].title) for i in range(0,hsets.values()[0].numBins) : outhistos[hpath].addBin(hsets.values()[0].bins[i].xMin, hsets.values()[0].bins[i].xMax) elif(type(hsets.values()[0])==yoda.core.Histo1D) : outhistos[hpath] = yoda.core.Histo1D(hsets.values()[0].path, hsets.values()[0].title) for i in range(0,hsets.values()[0].numBins) : outhistos[hpath].addBin(hsets.values()[0].bins[i].xMin, hsets.values()[0].bins[i].xMax) else : logging.error("Histogram %s is of unknown type" % hpath) print hpath,type(hsets.values()[0]) sys.exit(1) logging.info("Processing ATLAS_2013_I1263495") mergeByPt("/ATLAS_2013_I1263495/d01-x01-y01") mergeByPt("/ATLAS_2013_I1263495/d02-x01-y01") useOnePt("/ATLAS_2013_I1263495/d03-x01-y01", "90" ) logging.info("Processing ATLAS_2012_I1093738") mergeByPt("/ATLAS_2012_I1093738/d01-x01-y01") mergeByPt("/ATLAS_2012_I1093738/d02-x01-y01") mergeByPt("/ATLAS_2012_I1093738/d03-x01-y01") mergeByPt("/ATLAS_2012_I1093738/d04-x01-y01") mergeByPt("/ATLAS_2012_I1093738/d05-x01-y01") mergeByPt("/ATLAS_2012_I1093738/d06-x01-y01") logging.info("Processing ATLAS_2011_I921594") mergeByPt("/ATLAS_2011_I921594/d01-x01-y01") mergeByPt("/ATLAS_2011_I921594/d01-x01-y02") mergeByPt("/ATLAS_2011_I921594/d01-x01-y04") mergeByPt("/ATLAS_2011_I921594/d01-x01-y05") logging.info("Processing ATLAS_2010_S8914702") mergeByPt("/ATLAS_2010_S8914702/d01-x01-y01") mergeByPt("/ATLAS_2010_S8914702/d01-x01-y02") mergeByPt("/ATLAS_2010_S8914702/d01-x01-y03") logging.info("Processing CMS_2013_I1258128") useOnePt("/CMS_2013_I1258128/d05-x01-y01", "35" ) useOnePt("/CMS_2013_I1258128/d06-x01-y01", "35" ) useOnePt("/CMS_2013_I1258128/d07-x01-y01", "35" ) useOnePt("/CMS_2013_I1258128/d08-x01-y01", "35" ) logging.info("Processing ATLAS_2013_I1244522") mergeByPt("/ATLAS_2013_I1244522/d01-x01-y01") mergeByPt("/ATLAS_2013_I1244522/d02-x01-y01") useOnePt("/ATLAS_2013_I1244522/d03-x01-y01", "35" ) useOnePt("/ATLAS_2013_I1244522/d04-x01-y01", "35" ) useOnePt("/ATLAS_2013_I1244522/d05-x01-y01", "35" ) useOnePt("/ATLAS_2013_I1244522/d06-x01-y01", "35" ) useOnePt("/ATLAS_2013_I1244522/d07-x01-y01", "35" ) logging.info("Processing ATLAS_2016_I1457605") mergeByPt("/ATLAS_2016_I1457605/d01-x01-y01") mergeByPt("/ATLAS_2016_I1457605/d02-x01-y01") mergeByPt("/ATLAS_2016_I1457605/d03-x01-y01") mergeByPt("/ATLAS_2016_I1457605/d04-x01-y01") logging.info("Processing ATLAS_2017_I1632756") mergeByPt("/ATLAS_2017_I1632756/d02-x01-y01") mergeByPt("/ATLAS_2017_I1632756/d03-x01-y01") mergeByPt("/ATLAS_2017_I1632756/d04-x01-y01") mergeByPt("/ATLAS_2017_I1632756/d05-x01-y01") logging.info("Processing CMS_2014_I1266056") mergeByPt("/CMS_2014_I1266056/d01-x01-y01") mergeByPt("/CMS_2014_I1266056/d01-x01-y02") mergeByPt("/CMS_2014_I1266056/d02-x01-y01") mergeByPt("/CMS_2014_I1266056/d02-x01-y02") mergeByPt("/CMS_2014_I1266056/d03-x01-y01") mergeByPt("/CMS_2014_I1266056/d03-x01-y02") mergeByPt("/CMS_2014_I1266056/d04-x01-y01") mergeByPt("/CMS_2014_I1266056/d04-x01-y02") logging.info("Processing ATLAS_2017_I1645627") mergeByPt("/ATLAS_2017_I1645627/d01-x01-y01") mergeByPt("/ATLAS_2017_I1645627/d02-x01-y01") useOnePt("/ATLAS_2017_I1645627/d03-x01-y01","90") useOnePt("/ATLAS_2017_I1645627/d04-x01-y01","90") useOnePt("/ATLAS_2017_I1645627/d05-x01-y01","90") logging.info("Processing /MC_PHOTONJETS") useOnePt("/MC_PHOTONJETS/jet_HT","0") useOnePt("/MC_PHOTONJETS/jet_eta_1","0") useOnePt("/MC_PHOTONJETS/jet_eta_2","0") useOnePt("/MC_PHOTONJETS/jet_eta_3","0") useOnePt("/MC_PHOTONJETS/jet_eta_4","0") useOnePt("/MC_PHOTONJETS/jet_eta_pmratio_1","0") useOnePt("/MC_PHOTONJETS/jet_eta_pmratio_2","0") useOnePt("/MC_PHOTONJETS/jet_eta_pmratio_3","0") useOnePt("/MC_PHOTONJETS/jet_eta_pmratio_4","0") useOnePt("/MC_PHOTONJETS/jet_mass_1","0") useOnePt("/MC_PHOTONJETS/jet_mass_2","0") useOnePt("/MC_PHOTONJETS/jet_mass_3","0") useOnePt("/MC_PHOTONJETS/jet_mass_4","0") useOnePt("/MC_PHOTONJETS/jet_multi_exclusive","0") useOnePt("/MC_PHOTONJETS/jet_multi_inclusive","0") useOnePt("/MC_PHOTONJETS/jet_multi_ratio","0") useOnePt("/MC_PHOTONJETS/jet_pT_1","0") useOnePt("/MC_PHOTONJETS/jet_pT_2","0") useOnePt("/MC_PHOTONJETS/jet_pT_3","0") useOnePt("/MC_PHOTONJETS/jet_pT_4","0") useOnePt("/MC_PHOTONJETS/jet_y_1","0") useOnePt("/MC_PHOTONJETS/jet_y_2","0") useOnePt("/MC_PHOTONJETS/jet_y_3","0") useOnePt("/MC_PHOTONJETS/jet_y_4","0") useOnePt("/MC_PHOTONJETS/jet_y_pmratio_1","0") useOnePt("/MC_PHOTONJETS/jet_y_pmratio_2","0") useOnePt("/MC_PHOTONJETS/jet_y_pmratio_3","0") useOnePt("/MC_PHOTONJETS/jet_y_pmratio_4","0") useOnePt("/MC_PHOTONJETS/jets_dR_12","0") useOnePt("/MC_PHOTONJETS/jets_dR_13","0") useOnePt("/MC_PHOTONJETS/jets_dR_23","0") useOnePt("/MC_PHOTONJETS/jets_deta_12","0") useOnePt("/MC_PHOTONJETS/jets_deta_13","0") useOnePt("/MC_PHOTONJETS/jets_deta_23","0") useOnePt("/MC_PHOTONJETS/jets_dphi_12","0") useOnePt("/MC_PHOTONJETS/jets_dphi_13","0") useOnePt("/MC_PHOTONJETS/jets_dphi_23","0") useOnePt("/MC_PHOTONJETS/photon_jet1_dR","0") useOnePt("/MC_PHOTONJETS/photon_jet1_deta","0") useOnePt("/MC_PHOTONJETS/photon_jet1_dphi","0") useOnePt("/MC_PHOTONJETUE/gammajet-dR","0") useOnePt("/MC_PHOTONJETUE/gammajet-dphi","0") useOnePt("/MC_PHOTONJETUE/trans-maxnchg-gamma","0") useOnePt("/MC_PHOTONJETUE/trans-maxnchg-jet","0") useOnePt("/MC_PHOTONJETUE/trans-maxptsum-gamma","0") useOnePt("/MC_PHOTONJETUE/trans-maxptsum-jet","0") useOnePt("/MC_PHOTONJETUE/trans-minnchg-gamma","0") useOnePt("/MC_PHOTONJETUE/trans-minnchg-jet","0") useOnePt("/MC_PHOTONJETUE/trans-minptsum-gamma","0") useOnePt("/MC_PHOTONJETUE/trans-minptsum-jet","0") useOnePt("/MC_PHOTONJETUE/trans-nchg-gamma","0") useOnePt("/MC_PHOTONJETUE/trans-nchg-jet","0") useOnePt("/MC_PHOTONJETUE/trans-ptavg-gamma","0") useOnePt("/MC_PHOTONJETUE/trans-ptavg-jet","0") useOnePt("/MC_PHOTONJETUE/trans-ptsum-gamma","0") useOnePt("/MC_PHOTONJETUE/trans-ptsum-jet","0") # Choose output file name = args[0]+"-Photon.yoda" yoda.writeYODA(outhistos,name) sys.exit(0) diff --git a/Tests/python/merge-SppS b/Tests/python/merge-SppS --- a/Tests/python/merge-SppS +++ b/Tests/python/merge-SppS @@ -1,165 +1,165 @@ #! /usr/bin/env python # import lighthisto import logging import sys if sys.version_info[:3] < (2,4,0): print "rivet scripts require Python version >= 2.4.0... exiting" sys.exit(1) import os, yoda, copy # # ############################################# def useOne(hpath, sqrts): global inhistos global outhistos try: outhistos[hpath] = inhistos[hpath][float(sqrts)] except: pass if __name__ == "__main__": import logging from optparse import OptionParser, OptionGroup parser = OptionParser(usage="%prog name") verbgroup = OptionGroup(parser, "Verbosity control") verbgroup.add_option("-v", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL", default=logging.INFO, help="print debug (very verbose) messages") verbgroup.add_option("-q", "--quiet", action="store_const", const=logging.WARNING, dest="LOGLEVEL", default=logging.INFO, help="be very quiet") parser.add_option_group(verbgroup) (opts, args) = parser.parse_args() logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s") ## Check args if len(args) < 1: logging.error("Must specify at least the name of the files") sys.exit(1) ####################################### yodafiles=["ISR-44-UE.yoda","ISR-62-UE.yoda",args[0]+"-63-UE.yoda","ISR-30-UE.yoda", \ "ISR-53-UE.yoda",args[0]+"-200-UE.yoda",args[0]+"-500-UE.yoda",args[0]+"-900-UE.yoda", \ args[0]+"-546-UE.yoda",args[0]+"-53-UE.yoda"] ## Get histos inhistos = {} outhistos={} for file in yodafiles: file = 'Rivet-'+file if(file.find("44")>0) : sqrts=44 elif(file.find("63")>0) : sqrts=63 elif(file.find("30")>0) : sqrts=30 elif(file.find("53")>0) : sqrts=53 elif(file.find("200")>0) : sqrts=200 elif(file.find("500")>0) : sqrts=500 elif(file.find("900")>0) : sqrts=900 elif(file.find("546")>0) : sqrts=546 elif(file.find("53")>0) : sqrts=53 if not os.access(file, os.R_OK): logging.error("%s can not be read" % file) continue try: aos = yoda.read(file) except: logging.error("%s can not be parsed as yoda" % file) - break + continue ## Get histos from this YODA file for aopath, ao in aos.iteritems() : if("RAW" in aopath) :continue if(aopath.find("1926373")>0 or aopath.find("1867512")>0 or aopath.find("1583476")>0 or aopath.find("2044935")>0 or aopath.find("1178091")>0 ) : if not inhistos.has_key(aopath): inhistos[aopath] = {} if not inhistos[aopath].has_key(sqrts): inhistos[aopath][sqrts] = ao else: raise Exception("A set with sqrts = %s already exists" % ( sqrts)) else : outhistos[aopath] = ao # UA5_1989_S1926373 useOne("/UA5_1989_S1926373/d01-x01-y01","200") useOne("/UA5_1989_S1926373/d02-x01-y01","900") useOne("/UA5_1989_S1926373/d03-x01-y01","200") useOne("/UA5_1989_S1926373/d04-x01-y01","200") useOne("/UA5_1989_S1926373/d05-x01-y01","200") useOne("/UA5_1989_S1926373/d06-x01-y01","200") useOne("/UA5_1989_S1926373/d07-x01-y01","900") useOne("/UA5_1989_S1926373/d08-x01-y01","900") useOne("/UA5_1989_S1926373/d09-x01-y01","900") useOne("/UA5_1989_S1926373/d10-x01-y01","900") useOne("/UA5_1989_S1926373/d11-x01-y01","200") useOne("/UA5_1989_S1926373/d12-x01-y01","900") # UA5_1988_S1867512 useOne("/UA5_1988_S1867512/d02-x01-y01","200") useOne("/UA5_1988_S1867512/d02-x01-y02","546") useOne("/UA5_1988_S1867512/d02-x01-y03","900") useOne("/UA5_1988_S1867512/d03-x01-y01","200") useOne("/UA5_1988_S1867512/d03-x01-y02","546") useOne("/UA5_1988_S1867512/d03-x01-y03","900") # UA5_1986_S1583476 useOne("/UA5_1986_S1583476/d01-x01-y01","200") useOne("/UA5_1986_S1583476/d01-x01-y02","200") useOne("/UA5_1986_S1583476/d01-x01-y03","900") useOne("/UA5_1986_S1583476/d01-x01-y04","900") useOne("/UA5_1986_S1583476/d02-x01-y01","200") useOne("/UA5_1986_S1583476/d02-x01-y02","200") useOne("/UA5_1986_S1583476/d02-x01-y03","200") useOne("/UA5_1986_S1583476/d02-x01-y04","200") useOne("/UA5_1986_S1583476/d02-x01-y05","200") useOne("/UA5_1986_S1583476/d02-x01-y06","200") useOne("/UA5_1986_S1583476/d03-x01-y01","900") useOne("/UA5_1986_S1583476/d03-x01-y02","900") useOne("/UA5_1986_S1583476/d03-x01-y03","900") useOne("/UA5_1986_S1583476/d03-x01-y04","900") useOne("/UA5_1986_S1583476/d03-x01-y05","900") useOne("/UA5_1986_S1583476/d03-x01-y06","900") useOne("/UA5_1986_S1583476/d03-x01-y07","900") useOne("/UA5_1986_S1583476/d03-x01-y08","900") useOne("/UA5_1986_S1583476/d03-x01-y09","900") # UA1_1990_S2044935 useOne("/UA1_1990_S2044935/d01-x01-y01","200") useOne("/UA1_1990_S2044935/d01-x01-y02","500") useOne("/UA1_1990_S2044935/d01-x01-y03","900") useOne("/UA1_1990_S2044935/d02-x01-y01","200") useOne("/UA1_1990_S2044935/d02-x01-y02","500") useOne("/UA1_1990_S2044935/d02-x01-y03","900") useOne("/UA1_1990_S2044935/d03-x01-y01","900") useOne("/UA1_1990_S2044935/d04-x01-y01","900") useOne("/UA1_1990_S2044935/d05-x01-y01","900") useOne("/UA1_1990_S2044935/d06-x01-y01","200") useOne("/UA1_1990_S2044935/d07-x01-y01","900") useOne("/UA1_1990_S2044935/d08-x01-y01","63") useOne("/UA1_1990_S2044935/d09-x01-y01","200") useOne("/UA1_1990_S2044935/d10-x01-y01","500") useOne("/UA1_1990_S2044935/d11-x01-y01","900") useOne("/UA1_1990_S2044935/d12-x01-y01","200") useOne("/UA1_1990_S2044935/d12-x01-y02","500") useOne("/UA1_1990_S2044935/d12-x01-y03","900") # SFM_1984_S1178091 useOne("/SFM_1984_S1178091/d01-x01-y01","30") useOne("/SFM_1984_S1178091/d01-x01-y02","44") useOne("/SFM_1984_S1178091/d01-x01-y03","53") useOne("/SFM_1984_S1178091/d01-x01-y04","63") useOne("/SFM_1984_S1178091/d02-x01-y01","30") useOne("/SFM_1984_S1178091/d02-x01-y02","44") useOne("/SFM_1984_S1178091/d02-x01-y03","53") useOne("/SFM_1984_S1178091/d02-x01-y04","63") # Choose output file name = args[0]+".yoda" # output the yoda file yoda.writeYODA(outhistos,name) sys.exit(0) diff --git a/Tests/python/merge-Star b/Tests/python/merge-Star --- a/Tests/python/merge-Star +++ b/Tests/python/merge-Star @@ -1,168 +1,168 @@ #! /usr/bin/env python import logging import sys if sys.version_info[:3] < (2,4,0): print "rivet scripts require Python version >= 2.4.0... exiting" sys.exit(1) import os, yoda # ############################################# def fillAbove(desthisto, sourcehistosbyptmin): pthigh= 1e100 ptlow =-1e100 for pt, h in sorted(sourcehistosbyptmin.iteritems(),reverse=True): ptlow=pt if(type(desthisto)==yoda.core.Scatter2D) : for i in range(0,h.numPoints) : xMin = h.points[i].x-h.points[i].xErrs.minus if( xMin >= ptlow and xMin < pthigh ) : desthisto.addPoint(h.points[i]) elif(type(desthisto)==yoda.core.Profile1D) : for i in range(0,h.numBins) : if(h.bins[i].xMin >= ptlow and h.bins[i].xMin < pthigh ) : desthisto.bins[i] += h.bins[i] elif(type(desthisto)==yoda.core.Histo1D) : for i in range(0,h.numBins) : if(h.bins[i].xMin >= ptlow and h.bins[i].xMin < pthigh ) : desthisto.bins[i] += h.bins[i] else : logging.error("Can't merge %s, unknown type" % desthisto.path) sys.exit(1) pthigh=pt def mergeByPt(hpath, sqrts): global inhistos global outhistos try: fillAbove(outhistos[hpath], inhistos[hpath][float(sqrts)]) except: pass def useOnePt(hpath, sqrts, ptmin): global inhistos global outhistos try: ## Find best pT_min match ptmins = inhistos[hpath][float(sqrts)].keys() closest_ptmin = None for ptm in ptmins: if closest_ptmin is None or \ abs(ptm-float(ptmin)) < abs(closest_ptmin-float(ptmin)): closest_ptmin = ptm if closest_ptmin != float(ptmin): logging.warning("Inexact match for requested pTmin=%s: " % ptmin + \ "using pTmin=%e instead" % closest_ptmin) outhistos[hpath] = inhistos[hpath][float(sqrts)][closest_ptmin] except: pass # ####################################### if __name__ == "__main__": import logging from optparse import OptionParser, OptionGroup parser = OptionParser(usage="%prog name") verbgroup = OptionGroup(parser, "Verbosity control") verbgroup.add_option("-v", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL", default=logging.INFO, help="print debug (very verbose) messages") verbgroup.add_option("-q", "--quiet", action="store_const", const=logging.WARNING, dest="LOGLEVEL", default=logging.INFO, help="be very quiet") parser.add_option_group(verbgroup) (opts, args) = parser.parse_args() logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s") ## Check args if len(args) < 1: logging.error("Must specify at least the name of the files") sys.exit(1) yodafiles=["-UE.yoda","-Jets-1.yoda","-Jets-2.yoda","-Jets-3.yoda","-Jets-4.yoda"] ## Get histos inhistos = {} outhistos={} weights = {} for f in yodafiles: file='Rivet-'+args[0]+f if(file.find("-UE")>0) : sqrts=200 ptmin=0. elif(file.find("-Jets-1")>0) : sqrts=200 ptmin=2. elif(file.find("-Jets-2")>0) : sqrts=200 ptmin=5. elif(file.find("-Jets-3")>0) : sqrts=200 ptmin=26. elif(file.find("-Jets-4")>0) : sqrts=200 ptmin=15. if not os.access(file, os.R_OK): logging.error("%s can not be read" % file) - break + continue try: aos = yoda.read(file) except: logging.error("%s can not be parsed as YODA" % file) - break + continue ## Get histos from this YODA file for aopath, ao in aos.iteritems() : if("RAW" in aopath) :continue if(aopath.find("6870392")>0 or aopath.find("HELEN")>0) : if not inhistos.has_key(aopath): inhistos[aopath] = {} tmpE = inhistos[aopath] if not tmpE.has_key(sqrts): tmpE[sqrts] = {} tmpP = tmpE[sqrts] if not tmpP.has_key(ptmin): tmpP[ptmin] = ao else: raise Exception("A set with ptmin = %s already exists" % ( ptmin)) else : outhistos[aopath] = ao ## Make empty output histos if needed for hpath,hsets in inhistos.iteritems(): if( (hpath.find("6870392")>0 and hpath.find("d02-x01-y01" )>0 ) or hpath.find("HELEN")>0 ) : if(type(hsets.values()[0].values()[0])==yoda.core.Scatter2D) : outhistos[hpath] = yoda.core.Scatter2D(hsets.values()[0].values()[0].path, hsets.values()[0].values()[0].title) elif(type(hsets.values()[0].values()[0])==yoda.core.Profile1D) : outhistos[hpath] = yoda.core.Profile1D(hsets.values()[0].values()[0].path, hsets.values()[0].values()[0].title) for i in range(0,hsets.values()[0].values()[0].numBins) : outhistos[hpath].addBin(hsets.values()[0].values()[0].bins[i].xMin, hsets.values()[0].values()[0].bins[i].xMax) elif(type(hsets.values()[0].values()[0])==yoda.core.Histo1D) : outhistos[hpath] = yoda.core.Histo1D(hsets.values()[0].values()[0].path, hsets.values()[0].values()[0].title) for i in range(0,hsets.values()[0].values()[0].numBins) : outhistos[hpath].addBin(hsets.values()[0].values()[0].bins[i].xMin, hsets.values()[0].values()[0].bins[i].xMax) else : logging.error("Histogram %s is of unknown type" % hpath) print hpath,type(hsets.values()[0].values()[0]) sys.exit(1) useOnePt("/STAR_2006_S6870392/d01-x01-y01","200","2") mergeByPt("/STAR_2006_S6870392/d02-x01-y01","200") mergeByPt("/STAR_2009_UE_HELEN/d01-x01-y01","200") mergeByPt("/STAR_2009_UE_HELEN/d02-x01-y01","200") mergeByPt("/STAR_2009_UE_HELEN/d03-x01-y01","200") # Choose output file name = args[0]+".yoda" print "write to ",name yoda.writeYODA(outhistos,name) sys.exit(0)