11 import matplotlib.pyplot
as plt
13 from mpl_toolkits.mplot3d
import Axes3D
15 parser = argparse.ArgumentParser()
17 parser.add_argument(
"-PU",
"--filePU",help=
"input PU file")
18 parser.add_argument(
"-NPU",
"--fileNPU",help=
"input no PU file")
19 parser.add_argument(
"-O",
"--opfilename",help=
"ouput file name")
20 parser.add_argument(
"-s",
"--start", help=
"start entry for input PU file")
21 parser.add_argument(
"-e",
"--end", help=
"end entry for input PU file")
24 fName1 = parser.parse_args().filePU
25 fName2 = parser.parse_args().fileNPU
26 foutput = parser.parse_args().opfilename
27 start = parser.parse_args().start
28 stop = parser.parse_args().end
31 tree1 = uproot3.open(fName1)[
'hcalIsoTrkAnalyzer/CalibTree']
34 tree2 = uproot3.open(fName2)[
'hcalIsoTrkAnalyzer/CalibTree']
37 print (
"loaded files")
39 branchespu = [
't_Run',
't_Event',
't_nVtx',
't_ieta',
't_iphi',
't_p',
't_pt',
't_gentrackP',
't_eMipDR',
't_eHcal',
't_eHcal10',
't_eHcal30',
't_hmaxNearP',
't_emaxNearP',
't_hAnnular',
't_eAnnular',
't_rhoh',
't_selectTk',
't_qltyFlag']
41 branchesnpu = [
't_Run',
't_Event',
't_nVtx',
't_ieta',
't_iphi',
't_p',
't_pt',
't_gentrackP',
't_eMipDR',
't_eHcal',
't_eHcal10',
't_eHcal30',
't_hmaxNearP',
't_emaxNearP',
't_hAnnular',
't_eAnnular',
't_rhoh',
't_selectTk',
't_qltyFlag']
43 dictpu = tree1.arrays(branchespu, entrystart=
int(start), entrystop=
int(stop))
45 npu_entries = tree2.numentries
51 for index
in range(0,npu_entries, scale):
52 npu_stop = index+scale
53 if (npu_stop > npu_entries):
54 npu_stop = npu_entries
55 dictnpu = tree2.arrays(branchesnpu, entrystart=npu_start, entrystop=npu_stop)
57 dfspu = pd.DataFrame.from_dict(dictpu)
58 dfspu.columns=branchespu
59 dfsnpu = pd.DataFrame.from_dict(dictnpu)
60 dfsnpu.columns=branchesnpu
61 print(
"loaded % of nopile file is =",(npu_stop/npu_entries)*100)
62 print (
"PU sample size:",dfspu.shape[0])
63 print (
"noPU sample size:",dfsnpu.shape[0])
65 cuts_pu = (dfspu[
't_selectTk'])&(dfspu[
't_qltyFlag'])&(dfspu[
't_hmaxNearP']<20)&(dfspu[
't_eMipDR']<1)&(
abs(dfspu[
't_p'] - 50)<10)&(dfspu[
't_eHcal']>10)
67 cuts_npu = (dfsnpu[
't_selectTk'])&(dfsnpu[
't_qltyFlag'])&(dfsnpu[
't_hmaxNearP']<20)&(dfsnpu[
't_eMipDR']<1)&(
abs(dfsnpu[
't_p'] - 50)<10)&(dfsnpu[
't_eHcal']>10)
69 dfspu = dfspu.loc[cuts_pu]
70 dfspu = dfspu.reset_index(drop=
True)
72 dfsnpu = dfsnpu.loc[cuts_npu]
73 dfsnpu = dfsnpu.reset_index(drop=
True)
74 branches_skim = [
't_Event',
't_ieta',
't_iphi',
't_p',
't_eHcal',
't_eHcal10',
't_eHcal30']
75 dfsnpu = dfsnpu[branches_skim]
77 merged = pd.merge(dfspu, dfsnpu , on=[
't_Event',
't_ieta',
't_iphi'])
78 print (
"selected common events before cut:",merged.shape[0])
80 keepvars = [
't_nVtx',
't_ieta',
't_eHcal10_x',
't_eHcal30_x',
't_delta_x',
't_eHcal10_y',
't_eHcal30_y',
't_delta_y',
't_hmaxNearP',
't_emaxNearP',
't_hAnnular',
't_eAnnular',
't_rhoh',
't_pt',
't_eHcal_x',
't_eHcal_y',
't_p_x',
't_p_y',
't_eMipDR']
84 print (
"selected events after cut:",merged3.shape[0])
85 merged3[
't_delta_x']=merged3[
't_eHcal30_x']-merged3[
't_eHcal10_x']
86 merged3[
't_delta_y']=merged3[
't_eHcal30_y']-merged3[
't_eHcal10_y']
88 final_df_hi = merged3[keepvars]
89 final_df_hi.to_parquet(foutput+
'_'+
str(i)+
"_"+start+
"_"+stop+
".parquet")
90 final_df_hi.to_csv(foutput+
'_'+
str(i)+
"_"+start+
"_"+stop+
".txt")
92 print(merged3[
't_ieta'].dtype)
94 with uproot3.recreate(foutput+
'_'+
str(i)+
"_"+start+
"_"+stop+
".root")
as f:
96 f[
"tree"] = uproot3.newtree({
"t_Event": np.int32,
98 "t_eHcal_PU":np.float64,
99 "t_delta_PU":np.float64,
100 "t_p_NoPU": np.float64,
101 "t_eHcal_noPU":np.float64,
102 "t_delta_NoPU":np.float64,
106 f[
"tree"].extend({
"t_Event": merged3[
't_Event'],
107 "t_p_PU": merged3[
't_p_x'].to_numpy(),
108 "t_eHcal_PU": merged3[
't_eHcal_x'].to_numpy(),
109 "t_delta_PU": merged3[
't_delta_x'].to_numpy(),
110 "t_p_NoPU": merged3[
't_p_y'].to_numpy(),
111 "t_eHcal_noPU": merged3[
't_eHcal_y'].to_numpy(),
112 "t_delta_NoPU": merged3[
't_delta_y'].to_numpy(),
113 "t_ieta": merged3[
't_ieta'].to_numpy()})
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)