23 from ROOT
import Belle2
24 from ROOT
import TH1F, TH2F, TF1, TFile, TGraphErrors
29 ''' Module to study resolution and performances of the TOP Time Base Calibration.'''
32 h_WidthVSAmplitude_1 = TH2F(
34 'Width VS amplidute of the TOPDigits, first calibration pulse',
35 2000, 0., 2000, 100, 0., 10.)
37 h_WidthVSAmplitude_2 = TH2F(
39 'Width VS amplidute of the TOPDigits, second calibration pulse',
40 2000, 0., 2000, 100, 0., 10.)
43 h_dVdtRising_1 = TH1F(
'dVdtRising_1',
' dV/dt of the TOPRawDigits (rising edge), first calibration pulse', 1000, 0, 1000)
45 h_dVdtRising_2 = TH1F(
'dVdtRising_2',
' dV/dt of the TOPRawDigits (rising edge), second calibration pulse', 1000, 0, 1000)
47 h_dVdtFalling_1 = TH1F(
'dVdtFalling_1',
' dV/dt of the TOPRawDigits (falling edge), first calibration pulse', 1000, 0, 1000)
49 h_dVdtFalling_2 = TH1F(
'dVdtFalling_2',
' dV/dt of the TOPRawDigits (falling edge), second calibration pulse', 1000, 0, 1000)
51 h_dVdtRisingVSdVdtFalling_1 = TH2F(
52 'dVdtRisingVSdVdtFalling_1',
53 ' dV/dt of the TOPRawDigit: rising edge VS falling edge, first calibration pulse ',
54 1000, 0, 1000, 1000, 0., 1000.)
56 h_dVdtRisingVSdVdtFalling_2 = TH2F(
57 'dVdtRisingVSdVdtFalling_2',
58 ' dV/dt of the TOPRawDigit: rising edge VS falling edge, second calibration pulse ',
59 1000, 0, 1000, 1000, 0., 1000.)
61 h_dVdtRisingDifference = TH1F(
62 'dVdtRisingDifference',
' difference between the rising edge dV/dt of the first and the second pulse', 1000, -500, 500)
64 h_dVdtFallingDifference = TH1F(
65 'dVdtFallingDifference',
' difference between the falling edge dV/dt of the first and the second pulse', 1000, -500, 500)
68 h_DeltaT_RR = TH1F(
'DeltaT_RR',
' DeltaT bewteen the rising edges', 4000, 10, 30)
70 h_DeltaT_FF = TH1F(
'DeltaT_FF',
' DeltaT bewteen the falling edges', 4000, 10, 30)
72 h_DeltaT_FR = TH1F(
'DeltaT_FR',
' DeltaT bewteen falling and rising edges', 4000, 10, 30)
74 h_DeltaT_RF = TH1F(
'DeltaT_RF',
' DeltaT bewteen rising and falling edges', 4000, 10, 30)
77 h_DeltaTVSChannel_RR = TH2F(
79 ' DeltaT bewteen the rising edges, as function of the channel number',
80 512 * 16, 0, 512 * 16, 4000, 10., 30.)
82 h_DeltaTVSChannel_FF = TH2F(
84 ' DeltaT bewteen the falling edges, as function of the channel number',
85 512 * 16, 0, 512 * 16, 4000, 10., 30.)
87 h_DeltaTVSChannel_FR = TH2F(
89 ' DeltaT bewteen falling (pulse 1) and rising (pulse 2) edge, as function of the channel number',
90 512 * 16, 0, 512 * 16, 4000, 10., 30.)
92 h_DeltaTVSChannel_RF = TH2F(
94 ' DeltaT bewteen rising (pulse 1) and falling (pulse 2) edge, as function of the channel number',
95 512 * 16, 0, 512 * 16, 4000, 10., 30.)
97 h_DeltaTVSdVdt_RR = 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.)
102 h_DeltaTVSdVdt_FF = TH2F(
104 'DeltaT bewteen the rising edges VS average of dV/dt on the first and second pulser',
105 1000, 0., 1000., 4000, 10., 30.)
108 h_ResolutionVSdVdt_FF = TGraphErrors()
110 h_ResolutionVSdVdt_RR = TGraphErrors()
113 outname =
'outStudyTBCResolution.root'
115 m_calpulseMaxWidth = 3.
117 m_calpulseMinWidth = 0.5
119 m_calpulseMaxAmp = 700.
121 m_calpulseMinAmp = 250.
123 m_ignoreNotCalibrated =
True
126 ''' Sets the output file name '''
131 ''' Sets the maximum calpulse width '''
136 ''' Sets the minimum calpulse width '''
141 ''' Sets the maximum calpulse amplitude '''
146 ''' Sets the minimum calpulse amplitude '''
151 ''' Sets the flag to ingore the hits without calibration '''
156 ''' Event processor: fill histograms '''
160 for ipulse1, digit1
in enumerate(digits):
163 if (digit1.getHitQuality() != 0
and
169 slotID = digit1.getModuleID()
170 hwchan = digit1.getChannel()
171 for ipulse2, digit2
in enumerate(digits, start=ipulse1 + 1):
175 if (digit2.getHitQuality() != 0
and
180 slotID == digit2.getModuleID()
and
181 hwchan == digit2.getChannel()):
184 rawDigitFirst = digit1.getRelated(
'TOPRawDigits')
185 rawDigitSecond = digit2.getRelated(
'TOPRawDigits')
186 if digit1.getTime() > digit2.getTime():
187 rawDigitFirst = digit2.getRelated(
'TOPRawDigits')
188 rawDigitSecond = digit1.getRelated(
'TOPRawDigits')
189 digitFirst = rawDigitFirst.getRelated(
'TOPDigits')
190 digitSecond = rawDigitSecond.getRelated(
'TOPDigits')
192 globalCh = hwchan + 512 * (slotID - 1)
193 dV1_R = rawDigitFirst.getLeadingSlope()
194 dV1_F = -rawDigitFirst.getFallingSlope()
195 dV2_R = rawDigitSecond.getLeadingSlope()
196 dV2_F = -rawDigitSecond.getFallingSlope()
197 t1_R = digitFirst.getTime()
198 t1_F = digitFirst.getTime() + digitFirst.getPulseWidth()
199 t2_R = digitSecond.getTime()
200 t2_F = digitSecond.getTime() + digitSecond.getPulseWidth()
201 amp1 = digitFirst.getPulseHeight()
202 amp2 = digitSecond.getPulseHeight()
203 w1 = digitFirst.getPulseWidth()
204 w2 = digitSecond.getPulseWidth()
228 ''' Write histograms to file, fills and fits the resolution plots'''
235 for ibin
in range(0, 10):
236 projection = self.
h_DeltaTVSdVdt_RRh_DeltaTVSdVdt_RR.ProjectionY(
"tmpProj", ibin * 100 + 1, (ibin + 1) * 100)
237 gaussFit = TF1(
"gaussFit",
"[0]*exp(-0.5*((x-[1])/[2])**2)", 10., 30.)
238 gaussFit.SetParameter(0, 1.)
239 gaussFit.SetParameter(1, projection.GetMean())
240 gaussFit.SetParameter(2, projection.GetRMS())
241 gaussFit.SetParLimits(2, 0., 3. * projection.GetRMS())
243 projection.Fit(
"gaussFit")
244 self.
h_ResolutionVSdVdt_RRh_ResolutionVSdVdt_RR.SetPoint(ibin, ibin * 100. + 50., gaussFit.GetParameter(2))
248 self.
h_WidthVSAmplitude_1h_WidthVSAmplitude_1.GetXaxis().SetTitle(
"TOPDigit amplitude [ADC counts]")
251 self.
h_WidthVSAmplitude_2h_WidthVSAmplitude_2.GetXaxis().SetTitle(
"TOPDigit amplitude [ADC counts]")
255 self.
h_dVdtRising_1h_dVdtRising_1.GetXaxis().SetTitle(
"dV/dt [ADC counts / sample]")
257 self.
h_dVdtRising_2h_dVdtRising_2.GetXaxis().SetTitle(
"dV/dt [ADC counts / sample]")
259 self.
h_dVdtFalling_1h_dVdtFalling_1.GetXaxis().SetTitle(
"dV/dt [ADC counts / sample]")
261 self.
h_dVdtFalling_2h_dVdtFalling_2.GetXaxis().SetTitle(
"dV/dt [ADC counts / sample]")
272 self.
h_dVdtFallingDifferenceh_dVdtFallingDifference.GetXaxis().SetTitle(
"dV/dt_1 - dV/dt_2 [ADC counts / sample]")
275 self.
h_dVdtRisingDifferenceh_dVdtRisingDifference.GetXaxis().SetTitle(
"dV/dt_1 - dV/dt_2 [ADC counts / sample]")
278 self.
h_DeltaT_RRh_DeltaT_RR.GetXaxis().SetTitle(
"#Delta t [ns]")
280 self.
h_DeltaT_FFh_DeltaT_FF.GetXaxis().SetTitle(
"#Delta t [ns]")
282 self.
h_DeltaT_FRh_DeltaT_FR.GetXaxis().SetTitle(
"#Delta t [ns]")
284 self.
h_DeltaT_RFh_DeltaT_RF.GetXaxis().SetTitle(
"#Delta t [ns]")
287 self.
h_DeltaTVSChannel_RRh_DeltaTVSChannel_RR.GetXaxis().SetTitle(
"Global channel number [hwChannel + 512*(slotID-1)]")
290 self.
h_DeltaTVSChannel_FFh_DeltaTVSChannel_FF.GetXaxis().SetTitle(
"Global channel number [hwChannel + 512*(slotID-1)]")
293 self.
h_DeltaTVSChannel_FRh_DeltaTVSChannel_FR.GetXaxis().SetTitle(
"Global channel number [hwChannel + 512*(slotID-1)]")
296 self.
h_DeltaTVSChannel_RFh_DeltaTVSChannel_RF.GetXaxis().SetTitle(
"Global channel number [hwChannel + 512*(slotID-1)]")
300 self.
h_DeltaTVSdVdt_RRh_DeltaTVSdVdt_RR.GetXaxis().SetTitle(
"Average of dV/dt on first and second pulse [ACD counts / sample]")
304 self.
h_DeltaTVSdVdt_FFh_DeltaTVSdVdt_FF.GetXaxis().SetTitle(
"Average of dV/dt on first and second pulse [ACD counts / sample]")
314 print(
'usage: basf2', argvs[0],
'runNumber outfileName')
320 runnumbers = sys.argv[5:]
323 for runnumber
in runnumbers:
324 files += [f
for f
in glob.glob(str(folder) +
'/*' + str(runnumber) +
'*.sroot')]
327 print(
"file: " + fname)
329 if dbaddress !=
'none':
330 print(
"using local DB " + dbaddress)
332 b2.use_local_database(dbaddress +
"/localDB.txt", dbaddress)
334 print(
"database not set. Continuing without calibrations")
337 b2.set_log_level(b2.LogLevel.ERROR)
340 b2.use_central_database(
'data_reprocessing_proc8')
343 main = b2.create_path()
346 roinput = b2.register_module(
'SeqRootInput')
347 roinput.param(
'inputFileNames', files)
348 main.add_module(roinput)
351 if datatype ==
'pocket':
352 print(
'pocket DAQ data assumed')
353 converter = b2.register_module(
'Convert2RawDet')
354 main.add_module(converter)
357 main.add_module(
'TOPGeometryParInitializer')
360 unpack = b2.register_module(
'TOPUnpacker')
361 main.add_module(unpack)
364 featureExtractor = b2.register_module(
'TOPWaveformFeatureExtractor')
365 main.add_module(featureExtractor)
368 converter = b2.register_module(
'TOPRawDigitConverter')
369 if dbaddress ==
'none':
370 print(
"Not using TBC")
371 converter.param(
'useSampleTimeCalibration',
False)
374 converter.param(
'useSampleTimeCalibration',
True)
375 converter.param(
'useAsicShiftCalibration',
False)
376 converter.param(
'useChannelT0Calibration',
False)
377 converter.param(
'useModuleT0Calibration',
False)
378 converter.param(
'useCommonT0Calibration',
False)
379 converter.param(
'calibrationChannel', -1)
380 converter.param(
'lookBackWindows', 28)
381 main.add_module(converter)
385 resolutionModule.setOutputName(outfile)
386 resolutionModule.setMinWidth(0.5)
387 resolutionModule.setMaxWidth(3.5)
388 resolutionModule.setMinAmp(150)
389 resolutionModule.setMaxAmp(999)
390 if dbaddress ==
'none':
391 resolutionModule.ignoreNotCalibrated(
False)
393 resolutionModule.ignoreNotCalibrated(
True)
394 main.add_module(resolutionModule)
397 progress = b2.register_module(
'Progress')
398 main.add_module(progress)
405 print(b2.statistics(b2.statistics.TERM))
a (simplified) python wrapper for StoreArray.
h_DeltaT_RR
DeltaT rising-rising.
bool m_ignoreNotCalibrated
ignores the hits wthout calibration
h_DeltaTVSChannel_RF
DeltaT rising-falling VS channel.
int m_calpulseMinAmp
minimum amplitude to flag a calpulse candidate
h_WidthVSAmplitude_1
Width VS amplitude, first calibration pulse.
def setMinWidth(self, minWidth)
def ignoreNotCalibrated(self, ignoreNotCal)
h_DeltaTVSdVdt_RR
DeltaT rising-rising VS average of dV/dt on the first and second pulse.
h_DeltaT_FF
DeltaT falling-falling.
def setOutputName(self, outputname)
h_DeltaT_RF
DeltaT rising-falling.
m_calpulseMinWidth
output name
h_ResolutionVSdVdt_RR
DeltaT resolution VS average of dV/dt (rising-rising)
h_dVdtFallingDifference
Difference between the dV/dt of the first and the second calpulse, using the rising edges.
h_dVdtFalling_1
dV/dt on the falling edge, first calibration pulse
h_dVdtFalling_2
dV/dt on the falling edge, second calibration pulse
h_dVdtRisingVSdVdtFalling_2
dV/dt on the rising edge VS dV/dt on the falling edge, first calibration pulse
h_DeltaTVSChannel_RR
DeltaT rising-rising VS channel.
def setMinAmp(self, minAmp)
m_calpulseMaxWidth
output name
h_dVdtRising_2
dV/dt on the rising edge, second calibration pulse
def setMaxWidth(self, maxWidth)
m_calpulseMaxAmp
output name
int m_calpulseMaxAmp
minimum amplitude to flag a calpulse candidate
h_dVdtRisingDifference
Difference between the dV/dt of the first and the second calpulse, using the rising edges.
h_DeltaT_FR
DeltaT falling-rising.
string outname
output root file
h_DeltaTVSdVdt_FF
DeltaT falling-falling VS average of dV/dt on the first and second pulse.
h_dVdtRising_1
dV/dt on the rising edge, first calibration pulse
m_ignoreNotCalibrated
output name
h_ResolutionVSdVdt_FF
DeltaT resolution VS average of dV/dt (falling-falling)
float m_calpulseMinWidth
minimum width to flag a calpulse candidate
h_DeltaTVSChannel_FF
DeltaT falling-falling VS channel.
h_dVdtRisingVSdVdtFalling_1
dV/dt on the rising edge VS dV/dt on the falling edge, first calibration pulse
int m_calpulseMaxWidth
maximum width to flag a calpulse candidate
m_calpulseMinAmp
output name
h_DeltaTVSChannel_FR
DeltaT falling-rising VS channel.
def setMaxAmp(self, maxAmp)
h_WidthVSAmplitude_2
Width VS amplitude, second calibration pulse.