Belle II Software  release-05-02-19
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 from basf2 import *
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 = 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(LogLevel.DEBUG)
125 ECLtimeCalibValidationCollectorInfo.set_log_level(LogLevel.INFO)
126 ECLtimeCalibValidationCollectorInfo.set_debug_level(36)
127 
128 
129 # == Show progress
130 main.add_module('Progress')
131 
132 # set_log_level(LogLevel.DEBUG)
133 set_log_level(LogLevel.INFO)
134 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 B2INFO("Adding Local Database {} to head of chain of local databases.")
144 b2conditions.prepend_testing_payloads("localdb/database.txt")
145 B2INFO("Using Global Tag {}")
146 b2conditions.prepend_globaltag("ECL_testingNewPayload_RefCrystalPerCrate")
147 b2conditions.prepend_globaltag("master_2020-05-13")
148 b2conditions.prepend_globaltag("online_proc11")
149 b2conditions.prepend_globaltag("data_reprocessing_proc11")
150 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
151 
152 
153 # == Process events
154 # process(main, max_event=350000) # reasonable stats for one crate
155 # process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
156 # process(main, max_event=3000) # reasonable stats and speed for a quick test
157 process(main, max_event=30) # fast test
158 # process(main) # process all events
159 
160 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