5 from pprint
import pprint
7 commentRE = re.compile (
r'#.*$')
9 if __name__ ==
"__main__":
10 parser = optparse.OptionParser (
"Usage: %prog file1.root [file2.root...]")
11 parser.add_option (
'--loadFromFile', dest=
'loadFromFile', default=[],
14 help=
"Name of text file containing filenames" )
15 parser.add_option (
'--prefix', dest=
'prefix', type=
'string',
17 help=
"Prefix to add to files" )
19 (options, args) = parser.parse_args()
21 from DataFormats.FWLite
import Events, Handle
24 for filename
in options.loadFromFile:
25 source = open (filename,
'r')
27 line = commentRE.sub (
'', line).
strip()
31 listOfFiles.append (line)
37 listOfFiles.append( options.prefix + name )
40 raise RuntimeError,
"You have not provided any files"
42 events = Events (listOfFiles)
44 handle = Handle(
'PileupSummaryInfo')
45 label = (
'addPileupInfo')
53 event.getByLabel (label, handle)
54 pileup = handle.product()
55 num = pileup.getPU_NumInteractions()
57 if not countDict.has_key (num):
62 print "total", int(total),
"\ncounts:"
63 pprint (countDict, width=1)
67 for key, count
in countDict.iteritems():
68 renormDict[key] = count / total