Belle II Software  release-06-02-00
subtractCalPulse.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # Subtract cal pulse time in TOPDigits::m_time
14 #
15 # Usage: basf2 subtractCalPulse.py [channel] -i <input_file.root> -o <output_file.root>
16 # channel calibration channel (0-7, default=0)
17 # input_file root file prepared with unpackToTOPDigits.py (calibrationChannel must be set)
18 # outpu_file root output file (default = RootOutput.root)
19 #
20 # cal pulse time is subtracted only if exactly two cal pulses are found for given asic
21 # if this requirement is not satisfied the hits for given asic are marked as c_Junk
22 # (see python module)
23 # ---------------------------------------------------------------------------------------
24 
25 import basf2 as b2
26 from ROOT import Belle2
27 import sys
28 
29 calChannel = 0
30 argvs = sys.argv
31 if len(argvs) > 1:
32  calChannel = int(argvs[1])
33 
34 b2.B2RESULT('using calibration channel ' + str(calChannel))
35 
36 
37 class SubtractCalSignal(b2.Module):
38  ''' subtract time of the first calibration signal '''
39 
40  def event(self):
41  ''' event function '''
42 
43  digits = Belle2.PyStoreArray('TOPDigits')
44  t0 = [0 for i in range(64)]
45  num = [0 for i in range(64)]
46  for digit in digits:
47  channel = digit.getChannel()
48  i = int(channel / 8)
49  ch = int(channel) % 8
50  if ch == calChannel and digit.getHitQuality() == 4:
51  if num[i] == 0:
52  t0[i] = digit.getTime()
53  num[i] += 1
54  else:
55  t0[i] = min(t0[i], digit.getTime())
56  num[i] += 1
57  sum = 0
58  for digit in digits:
59  i = int(digit.getChannel()/8)
60  if num[i] == 2:
61  digit.subtractT0(t0[i])
62  sum += 1
63  else:
64  digit.setHitQuality(0)
65  if sum == 0:
66  b2.B2ERROR("No calibration double pulses found in the event")
67 
68 
69 # Create path
70 main = b2.create_path()
71 
72 # input
73 roinput = b2.register_module('RootInput')
74 main.add_module(roinput)
75 
76 # Subtract time of the first calibration signal pulse
77 main.add_module(SubtractCalSignal())
78 
79 # output
80 output = b2.register_module('RootOutput')
81 main.add_module(output)
82 
83 # Print progress
84 progress = b2.register_module('Progress')
85 main.add_module(progress)
86 
87 # Process events
88 b2.process(main)
89 
90 # Print statistics
91 print(b2.statistics)
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:56