Belle II Software development
EclShapeFitter.py
1#!/usr/bin/env python3
2
3
10
11"""Performs shape fit and compares emulator fit results with fit
12 results received from ShaperDSP module.
13"""
14
15import glob
16import basf2 as b2
17from ROOT import Belle2
18
20
21# PARAMETERS
22
23inputFile_list = []
24outputFileName = 'out.root'
25inputFile_list = sorted(glob.glob('/group/belle2/dataprod/Data/Raw/e0008/r03480/sub00/*.root'))
26
27# Override if "-i file.root" argument was sent to basf2.
28input_arg = env.getInputFilesOverride()
29if len(input_arg) > 0:
30 inputFile_list = [str(x) for x in input_arg]
31print(inputFile_list)
32
33# Override output if '-o file.root' argument was sent to basf2.
34output_arg = env.getOutputFileOverride()
35if len(output_arg) > 0:
36 outputFileName = output_arg
37
38verbose = False
39
40
41class ShapeFitterModule(b2.Module):
42
43 """Module that prints ShaperDSP emulator discrepancies
44 for ECL data.
45
46 Uses ECLDigits, ECLDsps, ECLTrigs dataobjects
47 """
48
49 def initialize(self):
50 """Initialize
51 """
52
53 self.eventNumber = 0
54
55 self.digits = 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.digits:
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(f'RealData: {cid:4} {amp:6} {time:6} {qual:6}')
91 print(f'Emulator: {cid:4} {amp2:6} {time2:6} {qual2:6}')
92 if verbose:
93 print(f'Event : {self.eventNumber} Trigger time: {trigger_time}')
94 print(f'CellID: {cid} AmpData: {amp} TimeData: {time} QualityData: {qual}')
95 print(' '.join([str(x) for x in adc]), end='')
96 print(' ')
97
98 self.eventNumber += 1
99
100
101b2.set_log_level(b2.LogLevel.ERROR)
102
103# Create path. Register necessary modules to this path.
104mainPath = b2.create_path()
105
106# Add '(Seq)RootInput' module
107if inputFile_list[0].endswith('sroot'):
108 mainPath.add_module('SeqRootInput',
109 inputFileName='',
110 inputFileNames=inputFile_list)
111else:
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]:
117mainPath.add_module('ECLUnpacker', storeTrigTime=True)
118
119# Do shape fitting of ECLDsps
120mainPath.add_module(ShapeFitterModule())
121
122b2.reset_database()
123b2.use_database_chain()
124b2.use_central_database('data_reprocessing_prompt', b2.LogLevel.WARNING)
125b2.use_central_database('online', b2.LogLevel.WARNING)
126b2.use_local_database('localdb/database.txt')
127
128# For exp9 data
129b2.conditions.override_globaltags()
130
131# Process the events and print call statistics
132mainPath.add_module('Progress')
133b2.process(mainPath, calculateStatistics=True)
134print(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.
A (simplified) python wrapper for StoreArray.
digits
Store array of ECLDigits.