HepSim

Repository with Monte Carlo simulations for particle physics

wjet_mcfm.py (raw text file)
# HepSim script using DataMelt http://jwork.org/dmelt
# Part of =HepMC= : https://atlaswww.hep.anl.gov/asc/hepsim/
# S.Chekanov (ANL)

from java.awt import Color,Font
from jhplot import  HPlot,P1D,HLabel,H1D
from jhplot.io import HBook
from java.lang import *
from proto import FileNLO # import FileNLO
from jhplot.utils import FileList
from hephysics.particle import LParticle
from hepsim import HepSim
import sys,os,math 


#from javax.swing import JOptionPane
#if JOptionPane.showConfirmDialog(None, "This macro works for local files. Quit?","Warning", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION: System.exit(0);



# set number of files for analysis
TotalFiles=-1

minJetPt=10

url=""; 
default_www="http://mc.hep.anl.gov/asc/hepsim/events/pp/8tev/wjet_mcfm/"
if len(sys.argv)>1:
   if sys.argv[1].startswith("http"):
                            flist=HepSim.getList(sys.argv[1])
                            url=sys.argv[1]
   else: flist=FileList.get(sys.argv[1],"promc")
   if (len(sys.argv)>2): TotalEvents=int(sys.argv[2])
else:
   url=default_www; flist=HepSim.getList(url)
if len(flist)==0: print "Error: No input file!"; sys.exit(0)
else: print "Reading "+str(len(flist))+" files."

bins=[0,40,80,120,160,200,240,280,320,360,400]
nPDF=52
histo=[]
for i in range(nPDF):
      h1=H1D("PT(W) pdf="+str(i),bins)
      histo.append(h1)

nev=0;  Nfiles=len(flist)
if TotalFiles>-1 and TotalFiles70 and massminJetPt):   # catch W             
               for k in range(nPDF):
                  delta = 1.0-(ve.getIdata(k)/1000.) # PDF errors (1-PDF(i)/PDF(0))*1000
                  histo[k].fill(w.perp(),weight*delta)
   file.close()
  
cross=histo[0].sumAllBinHeights()/1000 # convert to pb
print "Total cross section (pb)=",cross
data=[]
for k in range(nPDF):
    newD=histo[k].getDividedByBinWidth()
    newD.scale(1.0/1000) # convert to pb 
    data.append(P1D(newD))


# create P1D with errors evaluated from an array of P1D
xsec=P1D("MCFM CT10")
for j in range(data[0].size()):
     x=data[0].getX(j)
     y=data[0].getY(j)
     errX=0.5*(bins[j+1]-bins[j])
     up=0; dw=0;
     for n in range(1,nPDF):
        d=data[n].getY(j)-y
        if (d>0): up=up+d*d
        if (d0: name=sys.argv[0].replace(".py","")
file=HBook(name+".jdat","w"); print name+".jdat created"
file.write(xsec)
file.write(errors)
file.close()
c1.export(name+".svg");    print name+".svg created"
# xsec.toFile(name+".txt");  print name+".txt created"
# sys.exit(0)

HEP.ANL.GOV