11Script to perform the SVD dE/dx calibration
13from prompt
import CalibrationSettings, INPUT_DATA_FILTERS
15from ROOT.Belle2
import SVDdEdxCalibrationAlgorithm, SVDdEdxValidationAlgorithm
17import modularAnalysis
as ma
19import reconstruction
as re
21settings = CalibrationSettings(
23 expert_username=
"lisovsky",
25 input_data_formats=[
"cdst"],
26 input_data_names=[
"hadron_calib"],
27 input_data_filters={
"hadron_calib": [INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"],
28 INPUT_DATA_FILTERS[
"Beam Energy"][
"4S"],
29 INPUT_DATA_FILTERS[
"Beam Energy"][
"Continuum"],
30 INPUT_DATA_FILTERS[
"Run Type"][
"physics"],
31 INPUT_DATA_FILTERS[
"Magnet"][
"On"]]},
35 "listOfMutedCalibrations": [],
37 "rerun_reco_val":
True,
38 "validation_mode":
"basic",
40 "MaxFilesPerRunValidation": 6,
42 "MaxEvtsPerFile": 20000,
43 "MinEvtsPerTree": 100,
49 "MaxROCMomentum": 2.5,
56def create_path(rerun_reco, isMC, expert_config):
60 max_events_per_file = expert_config[
"MaxEvtsPerFile"]
77 entrySequences=[f
'0:{max_events_per_file - 1}'],
78 logLevel=b2.LogLevel.ERROR)
80 re.add_unpackers(path=rec_path)
82 rec_path.add_module(
"Gearbox")
83 rec_path.add_module(
"Geometry")
85 re.add_reconstruction(path=rec_path, pruneTracks=
False)
86 rec_path.add_module(
'VXDDedxPID')
88 rec_path.add_module(
'RootInput')
91 ma.fillParticleList(
"pi+:all",
"", path=rec_path)
92 ma.fillParticleList(
"pi+:lambda",
"nCDCHits > 0", path=rec_path)
93 ma.fillParticleList(
"pi+:cut",
"abs(dr) < 0.5 and abs(dz) < 2 and pValue > 0.00001 and nSVDHits > 1",
96 ma.fillParticleList(
'K-:cut', cut=
'abs(dr) < 0.5 and abs(dz) < 2 and pValue > 0.00001 and nSVDHits > 1', path=rec_path)
97 ma.fillParticleList(
'e+:cut', cut=
'nSVDHits > 0', path=rec_path)
99 ma.fillParticleList(
'p+:lambda', cut=
'nCDCHits > 0 and nSVDHits > 0 and p > 0.25', path=rec_path)
102 ma.reconstructDecay(decayString=
'D0:kpi -> K-:cut pi+:cut', cut=
'1.7 < M < 2.', path=rec_path)
104 decayString=
'D*+:myDstar -> D0:kpi pi+:all',
105 cut=
'1.95 < M <2.05 and massDifference(0) < 0.16',
109 ma.reconstructDecay(
'Lambda0:myLambda -> p+:lambda pi-:lambda',
'1.1 < M < 1.3', path=rec_path)
112 ma.reconstructDecay(
'gamma:myGamma -> e+:cut e-:cut',
'0.0 < M < 0.5', path=rec_path)
116 vx.treeFit(list_name=
'D*+:myDstar', conf_level=0, ipConstraint=
True, updateAllDaughters=
True, path=rec_path)
117 vx.treeFit(list_name=
'Lambda0:myLambda', conf_level=0, ipConstraint=
True, updateAllDaughters=
True, path=rec_path)
118 vx.treeFit(list_name=
'gamma:myGamma', conf_level=0, path=rec_path)
129 outputListName=
'Lambda0:cut',
130 inputListName=
'Lambda0:myLambda',
132 "1.10 < InvM < 1.13 and chiProb > 0.001 and distance>1.0 and "
133 "formula(daughter(0,p)) > formula(daughter(1,p)) and convertedPhotonInvariantMass(0,1) > 0.02 and "
134 "[[formula((((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
135 "daughter(1, E))*((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
136 "daughter(1, E))-(daughter(0, px)+daughter(1, px))*(daughter(0, px)+daughter(1, px))-(daughter(0, py)+"
137 "daughter(1, py))*(daughter(0, py)+daughter(1, py))-(daughter(0, pz)+daughter(1, pz))*(daughter(0, pz)+"
138 "daughter(1, pz)))**0.5) < 0.488]"
139 "or [formula((((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
140 "daughter(1, E))*((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
141 "daughter(1, E))-(daughter(0, px)+daughter(1, px))*(daughter(0, px)+daughter(1, px))-(daughter(0, py)+"
142 "daughter(1, py))*(daughter(0, py)+daughter(1, py))-(daughter(0, pz)+daughter(1, pz))*(daughter(0, pz)+"
143 "daughter(1, pz)))**0.5) > 0.513]]"
153 outputListName=
'D*+:cut',
154 inputListName=
'D*+:myDstar',
155 cut=
'massDifference(0) < 0.151 and 1.85 < daughter(0, InvM) < 1.88 and 1.95 < InvM < 2.05 and chiProb > 0.001',
166 outputListName=
'gamma:cut',
167 inputListName=
'gamma:myGamma',
168 cut=(
'chiProb > 0.001 and 1 < dr < 12 and InvM < 0.01'
169 'and convertedPhotonInvariantMass(0,1) < 0.005'
170 'and -0.05 < convertedPhotonDelR(0,1) < 0.15'
171 'and -0.05 < convertedPhotonDelZ(0,1) < 0.05'
177def get_calibrations(input_data, **kwargs):
180 input_data (dict): Should contain every name from the
'input_data_names' variable
as a key.
181 Each value
is a dictionary
with {
"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful
for
182 assigning to calibration.files_to_iov
184 **kwargs: Configuration options to be sent
in. Since this may change we use kwargs
as a way to help prevent
185 backwards compatibility problems. But you could use the correct arguments
in b2caf-prompt-run
for this
186 release explicitly
if you want to.
188 Currently only kwargs[
"requested_iov"]
and kwargs[
"expert_config"] are used.
190 "requested_iov" is the IoV range of the bucket
and your payloads should correspond to this range.
191 However your highest payload IoV should be open ended e.g. IoV(3,4,-1,-1)
193 "expert_config" is the input configuration. It takes default values
from your `CalibrationSettings` but these are
194 overwritten by values
from the
'expert_config' key
in your input `caf_config.json` file when running ``b2caf-prompt-run``.
197 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
204 file_to_iov_hadron_calib = input_data[
"hadron_calib"]
206 expert_config = kwargs.get(
"expert_config")
208 isMC = expert_config[
"isMC"]
209 listOfMutedCalibrations = expert_config[
"listOfMutedCalibrations"]
210 rerun_reco = expert_config[
"rerun_reco"]
211 rerun_reco_val = expert_config[
"rerun_reco_val"]
212 max_files_per_run = expert_config[
"MaxFilesPerRun"]
213 max_files_per_run_validation = expert_config[
"MaxFilesPerRunValidation"]
216 validation_mode = 1
if expert_config[
"validation_mode"] ==
"full" else 0
221 min_events_per_file = expert_config[
"MinEvtsPerFile"]
225 reduced_file_to_iov_hadron_calib = filter_by_max_files_per_run(file_to_iov_hadron_calib, max_files_per_run, min_events_per_file)
226 input_files_hadron_calib = list(reduced_file_to_iov_hadron_calib.keys())
227 basf2.B2INFO(f
"Total number of files actually used as input for calibration = {len(input_files_hadron_calib)}")
229 if "dEdxValidation" not in listOfMutedCalibrations:
230 reduced_file_to_iov_hadron_validation = filter_by_max_files_per_run(
231 file_to_iov_hadron_calib, max_files_per_run_validation, min_events_per_file)
232 input_files_hadron_validation = list(reduced_file_to_iov_hadron_validation.keys())
233 basf2.B2INFO(f
"Total number of files actually used as input for validation = {len(input_files_hadron_validation)}")
236 requested_iov = kwargs.get(
"requested_iov",
None)
238 from caf.utils
import IoV
240 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
245 algo = SVDdEdxCalibrationAlgorithm()
246 algo.setMonitoringPlots(
True)
247 algo.setNumPBins(expert_config[
'NBinsP'])
248 algo.setNumDEdxBins(expert_config[
'NBinsdEdx'])
249 algo.setDEdxCutoff(expert_config[
'dedxCutoff'])
250 algo.setMinEvtsPerTree(expert_config[
'MinEvtsPerTree'])
252 if "dEdxValidation" not in listOfMutedCalibrations:
253 algo_val = SVDdEdxValidationAlgorithm()
254 algo_val.setMonitoringPlots(
True)
255 algo_val.setMinEvtsPerTree(expert_config[
'MinEvtsPerTree'])
256 algo_val.setNumROCpoints(expert_config[
'NumROCpoints'])
257 algo_val.setMinROCMomentum(expert_config[
'MinROCMomentum'])
258 algo_val.setMaxROCMomentum(expert_config[
'MaxROCMomentum'])
259 algo_val.setNumEffBins(expert_config[
'NumEffBins'])
260 algo_val.setMaxEffMomentum(expert_config[
'MaxEffMomentum'])
261 algo_val.validationMode(validation_mode)
266 from caf.framework
import Calibration
268 rec_path = create_path(rerun_reco, isMC, expert_config)
269 rec_path_validation = create_path(rerun_reco_val, isMC, expert_config)
271 dedx_calibration =
Calibration(
"SVDdEdxCalibration",
272 collector=
"SVDdEdxCollector",
274 input_files=input_files_hadron_calib,
275 pre_collector_path=rec_path)
277 if "dEdxValidation" not in listOfMutedCalibrations:
279 collector=
"SVDdEdxValidationCollector",
280 algorithms=[algo_val],
281 backend_args={
"queue":
"l"},
282 input_files=input_files_hadron_validation,
283 pre_collector_path=rec_path_validation)
286 for algorithm
in dedx_calibration.algorithms:
287 algorithm.params = {
"apply_iov": output_iov}
292 if "dEdxValidation" not in listOfMutedCalibrations:
293 dedx_validation.depends_on(dedx_calibration)
295 list_of_calibrations = []
296 if "dEdxCalibration" not in listOfMutedCalibrations:
297 list_of_calibrations.append(dedx_calibration)
298 if "dEdxValidation" not in listOfMutedCalibrations:
299 list_of_calibrations.append(dedx_validation)
301 return list_of_calibrations