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