Belle II Software  release-08-01-10
TrackingValidation.py
1 #!/usr/bin/env python3
2 
3 
10 
11 """
12 Generic script to run the tracking validation code on-top of a root file containing
13 simulated events. This can speed up the development process allows for an easier reproducibility
14 in single events.
15 
16 Example to run only the cellular automaton track finder in the CDC:
17 
18 python tracking/examples/TrackingValidation.py -i <input.root> -o <output.root> -m TrackFinderCDCAutomaton
19 
20 Example to run the full reconstruction:
21 
22 python tracking/examples/TrackingValidation.py -i <input.root> -o <output.root> -m FullReco
23 """
24 
25 import ROOT
26 from tracking.validation.run import TrackingValidationRun
27 import argparse
28 import basf2
29 # run at most over this amount of events
30 N_EVENTS = 100
31 ACTIVE = True
32 CONTACT = 'software-tracking@belle2.org'
33 
34 basf2.set_random_seed(1337)
35 
36 
38  """Run-Class to run the validation on top of a simulated root file. Most parameters can be chosen from command line."""
39 
40 
41  n_events = N_EVENTS
42 
43  components = ['PXD', 'SVD', 'CDC', 'BeamPipe',
44  'MagneticFieldConstant4LimitedRCDC']
45 
46  finder_module = None
47 
48  pulls = True
49 
50  contact = CONTACT
51 
52 
53 def main():
54  argument_parser = argparse.ArgumentParser()
55 
56  # Indication if tracks should be fitted.
57  argument_parser.add_argument(
58  '-f',
59  '--fit',
60  action='store_true',
61  help='Perform fitting of the generated tracks with Genfit. Default is not '
62  'to perform a fit but use the seed values generated in track finding.')
63 
64  argument_parser.add_argument('-s', '--show', action='store_true',
65  help='Show generated plots in a TBrowser immediatly.')
66 
67  argument_parser.add_argument('-i', '--input', type=str,
68  nargs="?", default=None, required=True,
69  help='Path to the input root file containing the simulated events.')
70 
71  argument_parser.add_argument('-o', '--output', type=str,
72  nargs="?", default="TrackingValidation.root",
73  help='Name of the output file used to store the validation plots.')
74 
75  argument_parser.add_argument(
76  '-m',
77  '--module',
78  type=str,
79  choices=[
80  'TFCDC_TrackFinderAutomaton',
81  'TrackFinderCDC'
82  'Reconstruction'],
83  default='Reconstruction',
84  help='Short name of track finding module or Reconstruction for the full reconstruction chain.')
85 
86  arguments = argument_parser.parse_args()
87 
88  # Setup the validation run #
89 
90  standalone_validation_run = Standalone()
91  if arguments.fit:
92  standalone_validation_run.fit_tracks = True
93  else:
94  standalone_validation_run.fit_tracks = False
95 
96  # setup input root file #
97 
98  standalone_validation_run.root_input_file = arguments.input
99  # disable simulation
100  standalone_validation_run.run_simulation = False
101 
102  # setup output root file #
103 
104  standalone_validation_run.output_file_name = arguments.output
105 
106  # setup reco module(s) to execute #
107 
108  standalone_validation_run.finder_module = arguments.module
109 
110  # Execute the validation run #
111 
112  standalone_validation_run.execute()
113 
114  # Show plots #
115 
116  if arguments.show:
117  output_file_name = standalone_validation_run.output_file_name
118  tFile = ROOT.TFile(output_file_name)
119  tBrowser = ROOT.TBrowser()
120  tBrowser.BrowseObject(tFile)
121  tBrowser.Show()
122  input('Press enter to close.')
123  tFile.Close()
124 
125 
126 if __name__ == '__main__':
127  if ACTIVE:
128  main()
Definition: main.py:1
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91