Belle II Software  release-06-01-15
TrackingValidation.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """
13 Generic script to run the tracking validation code on-top of a root file containing
14 simulated events. This can speed up the development process allows for an easier reproducibility
15 in single events.
16 
17 Example to run only the cellular automaton track finder in the CDC:
18 
19 python tracking/examples/TrackingValidation.py -i <input.root> -o <output.root> -m TrackFinderCDCAutomaton
20 
21 Example to run the full reconstruction:
22 
23 python tracking/examples/TrackingValidation.py -i <input.root> -o <output.root> -m FullReco
24 """
25 
26 import ROOT
27 from tracking.validation.run import TrackingValidationRun
28 import argparse
29 import basf2
30 # run at most over this amount of events
31 N_EVENTS = 100
32 ACTIVE = True
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()
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:75