Go to the documentation of this file.00001
00002
00003 import optparse
00004 import re
00005 from pprint import pprint
00006
00007 commentRE = re.compile (r'#.*$')
00008
00009 if __name__ == "__main__":
00010 parser = optparse.OptionParser ("Usage: %prog file1.root [file2.root...]")
00011 parser.add_option ('--loadFromFile', dest='loadFromFile', default=[],
00012 type='string',
00013 action='append',
00014 help="Name of text file containing filenames" )
00015 parser.add_option ('--prefix', dest='prefix', type='string',
00016 default='',
00017 help="Prefix to add to files" )
00018
00019 parser.add_option ('--bx', dest='bx', type='int',
00020 default='0',
00021 help="Bunch crossing to check (0 = in-time)" )
00022 (options, args) = parser.parse_args()
00023 import ROOT
00024 from DataFormats.FWLite import Events, Handle
00025
00026 listOfFiles = args[:]
00027 for filename in options.loadFromFile:
00028 source = open (filename, 'r')
00029 for line in source:
00030 line = commentRE.sub ('', line).strip()
00031 if not line:
00032
00033 continue
00034 listOfFiles.append (line)
00035 source.close()
00036 if options.prefix:
00037 oldList = listOfFiles
00038 listOfFiles = []
00039 for name in oldList:
00040 listOfFiles.append( options.prefix + name )
00041
00042 if not listOfFiles:
00043 raise RuntimeError, "You have not provided any files"
00044
00045 events = Events (listOfFiles)
00046
00047 handle = Handle('vector<PileupSummaryInfo>')
00048 label = ('addPileupInfo')
00049
00050 ROOT.gROOT.SetBatch()
00051
00052
00053 countDict = {}
00054 total = 0.
00055 for event in events:
00056 event.getByLabel (label, handle)
00057 pileups = handle.product()
00058 for pileup in pileups:
00059 if pileup.getBunchCrossing() == options.bx:
00060 break
00061 if pileup == pileups[-1] and len(pileups)>1 :
00062 raise RuntimeError, "Requested BX not found in file"
00063
00064 num = pileup.getPU_NumInteractions()
00065 total += 1
00066 if not countDict.has_key (num):
00067 countDict[num] = 1
00068 else:
00069 countDict[num] += 1
00070
00071 print "total", int(total), "\ncounts:"
00072 pprint (countDict, width=1)
00073 print "normalized:"
00074
00075 renormDict = {}
00076 for key, count in countDict.iteritems():
00077 renormDict[key] = count / total
00078 pprint (renormDict)
00079