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