[Rivet-svn] r2200 - in trunk: . bin doc

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed Dec 23 17:31:38 GMT 2009


Author: hoeth
Date: Wed Dec 23 17:31:37 2009
New Revision: 2200

Log:
New option "RatioPlotMode=deviation" in make-plots

Modified:
   trunk/ChangeLog
   trunk/bin/make-plots
   trunk/doc/make-plots.txt

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Fri Dec 18 15:14:39 2009	(r2199)
+++ trunk/ChangeLog	Wed Dec 23 17:31:37 2009	(r2200)
@@ -1,3 +1,7 @@
+2009-12-23  Hendrik Hoeth <hendrik.hoeth at cern.ch>
+
+	* New option "RatioPlotMode=deviation" in make-plots.
+
 2009-12-14  Hendrik Hoeth <hendrik.hoeth at cern.ch>
 
 	* New option "MainPlot" in make-plots. For people who only want

Modified: trunk/bin/make-plots
==============================================================================
--- trunk/bin/make-plots	Fri Dec 18 15:14:39 2009	(r2199)
+++ trunk/bin/make-plots	Wed Dec 23 17:31:37 2009	(r2200)
@@ -469,8 +469,19 @@
     def __init__(self, inputdata):
         self.refdata=inputdata.description['RatioPlotReference']
         self.yoffset = inputdata.description['PlotSizeY'] + inputdata.description['RatioPlotSizeY']
+        inputdata.description['RatioPlotStage'] = True
         inputdata.description['PlotSizeY'] = inputdata.description['RatioPlotSizeY']
         inputdata.description['LogY'] = False
+        if inputdata.description.has_key('RatioPlotMode') and inputdata.description['RatioPlotMode']=='deviation':
+            inputdata.description['YLabel']='$(\\text{MC}-\\text{data})$'
+            inputdata.description['YMin']=-3.5
+            inputdata.description['YMax']=3.5
+        else:
+            inputdata.description['YLabel']='MC/data'
+            inputdata.description['YMin']=0.5
+            inputdata.description['YMax']=1.5
+        if inputdata.description.has_key('RatioPlotYLabel'):
+            inputdata.description['YLabel']=inputdata.description['RatioPlotYLabel']
         if inputdata.description.has_key('RatioPlotYMin'):
             inputdata.description['YMin']=inputdata.description['RatioPlotYMin']
         if inputdata.description.has_key('RatioPlotYMax'):
@@ -504,8 +515,14 @@
         inputdata.description['DrawOnly'].insert(0,foo)
         for i in inputdata.description['DrawOnly']:
             if i!=self.refdata:
-                inputdata.histos[i].divide(inputdata.histos[self.refdata])
-        inputdata.histos[self.refdata].divide(inputdata.histos[self.refdata])
+                if inputdata.description.has_key('RatioPlotMode') and inputdata.description['RatioPlotMode']=='deviation':
+                    inputdata.histos[i].deviation(inputdata.histos[self.refdata])
+                else:
+                    inputdata.histos[i].divide(inputdata.histos[self.refdata])
+        if inputdata.description.has_key('RatioPlotMode') and inputdata.description['RatioPlotMode']=='deviation':
+            inputdata.histos[self.refdata].deviation(inputdata.histos[self.refdata])
+        else:
+            inputdata.histos[self.refdata].divide(inputdata.histos[self.refdata])
 
     def _draw(self, inputdata):
         out = ""
@@ -560,9 +577,9 @@
 
         labels = Labels(inputdata.description)
         if inputdata.description.has_key('MainPlot') and inputdata.description['MainPlot']=='0':
-            out += labels.draw(['Title','XLabel','RatioPlotYLabel'])
+            out += labels.draw(['Title','XLabel','YLabel'])
         else:
-            out += labels.draw(['XLabel','RatioPlotYLabel'])
+            out += labels.draw(['XLabel','YLabel'])
         return out
 
 
