16 from ROOT
import Belle2
22 """Small module to demonstrate how the registration of StoreArrays works from Python"""
25 """ Register a StoreArray on the DataStore"""
27 mcParticles.registerInDataStore()
30 """ Access and fill the registered StoreArray """
33 mcParticle = mcParticles.appendNew()
36 vertex = ROOT.TVector3(0, 0, 0)
40 phi = ROOT.gRandom.Uniform(0.0, 2.0 * math.pi)
41 costheta = ROOT.gRandom.Uniform(-1.0, 1.0)
42 theta = math.acos(costheta)
43 r = max(0, ROOT.gRandom.Gaus(1, 0.2))
44 momentum = ROOT.TVector3(0, 0, 0)
45 momentum.SetMagThetaPhi(1, theta, phi)
48 mcParticle.setMassFromPDG()
49 mcParticle.addStatus(Belle2.MCParticle.c_PrimaryParticle)
50 mcParticle.addStatus(Belle2.MCParticle.c_StableInGenerator)
51 mcParticle.setProductionVertex(vertex)
52 mcParticle.setMomentum(momentum)
53 m = mcParticle.getMass()
54 mcParticle.setEnergy(math.sqrt(momentum * momentum + m * m))
55 mcParticle.setDecayTime(float(
"inf"))
59 """Collect statistics on particles - also parallel processable"""
62 """set module flags"""
64 self.set_property_flags(
65 basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED |
66 basf2.ModulePropFlags.TERMINATEINALLPROCESSES)
71 self.
tfile = ROOT.TFile(
"ParticleStatistics.root",
"recreate")
74 ntuple.registerInDataStore()
75 print(
"IsValid", ntuple.isValid())
77 print(
"IsValid", ntuple.isValid())
78 ntuple.obj().assign(ROOT.TNtuple(
"Particles",
79 "Momentum compontents of the particles",
84 hist.registerInDataStore()
85 print(
"IsValid", hist.isValid())
87 print(
"IsValid", hist.isValid())
88 hist.obj().assign(ROOT.TH1D(
"AbsMomentum",
89 "Absolute momentum of particles",
95 print(
"IsValid", ntuple.isValid())
96 print(
"IsValid", hist.isValid())
99 """actually collect info"""
105 for mcParticle
in mcParticles:
106 momentum = mcParticle.getMomentum()
107 ntuple.get().Fill(momentum.X(),
111 hist.get().Fill(momentum.Mag())
117 print(
"Writting objects")
119 ntuple.write(self.
tfile)
122 hist.write(self.
tfile)
128 path = basf2.create_path()
129 path.add_module(
'EventInfoSetter',
141 print(basf2.statistics)
144 if __name__ ==
"__main__":