-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompare_Histos_Script.py
More file actions
144 lines (95 loc) · 3.02 KB
/
Compare_Histos_Script.py
File metadata and controls
144 lines (95 loc) · 3.02 KB
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
import ROOT
import matplotlib.pyplot as plt
import numpy as np
root_file_1 = ROOT.TFile.Open("PUjetID_No_Weights.root","READ")
root_keys_1 = root_file_1.GetListOfKeys()
# print(type(root_keys_1))
# file_1_folder_list = []
for key in root_keys_1:
key_obj = key.ReadObj()
folder_name = key_obj.GetName()
# file_1_folder_list.append(folder_name)
# print(file_1_folder_list)
root_file_1.cd("NDiJetCombinations")
# root_keys_2 = root_file_1.GetListOfKeys()
# for key in root_keys_2:
# key_obj = key.ReadObj()
# folder_name = key_obj.GetName()
# file_1_folder_list.append(folder_name)
# print(file_1_folder_list)
canvas_1 = root_file_1.Get("NDiJetCombinations/FirstLeadingJetEta")
# list_1 = canvas_1.GetListOfPrimitives()
# for name in list_1:
# print(name.GetName())
# print(type(name))
top_1 = canvas_1.GetPrimitive("top")
# top_list = top.GetListOfPrimitives()
# print("Top list: ")
# for name in top_list:
# print(name.GetName())
# print(type(name))
MC_histos_1 = top_1.GetPrimitive("FirstLeadingJetEta")
# MC_list = MC_histos.ls()
MC_sum_1 = MC_histos_1.GetStack().Last()
number_of_bins_1 = MC_sum_1.GetNbinsX()
PU_Jet_No_Weights = []
for i in range(number_of_bins_1+1):
bin_content = MC_sum_1.GetBinContent(i)
# print("Bin "+str(i)+" has: "+str(bin_content))
PU_Jet_No_Weights.append(bin_content)
root_file_1.Close()
######### 2nd root file #########
root_file_2 = ROOT.TFile.Open("PUJetID_with_Weights.root","READ")
root_keys_2 = root_file_2.GetListOfKeys()
for key in root_keys_2:
key_obj = key.ReadObj()
folder_name = key_obj.GetName()
root_file_2.cd("NDiJetCombinations")
canvas_2 = root_file_2.Get("NDiJetCombinations/FirstLeadingJetEta")
top_2 = canvas_2.GetPrimitive("top")
MC_histos_2 = top_2.GetPrimitive("FirstLeadingJetEta")
MC_sum_2 = MC_histos_2.GetStack().Last()
number_of_bins_2 = MC_sum_2.GetNbinsX()
PU_Jet_With_Weights = []
for i in range(number_of_bins_2+1):
bin_content = MC_sum_2.GetBinContent(i)
# print("Bin "+str(i)+" has: "+str(bin_content))
PU_Jet_With_Weights.append(bin_content)
ratio = []
event_diff = []
for i, j in zip(PU_Jet_No_Weights, PU_Jet_With_Weights):
if i == 0.0:
ratio.append(1)
# elif (j/i) > 5 :
# ratio.append(1)
else:
ratio.append(j/i)
event_diff.append(j-i)
# for i in range(len(ratio)):
# print("Bin "+str(i)+" has ratio: "+str(ratio[i]))
# x_points = list(range(len(ratio)))
x_points = np.linspace(-5,5,101)
list(x_points.tolist())
print(ratio)
# del x_points[0]
# del ratio[0]
# plt.scatter(x_points, event_diff)
# plt.show()
plt.scatter(x_points, ratio)
plt.axhline(y=1.0, color='r', linestyle='-')
plt.suptitle("Ratio of with Weights to No Weights in FirstLeadingJetEta")
plt.show()
# max_content = MC_sum.GetMaximum()
# print(max_content)
# print("MC histos list: ")
# for name in MC_list:
# print(name.GetName())
# print(type(name))
# bottom = canvas_1.GetPrimitive("bottom")
# bottom_list = bottom.GetListOfPrimitives()
# print("Bottom list: ")
# for name in bottom_list:
# print(name.GetName())
# print(type(name))
# root_file.Purge()
root_file_2.Close()