Belle II Software  release-06-02-00
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  self.eventNumbereventNumber = 0
54  # Store array of ECLDigits
55  self.digitsdigits = Belle2.PyStoreArray('ECLDigits')
56 
57  def event(self):
58  """Check for discrepancy between real ShaperDSP
59  data and shapeFitter function from
60  ecl/utility/src/ECLDspUtilities.cc .
61  """
62 
63  for digit in self.digitsdigits:
64  waveform = digit.getRelated('ECLDsps')
65  if not waveform:
66  continue
67 
68  trig = digit.getRelated('ECLTrigs')
69  if not trig:
70  continue
71 
72  trigger_time = int(trig.getTimeTrig())
73 
74  # Waveform data
75  adc = waveform.getDspA()
76  cid = digit.getCellId()
77  amp = digit.getAmp()
78  time = digit.getTimeFit()
79  qual = digit.getQuality()
80 
81  # == Call emulator
82  result = Belle2.ECL.ECLDspUtilities.shapeFitter(cid, adc, trigger_time)
83 
84  amp2 = result.amp
85  time2 = result.time
86  qual2 = result.quality
87 
88  if amp != amp2 or time != time2 or qual != qual2:
89  print()
90  print('RealData: %4d %6d %6d %6d' % (cid, amp, time, qual))
91  print('Emulator: %4d %6d %6d %6d' % (cid, amp2, time2, qual2))
92  if verbose:
93  print('Event : %d Trigger time: %d' % (self.evtn, trigger_time))
94  print('CellID: %d AmpData: %d TimeData: %d QualityData: %d' % (cid, amp, time, qual))
95  print(' '.join([str(x) for x in adc]), end='')
96  print(' ')
97 
98  self.eventNumbereventNumber += 1
99 
100 
101 b2.set_log_level(b2.LogLevel.ERROR)
102 
103 # Create path. Register necessary modules to this path.
104 mainPath = b2.create_path()
105 
106 # Add '(Seq)RootInput' module
107 if inputFile_list[0].endswith('sroot'):
108  mainPath.add_module('SeqRootInput',
109  inputFileName='',
110  inputFileNames=inputFile_list)
111 else:
112  mainPath.add_module('RootInput',
113  inputFileName='',
114  inputFileNames=inputFile_list)
115 
116 # if inputFile_list[0].endswith('sroot') or 'Raw' in inputFile_list[0]:
117 mainPath.add_module('ECLUnpacker', storeTrigTime=True)
118 
119 # Do shape fitting of ECLDsps
120 mainPath.add_module(ShapeFitterModule())
121 
122 b2.reset_database()
123 b2.use_database_chain()
124 b2.use_central_database('data_reprocessing_prompt', b2.LogLevel.WARNING)
125 b2.use_central_database('online', b2.LogLevel.WARNING)
126 b2.use_local_database('localdb/database.txt')
127 
128 # For exp9 data
129 b2.conditions.override_globaltags()
130 
131 # Process the events and print call statistics
132 mainPath.add_module('Progress')
133 b2.process(mainPath)
134 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:29
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:56