Belle II Software  release-08-01-10
run_eclBhabhaT_collector.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
20 
21 
22 # There are two ways you can use this script:
23 # 1. Provide parameters from command line:
24 # basf2 run_eclBhabhaT_collector.py -i "/path/to/input/files/*.root" -o collector_output.root
25 #
26 # 2. Set parameters directly in steering file.
27 # Change INPUT_LIST and OUTPUT variables.
28 # (Multiple files can be easily added with glob.glob("/path/to/your/files/*.root"))
29 # And then call
30 # basf2 run_eclBhabhaT_collector.py
31 
32 import basf2 as b2
33 from ROOT import Belle2
34 import glob
35 import tracking
36 import rawdata
37 import reconstruction
38 
39 from basf2 import conditions as b2conditions
40 from reconstruction import prepare_cdst_analysis
41 
42 
44 
45 
48 
49 # == List of input files
50 # NOTE: It is going to be sorted (alphabetic and length sorting, files with
51 # shortest names are first)
52 INPUT_LIST = []
53 # = Processed data
54 INPUT_LIST += glob.glob("oneTestFile/*.root")
55 
56 # == Output file
57 OUTPUT = "eclBhabhaTCollector.root"
58 
59 
61 
62 # Override input if "-i file.root" argument was sent to basf2.
63 input_arg = env.getInputFilesOverride()
64 if len(input_arg) > 0:
65  INPUT_LIST = [str(x) for x in input_arg]
66 # Sort list of input files.
67 INPUT_LIST.sort(key=lambda item: (len(item), item))
68 
69 # Override output if "-o file.root" argument was sent to basf2.
70 output_arg = env.getOutputFileOverride()
71 if len(output_arg) > 0:
72  OUTPUT = output_arg
73 
74 
77 
78 
79 # Events with abs(time_ECL-time_CDC) > TIME_ABS_MAX are excluded
80 TIME_ABS_MAX = 250
81 
82 # If true, output file will contain TTree "tree" with detailed
83 # event information.
84 SAVE_TREE = False
85 
86 # First ECL CellId to calibrate
87 MIN_CRYSTAL = 1
88 # Last ECL CellId to calibrate
89 MAX_CRYSTAL = 8736
90 
91 # Bias of CDC event t0 in bhabha vs hadronic events (in ns)
92 CDC_T0_BIAS_CORRECTION_OFFSET = 0 # default is 0ns
93 
94 
95 
96 components = ['CDC', 'ECL']
97 
98 # == Create path
99 main = b2.create_path()
100 
101 add_unpackers = False
102 
103 # == SeqRoot/Root input
104 if INPUT_LIST[0].endswith('sroot'):
105  main.add_module('SeqRootInput', inputFileNames=INPUT_LIST)
106  add_unpackers = True
107 else:
108  main.add_module('RootInput', inputFileNames=INPUT_LIST)
109 
110 main.add_module("HistoManager", histoFileName=OUTPUT)
111 
112 if 'Raw' in INPUT_LIST[0]:
113  add_unpackers = True
114 
115 
116 main.add_module('Gearbox')
117 
118 if add_unpackers:
119  rawdata.add_unpackers(main, components=components)
120 
121  # = Get Tracks, RecoTracks, ECLClusters, add relations between them.
122  tracking.add_tracking_reconstruction(main, components=components)
123  reconstruction.add_ext_module(main, components)
124  reconstruction.add_ecl_modules(main, components)
125  reconstruction.add_ecl_track_matcher_module(main, components)
126 
127 prepare_cdst_analysis(main) # for new 2020 cdst format
128 
129 # == Generate time calibration matrix from ECLDigit
130 ECLBhabhaTCollectorInfo = main.add_module('ECLBhabhaTCollector', timeAbsMax=TIME_ABS_MAX,
131  minCrystal=MIN_CRYSTAL, maxCrystal=MAX_CRYSTAL,
132  saveTree=SAVE_TREE,
133  hadronEventT0_TO_bhabhaEventT0_correction=CDC_T0_BIAS_CORRECTION_OFFSET)
134 
135 ECLBhabhaTCollectorInfo.set_log_level(b2.LogLevel.INFO) # OR: b2.LogLevel.DEBUG
136 ECLBhabhaTCollectorInfo.set_debug_level(36)
137 
138 
139 # == Show progress
140 main.add_module('Progress')
141 
142 # set_log_level(LogLevel.DEBUG)
143 b2.set_log_level(b2.LogLevel.INFO)
144 b2.set_debug_level(100)
145 
146 # == Configure database
147 # reset_database()
148 # use_database_chain()
149 
150 b2conditions.reset()
151 b2conditions.override_globaltags()
152 
153 # These global tags will have to be updated for your files
154 # Highest priority last
155 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
156 b2conditions.prepend_testing_payloads("localdb/database.txt")
157 b2.B2INFO("Using Global Tag {}")
158 b2conditions.prepend_globaltag("dp_recon_release6_patch")
159 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
160 b2conditions.prepend_globaltag("AIRFLOW_online_snapshot_20210719-124441")
161 b2conditions.prepend_globaltag("data_reprocessing_prompt")
162 
163 
164 # == Process events
165 # b2.process(main, max_event=350000) # reasonable stats for one crate
166 # b2.process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
167 # b2.process(main, max_event=3000) # reasonable stats and speed for a quick test
168 b2.process(main) # process all events
169 
170 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)