Belle II Software development
bklm-eventdisplay.py
1#!/usr/bin/env python3
2
3
10
11# Purpose:
12# Analyze a DST file and write a PDF of "interesting" event displays that includes
13# BKLMHit2ds, ExtHits, and MuidHits.
14# This script cannot analyze MDST files because they don't contain RawKLMs, BKLMHit2ds, nor MuidHits.
15#
16# Prerequisites (on kekcc):
17# Before running this script, type
18# source /cvmfs/belle.cern.ch/tools/b2setup release-02-01-00 <or higher release>
19# then verify that the corresponding proper global tag is used near the end of this script.
20# (Global tags are tabulated at https://xwiki.desy.de/xwiki/rest/p/88ebe)
21# The external python script bklmDB.py must be in the same folder as this script.
22#
23# Usage:
24# basf2 bklm-eventdisplay.py -- -e # -r # -i infilename -n # -d # -m # -u # -t tagname
25# You need the '--' before these options to tell basf2 that these are options to this script.
26# Required arguments:
27# either -i infilename or -e # -r # (can supply all three)
28# -i infilename to specify the full pathname of the input ROOT DST file (no default)
29# -e # to specify the experiment number, e.g., -e 1 (no default)
30# -r # to specify the run number, e.g., -r 4794 (no default)
31# Optional arguments:
32# -n # to specify the maximum number of events to analyze (no default -> all events)
33# -d # to specify the maximum number of displayed events to write to the PDF file (default = 100)
34# -m # to specify the minimum number of RPC hits in one sector (default = 4)
35# -u # to specify the minimum number of Muid hits in the event (default = 1)
36# -t tagname to specify the name of conditions database global tag (no default)
37#
38# Input:
39# ROOT DST file written by basf2 (may include multiple folios for one expt/run). For example,
40# /ghi/fs01/belle2/bdata/Data/Raw/e0003/r04794/sub00/physics.0003.r04794.HLT2.f*.root
41# /ghi/fs01/belle2/bdata/Data/Raw/e0004/r06380/sub00/cosmic.0004.r06380.HLT2.f00000.root
42#
43# Output:
44# PDF file named bklmEvents-e#r#.pdf, using the experiment number and run number
45#
46
47import basf2
48import EventDisplayer
49import sys
50from tracking import add_tracking_reconstruction
51import rawdata
52from optparse import OptionParser
53import glob
54
55parser = OptionParser()
56parser.add_option('-i', '--inputfile',
57 dest='infilename', default='',
58 help='Input ROOT filename [no default]')
59parser.add_option('-e', '--experiment',
60 dest='eNumber', default='',
61 help='Experiment number [no default]')
62parser.add_option('-r', '--run',
63 dest='rNumber', default='',
64 help='Run number [no default]')
65parser.add_option('-n', '--nEvents',
66 dest='nEvents', default='',
67 help='Max # of analyzed events [no default]')
68parser.add_option('-d', '--displays',
69 dest='displays', default='100',
70 help='Max # of displayed events [default=100]')
71parser.add_option('-m', '--minRPCHits',
72 dest='minRPCHits', default='4',
73 help='Minimum # of RPC hits in one sector [default=4]')
74parser.add_option('-u', '--muids',
75 dest='minMuidHits', default='1',
76 help='Minimum # of Muid hits in the event [default=1]')
77parser.add_option('-t', '--tag',
78 dest='tagName', default='data_reprocessing_prompt',
79 help='Conditions-database global-tag name [data_reprocessing_prompt]')
80(options, args) = parser.parse_args()
81
82maxCount = -1
83if options.nEvents != '':
84 maxCount = int(options.nEvents)
85 if maxCount <= 0:
86 print("Maximum number of events to analyze is", maxCount, " - nothing to do.")
87 sys.exit()
88
89maxDisplays = int(options.displays)
90
91minRPCHits = int(options.minRPCHits)
92
93minMuidHits = int(options.minMuidHits)
94
95tagName = options.tagName
96
97inputName = ''
98exp = ''
99run = ''
100if options.infilename != '':
101 inputName = options.infilename
102 fileList = glob.glob(inputName)
103 if len(fileList) == 0:
104 print(f'No file(s) match {inputName}')
105 sys.exit()
106if options.eNumber != '':
107 if not options.eNumber.isdecimal():
108 print(f'Experiment number ({options.eNumber}) is not valid')
109 sys.exit()
110 exp = f'{int(options.eNumber):04d}'
111else:
112 eStart = inputName.find('/e') + 2
113 if eStart < 0:
114 print('Input filename does not contain the required experiment number')
115 sys.exit()
116 eEnd = inputName.find('/', eStart)
117 exp = inputName[eStart:eEnd]
118 if not exp.isdecimal():
119 print(f'Input filename experiment number({exp}) is not valid')
120 sys.exit()
121if options.rNumber != '':
122 if not options.rNumber.isdecimal():
123 print(f'Run number ({options.rNumber}) is not valid')
124 sys.exit()
125 run = f'{int(options.rNumber):05d}'
126else:
127 rStart = inputName.find('/r') + 2
128 if rStart < 0:
129 print('Input filename does not contain the required run number')
130 sys.exit()
131 rEnd = inputName.find('/', rStart)
132 run = inputName[rStart:rEnd]
133 if not run.isdecimal():
134 print(f'Input filename run number({run}) is not valid')
135 sys.exit()
136if len(inputName) == 0:
137 fileList = glob.glob(f'/ghi/fs01/belle2/bdata/Data/Raw/e{exp}/r{run}/sub00/*.{exp}.{run}.HLT2.f00000.root')
138 if len(fileList) == 0:
139 print(f'No file(s) found for experiment <{options.eNumber}> run <{options.rNumber}>')
140 sys.exit()
141 inputName = fileList[0].replace('f00000', 'f*')
142
143eventPdfName = f'bklmEvents-e{exp}r{run}.pdf'
144
145if maxCount >= 0:
146 print('bklm-display: exp=' + exp + ' run=' + run + ' input=' + inputName + '. Analyze', maxCount, 'events using ' + tagName)
147 print(' Write at most', maxDisplays, 'event displays, requiring # RPC hits per sector >=', minRPCHits,
148 ' # Muids in event >=', minMuidHits)
149else:
150 print('bklm-display: exp=' + exp + ' run=' + run + ' input=' + inputName + '. Analyze all events using ' + tagName)
151 print(' Write at most', maxDisplays, 'event displays, requiring # RPC hits per sector >=', minRPCHits,
152 ' # Muids in event >=', minMuidHits)
153
154basf2.conditions.prepend_globaltag(tagName)
155
156main = basf2.create_path()
157main.add_module('RootInput', inputFileName=inputName)
158main.add_module('ProgressBar')
159
160eventDisplayer = EventDisplayer(exp, run, eventPdfName, maxDisplays, minRPCHits, minMuidHits)
162main.add_module('KLMReconstructor')
163add_tracking_reconstruction(main)
164ext = main.add_module('Ext')
165ext.param('pdgCodes', [13])
166muid = main.add_module('Muid')
167# muid.param('MaxDistSigma', 10.0)
168main.add_module(eventDisplayer)
169
170basf2.process(main, max_event=maxCount)
171print(basf2.statistics)
def add_unpackers(path, components=None, writeKLMDigitRaws=False, addTOPRelations=False)
Definition: rawdata.py:67