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