9
9
from columnflow .calibration import Calibrator , calibrator
10
10
from columnflow .calibration .cms .met import met_phi
11
11
from columnflow .calibration .cms .jets import jec , jer
12
- from columnflow .production .cms .seeds import deterministic_seeds
12
+ from columnflow .calibration .cms .egamma import electrons
13
+ from columnflow .production .cms .seeds import (
14
+ deterministic_seeds , deterministic_electron_seeds , deterministic_event_seeds ,
15
+ )
16
+ from columnflow .production .cms .supercluster_eta import electron_sceta
13
17
from columnflow .util import maybe_import , try_float
14
18
from columnflow .columnar_util import set_ak_column , EMPTY_FLOAT
15
19
16
20
from hbw .util import MET_COLUMN
17
21
18
22
from hbw .calibration .jet import bjet_regression
23
+ # from hbw.calibration.jet import (
24
+ # fatjet_jec_data, fatjet_jec_total, fatjet_jer,
25
+ # bjet_regression,
26
+ # )
19
27
20
28
ak = maybe_import ("awkward" )
21
29
np = maybe_import ("numpy" )
24
32
logger = law .logger .get_logger (__name__ )
25
33
26
34
35
+ # customized electron calibrator (also needs deterministic event seeds...)
36
+ electrons .deterministic_seed_index = 0
37
+
38
+
39
+ @calibrator (
40
+ version = 1 ,
41
+ uses = {electron_sceta , deterministic_event_seeds , deterministic_electron_seeds },
42
+ produces = {deterministic_event_seeds , deterministic_electron_seeds },
43
+ )
44
+ def ele (self : Calibrator , events : ak .Array , ** kwargs ) -> ak .Array :
45
+ """
46
+ Electron calibrator, combining scale and resolution.
47
+ """
48
+ # obtain the electron super cluster eta needed for the calibration
49
+ events = self [electron_sceta ](events , ** kwargs )
50
+
51
+ events = self [deterministic_event_seeds ](events , ** kwargs )
52
+ events = self [deterministic_electron_seeds ](events , ** kwargs )
53
+
54
+ # apply the electron calibration
55
+ events = self [self .electron_calib_cls ](events , ** kwargs )
56
+ return events
57
+
58
+
59
+ @ele .init
60
+ def ele_init (self : Calibrator ) -> None :
61
+ self .electron_calib_cls = electrons
62
+
63
+ self .uses |= {self .electron_calib_cls }
64
+ self .produces |= {self .electron_calib_cls }
65
+
66
+
27
67
@calibrator (
28
- # jec uncertainty_sources: set to None to use config default
29
- jec_sources = ["Total" ],
30
68
version = 1 ,
31
69
# add dummy produces such that this calibrator will always be run when requested
32
70
# (temporary workaround until init's are only run as often as necessary)
71
+ # TODO: deterministic FatJet seeds
33
72
produces = {"FatJet.pt" },
34
73
)
35
74
def fatjet (self : Calibrator , events : ak .Array , ** kwargs ) -> ak .Array :
36
75
"""
37
76
FatJet calibrator, combining JEC and JER.
77
+ Uses as JER uncertainty either only "Total" for MC or no uncertainty for data.
38
78
"""
39
79
if self .task .local_shift != "nominal" :
40
80
raise Exception ("FatJet Calibrator should not be run for shifts other than nominal" )
@@ -53,42 +93,65 @@ def fatjet_init(self: Calibrator) -> None:
53
93
# init only required for task itself
54
94
return
55
95
96
+ # derive calibrators to add settings once
97
+ flag = f"custom_fatjet_calibs_registered_{ self .cls_name } "
98
+ if not self .config_inst .x (flag , False ):
99
+ fatjet_jec_cls_dict = {
100
+ "jet_name" : "FatJet" ,
101
+ "gen_jet_name" : "GenJetAK8" ,
102
+ # MET propagation is performed in AK4 jet calibrator; fatjet should never use any MET columns
103
+ "propagate_met" : False ,
104
+ "met_name" : "DO_NOT_USE" ,
105
+ "raw_met_name" : "DO_NOT_USE" ,
106
+ }
107
+ fatjet_jer_cls_dict = fatjet_jec_cls_dict .copy ()
108
+ # NOTE: deterministic FatJet seeds are not yet possible to produce
109
+ # fatjet_jer_cls_dict["deterministic_seed_index"] = 0
110
+
111
+ # fatjet_jec = jec.derive("fatjet_jec", cls_dict={
112
+ # **fatjet_jec_cls_dict,
113
+ # })
114
+ self .config_inst .x .fatjet_jec_data_cls = jec .derive ("fatjet_jec_data" , cls_dict = {
115
+ ** fatjet_jec_cls_dict ,
116
+ "data_only" : True ,
117
+ "nominal_only" : True ,
118
+ "uncertainty_sources" : [],
119
+ })
120
+ self .config_inst .x .fatjet_jec_total_cls = jec .derive ("fatjet_jec_total" , cls_dict = {
121
+ ** fatjet_jec_cls_dict ,
122
+ "mc_only" : True ,
123
+ "nominal_only" : True ,
124
+ "uncertainty_sources" : ["Total" ],
125
+ })
126
+ self .config_inst .x .fatjet_jer_cls = jer .derive ("deterministic_fatjet_jer" , cls_dict = fatjet_jer_cls_dict )
127
+
128
+ # change the flag
129
+ self .config_inst .set_aux (flag , True )
130
+
56
131
if not getattr (self , "dataset_inst" , None ):
57
132
return
58
133
59
- # list of calibrators to apply (in that order)
60
- self .calibrators = []
61
-
62
- fatjet_jec_cls_dict = {
63
- "jet_name" : "FatJet" ,
64
- "gen_jet_name" : "GenJetAK8" ,
65
- # MET propagation is performed in AK4 jet calibrator; fatjet should never use any MET columns
66
- "propagate_met" : False ,
67
- "met_name" : "DO_NOT_USE" ,
68
- "raw_met_name" : "DO_NOT_USE" ,
69
- }
70
- fatjet_jer_cls_dict = fatjet_jec_cls_dict .copy ()
71
- # NOTE: deterministic FatJet seeds are not yet possible to produce
72
- # fatjet_jer_cls_dict["deterministic_seed_index"] = 0
73
-
74
- uncertainty_sources = [] if self .dataset_inst .is_data else self .jec_sources
75
- jec_cls_name = f"fatjet_jec{ '_nominal' if uncertainty_sources == [] else '' } "
76
- self .fatjet_jec_cls = jec .derive (jec_cls_name , cls_dict = {
77
- ** fatjet_jec_cls_dict ,
78
- "uncertainty_sources" : uncertainty_sources ,
79
- })
80
- self .fatjet_jer_cls = jer .derive ("deterministic_fatjet_jer" , cls_dict = fatjet_jer_cls_dict )
134
+ # chose the JEC and JER calibrators based on dataset instance
135
+ self .fatjet_jec_cls = (
136
+ self .config_inst .x .fatjet_jec_total_cls if self .dataset_inst .is_mc
137
+ else self .config_inst .x .fatjet_jec_data_cls
138
+ )
139
+ self .fatjet_jer_cls = self .config_inst .x .fatjet_jer_cls
81
140
82
141
self .uses |= {self .fatjet_jec_cls , self .fatjet_jer_cls }
83
142
self .produces |= {self .fatjet_jec_cls , self .fatjet_jer_cls }
84
143
85
144
145
+ fatjet_test = fatjet .derive ("fatjet_test" )
146
+
147
+
86
148
@calibrator (
87
149
uses = {deterministic_seeds , MET_COLUMN ("{pt,phi}" )},
88
150
produces = {deterministic_seeds },
89
151
# jec uncertainty_sources: set to None to use config default
90
152
jec_sources = ["Total" ],
91
153
bjet_regression = True ,
154
+ skip_jer = False ,
92
155
version = 1 ,
93
156
)
94
157
def jet_base (self : Calibrator , events : ak .Array , ** kwargs ) -> ak .Array :
@@ -126,51 +189,74 @@ def jet_base_init(self: Calibrator) -> None:
126
189
# init only required for task itself
127
190
return
128
191
192
+ # derive calibrators to add settings once
193
+ flag = f"custom_jet_calibs_registered_{ self .cls_name } "
194
+ if not self .config_inst .x (flag , False ):
195
+ met_name = self .config_inst .x .met_name
196
+ raw_met_name = self .config_inst .x .raw_met_name
197
+
198
+ jec_cls_kwargs = {
199
+ "nominal_only" : True ,
200
+ "met_name" : met_name ,
201
+ "raw_met_name" : raw_met_name ,
202
+ }
203
+
204
+ # jec calibrators
205
+ self .config_inst .x .calib_jec_full_cls = jec .derive ("jec_full" , cls_dict = {
206
+ ** jec_cls_kwargs ,
207
+ "mc_only" : True ,
208
+ "uncertainty_sources" : self .jec_sources ,
209
+ })
210
+ self .config_inst .x .calib_jec_data_cls = jec .derive ("jec_data" , cls_dict = {
211
+ ** jec_cls_kwargs ,
212
+ "data_only" : True ,
213
+ "uncertainty_sources" : [],
214
+ })
215
+ # version of jer that uses the first random number from deterministic_seeds
216
+ self .config_inst .x .calib_deterministic_jer_cls = jer .derive ("deterministic_jer" , cls_dict = {
217
+ "deterministic_seed_index" : 0 ,
218
+ "met_name" : met_name ,
219
+ })
220
+ # derive met_phi calibrator (currently only used in run 2)
221
+ self .config_inst .x .calib_met_phi_cls = met_phi .derive ("met_phi" , cls_dict = {
222
+ "met_name" : met_name ,
223
+ })
224
+ # change the flag
225
+ self .config_inst .set_aux (flag , True )
226
+
129
227
if not getattr (self , "dataset_inst" , None ):
130
228
return
131
229
132
- met_name = self .config_inst .x .met_name
133
- raw_met_name = self .config_inst .x .raw_met_name
134
-
135
230
# list of calibrators to apply (in that order)
136
231
self .calibrators = []
137
232
138
- uncertainty_sources = [] if self .dataset_inst .is_data else self .jec_sources
139
- jec_cls_name = f"ak4_jec{ '_nominal' if uncertainty_sources == [] else '' } "
140
-
141
- jec_cls = jec .derive (
142
- jec_cls_name ,
143
- cls_dict = {
144
- "uncertainty_sources" : uncertainty_sources ,
145
- "met_name" : met_name ,
146
- "raw_met_name" : raw_met_name ,
147
- },
233
+ # JEC
234
+ jec_cls = (
235
+ self .config_inst .x .calib_jec_full_cls if self .dataset_inst .is_mc
236
+ else self .config_inst .x .calib_jec_data_cls
148
237
)
149
238
self .calibrators .append (jec_cls )
150
239
240
+ # BJet regression
151
241
if self .bjet_regression :
152
242
self .calibrators .append (bjet_regression )
153
243
154
- # run JER only on MC
155
- if self .dataset_inst .is_mc :
156
- # version of jer that uses the first random number from deterministic_seeds
157
- deterministic_jer_cls = jer .derive (
158
- "deterministic_jer" ,
159
- cls_dict = {
160
- "deterministic_seed_index" : 0 ,
161
- "met_name" : met_name ,
162
- },
163
- )
164
- self .calibrators .append (deterministic_jer_cls )
244
+ # JER (only for MC)
245
+ jer_cls = self .config_inst .x .calib_deterministic_jer_cls
246
+ if self .dataset_inst .is_mc and not self .skip_jer :
247
+ self .calibrators .append (jer_cls )
165
248
249
+ # MET phi (only in run 2)
166
250
if self .config_inst .x .run == 2 :
167
- # derive met_phi calibrator (currently only for run 2)
168
- met_phi_cls = met_phi .derive ("met_phi" , cls_dict = {"met_name" : met_name })
251
+ met_phi_cls = self .config_inst .x .calib_met_phi_cls
169
252
self .calibrators .append (met_phi_cls )
170
253
171
254
self .uses |= set (self .calibrators )
172
255
self .produces |= set (self .calibrators )
173
256
174
257
175
- skip_jecunc = jet_base .derive ("skip_jecunc" , cls_dict = dict (bjet_regression = False ))
258
+ jec_only = jet_base .derive ("jec_only" , cls_dict = dict (bjet_regression = False , skip_jer = True ))
259
+ skip_jer = jet_base .derive ("skip_jer" , cls_dict = dict (bjet_regression = True , skip_jer = True ))
260
+ no_breg = jet_base .derive ("no_breg" , cls_dict = dict (bjet_regression = False ))
176
261
with_b_reg = jet_base .derive ("with_b_reg" , cls_dict = dict (bjet_regression = True ))
262
+ with_b_reg_test = jet_base .derive ("with_b_reg_test" , cls_dict = dict (bjet_regression = True ))
0 commit comments