Belle II Software  release-08-01-10
run_eclBhabhaTimeCalibrationValidation_collector.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
20 
21 # There are two ways you can use this script:
22 # 1. Provide parameters from command line:
23 # basf2 run_eclBhabhaTimeCalibrationValidation_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_eclBhabhaTimeCalibrationValidation_collector.py
30 
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_user_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 = "eclBhabhaTimeCalibrationValidationCollector.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 = 70
81 
82 # If true, output file will contain TTree "tree" with detailed
83 # event information.
84 SAVE_TREE = True
85 
86 
87 
88 components = ['CDC', 'ECL']
89 
90 # == Create path
91 main = b2.create_path()
92 
93 add_unpackers = False
94 
95 # == SeqRoot/Root input
96 if INPUT_LIST[0].endswith('sroot'):
97  main.add_module('SeqRootInput', inputFileNames=INPUT_LIST)
98  add_unpackers = True
99 else:
100  main.add_module('RootInput', inputFileNames=INPUT_LIST)
101 
102 main.add_module("HistoManager", histoFileName=OUTPUT)
103 
104 if 'Raw' in INPUT_LIST[0]:
105  add_unpackers = True
106 
107 
108 main.add_module('Gearbox')
109 
110 if add_unpackers:
111  rawdata.add_unpackers(main, components=components)
112 
113  # = Get Tracks, RecoTracks, ECLClusters, add relations between them.
114  tracking.add_tracking_reconstruction(main, components=components)
115  reconstruction.add_ext_module(main, components)
116  reconstruction.add_ecl_modules(main, components)
117  reconstruction.add_ecl_track_matcher_module(main, components)
118 
119 prepare_user_cdst_analysis(main) # for new 2020 cdst format
120 
121 # == Generate time calibration matrix from ECLDigit
122 ECLtimeCalibValidationCollectorInfo = main.add_module('eclBhabhaTimeCalibrationValidationCollector', timeAbsMax=TIME_ABS_MAX,
123  saveTree=SAVE_TREE)
124 
125 ECLtimeCalibValidationCollectorInfo.set_log_level(b2.LogLevel.INFO) # OR: b2.LogLevel.DEBUG
126 ECLtimeCalibValidationCollectorInfo.set_debug_level(36)
127 
128 
129 # == Show progress
130 main.add_module('Progress')
131 
132 b2.set_log_level(b2.LogLevel.INFO)
133 b2.set_debug_level(100)
134 
135 # == Configure database
136 # reset_database()
137 # use_database_chain()
138 
139 b2conditions.reset()
140 b2conditions.override_globaltags()
141 
142 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
143 b2conditions.prepend_testing_payloads("localdb/database.txt")
144 b2.B2INFO("Using Global Tag {}")
145 b2conditions.prepend_globaltag("dp_recon_release6_patch")
146 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
147 b2conditions.prepend_globaltag("AIRFLOW_online_snapshot_20210719-124441")
148 b2conditions.prepend_globaltag("data_reprocessing_prompt")
149 
150 
151 # == Process events
152 # b2.process(main, max_event=350000) # reasonable stats for one crate
153 # b2.process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
154 # b2.process(main, max_event=3000) # reasonable stats and speed for a quick test
155 # b2.process(main, max_event=30) # fast test
156 b2.process(main) # process all events
157 
158 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)