Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:47:24

0001 # This file is part of the ACTS project.
0002 #
0003 # Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 #
0005 # This Source Code Form is subject to the terms of the Mozilla Public
0006 # License, v. 2.0. If a copy of the MPL was not distributed with this
0007 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 import matplotlib
0010 
0011 matplotlib.use("Agg")
0012 
0013 import matplotlib.pyplot as plt
0014 import pytest
0015 
0016 import acts
0017 
0018 bh = pytest.importorskip("boost_histogram")
0019 mplhep = pytest.importorskip("mplhep")
0020 
0021 
0022 def test_histogram1_to_boost_histogram():
0023     bh_h = bh.Histogram(acts._demo_histogram1())
0024     assert bh_h.ndim == 1
0025     assert bh_h.sum() > 0
0026     assert bh_h.axes[0].metadata == "x [a.u.]"
0027 
0028 
0029 def test_profile1_to_boost_histogram():
0030     bh_h = bh.Histogram(acts._demo_profile1())
0031     assert bh_h.ndim == 1
0032     assert bh_h.view()["count"].sum() > 0
0033 
0034 
0035 def test_efficiency1_to_boost_histogram():
0036     h = acts._demo_efficiency1()
0037     bh_acc = bh.Histogram(h.accepted)
0038     bh_tot = bh.Histogram(h.total)
0039     assert bh_acc.sum() > 0
0040     assert bh_tot.sum() >= bh_acc.sum()
0041 
0042 
0043 def test_plot_histogram():
0044     fig, ax = plt.subplots()
0045     result = acts._demo_histogram1().plot(ax=ax)
0046     assert result is not None
0047     assert ax.get_xlabel() == "x [a.u.]"
0048     assert ax.get_title() == "Demo Histogram"
0049     plt.close(fig)
0050 
0051 
0052 def test_plot_histogram_no_ax():
0053     result = acts._demo_histogram1().plot()
0054     assert result is not None
0055     plt.close("all")
0056 
0057 
0058 def test_plot_profile():
0059     fig, ax = plt.subplots()
0060     result = acts._demo_profile1().plot(ax=ax)
0061     assert result is not None
0062     assert ax.get_xlabel() == "x [a.u.]"
0063     assert ax.get_ylabel() == "y [a.u.]"
0064     assert ax.get_title() == "Demo Profile"
0065     plt.close(fig)
0066 
0067 
0068 def test_plot_efficiency():
0069     fig, ax = plt.subplots()
0070     acts._demo_efficiency1().plot(ax=ax)
0071     assert ax.get_title() == "Demo Efficiency"
0072     plt.close(fig)