13 genPixelLikelihoods.py
15 A sample script that demonstrates how to collect data using the TOPPixelLikelihood
19 basf2 genPixelLikelihoods.py -n100 -- --particle 321 --output kaon.awkd
21 Note: data writing uses AwkwardArrays (tested with v0.12.6).
25 from ROOT
import Belle2
26 from tracking
import add_tracking_reconstruction
27 from svd
import add_svd_reconstruction, add_svd_simulation
28 from pxd
import add_pxd_reconstruction, add_pxd_simulation
30 from argparse
import ArgumentParser
36 ap = ArgumentParser(
'')
37 ap.add_argument(
'--output',
'-o', default=
'output.awkd', help=
'output filename')
38 ap.add_argument(
'--particle', type=int, default=13, help=
'pdg code of the particles to generate')
39 ap.add_argument(
'--momentum_lower', type=float, default=2., help=
'lower bound for momentum')
40 ap.add_argument(
'--momentum_upper', type=float, default=2., help=
'upper bound for momentum')
41 ap.add_argument(
'--phi_lower', type=float, default=0., help=
'lower bound for phi')
42 ap.add_argument(
'--phi_upper', type=float, default=360., help=
'upper bound for phi')
43 ap.add_argument(
'--theta_lower', type=float, default=32.6, help=
'lower bound for theta')
44 ap.add_argument(
'--theta_upper', type=float, default=122., help=
'upper bound for theta')
45 ap.add_argument(
'--xVertex', type=float, default=0., help=
'x-coordinate of initial position')
46 ap.add_argument(
'--yVertex', type=float, default=0., help=
'y-coordinate of initial position')
47 ap.add_argument(
'--zVertex', type=float, default=0., help=
'z-coordinate of initial position')
49 opts = ap.parse_args()
54 Data collector module. Gathers TOP Cherenkov photon data for each event.
55 On terminate(), writes gathered data to given output file.
58 data: A list containing AwkwardArrays with each event's data.
62 """Inits WriteData object."""
67 """Collects event data about TOP Cherenkov photons."""
69 mcp = sorted(mcps, key=
lambda x: x.getEnergy(), reverse=
True)[0]
70 mcp_pdg = abs(mcp.getPDG())
71 track = mcp.getRelated(
'Tracks')
73 print(
'no related track')
75 logl = track.getRelated(
'TOPLikelihoods')
77 print(
'no related loglihoods')
79 pixlogl = track.getRelated(
'TOPPixelLikelihoods')
81 print(
'no related pixel loglihoods')
89 photon_detections = []
92 moduleID = d.getModuleID()
93 simhit = d.getRelated(
"TOPSimHits")
96 photon = simhit.getRelated(
"TOPSimPhotons")
100 chanID = d.getPixelID() - 1
101 time = photon.getDetectionTime()
102 point = photon.getEmissionPoint()
103 emitTime = photon.getEmissionTime()
104 photon_detections.append([
106 point.X(), point.Y(), point.Z(), emitTime
109 self.
datadata.append(
111 np.array(pixlogl.getPixelLogL_e()),
112 np.array(pixlogl.getPixelLogL_mu()),
113 np.array(pixlogl.getPixelLogL_pi()),
114 np.array(pixlogl.getPixelLogL_K()),
115 np.array(pixlogl.getPixelLogL_p()),
116 np.array(pixlogl.getPixelSigPhot_e()),
117 np.array(pixlogl.getPixelSigPhot_mu()),
118 np.array(pixlogl.getPixelSigPhot_pi()),
119 np.array(pixlogl.getPixelSigPhot_K()),
120 np.array(pixlogl.getPixelSigPhot_p()),
132 """Writes data to given output file."""
133 awk.save(opts.output, self.
datadata, mode=
"w")
137 b2.set_log_level(b2.LogLevel.ERROR)
140 main = b2.create_path()
143 eventinfosetter = b2.register_module(
'EventInfoSetter')
144 eventinfosetter.param({
'evtNumList': [10000]})
145 main.add_module(eventinfosetter)
148 gearbox = b2.register_module(
'Gearbox')
149 main.add_module(gearbox)
152 geometry = b2.register_module(
'Geometry')
153 main.add_module(geometry)
156 particlegun = b2.register_module(
'ParticleGun')
157 particlegun.param(
'pdgCodes', [opts.particle])
158 particlegun.param(
'nTracks', 1)
159 particlegun.param(
'varyNTracks',
False)
160 particlegun.param(
'independentVertices',
False)
161 particlegun.param(
'momentumGeneration',
'uniform')
162 particlegun.param(
'momentumParams', [opts.momentum_lower, opts.momentum_upper])
163 particlegun.param(
'thetaGeneration',
'uniform')
164 particlegun.param(
'thetaParams', [opts.theta_lower, opts.theta_upper])
165 particlegun.param(
'phiGeneration',
'uniform')
166 particlegun.param(
'phiParams', [opts.phi_lower, opts.phi_upper])
167 particlegun.param(
'vertexGeneration',
'fixed')
168 particlegun.param(
'xVertexParams', [opts.xVertex])
169 particlegun.param(
'yVertexParams', [opts.yVertex])
170 particlegun.param(
'zVertexParams', [opts.zVertex])
171 main.add_module(particlegun)
174 simulation = b2.register_module(
'FullSim')
175 main.add_module(simulation)
177 add_svd_simulation(main)
178 add_pxd_simulation(main)
181 add_pxd_reconstruction(main)
184 add_svd_reconstruction(main)
187 cdcDigitizer = b2.register_module(
'CDCDigitizer')
188 main.add_module(cdcDigitizer)
191 topdigi = b2.register_module(
'TOPDigitizer')
192 main.add_module(topdigi)
194 add_tracking_reconstruction(main)
197 ext = b2.register_module(
'Ext')
201 top_cm = b2.register_module(
'TOPChannelMasker')
202 main.add_module(top_cm)
204 topreco = b2.register_module(
'TOPReconstructor')
205 main.add_module(topreco)
207 pdfdebug = b2.register_module(
"TOPPDFDebugger")
208 pdfdebug.pdfOption =
'fine'
209 main.add_module(pdfdebug)
212 main.add_module(data_getter)
215 progress = b2.register_module(
'Progress')
216 main.add_module(progress)
A (simplified) python wrapper for StoreArray.
data
A list containing arrays with each event's data.