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