コード例 #1
0
ファイル: h2fakerate.py プロジェクト: rm821671/maCode
 def _calc_histo(self, *opt):
     self.tot = rt.TH1F( self.name+"_tot_"+aux.randomName(),
                         ";"+self.ytitle+"; Events / bin",
                         self.ybins,
                         self.ymin,
                         self.ymax)
     self.pas = rt.TH1F( self.name+"_pas_"+aux.randomName(),
                         ";"+self.ytitle+"; Events / bin",
                         self.ybins,
                         self.ymin,
                         self.ymax)
     if not opt:
         rng = [0, self.ybins] # TODO: set this to a different range
     else:
         rng = [opt[0], opt[1]]
     for yb in range(self.ybins):
         # NOTE:
         # The lists with the projection histograms
         # have to be looped from 0 to the number of bins,
         # but the setted bins in the total and passed histograms
         # go from 0 to the number of bins +1,
         # thats why there is SetBinContent(yb+1).
         val = self.tot_proj[yb].Integral(rng[0], rng[1])
         self.tot.SetBinContent(yb+1, val)
         val = self.pas_proj[yb].Integral(rng[0], rng[1])
         self.pas.SetBinContent(yb+1, val)
     self.tot.Sumw2()
     self.pas.Sumw2()
     return 0
コード例 #2
0
ファイル: h2fakerate.py プロジェクト: rm821671/maCode
 def addFakerate(self, f, name=""):
     # fakerate should be of type h2Fakerate
     self.h.append(f.ehis)
     self.f.append(f.f)
     
     if name=="":
         self.names.append(aux.randomName())
     else:
         self.names.append(name)
     return 0
コード例 #3
0
ファイル: h2fakerate.py プロジェクト: rm821671/maCode
 def __init__(self, name, tot, pas, *opt):
     # tot and pas are 2d histograms for the total and the passed
     # content to determine the efficiency.
     self.name = name
     
     self.ybins = tot.GetNbinsY()
     self.ymin = tot.GetYaxis().GetXmin()
     self.ymax = tot.GetYaxis().GetXmax()
     self.ytitle = tot.GetYaxis().GetTitle()
     
     self._calc_proj(tot, pas)
     
     if not opt:
         self._calc_histo()
     else:
         self._calc_histo(opt[0], opt[1])
     
     self.f = aux.randomName()
     self.egraph = aux.randomName()
     self.ehis = aux.randomName()
コード例 #4
0
ファイル: h2fakerate.py プロジェクト: rm821671/maCode
 def createFitPrediction(self, *opt):
     # here, the fitted fakerate function is used
     # to make a prediction for the closure test.
     bins = self.initial.GetNbinsX()
     xmin = self.initial.GetXaxis().GetXmin()
     xmax = self.initial.GetXaxis().GetXmax()
     for h in self.h:
         self.predictionf.append(self.initial.Clone(aux.randomName()))
     for i in range(1, bins+1):
         val = self.initial.GetBinContent(i)
         
         err = self.initial.GetBinError(i)
         x = self.initial.GetBinCenter(i)
         count = 0
         for f in self.f:
             R = self.evalFakerate(f, x)
             self.predictionf[count].SetBinContent(i, R*val)
             self.predictionf[count].SetBinError(i, R*err)
             count = count+1
     return 0
コード例 #5
0
ファイル: h2fakerate.py プロジェクト: rm821671/maCode
 def createHistoPrediction(self, *opt):
     # here, the fakerate histogram is used
     # to make a prediction for the closure test
     bins = self.initial.GetNbinsX()
     xmin = self.initial.GetXaxis().GetXmin()
     xmax = self.initial.GetXaxis().GetXmax()
     for h in self.h:
         self.predictionh.append(self.initial.Clone(aux.randomName()))
     for i in range(1, bins+1):
         val = self.initial.GetBinContent(i)
         #print i, val, 
         err = self.initial.GetBinError(i)
         count = 0
         for h in self.h:
             #fr = h.GetBinContent(i)
             #fr = 0.0102919054273 # background fit gauss + poly2, global bin
             fr = 0.010706 # roofit cms shape, global bin
             R = float(fr)/(1-fr)
             self.predictionh[count].SetBinContent(i, R*val)
             self.predictionh[count].SetBinError(i, R*err)
             #print self.predictionh[count].GetBinContent(i)
             count = count +1
     return 0
