Belle II Software development
ReadOrGenerateEventsRun Class Reference
Inheritance diagram for ReadOrGenerateEventsRun:
MinimalRun EmptyRun StandardEventGenerationRun ReadOrGenerateTrackedEventsRun BackgroundClusterFilterTrainingRun FeasibleAxialSegmentPairFilterTrainingRun FeasibleSegmentPairFilterTrainingRun FeasibleSegmentRelationFilterTrainingRun FeasibleTrackRelationFilterTrainingRun RealisticAxialSegmentPairFilterTrainingRun RealisticSegmentPairFilterTrainingRun RealisticSegmentPairRelationFilterTrainingRun RealisticSegmentRelationFilterTrainingRun RealisticTrackRelationFilterTrainingRun SegmentTrackFilterTrainingRun TrackFilterTrainingRun

Public Member Functions

def create_argument_parser (self, **kwds)
 
def configure (self, arguments)
 
def execute (self)
 
def create_path (self)
 

Public Attributes

 root_input_file
 generating events, so there is no ROOT input file
 

Static Public Attributes

str description = "Simulate events using various generator and detector setups from command line."
 Description of the run setup to be displayed on command line.
 
None generator_module = None
 By default, do not generate events.
 
str detector_setup = "Default"
 By default, use the default detector setup.
 
list bkg_files = []
 By default, no background overlay.
 
None components = None
 By default, do specific components.
 
bool disable_deltas = False
 By default, do not disable delta-ray generation.
 
None simulation_output = None
 By default, do no store the simulation output.
 

Detailed Description

Read generated events or generate new events

Definition at line 34 of file event_generation.py.

Member Function Documentation

◆ configure()

def configure (   self,
  arguments 
)
Configure for basf2 job; disable ROOT input if simulating events

Reimplemented from EmptyRun.

Reimplemented in CDCDisplayRun.

Definition at line 122 of file event_generation.py.

122 def configure(self, arguments):
123 """Configure for basf2 job; disable ROOT input if simulating events"""
124 super().configure(arguments)
125 if self.simulation_output:
126 get_logger().info("Requested to simulation run. Deactivate input file")
127
128 self.root_input_file = None
129

◆ create_argument_parser()

def create_argument_parser (   self,
**  kwds 
)
Convert command-line arguments to basf2 argument list

Reimplemented from MinimalRun.

Reimplemented in ReadOrGenerateTrackedEventsRun, TrackingValidationRun, CDCDisplayRun, ClusterFilterValidationRun, ElossHarvestingRun, LegendreBinningValidationRun, SegmentFitValidationRun, SegmentPairCreationValidationRun, SegmentPairFitValidationRun, and FacetFilterTrainingRun.

Definition at line 55 of file event_generation.py.

55 def create_argument_parser(self, **kwds):
56 """Convert command-line arguments to basf2 argument list"""
57 argument_parser = super().create_argument_parser(**kwds)
58
59 setup_argument_group = argument_parser.add_argument_group("Detector setup arguments")
60 setup_argument_group.add_argument(
61 '-d',
62 '--detector',
63 dest='detector_setup',
64 default=argparse.SUPPRESS,
65 metavar='DETECTOR_SETUP_NAME',
66 choices=utilities.NonstrictChoices(detector_setups_by_short_name.keys()),
67 help=('Name of the detector setup to be used')
68 )
69
70 setup_argument_group.add_argument(
71 '-c',
72 '--component',
73 dest='components',
74 nargs='+',
75 default=argparse.SUPPRESS,
76 metavar='COMPONENTS',
77 action='store',
78 help=('Overrides the components of the detector setup')
79 )
80
81 generator_argument_group = argument_parser.add_argument_group("Generator arguments")
82 generator_argument_group.add_argument(
83 '-g',
84 '--generator',
85 dest='generator_module',
86 default=argparse.SUPPRESS,
87 metavar='GENERATOR_NAME',
88 choices=utilities.NonstrictChoices(valid_generator_short_names),
89 help='Name module or short name of the generator to be used.',
90 )
91
92 simulation_argument_group = argument_parser.add_argument_group("Simulation arguments")
93 simulation_argument_group.add_argument(
94 '-b',
95 '--bkg-file',
96 dest='bkg_files',
97 nargs='+',
98 default=self.bkg_files,
99 metavar='BACKGROUND_DIRECTORY',
100 help='Path to folder of files or to a file containing the background to be used. ' +
101 'Can be given multiple times.',
102 )
103
104 simulation_argument_group.add_argument(
105 '--disable-deltas',
106 action='store_true',
107 help='Disable the generation of delta rays in the simulation'
108 )
109
110 simulation_argument_group.add_argument(
111 '-so',
112 '--simulation-output',
113 nargs='?',
114 default=self.simulation_output,
115 const=self.root_input_file,
116 dest='simulation_output',
117 help='Only generate and simulate the events and write them to the given output file. Skip rest of the path.'
118 )
119
120 return argument_parser
121

