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