Belle II Software  release-08-01-10
trgcdcReadout.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2
13 import numpy as np
14 import os
15 import glob
16 from ROOT import gROOT, Belle2
17 
18 from cdctrigger import add_cdc_trigger
19 
20 gROOT.ProcessLine("gErrorIgnoreLevel = 4000;") # ignore endless root errors for background files...
21 
22 """
23 Example script for the CDC trigger.
24 The path contains a particle gun with single tracks,
25 simulation up to the CDC, CDC digitizer and trigger.
26 Last is a short python test module to demonstrate the readout of the trigger tracks.
27 """
28 
29 # ------------ #
30 # user options #
31 # ------------ #
32 
33 # general options
34 seed = 10000
35 evtnum = 100
36 usebkg = False
37 simplext = False # switch for CDCDigitizer simple / realistic x-t
38 particlegun_params = {
39  'pdgCodes': [-13, 13],
40  'nTracks': 1,
41  'momentumGeneration': 'inversePt',
42  'momentumParams': [0.3, 10.],
43  'thetaGeneration': 'uniform',
44  'thetaParams': [35, 123],
45  'phiGeneration': 'uniform',
46  'phiParams': [0, 360],
47  'vertexGeneration': 'uniform',
48  'xVertexParams': [0, 0.0],
49  'yVertexParams': [0, 0.0],
50  'zVertexParams': [-50.0, 50.0]}
51 bkgdir = '/sw/belle2/bkg/'
52 
53 # ------------------------- #
54 # create path up to trigger #
55 # ------------------------- #
56 
57 # set random seed
58 basf2.set_random_seed(seed)
59 # suppress messages and warnings during processing:
60 basf2.set_log_level(basf2.LogLevel.ERROR)
61 
62 main = basf2.create_path()
63 
64 main.add_module('EventInfoSetter', evtNumList=evtnum)
65 main.add_module('Progress')
66 main.add_module('Gearbox')
67 main.add_module('Geometry', components=['BeamPipe',
68  'PXD', 'SVD', 'CDC',
69  'MagneticFieldConstant4LimitedRCDC'])
70 particlegun = basf2.register_module('ParticleGun')
71 particlegun.param(particlegun_params)
72 main.add_module(particlegun)
73 main.add_module('FullSim')
74 if usebkg:
75  bkgmixer = basf2.register_module('BeamBkgMixer')
76  bkgfiles = glob.glob(os.path.join(bkgdir, '*[!(PXD)(ECL)]??.root'))
77  bkgmixer.param('backgroundFiles', bkgfiles)
78  bkgmixer.param('components', ['CDC'])
79  main.add_module(bkgmixer)
80 cdcdigitizer = basf2.register_module('CDCDigitizer')
81 cdcdigitizer_params = {
82  'UseSimpleDigitization': simplext,
83  'DoSmearing': not simplext}
84 cdcdigitizer.param(cdcdigitizer_params)
85 main.add_module(cdcdigitizer)
86 
87 # ----------- #
88 # CDC trigger #
89 # ----------- #
90 
91 add_cdc_trigger(main)
92 
93 
94 # ----------- #
95 # test module #
96 # ----------- #
97 
98 class TestModule(basf2.Module):
99  """
100  short test module to demonstrate the readout of the CDC trigger
101  """
102 
103  def event(self):
104  """
105  print output values of the different stages in the CDC trigger
106  """
107  print("CDC trigger readout")
108  print("event time:", Belle2.PyStoreObj("CDCTriggerEventTime").obj().getTiming())
109  tracks2Dfinder = Belle2.PyStoreArray("Trg2DFinderTracks")
110  tracks2Dfitter = Belle2.PyStoreArray("Trg2DFitterTracks")
111  tracks3Dfitter = Belle2.PyStoreArray("Trg3DFitterTracks")
112  tracks3Dneuro = Belle2.PyStoreArray("TrgNNTracks")
113  listnames = ["2D finder", "2D fitter", "3D fitter", "Neurotrigger"]
114  for i, tracks in enumerate([tracks2Dfinder, tracks2Dfitter,
115  tracks3Dfitter, tracks3Dneuro]):
116  print(listnames[i], "has", len(tracks), "tracks.")
117  for track in tracks:
118  print("phi0[deg] = %.2f" % (track.getPhi0() * 180. / np.pi),
119  "pt[GeV] = %.3f" % track.getTransverseMomentum(1.5),
120  "charge = %d" % track.getChargeSign(),
121  "theta[deg] = %.2f" % (np.arctan2(1., track.getCotTheta()) * 180. / np.pi),
122  "z[cm] = %.2f" % track.getZ0())
123  print(len(Belle2.PyStoreArray("MCParticles")), "MCParticles.")
124  for particle in Belle2.PyStoreArray("MCParticles"):
125  print("phi0[deg] = %.2f" % (particle.getMomentum().Phi() * 180. / np.pi),
126  "pt[GeV] = %.3f" % particle.getMomentum().Pt(),
127  "charge = %d" % particle.getCharge(),
128  "theta[deg] = %.2f" % (particle.getMomentum().Theta() * 180. / np.pi),
129  "z[cm] = %.2f" % particle.getProductionVertex().Z())
130 
131 
132 main.add_module(TestModule())
133 
134 # Process events
135 basf2.process(main)
136 
137 # Print call statistics
138 print(basf2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67