ATLAS Offline Software
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 # **************************************************************************
10 import ROOT
11 import numpy as np
12 import math
13 
14 def delta_phi(phi1, phi2):
15  output = abs(phi1 - phi2)
16  if output > math.pi:
17  output = math.pi * 2. - output
18  return output
19 
20 def 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 
62 class eFEXAnalyzer():
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)
eFEXNTuple.eFEXAnalyzer.leading_l_id
def leading_l_id(self)
Definition: eFEXNTuple.py:97
eFEXNTuple.eFEXAnalyzer.set_class_type
def set_class_type(self, inputs)
Definition: eFEXNTuple.py:68
eFEXNTuple.delta_R
def delta_R(eta1, phi1, eta2, phi2)
Definition: eFEXNTuple.py:20
eFEXNTuple.eFEXNTupleLoader.__init__
def __init__(self, filename)
Definition: eFEXNTuple.py:24
eFEXNTuple.eFEXNTupleLoader.tfile
tfile
Definition: eFEXNTuple.py:25
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition: TRTCalib_makeplots.cxx:4019
eFEXNTuple.eFEXAnalyzer
Definition: eFEXNTuple.py:62
eFEXNTuple.eFEXNTupleLoader.entries
def entries(self)
Definition: eFEXNTuple.py:28
Get
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,...
Definition: comparitor.cxx:181
eFEXNTuple.eFEXAnalyzer.get_eg_matchedtob_id
def get_eg_matchedtob_id(self)
Definition: eFEXNTuple.py:71
eFEXNTuple.eFEXAnalyzer.is_in_crack
def is_in_crack(self, i_e)
Definition: eFEXNTuple.py:106
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
eFEXNTuple.eFEXAnalyzer.classtype
classtype
Definition: eFEXNTuple.py:64
eFEXNTuple.eFEXNTupleLoader.tree
tree
Definition: eFEXNTuple.py:26
eFEXNTuple.delta_phi
def delta_phi(phi1, phi2)
Definition: eFEXNTuple.py:14
eFEXNTuple.eFEXNTupleLoader.__len__
def __len__(self)
Definition: eFEXNTuple.py:59
eFEXNTuple.eFEXNTupleLoader
Definition: eFEXNTuple.py:23
eFEXNTuple.eFEXAnalyzer.__init__
def __init__(self, inputs)
Definition: eFEXNTuple.py:63