Belle II Software development
trainFacetFilter.py
1#!/usr/bin/env python3
2
3
10
11# This is for training a mva classifier for hit triplets
12# It performs a tip better than the current default chi2 filter
13# However run time is quite a bit slower which is why it wont be used in the standard chain.
14# Nevertheless this script can be used to generate variables to consider
15# for improvements or cross checks with --task explore
16
17import sys
18
19from tracking.run.event_generation import StandardEventGenerationRun
20from trackfindingcdc.run.training import TrainingRunMixin
21
22
24 """Run for recording facets encountered at the filter"""
25
26 n_events = 100
27
28
29 generator_module = "generic"
30 # detector_setup = "TrackingDetector"
31
32
33 task = "explore"
34
35
36 truth = "truth_positive"
37
38
39 flight_time_reestimation = False
40
41
42 facet_least_square_fit = False
43
44 @property
45 def identifier(self):
46 """Database identifier of the filter being trained"""
47 return "trackfindingcdc_FacetFilter.xml"
48
49 def create_argument_parser(self, **kwds):
50 """Convert command-line arguments to basf2 argument list"""
51
52 argument_parser = super().create_argument_parser(**kwds)
53
54 argument_parser.add_argument(
55 "-fr",
56 "--flight-time-reestimation",
57 action="store_true",
58 dest="flight_time_reestimation",
59 help="Switch to reestimate drift length before fitting."
60 )
61
62 argument_parser.add_argument(
63 "-fl",
64 "--facet-least-square-fit",
65 action="store_true",
66 dest="facet_least_square_fit",
67 help="Switch to fit the facet with least square method for the drift length update"
68 )
69
70 return argument_parser
71
72 def create_path(self):
73 """
74 Sets up a path that plays back pregenerated events or generates events
75 based on the properties in the base class.
76 """
77
78 path = super().create_path()
79
80
81 if self.tasktask == "train":
82 var_sets = [
83 "mva",
84 "filter(truth)",
85 ]
86
87 elif self.tasktask == "eval":
88 var_sets = [
89 "filter(chi2)",
90 "filter(realistic)",
91 "filter(mva)",
92 "filter(truth)",
93 ]
94
95 elif self.tasktask == "explore":
96 var_sets = [
97 "basic",
98 "truth",
99 "bend",
100 "fit",
101 "filter(truth)",
102 "filter(realistic)",
103 "filter(chi2)",
104 ]
105
106
107 self.variables = [
108 "curv",
109 "curv_pull",
110 "middle_phi_pull",
111 "middle_chi2",
112 "fit_0_phi0_sigma",
113 "chi2_0",
114 "chi2_0_per_s",
115 "fit_1_phi0_sigma",
116 "chi2_1",
117 "chi2_1_per_s",
118 "fit_phi0_sigma",
119 "chi2 chi2_per_s",
120 "realistic_accept",
121 "chi2_accept",
122 ]
123
124 path.add_module("TFCDC_WireHitPreparer",
125 flightTimeEstimation="outwards",
126 UseNLoops=1.0)
127
128 path.add_module("TFCDC_ClusterPreparer")
129
130 path.add_module("TFCDC_SegmentFinderFacetAutomaton",
131 FacetUpdateDriftLength=self.flight_time_reestimation,
132 FacetLeastSquareFit=self.facet_least_square_fit,
133 FacetFilter="unionrecording",
134 FacetFilterParameters={
135 "rootFileName": self.sample_file_name,
136 "varSets": var_sets,
137 },
138 FacetRelationFilter="none")
139
140 return path
141
142
143def main():
144 """Execute the facet recording"""
146 run.configure_and_execute_from_commandline()
147
148
149if __name__ == "__main__":
150 import logging
151 logging.basicConfig(stream=sys.stdout, level=logging.INFO, format="%(levelname)s:%(message)s")
152 main()
str task
Default task set to explore.
bool flight_time_reestimation
Option whether to reestimate the drift length.
variables
Signal some variables to select in the classification analysis.
bool facet_least_square_fit
Option whether to use the least square fit to the hit triplet.
task
Post-process events according to the user's desired task (train, eval, explore)
Definition: main.py:1