Permalink
Browse files

Add freqhist action

  • Loading branch information...
1 parent fcc8775 commit 74ae0c2294780fedc448a48a65f5bfa576d7eca8 @pwaller pwaller committed Sep 11, 2011
Showing with 37 additions and 0 deletions.
  1. +12 −0 utils/generate_pdgid_to_root_table.py
  2. +25 −0 weboot/resources/root/object.py
View
12 utils/generate_pdgid_to_root_table.py
@@ -0,0 +1,12 @@
+#! /usr/bin/env python
+
+import mcviz.utils.svg.texglyph as T
+from yaml import safe_dump
+
+result = {}
+
+db = T.read_pythia_particle_db()
+for pdgid, label, gd in sorted(db.values()):
+ result[pdgid] = T.particle_to_latex(gd, True)
+
+print safe_dump(result)
View
25 weboot/resources/root/object.py
@@ -115,7 +115,32 @@ def __getitem__(self, what):
elif what == "!rebin":
return HistogramRebinned.from_parent(self, "!rebin", self.o)
+ elif what == "!freqhist":
+ return FreqHist.from_parent(self, "!freqhist", self.o)
+
elif what == "!tohist":
return DrawTTree.from_parent(self, "!tohist", self.o)
+class FreqHist(RootObject):
+ def __init__(self, request, root_object):
+ from cPickle import loads
+ freqs = loads(root_object.ReadObj().GetString().Data())
+ total = sum(freqs.values())
+ n = len(freqs)
+
+ root_object = R.TH1F("frequencies", "frequencies;frequencies;%", n, 0, n)
+
+ from yaml import load
+ pdgs = load(open("pdg.yaml"))
+
+ for i, (pdgid, value) in enumerate(sorted(freqs.iteritems(), key=lambda (k, v): v, reverse=True), 1):
+ root_object.SetBinContent(i, value)
+ root_object.SetBinError(i, value**0.5)
+ root_object.GetXaxis().SetBinLabel(i, pdgs.get(pdgid, "?"))
+
+ root_object.GetXaxis().SetLabelSize(0.02)
+
+ root_object.Scale(100. / total)
+ super(FreqHist, self).__init__(request, root_object)
+

0 comments on commit 74ae0c2

Please sign in to comment.