ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/StackMaker.py
(Generate patch)

Comparing UserCode/VHbb/python/StackMaker.py (file contents):
Revision 1.1 by nmohr, Thu Oct 18 13:44:02 2012 UTC vs.
Revision 1.8 by nmohr, Tue Nov 6 13:51:05 2012 UTC

# Line 7 | Line 7 | from Ratio import getRatio
7  
8   class StackMaker:
9      def __init__(self, config, var,region,SignalRegion):
10        plotConfig = BetterConfigParser()
11        plotConfig.read('vhbbPlotDef.ini')
10          section='Plot:%s'%region
11          self.var = var
12 +        self.SignalRegion=SignalRegion
13          self.normalize = eval(config.get(section,'Normalize'))
14          self.log = eval(config.get(section,'log'))
15 <        if plotConfig.has_option('plotDef:%s'%var,'log') and not self.log:
16 <            self.log = eval(plotConfig.get('plotDef:%s'%var,'log'))
15 >        if config.has_option('plotDef:%s'%var,'log') and not self.log:
16 >            self.log = eval(config.get('plotDef:%s'%var,'log'))
17          self.blind = eval(config.get(section,'blind'))
18          if self.blind: blindopt='blind'
19          else: blindopt = 'noblind'
# Line 29 | Line 28 | class StackMaker:
28          if config.has_option(section,'nBins'):
29              self.nBins = int(eval(config.get(section,'nBins'))/self.rebin)
30          else:
31 <            self.nBins = int(eval(plotConfig.get('plotDef:%s'%var,'nBins'))/self.rebin)
31 >            self.nBins = int(eval(config.get('plotDef:%s'%var,'nBins'))/self.rebin)
32          print self.nBins
33          if config.has_option(section,'min'):
34              self.xMin = eval(config.get(section,'min'))
35          else:
36 <            self.xMin = eval(plotConfig.get('plotDef:%s'%var,'min'))
36 >            self.xMin = eval(config.get('plotDef:%s'%var,'min'))
37          if config.has_option(section,'max'):
38              self.xMax = eval(config.get(section,'max'))
39          else:
40 <            self.xMax = eval(plotConfig.get('plotDef:%s'%var,'max'))
41 <        self.name = plotConfig.get('plotDef:%s'%var,'relPath')
40 >            self.xMax = eval(config.get('plotDef:%s'%var,'max'))
41 >        self.name = config.get('plotDef:%s'%var,'relPath')
42          self.mass = config.get(section,'Signal')
43          data = config.get(section,'Datas')
44          if '<mass>' in self.name:
# Line 52 | Line 51 | class StackMaker:
51          self.colorDict=eval(config.get('Plot_general','colorDict'))
52          self.typLegendDict=eval(config.get('Plot_general','typLegendDict'))
53          self.anaTag = config.get("Analysis","tag")
54 <        self.xAxis = plotConfig.get('plotDef:%s'%var,'xAxis')
54 >        self.xAxis = config.get('plotDef:%s'%var,'xAxis')
55 >        self.plotDir = config.get('Directories','plotpath')
56          self.options = [self.name,'',self.xAxis,self.nBins,self.xMin,self.xMax,'%s_%s.pdf'%(region,var),region,datacut,self.mass,data,blindopt]
57 +        self.maxRatioUncert = 0.5
58 +        if self.SignalRegion:
59 +            self.maxRatioUncert = 1000.
60          self.config = config
61          self.datas = None
62          self.datatyps = None
# Line 61 | Line 64 | class StackMaker:
64          self.lumi = None
65          self.histos = None
66          self.typs = None
67 +        self.AddErrors = None
68          print self.setup
69  
70      def myText(self,txt="CMS Preliminary",ndcX=0,ndcY=0,size=0.8):
# Line 118 | Line 122 | class StackMaker:
122          #print setup
123  
124  
125 +        if not 'DYc' in self.typs: self.typLegendDict.update({'DYlight':self.typLegendDict['DYlc']})
126 +        print self.typLegendDict
127 +
128          k=len(self.histos)
129      
130          for j in range(0,k):
131              #print histos[j].GetBinContent(1)
132              i=k-j-1
133 <            self.histos[i].SetFillColor(int(self.colorDict[self.setup[i]]))
133 >            self.histos[i].SetFillColor(int(self.colorDict[self.typs[i]]))
134              self.histos[i].SetLineColor(1)
135              allStack.Add(self.histos[i])
136  
# Line 136 | Line 143 | class StackMaker:
143                  addFlag = 'Z(e^{-}e^{+})H(b#bar{b})'
144          elif 'Zmm' in self.datanames:
145                  addFlag = 'Z(#mu^{-}#mu^{+})H(b#bar{b})'
146 +        elif 'Znn' in self.datanames:
147 +                addFlag = 'Z(#nu#nu)H(b#bar{b})'
148 +        elif 'Wmn' in self.datanames:
149 +                addFlag = 'W(#mu#nu)H(b#bar{b})'
150 +        elif 'Wen' in self.datanames:
151 +                addFlag = 'W(e#nu)H(b#bar{b})'
152          for i in range(0,len(self.datas)):
153              d1.Add(self.datas[i],1)
154          print "\033[1;32m\n\tDATA integral = %s\033[1;m"%d1.Integral()
# Line 160 | Line 173 | class StackMaker:
173              stackhists=allStack.GetHists()
174              for blabla in stackhists:
175                      if MC_integral != 0: blabla.Scale(stackscale)
176 <    
177 <        allMC=allStack.GetStack().Last().Clone()
176 >  
177 >        if self.SignalRegion:
178 >            allMC=allStack.GetStack().At(allStack.GetStack().GetLast()-1).Clone()
179 >        else:
180 >            allMC=allStack.GetStack().Last().Clone()
181  
182          allStack.SetTitle()
183          allStack.Draw("hist")
184          allStack.GetXaxis().SetTitle('')
185          yTitle = 'Entries'
186          if not '/' in yTitle:
187 <            yAppend = '%s' %(allStack.GetXaxis().GetBinWidth(1))
187 >            yAppend = '%.2f' %(allStack.GetXaxis().GetBinWidth(1))
188              yTitle = '%s / %s' %(yTitle, yAppend)
189          allStack.GetYaxis().SetTitle(yTitle)
190          allStack.GetXaxis().SetRangeUser(self.xMin,self.xMax)
# Line 201 | Line 217 | class StackMaker:
217          unten.cd()
218          ROOT.gPad.SetTicks(1,1)
219  
220 <        ratio, error = getRatio(d1,allMC,self.xMin,self.xMax)
220 >        l2 = ROOT.TLegend(0.5, 0.82,0.92,0.95)
221 >        l2.SetLineWidth(2)
222 >        l2.SetBorderSize(0)
223 >        l2.SetFillColor(0)
224 >        l2.SetFillStyle(4000)
225 >        l2.SetTextFont(62)
226 >        #l2.SetTextSize(0.035)
227 >        l2.SetNColumns(2)
228 >
229 >
230 >        ratio, error = getRatio(d1,allMC,self.xMin,self.xMax,"",self.maxRatioUncert)
231          ksScore = d1.KolmogorovTest( allMC )
232          chiScore = d1.Chi2Test( allMC , "UWCHI2/NDF")
233          print ksScore
# Line 212 | Line 238 | class StackMaker:
238          ratioError.SetFillColor(ROOT.kGray+3)
239          ratioError.SetFillStyle(3013)
240          ratio.Draw("E1")
241 +
242 +
243 +
244 +        if not self.AddErrors == None:
245 +            self.AddErrors.SetFillColor(5)
246 +            self.AddErrors.SetFillStyle(1001)
247 +            self.AddErrors.Draw('SAME2')
248 +
249 +            l2.AddEntry(self.AddErrors,"MC uncert. (stat. + syst.)","f")
250 +
251 +        l2.AddEntry(ratioError,"MC uncert. (stat.)","f")
252 +
253 +        l2.Draw()
254 +
255          ratioError.Draw('SAME2')
256          ratio.Draw("E1SAME")
257          ratio.SetTitle("")
# Line 226 | Line 266 | class StackMaker:
266          t0.SetTextFont(ROOT.gStyle.GetLabelFont())
267          if not self.log:
268              t0.DrawTextNDC(0.1059,0.96, "0")
269 <
270 <        name = '%s/%s' %(self.config.get('Directories','plotpath'),self.options[6])
269 >        if not os.path.exists(self.plotDir):
270 >            os.makedirs(os.path.dirname(self.plotDir))
271 >        name = '%s/%s' %(self.plotDir,self.options[6])
272          c.Print(name)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines