56 from optparse
import OptionParser
59 parser = OptionParser()
60 parser.add_option(
'-i',
'--inputfile',
61 dest=
'infilename', default=
'',
62 help=
'Input [S]ROOT filename [no default]')
63 parser.add_option(
'-e',
'--experiment',
64 dest=
'eNumber', default=
'',
65 help=
'Experiment number [no default]')
66 parser.add_option(
'-r',
'--run',
67 dest=
'rNumber', default=
'',
68 help=
'Run number [no default]')
69 parser.add_option(
'-n',
'--nEvents',
70 dest=
'nEvents', default=
'',
71 help=
'Max # of analyzed events [no default]')
72 parser.add_option(
'-s',
'--singleEntry', type=
"int",
73 dest=
'singleEntry', default=0,
74 help=
'Select events with any (0) or exactly one (1) or more than one (2) entries/channel [0]')
75 parser.add_option(
'--verbosity', type=
"int",
76 dest=
'verbosity', default=0,
77 help=
'How many histograms to save (0=minimal, 1=all) [0]')
78 parser.add_option(
'-d',
'--displays', type=
"int",
79 dest=
'displays', default=0,
80 help=
'Max # of displayed events [0]')
81 parser.add_option(
'-v',
'--view', type=
"int",
82 dest=
'view', default=2,
83 help=
'View event displays using one-dimensional (1) or two-dimensional (2) hits [2]')
84 parser.add_option(
'-m',
'--minRPCHits', type=
"int",
85 dest=
'minRPCHits', default=4,
86 help=
'Min # of RPC hits in any one sector to display the event [4]')
87 parser.add_option(
'-l',
'--legacyTimes', type=
"int",
88 dest=
'legacyTimes', default=0,
89 help=
'Perform legacy time calculations (1) or not (0) for BKLMHit1ds,2ds [0]')
90 parser.add_option(
'-t',
'--tagName',
91 dest=
'tagName', default=
'data_reprocessing_prompt',
92 help=
'Conditions-database global-tag name [data_reprocessing_prompt]')
93 (options, args) = parser.parse_args()
95 singleEntry = options.singleEntry
96 if singleEntry < 0
or singleEntry > 2:
100 if options.nEvents !=
'':
101 maxCount = int(options.nEvents)
103 print(
"Maximum number of events to analyze is", maxCount,
" - nothing to do.")
106 verbosity = options.verbosity
110 maxDisplays = options.displays
112 minRPCHits = options.minRPCHits
114 legacyTimes = options.legacyTimes
116 tagName = options.tagName
121 if options.infilename !=
'':
122 inputName = re.sub(
r"HLT.\.f0....",
"HLT*.f*", options.infilename)
123 fileList = glob.glob(inputName)
124 if len(fileList) == 0:
125 print(
"No file(s) match {0}".format(inputName))
127 if options.eNumber !=
'':
128 if not options.eNumber.isdecimal():
129 print(
"Experiment number ({0}) is not valid".format(options.eNumber))
131 exp =
'{0:04d}'.format(int(options.eNumber))
133 eStart = inputName.find(
'/e') + 2
135 print(
"Input filename does not contain the required experiment number")
137 eEnd = inputName.find(
'/', eStart)
138 exp = inputName[eStart:eEnd]
139 if not exp.isdecimal():
140 print(
"Input filename's experiment number ({0}) is not valid".format(exp))
142 if options.rNumber !=
'':
143 if not options.rNumber.isdecimal():
144 print(
"Run number ({0}) is not valid".format(options.rNumber))
146 run =
'{0:05d}'.format(int(options.rNumber))
148 rStart = inputName.find(
'/r') + 2
150 print(
"Input filename does not contain the required run number")
152 rEnd = inputName.find(
'/', rStart)
153 run = inputName[rStart:rEnd]
154 if not run.isdecimal():
155 print(
"Input filename's run number ({0}) is not valid".format(run))
157 if len(inputName) == 0:
158 inputName =
'/ghi/fs01/belle2/bdata/Data/Raw/e{0}/r{1}/sub00/*.{0}.{1}.HLT*.f*.root'.format(exp, run)
159 fileList = glob.glob(inputName)
160 if len(fileList) == 0:
161 print(
"No file(s) found for experiment <{0}> run <{1}>".format(options.eNumber, options.rNumber))
164 suffix =
'' if singleEntry == 0
else '-singleEntry' if singleEntry == 1
else '-multipleEntries'
165 histName =
'bklmHists-e{0}r{1}{2}.root'.format(exp, run, suffix)
166 pdfName =
'bklmPlots-e{0}r{1}{2}.pdf'.format(exp, run, suffix)
167 eventPdfName =
'bklmEvents{3}D-e{0}r{1}{2}.pdf'.format(exp, run, suffix, view)
170 print(
'bklm-dst: exp=' + exp +
' run=' + run +
' input=' + inputName +
'. Analyze', maxCount,
'events using ' + tagName)
172 print(
'bklm-dst: exp=' + exp +
' run=' + run +
' input=' + inputName +
'. Analyze all events using ' + tagName)
174 basf2.conditions.prepend_globaltag(tagName)
176 main = basf2.create_path()
177 if inputName.find(
".sroot") >= 0:
178 main.add_module(
'SeqRootInput', inputFileNames=inputName)
180 main.add_module(
'RootInput', inputFileName=inputName)
181 main.add_module(
'ProgressBar')
183 eventInspector =
EventInspector(exp, run, histName, pdfName, eventPdfName, verbosity,
184 maxDisplays, minRPCHits, legacyTimes, singleEntry, view)
186 main.add_module(
'KLMReconstructor')
187 main.add_module(eventInspector)
189 basf2.process(main, max_event=maxCount)
190 print(basf2.statistics)
def add_unpackers(path, components=None, writeKLMDigitRaws=False, addTOPRelations=False)