Belle II Software development
SegmentPairFitValidationRun Class Reference
Inheritance diagram for SegmentPairFitValidationRun:
HarvestingRun HarvestingRunMixin StandardEventGenerationRun BrowseTFileOnTerminateRunMixin PostProcessingRunMixin ReadOrGenerateEventsRun PostProcessingRunMixin EmptyRun MinimalRun EmptyRun EmptyRun

Public Member Functions

 output_file_name (self)
 
 harvesting_module (self, path=None)
 
 create_argument_parser (self, **kwds)
 
 get_fit_method (self)
 
 create_path (self)
 
 pickle_crops (self, harvesting_module, crops, **kwds)
 
 unpickle_crops (self)
 
 postprocess (self)
 
 adjust_path (self, path)
 
 run (self, path)
 
 name (self)
 
 configure_and_execute_from_commandline (self)
 
 execute (self)
 
 configure_from_commandline (self)
 
 configure (self, arguments)
 

Public Attributes

 pickle_crops = self.output_file_name
 

Static Public Attributes

str monte_carlo = "no"
 do not generate new events
 
str segment_orientation = "outwards"
 ordering of the segments in the pair
 
str fit_method_name = "fuse-sz"
 use the Kalmanesk fuse of the two trajectory fits
 
bool show_results = False
 By default, do not show the browsing results.
 
bool postprocess_only = False
 By default, browse the output TFile too.
 
str description = "Empty execution of basf2"
 Description of the run setup to be displayed on command line.
 
 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.
 
 components = None
 By default, do specific components.
 
bool disable_deltas = False
 By default, do not disable delta-ray generation.
 
 simulation_output = None
 By default, do no store the simulation output.
 
bool allow_input = True
 By default, this basf2 job can read events from an input ROOT TFile.
 
int n_events = 10000
 By default, process 10000 events.
 
 root_input_file = None
 By default, there is no input ROOT TFile.
 
 random_seed = None
 By default, the random-number seed is unassigned.
 
int n_processes = 0
 By default, no parallel processing.
 
int n_events_to_skip = 0
 By default, do not skip any events at the start of the input ROOT TFile.
 

Detailed Description

Harvester to generate, postprocess and inspect MC events for track-segment-pair fit validation

Definition at line 33 of file record.py.

Member Function Documentation

◆ adjust_path()

adjust_path ( self,
path )
inherited
Add the harvester to the basf2 path

Reimplemented from EmptyRun.

Definition at line 66 of file run.py.

66 def adjust_path(self, path):
67 """Add the harvester to the basf2 path"""
68 super().adjust_path(path)
69 harvesting_module = self.harvesting_module()
70 if self.output_file_name:
71 harvesting_module.output_file_name = self.output_file_name
72 harvesting_module.refiners.append(self.pickle_crops)
73 path.add_module(harvesting_module)
74 return path
75
76

◆ configure()

configure ( self,
arguments )
inherited
Save the command-line arguments as key-value pairs

Reimplemented in CDCDisplayRun, and ReadOrGenerateEventsRun.

Definition at line 73 of file minimal.py.

73 def configure(self, arguments):
74 """Save the command-line arguments as key-value pairs"""
75 # Simply translate the arguments that have
76 # the same name as valid instance arguments
77 for (key, value) in list(vars(arguments).items()):
78 if value is None:
79 continue
80 if hasattr(self, key):
81 get_logger().info("Setting %s to %s", key, value)
82 setattr(self, key, value)
83

◆ configure_and_execute_from_commandline()

configure_and_execute_from_commandline ( self)
inherited
Configure basf2 job script from command-line arguments then run it

Definition at line 45 of file minimal.py.

45 def configure_and_execute_from_commandline(self):
46 """Configure basf2 job script from command-line arguments then run it"""
47 self.configure_from_commandline()
48 self.execute()
49

◆ configure_from_commandline()

configure_from_commandline ( self)
inherited
Convert the command-line arguments to a basf2 job script

Definition at line 67 of file minimal.py.

67 def configure_from_commandline(self):
68 """Convert the command-line arguments to a basf2 job script"""
69 argument_parser = self.create_argument_parser()
70 arguments = argument_parser.parse_args()
71 self.configure(arguments)
72

◆ create_argument_parser()

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

