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