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