3 from __future__
import print_function
6 from pprint
import pprint
8 commentRE = re.compile (
r'#.*$')
10 if __name__ ==
"__main__":
11 parser = optparse.OptionParser (
"Usage: %prog file1.root [file2.root...]")
12 parser.add_option (
'--loadFromFile', dest=
'loadFromFile', default=[],
15 help=
"Name of text file containing filenames" )
16 parser.add_option (
'--prefix', dest=
'prefix', type=
'string',
18 help=
"Prefix to add to files" )
20 parser.add_option (
'--bx', dest=
'bx', type=
'int',
22 help=
"Bunch crossing to check (0 = in-time)" )
23 (options, args) = parser.parse_args()
25 from DataFormats.FWLite
import Events, Handle
28 for filename
in options.loadFromFile:
29 source = open (filename,
'r')
31 line = commentRE.sub (
'', line).
strip()
35 listOfFiles.append (line)
41 listOfFiles.append( options.prefix + name )
44 raise RuntimeError(
"You have not provided any files")
46 events = Events (listOfFiles)
48 handle = Handle(
'vector<PileupSummaryInfo>')
49 label = (
'addPileupInfo')
57 event.getByLabel (label, handle)
58 pileups = handle.product()
59 for pileup
in pileups:
60 if pileup.getBunchCrossing() == options.bx:
62 if pileup == pileups[-1]
and len(pileups)>1 :
63 raise RuntimeError(
"Requested BX not found in file")
65 num = pileup.getPU_NumInteractions()
67 if num
not in countDict:
72 print(
"total",
int(total),
"\ncounts:")
73 pprint (countDict, width=1)
77 for key, count
in countDict.items():
78 renormDict[key] = count / total