20 from 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.TVector3(0, 0, 0)
46 momentum.SetMagThetaPhi(1, theta, phi)
49 mcParticle.setMassFromPDG()
50 mcParticle.addStatus(Belle2.MCParticle.c_PrimaryParticle)
51 mcParticle.addStatus(Belle2.MCParticle.c_StableInGenerator)
52 mcParticle.setProductionVertex(vertex)
53 mcParticle.setMomentum(momentum)
54 m = mcParticle.getMass()
55 mcParticle.setEnergy(math.sqrt(momentum * momentum + m * m))
56 mcParticle.setDecayTime(float(
"inf"))
60 """Collect statistics on particles - also parallel processable"""
63 """set module flags"""
65 self.set_property_flags(
66 basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED |
67 basf2.ModulePropFlags.TERMINATEINALLPROCESSES)
72 self.
tfiletfile = ROOT.TFile(
"ParticleStatistics.root",
"recreate")
75 ntuple.registerInDataStore()
76 print(
"IsValid", ntuple.isValid())
78 print(
"IsValid", ntuple.isValid())
79 ntuple.obj().assign(ROOT.TNtuple(
"Particles",
80 "Momentum compontents of the particles",
85 hist.registerInDataStore()
86 print(
"IsValid", hist.isValid())
88 print(
"IsValid", hist.isValid())
89 hist.obj().assign(ROOT.TH1D(
"AbsMomentum",
90 "Absolute momentum of particles",
96 print(
"IsValid", ntuple.isValid())
97 print(
"IsValid", hist.isValid())
100 """actually collect info"""
106 for mcParticle
in mcParticles:
107 momentum = mcParticle.getMomentum()
108 ntuple.get().Fill(momentum.X(),
112 hist.get().Fill(momentum.Mag())
118 print(
"Writting objects")
120 ntuple.write(self.
tfiletfile)
123 hist.write(self.
tfiletfile)
125 self.
tfiletfile.Close()
129 path = basf2.create_path()
130 path.add_module(
'EventInfoSetter',
142 print(basf2.statistics)
145 if __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
int main(int argc, char **argv)
Run all tests.