Пример #1
0
 def StatTest(self, numexp):
     diff = ROOT.TH1D(self.hmeasured)
     diffq = ROOT.TH1D(self.hmeasured)
     diff.Reset()
     diffq.Reset()
     numevents = self.hmeasured.Integral()
     for exp in range(0, numexp):
         self.Generate(numevents)
         genunfolded = self.GetUnfolded(self.genmeasured)
         print "exp", self.gentruth.Integral(), genunfolded.Integral(
         ), self.genmeasured.Integral(), numevents
         for b in range(1, genunfolded.GetNbinsX() + 1):
             bdiff = genunfolded.GetBinContent(
                 b) - self.gentruth.GetBinContent(b)
             diff.SetBinContent(b, diff.GetBinContent(b) + bdiff)
             diffq.SetBinContent(b, diff.GetBinContent(b) + bdiff * bdiff)
     for b in range(1, diff.GetNbinsX() + 1):
         mean = diff.GetBinContent(b) / float(numexp)
         meanq = diff.GetBinContent(b) / float(numexp)
         diff.SetBinContent(b, mean / self.gentruth.GetBinContent(b))
         diff.SetBinError(
             b,
             math.sqrt(abs(meanq - mean * mean)) /
             self.gentruth.GetBinContent(b))
     return diff
Пример #2
0
 def write_txt(txt, name):
     if txt:
         ttxt = ROOT.TText(0., 0., txt)
         ttxt.SetName(name)
         return ttxt.Write()
     else:
         return 0.
Пример #3
0
    def DoScanLcurve(self, npoints, tau_min=0, tau_max=20):
        #reset unfolding (if any) since the method messes up with the output
        self.unfoldingdone = False
        lcurve = ROOT.TGraph()
        spline_x = ROOT.TSpline3()
        spline_y = ROOT.TSpline3()
        best = self.unfolder.ScanLcurve(npoints, tau_min, tau_max, lcurve,
                                        spline_x, spline_y)
        lcurve.GetXaxis().SetTitle('log(#chi^{2})')
        lcurve.GetYaxis().SetTitle('log(regularization)')

        graph_x = spline2graph(spline_x)
        graph_y = spline2graph(spline_y)

        graph_x.get_xaxis().SetTitle('log(#tau)')
        graph_y.get_xaxis().SetTitle('log(#tau)')
        graph_x.get_yaxis().SetTitle('log(#chi^{2})')
        graph_y.get_yaxis().SetTitle('log(regularization)')

        return self.unfolder.GetTau(), lcurve, graph_x, graph_y
Пример #4
0
    def DoScanTau(self, npoints, tau_min=0., tau_max=20., mode='RhoAvg'):
        #reset unfolding (if any) since the method messes up with the output
        self.unfoldingdone = False
        scan_mode = URUnfolding.scantaumodes[mode]
        spline = ROOT.TSpline3()
        best = self.unfolder.ScanTau(npoints, tau_min, tau_max, spline,
                                     scan_mode)
        #, const char* distribution = 0, const char* projectionMode = 0, TGraph** lCurvePlot = 0, TSpline** logTauXPlot = 0, TSpline** logTauYPlot = 0)
        #convert spline in Graph

        scan = spline2graph(spline)
        scan.get_xaxis().SetTitle('log(#tau)')
        scan.get_yaxis().SetTitle(mode)
        return self.unfolder.GetTau(), scan, best
Пример #5
0
    def InitUnfolder(self):
        self.ScaleDistributions(self.scale)
        log.debug('Initializing unfolder.')
        self.unfolder = ROOT.TUnfoldDensity(
            self.matrix, URUnfolding.orientations[self.orientation],
            URUnfolding.regularizations[self.regmode],
            URUnfolding.constraints[self.constraint],
            URUnfolding.densities[self.density])
        log.debug('Loading histogram %s into unfolder' %
                  self.measured.GetName())
        if self.cov_matrix:
            status = self.unfolder.SetInput(self.measured, 0., 0.,
                                            self.cov_matrix)
        else:
            status = self.unfolder.SetInput(self.measured)

        if status >= 10000:
            raise RuntimeError('Unfolding status %i. Unfolding impossible!' %
                               status)
Пример #6
0
 def write_float(h, name):
     return ROOT.RooRealVar(name, name, h).Write()
Пример #7
0
 def Generate(self, numevents):
     if (not hasattr(self, 'gentruth')) or self.gentruth == 0:
         self.hmiss = ROOT.TH1D(self.truth)
         self.hmiss.Add(self.matrix.ProjectionX(), -1.)
         self.hfake = ROOT.TH1D(self.measured)
         self.hfake.Add(self.hmatrix.ProjectionY(), -1.)
         self.gentruth = ROOT.TH1D(self.htruth)
         self.genmeasured = ROOT.TH1D(self.htruth)
         maxima = [
             self.hmiss.GetMaximum(),
             self.hfake.GetMaximum(),
             self.matrix.GetMaximum()
         ]
         maxima.sort()
         self.maxval = maxima[2]
         newfile = rootpy.io.root_open("output_prova2.root", 'recreate')
         self.hmiss.Write()
         self.hfake.Write()
         self.gentruth.Write()
         self.genmeasured.Write()
         newfile.Close()
     self.gentruth.Reset()
     self.genmeasured.Reset()
     nev = numpy.random.poisson(numevents)
     print "nev =", nev
     nbinsx = self.hmiss.GetNbinsX()
     nbinsy = self.hfake.GetNbinsX()
     print "nbinsx, nbinsy =", nbinsx, nbinsy
     while nev != 0:
         #if nev%1000 == 0:
         #   print "nev =",nev
         binx = numpy.random.random_integers(0, nbinsx)
         biny = numpy.random.random_integers(0, nbinsy)
         test = numpy.random.uniform(0, self.maxval)
         if binx > 0 and biny > 0:
             dest = self.matrix.GetBinContent(binx, biny)
             if test < dest:
                 nev = nev - 1
                 self.gentruth.SetBinContent(
                     binx,
                     self.gentruth.GetBinContent(binx) + 1)
                 self.genmeasured.SetBinContent(
                     biny,
                     self.genmeasured.GetBinContent(biny) + 1)
         elif binx == 0:
             dest = self.hfake.GetBinContent(biny)
             if test < dest:
                 nev = nev - 1
                 self.genmeasured.SetBinContent(
                     biny,
                     self.genmeasured.GetBinContent(biny) + 1)
         elif biny == 0:
             dest = self.hmiss.GetBinContent(binx)
             if test < dest:
                 self.gentruth.SetBinContent(
                     binx,
                     self.gentruth.GetBinContent(binx) + 1)
     for i in range(1, nbinsx + 1):
         self.gentruth.SetBinError(
             i, math.sqrt(self.gentruth.GetBinContent(i)))
     for i in range(1, nbinsy + 1):
         self.genmeasured.SetBinError(
             i, math.sqrt(self.genmeasured.GetBinContent(i)))