11from ROOT
import Belle2
13from svd
import add_svd_simulation
42 """Set aside all SimHits on a selected sensor/side to create
43 signal/background collisions."""
46 '''initialize python module'''
56 for h
in storesimhits:
62 '''Inject stored SVDSimHits'''
65 '''initialize python module'''
73 self.
simhits.registerInDataStore()
80 simhit = self.
simhits.appendNew()
84if __name__ ==
"__main__":
88 basf2.B2INFO(
'Creating background data...')
90 create_bgfile = basf2.create_path()
91 create_bgfile.add_module(
'EventInfoSetter', expList=[0], runList=[0], evtNumList=[100])
92 create_bgfile.add_module(
'Gearbox')
93 create_bgfile.add_module(
'Geometry', components=[
'MagneticField',
'SVD'])
94 create_bgfile.add_module(
'ParticleGun')
95 create_bgfile.add_module(
'FullSim')
96 create_bgfile.add_module(
'BeamBkgTagSetter', backgroundType=
"twoPhoton", realTime=310.0)
97 create_bgfile.add_module(
'RootOutput', outputFileName=
'bgForMixing.root', branchNames=[
'BackgroundMetaData',
'SVDSimHits'])
101 basf2.B2INFO(
'Creating overlay data...')
103 create_ovrfile = basf2.create_path()
104 create_ovrfile.add_module(
'EventInfoSetter', expList=[0], runList=[0], evtNumList=[1])
105 create_ovrfile.add_module(
'Gearbox')
106 create_ovrfile.add_module(
'Geometry', components=[
'MagneticField',
'SVD'])
107 create_ovrfile.add_module(
'BeamBkgMixer', backgroundFiles=[
'bgForMixing.root'], minTime=-150, maxTime=150)
109 add_svd_simulation(create_ovrfile)
112 create_ovrfile.add_module(
'RootOutput', outputFileName=
'bgForOverlay.root', branchNames=[
'SVDShaperDigits'])
116 basf2.B2INFO(
'Background mixing...')
118 produce_mixed = basf2.create_path()
119 produce_mixed.add_module(
'EventInfoSetter', expList=[0], runList=[0], evtNumList=[1])
120 produce_mixed.add_module(
'Gearbox')
121 produce_mixed.add_module(
'Geometry', components=[
'MagneticField',
'SVD'])
125 produce_mixed.add_module(
'BeamBkgMixer', backgroundFiles=[
'bgForMixing.root'], minTime=-150, maxTime=150)
127 add_svd_simulation(produce_mixed)
129 produce_mixed.add_module(
'SVDShaperDigitSorter')
130 produce_mixed.add_module(
'RootOutput', outputFileName=
'mixedBg.root')
134 basf2.B2INFO(
'Background overlay...')
136 produce_overlaid = basf2.create_path()
137 produce_overlaid.add_module(
'EventInfoSetter', expList=[0], runList=[0], evtNumList=[1])
138 produce_overlaid.add_module(
'Gearbox')
139 produce_overlaid.add_module(
'Geometry', components=[
'MagneticField',
'SVD'])
140 produce_overlaid.add_module(
'BGOverlayInput', inputFileNames=[
'bgForOverlay.root'])
143 add_svd_simulation(produce_overlaid)
145 produce_overlaid.add_module(
'BGOverlayExecutor')
147 produce_overlaid.add_module(
'SVDShaperDigitSorter')
148 produce_overlaid.add_module(
'RootOutput', outputFileName=
'overlaidBg.root')
152 basf2.B2INFO(
'Comparing...')
154 with ROOT.TFile(
'mixedBg.root')
as f_mixed:
155 tree_mixed = f_mixed.Get(
'tree')
157 with ROOT.TFile(
'overlaidBg.root')
as f_over:
158 tree_over = f_over.Get(
'tree')
160 class_name =
"Belle2::SVDShaperDigit"
162 digits_mixed = ROOT.TClonesArray(class_name)
163 digits_over = ROOT.TClonesArray(class_name)
165 tree_mixed.SetBranchAddress(
"SVDShaperDigits", digits_mixed)
166 tree_over.SetBranchAddress(
"SVDShaperDigits", digits_over)
170 for i
in range(tree_mixed.GetEntries()):
171 tree_mixed.GetEntry(i)
172 tree_over.GetEntry(i)
174 n_mixed = digits_mixed.GetEntriesFast()
175 n_over = digits_over.GetEntriesFast()
177 if n_mixed != n_over:
178 basf2.B2FATAL(
'Lengths of SVDShaperDigit arrays differ')
181 for d1, d2
in zip(digits_mixed, digits_over):
183 d1.getSensorID() == d2.getSensorID()
and
184 d1.isUStrip() == d2.isUStrip()
and
185 d1.getCellID() == d2.getCellID()
188 samples1 = d1.getSamples()
189 samples2 = d2.getSamples()
191 if len(samples1) != len(samples2):
194 for s1, s2
in zip(samples1, samples2):
195 if int(s1) != int(s2):
202 basf2.B2FATAL(
'Digits do not match.')
206 basf2.B2INFO(f
'Processed {n_good} matching digits.')
A (simplified) python wrapper for StoreArray.
Class to uniquely identify a any structure of the PXD and SVD.
simhits
simHits store array
selected_sensorID
selected sensor info
clean_working_directory()
safe_process(*args, **kwargs)