Belle II Software  release-05-01-25
cdst_calibrateModuleT0.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # ---------------------------------------------------------------------------------------
5 # Calibrate module T0 with Bhabha (or dimuon) events using likelihood method
6 # Note: this method works correctly only if initial calibration is reasonably good
7 # (M. Staric, 2019-07-10)
8 #
9 # usage: basf2 cdst_calibrateModuleT0.py experiment runFirst runLast
10 # job: bsub -q l "basf2 cdst_calibrateModuleT0.py experiment runFirst runLast"
11 #
12 # note: runLast is inclusive
13 # ---------------------------------------------------------------------------------------
14 
15 from basf2 import *
16 from ROOT import Belle2
17 import sys
18 import glob
19 import os
20 
21 # ----- those need to be adjusted before running --------------------------------------
22 #
23 sampleType = 'bhabha' # sample type: 'bhabha' or 'dimuon'
24 data_dir = '/group/belle2/dataprod/Data/release-03-02-02/DB00000635/proc00000009_nofilter'
25 skim_dir = 'skim/hlt_bhabha/cdst/sub00'
26 globalTag = 'data_reprocessing_prompt' # base global tag (fall-back)
27 stagingTags = ['staging_data_reprocessing'] # list of global tags with new calibration
28 localDB = [] # list of local databases with new calibration
29 output_dir = 'moduleT0' # main output folder
30 #
31 # -------------------------------------------------------------------------------------
32 
33 # Argument parsing
34 argvs = sys.argv
35 if len(argvs) < 4:
36  print("usage: basf2", argvs[0], "experiment runFirst runLast")
37  sys.exit()
38 experiment = int(argvs[1])
39 run_first = int(argvs[2])
40 run_last = int(argvs[3])
41 
42 expNo = 'e' + '{:0=4d}'.format(experiment)
43 
44 # Make list of files
45 files = []
46 for run in range(run_first, run_last + 1):
47  runNo = 'r' + '{:0=5d}'.format(run)
48  for typ in ['4S', 'Continuum', 'Scan']:
49  folder = data_dir + '/' + expNo + '/' + typ + '/' + runNo + '/' + skim_dir
50  files += glob.glob(folder + '/cdst.*.root')
51 if len(files) == 0:
52  B2ERROR('No cdst files found')
53  sys.exit()
54 
55 # Output folder
56 method = 'LL'
57 output_folder = output_dir + '/' + expNo + '/' + sampleType + '/' + method
58 if not os.path.isdir(output_folder):
59  os.makedirs(output_folder)
60  print('New folder created: ' + output_folder)
61 
62 # Output file name
63 fileName = output_folder + '/moduleT0-' + expNo + '-'
64 run1 = 'r' + '{:0=5d}'.format(run_first)
65 run2 = 'r' + '{:0=5d}'.format(run_last)
66 fileName += run1 + '_to_' + run2 + '.root'
67 print('Output file:', fileName)
68 
69 
70 class Mask_BS13d(Module):
71  ''' exclude (mask-out) BS 13d '''
72 
73  def event(self):
74  ''' event processing '''
75 
76  for digit in Belle2.PyStoreArray('TOPDigits'):
77  if digit.getModuleID() == 13 and digit.getBoardstackNumber() == 3:
78  digit.setHitQuality(Belle2.TOPDigit.c_Junk)
79 
80 
81 # Database
82 use_central_database(globalTag)
83 for tag in stagingTags:
84  use_central_database(tag)
85 for db in localDB:
86  if os.path.isfile(db):
87  use_local_database(db, invertLogging=True)
88  else:
89  B2ERROR(db + ": local database not found")
90  sys.exit()
91 
92 # Create path
93 main = create_path()
94 
95 # Input (cdst files)
96 main.add_module('RootInput', inputFileNames=files)
97 
98 # Initialize TOP geometry parameters
99 main.add_module('TOPGeometryParInitializer')
100 
101 # Time Recalibrator
102 main.add_module('TOPTimeRecalibrator', subtractBunchTime=False)
103 
104 # Channel masking
105 main.add_module('TOPChannelMasker')
106 
107 # Exclude BS13d
108 main.add_module(Mask_BS13d())
109 
110 # Bunch finder
111 main.add_module('TOPBunchFinder', usePIDLikelihoods=True, subtractRunningOffset=False)
112 
113 # Module T0 calibration
114 main.add_module('TOPModuleT0Calibrator', sample=sampleType, outputFileName=fileName)
115 
116 # Print progress
117 progress = register_module('Progress')
118 main.add_module(progress)
119 
120 # Process events
121 process(main)
122 
123 # Print statistics
124 print(statistics)
cdst_calibrateModuleT0.Mask_BS13d
Definition: cdst_calibrateModuleT0.py:70
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58
cdst_calibrateModuleT0.Mask_BS13d.event
def event(self)
Definition: cdst_calibrateModuleT0.py:73