11Script to perform the SVD dE/dx calibration
13from prompt
import CalibrationSettings, INPUT_DATA_FILTERS
17import modularAnalysis
as ma
19import reconstruction
as re
20from reconstruction
import prepare_user_cdst_analysis, DIGITS_OBJECTS
22settings = CalibrationSettings(
24 expert_username=
"lisovsky",
26 input_data_formats=[
"cdst"],
27 input_data_names=[
"hadron_calib"],
28 input_data_filters={
"hadron_calib": [INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"],
29 INPUT_DATA_FILTERS[
"Beam Energy"][
"4S"],
30 INPUT_DATA_FILTERS[
"Beam Energy"][
"Continuum"],
31 INPUT_DATA_FILTERS[
"Run Type"][
"physics"],
32 INPUT_DATA_FILTERS[
"Magnet"][
"On"]]},
36 "listOfMutedCalibrations": [],
39 "rerun_reco_val":
False,
41 "rerun_pid_val":
True,
43 "validation_mode":
"basic",
45 "MaxFilesPerRunValidation": 6,
47 "MaxEvtsPerFile": 20000,
48 "MinEvtsPerTree": 100,
55 "CustomProfile":
True,
57 "FixUnstableFitParameter":
True,
59 "NEventsToGenerate": 5e5,
60 "UsePionBGFunctionForEverything":
False,
62 "UseProtonBGFunctionForEverything":
False,
65 "MaxROCMomentum": 2.5,
73def create_path(rerun_reco, rerun_pid, isMC, expert_config):
77 max_events_per_file = expert_config[
"MaxEvtsPerFile"]
83 branchNames=HLT_INPUT_OBJECTS,
84 entrySequences=[f
'0:{max_events_per_file - 1}'],
85 logLevel=b2.LogLevel.ERROR)
86 re.add_unpackers(path=rec_path)
88 rec_path.add_module(
'RootInput', branchNames=list(DIGITS_OBJECTS) + [
90 'EventLevelTriggerTimeInfo',
91 'SoftwareTriggerResult',
92 'TRGSummary'], entrySequences=[f
'0:{max_events_per_file - 1}'])
93 rec_path.add_module(
"Gearbox")
94 rec_path.add_module(
"Geometry")
96 re.add_reconstruction(path=rec_path, pruneTracks=
False)
97 rec_path.add_module(
'VXDDedxPID')
99 rec_path.add_module(
'RootInput', entrySequences=[f
'0:{max_events_per_file - 1}'])
100 prepare_user_cdst_analysis(rec_path, mc=isMC)
102 rec_path.add_module(
'RootInput')
105 ma.fillParticleList(
"pi+:all",
"", path=rec_path)
106 ma.fillParticleList(
"pi+:lambda",
"nCDCHits > 0", path=rec_path)
107 ma.fillParticleList(
"pi+:cut",
"abs(dr) < 0.5 and abs(dz) < 2 and nSVDHits > 1",
110 ma.fillParticleList(
'K-:cut', cut=
'abs(dr) < 0.5 and abs(dz) < 2 and nSVDHits > 1', path=rec_path)
111 ma.fillParticleList(
'e+:cut', cut=
'nSVDHits > 0', path=rec_path)
113 ma.fillParticleList(
'p+:lambda', cut=
'nCDCHits > 0 and nSVDHits > 0 and p > 0.135', path=rec_path)
116 ma.reconstructDecay(decayString=
'D0:kpi -> K-:cut pi+:cut', cut=
'1.7 < M < 2.', path=rec_path)
118 decayString=
'D*+:myDstar -> D0:kpi pi+:all',
119 cut=
'1.95 < M <2.05 and massDifference(0) < 0.16',
123 ma.reconstructDecay(
'Lambda0:myLambda -> p+:lambda pi-:lambda',
'1.1 < M < 1.3', path=rec_path)
126 ma.reconstructDecay(
'gamma:myGamma -> e+:cut e-:cut',
'0.0 < M < 0.5', path=rec_path)
130 vx.treeFit(list_name=
'D*+:myDstar', conf_level=0, ipConstraint=
True, updateAllDaughters=
True, path=rec_path)
131 vx.treeFit(list_name=
'Lambda0:myLambda', conf_level=0, ipConstraint=
True, updateAllDaughters=
True, path=rec_path)
132 vx.treeFit(list_name=
'gamma:myGamma', conf_level=0, path=rec_path)
143 outputListName=
'Lambda0:cut',
144 inputListName=
'Lambda0:myLambda',
146 "1.10 < InvM < 1.13 and chiProb > 0.001 and distance > 1.0 and "
147 "cosAngleBetweenMomentumAndVertexVector > 0 and "
148 "formula(daughter(0,p)) > formula(daughter(1,p)) and convertedPhotonInvariantMass(0,1) > 0.02 and "
149 "[[formula((((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
150 "daughter(1, E))*((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
151 "daughter(1, E))-(daughter(0, px)+daughter(1, px))*(daughter(0, px)+daughter(1, px))-(daughter(0, py)+"
152 "daughter(1, py))*(daughter(0, py)+daughter(1, py))-(daughter(0, pz)+daughter(1, pz))*(daughter(0, pz)+"
153 "daughter(1, pz)))**0.5) < 0.488]"
154 "or [formula((((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
155 "daughter(1, E))*((daughter(0, px)**2+daughter(0, py)**2+daughter(0, pz)**2 + 0.13957**2)**0.5+"
156 "daughter(1, E))-(daughter(0, px)+daughter(1, px))*(daughter(0, px)+daughter(1, px))-(daughter(0, py)+"
157 "daughter(1, py))*(daughter(0, py)+daughter(1, py))-(daughter(0, pz)+daughter(1, pz))*(daughter(0, pz)+"
158 "daughter(1, pz)))**0.5) > 0.513]]"
168 outputListName=
'D*+:cut',
169 inputListName=
'D*+:myDstar',
170 cut=(
'massDifference(0) < 0.151 and 1.85 < daughter(0, InvM) < 1.88 and '
171 '1.95 < InvM < 2.05 and chiProb > 0.001 and '
172 'formula(daughter(0,cosAngleBetweenMomentumAndVertexVector))>-0.75'),
183 outputListName=
'gamma:cut',
184 inputListName=
'gamma:myGamma',
185 cut=(
'chiProb > 0.001 and 1 < dr < 12 and InvM < 0.01'
186 ' and cosAngleBetweenMomentumAndVertexVector > 0.995'
187 ' and convertedPhotonInvariantMass(0,1) < 0.005'
188 ' and -0.05 < convertedPhotonDelR(0,1) < 0.15'
189 ' and -0.05 < convertedPhotonDelZ(0,1) < 0.05'
195def get_calibrations(input_data, **kwargs):
198 input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
199 Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
200 assigning to calibration.files_to_iov
202 **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
203 backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
204 release explicitly if you want to.
206 Currently only kwargs["requested_iov"] and kwargs["expert_config"] are used.
208 "requested_iov" is the IoV range of the bucket and your payloads should correspond to this range.
209 However your highest payload IoV should be open ended e.g. IoV(3,4,-1,-1)
211 "expert_config" is the input configuration. It takes default values from your `CalibrationSettings` but these are
212 overwritten by values from the 'expert_config' key in your input `caf_config.json` file when running ``b2caf-prompt-run``.
215 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
222 file_to_iov_hadron_calib = input_data[
"hadron_calib"]
224 expert_config = kwargs.get(
"expert_config")
226 isMC = expert_config[
"isMC"]
227 listOfMutedCalibrations = expert_config[
"listOfMutedCalibrations"]
228 rerun_reco = expert_config[
"rerun_reco"]
229 rerun_reco_val = expert_config[
"rerun_reco_val"]
230 rerun_pid_val = expert_config[
"rerun_pid_val"]
231 max_files_per_run = expert_config[
"MaxFilesPerRun"]
232 max_files_per_run_validation = expert_config[
"MaxFilesPerRunValidation"]
235 validation_mode = 1
if expert_config[
"validation_mode"] ==
"full" else 0
240 min_events_per_file = expert_config[
"MinEvtsPerFile"]
244 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)
245 input_files_hadron_calib = list(reduced_file_to_iov_hadron_calib.keys())
246 basf2.B2INFO(f
"Total number of files actually used as input for calibration = {len(input_files_hadron_calib)}")
248 if "dEdxValidation" not in listOfMutedCalibrations:
249 reduced_file_to_iov_hadron_validation = filter_by_max_files_per_run(
250 file_to_iov_hadron_calib, max_files_per_run_validation, min_events_per_file)
251 input_files_hadron_validation = list(reduced_file_to_iov_hadron_validation.keys())
252 basf2.B2INFO(f
"Total number of files actually used as input for validation = {len(input_files_hadron_validation)}")
255 requested_iov = kwargs.get(
"requested_iov",
None)
257 from caf.utils
import IoV
259 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
263 from ROOT
import Belle2
264 from ROOT.Belle2
import SVDdEdxCalibrationAlgorithm, SVDdEdxValidationAlgorithm
266 algo = SVDdEdxCalibrationAlgorithm()
267 algo.setMonitoringPlots(
True)
268 algo.setNumPBins(expert_config[
'NBinsP'])
269 algo.setNumDEdxBins(expert_config[
'NBinsdEdx'])
270 algo.setDEdxCutoff(expert_config[
'dedxCutoff'])
271 algo.setMinEvtsPerTree(expert_config[
'MinEvtsPerTree'])
272 algo.setNEventsToGenerate(int(expert_config[
'NEventsToGenerate']))
273 algo.setUsePionBGFunctionForEverything(expert_config[
'UsePionBGFunctionForEverything'])
274 algo.setUseProtonBGFunctionForEverything(expert_config[
'UseProtonBGFunctionForEverything'])
275 algo.setCustomProfile(expert_config[
'CustomProfile'])
276 algo.setFixUnstableFitParameter(expert_config[
'FixUnstableFitParameter'])
278 if "dEdxValidation" not in listOfMutedCalibrations:
279 algo_val = SVDdEdxValidationAlgorithm()
280 algo_val.setMonitoringPlots(
True)
281 algo_val.setMinEvtsPerTree(expert_config[
'MinEvtsPerTree'])
282 algo_val.setNumROCpoints(expert_config[
'NumROCpoints'])
283 algo_val.setMinROCMomentum(expert_config[
'MinROCMomentum'])
284 algo_val.setMaxROCMomentum(expert_config[
'MaxROCMomentum'])
285 algo_val.setNumEffBins(expert_config[
'NumEffBins'])
286 algo_val.setMaxEffMomentum(expert_config[
'MaxEffMomentum'])
287 algo_val.validationMode(validation_mode)
292 from caf.framework
import Calibration
294 rec_path = create_path(rerun_reco,
False, isMC, expert_config)
295 rec_path_validation = create_path(rerun_reco_val, rerun_pid_val, isMC, expert_config)
297 dedx_calibration = Calibration(
"SVDdEdxCalibration",
298 collector=
"SVDdEdxCollector",
300 input_files=input_files_hadron_calib,
301 pre_collector_path=rec_path)
303 if "dEdxValidation" not in listOfMutedCalibrations:
304 dedx_validation = Calibration(
"SVDdEdxValidation",
305 collector=
"SVDdEdxValidationCollector",
306 algorithms=[algo_val],
307 input_files=input_files_hadron_validation,
308 pre_collector_path=rec_path_validation)
311 for algorithm
in dedx_calibration.algorithms:
312 algorithm.params = {
"apply_iov": output_iov}
317 if "dEdxValidation" not in listOfMutedCalibrations:
318 dedx_validation.depends_on(dedx_calibration)
320 list_of_calibrations = []
321 if "dEdxCalibration" not in listOfMutedCalibrations:
322 list_of_calibrations.append(dedx_calibration)
323 if "dEdxValidation" not in listOfMutedCalibrations:
324 list_of_calibrations.append(dedx_validation)
326 return list_of_calibrations