-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_entries.py
executable file
·198 lines (164 loc) · 7.29 KB
/
get_entries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python
import os, glob, ROOT, subprocess
ROOT.gROOT.SetBatch(True)
c1 = ROOT.TCanvas("c1", "", 800, 600)
def print_entries(root, name):
f = ROOT.TFile.Open(root, "R")
t = f.Get(name)
entries = t.GetEntries()
print root, entries
#yields = t.Integral(0, t.GetSize()-1);
#print root, entries, yields
def print_yields(root, name):
f = ROOT.TFile.Open(root, "R")
t = f.Get(name) # need to be histogram
yields = t.Integral(0, t.GetSize()-1);
print root, yields
def print_content(root, name):
f = ROOT.TFile.Open(root, "R")
t = f.Get(name)
try:
import pandas
except:
print("Failed to import pandas.")
exit()
data, columns = t.AsMatrix(return_labels=True)
df = pandas.DataFrame(data=data, columns=columns)
print ">>> conntent:\n", df
def check_ntuples():
rootfile = "/eos/user/p/prsaha/for_YuWei/all_Data_16_CR_Mgg120_130GeV.root"
tree = "tagsDumper/trees/Data_13TeV_THQHadronicTag"
print_content(rootfile, tree)
#----------------------------------------------------------------------------------------------------
def check_rootfiles_Maxime():
directory = "/eos/user/y/ykao/tPrimeExcessHgg/rootfiles/forMaxime"
os.chdir(directory)
rootfiles = glob.glob("*.root")
for root in rootfiles:
print_entries(root, "t")
def check_produced_ntuples():
path = "/eos/user/y/ykao/tPrimeExcessHgg/merged_ntuples"
tree = "tagsDumper/trees/NRB_13TeV_THQHadronicTag"
directory = path + "/ntuples_qcdGjet_v3p8_201?/*/"
for root in glob.glob(directory + "*root"):
print_entries(root, tree)
def check_merged_ntuples(directory, tag):
path = "/eos/home-y/ykao/tPrimeExcessHgg/rootfiles/" + directory
tree = "tagsDumper/trees/NRB_13TeV_THQHadronicTag"
for root in glob.glob("%s/%s_Era201?.root" % (path, tag)):
print_entries(root, tree)
#print_entries("%s/%s_Era2016.root" % (path, tag), tree)
#print_entries("%s/%s_Era2017.root" % (path, tag), tree)
#print_entries("%s/%s_Era2018.root" % (path, tag), tree)
def check_myhist(tag, sample, directory = "plots"):
hist = "hMass_sideband_%s" % sample
hist = "hfake_photon_IDMVA_%s" % sample
hist = "hMass_pass_BDT_smh_cut_mixed03_%s" % sample
hist = "hMass_pass_BDTG_smh_cut_mixed03_%s" % sample
hist = "hMass_%s" % sample
#subprocess.call('grep "Expected Yields" %s/log/*Tprime*600*' % directory, shell=True)
print_entries("%s/myhist_%s_Era2016.root" % (directory, tag), hist)
print_entries("%s/myhist_%s_Era2017.root" % (directory, tag), hist)
print_entries("%s/myhist_%s_Era2018.root" % (directory, tag), hist)
#print_entries("plots_20210804_v2/myhist_%s_Era2016.root" % tag, hist)
#print_entries("plots_20210804_v2/myhist_%s_Era2017.root" % tag, hist)
#print_entries("plots_20210804_v2/myhist_%s_Era2018.root" % tag, hist)
#print_entries("shortcut_plots/plots_20210725/myhist_%s_Era2016.root" % tag, hist)
#print_entries("shortcut_plots/plots_20210725/myhist_%s_Era2017.root" % tag, hist)
#print_entries("shortcut_plots/plots_20210725/myhist_%s_Era2018.root" % tag, hist)
#print_entries("shortcut_plots/plots_20210725/myhist_combine_RunII.root", hist)
def update_to_my_webpage(myfigure):
directory = "/eos/user/y/ykao/www/tprimetH_THQHadronic/test/"
subprocess.call("mv %s %s" % (myfigure, directory), shell = True)
labels = { #{{{
0 : "ttHJet" ,
11 : "THQ" ,
14 : "GluGluHToGG" ,
15 : "VBF" ,
16 : "VHToGG" ,
2 : "DiPhotonJets" ,
5 : "TTGG" ,
6 : "TTGJets" ,
9 : "TTJets" ,
13 : "TGJets" ,
7 : "VG" ,
18 : "imputed" ,
4 : "QCD" ,
3 : "GJets" ,
27 : "Tprime-M600" ,
28 : "Tprime-M625" ,
29 : "Tprime-M650" ,
30 : "Tprime-M675" ,
31 : "Tprime-M700" ,
32 : "Tprime-M800" ,
33 : "Tprime-M900" ,
34 : "Tprime-M1000" ,
35 : "Tprime-M1100" ,
36 : "Tprime-M1200" ,
} #}}}
def check_mvababy_var(var):
filename = "plots/MVABaby_combine_RunII.root"
filename = "./shortcut_plots/plots_newBase_20210818/MVABaby_combine_RunII.root"
filename = "./plots_20210831_oldWjetCondition/MVABaby_combine_RunII.root"
filename = "/eos/user/y/ykao/tPrimeExcessHgg/rootfiles/plots/plots_newBase_20210818/MVABaby_combine_RunII.root"
filename = "plots/MVABaby_combine_RunII.root"
filename = "/afs/cern.ch/work/y/ykao/tPrimeExcessHgg/CMSSW_10_6_8/src/tprimetH/shortcut_plots/plots_dataDrivenQCD_scaleHT_central/MVABaby_combine_RunII.root"
f1 = ROOT.TFile.Open(filename, "R")
t = f1.Get("t")
h = ROOT.TH1D("h_%s" % var, "", 37, 0, 37)
t.Draw("%s >> h_%s" % (var, var), "")
#h = ROOT.gPad.GetPrimitive("h_%s" % var)
h.SetStats(0)
ids = [0, 11, 14, 15, 16, 2, 5, 6, 9, 7, 18, 4, 3, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
ids = [0, 11, 14, 15, 16, 2, 5, 6, 9, 13, 7, 18, 4, 3, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
print ">>> input file:", filename
for id in sorted(ids):
print ">>> id:%2d, Entry of %-15s = %d" % (id, labels[id], h.GetBinContent(id+1))
output = "mvaBaby_%s.png" % (var)
c1.SaveAs(output)
update_to_my_webpage(output)
#}}}
def check_mvababy(): #{{{
dirs = ["plots", "plots_20210821_lowPhotonID_correlation_study"]
dirs = [
"plots",
"/afs/cern.ch/user/y/ykao/work/tPrimeExcessHgg/CMSSW_10_6_8/src/tprimetH/shortcut_plots/plots_20220110_fakePhotonStudy/"
]
for d in dirs:
for filename in glob.glob(d + "/MVA*GJet*"):
#for filename in glob.glob(d + "/MVA*QCD*"):
#print d, filename
#print_entries(filename, "t")
#print_entries(filename, "t_lowPhotonSideband")
print_entries(filename, "t_fakePhotonIDMVA")
#}}}
if __name__ == "__main__":
#check_mvababy_var("process_id_")
#check_mvababy()
#rootfiles/ntuples_v4.1/tmp/*GJet_Ht*
#check_ntuples()
#check_produced_ntuples()
path = "/afs/cern.ch/work/y/ykao/tPrimeExcessHgg/CMSSW_10_6_8/src/tprimetH"
input_file = "%s/plots" % path
#input_file = "%s/shortcut_plots/plots_20210703_base" % path # base
#check_myhist("TprimeBToTH_M-600", "TprimeBToTH_M-600", input_file)
#input_file = "%s/shortcut_plots/plots_20210725" % path # base
#check_myhist("TprimeBToTH_M-600", "TprimeBToTH_M-600", input_file)
#input_file = "%s/plots_base_20210806" % path # base
#check_myhist("TprimeBToTH_M-600", "TprimeBToTH_M-600", input_file)
#check_myhist("TprimeBToTH_M-600", "TprimeBToTH_M-600")
check_myhist("Data", "Data", "shortcut_plots/plots_20220117_forTemplateFit")
check_myhist("Data", "Data", "plots_20220118_templateFit")
#check_myhist("Data", "Data", "plots_20210907_Maxime_config01")
#check_myhist("Data", "Data", "plots_20210907_Maxime_config02")
#check_myhist("Data", "Data")
#check_myhist("Data", "QCD_GammaJets_imputed")
#check_myhist("DiPhotonJets", "DiPhoton")
#check_myhist("QCD", "QCD")
#check_myhist("GJet_Pt", "GammaJets")
#check_merged_ntuples("ntuples_v3.6", "QCD")
#check_merged_ntuples("ntuples_v3.6", "GJet_Pt")
#check_merged_ntuples("ntuples_v3.8", "QCD")
#check_merged_ntuples("ntuples_v3.8", "GJet_Pt")
#check_merged_ntuples("ntuples_v3.8.1", "QCD")
#check_merged_ntuples("ntuples_v3.8.1", "GJet_Pt")