11"""
2- This piece of code generates a simplified variant of the uncertainties.yaml
3- files in which the 99 correlated systematic uncertainties of the legacy
2+ This piece of code generates a simplified variant of the uncertainties.yaml
3+ files in which the 99 correlated systematic uncertainties of the legacy
44version are replaced with two systematic uncertainties, one that is uncorrelated
55and that is correlated. Statistical, luminosity and )optional) Monte Carlo
66uncertainties are as in the legacy version.
77"""
88
99import yaml
1010
11+
1112def get_tables (observable ):
1213 """
1314 get the Hepdata tables, given the tables and version specified in metadata
@@ -26,14 +27,15 @@ def get_tables(observable):
2627 print ("- ATLAS_Z0J_8TEV_PT-Y" )
2728 print ("- ATLAS_Z0J_8TEV_PT-M" )
2829 exit ()
29-
30+
3031 hepdata_tables = []
3132
3233 for table in tables :
3334 hepdata_tables .append (f"{ prefix } { table } .yaml" )
3435
3536 return hepdata_tables
3637
38+
3739def get_uncertainties (observable ):
3840 """
3941 Returns uncertainties for dumping in the -yaml file
@@ -62,51 +64,68 @@ def get_uncertainties(observable):
6264
6365 return (data_central , uncertainties )
6466
67+
6568def filter_unc_ATLAS_Z0J_8TEV (MC = False ):
6669 """
6770 Dumps uncertainties on .yaml files
6871 """
69- lumi_unc = 2.8 # %
70- mc_unc = 1.0 # %
72+ lumi_unc = 2.8 # %
73+ mc_unc = 1.0 # %
7174 observables = ["PT-Y" , "PT-M" ]
7275 for observable in observables :
73- if MC == False :
76+ if MC == False :
7477 unc_file = "uncertainties_decorr_" + observable + ".yaml"
7578 else :
76- unc_file = "uncertainties_decorr_sys_10_" + observable + ".yaml"
79+ unc_file = "uncertainties_decorr_sys_10_" + observable + ".yaml"
7780 central_values , uncertainties = get_uncertainties (observable )
7881
7982 for i in range (len (central_values )):
8083 for k in uncertainties [i ]:
81- uncertainties [i ][k ] = float (uncertainties [i ][k ].replace ("%" ,"" ))/ 100. * central_values [i ] * 1000.
82- uncertainties [i ].update ({"sys_lumi_corr" : lumi_unc / 100 * central_values [i ] * 1000. })
83- if (MC == True ):
84- uncertainties [i ].update ({"sys_mc_uncorr" : mc_unc / 100 * central_values [i ] * 1000. })
85-
86- treatment = {"stat" : "ADD" ,
87- "sys,Uncorrelated" : "ADD" ,
88- "sys,Correlated" : "MULT" ,
89- "sys_lumi_corr" : "MULT" ,}
90- correlation = {"stat" : "UNCORR" ,
91- "sys,Uncorrelated" : "UNCORR" ,
92- "sys,Correlated" : "CORR" ,
93- "sys_lumi_corr" : "ATLASLUMI12" ,}
84+ uncertainties [i ][k ] = (
85+ float (uncertainties [i ][k ].replace ("%" , "" )) / 100.0 * central_values [i ] * 1000.0
86+ )
87+ uncertainties [i ].update ({"sys_lumi_corr" : lumi_unc / 100 * central_values [i ] * 1000.0 })
88+ if MC == True :
89+ uncertainties [i ].update (
90+ {"sys_mc_uncorr" : mc_unc / 100 * central_values [i ] * 1000.0 }
91+ )
92+
93+ treatment = {
94+ "stat" : "ADD" ,
95+ "sys,Uncorrelated" : "ADD" ,
96+ "sys,Correlated" : "MULT" ,
97+ "sys_lumi_corr" : "MULT" ,
98+ }
99+ correlation = {
100+ "stat" : "UNCORR" ,
101+ "sys,Uncorrelated" : "UNCORR" ,
102+ "sys,Correlated" : "CORR" ,
103+ "sys_lumi_corr" : "ATLASLUMI12" ,
104+ }
94105 if MC == True :
95106 treatment .update ({"sys_mc_uncorr" : "ADD" })
96107 correlation .update ({"sys_mc_uncorr" : "UNCORR" })
97108
98109 definitions = {}
99- for key ,value in uncertainties [0 ].items ():
100- definition = {key :
101- {"description" : key + " unc. from HepData" ,
102- "treatment" : treatment [key ],
103- "type" : correlation [key ]}}
110+ for key , value in uncertainties [0 ].items ():
111+ definition = {
112+ key : {
113+ "description" : key + " unc. from HepData" ,
114+ "treatment" : treatment [key ],
115+ "type" : correlation [key ],
116+ }
117+ }
104118 definitions .update (definition )
105- uncertainties_yaml = {"definitions" : definitions ,"bins" : uncertainties }
106-
119+ uncertainties_yaml = {"definitions" : definitions , "bins" : uncertainties }
120+
121+ if MC :
122+ uncertainties_yaml ["definitions" ][key ][
123+ "description"
124+ ] = "extra Monte Carlo statistical uncertainty"
125+
107126 with open (unc_file , "w" ) as file :
108127 yaml .dump (uncertainties_yaml , file , sort_keys = False )
109-
128+
110129
111130if __name__ == "__main__" :
112131 filter_unc_ATLAS_Z0J_8TEV (MC = False )
0 commit comments