@@ -669,11 +686,6 @@
             if self.description.has_key('YLabelSep'):
                 ylabelsep=float(self.description['YLabelSep'])
             out += ('\\rput(0,1){\\rput[rB]{90}(-%4.3f\\labelsep,0){\\normalsize '%(ylabelsep) +self.description['YLabel']+'}}\n')
-        if self.description.has_key('RatioPlotYLabel') and (axis.count('RatioPlotYLabel') or axis==[]):
-            ylabelsep=5.3
-            if self.description.has_key('YLabelSep'):
-                ylabelsep=float(self.description['YLabelSep'])
-            out += ('\\rput(0,1){\\rput[rB]{90}(-%4.3f\\labelsep,0){\\normalsize '%(ylabelsep) +self.description['RatioPlotYLabel']+'}}\n')
         return out
 
 
@@ -977,7 +989,6 @@
         for i in range(len(self.data)):
             if self.data[i]['LowEdge']==name.data[i]['LowEdge'] and \
                self.data[i]['UpEdge']==name.data[i]['UpEdge']:
-                # FIXME: Is this kind of error calculation correct?
                 try:
                     self.data[i]['Error'][0] /= name.data[i]['Content']
                 except ZeroDivisionError:
@@ -995,6 +1006,28 @@
             else:
                 print '+++ Error in Histogram.divide(): Binning of histograms differs'
 
+    def deviation(self,name):
+        if len(self.data)!=len(name.data):
+            print '+++ Error in Histogram.deviation(): Binning of histograms differs'
+        for i in range(len(self.data)):
+            if self.data[i]['LowEdge']==name.data[i]['LowEdge'] and \
+               self.data[i]['UpEdge']==name.data[i]['UpEdge']:
+                self.data[i]['Content'] -= name.data[i]['Content']
+                try:
+                    self.data[i]['Content'] /= 0.5*(name.data[i]['Error'][0] + name.data[i]['Error'][1])
+                except ZeroDivisionError:
+                    self.data[i]['Content'] = 0.0
+                try:
+                    self.data[i]['Error'][0] /= name.data[i]['Error'][0]
+                except ZeroDivisionError:
+                    self.data[i]['Error'][0] = 0.0
+                try:
+                    self.data[i]['Error'][1] /= name.data[i]['Error'][1]
+                except ZeroDivisionError:
+                    self.data[i]['Error'][1] = 0.0
+            else:
+                print '+++ Error in Histogram.deviation(): Binning of histograms differs'
+
     def draw(self,coors):
         out = ""
         out += self.startclip()
@@ -1370,7 +1403,11 @@
     def draw_majorticklabel(self, value, label=''):
         if label=='':
             label=self.get_ticklabel(value,self.description['LogY'])
-        return ('\\uput[180]{0}(0, '+self.coors.strphys2frameY(value)+'){\\strut{}'+label+'}\n')
+        if self.description.has_key('RatioPlotMode') and self.description['RatioPlotMode']=='deviation' \
+                and self.description.has_key('RatioPlotStage') and self.description['RatioPlotStage']==True:
+            return ('\\uput[180]{0}(0, '+self.coors.strphys2frameY(value)+'){\\strut{}'+label+'\\,$\\sigma$}\n')
+        else:
+            return ('\\uput[180]{0}(0, '+self.coors.strphys2frameY(value)+'){\\strut{}'+label+'}\n')
 
 
 

Modified: trunk/doc/make-plots.txt
==============================================================================
--- trunk/doc/make-plots.txt	Fri Dec 18 15:14:39 2009	(r2199)
+++ trunk/doc/make-plots.txt	Wed Dec 23 17:31:37 2009	(r2200)
@@ -240,6 +240,11 @@
 must specify your reference data ID. This option is used by the
 link:compare-histos.html[`compare-histos`] script.
 
+If you prefer showing `(MC-data)/uncertainty` rather than `MC/data`, you can set
+--------------------
+RatioPlotMode=deviation
+--------------------
+
 In ratio plots the following additional options are available and work in
 a similar way as their regular counterparts:
 


More information about the Rivet-svn mailing list