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