◆ create_path()

def create_path (   self)
Create and configure the basf2 path

Reimplemented from MinimalRun.

Reimplemented in ReadOrGenerateTrackedEventsRun, TrackingValidationRun, SegmentQuadTreeRun, CDCDisplayRun, ClusterFilterValidationRun, ElossHarvestingRun, LegendreBinningValidationRun, FitValidation, SegmentFitValidationRun, SegmentPairCreationValidationRun, SegmentPairFitValidationRun, BackgroundClusterFilterTrainingRun, FacetFilterTrainingRun, FacetRelationFilterTrainingRun, FeasibleAxialSegmentPairFilterTrainingRun, FeasibleSegmentPairFilterTrainingRun, FeasibleSegmentRelationFilterTrainingRun, FeasibleTrackRelationFilterTrainingRun, RealisticAxialSegmentPairFilterTrainingRun, RealisticSegmentPairFilterTrainingRun, RealisticSegmentPairRelationFilterTrainingRun, RealisticSegmentRelationFilterTrainingRun, RealisticTrackRelationFilterTrainingRun, SegmentTrackFilterTrainingRun, and TrackFilterTrainingRun.

Definition at line 140 of file event_generation.py.

140 def create_path(self):
141 """Create and configure the basf2 path"""
142 path = super().create_path()
143
144 # Gearbox & Geometry must always be registered
145 path.add_module("Gearbox")
146 path.add_module("Geometry", useDB=True)
147 if self.detector_setup:
148 detector_setup = self.detector_setup
149 detector_setup_function = detector_setups_by_short_name[detector_setup]
150 components = detector_setup_function(path)
151
152 if self.components:
153 components = self.components
154
155 # Only generate events if no input file has been provided
156 if self.root_input_file is None:
157 # Check if generator means a decay file
158 if isinstance(self.generator_module, str) and utilities.find_file(self.generator_module):
159 dec_file_path = utilities.find_file(self.generator_module)
160 add_evtgen_generator(path, dec_file_path)
161 else:
162 # All other possibilities
163 utilities.extend_path(path,
164 self.generator_module,
165 generators_by_short_name,
166 allow_function_import=True)
167
168 # Only simulate if generator is setup
169 if self.root_input_file is None:
170 bkg_file_paths = get_bkg_file_paths(self.bkg_files)
171
173 components=components,
174 bkgfiles=bkg_file_paths)
175
176 if self.disable_deltas:
177 adjustments.disable_deltas(path)
178
179 # Catch if no generator is added, no background should be simulated and events
180 # are not read from a file.
181 if not bkg_file_paths and self.generator_module is None:
182 raise RuntimeError('Need at least one of root_input_file,'
183 ' generator_module or bkg_files specified.')
184 else:
185 if not os.path.exists(self.root_input_file):
186 raise RuntimeError("Could not find file " + str(self.root_input_file) + ". Generate it with -- -so?")
187
188 # early write out if simulation output was requested
189 if self.simulation_output:
190 path.add_module('RootOutput',
191 outputFileName=self.simulation_output)
192
193 return path
194
195
def add_simulation(path, components=None, bkgfiles=None, bkgOverlay=True, forceSetPXDDataReduction=False, usePXDDataReduction=True, cleanupPXDDataReduction=True, generate_2nd_cdc_hits=False, simulateT0jitter=True, isCosmics=False, FilterEvents=False, usePXDGatedMode=False, skipExperimentCheckForBG=False, save_slow_pions_in_mc=False)
Definition: simulation.py:126

◆ execute()

def execute (   self)
Run the basf2 job

Reimplemented from EmptyRun.

Definition at line 130 of file event_generation.py.

130 def execute(self):
131 """Run the basf2 job"""
132 if not self.simulation_output:
133 super().execute()
134 return
135
136 # Run only simulation
137 path = ReadOrGenerateEventsRun.create_path(self)
138 self.run(path)
139

Member Data Documentation

◆ bkg_files

list bkg_files = []
static

By default, no background overlay.

Definition at line 47 of file event_generation.py.

◆ components

None components = None
static

By default, do specific components.

Definition at line 49 of file event_generation.py.

◆ description

str description = "Simulate events using various generator and detector setups from command line."
static

Description of the run setup to be displayed on command line.

Definition at line 38 of file event_generation.py.

◆ detector_setup

str detector_setup = "Default"
static

By default, use the default detector setup.

Definition at line 45 of file event_generation.py.

◆ disable_deltas

bool disable_deltas = False
static

By default, do not disable delta-ray generation.

Definition at line 51 of file event_generation.py.

◆ generator_module

None generator_module = None
static

By default, do not generate events.

Definition at line 43 of file event_generation.py.

◆ root_input_file

root_input_file

generating events, so there is no ROOT input file

Definition at line 128 of file event_generation.py.

◆ simulation_output

None simulation_output = None
static

By default, do no store the simulation output.

Definition at line 53 of file event_generation.py.


The documentation for this class was generated from the following file: