[Rivet-svn] r2172 - trunk/pyext

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Dec 10 22:14:08 GMT 2009


Author: holsch
Date: Thu Dec 10 22:14:07 2009
New Revision: 2172

Log:
Add method to renormalise histos.

Modified:
   trunk/pyext/lighthisto.py

Modified: trunk/pyext/lighthisto.py
==============================================================================
--- trunk/pyext/lighthisto.py	Thu Dec 10 18:20:08 2009	(r2171)
+++ trunk/pyext/lighthisto.py	Thu Dec 10 22:14:07 2009	(r2172)
@@ -232,6 +232,31 @@
                              b.getBinCenter()))
         return new
 
+    def renormalise(self, newarea):
+        """ Renormalise histo to newarea """
+        # Construc new histo
+        new = Histo()
+        # Use the same metadata
+        new.path = self.path
+        new.name = self.name
+        new.title = self.title
+        new.xlabel = self.xlabel
+        new.ylabel = self.ylabel
+
+        # The current histogram area
+        oldarea = self.getArea()
+
+        # Iterate over all bins
+        for b in self:
+            # Rescale YValue, YErr+, YErr-
+            newy = b.yval * float(newarea) / oldarea
+            newyerrplus = b.yerrplus * float(newarea) / oldarea
+            newyerrminus = b.yerrminus * float(newarea) / oldarea
+            newbin = Bin(b.xlow, b.xhigh, newy, newyerrplus, newyerrminus, b.focus)
+            new.addBin(newbin)
+
+        return new
+
     ## decorators are only available since Python 2.4
     def fromDPS(cls, dps):
         """Build a histogram from a xml dataPointSet."""


More information about the Rivet-svn mailing list