7 from ROOT
import Belle2
8 from ROOT
import TH1F, TH2F, TF1, TFile, TGraphErrors
24 ''' Module to study resolution and performances of the TOP Time Base Calibration.'''
27 h_WidthVSAmplitude_1 = TH2F(
29 'Width VS amplidute of the TOPDigits, first calibration pulse',
30 2000, 0., 2000, 100, 0., 10.)
32 h_WidthVSAmplitude_2 = TH2F(
34 'Width VS amplidute of the TOPDigits, second calibration pulse',
35 2000, 0., 2000, 100, 0., 10.)
38 h_dVdtRising_1 = TH1F(
'dVdtRising_1',
' dV/dt of the TOPRawDigits (rising edge), first calibration pulse', 1000, 0, 1000)
40 h_dVdtRising_2 = TH1F(
'dVdtRising_2',
' dV/dt of the TOPRawDigits (rising edge), second calibration pulse', 1000, 0, 1000)
42 h_dVdtFalling_1 = TH1F(
'dVdtFalling_1',
' dV/dt of the TOPRawDigits (falling edge), first calibration pulse', 1000, 0, 1000)
44 h_dVdtFalling_2 = TH1F(
'dVdtFalling_2',
' dV/dt of the TOPRawDigits (falling edge), second calibration pulse', 1000, 0, 1000)
46 h_dVdtRisingVSdVdtFalling_1 = TH2F(
47 'dVdtRisingVSdVdtFalling_1',
48 ' dV/dt of the TOPRawDigit: rising edge VS falling edge, first calibration pulse ',
49 1000, 0, 1000, 1000, 0., 1000.)
51 h_dVdtRisingVSdVdtFalling_2 = TH2F(
52 'dVdtRisingVSdVdtFalling_2',
53 ' dV/dt of the TOPRawDigit: rising edge VS falling edge, second calibration pulse ',
54 1000, 0, 1000, 1000, 0., 1000.)
56 h_dVdtRisingDifference = TH1F(
57 'dVdtRisingDifference',
' difference between the rising edge dV/dt of the first and the second pulse', 1000, -500, 500)
59 h_dVdtFallingDifference = TH1F(
60 'dVdtFallingDifference',
' difference between the falling edge dV/dt of the first and the second pulse', 1000, -500, 500)
63 h_DeltaT_RR = TH1F(
'DeltaT_RR',
' DeltaT bewteen the rising edges', 4000, 10, 30)
65 h_DeltaT_FF = TH1F(
'DeltaT_FF',
' DeltaT bewteen the falling edges', 4000, 10, 30)
67 h_DeltaT_FR = TH1F(
'DeltaT_FR',
' DeltaT bewteen falling and rising edges', 4000, 10, 30)
69 h_DeltaT_RF = TH1F(
'DeltaT_RF',
' DeltaT bewteen rising and falling edges', 4000, 10, 30)
72 h_DeltaTVSChannel_RR = TH2F(
74 ' DeltaT bewteen the rising edges, as function of the channel number',
75 512 * 16, 0, 512 * 16, 4000, 10., 30.)
77 h_DeltaTVSChannel_FF = TH2F(
79 ' DeltaT bewteen the falling edges, as function of the channel number',
80 512 * 16, 0, 512 * 16, 4000, 10., 30.)
82 h_DeltaTVSChannel_FR = TH2F(
84 ' DeltaT bewteen falling (pulse 1) and rising (pulse 2) edge, as function of the channel number',
85 512 * 16, 0, 512 * 16, 4000, 10., 30.)
87 h_DeltaTVSChannel_RF = TH2F(
89 ' DeltaT bewteen rising (pulse 1) and falling (pulse 2) edge, as function of the channel number',
90 512 * 16, 0, 512 * 16, 4000, 10., 30.)
92 h_DeltaTVSdVdt_RR = TH2F(
94 'DeltaT bewteen the rising edges VS average of dV/dt on the first and second pulser',
95 1000, 0., 1000., 4000, 10., 30.)
97 h_DeltaTVSdVdt_FF = TH2F(
99 'DeltaT bewteen the rising edges VS average of dV/dt on the first and second pulser',
100 1000, 0., 1000., 4000, 10., 30.)
103 h_ResolutionVSdVdt_FF = TGraphErrors()
105 h_ResolutionVSdVdt_RR = TGraphErrors()
108 outname =
'outStudyTBCResolution.root'
110 m_calpulseMaxWidth = 3.
112 m_calpulseMinWidth = 0.5
114 m_calpulseMaxAmp = 700.
116 m_calpulseMinAmp = 250.
118 m_ignoreNotCalibrated =
True
121 ''' Sets the output file name '''
126 ''' Sets the maximum calpulse width '''
131 ''' Sets the minimum calpulse width '''
136 ''' Sets the maximum calpulse amplitude '''
141 ''' Sets the minimum calpulse amplitude '''
146 ''' Sets the flag to ingore the hits without calibration '''
151 ''' Event processor: fill histograms '''
155 for ipulse1, digit1
in enumerate(digits):
158 if (digit1.getHitQuality() != 0
and
164 slotID = digit1.getModuleID()
165 hwchan = digit1.getChannel()
166 for ipulse2, digit2
in enumerate(digits, start=ipulse1 + 1):
170 if (digit2.getHitQuality() != 0
and
175 slotID == digit2.getModuleID()
and
176 hwchan == digit2.getChannel()):
179 rawDigitFirst = digit1.getRelated(
'TOPRawDigits')
180 rawDigitSecond = digit2.getRelated(
'TOPRawDigits')
181 if digit1.getTime() > digit2.getTime():
182 rawDigitFirst = digit2.getRelated(
'TOPRawDigits')
183 rawDigitSecond = digit1.getRelated(
'TOPRawDigits')
184 digitFirst = rawDigitFirst.getRelated(
'TOPDigits')
185 digitSecond = rawDigitSecond.getRelated(
'TOPDigits')
187 globalCh = hwchan + 512 * (slotID - 1)
188 dV1_R = rawDigitFirst.getLeadingSlope()
189 dV1_F = -rawDigitFirst.getFallingSlope()
190 dV2_R = rawDigitSecond.getLeadingSlope()
191 dV2_F = -rawDigitSecond.getFallingSlope()
192 t1_R = digitFirst.getTime()
193 t1_F = digitFirst.getTime() + digitFirst.getPulseWidth()
194 t2_R = digitSecond.getTime()
195 t2_F = digitSecond.getTime() + digitSecond.getPulseWidth()
196 amp1 = digitFirst.getPulseHeight()
197 amp2 = digitSecond.getPulseHeight()
198 w1 = digitFirst.getPulseWidth()
199 w2 = digitSecond.getPulseWidth()
223 ''' Write histograms to file, fills and fits the resolution plots'''
230 for ibin
in range(0, 10):
231 projection = self.
h_DeltaTVSdVdt_RR.ProjectionY(
"tmpProj", ibin * 100 + 1, (ibin + 1) * 100)
232 gaussFit = TF1(
"gaussFit",
"[0]*exp(-0.5*((x-[1])/[2])**2)", 10., 30.)
233 gaussFit.SetParameter(0, 1.)
234 gaussFit.SetParameter(1, projection.GetMean())
235 gaussFit.SetParameter(2, projection.GetRMS())
236 gaussFit.SetParLimits(2, 0., 3. * projection.GetRMS())
238 projection.Fit(
"gaussFit")
242 tfile = TFile(self.
outname,
'recreate')
250 self.
h_dVdtRising_1.GetXaxis().SetTitle(
"dV/dt [ADC counts / sample]")
252 self.
h_dVdtRising_2.GetXaxis().SetTitle(
"dV/dt [ADC counts / sample]")
254 self.
h_dVdtFalling_1.GetXaxis().SetTitle(
"dV/dt [ADC counts / sample]")
256 self.
h_dVdtFalling_2.GetXaxis().SetTitle(
"dV/dt [ADC counts / sample]")
273 self.
h_DeltaT_RR.GetXaxis().SetTitle(
"#Delta t [ns]")
275 self.
h_DeltaT_FF.GetXaxis().SetTitle(
"#Delta t [ns]")
277 self.
h_DeltaT_FR.GetXaxis().SetTitle(
"#Delta t [ns]")
279 self.
h_DeltaT_RF.GetXaxis().SetTitle(
"#Delta t [ns]")
282 self.
h_DeltaTVSChannel_RR.GetXaxis().SetTitle(
"Global channel number [hwChannel + 512*(slotID-1)]")
285 self.
h_DeltaTVSChannel_FF.GetXaxis().SetTitle(
"Global channel number [hwChannel + 512*(slotID-1)]")
288 self.
h_DeltaTVSChannel_FR.GetXaxis().SetTitle(
"Global channel number [hwChannel + 512*(slotID-1)]")
291 self.
h_DeltaTVSChannel_RF.GetXaxis().SetTitle(
"Global channel number [hwChannel + 512*(slotID-1)]")
295 self.
h_DeltaTVSdVdt_RR.GetXaxis().SetTitle(
"Average of dV/dt on first and second pulse [ACD counts / sample]")
299 self.
h_DeltaTVSdVdt_FF.GetXaxis().SetTitle(
"Average of dV/dt on first and second pulse [ACD counts / sample]")
309 print(
'usage: basf2', argvs[0],
'runNumber outfileName')
315 runnumbers = sys.argv[5:]
318 for runnumber
in runnumbers:
319 files += [f
for f
in glob.glob(str(folder) +
'/*' + str(runnumber) +
'*.sroot')]
322 print(
"file: " + fname)
324 if dbaddress !=
'none':
325 print(
"using local DB " + dbaddress)
327 use_local_database(dbaddress +
"/localDB.txt", dbaddress)
329 print(
"database not set. Continuing without calibrations")
332 set_log_level(LogLevel.ERROR)
335 use_central_database(
'data_reprocessing_proc8')
341 roinput = register_module(
'SeqRootInput')
342 roinput.param(
'inputFileNames', files)
343 main.add_module(roinput)
346 if datatype ==
'pocket':
347 print(
'pocket DAQ data assumed')
348 converter = register_module(
'Convert2RawDet')
349 main.add_module(converter)
352 main.add_module(
'TOPGeometryParInitializer')
355 unpack = register_module(
'TOPUnpacker')
356 main.add_module(unpack)
359 featureExtractor = register_module(
'TOPWaveformFeatureExtractor')
360 main.add_module(featureExtractor)
363 converter = register_module(
'TOPRawDigitConverter')
364 if dbaddress ==
'none':
365 print(
"Not using TBC")
366 converter.param(
'useSampleTimeCalibration',
False)
369 converter.param(
'useSampleTimeCalibration',
True)
370 converter.param(
'useAsicShiftCalibration',
False)
371 converter.param(
'useChannelT0Calibration',
False)
372 converter.param(
'useModuleT0Calibration',
False)
373 converter.param(
'useCommonT0Calibration',
False)
374 converter.param(
'calibrationChannel', -1)
375 converter.param(
'lookBackWindows', 28)
376 main.add_module(converter)
380 resolutionModule.setOutputName(outfile)
381 resolutionModule.setMinWidth(0.5)
382 resolutionModule.setMaxWidth(3.5)
383 resolutionModule.setMinAmp(150)
384 resolutionModule.setMaxAmp(999)
385 if dbaddress ==
'none':
386 resolutionModule.ignoreNotCalibrated(
False)
388 resolutionModule.ignoreNotCalibrated(
True)
389 main.add_module(resolutionModule)
392 progress = register_module(
'Progress')
393 main.add_module(progress)
400 print(statistics(statistics.TERM))