All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions
lib.glob Namespace Reference

Classes

class  NTupleProc
 
class  NTupleGlob
 

Functions

def _makedf
 
def _loaddf
 
def _process
 
def _do_process
 

Function Documentation

def lib.glob._do_process (   rootf,
  branches,
  vars,
  whens,
  bins 
)
private

Definition at line 84 of file glob.py.

84 
85 def _do_process(rootf, branches, vars, whens, bins):
86  hists = {}
87 
88  dfW = _makedf(rootf[names.folderW][names.tname].arrays(branches, library="pd"))
89  dfE = _makedf(rootf[names.folderE][names.tname].arrays(branches, library="pd"))
90 
91  valW = [v(dfW) for v in vars]
92  valE = [v(dfE) for v in vars]
93 
94  wW = [w(dfW) if w else None for w in whens]
95  wE = [w(dfE) if w else None for w in whens]
96 
97  runs = dfW.meta.run.unique()
98 
99  hists["W"] = {}
100  for r in runs:
101  hists["W"][r] = {}
102  for val, var in zip(valW, vars):
103  hists["W"][r][var.name] = {}
104  for w, when in zip(wW, whens):
105  if w is None:
106  hist = np.histogram(val[dfW.meta.run == r], bins=bins)
107  else:
108  hist = np.histogram(val[w & (dfW.meta.run == r)], bins=bins)
109 
110  hists["W"][r][var.name][when.name] = hist
111 
112  hists["E"] = {}
113  for r in runs:
114  hists["E"][r] = {}
115  for val, var in zip(valE, vars):
116  hists["E"][r][var.name] = {}
117  for w, when in zip(wE, whens):
118  if w is None:
119  hist = np.histogram(val[dfE.meta.run == r], bins=bins)
120  else:
121  hist = np.histogram(val[w & (dfE.meta.run == r)], bins=bins)
122 
123  hists["E"][r][var.name][when.name] = hist
124 
125  return hists
def _makedf
Definition: glob.py:33
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
def _do_process
Definition: glob.py:84
def lib.glob._loaddf (   inp)
private

Definition at line 56 of file glob.py.

56 
57 def _loaddf(inp):
58  fname, branches, index, applyf = inp
59  with uproot.open(fname) as f:
60  dfW = _makedf(f[names.folderW][names.tname].arrays(branches, library="pd"))
61  dfE = _makedf(f[names.folderE][names.tname].arrays(branches, library="pd"))
62  if applyf:
63  dfW = applyf(*dfW)
64  dfE = applyf(*dfE)
65  else:
66  dfW = dfW[0]
67  dfE = dfE[0]
68  # Set an index on the NTuple number to make sure we keep track of what is where
69  dfW["__ntuple"] = index
70  dfW.set_index("__ntuple", append=True, inplace=True)
71  dfW = dfW.reorder_levels([dfW.index.nlevels-1] + list(range(0, dfW.index.nlevels-1)))
72 
73  dfE["__ntuple"] = index + 1
74  dfE.set_index("__ntuple", append=True, inplace=True)
75  dfE = dfE.reorder_levels([dfE.index.nlevels-1] + list(range(0, dfE.index.nlevels-1)))
76 
77  dfW = dfW.append(dfE)
78  return dfW
def _makedf
Definition: glob.py:33
def _loaddf
Definition: glob.py:56
list
Definition: file_to_url.sh:28
def lib.glob._makedf (   dfs)
private

Definition at line 33 of file glob.py.

33 
34 def _makedf(dfs):
35  if not isinstance(dfs, tuple):
36  assert(isinstance(dfs, pd.DataFrame))
37  dfs = [dfs]
38  else:
39  dfs = list(dfs)
40 
41  npad = [max([len(b.split(".")) for b in df.columns]) for df in dfs]
42  def pad(b, i):
43  while len(b) < npad[i]:
44  b.append("")
45  return tuple(b)
46 
47  for i in range(len(dfs)):
48  dfs[i].columns = pd.MultiIndex.from_tuples([pad(b.split("."), i) for b in dfs[i].columns])
49 
50  # set the index name if not present
51  for i in range(len(dfs)):
52  if len(dfs[i].index.names) == 1 and dfs[i].index.names[0] is None:
53  dfs[i].index = dfs[i].index.set_names(["entry"])
54 
55  return dfs
def _makedf
Definition: glob.py:33
list
Definition: file_to_url.sh:28
def lib.glob._process (   inp)
private

Definition at line 79 of file glob.py.

79 
80 def _process(inp):
81  fname = inp[0]
82  with uproot.open(fname) as f:
83  return _do_process(f, *inp[1:])
def _process
Definition: glob.py:79
def _do_process
Definition: glob.py:84