Belle II Software  release-06-02-00
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 sys
36 import tracking
37 import rawdata
38 import reconstruction
39 
40 from basf2 import conditions as b2conditions
41 from reconstruction import prepare_cdst_analysis
42 
43 
45 
46 
49 
50 # == List of input files
51 # NOTE: It is going to be sorted (alphabetic and length sorting, files with
52 # shortest names are first)
53 INPUT_LIST = []
54 # = Processed data
55 INPUT_LIST += glob.glob("oneTestFile/*.root")
56 
57 # == Output file
58 OUTPUT = "eclBhabhaTCollector.root"
59 
60 
62 
63 # Override input if "-i file.root" argument was sent to basf2.
64 input_arg = env.getInputFilesOverride()
65 if len(input_arg) > 0:
66  INPUT_LIST = [str(x) for x in input_arg]
67 # Sort list of input files.
68 INPUT_LIST.sort(key=lambda item: (len(item), item))
69 
70 # Override output if "-o file.root" argument was sent to basf2.
71 output_arg = env.getOutputFileOverride()
72 if len(output_arg) > 0:
73  OUTPUT = output_arg
74 
75 
78 
79 
80 # Events with abs(time_ECL-time_CDC) > TIME_ABS_MAX are excluded
81 TIME_ABS_MAX = 250
82 
83 # If true, output file will contain TTree "tree" with detailed
84 # event information.
85 SAVE_TREE = False
86 
87 # First ECL CellId to calibrate
88 MIN_CRYSTAL = 1
89 # Last ECL CellId to calibrate
90 MAX_CRYSTAL = 8736
91 
92 # Bias of CDC event t0 in bhabha vs hadronic events (in ns)
93 CDC_T0_BIAS_CORRECTION_OFFSET = 0 # default is 0ns
94 
95 
96 
97 components = ['CDC', 'ECL']
98 
99 # == Create path
100 main = b2.create_path()
101 
102 add_unpackers = False
103 
104 # == SeqRoot/Root input
105 if INPUT_LIST[0].endswith('sroot'):
106  main.add_module('SeqRootInput', inputFileNames=INPUT_LIST)
107  add_unpackers = True
108 else:
109  main.add_module('RootInput', inputFileNames=INPUT_LIST)
110 
111 main.add_module("HistoManager", histoFileName=OUTPUT)
112 
113 if 'Raw' in INPUT_LIST[0]:
114  add_unpackers = True
115 
116 
117 main.add_module('Gearbox')
118 
119 if add_unpackers:
120  rawdata.add_unpackers(main, components=components)
121 
122  # = Get Tracks, RecoTracks, ECLClusters, add relations between them.
123  tracking.add_tracking_reconstruction(main, components=components)
124  reconstruction.add_ext_module(main, components)
125  reconstruction.add_ecl_modules(main, components)
126  reconstruction.add_ecl_track_matcher_module(main, components)
127 
128 prepare_cdst_analysis(main) # for new 2020 cdst format
129 
130 # == Generate time calibration matrix from ECLDigit
131 ECLBhabhaTCollectorInfo = main.add_module('ECLBhabhaTCollector', timeAbsMax=TIME_ABS_MAX,
132  minCrystal=MIN_CRYSTAL, maxCrystal=MAX_CRYSTAL,
133  saveTree=SAVE_TREE,
134  hadronEventT0_TO_bhabhaEventT0_correction=CDC_T0_BIAS_CORRECTION_OFFSET)
135 
136 ECLBhabhaTCollectorInfo.set_log_level(b2.LogLevel.INFO) # OR: b2.LogLevel.DEBUG
137 ECLBhabhaTCollectorInfo.set_debug_level(36)
138 
139 
140 # == Show progress
141 main.add_module('Progress')
142 
143 # set_log_level(LogLevel.DEBUG)
144 b2.set_log_level(b2.LogLevel.INFO)
145 b2.set_debug_level(100)
146 
147 # == Configure database
148 # reset_database()
149 # use_database_chain()
150 
151 b2conditions.reset()
152 b2conditions.override_globaltags()
153 
154 # These global tags will have to be updated for your files
155 # Highest priority last
156 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
157 b2conditions.prepend_testing_payloads("localdb/database.txt")
158 b2.B2INFO("Using Global Tag {}")
159 b2conditions.prepend_globaltag("dp_recon_release6_patch")
160 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
161 b2conditions.prepend_globaltag("AIRFLOW_online_snapshot_20210719-124441")
162 b2conditions.prepend_globaltag("data_reprocessing_prompt")
163 
164 
165 # == Process events
166 # b2.process(main, max_event=350000) # reasonable stats for one crate
167 # b2.process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
168 # b2.process(main, max_event=3000) # reasonable stats and speed for a quick test
169 b2.process(main) # process all events
170 
171 print(b2.statistics)
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:29
def add_unpackers(path, components=None, writeKLMDigitRaws=False, addTOPRelations=False)
Definition: rawdata.py:68
def add_ecl_modules(path, components=None)
def add_ext_module(path, components=None)
def add_tracking_reconstruction(path, components=None, pruneTracks=False, skipGeometryAdding=False, mcTrackFinding=False, trackFitHypotheses=None, reco_tracks="RecoTracks", prune_temporary_tracks=True, fit_tracks=True, use_second_cdc_hits=False, skipHitPreparerAdding=False, use_svd_to_cdc_ckf=True, use_ecl_to_cdc_ckf=False, add_cdcTrack_QI=True, add_vxdTrack_QI=False, add_recoTrack_QI=False)
Definition: __init__.py:44