[Rivet-svn] r4227 - branches/2012-06-aidarivet/bin branches/2012-06-aidarivet/doc trunk/bin trunk/doc

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Mar 18 14:49:01 GMT 2013


Author: fsiegert
Date: Mon Mar 18 14:49:01 2013
New Revision: 4227

Log:
- make-plots: Make Rebin work for variable x-axis binning
- make-plots: Replace EnvelopeRebin option with ErrorType that is used in combination with the Rebin option. This allows to rebin different types of histograms (statistical errors, envelope errors) in the same plot.

Modified:
   branches/2012-06-aidarivet/bin/make-plots
   branches/2012-06-aidarivet/doc/make-plots.txt
   trunk/bin/make-plots
   trunk/doc/make-plots.txt

Modified: branches/2012-06-aidarivet/bin/make-plots
==============================================================================
--- branches/2012-06-aidarivet/bin/make-plots	Mon Mar 18 10:47:37 2013	(r4226)
+++ branches/2012-06-aidarivet/bin/make-plots	Mon Mar 18 14:49:01 2013	(r4227)
@@ -123,9 +123,6 @@
         if self.description.has_key('Rebin'):
             for i in self.histos:
                 self.histos[i].description['Rebin'] = self.description['Rebin']
-        if self.description.has_key('EnvelopeRebin'):
-            for i in self.histos:
-                self.histos[i].description['EnvelopeRebin'] = self.description['EnvelopeRebin']
 
         histoordermap = {}
         histolist = self.histos.keys()
@@ -1320,6 +1317,9 @@
                 self.data[i]['Error'][1] *= scale
         if self.description.has_key('Rebin') and self.description['Rebin']!='':
             rebin=int(self.description['Rebin'])
+            errortype = "stat"
+            if self.description.has_key('ErrorType') and self.description['ErrorType']!='':
+                errortype = self.description['ErrorType']
             newdata=[]
             if rebin>=2:
                 for i in range(0,(len(self.data)/rebin)*rebin,rebin):
@@ -1327,30 +1327,27 @@
                     barl=0.
                     baru=0.
                     for j in range(rebin):
-                        foo +=self.data[i+j]['Content']
-                        barl+=self.data[i+j]['Error'][0]**2
-                        baru+=self.data[i+j]['Error'][1]**2
-                    newdata.append({'LowEdge': self.data[i]['LowEdge'],
-                                    'UpEdge':  self.data[i+rebin-1]['UpEdge'],
-                                    'Content': foo/float(rebin),
-                                    'Error':   [sqrt(barl)/float(rebin),sqrt(baru)/float(rebin)]})
-                self.data=newdata
-        if self.description.has_key('EnvelopeRebin') and self.description['EnvelopeRebin']!='':
-            rebin=int(self.description['EnvelopeRebin'])
-            newdata=[]
-            if rebin>=2:
-                for i in range(0,(len(self.data)/rebin)*rebin,rebin):
-                    newcentral=0.
-                    newmax=0.
-                    newmin=0.
-                    for j in range(rebin):
-                        newcentral +=self.data[i+j]['Content']
-                        newmin +=self.data[i+j]['Content']-self.data[i+j]['Error'][0]
-                        newmax +=self.data[i+j]['Content']+self.data[i+j]['Error'][1]
+                        binwidth=self.data[i+j]['UpEdge']-self.data[i+j]['LowEdge']
+                        foo +=self.data[i+j]['Content']*binwidth
+                        if errortype=="stat":
+                            barl+=(binwidth*self.data[i+j]['Error'][0])**2
+                            baru+=(binwidth*self.data[i+j]['Error'][1])**2
+                        elif errortype=="env":
+                            barl+=(self.data[i+j]['Content']-self.data[i+j]['Error'][0])*binwidth
+                            baru+=(self.data[i+j]['Content']+self.data[i+j]['Error'][1])*binwidth
+                        else:
+                            logging.error("Rebinning for ErrorType not implemented.")
+                            sys.exit(1)
+                    newbinwidth=self.data[i+rebin-1]['UpEdge']-self.data[i]['LowEdge']
+                    newcentral=foo/newbinwidth
+                    if errortype=="stat":
+                        newerror=[sqrt(barl)/newbinwidth,sqrt(baru)/newbinwidth]
+                    elif errortype=="env":
+                        newerror=[(foo-barl)/newbinwidth,(baru-foo)/newbinwidth]
                     newdata.append({'LowEdge': self.data[i]['LowEdge'],
                                     'UpEdge':  self.data[i+rebin-1]['UpEdge'],
-                                    'Content': newcentral/float(rebin),
-                                    'Error':   [(newcentral-newmin)/float(rebin),(newmax-newcentral)/float(rebin)]})
+                                    'Content': newcentral,
+                                    'Error':   newerror})
                 self.data=newdata
 
     def add(self,name):

Modified: branches/2012-06-aidarivet/doc/make-plots.txt
==============================================================================
--- branches/2012-06-aidarivet/doc/make-plots.txt	Mon Mar 18 10:47:37 2013	(r4226)
+++ branches/2012-06-aidarivet/doc/make-plots.txt	Mon Mar 18 14:49:01 2013	(r4227)
@@ -581,19 +581,17 @@
 
 --------------------
 Rebin=<nbins>
+ErrorType=<stat|env>
 --------------------
 Rebin the histogram. Starting with the lowest bin <nbins> bins are combined
 into a new bin. If the number of bins in the histogram is not a multiple of
 <nbins>, the remaining bins at the upper histogram end are silently ignored
 (i.e. if the original histogram has 10 bins and <nbins> is 3, the plotted
 histogram shows three bins combining the bins 1--9 of the original histogram).
