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