dijetmass_2tev_charhw_hw.py (raw text file)
from java.awt import Color,Font
from java.lang import *
from proto import FileMC
from jhplot import HPlot,P1D,HLabel,H1D
from jhplot.utils import FileList
from hepsim import HepSim
from java.util import ArrayList
from hephysics.hepsim import PromcUtil
from hephysics.jet import JetN2
from hephysics.particle import LParticle
import sys
ktjet=JetN2(0.4,"antikt",100)
NMax=2
dataset="tev27pp_mg5_chaHW_hw"
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
xmin=HepSim.getRanges(flist,"hw_m","_");
print "Mass ranges: ",xmin
filelist=[]
histo=[]
crosssection=[]
n=0
for i in xmin:
ma=[]
for j in flist:
if (j.find("m"+str(i)+"_")>-1): ma.append(j)
filelist.append(ma)
hh=H1D("M="+str(i),250,0,25000)
hh.setColor(Color(40+n*10,20+n*5,215-2*n))
histo.append( hh )
n=n+1
print "Total number of mass ranges=",len(filelist)
Total=len(filelist)
for ipt in range(Total):
ptlist=filelist[ipt]
print ipt, "Mass = "+str(xmin[ipt])
cross=0; xcross=0; nev=0; Nfiles=len(ptlist)
if (NMax>-1): Nfiles=NMax
for m in range(Nfiles):
file=FileMC(url+ptlist[m])
header = file.getHeader()
un=float(header.getMomentumUnit())
lunit=float(header.getLengthUnit())
print "Read=",url+ptlist[m]
for i in range(file.size()):
nev=nev+1
if (nev%200==0):
if (m==0): print "Event=",nev
else: print "Event=",nev," done=",int((100.0*m)/Nfiles),"%", 'x-cross=',xcross
eve = file.read(i)
pa = eve.getParticles()
NN=0
for j in range(pa.getPxCount()):
if (Math.abs(pa.getPdgId(j))==11 or Math.abs(pa.getPdgId(j))==13):
p=LParticle(pa.getPx(j)/un,pa.getPy(j)/un,pa.getPz(j)/un,pa.getEnergy(j)/un,0)
if (p.perp()>60): NN+=1
if (NN==0): continue;
ve = eve.getEvent()
particles=PromcUtil.getParticleDList(file.getHeader(), pa, 1, -1, 1000);
ktjet.buildJets(particles);
jets=ktjet.getJetsSorted()
if (len(jets)>1):
ptlead1=jets[0].perp()
ptlead2=jets[1].perp()
jets[0].add(jets[1])
mass=jets[0].mass()
histo[ipt].fill(mass)
stat = file.getStat()
xcross=stat.getCrossSectionAccumulated()
cross=cross+xcross;
erro=stat.getCrossSectionErrorAccumulated();
file.close()
cross=cross/Nfiles
lumi=nev/cross
crosssection.append( histo[ipt].entries()/lumi )
histo[ipt]=histo[ipt].getDividedByBinWidth()
crossD=histo[0].sumAllBinHeights()
c1 = HPlot("HepSim",600,400)
c1.setNameX("M_{jj} [GeV]")
c1.setNameY("Entries / GeV")
c1.visible(True)
c1.setAutoRange()
c1.setRangeX(0,25000)
c1.setRangeY(0,100)
c1.setMarginLeft(100)
print "Cross sections for masses [pb]"
for ipt in range(Total):
lab="{:.1e}".format(xmin[ipt]*0.001)+" TeV "+"{:.1e} pb".format(crosssection[ipt])
print ipt, lab
histo[ipt].setTitle(lab)
c1.draw(histo)
l2=HLabel("=HepSim=",0.75,0.84, "NDC")
l2.setFont(Font("Helvetica", Font.PLAIN, 14))
l2.setColor(Color.gray)
c1.add(l2)
name="output"
if len(sys.argv[0])>0: name=sys.argv[0].replace(".py","")
from jhplot.io import HBook
file=HBook(name+".jdat","w"); print name+".jdat created"
for i in histo: file.write(i)
file.close()
c1.export(name+".svg"); print name+".svg created"