Skip to content
Snippets Groups Projects
Commit be03d2c7 authored by Michal Dubovsky's avatar Michal Dubovsky
Browse files

Merge branch 'issue/94' into 'main'

Fixing regex support for (excluded) regions in sample block

Closes #94

See merge request atlas-amglab/fastframes!435
parents 9ce11039 cba4767d
No related branches found
No related tags found
No related merge requests found
# Changelog
### Upcoming release
- [issue #94](https://gitlab.cern.ch/atlas-amglab/fastframes/-/issues/92): Fixing bug with regex support for regions in sample block.
- [issue #92](https://gitlab.cern.ch/atlas-amglab/fastframes/-/issues/92): Adding CI test for testing histogram step on the ntuple output.
### 4.0.0 <small>December 4, 2024</small>
......
......@@ -15,12 +15,25 @@ from CommandLineOptions import CommandLineOptions
import re
def string_matches_some_regex(string : list, regex_list : list) -> bool:
def regex_in_string_list(regex : str, string_list : list) -> bool:
for string in string_list:
if re.fullmatch(regex, string):
return True
return False
def string_in_regex_list(string : str, regex_list : list) -> bool:
for regex in regex_list:
if re.match(regex, string):
return True
return False
def get_matched_regions(regex : str, all_regions : list) -> list:
result = []
for region in all_regions:
if re.fullmatch(regex, region):
result.append(region)
return result
def filter_only_selected_campaigns(campaigns_config : list[str]) -> list[str]:
"""!Filter only campaigns that are selected by the user
@param campaigns_config: list of campaigns from the config file
......@@ -137,21 +150,26 @@ class BlockReaderSample:
"""
if self._exclude_regions is not None:
for region_name in self._exclude_regions:
if not string_matches_some_regex(region_name, regions):
if not regex_in_string_list(region_name, regions):
Logger.log_message("ERROR", "Region {} specified for sample {} does not exist".format(region_name, self._name))
exit(1)
if self._regions is None: # if no regions are specified, take all regions
self._regions = []
for region_name in regions:
if self._exclude_regions is not None and string_matches_some_regex(region_name, self._exclude_regions):
if self._exclude_regions is not None and string_in_regex_list(region_name, self._exclude_regions):
continue
self._regions.append(region_name)
else: # if regions are specified, check if they exist
selected_regions = []
for region in self._regions:
if not string_matches_some_regex(region, regions):
matched_regions = get_matched_regions(region, regions)
if len(matched_regions) == 0:
Logger.log_message("ERROR", "Region {} specified for sample {} does not exist".format(region, self._name))
exit(1)
selected_regions.extend(matched_regions)
self._regions = selected_regions
for region_name in self._regions:
region_object = regions[region_name]
......@@ -218,11 +236,11 @@ class BlockReaderSample:
for variable in variables_defined_for_sample:
if variable in self.variables:
variables_to_keep.append(variable)
elif string_matches_some_regex(variable, self.variables):
elif string_in_regex_list(variable, self.variables):
variables_to_keep.append(variable)
elif self.exclude_variables is not None:
for variable in variables_defined_for_sample:
if variable not in self.exclude_variables and not string_matches_some_regex(variable, self.exclude_variables):
if variable not in self.exclude_variables and not string_in_regex_list(variable, self.exclude_variables):
variables_to_keep.append(variable)
for variable in variables_to_keep:
......
......@@ -235,7 +235,7 @@ samples:
simulation_type: "fullsim"
regions: ["Electron", "Muon"]
#reco_to_truth_pairing_indices: ["eventNumber", "runNumber"]
exclude_variables: ["jet_pt_*"]
exclude_variables: ["jet_pt_.*"]
define_custom_columns:
- name: "HT_3_jets"
definition: "jet_pt_NOSYS[0] + jet_pt_NOSYS[1] + jet_pt_NOSYS[2]"
......
......@@ -249,9 +249,9 @@ samples:
event_weights: "weight_mc_NOSYS"
selection_suffix: "n_bjets_truth == 0 && n_cjets_truth == 0"
simulation_type: "fullsim"
regions: ["Electron", "Muon"]
regions: ["M.*"]
reco_to_truth_pairing_indices: ["runNumber", "eventNumber"]
exclude_variables: ["jet_pt_*"]
exclude_variables: ["jet_pt.*"]
define_custom_columns:
- name: "HT_3_jets"
definition: "jet_pt_NOSYS[0] + jet_pt_NOSYS[1] + jet_pt_NOSYS[2]"
......@@ -264,7 +264,7 @@ samples:
sum_weights: "alternative_sum_weights"
selection_suffix: "n_bjets_truth > 0"
simulation_type: "fullsim"
exclude_regions: ["Muon"]
exclude_regions: ["M.*"]
- name: "sample_squence_#GT"
dsids: [364105]
......
......@@ -410,7 +410,7 @@ Samples block:
name: Zjets_light
regions: ['Electron', 'Muon']
regions: ['Muon']
weight: weight_mc_NOSYS
systematic: ['NOSYS', 'btag_B_1__up', 'btag_B_1__down']
selection_suffix: "n_bjets_truth == 0 && n_cjets_truth == 0"
......
......@@ -4,7 +4,7 @@
Job: "my_fit"
HistoChecks: NOCRASH
HistoPath: /home/dubovsky/Analysis/4L/fastframes
HistoPath: .
ImageFormat: pdf
Lumi: 1
POI: mu_signal
......@@ -155,7 +155,7 @@ Sample: "ttbar_FS"
Type: BACKGROUND
Sample: "Zjets_light"
Exclude: Electron_jet_pt,Muon_jet_pt
Exclude: Electron_jet_pt,Electron_met_met,Electron_met_phi,Muon_jet_pt
FillColor: 4
HistoFile: Zjets_light
LineColor: 4
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment