Belle II Software  release-05-02-19
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 from basf2 import *
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 = 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(LogLevel.DEBUG)
127 ECLtimeCalibValidationCollectorInfo.set_log_level(LogLevel.INFO)
128 ECLtimeCalibValidationCollectorInfo.set_debug_level(36)
129 
130 
131 # == Show progress
132 main.add_module('Progress')
133 
134 # set_log_level(LogLevel.DEBUG)
135 set_log_level(LogLevel.INFO)
136 set_debug_level(100)
137 
138 # == Configure database
139 # reset_database()
140 # use_database_chain()
141 
142 b2conditions.reset()
143 b2conditions.override_globaltags()
144 
145 B2INFO("Adding Local Database {} to head of chain of local databases.")
146 b2conditions.prepend_testing_payloads("localdb/database.txt")
147 B2INFO("Using Global Tag {}")
148 b2conditions.prepend_globaltag("ECL_testingNewPayload_RefCrystalPerCrate")
149 b2conditions.prepend_globaltag("master_2020-05-13")
150 b2conditions.prepend_globaltag("online_proc11")
151 b2conditions.prepend_globaltag("data_reprocessing_proc11")
152 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
153 
154 
155 # == Process events
156 # process(main, max_event=350000) # reasonable stats for one crate
157 # process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
158 # process(main, max_event=3000) # reasonable stats and speed for a quick test
159 process(main, max_event=30) # fast test
160 # process(main) # process all events
161 
162 print(statistics)
tracking.add_tracking_reconstruction
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:8
rawdata.add_unpackers
def add_unpackers(path, components=None, writeKLMDigitRaws=False)
Definition: rawdata.py:62
reconstruction.add_ecl_modules
def add_ecl_modules(path, components=None)
Definition: reconstruction.py:630
Belle2::Environment::Instance
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:31
reconstruction.add_ext_module
def add_ext_module(path, components=None)
Definition: reconstruction.py:764