Reimplemented from HarvestingRunMixin.

Definition at line 68 of file record.py.

68 def create_argument_parser(self, **kwds):
69 """Convert command-line arguments to basf2 argument list"""
70 argument_parser = super().create_argument_parser(**kwds)
71
72 argument_parser.add_argument(
73 '-m',
74 '--monte-carlo',
75 choices=["no", "medium", "full"],
76 default=self.monte_carlo,
77 dest='monte_carlo',
78 help='Amount of monte carlo information to be used in the segment generation.',
79 )
80
81 argument_parser.add_argument(
82 "--fit",
83 choices=["zreco", "fuse-pre", "fuse-sz", "fuse-sz-re"],
84 default=self.fit_method_name,
85 dest="fit_method_name",
86 help=("Choose which fit positional information of the segment should be used. \n"
87 "* 'zreco' means the z coordinate is reconstructed and a linear sz fit is made. "
88 "No covariance between the circle and the linear sz part can be made.\n"
89 "* 'fuse-sz' means the Kalmanesk fuse of the two trajectory fits.\n"
90 "* 'fuse-sz-re' means the Kalmanesk fuse of the two trajectory fits but reestimate the drift length."
91 )
92 )
93
94 return argument_parser
95

◆ create_path()

create_path ( self)
Sets up a path that plays back pregenerated events or generates events based on the properties in the base class.

Reimplemented from EmptyRun.

Definition at line 161 of file record.py.

161 def create_path(self):
162 """
163 Sets up a path that plays back pregenerated events or generates events
164 based on the properties in the base class.
165 """
166 path = super().create_path()
167
168 path.add_module("TFCDC_WireHitPreparer",
169 flightTimeEstimation="outwards",
170 UseNLoops=0.5
171 )
172
173 path.add_module("TFCDC_ClusterPreparer")
174
175
176 if self.monte_carlo == "no":
177 # MC free - default
178 path.add_module("TFCDC_SegmentFinderFacetAutomaton",
179 SegmentOrientation="outwards"
180 )
181
182 path.add_module("TFCDC_SegmentFitter",
183 inputSegments="CDCSegment2DVector",
184 updateDriftLength=True,
185 useAlphaInDriftLength=True,
186 )
187
188 elif self.monte_carlo == "medium":
189 # Medium MC - proper generation logic, but true facets and facet relations
190 path.add_module("TFCDC_SegmentFinderFacetAutomaton",
191 FacetFilter="truth",
192 FacetRelationFilter="truth",
193 SegmentOrientation="outwards"
194 )
195
196 path.add_module("TFCDC_SegmentFitter",
197 inputSegments="CDCSegment2DVector",
198 updateDriftLength=True,
199 useAlphaInDriftLength=True,
200 )
201
202 elif self.monte_carlo == "full":
203 # Only true monte carlo segments
204 # make the positions realistic but keep the true drift length
205 path.add_module("TFCDC_SegmentCreatorMCTruth",
206 reconstructedDriftLength=False,
207 reconstructedPositions=True,
208 # segments="MCSegments"
209 )
210
211 path.add_module("TFCDC_SegmentFitter",
212 inputSegments="CDCSegment2DVector",
213 updateDriftLength=False,
214 # useAlphaInDriftLength=True,
215 )
216
217 else:
218 raise ValueError("Invalid degree of Monte Carlo information")
219
220 path.add_module("TFCDC_SegmentOrienter",
221 SegmentOrientation="outwards",
222 # SegmentOrientation="none",
223 inputSegments="CDCSegment2DVector",
224 segments="CDCSegment2DVectorOriented"
225 )
226
227 path.add_module("TFCDC_TrackFinderSegmentPairAutomaton",
228 inputSegments="CDCSegment2DVectorOriented",
229 WriteSegmentPairs=True,
230 SegmentPairFilter="truth",
231 SegmentPairFilterParameters={"allowReverse": True},
232 SegmentPairRelationFilter="none"
233 )
234
235 path.add_module(AxialStereoPairFitterModule(fit_method=self.get_fit_method()))
236 return path
237
238

◆ execute()

execute ( self)
inherited
Create the basf2 path then run the job

Reimplemented in ReadOrGenerateEventsRun.

Definition at line 50 of file minimal.py.

