Belle II Software  release-05-02-19
run_eclBhabhaT_collector.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 #
4 # -----------------------------------------------------------
5 # BASF2 (Belle Analysis Framework 2)
6 # Copyright(C) 2019 Belle II Collaboration
7 #
8 # Author: The Belle II Collaboration
9 # Contributors: Ewan Hill (ehill@mail.ubc.ca)
10 # Mikhail Remnev
11 #
12 # This software is provided "as is" without any warranty.
13 # -----------------------------------------------------------
14 
15 
23 
24 
25 # There are two ways you can use this script:
26 # 1. Provide parameters from command line:
27 # basf2 run_eclBhabhaT_collector.py -i "/path/to/input/files/*.root" -o collector_output.root
28 #
29 # 2. Set parameters directly in steering file.
30 # Change INPUT_LIST and OUTPUT variables.
31 # (Multiple files can be easily added with glob.glob("/path/to/your/files/*.root"))
32 # And then call
33 # basf2 run_eclBhabhaT_collector.py
34 
35 from basf2 import *
36 from ROOT import Belle2
37 import glob
38 import sys
39 import tracking
40 import rawdata
41 import reconstruction
42 
43 from basf2 import conditions as b2conditions
44 from reconstruction import prepare_cdst_analysis
45 
46 
48 
49 
52 
53 # == List of input files
54 # NOTE: It is going to be sorted (alphabetic and length sorting, files with
55 # shortest names are first)
56 INPUT_LIST = []
57 # = Processed data
58 INPUT_LIST += glob.glob("oneTestFile/*.root")
59 
60 # == Output file
61 OUTPUT = "eclBhabhaTCollector.root"
62 
63 
65 
66 # Override input if "-i file.root" argument was sent to basf2.
67 input_arg = env.getInputFilesOverride()
68 if len(input_arg) > 0:
69  INPUT_LIST = [str(x) for x in input_arg]
70 # Sort list of input files.
71 INPUT_LIST.sort(key=lambda item: (len(item), item))
72 
73 # Override output if "-o file.root" argument was sent to basf2.
74 output_arg = env.getOutputFileOverride()
75 if len(output_arg) > 0:
76  OUTPUT = output_arg
77 
78 
81 
82 
83 # Events with abs(time_ECL-time_CDC) > TIME_ABS_MAX are excluded
84 TIME_ABS_MAX = 250
85 
86 # If true, output file will contain TTree "tree" with detailed
87 # event information.
88 SAVE_TREE = False
89 
90 # First ECL CellId to calibrate
91 MIN_CRYSTAL = 1
92 # Last ECL CellId to calibrate
93 MAX_CRYSTAL = 8736
94 
95 # Bias of CDC event t0 in bhabha vs hadronic events (in ns)
96 CDC_T0_BIAS_CORRECTION_OFFSET = 0 # default is 0ns
97 
98 
99 
100 components = ['CDC', 'ECL']
101 
102 # == Create path
103 main = create_path()
104 
105 add_unpackers = False
106 
107 # == SeqRoot/Root input
108 if INPUT_LIST[0].endswith('sroot'):
109  main.add_module('SeqRootInput', inputFileNames=INPUT_LIST)
110  add_unpackers = True
111 else:
112  main.add_module('RootInput', inputFileNames=INPUT_LIST)
113 
114 main.add_module("HistoManager", histoFileName=OUTPUT)
115 
116 if 'Raw' in INPUT_LIST[0]:
117  add_unpackers = True
118 
119 
120 main.add_module('Gearbox')
121 
122 if add_unpackers:
123  rawdata.add_unpackers(main, components=components)
124 
125  # = Get Tracks, RecoTracks, ECLClusters, add relations between them.
126  tracking.add_tracking_reconstruction(main, components=components)
127  reconstruction.add_ext_module(main, components)
128  reconstruction.add_ecl_modules(main, components)
129  reconstruction.add_ecl_track_matcher_module(main, components)
130 
131 prepare_cdst_analysis(main) # for new 2020 cdst format
132 
133 # == Generate time calibration matrix from ECLDigit
134 ECLBhabhaTCollectorInfo = main.add_module('ECLBhabhaTCollector', timeAbsMax=TIME_ABS_MAX,
135  minCrystal=MIN_CRYSTAL, maxCrystal=MAX_CRYSTAL,
136  saveTree=SAVE_TREE,
137  hadronEventT0_TO_bhabhaEventT0_correction=CDC_T0_BIAS_CORRECTION_OFFSET)
138 
139 ECLBhabhaTCollectorInfo.set_log_level(b2.LogLevel.INFO) # OR: b2.LogLevel.DEBUG
140 ECLBhabhaTCollectorInfo.set_debug_level(36)
141 
142 
143 # == Show progress
144 main.add_module('Progress')
145 
146 # set_log_level(LogLevel.DEBUG)
147 set_log_level(LogLevel.INFO)
148 set_debug_level(100)
149 
150 # == Configure database
151 # reset_database()
152 # use_database_chain()
153 
154 b2conditions.reset()
155 b2conditions.override_globaltags()
156 
157 # These global tags will have to be updated for your files
158 # Highest priority last
159 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
160 b2conditions.prepend_testing_payloads("localdb/database.txt")
161 b2.B2INFO("Using Global Tag {}")
162 b2conditions.prepend_globaltag("ECL_testingNewPayload_RefCrystalPerCrate")
163 b2conditions.prepend_globaltag("master_2020-05-13")
164 b2conditions.prepend_globaltag("online_proc11")
165 b2conditions.prepend_globaltag("data_reprocessing_proc11")
166 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
167 
168 # == Process events
169 # process(main, max_event=350000) # reasonable stats for one crate
170 # process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
171 # process(main, max_event=3000) # reasonable stats and speed for a quick test
172 b2.process(main) # process all events
173 
174 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