import ROOT
Welcome to JupyROOT 6.28/00
Sample from ATLAS 13 TeV Open Data release with exactly two leptons: https://opendata.cern.ch/record/15007
from ROOT import TFile
input_file = TFile("exactly2lep/MC/mc_361107.Zmumu.exactly2lep.root")
input_tree = input_file.Get("mini")
input_tree.Show(1)
======> EVENT:1 runNumber = 284500 eventNumber = 29655415 channelNumber = 361107 mcWeight = 1941.51 scaleFactor_PILEUP = 0.553627 scaleFactor_ELE = 1 scaleFactor_MUON = 0.96842 scaleFactor_PHOTON = 1 scaleFactor_TAU = 1 scaleFactor_BTAG = 1 scaleFactor_LepTRIGGER = 0.997809 scaleFactor_PhotonTRIGGER = 1 trigE = 0 trigM = 1 trigP = 0 lep_n = 2 lep_truthMatched = (vector<bool>*)0x125f2440 lep_trigMatched = (vector<bool>*)0x125f3940 lep_pt = (vector<float>*)0x12697d70 lep_eta = (vector<float>*)0x125dc260 lep_phi = (vector<float>*)0x125f6140 lep_E = (vector<float>*)0x12689970 lep_z0 = (vector<float>*)0x125f2190 lep_charge = (vector<int>*)0x1124b390 lep_type = (vector<unsigned int>*)0x10f73e00 lep_isTightID = (vector<bool>*)0x126a9360 lep_ptcone30 = (vector<float>*)0x10f78d00 lep_etcone20 = (vector<float>*)0x25db620 lep_trackd0pvunbiased = (vector<float>*)0x10f0f3f0 lep_tracksigd0pvunbiased = (vector<float>*)0x5e86660 met_et = 20477.5 met_phi = 2.30597 jet_n = 0 jet_pt = (vector<float>*)0x126a5b70 jet_eta = (vector<float>*)0x12689db0 jet_phi = (vector<float>*)0x1268bac0 jet_E = (vector<float>*)0x3b58970 jet_jvt = (vector<float>*)0x126a9fd0 jet_trueflav = (vector<int>*)0x126a9ec0 jet_truthMatched = (vector<bool>*)0x12680460 jet_MV2c10 = (vector<float>*)0x125e9f90 photon_n = 0 photon_truthMatched = (vector<bool>*)0x12681170 photon_trigMatched = (vector<bool>*)0x126816c0 photon_pt = (vector<float>*)0x5e86780 photon_eta = (vector<float>*)0x1123d9d0 photon_phi = (vector<float>*)0x12687cf0 photon_E = (vector<float>*)0x12698560 photon_isTightID = (vector<bool>*)0x125e3f40 photon_ptcone30 = (vector<float>*)0x1269b410 photon_etcone20 = (vector<float>*)0x126a3960 photon_convType = (vector<int>*)0x126a3360 tau_n = 0 tau_pt = (vector<float>*)0x125f3a50 tau_eta = (vector<float>*)0x9c85500 tau_phi = (vector<float>*)0x1268b750 tau_E = (vector<float>*)0x126a4890 tau_isTightID = (vector<bool>*)0x125e68d0 tau_truthMatched = (vector<bool>*)0x125e6dc0 tau_trigMatched = (vector<bool>*)0x125e7310 tau_nTracks = (vector<int>*)0x11239ad0 tau_BDTid = (vector<float>*)0x11230310 ditau_m = 0 lep_pt_syst = (vector<float>*)0x125ed260 met_et_syst = 28793.8 jet_pt_syst = (vector<float>*)0x126a93c0 photon_pt_syst = (vector<float>*)0x126a99f0 tau_pt_syst = (vector<float>*)0x126940c0 XSection = 1950.63 SumWeights = 1.47335e+11 largeRjet_n = 0 largeRjet_pt = (vector<float>*)0x12683bf0 largeRjet_eta = (vector<float>*)0x125ee2a0 largeRjet_phi = (vector<float>*)0x126965e0 largeRjet_E = (vector<float>*)0x12695980 largeRjet_m = (vector<float>*)0x12694f30 largeRjet_truthMatched = (vector<float>*)0x12684420 largeRjet_D2 = (vector<float>*)0x12693ca0 largeRjet_tau32 = (vector<float>*)0x1268c5b0 largeRjet_pt_syst = (vector<float>*)0x12682980 tau_charge = (vector<int>*)0x125a2dc0
from ROOT import TTree, TLorentzVector
# create a tree
tree = TTree()
# setup branches, they are all single-precision floats
from array import array
lep1_pt = array('f', [0])
tree.Branch('lep1_pt', lep1_pt, 'lep1_pt/F')
lep1_eta = array('f', [0])
tree.Branch('lep1_eta', lep1_eta, 'lep1_eta/F')
lep1_phi = array('f', [0])
tree.Branch('lep1_phi', lep1_phi, 'lep1_phi/F')
lep1_E = array('f', [0])
tree.Branch('lep1_E', lep1_E, 'lep1_E/F')
lep1_m = array('f', [0])
tree.Branch('lep1_m', lep1_m, 'lep1_m/F')
lep2_pt = array('f', [0])
tree.Branch('lep2_pt', lep2_pt, 'lep2_pt/F')
lep2_eta = array('f', [0])
tree.Branch('lep2_eta', lep2_eta, 'lep2_eta/F')
lep2_phi = array('f', [0])
tree.Branch('lep2_phi', lep2_phi, 'lep2_phi/F')
lep2_E = array('f', [0])
tree.Branch('lep2_E', lep2_E, 'lep2_E/F')
lep2_m = array('f', [0])
tree.Branch('lep2_m', lep2_m, 'lep2_m/F')
Z_pt = array('f', [0])
tree.Branch('Z_pt', Z_pt, 'Z_pt/F')
Z_eta = array('f', [0])
tree.Branch('Z_eta', Z_eta, 'Z_eta/F')
Z_phi = array('f', [0])
tree.Branch('Z_phi', Z_phi, 'Z_phi/F')
Z_E = array('f', [0])
tree.Branch('Z_E', Z_E, 'Z_E/F')
Z_m = array('f', [0])
tree.Branch('Z_m', Z_m, 'Z_m/F')
i = 0
# loop over the tree
for event in input_tree:
# create lorentz vectors for leptons
lep1_vec = TLorentzVector()
lep1_vec.SetPtEtaPhiE(event.lep_pt[0] / 1000, event.lep_eta[0], event.lep_phi[0], event.lep_E[0] / 1000)
lep2_vec = TLorentzVector()
lep2_vec.SetPtEtaPhiE(event.lep_pt[1] / 1000, event.lep_eta[1], event.lep_phi[1], event.lep_E[1] / 1000)
# fill lepton variables
lep1_pt[0] = lep1_vec.Pt()
lep1_eta[0] = lep1_vec.Eta()
lep1_phi[0] = lep1_vec.Phi()
lep1_E[0] = lep1_vec.E()
lep1_m[0] = lep1_vec.M()
lep2_pt[0] = lep2_vec.Pt()
lep2_eta[0] = lep2_vec.Eta()
lep2_phi[0] = lep2_vec.Phi()
lep2_E[0] = lep2_vec.E()
lep2_m[0] = lep2_vec.M()
# reconstruct a Z boson from two leptons
Z_vec = lep1_vec + lep2_vec
# fill Z boson variables
Z_pt[0] = Z_vec.Pt()
Z_eta[0] = Z_vec.Eta()
Z_phi[0] = Z_vec.Phi()
Z_E[0] = Z_vec.E()
Z_m[0] = Z_vec.M()
# fill the tree
tree.Fill()
# debugging, finish after 2.5M events
i += 1
if i % 10000 == 0:
print(i)
if i >= 2500000:
break
# inspect the result
tree.Show(1)
tree.GetEntries()
10000 20000 30000 40000 50000 60000 70000 80000 90000 100000 110000 120000 130000 140000 150000 160000 170000 180000 190000 200000 210000 220000 230000 240000 250000 260000 270000 280000 290000 300000 310000 320000 330000 340000 350000 360000 370000 380000 390000 400000 410000 420000 430000 440000 450000 460000 470000 480000 490000 500000 510000 520000 530000 540000 550000 560000 570000 580000 590000 600000 610000 620000 630000 640000 650000 660000 670000 680000 690000 700000 710000 720000 730000 740000 750000 760000 770000 780000 790000 800000 810000 820000 830000 840000 850000 860000 870000 880000 890000 900000 910000 920000 930000 940000 950000 960000 970000 980000 990000 1000000 1010000 1020000 1030000 1040000 1050000 1060000 1070000 1080000 1090000 1100000 1110000 1120000 1130000 1140000 1150000 1160000 1170000 1180000 1190000 1200000 1210000 1220000 1230000 1240000 1250000 1260000 1270000 1280000 1290000 1300000 1310000 1320000 1330000 1340000 1350000 1360000 1370000 1380000 1390000 1400000 1410000 1420000 1430000 1440000 1450000 1460000 1470000 1480000 1490000 1500000 1510000 1520000 1530000 1540000 1550000 1560000 1570000 1580000 1590000 1600000 1610000 1620000 1630000 1640000 1650000 1660000 1670000 1680000 1690000 1700000 1710000 1720000 1730000 1740000 1750000 1760000 1770000 1780000 1790000 1800000 1810000 1820000 1830000 1840000 1850000 1860000 1870000 1880000 1890000 1900000 1910000 1920000 1930000 1940000 1950000 1960000 1970000 1980000 1990000 2000000 2010000 2020000 2030000 2040000 2050000 2060000 2070000 2080000 2090000 2100000 2110000 2120000 2130000 2140000 2150000 2160000 2170000 2180000 2190000 2200000 2210000 2220000 2230000 2240000 2250000 2260000 2270000 2280000 2290000 2300000 2310000 2320000 2330000 2340000 2350000 2360000 2370000 2380000 2390000 2400000 2410000 2420000 2430000 2440000 2450000 2460000 2470000 2480000 2490000 2500000
2500000
======> EVENT:1 lep1_pt = 33.9272 lep1_eta = 1.93228 lep1_phi = 0.334629 lep1_E = 119.594 lep1_m = 0.108104 lep2_pt = 21.244 lep2_eta = 1.84182 lep2_phi = -1.3754 lep2_E = 68.6875 lep2_m = 0.103114 Z_pt = 37.4474 Z_eta = 2.27382 Z_phi = -0.261946 Z_E = 188.282 Z_m = 40.5895
# make a file and write the tree to it
file = TFile("Zmumu.root", "RECREATE")
file.WriteObject(tree, "physics")
file.Close()
Last update: 06 March 2023