HepSim

Repository with Monte Carlo simulations for particle physics

pythia_higgs2mumu.py (raw text file)
# HepSim validation script
# Use hs-tools, Jas4pp or DMelt 
# S.Chekanov (ANL)
from java.lang import *
from proto import FileMC   # import FileMC
from java.awt import Color,Font
from jhplot import  HPlot,P1D,HLabel,H1D
from jhplot.io import HBook
from jhplot.utils import FileList
from hephysics.particle import LParticle 
import sys
from hepsim import HepSim

url="";  TotalFiles=5 # 5 files for testing 
default_www="http://mc.hep.anl.gov/asc/hepsim/events/pp/14tev/pythia8_higgs2mumu/"
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): TotalFiles=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"

h1= H1D("Inv. mass",100,124.95,125.05)  
h1.setFill(True)
#h1.doc()               # check its methods

cross=0; nev=0;  Nfiles=len(flist)
if (TotalFiles>-1): 
               Nfiles=TotalFiles
               print "Debug mode for ",TotalFiles," files"
for m in range(Nfiles):              # loop over all files in this list    
   file=FileMC(url+flist[m])         # get input file
   header = file.getHeader()
   un=float(header.getMomentumUnit()) # conversion units
   lunit=float(header.getLengthUnit())
   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%500==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
      muons=[]
      for j in range(pa.getPxCount()): 
           p=LParticle(pa.getPx(j)/un,pa.getPy(j)/un,pa.getPz(j)/un,pa.getEnergy(j)/un,pa.getMass(j)/un)
           p.setCharge(1)
           if (pa.getPdgId(j)120 and mass0: name=sys.argv[0].replace(".py","")
file=HBook(name+".jdat","w"); print name+".jdat created"
file.write(xsec)
file.close()
c1.export(name+".svg");    print name+".svg created"
# xsec.toFile(name+".txt");  print name+".txt created"
# sys.exit(0)

HEP.ANL.GOV