117def getJetCalibTool(jetdef, context, data_type, calibseq = "", rhoname = "", pvname = "PrimaryVertices", gscdepth = "auto"):
118
119 jetcollection = jetdef.basename
120
121
122 if data_type not in ['data','mc','afii']:
123 jetcaliblog.error("JetCalibConfig accepts data_type values: 'data', 'mc', 'afii'")
124 raise ValueError("Unsupported data_type provided: '{0}".format(data_type))
125
126 if jetcollection.endswith("Jets"):
127 jetcaliblog.error("Jet collection '{0}'should be specified w/o 'Jets' in the name.".format(jetcollection))
128 raise ValueError("Bad jet collection formatting in getJetCalibTool.")
129
130 jetcaliblog.debug("Preparing calibration for {0}, in context {1} on sample type {2}".format(jetcollection,context,data_type))
131
132 jetcontexts = calibcontexts[jetcollection]
133
134 if jetcollection == "AntiKt4EMTopo" and context == "T0":
135 if jetdef._cflags.GeoModel.Run >= LHCPeriod.Run4:
136 context = "HLLHC"
137
138 try:
139 configfile, calibarea, calibseq_def = jetcontexts[context]
140 _calibseq = calibseq if calibseq else calibseq_def
141
142
143
144
145 if _calibseq.endswith("Insitu"):
146 if data_type == 'data':
147 if jetcollection not in hasInSitu:
148 raise ValueError("In situ calibration does not exist for {0}, context {1}".format(jetcollection,context))
149 else:
150 raise ValueError("In situ calibration requested for MC on {0}, context {1}".format(jetcollection,context))
151 _configfile = configfile
152 if data_type == "afii" and jetcollection in af2configs.keys():
153 _configfile = af2configs[jetcollection]
154 _data_type = data_type
155
156
157
158 if context == "T0":
159 _data_type = "data"
160 _pvname = ""
161 if "Residual" in _calibseq or "GSC" in _calibseq and gscdepth!="EM3" or "LargeRDNN" in _calibseq:
162 _pvname = pvname
163
164 if context == "TrigHIUPC":
165 _pvname = pvname
166
167 _jetcollection = jetcollection
168 if "PFlow" in jetcollection and (context=="TrigSoftDrop" or context=="TrigHLTSoftDrop"):
169 _jetcollection = jetcollection.replace("EMPFlow","UFO")
170
171
172
173 ignore_substr = [
174 '_noElectrons', '_noMuons', '_noLeptons', '_inclMuons',
175 '_tauSeedEleRM',
176 'ByVertex', 'CustomVtxGNN', 'CustomVtx',
177 ]
178 for text in ignore_substr:
179 if text in jetcollection :
180 _jetcollection = _jetcollection.replace(text,"")
181
182 return defineJetCalibTool(_jetcollection, context, _configfile, calibarea, _calibseq, _data_type, rhoname, _pvname, gscdepth)
183 except KeyError as e:
184 jetcaliblog.error("Context '{0}' not found for jet collection '{1}'".format(context,jetcollection))
185 jetcaliblog.error("Options are '{0}".format(','.join(jetcontexts.keys())))
186 raise e
187 return None
188
189