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