50 def execute(self):
51 """Create the basf2 path then run the job"""
52 # Create path and run #
53
54 path = self.create_path()
55 self.adjust_path(path)
56 self.run(path)
57

◆ get_fit_method()

get_fit_method ( self)
Determine which track-segment-pair fitter to use

Definition at line 96 of file record.py.

96 def get_fit_method(self):
97 """Determine which track-segment-pair fitter to use"""
98 fit_method_name = self.fit_method_name
99
100 if fit_method_name == 'zreco':
102
103 def z_reconstruction_fit(pair):
104 return sz_fitter.update(pair)
105 return z_reconstruction_fit
106
107 elif fit_method_name.startswith('fuse-pre'):
110 fusionFit = CDCAxialStereoFusion()
111
112 def sz_segment_pair_preliminary_fit(pair):
113 fusionFit.fusePreliminary(pair)
114 return sz_segment_pair_preliminary_fit
115
116 elif fit_method_name.startswith('fuse-sz'):
119 reestimateDriftLength = fit_method_name.endswith("re")
120 fusionFit = CDCAxialStereoFusion(reestimateDriftLength)
121
122 def sz_segment_pair_fusion_fit(pair):
123 fusionFit.reconstructFuseTrajectories(pair)
124 return
125
126 trajectory3D = pair.getTrajectory3D()
127 revFromSegment = pair.getFromSegment().reversed()
128 revToSegment = pair.getToSegment().reversed()
129 revPair = CDCSegmentPair(revToSegment, revFromSegment)
130
131 CDCAxialStereoFusion.reconstructFuseTrajectories(revPair)
132 revTrajectory3D = revPair.getTrajectory3D().reversed()
133
134 # print("One origin x", trajectory3D.getLocalOrigin().x())
135 # print("One origin y", trajectory3D.getLocalOrigin().y())
136 # print("One origin z", trajectory3D.getLocalOrigin().z())
137
138 # print("Rev origin x", revTrajectory3D.getLocalOrigin().x())
139 # print("Rev origin y", revTrajectory3D.getLocalOrigin().y())
140 # print("Rev origin z", revTrajectory3D.getLocalOrigin().z())
141
142 print("One parameters", [trajectory3D.getLocalHelix().parameters()[i] for i in range(5)])
143 print("Rev parameters", [revTrajectory3D.getLocalHelix().parameters()[i] for i in range(5)])
144
145 print("One covariance")
146 for j in range(5):
147 print([trajectory3D.getLocalHelix().helixCovariance()(i, j) for i in range(5)])
148
149 print("Rev covariance")
150 for j in range(5):
151 print([revTrajectory3D.getLocalHelix().helixCovariance()(i, j) for i in range(5)])
152
153 # return revTrajectory3D
154 # return trajectory3D
155
156 return sz_segment_pair_fusion_fit
157
158 else:
159 raise ValueError(f"Unexpected fit_positions {fit_method_name}")
160
Utility class implementing the Kalmanesk combination of to two dimensional trajectories to one three ...
static const CDCSZFitter & getFitter()
Getter for a standard sz line fitter instance.
Class representing a pair of one reconstructed axial segment and one stereo segment in adjacent super...

◆ harvesting_module()

harvesting_module ( self,
path = None )
Harvest and post-process the MC events

Reimplemented from HarvestingRunMixin.

Definition at line 61 of file record.py.

61 def harvesting_module(self, path=None):
62 """Harvest and post-process the MC events"""
63 harvesting_module = SegmentPairFitValidationModule(self.output_file_name)
64 if path:
65 path.add_module(harvesting_module)
66 return harvesting_module
67

◆ name()

name ( self)
inherited
provide name of this object

Definition at line 41 of file minimal.py.

41 def name(self):
42 """provide name of this object"""
43 return self.__class__.__name__
44

◆ output_file_name()

output_file_name ( self)
Get the output ROOT filename

Reimplemented from HarvestingRunMixin.

Definition at line 49 of file record.py.

49 def output_file_name(self):
50 """Get the output ROOT filename"""
51 file_name = self.fit_method_name
52 file_name += "-mc-" + self.monte_carlo
53
54 if self.root_input_file:
55 file_name += "-" + os.path.split(self.root_input_file)[1]
56 else:
57 file_name += ".root"
58
59 return file_name
60

◆ pickle_crops()

