8 from uproot_methods
import *
9 from concurrent.futures
import ThreadPoolExecutor
27 def UprootLoad(files=[], treename="", branches=[]):
29 print(f
"::UprootLoad({files}")
30 executor = ThreadPoolExecutor(8)
37 filenames = glob.glob(files[0])
39 data = pd.DataFrame(columns=branches)
41 for filename
in filenames:
42 tree = uproot.open(filename)[treename]
43 data = pd.concat([data, tree.arrays(branches, namedecode=
'utf-8', outputtype=pd.DataFrame)])
47 print(f
"Originally generated number of collisions: {n_gen}")
49 print(
"Exploding the DataFrame...")
52 print(
"Completed exploding the DataFrame")
58 if process ==
'CC_DIS_e18_p275':
60 elif process ==
'CC_DIS_e10_p100_CT18NNLO':
61 return 5.44044e-09*u_mb
62 elif process ==
'CC_DIS_e10_p275_CT18NNLO':
63 return 1.47637e-08*u_mb
64 elif process ==
'CC_DIS_e10_p275_CT1820Rs2':
65 return 1.47637e-08*u_mb
66 elif process ==
'CC_DIS_e10_p100_CT1820Rs2':
67 return 5.44842e-09*u_mb
68 elif process ==
'CC_DIS_e10_p275_CT1821Rs2':
69 return 1.45884e-08*u_mb
70 elif process ==
'CC_DIS_e10_p100_CT1821Rs2':
71 return 5.36006e-09*u_mb
72 elif process ==
'NC_DIS_e18_p275':
75 print(f
"EICAnalysisTools::TotalXSection == Unable to find requested process, {process}.")
84 pProton = branchParticle.At(0).P4(); #these numbers 0 , 3, 5 are hardcoded in Pythia8
85 pleptonIn = branchParticle.At(3).P4();
86 pleptonOut = branchParticle.At(5).P4();
87 pPhoton = pleptonIn - pleptonOut;
89 #Q2, W2, Bjorken x, y, nu.
91 W2 = (pProton + pPhoton).M2()
92 x = Q2 / (2. * pProton.Dot(pPhoton))
93 y = (pProton.Dot(pPhoton)) / (pProton.Dot(pleptonIn))
96 particles_px = row[
'Particle.Px']
97 particles_py = row[
'Particle.Py']
98 particles_pz = row[
'Particle.Pz']
99 particles_E = row[
'Particle.E']
106 pProton = TLorentzVector(particles_px[iproton], particles_py[iproton], particles_pz[iproton], particles_E[iproton])
107 pleptonIn = TLorentzVector(particles_px[ilepton1], particles_py[ilepton1], particles_pz[ilepton1], particles_E[ilepton1])
108 pleptonOut = TLorentzVector(particles_px[ilepton2], particles_py[ilepton2], particles_pz[ilepton2], particles_E[ilepton2])
109 pPhoton = pleptonIn - pleptonOut
112 W2 = (pProton + pPhoton).mag2
113 x = Q2 / (2. * pProton.dot(pPhoton))
116 x_array = np.ones(len(row[
'jet_pt'])) * x
128 def DifferentialTaggingYield(df, x='jet_pt', xrange=[10,50], xbins=[10,12.5,15,20,25,30,40,50], which='all', process='CC_DIS_e18_p275', target_lumi = 100, taggers="jet_sip3dtag"):
130 print(f
"n_gen = {n_gen}")
132 jet_flavor = np.concatenate(df[
'jet_flavor'].to_numpy()).ravel()
133 jet_tag = np.concatenate(df[
'jet_sip3dtag'].to_numpy()).ravel()
135 jet_x = np.concatenate(df[x].to_numpy()).ravel()
143 jet_x = jet_x[ (jet_tag == 1) & (jet_flavor == 4) ]
144 elif which ==
'light':
145 jet_x = jet_x[ (jet_tag == 1) & ((jet_flavor < 4) | (jet_flavor == 21)) ]
148 (counts, bins) = np.histogram(jet_x, range=xrange,
152 bin_widths = np.diff(bins)
153 bin_centers = bins[:-1] + bin_widths/2
155 errors = np.sqrt(counts)
156 rel_errors = errors/counts
160 dsigma_dx = counts *
TotalXSection(process) * target_lumi*u_fb**(-1) / n_gen
161 dsigma_dx_errors = rel_errors * dsigma_dx
164 print(f
"========= Validation Information from DifferentialTaggingYield ========= \n \
166 Process considered: {process} \n \
167 Theory Cross-Section: {TotalXSection(process)} \n \
168 Target Integrated Luminosity: {target_lumi} \n \
169 Total Predicted Yield of Events: {np.sum(dsigma_dx)} \ \
171 ========= Validation Information from DifferentialTaggingYield =========")
174 return (bin_centers, bin_widths, dsigma_dx, dsigma_dx_errors)
178 def DifferentialTaggingEfficiency(df, x='jet_pt', xrange=[10,50], xbins=[10,12.5,15,20,25,30,40,50], which='all', taggers="jet_sip3dtag"):
180 jet_flavor = np.concatenate(df[
'jet_flavor'].to_numpy()).ravel()
181 jet_tag = np.concatenate(df[
'jet_sip3dtag'].to_numpy()).ravel()
183 jet_x = np.concatenate(df[x].to_numpy()).ravel()
197 jet_x = jet_x[ jet_flavor == 4 ]
198 jet_tag = jet_tag[ jet_flavor == 4 ]
199 elif which ==
'light':
200 jet_x = jet_x[ ((jet_flavor < 4) | (jet_flavor == 21)) ]
201 jet_tag = jet_tag[ ((jet_flavor < 4) | (jet_flavor == 21)) ]
203 (tru_counts, bins) = np.histogram(jet_x, range=xrange,
206 (tag_counts, bins) = np.histogram(jet_x[ jet_tag == 1 ], range=xrange,
210 eff = tag_counts/tru_counts
211 n_err = scipy.stats.binom.interval(1.0-math.exp(-1), tru_counts, eff)
213 eff_err=[np.fabs(n_err[0]/tru_counts-eff), np.fabs(n_err[1]/tru_counts-eff)]
216 bin_widths = np.diff(bins)
217 bin_centers = bins[:-1] + bin_widths/2
219 print(f
"========= Validation Information from DifferentialTaggingEfficiency =========")
222 print(f
"Tagging Efficiency above X threshold for {which}:")
223 for ibin
in np.arange(len(bins)-1):
227 n_tag = np.sum(tag_counts[ibin:])
228 n_tru = np.sum(tru_counts[ibin:])
229 eff_above_x = n_tag/n_tru
230 err_above_x = np.nanmean([np.fabs(np.sum(n_err[0][ibin:])/n_tru-eff_above_x), np.fabs(np.sum(n_err[1][ibin:])/n_tru-eff_above_x)])
232 print(f
"Minimum X: {bins[ibin]:.1f} Tag. Efficiency: ({eff_above_x*100:.3f} +/- {err_above_x*100:.3f})%")
235 print(f
"========= Validation Information from DifferentialTaggingEfficiency =========")
237 return (bin_centers, bin_widths, eff, eff_err)