ATLAS Offline Software
Loading...
Searching...
No Matches
eFEXNTuple.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# eFEXNTuple.py -
6# -------------------
7# begin : 28 03 2020
8# email : tong.qiu@cern.ch
9# **************************************************************************
10import ROOT
11import numpy as np
12import math
13
14def delta_phi(phi1, phi2):
15 output = abs(phi1 - phi2)
16 if output > math.pi:
17 output = math.pi * 2. - output
18 return output
19
20def delta_R(eta1, phi1, eta2, phi2):
21 return (delta_phi(phi1, phi2)**2. + (eta1 - eta2)**2.)**0.5
22
24 def __init__(self, filename):
25 self.tfile = ROOT.TFile(filename)
26 self.tree = self.tfile.Get("data;1")
27
28 def entries(self):
29 for each_entry in self.tree:
30 entry_dict = {}
31 entry_dict["truth_e_ET"] = np.asarray(each_entry.truth_e_ET)/1000.
32 entry_dict["truth_e_phi"] = np.asarray(each_entry.truth_e_phi)
33 entry_dict["truth_e_eta"] = np.asarray(each_entry.truth_e_eta)
34 entry_dict["eg_eta"] = np.asarray(each_entry.eg_eta) * 0.1 #+ 0.05
35 entry_dict["eg_phi"] = np.asarray(each_entry.eg_phi) * math.pi/32. #+ math.pi / 64# - math.pi)
36 entry_dict["eg_ET"] = np.asarray(each_entry.eg_ET)/1000.
37 entry_dict["eg_wstotnum"] = np.asarray(each_entry.eg_wstotnum)
38 entry_dict["eg_wstotden"] = np.asarray(each_entry.eg_wstotden)
39 entry_dict["eg_rhadnum"] = np.asarray(each_entry.eg_wstotnum)
40 entry_dict["eg_rhadden"] = np.asarray(each_entry.eg_wstotden)
41 entry_dict["eg_retanum"] = np.asarray(each_entry.eg_wstotnum)
42 entry_dict["eg_retaden"] = np.asarray(each_entry.eg_wstotden)
43 entry_dict["eg_haveseed"] = np.asarray(each_entry.eg_haveseed).astype(dtype=bool)
44 entry_dict["eg_nTOBs"] = int(each_entry.eg_nTOBs)
45
46 entry_dict["truth_tauvisible_ET"] = np.asarray(each_entry.truth_tauvisible_ET)/1000.
47 entry_dict["truth_tauvisible_phi"] = np.asarray(each_entry.truth_tauvisible_phi)
48 entry_dict["truth_tauvisible_eta"] = np.asarray(each_entry.truth_tauvisible_eta)
49
50 entry_dict["eg_tauOregon_Et"] = np.asarray(each_entry.eg_tauOregon_Et)/1000.
51 entry_dict["eg_tauOregon_Iso"] = np.asarray(each_entry.eg_tauOregon_Iso)
52 entry_dict["eg_tauTLV_Et"] = np.asarray(each_entry.eg_tauTLV_Et)/1000.
53 entry_dict["eg_tauTLV_Iso"] = np.asarray(each_entry.eg_tauTLV_Iso)
54 # print(entry_dict["truth_e_phi"][0], entry_dict["truth_e_eta"][0])
55 # i = np.argmax(entry_dict["eg_ET"])
56 # print(entry_dict["eg_phi"][i], entry_dict["eg_eta"][i])
57 yield eFEXAnalyzer(entry_dict)
58
59 def __len__(self):
60 return self.tree.GetEntries() - 1
61
63 def __init__(self, inputs):
64 self.classtype = "e"
65 for key, value in inputs.items():
66 setattr(self, key, value)
67
68 def set_class_type(self, inputs):
69 self.classtype = inputs
70
72 output = []
73 if self.classtype == "e":
74 for i_e in range(len(self.truth_e_ET)):
75 tob_id_tem = []
76 for i_tob in range(self.eg_nTOBs):
77 # TODO et selection
78 if self.eg_ET[i_tob] < 15.:
79 continue
80 if delta_R(self.truth_e_eta[i_e], self.truth_e_phi[i_e], self.eg_eta[i_tob], self.eg_phi[i_tob]) > 0.12:
81 continue
82 tob_id_tem.append(i_tob)
83 output.append(tob_id_tem)
84 if self.classtype == "tau":
85 for i_e in range(len(self.truth_tauvisible_ET)):
86 tob_id_tem = []
87 for i_tob in range(self.eg_nTOBs):
88 # TODO et selection
89 # if self.truth_tauvisible_ET[i_tob] < 12.:
90 # continue
91 if delta_R(self.truth_tauvisible_eta[i_e], self.truth_tauvisible_phi[i_e], self.eg_eta[i_tob], self.eg_phi[i_tob]) > 0.12:
92 continue
93 tob_id_tem.append(i_tob)
94 output.append(tob_id_tem)
95 return output
96
97 def leading_l_id(self):
98 if self.classtype == "e":
99 return np.argmax(self.truth_e_ET)
100 if self.classtype == "tau":
101 if len(self.truth_tauvisible_ET) == 0:
102 return None
103 return np.argmax(self.truth_tauvisible_ET)
104
105
106 def is_in_crack(self, i_e):
107 if self.classtype == "e":
108 return (abs(self.truth_e_eta[i_e]) > 1.375 and abs(self.truth_e_eta[i_e]) < 1.52)
109 if self.classtype == "tau":
110 return (abs(self.truth_tauvisible_eta[i_e]) > 1.375 and abs(self.truth_tauvisible_eta[i_e]) < 1.52)
TGraphErrors * GetEntries(TH2F *histo)
__init__(self, inputs)
Definition eFEXNTuple.py:63
set_class_type(self, inputs)
Definition eFEXNTuple.py:68
__init__(self, filename)
Definition eFEXNTuple.py:24
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...
double entries
Definition listroot.cxx:49
delta_phi(phi1, phi2)
Definition eFEXNTuple.py:14
delta_R(eta1, phi1, eta2, phi2)
Definition eFEXNTuple.py:20