tev100_dijets_pythia8_pt.py (raw text file)
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
from jhplot.utils import FileList
from hephysics.particle import LParticle
from hepsim import HepSim
from java.util import ArrayList
from hephysics.hepsim import PromcUtil
from hephysics.jet import JetN2
import sys
NMax=4
dataset="tev100pp_qcd_pythia8_weighted"
tag=""
url=""
if len(sys.argv)>1:
flist=FileList.get(sys.argv[1],"slcio")
if (len(sys.argv)>2): NMax=int(sys.argv[2])
else:
sites=HepSim.urlRedirector(dataset)
url=sites[0]+"/"+tag
flist=HepSim.getList(url)
if len(flist)==0: print "Error: No input file!"; sys.exit(0)
else: print "Reading "+str(len(flist))+" files. Nr of files= ",NMax
h1= H1D("PT(jet)",50, 0,40000)
h2= H1D("M(jj)",50, 0, 40000)
ktjet=JetN2(0.4,"antikt",100)
cross=0; nev=0; Nfiles=len(flist)
if (NMax>-1): Nfiles=NMax
weightSumTot=0
across=0
mm=0
for m in range(Nfiles):
file=FileMC(url+flist[m])
weightSum=0
for i in range(file.size()):
nev=nev+1
if (nev%200==0):
if (Nfiles==1): print "Event=",nev
else: print "Event=",nev," done=",int((100.0*m)/Nfiles),"%"
eve = file.read(i)
event = eve.getEvent()
pa = eve.getParticles()
weight= event.getWeight()
weightSum = event.getPDF1()
mergingWeight = event.getPDF2()
ptHat=event.getScale()
particles=PromcUtil.getParticleDList(file.getHeader(), pa, 1, -1, 1000);
ktjet.buildJets(particles);
jets=ktjet.getJetsSorted()
if (len(jets)>0):
lead=jets[0]
h1.fill(lead.perp(),weight)
if (len(jets)>1):
pt1=jets[0].perp()
pt2=jets[1].perp()
if (abs(jets[0].phi()-jets[1].phi())>2):
jets[0].add(jets[1])
mass=jets[0].mass()
h2.fill(mass,weight)
stat = file.getStat()
across=across+stat.getCrossSectionAccumulated()
weightSumTot=weightSumTot+weightSum
mm=mm+1
erro=stat.getCrossSectionErrorAccumulated();
file.close()
cross=across/mm
lumi=nev/cross;
print "Lumi=%.3e pb"%lumi
print "Total cross section (pb)=",cross
print "Total weight=",weightSumTot
h1.scale(cross/(h1.getBinSize()*weightSumTot))
h2.scale(cross/(h1.getBinSize()*weightSumTot))
c1 = HPlot("HepSim")
c1.setNameX("p_{T}(jet) [GeV]")
c1.setNameY("d σ / d p_{T} [pb / GeV]")
c1.visible(True)
c1.setMarginLeft(90)
c1.setAutoRange(True)
c1.cd(1,1)
c1.setRangeX(0,40000)
c1.setRangeY(1E-10,1E5)
c1.setLogScale(1,1)
c1.draw(h1)
l1=HLabel("Pythia8 QCD σ=%.3e pb"%cross, 0.5, 0.75, "NDC")
l1.setFont(Font("Helvetica", Font.PLAIN, 12))
c1.add(l1)
l2=HLabel("=HepSim=",0.7,0.85, "NDC")
l2.setColor(Color.gray)
l2.setFont(Font("Helvetica", Font.PLAIN, 14))
c1.add(l2)
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"
</code></pre>
</div>
<script src="bootstrap/js/bootstrap.bundle.min.js">