ROOT Version: 6.08.06:
Compiler: 5.2.1
Hi, I wonder if I can get help from this website about PyRoot
I currently have a root file called qcd.root
(I wish I could have uploaded in this forum, but the size of file is 3.1 GB)
It is a root file, which as been generated through following steps
Use PythiaRun to generate 100000 pp->jj+X QCD events, output file being qcd.hepmc
Use DelphesHepmc executable with CMS card file does jet clustering and generates qcd.root
Therefore,qcd.root
is a 100000 QCD Jet clustered events file, which has Delphes TTree, and within there, branches of Event, Weight, Track, Jet, and so on.
My primary goal is to randomly sample N events from the sample of N events and histogram all jets with |y| < 0.5 and pT > 1 TeV.
I currently have my code, which works, but lack completeness.
`from ROOT import gSystem, TFile, TH1F, TCanvas
from histutil import *
#-------------------------------------------------------------------------------
rootfile = 'Jet.root'
def main():
# read all entries and fill the histograms
myfile = TFile("qcd.root")
mytree = myfile.Delphes
hfile = TFile(rootfile, "recreate")
if not hfile.IsOpen():
hutil.error("randomhist.py",
"can't open rootfile Event.root")
gSystem.Load('libDelphes') # for i in range(1000):
hfile.cd()
c1 = TCanvas('c1', 'Histogram', 200, 10, 700, 900)
# s = str(i)
hpx = TH1F("hpx","px distribution 1st", 100, 100, 4200)
for event in mytree:
for jet in event.Jet:
hpx.Fill(jet.PT)
hpx.Write()
myfile.Close()
hfile.Close()
#-------------------------------------------------------------------------------
try:
main()
except KeyboardInterrupt:
print 'ciao!'
`
For this code, I have 1 main question.
In my current code, the for loop for event goes over ENTIRE 1 MILLION events and creates that number of hpx. However, I want to Randomly select only 100 event from my tree and and then write out 1 px.
How may I do so?
Thank you for help!
In addition, if you notice something wrong or inefficient about my code, please let me know!