コード例 #6
0
ファイル: h2fakerate.py プロジェクト: rm821671/maCode
 def createCanvas(self, fs, yrng="", name="", log=False):
     cwidth = 800
     cheight = 800
     
     rat = 0.35
     
     c = rt.TCanvas(self.h2f.name, self.h2f.name, cwidth, cheight)
     rt.gStyle.SetTitleFontSize(0.07);
     c.cd()
     
     #c.SetLeftMargin(0.16)
     #c.SetBottomMargin(0.15)
     
     self.egraph.GetXaxis().SetTitleSize(0.05)
     self.egraph.GetXaxis().SetLabelSize(0.0)
     
     self.egraph.GetYaxis().SetTitleSize(0.05)
     self.egraph.GetYaxis().SetLabelSize(0.05)
     self.egraph.GetYaxis().SetTitleOffset(1.3)
     self.egraph.SetTitle(self.clabel)
     #self.egraph.SetTitleOffset(1.2)
     #h1.SetMinimum(-10)
     
     self.ratio.GetXaxis().SetTitleSize(0.15)
     self.ratio.GetXaxis().SetLabelSize(0.1)
     
     self.ratio.GetYaxis().SetNdivisions(5)
     self.ratio.GetYaxis().SetTitleSize(0.12)
     self.ratio.GetYaxis().SetLabelSize(0.09)
     self.ratio.GetYaxis().SetTitleOffset(0.6)
     
     
     self.ratio.SetMinimum(0.5)
     self.ratio.SetMaximum(1.5)
     
     
     
     pad1 = rt.TPad("pad1","pad1",0,rat,1,1)
     pad1.SetGrid()
     #pad1.SetTopMargin(0.8)
     pad1.SetBottomMargin(0)
     pad1.SetLeftMargin(0.16)
     pad1.Draw()
     pad1.cd()
     pad1.Update()
     
     self.egraph.GetYaxis().SetTitle("Fakerate")
     self.egraph.GetYaxis().SetTitleOffset(1.3)
     self.egraph.GetYaxis().SetTitleSize(0.05)
     
     self.egraph.GetXaxis().SetLabelSize(0.0)
     self.egraph.GetXaxis().SetTitleSize(0.05)
     #.SetMaximum(0.015)
     
     #eff.GetXaxis().SetRangeUser(0.,210.)
     if yrng=="":
         self.egraph.SetMinimum(0.)
     else:
         self.egraph.SetMinimum(yrng[0])
         self.egraph.SetMaximum(yrng[1])
     
     #eff.Draw("ap")
     
     self.egraph.Draw("ap")
     
     c.cd()
     
     pad2 = rt.TPad("pad2","pad2",0,0,1,rat)
     pad2.SetGridy()
     pad2.SetGridx()
     pad2.SetTopMargin(0)
     pad2.SetBottomMargin(0.35)
     pad2.SetLeftMargin(0.16)
     pad2.Draw()
     pad2.cd()
     
     
     oneline = rt.TF1("oneline"+aux.randomName(), "1", 
                             self.egraph.GetXaxis().GetXmin(),
                             self.egraph.GetXaxis().GetXmax())
     oneline.SetLineWidth(1)
     oneline.SetLineColor(rt.kBlack)
     
     self.ratio.Draw("ap")
     oneline.Draw("same")
     pad2.Update()
     
     c.Update()
     
     fs.savePdf(c, name)
     c.Close()
     #drawCMS(c)
     #c.Update()
     
     #raw_input()
     #self.c = c.Clone()
     #self.c.Update()
     return 0