Belle II Software  release-05-01-25
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 # --------------------------------------------------------------------------
16 # BASF2 script for the first (out of two) step of time shift calibration.
17 # using bhabha events.
18 # --------------------------------------------------------------------------
19 #
20 # There are two ways you can use it:
21 # 1. Provide parameters from command line:
22 # basf2 EclBhabhaTCollector.py -i "/path/to/input/files/*.root" -o collector_output.root
23 #
24 # 2. Set parameters directly in steering file.
25 # Change INPUT_LIST and OUTPUT variables.
26 # (Multiple files can be easily added with glob.glob("/path/to/your/files/*.root"))
27 # And then call
28 # basf2 EclBhabhaTCollector.py
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 
39 
40 
43 
44 # == List of input files
45 # NOTE: It is going to be sorted (alphabetic and length sorting, files with
46 # shortest names are first)
47 INPUT_LIST = []
48 # = Processed data
49 INPUT_LIST += glob.glob("oneTestFile/*.root")
50 
51 # == Output file
52 OUTPUT = "eclBhabhaTCollector.root"
53 
54 
56 
57 # Override input if "-i file.root" argument was sent to basf2.
58 input_arg = env.getInputFilesOverride()
59 if len(input_arg) > 0:
60  INPUT_LIST = [str(x) for x in input_arg]
61 # Sort list of input files.
62 INPUT_LIST.sort(key=lambda item: (len(item), item))
63 
64 # Override output if "-o file.root" argument was sent to basf2.
65 output_arg = env.getOutputFileOverride()
66 if len(output_arg) > 0:
67  OUTPUT = output_arg
68 
69 
72 
73 
74 # Events with abs(time_ECL-time_CDC) > TIME_ABS_MAX are excluded
75 TIME_ABS_MAX = 250
76 
77 # If true, output file will contain TTree "tree" with detailed
78 # event information.
79 SAVE_TREE = False
80 
81 # First ECL CellId to calibrate
82 MIN_CRYSTAL = 1
83 # Last ECL CellId to calibrate
84 MAX_CRYSTAL = 8736
85 
86 
87 
88 components = ['CDC', 'ECL']
89 
90 # == Create path
91 main = create_path()
92 
93 add_unpackers = False
94 
95 # == SeqRoot/Root input
96 if INPUT_LIST[0].endswith('sroot'):
97  main.add_module('SeqRootInput', inputFileNames=INPUT_LIST)
98  add_unpackers = True
99 else:
100  main.add_module('RootInput', inputFileNames=INPUT_LIST)
101 
102 main.add_module("HistoManager", histoFileName=OUTPUT)
103 
104 if 'Raw' in INPUT_LIST[0]:
105  add_unpackers = True
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 
119 # == Generate time calibration matrix from ECLDigit
120 ECLBhabhaTCollectorInfo = main.add_module('ECLBhabhaTCollector', timeAbsMax=TIME_ABS_MAX,
121  minCrystal=MIN_CRYSTAL, maxCrystal=MAX_CRYSTAL,
122  saveTree=SAVE_TREE)
123 
124 ECLBhabhaTCollectorInfo.set_log_level(LogLevel.INFO) # OR: LogLevel.DEBUG
125 ECLBhabhaTCollectorInfo.set_debug_level(36)
126 
127 
128 # == Show progress
129 main.add_module('Progress')
130 
131 # set_log_level(LogLevel.DEBUG)
132 set_log_level(LogLevel.INFO)
133 set_debug_level(100)
134 
135 # == Configure database
136 reset_database()
137 use_database_chain()
138 
139 # Read in any required central databases
140 # use_central_database("online")
141 
142 # 2 GT required for making proc 10
143 use_central_database("data_reprocessing_proc10")
144 use_central_database("data_reprocessing_prompt_rel4_patchb")
145 
146 # Read in any required local databases. This may be required when doing crystal/crate iterations
147 use_local_database("localdb/database.txt")
148 
149 
150 # == Process events
151 # process(main, max_event=350000) # reasonable stats for one crate
152 # process(main, max_event=600000) # reasonable stats for crystal calibs for proc10
153 # process(main, max_event=3000) # reasonable stats and speed for a quick test
154 process(main) # process all events
155 
156 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:618
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:752