20from ROOT
import Belle2
24 """Small module to demonstrate how the registration of StoreArrays works from Python"""
27 """ Register a StoreArray on the DataStore"""
29 mcParticles.registerInDataStore()
32 """ Access and fill the registered StoreArray """
35 mcParticle = mcParticles.appendNew()
38 vertex = ROOT.TVector3(0, 0, 0)
42 phi = ROOT.gRandom.Uniform(0.0, 2.0 * math.pi)
43 costheta = ROOT.gRandom.Uniform(-1.0, 1.0)
44 theta = math.acos(costheta)
45 momentum = ROOT.Math.XYZVector(math.sin(theta) * math.cos(phi), math.sin(theta) * math.sin(phi), costheta)
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)
144if __name__ ==
"__main__":
static bool isOutputProcess()
Return true if the process is an output process.
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
Wrap a root histogram or TNtuple to make it mergeable.
tfile
save statistics in here