コード例 #1
0
ファイル: test_beam_maker.py プロジェクト: durgarajaram/maus
 def test_no_nan(self):
     """
     Check that no nans appear
     """
     bunch = Bunch.new_from_read_builtin('maus_json_primary', NAN_SIM)
     self.assertAlmostEqual(bunch.bunch_weight(), 1000.)
     for hit in bunch:
         self.assertFalse(math.isnan(hit['energy']))
     canvas, hist = bunch.root_histogram('kinetic_energy',
                                         'MeV',
                                         xmin=0.,
                                         xmax=150.)
     cmp_hist = ROOT.TH1D("test", "test", hist.GetNbinsX(), 0.,
                          150.)  # pylint: disable = E1101, C0301
     for h_bin in range(1, hist.GetNbinsX() + 1):
         sigma = 25.
         norm = 2. * bunch.bunch_weight() / sigma / (2. * math.pi)**0.5
         norm *= 150. / hist.GetNbinsX()
         my_x = hist.GetBinCenter(h_bin)
         my_y = math.exp(-my_x**2. / 2. / sigma**2.) * norm
         cmp_hist.Fill(my_x, my_y)
     cmp_hist.SetLineStyle(2)
     cmp_hist.Draw("SAME")
     ks_value = cmp_hist.KolmogorovTest(hist)
     print "nan energy ks_value", ks_value
     canvas.Update()
     canvas.Print(PLOT_DIR + "/nan_energy_distribution_test.png")
     self.assertGreater(ks_value, 1e-3)
コード例 #2
0
ファイル: test_beam_maker.py プロジェクト: durgarajaram/maus
 def test_defaults(self):
     """
     Check that the default beam parameters run and produce some number of
     primary hits > 0
     """
     bunch = Bunch.new_from_read_builtin('maus_json_primary', DEF_SIM)
     self.assertTrue(len(bunch) > 0)
コード例 #3
0
ファイル: test_beam_maker.py プロジェクト: mice-software/maus
 def test_defaults(self):
     """
     Check that the default beam parameters run and produce some number of
     primary hits > 0
     """
     bunch = Bunch.new_from_read_builtin('maus_json_primary', DEF_SIM)
     self.assertTrue(len(bunch) > 0)
コード例 #4
0
ファイル: test_beam_maker.py プロジェクト: mice-software/maus
 def test_no_nan(self):
     """
     Check that no nans appear
     """
     bunch = Bunch.new_from_read_builtin('maus_json_primary', NAN_SIM)
     self.assertAlmostEqual(bunch.bunch_weight(), 1000.)
     for hit in bunch:
         self.assertFalse(math.isnan(hit['energy']))
     canvas, hist = bunch.root_histogram('kinetic_energy', 'MeV', xmin=0.,
                                                       xmax=150.)
     cmp_hist = ROOT.TH1D("test", "test", hist.GetNbinsX(), 0., 150.) # pylint: disable = E1101, C0301
     for h_bin in range(1, hist.GetNbinsX()+1):
         sigma = 25.
         norm = 2.*bunch.bunch_weight()/sigma/(2.*math.pi)**0.5
         norm *= 150./hist.GetNbinsX()
         my_x = hist.GetBinCenter(h_bin)
         my_y = math.exp(-my_x**2./2./sigma**2.)*norm
         cmp_hist.Fill(my_x, my_y)
     cmp_hist.SetLineStyle(2)
     cmp_hist.Draw("SAME")
     ks_value = cmp_hist.KolmogorovTest(hist)
     print "nan energy ks_value", ks_value
     canvas.Update()
     canvas.Print(PLOT_DIR+"/nan_energy_distribution_test.png")
     self.assertGreater(ks_value, 1e-3)
コード例 #5
0
def smear_test():
    src_fname = '/tmp/smear_test.in'
    tgt_fname = '/tmp/smear_test.out'
    tgt_nevents = 10000

    cov = numpy.array([
        [
            1000.,
            0.,
            0.,
            0.,
            0.,
        ],
        [
            0.,
            600.,
            0.,
            0.,
            0.,
        ],
        [
            0.,
            0.,
            1000.,
            0.,
            0.,
        ],
        [
            0.,
            0.,
            0.,
            600.,
            0.,
        ],
        [
            0.,
            0.,
            0.,
            0.,
            100.,
        ],
    ])
    mean = numpy.array([0., 0., 0., 0., 0.])
    src_dist = numpy.random.multivariate_normal(mean, cov, 1000)
    fsrc = open(src_fname, 'w')
    for item in src_dist:
        fsrc.write(json.dumps(item.tolist()) + '\n')
    fsrc.close()

    SmearAndSample(src_fname, tgt_fname, "icool_for003", tgt_nevents)

    fin = open(tgt_fname)
    tgt_bunch = Bunch.new_from_read_builtin("icool_for003", tgt_fname)
    tgt_dist = [[hit[key] for key in SmearAndSample.keys] for hit in tgt_bunch]

    if len(tgt_dist) != tgt_nevents:
        raise RuntimeError("Fail")

    tgt_dist = numpy.array(tgt_dist).transpose()
    numpy.set_printoptions(precision=8, linewidth=1000)
    print numpy.cov(src_dist.transpose())
    print
    print numpy.cov(tgt_dist)