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