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 parser.add_option (
'--bx', dest=
'bx', type=
'int',
21 help=
"Bunch crossing to check (0 = in-time)" )
22 (options, args) = parser.parse_args()
24 from DataFormats.FWLite
import Events, Handle
27 for filename
in options.loadFromFile:
28 source = open (filename,
'r') 30 line = commentRE.sub (
'', line).
strip()
34 listOfFiles.append (line)
40 listOfFiles.append( options.prefix + name )
43 raise RuntimeError(
"You have not provided any files")
45 events = Events (listOfFiles)
47 handle = Handle(
'vector<PileupSummaryInfo>')
48 label = (
'addPileupInfo')
56 event.getByLabel (label, handle)
57 pileups = handle.product()
58 for pileup
in pileups:
59 if pileup.getBunchCrossing() == options.bx:
61 if pileup == pileups[-1]
and len(pileups)>1 :
62 raise RuntimeError(
"Requested BX not found in file")
64 num = pileup.getPU_NumInteractions()
66 if num
not in countDict:
71 print "total",
int(total),
"\ncounts:" 72 pprint (countDict, width=1)
76 for key, count
in countDict.iteritems():
77 renormDict[key] = count / total