Belle II Software  release-08-01-10
SVDDQMDoseModuleExample.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
22 
23 """Uses the SVDDQMDose module and makes a rootfile with the histos."""
24 
25 import argparse
26 import os
27 import basf2 as b2
28 from basf2 import conditions
29 from rawdata import add_unpackers
30 from svd import add_svd_reconstruction
31 from svd.executionTime_utils import SVDExtraEventStatisticsModule
32 from svd.dqm_utils import add_svd_dqm_dose
33 
34 
35 def prepend_to_filename(file_path, prefix):
36  dn, bn = os.path.dirname(file_path), os.path.basename(file_path)
37  return os.path.join(dn, f"{prefix}{bn}")
38 
39 
40 parser = argparse.ArgumentParser(description=__doc__)
41 parser.add_argument("files", metavar="FILE", nargs="+",
42  help="The input rootfile(s) with the RAW data.")
43 parser.add_argument("-o", "--out-file", default="SVDDQM.root",
44  help='The output rootfile. Default "SVDDQM.root".')
45 parser.add_argument("--no-trg-filter", action="store_true",
46  help="Take all events instead of TTYP_POIS only.")
47 parser.add_argument("--exec-time", action="store_true",
48  help="Also record execution time statistics.")
49 args = parser.parse_args()
50 
51 conditions.override_globaltags()
52 conditions.globaltags = ['svd_onlySVDinGeoConfiguration', 'online',
53  'Reco_master_patch_rel5'] # For HardwareClockSettings
54 
55 main = b2.create_path()
56 
57 # Read input (RAW data)
58 main.add_module("RootInput", inputFileNames=args.files)
59 
60 # HistoManager and output
61 main.add_module("HistoManager", histoFileName=args.out_file)
62 
63 # Necessary modules
64 main.add_module('Gearbox')
65 main.add_module('Geometry')
66 if args.no_trg_filter:
67  add_unpackers(main, components=['SVD'])
68 else:
69  add_unpackers(main, components=['SVD', 'TRG'])
70 main.add_module(
71  "SVDZeroSuppressionEmulator", SNthreshold=5,
72  ShaperDigits='SVDShaperDigits', ShaperDigitsIN='SVDShaperDigitsZS5',
73  FADCmode=True)
74 if args.exec_time:
75  add_svd_reconstruction(main) # Required for the statistics
76 
77 # SVDDQMDose module (Poisson trigger only)
78 params = {'trgTypes': []} if args.no_trg_filter else {}
79 add_svd_dqm_dose(main, "SVDShaperDigitsZS5", **params)
80 
81 # SVDDQMInjection for execution time comparison
82 main.add_module('SVDDQMInjection', ShaperDigits='SVDShaperDigitsZS5')
83 
84 # Execution time statistics
85 if args.exec_time:
86  main.add_module(SVDExtraEventStatisticsModule(
87  prepend_to_filename(args.out_file, "stats_")))
88 
89 # Necessary for impatient humans :)
90 main.add_module("ProgressBar")
91 
92 # b2.print_path(main)
93 b2.process(main)
94 print(b2.statistics)