forked from sagittaeri/htt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge-ntup
More file actions
executable file
·63 lines (56 loc) · 2.41 KB
/
merge-ntup
File metadata and controls
executable file
·63 lines (56 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-s', '--student', required=True)
parser.add_argument('-o', '--output', default=None)
parser.add_argument('paths', nargs='+')
args = parser.parse_args()
import re
import os
from glob import glob
from rootpy.io import root_open as ropen
from rootpy.tree import Tree
import ROOT
import logging
log = logging.getLogger('merge-ntup')
if args.output is None:
args.output = '%s.root' % args.student
ds_pattern = re.compile('%s\.(?P<name>.+)\.root$' % (args.student))
with ropen(args.output, 'UPDATE') as outfile:
for path in args.paths:
if os.path.isdir(path):
filenames = glob(os.path.join(path, '*.root'))
else:
filenames = [path]
for filename in filenames:
if os.path.normpath(filename) == os.path.normpath(args.output):
continue
match = re.search(ds_pattern, filename)
if not match:
log.warning("%s is not a valid filename" % filename)
continue
# replace . and - with _ for natural naming in PyTables
name = match.group('name').replace('.', '_').replace('-', '_')
if name in outfile:
log.warning("skipping %s" % filename)
continue
log.info("merging in %s ..." % filename)
with ropen(filename, 'READ') as infile:
intree = infile.tau
intree.deactivate("jet_*_original")
intree.deactivate("jet_antikt4truth*")
intree.deactivate("mcevt_*")
intree.deactivate("mc_*")
intree.activate("mc_event_weight")
intree.activate("mc_weight")
outfile.cd()
outtree = intree.CloneTree(-1, "fast SortBasketsByEntry")
outtree.OptimizeBaskets()
outtree.SetName(name)
outtree.Write(outtree.GetName(), ROOT.TObject.kOverwrite)
# will need to be upated for the next skim
outcutflow = infile.cutflow.Clone(name=name + '_cutflow')
#outcutflow_event = infile.cutflow_event.Clone(name=name + '_cutflow_event')
outfile.cd()
outcutflow.Write(outcutflow.GetName(), ROOT.TObject.kOverwrite)
#outcutflow_event.Write(outcutflow_event.GetName(), ROOT.TObject.kOverwrite)