Beispiel #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
Beispiel #2
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)))