Adding functions to checks.py module
The functions range_check_nd
and num_entries_per_invpb
(see also !21 (merged) , lhcb-dpa&1 (closed), https://gitlab.cern.ch/lhcb-dpa/project/-/issues/93) are added to checks.py
module.
The range_check_nd
function saves two-dimensional histograms of variables (or expressions) taken from a TTree object. At least two variables are expected in input (and a maximum of four). If more than two variables are given as input, all the possible combinations of two-dimensional histograms are saved.
The num_entries_per_invpb
function checks if the number of entries per unit luminosity in the tuple is larger than a fixed value.
They can be tested with the code displayed below. As a test-file I've used https://lhcb-analysis-productions.web.cern.ch/2535814/ and https://lhcb-analysis-productions.web.cern.ch/2641129/D02HHHH_Run1/2012_MagDown/
import checks
import boost_histogram as bh
from hist import Hist
import hist
import re
import numpy
import mplhep
import matplotlib.pyplot as plt
#Testing range check_nd
check_name = "range_check_nd"
check_arguments = {"expression": {"x": "D0_M", "y": "Dst_M"}, "limits": {"x": {"min": 1800., "max": 1950.}, "y": {"min": 1970. , "max": 2050.}} , "abs_tolerance": 1.}
check_function = getattr(checks, check_name)
result = check_function("./test_file.root", **check_arguments)
if not result.passed:
print("ERROR:", check_name, "failed with messages:\n", "\n".join(result.messages))
else:
for i in range(0,len(result.histograms),1):
h=result.histograms[i]
plt.figure(figsize=(10, 6))
mplhep.hist2dplot(h)
plt.savefig("test2_%d.pdf"%(i))
plt.show()
for k in range(0, len(result.messages),1):
print(result.messages[k])
#Testing num_entries_per_invpb check
check_name = "num_entries_per_invpb"
check_arguments = {"count_per_invpb": 10.}
check_function = getattr(checks, check_name)
result = check_function("./test_file_2.root", **check_arguments)
if not result.passed:
print("ERROR:", check_name, "failed with messages:\n", "\n".join(result.messages))
else:
for k in range(0, len(result.messages),1):
print(result.messages[k])