Skip to content

Commit

Permalink
Remove save_to_yaml and variant
Browse files Browse the repository at this point in the history
  • Loading branch information
achiefa authored Dec 18, 2024
1 parent 5bc8d02 commit b604ba4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 48 deletions.
4 changes: 2 additions & 2 deletions nnpdf_data/nnpdf_data/commondata/CMS_WCHARM_7TEV/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

if __name__ == "__main__":
CMS_WCHARM_TOT = Extractor("./metadata.yaml", "WPWM-TOT", mult_factor=1000)
_, _, _ = CMS_WCHARM_TOT.generate_data(variant='default', save_to_yaml=True)
CMS_WCHARM_TOT.generate_data()

CMS_WCHARM_RATIO = Extractor("./metadata.yaml", "WPWM-RATIO", mult_factor=1.0)
_, _, _ = CMS_WCHARM_RATIO.generate_data(variant='default', save_to_yaml=True)
CMS_WCHARM_RATIO.generate_data()
77 changes: 31 additions & 46 deletions nnpdf_data/nnpdf_data/commondata/CMS_WCHARM_7TEV/filter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

yaml.add_representer(float, prettify_float)

SQRTS = 8000
MW2 = 80.385**2
CMSLUMI13 = 2.5

# List of systematic uncertainties that shuold
# be considered uncorrelated
UNCORR_SYS_UNC = ['UnfoldMCstat', 'UnfoldOtherGen', 'UnfoldReweight']
ART_LABEL = 'art_corr'
STAT_LABEL = 'stat_uncorr'
TABLE_TOKEN = 'Table'
Expand Down Expand Up @@ -98,8 +94,6 @@ def __extract_kinematics(self, table: dict):
----------
table: dict
Dictionary containing the bins in the transverse momentum
tab_number: int
Index to select the range of the second kinematic variable
Return
------
Expand Down Expand Up @@ -176,7 +170,7 @@ def generate_data_and_unc(self, mult_factor=1.0):
asy_sys_unc.append(rap_bin['errors'][1]['symerror'] * mult_factor)
return dat_central, stat_unc, asy_sys_unc

def __build_unc_definitions(self, variant='default'):
def __build_unc_definitions(self):
unc_definitions = {}

# Statistical uncertainty
Expand All @@ -200,9 +194,6 @@ def __build_unc_definitions(self, variant='default'):
'type': 'CORR',
}

if variant != 'default':
raise ValueError(f'The variant {variant} is not implemented yet.')

return unc_definitions

def generate_covmat(self, diag_uncs=None):
Expand All @@ -216,13 +207,13 @@ def generate_covmat(self, diag_uncs=None):
covmat[i, j] = matlist[i + self.ndata * j] * diag_uncs[i] * diag_uncs[j]
return covmat

def generate_data(self, variant='default', save_to_yaml=False, path='./'):
def generate_data(self):
# Get central data and kinematics
central_data, stat_unc, sys_unc = self.generate_data_and_unc(self.mult_factor)
kinematics = self.generate_kinematics()

# Uncertainty definitions
unc_definitions = self.__build_unc_definitions(variant=variant)
unc_definitions = self.__build_unc_definitions()
sys_artificial = [] # Initialize vector of artificial uncertainties

if self.observable == 'WPWM-TOT':
Expand All @@ -246,37 +237,31 @@ def generate_data(self, variant='default', save_to_yaml=False, path='./'):
# Systematic uncertainty
unc_dict[f'{ART_LABEL}'] = sys_unc[data_idx]
sys_artificial.append(unc_dict)

if save_to_yaml:
# Save kinematics into file
logging.info("Dumping kinematics to file...")
kinematics_yaml = {'bins': kinematics}
with open(path + self.metadata['kinematics']['file'], 'w') as kin_out_file:
yaml.dump(kinematics_yaml, kin_out_file, sort_keys=False)
logging.info("Done!")

# Save central data into file
logging.info("Dumping kinematics to file...")
dat_central_yaml = {'data_central': central_data}
file_name = self.metadata['data_central']
with open(path + file_name, 'w') as dat_out_file:
yaml.dump(dat_central_yaml, dat_out_file, sort_keys=False)
logging.info("Done!")

# Save unertainties
logging.info("Dumping kinematics to file...")
uncertainties_yaml = {'definitions': unc_definitions, 'bins': sys_artificial}
file_name = (
self.metadata['data_uncertainties'][0]
if variant == 'default'
else self.metadata['variants'][variant]['data_uncertainties'][0]
)
with open(path + file_name, 'w') as dat_out_file:
yaml.dump(uncertainties_yaml, dat_out_file, sort_keys=False)
logging.info("Done!")
return kinematics, central_data, sys_artificial
else:
return kinematics, central_data, sys_artificial

def get_table(self, table_id):
return self.__retrieve_table(table_id)

# Local path for yaml files
path='./'

# Save kinematics into file
logging.info("Dumping kinematics to file...")
kinematics_yaml = {'bins': kinematics}
with open(path + self.metadata['kinematics']['file'], 'w') as kin_out_file:
yaml.dump(kinematics_yaml, kin_out_file, sort_keys=False)
logging.info("Done!")

# Save central data into file
logging.info("Dumping kinematics to file...")
dat_central_yaml = {'data_central': central_data}
file_name = self.metadata['data_central']
with open(path + file_name, 'w') as dat_out_file:
yaml.dump(dat_central_yaml, dat_out_file, sort_keys=False)
logging.info("Done!")

# Save unertainties
logging.info("Dumping kinematics to file...")
uncertainties_yaml = {'definitions': unc_definitions, 'bins': sys_artificial}
file_name = (
self.metadata['data_uncertainties'][0]
)
with open(path + file_name, 'w') as dat_out_file:
yaml.dump(uncertainties_yaml, dat_out_file, sort_keys=False)
logging.info("Done!")

0 comments on commit b604ba4

Please sign in to comment.