1 from PhysicsTools.NanoAODTools.postprocessing.framework.treeReaderArrayTools
import InputTree
4 ROOT.PyConfig.IgnoreCommandLineOptions =
True 9 'isPrompt': (1 << 0),
'fromHardProcess': (1 << 8),
10 'isDecayedLeptonHadron': (1 << 1),
'isHardProcessTauDecayProduct': (1 << 9),
11 'isTauDecayProduct': (1 << 2),
'isDirectHardProcessTauDecayProduct': (1 << 10),
12 'isPromptTauDecayProduct': (1 << 3),
'fromHardProcessBeforeFSR': (1 << 11),
13 'isDirectTauDecayProduct': (1 << 4),
'isFirstCopy': (1 << 12),
14 'isDirectPromptTauDecayProduct': (1 << 5),
'isLastCopy': (1 << 13),
15 'isDirectHadronDecayProduct': (1 << 6),
'isLastCopyBeforeFSR': (1 << 14),
16 'isHardProcess': (1 << 7),
21 """Class that allows seeing an entry of a PyROOT TTree as an Event""" 26 self.
_tree.gotoEntry(entry)
29 if name
in self.__dict__:
30 return self.__dict__[name]
37 """Evaluate an expression, as TTree::Draw would do. 39 This is added for convenience, but it may perform poorly and the implementation is not bulletproof, 40 so it's better to rely on reading values, collections or objects directly 42 if not hasattr(self.
_tree,
'_exprs'):
43 self.
_tree._exprs = {}
46 warnings.filterwarnings(action=
'ignore', category=RuntimeWarning,
47 message=
'creating converter for unknown type "const char\\*\\*"$')
48 warnings.filterwarnings(action=
'ignore', category=RuntimeWarning,
49 message=
'creating converter for unknown type "const char\\*\\[\\]"$')
50 if expr
not in self.
_tree._exprs:
51 formula = ROOT.TTreeFormula(expr, expr, self.
_tree)
52 if formula.IsInteger():
53 formula.go = formula.EvalInstance64
55 formula.go = formula.EvalInstance
56 self.
_tree._exprs[expr] = formula
63 formula = self.
_tree._exprs[expr]
70 """Class that allows seeing a set branches plus possibly an index as an Object""" 78 if name
in self.__dict__:
79 return self.__dict__[name]
80 if name[:2] ==
"__" and name[-2:] ==
"__":
86 val = ord(val)
if type(val) == str
else val
87 self.__dict__[name] = val
93 def p4(self, corr_pt=None):
94 """Create TLorentzVector for this particle.""" 95 ret = ROOT.TLorentzVector()
97 ret.SetPtEtaPhiM(self.pt, self.eta, self.phi, self.mass)
99 ret.SetPtEtaPhiM(corr_pt, self.eta, self.phi, self.mass)
103 if isinstance(other, ROOT.TLorentzVector):
104 deta =
abs(other.Eta() - self.eta)
105 dphi =
abs(other.Phi() - self.phi)
107 deta =
abs(other.eta - self.eta)
108 dphi =
abs(other.phi - self.phi)
109 while dphi > math.pi:
110 dphi =
abs(dphi - 2 * math.pi)
111 return math.sqrt(dphi**2 + deta**2)
114 """Find if bit for statusflag is set (for GenPart only).""" 115 return (self.statusFlags & statusflags[flag])==statusflags[flag]
132 self.
_len = getattr(event, lenVar)
134 self.
_len = getattr(event,
"n" + prefix)
138 if type(index) == int
and index
in self.
_cache:
140 if index >= self.
_len:
141 raise IndexError(
"Invalid index %r (len is %r) at %s" % (index, self.
_len, self.
_prefix))
143 raise IndexError(
"Invalid index %r (negative) at %s" % (index, self.
_prefix))
145 if type(index) == int:
def __getattr__(self, name)
def __getitem__(self, index)
def __getitem__(self, attr)
def __getattr__(self, name)
def p4(self, corr_pt=None)
def __getitem__(self, attr)
def __init__(self, event, prefix, index=None)
Abs< T >::type abs(const T &t)
def __init__(self, tree, entry)
def __init__(self, event, prefix, lenVar=None)
def statusflag(self, flag)