Belle II Software  release-08-01-10
run_eclHadronTimeCalibrationValidation_collector.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 #
13 # This script executes the hadron timing calibration collector,
14 # which reads in the hadron events to perform the hadron
15 # validation, where the final validation fits is performed
16 # by the algorithm.
17 # This script is run directly with basf2.
18 #
19 # There are two ways you can use this script:
20 # 1. Provide parameters from command line:
21 # basf2 run_eclHadronTimeCalibrationValidation_collector.py -i "/path/to/input/files/*.root" -o collector_output.root
22 #
23 # 2. Set parameters directly in steering file.
24 # Change INPUT_LIST and OUTPUT variables.
25 # (Multiple files can be easily added with glob.glob("/path/to/your/files/*.root"))
26 # And then call
27 # basf2 run_eclHadronTimeCalibrationValidation_collector.py
28 
29 
30 import basf2 as b2
31 from ROOT import Belle2
32 import glob
33 import tracking
34 import rawdata
35 import reconstruction
36 
37 from basf2 import conditions as b2conditions
38 from reconstruction import prepare_user_cdst_analysis
39 
40 
42 
43 
46 
47 # == List of input files
48 # NOTE: It is going to be sorted (alphabetic and length sorting, files with
49 # shortest names are first)
50 INPUT_LIST = []
51 # = Processed data
52 INPUT_LIST += glob.glob("oneTestFile/*.root")
53 
54 # == Output file
55 OUTPUT = "eclHadronTimeCalibrationValidationCollector.root"
56 
57 
59 
60 # Override input if "-i file.root" argument was sent to basf2.
61 input_arg = env.getInputFilesOverride()
62 if len(input_arg) > 0:
63  INPUT_LIST = [str(x) for x in input_arg]
64 # Sort list of input files.
65 INPUT_LIST.sort(key=lambda item: (len(item), item))
66 
67 # Override output if "-o file.root" argument was sent to basf2.
68 output_arg = env.getOutputFileOverride()
69 if len(output_arg) > 0:
70  OUTPUT = output_arg
71 
72 
75 
76 
77 # Events with abs(time_ECL-time_CDC) > TIME_ABS_MAX are excluded
78 TIME_ABS_MAX = 70
79 
80 # If true, output file will contain TTree "tree" with detailed
81 # event information.
82 SAVE_TREE = True
83 
84 
85 
86 components = ['CDC', 'ECL']
87 
88 # == Create path
89 main = b2.create_path()
90 
91 add_unpackers = False
92 
93 # == SeqRoot/Root input
94 if INPUT_LIST[0].endswith('sroot'):
95  main.add_module('SeqRootInput', inputFileNames=INPUT_LIST)
96  add_unpackers = True
97 else:
98  main.add_module('RootInput', inputFileNames=INPUT_LIST)
99 
100 main.add_module("HistoManager", histoFileName=OUTPUT)
101 
102 if 'Raw' in INPUT_LIST[0]:
103  add_unpackers = True
104 
105 
106 main.add_module('Gearbox')
107 
108 if add_unpackers:
109  rawdata.add_unpackers(main, components=components)
110 
111  # = Get Tracks, RecoTracks, ECLClusters, add relations between them.
112  tracking.add_tracking_reconstruction(main, components=components)
113  reconstruction.add_ext_module(main, components)
114  reconstruction.add_ecl_modules(main, components)
115  reconstruction.add_ecl_track_matcher_module(main, components)
116 
117 prepare_user_cdst_analysis(main) # for new 2020 cdst format
118 
119 # == Generate time calibration matrix from ECLDigit
120 ECLtimeCalibValidationCollectorInfo = main.add_module('eclHadronTimeCalibrationValidationCollector', timeAbsMax=TIME_ABS_MAX,
121  saveTree=SAVE_TREE)
122 
123 ECLtimeCalibValidationCollectorInfo.set_log_level(b2.LogLevel.INFO) # OR: b2.LogLevel.DEBUG
124 ECLtimeCalibValidationCollectorInfo.set_debug_level(36)
125 
126 
127 # == Show progress
128 main.add_module('Progress')
129 
130 b2.set_log_level(b2.LogLevel.INFO)
131 b2.set_debug_level(100)
132 
133 # == Configure database
134 # reset_database()
135 # use_database_chain()
136 
137 b2conditions.reset()
138 b2conditions.override_globaltags()
139 
140 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
141 b2conditions.prepend_testing_payloads("localdb/database.txt")
142 b2.B2INFO("Using Global Tag {}")
143 b2conditions.prepend_globaltag("dp_recon_release6_patch")
144 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
145 b2conditions.prepend_globaltag("AIRFLOW_online_snapshot_20210719-124441")
146 b2conditions.prepend_globaltag("data_reprocessing_prompt")
147 
148 
149 # == Process events
150 # b2.process(main, max_event=350000) # reasonable stats for one crate
151 # b2.process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
152 # b2.process(main, max_event=3000) # reasonable stats and speed for a quick test
153 # b2.process(main, max_event=30) # fast test
154 b2.process(main) # process all events
155 
156 print(b2.statistics)
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
def add_unpackers(path, components=None, writeKLMDigitRaws=False, addTOPRelations=False)
Definition: rawdata.py:67
def add_ecl_modules(path, components=None)
def add_ext_module(path, components=None)