14A sample script that demonstrates how to collect data using the TOPPixelLikelihood
18 basf2 genPixelLikelihoods.py -n100 -- --particle 321 --output kaon.awkd
20Note: data writing uses AwkwardArrays (tested with v0.12.6).
24from ROOT import Belle2
25from tracking import add_tracking_reconstruction
26from svd import add_svd_reconstruction, add_svd_simulation
27from pxd import add_pxd_reconstruction, add_pxd_simulation
29from argparse import ArgumentParser
35ap = ArgumentParser('')
36ap.add_argument('--output', '-o', default='output.awkd', help='output filename')
37ap.add_argument('--particle', type=int, default=13, help='pdg code of the particles to generate')
38ap.add_argument(
'--momentum_lower', type=float, default=2., help=
'lower bound for momentum')
39ap.add_argument(
'--momentum_upper', type=float, default=2., help=
'upper bound for momentum')
40ap.add_argument(
'--phi_lower', type=float, default=0., help=
'lower bound for phi')
41ap.add_argument(
'--phi_upper', type=float, default=360., help=
'upper bound for phi')
42ap.add_argument(
'--theta_lower', type=float, default=32.6, help=
'lower bound for theta')
43ap.add_argument(
'--theta_upper', type=float, default=122., help=
'upper bound for theta')
44ap.add_argument(
'--xVertex', type=float, default=0., help=
'x-coordinate of initial position')
45ap.add_argument(
'--yVertex', type=float, default=0., help=
'y-coordinate of initial position')
46ap.add_argument(
'--zVertex', type=float, default=0., help=
'z-coordinate of initial position')
53 Data collector module. Gathers TOP Cherenkov photon data for each event.
54 On
terminate(), writes gathered data to given output file.
57 data: A list containing AwkwardArrays
with each event
's data.
61 """Inits WriteData object."""
66 """Collects event data about TOP Cherenkov photons."""
68 mcp = sorted(mcps, key=
lambda x: x.getEnergy(), reverse=
True)[0]
69 mcp_pdg = abs(mcp.getPDG())
70 track = mcp.getRelated(
'Tracks')
72 print(
'no related track')
74 logl = track.getRelated(
'TOPLikelihoods')
76 print(
'no related loglihoods')
78 pixlogl = track.getRelated(
'TOPPixelLikelihoods')
80 print(
'no related pixel loglihoods')
88 photon_detections = []
91 moduleID = d.getModuleID()
92 simhit = d.getRelated(
"TOPSimHits")
95 photon = simhit.getRelated(
"TOPSimPhotons")
99 chanID = d.getPixelID() - 1
100 time = photon.getDetectionTime()
101 point = photon.getEmissionPoint()
102 emitTime = photon.getEmissionTime()
103 photon_detections.append([
105 point.X(), point.Y(), point.Z(), emitTime
110 np.array(pixlogl.getPixelLogL_e()),
111 np.array(pixlogl.getPixelLogL_mu()),
112 np.array(pixlogl.getPixelLogL_pi()),
113 np.array(pixlogl.getPixelLogL_K()),
114 np.array(pixlogl.getPixelLogL_p()),
115 np.array(pixlogl.getPixelSigPhot_e()),
116 np.array(pixlogl.getPixelSigPhot_mu()),
117 np.array(pixlogl.getPixelSigPhot_pi()),
118 np.array(pixlogl.getPixelSigPhot_K()),
119 np.array(pixlogl.getPixelSigPhot_p()),
131 """Writes data to given output file."""
132 awk.save(opts.output, self.
data, mode=
"w")
136b2.set_log_level(b2.LogLevel.ERROR)
139main = b2.create_path()
142eventinfosetter = b2.register_module(
'EventInfoSetter')
143eventinfosetter.param({
'evtNumList': [10000]})
144main.add_module(eventinfosetter)
147gearbox = b2.register_module(
'Gearbox')
148main.add_module(gearbox)
151geometry = b2.register_module(
'Geometry')
152main.add_module(geometry)
155particlegun = b2.register_module(
'ParticleGun')
156particlegun.param(
'pdgCodes', [opts.particle])
157particlegun.param(
'nTracks', 1)
158particlegun.param(
'varyNTracks',
False)
159particlegun.param(
'independentVertices',
False)
160particlegun.param(
'momentumGeneration',
'uniform')
161particlegun.param(
'momentumParams', [opts.momentum_lower, opts.momentum_upper])
162particlegun.param(
'thetaGeneration',
'uniform')
163particlegun.param(
'thetaParams', [opts.theta_lower, opts.theta_upper])
164particlegun.param(
'phiGeneration',
'uniform')
165particlegun.param(
'phiParams', [opts.phi_lower, opts.phi_upper])
166particlegun.param(
'vertexGeneration',
'fixed')
167particlegun.param(
'xVertexParams', [opts.xVertex])
168particlegun.param(
'yVertexParams', [opts.yVertex])
169particlegun.param(
'zVertexParams', [opts.zVertex])
170main.add_module(particlegun)
173simulation = b2.register_module(
'FullSim')
174main.add_module(simulation)
176add_svd_simulation(main)
177add_pxd_simulation(main)
180add_pxd_reconstruction(main)
183add_svd_reconstruction(main)
186cdcDigitizer = b2.register_module(
'CDCDigitizer')
187main.add_module(cdcDigitizer)
190topdigi = b2.register_module(
'TOPDigitizer')
191main.add_module(topdigi)
193add_tracking_reconstruction(main)
196ext = b2.register_module(
'Ext')
200top_cm = b2.register_module(
'TOPChannelMasker')
201main.add_module(top_cm)
203topreco = b2.register_module(
'TOPReconstructor')
204main.add_module(topreco)
206pdfdebug = b2.register_module(
"TOPPDFDebugger")
207pdfdebug.pdfOption =
'fine'
208main.add_module(pdfdebug)
211main.add_module(data_getter)
214progress = b2.register_module(
'Progress')
215main.add_module(progress)
A (simplified) python wrapper for StoreArray.
data
A list containing arrays with each event's data.