19 from ROOT
import Belle2
20 from ROOT
import TH1F, TH2F, TF1, TFile, TGraphErrors, TSpectrum, TCanvas
25 from laserResolutionTools
import fitLaserResolution, plotLaserResolution
30 ''' Module to study resolution and performance of the top laser calibration.'''
33 h_LaserTimingVSChannel = TH2F(
34 'LaserTimingVSChannel',
35 'Laser timing in as function of the channel number',
43 h_LaserTimingVSChannelOneSlot = TH2F(
44 'LaserTimingVSChannelOneSlot',
45 'Laser timing in as function of the channel number',
54 h_crossOccupancy = [[TH2F(
55 'crossOccupancy_' + str(slotA) +
'_' + str(slotB),
62 200)
for slotA
in range(16)]
for slotB
in range(16)]
65 outname =
'outStudyLaserResolution.root'
68 m_ignoreNotCalibrated =
True
81 m_mcCorrectionsFile =
'/group/belle2/group/detector/TOP/calibration/MCreferences/t0MC.root'
86 ''' Sets the output file name '''
91 ''' Sets the maximum calpulse width '''
96 ''' Sets the minimum calpulse width '''
101 ''' Sets the maximum calpulse amplitude '''
106 ''' Sets the minimum calpulse amplitude '''
111 ''' Sets the file containing the MC correction'''
116 ''' Sets the flag to ingore the hits without calibration '''
121 ''' Event processor: fill histograms '''
124 nhits = [0
for i
in range(16)]
128 if (digit.getHitQuality() == 1
and
130 digit.getPulseHeight() > self.
m_minAmp and digit.getPulseHeight() < self.
m_maxAmp):
131 slotID = digit.getModuleID()
132 hwchan = digit.getChannel()
134 simhits = digit.getRelationsWith(
'TOPSimHits')
135 nhits[slotID - 1] = nhits[slotID - 1] + 1
136 for simhit
in simhits:
138 for slotA
in range(16):
139 for slotB
in range(16):
143 ''' Write histograms to file, fills and fits the resolution plots'''
144 tfile = TFile(self.
outname,
'recreate')
147 for slotA
in range(16):
148 for slotB
in range(16):
154 print(
'usage: basf2', argvs[0],
'runNumber outfileName')
161 runnumbers = sys.argv[6:]
164 for runnumber
in runnumbers:
165 if datatype ==
'root':
166 files += [f
for f
in glob.glob(str(folder) +
'/*' + str(runnumber) +
'*.root')]
169 files += [f
for f
in glob.glob(str(folder) +
'/*' + str(runnumber) +
'*.sroot')]
171 print(
"file: " + fname)
173 if dbaddress !=
'none':
174 print(
"using local DB " + dbaddress)
176 use_local_database(dbaddress +
"/localDB.txt", dbaddress)
178 print(
"database not set. Continuing without calibrations")
181 set_log_level(LogLevel.ERROR)
184 use_central_database(
'data_reprocessing_proc8')
190 if datatype ==
'root':
191 roinput = register_module(
'RootInput')
192 roinput.param(
'inputFileNames', files)
193 main.add_module(roinput)
195 roinput = register_module(
'SeqRootInput')
196 roinput.param(
'inputFileNames', files)
197 main.add_module(roinput)
200 if datatype ==
'pocket':
201 print(
'pocket DAQ data assumed')
202 converter = register_module(
'Convert2RawDet')
203 main.add_module(converter)
206 main.add_module(
'TOPGeometryParInitializer')
208 if datatype !=
'root':
210 unpack = register_module(
'TOPUnpacker')
211 main.add_module(unpack)
214 featureExtractor = register_module(
'TOPWaveformFeatureExtractor')
215 main.add_module(featureExtractor)
218 converter = register_module(
'TOPRawDigitConverter')
219 if dbaddress ==
'none':
220 print(
"Not using Calibrations")
221 converter.param(
'useSampleTimeCalibration',
False)
222 converter.param(
'useAsicShiftCalibration',
False)
223 converter.param(
'useChannelT0Calibration',
False)
224 converter.param(
'useModuleT0Calibration',
False)
226 print(
"Using Calibrations")
227 converter.param(
'useSampleTimeCalibration',
True)
228 converter.param(
'useAsicShiftCalibration',
True)
229 converter.param(
'useChannelT0Calibration',
True)
230 converter.param(
'useModuleT0Calibration',
True)
231 converter.param(
'useCommonT0Calibration',
False)
232 converter.param(
'calibrationChannel', -1)
233 converter.param(
'lookBackWindows', int(lookBack))
234 main.add_module(converter)
238 resolutionModule.setOutputName(outfile)
239 resolutionModule.setMinWidth(0.1)
240 resolutionModule.setMaxWidth(999)
241 resolutionModule.setMinAmp(100)
242 resolutionModule.setMaxAmp(999)
243 if dbaddress ==
'none':
244 resolutionModule.ignoreNotCalibrated(
True)
246 resolutionModule.ignoreNotCalibrated(
False)
247 main.add_module(resolutionModule)
250 progress = register_module(
'Progress')
251 main.add_module(progress)
258 print(statistics(statistics.TERM))
261 fitLaserResolution(dataFile=outfile, outputFile=
'laserResolutionResults.root', pdfType=
'cb', saveFits=
True)
262 plotLaserResolution()