-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepareSync.py
70 lines (47 loc) · 1.57 KB
/
prepareSync.py
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
64
65
66
67
68
69
70
import ROOT
import math
import optparse
import os, sys
from syncUtils import *
from operator import attrgetter
# define function for parsing options
def parseOptions():
usage = ('usage: %prog [options] datasetList\n'
+ '%prog -h for help')
parser = optparse.OptionParser(usage)
parser.add_option('-i', '--input', dest='inFile', type='string', default="ZZ4lAnalysis.root", help='input file')
parser.add_option('-o', '--output', dest='outFile', type='string', default="CJLSTevents.txt", help='output sync file')
# store options and arguments as global variables
global opt, args
(opt, args) = parser.parse_args()
if not "." in opt.outFile:
print "Please use an extension for the output file (e.g. \".txt\")"
sys.exit()
def loop():
inFileName = opt.inFile
outFileName = opt.outFile
print "Processing file: ",inFileName
cands = []
totCounter = 0
chanCounter = {}
hfile = ROOT.TFile(inFileName)
hCounters = hfile.Get('ZZTree/Counters')
tree = ROOT.TChain()
tree.Add(inFileName+'/ZZTree/candTree')
tree.Add(inFileName+'/ZZTree/candTree_failed')
iEntry = 0
while tree.GetEntry(iEntry):
iEntry +=1
theCand = Candidate(tree)
cands.append(theCand)
# if iEntry == 1500: break
sortedCands = sorted(cands, key=attrgetter('run', 'lumi', 'event'))
outFile = open(outFileName,"w")
line = ''
for aCand in sortedCands:
line += aCand.printOut()
line += "\n"
outFile.write(line)
outFile.close()
parseOptions()
loop()