10 from optparse
import OptionParser
14 usage =
"usage: %prog [options] input_file"
15 parser = OptionParser(usage=usage)
16 parser.add_option (
"-s",
"--subgroups" , action=
"store_true" , dest=
"subgroups" , default=
False, help=
"Include additional subgroups for primary branch groups")
17 parser.add_option (
"-T",
"--TeX" , action=
"store_true" , dest=
"TeX" , default=
False, help=
"Print branch sizes in TeX format")
18 parser.add_option (
"-p",
"--plots" , action=
"store_true" , dest=
"plots" , default=
False, help=
"Create pie plots with fractional fize size for branch groups")
19 parser.add_option (
"-v",
"--debug" , action=
"store_true" , dest=
"debug" , default=
False, help=
"Print verbose output (for debugging)")
20 parser.add_option (
"-f",
"--file" , action=
"store" , dest=
"filename" , default=
"pie", help=
"Filename for output pie chart", type=
"string")
21 parser.add_option (
"-e",
"--ext" , action=
"store" , dest=
"extension" , default=
"png", help=
"Filetype for output pie chart", type=
"string")
22 (options, args) = parser.parse_args()
26 subgroups[
'el'] = [[
'Basic',
'n E Et pt m eta phi px py pz charge author ' +
27 'isEM loose medium mediumIso tight tightIso'],
28 [
'PID',
'electronweight electronbgweight ' +
29 'isolationlikelihood.* softeweight ' +
30 'softebgweight neuralnet Hmatrix Hmatrix5 ' +
31 'adaboost softeneuralnet '],
32 [
'Conv',
'.*conv.* .*Conv.*'],
33 [
'Truth',
'type origin truth_.*'],
34 [
'Calo',
'Ethad Ethad1 f1 f1core Emins1 fside Emax2 ' +
35 'ws3 wstot emaxs1 deltaEs E233 E237 E277 ' +
36 'weta2 f3 f3core rphiallcalo reta rphi ' +
38 [
'Iso',
'Etcone.* ptcone.* Etring.* isIso'],
39 [
'Track',
'deltaeta1 deltaeta2 deltaphi2 deltaphiRescaled '+
40 'track.* n.*Hits n.*Holes n.*Outliers ' +
41 'vert.* hastrack TRT.*Ratio etacorrmag'],
42 [
'Pointing',
'zvertex errz etap depth'],
43 [
'Brem',
'brem.* refitted.* hasbrem'],
44 [
'Cluster',
'Es[0-3] etas[0-3] phis[0-3] cl_.*'],
45 [
'Forward',
'firstEdens cellmaxfrac longitudinal ' +
46 'secondlambda lateral secondR centerlambda'],
47 [
'Rawcl',
'rawcl_.*'],
48 [
'Jettruth',
'jet_truth_.*'],
50 [
'Trigger',
'L1_.* L2_.* EF.*'],
56 text_format =
'%(name)-10s %(nbr)5s %(nobj)7s %(nobjper)7s %(totsiz)8s %(totsizper)8s %(filesiz)8s %(filesizper)9s %(comp)4s'
57 sg_text_format = text_format.replace (
'(name)-',
'(name)')
59 tex_format =
'%(name)-10s&%(nbr)5s&%(nobj)7s&%(nobjper)7s&%(totsiz)8s&%(totsizper)8s&%(filesiz)8s&%(filesizper)9s&%(comp)4s \\\\'
60 sg_tex_format = tex_format
64 sg_format = sg_tex_format
67 sg_format = sg_text_format
80 sglist = subgroups.get (self.
name)
81 if not sglist:
return None
83 for (sgname, pats)
in sglist:
84 for p
in pats.split():
85 pp = self.
name +
'_' + p +
'$'
86 if re.match (pp, bname):
92 sg = Branchgroup (sgname)
103 if bname == self.
name +
'_n':
105 for i
in range(b.GetEntries()):
107 self.
totobj +=
int(b.GetLeaf(bname).GetValue())
109 if options.subgroups:
123 d[
'name'] = self.
name
124 d[
'nbr'] = `self.
nbr`
128 d[
'totsizper'] =
"%.2fk" % (
float(self.
totbytes) / 1024 / nev )
138 print '\\begin{tabular}{|l|r|r|r|r|r|r|r|r|}'
144 d[
'nobjper'] =
'Nobj/ev'
145 d[
'totsiz'] =
'Totsz'
146 d[
'totsizper'] =
'Totsz/ev'
147 d[
'filesiz'] =
'Filesz'
148 d[
'filesizper'] =
'Filesz/ev'
150 print Branchgroup.format % d
156 print Branchgroup.format % self.
get_dict (nev)
159 sl.sort (
lambda a, b:
int(b.filebytes - a.filebytes))
161 print Branchgroup.sg_format % sg.get_dict (nev)
168 print '\\end{tabular}'
183 for kk
in self.
rfile.GetListOfKeys():
184 if (kk.GetClassName() ==
'TTree' and
185 kk.GetName() !=
'CollectionTree'):
192 ll = bname.split (
'_')
193 if bname
in [
'RunNumber',
205 elif (bname.endswith (
'Error')
or bname.endswith (
'Flags')):
211 group = Branchgroup (gname)
221 raise Exception (
"Can't find tree name in file.")
224 raise Exception (
"Can't find tree " + self.
treename +
" in file.")
231 for b
in self.
tree.GetListOfBranches():
238 print "Number of events:", self.
nev
243 bl.sort (
lambda a, b:
int(b.filebytes - a.filebytes))
244 Branchgroup.print_header()
246 bg.print_stats (self.
nev)
247 Branchgroup.print_trailer()
254 print "Number of branch groups:", len(self.
branchgroups)
258 blist.sort (
lambda a, b:
int(b.filebytes - a.filebytes))
259 pie = ROOT.TPie(
"BranchPie",
"", len(self.
branchgroups))
260 for i, bgroup
in enumerate( blist ):
261 bginfo = bgroup.get_dict(self.
nev)
264 print "Branch group #%d, named %s with size %f = %f%%" % (i , bginfo[
'name'], (
float(bgroup.filebytes) / 1024 / self.
nev ), (100. *
float(bgroup.filebytes) /
float(self.
file_size)) )
266 pie.SetEntryLabel(i, bginfo[
'name'])
268 pie.SetEntryFillColor(i, i+2)
271 c1 = ROOT.TCanvas(
'c1' ,
'c1' )
273 pie.SetCircle(.5,.45,.2)
274 pie.SetLabelFormat(
"#splitline{%txt}{(%perc)}")
275 pie.SetLabelFormat(
"%txt")
277 pie.SetTextSize(0.03)
278 pie.SetCircle(0.4808696, 0.7940109, 0.2)
279 pie.SetValueFormat(
"%4.2f")
280 pie.SetLabelFormat(
"%txt")
281 pie.SetPercentFormat(
"%3.1f")
282 pie.SetLabelsOffset(0.005)
283 pie.SetAngularOffset(265.2655)
284 leg = ROOT.TLegend(0.05580866, 0.06554878, 0.785877, 0.4512195)
285 for i, bgroup
in enumerate( blist ):
287 pie.SetEntryRadiusOffset(i,.07)
288 bginfo = bgroup.get_dict(self.
nev)
289 leg.AddEntry( pie.GetSlice(i),
"%s : %1.1lf%%" % (bginfo[
'name'] , 100. *
float(bgroup.filebytes) /
float(self.
file_size)) ,
"f" )
291 pie.SetEntryLabel(i,
"")
299 c1.SaveAs(options.filename +
"." + options.extension)
305 ff = Filestats (args[0])
306 ff.print_stats_text()