11Script to perform the SVD dE/dx calibration
13from prompt
import CalibrationSettings, INPUT_DATA_FILTERS
16import modularAnalysis
as ma
18from reconstruction
import prepare_user_cdst_analysis
20settings = CalibrationSettings(
22 expert_username=
"lisovsky",
24 input_data_formats=[
"cdst"],
25 input_data_names=[
"hadron_calib"],
26 input_data_filters={
"hadron_calib": [INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"],
27 INPUT_DATA_FILTERS[
"Beam Energy"][
"4S"],
28 INPUT_DATA_FILTERS[
"Beam Energy"][
"Continuum"],
29 INPUT_DATA_FILTERS[
"Run Type"][
"physics"],
30 INPUT_DATA_FILTERS[
"Magnet"][
"On"]]},
34 "listOfMutedCalibrations": [],
36 "rerun_pid_val":
True,
37 "validation_mode":
"basic",
39 "MaxFilesPerRunValidation": 6,
41 "MaxEvtsPerFile": 20000,
42 "MinEvtsPerTree": 100,
48 "MaxROCMomentum": 2.5,
55def create_path(rerun_pid, isMC, expert_config):
59 max_events_per_file = expert_config[
"MaxEvtsPerFile"]
62 rec_path.add_module(
'RootInput', entrySequences=[f
'0:{max_events_per_file - 1}']
64 prepare_user_cdst_analysis(rec_path, mc=isMC)
67 rec_path.add_module(
'RootInput')
70 ma.fillParticleList(
"pi+:all",
"", path=rec_path)
71 ma.fillParticleList(
"pi+:lambda",
"nCDCHits > 0", path=rec_path)
72 ma.fillParticleList(
"pi+:cut",
"abs(dr) < 0.5 and abs(dz) < 2 and pValue > 0.00001 and nSVDHits > 1",
75 ma.fillParticleList(
'K-:cut', cut=
'abs(dr) < 0.5 and abs(dz) < 2 and pValue > 0.00001 and nSVDHits > 1', path=rec_path)
76 ma.fillParticleList(
'e+:cut', cut=
'nSVDHits > 0', path=rec_path)
78 ma.fillParticleList(
'p+:lambda', cut=
'nCDCHits > 0 and nSVDHits > 0 and p > 0.25', path=rec_path)
81 ma.reconstructDecay(decayString=
'D0:kpi -> K-:cut pi+:cut', cut=
'1.7 < M < 2.', path=rec_path)
83 decayString=
'D*+:myDstar -> D0:kpi pi+:all',
84 cut=
'1.95 < M <2.05 and massDifference(0) < 0.16',
88 ma.reconstructDecay(
'Lambda0:myLambda -> p+:lambda pi-:lambda',
'1.1 < M < 1.3', path=rec_path)
91 ma.reconstructDecay(
'gamma:myGamma -> e+:cut e-:cut',
'0.0 < M < 0.5', path=rec_path)
95 vx.treeFit(list_name=
'D*+:myDstar', conf_level=0, ipConstraint=
True, updateAllDaughters=
True, path=rec_path)
96 vx.treeFit(list_name=
'Lambda0:myLambda', conf_level=0, ipConstraint=
True, updateAllDaughters=
True, path=rec_path)
97 vx.treeFit(list_name=
'gamma:myGamma', conf_level=0, path=rec_path)
108 outputListName=
'Lambda0:cut',
109 inputListName=
'Lambda0:myLambda',
111 "1.10 < InvM < 1.13 and chiProb > 0.001 and distance>1.0 and "
112 "formula(daughter(0,p)) > formula(daughter(1,p)) and convertedPhotonInvariantMass(0,1) > 0.02 and "
113 "[[formula((((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
114 "daughter(1, E))*((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
115 "daughter(1, E))-(daughter(0, px)+daughter(1, px))*(daughter(0, px)+daughter(1, px))-(daughter(0, py)+"
116 "daughter(1, py))*(daughter(0, py)+daughter(1, py))-(daughter(0, pz)+daughter(1, pz))*(daughter(0, pz)+"
117 "daughter(1, pz)))**0.5) < 0.488]"
118 "or [formula((((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
119 "daughter(1, E))*((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
120 "daughter(1, E))-(daughter(0, px)+daughter(1, px))*(daughter(0, px)+daughter(1, px))-(daughter(0, py)+"
121 "daughter(1, py))*(daughter(0, py)+daughter(1, py))-(daughter(0, pz)+daughter(1, pz))*(daughter(0, pz)+"
122 "daughter(1, pz)))**0.5) > 0.513]]"
132 outputListName=
'D*+:cut',
133 inputListName=
'D*+:myDstar',
134 cut=
'massDifference(0) < 0.151 and 1.85 < daughter(0, InvM) < 1.88 and 1.95 < InvM < 2.05 and chiProb > 0.001',
145 outputListName=
'gamma:cut',
146 inputListName=
'gamma:myGamma',
147 cut=(
'chiProb > 0.001 and 1 < dr < 12 and InvM < 0.01'
148 'and convertedPhotonInvariantMass(0,1) < 0.005'
149 'and -0.05 < convertedPhotonDelR(0,1) < 0.15'
150 'and -0.05 < convertedPhotonDelZ(0,1) < 0.05'
156def get_calibrations(input_data, **kwargs):
159 input_data (dict): Should contain every name from the
'input_data_names' variable
as a key.
160 Each value
is a dictionary
with {
"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful
for
161 assigning to calibration.files_to_iov
163 **kwargs: Configuration options to be sent
in. Since this may change we use kwargs
as a way to help prevent
164 backwards compatibility problems. But you could use the correct arguments
in b2caf-prompt-run
for this
165 release explicitly
if you want to.
167 Currently only kwargs[
"requested_iov"]
and kwargs[
"expert_config"] are used.
169 "requested_iov" is the IoV range of the bucket
and your payloads should correspond to this range.
170 However your highest payload IoV should be open ended e.g. IoV(3,4,-1,-1)
172 "expert_config" is the input configuration. It takes default values
from your `CalibrationSettings` but these are
173 overwritten by values
from the
'expert_config' key
in your input `caf_config.json` file when running ``b2caf-prompt-run``.
176 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
183 file_to_iov_hadron_calib = input_data[
"hadron_calib"]
185 expert_config = kwargs.get(
"expert_config")
187 isMC = expert_config[
"isMC"]
188 listOfMutedCalibrations = expert_config[
"listOfMutedCalibrations"]
189 rerun_pid = expert_config[
"rerun_pid"]
190 rerun_pid_val = expert_config[
"rerun_pid_val"]
191 max_files_per_run = expert_config[
"MaxFilesPerRun"]
192 max_files_per_run_validation = expert_config[
"MaxFilesPerRunValidation"]
195 validation_mode = 1
if expert_config[
"validation_mode"] ==
"full" else 0
200 min_events_per_file = expert_config[
"MinEvtsPerFile"]
204 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)
205 input_files_hadron_calib = list(reduced_file_to_iov_hadron_calib.keys())
206 basf2.B2INFO(f
"Total number of files actually used as input for calibration = {len(input_files_hadron_calib)}")
208 if "dEdxValidation" not in listOfMutedCalibrations:
209 reduced_file_to_iov_hadron_validation = filter_by_max_files_per_run(
210 file_to_iov_hadron_calib, max_files_per_run_validation, min_events_per_file)
211 input_files_hadron_validation = list(reduced_file_to_iov_hadron_validation.keys())
212 basf2.B2INFO(f
"Total number of files actually used as input for validation = {len(input_files_hadron_validation)}")
215 requested_iov = kwargs.get(
"requested_iov",
None)
217 from caf.utils
import IoV
219 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
223 from ROOT
import Belle2
224 from ROOT.Belle2
import SVDdEdxCalibrationAlgorithm, SVDdEdxValidationAlgorithm
226 algo = SVDdEdxCalibrationAlgorithm()
227 algo.setMonitoringPlots(
True)
228 algo.setNumPBins(expert_config[
'NBinsP'])
229 algo.setNumDEdxBins(expert_config[
'NBinsdEdx'])
230 algo.setDEdxCutoff(expert_config[
'dedxCutoff'])
231 algo.setMinEvtsPerTree(expert_config[
'MinEvtsPerTree'])
233 if "dEdxValidation" not in listOfMutedCalibrations:
234 algo_val = SVDdEdxValidationAlgorithm()
235 algo_val.setMonitoringPlots(
True)
236 algo_val.setMinEvtsPerTree(expert_config[
'MinEvtsPerTree'])
237 algo_val.setNumROCpoints(expert_config[
'NumROCpoints'])
238 algo_val.setMinROCMomentum(expert_config[
'MinROCMomentum'])
239 algo_val.setMaxROCMomentum(expert_config[
'MaxROCMomentum'])
240 algo_val.setNumEffBins(expert_config[
'NumEffBins'])
241 algo_val.setMaxEffMomentum(expert_config[
'MaxEffMomentum'])
242 algo_val.validationMode(validation_mode)
247 from caf.framework
import Calibration
249 rec_path = create_path(rerun_pid, isMC, expert_config)
250 rec_path_validation = create_path(rerun_pid_val, isMC, expert_config)
252 dedx_calibration =
Calibration(
"SVDdEdxCalibration",
253 collector=
"SVDdEdxCollector",
255 input_files=input_files_hadron_calib,
256 pre_collector_path=rec_path)
258 if "dEdxValidation" not in listOfMutedCalibrations:
260 collector=
"SVDdEdxValidationCollector",
261 algorithms=[algo_val],
262 backend_args={
"queue":
"l"},
263 input_files=input_files_hadron_validation,
264 pre_collector_path=rec_path_validation)
267 for algorithm
in dedx_calibration.algorithms:
268 algorithm.params = {
"apply_iov": output_iov}
273 if "dEdxValidation" not in listOfMutedCalibrations:
274 dedx_validation.depends_on(dedx_calibration)
276 list_of_calibrations = []
277 if "dEdxCalibration" not in listOfMutedCalibrations:
278 list_of_calibrations.append(dedx_calibration)
279 if "dEdxValidation" not in listOfMutedCalibrations:
280 list_of_calibrations.append(dedx_validation)
282 return list_of_calibrations