check_promc_single.py (raw text file)
# HepSim script using Jas4pp
# Part of =HepSim= : https://atlaswww.hep.anl.gov/hepsim/
# S.Chekanov (ANL)
from java.lang import *
from java.awt import Color,Font
from jhplot import  HPlot,P1D,HLabel,H1D
from jhplot.io import HBook
from proto import FileMC   # import FileMC
from jhplot.utils import FileList
from hephysics.particle import LParticle 
from hepsim import HepSim
import sys,math 

url="";  TotalEvents=50000
default_www="http://mc.hep.anl.gov/asc/hepsim/events/misc/pgun/pgun_eta4_pt30_elec/"
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. Nr events= ",TotalEvents

h1= H1D("p_{T}",50,0,50)  
h1.setFill(True)
h2= H1D("ETA",50,-5,5) 
h2.setFill(True)
h3= H1D("PHI [rad]",50,-5,5)  
h3.setFill(True)

cross=0; nev=0;  Nfiles=len(flist)
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 
   if (nev>TotalEvents): print "Max Nr of events are done"; break # stop after some events
   for i in range(file.size()):
      if (nev>TotalEvents): break
      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
      for j in range(pa.getPxCount()): 
        if (pa.getStatus(j)==1):
           p=LParticle(pa.getPx(j)/un,pa.getPy(j)/un,pa.getPz(j)/un,pa.getEnergy(j)/un)
           h2.fill(p.pseudoRapidity())
           h3.fill(p.phi())
           h1.fill( p.perp() )

   stat = file.getStat()
   cross=stat.getCrossSectionAccumulated()
   erro=stat.getCrossSectionErrorAccumulated();
   file.close()

print "Total Nr =",h1.allEntries()
c1 = HPlot("=HepSim=",600,700, 1,3) # plot histogram
c1.visible(True)
# c1.setAutoRange()
c1.setRange(0,50,0,0.1)
# c1.setRangeY(1,1)
c1.setMarginLeft(90)
c1.setNameX("p_{T} [GeV]")
c1.setNameY("Density")
c1.draw(h1.getDensity())
# h1.toTable() 

c1.cd(1,2)
c1.setAutoRange()
c1.setRange(-5,5,0,0.3)
c1.setMarginLeft(90)
c1.setNameX("ETA")
c1.setNameY("Density")
c1.draw(h2.getDensity())

c1.cd(1,3)
c1.setAutoRange()
c1.setRange(-4,4,0,0.3)
c1.setMarginLeft(90)
c1.setNameX("PHI")
c1.setNameY("Density")
c1.draw(h3.getDensity())

# create file/image using name of the file
name="output"
if len(sys.argv[0])>0: name=sys.argv[0].replace(".py","")
file=HBook(name+".jdat","w"); print name+".jdat created"
file.write(h1)
file.close()
c1.export(name+".svg");    print name+".svg created"
# h1.toFile(name+".txt");  print name+".txt created"
# sys.exit(0)