Belle II Software  release-06-02-00
checkHitHeightAndWidth.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 import sys
14 import glob
15 from ROOT import Belle2
16 from ROOT import TH2F, TFile
17 
18 #
19 # ------------------------------------------------------------------------
20 # Simple module to study the width and amplitude of all the topdigits
21 #
22 # usage: basf2 checkHitHeightAndWidth.py run_number output_name.root
23 # the run number accepts wildcards
24 # ------------------------------------------------------------------------
25 
26 
27 class Histogrammer(b2.Module):
28 
29  ''' A module to histogram width and amplitude of calibration pulses'''
30 
31 
32  hist = [TH2F('WidthVSAmplitude_Slot_' + str(k + 1), 'With VS amplidute of the Digits in slot ' + str(k + 1),
33  2000, 0., 2000, 80, 0., 20) for k in range(16)]
34 
35 
36  histSampling = [[TH2F('WidthVSample_Slot_' + str(k + 1) + '_Channel_' + str(j),
37  'With VS amplidute of the Digits in slot ' + str(k + 1) + ' channel ' + str(j),
38  256,
39  0.,
40  256,
41  100,
42  0.,
43  20) for k in range(16)] for j in range(512)]
44 
45  outname = 'calpulseCheck.root'
46 
47  def setOutputName(self, outputname):
48  ''' Sets the output file name '''
49 
50 
51  self.outnameoutnameoutname = outputname
52 
53  def event(self):
54  ''' Event processor: fill histograms '''
55 
56  digits = Belle2.PyStoreArray('TOPDigits')
57  for digit in digits:
58  # quality = digit.getHitQuality()
59  slotID = digit.getModuleID()
60  hwchan = digit.getChannel()
61  self.histhist[slotID - 1].Fill(digit.getPulseHeight(), digit.getPulseWidth())
62  self.histSamplinghistSampling[hwchan][slotID - 1].Fill(digit.getModulo256Sample(), digit.getPulseWidth())
63 
64  def terminate(self):
65  ''' Write histograms to file '''
66 
67  tfile = TFile(self.outnameoutnameoutname, 'recreate')
68  for k in range(16):
69  self.histhist[k].GetXaxis().SetTitle("TOPDigit amplitude [ADC counts]")
70  self.histhist[k].GetYaxis().SetTitle("TOPDigit width [ns]")
71  self.histhist[k].Write()
72  for k in range(16):
73  for j in range(512):
74  self.histSamplinghistSampling[j][k].GetXaxis().SetTitle("TOPDigit sample%256")
75  self.histSamplinghistSampling[j][k].GetYaxis().SetTitle("TOPDigit width [ns]")
76  self.histSamplinghistSampling[j][k].Write()
77 
78  tfile.Close()
79 
80 
81 argvs = sys.argv
82 
83 print('usage: basf2', argvs[0], 'runNumber outfileName')
84 
85 runnumber = argvs[1] # run number. Wildcards should work
86 outfile = argvs[2] # output name
87 
88 
89 files = glob.glob('/ghi/fs01/belle2/bdata/Data/sRaw/e0001/r0' + str(runnumber) + '/sub00/*.sroot')
90 
91 # Suppress messages and warnings during processing
92 b2.set_log_level(b2.LogLevel.ERROR)
93 
94 # Define a global tag (note: the one given bellow will become out-dated!)
95 b2.use_central_database('data_reprocessing_proc8')
96 
97 # Create path
98 main = b2.create_path()
99 
100 # input
101 roinput = b2.register_module('SeqRootInput')
102 roinput.param('inputFileNames', files)
103 main.add_module(roinput)
104 
105 #
106 # conversion from RawCOPPER or RawDataBlock to RawDetector objects
107 # Pocket DAQ data not supported yet
108 #
109 # if datatype == 'pocket':
110 # print('pocket DAQ data assumed')
111 # converter = register_module('Convert2RawDet')
112 # main.add_module(converter)
113 
114 # Initialize TOP geometry parameters (creation of Geant geometry is not needed)
115 main.add_module('TOPGeometryParInitializer')
116 
117 # Unpacking (format auto detection works now)
118 unpack = b2.register_module('TOPUnpacker')
119 main.add_module(unpack)
120 
121 # Add multiple hits by running feature extraction offline
122 featureExtractor = b2.register_module('TOPWaveformFeatureExtractor')
123 main.add_module(featureExtractor)
124 
125 # Convert to TOPDigits
126 converter = b2.register_module('TOPRawDigitConverter')
127 converter.param('useSampleTimeCalibration', False)
128 converter.param('useChannelT0Calibration', False)
129 converter.param('useModuleT0Calibration', False)
130 converter.param('useCommonT0Calibration', False)
131 # converter.param('calibrationChannel', channel) # if set, cal pulses will be flagged
132 converter.param('calpulseHeightMin', 450) # in [ADC counts]
133 converter.param('calpulseHeightMax', 900) # in [ADC counts]
134 converter.param('calpulseWidthMin', 2.0) # in [ns]
135 converter.param('calpulseWidthMax', 8.0) # in [ns]
136 converter.param('lookBackWindows', 29) # in number of windows
137 main.add_module(converter)
138 
139 # Histogrammer
140 histogramModule = Histogrammer()
141 histogramModule.setOutputName(outfile)
142 main.add_module(histogramModule)
143 
144 # Show progress of processing
145 progress = b2.register_module('Progress')
146 main.add_module(progress)
147 
148 # Process events
149 b2.process(main)
150 
151 # Print call statistics
152 print(b2.statistics)
153 print(b2.statistics(b2.statistics.TERM))
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:56
list histSampling
Width as function of the sample number in each channel.
list hist
Width VS amplitude plot in each slot.