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