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