diff --git a/Validation/src/Validation/__main__.py b/Validation/src/Validation/__main__.py index 4f4237c70..1a0c0ab14 100644 --- a/Validation/src/Validation/__main__.py +++ b/Validation/src/Validation/__main__.py @@ -45,6 +45,12 @@ parser.add_argument('--param', nargs='+', help='parameter(s) in filename to use as file labels') + parser.add_argument('--input-file-filter', type=str, + help="""Filter which root files in the input data directory to + use using a regular expression""") + parser.add_argument('--input-files', nargs='+', type=str, + help="""Specify the name of the root files directly (either + full/relative path or name of files in the input data directory)""") arg = parser.parse_args() @@ -79,8 +85,23 @@ logging.debug(f'Deduced Args: label = {label} out_dir = {out_dir}') - root_files = [ File.from_path(os.path.join(data,f), legendlabel_parameter = arg.param) - for f in os.listdir(data) if f.endswith('.root') ] + if arg.input_files: + input_files = [os.path.join(data, f) + if not f.startswith(data) + else f + for f in arg.input_files + ] + root_files = [File.from_path(f, legendlabel_parameter=arg.param) + for f in input_files] + else: + root_files = [ File.from_path(os.path.join(data,f), legendlabel_parameter = arg.param) + for f in os.listdir(data) if f.endswith('.root') ] + + if arg.input_file_filter: + # Not sure if this can be done in one step so doing it in two + filtered_files = [f for f in root_files + if re.search(arg.input_file_filter, f.path) ] + root_files = filtered_files logging.debug(f'ROOT Files: {root_files}') diff --git a/Validation/src/Validation/_differ.py b/Validation/src/Validation/_differ.py index fe6ca1bd8..ab4adb2be 100644 --- a/Validation/src/Validation/_differ.py +++ b/Validation/src/Validation/_differ.py @@ -7,6 +7,7 @@ # external dependencies import matplotlib.pyplot as plt import matplotlib +import uproot # us from ._file import File @@ -110,7 +111,11 @@ def plot1d(self, column, xlabel, ax = fig.subplots() for f in self.files : - weights, bins, patches = f.plot1d(ax, column, **hist_kwargs) + try: + weights, bins, patches = f.plot1d(ax, column, **hist_kwargs) + except uproot.KeyInFileError: + f.log.warn(f"Key {column} doesn't exist in {self}, skipping") + continue ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) diff --git a/Validation/src/Validation/_file.py b/Validation/src/Validation/_file.py index bd5b055df..18d7f4724 100644 --- a/Validation/src/Validation/_file.py +++ b/Validation/src/Validation/_file.py @@ -104,7 +104,12 @@ def is_events(self) : Otherwise, we assume that it is a histogram file. """ return 'LDMX_Events' in self.__file - + + @property + def path(self): + """Retrun the path to the file on disk""" + return self.__file.file_path + def events(self, **kwargs) : """Callback for retrieving a full in-memory data frame of the events