pickle_crops ( self,
harvesting_module,
crops,
** kwds )
inherited
Save the raw crops as a pickle file

Definition at line 41 of file run.py.

41 def pickle_crops(self, harvesting_module, crops, **kwds):
42 """Save the raw crops as a pickle file"""
43 with open(self.output_file_name + ".pickle", "wb") as pickle_file:
44 pickle.dump(crops, pickle_file)
45

◆ postprocess()

postprocess ( self)
inherited
Post-process the crops

Reimplemented from BrowseTFileOnTerminateRunMixin.

Definition at line 51 of file run.py.

51 def postprocess(self):
52 """Post-process the crops"""
53 if self.postprocess_only:
54 harvesting_module = self.harvesting_module()
55 if self.output_file_name:
56 harvesting_module.output_file_name = self.output_file_name
57 try:
58 crops = self.unpickle_crops()
59 except FileNotFoundError:
60 print("Crops pickle file not found. Create it now.")
61 else:
62 harvesting_module.refine(crops)
63
64 super().postprocess()
65

◆ run()

run ( self,
path )
inherited
Post-process the basf2 job output

Reimplemented from EmptyRun.

Definition at line 45 of file mixins.py.

45 def run(self, path):
46 """Post-process the basf2 job output"""
47 if not self.postprocess_only:
48 super().run(path)
49
50 self.postprocess()
51

◆ unpickle_crops()

unpickle_crops ( self)
inherited
Load the raw crops from a pickle file

Definition at line 46 of file run.py.

46 def unpickle_crops(self):
47 """Load the raw crops from a pickle file"""
48 with open(self.output_file_name + ".pickle", "rb") as pickle_file:
49 return pickle.load(pickle_file)
50

Member Data Documentation

◆ allow_input

bool allow_input = True
staticinherited

By default, this basf2 job can read events from an input ROOT TFile.

Definition at line 109 of file minimal.py.

◆ bkg_files

list bkg_files = []
staticinherited

By default, no background overlay.

Definition at line 47 of file event_generation.py.

◆ components

components = None
staticinherited

By default, do specific components.

Definition at line 49 of file event_generation.py.

◆ description

str description = "Empty execution of basf2"
staticinherited

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

Definition at line 33 of file minimal.py.

◆ detector_setup

str detector_setup = "Default"
staticinherited

By default, use the default detector setup.

Definition at line 45 of file event_generation.py.

◆ disable_deltas

bool disable_deltas = False
staticinherited

By default, do not disable delta-ray generation.

Definition at line 51 of file event_generation.py.

◆ fit_method_name

str fit_method_name = "fuse-sz"
static

use the Kalmanesk fuse of the two trajectory fits

Definition at line 46 of file record.py.

◆ generator_module

generator_module = None
staticinherited

By default, do not generate events.

Definition at line 43 of file event_generation.py.

◆ monte_carlo

str monte_carlo = "no"
static

do not generate new events

Definition at line 41 of file record.py.

◆ n_events

n_events = 10000
staticinherited

By default, process 10000 events.

Definition at line 111 of file minimal.py.

◆ n_events_to_skip

int n_events_to_skip = 0
staticinherited

By default, do not skip any events at the start of the input ROOT TFile.

Definition at line 119 of file minimal.py.

◆ n_processes

n_processes = 0
staticinherited

By default, no parallel processing.

Definition at line 117 of file minimal.py.

◆ pickle_crops

pickle_crops = self.output_file_name
inherited

Definition at line 72 of file run.py.

◆ postprocess_only

bool postprocess_only = False
staticinherited

By default, browse the output TFile too.

Post-process the basf2 job output

Definition at line 29 of file mixins.py.

◆ random_seed

random_seed = None
staticinherited

By default, the random-number seed is unassigned.

Definition at line 115 of file minimal.py.

◆ root_input_file

root_input_file = None
staticinherited

By default, there is no input ROOT TFile.

Definition at line 113 of file minimal.py.

◆ segment_orientation

str segment_orientation = "outwards"
static

ordering of the segments in the pair

Definition at line 43 of file record.py.

◆ show_results

bool show_results = False
staticinherited

By default, do not show the browsing results.

Definition at line 62 of file mixins.py.

◆ simulation_output

simulation_output = None
staticinherited

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: