Belle II Software  release-08-01-10
checkCalpulse.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # ---------------------------------------------------------------------------------------------------------------------------
12 # Makes histograms from TOPDigits to decide visually about calpulse selection settings.
13 # Input: pulser or laser raw data in root format (local run)
14 # Output: checkCalpulse.root
15 #
16 # usage: basf2 checkCalpulse.py -i <local_run.root> [cal_channel] [time_cut_lo] [time_cut_hi] [localDB]
17 # cal_channel (optional) calibration channel number (0 - 7), if given TOPDigits in other ASIC channels will be ignored
18 # time_cut_lo (optional) cut on hit time, if given TOPDigits with time < time_cut_lo will be ignored
19 # time_cut_hi (optional) cut on hit time, if given TOPDigits with time > time_cut_hi will be ignored
20 # localDB (optional) local database or global tag, if given the time base calibration will be used
21 # ---------------------------------------------------------------------------------------------------------------------------
22 
23 import basf2 as b2
24 from ROOT import Belle2
25 from ROOT import TFile, TH1F, TH2F
26 import sys
27 
28 look_back_windows = 30 # make sure this is the correct setting for your local run!
29 
30 cal_channel = None
31 if len(sys.argv) > 1:
32  cal_channel = int(sys.argv[1])
33 time_cut_lo = None
34 if len(sys.argv) > 2:
35  time_cut_lo = float(sys.argv[2])
36 time_cut_hi = None
37 if len(sys.argv) > 3:
38  time_cut_hi = float(sys.argv[3])
39 use_sample_times = False
40 use_asic_shifts = False
41 if len(sys.argv) > 4:
42  use_sample_times = True
43  use_asic_shifts = True
44  tag = sys.argv[4]
45  if '.txt' in tag:
46  b2.conditions.append_testing_payloads(tag)
47  else:
48  b2.conditions.expert_settings(usable_globaltag_states={'PUBLISHED', 'RUNNING', 'TESTING', 'VALIDATED', 'OPEN'})
49  b2.conditions.prepend_globaltag(tag)
50 
51 
52 class Histogrammer(b2.Module):
53  ''' Makes histograms from TOPDigits '''
54 
55  def initialize(self):
56  ''' initialize: open root file, book histograms '''
57 
58 
59  self.tfiletfile = TFile.Open('checkCalpulse.root', 'recreate')
60 
61  self.height_vs_widthheight_vs_width = TH2F("height_vs_width", "Pulse height vs. width; pulse width [ns]; pulse height [ADC counts]",
62  100, 0, 10, 200, 0, 2000)
63 
64  self.height_vs_sampleheight_vs_sample = TH2F("height_vs_sample", "Pulse height vs. sample; sample number; pulse height [ADC counts]",
65  256, 0, 256, 200, 0, 2000)
66 
67  self.width_vs_samplewidth_vs_sample = TH2F("width_vs_sample", "Pulse width vs. sample; sample number; pulse width [ns]",
68  256, 0, 256, 100, 0, 10)
69 
70  self.timetime = TH1F('time', 'Time distibution; time [ns]', 400, -100, 300)
71 
72  self.asic_channelsasic_channels = TH1F('asic_channels', 'ASIC channel occupancy; ASIC channel number', 8, 0, 8)
73 
74  def event(self):
75  ''' event processing: fill histograms '''
76 
77  for digit in Belle2.PyStoreArray('TOPDigits'):
78  if digit.getHitQuality() == 0:
79  continue
80  if cal_channel is not None and digit.getASICChannel() != cal_channel:
81  continue
82  if time_cut_lo is not None and digit.getTime() < time_cut_lo:
83  continue
84  if time_cut_hi is not None and digit.getTime() > time_cut_hi:
85  continue
86  self.height_vs_widthheight_vs_width.Fill(digit.getPulseWidth(), digit.getPulseHeight())
87  self.height_vs_sampleheight_vs_sample.Fill(digit.getModulo256Sample(), digit.getPulseHeight())
88  if digit.getPulseHeight() > 100:
89  self.width_vs_samplewidth_vs_sample.Fill(digit.getModulo256Sample(), digit.getPulseWidth())
90  self.timetime.Fill(digit.getTime())
91  self.asic_channelsasic_channels.Fill(digit.getASICChannel())
92 
93  def terminate(self):
94  ''' terminate: write histograms and close the file '''
95 
96  h = self.height_vs_widthheight_vs_width.ProjectionX('width')
97  h.SetTitle('Pulse width')
98  h = self.height_vs_widthheight_vs_width.ProjectionY('height')
99  h.SetTitle('Pulse height')
100  self.tfiletfile.Write()
101  self.tfiletfile.Close()
102 
103 
104 main = b2.create_path()
105 main.add_module('RootInput')
106 main.add_module('TOPGeometryParInitializer')
107 main.add_module('TOPUnpacker')
108 main.add_module('TOPRawDigitConverter',
109  useSampleTimeCalibration=use_sample_times,
110  useAsicShiftCalibration=use_asic_shifts,
111  useChannelT0Calibration=False,
112  useModuleT0Calibration=False,
113  useCommonT0Calibration=False,
114  minPulseWidth=0.5,
115  lookBackWindows=look_back_windows)
116 
117 main.add_module(Histogrammer())
118 main.add_module('Progress')
119 
120 # Process events
121 b2.process(main)
122 
123 # Print call statistics
124 print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
height_vs_sample
histogram of pulse height vs.
asic_channels
histogram of asic channel occupancy
width_vs_sample
histogram of pulse width vs.
height_vs_width
histogram of pulse height vs.
time
histogram of time distribution