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 from __future__ import division
11 import ROOT
12 import numpy as np
13 import math
14 
15 def delta_phi(phi1, phi2):
16  output = abs(phi1 - phi2)
17  if output > math.pi:
18  output = math.pi * 2. - output
19  return output
20 
21 def delta_R(eta1, phi1, eta2, phi2):
22  return (delta_phi(phi1, phi2)**2. + (eta1 - eta2)**2.)**0.5
23 
25  def __init__(self, filename):
26  self.tfile = ROOT.TFile(filename)
27  self.tree = self.tfile.Get("data;1")
28 
29  def entries(self):
30  for each_entry in self.tree:
31  entry_dict = {}
32  entry_dict["truth_e_ET"] = np.asarray(each_entry.truth_e_ET)/1000.
33  entry_dict["truth_e_phi"] = np.asarray(each_entry.truth_e_phi)
34  entry_dict["truth_e_eta"] = np.asarray(each_entry.truth_e_eta)
35  entry_dict["eg_eta"] = np.asarray(each_entry.eg_eta) * 0.1 #+ 0.05
36  entry_dict["eg_phi"] = np.asarray(each_entry.eg_phi) * math.pi/32. #+ math.pi / 64# - math.pi)
37  entry_dict["eg_ET"] = np.asarray(each_entry.eg_ET)/1000.
38  entry_dict["eg_wstotnum"] = np.asarray(each_entry.eg_wstotnum)
39  entry_dict["eg_wstotden"] = np.asarray(each_entry.eg_wstotden)
40  entry_dict["eg_rhadnum"] = np.asarray(each_entry.eg_wstotnum)
41  entry_dict["eg_rhadden"] = np.asarray(each_entry.eg_wstotden)
42  entry_dict["eg_retanum"] = np.asarray(each_entry.eg_wstotnum)
43  entry_dict["eg_retaden"] = np.asarray(each_entry.eg_wstotden)
44  entry_dict["eg_haveseed"] = np.asarray(each_entry.eg_haveseed).astype(dtype=bool)
45  entry_dict["eg_nTOBs"] = int(each_entry.eg_nTOBs)
46 
47  entry_dict["truth_tauvisible_ET"] = np.asarray(each_entry.truth_tauvisible_ET)/1000.
48  entry_dict["truth_tauvisible_phi"] = np.asarray(each_entry.truth_tauvisible_phi)
49  entry_dict["truth_tauvisible_eta"] = np.asarray(each_entry.truth_tauvisible_eta)
50 
51  entry_dict["eg_tauOregon_Et"] = np.asarray(each_entry.eg_tauOregon_Et)/1000.
52  entry_dict["eg_tauOregon_Iso"] = np.asarray(each_entry.eg_tauOregon_Iso)
53  entry_dict["eg_tauTLV_Et"] = np.asarray(each_entry.eg_tauTLV_Et)/1000.
54  entry_dict["eg_tauTLV_Iso"] = np.asarray(each_entry.eg_tauTLV_Iso)
55  # print(entry_dict["truth_e_phi"][0], entry_dict["truth_e_eta"][0])
56  # i = np.argmax(entry_dict["eg_ET"])
57  # print(entry_dict["eg_phi"][i], entry_dict["eg_eta"][i])
58  yield eFEXAnalyzer(entry_dict)
59 
60  def __len__(self):
61  return self.tree.GetEntries() - 1
62 
63 class eFEXAnalyzer():
64  def __init__(self, inputs):
65  self.classtype = "e"
66  for key, value in inputs.items():
67  setattr(self, key, value)
68 
69  def set_class_type(self, inputs):
70  self.classtype = inputs
71 
73  output = []
74  if self.classtype == "e":
75  for i_e in range(len(self.truth_e_ET)):
76  tob_id_tem = []
77  for i_tob in range(self.eg_nTOBs):
78  # TODO et selection
79  if self.eg_ET[i_tob] < 15.:
80  continue
81  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:
82  continue
83  tob_id_tem.append(i_tob)
84  output.append(tob_id_tem)
85  if self.classtype == "tau":
86  for i_e in range(len(self.truth_tauvisible_ET)):
87  tob_id_tem = []
88  for i_tob in range(self.eg_nTOBs):
89  # TODO et selection
90  # if self.truth_tauvisible_ET[i_tob] < 12.:
91  # continue
92  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:
93  continue
94  tob_id_tem.append(i_tob)
95  output.append(tob_id_tem)
96  return output
97 
98  def leading_l_id(self):
99  if self.classtype == "e":
100  return np.argmax(self.truth_e_ET)
101  if self.classtype == "tau":
102  if len(self.truth_tauvisible_ET) == 0:
103  return None
104  return np.argmax(self.truth_tauvisible_ET)
105 
106 
107  def is_in_crack(self, i_e):
108  if self.classtype == "e":
109  return (abs(self.truth_e_eta[i_e]) > 1.375 and abs(self.truth_e_eta[i_e]) < 1.52)
110  if self.classtype == "tau":
111  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:98
eFEXNTuple.eFEXAnalyzer.set_class_type
def set_class_type(self, inputs)
Definition: eFEXNTuple.py:69
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
eFEXNTuple.delta_R
def delta_R(eta1, phi1, eta2, phi2)
Definition: eFEXNTuple.py:21
eFEXNTuple.eFEXNTupleLoader.__init__
def __init__(self, filename)
Definition: eFEXNTuple.py:25
eFEXNTuple.eFEXNTupleLoader.tfile
tfile
Definition: eFEXNTuple.py:26
eFEXNTuple.eFEXAnalyzer
Definition: eFEXNTuple.py:63
eFEXNTuple.eFEXNTupleLoader.entries
def entries(self)
Definition: eFEXNTuple.py:29
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:178
eFEXNTuple.eFEXAnalyzer.get_eg_matchedtob_id
def get_eg_matchedtob_id(self)
Definition: eFEXNTuple.py:72
eFEXNTuple.eFEXAnalyzer.is_in_crack
def is_in_crack(self, i_e)
Definition: eFEXNTuple.py:107
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
eFEXNTuple.eFEXAnalyzer.classtype
classtype
Definition: eFEXNTuple.py:65
eFEXNTuple.eFEXNTupleLoader.tree
tree
Definition: eFEXNTuple.py:27
eFEXNTuple.delta_phi
def delta_phi(phi1, phi2)
Definition: eFEXNTuple.py:15
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
eFEXNTuple.eFEXNTupleLoader.__len__
def __len__(self)
Definition: eFEXNTuple.py:60
eFEXNTuple.eFEXNTupleLoader
Definition: eFEXNTuple.py:24
eFEXNTuple.eFEXAnalyzer.__init__
def __init__(self, inputs)
Definition: eFEXNTuple.py:64