Belle II Software development
path_functions.py
1
8
9from ROOT import Belle2 # noqa: make the Belle2 namespace available
10from ROOT.Belle2 import DAFConfiguration
11
12
13def add_ckf_based_merger(path, cdc_reco_tracks, svd_reco_tracks, use_mc_truth=False, direction="backward"):
14 """
15 Convenience function to add the SVD track finding using VXDTF2 and the merger based on the CKF to the path.
16 :param path: The path to add the module to
17 :param cdc_reco_tracks: The name of the already created CDC Reco Tracks
18 :param svd_reco_tracks: The name of the already created CDC Reco Tracks
19 :param use_mc_truth: Use the MC information in the CKF
20 :param direction: where to extrapolate to. Valid options are forward and backward
21 """
22 # The CDC tracks need to be fitted
23 path.add_module("DAFRecoFitter", trackFitType=DAFConfiguration.c_CDConly,
24 recoTracksStoreArrayName=cdc_reco_tracks).set_name(f"DAFRecoFitter {cdc_reco_tracks}")
25
26 if use_mc_truth:
27 # MC CKF needs MC matching information
28 path.add_module("MCRecoTracksMatcher", UsePXDHits=False, UseSVDHits=True, UseCDCHits=False,
29 mcRecoTracksStoreArrayName="MCRecoTracks",
30 prRecoTracksStoreArrayName=svd_reco_tracks)
31
32 result_filter = "truth_svd_cdc_relation"
33 result_filter_parameters = {}
34 else:
35 result_filter = "mva_with_relations"
36 result_filter_parameters = {'DBPayloadName': 'ckf_SeededCDCToSVDResultParameters'}
37
38 if direction == "forward":
39 reverse_seed = True
40 else:
41 reverse_seed = False
42
43 path.add_module("CDCToSVDSeedCKF",
44 advanceHighFilterParameters={"direction": direction},
45
46 fromRelationStoreArrayName=cdc_reco_tracks,
47 toRelationStoreArrayName=svd_reco_tracks,
48
49 writeOutDirection=direction,
50
51 inputRecoTrackStoreArrayName=cdc_reco_tracks,
52 relatedRecoTrackStoreArrayName=svd_reco_tracks,
53 relationCheckForDirection=direction,
54 cdcTracksStoreArrayName=cdc_reco_tracks,
55 vxdTracksStoreArrayName=svd_reco_tracks,
56
57 firstHighFilterParameters={"direction": direction},
58 reverseSeed=reverse_seed,
59
60 filter=result_filter,
61 filterParameters=result_filter_parameters,
62
63 trackFitType=DAFConfiguration.c_CDConly
64 ).set_name(f"CDCToSVDSeedCKF_{direction}")
65
66
67def add_pxd_ckf(
68 path,
69 svd_cdc_reco_tracks,
70 pxd_reco_tracks,
71 use_mc_truth=False,
72 use_best_seeds=10,
73 use_best_results=2,
74 direction="backward"):
75 """
76 Convenience function to add the PXD ckf to the path.
77 :param path: The path to add the module to
78 :param svd_cdc_reco_tracks: The name of the already created SVD+CDC reco tracks
79 :param pxd_reco_tracks: The name to output the PXD reco tracks to
80 :param use_mc_truth: Use the MC information in the CKF
81 :param use_best_results: CKF parameter for useBestNInSeed
82 :param use_best_seeds: CKF parameter for UseNStates
83 :param direction: where to extrapolate to. Valid options are forward and backward
84 """
85 if "PXDSpacePointCreator" not in [m.name() for m in path.modules()]:
86 path.add_module("PXDSpacePointCreator")
87
88 path.add_module("DAFRecoFitter", recoTracksStoreArrayName=svd_cdc_reco_tracks).set_name(f"DAFRecoFitter {svd_cdc_reco_tracks}")
89
90 if direction == "forward":
91 reverse_seed = True
92 else:
93 reverse_seed = False
94
95 if use_mc_truth:
96 module_parameters = dict(
97 firstHighFilter="truth",
98 secondHighFilter="all",
99 thirdHighFilter="all",
100
101 filter="truth",
102 useBestNInSeed=1
103 )
104 else:
105 module_parameters = dict(
106 firstHighFilterParameters={
107 'DBPayloadName': 'ckf_ToPXDStateFilter_1Parameters',
108 "direction": direction},
109 firstHighUseNStates=use_best_seeds,
110 secondHighFilterParameters={
111 'DBPayloadName': 'ckf_ToPXDStateFilter_2Parameters'},
112 secondHighUseNStates=use_best_seeds,
113 thirdHighFilterParameters={
114 'DBPayloadName': 'ckf_ToPXDStateFilter_3Parameters'},
115 thirdHighUseNStates=use_best_seeds,
116 filterParameters={
117 'DBPayloadName': 'ckf_PXDTrackCombinationParameters'},
118 useBestNInSeed=use_best_results,
119 )
120
121 module_parameters["seedHitJumping"] = -1 # get from payload
122 module_parameters["hitHitJumping"] = 0
123
124 path.add_module("ToPXDCKF",
125 advanceHighFilterParameters={"direction": direction},
126
127 writeOutDirection=direction,
128
129 inputRecoTrackStoreArrayName=svd_cdc_reco_tracks,
130 relatedRecoTrackStoreArrayName=pxd_reco_tracks,
131 relationCheckForDirection=direction,
132
133 outputRecoTrackStoreArrayName=pxd_reco_tracks,
134 outputRelationRecoTrackStoreArrayName=svd_cdc_reco_tracks,
135
136 reverseSeed=reverse_seed,
137 reverseSeedState=reverse_seed, # Parameter cannot be read twice within a module
138 **module_parameters).set_name(f"ToPXDCKF_{direction}")
139
140
141def add_svd_ckf(
142 path,
143 cdc_reco_tracks,
144 svd_reco_tracks,
145 use_mc_truth=False,
146 use_best_results=5,
147 use_best_seeds=10,
148 direction="backward"):
149 """
150 Convenience function to add the SVD ckf to the path.
151 :param path: The path to add the module to
152 :param cdc_reco_tracks: The name of the already created CDC reco tracks
153 :param svd_reco_tracks: The name to output the SVD reco tracks to
154 :param use_mc_truth: Use the MC information in the CKF
155 :param use_best_results: CKF parameter for useNResults
156 :param use_best_seeds: CKF parameter for useBestNInSeed
157 :param direction: where to extrapolate to. Valid options are forward and backward
158 """
159 if direction == "forward":
160 reverse_seed = True
161 else:
162 reverse_seed = False
163
164 if use_mc_truth:
165 module_parameters = dict(
166 firstHighFilter="truth",
167 secondHighFilter="all",
168 thirdHighFilter="all",
169
170 filter="truth",
171 useBestNInSeed=1
172 )
173 else:
174 module_parameters = dict(
175 firstHighFilterParameters={
176 "direction": direction,
177 'DBPayloadName': f'ckf_CDCSVDStateFilter_1_{direction}_Parameters'},
178 firstHighUseNStates=use_best_seeds,
179 secondHighFilterParameters={
180 'DBPayloadName': f'ckf_CDCSVDStateFilter_2_{direction}_Parameters'},
181 secondHighUseNStates=use_best_seeds,
182 thirdHighFilterParameters={
183 'DBPayloadName': f'ckf_CDCSVDStateFilter_3_{direction}_Parameters'},
184 thirdHighUseNStates=use_best_seeds,
185 filterParameters={
186 'DBPayloadName': 'ckf_CDCToSVDResultParameters'},
187 useBestNInSeed=use_best_results,
188 )
189
190 path.add_module("CDCToSVDSpacePointCKF",
191 inputRecoTrackStoreArrayName=cdc_reco_tracks,
192 outputRecoTrackStoreArrayName=svd_reco_tracks,
193 outputRelationRecoTrackStoreArrayName=cdc_reco_tracks,
194 relatedRecoTrackStoreArrayName=svd_reco_tracks,
195
196 advanceHighFilterParameters={"direction": direction},
197 reverseSeed=reverse_seed,
198
199 writeOutDirection=direction,
200 relationCheckForDirection=direction,
201
202 seedHitJumping=1,
203 hitHitJumping=1,
204
205 trackFitType=DAFConfiguration.c_CDConly,
206
207 **module_parameters).set_name(f"CDCToSVDSpacePointCKF_{direction}")
208
209
210def add_cosmics_svd_ckf(
211 path,
212 cdc_reco_tracks,
213 svd_reco_tracks,
214 use_mc_truth=False,
215 use_best_results=5,
216 use_best_seeds=10,
217 direction="backward"):
218 """
219 Convenience function to add the SVD ckf to the path with cosmics settings valid for phase2 and 3.
220 :param path: The path to add the module to
221 :param cdc_reco_tracks: The name of the already created CDC reco tracks
222 :param svd_reco_tracks: The name to output the SVD reco tracks to
223 :param use_mc_truth: Use the MC information in the CKF
224 :param use_best_results: CKF parameter for useNResults
225 :param use_best_seeds: CKF parameter for useBestNInSeed
226 :param direction: where to extrapolate to. Valid options are forward and backward
227 """
228 if direction == "forward":
229 reverse_seed = True
230 else:
231 reverse_seed = False
232
233 if use_mc_truth:
234 module_parameters = dict(
235 firstHighFilter="truth",
236 secondHighFilter="all",
237 thirdHighFilter="all",
238
239 filter="truth",
240 useBestNInSeed=1
241 )
242 else:
243 module_parameters = dict(
244 hitFilter="all",
245 seedFilter="all",
246
247 firstHighFilter="non_ip_crossing",
248 firstHighFilterParameters={"direction": direction},
249 firstHighUseNStates=0,
250
251 secondHighFilter="residual",
252 secondHighFilterParameters={},
253 secondHighUseNStates=use_best_seeds,
254
255 thirdHighFilter="residual",
256 thirdHighFilterParameters={},
257 thirdHighUseNStates=use_best_seeds,
258
259 filter="weight",
260 filterParameters={},
261 useBestNInSeed=use_best_results,
262 )
263
264 path.add_module("CDCToSVDSpacePointCKF",
265 inputRecoTrackStoreArrayName=cdc_reco_tracks,
266 outputRecoTrackStoreArrayName=svd_reco_tracks,
267 outputRelationRecoTrackStoreArrayName=cdc_reco_tracks,
268 relatedRecoTrackStoreArrayName=svd_reco_tracks,
269
270 advanceHighFilterParameters={"direction": direction},
271 reverseSeed=reverse_seed,
272
273 writeOutDirection=direction,
274 relationCheckForDirection=direction,
275
276 seedHitJumping=3,
277 hitHitJumping=1,
278 **module_parameters).set_name(f"CDCToSVDSpacePointCKF_{direction}")
279
280
281def add_cosmics_pxd_ckf(
282 path,
283 svd_cdc_reco_tracks,
284 pxd_reco_tracks,
285 use_mc_truth=False,
286 use_best_results=5,
287 use_best_seeds=10,
288 direction="backward"):
289 """
290 Convenience function to add the PXD ckf to the path with cosmics settings valid for phase2 and 3.
291 :param path: The path to add the module to
292 :param svd_cdc_reco_tracks: The name of the already created CDC reco tracks
293 :param pxd_reco_tracks: The name to output the SVD reco tracks to
294 :param use_mc_truth: Use the MC information in the CKF
295 :param use_best_results: CKF parameter for useNResults
296 :param use_best_seeds: CKF parameter for useBestNInSeed
297 :param direction: where to extrapolate to. Valid options are forward and backward
298 """
299 if "PXDSpacePointCreator" not in [m.name() for m in path.modules()]:
300 path.add_module("PXDSpacePointCreator")
301
302 path.add_module("DAFRecoFitter", recoTracksStoreArrayName=svd_cdc_reco_tracks).set_name(f"DAFRecoFitter {svd_cdc_reco_tracks}")
303
304 if direction == "forward":
305 reverse_seed = True
306 else:
307 reverse_seed = False
308
309 if use_mc_truth:
310 path.add_module("MCRecoTracksMatcher", UsePXDHits=False, UseSVDHits=True, UseCDCHits=True,
311 mcRecoTracksStoreArrayName="MCRecoTracks",
312 prRecoTracksStoreArrayName=svd_cdc_reco_tracks)
313
314 module_parameters = dict(
315 firstHighFilter="truth",
316 secondHighFilter="all",
317 thirdHighFilter="all",
318
319 filter="truth",
320 useBestNInSeed=1
321 )
322 else:
323 module_parameters = dict(
324 hitFilter="all",
325 seedFilter="all",
326 preHitFilter="all",
327 preSeedFilter="all",
328 firstHighFilterParameters={
329 'DBPayloadName': 'ckf_ToPXDStateFilter_1Parameters',
330 "direction": direction},
331 firstHighUseNStates=use_best_seeds,
332 secondHighFilterParameters={
333 'DBPayloadName': 'ckf_ToPXDStateFilter_2Parameters'},
334 secondHighUseNStates=use_best_seeds,
335 thirdHighFilterParameters={
336 'DBPayloadName': 'ckf_ToPXDStateFilter_3Parameters'},
337 thirdHighUseNStates=use_best_seeds,
338 filterParameters={
339 'DBPayloadName': 'ckf_PXDTrackCombinationParameters'},
340 useBestNInSeed=use_best_results,
341 seedHitJumping=1,
342 hitHitJumping=0,
343 )
344
345 path.add_module("ToPXDCKF",
346 advanceHighFilterParameters={"direction": direction},
347
348 writeOutDirection=direction,
349
350 inputRecoTrackStoreArrayName=svd_cdc_reco_tracks,
351 relatedRecoTrackStoreArrayName=pxd_reco_tracks,
352 relationCheckForDirection=direction,
353
354 outputRecoTrackStoreArrayName=pxd_reco_tracks,
355 outputRelationRecoTrackStoreArrayName=svd_cdc_reco_tracks,
356
357 reverseSeed=reverse_seed,
358 reverseSeedState=reverse_seed,
359 **module_parameters).set_name(f"ToPXDCKF_{direction}")