Belle II Software  release-08-01-10
EclShapeFitter.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """Performs shape fit and compares emulator fit results with fit
13  results received from ShaperDSP module.
14 """
15 
16 import glob
17 import basf2 as b2
18 from ROOT import Belle2
19 
21 
22 # PARAMETERS
23 
24 inputFile_list = []
25 outputFileName = 'out.root'
26 inputFile_list = sorted(glob.glob('/group/belle2/dataprod/Data/Raw/e0008/r03480/sub00/*.root'))
27 
28 # Override if "-i file.root" argument was sent to basf2.
29 input_arg = env.getInputFilesOverride()
30 if len(input_arg) > 0:
31  inputFile_list = [str(x) for x in input_arg]
32 print(inputFile_list)
33 
34 # Override output if '-o file.root' argument was sent to basf2.
35 output_arg = env.getOutputFileOverride()
36 if len(output_arg) > 0:
37  outputFileName = output_arg
38 
39 verbose = False
40 
41 
42 class ShapeFitterModule(b2.Module):
43 
44  """Module that prints ShaperDSP emulator discrepancies
45  for ECL data.
46 
47  Uses ECLDigits, ECLDsps, ECLTrigs dataobjects
48  """
49 
50  def initialize(self):
51  """Initialize
52  """
53 
54  self.eventNumbereventNumber = 0
55 
56  self.digitsdigits = Belle2.PyStoreArray('ECLDigits')
57 
58  def event(self):
59  """Check for discrepancy between real ShaperDSP
60  data and shapeFitter function from
61  ecl/utility/src/ECLDspUtilities.cc .
62  """
63 
64  for digit in self.digitsdigits:
65  waveform = digit.getRelated('ECLDsps')
66  if not waveform:
67  continue
68 
69  trig = digit.getRelated('ECLTrigs')
70  if not trig:
71  continue
72 
73  trigger_time = int(trig.getTimeTrig())
74 
75  # Waveform data
76  adc = waveform.getDspA()
77  cid = digit.getCellId()
78  amp = digit.getAmp()
79  time = digit.getTimeFit()
80  qual = digit.getQuality()
81 
82  # == Call emulator
83  result = Belle2.ECL.ECLDspUtilities.shapeFitter(cid, adc, trigger_time)
84 
85  amp2 = result.amp
86  time2 = result.time
87  qual2 = result.quality
88 
89  if amp != amp2 or time != time2 or qual != qual2:
90  print()
91  print('RealData: %4d %6d %6d %6d' % (cid, amp, time, qual))
92  print('Emulator: %4d %6d %6d %6d' % (cid, amp2, time2, qual2))
93  if verbose:
94  print('Event : %d Trigger time: %d' % (self.evtn, trigger_time))
95  print('CellID: %d AmpData: %d TimeData: %d QualityData: %d' % (cid, amp, time, qual))
96  print(' '.join([str(x) for x in adc]), end='')
97  print(' ')
98 
99  self.eventNumbereventNumber += 1
100 
101 
102 b2.set_log_level(b2.LogLevel.ERROR)
103 
104 # Create path. Register necessary modules to this path.
105 mainPath = b2.create_path()
106 
107 # Add '(Seq)RootInput' module
108 if inputFile_list[0].endswith('sroot'):
109  mainPath.add_module('SeqRootInput',
110  inputFileName='',
111  inputFileNames=inputFile_list)
112 else:
113  mainPath.add_module('RootInput',
114  inputFileName='',
115  inputFileNames=inputFile_list)
116 
117 # if inputFile_list[0].endswith('sroot') or 'Raw' in inputFile_list[0]:
118 mainPath.add_module('ECLUnpacker', storeTrigTime=True)
119 
120 # Do shape fitting of ECLDsps
121 mainPath.add_module(ShapeFitterModule())
122 
123 b2.reset_database()
124 b2.use_database_chain()
125 b2.use_central_database('data_reprocessing_prompt', b2.LogLevel.WARNING)
126 b2.use_central_database('online', b2.LogLevel.WARNING)
127 b2.use_local_database('localdb/database.txt')
128 
129 # For exp9 data
130 b2.conditions.override_globaltags()
131 
132 # Process the events and print call statistics
133 mainPath.add_module('Progress')
134 b2.process(mainPath)
135 print(b2.statistics)
static ECLShapeFit shapeFitter(int cid, std::vector< int > adc, int ttrig, bool adjusted_timing=true)
Emulate shape fitting algorithm from ShaperDSP using algorithm from ecl/utility/src/ECLDspEmulator....
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
digits
Store array of ECLDigits.