Add module with definitions of checks
The module check is added, where the definition of the check_functions is given. Related to !21 (merged) and lhcb-dpa/project#109, https://gitlab.cern.ch/lhcb-dpa/project/-/issues/93.
This is still work-in-progress. Only the check_functions num_entries
and range
are implemented. They can be tested with the code displayed below. As a test-file I've used https://lhcb-analysis-productions.web.cern.ch/2535814/
The num_entries
function checks if the number of events in the TTree is at least count
, which is defined my the user in the YAML
The range_check
function checks if, for one particular branch (or a combination of them), there is at least one entry falling in a range, which is defined by the user in the YAML. If the check is passed, an histogram is saved. There is also the possibility to blind some regions.
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 num_entries check
check_name = "num_entries"
check_arguments = {"count": 100}
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))
#Test range check
check_name = "range_check"
check_arguments = {"expression": "Dst_M-D0_M", "limits": {"min": 143., "max": 148.}, "abs_tolerance": 1., "blind_ranges": []}
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.histplot(h)
plt.show()
for k in range(0, len(result.messages),1):
print(result.messages[k])