Belle II Software  release-05-01-25
display.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 import basf2
4 import logging
5 
6 from tracking.run.tracked_event_generation import ReadOrGenerateTrackedEventsRun
7 import trackfindingcdc.cdcdisplay as cdcdisplay
8 
9 
11  """Prepare and execute a basf2 job to read generated events or generate new events then display the CDC tracks"""
12 
13 
14  output_folder = '/tmp'
15 
16 
17  iteractive = True
18 
19 
20  show_all_drawoptions = False
21 
22 
23  filename_prefix = ""
24 
25  def __init__(self):
26  """Constructor"""
27  super().__init__()
28 
29  self._cdc_display_module = cdcdisplay.CDCSVGDisplayModule(self.output_folder)
30 
31  @property
32  def cdc_display_module(self):
33  """Get the display module"""
34  cdc_display_module = self._cdc_display_module
35  return cdc_display_module
36 
37  def create_argument_parser(self, **kwds):
38  """Translate the command-lne arguments to basf2-job parameter"""
39  argument_parser = super().create_argument_parser(**kwds)
40 
41  argument_parser.add_argument(
42  '-o',
43  '--output-folder',
44  dest='output_folder',
45  default=self.output_folder,
46  help='Folder where the output files are written to. If the folder does not exist create it. '
47  )
48 
49  argument_parser.add_argument(
50  '--non-interactive',
51  dest='interactive',
52  action='store_false',
53  help='Run in batch mode and do not show each event.'
54  )
55 
56  argument_parser.add_argument(
57  '--use-python',
58  dest='use_python',
59  action='store_true',
60  help='Swtich to activate the legacy implementation written in python'
61  )
62 
63  argument_parser.add_argument(
64  "--use_time_in_filename",
65  action='store_true',
66  help='Use the current time in the names of the generated files'
67  )
68 
69  argument_parser.add_argument(
70  "-pf",
71  '--filename_prefix',
72  default=self.filename_prefix,
73  help='Prefix to the names of the generated files'
74  )
75 
76  argument_parser.add_argument(
77  '-m',
78  '--mc-tracks',
79  action='store_const',
80  dest='finder_module',
81  const='TrackFinderMCTruthRecoTracks',
82  default=self.finder_module,
83  help='Generate the mc tracks using the TrackFinderMCTruthRecoTracks. Short hand for -f TrackFinderMCTruthRecoTracks'
84  )
85 
86  subparser_description = \
87  """
88 Various options to configure what shall be drawn in the display.
89 Note that some options are only relevant, if the cellular automaton finder in the CDC has been run before.
90 """
91  draw_argument_group = argument_parser.add_argument_group(
92  title='Draw options',
93  description=subparser_description
94  )
95 
96  cdc_display_module = self.cdc_display_module
97 
98  if self.show_all_drawoptions:
99  drawoptions = cdc_display_module.all_drawoptions
100  else:
101  drawoptions = cdc_display_module.drawoptions
102 
103  for option in sorted(drawoptions):
104  options_flag = '--%s ' % option.replace('_', '-')
105 
106  draw_argument_group.add_argument(
107  options_flag,
108  dest=option,
109  action='store_true',
110  default=getattr(cdc_display_module, option)
111  )
112 
113  return argument_parser
114 
115  def configure(self, arguments):
116  """Configure the basf2 job script using the translated command-line arguments"""
117  super().configure(arguments)
118 
119  cdc_display_module = self.cdc_display_module
120 
121  cdc_display_module.output_folder = arguments.output_folder
122  cdc_display_module.interactive = arguments.interactive
123 
124  cdc_display_module.use_python = arguments.use_python
125  cdc_display_module.use_cpp = not arguments.use_python
126  cdc_display_module.use_time_in_filename = arguments.use_time_in_filename
127  cdc_display_module.filename_prefix = arguments.filename_prefix
128 
129  if self.show_all_drawoptions:
130  drawoptions = cdc_display_module.all_drawoptions
131  else:
132  drawoptions = cdc_display_module.drawoptions
133 
134  for option in drawoptions:
135  try:
136  is_active_option = getattr(arguments, option)
137  except AttributeError:
138  continue
139  else:
140  print('Setting', option, 'to', is_active_option)
141  setattr(cdc_display_module, option, is_active_option)
142 
143  def create_path(self):
144  """Create the basf2 path"""
145  main_path = super().create_path()
146  main_path.add_module(self.cdc_display_module)
147  return main_path
tracking.run.tracked_event_generation.ReadOrGenerateTrackedEventsRun
Definition: tracked_event_generation.py:18
display.CDCDisplayRun
Definition: display.py:10
display.CDCDisplayRun.configure
def configure(self, arguments)
Definition: display.py:115
display.CDCDisplayRun.create_argument_parser
def create_argument_parser(self, **kwds)
Definition: display.py:37
trackfindingcdc.cdcdisplay
Definition: __init__.py:1
display.CDCDisplayRun.filename_prefix
string filename_prefix
Prefix of the output files.
Definition: display.py:23
display.CDCDisplayRun.show_all_drawoptions
bool show_all_drawoptions
Switch to also show draw command line options only related to the cellular automaton track finder.
Definition: display.py:20
display.CDCDisplayRun.output_folder
string output_folder
Destination folder for displays.
Definition: display.py:14
tracking.run.tracked_event_generation.ReadOrGenerateTrackedEventsRun.finder_module
finder_module
Name of the finder module to be used - can be everything that is accepted by tracking....
Definition: tracked_event_generation.py:25
display.CDCDisplayRun._cdc_display_module
_cdc_display_module
Use the CDCSVGDisplay module to draw the CDC and tracks/hits.
Definition: display.py:29
tracking.run.tracked_event_generation
Definition: tracked_event_generation.py:1
display.CDCDisplayRun.cdc_display_module
def cdc_display_module(self)
Definition: display.py:32
display.CDCDisplayRun.create_path
def create_path(self)
Definition: display.py:143
display.CDCDisplayRun.__init__
def __init__(self)
Definition: display.py:25