Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:06

0001 #!/bin/env python3
0002 import argparse
0003 import os
0004 import sys
0005 import copy
0006 
0007 from processors import (
0008     AverageTrackPlotter,
0009     ComponentsPlotter,
0010     MomentumGraph,
0011     BoundParametersProcessor,
0012 )
0013 
0014 
0015 def main():
0016     # fmt: off
0017     parser = argparse.ArgumentParser(description='GSF Debugger')
0018     parser.add_argument('--detector', '-d', help="detector description as csv file", type=str)
0019     parser.add_argument('--logfile', '-f', help="log file (if not given, stdin is read)", type=str)
0020     parser.add_argument('--nogui', action="store_true", default=False, help="for testing the log parsing (works without Qt)")
0021     parser.add_argument('--view', choices=["cylindrical", "telescope"], default="cylindrical", help="cylindrical=zr+xy, telescope=zx,xy")
0022     # fmt: on
0023     args = vars(parser.parse_args())
0024 
0025     # Try to be smart an load the detectors.csv from the current working dir if possible
0026     if args["detector"] is None and "detectors.csv" in os.listdir():
0027         args["detector"] = "detectors.csv"
0028 
0029     # If no logfile is given, read from stdin (for piping)
0030     if args["logfile"] is not None:
0031         with open(args["logfile"], "r") as f:
0032             lines = f.readlines()
0033     else:
0034         print("Read from standard input...")
0035         lines = sys.stdin.readlines()
0036 
0037     # Group the log into steps to forward it to the processors
0038     # TODO this is maybe not super reliable and also highly GSF specific
0039     steps = []
0040     current_step = []
0041     for line in lines:
0042         if line.count("at mean position") == 1:
0043             steps.append(copy.deepcopy(current_step))
0044             current_step = []
0045 
0046         current_step.append(line)
0047 
0048     # Initialize the drawers
0049     if args["nogui"]:
0050         drawers = None
0051     else:
0052         from drawers import CsvZRDrawer, CsvXYDrawer, CsvXZDrawer
0053 
0054         if args["view"] == "cylindrical":
0055             drawers = [CsvZRDrawer(args["detector"]), CsvXYDrawer(args["detector"])]
0056         elif args["view"] == "telescope":
0057             drawers = [
0058                 CsvXZDrawer(args["detector"], assume_telescope=True),
0059                 CsvXYDrawer(args["detector"], assume_telescope=True),
0060             ]
0061 
0062     # Initialize the processors
0063     processors = [
0064         AverageTrackPlotter(drawers),
0065         ComponentsPlotter(drawers),
0066         MomentumGraph(),
0067         BoundParametersProcessor("Predicted"),
0068         BoundParametersProcessor("Filtered"),
0069     ]
0070 
0071     # Parse the step in each processor
0072     for step in steps:
0073         for processor in processors:
0074             processor.parse_step(step)
0075 
0076     # Run the Qt app
0077     if not args["nogui"]:
0078         from PyQt5 import QtWidgets
0079         from widgets import MainWindow
0080 
0081         app = QtWidgets.QApplication(sys.argv)
0082         w = MainWindow(processors, steps)
0083         app.exec_()
0084 
0085 
0086 if __name__ == "__main__":
0087     main()