-
---------------------
-EnvelopeRebin=<nbins>
---------------------
-Rebin an envelope histogram where the error bars represent an envelope. Thus,
-they are combined linearly instead of as sum of squares. The functionality
-is the same as 'Rebin' otherwise.
+The treatment of the errors is determined by the given ErrorType:
+`stat` (default) assumes the errors are of statistical nature and combines
+them in quadrature sum, while `env` allows to treat errors as envelope of
+various uncertainty runs which are combined linearly.
 
 
 FUNCTION

Modified: trunk/bin/make-plots
==============================================================================
--- trunk/bin/make-plots	Mon Mar 18 10:47:37 2013	(r4226)
+++ trunk/bin/make-plots	Mon Mar 18 14:49:01 2013	(r4227)
@@ -133,9 +133,6 @@
         if self.description.has_key('Rebin'):
             for i in self.histos:
                 self.histos[i].description['Rebin'] = self.description['Rebin']
-        if self.description.has_key('EnvelopeRebin'):
-            for i in self.histos:
-                self.histos[i].description['EnvelopeRebin'] = self.description['EnvelopeRebin']
 
         histoordermap = {}
         histolist = self.histos.keys()
@@ -1330,6 +1327,9 @@
                 self.data[i]['Error'][1] *= scale
         if self.description.has_key('Rebin') and self.description['Rebin']!='':
             rebin=int(self.description['Rebin'])
+            errortype = "stat"
+            if self.description.has_key('ErrorType') and self.description['ErrorType']!='':
+                errortype = self.description['ErrorType']
             newdata=[]
             if rebin>=2:
                 for i in range(0,(len(self.data)/rebin)*rebin,rebin):
@@ -1337,30 +1337,27 @@
                     barl=0.
                     baru=0.
                     for j in range(rebin):
-                        foo +=self.data[i+j]['Content']
-                        barl+=self.data[i+j]['Error'][0]**2
-                        baru+=self.data[i+j]['Error'][1]**2
-                    newdata.append({'LowEdge': self.data[i]['LowEdge'],
-                                    'UpEdge':  self.data[i+rebin-1]['UpEdge'],
-                                    'Content': foo/float(rebin),
-                                    'Error':   [sqrt(barl)/float(rebin),sqrt(baru)/float(rebin)]})
-                self.data=newdata
-        if self.description.has_key('EnvelopeRebin') and self.description['EnvelopeRebin']!='':
-            rebin=int(self.description['EnvelopeRebin'])
-            newdata=[]
-            if rebin>=2:
-                for i in range(0,(len(self.data)/rebin)*rebin,rebin):
-                    newcentral=0.
-                    newmax=0.
-                    newmin=0.
-                    for j in range(rebin):
-                        newcentral +=self.data[i+j]['Content']
-                        newmin +=self.data[i+j]['Content']-self.data[i+j]['Error'][0]
-                        newmax +=self.data[i+j]['Content']+self.data[i+j]['Error'][1]
+                        binwidth=self.data[i+j]['UpEdge']-self.data[i+j]['LowEdge']
+                        foo +=self.data[i+j]['Content']*binwidth
+                        if errortype=="stat":
+                            barl+=(binwidth*self.data[i+j]['Error'][0])**2
+                            baru+=(binwidth*self.data[i+j]['Error'][1])**2
+                        elif errortype=="env":
+                            barl+=(self.data[i+j]['Content']-self.data[i+j]['Error'][0])*binwidth
+                            baru+=(self.data[i+j]['Content']+self.data[i+j]['Error'][1])*binwidth
+                        else:
+                            logging.error("Rebinning for ErrorType not implemented.")
+                            sys.exit(1)
+                    newbinwidth=self.data[i+rebin-1]['UpEdge']-self.data[i]['LowEdge']
+                    newcentral=foo/newbinwidth
+                    if errortype=="stat":
+                        newerror=[sqrt(barl)/newbinwidth,sqrt(baru)/newbinwidth]
+                    elif errortype=="env":
+                        newerror=[(foo-barl)/newbinwidth,(baru-foo)/newbinwidth]
                     newdata.append({'LowEdge': self.data[i]['LowEdge'],
                                     'UpEdge':  self.data[i+rebin-1]['UpEdge'],
-                                    'Content': newcentral/float(rebin),
-                                    'Error':   [(newcentral-newmin)/float(rebin),(newmax-newcentral)/float(rebin)]})
+                                    'Content': newcentral,
+                                    'Error':   newerror})
                 self.data=newdata
 
     def add(self,name):

Modified: trunk/doc/make-plots.txt
==============================================================================
--- trunk/doc/make-plots.txt	Mon Mar 18 10:47:37 2013	(r4226)
+++ trunk/doc/make-plots.txt	Mon Mar 18 14:49:01 2013	(r4227)
@@ -581,19 +581,17 @@
 
 --------------------
 Rebin=<nbins>
+ErrorType=<stat|env>
 --------------------
 Rebin the histogram. Starting with the lowest bin <nbins> bins are combined
 into a new bin. If the number of bins in the histogram is not a multiple of
 <nbins>, the remaining bins at the upper histogram end are silently ignored
 (i.e. if the original histogram has 10 bins and <nbins> is 3, the plotted
 histogram shows three bins combining the bins 1--9 of the original histogram).
-
---------------------
-EnvelopeRebin=<nbins>
---------------------
-Rebin an envelope histogram where the error bars represent an envelope. Thus,
-they are combined linearly instead of as sum of squares. The functionality
-is the same as 'Rebin' otherwise.
+The treatment of the errors is determined by the given ErrorType:
+`stat` (default) assumes the errors are of statistical nature and combines
+them in quadrature sum, while `env` allows to treat errors as envelope of
+various uncertainty runs which are combined linearly.
 
 
 FUNCTION


More information about the Rivet-svn mailing list