HepSim

Repository with Monte Carlo simulations for particle physics

higgs_higgs_ggbbar_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 

# set number of files for analysis
TotalFiles=-1

url=""; 
default_www="http://mc.hep.anl.gov/asc/hepsim/events/pp/100tev/hh_ggbbar/"
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(H0) pdf="+str(i),bins)
      histo.append(h1)

nev=0;  Nfiles=len(flist)
if TotalFiles>-1 and TotalFiles5): break                    # debugging
   file=FileNLO(url+flist[m])             # get input file
   header = file.getHeader()
   un=float(header.getMomentumUnit()) # GeV units
   lunit=float(header.getLengthUnit())
   nIterations=header.getWeight() # MCFM Nr of iterations
   NXF=nIterations*Nfiles
   # print nIterations, Nfiles
   if m==0:
      print "ProMC v=",file.getVersion(), "M unit=",un,"L unit=",lunit
   for i in range(file.size()):
      nev=nev+1  
      if (nev%20000==0): 
           if (Nfiles==1): print "Event=",nev
           else: print "Event=",nev," done=",int((100.0*m)/Nfiles),"%"
      eve = file.read(i) 
      pa = eve.getParticles()    # particle information
      ve = eve.getEvent()        # event information
      weight=ve.getFdata(0)      # global weight. 1-gg, 2-gq, 3-qq, 4-qqb
      for j in range(ve.getIdataCount()): 
                pdferrors= ve.getIdata(j)      # PDF errors (1-PDF(i)/PDF(0))*1000 
      weight=weight/NXF            # take into account iterations & Nr of files
      gammas=[] 
      bquarks=[]
      for j in range(pa.getPxCount()):
         if (math.fabs(pa.getPdgId(j))==22):
           p=LParticle(pa.getPx(j)/un,pa.getPy(j)/un,pa.getPz(j)/un,pa.getEnergy(j)/un)
           gammas.append(p)
         if (math.fabs(pa.getPdgId(j))==5):
           p=LParticle(pa.getPx(j)/un,pa.getPy(j)/un,pa.getPz(j)/un,pa.getEnergy(j)/un)
           bquarks.append(p)

      higgses=[] 
      if (len(gammas)>1):      
           higgs=gammas[0]
           higgs.add(gammas[1])
           higgses.append(higgs)
      if (len(bquarks)>1):                  
           higgs=bquarks[0]
           higgs.add(bquarks[1])
           higgses.append(higgs)
      for h in higgses:
           mass=h.calcMass()
           if (mass>120 and mass0): 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