Belle II Software  release-06-02-00
run_eclHadronTimeCalibrationValidation_collector.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 #
13 # This script executes the hadron timing calibration collector,
14 # which reads in the hadron events to perform the hadron
15 # validation, where the final validation fits is performed
16 # by the algorithm.
17 # This script is run directly with basf2.
18 #
19 # There are two ways you can use this script:
20 # 1. Provide parameters from command line:
21 # basf2 run_eclHadronTimeCalibrationValidation_collector.py -i "/path/to/input/files/*.root" -o collector_output.root
22 #
23 # 2. Set parameters directly in steering file.
24 # Change INPUT_LIST and OUTPUT variables.
25 # (Multiple files can be easily added with glob.glob("/path/to/your/files/*.root"))
26 # And then call
27 # basf2 run_eclHadronTimeCalibrationValidation_collector.py
28 
29 
30 import basf2 as b2
31 from ROOT import Belle2
32 import glob
33 import sys
34 import tracking
35 import rawdata
36 import reconstruction
37 
38 from basf2 import conditions as b2conditions
39 from reconstruction import prepare_user_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)
51 INPUT_LIST = []
52 # = Processed data
53 INPUT_LIST += glob.glob("oneTestFile/*.root")
54 
55 # == Output file
56 OUTPUT = "eclHadronTimeCalibrationValidationCollector.root"
57 
58 
60 
61 # Override input if "-i file.root" argument was sent to basf2.
62 input_arg = env.getInputFilesOverride()
63 if len(input_arg) > 0:
64  INPUT_LIST = [str(x) for x in input_arg]
65 # Sort list of input files.
66 INPUT_LIST.sort(key=lambda item: (len(item), item))
67 
68 # Override output if "-o file.root" argument was sent to basf2.
69 output_arg = env.getOutputFileOverride()
70 if 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
79 TIME_ABS_MAX = 70
80 
81 # If true, output file will contain TTree "tree" with detailed
82 # event information.
83 SAVE_TREE = True
84 
85 
86 
87 components = ['CDC', 'ECL']
88 
89 # == Create path
90 main = b2.create_path()
91 
92 add_unpackers = False
93 
94 # == SeqRoot/Root input
95 if INPUT_LIST[0].endswith('sroot'):
96  main.add_module('SeqRootInput', inputFileNames=INPUT_LIST)
97  add_unpackers = True
98 else:
99  main.add_module('RootInput', inputFileNames=INPUT_LIST)
100 
101 main.add_module("HistoManager", histoFileName=OUTPUT)
102 
103 if 'Raw' in INPUT_LIST[0]:
104  add_unpackers = True
105 
106 
107 main.add_module('Gearbox')
108 
109 if add_unpackers:
110  rawdata.add_unpackers(main, components=components)
111 
112  # = Get Tracks, RecoTracks, ECLClusters, add relations between them.
113  tracking.add_tracking_reconstruction(main, components=components)
114  reconstruction.add_ext_module(main, components)
115  reconstruction.add_ecl_modules(main, components)
116  reconstruction.add_ecl_track_matcher_module(main, components)
117 
118 prepare_user_cdst_analysis(main) # for new 2020 cdst format
119 
120 # == Generate time calibration matrix from ECLDigit
121 ECLtimeCalibValidationCollectorInfo = main.add_module('eclHadronTimeCalibrationValidationCollector', timeAbsMax=TIME_ABS_MAX,
122  saveTree=SAVE_TREE)
123 
124 ECLtimeCalibValidationCollectorInfo.set_log_level(b2.LogLevel.INFO) # OR: b2.LogLevel.DEBUG
125 ECLtimeCalibValidationCollectorInfo.set_debug_level(36)
126 
127 
128 # == Show progress
129 main.add_module('Progress')
130 
131 b2.set_log_level(b2.LogLevel.INFO)
132 b2.set_debug_level(100)
133 
134 # == Configure database
135 # reset_database()
136 # use_database_chain()
137 
138 b2conditions.reset()
139 b2conditions.override_globaltags()
140 
141 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
142 b2conditions.prepend_testing_payloads("localdb/database.txt")
143 b2.B2INFO("Using Global Tag {}")
144 b2conditions.prepend_globaltag("dp_recon_release6_patch")
145 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
146 b2conditions.prepend_globaltag("AIRFLOW_online_snapshot_20210719-124441")
147 b2conditions.prepend_globaltag("data_reprocessing_prompt")
148 
149 
150 # == Process events
151 # b2.process(main, max_event=350000) # reasonable stats for one crate
152 # b2.process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
153 # b2.process(main, max_event=3000) # reasonable stats and speed for a quick test
154 # b2.process(main, max_event=30) # fast test
155 b2.process(main) # process all events
156 
157 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