ATLAS Offline Software
Loading...
Searching...
No Matches
maketauturnon.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3
4#***************************************************************************
5# makeplots.py -
6# -------------------
7# begin : 28 03 2020
8# email : tong.qiu@cern.ch
9# **************************************************************************
10import numpy as np
11from eFEXNTuple import *
12from plotlib import *
13import sys
14
15def rebin(binning, data):
16 hist, edge = np.histogram(data, binning)
17 newbin = [edge[0]]
18 total_i = 0
19 for i in range(len(hist)):
20 total_i += hist[i]
21 if total_i > 0:
22 newbin.append(edge[i+1])
23 total_i = 0
24 newbin[-1] = binning[-1]
25 return newbin
26
27def rebin2(binning, data1, data2):
28 hist1, edge = np.histogram(data1, binning)
29 hist2, edge = np.histogram(data2, binning)
30 newbin = [edge[0]]
31 total_1 = 0
32 total_2 = 0
33 for i in range(len(hist1)):
34 total_1 += hist1[i]
35 total_2 += hist2[i]
36 if total_1 > 0 and total_2 > 0:
37 newbin.append(edge[i+1])
38 total_1 = 0
39 total_2 = 0
40 newbin[-1] = binning[-1]
41 return newbin
42
43def turn_on_curve(all_data, selected_data, bins):
44 bins = rebin(bins, all_data)
45 hist_all, edges = np.histogram(all_data, bins)
46 hist_selected, edges = np.histogram(selected_data, bins)
47 bin_centre = [(edges[i] + edges[i+1])/2. for i in range(len(edges)-1)]
48 hist_height = hist_selected / hist_all
49 hist_error = ((hist_selected**0.5 / hist_all)**2. + (hist_all**0.5 * hist_selected / hist_all**2.)**2.)**0.5
50 return (hist_height, bin_centre, hist_error)
51
52def main(path):
53 myntuple = eFEXNTupleLoader(path)
54 all_l_ET = []
55 selected_l_ET_TLV = []
56 selected_l_eta_TLV = []
57 selected_l_ET_Oregon = []
58 selected_l_eta_Oregon = []
59 all_l_eta = []
60 for each in myntuple.entries():
61 each.set_class_type("tau")
62 if each.leading_l_id() is None:
63 continue
64 # if len(each.truth_l_ET)==0:
65 # continue
66 if each.is_in_crack(each.leading_l_id()):
67 continue
68 if abs(each.truth_tauvisible_eta[each.leading_l_id()]) > 2.3:
69 continue
70 # if abs(each.truth_tauvisible_ET[each.leading_l_id()] <= 40):
71 # continue
72 all_l_ET.append(each.truth_tauvisible_ET[each.leading_l_id()])
73 all_l_eta.append(each.truth_tauvisible_eta[each.leading_l_id()])
74 matched_tobs = each.get_eg_matchedtob_id()[each.leading_l_id()]
75 tlv_selected = False
76 oregon_selected = False
77 for i in matched_tobs:
78 if each.eg_tauTLV_Et[i] <= 12:
79 continue
80 if each.eg_tauTLV_Iso[i] < 0.66 and each.eg_tauTLV_Et[i] <= 15:
81 continue
82 tlv_selected = True
83 break
84 for i in matched_tobs:
85 if each.eg_tauOregon_Et[i] <= 12:
86 continue
87 if each.eg_tauOregon_Iso[i] < 0.66 and each.eg_tauOregon_Et[i] <= 15:
88 continue
89 oregon_selected = True
90 break
91 if tlv_selected:
92 selected_l_ET_TLV.append(each.truth_tauvisible_ET[each.leading_l_id()])
93 #selected_l_eta_TLV.append(each.truth_tauvisible_eta[each.leading_l_id()])
94 if oregon_selected:
95 selected_l_ET_Oregon.append(each.truth_tauvisible_ET[each.leading_l_id()])
96 #selected_l_eta_Oregon.append(each.truth_tauvisible_eta[each.leading_l_id()])
97 hist_height, bin_centre, hist_error = turn_on_curve(all_l_ET, selected_l_ET_TLV, range(0,100,5))
98 histplot([bin_centre], [hist_height], [hist_error], errorbar_limit=1, filename="tautlvtrunon")
99 hist_height, bin_centre, hist_error = turn_on_curve(all_l_ET, selected_l_ET_Oregon, range(0,100,5))
100 histplot([bin_centre], [hist_height], [hist_error], errorbar_limit=1, filename="tauoregontrunon")
101 # hist_height, bin_centre, hist_error = turn_on_curve(all_l_eta, selected_l_eta, np.linspace(-2.3,2.3,10))
102 # histplot([bin_centre], [hist_height], [hist_error], errorbar_limit=1, filename="eta", xlabel="eta")
103
104
105if __name__ == "__main__":
106 if len(sys.argv) > 2:
107 print("Error: too many arguments")
108 print("Example: python makeplots.py PATH/TO/INPUT")
109 exit(1)
110 if len(sys.argv) == 1:
111 print("Error: need the path to the input file")
112 print("Example: python makeplots.py PATH/TO/INPUT")
113 print("Info: Using default input file path")
114 inputfile = "myfile.root"
115 else:
116 inputfile = sys.argv[1]
117 main(inputfile)
void print(char *figname, TCanvas *c1)
int main()
Definition hello.cxx:18
turn_on_curve(all_data, selected_data, bins)
rebin2(binning, data1, data2)
rebin(binning, data)
histplot(data_x, data_y, error=None, label=None, **kwargs)
Definition plotlib.py:17