Belle II Software development
z0_with_clone_suppression.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from ROOT import Belle2
13from math import pi, tan
14
15"""
16generate tracks with particle gun, simulate CDC and CDC trigger, save the output.
17"""
18
19# ------------ #
20# user options #
21# ------------ #
22
23# general options
24seed = 10000
25evtnum = 600
26particlegun_params = {
27 'pdgCodes': [-13, 13],
28 'nTracks': 1,
29 'momentumGeneration': 'inversePt',
30 'momentumParams': [0.3, 10.],
31 'thetaGeneration': 'uniform',
32 'thetaParams': [35, 145],
33 'phiGeneration': 'uniform',
34 'phiParams': [0, 360],
35 'vertexGeneration': 'uniform',
36 'xVertexParams': [0, 0.0],
37 'yVertexParams': [0, 0.0],
38 'zVertexParams': [-50.0, 50.0]}
39
40# ------------------------- #
41# create path up to trigger #
42# ------------------------- #
43
44# set random seed
45b2.set_random_seed(seed)
46# suppress messages and warnings during processing:
47# b2.set_log_level(b2.LogLevel.ERROR)
48
49main = b2.create_path()
50
51empty_path = b2.create_path()
52
53main.add_module('EventInfoSetter', evtNumList=evtnum)
54main.add_module('Progress')
55main.add_module('Gearbox')
56main.add_module('Geometry', components=['BeamPipe',
57 'PXD', 'SVD', 'CDC',
58 'MagneticFieldConstant4LimitedRCDC'])
59particlegun = b2.register_module('ParticleGun')
60particlegun.param(particlegun_params)
61main.add_module(particlegun)
62
63# z position of the two ends of the first layer used by trigger
64z_SL0 = [-31 - 1.5 / tan(30 / 180. * pi), 57 + 1.5 / tan(17 / 180. * pi)]
65# radius of the first layer used by trigger
66r_SL0 = 18.3
67
68
69class Skim(b2.Module):
70 """Reject tracks with bad combination of z0 and theta"""
71
72 def initialize(self):
73 """Initialization of Skim"""
74
75 self.mc = Belle2.PyStoreArray('MCParticles')
76
77 def event(self):
78 """event function of Skim"""
79 self.return_value(0)
80
81 z0 = self.mc[0].getVertex().Z()
82
83 vec = self.mc[0].getMomentum()
84 # skip the event if the track didn't reach SL0
85 if z_SL0[0] < z0 + r_SL0 / vec.Pt() * vec.Z() < z_SL0[1]:
86 self.return_value(1)
87
88
89skim = Skim()
90main.add_module(skim)
91skim.if_false(empty_path)
92
93main.add_module('FullSim')
94main.add_module('CDCDigitizer')
95
96# ---------------------- #
97# CDC trigger and output #
98# ---------------------- #
99
100SimulationMode = 1
101minHits = 4
102trueEventTime = False
103# TSF
104main.add_module('CDCTriggerTSF',
105 InnerTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_Bkg_p0.70_b0.80.coe"),
106 OuterTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_Bkg_p0.70_b0.80.coe"))
107# 2D finder
108original2d = b2.register_module('CDCTrigger2DFinder')
109# original2d.logging.log_level = b2.LogLevel.DEBUG
110# original2d.logging.debug_level = 20
111# original2d.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
112original2d.param('testFilename', 'tracks.txt')
113
114fast2d = b2.register_module('CDCTrigger2DFinder')
115# fast2d.logging.log_level = b2.LogLevel.DEBUG
116# fast2d.logging.debug_level = 20
117# fast2d.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
118fast2d.param('testFilename', 'fasttracks.txt')
119fast2d.param('suppressClone', True)
120fast2d.param('outputCollectionName', "TRGCDC2DFinderFastTracks")
121main.add_module(original2d)
122main.add_module(fast2d)
123
124
125# ETF
126main.add_module('CDCTriggerETF', trueEventTime=trueEventTime)
127# fitters
128main.add_module('CDCTrigger2DFitter')
129main.add_module('CDCTrigger2DFitter',
130 inputCollectionName="TRGCDC2DFinderFastTracks",
131 outputCollectionName="TRGCDC2DFitterFastTracks")
132main.add_module('CDCTrigger3DFitter')
133main.add_module('CDCTrigger3DFitter',
134 inputCollectionName="TRGCDC2DFitterFastTracks",
135 outputCollectionName="TRGCDC3DFitterFastTracks")
136# neurotrigger
137main.add_module('CDCTriggerNeuro',
138 filename=Belle2.FileSystem.findFile("data/trg/cdc/Neuro20170405_LUTBkg.root"))
139main.add_module('CDCTriggerNeuro',
140 filename=Belle2.FileSystem.findFile("data/trg/cdc/Neuro20170405_LUTBkg.root"),
141 inputCollectionName="TRGCDC2DFinderFastTracks",
142 outputCollectionName="TRGCDCNeuroFastTracks")
143
144
145class Ana(b2.Module):
146 """analyze the difference between 2D with and without clone suppression"""
147
148 def initialize(self):
149 """Initilization of Ana"""
150
151 self.event_info = Belle2.PyStoreObj('EventMetaData')
152
153 self.mc = Belle2.PyStoreArray('MCParticles')
154
155 self.finder_trk2d = Belle2.PyStoreArray('TRGCDC2DFinderTracks')
156
157 self.fast_finder_trk2d = Belle2.PyStoreArray('TRGCDC2DFinderFastTracks')
158
159 self.trk2d = Belle2.PyStoreArray('TRGCDC2DFitterTracks')
160
161 self.fast_trk2d = Belle2.PyStoreArray('TRGCDC2DFitterFastTracks')
162
163 self.trk3d = Belle2.PyStoreArray('TRGCDC3DFitterTracks')
164
165 self.fast_trk3d = Belle2.PyStoreArray('TRGCDC3DFitterFastTracks')
166
167 self.trknt = Belle2.PyStoreArray('TRGCDCNeuroTracks')
168
169 self.fast_trknt = Belle2.PyStoreArray('TRGCDCNeuroFastTracks')
170
171
172 self.n2d_finder = 0
173
175
176 self.n2d_fitter = 0
177
179
180 self.n3d_fitter = 0
181
183
184 self.n3d_neuro = 0
185
187
188 def event(self):
189 """event function of Ana"""
190 self.n2d_finder += any(self.finder_trk2d)
191 self.n2d_fitter += any(self.trk2d)
192 self.n3d_fitter += any(self.trk3d)
193 self.n3d_neuro += any(self.trknt)
194 self.n2d_fast_finder += any(self.fast_finder_trk2d)
195 self.n2d_fast_fitter += any(self.fast_trk2d)
196 self.n3d_fast_fitter += any(self.fast_trk3d)
197 self.n3d_fast_neuro += any(self.fast_trknt)
198
199 if len(self.trk2d) == 0 or len(self.fast_trk2d) == 0:
200 return
201 ts_hits = self.trk2d[0].getRelationsTo('CDCTriggerSegmentHits')
202 b2.B2DEBUG(10, f'TS size: {ts_hits.size()}')
203 fast_ts_hits = self.fast_trk2d[0].getRelationsTo('CDCTriggerSegmentHits')
204 b2.B2DEBUG(10, f'fast TS size: {fast_ts_hits.size()}')
205
206 def terminate(self):
207 """Terminate Ana"""
208 total = self.n2d_finder
209 fast_total = self.n2d_fast_finder
210 all_numbers = ','.join(['{}'] * 8)
211
212 b2.B2INFO(all_numbers.format(self.n2d_finder, self.n2d_fitter, self.n3d_fitter, self.n3d_neuro,
214
215 b2.B2INFO(f'2D fitter retention rate: {self.n2d_fitter / total:.2%} ' +
216 f'(original)/ {self.n2d_fast_fitter / fast_total:.2%} (fast)')
217 b2.B2INFO(f'3D fitter retention rate: {self.n3d_fitter / self.n2d_fitter:.2%} ' +
218 f'(original)/ {self.n3d_fast_fitter / self.n2d_fast_fitter:.2%} (fast)')
219 b2.B2INFO(f'3D neuro retention rate: {self.n3d_neuro / total:.2%} ' +
220 f'(original)/ {self.n3d_fast_neuro / fast_total:.2%} (fast)')
221
222
223main.add_module(Ana())
224main.add_module('RootOutput', outputFileName='cdctrigger.root')
225
226# input('paused')
227# Process events
228b2.process(main)
229
230# Print call statistics
231print(b2.statistics)
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:151
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
n3d_neuro
number of TRGCDCNeuroTracks
n2d_finder
number of TRGCDC2DFinderTracks
n3d_fitter
number of TRGCDC3DFitterTracks
n3d_fast_neuro
number of TRGCDCNeuroFastTracks
fast_finder_trk2d
TRGCDC2DFinderFastTracks.
n3d_fast_fitter
number of TRGCDC3DFitterFastTracks
n2d_fast_finder
number of TRGCDC2DFinderFastTracks
n2d_fast_fitter
number of TRGCDC2DFitterFastTracks
n2d_fitter
number of TRGCDC2DFitterTracks